@kerf-js/veneer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +1338 -2
- package/package.json +56 -3
- package/plugin.d.mts +187 -0
- package/plugin.mjs +399 -0
- package/src/Accordion.tsx +98 -0
- package/src/Alert.tsx +55 -0
- package/src/Badge.tsx +39 -0
- package/src/Button.tsx +175 -0
- package/src/Calendar-month.tsx +140 -0
- package/src/Calendar.tsx +335 -0
- package/src/Canvas.tsx +221 -0
- package/src/Card.tsx +85 -0
- package/src/Chart.tsx +278 -0
- package/src/Charts.tsx +158 -0
- package/src/Chip.tsx +61 -0
- package/src/Choice-checkbox.tsx +53 -0
- package/src/Choice-parts.tsx +7 -0
- package/src/Choice-radio.tsx +78 -0
- package/src/Choice-segmented.tsx +76 -0
- package/src/Choice-switch.tsx +51 -0
- package/src/Choice.tsx +4 -0
- package/src/CloseX.tsx +14 -0
- package/src/CodeBlock.tsx +81 -0
- package/src/CodeInput.tsx +256 -0
- package/src/Combobox.tsx +281 -0
- package/src/CommandPalette-controller.ts +314 -0
- package/src/CommandPalette-rows.tsx +137 -0
- package/src/CommandPalette.tsx +196 -0
- package/src/DataGrid-actions.ts +119 -0
- package/src/DataGrid-body.tsx +58 -0
- package/src/DataGrid-controller.ts +145 -0
- package/src/DataGrid-header.tsx +108 -0
- package/src/DataGrid-model.ts +248 -0
- package/src/DataGrid-pivot.tsx +108 -0
- package/src/DataGrid-rows.tsx +296 -0
- package/src/DataGrid-toolbar.tsx +127 -0
- package/src/DataGrid-tree.ts +149 -0
- package/src/DataGrid-viewport.tsx +37 -0
- package/src/DataGrid.tsx +145 -0
- package/src/DateField-presets.tsx +27 -0
- package/src/DateField-range.tsx +370 -0
- package/src/DateField.tsx +295 -0
- package/src/Dither.tsx +313 -0
- package/src/Drawer.tsx +123 -0
- package/src/DurationField.tsx +227 -0
- package/src/Feed.tsx +78 -0
- package/src/Field/view.tsx +147 -0
- package/src/Field.tsx +238 -0
- package/src/HamburgerMenu.tsx +119 -0
- package/src/Icon.tsx +15 -0
- package/src/Kbd.tsx +6 -0
- package/src/KeyValueEditor/actions.ts +75 -0
- package/src/KeyValueEditor/rows.tsx +104 -0
- package/src/KeyValueEditor.tsx +112 -0
- package/src/Layout.tsx +221 -0
- package/src/Markdown.tsx +127 -0
- package/src/MentionsInput/actions.ts +161 -0
- package/src/MentionsInput/end.tsx +82 -0
- package/src/MentionsInput.tsx +103 -0
- package/src/Menu.tsx +221 -0
- package/src/Modal.tsx +109 -0
- package/src/MonthPicker/month.tsx +117 -0
- package/src/MonthPicker/period.tsx +197 -0
- package/src/MonthPicker/shared.tsx +272 -0
- package/src/MonthPicker/week.tsx +103 -0
- package/src/MonthPicker.tsx +11 -0
- package/src/MultiSelect.tsx +139 -0
- package/src/Nav.tsx +36 -0
- package/src/NumberField.tsx +156 -0
- package/src/Pagination.tsx +335 -0
- package/src/PaymentCard.tsx +111 -0
- package/src/Picker.tsx +228 -0
- package/src/PlaceField.tsx +285 -0
- package/src/Popover.tsx +88 -0
- package/src/Presence.tsx +37 -0
- package/src/Progress.tsx +71 -0
- package/src/RecurrenceField.tsx +372 -0
- package/src/RichSelect/codes.tsx +94 -0
- package/src/RichSelect/list.tsx +380 -0
- package/src/RichSelect/phone-view.tsx +114 -0
- package/src/RichSelect/phone.tsx +305 -0
- package/src/RichSelect/search-keys.ts +28 -0
- package/src/RichSelect/timezone.tsx +53 -0
- package/src/RichSelect.tsx +13 -0
- package/src/RichTextEditor/controller.tsx +305 -0
- package/src/RichTextEditor/editor.tsx +61 -0
- package/src/RichTextEditor/tools.tsx +132 -0
- package/src/RichTextEditor/view.tsx +210 -0
- package/src/RichTextEditor.tsx +9 -0
- package/src/ScrollGrid/measure.ts +39 -0
- package/src/ScrollGrid/parts.tsx +112 -0
- package/src/ScrollGrid.tsx +375 -0
- package/src/ScrollRail.tsx +114 -0
- package/src/ScrollView.tsx +57 -0
- package/src/Segments/controller.tsx +148 -0
- package/src/Segments/events.ts +99 -0
- package/src/Segments/view.tsx +77 -0
- package/src/Segments.tsx +2 -0
- package/src/Select.tsx +343 -0
- package/src/Shape.tsx +41 -0
- package/src/Shell/branches.tsx +108 -0
- package/src/Shell/button.tsx +33 -0
- package/src/Shell/shared.tsx +220 -0
- package/src/Shell/shell.tsx +25 -0
- package/src/Shell/state.ts +138 -0
- package/src/Shell/view.tsx +280 -0
- package/src/Shell.tsx +17 -0
- package/src/SideNav/sections.tsx +50 -0
- package/src/SideNav/state.ts +140 -0
- package/src/SideNav.tsx +130 -0
- package/src/SideNavTitle.tsx +25 -0
- package/src/SignaturePad/state.ts +172 -0
- package/src/SignaturePad/view.tsx +69 -0
- package/src/SignaturePad.tsx +76 -0
- package/src/Skeleton.tsx +46 -0
- package/src/Slider.tsx +81 -0
- package/src/Spinner.tsx +21 -0
- package/src/Stage-director.ts +361 -0
- package/src/Stage-look.ts +75 -0
- package/src/Stage-poster.tsx +62 -0
- package/src/Stage-types.ts +206 -0
- package/src/Stage.tsx +147 -0
- package/src/TabBar.tsx +114 -0
- package/src/Table-actions.tsx +51 -0
- package/src/Table-base.ts +70 -0
- package/src/Table-body.tsx +84 -0
- package/src/Table-columns.tsx +58 -0
- package/src/Table-details.tsx +66 -0
- package/src/Table-editor.tsx +66 -0
- package/src/Table-head.tsx +52 -0
- package/src/Table-model.ts +82 -0
- package/src/Table-notice.ts +39 -0
- package/src/Table-paging.ts +50 -0
- package/src/Table-rows.tsx +308 -0
- package/src/Table-selection.ts +63 -0
- package/src/Table-sortbar.tsx +41 -0
- package/src/Table-source.ts +66 -0
- package/src/Table-toolbar.tsx +71 -0
- package/src/Table-types.ts +115 -0
- package/src/Table-view.tsx +87 -0
- package/src/Table.tsx +31 -0
- package/src/Tabs.tsx +129 -0
- package/src/Tag.tsx +40 -0
- package/src/Ticker.tsx +42 -0
- package/src/TimeField-date-model.ts +77 -0
- package/src/TimeField-date-view.tsx +152 -0
- package/src/TimeField-model.ts +80 -0
- package/src/TimeField-options.tsx +224 -0
- package/src/TimeField-slots.tsx +32 -0
- package/src/TimeField-types.ts +33 -0
- package/src/TimeField-view.tsx +124 -0
- package/src/TimeField.tsx +126 -0
- package/src/Toast.tsx +143 -0
- package/src/Toggle.tsx +75 -0
- package/src/Tooltip.tsx +69 -0
- package/src/Type.tsx +136 -0
- package/src/VirtualList-controls.ts +105 -0
- package/src/VirtualList-data.ts +43 -0
- package/src/VirtualList-measure.ts +169 -0
- package/src/VirtualList-metrics.ts +41 -0
- package/src/VirtualList-mount.ts +145 -0
- package/src/VirtualList-rows.tsx +91 -0
- package/src/VirtualList-types.ts +76 -0
- package/src/VirtualList-view.tsx +123 -0
- package/src/VirtualList.tsx +81 -0
- package/src/admin/ApiKeys-actions.ts +124 -0
- package/src/admin/ApiKeys-form.tsx +64 -0
- package/src/admin/ApiKeys-view.tsx +101 -0
- package/src/admin/ApiKeys.tsx +224 -0
- package/src/admin/Audit.tsx +246 -0
- package/src/admin/Billing.tsx +307 -0
- package/src/admin/Cart.tsx +177 -0
- package/src/admin/Checkout-address.tsx +125 -0
- package/src/admin/Checkout-cart.tsx +78 -0
- package/src/admin/Checkout-coupon.ts +34 -0
- package/src/admin/Checkout-done.tsx +31 -0
- package/src/admin/Checkout-model.ts +33 -0
- package/src/admin/Checkout-navigation.ts +76 -0
- package/src/admin/Checkout-payment-view.tsx +49 -0
- package/src/admin/Checkout-payment.ts +80 -0
- package/src/admin/Checkout-review.tsx +60 -0
- package/src/admin/Checkout-shipping.tsx +47 -0
- package/src/admin/Checkout-state.ts +122 -0
- package/src/admin/Checkout-steps.ts +10 -0
- package/src/admin/Checkout-summary.tsx +97 -0
- package/src/admin/Checkout-types.ts +60 -0
- package/src/admin/Checkout-view.tsx +51 -0
- package/src/admin/Checkout.tsx +72 -0
- package/src/admin/CsvImport-actions.ts +131 -0
- package/src/admin/CsvImport.tsx +379 -0
- package/src/admin/Danger.tsx +240 -0
- package/src/admin/Integrations/Card.tsx +82 -0
- package/src/admin/Integrations/Webhooks.tsx +341 -0
- package/src/admin/Integrations.tsx +169 -0
- package/src/admin/InviteDialog.tsx +153 -0
- package/src/admin/Members/columns.tsx +181 -0
- package/src/admin/Members.tsx +316 -0
- package/src/admin/Order.tsx +115 -0
- package/src/admin/PlainTable.tsx +34 -0
- package/src/admin/Plans.tsx +375 -0
- package/src/admin/SaveBar/actions.ts +86 -0
- package/src/admin/SaveBar.tsx +153 -0
- package/src/admin/Secret.tsx +74 -0
- package/src/admin/Settings.tsx +145 -0
- package/src/admin/StepBar.tsx +66 -0
- package/src/admin/TagsInput/actions.ts +60 -0
- package/src/admin/TagsInput.tsx +95 -0
- package/src/admin/atoms.tsx +73 -0
- package/src/admin/index.ts +67 -0
- package/src/agent/Actions/reasons.tsx +38 -0
- package/src/agent/Actions.tsx +166 -0
- package/src/agent/AgentPlan.tsx +86 -0
- package/src/agent/ArtifactPanel.tsx +299 -0
- package/src/agent/Assistant.tsx +168 -0
- package/src/agent/Checkpoint.tsx +19 -0
- package/src/agent/Cite.tsx +70 -0
- package/src/agent/ContextMeter.tsx +70 -0
- package/src/agent/Conversation.tsx +70 -0
- package/src/agent/Message.tsx +92 -0
- package/src/agent/ModelPicker.tsx +167 -0
- package/src/agent/Prompt-model.ts +118 -0
- package/src/agent/Prompt-view.tsx +246 -0
- package/src/agent/Prompt.tsx +128 -0
- package/src/agent/Prose.tsx +118 -0
- package/src/agent/Question.tsx +137 -0
- package/src/agent/Reasoning.tsx +31 -0
- package/src/agent/Shimmer.tsx +11 -0
- package/src/agent/Sources.tsx +23 -0
- package/src/agent/SpeechInput.tsx +243 -0
- package/src/agent/Suggestions.tsx +36 -0
- package/src/agent/ToolCall.tsx +219 -0
- package/src/agent/TraceViewer.tsx +96 -0
- package/src/agent/bits.tsx +88 -0
- package/src/agent/index.ts +38 -0
- package/src/bind.ts +57 -0
- package/src/collab/AutoTrack.tsx +91 -0
- package/src/collab/Comments.tsx +204 -0
- package/src/collab/Composer/state.ts +125 -0
- package/src/collab/Composer/view.tsx +155 -0
- package/src/collab/Composer.tsx +141 -0
- package/src/collab/ConversationList.tsx +120 -0
- package/src/collab/Cursors.tsx +71 -0
- package/src/collab/DataIntegrity.tsx +103 -0
- package/src/collab/Kanban-card.ts +74 -0
- package/src/collab/Kanban.tsx +368 -0
- package/src/collab/Lock.tsx +36 -0
- package/src/collab/PresenceStack.tsx +176 -0
- package/src/collab/ShareDialog.tsx +273 -0
- package/src/collab/Status.tsx +101 -0
- package/src/collab/SyncedForm.tsx +42 -0
- package/src/collab/Thread/Message.tsx +265 -0
- package/src/collab/Thread/rows.tsx +56 -0
- package/src/collab/Thread.tsx +323 -0
- package/src/collab/VersionHistory.tsx +173 -0
- package/src/collab/ViewportRail.tsx +73 -0
- package/src/collab/index.ts +37 -0
- package/src/collab/peer.tsx +42 -0
- package/src/fields.ts +5 -0
- package/src/flow/AuthScreen.tsx +81 -0
- package/src/flow/AuthSteps.tsx +296 -0
- package/src/flow/Checklist.tsx +211 -0
- package/src/flow/ConnBanner.tsx +304 -0
- package/src/flow/Flow.tsx +97 -0
- package/src/flow/MfaSetup.tsx +244 -0
- package/src/flow/Otp.tsx +243 -0
- package/src/flow/ReauthDialog.tsx +79 -0
- package/src/flow/ShortcutsOverlay.tsx +121 -0
- package/src/flow/SignGate.tsx +184 -0
- package/src/flow/SignIn.tsx +136 -0
- package/src/flow/SignUp.tsx +149 -0
- package/src/flow/Sso.tsx +96 -0
- package/src/flow/SystemPage/accounts.tsx +74 -0
- package/src/flow/SystemPage/art.tsx +113 -0
- package/src/flow/SystemPage.tsx +395 -0
- package/src/flow/Tour.tsx +207 -0
- package/src/flow/index.ts +29 -0
- package/src/flow/kit.tsx +334 -0
- package/src/index.ts +237 -0
- package/src/layout.css +4 -0
- package/src/links.css +4 -0
- package/src/live/ActivityFeed.tsx +88 -0
- package/src/live/Bell.tsx +108 -0
- package/src/live/Connection.tsx +113 -0
- package/src/live/Inbox.tsx +113 -0
- package/src/live/InboxFeed.tsx +67 -0
- package/src/live/InboxGestures.ts +41 -0
- package/src/live/InboxHandlers.ts +102 -0
- package/src/live/InboxHeader.tsx +81 -0
- package/src/live/InboxModel.ts +81 -0
- package/src/live/InboxRow.tsx +125 -0
- package/src/live/MeetingRoom.tsx +22 -0
- package/src/live/MeetingRoomControlBar.tsx +197 -0
- package/src/live/MeetingRoomHandlers.ts +53 -0
- package/src/live/MeetingRoomLayout.tsx +27 -0
- package/src/live/MeetingRoomModel.ts +49 -0
- package/src/live/MeetingRoomMount.ts +49 -0
- package/src/live/MeetingRoomParts.tsx +178 -0
- package/src/live/MeetingRoomPerson.tsx +21 -0
- package/src/live/MeetingRoomState.ts +88 -0
- package/src/live/MeetingRoomTile.tsx +84 -0
- package/src/live/MeetingRoomTypes.ts +68 -0
- package/src/live/MeetingRoomView.tsx +36 -0
- package/src/live/NotificationPreferences.tsx +99 -0
- package/src/live/NotificationPreferencesActions.ts +55 -0
- package/src/live/NotificationPreferencesCell.tsx +26 -0
- package/src/live/NotificationPreferencesCells.tsx +59 -0
- package/src/live/NotificationPreferencesGrid.tsx +129 -0
- package/src/live/NotificationPreferencesModel.tsx +91 -0
- package/src/live/NotificationPreferencesSave.ts +85 -0
- package/src/live/NotificationPreferencesWatch.ts +31 -0
- package/src/live/Prejoin.tsx +238 -0
- package/src/live/PrejoinMeter.tsx +26 -0
- package/src/live/PrejoinPreview.tsx +53 -0
- package/src/live/PushSoftAsk.tsx +63 -0
- package/src/live/TransportPicker.tsx +341 -0
- package/src/live/TransportPickerDetails.tsx +130 -0
- package/src/live/index.ts +31 -0
- package/src/live/notify.tsx +22 -0
- package/src/live/shared.tsx +110 -0
- package/src/parts.tsx +199 -0
- package/src/plugin/catalog.mjs +129 -0
- package/src/plugin/dtcg.mjs +79 -0
- package/src/plugin/icons.mjs +7 -0
- package/src/plugin/seed.mjs +40 -0
- package/src/plugin/theme-context.mjs +44 -0
- package/src/plugin/theme-css.mjs +143 -0
- package/src/plugin/theme-motion.mjs +43 -0
- package/src/plugin/theme-parts.d.mts +41 -0
- package/src/plugin/theme-parts.mjs +224 -0
- package/src/plugin/theme-text.mjs +93 -0
- package/src/plugin/theme-values.mjs +15 -0
- package/src/plugin/theme.d.mts +82 -0
- package/src/plugin/theme.mjs +316 -0
- package/src/schedule/Agenda.tsx +124 -0
- package/src/schedule/AgendaActions.ts +31 -0
- package/src/schedule/AgendaDay.tsx +124 -0
- package/src/schedule/AgendaGestures.ts +27 -0
- package/src/schedule/AgendaKeys.ts +52 -0
- package/src/schedule/AgendaModel.ts +82 -0
- package/src/schedule/AgendaNavigation.ts +38 -0
- package/src/schedule/AgendaPage.tsx +39 -0
- package/src/schedule/AgendaStrip.tsx +55 -0
- package/src/schedule/AvailabilityEditor-actions.ts +146 -0
- package/src/schedule/AvailabilityEditor-day.tsx +119 -0
- package/src/schedule/AvailabilityEditor-view.tsx +205 -0
- package/src/schedule/AvailabilityEditor.tsx +113 -0
- package/src/schedule/BookingCalendar.tsx +121 -0
- package/src/schedule/BookingCalendarActions.ts +85 -0
- package/src/schedule/BookingCalendarModel.ts +86 -0
- package/src/schedule/BookingCalendarParts.tsx +87 -0
- package/src/schedule/Calendar/AgendaView.tsx +45 -0
- package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
- package/src/schedule/Calendar/CalendarMain.tsx +47 -0
- package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
- package/src/schedule/Calendar/Column.tsx +129 -0
- package/src/schedule/Calendar/EventBlock.tsx +71 -0
- package/src/schedule/Calendar/MiniMonth.tsx +169 -0
- package/src/schedule/Calendar/MonthGrid.tsx +296 -0
- package/src/schedule/Calendar/TimeGrid.tsx +252 -0
- package/src/schedule/Calendar/Timeline.tsx +287 -0
- package/src/schedule/Calendar/ZoneChip.tsx +73 -0
- package/src/schedule/Calendar/calendar-shell.ts +160 -0
- package/src/schedule/Calendar/calendar-state.ts +30 -0
- package/src/schedule/Calendar/now-spans.tsx +33 -0
- package/src/schedule/Calendar/shared.ts +3 -0
- package/src/schedule/Calendar/state-actions.ts +189 -0
- package/src/schedule/Calendar/state-base.ts +143 -0
- package/src/schedule/Calendar/state-keys.ts +128 -0
- package/src/schedule/Calendar/time-fit.ts +84 -0
- package/src/schedule/Calendar.tsx +182 -0
- package/src/schedule/EventEditor.tsx +267 -0
- package/src/schedule/EventPopover.tsx +190 -0
- package/src/schedule/MeetingPlanner-model.ts +222 -0
- package/src/schedule/MeetingPlanner-view.tsx +310 -0
- package/src/schedule/MeetingPlanner.tsx +122 -0
- package/src/schedule/MoveSheet.tsx +168 -0
- package/src/schedule/YearView-model.ts +164 -0
- package/src/schedule/YearView-parts.tsx +147 -0
- package/src/schedule/YearView.tsx +100 -0
- package/src/schedule/bits.tsx +65 -0
- package/src/schedule/index.ts +25 -0
- package/src/skeleton-css.ts +4 -0
- package/src/styles.ts +13 -0
- package/src/type.css +15 -0
- package/src/ui.ts +41 -0
- package/src/use-ui.ts +10 -0
- package/tailwind.css +38 -0
- package/tokens/color.mjs +87 -0
package/src/Combobox.tsx
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { comboPopup, uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, flush, onCleanup, state, untrack, type State } from '@kerf-js/core'
|
|
3
|
+
import { Field, type FieldProps } from './Field'
|
|
4
|
+
import { Icon, type IconRef } from './Icon'
|
|
5
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/rich/listbox.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/rich/popover.css'
|
|
8
|
+
|
|
9
|
+
export type ComboRow = {
|
|
10
|
+
main: string
|
|
11
|
+
sub?: string | undefined
|
|
12
|
+
meta?: string | undefined
|
|
13
|
+
icon?: IconRef | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ComboFieldProps<T> = FieldProps & {
|
|
17
|
+
/** The app's search. Superseded calls are aborted. */
|
|
18
|
+
find: (q: string, signal: AbortSignal) => Promise<T[]>
|
|
19
|
+
row: (hit: T) => ComboRow
|
|
20
|
+
onPick: (hit: T) => unknown
|
|
21
|
+
/** The text changed: by typing, or cleared by a second Esc. */
|
|
22
|
+
onText?: (text: string) => void
|
|
23
|
+
/** The search failed or took longer than `timeout` ms. */
|
|
24
|
+
onFail?: () => void
|
|
25
|
+
text: () => string
|
|
26
|
+
minChars?: number
|
|
27
|
+
timeout?: number
|
|
28
|
+
/** Announced in the hint while there is no search running. */
|
|
29
|
+
status?: () => string | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ComboEndContext = {
|
|
33
|
+
id: string
|
|
34
|
+
label: () => string
|
|
35
|
+
rows: { readonly value: { at: number; r: ComboRow }[] }
|
|
36
|
+
active: State<number>
|
|
37
|
+
pick: (at: number) => void
|
|
38
|
+
setPop: (el: HTMLDivElement) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function comboEnd(ctx: ComboEndContext) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
ref={ctx.setPop}
|
|
45
|
+
data-scope="popover"
|
|
46
|
+
data-kind="combo"
|
|
47
|
+
data-sweep=""
|
|
48
|
+
popover="manual"
|
|
49
|
+
role="presentation"
|
|
50
|
+
onPointerDown={(e) => e.preventDefault()}
|
|
51
|
+
>
|
|
52
|
+
<span data-part="sweep" aria-hidden="true"></span>
|
|
53
|
+
<ul data-part="listbox" role="listbox" id={ctx.id} aria-label={ctx.label()}>
|
|
54
|
+
{ctx.rows.value.map(({ at, r }) => (
|
|
55
|
+
<li
|
|
56
|
+
key={`${at}:${r.main}`}
|
|
57
|
+
role="option"
|
|
58
|
+
id={`${ctx.id}-${at}`}
|
|
59
|
+
aria-selected={at === ctx.active.value ? 'true' : 'false'}
|
|
60
|
+
data-active={at === ctx.active.value ? '' : undefined}
|
|
61
|
+
onClick={() => ctx.pick(at)}
|
|
62
|
+
>
|
|
63
|
+
{r.icon && <Icon name={r.icon} />}
|
|
64
|
+
<span>
|
|
65
|
+
{r.main}
|
|
66
|
+
{r.sub && <small> {r.sub}</small>}
|
|
67
|
+
</span>
|
|
68
|
+
{r.meta && <span data-part="opt-meta">{r.meta}</span>}
|
|
69
|
+
</li>
|
|
70
|
+
))}
|
|
71
|
+
</ul>
|
|
72
|
+
</div>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type ComboOptions<T> = {
|
|
77
|
+
find: (query: string, controller: AbortController) => Promise<T[]>
|
|
78
|
+
row: () => ComboFieldProps<T>['row']
|
|
79
|
+
onPick: (hit: () => T) => unknown
|
|
80
|
+
onText: (text: string) => void
|
|
81
|
+
onFail: () => void
|
|
82
|
+
minChars: () => number
|
|
83
|
+
timeout: () => number | undefined
|
|
84
|
+
status: () => string | undefined
|
|
85
|
+
hint: () => ComboFieldProps<T>['hint']
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function comboSearch<T>({
|
|
89
|
+
opts,
|
|
90
|
+
hits,
|
|
91
|
+
active,
|
|
92
|
+
open,
|
|
93
|
+
busy,
|
|
94
|
+
}: {
|
|
95
|
+
opts: ComboOptions<T>
|
|
96
|
+
hits: State<T[]>
|
|
97
|
+
active: State<number>
|
|
98
|
+
open: State<boolean>
|
|
99
|
+
busy: State<boolean>
|
|
100
|
+
}) {
|
|
101
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
102
|
+
let stop: AbortController | undefined
|
|
103
|
+
const cancel = () => {
|
|
104
|
+
clearTimeout(timer)
|
|
105
|
+
stop?.abort()
|
|
106
|
+
stop = undefined
|
|
107
|
+
busy.value = false
|
|
108
|
+
}
|
|
109
|
+
const run = (q: string) => {
|
|
110
|
+
cancel()
|
|
111
|
+
if (q.trim().length < opts.minChars()) {
|
|
112
|
+
open.value = false
|
|
113
|
+
hits.value = []
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
// oxlint-disable-next-line typescript/no-misused-promises -- the body catches its own failure, and a sync wrapper would add a closure to a hot field
|
|
117
|
+
timer = setTimeout(async () => {
|
|
118
|
+
const me = (stop = new AbortController())
|
|
119
|
+
busy.value = true
|
|
120
|
+
const late = opts.timeout() ? setTimeout(() => me.abort(), opts.timeout()) : undefined
|
|
121
|
+
try {
|
|
122
|
+
const r = await opts.find(q, me)
|
|
123
|
+
if (me !== stop) return
|
|
124
|
+
hits.value = r
|
|
125
|
+
active.value = 0
|
|
126
|
+
open.value = r.length > 0
|
|
127
|
+
} catch {
|
|
128
|
+
if (me === stop || me.signal.aborted) {
|
|
129
|
+
open.value = false
|
|
130
|
+
opts.onFail()
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
clearTimeout(late)
|
|
134
|
+
if (me === stop) busy.value = false
|
|
135
|
+
}
|
|
136
|
+
}, 120)
|
|
137
|
+
}
|
|
138
|
+
return { cancel, run }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function comboModel<T>(opts: ComboOptions<T>) {
|
|
142
|
+
const id = uid('combo')
|
|
143
|
+
const hits = state<T[]>([])
|
|
144
|
+
const active = state(0)
|
|
145
|
+
const open = state(false)
|
|
146
|
+
const busy = state(false)
|
|
147
|
+
const rows = derived(() => hits.value.map((hit, at) => ({ at, r: untrack(opts.row)(hit) })))
|
|
148
|
+
let input: HTMLInputElement | undefined
|
|
149
|
+
let pop: HTMLDivElement | undefined
|
|
150
|
+
const { cancel, run } = comboSearch({ opts, hits, active, open, busy })
|
|
151
|
+
onCleanup(cancel)
|
|
152
|
+
use(
|
|
153
|
+
comboPopup,
|
|
154
|
+
() => pop,
|
|
155
|
+
() => ({
|
|
156
|
+
open: open.value,
|
|
157
|
+
anchor: (input?.closest('[data-part="control"]') ?? input) as HTMLElement,
|
|
158
|
+
onClose: () => (open.value = false),
|
|
159
|
+
}),
|
|
160
|
+
)
|
|
161
|
+
const pick = (at: number) => {
|
|
162
|
+
open.value = false
|
|
163
|
+
opts.onPick(() => hits.value[at]!)
|
|
164
|
+
}
|
|
165
|
+
const onKey = (e: KeyboardEvent) => {
|
|
166
|
+
const el = e.currentTarget as HTMLInputElement
|
|
167
|
+
if (e.key === 'Escape') {
|
|
168
|
+
if (e.defaultPrevented) return // an overlay took it: this popup, or the dialog around a closed one
|
|
169
|
+
e.preventDefault()
|
|
170
|
+
if (el.value) {
|
|
171
|
+
cancel()
|
|
172
|
+
opts.onText('')
|
|
173
|
+
}
|
|
174
|
+
} else if (e.key === 'ArrowDown' && !open.value) {
|
|
175
|
+
e.preventDefault()
|
|
176
|
+
run(el.value)
|
|
177
|
+
} else if (open.value && hits.value.length) {
|
|
178
|
+
const d = ({ ArrowDown: 1, ArrowUp: -1 } as Record<string, number>)[e.key]
|
|
179
|
+
if (d) {
|
|
180
|
+
e.preventDefault()
|
|
181
|
+
active.value = (active.value + d + hits.value.length) % hits.value.length
|
|
182
|
+
flush()
|
|
183
|
+
pop?.querySelector('[data-active]')?.scrollIntoView?.({ block: 'nearest' })
|
|
184
|
+
} else if (e.key === 'Enter') {
|
|
185
|
+
e.preventDefault()
|
|
186
|
+
pick(active.value)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const shownHint = derived(() => (busy.value ? 'Searching…' : (opts.status() ?? opts.hint())))
|
|
191
|
+
return [
|
|
192
|
+
id,
|
|
193
|
+
hits,
|
|
194
|
+
active,
|
|
195
|
+
open,
|
|
196
|
+
busy,
|
|
197
|
+
rows,
|
|
198
|
+
run,
|
|
199
|
+
pick,
|
|
200
|
+
onKey,
|
|
201
|
+
shownHint,
|
|
202
|
+
(n: HTMLInputElement) => (input = n),
|
|
203
|
+
(n: HTMLDivElement) => (pop = n),
|
|
204
|
+
] as const
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A text field with a list popup (04 §3, APG Combobox, list autocomplete with automatic selection): focus stays in the
|
|
209
|
+
* input. Typing `minChars` opens the list with the first result active, ↓/↑ wrap, Enter picks, Esc closes and keeps the
|
|
210
|
+
* text, a second Esc clears it, ↓ on a closed combobox searches again. Requests are debounced 120ms and aborted when
|
|
211
|
+
* superseded. Shared by PlaceLookupInput and AddressField's line 1.
|
|
212
|
+
*/
|
|
213
|
+
export function ComboField<T>({
|
|
214
|
+
find,
|
|
215
|
+
row,
|
|
216
|
+
onPick,
|
|
217
|
+
onText,
|
|
218
|
+
onFail,
|
|
219
|
+
text,
|
|
220
|
+
minChars = 2,
|
|
221
|
+
timeout,
|
|
222
|
+
status,
|
|
223
|
+
hint,
|
|
224
|
+
...rest
|
|
225
|
+
}: ComboFieldProps<T>) {
|
|
226
|
+
const [id, hits, active, open, busy, rows, run, pick, onKey, shownHint, setInput, setPop] =
|
|
227
|
+
comboModel({
|
|
228
|
+
find: (query, controller) => find(query.trim(), controller.signal),
|
|
229
|
+
row: () => row,
|
|
230
|
+
onPick: (hit) => onPick(hit()),
|
|
231
|
+
onText: (value) => onText?.(value),
|
|
232
|
+
onFail: () => onFail?.(),
|
|
233
|
+
minChars: () => minChars,
|
|
234
|
+
timeout: () => timeout,
|
|
235
|
+
status: () => status?.(),
|
|
236
|
+
hint: () => hint,
|
|
237
|
+
})
|
|
238
|
+
return (
|
|
239
|
+
<Field
|
|
240
|
+
{...rest}
|
|
241
|
+
hint={shownHint.value}
|
|
242
|
+
filled={text().length > 0}
|
|
243
|
+
hold={open.value}
|
|
244
|
+
control={(p) => (
|
|
245
|
+
<input
|
|
246
|
+
ref={setInput}
|
|
247
|
+
{...p.rest}
|
|
248
|
+
data-part="input"
|
|
249
|
+
id={p.id}
|
|
250
|
+
placeholder=" "
|
|
251
|
+
role="combobox"
|
|
252
|
+
aria-autocomplete="list"
|
|
253
|
+
aria-expanded={open.value ? 'true' : 'false'}
|
|
254
|
+
aria-controls={id}
|
|
255
|
+
aria-activedescendant={
|
|
256
|
+
open.value && hits.value.length ? `${id}-${active.value}` : undefined
|
|
257
|
+
}
|
|
258
|
+
aria-busy={busy.value ? 'true' : undefined}
|
|
259
|
+
aria-describedby={p.describedby}
|
|
260
|
+
aria-invalid={p.invalid ? 'true' : undefined}
|
|
261
|
+
autocomplete={p.rest.autocomplete ?? 'off'}
|
|
262
|
+
value={text()}
|
|
263
|
+
onInput={(e) => {
|
|
264
|
+
const v = e.currentTarget.value
|
|
265
|
+
onText?.(v)
|
|
266
|
+
run(v)
|
|
267
|
+
}}
|
|
268
|
+
onKeyDown={onKey}
|
|
269
|
+
/>
|
|
270
|
+
)}
|
|
271
|
+
end={comboEnd({
|
|
272
|
+
id,
|
|
273
|
+
label: () => rest.label,
|
|
274
|
+
rows,
|
|
275
|
+
active,
|
|
276
|
+
pick,
|
|
277
|
+
setPop,
|
|
278
|
+
})}
|
|
279
|
+
/>
|
|
280
|
+
)
|
|
281
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Per-instance palette state, search and keyboard navigation.
|
|
2
|
+
import {
|
|
3
|
+
dialog,
|
|
4
|
+
listKey,
|
|
5
|
+
moveShuttle,
|
|
6
|
+
paletteHotkey,
|
|
7
|
+
rankCommands,
|
|
8
|
+
uid,
|
|
9
|
+
} from '@kerf-js/veneer-core'
|
|
10
|
+
import { derived, flush, state, untrack, watch } from '@kerf-js/core'
|
|
11
|
+
import { bindable } from './bind'
|
|
12
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
13
|
+
import { arrange, paint, type Row } from './CommandPalette-rows'
|
|
14
|
+
import type { Command, CommandPaletteProps } from './CommandPalette'
|
|
15
|
+
|
|
16
|
+
type PaletteRefs = {
|
|
17
|
+
face?: HTMLElement | undefined
|
|
18
|
+
el?: HTMLDialogElement | undefined
|
|
19
|
+
input?: HTMLInputElement | undefined
|
|
20
|
+
list?: HTMLDivElement | undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function paletteState(props: CommandPaletteProps) {
|
|
24
|
+
const refs: PaletteRefs = {}
|
|
25
|
+
const id = uid('pal')
|
|
26
|
+
const flag = bindable<boolean>(
|
|
27
|
+
() => props.open,
|
|
28
|
+
() => props.defaultOpen,
|
|
29
|
+
false,
|
|
30
|
+
() => (o) => props.onOpenChange?.(o),
|
|
31
|
+
)
|
|
32
|
+
const typed = state('')
|
|
33
|
+
const active = state(0)
|
|
34
|
+
const rows = state<Row[]>([])
|
|
35
|
+
const size = state(0)
|
|
36
|
+
const drill = state<Command[] | undefined>(undefined)
|
|
37
|
+
// the open level's name: its row's `title`, or its label without a trailing "…"
|
|
38
|
+
const crumb = state('')
|
|
39
|
+
const mode = derived(() => props.modes?.find((m) => typed.value.startsWith(m.prefix)))
|
|
40
|
+
const items = derived(() => rows.value.flatMap((r) => (r.item ? [r.item] : [])))
|
|
41
|
+
const pending = state(false)
|
|
42
|
+
const result = derived(() => {
|
|
43
|
+
const n = items.value.length
|
|
44
|
+
return !flag.value
|
|
45
|
+
? ''
|
|
46
|
+
: n
|
|
47
|
+
? `${n} ${n === 1 ? 'command' : 'commands'}`
|
|
48
|
+
: pending.value
|
|
49
|
+
? ''
|
|
50
|
+
: 'No results'
|
|
51
|
+
})
|
|
52
|
+
return { refs, id, flag, typed, active, rows, size, drill, crumb, mode, items, pending, result }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function paletteSearch(props: CommandPaletteProps, model: ReturnType<typeof paletteState>) {
|
|
56
|
+
const { refs, size, rows, drill, active, pending } = model
|
|
57
|
+
let query: AbortController | undefined
|
|
58
|
+
let shown: Command[] = []
|
|
59
|
+
const show = (next: Command[], q: string) => {
|
|
60
|
+
shown = next
|
|
61
|
+
const arranged = arrange(next, props.groupOrder)
|
|
62
|
+
if (arranged.length > untrack(() => size.value)) size.value = arranged.length
|
|
63
|
+
rows.value = arranged
|
|
64
|
+
flush()
|
|
65
|
+
paint(refs.list, q, arranged)
|
|
66
|
+
}
|
|
67
|
+
const rank = (cmds: Command[], q: string) =>
|
|
68
|
+
rankCommands(cmds, q).flatMap((g) =>
|
|
69
|
+
g.rows.map((r) => (r.hits.length ? { ...r.item, hits: r.hits } : r.item)),
|
|
70
|
+
)
|
|
71
|
+
const answer = (value: string) => {
|
|
72
|
+
query?.abort()
|
|
73
|
+
const kids = untrack(() => drill.value)
|
|
74
|
+
if (kids) {
|
|
75
|
+
active.value = 0
|
|
76
|
+
pending.value = false
|
|
77
|
+
return show(rank(kids, value), value)
|
|
78
|
+
} // a nested level filters its own rows
|
|
79
|
+
const ctrl = (query = new AbortController())
|
|
80
|
+
const m = props.modes?.find((x) => value.startsWith(x.prefix))
|
|
81
|
+
const q = m ? value.slice(m.prefix.length) : value
|
|
82
|
+
const statics = m ? (m.commands ?? []) : (props.commands ?? [])
|
|
83
|
+
let now = rank(statics, q)
|
|
84
|
+
const late: Promise<Command[]>[] = []
|
|
85
|
+
for (const source of (m ? m.sources : props.sources) ?? []) {
|
|
86
|
+
const got = source(q, ctrl.signal)
|
|
87
|
+
if (Array.isArray(got)) now = now.concat(got)
|
|
88
|
+
else late.push(got)
|
|
89
|
+
}
|
|
90
|
+
active.value = 0
|
|
91
|
+
pending.value = late.length > 0
|
|
92
|
+
show(now, q)
|
|
93
|
+
let left = late.length
|
|
94
|
+
for (const p of late)
|
|
95
|
+
void p.then(
|
|
96
|
+
(more) => {
|
|
97
|
+
if (ctrl.signal.aborted) return
|
|
98
|
+
if (more.length)
|
|
99
|
+
show(
|
|
100
|
+
shown.concat(more.filter((c) => !shown.some((s) => s.href && s.href === c.href))),
|
|
101
|
+
q,
|
|
102
|
+
)
|
|
103
|
+
if (!--left) pending.value = false
|
|
104
|
+
},
|
|
105
|
+
() => {
|
|
106
|
+
if (!ctrl.signal.aborted && !--left) pending.value = false
|
|
107
|
+
},
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
return answer
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function paletteNavigation(
|
|
114
|
+
props: CommandPaletteProps,
|
|
115
|
+
model: ReturnType<typeof paletteState>,
|
|
116
|
+
answer: (value: string) => void,
|
|
117
|
+
) {
|
|
118
|
+
const { refs, typed, crumb, drill, items, flag, active } = model
|
|
119
|
+
// entering or leaving a level starts its search afresh: what was typed found the row, it isn't a search of its rows
|
|
120
|
+
const clear = () => {
|
|
121
|
+
if (refs.input) refs.input.value = ''
|
|
122
|
+
typed.value = ''
|
|
123
|
+
}
|
|
124
|
+
const down = (from: Command) => {
|
|
125
|
+
clear()
|
|
126
|
+
crumb.value = from.title ?? from.label.replace(/\s*(…|\.\.\.)$/, '')
|
|
127
|
+
drill.value = from.children!()
|
|
128
|
+
answer('')
|
|
129
|
+
}
|
|
130
|
+
const up = () => {
|
|
131
|
+
clear()
|
|
132
|
+
drill.value = undefined
|
|
133
|
+
crumb.value = ''
|
|
134
|
+
answer('')
|
|
135
|
+
refs.input?.focus()
|
|
136
|
+
}
|
|
137
|
+
const run = (at: number, reason: 'pointer' | 'keyboard') => {
|
|
138
|
+
const c = items.value[at]
|
|
139
|
+
if (!c) return
|
|
140
|
+
if (!c.run && c.children) return down(c)
|
|
141
|
+
flag.set(false)
|
|
142
|
+
flush()
|
|
143
|
+
// after the dialog has gone, so what the command opens takes focus from the opener
|
|
144
|
+
queueMicrotask(() => {
|
|
145
|
+
c.run?.()
|
|
146
|
+
props.onRun?.(c, reason)
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
const move = (to: number) => {
|
|
150
|
+
active.value = to
|
|
151
|
+
flush()
|
|
152
|
+
refs.el?.querySelector('[aria-selected="true"]')?.scrollIntoView?.({ block: 'nearest' })
|
|
153
|
+
}
|
|
154
|
+
return { clear, down, up, run, move }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function paletteKey(
|
|
158
|
+
model: ReturnType<typeof paletteState>,
|
|
159
|
+
navigation: ReturnType<typeof paletteNavigation>,
|
|
160
|
+
back: () => boolean,
|
|
161
|
+
) {
|
|
162
|
+
const { items, active, rows, refs, drill } = model
|
|
163
|
+
const { move, down, up, run } = navigation
|
|
164
|
+
return (e: KeyboardEvent) => {
|
|
165
|
+
if (e.isComposing) return
|
|
166
|
+
if (e.key === 'Escape') {
|
|
167
|
+
if (!e.defaultPrevented && back()) e.preventDefault()
|
|
168
|
+
return
|
|
169
|
+
} // the layer took it first
|
|
170
|
+
const count = items.value.length
|
|
171
|
+
if (!count) return
|
|
172
|
+
const at = active.value
|
|
173
|
+
if (e.key === 'Home' || e.key === 'End') {
|
|
174
|
+
e.preventDefault()
|
|
175
|
+
return move(e.key === 'Home' ? 0 : count - 1)
|
|
176
|
+
}
|
|
177
|
+
if (e.key === 'Tab') {
|
|
178
|
+
const heads = rows.value.flatMap((r, i) =>
|
|
179
|
+
r.head === undefined ? [] : [rows.value[i + 1]?.at ?? 0],
|
|
180
|
+
)
|
|
181
|
+
if (heads.length < 2) return e.preventDefault()
|
|
182
|
+
e.preventDefault()
|
|
183
|
+
const next = e.shiftKey
|
|
184
|
+
? ([...heads].reverse().find((h) => h < at) ?? heads.at(-1)!)
|
|
185
|
+
: (heads.find((h) => h > at) ?? heads[0])
|
|
186
|
+
return move(next!)
|
|
187
|
+
}
|
|
188
|
+
if (
|
|
189
|
+
e.key === 'ArrowRight' &&
|
|
190
|
+
refs.input &&
|
|
191
|
+
refs.input.selectionStart === refs.input.value.length &&
|
|
192
|
+
items.value[at]?.children
|
|
193
|
+
) {
|
|
194
|
+
e.preventDefault()
|
|
195
|
+
return down(items.value[at])
|
|
196
|
+
}
|
|
197
|
+
if (e.key === 'ArrowLeft' && drill.value && !refs.input?.selectionStart) {
|
|
198
|
+
e.preventDefault()
|
|
199
|
+
return up()
|
|
200
|
+
}
|
|
201
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
202
|
+
const href = items.value[at]?.href
|
|
203
|
+
if (href) {
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
window.open(href, '_blank', 'noopener')
|
|
206
|
+
}
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
const m = listKey(e.key, at, count, { wrap: true, typing: true, page: 5 })
|
|
210
|
+
if (!m.handled) return
|
|
211
|
+
e.preventDefault()
|
|
212
|
+
if (m.pick) return run(at, 'keyboard')
|
|
213
|
+
move(m.to)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function paletteShuttle(model: ReturnType<typeof paletteState>) {
|
|
218
|
+
const { refs, active, rows, flag } = model
|
|
219
|
+
// one highlight that travels (redesign §3): it reads the row after the render that moved it
|
|
220
|
+
watch(
|
|
221
|
+
() => [active.value, rows.value, flag.value] as const,
|
|
222
|
+
([, , on]) => {
|
|
223
|
+
requestAnimationFrame(() => {
|
|
224
|
+
if (!refs.face) return
|
|
225
|
+
if (!on) {
|
|
226
|
+
refs.face.setAttribute('data-instant', '')
|
|
227
|
+
refs.face.style.removeProperty('--veneer-a')
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
// the row, not its option: while a row's entrance runs, its translate makes it the option's offsetParent
|
|
231
|
+
const row = refs.list?.querySelector<HTMLElement>('[aria-selected="true"]')?.parentElement
|
|
232
|
+
if (row) moveShuttle(refs.face, row.offsetTop, row.offsetTop + row.offsetHeight)
|
|
233
|
+
requestAnimationFrame(() => refs.face?.removeAttribute('data-instant'))
|
|
234
|
+
})
|
|
235
|
+
},
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Creates the palette state and event handlers. */
|
|
240
|
+
export function paletteController(props: CommandPaletteProps) {
|
|
241
|
+
const model = paletteState(props)
|
|
242
|
+
const { refs, id, flag, typed, active, rows, size, drill, crumb, mode, items, pending, result } =
|
|
243
|
+
model
|
|
244
|
+
// Esc steps back before it closes: a query clears first, then an empty nested level goes up one, then the palette
|
|
245
|
+
// closes. The dialog's layer asks this first, so the step holds whether the key reached the input or the dialog.
|
|
246
|
+
const back = () => {
|
|
247
|
+
if (refs.input?.value) {
|
|
248
|
+
clear()
|
|
249
|
+
answer('')
|
|
250
|
+
return true
|
|
251
|
+
}
|
|
252
|
+
if (untrack(() => drill.value)) {
|
|
253
|
+
up()
|
|
254
|
+
return true
|
|
255
|
+
}
|
|
256
|
+
return false
|
|
257
|
+
}
|
|
258
|
+
use(
|
|
259
|
+
dialog,
|
|
260
|
+
() => refs.el,
|
|
261
|
+
() => ({ open: flag.value, onClose: () => flag.set(false), onEscape: back }),
|
|
262
|
+
)
|
|
263
|
+
if (untrack(() => (props.hotkey === undefined ? 'k' : props.hotkey)) !== false)
|
|
264
|
+
use(
|
|
265
|
+
paletteHotkey,
|
|
266
|
+
() => refs.el,
|
|
267
|
+
() => ({
|
|
268
|
+
key: String(props.hotkey === undefined ? 'k' : props.hotkey),
|
|
269
|
+
slash: props.slash,
|
|
270
|
+
onPress: () => flag.set(!untrack(() => flag.value)),
|
|
271
|
+
}),
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
const answer = paletteSearch(props, model)
|
|
275
|
+
watch(
|
|
276
|
+
() => flag.value,
|
|
277
|
+
(on) => {
|
|
278
|
+
if (!on) return
|
|
279
|
+
typed.value = ''
|
|
280
|
+
drill.value = undefined
|
|
281
|
+
crumb.value = ''
|
|
282
|
+
active.value = 0
|
|
283
|
+
if (refs.input) refs.input.value = ''
|
|
284
|
+
answer('')
|
|
285
|
+
},
|
|
286
|
+
)
|
|
287
|
+
const navigation = paletteNavigation(props, model, answer)
|
|
288
|
+
const { clear, up, run } = navigation
|
|
289
|
+
const onKey = paletteKey(model, navigation, back)
|
|
290
|
+
const onInput = (e: Event & { currentTarget: HTMLInputElement }) => {
|
|
291
|
+
typed.value = e.currentTarget.value
|
|
292
|
+
answer(e.currentTarget.value)
|
|
293
|
+
}
|
|
294
|
+
const slots = derived(() => Array.from({ length: size.value }, (_, i) => i))
|
|
295
|
+
paletteShuttle(model)
|
|
296
|
+
return {
|
|
297
|
+
refs,
|
|
298
|
+
id,
|
|
299
|
+
flag,
|
|
300
|
+
typed,
|
|
301
|
+
active,
|
|
302
|
+
rows,
|
|
303
|
+
crumb,
|
|
304
|
+
mode,
|
|
305
|
+
items,
|
|
306
|
+
pending,
|
|
307
|
+
result,
|
|
308
|
+
slots,
|
|
309
|
+
up,
|
|
310
|
+
onInput,
|
|
311
|
+
onKey,
|
|
312
|
+
run,
|
|
313
|
+
}
|
|
314
|
+
}
|