(props: DialogSelectProps<T>)
| 78 | } |
| 79 | |
| 80 | export function DialogSelect<T>(props: DialogSelectProps<T>) { |
| 81 | type Action = NonNullable<DialogSelectProps<T>["actions"]>[number] |
| 82 | type FooterHint = NonNullable<DialogSelectProps<T>["footerHints"]>[number] |
| 83 | type VisibleAction = (Action & { label: string }) | FooterHint |
| 84 | |
| 85 | const dialog = useDialog() |
| 86 | const { theme } = useTheme() |
| 87 | const tuiConfig = useTuiConfig() |
| 88 | const scrollAcceleration = createMemo(() => getScrollAcceleration(tuiConfig)) |
| 89 | |
| 90 | const [store, setStore] = createStore({ |
| 91 | selected: 0, |
| 92 | filter: "", |
| 93 | input: "keyboard" as "keyboard" | "mouse", |
| 94 | }) |
| 95 | const [focusedAction, setFocusedAction] = createSignal<number>() |
| 96 | const actionFocused = createMemo(() => focusedAction() !== undefined) |
| 97 | let selection: { value: T; category?: string } | undefined |
| 98 | let resetSelection = false |
| 99 | let visibilityGeneration = 0 |
| 100 | |
| 101 | createEffect( |
| 102 | on( |
| 103 | () => props.current, |
| 104 | (current) => { |
| 105 | if (current) { |
| 106 | const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current)) |
| 107 | if (currentIndex >= 0) { |
| 108 | setStore("selected", currentIndex) |
| 109 | selection = flat()[currentIndex] |
| 110 | } |
| 111 | } |
| 112 | }, |
| 113 | ), |
| 114 | ) |
| 115 | |
| 116 | let input: InputRenderable |
| 117 | |
| 118 | const actions = createMemo(() => props.actions ?? []) |
| 119 | const shownActions = createMemo(() => actions().filter((item) => !item.hidden)) |
| 120 | const actionBindings = useKeymapSelector((keymap) => |
| 121 | keymap.getCommandBindings({ |
| 122 | visibility: "registered", |
| 123 | commands: shownActions().map((item) => item.command), |
| 124 | }), |
| 125 | ) |
| 126 | |
| 127 | const actionLabels = createMemo(() => { |
| 128 | const labels = new Map<string, string>() |
| 129 | |
| 130 | for (const action of shownActions()) { |
| 131 | const label = formatKeyBindings(actionBindings().get(action.command), tuiConfig) |
| 132 | if (label) labels.set(action.command, label) |
| 133 | } |
| 134 | |
| 135 | return labels |
| 136 | }) |
| 137 | const visibleActions = createMemo(() => [ |
nothing calls this directly
no test coverage detected