@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,1271 @@
|
|
|
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
|
+
const require_create_props = require('../../create-props-YKy7JIKj.cjs');
|
|
7
|
+
|
|
8
|
+
//#region src/machines/tree-view/tree-view.anatomy.ts
|
|
9
|
+
const anatomy = require_create_anatomy.createAnatomy("tree-view").parts("branch", "branchContent", "branchControl", "branchIndentGuide", "branchIndicator", "branchText", "branchTrigger", "item", "itemIndicator", "itemText", "label", "nodeCheckbox", "nodeRenameInput", "root", "tree");
|
|
10
|
+
const parts = anatomy.build();
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/machines/tree-view/tree-view.collection.ts
|
|
14
|
+
const collection = (options) => {
|
|
15
|
+
return new require_collection.TreeCollection(options);
|
|
16
|
+
};
|
|
17
|
+
collection.empty = () => {
|
|
18
|
+
return new require_collection.TreeCollection({ rootNode: { children: [] } });
|
|
19
|
+
};
|
|
20
|
+
function filePathCollection(paths) {
|
|
21
|
+
return require_collection.filePathToTree(paths);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/machines/tree-view/tree-view.dom.ts
|
|
26
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `tree-view:${ctx.id}:root`;
|
|
27
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `tree-view:${ctx.id}:label`;
|
|
28
|
+
const getNodeId = (ctx, value) => ctx.ids?.node?.(value) ?? `tree-view:${ctx.id}:node:${value}`;
|
|
29
|
+
const getTreeId = (ctx) => ctx.ids?.tree ?? `tree-view:${ctx.id}:tree`;
|
|
30
|
+
const focusNode = (ctx, value) => {
|
|
31
|
+
if (value == null) return;
|
|
32
|
+
ctx.getById(getNodeId(ctx, value))?.focus();
|
|
33
|
+
};
|
|
34
|
+
const getRenameInputId = (ctx, value) => `tree-view:${ctx.id}:rename-input:${value}`;
|
|
35
|
+
const getRenameInputEl = (ctx, value) => {
|
|
36
|
+
return ctx.getById(getRenameInputId(ctx, value));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/machines/tree-view/utils/checked-state.ts
|
|
41
|
+
function getCheckedState(collection$1, node, checkedValue) {
|
|
42
|
+
const value = collection$1.getNodeValue(node);
|
|
43
|
+
if (!collection$1.isBranchNode(node)) return checkedValue.includes(value);
|
|
44
|
+
const childValues = collection$1.getDescendantValues(value);
|
|
45
|
+
const allChecked = childValues.every((v) => checkedValue.includes(v));
|
|
46
|
+
const someChecked = childValues.some((v) => checkedValue.includes(v));
|
|
47
|
+
return allChecked ? true : someChecked ? "indeterminate" : false;
|
|
48
|
+
}
|
|
49
|
+
function toggleBranchChecked(collection$1, value, checkedValue) {
|
|
50
|
+
const childValues = collection$1.getDescendantValues(value);
|
|
51
|
+
return require_utils.uniq(childValues.every((child) => checkedValue.includes(child)) ? require_utils.remove(checkedValue, ...childValues) : require_utils.add(checkedValue, ...childValues));
|
|
52
|
+
}
|
|
53
|
+
function getCheckedValueMap(collection$1, checkedValue) {
|
|
54
|
+
const map = /* @__PURE__ */ new Map();
|
|
55
|
+
collection$1.visit({ onEnter: (node) => {
|
|
56
|
+
const value = collection$1.getNodeValue(node);
|
|
57
|
+
const isBranch = collection$1.isBranchNode(node);
|
|
58
|
+
const checked = getCheckedState(collection$1, node, checkedValue);
|
|
59
|
+
map.set(value, {
|
|
60
|
+
type: isBranch ? "branch" : "leaf",
|
|
61
|
+
checked
|
|
62
|
+
});
|
|
63
|
+
} });
|
|
64
|
+
return map;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/machines/tree-view/tree-view.connect.ts
|
|
69
|
+
function connect(service, normalize) {
|
|
70
|
+
const { context, scope, computed, prop, send } = service;
|
|
71
|
+
const collection$1 = prop("collection");
|
|
72
|
+
const expandedValue = Array.from(context.get("expandedValue"));
|
|
73
|
+
const selectedValue = Array.from(context.get("selectedValue"));
|
|
74
|
+
const checkedValue = Array.from(context.get("checkedValue"));
|
|
75
|
+
const isTypingAhead = computed("isTypingAhead");
|
|
76
|
+
const focusedValue = context.get("focusedValue");
|
|
77
|
+
const loadingStatus = context.get("loadingStatus");
|
|
78
|
+
const renamingValue = context.get("renamingValue");
|
|
79
|
+
function getNodeState(props$1) {
|
|
80
|
+
const { node, indexPath } = props$1;
|
|
81
|
+
const value = collection$1.getNodeValue(node);
|
|
82
|
+
const firstNode = collection$1.getFirstNode();
|
|
83
|
+
const firstNodeValue = firstNode ? collection$1.getNodeValue(firstNode) : null;
|
|
84
|
+
return {
|
|
85
|
+
id: getNodeId(scope, value),
|
|
86
|
+
value,
|
|
87
|
+
indexPath,
|
|
88
|
+
valuePath: collection$1.getValuePath(indexPath),
|
|
89
|
+
disabled: Boolean(node.disabled),
|
|
90
|
+
focused: focusedValue == null ? firstNodeValue == value : focusedValue === value,
|
|
91
|
+
selected: selectedValue.includes(value),
|
|
92
|
+
expanded: expandedValue.includes(value),
|
|
93
|
+
loading: loadingStatus[value] === "loading",
|
|
94
|
+
depth: indexPath.length,
|
|
95
|
+
isBranch: collection$1.isBranchNode(node),
|
|
96
|
+
renaming: renamingValue === value,
|
|
97
|
+
get checked() {
|
|
98
|
+
return getCheckedState(collection$1, node, checkedValue);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
collection: collection$1,
|
|
104
|
+
expandedValue,
|
|
105
|
+
selectedValue,
|
|
106
|
+
checkedValue,
|
|
107
|
+
toggleChecked(value, isBranch) {
|
|
108
|
+
send({
|
|
109
|
+
type: "CHECKED.TOGGLE",
|
|
110
|
+
value,
|
|
111
|
+
isBranch
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
setChecked(value) {
|
|
115
|
+
send({
|
|
116
|
+
type: "CHECKED.SET",
|
|
117
|
+
value
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
clearChecked() {
|
|
121
|
+
send({ type: "CHECKED.CLEAR" });
|
|
122
|
+
},
|
|
123
|
+
getCheckedMap() {
|
|
124
|
+
return getCheckedValueMap(collection$1, checkedValue);
|
|
125
|
+
},
|
|
126
|
+
expand(value) {
|
|
127
|
+
send({
|
|
128
|
+
type: value ? "BRANCH.EXPAND" : "EXPANDED.ALL",
|
|
129
|
+
value
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
collapse(value) {
|
|
133
|
+
send({
|
|
134
|
+
type: value ? "BRANCH.COLLAPSE" : "EXPANDED.CLEAR",
|
|
135
|
+
value
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
deselect(value) {
|
|
139
|
+
send({
|
|
140
|
+
type: value ? "NODE.DESELECT" : "SELECTED.CLEAR",
|
|
141
|
+
value
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
select(value) {
|
|
145
|
+
send({
|
|
146
|
+
type: value ? "NODE.SELECT" : "SELECTED.ALL",
|
|
147
|
+
value,
|
|
148
|
+
isTrusted: false
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
getVisibleNodes() {
|
|
152
|
+
return computed("visibleNodes");
|
|
153
|
+
},
|
|
154
|
+
focus(value) {
|
|
155
|
+
focusNode(scope, value);
|
|
156
|
+
},
|
|
157
|
+
selectParent(value) {
|
|
158
|
+
const parentNode = collection$1.getParentNode(value);
|
|
159
|
+
if (!parentNode) return;
|
|
160
|
+
send({
|
|
161
|
+
type: "SELECTED.SET",
|
|
162
|
+
value: require_utils.add(selectedValue, collection$1.getNodeValue(parentNode)),
|
|
163
|
+
src: "select.parent"
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
expandParent(value) {
|
|
167
|
+
const parentNode = collection$1.getParentNode(value);
|
|
168
|
+
if (!parentNode) return;
|
|
169
|
+
send({
|
|
170
|
+
type: "EXPANDED.SET",
|
|
171
|
+
value: require_utils.add(expandedValue, collection$1.getNodeValue(parentNode)),
|
|
172
|
+
src: "expand.parent"
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
setExpandedValue(value) {
|
|
176
|
+
send({
|
|
177
|
+
type: "EXPANDED.SET",
|
|
178
|
+
value: require_utils.uniq(value)
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
setSelectedValue(value) {
|
|
182
|
+
send({
|
|
183
|
+
type: "SELECTED.SET",
|
|
184
|
+
value: require_utils.uniq(value)
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
startRenaming(value) {
|
|
188
|
+
send({
|
|
189
|
+
type: "NODE.RENAME",
|
|
190
|
+
value
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
submitRenaming(value, label) {
|
|
194
|
+
send({
|
|
195
|
+
type: "RENAME.SUBMIT",
|
|
196
|
+
value,
|
|
197
|
+
label
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
cancelRenaming() {
|
|
201
|
+
send({ type: "RENAME.CANCEL" });
|
|
202
|
+
},
|
|
203
|
+
getRootProps() {
|
|
204
|
+
return normalize.element({
|
|
205
|
+
...parts.root.attrs,
|
|
206
|
+
id: getRootId(scope),
|
|
207
|
+
dir: prop("dir")
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
getLabelProps() {
|
|
211
|
+
return normalize.element({
|
|
212
|
+
...parts.label.attrs,
|
|
213
|
+
id: getLabelId(scope),
|
|
214
|
+
dir: prop("dir")
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
getTreeProps() {
|
|
218
|
+
return normalize.element({
|
|
219
|
+
...parts.tree.attrs,
|
|
220
|
+
id: getTreeId(scope),
|
|
221
|
+
dir: prop("dir"),
|
|
222
|
+
role: "tree",
|
|
223
|
+
"aria-label": "Tree View",
|
|
224
|
+
"aria-labelledby": getLabelId(scope),
|
|
225
|
+
"aria-multiselectable": prop("selectionMode") === "multiple" || void 0,
|
|
226
|
+
tabIndex: -1,
|
|
227
|
+
onKeyDown(event) {
|
|
228
|
+
if (event.defaultPrevented) return;
|
|
229
|
+
if (require_dom_query.isComposingEvent(event)) return;
|
|
230
|
+
const target = require_dom_query.getEventTarget(event);
|
|
231
|
+
if (require_dom_query.isEditableElement(target)) return;
|
|
232
|
+
const node = target?.closest("[data-part=branch-control], [data-part=item]");
|
|
233
|
+
if (!node) return;
|
|
234
|
+
const nodeId = node.dataset.value;
|
|
235
|
+
if (nodeId == null) {
|
|
236
|
+
console.warn(`[sprawlify-js/tree-view] Node id not found for node`, node);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const isBranchNode = node.matches("[data-part=branch-control]");
|
|
240
|
+
const keyMap = {
|
|
241
|
+
ArrowDown(event$1) {
|
|
242
|
+
if (require_dom_query.isModifierKey(event$1)) return;
|
|
243
|
+
event$1.preventDefault();
|
|
244
|
+
send({
|
|
245
|
+
type: "NODE.ARROW_DOWN",
|
|
246
|
+
id: nodeId,
|
|
247
|
+
shiftKey: event$1.shiftKey
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
ArrowUp(event$1) {
|
|
251
|
+
if (require_dom_query.isModifierKey(event$1)) return;
|
|
252
|
+
event$1.preventDefault();
|
|
253
|
+
send({
|
|
254
|
+
type: "NODE.ARROW_UP",
|
|
255
|
+
id: nodeId,
|
|
256
|
+
shiftKey: event$1.shiftKey
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
ArrowLeft(event$1) {
|
|
260
|
+
if (require_dom_query.isModifierKey(event$1) || node.dataset.disabled) return;
|
|
261
|
+
event$1.preventDefault();
|
|
262
|
+
send({
|
|
263
|
+
type: isBranchNode ? "BRANCH_NODE.ARROW_LEFT" : "NODE.ARROW_LEFT",
|
|
264
|
+
id: nodeId
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
ArrowRight(event$1) {
|
|
268
|
+
if (!isBranchNode || node.dataset.disabled) return;
|
|
269
|
+
event$1.preventDefault();
|
|
270
|
+
send({
|
|
271
|
+
type: "BRANCH_NODE.ARROW_RIGHT",
|
|
272
|
+
id: nodeId
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
Home(event$1) {
|
|
276
|
+
if (require_dom_query.isModifierKey(event$1)) return;
|
|
277
|
+
event$1.preventDefault();
|
|
278
|
+
send({
|
|
279
|
+
type: "NODE.HOME",
|
|
280
|
+
id: nodeId,
|
|
281
|
+
shiftKey: event$1.shiftKey
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
End(event$1) {
|
|
285
|
+
if (require_dom_query.isModifierKey(event$1)) return;
|
|
286
|
+
event$1.preventDefault();
|
|
287
|
+
send({
|
|
288
|
+
type: "NODE.END",
|
|
289
|
+
id: nodeId,
|
|
290
|
+
shiftKey: event$1.shiftKey
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
Space(event$1) {
|
|
294
|
+
if (node.dataset.disabled) return;
|
|
295
|
+
if (isTypingAhead) send({
|
|
296
|
+
type: "TREE.TYPEAHEAD",
|
|
297
|
+
key: event$1.key
|
|
298
|
+
});
|
|
299
|
+
else keyMap.Enter?.(event$1);
|
|
300
|
+
},
|
|
301
|
+
Enter(event$1) {
|
|
302
|
+
if (node.dataset.disabled) return;
|
|
303
|
+
if (require_dom_query.isAnchorElement(target) && require_dom_query.isModifierKey(event$1)) return;
|
|
304
|
+
send({
|
|
305
|
+
type: isBranchNode ? "BRANCH_NODE.CLICK" : "NODE.CLICK",
|
|
306
|
+
id: nodeId,
|
|
307
|
+
src: "keyboard"
|
|
308
|
+
});
|
|
309
|
+
if (!require_dom_query.isAnchorElement(target)) event$1.preventDefault();
|
|
310
|
+
},
|
|
311
|
+
"*"(event$1) {
|
|
312
|
+
if (node.dataset.disabled) return;
|
|
313
|
+
event$1.preventDefault();
|
|
314
|
+
send({
|
|
315
|
+
type: "SIBLINGS.EXPAND",
|
|
316
|
+
id: nodeId
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
a(event$1) {
|
|
320
|
+
if (!event$1.metaKey || node.dataset.disabled) return;
|
|
321
|
+
event$1.preventDefault();
|
|
322
|
+
send({
|
|
323
|
+
type: "SELECTED.ALL",
|
|
324
|
+
moveFocus: true
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
F2(event$1) {
|
|
328
|
+
if (node.dataset.disabled) return;
|
|
329
|
+
const canRenameFn = prop("canRename");
|
|
330
|
+
if (!canRenameFn) return;
|
|
331
|
+
const indexPath = collection$1.getIndexPath(nodeId);
|
|
332
|
+
if (indexPath) {
|
|
333
|
+
const node$1 = collection$1.at(indexPath);
|
|
334
|
+
if (node$1 && !canRenameFn(node$1, indexPath)) return;
|
|
335
|
+
}
|
|
336
|
+
event$1.preventDefault();
|
|
337
|
+
send({
|
|
338
|
+
type: "NODE.RENAME",
|
|
339
|
+
value: nodeId
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const exec = keyMap[require_dom_query.getEventKey(event, { dir: prop("dir") })];
|
|
344
|
+
if (exec) {
|
|
345
|
+
exec(event);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (!require_dom_query.getByTypeahead.isValidEvent(event)) return;
|
|
349
|
+
send({
|
|
350
|
+
type: "TREE.TYPEAHEAD",
|
|
351
|
+
key: event.key,
|
|
352
|
+
id: nodeId
|
|
353
|
+
});
|
|
354
|
+
event.preventDefault();
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
},
|
|
358
|
+
getNodeState,
|
|
359
|
+
getItemProps(props$1) {
|
|
360
|
+
const nodeState = getNodeState(props$1);
|
|
361
|
+
return normalize.element({
|
|
362
|
+
...parts.item.attrs,
|
|
363
|
+
id: nodeState.id,
|
|
364
|
+
dir: prop("dir"),
|
|
365
|
+
"data-ownedby": getTreeId(scope),
|
|
366
|
+
"data-path": props$1.indexPath.join("/"),
|
|
367
|
+
"data-value": nodeState.value,
|
|
368
|
+
tabIndex: nodeState.focused ? 0 : -1,
|
|
369
|
+
"data-focus": require_dom_query.dataAttr(nodeState.focused),
|
|
370
|
+
role: "treeitem",
|
|
371
|
+
"aria-current": nodeState.selected ? "true" : void 0,
|
|
372
|
+
"aria-selected": nodeState.disabled ? void 0 : nodeState.selected,
|
|
373
|
+
"data-selected": require_dom_query.dataAttr(nodeState.selected),
|
|
374
|
+
"aria-disabled": require_dom_query.ariaAttr(nodeState.disabled),
|
|
375
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
376
|
+
"data-renaming": require_dom_query.dataAttr(nodeState.renaming),
|
|
377
|
+
"aria-level": nodeState.depth,
|
|
378
|
+
"data-depth": nodeState.depth,
|
|
379
|
+
style: { "--depth": nodeState.depth },
|
|
380
|
+
onFocus(event) {
|
|
381
|
+
event.stopPropagation();
|
|
382
|
+
send({
|
|
383
|
+
type: "NODE.FOCUS",
|
|
384
|
+
id: nodeState.value
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
onClick(event) {
|
|
388
|
+
if (nodeState.disabled) return;
|
|
389
|
+
if (!require_dom_query.isLeftClick(event)) return;
|
|
390
|
+
if (require_dom_query.isAnchorElement(event.currentTarget) && require_dom_query.isModifierKey(event)) return;
|
|
391
|
+
const isMetaKey = event.metaKey || event.ctrlKey;
|
|
392
|
+
send({
|
|
393
|
+
type: "NODE.CLICK",
|
|
394
|
+
id: nodeState.value,
|
|
395
|
+
shiftKey: event.shiftKey,
|
|
396
|
+
ctrlKey: isMetaKey
|
|
397
|
+
});
|
|
398
|
+
event.stopPropagation();
|
|
399
|
+
if (!require_dom_query.isAnchorElement(event.currentTarget)) event.preventDefault();
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
getItemTextProps(props$1) {
|
|
404
|
+
const itemState = getNodeState(props$1);
|
|
405
|
+
return normalize.element({
|
|
406
|
+
...parts.itemText.attrs,
|
|
407
|
+
"data-disabled": require_dom_query.dataAttr(itemState.disabled),
|
|
408
|
+
"data-selected": require_dom_query.dataAttr(itemState.selected),
|
|
409
|
+
"data-focus": require_dom_query.dataAttr(itemState.focused)
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
getItemIndicatorProps(props$1) {
|
|
413
|
+
const itemState = getNodeState(props$1);
|
|
414
|
+
return normalize.element({
|
|
415
|
+
...parts.itemIndicator.attrs,
|
|
416
|
+
"aria-hidden": true,
|
|
417
|
+
"data-disabled": require_dom_query.dataAttr(itemState.disabled),
|
|
418
|
+
"data-selected": require_dom_query.dataAttr(itemState.selected),
|
|
419
|
+
"data-focus": require_dom_query.dataAttr(itemState.focused),
|
|
420
|
+
hidden: !itemState.selected
|
|
421
|
+
});
|
|
422
|
+
},
|
|
423
|
+
getBranchProps(props$1) {
|
|
424
|
+
const nodeState = getNodeState(props$1);
|
|
425
|
+
return normalize.element({
|
|
426
|
+
...parts.branch.attrs,
|
|
427
|
+
"data-depth": nodeState.depth,
|
|
428
|
+
dir: prop("dir"),
|
|
429
|
+
"data-branch": nodeState.value,
|
|
430
|
+
role: "treeitem",
|
|
431
|
+
"data-ownedby": getTreeId(scope),
|
|
432
|
+
"data-value": nodeState.value,
|
|
433
|
+
"aria-level": nodeState.depth,
|
|
434
|
+
"aria-selected": nodeState.disabled ? void 0 : nodeState.selected,
|
|
435
|
+
"data-path": props$1.indexPath.join("/"),
|
|
436
|
+
"data-selected": require_dom_query.dataAttr(nodeState.selected),
|
|
437
|
+
"aria-expanded": nodeState.expanded,
|
|
438
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
439
|
+
"aria-disabled": require_dom_query.ariaAttr(nodeState.disabled),
|
|
440
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
441
|
+
"data-loading": require_dom_query.dataAttr(nodeState.loading),
|
|
442
|
+
"aria-busy": require_dom_query.ariaAttr(nodeState.loading),
|
|
443
|
+
style: { "--depth": nodeState.depth }
|
|
444
|
+
});
|
|
445
|
+
},
|
|
446
|
+
getBranchIndicatorProps(props$1) {
|
|
447
|
+
const nodeState = getNodeState(props$1);
|
|
448
|
+
return normalize.element({
|
|
449
|
+
...parts.branchIndicator.attrs,
|
|
450
|
+
"aria-hidden": true,
|
|
451
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
452
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
453
|
+
"data-selected": require_dom_query.dataAttr(nodeState.selected),
|
|
454
|
+
"data-focus": require_dom_query.dataAttr(nodeState.focused),
|
|
455
|
+
"data-loading": require_dom_query.dataAttr(nodeState.loading)
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
getBranchTriggerProps(props$1) {
|
|
459
|
+
const nodeState = getNodeState(props$1);
|
|
460
|
+
return normalize.element({
|
|
461
|
+
...parts.branchTrigger.attrs,
|
|
462
|
+
role: "button",
|
|
463
|
+
dir: prop("dir"),
|
|
464
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
465
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
466
|
+
"data-value": nodeState.value,
|
|
467
|
+
"data-loading": require_dom_query.dataAttr(nodeState.loading),
|
|
468
|
+
disabled: nodeState.loading,
|
|
469
|
+
onClick(event) {
|
|
470
|
+
if (nodeState.disabled || nodeState.loading) return;
|
|
471
|
+
send({
|
|
472
|
+
type: "BRANCH_TOGGLE.CLICK",
|
|
473
|
+
id: nodeState.value
|
|
474
|
+
});
|
|
475
|
+
event.stopPropagation();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
getBranchControlProps(props$1) {
|
|
480
|
+
const nodeState = getNodeState(props$1);
|
|
481
|
+
return normalize.element({
|
|
482
|
+
...parts.branchControl.attrs,
|
|
483
|
+
role: "button",
|
|
484
|
+
id: nodeState.id,
|
|
485
|
+
dir: prop("dir"),
|
|
486
|
+
tabIndex: nodeState.focused ? 0 : -1,
|
|
487
|
+
"data-path": props$1.indexPath.join("/"),
|
|
488
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
489
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
490
|
+
"data-selected": require_dom_query.dataAttr(nodeState.selected),
|
|
491
|
+
"data-focus": require_dom_query.dataAttr(nodeState.focused),
|
|
492
|
+
"data-renaming": require_dom_query.dataAttr(nodeState.renaming),
|
|
493
|
+
"data-value": nodeState.value,
|
|
494
|
+
"data-depth": nodeState.depth,
|
|
495
|
+
"data-loading": require_dom_query.dataAttr(nodeState.loading),
|
|
496
|
+
"aria-busy": require_dom_query.ariaAttr(nodeState.loading),
|
|
497
|
+
onFocus(event) {
|
|
498
|
+
send({
|
|
499
|
+
type: "NODE.FOCUS",
|
|
500
|
+
id: nodeState.value
|
|
501
|
+
});
|
|
502
|
+
event.stopPropagation();
|
|
503
|
+
},
|
|
504
|
+
onClick(event) {
|
|
505
|
+
if (nodeState.disabled) return;
|
|
506
|
+
if (nodeState.loading) return;
|
|
507
|
+
if (!require_dom_query.isLeftClick(event)) return;
|
|
508
|
+
if (require_dom_query.isAnchorElement(event.currentTarget) && require_dom_query.isModifierKey(event)) return;
|
|
509
|
+
const isMetaKey = event.metaKey || event.ctrlKey;
|
|
510
|
+
send({
|
|
511
|
+
type: "BRANCH_NODE.CLICK",
|
|
512
|
+
id: nodeState.value,
|
|
513
|
+
shiftKey: event.shiftKey,
|
|
514
|
+
ctrlKey: isMetaKey
|
|
515
|
+
});
|
|
516
|
+
event.stopPropagation();
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
},
|
|
520
|
+
getBranchTextProps(props$1) {
|
|
521
|
+
const nodeState = getNodeState(props$1);
|
|
522
|
+
return normalize.element({
|
|
523
|
+
...parts.branchText.attrs,
|
|
524
|
+
dir: prop("dir"),
|
|
525
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
526
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
527
|
+
"data-loading": require_dom_query.dataAttr(nodeState.loading)
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
getBranchContentProps(props$1) {
|
|
531
|
+
const nodeState = getNodeState(props$1);
|
|
532
|
+
return normalize.element({
|
|
533
|
+
...parts.branchContent.attrs,
|
|
534
|
+
role: "group",
|
|
535
|
+
dir: prop("dir"),
|
|
536
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
537
|
+
"data-depth": nodeState.depth,
|
|
538
|
+
"data-path": props$1.indexPath.join("/"),
|
|
539
|
+
"data-value": nodeState.value,
|
|
540
|
+
hidden: !nodeState.expanded
|
|
541
|
+
});
|
|
542
|
+
},
|
|
543
|
+
getBranchIndentGuideProps(props$1) {
|
|
544
|
+
const nodeState = getNodeState(props$1);
|
|
545
|
+
return normalize.element({
|
|
546
|
+
...parts.branchIndentGuide.attrs,
|
|
547
|
+
"data-depth": nodeState.depth
|
|
548
|
+
});
|
|
549
|
+
},
|
|
550
|
+
getNodeCheckboxProps(props$1) {
|
|
551
|
+
const nodeState = getNodeState(props$1);
|
|
552
|
+
const checkedState = nodeState.checked;
|
|
553
|
+
return normalize.element({
|
|
554
|
+
...parts.nodeCheckbox.attrs,
|
|
555
|
+
tabIndex: -1,
|
|
556
|
+
role: "checkbox",
|
|
557
|
+
"data-state": checkedState === true ? "checked" : checkedState === false ? "unchecked" : "indeterminate",
|
|
558
|
+
"aria-checked": checkedState === true ? "true" : checkedState === false ? "false" : "mixed",
|
|
559
|
+
"data-disabled": require_dom_query.dataAttr(nodeState.disabled),
|
|
560
|
+
onClick(event) {
|
|
561
|
+
if (event.defaultPrevented) return;
|
|
562
|
+
if (nodeState.disabled) return;
|
|
563
|
+
if (!require_dom_query.isLeftClick(event)) return;
|
|
564
|
+
send({
|
|
565
|
+
type: "CHECKED.TOGGLE",
|
|
566
|
+
value: nodeState.value,
|
|
567
|
+
isBranch: nodeState.isBranch
|
|
568
|
+
});
|
|
569
|
+
event.stopPropagation();
|
|
570
|
+
event.currentTarget.closest("[role=treeitem]")?.focus({ preventScroll: true });
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
},
|
|
574
|
+
getNodeRenameInputProps(props$1) {
|
|
575
|
+
const nodeState = getNodeState(props$1);
|
|
576
|
+
return normalize.input({
|
|
577
|
+
...parts.nodeRenameInput.attrs,
|
|
578
|
+
id: getRenameInputId(scope, nodeState.value),
|
|
579
|
+
type: "text",
|
|
580
|
+
"aria-label": "Rename tree item",
|
|
581
|
+
hidden: !nodeState.renaming,
|
|
582
|
+
onKeyDown(event) {
|
|
583
|
+
if (require_dom_query.isComposingEvent(event)) return;
|
|
584
|
+
if (event.key === "Escape") {
|
|
585
|
+
send({ type: "RENAME.CANCEL" });
|
|
586
|
+
event.preventDefault();
|
|
587
|
+
}
|
|
588
|
+
if (event.key === "Enter") {
|
|
589
|
+
send({
|
|
590
|
+
type: "RENAME.SUBMIT",
|
|
591
|
+
label: event.currentTarget.value
|
|
592
|
+
});
|
|
593
|
+
event.preventDefault();
|
|
594
|
+
}
|
|
595
|
+
event.stopPropagation();
|
|
596
|
+
},
|
|
597
|
+
onBlur(event) {
|
|
598
|
+
send({
|
|
599
|
+
type: "RENAME.SUBMIT",
|
|
600
|
+
label: event.currentTarget.value
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/machines/tree-view/utils/expand-branch.ts
|
|
610
|
+
function expandBranches(params, values) {
|
|
611
|
+
const { context, prop, refs } = params;
|
|
612
|
+
if (!prop("loadChildren")) {
|
|
613
|
+
context.set("expandedValue", (prev) => require_utils.uniq(require_utils.add(prev, ...values)));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const loadingStatus = context.get("loadingStatus");
|
|
617
|
+
const [loadedValues, loadingValues] = require_utils.partition(values, (value) => loadingStatus[value] === "loaded");
|
|
618
|
+
if (loadedValues.length > 0) context.set("expandedValue", (prev) => require_utils.uniq(require_utils.add(prev, ...loadedValues)));
|
|
619
|
+
if (loadingValues.length === 0) return;
|
|
620
|
+
const collection$1 = prop("collection");
|
|
621
|
+
const [nodeWithChildren, nodeWithoutChildren] = require_utils.partition(loadingValues, (id) => {
|
|
622
|
+
const node = collection$1.findNode(id);
|
|
623
|
+
return collection$1.getNodeChildren(node).length > 0;
|
|
624
|
+
});
|
|
625
|
+
if (nodeWithChildren.length > 0) context.set("expandedValue", (prev) => require_utils.uniq(require_utils.add(prev, ...nodeWithChildren)));
|
|
626
|
+
if (nodeWithoutChildren.length === 0) return;
|
|
627
|
+
context.set("loadingStatus", (prev) => ({
|
|
628
|
+
...prev,
|
|
629
|
+
...nodeWithoutChildren.reduce((acc, id) => ({
|
|
630
|
+
...acc,
|
|
631
|
+
[id]: "loading"
|
|
632
|
+
}), {})
|
|
633
|
+
}));
|
|
634
|
+
const nodesToLoad = nodeWithoutChildren.map((id) => {
|
|
635
|
+
const indexPath = collection$1.getIndexPath(id);
|
|
636
|
+
return {
|
|
637
|
+
id,
|
|
638
|
+
indexPath,
|
|
639
|
+
valuePath: collection$1.getValuePath(indexPath),
|
|
640
|
+
node: collection$1.findNode(id)
|
|
641
|
+
};
|
|
642
|
+
});
|
|
643
|
+
const pendingAborts = refs.get("pendingAborts");
|
|
644
|
+
const loadChildren = prop("loadChildren");
|
|
645
|
+
require_utils.ensure(loadChildren, () => "[sprawlify-js/tree-view] `loadChildren` is required for async expansion");
|
|
646
|
+
const proms = nodesToLoad.map(({ id, indexPath, valuePath, node }) => {
|
|
647
|
+
const existingAbort = pendingAborts.get(id);
|
|
648
|
+
if (existingAbort) {
|
|
649
|
+
existingAbort.abort();
|
|
650
|
+
pendingAborts.delete(id);
|
|
651
|
+
}
|
|
652
|
+
const abortController = new AbortController();
|
|
653
|
+
pendingAborts.set(id, abortController);
|
|
654
|
+
return loadChildren({
|
|
655
|
+
valuePath,
|
|
656
|
+
indexPath,
|
|
657
|
+
node,
|
|
658
|
+
signal: abortController.signal
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
Promise.allSettled(proms).then((results) => {
|
|
662
|
+
const loadedValues$1 = [];
|
|
663
|
+
const nodeWithErrors = [];
|
|
664
|
+
const nextLoadingStatus = context.get("loadingStatus");
|
|
665
|
+
let collection$2 = prop("collection");
|
|
666
|
+
results.forEach((result, index) => {
|
|
667
|
+
const { id, indexPath, node, valuePath } = nodesToLoad[index];
|
|
668
|
+
if (result.status === "fulfilled") {
|
|
669
|
+
nextLoadingStatus[id] = "loaded";
|
|
670
|
+
loadedValues$1.push(id);
|
|
671
|
+
collection$2 = collection$2.replace(indexPath, {
|
|
672
|
+
...node,
|
|
673
|
+
children: result.value
|
|
674
|
+
});
|
|
675
|
+
} else {
|
|
676
|
+
pendingAborts.delete(id);
|
|
677
|
+
Reflect.deleteProperty(nextLoadingStatus, id);
|
|
678
|
+
nodeWithErrors.push({
|
|
679
|
+
node,
|
|
680
|
+
error: result.reason,
|
|
681
|
+
indexPath,
|
|
682
|
+
valuePath
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
context.set("loadingStatus", nextLoadingStatus);
|
|
687
|
+
if (loadedValues$1.length) {
|
|
688
|
+
context.set("expandedValue", (prev) => require_utils.uniq(require_utils.add(prev, ...loadedValues$1)));
|
|
689
|
+
prop("onLoadChildrenComplete")?.({ collection: collection$2 });
|
|
690
|
+
}
|
|
691
|
+
if (nodeWithErrors.length) prop("onLoadChildrenError")?.({ nodes: nodeWithErrors });
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region src/machines/tree-view/utils/visit-skip.ts
|
|
697
|
+
function skipFn(params) {
|
|
698
|
+
const { prop, context } = params;
|
|
699
|
+
return function skip({ indexPath }) {
|
|
700
|
+
return prop("collection").getValuePath(indexPath).slice(0, -1).some((value) => !context.get("expandedValue").includes(value));
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/machines/tree-view/tree-view.machine.ts
|
|
706
|
+
const { and } = require_core.createGuards();
|
|
707
|
+
const machine = require_core.createMachine({
|
|
708
|
+
props({ props: props$1 }) {
|
|
709
|
+
return {
|
|
710
|
+
selectionMode: "single",
|
|
711
|
+
collection: collection.empty(),
|
|
712
|
+
typeahead: true,
|
|
713
|
+
expandOnClick: true,
|
|
714
|
+
defaultExpandedValue: [],
|
|
715
|
+
defaultSelectedValue: [],
|
|
716
|
+
...props$1
|
|
717
|
+
};
|
|
718
|
+
},
|
|
719
|
+
initialState() {
|
|
720
|
+
return "idle";
|
|
721
|
+
},
|
|
722
|
+
context({ prop, bindable, getContext }) {
|
|
723
|
+
return {
|
|
724
|
+
expandedValue: bindable(() => ({
|
|
725
|
+
defaultValue: prop("defaultExpandedValue"),
|
|
726
|
+
value: prop("expandedValue"),
|
|
727
|
+
isEqual: require_utils.isEqual,
|
|
728
|
+
onChange(expandedValue) {
|
|
729
|
+
const focusedValue = getContext().get("focusedValue");
|
|
730
|
+
prop("onExpandedChange")?.({
|
|
731
|
+
expandedValue,
|
|
732
|
+
focusedValue,
|
|
733
|
+
get expandedNodes() {
|
|
734
|
+
return prop("collection").findNodes(expandedValue);
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
})),
|
|
739
|
+
selectedValue: bindable(() => ({
|
|
740
|
+
defaultValue: prop("defaultSelectedValue"),
|
|
741
|
+
value: prop("selectedValue"),
|
|
742
|
+
isEqual: require_utils.isEqual,
|
|
743
|
+
onChange(selectedValue) {
|
|
744
|
+
const focusedValue = getContext().get("focusedValue");
|
|
745
|
+
prop("onSelectionChange")?.({
|
|
746
|
+
selectedValue,
|
|
747
|
+
focusedValue,
|
|
748
|
+
get selectedNodes() {
|
|
749
|
+
return prop("collection").findNodes(selectedValue);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
})),
|
|
754
|
+
focusedValue: bindable(() => ({
|
|
755
|
+
defaultValue: prop("defaultFocusedValue") || null,
|
|
756
|
+
value: prop("focusedValue"),
|
|
757
|
+
onChange(focusedValue) {
|
|
758
|
+
prop("onFocusChange")?.({
|
|
759
|
+
focusedValue,
|
|
760
|
+
get focusedNode() {
|
|
761
|
+
return focusedValue ? prop("collection").findNode(focusedValue) : null;
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
})),
|
|
766
|
+
loadingStatus: bindable(() => ({ defaultValue: {} })),
|
|
767
|
+
checkedValue: bindable(() => ({
|
|
768
|
+
defaultValue: prop("defaultCheckedValue") || [],
|
|
769
|
+
value: prop("checkedValue"),
|
|
770
|
+
isEqual: require_utils.isEqual,
|
|
771
|
+
onChange(value) {
|
|
772
|
+
prop("onCheckedChange")?.({ checkedValue: value });
|
|
773
|
+
}
|
|
774
|
+
})),
|
|
775
|
+
renamingValue: bindable(() => ({
|
|
776
|
+
sync: true,
|
|
777
|
+
defaultValue: null
|
|
778
|
+
}))
|
|
779
|
+
};
|
|
780
|
+
},
|
|
781
|
+
refs() {
|
|
782
|
+
return {
|
|
783
|
+
typeaheadState: { ...require_dom_query.getByTypeahead.defaultOptions },
|
|
784
|
+
pendingAborts: /* @__PURE__ */ new Map()
|
|
785
|
+
};
|
|
786
|
+
},
|
|
787
|
+
computed: {
|
|
788
|
+
isMultipleSelection: ({ prop }) => prop("selectionMode") === "multiple",
|
|
789
|
+
isTypingAhead: ({ refs }) => refs.get("typeaheadState").keysSoFar.length > 0,
|
|
790
|
+
visibleNodes: ({ prop, context }) => {
|
|
791
|
+
const nodes = [];
|
|
792
|
+
prop("collection").visit({
|
|
793
|
+
skip: skipFn({
|
|
794
|
+
prop,
|
|
795
|
+
context
|
|
796
|
+
}),
|
|
797
|
+
onEnter: (node, indexPath) => {
|
|
798
|
+
nodes.push({
|
|
799
|
+
node,
|
|
800
|
+
indexPath
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
return nodes;
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
on: {
|
|
808
|
+
"EXPANDED.SET": { actions: ["setExpanded"] },
|
|
809
|
+
"EXPANDED.CLEAR": { actions: ["clearExpanded"] },
|
|
810
|
+
"EXPANDED.ALL": { actions: ["expandAllBranches"] },
|
|
811
|
+
"BRANCH.EXPAND": { actions: ["expandBranches"] },
|
|
812
|
+
"BRANCH.COLLAPSE": { actions: ["collapseBranches"] },
|
|
813
|
+
"SELECTED.SET": { actions: ["setSelected"] },
|
|
814
|
+
"SELECTED.ALL": [{
|
|
815
|
+
guard: and("isMultipleSelection", "moveFocus"),
|
|
816
|
+
actions: ["selectAllNodes", "focusTreeLastNode"]
|
|
817
|
+
}, {
|
|
818
|
+
guard: "isMultipleSelection",
|
|
819
|
+
actions: ["selectAllNodes"]
|
|
820
|
+
}],
|
|
821
|
+
"SELECTED.CLEAR": { actions: ["clearSelected"] },
|
|
822
|
+
"NODE.SELECT": { actions: ["selectNode"] },
|
|
823
|
+
"NODE.DESELECT": { actions: ["deselectNode"] },
|
|
824
|
+
"CHECKED.TOGGLE": { actions: ["toggleChecked"] },
|
|
825
|
+
"CHECKED.SET": { actions: ["setChecked"] },
|
|
826
|
+
"CHECKED.CLEAR": { actions: ["clearChecked"] },
|
|
827
|
+
"NODE.FOCUS": { actions: ["setFocusedNode"] },
|
|
828
|
+
"NODE.ARROW_DOWN": [{
|
|
829
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
830
|
+
actions: ["focusTreeNextNode", "extendSelectionToNextNode"]
|
|
831
|
+
}, { actions: ["focusTreeNextNode"] }],
|
|
832
|
+
"NODE.ARROW_UP": [{
|
|
833
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
834
|
+
actions: ["focusTreePrevNode", "extendSelectionToPrevNode"]
|
|
835
|
+
}, { actions: ["focusTreePrevNode"] }],
|
|
836
|
+
"NODE.ARROW_LEFT": { actions: ["focusBranchNode"] },
|
|
837
|
+
"BRANCH_NODE.ARROW_LEFT": [{
|
|
838
|
+
guard: "isBranchExpanded",
|
|
839
|
+
actions: ["collapseBranch"]
|
|
840
|
+
}, { actions: ["focusBranchNode"] }],
|
|
841
|
+
"BRANCH_NODE.ARROW_RIGHT": [{
|
|
842
|
+
guard: and("isBranchFocused", "isBranchExpanded"),
|
|
843
|
+
actions: ["focusBranchFirstNode"]
|
|
844
|
+
}, { actions: ["expandBranch"] }],
|
|
845
|
+
"SIBLINGS.EXPAND": { actions: ["expandSiblingBranches"] },
|
|
846
|
+
"NODE.HOME": [{
|
|
847
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
848
|
+
actions: ["extendSelectionToFirstNode", "focusTreeFirstNode"]
|
|
849
|
+
}, { actions: ["focusTreeFirstNode"] }],
|
|
850
|
+
"NODE.END": [{
|
|
851
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
852
|
+
actions: ["extendSelectionToLastNode", "focusTreeLastNode"]
|
|
853
|
+
}, { actions: ["focusTreeLastNode"] }],
|
|
854
|
+
"NODE.CLICK": [
|
|
855
|
+
{
|
|
856
|
+
guard: and("isCtrlKey", "isMultipleSelection"),
|
|
857
|
+
actions: ["toggleNodeSelection"]
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
861
|
+
actions: ["extendSelectionToNode"]
|
|
862
|
+
},
|
|
863
|
+
{ actions: ["selectNode"] }
|
|
864
|
+
],
|
|
865
|
+
"BRANCH_NODE.CLICK": [
|
|
866
|
+
{
|
|
867
|
+
guard: and("isCtrlKey", "isMultipleSelection"),
|
|
868
|
+
actions: ["toggleNodeSelection"]
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
guard: and("isShiftKey", "isMultipleSelection"),
|
|
872
|
+
actions: ["extendSelectionToNode"]
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
guard: "expandOnClick",
|
|
876
|
+
actions: ["selectNode", "toggleBranchNode"]
|
|
877
|
+
},
|
|
878
|
+
{ actions: ["selectNode"] }
|
|
879
|
+
],
|
|
880
|
+
"BRANCH_TOGGLE.CLICK": { actions: ["toggleBranchNode"] },
|
|
881
|
+
"TREE.TYPEAHEAD": { actions: ["focusMatchedNode"] }
|
|
882
|
+
},
|
|
883
|
+
exit: ["clearPendingAborts"],
|
|
884
|
+
states: {
|
|
885
|
+
idle: { on: { "NODE.RENAME": {
|
|
886
|
+
target: "renaming",
|
|
887
|
+
actions: ["setRenamingValue"]
|
|
888
|
+
} } },
|
|
889
|
+
renaming: {
|
|
890
|
+
entry: ["syncRenameInput", "focusRenameInput"],
|
|
891
|
+
on: {
|
|
892
|
+
"RENAME.SUBMIT": {
|
|
893
|
+
guard: "isRenameLabelValid",
|
|
894
|
+
target: "idle",
|
|
895
|
+
actions: ["submitRenaming"]
|
|
896
|
+
},
|
|
897
|
+
"RENAME.CANCEL": {
|
|
898
|
+
target: "idle",
|
|
899
|
+
actions: ["cancelRenaming"]
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
implementations: {
|
|
905
|
+
guards: {
|
|
906
|
+
isBranchFocused: ({ context, event }) => context.get("focusedValue") === event.id,
|
|
907
|
+
isBranchExpanded: ({ context, event }) => context.get("expandedValue").includes(event.id),
|
|
908
|
+
isShiftKey: ({ event }) => event.shiftKey,
|
|
909
|
+
isCtrlKey: ({ event }) => event.ctrlKey,
|
|
910
|
+
hasSelectedItems: ({ context }) => context.get("selectedValue").length > 0,
|
|
911
|
+
isMultipleSelection: ({ prop }) => prop("selectionMode") === "multiple",
|
|
912
|
+
moveFocus: ({ event }) => !!event.moveFocus,
|
|
913
|
+
expandOnClick: ({ prop }) => !!prop("expandOnClick"),
|
|
914
|
+
isRenameLabelValid: ({ event }) => event.label.trim() !== ""
|
|
915
|
+
},
|
|
916
|
+
actions: {
|
|
917
|
+
selectNode({ context, event }) {
|
|
918
|
+
const value = event.id || event.value;
|
|
919
|
+
context.set("selectedValue", (prev) => {
|
|
920
|
+
if (value == null) return prev;
|
|
921
|
+
if (!event.isTrusted && require_utils.isArray(value)) return prev.concat(...value);
|
|
922
|
+
return [require_utils.isArray(value) ? require_utils.last(value) : value].filter(Boolean);
|
|
923
|
+
});
|
|
924
|
+
},
|
|
925
|
+
deselectNode({ context, event }) {
|
|
926
|
+
const value = require_utils.toArray(event.id || event.value);
|
|
927
|
+
context.set("selectedValue", (prev) => require_utils.remove(prev, ...value));
|
|
928
|
+
},
|
|
929
|
+
setFocusedNode({ context, event }) {
|
|
930
|
+
context.set("focusedValue", event.id);
|
|
931
|
+
},
|
|
932
|
+
clearFocusedNode({ context }) {
|
|
933
|
+
context.set("focusedValue", null);
|
|
934
|
+
},
|
|
935
|
+
clearSelectedItem({ context }) {
|
|
936
|
+
context.set("selectedValue", []);
|
|
937
|
+
},
|
|
938
|
+
toggleBranchNode({ context, event, action }) {
|
|
939
|
+
action(context.get("expandedValue").includes(event.id) ? ["collapseBranch"] : ["expandBranch"]);
|
|
940
|
+
},
|
|
941
|
+
expandBranch(params) {
|
|
942
|
+
const { event } = params;
|
|
943
|
+
expandBranches(params, [event.id]);
|
|
944
|
+
},
|
|
945
|
+
expandBranches(params) {
|
|
946
|
+
const { context, event } = params;
|
|
947
|
+
expandBranches(params, require_utils.diff(require_utils.toArray(event.value), context.get("expandedValue")));
|
|
948
|
+
},
|
|
949
|
+
collapseBranch({ context, event }) {
|
|
950
|
+
context.set("expandedValue", (prev) => require_utils.remove(prev, event.id));
|
|
951
|
+
},
|
|
952
|
+
collapseBranches(params) {
|
|
953
|
+
const { context, event } = params;
|
|
954
|
+
const value = require_utils.toArray(event.value);
|
|
955
|
+
context.set("expandedValue", (prev) => require_utils.remove(prev, ...value));
|
|
956
|
+
},
|
|
957
|
+
setExpanded({ context, event }) {
|
|
958
|
+
if (!require_utils.isArray(event.value)) return;
|
|
959
|
+
context.set("expandedValue", event.value);
|
|
960
|
+
},
|
|
961
|
+
clearExpanded({ context }) {
|
|
962
|
+
context.set("expandedValue", []);
|
|
963
|
+
},
|
|
964
|
+
setSelected({ context, event }) {
|
|
965
|
+
if (!require_utils.isArray(event.value)) return;
|
|
966
|
+
context.set("selectedValue", event.value);
|
|
967
|
+
},
|
|
968
|
+
clearSelected({ context }) {
|
|
969
|
+
context.set("selectedValue", []);
|
|
970
|
+
},
|
|
971
|
+
focusTreeFirstNode(params) {
|
|
972
|
+
const { prop, scope } = params;
|
|
973
|
+
const collection$1 = prop("collection");
|
|
974
|
+
const firstNode = collection$1.getFirstNode();
|
|
975
|
+
const firstValue = collection$1.getNodeValue(firstNode);
|
|
976
|
+
if (scrollToNode(params, firstValue)) require_dom_query.raf(() => focusNode(scope, firstValue));
|
|
977
|
+
else focusNode(scope, firstValue);
|
|
978
|
+
},
|
|
979
|
+
focusTreeLastNode(params) {
|
|
980
|
+
const { prop, scope } = params;
|
|
981
|
+
const collection$1 = prop("collection");
|
|
982
|
+
const lastNode = collection$1.getLastNode(void 0, { skip: skipFn(params) });
|
|
983
|
+
const lastValue = collection$1.getNodeValue(lastNode);
|
|
984
|
+
if (scrollToNode(params, lastValue)) require_dom_query.raf(() => focusNode(scope, lastValue));
|
|
985
|
+
else focusNode(scope, lastValue);
|
|
986
|
+
},
|
|
987
|
+
focusBranchFirstNode(params) {
|
|
988
|
+
const { event, prop, scope } = params;
|
|
989
|
+
const collection$1 = prop("collection");
|
|
990
|
+
const branchNode = collection$1.findNode(event.id);
|
|
991
|
+
const firstNode = collection$1.getFirstNode(branchNode);
|
|
992
|
+
const firstValue = collection$1.getNodeValue(firstNode);
|
|
993
|
+
if (scrollToNode(params, firstValue)) require_dom_query.raf(() => focusNode(scope, firstValue));
|
|
994
|
+
else focusNode(scope, firstValue);
|
|
995
|
+
},
|
|
996
|
+
focusTreeNextNode(params) {
|
|
997
|
+
const { event, prop, scope } = params;
|
|
998
|
+
const collection$1 = prop("collection");
|
|
999
|
+
const nextNode = collection$1.getNextNode(event.id, { skip: skipFn(params) });
|
|
1000
|
+
if (!nextNode) return;
|
|
1001
|
+
const nextValue = collection$1.getNodeValue(nextNode);
|
|
1002
|
+
if (scrollToNode(params, nextValue)) require_dom_query.raf(() => focusNode(scope, nextValue));
|
|
1003
|
+
else focusNode(scope, nextValue);
|
|
1004
|
+
},
|
|
1005
|
+
focusTreePrevNode(params) {
|
|
1006
|
+
const { event, prop, scope } = params;
|
|
1007
|
+
const collection$1 = prop("collection");
|
|
1008
|
+
const prevNode = collection$1.getPreviousNode(event.id, { skip: skipFn(params) });
|
|
1009
|
+
if (!prevNode) return;
|
|
1010
|
+
const prevValue = collection$1.getNodeValue(prevNode);
|
|
1011
|
+
if (scrollToNode(params, prevValue)) require_dom_query.raf(() => focusNode(scope, prevValue));
|
|
1012
|
+
else focusNode(scope, prevValue);
|
|
1013
|
+
},
|
|
1014
|
+
focusBranchNode(params) {
|
|
1015
|
+
const { event, prop, scope } = params;
|
|
1016
|
+
const collection$1 = prop("collection");
|
|
1017
|
+
const parentNode = collection$1.getParentNode(event.id);
|
|
1018
|
+
const parentValue = parentNode ? collection$1.getNodeValue(parentNode) : void 0;
|
|
1019
|
+
if (!parentValue) return;
|
|
1020
|
+
if (scrollToNode(params, parentValue)) require_dom_query.raf(() => focusNode(scope, parentValue));
|
|
1021
|
+
else focusNode(scope, parentValue);
|
|
1022
|
+
},
|
|
1023
|
+
selectAllNodes({ context, prop }) {
|
|
1024
|
+
context.set("selectedValue", prop("collection").getValues());
|
|
1025
|
+
},
|
|
1026
|
+
focusMatchedNode(params) {
|
|
1027
|
+
const { context, prop, refs, event, scope, computed } = params;
|
|
1028
|
+
const node = require_dom_query.getByTypeahead(computed("visibleNodes").map(({ node: node$1 }) => ({
|
|
1029
|
+
textContent: prop("collection").stringifyNode(node$1),
|
|
1030
|
+
id: prop("collection").getNodeValue(node$1)
|
|
1031
|
+
})), {
|
|
1032
|
+
state: refs.get("typeaheadState"),
|
|
1033
|
+
activeId: context.get("focusedValue"),
|
|
1034
|
+
key: event.key
|
|
1035
|
+
});
|
|
1036
|
+
if (!node?.id) return;
|
|
1037
|
+
if (scrollToNode(params, node.id)) require_dom_query.raf(() => focusNode(scope, node.id));
|
|
1038
|
+
else focusNode(scope, node.id);
|
|
1039
|
+
},
|
|
1040
|
+
toggleNodeSelection({ context, event }) {
|
|
1041
|
+
const selectedValue = require_utils.addOrRemove(context.get("selectedValue"), event.id);
|
|
1042
|
+
context.set("selectedValue", selectedValue);
|
|
1043
|
+
},
|
|
1044
|
+
expandAllBranches(params) {
|
|
1045
|
+
const { context, prop } = params;
|
|
1046
|
+
expandBranches(params, require_utils.diff(prop("collection").getBranchValues(), context.get("expandedValue")));
|
|
1047
|
+
},
|
|
1048
|
+
expandSiblingBranches(params) {
|
|
1049
|
+
const { context, event, prop } = params;
|
|
1050
|
+
const collection$1 = prop("collection");
|
|
1051
|
+
const indexPath = collection$1.getIndexPath(event.id);
|
|
1052
|
+
if (!indexPath) return;
|
|
1053
|
+
expandBranches(params, require_utils.diff(collection$1.getSiblingNodes(indexPath).map((node) => collection$1.getNodeValue(node)), context.get("expandedValue")));
|
|
1054
|
+
},
|
|
1055
|
+
extendSelectionToNode(params) {
|
|
1056
|
+
const { context, event, prop, computed } = params;
|
|
1057
|
+
const collection$1 = prop("collection");
|
|
1058
|
+
const anchorValue = require_utils.first(context.get("selectedValue")) || collection$1.getNodeValue(collection$1.getFirstNode());
|
|
1059
|
+
const targetValue = event.id;
|
|
1060
|
+
let values = [anchorValue, targetValue];
|
|
1061
|
+
let hits = 0;
|
|
1062
|
+
computed("visibleNodes").forEach(({ node }) => {
|
|
1063
|
+
const nodeValue = collection$1.getNodeValue(node);
|
|
1064
|
+
if (hits === 1) values.push(nodeValue);
|
|
1065
|
+
if (nodeValue === anchorValue || nodeValue === targetValue) hits++;
|
|
1066
|
+
});
|
|
1067
|
+
context.set("selectedValue", require_utils.uniq(values));
|
|
1068
|
+
},
|
|
1069
|
+
extendSelectionToNextNode(params) {
|
|
1070
|
+
const { context, event, prop } = params;
|
|
1071
|
+
const collection$1 = prop("collection");
|
|
1072
|
+
const nextNode = collection$1.getNextNode(event.id, { skip: skipFn(params) });
|
|
1073
|
+
if (!nextNode) return;
|
|
1074
|
+
const values = new Set(context.get("selectedValue"));
|
|
1075
|
+
const nextValue = collection$1.getNodeValue(nextNode);
|
|
1076
|
+
if (nextValue == null) return;
|
|
1077
|
+
if (values.has(event.id) && values.has(nextValue)) values.delete(event.id);
|
|
1078
|
+
else if (!values.has(nextValue)) values.add(nextValue);
|
|
1079
|
+
context.set("selectedValue", Array.from(values));
|
|
1080
|
+
},
|
|
1081
|
+
extendSelectionToPrevNode(params) {
|
|
1082
|
+
const { context, event, prop } = params;
|
|
1083
|
+
const collection$1 = prop("collection");
|
|
1084
|
+
const prevNode = collection$1.getPreviousNode(event.id, { skip: skipFn(params) });
|
|
1085
|
+
if (!prevNode) return;
|
|
1086
|
+
const values = new Set(context.get("selectedValue"));
|
|
1087
|
+
const prevValue = collection$1.getNodeValue(prevNode);
|
|
1088
|
+
if (prevValue == null) return;
|
|
1089
|
+
if (values.has(event.id) && values.has(prevValue)) values.delete(event.id);
|
|
1090
|
+
else if (!values.has(prevValue)) values.add(prevValue);
|
|
1091
|
+
context.set("selectedValue", Array.from(values));
|
|
1092
|
+
},
|
|
1093
|
+
extendSelectionToFirstNode(params) {
|
|
1094
|
+
const { context, prop } = params;
|
|
1095
|
+
const collection$1 = prop("collection");
|
|
1096
|
+
const currentSelection = require_utils.first(context.get("selectedValue"));
|
|
1097
|
+
const values = [];
|
|
1098
|
+
collection$1.visit({
|
|
1099
|
+
skip: skipFn(params),
|
|
1100
|
+
onEnter: (node) => {
|
|
1101
|
+
const nodeValue = collection$1.getNodeValue(node);
|
|
1102
|
+
values.push(nodeValue);
|
|
1103
|
+
if (nodeValue === currentSelection) return "stop";
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
context.set("selectedValue", values);
|
|
1107
|
+
},
|
|
1108
|
+
extendSelectionToLastNode(params) {
|
|
1109
|
+
const { context, prop } = params;
|
|
1110
|
+
const collection$1 = prop("collection");
|
|
1111
|
+
const currentSelection = require_utils.first(context.get("selectedValue"));
|
|
1112
|
+
const values = [];
|
|
1113
|
+
let current = false;
|
|
1114
|
+
collection$1.visit({
|
|
1115
|
+
skip: skipFn(params),
|
|
1116
|
+
onEnter: (node) => {
|
|
1117
|
+
const nodeValue = collection$1.getNodeValue(node);
|
|
1118
|
+
if (nodeValue === currentSelection) current = true;
|
|
1119
|
+
if (current) values.push(nodeValue);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
context.set("selectedValue", values);
|
|
1123
|
+
},
|
|
1124
|
+
clearPendingAborts({ refs }) {
|
|
1125
|
+
const aborts = refs.get("pendingAborts");
|
|
1126
|
+
aborts.forEach((abort) => abort.abort());
|
|
1127
|
+
aborts.clear();
|
|
1128
|
+
},
|
|
1129
|
+
toggleChecked({ context, event, prop }) {
|
|
1130
|
+
const collection$1 = prop("collection");
|
|
1131
|
+
context.set("checkedValue", (prev) => event.isBranch ? toggleBranchChecked(collection$1, event.value, prev) : require_utils.addOrRemove(prev, event.value));
|
|
1132
|
+
},
|
|
1133
|
+
setChecked({ context, event }) {
|
|
1134
|
+
context.set("checkedValue", event.value);
|
|
1135
|
+
},
|
|
1136
|
+
clearChecked({ context }) {
|
|
1137
|
+
context.set("checkedValue", []);
|
|
1138
|
+
},
|
|
1139
|
+
setRenamingValue({ context, event, prop }) {
|
|
1140
|
+
context.set("renamingValue", event.value);
|
|
1141
|
+
const onRenameStartFn = prop("onRenameStart");
|
|
1142
|
+
if (onRenameStartFn) {
|
|
1143
|
+
const collection$1 = prop("collection");
|
|
1144
|
+
const indexPath = collection$1.getIndexPath(event.value);
|
|
1145
|
+
if (indexPath) {
|
|
1146
|
+
const node = collection$1.at(indexPath);
|
|
1147
|
+
if (node) onRenameStartFn({
|
|
1148
|
+
value: event.value,
|
|
1149
|
+
node,
|
|
1150
|
+
indexPath
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
submitRenaming({ context, event, prop, scope }) {
|
|
1156
|
+
const renamingValue = context.get("renamingValue");
|
|
1157
|
+
if (!renamingValue) return;
|
|
1158
|
+
const indexPath = prop("collection").getIndexPath(renamingValue);
|
|
1159
|
+
if (!indexPath) return;
|
|
1160
|
+
const trimmedLabel = event.label.trim();
|
|
1161
|
+
const onBeforeRenameFn = prop("onBeforeRename");
|
|
1162
|
+
if (onBeforeRenameFn) {
|
|
1163
|
+
if (!onBeforeRenameFn({
|
|
1164
|
+
value: renamingValue,
|
|
1165
|
+
label: trimmedLabel,
|
|
1166
|
+
indexPath
|
|
1167
|
+
})) {
|
|
1168
|
+
context.set("renamingValue", null);
|
|
1169
|
+
focusNode(scope, renamingValue);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
prop("onRenameComplete")?.({
|
|
1174
|
+
value: renamingValue,
|
|
1175
|
+
label: trimmedLabel,
|
|
1176
|
+
indexPath
|
|
1177
|
+
});
|
|
1178
|
+
context.set("renamingValue", null);
|
|
1179
|
+
focusNode(scope, renamingValue);
|
|
1180
|
+
},
|
|
1181
|
+
cancelRenaming({ context, scope }) {
|
|
1182
|
+
const renamingValue = context.get("renamingValue");
|
|
1183
|
+
context.set("renamingValue", null);
|
|
1184
|
+
if (renamingValue) focusNode(scope, renamingValue);
|
|
1185
|
+
},
|
|
1186
|
+
syncRenameInput({ context, scope, prop }) {
|
|
1187
|
+
const renamingValue = context.get("renamingValue");
|
|
1188
|
+
if (!renamingValue) return;
|
|
1189
|
+
const collection$1 = prop("collection");
|
|
1190
|
+
const node = collection$1.findNode(renamingValue);
|
|
1191
|
+
if (!node) return;
|
|
1192
|
+
const label = collection$1.stringifyNode(node);
|
|
1193
|
+
require_dom_query.setElementValue(getRenameInputEl(scope, renamingValue), label);
|
|
1194
|
+
},
|
|
1195
|
+
focusRenameInput({ context, scope }) {
|
|
1196
|
+
const renamingValue = context.get("renamingValue");
|
|
1197
|
+
if (!renamingValue) return;
|
|
1198
|
+
const inputEl = getRenameInputEl(scope, renamingValue);
|
|
1199
|
+
if (!inputEl) return;
|
|
1200
|
+
inputEl.focus();
|
|
1201
|
+
inputEl.select();
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
function scrollToNode(params, value) {
|
|
1207
|
+
const { prop, scope, computed } = params;
|
|
1208
|
+
const scrollToIndexFn = prop("scrollToIndexFn");
|
|
1209
|
+
if (!scrollToIndexFn) return false;
|
|
1210
|
+
const collection$1 = prop("collection");
|
|
1211
|
+
const visibleNodes = computed("visibleNodes");
|
|
1212
|
+
for (let i = 0; i < visibleNodes.length; i++) {
|
|
1213
|
+
const { node, indexPath } = visibleNodes[i];
|
|
1214
|
+
if (collection$1.getNodeValue(node) !== value) continue;
|
|
1215
|
+
scrollToIndexFn({
|
|
1216
|
+
index: i,
|
|
1217
|
+
node,
|
|
1218
|
+
indexPath,
|
|
1219
|
+
getElement: () => scope.getById(getNodeId(scope, value))
|
|
1220
|
+
});
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
//#endregion
|
|
1227
|
+
//#region src/machines/tree-view/tree-view.props.ts
|
|
1228
|
+
const props = require_create_props.createProps()([
|
|
1229
|
+
"ids",
|
|
1230
|
+
"collection",
|
|
1231
|
+
"dir",
|
|
1232
|
+
"expandedValue",
|
|
1233
|
+
"expandOnClick",
|
|
1234
|
+
"defaultFocusedValue",
|
|
1235
|
+
"focusedValue",
|
|
1236
|
+
"getRootNode",
|
|
1237
|
+
"id",
|
|
1238
|
+
"onExpandedChange",
|
|
1239
|
+
"onFocusChange",
|
|
1240
|
+
"onSelectionChange",
|
|
1241
|
+
"checkedValue",
|
|
1242
|
+
"selectedValue",
|
|
1243
|
+
"selectionMode",
|
|
1244
|
+
"typeahead",
|
|
1245
|
+
"defaultExpandedValue",
|
|
1246
|
+
"defaultSelectedValue",
|
|
1247
|
+
"defaultCheckedValue",
|
|
1248
|
+
"onCheckedChange",
|
|
1249
|
+
"onLoadChildrenComplete",
|
|
1250
|
+
"onLoadChildrenError",
|
|
1251
|
+
"loadChildren",
|
|
1252
|
+
"canRename",
|
|
1253
|
+
"onRenameStart",
|
|
1254
|
+
"onBeforeRename",
|
|
1255
|
+
"onRenameComplete",
|
|
1256
|
+
"scrollToIndexFn"
|
|
1257
|
+
]);
|
|
1258
|
+
const splitProps = require_utils.createSplitProps(props);
|
|
1259
|
+
const itemProps = require_create_props.createProps()(["node", "indexPath"]);
|
|
1260
|
+
const splitItemProps = require_utils.createSplitProps(itemProps);
|
|
1261
|
+
|
|
1262
|
+
//#endregion
|
|
1263
|
+
exports.anatomy = anatomy;
|
|
1264
|
+
exports.collection = collection;
|
|
1265
|
+
exports.connect = connect;
|
|
1266
|
+
exports.filePathCollection = filePathCollection;
|
|
1267
|
+
exports.itemProps = itemProps;
|
|
1268
|
+
exports.machine = machine;
|
|
1269
|
+
exports.props = props;
|
|
1270
|
+
exports.splitItemProps = splitItemProps;
|
|
1271
|
+
exports.splitProps = splitProps;
|