@ui-sdk/web 0.0.0-stage → 0.1.0-beta.1
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 +202 -0
- package/README.md +10 -2
- package/browser/web/accordion.js +1 -0
- package/browser/web/alert-dialog.js +1 -0
- package/browser/web/autocomplete.js +1 -0
- package/browser/web/avatar.js +1 -0
- package/browser/web/button.js +1 -0
- package/browser/web/calendar.js +1 -0
- package/browser/web/carousel.js +1 -0
- package/browser/web/checkbox.js +1 -0
- package/browser/web/chunks/0eRGibL6.js +1 -0
- package/browser/web/chunks/2bIEUO6_.js +1 -0
- package/browser/web/chunks/5A9w2ULz.js +1 -0
- package/browser/web/chunks/5RSyydjV.js +1 -0
- package/browser/web/chunks/9pWTy2wl.js +1 -0
- package/browser/web/chunks/B0f2j6zz.js +1 -0
- package/browser/web/chunks/B1rux6br.js +1 -0
- package/browser/web/chunks/B3-APaNf.js +1 -0
- package/browser/web/chunks/B7EgSgjQ.js +1 -0
- package/browser/web/chunks/B8QcOzJU.js +1 -0
- package/browser/web/chunks/BFueEkwm.js +3 -0
- package/browser/web/chunks/BJj3oS29.js +1 -0
- package/browser/web/chunks/BNSvTCpr.js +1 -0
- package/browser/web/chunks/BPD0kAZB.js +1 -0
- package/browser/web/chunks/BQeduZqT.js +1 -0
- package/browser/web/chunks/B_CVFyiz.js +1 -0
- package/browser/web/chunks/B_ns1YHO.js +1 -0
- package/browser/web/chunks/BcwkVTsR.js +1 -0
- package/browser/web/chunks/BeaQ6TYM.js +1 -0
- package/browser/web/chunks/BgBB013u.js +1 -0
- package/browser/web/chunks/BgsKhHDm.js +1 -0
- package/browser/web/chunks/BjMcbuhi.js +9 -0
- package/browser/web/chunks/Bjiy_F2N.js +1 -0
- package/browser/web/chunks/BqScCLwv.js +1 -0
- package/browser/web/chunks/BqX3Utqx.js +1 -0
- package/browser/web/chunks/BtVkQf3z.js +1 -0
- package/browser/web/chunks/By30h-7B.js +1 -0
- package/browser/web/chunks/C1zqYpy2.js +1 -0
- package/browser/web/chunks/C436juFf.js +1 -0
- package/browser/web/chunks/C4_bULs1.js +1 -0
- package/browser/web/chunks/C4omqJEz.js +1 -0
- package/browser/web/chunks/C7tt0T3n.js +1 -0
- package/browser/web/chunks/C8w7s5dg.js +1 -0
- package/browser/web/chunks/CElY4erO.js +1 -0
- package/browser/web/chunks/CFODo-m2.js +1 -0
- package/browser/web/chunks/CL4wjam9.js +1 -0
- package/browser/web/chunks/CMg-8UVf.js +1 -0
- package/browser/web/chunks/COWKfakj.js +1 -0
- package/browser/web/chunks/CQBU0qZ4.js +1 -0
- package/browser/web/chunks/CV6uABgc.js +1 -0
- package/browser/web/chunks/C_SWFpWQ.js +1 -0
- package/browser/web/chunks/C_Uanbrl.js +1 -0
- package/browser/web/chunks/Ce_CSanC.js +1 -0
- package/browser/web/chunks/Cg-ZmRhS.js +1 -0
- package/browser/web/chunks/Cgf2wPI_.js +1 -0
- package/browser/web/chunks/Cuep_3Vf.js +1 -0
- package/browser/web/chunks/D02PaHn6.js +1 -0
- package/browser/web/chunks/D5LiaI5R.js +1 -0
- package/browser/web/chunks/D9UgVYvF.js +1 -0
- package/browser/web/chunks/DC08tnkE.js +2 -0
- package/browser/web/chunks/DG8YGSvu.js +1 -0
- package/browser/web/chunks/DIQd0FYD.js +1 -0
- package/browser/web/chunks/DMLqacE8.js +1 -0
- package/browser/web/chunks/DSUI3yI-.js +1 -0
- package/browser/web/chunks/DT3Hb76X.js +1 -0
- package/browser/web/chunks/DY75g3-W.js +1 -0
- package/browser/web/chunks/DZpNQKZ9.js +1 -0
- package/browser/web/chunks/Db-W1wrC.js +1 -0
- package/browser/web/chunks/Dc1xK3Ii.js +1 -0
- package/browser/web/chunks/DdF6awFs.js +1 -0
- package/browser/web/chunks/DdaCLml8.js +1 -0
- package/browser/web/chunks/Dh8MLjQO.js +1 -0
- package/browser/web/chunks/DiuslJRy.js +1 -0
- package/browser/web/chunks/DjRcw3Y0.js +1 -0
- package/browser/web/chunks/Djdv-16J.js +1 -0
- package/browser/web/chunks/DnFXe_lF.js +1 -0
- package/browser/web/chunks/DneGv1oC.js +1 -0
- package/browser/web/chunks/DsVxP-p-.js +1 -0
- package/browser/web/chunks/DwDilCo2.js +1 -0
- package/browser/web/chunks/DwV48AXv.js +1 -0
- package/browser/web/chunks/F37aF4-L.js +1 -0
- package/browser/web/chunks/LyB6XIbN.js +1 -0
- package/browser/web/chunks/NKnbYGjC.js +1 -0
- package/browser/web/chunks/Vk-rVi16.js +1 -0
- package/browser/web/chunks/XsM0J1Ex.js +1 -0
- package/browser/web/chunks/asSN9iEp.js +1 -0
- package/browser/web/chunks/c-AjHfdF.js +1 -0
- package/browser/web/chunks/dR-12TPY.js +1 -0
- package/browser/web/chunks/hR4xM0EC.js +1 -0
- package/browser/web/chunks/hqOaBxAg.js +1 -0
- package/browser/web/chunks/kMKqqeG4.js +1 -0
- package/browser/web/chunks/kXboBcfi.js +1 -0
- package/browser/web/chunks/l4aQIg22.js +1 -0
- package/browser/web/chunks/tJC0JSU4.js +1 -0
- package/browser/web/chunks/wHdS_QYM.js +1 -0
- package/browser/web/chunks/yv8dTvNI.js +1 -0
- package/browser/web/chunks/yw9M3nfi.js +1 -0
- package/browser/web/collapsible.js +1 -0
- package/browser/web/color-picker.js +1 -0
- package/browser/web/combobox.js +2 -0
- package/browser/web/command.js +1 -0
- package/browser/web/core.js +5 -0
- package/browser/web/date-input.js +1 -0
- package/browser/web/date-picker.js +1 -0
- package/browser/web/dialog.js +1 -0
- package/browser/web/drawer.js +1 -0
- package/browser/web/field.js +1 -0
- package/browser/web/file-input.js +1 -0
- package/browser/web/hover-card.js +1 -0
- package/browser/web/image-cropper.js +1 -0
- package/browser/web/input.js +1 -0
- package/browser/web/label.js +1 -0
- package/browser/web/listbox.js +1 -0
- package/browser/web/menu.js +1 -0
- package/browser/web/menubar.js +1 -0
- package/browser/web/meter.js +1 -0
- package/browser/web/navigation-menu.js +1 -0
- package/browser/web/number-input.js +1 -0
- package/browser/web/otp-input.js +2 -0
- package/browser/web/overlays.js +1 -0
- package/browser/web/pagination.js +1 -0
- package/browser/web/password-input.js +1 -0
- package/browser/web/popover.js +1 -0
- package/browser/web/preferences.js +1 -0
- package/browser/web/progress.js +1 -0
- package/browser/web/radio.js +1 -0
- package/browser/web/rating.js +1 -0
- package/browser/web/resizable.js +1 -0
- package/browser/web/scroll-area.js +1 -0
- package/browser/web/segmented-control.js +1 -0
- package/browser/web/select.js +1 -0
- package/browser/web/separator.js +1 -0
- package/browser/web/slider.js +1 -0
- package/browser/web/switch.js +1 -0
- package/browser/web/tabs.js +1 -0
- package/browser/web/textarea.js +1 -0
- package/browser/web/time-input.js +1 -0
- package/browser/web/timeline.js +1 -0
- package/browser/web/toast.js +1 -0
- package/browser/web/toggle.js +1 -0
- package/browser/web/token-input.js +8 -0
- package/browser/web/toolbar.js +1 -0
- package/browser/web/tooltip.js +1 -0
- package/browser/web/tree.js +1 -0
- package/browser/web/trigger-menu.js +4 -0
- package/browser/web/waterfall.js +1 -0
- package/browser/web.css +3378 -0
- package/browser/web.js +3 -0
- package/custom-elements.json +32315 -0
- package/dist/accordion.d.ts +2 -0
- package/dist/accordion.js +57 -0
- package/dist/action.d.ts +16 -0
- package/dist/action.js +39 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/autocomplete.d.ts +2 -0
- package/dist/autocomplete.js +120 -0
- package/dist/autoload.d.ts +18 -0
- package/dist/autoload.js +63 -0
- package/dist/avatar.d.ts +2 -0
- package/dist/avatar.js +27 -0
- package/dist/browser-core.d.ts +2 -0
- package/dist/browser-core.js +8 -0
- package/dist/button.d.ts +2 -0
- package/dist/button.js +35 -0
- package/dist/calendar.d.ts +23 -0
- package/dist/calendar.js +429 -0
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +54 -0
- package/dist/checkbox.d.ts +4 -0
- package/dist/checkbox.js +75 -0
- package/dist/collapsible.d.ts +2 -0
- package/dist/collapsible.js +28 -0
- package/dist/color-picker.d.ts +2 -0
- package/dist/color-picker.js +64 -0
- package/dist/combobox.d.ts +2 -0
- package/dist/combobox.js +334 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +122 -0
- package/dist/date-input.d.ts +3 -0
- package/dist/date-input.js +87 -0
- package/dist/date-picker.d.ts +2 -0
- package/dist/date-picker.js +174 -0
- package/dist/default-text.d.ts +3 -0
- package/dist/default-text.js +24 -0
- package/dist/define-element.d.ts +404 -0
- package/dist/define-element.js +1489 -0
- package/dist/dialog.d.ts +3 -0
- package/dist/dialog.js +94 -0
- package/dist/drawer.d.ts +2 -0
- package/dist/drawer.js +96 -0
- package/dist/entries/accordion.d.ts +3 -0
- package/dist/entries/accordion.js +7 -0
- package/dist/entries/alert-dialog.d.ts +3 -0
- package/dist/entries/alert-dialog.js +13 -0
- package/dist/entries/autocomplete.d.ts +3 -0
- package/dist/entries/autocomplete.js +7 -0
- package/dist/entries/avatar.d.ts +2 -0
- package/dist/entries/avatar.js +3 -0
- package/dist/entries/button.d.ts +2 -0
- package/dist/entries/button.js +3 -0
- package/dist/entries/calendar.d.ts +3 -0
- package/dist/entries/calendar.js +7 -0
- package/dist/entries/carousel.d.ts +3 -0
- package/dist/entries/carousel.js +7 -0
- package/dist/entries/checkbox.d.ts +3 -0
- package/dist/entries/checkbox.js +15 -0
- package/dist/entries/collapsible.d.ts +3 -0
- package/dist/entries/collapsible.js +7 -0
- package/dist/entries/color-picker.d.ts +3 -0
- package/dist/entries/color-picker.js +7 -0
- package/dist/entries/combobox.d.ts +3 -0
- package/dist/entries/combobox.js +7 -0
- package/dist/entries/command.d.ts +3 -0
- package/dist/entries/command.js +7 -0
- package/dist/entries/date-input.d.ts +3 -0
- package/dist/entries/date-input.js +7 -0
- package/dist/entries/date-picker.d.ts +3 -0
- package/dist/entries/date-picker.js +7 -0
- package/dist/entries/dialog.d.ts +3 -0
- package/dist/entries/dialog.js +7 -0
- package/dist/entries/drawer.d.ts +3 -0
- package/dist/entries/drawer.js +8 -0
- package/dist/entries/field.d.ts +2 -0
- package/dist/entries/field.js +3 -0
- package/dist/entries/file-input.d.ts +3 -0
- package/dist/entries/file-input.js +13 -0
- package/dist/entries/hover-card.d.ts +3 -0
- package/dist/entries/hover-card.js +7 -0
- package/dist/entries/image-cropper.d.ts +3 -0
- package/dist/entries/image-cropper.js +7 -0
- package/dist/entries/input.d.ts +3 -0
- package/dist/entries/input.js +8 -0
- package/dist/entries/label.d.ts +2 -0
- package/dist/entries/label.js +3 -0
- package/dist/entries/listbox.d.ts +3 -0
- package/dist/entries/listbox.js +7 -0
- package/dist/entries/menu.d.ts +3 -0
- package/dist/entries/menu.js +7 -0
- package/dist/entries/menubar.d.ts +3 -0
- package/dist/entries/menubar.js +7 -0
- package/dist/entries/meter.d.ts +2 -0
- package/dist/entries/meter.js +3 -0
- package/dist/entries/navigation-menu.d.ts +3 -0
- package/dist/entries/navigation-menu.js +7 -0
- package/dist/entries/number-input.d.ts +3 -0
- package/dist/entries/number-input.js +7 -0
- package/dist/entries/otp-input.d.ts +3 -0
- package/dist/entries/otp-input.js +7 -0
- package/dist/entries/overlays.d.ts +2 -0
- package/dist/entries/overlays.js +3 -0
- package/dist/entries/pagination.d.ts +3 -0
- package/dist/entries/pagination.js +11 -0
- package/dist/entries/password-input.d.ts +3 -0
- package/dist/entries/password-input.js +7 -0
- package/dist/entries/popover.d.ts +3 -0
- package/dist/entries/popover.js +7 -0
- package/dist/entries/preferences.d.ts +3 -0
- package/dist/entries/preferences.js +13 -0
- package/dist/entries/progress.d.ts +2 -0
- package/dist/entries/progress.js +3 -0
- package/dist/entries/radio.d.ts +3 -0
- package/dist/entries/radio.js +7 -0
- package/dist/entries/rating.d.ts +3 -0
- package/dist/entries/rating.js +8 -0
- package/dist/entries/resizable.d.ts +3 -0
- package/dist/entries/resizable.js +11 -0
- package/dist/entries/scroll-area.d.ts +3 -0
- package/dist/entries/scroll-area.js +7 -0
- package/dist/entries/segmented-control.d.ts +3 -0
- package/dist/entries/segmented-control.js +7 -0
- package/dist/entries/select.d.ts +3 -0
- package/dist/entries/select.js +7 -0
- package/dist/entries/separator.d.ts +2 -0
- package/dist/entries/separator.js +3 -0
- package/dist/entries/slider.d.ts +3 -0
- package/dist/entries/slider.js +7 -0
- package/dist/entries/switch.d.ts +3 -0
- package/dist/entries/switch.js +7 -0
- package/dist/entries/tabs.d.ts +3 -0
- package/dist/entries/tabs.js +7 -0
- package/dist/entries/textarea.d.ts +3 -0
- package/dist/entries/textarea.js +7 -0
- package/dist/entries/time-input.d.ts +3 -0
- package/dist/entries/time-input.js +7 -0
- package/dist/entries/timeline.d.ts +3 -0
- package/dist/entries/timeline.js +7 -0
- package/dist/entries/toast.d.ts +2 -0
- package/dist/entries/toast.js +3 -0
- package/dist/entries/toggle.d.ts +3 -0
- package/dist/entries/toggle.js +12 -0
- package/dist/entries/token-input.d.ts +3 -0
- package/dist/entries/token-input.js +17 -0
- package/dist/entries/toolbar.d.ts +3 -0
- package/dist/entries/toolbar.js +7 -0
- package/dist/entries/tooltip.d.ts +3 -0
- package/dist/entries/tooltip.js +7 -0
- package/dist/entries/tree.d.ts +3 -0
- package/dist/entries/tree.js +17 -0
- package/dist/entries/trigger-menu.d.ts +3 -0
- package/dist/entries/trigger-menu.js +11 -0
- package/dist/entries/waterfall.d.ts +3 -0
- package/dist/entries/waterfall.js +11 -0
- package/dist/events.d.ts +1658 -0
- package/dist/events.js +0 -0
- package/dist/field.d.ts +2 -0
- package/dist/field.js +101 -0
- package/dist/file-input.d.ts +2 -0
- package/dist/file-input.js +140 -0
- package/dist/forward-attributes.d.ts +2 -0
- package/dist/forward-attributes.js +22 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +2 -0
- package/dist/hover-card.js +31 -0
- package/dist/image-cropper.d.ts +2 -0
- package/dist/image-cropper.js +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +269 -0
- package/dist/input.d.ts +3 -0
- package/dist/input.js +69 -0
- package/dist/label.d.ts +2 -0
- package/dist/label.js +11 -0
- package/dist/list.d.ts +40 -0
- package/dist/list.js +192 -0
- package/dist/listbox.d.ts +2 -0
- package/dist/listbox.js +84 -0
- package/dist/menu.d.ts +4 -0
- package/dist/menu.js +295 -0
- package/dist/menubar.d.ts +4 -0
- package/dist/menubar.js +30 -0
- package/dist/meter.d.ts +2 -0
- package/dist/meter.js +22 -0
- package/dist/navigation-menu.d.ts +2 -0
- package/dist/navigation-menu.js +114 -0
- package/dist/number-input.d.ts +2 -0
- package/dist/number-input.js +73 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +2 -0
- package/dist/otp-input.js +72 -0
- package/dist/overlays.d.ts +13 -0
- package/dist/overlays.js +156 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +127 -0
- package/dist/password-input.d.ts +2 -0
- package/dist/password-input.js +57 -0
- package/dist/popover.d.ts +2 -0
- package/dist/popover.js +64 -0
- package/dist/popup.d.ts +40 -0
- package/dist/popup.js +112 -0
- package/dist/preferences.d.ts +2 -0
- package/dist/preferences.js +56 -0
- package/dist/progress.d.ts +2 -0
- package/dist/progress.js +22 -0
- package/dist/radio.d.ts +2 -0
- package/dist/radio.js +33 -0
- package/dist/rating.d.ts +2 -0
- package/dist/rating.js +64 -0
- package/dist/resizable.d.ts +2 -0
- package/dist/resizable.js +42 -0
- package/dist/scroll-area.d.ts +2 -0
- package/dist/scroll-area.js +45 -0
- package/dist/segmented-control.d.ts +2 -0
- package/dist/segmented-control.js +28 -0
- package/dist/select.d.ts +2 -0
- package/dist/select.js +239 -0
- package/dist/separator.d.ts +2 -0
- package/dist/separator.js +11 -0
- package/dist/slider.d.ts +2 -0
- package/dist/slider.js +77 -0
- package/dist/tabs.d.ts +2 -0
- package/dist/tabs.js +37 -0
- package/dist/timeline.d.ts +2 -0
- package/dist/timeline.js +27 -0
- package/dist/toast.d.ts +20 -0
- package/dist/toast.js +177 -0
- package/dist/toggle.d.ts +3 -0
- package/dist/toggle.js +64 -0
- package/dist/token-input.d.ts +2 -0
- package/dist/token-input.js +103 -0
- package/dist/toolbar.d.ts +2 -0
- package/dist/toolbar.js +36 -0
- package/dist/tooltip.d.ts +2 -0
- package/dist/tooltip.js +35 -0
- package/dist/tree.d.ts +2 -0
- package/dist/tree.js +147 -0
- package/dist/trigger-menu.d.ts +2 -0
- package/dist/trigger-menu.js +133 -0
- package/dist/waterfall.d.ts +2 -0
- package/dist/waterfall.js +140 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1401 -0
- package/docs/components/alert-dialog.md +788 -0
- package/docs/components/autocomplete.md +1692 -0
- package/docs/components/avatar.md +261 -0
- package/docs/components/button.md +441 -0
- package/docs/components/calendar.md +1536 -0
- package/docs/components/carousel.md +1055 -0
- package/docs/components/checkbox.md +1045 -0
- package/docs/components/collapsible.md +535 -0
- package/docs/components/color-picker.md +651 -0
- package/docs/components/combobox.md +3274 -0
- package/docs/components/command.md +1431 -0
- package/docs/components/date-input.md +563 -0
- package/docs/components/date-picker.md +1136 -0
- package/docs/components/dialog.md +1360 -0
- package/docs/components/drawer.md +1201 -0
- package/docs/components/field.md +519 -0
- package/docs/components/file-input.md +617 -0
- package/docs/components/hover-card.md +486 -0
- package/docs/components/image-cropper.md +489 -0
- package/docs/components/input.md +327 -0
- package/docs/components/label.md +208 -0
- package/docs/components/listbox.md +1015 -0
- package/docs/components/menu.md +1212 -0
- package/docs/components/menubar.md +460 -0
- package/docs/components/meter.md +298 -0
- package/docs/components/navigation-menu.md +1573 -0
- package/docs/components/number-input.md +1087 -0
- package/docs/components/otp-input.md +558 -0
- package/docs/components/pagination.md +639 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1433 -0
- package/docs/components/preferences.md +243 -0
- package/docs/components/progress.md +406 -0
- package/docs/components/radio.md +855 -0
- package/docs/components/rating.md +431 -0
- package/docs/components/resizable.md +866 -0
- package/docs/components/scroll-area.md +898 -0
- package/docs/components/segmented-control.md +421 -0
- package/docs/components/select.md +1957 -0
- package/docs/components/separator.md +238 -0
- package/docs/components/slider.md +1018 -0
- package/docs/components/switch.md +583 -0
- package/docs/components/tabs.md +948 -0
- package/docs/components/textarea.md +331 -0
- package/docs/components/time-input.md +235 -0
- package/docs/components/timeline.md +622 -0
- package/docs/components/toast.md +1223 -0
- package/docs/components/toggle.md +522 -0
- package/docs/components/token-input.md +854 -0
- package/docs/components/toolbar.md +815 -0
- package/docs/components/tooltip.md +860 -0
- package/docs/components/tree.md +1243 -0
- package/docs/components/trigger-menu.md +1110 -0
- package/docs/components/waterfall.md +709 -0
- package/docs/controllers.md +66 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +91 -0
- package/docs/first-component.md +88 -0
- package/docs/forms.md +125 -0
- package/docs/installation.md +141 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +166 -0
- package/docs/llms.txt +1566 -0
- package/docs/parts-and-composition.md +57 -0
- package/docs/popups.md +92 -0
- package/docs/rendering.md +71 -0
- package/docs/server-rendering.md +118 -0
- package/docs/state-and-events.md +134 -0
- package/docs/styling-and-animation.md +104 -0
- package/docs/utilities/async-options.md +332 -0
- package/docs/utilities/shortcuts.md +184 -0
- package/html-custom-data.json +14792 -0
- package/package.json +302 -3
package/dist/combobox.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// src/combobox.ts
|
|
2
|
+
import {
|
|
3
|
+
combobox
|
|
4
|
+
} from "@ui-sdk/core/combobox";
|
|
5
|
+
import {
|
|
6
|
+
comboboxChips,
|
|
7
|
+
comboboxCreate,
|
|
8
|
+
comboboxItemIcons,
|
|
9
|
+
comboboxSelectAll,
|
|
10
|
+
selectAllKey
|
|
11
|
+
} from "@ui-sdk/core/renderer";
|
|
12
|
+
import { autoId, createParts, findOwner, wrappedChild } from "./define-element.js";
|
|
13
|
+
import {
|
|
14
|
+
adoptDefaultValue,
|
|
15
|
+
copy,
|
|
16
|
+
element,
|
|
17
|
+
itemText,
|
|
18
|
+
listAttribute,
|
|
19
|
+
placeItems,
|
|
20
|
+
renderListItems,
|
|
21
|
+
stashedEmpty,
|
|
22
|
+
templateOf,
|
|
23
|
+
valuesOf
|
|
24
|
+
} from "./list.js";
|
|
25
|
+
import { popupKinds, popupState, sheetInputPortal } from "./popup.js";
|
|
26
|
+
var owner = "ui-combobox";
|
|
27
|
+
var generated = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
var renderedChip = /* @__PURE__ */ new WeakSet();
|
|
29
|
+
var automaticCreate = /* @__PURE__ */ new WeakSet();
|
|
30
|
+
var automaticOverflow = /* @__PURE__ */ new WeakSet();
|
|
31
|
+
function defineComboboxElements() {
|
|
32
|
+
createParts(combobox, {
|
|
33
|
+
root: {
|
|
34
|
+
tag: owner,
|
|
35
|
+
defaults: { loop: true, dismissible: true },
|
|
36
|
+
formAssociated: true,
|
|
37
|
+
display: "contents",
|
|
38
|
+
kinds: popupKinds,
|
|
39
|
+
// A filter function is a property; the attribute takes the named modes.
|
|
40
|
+
properties: ["filter"],
|
|
41
|
+
options: (el) => {
|
|
42
|
+
const data = el;
|
|
43
|
+
const multiple = el.hasAttribute("multiple") && el.getAttribute("multiple") !== "false";
|
|
44
|
+
const start = el.getAttribute("default-value") ?? el.getAttribute("value");
|
|
45
|
+
const items = data.items;
|
|
46
|
+
const toValues = (keys) => valuesOf(keys, items, data.itemToValue);
|
|
47
|
+
return {
|
|
48
|
+
items,
|
|
49
|
+
...(typeof data.filter === "function" || data.filter === false) && {
|
|
50
|
+
filter: data.filter
|
|
51
|
+
},
|
|
52
|
+
itemToValue: data.itemToValue,
|
|
53
|
+
itemToLabel: data.itemToLabel,
|
|
54
|
+
isItemEqualToValue: data.isItemEqualToValue,
|
|
55
|
+
container: void 0,
|
|
56
|
+
...start !== null && {
|
|
57
|
+
defaultValue: multiple ? toValues(listAttribute(start)) : toValues([start])[0]
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
state: {
|
|
62
|
+
value: {
|
|
63
|
+
get: (api) => api.getValue(),
|
|
64
|
+
// A string names items by key, comma-separated with multiple.
|
|
65
|
+
set: (api, value) => {
|
|
66
|
+
if (typeof value !== "string") {
|
|
67
|
+
return api.setValue(value);
|
|
68
|
+
}
|
|
69
|
+
const keys = api.internal.options().multiple ? listAttribute(value) : [value];
|
|
70
|
+
const found = keys.map(
|
|
71
|
+
(key) => api.internal.listbox.valueOf(key) ?? key
|
|
72
|
+
);
|
|
73
|
+
api.setValue(
|
|
74
|
+
api.internal.options().multiple ? found : found[0] ?? null
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
query: {
|
|
79
|
+
get: (api) => api.getQuery(),
|
|
80
|
+
set: (api, query) => api.setQuery(query ?? "")
|
|
81
|
+
},
|
|
82
|
+
...popupState
|
|
83
|
+
},
|
|
84
|
+
api: [
|
|
85
|
+
"isOpen",
|
|
86
|
+
"setOpen",
|
|
87
|
+
"open",
|
|
88
|
+
"close",
|
|
89
|
+
"toggle",
|
|
90
|
+
"getValue",
|
|
91
|
+
"setValue",
|
|
92
|
+
"clear",
|
|
93
|
+
"getQuery",
|
|
94
|
+
"setQuery",
|
|
95
|
+
"focus"
|
|
96
|
+
],
|
|
97
|
+
// container="#id" renders the list there. As a sheet, the list sits in a
|
|
98
|
+
// viewport there and the input moves into its header.
|
|
99
|
+
portal: sheetInputPortal("ui-combobox-viewport"),
|
|
100
|
+
// Runs again whenever `items` is set.
|
|
101
|
+
render(el, { api, subscribe }) {
|
|
102
|
+
const target = el;
|
|
103
|
+
adoptDefaultValue(el, target.items, api);
|
|
104
|
+
renderChips(target, api, { force: true });
|
|
105
|
+
renderData(target, api);
|
|
106
|
+
return subscribe(() => {
|
|
107
|
+
renderChips(target, api);
|
|
108
|
+
renderData(target, api);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
label: { tag: "ui-combobox-label", display: "block" },
|
|
113
|
+
// A wrapper, so the input stays a real input.
|
|
114
|
+
input: {
|
|
115
|
+
tag: "ui-combobox-input",
|
|
116
|
+
display: "contents",
|
|
117
|
+
target: wrappedChild("input")
|
|
118
|
+
},
|
|
119
|
+
trigger: {
|
|
120
|
+
tag: "ui-combobox-trigger",
|
|
121
|
+
display: "contents",
|
|
122
|
+
target: wrappedChild("button")
|
|
123
|
+
},
|
|
124
|
+
clear: {
|
|
125
|
+
tag: "ui-combobox-clear",
|
|
126
|
+
display: "contents",
|
|
127
|
+
target: wrappedChild("button")
|
|
128
|
+
},
|
|
129
|
+
content: { tag: "ui-combobox-content", kinds: popupKinds },
|
|
130
|
+
list: { tag: "ui-combobox-list", display: "block" },
|
|
131
|
+
item: { tag: "ui-combobox-item", display: "block" },
|
|
132
|
+
"item-indicator": "ui-combobox-item-indicator",
|
|
133
|
+
// An icon inside an item. Screen readers and filtering skip it.
|
|
134
|
+
"item-icon": { tag: "ui-combobox-item-icon", feature: comboboxItemIcons },
|
|
135
|
+
// The selected item's icon, copied from its <ui-combobox-item-icon>, like next to the input.
|
|
136
|
+
"value-icon": { tag: "ui-combobox-value-icon", feature: comboboxItemIcons },
|
|
137
|
+
group: { tag: "ui-combobox-group", display: "block" },
|
|
138
|
+
"group-label": { tag: "ui-combobox-group-label", display: "block" },
|
|
139
|
+
separator: { tag: "ui-combobox-separator", display: "block" },
|
|
140
|
+
// Without content, it offers to create the text: Create “…”. Listen for `create`.
|
|
141
|
+
create: {
|
|
142
|
+
tag: "ui-combobox-create",
|
|
143
|
+
display: "block",
|
|
144
|
+
feature: comboboxCreate,
|
|
145
|
+
render(el) {
|
|
146
|
+
if (!el.childNodes.length) {
|
|
147
|
+
automaticCreate.add(el);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
kinds: { text: null },
|
|
151
|
+
context: (el) => ({
|
|
152
|
+
onCreate: (query) => created(el, query),
|
|
153
|
+
text: automaticCreate.has(el)
|
|
154
|
+
})
|
|
155
|
+
},
|
|
156
|
+
empty: { tag: "ui-combobox-empty", ...stashedEmpty },
|
|
157
|
+
status: { tag: "ui-combobox-status", display: "block" },
|
|
158
|
+
chips: {
|
|
159
|
+
tag: "ui-combobox-chips",
|
|
160
|
+
feature: comboboxChips,
|
|
161
|
+
display: "block"
|
|
162
|
+
},
|
|
163
|
+
chip: { tag: "ui-combobox-chip", feature: comboboxChips, display: "block" },
|
|
164
|
+
// "+2 more" once chips don't fit on the chips' line. Rendering it turns collapsing on.
|
|
165
|
+
"chips-overflow": {
|
|
166
|
+
tag: "ui-combobox-chips-overflow",
|
|
167
|
+
feature: comboboxChips,
|
|
168
|
+
render(el) {
|
|
169
|
+
if (!el.childNodes.length) {
|
|
170
|
+
automaticOverflow.add(el);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
context: (el) => ({ text: automaticOverflow.has(el) }),
|
|
174
|
+
kinds: { text: null }
|
|
175
|
+
},
|
|
176
|
+
// Its text, with what the input's text matched in <mark>. It holds text only.
|
|
177
|
+
"item-text": { tag: "ui-combobox-item-text", ...itemText },
|
|
178
|
+
// Selects every item that matches, in its <ui-combobox-group> or in the whole list.
|
|
179
|
+
"select-all": {
|
|
180
|
+
tag: "ui-combobox-select-all",
|
|
181
|
+
display: "block",
|
|
182
|
+
feature: comboboxSelectAll,
|
|
183
|
+
context: (el) => {
|
|
184
|
+
const group = el.closest("ui-combobox-group");
|
|
185
|
+
return { id: selectAllKey(group ? autoId(group) : void 0) };
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"chip-remove": {
|
|
189
|
+
tag: "ui-combobox-chip-remove",
|
|
190
|
+
feature: comboboxChips,
|
|
191
|
+
display: "contents",
|
|
192
|
+
target: wrappedChild("button"),
|
|
193
|
+
context: (el) => ({
|
|
194
|
+
value: el.closest("ui-combobox-chip")?.getAttribute("value") ?? ""
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
arrow: { tag: "ui-combobox-arrow", display: "block" }
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function created(el, query) {
|
|
201
|
+
let pending;
|
|
202
|
+
(findOwner(el, owner) ?? el).dispatchEvent(
|
|
203
|
+
new CustomEvent("create", {
|
|
204
|
+
composed: true,
|
|
205
|
+
detail: {
|
|
206
|
+
value: query,
|
|
207
|
+
waitUntil: (promise) => pending = promise
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
return pending;
|
|
212
|
+
}
|
|
213
|
+
var renderedChips = /* @__PURE__ */ new WeakMap();
|
|
214
|
+
function renderChips(el, api, { force = false, settled = false } = {}) {
|
|
215
|
+
const chips = el.querySelector("ui-combobox-chips");
|
|
216
|
+
if (!chips) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const all = Array.from(
|
|
220
|
+
chips.querySelectorAll("ui-combobox-chip")
|
|
221
|
+
);
|
|
222
|
+
if (all.some((chip) => !renderedChip.has(chip))) {
|
|
223
|
+
for (const chip of all) {
|
|
224
|
+
if (renderedChip.has(chip)) {
|
|
225
|
+
chip.remove();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
renderedChips.delete(chips);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const children = all.filter((chip) => chip.parentElement === chips);
|
|
232
|
+
const value = api.getValue();
|
|
233
|
+
const { selection } = api.internal;
|
|
234
|
+
const values = selection.values();
|
|
235
|
+
const labels = values.map((selected) => api.internal.labelOf(selected));
|
|
236
|
+
const last = renderedChips.get(chips);
|
|
237
|
+
const joined = labels.join("\n");
|
|
238
|
+
if (!force && last && last.value === value && last.labels === joined) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const keys = selection.keys();
|
|
242
|
+
const kept = new Set(keys);
|
|
243
|
+
const existing = new Map(
|
|
244
|
+
children.map((chip) => [chip.getAttribute("value"), chip])
|
|
245
|
+
);
|
|
246
|
+
if (!settled && keys.some((key) => !existing.has(key))) {
|
|
247
|
+
return void queueMicrotask(
|
|
248
|
+
() => renderChips(el, api, { force, settled: true })
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
renderedChips.set(chips, { value, labels: joined });
|
|
252
|
+
for (const [key, chip] of existing) {
|
|
253
|
+
if (!kept.has(key ?? "")) {
|
|
254
|
+
chip.remove();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const input = chips.querySelector(":scope > ui-combobox-chips-overflow") ?? chips.querySelector("ui-combobox-input");
|
|
258
|
+
for (const [index, key] of keys.entries()) {
|
|
259
|
+
let chip = existing.get(key);
|
|
260
|
+
if (!chip) {
|
|
261
|
+
chip = copy(templateOf(el), "ui-combobox-chip");
|
|
262
|
+
renderedChip.add(chip);
|
|
263
|
+
chip.setAttribute("value", key);
|
|
264
|
+
if (!chip.querySelector(":scope > ui-combobox-chip-remove")) {
|
|
265
|
+
const remove = element("ui-combobox-chip-remove");
|
|
266
|
+
remove.append(element("button", { type: "button" }, "\xD7"));
|
|
267
|
+
chip.append(remove);
|
|
268
|
+
}
|
|
269
|
+
chip.prepend(document.createTextNode(""));
|
|
270
|
+
}
|
|
271
|
+
const label = labels[index];
|
|
272
|
+
const text = chip.firstChild;
|
|
273
|
+
if (text?.nodeType === Node.TEXT_NODE && text.textContent !== label) {
|
|
274
|
+
text.textContent = label;
|
|
275
|
+
}
|
|
276
|
+
chip.querySelector(":scope > ui-combobox-chip-remove > button")?.setAttribute("aria-label", `Remove ${label}`);
|
|
277
|
+
chips.insertBefore(chip, input);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
var generatedItems = /* @__PURE__ */ new WeakSet();
|
|
281
|
+
var markupLists = /* @__PURE__ */ new WeakMap();
|
|
282
|
+
var rendered = /* @__PURE__ */ new WeakMap();
|
|
283
|
+
function renderData(el, api) {
|
|
284
|
+
const { items } = el;
|
|
285
|
+
const content = generated.get(el);
|
|
286
|
+
if (!items) {
|
|
287
|
+
content?.remove();
|
|
288
|
+
generated.delete(el);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const visible = api.internal.listbox.visibleData()?.list ?? items;
|
|
292
|
+
const toKey = api.internal.keyOf;
|
|
293
|
+
const markup = [...el.querySelectorAll("ui-combobox-content")].find(
|
|
294
|
+
(found) => found !== content && found.closest("ui-combobox") === el
|
|
295
|
+
);
|
|
296
|
+
if (markup && !markupLists.has(el)) {
|
|
297
|
+
markupLists.set(el, markup.querySelector("ui-combobox-list"));
|
|
298
|
+
}
|
|
299
|
+
const list = markupLists.has(el) ? markupLists.get(el) ?? null : content?.querySelector("ui-combobox-list") ?? null;
|
|
300
|
+
if (markupLists.has(el) && !list) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (list) {
|
|
304
|
+
if (!markup && !content && !list.isConnected) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const own = Array.from(list.children).some(
|
|
308
|
+
(child) => child.localName === "ui-combobox-item" && !generatedItems.has(child)
|
|
309
|
+
);
|
|
310
|
+
if (own || rendered.get(list) === visible) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
rendered.set(list, visible);
|
|
314
|
+
const fresh2 = renderListItems("ui-combobox", visible, toKey, templateOf(el));
|
|
315
|
+
fresh2.forEach((item) => generatedItems.add(item));
|
|
316
|
+
placeItems(
|
|
317
|
+
list,
|
|
318
|
+
fresh2,
|
|
319
|
+
(child) => generatedItems.has(child),
|
|
320
|
+
"ui-combobox-select-all"
|
|
321
|
+
);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const template = templateOf(el);
|
|
325
|
+
const created2 = copy(template, "ui-combobox-content", false);
|
|
326
|
+
const fresh = copy(template, "ui-combobox-list", false);
|
|
327
|
+
created2.append(fresh);
|
|
328
|
+
generated.set(el, created2);
|
|
329
|
+
el.append(created2);
|
|
330
|
+
renderData(el, api);
|
|
331
|
+
}
|
|
332
|
+
export {
|
|
333
|
+
defineComboboxElements
|
|
334
|
+
};
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/command.ts
|
|
2
|
+
import {
|
|
3
|
+
command
|
|
4
|
+
} from "@ui-sdk/core/command";
|
|
5
|
+
import { pageItems } from "@ui-sdk/core/renderer";
|
|
6
|
+
import { createParts, wrappedChild } from "./define-element.js";
|
|
7
|
+
import {
|
|
8
|
+
copy,
|
|
9
|
+
isGenerated,
|
|
10
|
+
itemText,
|
|
11
|
+
listAttribute,
|
|
12
|
+
renderData,
|
|
13
|
+
stashedEmpty,
|
|
14
|
+
templateOf
|
|
15
|
+
} from "./list.js";
|
|
16
|
+
function defineCommandElements() {
|
|
17
|
+
createParts(command, {
|
|
18
|
+
root: {
|
|
19
|
+
tag: "ui-command",
|
|
20
|
+
display: "block",
|
|
21
|
+
defaults: { autoHighlight: true, loop: true },
|
|
22
|
+
// A filter function is a property; the attribute takes the named modes.
|
|
23
|
+
properties: ["filter"],
|
|
24
|
+
options: (el) => {
|
|
25
|
+
const data = el;
|
|
26
|
+
return {
|
|
27
|
+
items: data.items,
|
|
28
|
+
...(typeof data.filter === "function" || data.filter === false) && {
|
|
29
|
+
filter: data.filter
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
state: {
|
|
34
|
+
value: {
|
|
35
|
+
get: (api) => api.getValue(),
|
|
36
|
+
set: (api, value) => api.setValue(value || null)
|
|
37
|
+
},
|
|
38
|
+
query: {
|
|
39
|
+
get: (api) => api.getQuery(),
|
|
40
|
+
set: (api, query) => api.setQuery(query ?? "")
|
|
41
|
+
},
|
|
42
|
+
pages: {
|
|
43
|
+
get: (api) => api.getPages(),
|
|
44
|
+
set: (api, pages) => api.setPages(
|
|
45
|
+
typeof pages === "string" ? listAttribute(pages) : pages ?? []
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
api: [
|
|
50
|
+
"getValue",
|
|
51
|
+
"setValue",
|
|
52
|
+
"getQuery",
|
|
53
|
+
"setQuery",
|
|
54
|
+
"getPages",
|
|
55
|
+
"setPages",
|
|
56
|
+
"push",
|
|
57
|
+
"pop",
|
|
58
|
+
"run",
|
|
59
|
+
"focus"
|
|
60
|
+
],
|
|
61
|
+
// Runs again whenever `items` is set. Data commands follow the text and the page.
|
|
62
|
+
render(el, instance) {
|
|
63
|
+
const target = el;
|
|
64
|
+
renderCommands(target, instance.api);
|
|
65
|
+
return instance.subscribe(() => renderCommands(target, instance.api));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
// A wrapper, so the field stays a real input.
|
|
69
|
+
input: {
|
|
70
|
+
tag: "ui-command-input",
|
|
71
|
+
display: "contents",
|
|
72
|
+
target: wrappedChild("input")
|
|
73
|
+
},
|
|
74
|
+
list: { tag: "ui-command-list", display: "block" },
|
|
75
|
+
// Its text, with what the search matched in <mark>. It holds text only.
|
|
76
|
+
"item-text": { tag: "ui-command-item-text", ...itemText },
|
|
77
|
+
item: {
|
|
78
|
+
tag: "ui-command-item",
|
|
79
|
+
display: "block",
|
|
80
|
+
// Whether it came from `items`, and the page it's on: null on a page
|
|
81
|
+
// without a value, the first one.
|
|
82
|
+
context: (el) => {
|
|
83
|
+
const page = el.closest("ui-command-page");
|
|
84
|
+
return {
|
|
85
|
+
data: isGenerated(el),
|
|
86
|
+
...page && { inPage: page.getAttribute("value") }
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
kinds: { data: null, inPage: null }
|
|
90
|
+
},
|
|
91
|
+
shortcut: {
|
|
92
|
+
tag: "ui-command-shortcut",
|
|
93
|
+
// Its own `shortcut`, else its command's.
|
|
94
|
+
kinds: { shortcut: { kind: "string", from: "item" } }
|
|
95
|
+
},
|
|
96
|
+
// A wrapper that doesn't split the list for assistive technology.
|
|
97
|
+
page: { tag: "ui-command-page", display: "contents" },
|
|
98
|
+
// An icon inside a command. Screen readers and filtering skip it.
|
|
99
|
+
"item-icon": "ui-command-item-icon",
|
|
100
|
+
group: { tag: "ui-command-group", display: "block" },
|
|
101
|
+
"group-label": { tag: "ui-command-group-label", display: "block" },
|
|
102
|
+
separator: { tag: "ui-command-separator", display: "block" },
|
|
103
|
+
empty: { tag: "ui-command-empty", ...stashedEmpty },
|
|
104
|
+
status: { tag: "ui-command-status", display: "block" }
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function renderCommands(el, api) {
|
|
108
|
+
if (!el.items) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const template = templateOf(el);
|
|
112
|
+
let list = el.querySelector(":scope > ui-command-list");
|
|
113
|
+
if (!list) {
|
|
114
|
+
list = copy(template, "ui-command-list", false);
|
|
115
|
+
el.append(list);
|
|
116
|
+
}
|
|
117
|
+
const visible = api.internal.listbox.visibleData()?.list ?? pageItems(el.items, api.getPages()) ?? [];
|
|
118
|
+
renderData(list, "ui-command", visible, template);
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
defineCommandElements
|
|
122
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/date-input.ts
|
|
2
|
+
import {
|
|
3
|
+
dateInput
|
|
4
|
+
} from "@ui-sdk/core/date-input";
|
|
5
|
+
import { partState } from "@ui-sdk/core/renderer";
|
|
6
|
+
import { timeInput } from "@ui-sdk/core/time-input";
|
|
7
|
+
import { createParts } from "./define-element.js";
|
|
8
|
+
import { copy } from "./list.js";
|
|
9
|
+
var rendered = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function renderSegments(el, instance, tag) {
|
|
11
|
+
const { segments } = partState(instance.part("root", {}));
|
|
12
|
+
const signature = segments.map(
|
|
13
|
+
(segment) => segment.editable ? segment.key : `${segment.key}:${segment.text}`
|
|
14
|
+
).join("|");
|
|
15
|
+
if (rendered.get(el) === signature) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
rendered.set(el, signature);
|
|
19
|
+
const template = el.querySelector(":scope > template");
|
|
20
|
+
for (const child of Array.from(
|
|
21
|
+
el.querySelectorAll(`:scope > ${tag}-segment`)
|
|
22
|
+
)) {
|
|
23
|
+
child.remove();
|
|
24
|
+
}
|
|
25
|
+
for (const segment of segments) {
|
|
26
|
+
const part = copy(template, `${tag}-segment`);
|
|
27
|
+
part.setAttribute("segment", segment.key);
|
|
28
|
+
if (!segment.editable) {
|
|
29
|
+
part.textContent = segment.text;
|
|
30
|
+
} else if (!part.querySelector("input")) {
|
|
31
|
+
part.append(document.createElement("input"));
|
|
32
|
+
}
|
|
33
|
+
el.append(part);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function defineSegmented(primitive, tag, dates) {
|
|
37
|
+
createParts(primitive, {
|
|
38
|
+
root: {
|
|
39
|
+
tag,
|
|
40
|
+
display: "block",
|
|
41
|
+
formAssociated: true,
|
|
42
|
+
// `unavailable` as a property takes any matcher, like `{ weekday: [0, 6] }`.
|
|
43
|
+
properties: dates ? ["unavailable"] : [],
|
|
44
|
+
state: {
|
|
45
|
+
value: {
|
|
46
|
+
get: (api) => api.getValue(),
|
|
47
|
+
set: (api, value) => {
|
|
48
|
+
const next = value || null;
|
|
49
|
+
if (next !== api.getValue()) {
|
|
50
|
+
api.setValue(next);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
api: ["getValue", "setValue", "clear", "focus"],
|
|
56
|
+
render(el, instance) {
|
|
57
|
+
const update = () => renderSegments(el, instance, tag);
|
|
58
|
+
update();
|
|
59
|
+
return instance.subscribe(update);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
segment: {
|
|
63
|
+
tag: `${tag}-segment`,
|
|
64
|
+
// A segment you type in binds its <input>; the text between segments is the element itself.
|
|
65
|
+
target: (el) => el.querySelector("input") ?? el,
|
|
66
|
+
context: (el) => {
|
|
67
|
+
const key = el.getAttribute("segment") ?? "";
|
|
68
|
+
return { segment: { key }, id: key };
|
|
69
|
+
},
|
|
70
|
+
rebind: ["segment"]
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function defineDateInputElements() {
|
|
75
|
+
defineSegmented(dateInput, "ui-date-input", true);
|
|
76
|
+
}
|
|
77
|
+
function defineTimeInputElements() {
|
|
78
|
+
defineSegmented(
|
|
79
|
+
timeInput,
|
|
80
|
+
"ui-time-input",
|
|
81
|
+
false
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
defineDateInputElements,
|
|
86
|
+
defineTimeInputElements
|
|
87
|
+
};
|