@ariakit/core 0.4.4 → 0.4.6

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 (128) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/cjs/__chunks/{Y7KNI5NS.cjs → 3HYNC3XA.cjs} +5 -5
  3. package/cjs/__chunks/{FFZYCAXA.cjs → 4W3OYRR3.cjs} +2 -2
  4. package/cjs/__chunks/{SU2BSHGB.cjs → B4AKUC4S.cjs} +2 -2
  5. package/cjs/__chunks/{7DU6YMLQ.cjs → D7M2PCAQ.cjs} +6 -6
  6. package/cjs/__chunks/LPDHSEHU.cjs +71 -0
  7. package/cjs/__chunks/{UKR6TQI3.cjs → Q2WCPTYS.cjs} +37 -39
  8. package/cjs/checkbox/checkbox-store.d.cts +2 -2
  9. package/cjs/checkbox/checkbox-store.d.ts +2 -2
  10. package/cjs/collection/collection-store.cjs +3 -3
  11. package/cjs/collection/collection-store.d.cts +2 -2
  12. package/cjs/collection/collection-store.d.ts +2 -2
  13. package/cjs/combobox/combobox-store.cjs +50 -22
  14. package/cjs/combobox/combobox-store.d.cts +20 -9
  15. package/cjs/combobox/combobox-store.d.ts +20 -9
  16. package/cjs/composite/composite-overflow-store.d.cts +2 -2
  17. package/cjs/composite/composite-overflow-store.d.ts +2 -2
  18. package/cjs/composite/composite-store.cjs +5 -5
  19. package/cjs/composite/composite-store.d.cts +3 -3
  20. package/cjs/composite/composite-store.d.ts +3 -3
  21. package/cjs/dialog/dialog-store.d.cts +2 -2
  22. package/cjs/dialog/dialog-store.d.ts +2 -2
  23. package/cjs/disclosure/disclosure-store.d.cts +2 -2
  24. package/cjs/disclosure/disclosure-store.d.ts +2 -2
  25. package/cjs/form/form-store.cjs +3 -3
  26. package/cjs/form/form-store.d.cts +4 -4
  27. package/cjs/form/form-store.d.ts +4 -4
  28. package/cjs/form/types.d.cts +3 -3
  29. package/cjs/form/types.d.ts +3 -3
  30. package/cjs/hovercard/hovercard-store.d.cts +3 -3
  31. package/cjs/hovercard/hovercard-store.d.ts +3 -3
  32. package/cjs/menu/menu-bar-store.cjs +6 -6
  33. package/cjs/menu/menu-bar-store.d.cts +2 -2
  34. package/cjs/menu/menu-bar-store.d.ts +2 -2
  35. package/cjs/menu/menu-store.cjs +7 -7
  36. package/cjs/menu/menu-store.d.cts +6 -6
  37. package/cjs/menu/menu-store.d.ts +6 -6
  38. package/cjs/menubar/menubar-store.cjs +6 -6
  39. package/cjs/menubar/menubar-store.d.cts +2 -2
  40. package/cjs/menubar/menubar-store.d.ts +2 -2
  41. package/cjs/popover/popover-store.d.cts +3 -3
  42. package/cjs/popover/popover-store.d.ts +3 -3
  43. package/cjs/radio/radio-store.cjs +5 -5
  44. package/cjs/radio/radio-store.d.cts +3 -3
  45. package/cjs/radio/radio-store.d.ts +3 -3
  46. package/cjs/select/select-store.cjs +21 -11
  47. package/cjs/select/select-store.d.cts +17 -9
  48. package/cjs/select/select-store.d.ts +17 -9
  49. package/cjs/tab/tab-store.cjs +46 -13
  50. package/cjs/tab/tab-store.d.cts +7 -6
  51. package/cjs/tab/tab-store.d.ts +7 -6
  52. package/cjs/tag/tag-store.cjs +90 -0
  53. package/cjs/tag/tag-store.d.cts +80 -0
  54. package/cjs/tag/tag-store.d.ts +80 -0
  55. package/cjs/toolbar/toolbar-store.cjs +5 -5
  56. package/cjs/toolbar/toolbar-store.d.cts +2 -2
  57. package/cjs/toolbar/toolbar-store.d.ts +2 -2
  58. package/cjs/tooltip/tooltip-store.d.cts +2 -2
  59. package/cjs/tooltip/tooltip-store.d.ts +2 -2
  60. package/cjs/utils/dom.cjs +2 -2
  61. package/cjs/utils/dom.d.cts +15 -22
  62. package/cjs/utils/dom.d.ts +15 -22
  63. package/cjs/utils/events.cjs +32 -16
  64. package/cjs/utils/events.d.cts +7 -1
  65. package/cjs/utils/events.d.ts +7 -1
  66. package/cjs/utils/focus.cjs +13 -15
  67. package/cjs/utils/focus.d.cts +1 -1
  68. package/cjs/utils/focus.d.ts +1 -1
  69. package/cjs/utils/misc.d.cts +1 -1
  70. package/cjs/utils/misc.d.ts +1 -1
  71. package/cjs/utils/platform.cjs +3 -3
  72. package/cjs/utils/store.d.cts +3 -3
  73. package/cjs/utils/store.d.ts +3 -3
  74. package/cjs/utils/undo.cjs +10 -0
  75. package/cjs/utils/undo.d.cts +19 -0
  76. package/cjs/utils/undo.d.ts +19 -0
  77. package/esm/__chunks/{VDNATJW2.js → CLSHHUGK.js} +1 -1
  78. package/esm/__chunks/EKIWAN6A.js +71 -0
  79. package/esm/__chunks/{URUD7X4C.js → EQPTKGFA.js} +1 -1
  80. package/esm/__chunks/{RRSZHCH6.js → I2NJJ3XW.js} +39 -41
  81. package/esm/__chunks/{PXYVPXSS.js → P3MTNH46.js} +1 -1
  82. package/esm/__chunks/{2H5K47H4.js → PBSSD2DM.js} +5 -5
  83. package/esm/checkbox/checkbox-store.d.ts +2 -2
  84. package/esm/collection/collection-store.d.ts +2 -2
  85. package/esm/collection/collection-store.js +2 -2
  86. package/esm/combobox/combobox-store.d.ts +20 -9
  87. package/esm/combobox/combobox-store.js +52 -24
  88. package/esm/composite/composite-overflow-store.d.ts +2 -2
  89. package/esm/composite/composite-store.d.ts +3 -3
  90. package/esm/composite/composite-store.js +4 -4
  91. package/esm/dialog/dialog-store.d.ts +2 -2
  92. package/esm/disclosure/disclosure-store.d.ts +2 -2
  93. package/esm/form/form-store.d.ts +4 -4
  94. package/esm/form/form-store.js +2 -2
  95. package/esm/form/types.d.ts +3 -3
  96. package/esm/hovercard/hovercard-store.d.ts +3 -3
  97. package/esm/menu/menu-bar-store.d.ts +2 -2
  98. package/esm/menu/menu-bar-store.js +5 -5
  99. package/esm/menu/menu-store.d.ts +6 -6
  100. package/esm/menu/menu-store.js +6 -6
  101. package/esm/menubar/menubar-store.d.ts +2 -2
  102. package/esm/menubar/menubar-store.js +5 -5
  103. package/esm/popover/popover-store.d.ts +3 -3
  104. package/esm/radio/radio-store.d.ts +3 -3
  105. package/esm/radio/radio-store.js +4 -4
  106. package/esm/select/select-store.d.ts +17 -9
  107. package/esm/select/select-store.js +20 -10
  108. package/esm/tab/tab-store.d.ts +7 -6
  109. package/esm/tab/tab-store.js +44 -11
  110. package/esm/tag/tag-store.d.ts +80 -0
  111. package/esm/tag/tag-store.js +90 -0
  112. package/esm/toolbar/toolbar-store.d.ts +2 -2
  113. package/esm/toolbar/toolbar-store.js +4 -4
  114. package/esm/tooltip/tooltip-store.d.ts +2 -2
  115. package/esm/utils/dom.d.ts +15 -22
  116. package/esm/utils/dom.js +5 -5
  117. package/esm/utils/events.d.ts +7 -1
  118. package/esm/utils/events.js +28 -12
  119. package/esm/utils/focus.d.ts +1 -1
  120. package/esm/utils/focus.js +5 -7
  121. package/esm/utils/misc.d.ts +1 -1
  122. package/esm/utils/platform.js +2 -2
  123. package/esm/utils/store.d.ts +3 -3
  124. package/esm/utils/undo.d.ts +19 -0
  125. package/esm/utils/undo.js +10 -0
  126. package/package.json +15 -1
  127. package/tag/tag-store/package.json +8 -0
  128. package/utils/undo/package.json +8 -0
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  createCompositeStore
4
- } from "../__chunks/2H5K47H4.js";
4
+ } from "../__chunks/PBSSD2DM.js";
5
5
  import {
6
6
  createCollectionStore
7
- } from "../__chunks/URUD7X4C.js";
7
+ } from "../__chunks/EQPTKGFA.js";
8
+ import "../__chunks/7PRQYBBV.js";
8
9
  import {
9
10
  batch,
10
11
  createStore,
@@ -14,10 +15,10 @@ import {
14
15
  sync
15
16
  } from "../__chunks/R676XYVY.js";
16
17
  import {
18
+ chain,
17
19
  defaultValue
18
20
  } from "../__chunks/22HHDS5F.js";
19
- import "../__chunks/RRSZHCH6.js";
20
- import "../__chunks/7PRQYBBV.js";
21
+ import "../__chunks/I2NJJ3XW.js";
21
22
  import {
22
23
  __objRest,
23
24
  __spreadProps,
@@ -38,6 +39,8 @@ function createTabStore(_a = {}) {
38
39
  "renderedItems",
39
40
  "moves",
40
41
  "orientation",
42
+ "virtualFocus",
43
+ "includesBaseElement",
41
44
  "baseElement",
42
45
  "focusLoop",
43
46
  "focusShift",
@@ -50,6 +53,16 @@ function createTabStore(_a = {}) {
50
53
  );
51
54
  const syncState = store == null ? void 0 : store.getState();
52
55
  const composite = createCompositeStore(__spreadProps(__spreadValues({}, props), {
56
+ store,
57
+ // We need to explicitly set the default value of `includesBaseElement` to
58
+ // `false` since we don't want the composite store to default it to `true`
59
+ // when the activeId state is null, which could be the case when rendering
60
+ // combobox with tab.
61
+ includesBaseElement: defaultValue(
62
+ props.includesBaseElement,
63
+ syncState == null ? void 0 : syncState.includesBaseElement,
64
+ false
65
+ ),
53
66
  orientation: defaultValue(
54
67
  props.orientation,
55
68
  syncState == null ? void 0 : syncState.orientation,
@@ -62,8 +75,7 @@ function createTabStore(_a = {}) {
62
75
  selectedId: defaultValue(
63
76
  props.selectedId,
64
77
  syncState == null ? void 0 : syncState.selectedId,
65
- props.defaultSelectedId,
66
- void 0
78
+ props.defaultSelectedId
67
79
  ),
68
80
  selectOnMove: defaultValue(
69
81
  props.selectOnMove,
@@ -92,11 +104,11 @@ function createTabStore(_a = {}) {
92
104
  );
93
105
  setup(
94
106
  tab,
95
- () => batch(
96
- tab,
97
- ["selectedId"],
98
- (state) => tab.setState("activeId", state.selectedId)
99
- )
107
+ () => batch(tab, ["selectedId"], (state, prev) => {
108
+ if (parentComposite && state.selectedId === prev.selectedId)
109
+ return;
110
+ tab.setState("activeId", state.selectedId);
111
+ })
100
112
  );
101
113
  setup(
102
114
  tab,
@@ -137,6 +149,27 @@ function createTabStore(_a = {}) {
137
149
  });
138
150
  })
139
151
  );
152
+ let selectedIdFromSelectedValue = null;
153
+ setup(tab, () => {
154
+ const backupSelectedId = () => {
155
+ selectedIdFromSelectedValue = tab.getState().selectedId;
156
+ };
157
+ const restoreSelectedId = () => {
158
+ tab.setState("selectedId", selectedIdFromSelectedValue);
159
+ };
160
+ if (parentComposite && "setSelectElement" in parentComposite) {
161
+ return chain(
162
+ sync(parentComposite, ["value"], backupSelectedId),
163
+ sync(parentComposite, ["open"], restoreSelectedId)
164
+ );
165
+ }
166
+ if (!combobox)
167
+ return;
168
+ return chain(
169
+ sync(combobox, ["selectedValue"], backupSelectedId),
170
+ sync(combobox, ["open"], restoreSelectedId)
171
+ );
172
+ });
140
173
  return __spreadProps(__spreadValues(__spreadValues({}, composite), tab), {
141
174
  panels,
142
175
  setSelectedId: (id) => tab.setState("selectedId", id),
@@ -0,0 +1,80 @@
1
+ import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.ts";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.ts";
3
+ import type { SetState } from "../utils/types.ts";
4
+ /**
5
+ * Creates a tag store.
6
+ */
7
+ export declare function createTagStore(props?: TagStoreProps): TagStore;
8
+ export interface TagStoreItem extends CompositeStoreItem {
9
+ value?: string;
10
+ }
11
+ export interface TagStoreState extends CompositeStoreState<TagStoreItem> {
12
+ /**
13
+ * The input element.
14
+ */
15
+ inputElement: HTMLElement | null;
16
+ /**
17
+ * The label element.
18
+ */
19
+ labelElement: HTMLElement | null;
20
+ /**
21
+ * The value of the tag input.
22
+ * @default ""
23
+ */
24
+ value: string;
25
+ /**
26
+ * The values of the selected tags.
27
+ * @default []
28
+ */
29
+ values: string[];
30
+ }
31
+ export interface TagStoreFunctions extends CompositeStoreFunctions<TagStoreItem> {
32
+ /**
33
+ * Sets the `inputElement` state.
34
+ */
35
+ setInputElement: SetState<TagStoreState["inputElement"]>;
36
+ /**
37
+ * Sets the `labelElement` state.
38
+ */
39
+ setLabelElement: SetState<TagStoreState["labelElement"]>;
40
+ /**
41
+ * Sets the [`value`](https://ariakit.org/reference/tag-provider#value) state.
42
+ */
43
+ setValue: SetState<TagStoreState["value"]>;
44
+ /**
45
+ * Resets the [`value`](https://ariakit.org/reference/tag-provider#value)
46
+ * state to its initial value.
47
+ */
48
+ resetValue: () => void;
49
+ /**
50
+ * Sets the [`values`](https://ariakit.org/reference/tag-provider#values) state.
51
+ */
52
+ setValues: SetState<TagStoreState["values"]>;
53
+ /**
54
+ * Add a new value to the
55
+ * [`values`](https://ariakit.org/reference/tag-provider#values) state if it
56
+ * doesn't already exist.
57
+ */
58
+ addValue: (value: string) => void;
59
+ /**
60
+ * Remove a value from the
61
+ * [`values`](https://ariakit.org/reference/tag-provider#values) state.
62
+ */
63
+ removeValue: (value: string) => void;
64
+ }
65
+ export interface TagStoreOptions extends StoreOptions<TagStoreState, "value" | "values">, CompositeStoreOptions<TagStoreItem> {
66
+ /**
67
+ * The initial value of the tag input.
68
+ * @default ""
69
+ */
70
+ defaultValue?: TagStoreState["value"];
71
+ /**
72
+ * The initial selected tag values.
73
+ * @default []
74
+ */
75
+ defaultValues?: TagStoreState["values"];
76
+ }
77
+ export interface TagStoreProps extends TagStoreOptions, StoreProps<TagStoreState> {
78
+ }
79
+ export interface TagStore extends TagStoreFunctions, Store<TagStoreState> {
80
+ }
@@ -0,0 +1,90 @@
1
+ "use client";
2
+ import {
3
+ createCompositeStore
4
+ } from "../__chunks/PBSSD2DM.js";
5
+ import "../__chunks/EQPTKGFA.js";
6
+ import "../__chunks/7PRQYBBV.js";
7
+ import {
8
+ UndoManager
9
+ } from "../__chunks/EKIWAN6A.js";
10
+ import {
11
+ createStore,
12
+ setup,
13
+ sync
14
+ } from "../__chunks/R676XYVY.js";
15
+ import {
16
+ applyState,
17
+ defaultValue
18
+ } from "../__chunks/22HHDS5F.js";
19
+ import "../__chunks/I2NJJ3XW.js";
20
+ import {
21
+ __spreadProps,
22
+ __spreadValues
23
+ } from "../__chunks/4R3V3JGP.js";
24
+
25
+ // src/tag/tag-store.ts
26
+ function createTagStore(props = {}) {
27
+ var _a;
28
+ const syncState = (_a = props.store) == null ? void 0 : _a.getState();
29
+ const composite = createCompositeStore(props);
30
+ const initialState = __spreadProps(__spreadValues({}, composite.getState()), {
31
+ inputElement: defaultValue(syncState == null ? void 0 : syncState.inputElement, null),
32
+ labelElement: defaultValue(syncState == null ? void 0 : syncState.labelElement, null),
33
+ value: defaultValue(props.value, syncState == null ? void 0 : syncState.value, props.defaultValue, ""),
34
+ values: defaultValue(
35
+ props.values,
36
+ syncState == null ? void 0 : syncState.values,
37
+ props.defaultValues,
38
+ []
39
+ )
40
+ });
41
+ const tag = createStore(initialState, composite, props.store);
42
+ setup(
43
+ tag,
44
+ () => sync(tag, ["inputElement", "activeId"], (state) => {
45
+ if (!state.inputElement)
46
+ return;
47
+ if (state.activeId !== void 0)
48
+ return;
49
+ tag.setState("activeId", state.inputElement.id);
50
+ })
51
+ );
52
+ const setValues = (values) => {
53
+ const { values: previousValues } = tag.getState();
54
+ UndoManager.execute(() => {
55
+ let changed = true;
56
+ tag.setState("values", (prev) => {
57
+ const next = applyState(values, prev);
58
+ if (next === prev) {
59
+ changed = false;
60
+ }
61
+ return next;
62
+ });
63
+ if (!changed)
64
+ return;
65
+ return () => {
66
+ var _a2;
67
+ tag.setState("values", previousValues);
68
+ composite.move((_a2 = tag.getState().inputElement) == null ? void 0 : _a2.id);
69
+ };
70
+ });
71
+ };
72
+ return __spreadProps(__spreadValues(__spreadValues({}, composite), tag), {
73
+ setInputElement: (inputElement) => tag.setState("inputElement", inputElement),
74
+ setLabelElement: (labelElement) => tag.setState("labelElement", labelElement),
75
+ setValue: (value) => tag.setState("value", value),
76
+ resetValue: () => tag.setState("value", initialState.value),
77
+ setValues,
78
+ addValue: (value) => {
79
+ setValues((values) => {
80
+ if (values.includes(value))
81
+ return values;
82
+ return [...values, value];
83
+ });
84
+ },
85
+ removeValue: (value) => setValues((values) => values.filter((v) => v !== value))
86
+ });
87
+ }
88
+ export {
89
+ createTagStore
90
+ };
@@ -1,5 +1,5 @@
1
- import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
- import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
1
+ import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.ts";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.ts";
3
3
  /**
4
4
  * Creates a toolbar store.
5
5
  */
@@ -1,14 +1,14 @@
1
1
  "use client";
2
2
  import {
3
3
  createCompositeStore
4
- } from "../__chunks/2H5K47H4.js";
5
- import "../__chunks/URUD7X4C.js";
4
+ } from "../__chunks/PBSSD2DM.js";
5
+ import "../__chunks/EQPTKGFA.js";
6
+ import "../__chunks/7PRQYBBV.js";
6
7
  import "../__chunks/R676XYVY.js";
7
8
  import {
8
9
  defaultValue
9
10
  } from "../__chunks/22HHDS5F.js";
10
- import "../__chunks/RRSZHCH6.js";
11
- import "../__chunks/7PRQYBBV.js";
11
+ import "../__chunks/I2NJJ3XW.js";
12
12
  import {
13
13
  __spreadProps,
14
14
  __spreadValues
@@ -1,5 +1,5 @@
1
- import type { HovercardStoreFunctions, HovercardStoreOptions, HovercardStoreState } from "../hovercard/hovercard-store.js";
2
- import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
1
+ import type { HovercardStoreFunctions, HovercardStoreOptions, HovercardStoreState } from "../hovercard/hovercard-store.ts";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.ts";
3
3
  /**
4
4
  * Creates a tooltip store.
5
5
  */
@@ -1,4 +1,4 @@
1
- import type { AriaHasPopup, AriaRole } from "./types.js";
1
+ import type { AriaHasPopup, AriaRole } from "./types.ts";
2
2
  /**
3
3
  * It's `true` if it is running in a browser environment or `false` if it is not
4
4
  * (SSR).
@@ -45,26 +45,10 @@ export declare function isButton(element: {
45
45
  tagName: string;
46
46
  type?: string;
47
47
  }): boolean;
48
- /**
49
- * Ponyfill for `Element.prototype.matches`
50
- *
51
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
52
- */
53
- export declare function matches(element: Element, selectors: string): boolean;
54
48
  /**
55
49
  * Checks if the element is visible or not.
56
50
  */
57
51
  export declare function isVisible(element: Element): boolean;
58
- /**
59
- * Ponyfill for `Element.prototype.closest`
60
- * @example
61
- * closest(document.getElementById("id"), "div");
62
- * // same as
63
- * document.getElementById("id").closest("div");
64
- */
65
- export declare function closest<K extends keyof HTMLElementTagNameMap>(element: Element, selectors: K): HTMLElementTagNameMap[K];
66
- export declare function closest<K extends keyof SVGElementTagNameMap>(element: Element, selectors: K): SVGElementTagNameMap[K];
67
- export declare function closest<T extends Element = Element>(element: Element, selectors: string): T | null;
68
52
  /**
69
53
  * Check whether the given element is a text field, where text field is defined
70
54
  * by the ability to select within the input.
@@ -76,13 +60,14 @@ export declare function closest<T extends Element = Element>(element: Element, s
76
60
  */
77
61
  export declare function isTextField(element: Element): element is HTMLInputElement | HTMLTextAreaElement;
78
62
  /**
79
- * Returns the element's role attribute, if it has one.
63
+ * Check whether the given element is a text field or a content editable
64
+ * element.
80
65
  */
81
- export declare function getPopupRole(element?: Element | null, fallback?: AriaHasPopup): AriaHasPopup;
66
+ export declare function isTextbox(element: HTMLElement): boolean;
82
67
  /**
83
- * Returns the item role attribute based on the popup's role.
68
+ * Returns the value of the text field or content editable element as a string.
84
69
  */
85
- export declare function getPopupItemRole(element?: Element | null, fallback?: AriaRole): string | undefined;
70
+ export declare function getTextboxValue(element: HTMLElement): string;
86
71
  /**
87
72
  * Returns the start and end offsets of the selection in the element.
88
73
  */
@@ -90,6 +75,14 @@ export declare function getTextboxSelection(element: HTMLElement): {
90
75
  start: number;
91
76
  end: number;
92
77
  };
78
+ /**
79
+ * Returns the element's role attribute, if it has one.
80
+ */
81
+ export declare function getPopupRole(element?: Element | null, fallback?: AriaHasPopup): AriaHasPopup;
82
+ /**
83
+ * Returns the item role attribute based on the popup's role.
84
+ */
85
+ export declare function getPopupItemRole(element?: Element | null, fallback?: AriaRole): string | undefined;
93
86
  /**
94
87
  * Calls `element.scrollIntoView()` if the element is hidden or partly hidden in
95
88
  * the viewport.
@@ -112,4 +105,4 @@ export declare function isPartiallyHidden(element: Element): boolean;
112
105
  * @see
113
106
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
114
107
  */
115
- export declare function setSelectionRange(element: HTMLInputElement, ...args: Parameters<typeof HTMLInputElement.prototype.setSelectionRange>): void;
108
+ export declare function setSelectionRange(element: HTMLInputElement | HTMLTextAreaElement, ...args: Parameters<typeof HTMLInputElement.prototype.setSelectionRange>): void;
package/esm/utils/dom.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import {
3
3
  canUseDOM,
4
- closest,
5
4
  contains,
6
5
  getActiveElement,
7
6
  getDocument,
@@ -9,20 +8,20 @@ import {
9
8
  getPopupRole,
10
9
  getScrollingElement,
11
10
  getTextboxSelection,
11
+ getTextboxValue,
12
12
  getWindow,
13
13
  isButton,
14
14
  isFrame,
15
15
  isPartiallyHidden,
16
16
  isTextField,
17
+ isTextbox,
17
18
  isVisible,
18
- matches,
19
19
  scrollIntoViewIfNeeded,
20
20
  setSelectionRange
21
- } from "../__chunks/RRSZHCH6.js";
21
+ } from "../__chunks/I2NJJ3XW.js";
22
22
  import "../__chunks/4R3V3JGP.js";
23
23
  export {
24
24
  canUseDOM,
25
- closest,
26
25
  contains,
27
26
  getActiveElement,
28
27
  getDocument,
@@ -30,13 +29,14 @@ export {
30
29
  getPopupRole,
31
30
  getScrollingElement,
32
31
  getTextboxSelection,
32
+ getTextboxValue,
33
33
  getWindow,
34
34
  isButton,
35
35
  isFrame,
36
36
  isPartiallyHidden,
37
37
  isTextField,
38
+ isTextbox,
38
39
  isVisible,
39
- matches,
40
40
  scrollIntoViewIfNeeded,
41
41
  setSelectionRange
42
42
  };
@@ -62,9 +62,15 @@ export declare function fireClickEvent(element: Element, eventInit?: PointerEven
62
62
  * });
63
63
  */
64
64
  export declare function isFocusEventOutside(event: Pick<FocusEvent, "currentTarget" | "relatedTarget">, container?: Element | null): boolean;
65
+ /**
66
+ * Returns the `inputType` property of the event, if available.
67
+ */
68
+ export declare function getInputType(event: Event | {
69
+ nativeEvent: Event;
70
+ }): string | undefined;
65
71
  /**
66
72
  * Runs a callback on the next animation frame, but before a certain event.
67
73
  */
68
- export declare function queueBeforeEvent(element: Element, type: string, callback: () => void): number;
74
+ export declare function queueBeforeEvent(element: Element, type: string, callback: () => void, timeout?: number): () => void;
69
75
  export declare function addGlobalEventListener<K extends keyof DocumentEventMap>(type: K, listener: (event: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions, scope?: Window): () => void;
70
76
  export declare function addGlobalEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions, scope?: Window): () => void;
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  isApple
4
- } from "../__chunks/VDNATJW2.js";
4
+ } from "../__chunks/CLSHHUGK.js";
5
5
  import {
6
6
  contains
7
- } from "../__chunks/RRSZHCH6.js";
7
+ } from "../__chunks/I2NJJ3XW.js";
8
8
  import {
9
9
  __spreadProps,
10
10
  __spreadValues
@@ -83,20 +83,35 @@ function isFocusEventOutside(event, container) {
83
83
  const relatedTarget = event.relatedTarget;
84
84
  return !relatedTarget || !contains(containerElement, relatedTarget);
85
85
  }
86
- function queueBeforeEvent(element, type, callback) {
87
- const raf = requestAnimationFrame(() => {
88
- element.removeEventListener(type, callImmediately, true);
86
+ function getInputType(event) {
87
+ const nativeEvent = "nativeEvent" in event ? event.nativeEvent : event;
88
+ if (!nativeEvent)
89
+ return;
90
+ if (!("inputType" in nativeEvent))
91
+ return;
92
+ if (typeof nativeEvent.inputType !== "string")
93
+ return;
94
+ return nativeEvent.inputType;
95
+ }
96
+ function queueBeforeEvent(element, type, callback, timeout) {
97
+ const createTimer = (callback2) => {
98
+ if (timeout) {
99
+ const timerId2 = setTimeout(callback2, timeout);
100
+ return () => clearTimeout(timerId2);
101
+ }
102
+ const timerId = requestAnimationFrame(callback2);
103
+ return () => cancelAnimationFrame(timerId);
104
+ };
105
+ const cancelTimer = createTimer(() => {
106
+ element.removeEventListener(type, callSync, true);
89
107
  callback();
90
108
  });
91
- const callImmediately = () => {
92
- cancelAnimationFrame(raf);
109
+ const callSync = () => {
110
+ cancelTimer();
93
111
  callback();
94
112
  };
95
- element.addEventListener(type, callImmediately, {
96
- once: true,
97
- capture: true
98
- });
99
- return raf;
113
+ element.addEventListener(type, callSync, { once: true, capture: true });
114
+ return cancelTimer;
100
115
  }
101
116
  function addGlobalEventListener(type, listener, options, scope = window) {
102
117
  const children = [];
@@ -123,6 +138,7 @@ export {
123
138
  fireEvent,
124
139
  fireFocusEvent,
125
140
  fireKeyboardEvent,
141
+ getInputType,
126
142
  isDownloading,
127
143
  isFocusEventOutside,
128
144
  isOpeningInNewTab,
@@ -6,7 +6,7 @@
6
6
  * isFocusable(document.querySelector("input[hidden]")); // false
7
7
  * isFocusable(document.querySelector("input:disabled")); // false
8
8
  */
9
- export declare function isFocusable(element: Element): element is HTMLElement;
9
+ export declare function isFocusable(element: Element): boolean;
10
10
  /**
11
11
  * Checks whether `element` is tabbable or not.
12
12
  * @example
@@ -1,12 +1,10 @@
1
1
  "use client";
2
2
  import {
3
- closest,
4
3
  contains,
5
4
  getActiveElement,
6
5
  isFrame,
7
- isVisible,
8
- matches
9
- } from "../__chunks/RRSZHCH6.js";
6
+ isVisible
7
+ } from "../__chunks/I2NJJ3XW.js";
10
8
  import {
11
9
  __spreadValues
12
10
  } from "../__chunks/4R3V3JGP.js";
@@ -18,11 +16,11 @@ function hasNegativeTabIndex(element) {
18
16
  return tabIndex < 0;
19
17
  }
20
18
  function isFocusable(element) {
21
- if (!matches(element, selector))
19
+ if (!element.matches(selector))
22
20
  return false;
23
21
  if (!isVisible(element))
24
22
  return false;
25
- if (closest(element, "[inert]"))
23
+ if (element.closest("[inert]"))
26
24
  return false;
27
25
  return true;
28
26
  }
@@ -164,7 +162,7 @@ function getPreviousTabbable(fallbackToFirst, fallbackToFocusable) {
164
162
  }
165
163
  function getClosestFocusable(element) {
166
164
  while (element && !isFocusable(element)) {
167
- element = closest(element, selector);
165
+ element = element.closest(selector);
168
166
  }
169
167
  return element || null;
170
168
  }
@@ -1,4 +1,4 @@
1
- import type { AnyFunction, AnyObject, SetStateAction } from "./types.js";
1
+ import type { AnyFunction, AnyObject, SetStateAction } from "./types.ts";
2
2
  /**
3
3
  * Empty function.
4
4
  */
@@ -5,8 +5,8 @@ import {
5
5
  isMac,
6
6
  isSafari,
7
7
  isTouchDevice
8
- } from "../__chunks/VDNATJW2.js";
9
- import "../__chunks/RRSZHCH6.js";
8
+ } from "../__chunks/CLSHHUGK.js";
9
+ import "../__chunks/I2NJJ3XW.js";
10
10
  import "../__chunks/4R3V3JGP.js";
11
11
  export {
12
12
  isApple,
@@ -1,4 +1,4 @@
1
- import type { AnyObject, SetStateAction } from "./types.js";
1
+ import type { AnyObject, SetStateAction } from "./types.ts";
2
2
  type Listener<S> = (state: S, prevState: S) => void | (() => void);
3
3
  type Sync<S, K extends keyof S> = (keys: K[] | null, listener: Listener<Pick<S, K>>) => () => void;
4
4
  type StoreSetup = (callback: () => void | (() => void)) => () => void;
@@ -43,7 +43,7 @@ export type StoreOptions<S extends State, K extends keyof S> = Partial<Pick<S, K
43
43
  * Props that can be passed to a store creator function.
44
44
  * @template S State type.
45
45
  */
46
- export type StoreProps<S extends State = State> = {
46
+ export interface StoreProps<S extends State = State> {
47
47
  /**
48
48
  * Another store object that will be kept in sync with the original store.
49
49
  *
@@ -51,7 +51,7 @@ export type StoreProps<S extends State = State> = {
51
51
  * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
52
52
  */
53
53
  store?: Store<Partial<S>>;
54
- };
54
+ }
55
55
  /**
56
56
  * Extracts the state type from a store type.
57
57
  * @template T Store type.
@@ -0,0 +1,19 @@
1
+ type Callback = void | (() => Callback | Promise<Callback>);
2
+ interface CreateUndoManagerOptions {
3
+ limit?: number;
4
+ }
5
+ export declare const UndoManager: {
6
+ canUndo: () => boolean;
7
+ canRedo: () => boolean;
8
+ undo: () => Promise<void>;
9
+ redo: () => Promise<void>;
10
+ execute: (callback: Callback, group?: string) => Promise<void>;
11
+ };
12
+ export declare function createUndoManager({ limit, }?: CreateUndoManagerOptions): {
13
+ canUndo: () => boolean;
14
+ canRedo: () => boolean;
15
+ undo: () => Promise<void>;
16
+ redo: () => Promise<void>;
17
+ execute: (callback: Callback, group?: string) => Promise<void>;
18
+ };
19
+ export {};
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import {
3
+ UndoManager,
4
+ createUndoManager
5
+ } from "../__chunks/EKIWAN6A.js";
6
+ import "../__chunks/4R3V3JGP.js";
7
+ export {
8
+ UndoManager,
9
+ createUndoManager
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariakit/core",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Ariakit core",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -36,6 +36,13 @@
36
36
  "default": "./cjs/index.cjs"
37
37
  }
38
38
  },
39
+ "./utils/undo": {
40
+ "import": "./esm/utils/undo.js",
41
+ "require": {
42
+ "types": "./cjs/utils/undo.d.cts",
43
+ "default": "./cjs/utils/undo.cjs"
44
+ }
45
+ },
39
46
  "./utils/types": {
40
47
  "import": "./esm/utils/types.js",
41
48
  "require": {
@@ -106,6 +113,13 @@
106
113
  "default": "./cjs/toolbar/toolbar-store.cjs"
107
114
  }
108
115
  },
116
+ "./tag/tag-store": {
117
+ "import": "./esm/tag/tag-store.js",
118
+ "require": {
119
+ "types": "./cjs/tag/tag-store.d.cts",
120
+ "default": "./cjs/tag/tag-store.cjs"
121
+ }
122
+ },
109
123
  "./tab/tab-store": {
110
124
  "import": "./esm/tab/tab-store.js",
111
125
  "require": {