@sprawlify/primitives 0.0.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/dist/anatomy.cjs +3 -0
- package/dist/anatomy.d.cts +2 -0
- package/dist/anatomy.d.mts +2 -0
- package/dist/anatomy.mjs +3 -0
- package/dist/aria-hidden-DqYx0f_y.mjs +177 -0
- package/dist/aria-hidden-DtLU6hSU.cjs +182 -0
- package/dist/aria-hidden.cjs +4 -0
- package/dist/aria-hidden.d.cts +16 -0
- package/dist/aria-hidden.d.mts +16 -0
- package/dist/aria-hidden.mjs +4 -0
- package/dist/auto-resize-D3qHtFy1.mjs +114 -0
- package/dist/auto-resize-xzlPFDyD.cjs +125 -0
- package/dist/auto-resize.cjs +5 -0
- package/dist/auto-resize.d.cts +17 -0
- package/dist/auto-resize.d.mts +17 -0
- package/dist/auto-resize.mjs +4 -0
- package/dist/chunk-CbDLau6x.cjs +34 -0
- package/dist/collection-8XqaNHs_.mjs +1279 -0
- package/dist/collection-DIoIDISa.cjs +1326 -0
- package/dist/collection.cjs +11 -0
- package/dist/collection.d.cts +5 -0
- package/dist/collection.d.mts +5 -0
- package/dist/collection.mjs +4 -0
- package/dist/color-BkAP1Tkd.d.mts +60 -0
- package/dist/color-VKewNv2e.d.cts +60 -0
- package/dist/color-utils-Cc5GVXZh.mjs +657 -0
- package/dist/color-utils-LER_6Zwu.cjs +680 -0
- package/dist/color-utils.cjs +7 -0
- package/dist/color-utils.d.cts +19 -0
- package/dist/color-utils.d.mts +19 -0
- package/dist/color-utils.mjs +4 -0
- package/dist/core-30pJjyC2.d.mts +49 -0
- package/dist/core-CQFbMdTl.cjs +176 -0
- package/dist/core-CefBjbst.d.cts +49 -0
- package/dist/core-DCFNMTZF.mjs +129 -0
- package/dist/core.cjs +12 -0
- package/dist/core.d.cts +3 -0
- package/dist/core.d.mts +3 -0
- package/dist/core.mjs +5 -0
- package/dist/create-anatomy-B3XYc-qG.d.mts +70 -0
- package/dist/create-anatomy-BGQ8pv8J.d.cts +70 -0
- package/dist/create-anatomy-BbDZbHpC.mjs +39 -0
- package/dist/create-anatomy-CDsIFUXg.cjs +45 -0
- package/dist/create-props-BnF_vl-E.mjs +5 -0
- package/dist/create-props-YKy7JIKj.cjs +11 -0
- package/dist/data-url-C3ITPVRX.d.cts +10 -0
- package/dist/data-url-DLwZ9M77.d.mts +10 -0
- package/dist/date-utils-D2xPHa_I.cjs +738 -0
- package/dist/date-utils-wEa1hhpc.mjs +474 -0
- package/dist/date-utils.cjs +46 -0
- package/dist/date-utils.d.cts +101 -0
- package/dist/date-utils.d.mts +2 -0
- package/dist/date-utils.mjs +3 -0
- package/dist/defineProperty-BoUOT9Ie.cjs +49 -0
- package/dist/defineProperty-DrXfyjd4.mjs +43 -0
- package/dist/dismissable-CTfKZ4OG.cjs +282 -0
- package/dist/dismissable-DDrx0xnH.mjs +271 -0
- package/dist/dismissable-layer-C7pZU2wi.d.cts +39 -0
- package/dist/dismissable-layer-t_b0fk-p.d.mts +39 -0
- package/dist/dismissable.cjs +7 -0
- package/dist/dismissable.d.cts +3 -0
- package/dist/dismissable.d.mts +3 -0
- package/dist/dismissable.mjs +6 -0
- package/dist/dom-query-CWZdWUGp.cjs +2141 -0
- package/dist/dom-query-DFCRhyj1.mjs +1374 -0
- package/dist/dom-query.cjs +130 -0
- package/dist/dom-query.d.cts +307 -0
- package/dist/dom-query.d.mts +307 -0
- package/dist/dom-query.mjs +3 -0
- package/dist/file-utils.cjs +220 -0
- package/dist/file-utils.d.cts +51 -0
- package/dist/file-utils.d.mts +51 -0
- package/dist/file-utils.mjs +210 -0
- package/dist/focus-trap-D-bypQEJ.mjs +485 -0
- package/dist/focus-trap-D4i52S9A.cjs +496 -0
- package/dist/focus-trap.cjs +5 -0
- package/dist/focus-trap.d.cts +88 -0
- package/dist/focus-trap.d.mts +88 -0
- package/dist/focus-trap.mjs +4 -0
- package/dist/focus-visible-DYTWdWpa.cjs +210 -0
- package/dist/focus-visible-irppYatv.mjs +175 -0
- package/dist/focus-visible.cjs +9 -0
- package/dist/focus-visible.d.cts +31 -0
- package/dist/focus-visible.d.mts +31 -0
- package/dist/focus-visible.mjs +4 -0
- package/dist/functions-BOkTDEFM.d.cts +15 -0
- package/dist/functions-IZtWcC8Q.d.mts +15 -0
- package/dist/highlight-word.cjs +100 -0
- package/dist/highlight-word.d.cts +24 -0
- package/dist/highlight-word.d.mts +24 -0
- package/dist/highlight-word.mjs +99 -0
- package/dist/hotkeys.cjs +758 -0
- package/dist/hotkeys.d.cts +130 -0
- package/dist/hotkeys.d.mts +130 -0
- package/dist/hotkeys.mjs +754 -0
- package/dist/i18n-utils.cjs +450 -0
- package/dist/i18n-utils.d.cts +61 -0
- package/dist/i18n-utils.d.mts +61 -0
- package/dist/i18n-utils.mjs +440 -0
- package/dist/index-BkzYij2j.d.mts +25 -0
- package/dist/index-Bqw3r34-.d.cts +1383 -0
- package/dist/index-C0MKXQmE.d.mts +1383 -0
- package/dist/index-C9-feK5c.d.cts +25 -0
- package/dist/index-CD5FN7kY.d.mts +114 -0
- package/dist/index-CJji6wHl.d.cts +15 -0
- package/dist/index-CNi5FkPe.d.mts +15 -0
- package/dist/index-D96rs8B0.d.mts +115 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/interact-outside-BplxR9cR.mjs +200 -0
- package/dist/interact-outside-C8-oFBpB.cjs +205 -0
- package/dist/interact-outside.cjs +5 -0
- package/dist/interact-outside.d.cts +2 -0
- package/dist/interact-outside.d.mts +2 -0
- package/dist/interact-outside.mjs +5 -0
- package/dist/json-tree-utils.cjs +1512 -0
- package/dist/json-tree-utils.d.cts +117 -0
- package/dist/json-tree-utils.d.mts +117 -0
- package/dist/json-tree-utils.mjs +1463 -0
- package/dist/list-collection-BIMJGQjn.d.cts +61 -0
- package/dist/list-collection-Db3eixRU.d.mts +61 -0
- package/dist/live-region-CcZPGo89.cjs +52 -0
- package/dist/live-region-CnPh21WH.mjs +46 -0
- package/dist/live-region.cjs +3 -0
- package/dist/live-region.d.cts +2 -0
- package/dist/live-region.d.mts +2 -0
- package/dist/live-region.mjs +3 -0
- package/dist/machines/accordion/index.cjs +328 -0
- package/dist/machines/accordion/index.d.cts +83 -0
- package/dist/machines/accordion/index.d.mts +83 -0
- package/dist/machines/accordion/index.mjs +322 -0
- package/dist/machines/async-list/index.cjs +311 -0
- package/dist/machines/async-list/index.d.cts +89 -0
- package/dist/machines/async-list/index.d.mts +89 -0
- package/dist/machines/async-list/index.mjs +310 -0
- package/dist/machines/avatar/index.cjs +169 -0
- package/dist/machines/avatar/index.d.cts +63 -0
- package/dist/machines/avatar/index.d.mts +63 -0
- package/dist/machines/avatar/index.mjs +165 -0
- package/dist/machines/bottom-sheet/index.cjs +676 -0
- package/dist/machines/bottom-sheet/index.d.cts +239 -0
- package/dist/machines/bottom-sheet/index.d.mts +239 -0
- package/dist/machines/bottom-sheet/index.mjs +672 -0
- package/dist/machines/carousel/index.cjs +859 -0
- package/dist/machines/carousel/index.d.cts +146 -0
- package/dist/machines/carousel/index.d.mts +146 -0
- package/dist/machines/carousel/index.mjs +851 -0
- package/dist/machines/checkbox/index.cjs +316 -0
- package/dist/machines/checkbox/index.d.cts +81 -0
- package/dist/machines/checkbox/index.d.mts +81 -0
- package/dist/machines/checkbox/index.mjs +312 -0
- package/dist/machines/clipboard/index.cjs +225 -0
- package/dist/machines/clipboard/index.d.cts +68 -0
- package/dist/machines/clipboard/index.d.mts +68 -0
- package/dist/machines/clipboard/index.mjs +219 -0
- package/dist/machines/collapsible/index.cjs +362 -0
- package/dist/machines/collapsible/index.d.cts +82 -0
- package/dist/machines/collapsible/index.d.mts +82 -0
- package/dist/machines/collapsible/index.mjs +358 -0
- package/dist/machines/color-picker/index.cjs +1529 -0
- package/dist/machines/color-picker/index.d.cts +205 -0
- package/dist/machines/color-picker/index.d.mts +205 -0
- package/dist/machines/color-picker/index.mjs +1514 -0
- package/dist/machines/combobox/index.cjs +1593 -0
- package/dist/machines/combobox/index.d.cts +214 -0
- package/dist/machines/combobox/index.d.mts +214 -0
- package/dist/machines/combobox/index.mjs +1582 -0
- package/dist/machines/date-picker/index.cjs +2177 -0
- package/dist/machines/date-picker/index.d.cts +350 -0
- package/dist/machines/date-picker/index.d.mts +350 -0
- package/dist/machines/date-picker/index.mjs +2161 -0
- package/dist/machines/dialog/index.cjs +325 -0
- package/dist/machines/dialog/index.d.cts +80 -0
- package/dist/machines/dialog/index.d.mts +80 -0
- package/dist/machines/dialog/index.mjs +321 -0
- package/dist/machines/editable/index.cjs +551 -0
- package/dist/machines/editable/index.d.cts +114 -0
- package/dist/machines/editable/index.d.mts +114 -0
- package/dist/machines/editable/index.mjs +547 -0
- package/dist/machines/floating-panel/index.cjs +995 -0
- package/dist/machines/floating-panel/index.d.cts +147 -0
- package/dist/machines/floating-panel/index.d.mts +147 -0
- package/dist/machines/floating-panel/index.mjs +988 -0
- package/dist/machines/hover-card/index.cjs +383 -0
- package/dist/machines/hover-card/index.d.cts +69 -0
- package/dist/machines/hover-card/index.d.mts +69 -0
- package/dist/machines/hover-card/index.mjs +379 -0
- package/dist/machines/image-cropper/index.cjs +1995 -0
- package/dist/machines/image-cropper/index.d.cts +182 -0
- package/dist/machines/image-cropper/index.d.mts +182 -0
- package/dist/machines/image-cropper/index.mjs +1990 -0
- package/dist/machines/listbox/index.cjs +794 -0
- package/dist/machines/listbox/index.d.cts +168 -0
- package/dist/machines/listbox/index.d.mts +168 -0
- package/dist/machines/listbox/index.mjs +782 -0
- package/dist/machines/marquee/index.cjs +395 -0
- package/dist/machines/marquee/index.d.cts +102 -0
- package/dist/machines/marquee/index.d.mts +102 -0
- package/dist/machines/marquee/index.mjs +391 -0
- package/dist/machines/menu/index.cjs +1298 -0
- package/dist/machines/menu/index.d.cts +175 -0
- package/dist/machines/menu/index.d.mts +175 -0
- package/dist/machines/menu/index.mjs +1286 -0
- package/dist/machines/navigation-menu/index.cjs +861 -0
- package/dist/machines/navigation-menu/index.d.cts +127 -0
- package/dist/machines/navigation-menu/index.d.mts +127 -0
- package/dist/machines/navigation-menu/index.mjs +857 -0
- package/dist/machines/number-input/index.cjs +996 -0
- package/dist/machines/number-input/index.d.cts +134 -0
- package/dist/machines/number-input/index.d.mts +134 -0
- package/dist/machines/number-input/index.mjs +991 -0
- package/dist/machines/pagination/index.cjs +419 -0
- package/dist/machines/pagination/index.d.cts +139 -0
- package/dist/machines/pagination/index.d.mts +139 -0
- package/dist/machines/pagination/index.mjs +411 -0
- package/dist/machines/password-input/index.cjs +228 -0
- package/dist/machines/password-input/index.d.cts +71 -0
- package/dist/machines/password-input/index.d.mts +71 -0
- package/dist/machines/password-input/index.mjs +224 -0
- package/dist/machines/pin-input/index.cjs +523 -0
- package/dist/machines/pin-input/index.d.cts +105 -0
- package/dist/machines/pin-input/index.d.mts +105 -0
- package/dist/machines/pin-input/index.mjs +519 -0
- package/dist/machines/popover/index.cjs +430 -0
- package/dist/machines/popover/index.d.cts +88 -0
- package/dist/machines/popover/index.d.mts +88 -0
- package/dist/machines/popover/index.mjs +426 -0
- package/dist/machines/presence/index.cjs +192 -0
- package/dist/machines/presence/index.d.cts +44 -0
- package/dist/machines/presence/index.d.mts +44 -0
- package/dist/machines/presence/index.mjs +190 -0
- package/dist/machines/progress/index.cjs +288 -0
- package/dist/machines/progress/index.d.cts +96 -0
- package/dist/machines/progress/index.d.mts +96 -0
- package/dist/machines/progress/index.mjs +284 -0
- package/dist/machines/qr-code/index.cjs +172 -0
- package/dist/machines/qr-code/index.d.cts +70 -0
- package/dist/machines/qr-code/index.d.mts +70 -0
- package/dist/machines/qr-code/index.mjs +167 -0
- package/dist/machines/radio-group/index.cjs +436 -0
- package/dist/machines/radio-group/index.d.cts +106 -0
- package/dist/machines/radio-group/index.d.mts +106 -0
- package/dist/machines/radio-group/index.mjs +430 -0
- package/dist/machines/rating-group/index.cjs +405 -0
- package/dist/machines/rating-group/index.d.cts +101 -0
- package/dist/machines/rating-group/index.d.mts +101 -0
- package/dist/machines/rating-group/index.mjs +399 -0
- package/dist/machines/scroll-area/index.cjs +857 -0
- package/dist/machines/scroll-area/index.d.cts +159 -0
- package/dist/machines/scroll-area/index.d.mts +159 -0
- package/dist/machines/scroll-area/index.mjs +853 -0
- package/dist/machines/select/index.cjs +1165 -0
- package/dist/machines/select/index.d.cts +183 -0
- package/dist/machines/select/index.d.mts +183 -0
- package/dist/machines/select/index.mjs +1154 -0
- package/dist/machines/signature-pad/index.cjs +334 -0
- package/dist/machines/signature-pad/index.d.cts +108 -0
- package/dist/machines/signature-pad/index.d.mts +108 -0
- package/dist/machines/signature-pad/index.mjs +328 -0
- package/dist/machines/slider/index.cjs +957 -0
- package/dist/machines/slider/index.d.cts +149 -0
- package/dist/machines/slider/index.d.mts +149 -0
- package/dist/machines/slider/index.mjs +949 -0
- package/dist/machines/splitter/index.cjs +1112 -0
- package/dist/machines/splitter/index.d.cts +155 -0
- package/dist/machines/splitter/index.d.mts +155 -0
- package/dist/machines/splitter/index.mjs +1103 -0
- package/dist/machines/steps/index.cjs +289 -0
- package/dist/machines/steps/index.d.cts +97 -0
- package/dist/machines/steps/index.d.mts +97 -0
- package/dist/machines/steps/index.mjs +285 -0
- package/dist/machines/switch/index.cjs +305 -0
- package/dist/machines/switch/index.d.cts +80 -0
- package/dist/machines/switch/index.d.mts +80 -0
- package/dist/machines/switch/index.mjs +301 -0
- package/dist/machines/tabs/index.cjs +508 -0
- package/dist/machines/tabs/index.d.cts +111 -0
- package/dist/machines/tabs/index.d.mts +111 -0
- package/dist/machines/tabs/index.mjs +500 -0
- package/dist/machines/tags-input/index.cjs +1127 -0
- package/dist/machines/tags-input/index.d.cts +179 -0
- package/dist/machines/tags-input/index.d.mts +179 -0
- package/dist/machines/tags-input/index.mjs +1121 -0
- package/dist/machines/timer/index.cjs +329 -0
- package/dist/machines/timer/index.d.cts +98 -0
- package/dist/machines/timer/index.d.mts +98 -0
- package/dist/machines/timer/index.mjs +324 -0
- package/dist/machines/toast/index.cjs +1155 -0
- package/dist/machines/toast/index.d.cts +195 -0
- package/dist/machines/toast/index.d.mts +195 -0
- package/dist/machines/toast/index.mjs +1151 -0
- package/dist/machines/toggle/index.cjs +103 -0
- package/dist/machines/toggle/index.d.cts +46 -0
- package/dist/machines/toggle/index.d.mts +46 -0
- package/dist/machines/toggle/index.mjs +99 -0
- package/dist/machines/toggle-group/index.cjs +328 -0
- package/dist/machines/toggle-group/index.d.cts +81 -0
- package/dist/machines/toggle-group/index.d.mts +81 -0
- package/dist/machines/toggle-group/index.mjs +322 -0
- package/dist/machines/tooltip/index.cjs +516 -0
- package/dist/machines/tooltip/index.d.cts +71 -0
- package/dist/machines/tooltip/index.d.mts +71 -0
- package/dist/machines/tooltip/index.mjs +512 -0
- package/dist/machines/tour/index.cjs +1108 -0
- package/dist/machines/tour/index.d.cts +206 -0
- package/dist/machines/tour/index.d.mts +206 -0
- package/dist/machines/tour/index.mjs +1101 -0
- package/dist/machines/tree-view/index.cjs +1271 -0
- package/dist/machines/tree-view/index.d.cts +215 -0
- package/dist/machines/tree-view/index.d.mts +215 -0
- package/dist/machines/tree-view/index.mjs +1263 -0
- package/dist/node-BctU8GXk.d.mts +24 -0
- package/dist/node-CSsuPZVZ.d.cts +24 -0
- package/dist/popper-BPJeAtcA.mjs +349 -0
- package/dist/popper-D0FAW_p7.cjs +373 -0
- package/dist/popper.cjs +8 -0
- package/dist/popper.d.cts +74 -0
- package/dist/popper.d.mts +2 -0
- package/dist/popper.mjs +5 -0
- package/dist/raf-BnlYUlDi.d.mts +15 -0
- package/dist/raf-Cd2FGy0z.d.cts +15 -0
- package/dist/rect-utils-0ellN0a_.mjs +854 -0
- package/dist/rect-utils-DKLRhP8G.cjs +1147 -0
- package/dist/rect-utils.cjs +51 -0
- package/dist/rect-utils.d.cts +198 -0
- package/dist/rect-utils.d.mts +198 -0
- package/dist/rect-utils.mjs +3 -0
- package/dist/remove-scroll-Lrfv79X_.mjs +58 -0
- package/dist/remove-scroll-Uvzg1L9r.cjs +63 -0
- package/dist/remove-scroll.cjs +0 -0
- package/dist/remove-scroll.d.cts +1 -0
- package/dist/remove-scroll.d.mts +1 -0
- package/dist/remove-scroll.mjs +1 -0
- package/dist/scroll-snap-CrTmQRzA.mjs +152 -0
- package/dist/scroll-snap-zyiZLv7W.cjs +175 -0
- package/dist/scroll-snap.cjs +7 -0
- package/dist/scroll-snap.d.cts +14 -0
- package/dist/scroll-snap.d.mts +14 -0
- package/dist/scroll-snap.mjs +4 -0
- package/dist/selection-BIhSzkF7.d.mts +50 -0
- package/dist/selection-CS1GBp8e.d.cts +50 -0
- package/dist/store-BZcXv49B.cjs +305 -0
- package/dist/store-DEojWy9H.mjs +263 -0
- package/dist/store.cjs +9 -0
- package/dist/store.d.cts +26 -0
- package/dist/store.d.mts +26 -0
- package/dist/store.mjs +3 -0
- package/dist/stringify-state.cjs +49 -0
- package/dist/stringify-state.d.cts +8 -0
- package/dist/stringify-state.d.mts +8 -0
- package/dist/stringify-state.mjs +46 -0
- package/dist/tree-collection-BwU5WhGQ.d.mts +78 -0
- package/dist/tree-collection-DP_eznnI.d.cts +78 -0
- package/dist/typeahead-BdNwVP09.d.cts +45 -0
- package/dist/typeahead-XN6lZ7G9.d.mts +45 -0
- package/dist/types-BivBkYg9.d.cts +57 -0
- package/dist/types-Bl_6JtPQ.d.mts +57 -0
- package/dist/types-CPUMVt7c.d.mts +54 -0
- package/dist/types-CT_W6HWr.d.cts +54 -0
- package/dist/types-DDTcG99l.d.mts +201 -0
- package/dist/types-DejIu60O.d.cts +201 -0
- package/dist/types-DiIdKZ3K.d.cts +45 -0
- package/dist/types-GxLIgJib.d.cts +17 -0
- package/dist/types.cjs +15 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +14 -0
- package/dist/utils-BZyrxWWR.mjs +525 -0
- package/dist/utils-_6frwjgJ.cjs +1040 -0
- package/dist/utils.cjs +88 -0
- package/dist/utils.d.cts +144 -0
- package/dist/utils.d.mts +144 -0
- package/dist/utils.mjs +3 -0
- package/dist/wait-for-CMjPsqWk.d.cts +10 -0
- package/dist/wait-for-D2nkdD4z.d.mts +10 -0
- package/package.json +399 -0
|
@@ -0,0 +1,1165 @@
|
|
|
1
|
+
const require_create_anatomy = require('../../create-anatomy-CDsIFUXg.cjs');
|
|
2
|
+
const require_dom_query = require('../../dom-query-CWZdWUGp.cjs');
|
|
3
|
+
const require_utils = require('../../utils-_6frwjgJ.cjs');
|
|
4
|
+
const require_collection = require('../../collection-DIoIDISa.cjs');
|
|
5
|
+
const require_core = require('../../core-CQFbMdTl.cjs');
|
|
6
|
+
require('../../interact-outside-C8-oFBpB.cjs');
|
|
7
|
+
const require_dismissable = require('../../dismissable-CTfKZ4OG.cjs');
|
|
8
|
+
const require_popper = require('../../popper-D0FAW_p7.cjs');
|
|
9
|
+
const require_create_props = require('../../create-props-YKy7JIKj.cjs');
|
|
10
|
+
|
|
11
|
+
//#region src/machines/select/select.anatomy.ts
|
|
12
|
+
const anatomy = require_create_anatomy.createAnatomy("select").parts("label", "positioner", "trigger", "indicator", "clearTrigger", "item", "itemText", "itemIndicator", "itemGroup", "itemGroupLabel", "list", "content", "root", "control", "valueText");
|
|
13
|
+
const parts = anatomy.build();
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/machines/select/select.collection.ts
|
|
17
|
+
const collection = (options) => {
|
|
18
|
+
return new require_collection.ListCollection(options);
|
|
19
|
+
};
|
|
20
|
+
collection.empty = () => {
|
|
21
|
+
return new require_collection.ListCollection({ items: [] });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/machines/select/select.dom.ts
|
|
26
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `select:${ctx.id}`;
|
|
27
|
+
const getContentId = (ctx) => ctx.ids?.content ?? `select:${ctx.id}:content`;
|
|
28
|
+
const getTriggerId = (ctx) => ctx.ids?.trigger ?? `select:${ctx.id}:trigger`;
|
|
29
|
+
const getClearTriggerId = (ctx) => ctx.ids?.clearTrigger ?? `select:${ctx.id}:clear-trigger`;
|
|
30
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `select:${ctx.id}:label`;
|
|
31
|
+
const getControlId = (ctx) => ctx.ids?.control ?? `select:${ctx.id}:control`;
|
|
32
|
+
const getItemId = (ctx, id) => ctx.ids?.item?.(id) ?? `select:${ctx.id}:option:${id}`;
|
|
33
|
+
const getHiddenSelectId = (ctx) => ctx.ids?.hiddenSelect ?? `select:${ctx.id}:select`;
|
|
34
|
+
const getPositionerId = (ctx) => ctx.ids?.positioner ?? `select:${ctx.id}:positioner`;
|
|
35
|
+
const getItemGroupId = (ctx, id) => ctx.ids?.itemGroup?.(id) ?? `select:${ctx.id}:optgroup:${id}`;
|
|
36
|
+
const getItemGroupLabelId = (ctx, id) => ctx.ids?.itemGroupLabel?.(id) ?? `select:${ctx.id}:optgroup-label:${id}`;
|
|
37
|
+
const getHiddenSelectEl = (ctx) => ctx.getById(getHiddenSelectId(ctx));
|
|
38
|
+
const getContentEl = (ctx) => ctx.getById(getContentId(ctx));
|
|
39
|
+
const getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
40
|
+
const getClearTriggerEl = (ctx) => ctx.getById(getClearTriggerId(ctx));
|
|
41
|
+
const getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
42
|
+
const getItemEl = (ctx, id) => {
|
|
43
|
+
if (id == null) return null;
|
|
44
|
+
return ctx.getById(getItemId(ctx, id));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/machines/select/select.connect.ts
|
|
49
|
+
function connect(service, normalize) {
|
|
50
|
+
const { context, prop, scope, state, computed, send } = service;
|
|
51
|
+
const disabled = prop("disabled") || context.get("fieldsetDisabled");
|
|
52
|
+
const invalid = !!prop("invalid");
|
|
53
|
+
const required = !!prop("required");
|
|
54
|
+
const readOnly = !!prop("readOnly");
|
|
55
|
+
const composite = prop("composite");
|
|
56
|
+
const collection$1 = prop("collection");
|
|
57
|
+
const open = state.hasTag("open");
|
|
58
|
+
const focused = state.matches("focused");
|
|
59
|
+
const highlightedValue = context.get("highlightedValue");
|
|
60
|
+
const highlightedItem = context.get("highlightedItem");
|
|
61
|
+
const selectedItems = context.get("selectedItems");
|
|
62
|
+
const currentPlacement = context.get("currentPlacement");
|
|
63
|
+
const isTypingAhead = computed("isTypingAhead");
|
|
64
|
+
const interactive = computed("isInteractive");
|
|
65
|
+
const ariaActiveDescendant = highlightedValue ? getItemId(scope, highlightedValue) : void 0;
|
|
66
|
+
function getItemState(props$1) {
|
|
67
|
+
const _disabled = collection$1.getItemDisabled(props$1.item);
|
|
68
|
+
const value = collection$1.getItemValue(props$1.item);
|
|
69
|
+
require_utils.ensure(value, () => `[sprawlify-js] No value found for item ${JSON.stringify(props$1.item)}`);
|
|
70
|
+
return {
|
|
71
|
+
value,
|
|
72
|
+
disabled: Boolean(disabled || _disabled),
|
|
73
|
+
highlighted: highlightedValue === value,
|
|
74
|
+
selected: context.get("value").includes(value)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const popperStyles = require_popper.getPlacementStyles({
|
|
78
|
+
...prop("positioning"),
|
|
79
|
+
placement: currentPlacement
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
open,
|
|
83
|
+
focused,
|
|
84
|
+
empty: context.get("value").length === 0,
|
|
85
|
+
highlightedItem,
|
|
86
|
+
highlightedValue,
|
|
87
|
+
selectedItems,
|
|
88
|
+
hasSelectedItems: computed("hasSelectedItems"),
|
|
89
|
+
value: context.get("value"),
|
|
90
|
+
valueAsString: computed("valueAsString"),
|
|
91
|
+
collection: collection$1,
|
|
92
|
+
multiple: !!prop("multiple"),
|
|
93
|
+
disabled: !!disabled,
|
|
94
|
+
reposition(options = {}) {
|
|
95
|
+
send({
|
|
96
|
+
type: "POSITIONING.SET",
|
|
97
|
+
options
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
focus() {
|
|
101
|
+
getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
102
|
+
},
|
|
103
|
+
setOpen(nextOpen) {
|
|
104
|
+
if (state.hasTag("open") === nextOpen) return;
|
|
105
|
+
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
106
|
+
},
|
|
107
|
+
selectValue(value) {
|
|
108
|
+
send({
|
|
109
|
+
type: "ITEM.SELECT",
|
|
110
|
+
value
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
setValue(value) {
|
|
114
|
+
send({
|
|
115
|
+
type: "VALUE.SET",
|
|
116
|
+
value
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
selectAll() {
|
|
120
|
+
send({
|
|
121
|
+
type: "VALUE.SET",
|
|
122
|
+
value: collection$1.getValues()
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
setHighlightValue(value) {
|
|
126
|
+
send({
|
|
127
|
+
type: "HIGHLIGHTED_VALUE.SET",
|
|
128
|
+
value
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
clearHighlightValue() {
|
|
132
|
+
send({ type: "HIGHLIGHTED_VALUE.CLEAR" });
|
|
133
|
+
},
|
|
134
|
+
clearValue(value) {
|
|
135
|
+
if (value) send({
|
|
136
|
+
type: "ITEM.CLEAR",
|
|
137
|
+
value
|
|
138
|
+
});
|
|
139
|
+
else send({ type: "VALUE.CLEAR" });
|
|
140
|
+
},
|
|
141
|
+
getItemState,
|
|
142
|
+
getRootProps() {
|
|
143
|
+
return normalize.element({
|
|
144
|
+
...parts.root.attrs,
|
|
145
|
+
dir: prop("dir"),
|
|
146
|
+
id: getRootId(scope),
|
|
147
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
148
|
+
"data-readonly": require_dom_query.dataAttr(readOnly)
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
getLabelProps() {
|
|
152
|
+
return normalize.label({
|
|
153
|
+
dir: prop("dir"),
|
|
154
|
+
id: getLabelId(scope),
|
|
155
|
+
...parts.label.attrs,
|
|
156
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
157
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
158
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
159
|
+
"data-required": require_dom_query.dataAttr(required),
|
|
160
|
+
htmlFor: getHiddenSelectId(scope),
|
|
161
|
+
onClick(event) {
|
|
162
|
+
if (event.defaultPrevented) return;
|
|
163
|
+
if (disabled) return;
|
|
164
|
+
getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
getControlProps() {
|
|
169
|
+
return normalize.element({
|
|
170
|
+
...parts.control.attrs,
|
|
171
|
+
dir: prop("dir"),
|
|
172
|
+
id: getControlId(scope),
|
|
173
|
+
"data-state": open ? "open" : "closed",
|
|
174
|
+
"data-focus": require_dom_query.dataAttr(focused),
|
|
175
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
176
|
+
"data-invalid": require_dom_query.dataAttr(invalid)
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
getValueTextProps() {
|
|
180
|
+
return normalize.element({
|
|
181
|
+
...parts.valueText.attrs,
|
|
182
|
+
dir: prop("dir"),
|
|
183
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
184
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
185
|
+
"data-focus": require_dom_query.dataAttr(focused)
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
getTriggerProps() {
|
|
189
|
+
return normalize.button({
|
|
190
|
+
id: getTriggerId(scope),
|
|
191
|
+
disabled,
|
|
192
|
+
dir: prop("dir"),
|
|
193
|
+
type: "button",
|
|
194
|
+
role: "combobox",
|
|
195
|
+
"aria-controls": getContentId(scope),
|
|
196
|
+
"aria-expanded": open,
|
|
197
|
+
"aria-haspopup": "listbox",
|
|
198
|
+
"data-state": open ? "open" : "closed",
|
|
199
|
+
"aria-invalid": invalid,
|
|
200
|
+
"aria-required": required,
|
|
201
|
+
"aria-labelledby": getLabelId(scope),
|
|
202
|
+
...parts.trigger.attrs,
|
|
203
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
204
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
205
|
+
"data-readonly": require_dom_query.dataAttr(readOnly),
|
|
206
|
+
"data-placement": currentPlacement,
|
|
207
|
+
"data-placeholder-shown": require_dom_query.dataAttr(!computed("hasSelectedItems")),
|
|
208
|
+
onClick(event) {
|
|
209
|
+
if (!interactive) return;
|
|
210
|
+
if (event.defaultPrevented) return;
|
|
211
|
+
send({ type: "TRIGGER.CLICK" });
|
|
212
|
+
},
|
|
213
|
+
onFocus() {
|
|
214
|
+
send({ type: "TRIGGER.FOCUS" });
|
|
215
|
+
},
|
|
216
|
+
onBlur() {
|
|
217
|
+
send({ type: "TRIGGER.BLUR" });
|
|
218
|
+
},
|
|
219
|
+
onKeyDown(event) {
|
|
220
|
+
if (event.defaultPrevented) return;
|
|
221
|
+
if (!interactive) return;
|
|
222
|
+
const exec = {
|
|
223
|
+
ArrowUp() {
|
|
224
|
+
send({ type: "TRIGGER.ARROW_UP" });
|
|
225
|
+
},
|
|
226
|
+
ArrowDown(event$1) {
|
|
227
|
+
send({ type: event$1.altKey ? "OPEN" : "TRIGGER.ARROW_DOWN" });
|
|
228
|
+
},
|
|
229
|
+
ArrowLeft() {
|
|
230
|
+
send({ type: "TRIGGER.ARROW_LEFT" });
|
|
231
|
+
},
|
|
232
|
+
ArrowRight() {
|
|
233
|
+
send({ type: "TRIGGER.ARROW_RIGHT" });
|
|
234
|
+
},
|
|
235
|
+
Home() {
|
|
236
|
+
send({ type: "TRIGGER.HOME" });
|
|
237
|
+
},
|
|
238
|
+
End() {
|
|
239
|
+
send({ type: "TRIGGER.END" });
|
|
240
|
+
},
|
|
241
|
+
Enter() {
|
|
242
|
+
send({ type: "TRIGGER.ENTER" });
|
|
243
|
+
},
|
|
244
|
+
Space(event$1) {
|
|
245
|
+
if (isTypingAhead) send({
|
|
246
|
+
type: "TRIGGER.TYPEAHEAD",
|
|
247
|
+
key: event$1.key
|
|
248
|
+
});
|
|
249
|
+
else send({ type: "TRIGGER.ENTER" });
|
|
250
|
+
}
|
|
251
|
+
}[require_dom_query.getEventKey(event, {
|
|
252
|
+
dir: prop("dir"),
|
|
253
|
+
orientation: "vertical"
|
|
254
|
+
})];
|
|
255
|
+
if (exec) {
|
|
256
|
+
exec(event);
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (require_dom_query.getByTypeahead.isValidEvent(event)) {
|
|
261
|
+
send({
|
|
262
|
+
type: "TRIGGER.TYPEAHEAD",
|
|
263
|
+
key: event.key
|
|
264
|
+
});
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
getIndicatorProps() {
|
|
271
|
+
return normalize.element({
|
|
272
|
+
...parts.indicator.attrs,
|
|
273
|
+
dir: prop("dir"),
|
|
274
|
+
"aria-hidden": true,
|
|
275
|
+
"data-state": open ? "open" : "closed",
|
|
276
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
277
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
278
|
+
"data-readonly": require_dom_query.dataAttr(readOnly)
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
getItemProps(props$1) {
|
|
282
|
+
const itemState = getItemState(props$1);
|
|
283
|
+
return normalize.element({
|
|
284
|
+
id: getItemId(scope, itemState.value),
|
|
285
|
+
role: "option",
|
|
286
|
+
...parts.item.attrs,
|
|
287
|
+
dir: prop("dir"),
|
|
288
|
+
"data-value": itemState.value,
|
|
289
|
+
"aria-selected": itemState.selected,
|
|
290
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
291
|
+
"data-highlighted": require_dom_query.dataAttr(itemState.highlighted),
|
|
292
|
+
"data-disabled": require_dom_query.dataAttr(itemState.disabled),
|
|
293
|
+
"aria-disabled": require_dom_query.ariaAttr(itemState.disabled),
|
|
294
|
+
onPointerMove(event) {
|
|
295
|
+
if (itemState.disabled || event.pointerType !== "mouse") return;
|
|
296
|
+
if (itemState.value === highlightedValue) return;
|
|
297
|
+
send({
|
|
298
|
+
type: "ITEM.POINTER_MOVE",
|
|
299
|
+
value: itemState.value
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
onClick(event) {
|
|
303
|
+
if (event.defaultPrevented) return;
|
|
304
|
+
if (itemState.disabled) return;
|
|
305
|
+
send({
|
|
306
|
+
type: "ITEM.CLICK",
|
|
307
|
+
src: "pointerup",
|
|
308
|
+
value: itemState.value
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
onPointerLeave(event) {
|
|
312
|
+
if (itemState.disabled) return;
|
|
313
|
+
if (props$1.persistFocus) return;
|
|
314
|
+
if (event.pointerType !== "mouse") return;
|
|
315
|
+
if (!service.event.previous()?.type.includes("POINTER")) return;
|
|
316
|
+
send({ type: "ITEM.POINTER_LEAVE" });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
getItemTextProps(props$1) {
|
|
321
|
+
const itemState = getItemState(props$1);
|
|
322
|
+
return normalize.element({
|
|
323
|
+
...parts.itemText.attrs,
|
|
324
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
325
|
+
"data-disabled": require_dom_query.dataAttr(itemState.disabled),
|
|
326
|
+
"data-highlighted": require_dom_query.dataAttr(itemState.highlighted)
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
getItemIndicatorProps(props$1) {
|
|
330
|
+
const itemState = getItemState(props$1);
|
|
331
|
+
return normalize.element({
|
|
332
|
+
"aria-hidden": true,
|
|
333
|
+
...parts.itemIndicator.attrs,
|
|
334
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
335
|
+
hidden: !itemState.selected
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
getItemGroupLabelProps(props$1) {
|
|
339
|
+
const { htmlFor } = props$1;
|
|
340
|
+
return normalize.element({
|
|
341
|
+
...parts.itemGroupLabel.attrs,
|
|
342
|
+
id: getItemGroupLabelId(scope, htmlFor),
|
|
343
|
+
dir: prop("dir"),
|
|
344
|
+
role: "presentation"
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
getItemGroupProps(props$1) {
|
|
348
|
+
const { id } = props$1;
|
|
349
|
+
return normalize.element({
|
|
350
|
+
...parts.itemGroup.attrs,
|
|
351
|
+
"data-disabled": require_dom_query.dataAttr(disabled),
|
|
352
|
+
id: getItemGroupId(scope, id),
|
|
353
|
+
"aria-labelledby": getItemGroupLabelId(scope, id),
|
|
354
|
+
role: "group",
|
|
355
|
+
dir: prop("dir")
|
|
356
|
+
});
|
|
357
|
+
},
|
|
358
|
+
getClearTriggerProps() {
|
|
359
|
+
return normalize.button({
|
|
360
|
+
...parts.clearTrigger.attrs,
|
|
361
|
+
id: getClearTriggerId(scope),
|
|
362
|
+
type: "button",
|
|
363
|
+
"aria-label": "Clear value",
|
|
364
|
+
"data-invalid": require_dom_query.dataAttr(invalid),
|
|
365
|
+
disabled,
|
|
366
|
+
hidden: !computed("hasSelectedItems"),
|
|
367
|
+
dir: prop("dir"),
|
|
368
|
+
onClick(event) {
|
|
369
|
+
if (event.defaultPrevented) return;
|
|
370
|
+
send({ type: "CLEAR.CLICK" });
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
getHiddenSelectProps() {
|
|
375
|
+
const value = context.get("value");
|
|
376
|
+
const defaultValue = prop("multiple") ? value : value?.[0];
|
|
377
|
+
return normalize.select({
|
|
378
|
+
name: prop("name"),
|
|
379
|
+
form: prop("form"),
|
|
380
|
+
disabled,
|
|
381
|
+
multiple: prop("multiple"),
|
|
382
|
+
required: prop("required"),
|
|
383
|
+
"aria-hidden": true,
|
|
384
|
+
id: getHiddenSelectId(scope),
|
|
385
|
+
defaultValue,
|
|
386
|
+
style: require_dom_query.visuallyHiddenStyle,
|
|
387
|
+
tabIndex: -1,
|
|
388
|
+
onFocus() {
|
|
389
|
+
getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
390
|
+
},
|
|
391
|
+
"aria-labelledby": getLabelId(scope)
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
getPositionerProps() {
|
|
395
|
+
return normalize.element({
|
|
396
|
+
...parts.positioner.attrs,
|
|
397
|
+
dir: prop("dir"),
|
|
398
|
+
id: getPositionerId(scope),
|
|
399
|
+
style: popperStyles.floating
|
|
400
|
+
});
|
|
401
|
+
},
|
|
402
|
+
getContentProps() {
|
|
403
|
+
return normalize.element({
|
|
404
|
+
hidden: !open,
|
|
405
|
+
dir: prop("dir"),
|
|
406
|
+
id: getContentId(scope),
|
|
407
|
+
role: composite ? "listbox" : "dialog",
|
|
408
|
+
...parts.content.attrs,
|
|
409
|
+
"data-state": open ? "open" : "closed",
|
|
410
|
+
"data-placement": currentPlacement,
|
|
411
|
+
"data-activedescendant": ariaActiveDescendant,
|
|
412
|
+
"aria-activedescendant": composite ? ariaActiveDescendant : void 0,
|
|
413
|
+
"aria-multiselectable": prop("multiple") && composite ? true : void 0,
|
|
414
|
+
"aria-labelledby": getLabelId(scope),
|
|
415
|
+
tabIndex: 0,
|
|
416
|
+
onKeyDown(event) {
|
|
417
|
+
if (!interactive) return;
|
|
418
|
+
if (!require_dom_query.contains(event.currentTarget, require_dom_query.getEventTarget(event))) return;
|
|
419
|
+
if (event.key === "Tab") {
|
|
420
|
+
if (!require_dom_query.isValidTabEvent(event)) {
|
|
421
|
+
event.preventDefault();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const keyMap = {
|
|
426
|
+
ArrowUp() {
|
|
427
|
+
send({ type: "CONTENT.ARROW_UP" });
|
|
428
|
+
},
|
|
429
|
+
ArrowDown() {
|
|
430
|
+
send({ type: "CONTENT.ARROW_DOWN" });
|
|
431
|
+
},
|
|
432
|
+
Home() {
|
|
433
|
+
send({ type: "CONTENT.HOME" });
|
|
434
|
+
},
|
|
435
|
+
End() {
|
|
436
|
+
send({ type: "CONTENT.END" });
|
|
437
|
+
},
|
|
438
|
+
Enter() {
|
|
439
|
+
send({
|
|
440
|
+
type: "ITEM.CLICK",
|
|
441
|
+
src: "keydown.enter"
|
|
442
|
+
});
|
|
443
|
+
},
|
|
444
|
+
Space(event$1) {
|
|
445
|
+
if (isTypingAhead) send({
|
|
446
|
+
type: "CONTENT.TYPEAHEAD",
|
|
447
|
+
key: event$1.key
|
|
448
|
+
});
|
|
449
|
+
else keyMap.Enter?.(event$1);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
const exec = keyMap[require_dom_query.getEventKey(event)];
|
|
453
|
+
if (exec) {
|
|
454
|
+
exec(event);
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (require_dom_query.isEditableElement(require_dom_query.getEventTarget(event))) return;
|
|
459
|
+
if (require_dom_query.getByTypeahead.isValidEvent(event)) {
|
|
460
|
+
send({
|
|
461
|
+
type: "CONTENT.TYPEAHEAD",
|
|
462
|
+
key: event.key
|
|
463
|
+
});
|
|
464
|
+
event.preventDefault();
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
},
|
|
469
|
+
getListProps() {
|
|
470
|
+
return normalize.element({
|
|
471
|
+
...parts.list.attrs,
|
|
472
|
+
tabIndex: 0,
|
|
473
|
+
role: !composite ? "listbox" : void 0,
|
|
474
|
+
"aria-labelledby": getTriggerId(scope),
|
|
475
|
+
"aria-activedescendant": !composite ? ariaActiveDescendant : void 0,
|
|
476
|
+
"aria-multiselectable": !composite && prop("multiple") ? true : void 0
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/machines/select/select.machine.ts
|
|
484
|
+
const { and, not, or } = require_core.createGuards();
|
|
485
|
+
const machine = require_core.createMachine({
|
|
486
|
+
props({ props: props$1 }) {
|
|
487
|
+
return {
|
|
488
|
+
loopFocus: false,
|
|
489
|
+
closeOnSelect: !props$1.multiple,
|
|
490
|
+
composite: true,
|
|
491
|
+
defaultValue: [],
|
|
492
|
+
...props$1,
|
|
493
|
+
collection: props$1.collection ?? collection.empty(),
|
|
494
|
+
positioning: {
|
|
495
|
+
placement: "bottom-start",
|
|
496
|
+
gutter: 8,
|
|
497
|
+
...props$1.positioning
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
},
|
|
501
|
+
context({ prop, bindable }) {
|
|
502
|
+
return {
|
|
503
|
+
value: bindable(() => ({
|
|
504
|
+
defaultValue: prop("defaultValue"),
|
|
505
|
+
value: prop("value"),
|
|
506
|
+
isEqual: require_utils.isEqual,
|
|
507
|
+
onChange(value) {
|
|
508
|
+
const items = prop("collection").findMany(value);
|
|
509
|
+
return prop("onValueChange")?.({
|
|
510
|
+
value,
|
|
511
|
+
items
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
})),
|
|
515
|
+
highlightedValue: bindable(() => ({
|
|
516
|
+
defaultValue: prop("defaultHighlightedValue") || null,
|
|
517
|
+
value: prop("highlightedValue"),
|
|
518
|
+
onChange(value) {
|
|
519
|
+
prop("onHighlightChange")?.({
|
|
520
|
+
highlightedValue: value,
|
|
521
|
+
highlightedItem: prop("collection").find(value),
|
|
522
|
+
highlightedIndex: prop("collection").indexOf(value)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
})),
|
|
526
|
+
currentPlacement: bindable(() => ({ defaultValue: void 0 })),
|
|
527
|
+
fieldsetDisabled: bindable(() => ({ defaultValue: false })),
|
|
528
|
+
highlightedItem: bindable(() => ({ defaultValue: null })),
|
|
529
|
+
selectedItems: bindable(() => {
|
|
530
|
+
const value = prop("value") ?? prop("defaultValue") ?? [];
|
|
531
|
+
return { defaultValue: prop("collection").findMany(value) };
|
|
532
|
+
})
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
refs() {
|
|
536
|
+
return { typeahead: { ...require_dom_query.getByTypeahead.defaultOptions } };
|
|
537
|
+
},
|
|
538
|
+
computed: {
|
|
539
|
+
hasSelectedItems: ({ context }) => context.get("value").length > 0,
|
|
540
|
+
isTypingAhead: ({ refs }) => refs.get("typeahead").keysSoFar !== "",
|
|
541
|
+
isDisabled: ({ prop, context }) => !!prop("disabled") || !!context.get("fieldsetDisabled"),
|
|
542
|
+
isInteractive: ({ prop }) => !(prop("disabled") || prop("readOnly")),
|
|
543
|
+
valueAsString: ({ context, prop }) => prop("collection").stringifyItems(context.get("selectedItems"))
|
|
544
|
+
},
|
|
545
|
+
initialState({ prop }) {
|
|
546
|
+
return prop("open") || prop("defaultOpen") ? "open" : "idle";
|
|
547
|
+
},
|
|
548
|
+
entry: ["syncSelectElement"],
|
|
549
|
+
watch({ context, prop, track, action }) {
|
|
550
|
+
track([() => context.get("value").toString()], () => {
|
|
551
|
+
action([
|
|
552
|
+
"syncSelectedItems",
|
|
553
|
+
"syncSelectElement",
|
|
554
|
+
"dispatchChangeEvent"
|
|
555
|
+
]);
|
|
556
|
+
});
|
|
557
|
+
track([() => prop("open")], () => {
|
|
558
|
+
action(["toggleVisibility"]);
|
|
559
|
+
});
|
|
560
|
+
track([() => context.get("highlightedValue")], () => {
|
|
561
|
+
action(["syncHighlightedItem"]);
|
|
562
|
+
});
|
|
563
|
+
track([() => prop("collection").toString()], () => {
|
|
564
|
+
action(["syncCollection"]);
|
|
565
|
+
});
|
|
566
|
+
},
|
|
567
|
+
on: {
|
|
568
|
+
"HIGHLIGHTED_VALUE.SET": { actions: ["setHighlightedItem"] },
|
|
569
|
+
"HIGHLIGHTED_VALUE.CLEAR": { actions: ["clearHighlightedItem"] },
|
|
570
|
+
"ITEM.SELECT": { actions: ["selectItem"] },
|
|
571
|
+
"ITEM.CLEAR": { actions: ["clearItem"] },
|
|
572
|
+
"VALUE.SET": { actions: ["setSelectedItems"] },
|
|
573
|
+
"VALUE.CLEAR": { actions: ["clearSelectedItems"] },
|
|
574
|
+
"CLEAR.CLICK": { actions: ["clearSelectedItems", "focusTriggerEl"] }
|
|
575
|
+
},
|
|
576
|
+
effects: ["trackFormControlState"],
|
|
577
|
+
states: {
|
|
578
|
+
idle: {
|
|
579
|
+
tags: ["closed"],
|
|
580
|
+
on: {
|
|
581
|
+
"CONTROLLED.OPEN": [{
|
|
582
|
+
guard: "isTriggerClickEvent",
|
|
583
|
+
target: "open",
|
|
584
|
+
actions: ["setInitialFocus", "highlightFirstSelectedItem"]
|
|
585
|
+
}, {
|
|
586
|
+
target: "open",
|
|
587
|
+
actions: ["setInitialFocus"]
|
|
588
|
+
}],
|
|
589
|
+
"TRIGGER.CLICK": [{
|
|
590
|
+
guard: "isOpenControlled",
|
|
591
|
+
actions: ["invokeOnOpen"]
|
|
592
|
+
}, {
|
|
593
|
+
target: "open",
|
|
594
|
+
actions: [
|
|
595
|
+
"invokeOnOpen",
|
|
596
|
+
"setInitialFocus",
|
|
597
|
+
"highlightFirstSelectedItem"
|
|
598
|
+
]
|
|
599
|
+
}],
|
|
600
|
+
"TRIGGER.FOCUS": { target: "focused" },
|
|
601
|
+
OPEN: [{
|
|
602
|
+
guard: "isOpenControlled",
|
|
603
|
+
actions: ["invokeOnOpen"]
|
|
604
|
+
}, {
|
|
605
|
+
target: "open",
|
|
606
|
+
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
607
|
+
}]
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
focused: {
|
|
611
|
+
tags: ["closed"],
|
|
612
|
+
on: {
|
|
613
|
+
"CONTROLLED.OPEN": [
|
|
614
|
+
{
|
|
615
|
+
guard: "isTriggerClickEvent",
|
|
616
|
+
target: "open",
|
|
617
|
+
actions: ["setInitialFocus", "highlightFirstSelectedItem"]
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
guard: "isTriggerArrowUpEvent",
|
|
621
|
+
target: "open",
|
|
622
|
+
actions: ["setInitialFocus", "highlightComputedLastItem"]
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
guard: or("isTriggerArrowDownEvent", "isTriggerEnterEvent"),
|
|
626
|
+
target: "open",
|
|
627
|
+
actions: ["setInitialFocus", "highlightComputedFirstItem"]
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
target: "open",
|
|
631
|
+
actions: ["setInitialFocus"]
|
|
632
|
+
}
|
|
633
|
+
],
|
|
634
|
+
OPEN: [{
|
|
635
|
+
guard: "isOpenControlled",
|
|
636
|
+
actions: ["invokeOnOpen"]
|
|
637
|
+
}, {
|
|
638
|
+
target: "open",
|
|
639
|
+
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
640
|
+
}],
|
|
641
|
+
"TRIGGER.BLUR": { target: "idle" },
|
|
642
|
+
"TRIGGER.CLICK": [{
|
|
643
|
+
guard: "isOpenControlled",
|
|
644
|
+
actions: ["invokeOnOpen"]
|
|
645
|
+
}, {
|
|
646
|
+
target: "open",
|
|
647
|
+
actions: [
|
|
648
|
+
"setInitialFocus",
|
|
649
|
+
"invokeOnOpen",
|
|
650
|
+
"highlightFirstSelectedItem"
|
|
651
|
+
]
|
|
652
|
+
}],
|
|
653
|
+
"TRIGGER.ENTER": [{
|
|
654
|
+
guard: "isOpenControlled",
|
|
655
|
+
actions: ["invokeOnOpen"]
|
|
656
|
+
}, {
|
|
657
|
+
target: "open",
|
|
658
|
+
actions: [
|
|
659
|
+
"setInitialFocus",
|
|
660
|
+
"invokeOnOpen",
|
|
661
|
+
"highlightComputedFirstItem"
|
|
662
|
+
]
|
|
663
|
+
}],
|
|
664
|
+
"TRIGGER.ARROW_UP": [{
|
|
665
|
+
guard: "isOpenControlled",
|
|
666
|
+
actions: ["invokeOnOpen"]
|
|
667
|
+
}, {
|
|
668
|
+
target: "open",
|
|
669
|
+
actions: [
|
|
670
|
+
"setInitialFocus",
|
|
671
|
+
"invokeOnOpen",
|
|
672
|
+
"highlightComputedLastItem"
|
|
673
|
+
]
|
|
674
|
+
}],
|
|
675
|
+
"TRIGGER.ARROW_DOWN": [{
|
|
676
|
+
guard: "isOpenControlled",
|
|
677
|
+
actions: ["invokeOnOpen"]
|
|
678
|
+
}, {
|
|
679
|
+
target: "open",
|
|
680
|
+
actions: [
|
|
681
|
+
"setInitialFocus",
|
|
682
|
+
"invokeOnOpen",
|
|
683
|
+
"highlightComputedFirstItem"
|
|
684
|
+
]
|
|
685
|
+
}],
|
|
686
|
+
"TRIGGER.ARROW_LEFT": [{
|
|
687
|
+
guard: and(not("multiple"), "hasSelectedItems"),
|
|
688
|
+
actions: ["selectPreviousItem"]
|
|
689
|
+
}, {
|
|
690
|
+
guard: not("multiple"),
|
|
691
|
+
actions: ["selectLastItem"]
|
|
692
|
+
}],
|
|
693
|
+
"TRIGGER.ARROW_RIGHT": [{
|
|
694
|
+
guard: and(not("multiple"), "hasSelectedItems"),
|
|
695
|
+
actions: ["selectNextItem"]
|
|
696
|
+
}, {
|
|
697
|
+
guard: not("multiple"),
|
|
698
|
+
actions: ["selectFirstItem"]
|
|
699
|
+
}],
|
|
700
|
+
"TRIGGER.HOME": {
|
|
701
|
+
guard: not("multiple"),
|
|
702
|
+
actions: ["selectFirstItem"]
|
|
703
|
+
},
|
|
704
|
+
"TRIGGER.END": {
|
|
705
|
+
guard: not("multiple"),
|
|
706
|
+
actions: ["selectLastItem"]
|
|
707
|
+
},
|
|
708
|
+
"TRIGGER.TYPEAHEAD": {
|
|
709
|
+
guard: not("multiple"),
|
|
710
|
+
actions: ["selectMatchingItem"]
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
open: {
|
|
715
|
+
tags: ["open"],
|
|
716
|
+
exit: ["scrollContentToTop"],
|
|
717
|
+
effects: [
|
|
718
|
+
"trackDismissableElement",
|
|
719
|
+
"computePlacement",
|
|
720
|
+
"scrollToHighlightedItem"
|
|
721
|
+
],
|
|
722
|
+
on: {
|
|
723
|
+
"CONTROLLED.CLOSE": [{
|
|
724
|
+
guard: "restoreFocus",
|
|
725
|
+
target: "focused",
|
|
726
|
+
actions: ["focusTriggerEl", "clearHighlightedItem"]
|
|
727
|
+
}, {
|
|
728
|
+
target: "idle",
|
|
729
|
+
actions: ["clearHighlightedItem"]
|
|
730
|
+
}],
|
|
731
|
+
CLOSE: [
|
|
732
|
+
{
|
|
733
|
+
guard: "isOpenControlled",
|
|
734
|
+
actions: ["invokeOnClose"]
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
guard: "restoreFocus",
|
|
738
|
+
target: "focused",
|
|
739
|
+
actions: [
|
|
740
|
+
"invokeOnClose",
|
|
741
|
+
"focusTriggerEl",
|
|
742
|
+
"clearHighlightedItem"
|
|
743
|
+
]
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
target: "idle",
|
|
747
|
+
actions: ["invokeOnClose", "clearHighlightedItem"]
|
|
748
|
+
}
|
|
749
|
+
],
|
|
750
|
+
"TRIGGER.CLICK": [{
|
|
751
|
+
guard: "isOpenControlled",
|
|
752
|
+
actions: ["invokeOnClose"]
|
|
753
|
+
}, {
|
|
754
|
+
target: "focused",
|
|
755
|
+
actions: ["invokeOnClose", "clearHighlightedItem"]
|
|
756
|
+
}],
|
|
757
|
+
"ITEM.CLICK": [
|
|
758
|
+
{
|
|
759
|
+
guard: and("closeOnSelect", "isOpenControlled"),
|
|
760
|
+
actions: ["selectHighlightedItem", "invokeOnClose"]
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
guard: "closeOnSelect",
|
|
764
|
+
target: "focused",
|
|
765
|
+
actions: [
|
|
766
|
+
"selectHighlightedItem",
|
|
767
|
+
"invokeOnClose",
|
|
768
|
+
"focusTriggerEl",
|
|
769
|
+
"clearHighlightedItem"
|
|
770
|
+
]
|
|
771
|
+
},
|
|
772
|
+
{ actions: ["selectHighlightedItem"] }
|
|
773
|
+
],
|
|
774
|
+
"CONTENT.HOME": { actions: ["highlightFirstItem"] },
|
|
775
|
+
"CONTENT.END": { actions: ["highlightLastItem"] },
|
|
776
|
+
"CONTENT.ARROW_DOWN": [
|
|
777
|
+
{
|
|
778
|
+
guard: and("hasHighlightedItem", "loop", "isLastItemHighlighted"),
|
|
779
|
+
actions: ["highlightFirstItem"]
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
guard: "hasHighlightedItem",
|
|
783
|
+
actions: ["highlightNextItem"]
|
|
784
|
+
},
|
|
785
|
+
{ actions: ["highlightFirstItem"] }
|
|
786
|
+
],
|
|
787
|
+
"CONTENT.ARROW_UP": [
|
|
788
|
+
{
|
|
789
|
+
guard: and("hasHighlightedItem", "loop", "isFirstItemHighlighted"),
|
|
790
|
+
actions: ["highlightLastItem"]
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
guard: "hasHighlightedItem",
|
|
794
|
+
actions: ["highlightPreviousItem"]
|
|
795
|
+
},
|
|
796
|
+
{ actions: ["highlightLastItem"] }
|
|
797
|
+
],
|
|
798
|
+
"CONTENT.TYPEAHEAD": { actions: ["highlightMatchingItem"] },
|
|
799
|
+
"ITEM.POINTER_MOVE": { actions: ["highlightItem"] },
|
|
800
|
+
"ITEM.POINTER_LEAVE": { actions: ["clearHighlightedItem"] },
|
|
801
|
+
"POSITIONING.SET": { actions: ["reposition"] }
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
implementations: {
|
|
806
|
+
guards: {
|
|
807
|
+
loop: ({ prop }) => !!prop("loopFocus"),
|
|
808
|
+
multiple: ({ prop }) => !!prop("multiple"),
|
|
809
|
+
hasSelectedItems: ({ computed }) => !!computed("hasSelectedItems"),
|
|
810
|
+
hasHighlightedItem: ({ context }) => context.get("highlightedValue") != null,
|
|
811
|
+
isFirstItemHighlighted: ({ context, prop }) => context.get("highlightedValue") === prop("collection").firstValue,
|
|
812
|
+
isLastItemHighlighted: ({ context, prop }) => context.get("highlightedValue") === prop("collection").lastValue,
|
|
813
|
+
closeOnSelect: ({ prop, event }) => !!(event.closeOnSelect ?? prop("closeOnSelect")),
|
|
814
|
+
restoreFocus: ({ event }) => restoreFocusFn(event),
|
|
815
|
+
isOpenControlled: ({ prop }) => prop("open") !== void 0,
|
|
816
|
+
isTriggerClickEvent: ({ event }) => event.previousEvent?.type === "TRIGGER.CLICK",
|
|
817
|
+
isTriggerEnterEvent: ({ event }) => event.previousEvent?.type === "TRIGGER.ENTER",
|
|
818
|
+
isTriggerArrowUpEvent: ({ event }) => event.previousEvent?.type === "TRIGGER.ARROW_UP",
|
|
819
|
+
isTriggerArrowDownEvent: ({ event }) => event.previousEvent?.type === "TRIGGER.ARROW_DOWN"
|
|
820
|
+
},
|
|
821
|
+
effects: {
|
|
822
|
+
trackFormControlState({ context, scope }) {
|
|
823
|
+
return require_dom_query.trackFormControl(getHiddenSelectEl(scope), {
|
|
824
|
+
onFieldsetDisabledChange(disabled) {
|
|
825
|
+
context.set("fieldsetDisabled", disabled);
|
|
826
|
+
},
|
|
827
|
+
onFormReset() {
|
|
828
|
+
const value = context.initial("value");
|
|
829
|
+
context.set("value", value);
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
trackDismissableElement({ scope, send, prop }) {
|
|
834
|
+
const contentEl = () => getContentEl(scope);
|
|
835
|
+
let restoreFocus = true;
|
|
836
|
+
return require_dismissable.trackDismissableElement(contentEl, {
|
|
837
|
+
type: "listbox",
|
|
838
|
+
defer: true,
|
|
839
|
+
exclude: [getTriggerEl(scope), getClearTriggerEl(scope)],
|
|
840
|
+
onFocusOutside: prop("onFocusOutside"),
|
|
841
|
+
onPointerDownOutside: prop("onPointerDownOutside"),
|
|
842
|
+
onInteractOutside(event) {
|
|
843
|
+
prop("onInteractOutside")?.(event);
|
|
844
|
+
restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
845
|
+
},
|
|
846
|
+
onDismiss() {
|
|
847
|
+
send({
|
|
848
|
+
type: "CLOSE",
|
|
849
|
+
src: "interact-outside",
|
|
850
|
+
restoreFocus
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
},
|
|
855
|
+
computePlacement({ context, prop, scope }) {
|
|
856
|
+
const positioning = prop("positioning");
|
|
857
|
+
context.set("currentPlacement", positioning.placement);
|
|
858
|
+
const triggerEl = () => getTriggerEl(scope);
|
|
859
|
+
const positionerEl = () => getPositionerEl(scope);
|
|
860
|
+
return require_popper.getPlacement(triggerEl, positionerEl, {
|
|
861
|
+
defer: true,
|
|
862
|
+
...positioning,
|
|
863
|
+
onComplete(data) {
|
|
864
|
+
context.set("currentPlacement", data.placement);
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
},
|
|
868
|
+
scrollToHighlightedItem({ context, prop, scope, event }) {
|
|
869
|
+
const exec = (immediate) => {
|
|
870
|
+
const highlightedValue = context.get("highlightedValue");
|
|
871
|
+
if (highlightedValue == null) return;
|
|
872
|
+
if (event.current().type.includes("POINTER")) return;
|
|
873
|
+
const contentEl$1 = getContentEl(scope);
|
|
874
|
+
const scrollToIndexFn = prop("scrollToIndexFn");
|
|
875
|
+
if (scrollToIndexFn) {
|
|
876
|
+
const highlightedIndex = prop("collection").indexOf(highlightedValue);
|
|
877
|
+
scrollToIndexFn?.({
|
|
878
|
+
index: highlightedIndex,
|
|
879
|
+
immediate,
|
|
880
|
+
getElement: () => getItemEl(scope, highlightedValue)
|
|
881
|
+
});
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
require_dom_query.scrollIntoView(getItemEl(scope, highlightedValue), {
|
|
885
|
+
rootEl: contentEl$1,
|
|
886
|
+
block: "nearest"
|
|
887
|
+
});
|
|
888
|
+
};
|
|
889
|
+
require_dom_query.raf(() => exec(true));
|
|
890
|
+
const contentEl = () => getContentEl(scope);
|
|
891
|
+
return require_dom_query.observeAttributes(contentEl, {
|
|
892
|
+
defer: true,
|
|
893
|
+
attributes: ["data-activedescendant"],
|
|
894
|
+
callback() {
|
|
895
|
+
exec(false);
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
actions: {
|
|
901
|
+
reposition({ context, prop, scope, event }) {
|
|
902
|
+
const positionerEl = () => getPositionerEl(scope);
|
|
903
|
+
require_popper.getPlacement(getTriggerEl(scope), positionerEl, {
|
|
904
|
+
...prop("positioning"),
|
|
905
|
+
...event.options,
|
|
906
|
+
defer: true,
|
|
907
|
+
listeners: false,
|
|
908
|
+
onComplete(data) {
|
|
909
|
+
context.set("currentPlacement", data.placement);
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
},
|
|
913
|
+
toggleVisibility({ send, prop, event }) {
|
|
914
|
+
send({
|
|
915
|
+
type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE",
|
|
916
|
+
previousEvent: event
|
|
917
|
+
});
|
|
918
|
+
},
|
|
919
|
+
highlightPreviousItem({ context, prop }) {
|
|
920
|
+
const highlightedValue = context.get("highlightedValue");
|
|
921
|
+
if (highlightedValue == null) return;
|
|
922
|
+
const value = prop("collection").getPreviousValue(highlightedValue, 1, prop("loopFocus"));
|
|
923
|
+
if (value == null) return;
|
|
924
|
+
context.set("highlightedValue", value);
|
|
925
|
+
},
|
|
926
|
+
highlightNextItem({ context, prop }) {
|
|
927
|
+
const highlightedValue = context.get("highlightedValue");
|
|
928
|
+
if (highlightedValue == null) return;
|
|
929
|
+
const value = prop("collection").getNextValue(highlightedValue, 1, prop("loopFocus"));
|
|
930
|
+
if (value == null) return;
|
|
931
|
+
context.set("highlightedValue", value);
|
|
932
|
+
},
|
|
933
|
+
highlightFirstItem({ context, prop }) {
|
|
934
|
+
const value = prop("collection").firstValue;
|
|
935
|
+
context.set("highlightedValue", value);
|
|
936
|
+
},
|
|
937
|
+
highlightLastItem({ context, prop }) {
|
|
938
|
+
const value = prop("collection").lastValue;
|
|
939
|
+
context.set("highlightedValue", value);
|
|
940
|
+
},
|
|
941
|
+
setInitialFocus({ scope }) {
|
|
942
|
+
require_dom_query.raf(() => {
|
|
943
|
+
require_dom_query.getInitialFocus({ root: getContentEl(scope) })?.focus({ preventScroll: true });
|
|
944
|
+
});
|
|
945
|
+
},
|
|
946
|
+
focusTriggerEl({ event, scope }) {
|
|
947
|
+
if (!restoreFocusFn(event)) return;
|
|
948
|
+
require_dom_query.raf(() => {
|
|
949
|
+
getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
950
|
+
});
|
|
951
|
+
},
|
|
952
|
+
selectHighlightedItem({ context, prop, event }) {
|
|
953
|
+
let value = event.value ?? context.get("highlightedValue");
|
|
954
|
+
if (value == null || !prop("collection").has(value)) return;
|
|
955
|
+
prop("onSelect")?.({ value });
|
|
956
|
+
value = prop("deselectable") && !prop("multiple") && context.get("value").includes(value) ? null : value;
|
|
957
|
+
context.set("value", (prev) => {
|
|
958
|
+
if (value == null) return [];
|
|
959
|
+
if (prop("multiple")) return require_utils.addOrRemove(prev, value);
|
|
960
|
+
return [value];
|
|
961
|
+
});
|
|
962
|
+
},
|
|
963
|
+
highlightComputedFirstItem({ context, prop, computed }) {
|
|
964
|
+
const collection$1 = prop("collection");
|
|
965
|
+
const value = computed("hasSelectedItems") ? collection$1.sort(context.get("value"))[0] : collection$1.firstValue;
|
|
966
|
+
context.set("highlightedValue", value);
|
|
967
|
+
},
|
|
968
|
+
highlightComputedLastItem({ context, prop, computed }) {
|
|
969
|
+
const collection$1 = prop("collection");
|
|
970
|
+
const value = computed("hasSelectedItems") ? collection$1.sort(context.get("value"))[0] : collection$1.lastValue;
|
|
971
|
+
context.set("highlightedValue", value);
|
|
972
|
+
},
|
|
973
|
+
highlightFirstSelectedItem({ context, prop, computed }) {
|
|
974
|
+
if (!computed("hasSelectedItems")) return;
|
|
975
|
+
const value = prop("collection").sort(context.get("value"))[0];
|
|
976
|
+
context.set("highlightedValue", value);
|
|
977
|
+
},
|
|
978
|
+
highlightItem({ context, event }) {
|
|
979
|
+
context.set("highlightedValue", event.value);
|
|
980
|
+
},
|
|
981
|
+
highlightMatchingItem({ context, prop, event, refs }) {
|
|
982
|
+
const value = prop("collection").search(event.key, {
|
|
983
|
+
state: refs.get("typeahead"),
|
|
984
|
+
currentValue: context.get("highlightedValue")
|
|
985
|
+
});
|
|
986
|
+
if (value == null) return;
|
|
987
|
+
context.set("highlightedValue", value);
|
|
988
|
+
},
|
|
989
|
+
setHighlightedItem({ context, event }) {
|
|
990
|
+
context.set("highlightedValue", event.value);
|
|
991
|
+
},
|
|
992
|
+
clearHighlightedItem({ context }) {
|
|
993
|
+
context.set("highlightedValue", null);
|
|
994
|
+
},
|
|
995
|
+
selectItem({ context, prop, event }) {
|
|
996
|
+
prop("onSelect")?.({ value: event.value });
|
|
997
|
+
const value = prop("deselectable") && !prop("multiple") && context.get("value").includes(event.value) ? null : event.value;
|
|
998
|
+
context.set("value", (prev) => {
|
|
999
|
+
if (value == null) return [];
|
|
1000
|
+
if (prop("multiple")) return require_utils.addOrRemove(prev, value);
|
|
1001
|
+
return [value];
|
|
1002
|
+
});
|
|
1003
|
+
},
|
|
1004
|
+
clearItem({ context, event }) {
|
|
1005
|
+
context.set("value", (prev) => prev.filter((v) => v !== event.value));
|
|
1006
|
+
},
|
|
1007
|
+
setSelectedItems({ context, event }) {
|
|
1008
|
+
context.set("value", event.value);
|
|
1009
|
+
},
|
|
1010
|
+
clearSelectedItems({ context }) {
|
|
1011
|
+
context.set("value", []);
|
|
1012
|
+
},
|
|
1013
|
+
selectPreviousItem({ context, prop }) {
|
|
1014
|
+
const [firstItem] = context.get("value");
|
|
1015
|
+
const value = prop("collection").getPreviousValue(firstItem);
|
|
1016
|
+
if (value) context.set("value", [value]);
|
|
1017
|
+
},
|
|
1018
|
+
selectNextItem({ context, prop }) {
|
|
1019
|
+
const [firstItem] = context.get("value");
|
|
1020
|
+
const value = prop("collection").getNextValue(firstItem);
|
|
1021
|
+
if (value) context.set("value", [value]);
|
|
1022
|
+
},
|
|
1023
|
+
selectFirstItem({ context, prop }) {
|
|
1024
|
+
const value = prop("collection").firstValue;
|
|
1025
|
+
if (value) context.set("value", [value]);
|
|
1026
|
+
},
|
|
1027
|
+
selectLastItem({ context, prop }) {
|
|
1028
|
+
const value = prop("collection").lastValue;
|
|
1029
|
+
if (value) context.set("value", [value]);
|
|
1030
|
+
},
|
|
1031
|
+
selectMatchingItem({ context, prop, event, refs }) {
|
|
1032
|
+
const value = prop("collection").search(event.key, {
|
|
1033
|
+
state: refs.get("typeahead"),
|
|
1034
|
+
currentValue: context.get("value")[0]
|
|
1035
|
+
});
|
|
1036
|
+
if (value == null) return;
|
|
1037
|
+
context.set("value", [value]);
|
|
1038
|
+
},
|
|
1039
|
+
scrollContentToTop({ prop, scope }) {
|
|
1040
|
+
if (prop("scrollToIndexFn")) {
|
|
1041
|
+
const firstValue = prop("collection").firstValue;
|
|
1042
|
+
prop("scrollToIndexFn")?.({
|
|
1043
|
+
index: 0,
|
|
1044
|
+
immediate: true,
|
|
1045
|
+
getElement: () => getItemEl(scope, firstValue)
|
|
1046
|
+
});
|
|
1047
|
+
} else getContentEl(scope)?.scrollTo(0, 0);
|
|
1048
|
+
},
|
|
1049
|
+
invokeOnOpen({ prop, context }) {
|
|
1050
|
+
prop("onOpenChange")?.({
|
|
1051
|
+
open: true,
|
|
1052
|
+
value: context.get("value")
|
|
1053
|
+
});
|
|
1054
|
+
},
|
|
1055
|
+
invokeOnClose({ prop, context }) {
|
|
1056
|
+
prop("onOpenChange")?.({
|
|
1057
|
+
open: false,
|
|
1058
|
+
value: context.get("value")
|
|
1059
|
+
});
|
|
1060
|
+
},
|
|
1061
|
+
syncSelectElement({ context, prop, scope }) {
|
|
1062
|
+
const selectEl = getHiddenSelectEl(scope);
|
|
1063
|
+
if (!selectEl) return;
|
|
1064
|
+
if (context.get("value").length === 0 && !prop("multiple")) {
|
|
1065
|
+
selectEl.selectedIndex = -1;
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
for (const option of selectEl.options) option.selected = context.get("value").includes(option.value);
|
|
1069
|
+
},
|
|
1070
|
+
syncCollection({ context, prop }) {
|
|
1071
|
+
const collection$1 = prop("collection");
|
|
1072
|
+
const highlightedItem = collection$1.find(context.get("highlightedValue"));
|
|
1073
|
+
if (highlightedItem) context.set("highlightedItem", highlightedItem);
|
|
1074
|
+
const selectedItems = collection$1.findMany(context.get("value"));
|
|
1075
|
+
context.set("selectedItems", selectedItems);
|
|
1076
|
+
},
|
|
1077
|
+
syncSelectedItems({ context, prop }) {
|
|
1078
|
+
const collection$1 = prop("collection");
|
|
1079
|
+
const prevSelectedItems = context.get("selectedItems");
|
|
1080
|
+
const selectedItems = context.get("value").map((value) => {
|
|
1081
|
+
return prevSelectedItems.find((item) => collection$1.getItemValue(item) === value) || collection$1.find(value);
|
|
1082
|
+
});
|
|
1083
|
+
context.set("selectedItems", selectedItems);
|
|
1084
|
+
},
|
|
1085
|
+
syncHighlightedItem({ context, prop }) {
|
|
1086
|
+
const collection$1 = prop("collection");
|
|
1087
|
+
const highlightedValue = context.get("highlightedValue");
|
|
1088
|
+
const highlightedItem = highlightedValue ? collection$1.find(highlightedValue) : null;
|
|
1089
|
+
context.set("highlightedItem", highlightedItem);
|
|
1090
|
+
},
|
|
1091
|
+
dispatchChangeEvent({ scope }) {
|
|
1092
|
+
queueMicrotask(() => {
|
|
1093
|
+
const node = getHiddenSelectEl(scope);
|
|
1094
|
+
if (!node) return;
|
|
1095
|
+
const changeEvent = new (scope.getWin()).Event("change", {
|
|
1096
|
+
bubbles: true,
|
|
1097
|
+
composed: true
|
|
1098
|
+
});
|
|
1099
|
+
node.dispatchEvent(changeEvent);
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
function restoreFocusFn(event) {
|
|
1106
|
+
const v = event.restoreFocus ?? event.previousEvent?.restoreFocus;
|
|
1107
|
+
return v == null || !!v;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
//#endregion
|
|
1111
|
+
//#region src/machines/select/select.props.ts
|
|
1112
|
+
const props = require_create_props.createProps()([
|
|
1113
|
+
"closeOnSelect",
|
|
1114
|
+
"collection",
|
|
1115
|
+
"composite",
|
|
1116
|
+
"defaultHighlightedValue",
|
|
1117
|
+
"defaultOpen",
|
|
1118
|
+
"defaultValue",
|
|
1119
|
+
"deselectable",
|
|
1120
|
+
"dir",
|
|
1121
|
+
"disabled",
|
|
1122
|
+
"form",
|
|
1123
|
+
"getRootNode",
|
|
1124
|
+
"highlightedValue",
|
|
1125
|
+
"id",
|
|
1126
|
+
"ids",
|
|
1127
|
+
"invalid",
|
|
1128
|
+
"loopFocus",
|
|
1129
|
+
"multiple",
|
|
1130
|
+
"name",
|
|
1131
|
+
"onFocusOutside",
|
|
1132
|
+
"onHighlightChange",
|
|
1133
|
+
"onInteractOutside",
|
|
1134
|
+
"onOpenChange",
|
|
1135
|
+
"onPointerDownOutside",
|
|
1136
|
+
"onSelect",
|
|
1137
|
+
"onValueChange",
|
|
1138
|
+
"open",
|
|
1139
|
+
"positioning",
|
|
1140
|
+
"readOnly",
|
|
1141
|
+
"required",
|
|
1142
|
+
"scrollToIndexFn",
|
|
1143
|
+
"value"
|
|
1144
|
+
]);
|
|
1145
|
+
const splitProps = require_utils.createSplitProps(props);
|
|
1146
|
+
const itemProps = require_create_props.createProps()(["item", "persistFocus"]);
|
|
1147
|
+
const splitItemProps = require_utils.createSplitProps(itemProps);
|
|
1148
|
+
const itemGroupProps = require_create_props.createProps()(["id"]);
|
|
1149
|
+
const splitItemGroupProps = require_utils.createSplitProps(itemGroupProps);
|
|
1150
|
+
const itemGroupLabelProps = require_create_props.createProps()(["htmlFor"]);
|
|
1151
|
+
const splitItemGroupLabelProps = require_utils.createSplitProps(itemGroupLabelProps);
|
|
1152
|
+
|
|
1153
|
+
//#endregion
|
|
1154
|
+
exports.anatomy = anatomy;
|
|
1155
|
+
exports.collection = collection;
|
|
1156
|
+
exports.connect = connect;
|
|
1157
|
+
exports.itemGroupLabelProps = itemGroupLabelProps;
|
|
1158
|
+
exports.itemGroupProps = itemGroupProps;
|
|
1159
|
+
exports.itemProps = itemProps;
|
|
1160
|
+
exports.machine = machine;
|
|
1161
|
+
exports.props = props;
|
|
1162
|
+
exports.splitItemGroupLabelProps = splitItemGroupLabelProps;
|
|
1163
|
+
exports.splitItemGroupProps = splitItemGroupProps;
|
|
1164
|
+
exports.splitItemProps = splitItemProps;
|
|
1165
|
+
exports.splitProps = splitProps;
|