@zag-js/combobox 0.58.3 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -567,8 +567,8 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
567
567
  isInputValueEmpty: (ctx) => ctx.isInputValueEmpty,
568
568
  autoComplete: (ctx) => ctx.autoComplete && !ctx.multiple,
569
569
  autoHighlight: (ctx) => ctx.autoHighlight,
570
- isFirstItemHighlighted: (ctx) => ctx.collection.first() === ctx.highlightedValue,
571
- isLastItemHighlighted: (ctx) => ctx.collection.last() === ctx.highlightedValue,
570
+ isFirstItemHighlighted: (ctx) => ctx.collection.firstValue === ctx.highlightedValue,
571
+ isLastItemHighlighted: (ctx) => ctx.collection.lastValue === ctx.highlightedValue,
572
572
  isCustomValue: (ctx) => ctx.inputValue !== ctx.valueAsString,
573
573
  allowCustomValue: (ctx) => !!ctx.allowCustomValue,
574
574
  hasHighlightedItem: (ctx) => ctx.highlightedValue != null,
@@ -747,10 +747,10 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
747
747
  set.inputValue(ctx, inputValue)
748
748
  },
749
749
  syncInitialValues(ctx) {
750
- const selectedItems = ctx.collection.items(ctx.value)
751
- const valueAsString = ctx.collection.itemsToString(selectedItems)
750
+ const selectedItems = ctx.collection.findMany(ctx.value)
751
+ const valueAsString = ctx.collection.stringifyMany(ctx.value)
752
752
 
753
- ctx.highlightedItem = ctx.collection.item(ctx.highlightedValue)
753
+ ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue)
754
754
  ctx.selectedItems = selectedItems
755
755
  ctx.valueAsString = valueAsString
756
756
 
@@ -791,40 +791,40 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
791
791
  },
792
792
  highlightFirstItem(ctx) {
793
793
  raf(() => {
794
- const value = ctx.collection.first()
794
+ const value = ctx.collection.firstValue
795
795
  set.highlightedValue(ctx, value)
796
796
  })
797
797
  },
798
798
  highlightFirstItemIfNeeded(ctx) {
799
799
  if (!ctx.autoHighlight) return
800
800
  raf(() => {
801
- const value = ctx.collection.first()
801
+ const value = ctx.collection.firstValue
802
802
  set.highlightedValue(ctx, value)
803
803
  })
804
804
  },
805
805
  highlightLastItem(ctx) {
806
806
  raf(() => {
807
- const value = ctx.collection.last()
807
+ const value = ctx.collection.lastValue
808
808
  set.highlightedValue(ctx, value)
809
809
  })
810
810
  },
811
811
  highlightNextItem(ctx) {
812
812
  let value: string | null = null
813
813
  if (ctx.highlightedValue) {
814
- value = ctx.collection.next(ctx.highlightedValue)
815
- if (!value && ctx.loopFocus) value = ctx.collection.first()
814
+ value = ctx.collection.getNextValue(ctx.highlightedValue)
815
+ if (!value && ctx.loopFocus) value = ctx.collection.firstValue
816
816
  } else {
817
- value = ctx.collection.first()
817
+ value = ctx.collection.firstValue
818
818
  }
819
819
  set.highlightedValue(ctx, value)
820
820
  },
821
821
  highlightPrevItem(ctx) {
822
822
  let value: string | null = null
823
823
  if (ctx.highlightedValue) {
824
- value = ctx.collection.prev(ctx.highlightedValue)
825
- if (!value && ctx.loopFocus) value = ctx.collection.last()
824
+ value = ctx.collection.getPreviousValue(ctx.highlightedValue)
825
+ if (!value && ctx.loopFocus) value = ctx.collection.lastValue
826
826
  } else {
827
- value = ctx.collection.last()
827
+ value = ctx.collection.lastValue
828
828
  }
829
829
  set.highlightedValue(ctx, value)
830
830
  },
@@ -840,7 +840,7 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
840
840
  if (ctx.hasSelectedItems) {
841
841
  value = ctx.collection.sort(ctx.value)[0]
842
842
  } else {
843
- value = ctx.collection.first()
843
+ value = ctx.collection.firstValue
844
844
  }
845
845
  set.highlightedValue(ctx, value)
846
846
  })
@@ -851,7 +851,7 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
851
851
  if (ctx.hasSelectedItems) {
852
852
  value = ctx.collection.sort(ctx.value)[0]
853
853
  } else {
854
- value = ctx.collection.last()
854
+ value = ctx.collection.lastValue
855
855
  }
856
856
  set.highlightedValue(ctx, value)
857
857
  })
@@ -859,7 +859,7 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
859
859
  autofillInputValue(ctx, evt) {
860
860
  const inputEl = dom.getInputEl(ctx)
861
861
  if (!ctx.autoComplete || !inputEl || !evt.keypress) return
862
- const valueText = ctx.collection.valueToString(ctx.highlightedValue)
862
+ const valueText = ctx.collection.stringify(ctx.highlightedValue)
863
863
  raf(() => {
864
864
  inputEl.value = valueText || ctx.inputValue
865
865
  })
@@ -885,14 +885,14 @@ const sync = {
885
885
  valueChange: (ctx: MachineContext) => {
886
886
  // side effect
887
887
  const prevSelectedItems = ctx.selectedItems
888
+
888
889
  ctx.selectedItems = ctx.value.map((v) => {
889
- const foundItem = prevSelectedItems.find((item) => ctx.collection.itemToValue(item) === v)
890
+ const foundItem = prevSelectedItems.find((item) => ctx.collection.hasItem(item))
890
891
  if (foundItem) return foundItem
891
- return ctx.collection.item(v)
892
+ return ctx.collection.find(v)
892
893
  })
893
894
 
894
- // set valueAsString
895
- const valueAsString = ctx.collection.itemsToString(ctx.selectedItems)
895
+ const valueAsString = ctx.collection.stringifyItems(ctx.selectedItems)
896
896
  ctx.valueAsString = valueAsString
897
897
 
898
898
  // set inputValue
@@ -917,7 +917,7 @@ const sync = {
917
917
  set.inputValue(ctx, inputValue)
918
918
  },
919
919
  highlightChange: (ctx: MachineContext) => {
920
- ctx.highlightedItem = ctx.collection.item(ctx.highlightedValue)
920
+ ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue)
921
921
  },
922
922
  }
923
923