akar 1.19.0 → 1.20.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.
Files changed (74) hide show
  1. package/dist/autocomplete/autocomplete-input.js +122 -0
  2. package/dist/autocomplete/autocomplete-input.js.map +1 -0
  3. package/dist/autocomplete/autocomplete-root.js +253 -0
  4. package/dist/autocomplete/autocomplete-root.js.map +1 -0
  5. package/dist/checkbox/checkbox-group-root.js +1 -1
  6. package/dist/checkbox/checkbox-root.js +1 -1
  7. package/dist/combobox/combobox-content-impl.js +9 -2
  8. package/dist/combobox/combobox-content-impl.js.map +1 -1
  9. package/dist/combobox/combobox-content.js +4 -0
  10. package/dist/combobox/combobox-content.js.map +1 -1
  11. package/dist/combobox/combobox-root.js +1 -1
  12. package/dist/composables/use-window-splitter-panel-group-behavior.js +13 -9
  13. package/dist/composables/use-window-splitter-panel-group-behavior.js.map +1 -1
  14. package/dist/constant/components.js +18 -0
  15. package/dist/constant/components.js.map +1 -1
  16. package/dist/constant.d.ts +1 -0
  17. package/dist/constant.d.ts.map +1 -1
  18. package/dist/date-field/date-field-root.js +1 -1
  19. package/dist/date-range-field/date-range-field-root.js +1 -1
  20. package/dist/dialog/dialog-content-impl.js +1 -1
  21. package/dist/hover-card/hover-card-content-impl.js +1 -1
  22. package/dist/index.d.ts +2163 -2033
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +50 -47
  25. package/dist/listbox/listbox-root.js +1 -1
  26. package/dist/listbox/listbox-virtualizer.js +1 -1
  27. package/dist/menu/menu-content-impl.js +1 -1
  28. package/dist/menu/menu-item-impl.js +1 -1
  29. package/dist/namespaced/index.cjs +19 -0
  30. package/dist/namespaced/index.d.cts +20 -2
  31. package/dist/namespaced/index.d.mts +20 -2
  32. package/dist/namespaced/index.mjs +20 -2
  33. package/dist/popover/popover-content-impl.js +1 -1
  34. package/dist/radio-group/radio-group-root.js +1 -1
  35. package/dist/select/select-content-impl.js +1 -1
  36. package/dist/select/select-root.js +1 -1
  37. package/dist/select/select-trigger.js +1 -1
  38. package/dist/shared/use-id.js +7 -4
  39. package/dist/shared/use-id.js.map +1 -1
  40. package/dist/splitter/splitter-group.js +143 -30
  41. package/dist/splitter/splitter-group.js.map +1 -1
  42. package/dist/splitter/splitter-panel.js +7 -2
  43. package/dist/splitter/splitter-panel.js.map +1 -1
  44. package/dist/time-field/time-field-root.js +1 -1
  45. package/dist/toast/toast-announce.js +4 -1
  46. package/dist/toast/toast-announce.js.map +1 -1
  47. package/dist/toggle-group/toggle-group-root.js +1 -1
  48. package/dist/tooltip/tooltip-content-impl.js +26 -19
  49. package/dist/tooltip/tooltip-content-impl.js.map +1 -1
  50. package/dist/tooltip/tooltip-content.js +1 -2
  51. package/dist/tooltip/tooltip-content.js.map +1 -1
  52. package/dist/tooltip/tooltip-provider.js +7 -2
  53. package/dist/tooltip/tooltip-provider.js.map +1 -1
  54. package/dist/utils/storage.js +7 -1
  55. package/dist/utils/storage.js.map +1 -1
  56. package/dist/utils/units.js +82 -0
  57. package/dist/utils/units.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/autocomplete/autocomplete-input.vue +124 -0
  60. package/src/autocomplete/autocomplete-root.vue +292 -0
  61. package/src/autocomplete/index.ts +74 -0
  62. package/src/combobox/combobox-content-impl.vue +13 -1
  63. package/src/index.ts +1 -0
  64. package/src/shared/use-id.ts +6 -8
  65. package/src/splitter/splitter-group.vue +249 -54
  66. package/src/splitter/splitter-panel.vue +12 -7
  67. package/src/splitter/utils/composables/use-window-splitter-panel-group-behavior.ts +18 -7
  68. package/src/splitter/utils/storage.ts +14 -0
  69. package/src/splitter/utils/units.ts +166 -0
  70. package/src/splitter/utils/validation.ts +3 -2
  71. package/src/toast/toast-announce.vue +4 -1
  72. package/src/tooltip/tooltip-content-impl.vue +18 -10
  73. package/src/tooltip/tooltip-content.vue +1 -3
  74. package/src/tooltip/tooltip-provider.vue +20 -3
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","names":["storageObject: PanelGroupStorage","name: string","value: string","autoSaveId: string","panels: Array<PanelData>","storage: PanelGroupStorage","panelSizesBeforeCollapse: Map<string, number>","sizes: Array<number>"],"sources":["../../src/splitter/utils/storage.ts"],"sourcesContent":[],"mappings":";AAOA,SAAgB,yBAAyBA,eAAkC;AACzE,KAAI;AACF,aAAW,iBAAiB,aAAa;AAEvC,iBAAc,UAAU,CAACC,SAAiB;AACxC,WAAO,aAAa,QAAQ,KAAK;GAClC;AACD,iBAAc,UAAU,CAACA,MAAcC,UAAkB;AACvD,iBAAa,QAAQ,MAAM,MAAM;GAClC;EACF,MACC,OAAM,IAAI,UAAU;CAEvB,SAAQ,OAAO;AACd,UAAQ,MAAM,MAAM;AAEpB,gBAAc,UAAU,MAAM;AAC9B,gBAAc,UAAU,MAAM,CAAE;CACjC;AACF;AAaD,SAAS,iBAAiBC,YAA4B;AACpD,QAAO,CAAC,KAAK,EAAE,YAAY;AAC5B;AAMD,SAAS,YAAYC,QAAkC;AACrD,QAAO,OACJ,IAAI,CAAC,UAAU;EACd,MAAM,EAAE,aAAa,IAAI,eAAe,OAAO,GAAG;AAClD,MAAI,cACF,QAAO;MAEP,QAAO,QACH,GAAG,MAAM,CAAC,EAAE,KAAK,UAAU,YAAY,EAAE,GACzC,KAAK,UAAU,YAAY;CAElC,EAAC,CACD,KAAK,CAAC,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,CAClC,KAAK,IAAI;AACb;AAED,SAAS,8BACPD,YACAE,SACkC;AAClC,KAAI;EACF,MAAM,gBAAgB,iBAAiB,WAAW;EAClD,MAAM,aAAa,QAAQ,QAAQ,cAAc;AACjD,MAAI,YAAY;GACd,MAAM,SAAS,KAAK,MAAM,WAAW;AACrC,cAAW,WAAW,YAAY,UAAU,KAC1C,QAAO;EAEV;CACF,QAAO,CAAE;AAEV,QAAO;AACR;AAED,SAAgB,oBACdF,YACAC,QACAC,SACgC;CAChC,MAAM,QAAQ,8BAA8B,YAAY,QAAQ,IAAI,CAAE;CACtE,MAAM,WAAW,YAAY,OAAO;AACpC,QAAO,MAAM,aAAa;AAC3B;AAED,SAAgB,oBACdF,YACAC,QACAE,0BACAC,OACAF,SACM;CACN,MAAM,gBAAgB,iBAAiB,WAAW;CAClD,MAAM,WAAW,YAAY,OAAO;CACpC,MAAM,QAAQ,8BAA8B,YAAY,QAAQ,IAAI,CAAE;AACtE,OAAM,YAAY;EAChB,eAAe,OAAO,YAAY,yBAAyB,SAAS,CAAC;EACrE,QAAQ;CACT;AAED,KAAI;AACF,UAAQ,QAAQ,eAAe,KAAK,UAAU,MAAM,CAAC;CACtD,SAAQ,OAAO;AACd,UAAQ,MAAM,MAAM;CACrB;AACF"}
1
+ {"version":3,"file":"storage.js","names":["storageObject: PanelGroupStorage","name: string","value: string","autoSaveId: string","panels: Array<PanelData>","storage: PanelGroupStorage","panelSizesBeforeCollapse: Map<string, number>","sizes: Array<number>","sizeUnits: { [panelIndex: number]: 'px' | '%' }"],"sources":["../../src/splitter/utils/storage.ts"],"sourcesContent":[],"mappings":";AAOA,SAAgB,yBAAyBA,eAAkC;AACzE,KAAI;AACF,aAAW,iBAAiB,aAAa;AAEvC,iBAAc,UAAU,CAACC,SAAiB;AACxC,WAAO,aAAa,QAAQ,KAAK;GAClC;AACD,iBAAc,UAAU,CAACA,MAAcC,UAAkB;AACvD,iBAAa,QAAQ,MAAM,MAAM;GAClC;EACF,MACC,OAAM,IAAI,UAAU;CAEvB,SAAQ,OAAO;AACd,UAAQ,MAAM,MAAM;AAEpB,gBAAc,UAAU,MAAM;AAC9B,gBAAc,UAAU,MAAM,CAAE;CACjC;AACF;AAgBD,SAAS,iBAAiBC,YAA4B;AACpD,QAAO,CAAC,KAAK,EAAE,YAAY;AAC5B;AAMD,SAAS,YAAYC,QAAkC;AACrD,QAAO,OACJ,IAAI,CAAC,UAAU;EACd,MAAM,EAAE,aAAa,IAAI,eAAe,OAAO,GAAG;AAClD,MAAI,cACF,QAAO;MAEP,QAAO,QACH,GAA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== null) return value;
4
+ if (sizeUnit === "%") return value;
5
+ if (groupSizeInPixels == null || groupSizeInPixels === 0) return void 0;
6
+ return value / groupSizeInPixels * 100;
7
+ }
8
+ function convertPanelConstraintsToPercent({ panelDataArray, groupSizeInPixels }) {
9
+ const requiresMeasurement = panelDataArray.some((panelData) => (panelData.constraints.sizeUnit ?? "%") === "px");
10
+ if (requiresMeasurement && (!groupSizeInPixels || Number.isNaN(groupSizeInPixels))) return null;
11
+ return panelDataArray.map((panelData) => {
12
+ const constraints = panelData.constraints;
13
+ const sizeUnit = constraints.sizeUnit ?? "%";
14
+ const collapsedSize = convertValueToPercent({
15
+ groupSizeInPixels,
16
+ sizeUnit,
17
+ value: constraints.collapsedSize
18
+ });
19
+ const defaultSize = convertValueToPercent({
20
+ groupSizeInPixels,
21
+ sizeUnit,
22
+ value: constraints.defaultSize
23
+ });
24
+ const maxSize = convertValueToPercent({
25
+ groupSizeInPixels,
26
+ sizeUnit,
27
+ value: constraints.maxSize
28
+ });
29
+ const minSize = convertValueToPercent({
30
+ groupSizeInPixels,
31
+ sizeUnit,
32
+ value: constraints.minSize
33
+ });
34
+ return {
35
+ ...constraints,
36
+ collapsedSize: collapsedSize ?? constraints.collapsedSize ?? 0,
37
+ defaultSize,
38
+ maxSize: maxSize ?? 100,
39
+ minSize: minSize ?? 0,
40
+ sizeUnit: "%"
41
+ };
42
+ });
43
+ }
44
+ function hasPixelSizedPanel(panelDataArray) {
45
+ return panelDataArray.some((panelData) => (panelData.constraints.sizeUnit ?? "%") === "px");
46
+ }
47
+ function recalculateLayoutForPixelPanels({ layout, panelDataArray, prevGroupSize, nextGroupSize }) {
48
+ if (!hasPixelSizedPanel(panelDataArray)) return null;
49
+ if (prevGroupSize == null || nextGroupSize == null || prevGroupSize === 0 || nextGroupSize === 0 || Number.isNaN(prevGroupSize) || Number.isNaN(nextGroupSize)) return null;
50
+ const pixelPanelIndices = panelDataArray.reduce((indices, panelData, index) => {
51
+ if ((panelData.constraints.sizeUnit ?? "%") === "px") indices.push(index);
52
+ return indices;
53
+ }, []);
54
+ if (pixelPanelIndices.length === 0) return null;
55
+ const pixelIndexSet = new Set(pixelPanelIndices);
56
+ const nextLayout = layout.map((size) => size ?? 0);
57
+ const nextPixelPercents = pixelPanelIndices.map((index) => {
58
+ const prevPercent = layout[index] ?? 0;
59
+ const prevPixelSize = prevPercent / 100 * prevGroupSize;
60
+ return prevPixelSize / nextGroupSize * 100;
61
+ });
62
+ const totalNextPixelPercent = nextPixelPercents.reduce((sum, value) => sum + value, 0);
63
+ const prevPercentForPercentPanels = layout.reduce((sum, size, index) => {
64
+ if (pixelIndexSet.has(index)) return sum;
65
+ return sum + (size ?? 0);
66
+ }, 0);
67
+ const availableNextPercent = Math.max(0, 100 - totalNextPixelPercent);
68
+ const scaleFactor = prevPercentForPercentPanels > 0 ? availableNextPercent / prevPercentForPercentPanels : 0;
69
+ pixelPanelIndices.forEach((panelIndex, arrayIndex) => {
70
+ nextLayout[panelIndex] = nextPixelPercents[arrayIndex];
71
+ });
72
+ for (let index = 0; index < nextLayout.length; index++) {
73
+ if (pixelIndexSet.has(index)) continue;
74
+ const prevSize = layout[index] ?? 0;
75
+ nextLayout[index] = prevSize * scaleFactor;
76
+ }
77
+ return nextLayout;
78
+ }
79
+
80
+ //#endregion
81
+ export { convertPanelConstraintsToPercent, hasPixelSizedPanel, recalculateLayoutForPixelPanels };
82
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","names":["panelDataArray: Array<PanelData>"],"sources":["../../src/splitter/utils/units.ts"],"sourcesContent":[],"mappings":";AAeA,SAAS,sBAAsB,EAAE,UAAU,mBAAmB,OAA4B,EAAsB;AAC9G,KAAI,SAAS,KACX,QAAO;AAGT,KAAI,aAAa,IACf,QAAO;AAGT,KAAI,qBAAqB,QAAQ,sBAAsB,EACrD;AAGF,QAAQ,QAAQ,oBAAqB;AACtC;AAED,SAAgB,iCAAiC,EAC/C,gBACA,mBACmC,EAAk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Q,EAAE;CAElD,MAAM,oBAAoB,kBAAkB,IAAI,CAAC,UAAU;EACzD,MAAM,cAAc,OAAO,UAAU;EACrC,MAAM,gBAAiB,cAAc,MAAO;AAC5C,SAAQ,gBAAgB,gBAAiB;CAC1C,EAAC;CAEF,MAAM,wBAAwB,kBAAkB,OAAO,CAAC,KAAK,UAAU,MAAM,OAAO,EAAE;CAEtF,MAAM,8BAA8B,OAAO,OAAO,CAAC,KAAK,MAAM,UAAU;AACtE,MAAI,cAAc,IAAI,MAAM,CAC1B,QAAO;AAGT,SAAO,OAAO,QAAQ;CACvB,GAAE,EAAE;CAEL,MAAM,uBAAuB,KAAK,IAAI,GAAG,MAAM,sBAAsB;CACrE,MAAM,cAAc,8BAA8B,IAC9C,uBAAuB,8BACvB;AAEJ,mBAAkB,QAAQ,CAAC,YAAY,eAAe;AACpD,aAAW,cAAc,kBAAkB;CAC5C,EAAC;AAEF,MAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS;AACtD,MAAI,cAAc,IAAI,MAAM,CAC1B;EAGF,MAAM,WAAW,OAAO,UAAU;AAClC,aAAW,SAAS,WAAW;CAChC;AAED,QAAO;AACR"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "akar",
3
3
  "type": "module",
4
- "version": "1.19.0",
4
+ "version": "1.20.0",
5
5
  "description": "Vue UI components",
6
6
  "author": "Vinicunca Contributors (https://github.com/vinicunca)",
7
7
  "license": "MIT",
@@ -0,0 +1,124 @@
1
+ <script lang="ts">
2
+ import type { AListboxFilterEmits, AListboxFilterProps } from '../listbox';
3
+
4
+ export type AAutocompleteInputEmits = AListboxFilterEmits;
5
+ export interface AAutocompleteInputProps extends AListboxFilterProps {}
6
+ </script>
7
+
8
+ <script setup lang="ts">
9
+ import { useVModel } from '@vueuse/core';
10
+ import { nextTick, onMounted, watch } from 'vue';
11
+ import { injectAComboboxRootContext } from '../combobox/combobox-root.vue';
12
+ import { AListboxFilter } from '../listbox';
13
+ import { injectAListboxRootContext } from '../listbox/listbox-root.vue';
14
+ import { usePrimitiveElement } from '../primitive';
15
+ import { injectAAutocompleteRootContext } from './autocomplete-root.vue';
16
+
17
+ const props = withDefaults(
18
+ defineProps<AAutocompleteInputProps>(),
19
+ {
20
+ as: 'input',
21
+ },
22
+ );
23
+ const emits = defineEmits<AAutocompleteInputEmits>();
24
+
25
+ const rootContext = injectAComboboxRootContext();
26
+ const autocompleteContext = injectAAutocompleteRootContext();
27
+ const listboxContext = injectAListboxRootContext();
28
+ const { primitiveElement, currentElement } = usePrimitiveElement();
29
+
30
+ const modelValue = useVModel(
31
+ props,
32
+ 'modelValue',
33
+ emits,
34
+ {
35
+ passive: (props.modelValue === undefined) as false,
36
+ },
37
+ );
38
+
39
+ if (autocompleteContext.modelValue.value) {
40
+ modelValue.value = autocompleteContext.modelValue.value;
41
+ }
42
+
43
+ onMounted(() => {
44
+ if (currentElement.value) {
45
+ rootContext.onInputElementChange(currentElement.value as HTMLInputElement);
46
+ }
47
+ });
48
+
49
+ function handleKeyDown(ev: KeyboardEvent) {
50
+ if (!rootContext.open.value) {
51
+ rootContext.onOpenChange(true);
52
+ }
53
+ }
54
+
55
+ function handleInput(event: InputEvent) {
56
+ const target = event.target as HTMLInputElement;
57
+ if (!rootContext.open.value) {
58
+ rootContext.onOpenChange(true);
59
+ nextTick(() => {
60
+ if (target.value) {
61
+ rootContext.filterSearch.value = target.value;
62
+ listboxContext.highlightFirstItem();
63
+ }
64
+ });
65
+ } else {
66
+ rootContext.filterSearch.value = target.value;
67
+ }
68
+ // Autocomplete-specific: update root's modelValue with the typed text
69
+ autocompleteContext.modelValue.value = target.value;
70
+ }
71
+
72
+ function handleFocus() {
73
+ if (rootContext.openOnFocus.value && !rootContext.open.value) {
74
+ rootContext.onOpenChange(true);
75
+ }
76
+ }
77
+
78
+ function handleClick() {
79
+ if (rootContext.openOnClick.value && !rootContext.open.value) {
80
+ rootContext.onOpenChange(true);
81
+ }
82
+ }
83
+
84
+ // When root's modelValue changes externally (e.g. item click, programmatic), sync the input display
85
+ watch(autocompleteContext.modelValue, (newVal) => {
86
+ const text = newVal ?? '';
87
+ if (modelValue.value !== text) {
88
+ modelValue.value = text;
89
+ }
90
+ });
91
+
92
+ // Restore input text when root triggers resetSearchTerm (e.g. on blur with resetSearchTermOnBlur)
93
+ rootContext.onResetSearchTerm(() => {
94
+ modelValue.value = autocompleteContext.modelValue.value ?? '';
95
+ });
96
+
97
+ watch(rootContext.filterState, (_newValue, oldValue) => {
98
+ if (!rootContext.isVirtual.value && (oldValue.count === 0)) {
99
+ listboxContext.highlightFirstItem();
100
+ }
101
+ });
102
+ </script>
103
+
104
+ <template>
105
+ <AListboxFilter
106
+ ref="primitiveElement"
107
+ v-model="modelValue"
108
+ :as="as"
109
+ :as-child="asChild"
110
+ :auto-focus="autoFocus"
111
+ :disabled="disabled"
112
+ :aria-expanded="rootContext.open.value"
113
+ :aria-controls="rootContext.contentId"
114
+ aria-autocomplete="list"
115
+ role="combobox"
116
+ autocomplete="off"
117
+ @click="handleClick"
118
+ @input="handleInput"
119
+ @keydown.down.up.prevent="handleKeyDown"
120
+ @focus="handleFocus"
121
+ >
122
+ <slot />
123
+ </AListboxFilter>
124
+ </template>
@@ -0,0 +1,292 @@
1
+ <script lang="ts">
2
+ import type { Ref } from 'vue';
3
+ import type { APrimitiveProps } from '../primitive';
4
+ import type { Direction, GenericComponentInstance } from '../shared/types';
5
+ import { createContext, useDirection, useFilter } from '../shared';
6
+
7
+ export interface AAutocompleteRootProps extends APrimitiveProps {
8
+ /** The controlled value of the Autocomplete (the input text). Can be bound with `v-model`. */
9
+ modelValue?: string;
10
+ /** The value of the autocomplete when initially rendered. Use when you do not need to control the state. */
11
+ defaultValue?: string;
12
+ /** The controlled open state of the Autocomplete. Can be bound with `v-model:open`. */
13
+ open?: boolean;
14
+ /** The open state of the autocomplete when it is initially rendered. Use when you do not need to control its open state. */
15
+ defaultOpen?: boolean;
16
+ /** When `true`, prevents the user from interacting with autocomplete */
17
+ disabled?: boolean;
18
+ /** The reading direction of the autocomplete when applicable. */
19
+ dir?: Direction;
20
+ /** The name of the field. Submitted with its owning form as part of a name/value pair. */
21
+ name?: string;
22
+ /** When `true`, indicates that the user must set the value before the owning form can be submitted. */
23
+ required?: boolean;
24
+ /**
25
+ * Whether to reset the searchTerm when the Autocomplete input blurred
26
+ * @defaultValue `false`
27
+ */
28
+ resetSearchTermOnBlur?: boolean;
29
+ /**
30
+ * Whether to open the autocomplete when the input is focused
31
+ * @defaultValue `false`
32
+ */
33
+ openOnFocus?: boolean;
34
+ /**
35
+ * Whether to open the autocomplete when the input is clicked
36
+ * @defaultValue `false`
37
+ */
38
+ openOnClick?: boolean;
39
+ /**
40
+ * When `true`, disable the default filters
41
+ */
42
+ ignoreFilter?: boolean;
43
+ /** When `true`, hover over item will trigger highlight */
44
+ highlightOnHover?: boolean;
45
+ }
46
+
47
+ export type AAutocompleteRootEmits = {
48
+ /** Event handler called when the value changes. */
49
+ 'update:modelValue': [value: string];
50
+ /** Event handler when highlighted element changes. */
51
+ 'highlight': [payload: { ref: HTMLElement; value: string } | undefined];
52
+ /** Event handler called when the open state of the autocomplete changes. */
53
+ 'update:open': [value: boolean];
54
+ };
55
+
56
+ export type AAutocompleteRootContext = {
57
+ modelValue: Ref<string>;
58
+ };
59
+
60
+ export const [
61
+ injectAAutocompleteRootContext,
62
+ provideAAutocompleteRootContext,
63
+ ] = createContext<AAutocompleteRootContext>('AutocompleteRoot');
64
+ </script>
65
+
66
+ <script setup lang="ts">
67
+ import { createEventHook, useVModel } from '@vueuse/core';
68
+ import { computed, getCurrentInstance, nextTick, onMounted, ref, toRefs } from 'vue';
69
+ import { provideComboboxRootContext } from '../combobox/combobox-root.vue';
70
+ import { AListboxRoot } from '../listbox';
71
+ import { APopperRoot } from '../popper';
72
+ import { usePrimitiveElement } from '../primitive';
73
+
74
+ const props = withDefaults(
75
+ defineProps<AAutocompleteRootProps>(),
76
+ {
77
+ open: undefined,
78
+ resetSearchTermOnBlur: false,
79
+ openOnFocus: false,
80
+ openOnClick: false,
81
+ highlightOnHover: true,
82
+ },
83
+ );
84
+ const emits = defineEmits<AAutocompleteRootEmits>();
85
+
86
+ defineSlots<{
87
+ default?: (props: {
88
+ /** Current open state */
89
+ open: typeof open.value;
90
+ /** Current active value */
91
+ modelValue: typeof modelValue.value;
92
+ }) => any;
93
+ }>();
94
+
95
+ const {
96
+ primitiveElement,
97
+ currentElement: parentElement,
98
+ } = usePrimitiveElement<GenericComponentInstance<typeof AListboxRoot>>();
99
+ const {
100
+ disabled,
101
+ ignoreFilter,
102
+ openOnFocus,
103
+ openOnClick,
104
+ dir: propDir,
105
+ highlightOnHover,
106
+ } = toRefs(props);
107
+
108
+ const dir = useDirection(propDir);
109
+
110
+ const modelValue = useVModel(props, 'modelValue', emits, {
111
+ defaultValue: props.defaultValue ?? '',
112
+ passive: (props.modelValue === undefined) as false,
113
+ }) as Ref<string>;
114
+
115
+ const open = useVModel(props, 'open', emits, {
116
+ defaultValue: props.defaultOpen,
117
+ passive: (props.open === undefined) as false,
118
+ }) as Ref<boolean>;
119
+
120
+ // Writable computed that converts any value to string for the ComboboxRootContext.
121
+ // This handles the case when ComboboxItem sets modelValue to a non-string value,
122
+ // or when ComboboxCancel resets modelValue to null.
123
+ const contextModelValue = computed({
124
+ get: () => modelValue.value,
125
+ set: (val: any) => {
126
+ if (val === null || val === undefined) {
127
+ modelValue.value = '';
128
+ } else {
129
+ modelValue.value = String(val);
130
+ }
131
+ },
132
+ });
133
+
134
+ async function onOpenChange(val: boolean) {
135
+ open.value = val;
136
+
137
+ if (val) {
138
+ // When opening, set filter to current text so items are filtered by what's in the input
139
+ filterSearch.value = modelValue.value || '';
140
+
141
+ await nextTick();
142
+ primitiveElement.value?.highlightSelected();
143
+ isUserInputted.value = true;
144
+ inputElement.value?.focus();
145
+ } else {
146
+ isUserInputted.value = false;
147
+ filterSearch.value = '';
148
+ setTimeout(() => {
149
+ // eslint-disable-next-line sonar/no-gratuitous-expressions
150
+ if (!val && props.resetSearchTermOnBlur) {
151
+ resetSearchTerm.trigger();
152
+ }
153
+ }, 1);
154
+ }
155
+ }
156
+
157
+ const resetSearchTerm = createEventHook();
158
+ const isUserInputted = ref(false);
159
+ const isVirtual = ref(false);
160
+ const inputElement = ref<HTMLInputElement>();
161
+ const triggerElement = ref<HTMLElement>();
162
+
163
+ const highlightedElement = computed(() => primitiveElement.value?.highlightedElement ?? undefined);
164
+
165
+ const allItems = ref<Map<string, string>>(new Map());
166
+ const allGroups = ref<Map<string, Set<string>>>(new Map());
167
+
168
+ const { contains } = useFilter({ sensitivity: 'base' });
169
+
170
+ const filterSearch = ref('');
171
+
172
+ const filterState = computed<{
173
+ count: number;
174
+ items: Map<string, number>;
175
+ groups: Set<string>;
176
+ }>((oldValue) => {
177
+ if (!filterSearch.value || props.ignoreFilter || isVirtual.value) {
178
+ return {
179
+ count: allItems.value.size,
180
+ items: oldValue?.items ?? new Map(),
181
+ groups: oldValue?.groups ?? new Set(allGroups.value.keys()),
182
+ };
183
+ }
184
+
185
+ let itemCount = 0;
186
+ const filteredItems = new Map<string, number>();
187
+ const filteredGroups = new Set<string>();
188
+
189
+ for (const [id, value] of allItems.value) {
190
+ const score = contains({ string: value, substring: filterSearch.value });
191
+ filteredItems.set(id, score ? 1 : 0);
192
+ if (score) {
193
+ itemCount++;
194
+ }
195
+ }
196
+
197
+ for (const [groupId, group] of allGroups.value) {
198
+ for (const itemId of group) {
199
+ if (filteredItems.get(itemId)! > 0) {
200
+ filteredGroups.add(groupId);
201
+ break;
202
+ }
203
+ }
204
+ }
205
+
206
+ return {
207
+ count: itemCount,
208
+ items: filteredItems,
209
+ groups: filteredGroups,
210
+ };
211
+ });
212
+
213
+ const inst = getCurrentInstance();
214
+ onMounted(() => {
215
+ if (inst?.exposed) {
216
+ inst.exposed.highlightItem = primitiveElement.value?.highlightItem;
217
+ inst.exposed.highlightFirstItem = primitiveElement.value?.highlightFirstItem;
218
+ inst.exposed.highlightSelected = primitiveElement.value?.highlightSelected;
219
+ }
220
+ });
221
+
222
+ defineExpose({
223
+ filtered: filterState,
224
+ highlightedElement,
225
+ highlightItem: primitiveElement.value?.highlightItem,
226
+ highlightFirstItem: primitiveElement.value?.highlightFirstItem,
227
+ highlightSelected: primitiveElement.value?.highlightSelected,
228
+ });
229
+
230
+ // Provide the Combobox context so all Combobox sub-components work inside Autocomplete
231
+ provideComboboxRootContext({
232
+ modelValue: contextModelValue as any,
233
+ multiple: ref(false),
234
+ disabled,
235
+ open,
236
+ onOpenChange,
237
+ contentId: '',
238
+ isUserInputted,
239
+ isVirtual,
240
+ inputElement,
241
+ highlightedElement,
242
+ onInputElementChange: (val) => {
243
+ inputElement.value = val;
244
+ },
245
+ triggerElement,
246
+ onTriggerElementChange: (val) => {
247
+ triggerElement.value = val;
248
+ },
249
+ parentElement,
250
+ resetSearchTermOnSelect: ref(false),
251
+ onResetSearchTerm: resetSearchTerm.on,
252
+ allItems,
253
+ allGroups,
254
+ filterSearch,
255
+ filterState,
256
+ ignoreFilter,
257
+ openOnFocus,
258
+ openOnClick,
259
+ resetModelValueOnClear: ref(true),
260
+ });
261
+
262
+ // Provide autocomplete-specific context
263
+ provideAAutocompleteRootContext({
264
+ modelValue,
265
+ });
266
+ </script>
267
+
268
+ <template>
269
+ <APopperRoot>
270
+ <AListboxRoot
271
+ ref="primitiveElement"
272
+ v-bind="$attrs"
273
+ v-model="(contextModelValue as any)"
274
+ :style="{
275
+ pointerEvents: open ? 'auto' : undefined,
276
+ }"
277
+ :as="as"
278
+ :as-child="asChild"
279
+ :dir="dir"
280
+ :name="name"
281
+ :required="required"
282
+ :disabled="disabled"
283
+ :highlight-on-hover="highlightOnHover"
284
+ @highlight="emits('highlight', $event as any)"
285
+ >
286
+ <slot
287
+ :open="open"
288
+ :model-value="modelValue"
289
+ />
290
+ </AListboxRoot>
291
+ </APopperRoot>
292
+ </template>
@@ -0,0 +1,74 @@
1
+ // Re-export Combobox sub-components as Autocomplete equivalents.
2
+ // These components inject ComboboxRootContext which AutocompleteRoot provides.
3
+ export {
4
+ AComboboxAnchor as AAutocompleteAnchor,
5
+ type AComboboxAnchorProps as AAutocompleteAnchorProps,
6
+ } from '../combobox';
7
+ export {
8
+ AComboboxArrow as AAutocompleteArrow,
9
+ type AComboboxArrowProps as AAutocompleteArrowProps,
10
+ } from '../combobox';
11
+
12
+ export {
13
+ AComboboxCancel as AAutocompleteCancel,
14
+ type AComboboxCancelProps as AAutocompleteCancelProps,
15
+ } from '../combobox';
16
+ export {
17
+ AComboboxContent as AAutocompleteContent,
18
+ type AComboboxContentEmits as AAutocompleteContentEmits,
19
+ type AComboboxContentProps as AAutocompleteContentProps,
20
+ } from '../combobox';
21
+ export {
22
+ AComboboxEmpty as AAutocompleteEmpty,
23
+ type AComboboxEmptyProps as AAutocompleteEmptyProps,
24
+ } from '../combobox';
25
+ export {
26
+ AComboboxGroup as AAutocompleteGroup,
27
+ type AComboboxGroupProps as AAutocompleteGroupProps,
28
+ } from '../combobox';
29
+ export {
30
+ AComboboxItem as AAutocompleteItem,
31
+ type AComboboxItemEmits as AAutocompleteItemEmits,
32
+ type AComboboxItemProps as AAutocompleteItemProps,
33
+ } from '../combobox';
34
+ export {
35
+ AComboboxItemIndicator as AAutocompleteItemIndicator,
36
+ type AComboboxItemIndicatorProps as AAutocompleteItemIndicatorProps,
37
+ } from '../combobox';
38
+ export {
39
+ AComboboxLabel as AAutocompleteLabel,
40
+ type AComboboxLabelProps as AAutocompleteLabelProps,
41
+ } from '../combobox';
42
+ export {
43
+ AComboboxPortal as AAutocompletePortal,
44
+ type AComboboxPortalProps as AAutocompletePortalProps,
45
+ } from '../combobox';
46
+ export {
47
+ AComboboxSeparator as AAutocompleteSeparator,
48
+ type AComboboxSeparatorProps as AAutocompleteSeparatorProps,
49
+ } from '../combobox';
50
+ export {
51
+ AComboboxTrigger as AAutocompleteTrigger,
52
+ type AComboboxTriggerProps as AAutocompleteTriggerProps,
53
+ } from '../combobox';
54
+ export {
55
+ AComboboxViewport as AAutocompleteViewport,
56
+ type AComboboxViewportProps as AAutocompleteViewportProps,
57
+ } from '../combobox';
58
+ export {
59
+ AComboboxVirtualizer as AAutocompleteVirtualizer,
60
+ type AComboboxVirtualizerProps as AAutocompleteVirtualizerProps,
61
+ } from '../combobox';
62
+
63
+ export {
64
+ default as AAutocompleteInput,
65
+ type AAutocompleteInputEmits,
66
+ type AAutocompleteInputProps,
67
+ } from './autocomplete-input.vue';
68
+
69
+ export {
70
+ default as AAutocompleteRoot,
71
+ type AAutocompleteRootEmits,
72
+ type AAutocompleteRootProps,
73
+ injectAAutocompleteRootContext,
74
+ } from './autocomplete-root.vue';
@@ -24,6 +24,11 @@ export interface ComboboxContentImplProps extends APopperContentProps, Dismissab
24
24
  position?: 'inline' | 'popper';
25
25
  /** The document.body will be lock, and scrolling will be disabled. */
26
26
  bodyLock?: boolean;
27
+ /**
28
+ * When `true`, hides the content when there are no items matching the filter.
29
+ * @defaultValue false
30
+ */
31
+ hideWhenEmpty?: boolean;
27
32
  }
28
33
 
29
34
  export const [
@@ -51,6 +56,11 @@ const emits = defineEmits<ComboboxContentImplEmits>();
51
56
  const { position } = toRefs(props);
52
57
  const rootContext = injectAComboboxRootContext();
53
58
 
59
+ const isEmpty = computed(() => rootContext.ignoreFilter.value
60
+ ? rootContext.allItems.value.size === 0
61
+ : rootContext.filterState.value.count === 0,
62
+ );
63
+
54
64
  const { forwardRef, currentElement } = useForwardExpose();
55
65
  useBodyScrollLock(props.bodyLock);
56
66
  useFocusGuards();
@@ -130,9 +140,11 @@ onUnmounted(() => {
130
140
  :id="rootContext.contentId"
131
141
  :ref="forwardRef"
132
142
  :data-state="rootContext.open.value ? 'open' : 'closed'"
143
+ :data-empty="isEmpty ? '' : undefined"
133
144
  :style="{
134
145
  // flex layout so we can place the scroll buttons properly
135
- display: 'flex',
146
+ // When hideWhenEmpty is true, hide the content when no items match
147
+ display: (props.hideWhenEmpty && isEmpty) ? 'none' : 'flex',
136
148
  flexDirection: 'column',
137
149
  // reset the outline by default as the content MAY get focused
138
150
  outline: 'none',
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable perfectionist/sort-exports */
2
2
  export * from './accordion';
3
+ export * from './autocomplete';
3
4
  export * from './avatar';
4
5
  export * from './alert-dialog';
5
6
  export * from './calendar';
@@ -18,15 +18,13 @@ export function useId(deterministicId?: null | string | undefined, prefix = 'aka
18
18
  return deterministicId;
19
19
  }
20
20
 
21
+ let id: string;
21
22
  if (Object.hasOwn(vue, 'useId')) {
22
- return `${prefix}-${vue.useId?.()}`;
23
+ id = vue.useId?.();
24
+ } else {
25
+ const configProviderContext = injectAConfigProviderContext({ useId: undefined });
26
+ id = configProviderContext.useId?.() ?? `${++count}`;
23
27
  }
24
28
 
25
- const configProviderContext = injectAConfigProviderContext({ useId: undefined });
26
-
27
- if (configProviderContext.useId) {
28
- return `${prefix}-${configProviderContext.useId()}`;
29
- }
30
-
31
- return `${prefix}-${++count}`;
29
+ return prefix ? `${prefix}-${id}` : id;
32
30
  }