MCPcopy
hub / github.com/anomalyco/opencode / DialogSelect

Function DialogSelect

packages/tui/src/ui/dialog-select.tsx:80–729  ·  view source on GitHub ↗
(props: DialogSelectProps<T>)

Source from the content-addressed store, hash-verified

78}
79
80export 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(() => [

Callers

nothing calls this directly

Calls 15

useDialogFunction · 0.90
useTuiConfigFunction · 0.90
getScrollAccelerationFunction · 0.90
formatKeyBindingsFunction · 0.90
setStoreFunction · 0.85
actionsFunction · 0.85
isActionDisabledFunction · 0.85
pipeFunction · 0.85
filterFunction · 0.85
filteredFunction · 0.85
groupedFunction · 0.85
scrollToSelectionFunction · 0.85

Tested by

no test coverage detected