@sprawlify/primitives 0.1.10 → 0.1.12

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.
Files changed (107) hide show
  1. package/dist/{collection-BBgC8xCb.cjs → collection-D0Abtxc0.cjs} +68 -0
  2. package/dist/{collection-DgzidRvr.mjs → collection-GSpaYJ2f.mjs} +45 -1
  3. package/dist/collection.cjs +5 -1
  4. package/dist/collection.d.cts +49 -3
  5. package/dist/collection.d.mts +49 -3
  6. package/dist/collection.mjs +2 -2
  7. package/dist/{focus-trap-BewqTQFt.cjs → focus-trap-BbU9QXMe.cjs} +1 -1
  8. package/dist/{focus-trap-Do8IUXYh.mjs → focus-trap-CzhQ01j4.mjs} +1 -1
  9. package/dist/focus-trap.cjs +1 -1
  10. package/dist/focus-trap.mjs +1 -1
  11. package/dist/{list-collection-B_8BN0XB.d.cts → list-collection-Cjgbx_9l.d.cts} +1 -1
  12. package/dist/{list-collection-DkRA5LOq.d.mts → list-collection-IF510iNl.d.mts} +1 -1
  13. package/dist/machines/accordion/index.d.cts +1 -1
  14. package/dist/machines/accordion/index.d.mts +1 -1
  15. package/dist/machines/angle-slider/index.d.cts +1 -1
  16. package/dist/machines/angle-slider/index.d.mts +1 -1
  17. package/dist/machines/cascade-select/index.cjs +1 -1
  18. package/dist/machines/cascade-select/index.d.cts +2 -2
  19. package/dist/machines/cascade-select/index.d.mts +2 -2
  20. package/dist/machines/cascade-select/index.mjs +1 -1
  21. package/dist/machines/clipboard/index.d.cts +1 -1
  22. package/dist/machines/clipboard/index.d.mts +1 -1
  23. package/dist/machines/collapsible/index.d.cts +1 -1
  24. package/dist/machines/collapsible/index.d.mts +1 -1
  25. package/dist/machines/color-picker/index.d.cts +1 -1
  26. package/dist/machines/color-picker/index.d.mts +1 -1
  27. package/dist/machines/combobox/index.cjs +279 -355
  28. package/dist/machines/combobox/index.d.cts +5 -4
  29. package/dist/machines/combobox/index.d.mts +5 -4
  30. package/dist/machines/combobox/index.mjs +279 -355
  31. package/dist/machines/date-input/index.cjs +1830 -0
  32. package/dist/machines/date-input/index.d.cts +223 -0
  33. package/dist/machines/date-input/index.d.mts +223 -0
  34. package/dist/machines/date-input/index.mjs +1813 -0
  35. package/dist/machines/date-picker/index.d.cts +1 -1
  36. package/dist/machines/date-picker/index.d.mts +1 -1
  37. package/dist/machines/dialog/index.cjs +1 -1
  38. package/dist/machines/dialog/index.d.cts +1 -1
  39. package/dist/machines/dialog/index.d.mts +1 -1
  40. package/dist/machines/dialog/index.mjs +1 -1
  41. package/dist/machines/drawer/index.cjs +1 -1
  42. package/dist/machines/drawer/index.d.cts +1 -1
  43. package/dist/machines/drawer/index.d.mts +1 -1
  44. package/dist/machines/drawer/index.mjs +1 -1
  45. package/dist/machines/dropdown-menu/index.d.cts +1 -1
  46. package/dist/machines/dropdown-menu/index.d.mts +1 -1
  47. package/dist/machines/editable/index.d.cts +1 -1
  48. package/dist/machines/editable/index.d.mts +1 -1
  49. package/dist/machines/file-upload/index.d.cts +1 -1
  50. package/dist/machines/file-upload/index.d.mts +1 -1
  51. package/dist/machines/floating-panel/index.d.cts +1 -1
  52. package/dist/machines/floating-panel/index.d.mts +1 -1
  53. package/dist/machines/hover-card/index.d.cts +1 -1
  54. package/dist/machines/hover-card/index.d.mts +1 -1
  55. package/dist/machines/listbox/index.cjs +41 -16
  56. package/dist/machines/listbox/index.d.cts +5 -4
  57. package/dist/machines/listbox/index.d.mts +5 -4
  58. package/dist/machines/listbox/index.mjs +42 -17
  59. package/dist/machines/marquee/index.d.cts +2 -2
  60. package/dist/machines/marquee/index.d.mts +2 -2
  61. package/dist/machines/navigation-menu/index.d.cts +1 -1
  62. package/dist/machines/navigation-menu/index.d.mts +1 -1
  63. package/dist/machines/number-input/index.d.cts +1 -1
  64. package/dist/machines/number-input/index.d.mts +1 -1
  65. package/dist/machines/password-input/index.d.cts +1 -1
  66. package/dist/machines/password-input/index.d.mts +1 -1
  67. package/dist/machines/pin-input/index.d.cts +1 -1
  68. package/dist/machines/pin-input/index.d.mts +1 -1
  69. package/dist/machines/popover/index.cjs +1 -1
  70. package/dist/machines/popover/index.d.cts +1 -1
  71. package/dist/machines/popover/index.d.mts +1 -1
  72. package/dist/machines/popover/index.mjs +1 -1
  73. package/dist/machines/progress/index.d.cts +1 -1
  74. package/dist/machines/progress/index.d.mts +1 -1
  75. package/dist/machines/select/index.cjs +47 -18
  76. package/dist/machines/select/index.d.cts +4 -3
  77. package/dist/machines/select/index.d.mts +4 -3
  78. package/dist/machines/select/index.mjs +48 -19
  79. package/dist/machines/signature-pad/index.d.cts +1 -1
  80. package/dist/machines/signature-pad/index.d.mts +1 -1
  81. package/dist/machines/slider/index.d.cts +1 -1
  82. package/dist/machines/slider/index.d.mts +1 -1
  83. package/dist/machines/steps/index.d.cts +1 -1
  84. package/dist/machines/steps/index.d.mts +1 -1
  85. package/dist/machines/switch/index.d.cts +1 -1
  86. package/dist/machines/switch/index.d.mts +1 -1
  87. package/dist/machines/tabs/index.d.cts +1 -1
  88. package/dist/machines/tabs/index.d.mts +1 -1
  89. package/dist/machines/tags-input/index.d.cts +1 -1
  90. package/dist/machines/tags-input/index.d.mts +1 -1
  91. package/dist/machines/timer/index.d.cts +1 -1
  92. package/dist/machines/timer/index.d.mts +1 -1
  93. package/dist/machines/toast/index.d.cts +1 -1
  94. package/dist/machines/toast/index.d.mts +1 -1
  95. package/dist/machines/tooltip/index.d.cts +1 -1
  96. package/dist/machines/tooltip/index.d.mts +1 -1
  97. package/dist/machines/tour/index.cjs +1 -1
  98. package/dist/machines/tour/index.d.cts +1 -1
  99. package/dist/machines/tour/index.d.mts +1 -1
  100. package/dist/machines/tour/index.mjs +1 -1
  101. package/dist/machines/tree-view/index.cjs +1 -1
  102. package/dist/machines/tree-view/index.d.cts +1 -1
  103. package/dist/machines/tree-view/index.d.mts +1 -1
  104. package/dist/machines/tree-view/index.mjs +1 -1
  105. package/dist/{selection-DdNvrKbj.d.mts → selection-6urf-c8j.d.mts} +1 -1
  106. package/dist/{selection-Bb_ZSVxe.d.cts → selection-BmS2RDMq.d.cts} +1 -1
  107. package/package.json +13 -1
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_create_anatomy = require("../../create-anatomy-BnwEmNnc.cjs");
3
3
  const require_dom_query = require("../../dom-query-BUO7rGsg.cjs");
4
4
  const require_utils = require("../../utils-ByNiZU8f.cjs");
5
- const require_collection = require("../../collection-BBgC8xCb.cjs");
5
+ const require_collection = require("../../collection-D0Abtxc0.cjs");
6
6
  const require_core = require("../../core-Bw_czdwX.cjs");
7
7
  require("../../interact-outside-Bg-QSXqp.cjs");
8
8
  const require_dismissable = require("../../dismissable-DxjbwsOf.cjs");
@@ -93,7 +93,7 @@ function connect(service, normalize) {
93
93
  value: context.get("value"),
94
94
  valueAsString: computed("valueAsString"),
95
95
  hasSelectedItems: computed("hasSelectedItems"),
96
- selectedItems: context.get("selectedItems"),
96
+ selectedItems: computed("selectedItems"),
97
97
  collection: prop("collection"),
98
98
  multiple: !!prop("multiple"),
99
99
  disabled: !!disabled,
@@ -565,9 +565,11 @@ const machine = createMachine({
565
565
  };
566
566
  },
567
567
  initialState({ prop }) {
568
- return prop("open") || prop("defaultOpen") ? "suggesting" : "idle";
568
+ return prop("open") || prop("defaultOpen") ? "open.suggesting" : "closed.idle";
569
569
  },
570
570
  context({ prop, bindable, getContext, getEvent }) {
571
+ const initialValue = prop("value") ?? prop("defaultValue") ?? [];
572
+ const initialSelectedItems = prop("collection").findMany(initialValue);
571
573
  return {
572
574
  currentPlacement: bindable(() => ({ defaultValue: void 0 })),
573
575
  value: bindable(() => ({
@@ -579,15 +581,22 @@ const machine = createMachine({
579
581
  },
580
582
  onChange(value) {
581
583
  const context = getContext();
582
- const prevSelectedItems = context.get("selectedItems");
583
584
  const collection = prop("collection");
584
- const findItems = (vals) => vals.map((v) => prevSelectedItems.find((item) => collection.getItemValue(item) === v) || collection.find(v));
585
- const nextItems = findItems(value);
586
- const effectiveValue = prop("value") || value;
587
- context.set("selectedItems", findItems(effectiveValue));
585
+ const proposed = require_collection.deriveSelectionState({
586
+ values: value,
587
+ collection,
588
+ selectedItemMap: context.get("selectedItemMap")
589
+ });
590
+ const effectiveValue = prop("value") ?? value;
591
+ const effective = effectiveValue === value ? proposed : require_collection.deriveSelectionState({
592
+ values: effectiveValue,
593
+ collection,
594
+ selectedItemMap: proposed.nextSelectedItemMap
595
+ });
596
+ context.set("selectedItemMap", effective.nextSelectedItemMap);
588
597
  prop("onValueChange")?.({
589
598
  value,
590
- items: nextItems
599
+ items: proposed.selectedItems
591
600
  });
592
601
  }
593
602
  })),
@@ -630,9 +639,11 @@ const machine = createMachine({
630
639
  const highlightedValue = prop("highlightedValue");
631
640
  return { defaultValue: prop("collection").find(highlightedValue) };
632
641
  }),
633
- selectedItems: bindable(() => {
634
- const value = prop("value") || prop("defaultValue") || [];
635
- return { defaultValue: prop("collection").findMany(value) };
642
+ selectedItemMap: bindable(() => {
643
+ return { defaultValue: require_collection.createSelectedItemMap({
644
+ selectedItems: initialSelectedItems,
645
+ collection: prop("collection")
646
+ }) };
636
647
  })
637
648
  };
638
649
  },
@@ -642,7 +653,12 @@ const machine = createMachine({
642
653
  autoComplete: ({ prop }) => prop("inputBehavior") === "autocomplete",
643
654
  autoHighlight: ({ prop }) => prop("inputBehavior") === "autohighlight",
644
655
  hasSelectedItems: ({ context }) => context.get("value").length > 0,
645
- valueAsString: ({ context, prop }) => prop("collection").stringifyItems(context.get("selectedItems")),
656
+ selectedItems: ({ context, prop }) => require_collection.resolveSelectedItems({
657
+ values: context.get("value"),
658
+ collection: prop("collection"),
659
+ selectedItemMap: context.get("selectedItemMap")
660
+ }),
661
+ valueAsString: ({ computed, prop }) => prop("collection").stringifyItems(computed("selectedItems")),
646
662
  isCustomValue: ({ context, computed }) => context.get("inputValue") !== computed("valueAsString")
647
663
  },
648
664
  watch({ context, prop, track, action, send }) {
@@ -677,156 +693,162 @@ const machine = createMachine({
677
693
  actions: ["setInitialFocus"]
678
694
  }]),
679
695
  states: {
680
- idle: {
681
- tags: ["idle", "closed"],
682
- entry: ["scrollContentToTop", "clearHighlightedValue"],
683
- on: {
684
- "CONTROLLED.OPEN": { target: "interacting" },
685
- "TRIGGER.CLICK": [{
686
- guard: "isOpenControlled",
687
- actions: [
688
- "setInitialFocus",
689
- "highlightFirstSelectedItem",
690
- "invokeOnOpen"
691
- ]
692
- }, {
693
- target: "interacting",
694
- actions: [
695
- "setInitialFocus",
696
- "highlightFirstSelectedItem",
697
- "invokeOnOpen"
698
- ]
699
- }],
700
- "INPUT.CLICK": [{
701
- guard: "isOpenControlled",
702
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
703
- }, {
704
- target: "interacting",
705
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
706
- }],
707
- "INPUT.FOCUS": { target: "focused" },
708
- OPEN: [{
709
- guard: "isOpenControlled",
710
- actions: ["invokeOnOpen"]
711
- }, {
712
- target: "interacting",
713
- actions: ["invokeOnOpen"]
714
- }],
715
- "VALUE.CLEAR": {
716
- target: "focused",
717
- actions: [
718
- "clearInputValue",
719
- "clearSelectedItems",
720
- "setInitialFocus"
721
- ]
722
- }
723
- }
724
- },
725
- focused: {
726
- tags: ["focused", "closed"],
727
- entry: ["scrollContentToTop", "clearHighlightedValue"],
728
- on: {
729
- "CONTROLLED.OPEN": [{
730
- guard: "isChangeEvent",
731
- target: "suggesting"
732
- }, { target: "interacting" }],
733
- "INPUT.CHANGE": [
734
- {
735
- guard: and("isOpenControlled", "openOnChange"),
736
- actions: [
737
- "setInputValue",
738
- "invokeOnOpen",
739
- "highlightFirstItemIfNeeded"
740
- ]
741
- },
742
- {
743
- guard: "openOnChange",
744
- target: "suggesting",
745
- actions: [
746
- "setInputValue",
747
- "invokeOnOpen",
748
- "highlightFirstItemIfNeeded"
749
- ]
750
- },
751
- { actions: ["setInputValue"] }
752
- ],
753
- "LAYER.INTERACT_OUTSIDE": { target: "idle" },
754
- "INPUT.ESCAPE": {
755
- guard: and("isCustomValue", not("allowCustomValue")),
756
- actions: ["revertInputValue"]
757
- },
758
- "INPUT.BLUR": { target: "idle" },
759
- "INPUT.CLICK": [{
760
- guard: "isOpenControlled",
761
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
762
- }, {
763
- target: "interacting",
764
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
765
- }],
766
- "TRIGGER.CLICK": [{
767
- guard: "isOpenControlled",
768
- actions: [
769
- "setInitialFocus",
770
- "highlightFirstSelectedItem",
771
- "invokeOnOpen"
772
- ]
773
- }, {
774
- target: "interacting",
775
- actions: [
776
- "setInitialFocus",
777
- "highlightFirstSelectedItem",
778
- "invokeOnOpen"
779
- ]
780
- }],
781
- "INPUT.ARROW_DOWN": [
782
- {
783
- guard: and("isOpenControlled", "autoComplete"),
784
- actions: ["invokeOnOpen"]
785
- },
786
- {
787
- guard: "autoComplete",
788
- target: "interacting",
789
- actions: ["invokeOnOpen"]
790
- },
791
- {
792
- guard: "isOpenControlled",
793
- actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
794
- },
795
- {
796
- target: "interacting",
797
- actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
696
+ closed: {
697
+ tags: ["closed"],
698
+ initial: "idle",
699
+ states: {
700
+ idle: {
701
+ tags: ["idle"],
702
+ entry: ["scrollContentToTop", "clearHighlightedValue"],
703
+ on: {
704
+ "CONTROLLED.OPEN": { target: "open.interacting" },
705
+ "TRIGGER.CLICK": [{
706
+ guard: "isOpenControlled",
707
+ actions: [
708
+ "setInitialFocus",
709
+ "highlightFirstSelectedItem",
710
+ "invokeOnOpen"
711
+ ]
712
+ }, {
713
+ target: "open.interacting",
714
+ actions: [
715
+ "setInitialFocus",
716
+ "highlightFirstSelectedItem",
717
+ "invokeOnOpen"
718
+ ]
719
+ }],
720
+ "INPUT.CLICK": [{
721
+ guard: "isOpenControlled",
722
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
723
+ }, {
724
+ target: "open.interacting",
725
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
726
+ }],
727
+ "INPUT.FOCUS": { target: "focused" },
728
+ OPEN: [{
729
+ guard: "isOpenControlled",
730
+ actions: ["invokeOnOpen"]
731
+ }, {
732
+ target: "open.interacting",
733
+ actions: ["invokeOnOpen"]
734
+ }],
735
+ "VALUE.CLEAR": {
736
+ target: "focused",
737
+ actions: [
738
+ "clearInputValue",
739
+ "clearSelectedItems",
740
+ "setInitialFocus"
741
+ ]
742
+ }
798
743
  }
799
- ],
800
- "INPUT.ARROW_UP": [
801
- {
802
- guard: and("isOpenControlled", "autoComplete"),
803
- actions: ["invokeOnOpen"]
804
- },
805
- {
806
- guard: "autoComplete",
807
- target: "interacting",
808
- actions: ["invokeOnOpen"]
809
- },
810
- {
811
- guard: "isOpenControlled",
812
- actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
813
- },
814
- {
815
- target: "interacting",
816
- actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
744
+ },
745
+ focused: {
746
+ tags: ["focused"],
747
+ entry: ["scrollContentToTop", "clearHighlightedValue"],
748
+ on: {
749
+ "CONTROLLED.OPEN": [{
750
+ guard: "isChangeEvent",
751
+ target: "open.suggesting"
752
+ }, { target: "open.interacting" }],
753
+ "INPUT.CHANGE": [
754
+ {
755
+ guard: and("isOpenControlled", "openOnChange"),
756
+ actions: [
757
+ "setInputValue",
758
+ "invokeOnOpen",
759
+ "highlightFirstItemIfNeeded"
760
+ ]
761
+ },
762
+ {
763
+ guard: "openOnChange",
764
+ target: "open.suggesting",
765
+ actions: [
766
+ "setInputValue",
767
+ "invokeOnOpen",
768
+ "highlightFirstItemIfNeeded"
769
+ ]
770
+ },
771
+ { actions: ["setInputValue"] }
772
+ ],
773
+ "LAYER.INTERACT_OUTSIDE": { target: "idle" },
774
+ "INPUT.ESCAPE": {
775
+ guard: and("isCustomValue", not("allowCustomValue")),
776
+ actions: ["revertInputValue"]
777
+ },
778
+ "INPUT.BLUR": { target: "idle" },
779
+ "INPUT.CLICK": [{
780
+ guard: "isOpenControlled",
781
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
782
+ }, {
783
+ target: "open.interacting",
784
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
785
+ }],
786
+ "TRIGGER.CLICK": [{
787
+ guard: "isOpenControlled",
788
+ actions: [
789
+ "setInitialFocus",
790
+ "highlightFirstSelectedItem",
791
+ "invokeOnOpen"
792
+ ]
793
+ }, {
794
+ target: "open.interacting",
795
+ actions: [
796
+ "setInitialFocus",
797
+ "highlightFirstSelectedItem",
798
+ "invokeOnOpen"
799
+ ]
800
+ }],
801
+ "INPUT.ARROW_DOWN": [
802
+ {
803
+ guard: and("isOpenControlled", "autoComplete"),
804
+ actions: ["invokeOnOpen"]
805
+ },
806
+ {
807
+ guard: "autoComplete",
808
+ target: "open.interacting",
809
+ actions: ["invokeOnOpen"]
810
+ },
811
+ {
812
+ guard: "isOpenControlled",
813
+ actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
814
+ },
815
+ {
816
+ target: "open.interacting",
817
+ actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
818
+ }
819
+ ],
820
+ "INPUT.ARROW_UP": [
821
+ {
822
+ guard: and("isOpenControlled", "autoComplete"),
823
+ actions: ["invokeOnOpen"]
824
+ },
825
+ {
826
+ guard: "autoComplete",
827
+ target: "open.interacting",
828
+ actions: ["invokeOnOpen"]
829
+ },
830
+ {
831
+ guard: "isOpenControlled",
832
+ actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
833
+ },
834
+ {
835
+ target: "open.interacting",
836
+ actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
837
+ }
838
+ ],
839
+ OPEN: [{
840
+ guard: "isOpenControlled",
841
+ actions: ["invokeOnOpen"]
842
+ }, {
843
+ target: "open.interacting",
844
+ actions: ["invokeOnOpen"]
845
+ }],
846
+ "VALUE.CLEAR": { actions: ["clearInputValue", "clearSelectedItems"] }
817
847
  }
818
- ],
819
- OPEN: [{
820
- guard: "isOpenControlled",
821
- actions: ["invokeOnOpen"]
822
- }, {
823
- target: "interacting",
824
- actions: ["invokeOnOpen"]
825
- }],
826
- "VALUE.CLEAR": { actions: ["clearInputValue", "clearSelectedItems"] }
848
+ }
827
849
  }
828
850
  },
829
- interacting: {
851
+ open: {
830
852
  tags: ["open", "focused"],
831
853
  entry: ["setInitialFocus"],
832
854
  effects: [
@@ -838,23 +860,9 @@ const machine = createMachine({
838
860
  on: {
839
861
  "CONTROLLED.CLOSE": [{
840
862
  guard: "restoreFocus",
841
- target: "focused",
863
+ target: "closed.focused",
842
864
  actions: ["setFinalFocus"]
843
- }, { target: "idle" }],
844
- CHILDREN_CHANGE: [{
845
- guard: "isHighlightedItemRemoved",
846
- actions: ["clearHighlightedValue"]
847
- }, { actions: ["scrollToHighlightedItem"] }],
848
- "INPUT.HOME": { actions: ["highlightFirstItem"] },
849
- "INPUT.END": { actions: ["highlightLastItem"] },
850
- "INPUT.ARROW_DOWN": [{
851
- guard: and("autoComplete", "isLastItemHighlighted"),
852
- actions: ["clearHighlightedValue", "scrollContentToTop"]
853
- }, { actions: ["highlightNextItem"] }],
854
- "INPUT.ARROW_UP": [{
855
- guard: and("autoComplete", "isFirstItemHighlighted"),
856
- actions: ["clearHighlightedValue"]
857
- }, { actions: ["highlightPrevItem"] }],
865
+ }, { target: "closed.idle" }],
858
866
  "INPUT.ENTER": [
859
867
  {
860
868
  guard: and("isOpenControlled", "isCustomValue", not("hasHighlightedItem"), not("allowCustomValue")),
@@ -862,7 +870,7 @@ const machine = createMachine({
862
870
  },
863
871
  {
864
872
  guard: and("isCustomValue", not("hasHighlightedItem"), not("allowCustomValue")),
865
- target: "focused",
873
+ target: "closed.focused",
866
874
  actions: ["revertInputValue", "invokeOnClose"]
867
875
  },
868
876
  {
@@ -871,7 +879,7 @@ const machine = createMachine({
871
879
  },
872
880
  {
873
881
  guard: "closeOnSelect",
874
- target: "focused",
882
+ target: "closed.focused",
875
883
  actions: [
876
884
  "selectHighlightedItem",
877
885
  "invokeOnClose",
@@ -880,16 +888,6 @@ const machine = createMachine({
880
888
  },
881
889
  { actions: ["selectHighlightedItem"] }
882
890
  ],
883
- "INPUT.CHANGE": [{
884
- guard: "autoComplete",
885
- target: "suggesting",
886
- actions: ["setInputValue"]
887
- }, {
888
- target: "suggesting",
889
- actions: ["clearHighlightedValue", "setInputValue"]
890
- }],
891
- "ITEM.POINTER_MOVE": { actions: ["setHighlightedValue"] },
892
- "ITEM.POINTER_LEAVE": { actions: ["clearHighlightedValue"] },
893
891
  "ITEM.CLICK": [
894
892
  {
895
893
  guard: and("isOpenControlled", "closeOnSelect"),
@@ -897,7 +895,7 @@ const machine = createMachine({
897
895
  },
898
896
  {
899
897
  guard: "closeOnSelect",
900
- target: "focused",
898
+ target: "closed.focused",
901
899
  actions: [
902
900
  "selectItem",
903
901
  "invokeOnClose",
@@ -906,30 +904,11 @@ const machine = createMachine({
906
904
  },
907
905
  { actions: ["selectItem"] }
908
906
  ],
909
- "LAYER.ESCAPE": [
910
- {
911
- guard: and("isOpenControlled", "autoComplete"),
912
- actions: ["syncInputValue", "invokeOnClose"]
913
- },
914
- {
915
- guard: "autoComplete",
916
- target: "focused",
917
- actions: ["syncInputValue", "invokeOnClose"]
918
- },
919
- {
920
- guard: "isOpenControlled",
921
- actions: ["invokeOnClose"]
922
- },
923
- {
924
- target: "focused",
925
- actions: ["invokeOnClose", "setFinalFocus"]
926
- }
927
- ],
928
907
  "TRIGGER.CLICK": [{
929
908
  guard: "isOpenControlled",
930
909
  actions: ["invokeOnClose"]
931
910
  }, {
932
- target: "focused",
911
+ target: "closed.focused",
933
912
  actions: ["invokeOnClose"]
934
913
  }],
935
914
  "LAYER.INTERACT_OUTSIDE": [
@@ -939,7 +918,7 @@ const machine = createMachine({
939
918
  },
940
919
  {
941
920
  guard: and("isCustomValue", not("allowCustomValue")),
942
- target: "idle",
921
+ target: "closed.idle",
943
922
  actions: ["revertInputValue", "invokeOnClose"]
944
923
  },
945
924
  {
@@ -947,7 +926,7 @@ const machine = createMachine({
947
926
  actions: ["invokeOnClose"]
948
927
  },
949
928
  {
950
- target: "idle",
929
+ target: "closed.idle",
951
930
  actions: ["invokeOnClose"]
952
931
  }
953
932
  ],
@@ -955,7 +934,7 @@ const machine = createMachine({
955
934
  guard: "isOpenControlled",
956
935
  actions: ["invokeOnClose"]
957
936
  }, {
958
- target: "focused",
937
+ target: "closed.focused",
959
938
  actions: ["invokeOnClose", "setFinalFocus"]
960
939
  }],
961
940
  "VALUE.CLEAR": [{
@@ -966,7 +945,7 @@ const machine = createMachine({
966
945
  "invokeOnClose"
967
946
  ]
968
947
  }, {
969
- target: "focused",
948
+ target: "closed.focused",
970
949
  actions: [
971
950
  "clearInputValue",
972
951
  "clearSelectedItems",
@@ -974,156 +953,99 @@ const machine = createMachine({
974
953
  "setFinalFocus"
975
954
  ]
976
955
  }]
977
- }
978
- },
979
- suggesting: {
980
- tags: ["open", "focused"],
981
- effects: [
982
- "trackFocusVisible",
983
- "trackDismissableLayer",
984
- "scrollToHighlightedItem",
985
- "trackPlacement"
986
- ],
987
- entry: ["setInitialFocus"],
988
- on: {
989
- "CONTROLLED.CLOSE": [{
990
- guard: "restoreFocus",
991
- target: "focused",
992
- actions: ["setFinalFocus"]
993
- }, { target: "idle" }],
994
- CHILDREN_CHANGE: [
995
- {
996
- guard: and("isHighlightedItemRemoved", "hasCollectionItems", "autoHighlight"),
997
- actions: ["clearHighlightedValue", "highlightFirstItem"]
998
- },
999
- {
956
+ },
957
+ initial: "interacting",
958
+ states: {
959
+ interacting: { on: {
960
+ CHILDREN_CHANGE: [{
1000
961
  guard: "isHighlightedItemRemoved",
1001
962
  actions: ["clearHighlightedValue"]
963
+ }, { actions: ["scrollToHighlightedItem"] }],
964
+ "INPUT.HOME": { actions: ["highlightFirstItem"] },
965
+ "INPUT.END": { actions: ["highlightLastItem"] },
966
+ "INPUT.ARROW_DOWN": [{
967
+ guard: and("autoComplete", "isLastItemHighlighted"),
968
+ actions: ["clearHighlightedValue", "scrollContentToTop"]
969
+ }, { actions: ["highlightNextItem"] }],
970
+ "INPUT.ARROW_UP": [{
971
+ guard: and("autoComplete", "isFirstItemHighlighted"),
972
+ actions: ["clearHighlightedValue"]
973
+ }, { actions: ["highlightPrevItem"] }],
974
+ "INPUT.CHANGE": [{
975
+ guard: "autoComplete",
976
+ target: "suggesting",
977
+ actions: ["setInputValue"]
978
+ }, {
979
+ target: "suggesting",
980
+ actions: ["clearHighlightedValue", "setInputValue"]
981
+ }],
982
+ "ITEM.POINTER_MOVE": { actions: ["setHighlightedValue"] },
983
+ "ITEM.POINTER_LEAVE": { actions: ["clearHighlightedValue"] },
984
+ "LAYER.ESCAPE": [
985
+ {
986
+ guard: and("isOpenControlled", "autoComplete"),
987
+ actions: ["syncInputValue", "invokeOnClose"]
988
+ },
989
+ {
990
+ guard: "autoComplete",
991
+ target: "closed.focused",
992
+ actions: ["syncInputValue", "invokeOnClose"]
993
+ },
994
+ {
995
+ guard: "isOpenControlled",
996
+ actions: ["invokeOnClose"]
997
+ },
998
+ {
999
+ target: "closed.focused",
1000
+ actions: ["invokeOnClose", "setFinalFocus"]
1001
+ }
1002
+ ]
1003
+ } },
1004
+ suggesting: { on: {
1005
+ CHILDREN_CHANGE: [
1006
+ {
1007
+ guard: and("isHighlightedItemRemoved", "hasCollectionItems", "autoHighlight"),
1008
+ actions: ["clearHighlightedValue", "highlightFirstItem"]
1009
+ },
1010
+ {
1011
+ guard: "isHighlightedItemRemoved",
1012
+ actions: ["clearHighlightedValue"]
1013
+ },
1014
+ {
1015
+ guard: "autoHighlight",
1016
+ actions: ["highlightFirstItem"]
1017
+ }
1018
+ ],
1019
+ "INPUT.ARROW_DOWN": {
1020
+ target: "interacting",
1021
+ actions: ["highlightNextItem"]
1002
1022
  },
1003
- {
1004
- guard: "autoHighlight",
1005
- actions: ["highlightFirstItem"]
1006
- }
1007
- ],
1008
- "INPUT.ARROW_DOWN": {
1009
- target: "interacting",
1010
- actions: ["highlightNextItem"]
1011
- },
1012
- "INPUT.ARROW_UP": {
1013
- target: "interacting",
1014
- actions: ["highlightPrevItem"]
1015
- },
1016
- "INPUT.HOME": {
1017
- target: "interacting",
1018
- actions: ["highlightFirstItem"]
1019
- },
1020
- "INPUT.END": {
1021
- target: "interacting",
1022
- actions: ["highlightLastItem"]
1023
- },
1024
- "INPUT.ENTER": [
1025
- {
1026
- guard: and("isOpenControlled", "isCustomValue", not("hasHighlightedItem"), not("allowCustomValue")),
1027
- actions: ["revertInputValue", "invokeOnClose"]
1028
- },
1029
- {
1030
- guard: and("isCustomValue", not("hasHighlightedItem"), not("allowCustomValue")),
1031
- target: "focused",
1032
- actions: ["revertInputValue", "invokeOnClose"]
1033
- },
1034
- {
1035
- guard: and("isOpenControlled", "closeOnSelect"),
1036
- actions: ["selectHighlightedItem", "invokeOnClose"]
1037
- },
1038
- {
1039
- guard: "closeOnSelect",
1040
- target: "focused",
1041
- actions: [
1042
- "selectHighlightedItem",
1043
- "invokeOnClose",
1044
- "setFinalFocus"
1045
- ]
1023
+ "INPUT.ARROW_UP": {
1024
+ target: "interacting",
1025
+ actions: ["highlightPrevItem"]
1046
1026
  },
1047
- { actions: ["selectHighlightedItem"] }
1048
- ],
1049
- "INPUT.CHANGE": { actions: ["setInputValue"] },
1050
- "LAYER.ESCAPE": [{
1051
- guard: "isOpenControlled",
1052
- actions: ["invokeOnClose"]
1053
- }, {
1054
- target: "focused",
1055
- actions: ["invokeOnClose"]
1056
- }],
1057
- "ITEM.POINTER_MOVE": {
1058
- target: "interacting",
1059
- actions: ["setHighlightedValue"]
1060
- },
1061
- "ITEM.POINTER_LEAVE": { actions: ["clearHighlightedValue"] },
1062
- "LAYER.INTERACT_OUTSIDE": [
1063
- {
1064
- guard: and("isOpenControlled", "isCustomValue", not("allowCustomValue")),
1065
- actions: ["revertInputValue", "invokeOnClose"]
1027
+ "INPUT.HOME": {
1028
+ target: "interacting",
1029
+ actions: ["highlightFirstItem"]
1066
1030
  },
1067
- {
1068
- guard: and("isCustomValue", not("allowCustomValue")),
1069
- target: "idle",
1070
- actions: ["revertInputValue", "invokeOnClose"]
1031
+ "INPUT.END": {
1032
+ target: "interacting",
1033
+ actions: ["highlightLastItem"]
1071
1034
  },
1072
- {
1035
+ "INPUT.CHANGE": { actions: ["setInputValue"] },
1036
+ "LAYER.ESCAPE": [{
1073
1037
  guard: "isOpenControlled",
1074
1038
  actions: ["invokeOnClose"]
1075
- },
1076
- {
1077
- target: "idle",
1039
+ }, {
1040
+ target: "closed.focused",
1078
1041
  actions: ["invokeOnClose"]
1079
- }
1080
- ],
1081
- "TRIGGER.CLICK": [{
1082
- guard: "isOpenControlled",
1083
- actions: ["invokeOnClose"]
1084
- }, {
1085
- target: "focused",
1086
- actions: ["invokeOnClose"]
1087
- }],
1088
- "ITEM.CLICK": [
1089
- {
1090
- guard: and("isOpenControlled", "closeOnSelect"),
1091
- actions: ["selectItem", "invokeOnClose"]
1092
- },
1093
- {
1094
- guard: "closeOnSelect",
1095
- target: "focused",
1096
- actions: [
1097
- "selectItem",
1098
- "invokeOnClose",
1099
- "setFinalFocus"
1100
- ]
1042
+ }],
1043
+ "ITEM.POINTER_MOVE": {
1044
+ target: "interacting",
1045
+ actions: ["setHighlightedValue"]
1101
1046
  },
1102
- { actions: ["selectItem"] }
1103
- ],
1104
- CLOSE: [{
1105
- guard: "isOpenControlled",
1106
- actions: ["invokeOnClose"]
1107
- }, {
1108
- target: "focused",
1109
- actions: ["invokeOnClose", "setFinalFocus"]
1110
- }],
1111
- "VALUE.CLEAR": [{
1112
- guard: "isOpenControlled",
1113
- actions: [
1114
- "clearInputValue",
1115
- "clearSelectedItems",
1116
- "invokeOnClose"
1117
- ]
1118
- }, {
1119
- target: "focused",
1120
- actions: [
1121
- "clearInputValue",
1122
- "clearSelectedItems",
1123
- "invokeOnClose",
1124
- "setFinalFocus"
1125
- ]
1126
- }]
1047
+ "ITEM.POINTER_LEAVE": { actions: ["clearHighlightedValue"] }
1048
+ } }
1127
1049
  }
1128
1050
  }
1129
1051
  },
@@ -1495,10 +1417,12 @@ const machine = createMachine({
1495
1417
  const { context, prop } = params;
1496
1418
  const collection = prop("collection");
1497
1419
  const value = context.get("value");
1498
- const selectedItems = value.map((v) => {
1499
- return context.get("selectedItems").find((item) => collection.getItemValue(item) === v) || collection.find(v);
1420
+ const next = require_collection.deriveSelectionState({
1421
+ values: value,
1422
+ collection,
1423
+ selectedItemMap: context.get("selectedItemMap")
1500
1424
  });
1501
- context.set("selectedItems", selectedItems);
1425
+ context.set("selectedItemMap", next.nextSelectedItemMap);
1502
1426
  const inputValue = require_utils.match(prop("selectionBehavior"), {
1503
1427
  preserve: context.get("inputValue"),
1504
1428
  replace: collection.stringifyMany(value),