@hypoth-ui/cli 0.0.1 → 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 +21 -0
- package/README.md +19 -115
- package/dist/{add-PDBC4JTE.js → add-V5PW73GC.js} +29 -17
- package/dist/{chunk-5LTQ2XVL.js → chunk-27CLUUVC.js} +0 -2
- package/dist/{chunk-YPKFYE45.js → chunk-NWIRSZUQ.js} +6 -13
- package/dist/{chunk-GJ6JOQ3Q.js → chunk-PBK72SJJ.js} +1 -1
- package/dist/{diff-BQEXG7HU.js → diff-776UATCA.js} +2 -2
- package/dist/index.js +5 -5
- package/dist/{init-7AZXYAPJ.js → init-GDU2PW7K.js} +10 -13
- package/dist/{list-X6ZLM2NQ.js → list-XDP5I537.js} +3 -3
- package/package.json +16 -12
- package/registry/components.json +1820 -206
- package/templates/accordion/index.tsx +266 -0
- package/templates/accordion/wc/accordion-content.ts +113 -0
- package/templates/accordion/wc/accordion-item.ts +111 -0
- package/templates/accordion/wc/accordion-trigger.ts +105 -0
- package/templates/accordion/wc/accordion.ts +213 -0
- package/templates/accordion/wc/index.ts +12 -0
- package/templates/alert/index.tsx +177 -0
- package/templates/alert/wc/alert.ts +167 -0
- package/templates/alert/wc/index.ts +1 -0
- package/templates/alert-dialog/index.tsx +360 -0
- package/templates/alert-dialog/wc/alert-dialog-action.ts +43 -0
- package/templates/alert-dialog/wc/alert-dialog-cancel.ts +43 -0
- package/templates/alert-dialog/wc/alert-dialog-content.ts +42 -0
- package/templates/alert-dialog/wc/alert-dialog-description.ts +34 -0
- package/templates/alert-dialog/wc/alert-dialog-footer.ts +25 -0
- package/templates/alert-dialog/wc/alert-dialog-header.ts +25 -0
- package/templates/alert-dialog/wc/alert-dialog-title.ts +34 -0
- package/templates/alert-dialog/wc/alert-dialog-trigger.ts +46 -0
- package/templates/alert-dialog/wc/alert-dialog.ts +302 -0
- package/templates/alert-dialog/wc/index.ts +13 -0
- package/templates/aspect-ratio/index.tsx +50 -0
- package/templates/aspect-ratio/wc/aspect-ratio.ts +78 -0
- package/templates/aspect-ratio/wc/index.ts +5 -0
- package/templates/avatar/avatar-group.tsx +88 -0
- package/templates/avatar/avatar.tsx +124 -0
- package/templates/avatar/index.tsx +33 -0
- package/templates/avatar/wc/avatar-group.ts +112 -0
- package/templates/avatar/wc/avatar.ts +184 -0
- package/templates/avatar/wc/index.ts +5 -0
- package/templates/badge/index.tsx +140 -0
- package/templates/badge/wc/badge.ts +119 -0
- package/templates/badge/wc/index.ts +9 -0
- package/templates/breadcrumb/index.tsx +157 -0
- package/templates/breadcrumb/wc/breadcrumb-item.ts +30 -0
- package/templates/breadcrumb/wc/breadcrumb-link.ts +70 -0
- package/templates/breadcrumb/wc/breadcrumb-list.ts +30 -0
- package/templates/breadcrumb/wc/breadcrumb-page.ts +32 -0
- package/templates/breadcrumb/wc/breadcrumb-separator.ts +31 -0
- package/templates/breadcrumb/wc/breadcrumb.ts +55 -0
- package/templates/breadcrumb/wc/index.ts +10 -0
- package/templates/button/button.tsx +119 -0
- package/templates/button/index.ts +1 -0
- package/templates/button/wc/button.ts +169 -0
- package/templates/calendar/index.tsx +149 -0
- package/templates/calendar/wc/calendar.ts +316 -0
- package/templates/calendar/wc/index.ts +4 -0
- package/templates/card/index.tsx +108 -0
- package/templates/card/wc/card-content.ts +25 -0
- package/templates/card/wc/card-footer.ts +25 -0
- package/templates/card/wc/card-header.ts +25 -0
- package/templates/card/wc/card.ts +43 -0
- package/templates/card/wc/index.ts +8 -0
- package/templates/checkbox/checkbox.tsx +85 -0
- package/templates/checkbox/wc/checkbox.ts +247 -0
- package/templates/collapsible/index.tsx +172 -0
- package/templates/collapsible/wc/collapsible-content.ts +97 -0
- package/templates/collapsible/wc/collapsible-trigger.ts +39 -0
- package/templates/collapsible/wc/collapsible.ts +143 -0
- package/templates/collapsible/wc/index.ts +7 -0
- package/templates/combobox/combobox-content.tsx +141 -0
- package/templates/combobox/combobox-context.ts +36 -0
- package/templates/combobox/combobox-empty.tsx +38 -0
- package/templates/combobox/combobox-input.tsx +159 -0
- package/templates/combobox/combobox-loading.tsx +38 -0
- package/templates/combobox/combobox-option.tsx +99 -0
- package/templates/combobox/combobox-root.tsx +207 -0
- package/templates/combobox/combobox-tag.tsx +62 -0
- package/templates/combobox/index.ts +62 -0
- package/templates/combobox/wc/combobox-content.ts +97 -0
- package/templates/combobox/wc/combobox-input.ts +134 -0
- package/templates/combobox/wc/combobox-option.ts +111 -0
- package/templates/combobox/wc/combobox-tag.ts +103 -0
- package/templates/combobox/wc/combobox.ts +981 -0
- package/templates/combobox/wc/index.ts +5 -0
- package/templates/command/index.tsx +279 -0
- package/templates/command/wc/command-empty.ts +24 -0
- package/templates/command/wc/command-group.ts +60 -0
- package/templates/command/wc/command-input.ts +136 -0
- package/templates/command/wc/command-item.ts +78 -0
- package/templates/command/wc/command-list.ts +103 -0
- package/templates/command/wc/command-loading.ts +24 -0
- package/templates/command/wc/command-separator.ts +23 -0
- package/templates/command/wc/command.ts +176 -0
- package/templates/context-menu/index.tsx +262 -0
- package/templates/context-menu/wc/context-menu-content.ts +41 -0
- package/templates/context-menu/wc/context-menu-item.ts +83 -0
- package/templates/context-menu/wc/context-menu-label.ts +30 -0
- package/templates/context-menu/wc/context-menu-separator.ts +28 -0
- package/templates/context-menu/wc/context-menu.ts +324 -0
- package/templates/context-menu/wc/index.ts +9 -0
- package/templates/data-table/index.tsx +263 -0
- package/templates/data-table/wc/data-table.ts +405 -0
- package/templates/data-table/wc/index.ts +10 -0
- package/templates/date-picker/date-picker-calendar.tsx +352 -0
- package/templates/date-picker/date-picker-content.tsx +121 -0
- package/templates/date-picker/date-picker-context.ts +46 -0
- package/templates/date-picker/date-picker-root.tsx +201 -0
- package/templates/date-picker/date-picker-trigger.tsx +95 -0
- package/templates/date-picker/index.ts +44 -0
- package/templates/date-picker/wc/date-picker-calendar.ts +457 -0
- package/templates/date-picker/wc/date-picker.ts +592 -0
- package/templates/date-picker/wc/date-utils.ts +467 -0
- package/templates/date-picker/wc/index.ts +3 -0
- package/templates/dialog/dialog-close.tsx +57 -0
- package/templates/dialog/dialog-content.tsx +106 -0
- package/templates/dialog/dialog-context.ts +24 -0
- package/templates/dialog/dialog-description.tsx +51 -0
- package/templates/dialog/dialog-root.tsx +104 -0
- package/templates/dialog/dialog-title.tsx +38 -0
- package/templates/dialog/dialog-trigger.tsx +94 -0
- package/templates/dialog/index.ts +52 -0
- package/templates/dialog/wc/dialog-content.ts +59 -0
- package/templates/dialog/wc/dialog-description.ts +58 -0
- package/templates/dialog/wc/dialog-title.ts +56 -0
- package/templates/dialog/wc/dialog.ts +411 -0
- package/templates/drawer/index.tsx +263 -0
- package/templates/drawer/wc/drawer-content.ts +150 -0
- package/templates/drawer/wc/drawer-description.ts +34 -0
- package/templates/drawer/wc/drawer-footer.ts +25 -0
- package/templates/drawer/wc/drawer-header.ts +25 -0
- package/templates/drawer/wc/drawer-title.ts +34 -0
- package/templates/drawer/wc/drawer.ts +348 -0
- package/templates/drawer/wc/index.ts +10 -0
- package/templates/dropdown-menu/index.tsx +454 -0
- package/templates/dropdown-menu/wc/dropdown-menu-checkbox-item.ts +93 -0
- package/templates/dropdown-menu/wc/dropdown-menu-content.ts +43 -0
- package/templates/dropdown-menu/wc/dropdown-menu-item.ts +85 -0
- package/templates/dropdown-menu/wc/dropdown-menu-label.ts +31 -0
- package/templates/dropdown-menu/wc/dropdown-menu-radio-group.ts +80 -0
- package/templates/dropdown-menu/wc/dropdown-menu-radio-item.ts +101 -0
- package/templates/dropdown-menu/wc/dropdown-menu-separator.ts +28 -0
- package/templates/dropdown-menu/wc/dropdown-menu.ts +358 -0
- package/templates/dropdown-menu/wc/index.ts +12 -0
- package/templates/field/field-description.tsx +39 -0
- package/templates/field/field-error.tsx +37 -0
- package/templates/field/field.tsx +46 -0
- package/templates/field/index.ts +4 -0
- package/templates/field/label.tsx +40 -0
- package/templates/field/wc/field-description.ts +42 -0
- package/templates/field/wc/field-error.ts +46 -0
- package/templates/field/wc/field.ts +210 -0
- package/templates/field/wc/label.ts +54 -0
- package/templates/file-upload/file-upload-context.ts +26 -0
- package/templates/file-upload/file-upload-dropzone.tsx +111 -0
- package/templates/file-upload/file-upload-input.tsx +86 -0
- package/templates/file-upload/file-upload-item.tsx +105 -0
- package/templates/file-upload/file-upload-root.tsx +115 -0
- package/templates/file-upload/index.ts +50 -0
- package/templates/file-upload/wc/file-upload.ts +380 -0
- package/templates/file-upload/wc/index.ts +1 -0
- package/templates/hover-card/index.tsx +203 -0
- package/templates/hover-card/wc/hover-card-content.ts +50 -0
- package/templates/hover-card/wc/hover-card.ts +382 -0
- package/templates/hover-card/wc/index.ts +6 -0
- package/templates/icon/icon.tsx +76 -0
- package/templates/icon/wc/icon-adapter.ts +108 -0
- package/templates/icon/wc/icon.ts +161 -0
- package/templates/input/input.tsx +130 -0
- package/templates/input/wc/input.ts +216 -0
- package/templates/layout/app-shell.tsx +177 -0
- package/templates/layout/box.tsx +53 -0
- package/templates/layout/center.tsx +42 -0
- package/templates/layout/container.tsx +43 -0
- package/templates/layout/flow.tsx +83 -0
- package/templates/layout/grid.tsx +79 -0
- package/templates/layout/index.ts +33 -0
- package/templates/layout/inline.tsx +16 -0
- package/templates/layout/page.tsx +43 -0
- package/templates/layout/section.tsx +39 -0
- package/templates/layout/spacer.tsx +30 -0
- package/templates/layout/split.tsx +47 -0
- package/templates/layout/stack.tsx +16 -0
- package/templates/layout/wc/app-shell.ts +58 -0
- package/templates/layout/wc/box.ts +117 -0
- package/templates/layout/wc/center.ts +78 -0
- package/templates/layout/wc/container.ts +77 -0
- package/templates/layout/wc/flow.ts +149 -0
- package/templates/layout/wc/footer.ts +57 -0
- package/templates/layout/wc/grid.ts +142 -0
- package/templates/layout/wc/header.ts +57 -0
- package/templates/layout/wc/index.ts +41 -0
- package/templates/layout/wc/main.ts +46 -0
- package/templates/layout/wc/page.ts +81 -0
- package/templates/layout/wc/section.ts +65 -0
- package/templates/layout/wc/spacer.ts +77 -0
- package/templates/layout/wc/split.ts +94 -0
- package/templates/layout/wc/wrap.ts +93 -0
- package/templates/layout/wrap.tsx +46 -0
- package/templates/link/link.tsx +109 -0
- package/templates/link/wc/link.ts +124 -0
- package/templates/list/index.tsx +55 -0
- package/templates/list/list-item.tsx +117 -0
- package/templates/list/list.tsx +115 -0
- package/templates/list/wc/index.ts +5 -0
- package/templates/list/wc/list-item.ts +127 -0
- package/templates/list/wc/list.ts +114 -0
- package/templates/menu/index.ts +49 -0
- package/templates/menu/menu-content.tsx +109 -0
- package/templates/menu/menu-context.ts +17 -0
- package/templates/menu/menu-item.tsx +108 -0
- package/templates/menu/menu-label.tsx +32 -0
- package/templates/menu/menu-root.tsx +108 -0
- package/templates/menu/menu-separator.tsx +24 -0
- package/templates/menu/menu-trigger.tsx +104 -0
- package/templates/menu/wc/menu-content.ts +67 -0
- package/templates/menu/wc/menu-item.ts +109 -0
- package/templates/menu/wc/menu.ts +449 -0
- package/templates/navigation-menu/index.tsx +328 -0
- package/templates/navigation-menu/wc/index.ts +12 -0
- package/templates/navigation-menu/wc/navigation-menu-content.ts +30 -0
- package/templates/navigation-menu/wc/navigation-menu-indicator.ts +30 -0
- package/templates/navigation-menu/wc/navigation-menu-item.ts +60 -0
- package/templates/navigation-menu/wc/navigation-menu-link.ts +97 -0
- package/templates/navigation-menu/wc/navigation-menu-list.ts +30 -0
- package/templates/navigation-menu/wc/navigation-menu-trigger.ts +110 -0
- package/templates/navigation-menu/wc/navigation-menu-viewport.ts +85 -0
- package/templates/navigation-menu/wc/navigation-menu.ts +272 -0
- package/templates/number-input/index.ts +46 -0
- package/templates/number-input/number-input-context.ts +38 -0
- package/templates/number-input/number-input-decrement.tsx +53 -0
- package/templates/number-input/number-input-field.tsx +93 -0
- package/templates/number-input/number-input-increment.tsx +53 -0
- package/templates/number-input/number-input-root.tsx +137 -0
- package/templates/number-input/wc/index.ts +1 -0
- package/templates/number-input/wc/number-input.ts +283 -0
- package/templates/pagination/index.tsx +198 -0
- package/templates/pagination/wc/index.ts +11 -0
- package/templates/pagination/wc/pagination-content.ts +30 -0
- package/templates/pagination/wc/pagination-ellipsis.ts +28 -0
- package/templates/pagination/wc/pagination-item.ts +30 -0
- package/templates/pagination/wc/pagination-link.ts +76 -0
- package/templates/pagination/wc/pagination-next.ts +69 -0
- package/templates/pagination/wc/pagination-previous.ts +69 -0
- package/templates/pagination/wc/pagination.ts +156 -0
- package/templates/pin-input/index.ts +39 -0
- package/templates/pin-input/pin-input-context.ts +30 -0
- package/templates/pin-input/pin-input-field.tsx +186 -0
- package/templates/pin-input/pin-input-root.tsx +120 -0
- package/templates/pin-input/wc/index.ts +1 -0
- package/templates/pin-input/wc/pin-input.ts +259 -0
- package/templates/popover/popover.tsx +121 -0
- package/templates/popover/wc/popover-content.ts +66 -0
- package/templates/popover/wc/popover.ts +343 -0
- package/templates/progress/index.tsx +117 -0
- package/templates/progress/wc/index.ts +4 -0
- package/templates/progress/wc/progress.ts +174 -0
- package/templates/radio/radio.tsx +43 -0
- package/templates/radio/wc/radio-group.ts +261 -0
- package/templates/radio/wc/radio.ts +145 -0
- package/templates/scroll-area/index.tsx +144 -0
- package/templates/scroll-area/wc/index.ts +8 -0
- package/templates/scroll-area/wc/scroll-area-scrollbar.ts +143 -0
- package/templates/scroll-area/wc/scroll-area-thumb.ts +225 -0
- package/templates/scroll-area/wc/scroll-area-viewport.ts +120 -0
- package/templates/scroll-area/wc/scroll-area.ts +63 -0
- package/templates/select/index.ts +57 -0
- package/templates/select/select-content.tsx +243 -0
- package/templates/select/select-context.ts +30 -0
- package/templates/select/select-group.tsx +53 -0
- package/templates/select/select-label.tsx +34 -0
- package/templates/select/select-option.tsx +97 -0
- package/templates/select/select-root.tsx +153 -0
- package/templates/select/select-separator.tsx +27 -0
- package/templates/select/select-trigger.tsx +112 -0
- package/templates/select/select-value.tsx +48 -0
- package/templates/select/wc/index.ts +6 -0
- package/templates/select/wc/select-content.ts +89 -0
- package/templates/select/wc/select-group.ts +82 -0
- package/templates/select/wc/select-label.ts +49 -0
- package/templates/select/wc/select-option.ts +111 -0
- package/templates/select/wc/select-trigger.ts +101 -0
- package/templates/select/wc/select.ts +840 -0
- package/templates/separator/index.tsx +49 -0
- package/templates/separator/wc/index.ts +5 -0
- package/templates/separator/wc/separator.ts +60 -0
- package/templates/sheet/index.tsx +291 -0
- package/templates/sheet/wc/index.ts +12 -0
- package/templates/sheet/wc/sheet-close.ts +43 -0
- package/templates/sheet/wc/sheet-content.ts +47 -0
- package/templates/sheet/wc/sheet-description.ts +34 -0
- package/templates/sheet/wc/sheet-footer.ts +25 -0
- package/templates/sheet/wc/sheet-header.ts +25 -0
- package/templates/sheet/wc/sheet-overlay.ts +23 -0
- package/templates/sheet/wc/sheet-title.ts +34 -0
- package/templates/sheet/wc/sheet.ts +336 -0
- package/templates/skeleton/index.tsx +131 -0
- package/templates/skeleton/wc/index.ts +10 -0
- package/templates/skeleton/wc/skeleton.ts +107 -0
- package/templates/slider/index.ts +41 -0
- package/templates/slider/slider-context.ts +36 -0
- package/templates/slider/slider-range.tsx +59 -0
- package/templates/slider/slider-root.tsx +166 -0
- package/templates/slider/slider-thumb.tsx +213 -0
- package/templates/slider/slider-track.tsx +113 -0
- package/templates/slider/wc/index.ts +1 -0
- package/templates/slider/wc/slider.ts +465 -0
- package/templates/spinner/spinner.tsx +64 -0
- package/templates/spinner/wc/spinner.ts +70 -0
- package/templates/stepper/index.tsx +230 -0
- package/templates/stepper/wc/index.ts +12 -0
- package/templates/stepper/wc/stepper-content.ts +30 -0
- package/templates/stepper/wc/stepper-description.ts +25 -0
- package/templates/stepper/wc/stepper-indicator.ts +30 -0
- package/templates/stepper/wc/stepper-item.ts +55 -0
- package/templates/stepper/wc/stepper-separator.ts +29 -0
- package/templates/stepper/wc/stepper-title.ts +25 -0
- package/templates/stepper/wc/stepper-trigger.ts +67 -0
- package/templates/stepper/wc/stepper.ts +164 -0
- package/templates/switch/switch.tsx +90 -0
- package/templates/switch/wc/switch.ts +228 -0
- package/templates/table/body.tsx +21 -0
- package/templates/table/cell.tsx +44 -0
- package/templates/table/head.tsx +112 -0
- package/templates/table/header.tsx +21 -0
- package/templates/table/index.tsx +93 -0
- package/templates/table/root.tsx +82 -0
- package/templates/table/row.tsx +36 -0
- package/templates/table/wc/index.ts +9 -0
- package/templates/table/wc/table-body.ts +32 -0
- package/templates/table/wc/table-cell.ts +58 -0
- package/templates/table/wc/table-head.ts +129 -0
- package/templates/table/wc/table-header.ts +32 -0
- package/templates/table/wc/table-row.ts +50 -0
- package/templates/table/wc/table.ts +93 -0
- package/templates/tabs/index.tsx +222 -0
- package/templates/tabs/wc/index.ts +8 -0
- package/templates/tabs/wc/tabs-content.ts +82 -0
- package/templates/tabs/wc/tabs-list.ts +56 -0
- package/templates/tabs/wc/tabs-trigger.ts +136 -0
- package/templates/tabs/wc/tabs.ts +202 -0
- package/templates/tag/index.tsx +186 -0
- package/templates/tag/wc/index.ts +4 -0
- package/templates/tag/wc/tag.ts +166 -0
- package/templates/text/text.tsx +100 -0
- package/templates/text/wc/text.ts +94 -0
- package/templates/textarea/textarea.tsx +134 -0
- package/templates/textarea/wc/textarea.ts +280 -0
- package/templates/time-picker/index.ts +42 -0
- package/templates/time-picker/time-picker-context.ts +28 -0
- package/templates/time-picker/time-picker-root.tsx +113 -0
- package/templates/time-picker/time-picker-segment.tsx +91 -0
- package/templates/time-picker/wc/index.ts +1 -0
- package/templates/time-picker/wc/time-picker.ts +221 -0
- package/templates/toast/index.tsx +71 -0
- package/templates/toast/provider.tsx +228 -0
- package/templates/toast/toast.tsx +142 -0
- package/templates/toast/use-toast.ts +89 -0
- package/templates/toast/wc/index.ts +15 -0
- package/templates/toast/wc/toast-controller.ts +282 -0
- package/templates/toast/wc/toast-provider.ts +161 -0
- package/templates/toast/wc/toast.ts +165 -0
- package/templates/tooltip/tooltip.tsx +62 -0
- package/templates/tooltip/wc/tooltip-content.ts +64 -0
- package/templates/tooltip/wc/tooltip.ts +289 -0
- package/templates/tree/index.tsx +60 -0
- package/templates/tree/tree-item.tsx +131 -0
- package/templates/tree/tree.tsx +138 -0
- package/templates/tree/wc/index.ts +11 -0
- package/templates/tree/wc/tree-item.ts +273 -0
- package/templates/tree/wc/tree-utils.ts +143 -0
- package/templates/tree/wc/tree.ts +139 -0
- package/templates/visually-hidden/visually-hidden.tsx +45 -0
- package/templates/visually-hidden/wc/visually-hidden.ts +64 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DsCombobox } from "./combobox.js";
|
|
2
|
+
export { DsComboboxInput } from "./combobox-input.js";
|
|
3
|
+
export { DsComboboxContent, type ComboboxContentState } from "./combobox-content.js";
|
|
4
|
+
export { DsComboboxOption } from "./combobox-option.js";
|
|
5
|
+
export { DsComboboxTag } from "./combobox-tag.js";
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command palette compound component exports.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { Command } from "@/components/ui";
|
|
7
|
+
*
|
|
8
|
+
* <Command.Root onSelect={(value) => console.log(value)}>
|
|
9
|
+
* <Command.Input placeholder="Type a command..." />
|
|
10
|
+
* <Command.List>
|
|
11
|
+
* <Command.Empty>No results found.</Command.Empty>
|
|
12
|
+
* <Command.Group heading="Actions">
|
|
13
|
+
* <Command.Item value="copy">Copy</Command.Item>
|
|
14
|
+
* <Command.Item value="paste">Paste</Command.Item>
|
|
15
|
+
* </Command.Group>
|
|
16
|
+
* </Command.List>
|
|
17
|
+
* </Command.Root>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
type HTMLAttributes,
|
|
23
|
+
type ReactNode,
|
|
24
|
+
createElement,
|
|
25
|
+
forwardRef,
|
|
26
|
+
useCallback,
|
|
27
|
+
useEffect,
|
|
28
|
+
useRef,
|
|
29
|
+
useState,
|
|
30
|
+
} from "react";
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Types
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
export interface CommandRootProps extends Omit<HTMLAttributes<HTMLElement>, "onSelect"> {
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
value?: string;
|
|
39
|
+
defaultValue?: string;
|
|
40
|
+
onValueChange?: (value: string) => void;
|
|
41
|
+
onSelect?: (value: string) => void;
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
filter?: boolean;
|
|
44
|
+
label?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface CommandInputProps extends HTMLAttributes<HTMLElement> {
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
value?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface CommandListProps extends HTMLAttributes<HTMLElement> {
|
|
54
|
+
children?: ReactNode;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CommandItemProps extends Omit<HTMLAttributes<HTMLElement>, "onSelect"> {
|
|
58
|
+
children?: ReactNode;
|
|
59
|
+
value?: string;
|
|
60
|
+
keywords?: string;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
onSelect?: (value: string) => void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CommandGroupProps extends HTMLAttributes<HTMLElement> {
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
heading?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CommandSeparatorProps extends HTMLAttributes<HTMLElement> {}
|
|
71
|
+
|
|
72
|
+
export interface CommandEmptyProps extends HTMLAttributes<HTMLElement> {
|
|
73
|
+
children?: ReactNode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface CommandLoadingProps extends HTMLAttributes<HTMLElement> {
|
|
77
|
+
children?: ReactNode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Components
|
|
82
|
+
// ============================================================================
|
|
83
|
+
|
|
84
|
+
const CommandRoot = forwardRef<HTMLElement, CommandRootProps>(function CommandRoot(
|
|
85
|
+
{
|
|
86
|
+
children,
|
|
87
|
+
className,
|
|
88
|
+
value: controlledValue,
|
|
89
|
+
defaultValue = "",
|
|
90
|
+
onValueChange,
|
|
91
|
+
onSelect,
|
|
92
|
+
loading,
|
|
93
|
+
filter = true,
|
|
94
|
+
label,
|
|
95
|
+
...props
|
|
96
|
+
},
|
|
97
|
+
ref
|
|
98
|
+
) {
|
|
99
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
100
|
+
const isControlled = controlledValue !== undefined;
|
|
101
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
102
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
103
|
+
|
|
104
|
+
const combinedRef = (node: HTMLElement | null) => {
|
|
105
|
+
(elementRef as React.MutableRefObject<HTMLElement | null>).current = node;
|
|
106
|
+
if (typeof ref === "function") ref(node);
|
|
107
|
+
else if (ref) (ref as React.MutableRefObject<HTMLElement | null>).current = node;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const handleValueChange = useCallback(
|
|
111
|
+
(event: Event) => {
|
|
112
|
+
const e = event as CustomEvent<{ value: string }>;
|
|
113
|
+
if (!isControlled) setInternalValue(e.detail.value);
|
|
114
|
+
onValueChange?.(e.detail.value);
|
|
115
|
+
},
|
|
116
|
+
[isControlled, onValueChange]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const handleSelect = useCallback(
|
|
120
|
+
(event: Event) => {
|
|
121
|
+
const e = event as CustomEvent<{ value: string }>;
|
|
122
|
+
onSelect?.(e.detail.value);
|
|
123
|
+
},
|
|
124
|
+
[onSelect]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
const element = elementRef.current;
|
|
129
|
+
if (!element) return;
|
|
130
|
+
element.addEventListener("ds:value-change", handleValueChange);
|
|
131
|
+
element.addEventListener("ds:select", handleSelect);
|
|
132
|
+
return () => {
|
|
133
|
+
element.removeEventListener("ds:value-change", handleValueChange);
|
|
134
|
+
element.removeEventListener("ds:select", handleSelect);
|
|
135
|
+
};
|
|
136
|
+
}, [handleValueChange, handleSelect]);
|
|
137
|
+
|
|
138
|
+
return createElement(
|
|
139
|
+
"ds-command",
|
|
140
|
+
{
|
|
141
|
+
ref: combinedRef,
|
|
142
|
+
class: className,
|
|
143
|
+
value,
|
|
144
|
+
loading: loading || undefined,
|
|
145
|
+
filter: filter || undefined,
|
|
146
|
+
label,
|
|
147
|
+
...props,
|
|
148
|
+
},
|
|
149
|
+
children
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
CommandRoot.displayName = "Command.Root";
|
|
153
|
+
|
|
154
|
+
const CommandInput = forwardRef<HTMLElement, CommandInputProps>(function CommandInput(
|
|
155
|
+
{ className, placeholder, disabled, value, ...props },
|
|
156
|
+
ref
|
|
157
|
+
) {
|
|
158
|
+
return createElement("ds-command-input", {
|
|
159
|
+
ref,
|
|
160
|
+
class: className,
|
|
161
|
+
placeholder,
|
|
162
|
+
disabled: disabled || undefined,
|
|
163
|
+
value,
|
|
164
|
+
...props,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
CommandInput.displayName = "Command.Input";
|
|
168
|
+
|
|
169
|
+
const CommandList = forwardRef<HTMLElement, CommandListProps>(function CommandList(
|
|
170
|
+
{ children, className, ...props },
|
|
171
|
+
ref
|
|
172
|
+
) {
|
|
173
|
+
return createElement("ds-command-list", { ref, class: className, ...props }, children);
|
|
174
|
+
});
|
|
175
|
+
CommandList.displayName = "Command.List";
|
|
176
|
+
|
|
177
|
+
const CommandItem = forwardRef<HTMLElement, CommandItemProps>(function CommandItem(
|
|
178
|
+
{ children, className, value, keywords, disabled, onSelect, ...props },
|
|
179
|
+
ref
|
|
180
|
+
) {
|
|
181
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
182
|
+
|
|
183
|
+
const combinedRef = (node: HTMLElement | null) => {
|
|
184
|
+
(elementRef as React.MutableRefObject<HTMLElement | null>).current = node;
|
|
185
|
+
if (typeof ref === "function") ref(node);
|
|
186
|
+
else if (ref) (ref as React.MutableRefObject<HTMLElement | null>).current = node;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const handleSelect = useCallback(
|
|
190
|
+
(event: Event) => {
|
|
191
|
+
const e = event as CustomEvent<{ value: string }>;
|
|
192
|
+
onSelect?.(e.detail.value);
|
|
193
|
+
},
|
|
194
|
+
[onSelect]
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
const element = elementRef.current;
|
|
199
|
+
if (!element) return;
|
|
200
|
+
element.addEventListener("ds:command-select", handleSelect);
|
|
201
|
+
return () => element.removeEventListener("ds:command-select", handleSelect);
|
|
202
|
+
}, [handleSelect]);
|
|
203
|
+
|
|
204
|
+
return createElement(
|
|
205
|
+
"ds-command-item",
|
|
206
|
+
{
|
|
207
|
+
ref: combinedRef,
|
|
208
|
+
class: className,
|
|
209
|
+
value,
|
|
210
|
+
keywords,
|
|
211
|
+
disabled: disabled || undefined,
|
|
212
|
+
...props,
|
|
213
|
+
},
|
|
214
|
+
children
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
CommandItem.displayName = "Command.Item";
|
|
218
|
+
|
|
219
|
+
const CommandGroup = forwardRef<HTMLElement, CommandGroupProps>(function CommandGroup(
|
|
220
|
+
{ children, className, heading, ...props },
|
|
221
|
+
ref
|
|
222
|
+
) {
|
|
223
|
+
return createElement("ds-command-group", { ref, class: className, heading, ...props }, children);
|
|
224
|
+
});
|
|
225
|
+
CommandGroup.displayName = "Command.Group";
|
|
226
|
+
|
|
227
|
+
const CommandSeparator = forwardRef<HTMLElement, CommandSeparatorProps>(function CommandSeparator(
|
|
228
|
+
{ className, ...props },
|
|
229
|
+
ref
|
|
230
|
+
) {
|
|
231
|
+
return createElement("ds-command-separator", {
|
|
232
|
+
ref,
|
|
233
|
+
class: className,
|
|
234
|
+
...props,
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
CommandSeparator.displayName = "Command.Separator";
|
|
238
|
+
|
|
239
|
+
const CommandEmpty = forwardRef<HTMLElement, CommandEmptyProps>(function CommandEmpty(
|
|
240
|
+
{ children, className, ...props },
|
|
241
|
+
ref
|
|
242
|
+
) {
|
|
243
|
+
return createElement("ds-command-empty", { ref, class: className, ...props }, children);
|
|
244
|
+
});
|
|
245
|
+
CommandEmpty.displayName = "Command.Empty";
|
|
246
|
+
|
|
247
|
+
const CommandLoading = forwardRef<HTMLElement, CommandLoadingProps>(function CommandLoading(
|
|
248
|
+
{ children, className, ...props },
|
|
249
|
+
ref
|
|
250
|
+
) {
|
|
251
|
+
return createElement("ds-command-loading", { ref, class: className, ...props }, children);
|
|
252
|
+
});
|
|
253
|
+
CommandLoading.displayName = "Command.Loading";
|
|
254
|
+
|
|
255
|
+
// ============================================================================
|
|
256
|
+
// Compound Component
|
|
257
|
+
// ============================================================================
|
|
258
|
+
|
|
259
|
+
export const Command = {
|
|
260
|
+
Root: CommandRoot,
|
|
261
|
+
Input: CommandInput,
|
|
262
|
+
List: CommandList,
|
|
263
|
+
Item: CommandItem,
|
|
264
|
+
Group: CommandGroup,
|
|
265
|
+
Separator: CommandSeparator,
|
|
266
|
+
Empty: CommandEmpty,
|
|
267
|
+
Loading: CommandLoading,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
CommandRoot,
|
|
272
|
+
CommandInput,
|
|
273
|
+
CommandList,
|
|
274
|
+
CommandItem,
|
|
275
|
+
CommandGroup,
|
|
276
|
+
CommandSeparator,
|
|
277
|
+
CommandEmpty,
|
|
278
|
+
CommandLoading,
|
|
279
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DSElement } from "../../base/ds-element.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Command palette empty state component - shown when no results match the search.
|
|
5
|
+
*
|
|
6
|
+
* @element ds-command-empty
|
|
7
|
+
* @slot - Empty state content
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```html
|
|
11
|
+
* <ds-command-empty>
|
|
12
|
+
* No results found.
|
|
13
|
+
* </ds-command-empty>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class DsCommandEmpty extends DSElement {
|
|
17
|
+
connectedCallback(): void {
|
|
18
|
+
super.connectedCallback();
|
|
19
|
+
this.setAttribute("role", "status");
|
|
20
|
+
this.setAttribute("aria-live", "polite");
|
|
21
|
+
// Start hidden - ds-command will show when needed
|
|
22
|
+
this.setAttribute("hidden", "");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { property } from "lit/decorators.js";
|
|
2
|
+
import { DSElement } from "../../base/ds-element.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Command palette group component - groups related command items with a heading.
|
|
6
|
+
*
|
|
7
|
+
* @element ds-command-group
|
|
8
|
+
* @slot - Command items
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```html
|
|
12
|
+
* <ds-command-group heading="Actions">
|
|
13
|
+
* <ds-command-item value="copy">Copy</ds-command-item>
|
|
14
|
+
* <ds-command-item value="paste">Paste</ds-command-item>
|
|
15
|
+
* </ds-command-group>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class DsCommandGroup extends DSElement {
|
|
19
|
+
/**
|
|
20
|
+
* Heading text for the group.
|
|
21
|
+
*/
|
|
22
|
+
@property({ type: String })
|
|
23
|
+
heading = "";
|
|
24
|
+
|
|
25
|
+
private _headingEl: HTMLDivElement | null = null;
|
|
26
|
+
|
|
27
|
+
connectedCallback(): void {
|
|
28
|
+
super.connectedCallback();
|
|
29
|
+
this.setAttribute("role", "group");
|
|
30
|
+
|
|
31
|
+
if (this.heading) {
|
|
32
|
+
this._createHeading();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updated(changedProperties: Map<string, unknown>): void {
|
|
37
|
+
if (changedProperties.has("heading")) {
|
|
38
|
+
if (this.heading) {
|
|
39
|
+
this._createHeading();
|
|
40
|
+
} else if (this._headingEl) {
|
|
41
|
+
this._headingEl.remove();
|
|
42
|
+
this._headingEl = null;
|
|
43
|
+
this.removeAttribute("aria-labelledby");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private _createHeading(): void {
|
|
49
|
+
if (!this._headingEl) {
|
|
50
|
+
this._headingEl = document.createElement("div");
|
|
51
|
+
this._headingEl.className = "ds-command-group__heading";
|
|
52
|
+
this._headingEl.id = `ds-command-group-${Math.random().toString(36).slice(2, 9)}`;
|
|
53
|
+
this._headingEl.setAttribute("aria-hidden", "true");
|
|
54
|
+
this.prepend(this._headingEl);
|
|
55
|
+
this.setAttribute("aria-labelledby", this._headingEl.id);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this._headingEl.textContent = this.heading;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { property } from "lit/decorators.js";
|
|
2
|
+
import { DSElement } from "../../base/ds-element.js";
|
|
3
|
+
import { emitEvent } from "../../events/emit.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Command palette input component - search input for filtering commands.
|
|
7
|
+
*
|
|
8
|
+
* @element ds-command-input
|
|
9
|
+
*
|
|
10
|
+
* @fires ds:command-input - When the input value changes (bubbles to ds-command)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```html
|
|
14
|
+
* <ds-command-input placeholder="Type a command or search..."></ds-command-input>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class DsCommandInput extends DSElement {
|
|
18
|
+
/**
|
|
19
|
+
* Current input value.
|
|
20
|
+
*/
|
|
21
|
+
@property({ type: String })
|
|
22
|
+
value = "";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Placeholder text.
|
|
26
|
+
*/
|
|
27
|
+
@property({ type: String })
|
|
28
|
+
placeholder = "Type a command or search...";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether the input is disabled.
|
|
32
|
+
*/
|
|
33
|
+
@property({ type: Boolean, reflect: true })
|
|
34
|
+
disabled = false;
|
|
35
|
+
|
|
36
|
+
private _input: HTMLInputElement | null = null;
|
|
37
|
+
|
|
38
|
+
connectedCallback(): void {
|
|
39
|
+
super.connectedCallback();
|
|
40
|
+
this._createInput();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
disconnectedCallback(): void {
|
|
44
|
+
super.disconnectedCallback();
|
|
45
|
+
if (this._input) {
|
|
46
|
+
this._input.removeEventListener("input", this._handleInput);
|
|
47
|
+
this._input.removeEventListener("keydown", this._handleKeyDown);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private _createInput(): void {
|
|
52
|
+
// Check if input already exists (slotted)
|
|
53
|
+
let input = this.querySelector("input");
|
|
54
|
+
|
|
55
|
+
if (!input) {
|
|
56
|
+
input = document.createElement("input");
|
|
57
|
+
input.type = "text";
|
|
58
|
+
input.className = "ds-command-input__field";
|
|
59
|
+
this.appendChild(input);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this._input = input;
|
|
63
|
+
this._input.placeholder = this.placeholder;
|
|
64
|
+
this._input.disabled = this.disabled;
|
|
65
|
+
this._input.value = this.value;
|
|
66
|
+
this._input.setAttribute("role", "combobox");
|
|
67
|
+
this._input.setAttribute("aria-expanded", "true");
|
|
68
|
+
this._input.setAttribute("aria-controls", "");
|
|
69
|
+
this._input.setAttribute("aria-autocomplete", "list");
|
|
70
|
+
this._input.setAttribute("autocomplete", "off");
|
|
71
|
+
this._input.setAttribute("autocorrect", "off");
|
|
72
|
+
this._input.setAttribute("spellcheck", "false");
|
|
73
|
+
|
|
74
|
+
this._input.addEventListener("input", this._handleInput);
|
|
75
|
+
this._input.addEventListener("keydown", this._handleKeyDown);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private _handleInput = (event: Event): void => {
|
|
79
|
+
const target = event.target as HTMLInputElement;
|
|
80
|
+
this.value = target.value;
|
|
81
|
+
|
|
82
|
+
emitEvent(this, "command-input", {
|
|
83
|
+
detail: { value: this.value },
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
private _handleKeyDown = (event: KeyboardEvent): void => {
|
|
88
|
+
const command = this.closest("ds-command");
|
|
89
|
+
const list = command?.querySelector("ds-command-list") as HTMLElement | null;
|
|
90
|
+
|
|
91
|
+
switch (event.key) {
|
|
92
|
+
case "ArrowDown":
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
list?.focus();
|
|
95
|
+
break;
|
|
96
|
+
case "ArrowUp":
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
if (
|
|
99
|
+
list &&
|
|
100
|
+
"focusLast" in list &&
|
|
101
|
+
typeof (list as unknown as { focusLast: () => void }).focusLast === "function"
|
|
102
|
+
) {
|
|
103
|
+
(list as unknown as { focusLast: () => void }).focusLast();
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case "Enter": {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
const activeItem = command?.querySelector(
|
|
109
|
+
"ds-command-item[data-active]"
|
|
110
|
+
) as HTMLElement | null;
|
|
111
|
+
if (activeItem) {
|
|
112
|
+
activeItem.click();
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case "Escape":
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
emitEvent(this, "command-escape", { detail: {} });
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Focus the input.
|
|
125
|
+
*/
|
|
126
|
+
focus(): void {
|
|
127
|
+
this._input?.focus();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Blur the input.
|
|
132
|
+
*/
|
|
133
|
+
blur(): void {
|
|
134
|
+
this._input?.blur();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { property } from "lit/decorators.js";
|
|
2
|
+
import { DSElement } from "../../base/ds-element.js";
|
|
3
|
+
import { emitEvent } from "../../events/emit.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Command palette item component - selectable command/option.
|
|
7
|
+
*
|
|
8
|
+
* @element ds-command-item
|
|
9
|
+
* @slot - Item content
|
|
10
|
+
*
|
|
11
|
+
* @fires ds:command-select - When the item is selected (bubbles to ds-command)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```html
|
|
15
|
+
* <ds-command-item value="copy" keywords="duplicate clone">
|
|
16
|
+
* <ds-icon name="copy"></ds-icon>
|
|
17
|
+
* Copy
|
|
18
|
+
* </ds-command-item>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class DsCommandItem extends DSElement {
|
|
22
|
+
/**
|
|
23
|
+
* Value to emit when selected.
|
|
24
|
+
*/
|
|
25
|
+
@property({ type: String })
|
|
26
|
+
value = "";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Additional keywords for fuzzy search (space-separated).
|
|
30
|
+
*/
|
|
31
|
+
@property({ type: String })
|
|
32
|
+
keywords = "";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether the item is disabled.
|
|
36
|
+
*/
|
|
37
|
+
@property({ type: Boolean, reflect: true })
|
|
38
|
+
disabled = false;
|
|
39
|
+
|
|
40
|
+
connectedCallback(): void {
|
|
41
|
+
super.connectedCallback();
|
|
42
|
+
this.setAttribute("role", "option");
|
|
43
|
+
this.tabIndex = -1;
|
|
44
|
+
|
|
45
|
+
if (this.disabled) {
|
|
46
|
+
this.setAttribute("aria-disabled", "true");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.addEventListener("click", this._handleClick);
|
|
50
|
+
this.addEventListener("keydown", this._handleKeyDown);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
disconnectedCallback(): void {
|
|
54
|
+
super.disconnectedCallback();
|
|
55
|
+
this.removeEventListener("click", this._handleClick);
|
|
56
|
+
this.removeEventListener("keydown", this._handleKeyDown);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private _handleClick = (): void => {
|
|
60
|
+
if (this.disabled) return;
|
|
61
|
+
this._select();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
private _handleKeyDown = (event: KeyboardEvent): void => {
|
|
65
|
+
if (this.disabled) return;
|
|
66
|
+
|
|
67
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
this._select();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
private _select(): void {
|
|
74
|
+
emitEvent(this, "command-select", {
|
|
75
|
+
detail: { value: this.value || this.textContent?.trim() || "" },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createRovingFocus } from "@hypoth-ui/primitives-dom";
|
|
2
|
+
import { DSElement } from "../../base/ds-element.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Command palette list component - contains command items with keyboard navigation.
|
|
6
|
+
*
|
|
7
|
+
* @element ds-command-list
|
|
8
|
+
* @slot - Command items and groups
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```html
|
|
12
|
+
* <ds-command-list>
|
|
13
|
+
* <ds-command-item value="copy">Copy</ds-command-item>
|
|
14
|
+
* <ds-command-item value="paste">Paste</ds-command-item>
|
|
15
|
+
* </ds-command-list>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class DsCommandList extends DSElement {
|
|
19
|
+
private _rovingFocus: ReturnType<typeof createRovingFocus> | null = null;
|
|
20
|
+
private _observer: MutationObserver | null = null;
|
|
21
|
+
|
|
22
|
+
connectedCallback(): void {
|
|
23
|
+
super.connectedCallback();
|
|
24
|
+
this.setAttribute("role", "listbox");
|
|
25
|
+
this.tabIndex = -1;
|
|
26
|
+
|
|
27
|
+
this._setupRovingFocus();
|
|
28
|
+
this._setupMutationObserver();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnectedCallback(): void {
|
|
32
|
+
super.disconnectedCallback();
|
|
33
|
+
this._rovingFocus?.destroy();
|
|
34
|
+
this._observer?.disconnect();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private _setupMutationObserver(): void {
|
|
38
|
+
this._observer = new MutationObserver(() => {
|
|
39
|
+
// Re-setup roving focus when items change
|
|
40
|
+
this._rovingFocus?.destroy();
|
|
41
|
+
this._setupRovingFocus();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
this._observer.observe(this, {
|
|
45
|
+
childList: true,
|
|
46
|
+
subtree: true,
|
|
47
|
+
attributes: true,
|
|
48
|
+
attributeFilter: ["data-filtered", "disabled"],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private _setupRovingFocus(): void {
|
|
53
|
+
const items = this._getVisibleItems();
|
|
54
|
+
|
|
55
|
+
if (items.length === 0) return;
|
|
56
|
+
|
|
57
|
+
this._rovingFocus = createRovingFocus({
|
|
58
|
+
container: this,
|
|
59
|
+
selector: "ds-command-item:not([data-filtered]):not([disabled])",
|
|
60
|
+
direction: "vertical",
|
|
61
|
+
loop: true,
|
|
62
|
+
onFocus: (item: HTMLElement) => {
|
|
63
|
+
// Update active state for styling
|
|
64
|
+
this._getVisibleItems().forEach((i) => i.removeAttribute("data-active"));
|
|
65
|
+
item.setAttribute("data-active", "true");
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private _getVisibleItems(): HTMLElement[] {
|
|
71
|
+
return Array.from(
|
|
72
|
+
this.querySelectorAll("ds-command-item:not([data-filtered]):not([disabled])")
|
|
73
|
+
) as HTMLElement[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Focus the first visible item.
|
|
78
|
+
*/
|
|
79
|
+
focus(): void {
|
|
80
|
+
const items = this._getVisibleItems();
|
|
81
|
+
if (items.length > 0) {
|
|
82
|
+
const firstItem = items[0];
|
|
83
|
+
if (firstItem) {
|
|
84
|
+
firstItem.focus();
|
|
85
|
+
firstItem.setAttribute("data-active", "true");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Focus the last visible item.
|
|
92
|
+
*/
|
|
93
|
+
focusLast(): void {
|
|
94
|
+
const items = this._getVisibleItems();
|
|
95
|
+
if (items.length > 0) {
|
|
96
|
+
const lastItem = items[items.length - 1];
|
|
97
|
+
if (lastItem) {
|
|
98
|
+
lastItem.focus();
|
|
99
|
+
lastItem.setAttribute("data-active", "true");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|