@ariakit/core 0.4.4 → 0.4.5

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 (65) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/cjs/__chunks/{7DU6YMLQ.cjs → 2D5LEVE7.cjs} +6 -6
  3. package/cjs/__chunks/{UKR6TQI3.cjs → IMYW2UAC.cjs} +36 -20
  4. package/cjs/__chunks/{Y7KNI5NS.cjs → KL74MAHB.cjs} +5 -5
  5. package/cjs/__chunks/LPDHSEHU.cjs +71 -0
  6. package/cjs/__chunks/{SU2BSHGB.cjs → MHZQJPY3.cjs} +2 -2
  7. package/cjs/__chunks/{FFZYCAXA.cjs → QD2A4YF6.cjs} +2 -2
  8. package/cjs/collection/collection-store.cjs +3 -3
  9. package/cjs/combobox/combobox-store.cjs +40 -21
  10. package/cjs/combobox/combobox-store.d.cts +16 -5
  11. package/cjs/combobox/combobox-store.d.ts +16 -5
  12. package/cjs/composite/composite-store.cjs +5 -5
  13. package/cjs/form/form-store.cjs +3 -3
  14. package/cjs/menu/menu-bar-store.cjs +6 -6
  15. package/cjs/menu/menu-store.cjs +7 -7
  16. package/cjs/menubar/menubar-store.cjs +6 -6
  17. package/cjs/radio/radio-store.cjs +5 -5
  18. package/cjs/select/select-store.cjs +9 -9
  19. package/cjs/tab/tab-store.cjs +6 -6
  20. package/cjs/tag/tag-store.cjs +90 -0
  21. package/cjs/tag/tag-store.d.cts +80 -0
  22. package/cjs/tag/tag-store.d.ts +80 -0
  23. package/cjs/toolbar/toolbar-store.cjs +5 -5
  24. package/cjs/utils/dom.cjs +6 -2
  25. package/cjs/utils/dom.d.cts +14 -5
  26. package/cjs/utils/dom.d.ts +14 -5
  27. package/cjs/utils/events.cjs +17 -6
  28. package/cjs/utils/events.d.cts +6 -0
  29. package/cjs/utils/events.d.ts +6 -0
  30. package/cjs/utils/focus.cjs +13 -13
  31. package/cjs/utils/platform.cjs +3 -3
  32. package/cjs/utils/undo.cjs +10 -0
  33. package/cjs/utils/undo.d.cts +19 -0
  34. package/cjs/utils/undo.d.ts +19 -0
  35. package/esm/__chunks/{URUD7X4C.js → ABMC67JW.js} +1 -1
  36. package/esm/__chunks/EKIWAN6A.js +71 -0
  37. package/esm/__chunks/{RRSZHCH6.js → IUORCTET.js} +36 -20
  38. package/esm/__chunks/{PXYVPXSS.js → K7A7LTR3.js} +1 -1
  39. package/esm/__chunks/{VDNATJW2.js → QAI5BPCY.js} +1 -1
  40. package/esm/__chunks/{2H5K47H4.js → YVUNPQHS.js} +5 -5
  41. package/esm/collection/collection-store.js +2 -2
  42. package/esm/combobox/combobox-store.d.ts +16 -5
  43. package/esm/combobox/combobox-store.js +40 -21
  44. package/esm/composite/composite-store.js +4 -4
  45. package/esm/form/form-store.js +2 -2
  46. package/esm/menu/menu-bar-store.js +5 -5
  47. package/esm/menu/menu-store.js +6 -6
  48. package/esm/menubar/menubar-store.js +5 -5
  49. package/esm/radio/radio-store.js +4 -4
  50. package/esm/select/select-store.js +8 -8
  51. package/esm/tab/tab-store.js +4 -4
  52. package/esm/tag/tag-store.d.ts +80 -0
  53. package/esm/tag/tag-store.js +90 -0
  54. package/esm/toolbar/toolbar-store.js +4 -4
  55. package/esm/utils/dom.d.ts +14 -5
  56. package/esm/utils/dom.js +5 -1
  57. package/esm/utils/events.d.ts +6 -0
  58. package/esm/utils/events.js +13 -2
  59. package/esm/utils/focus.js +1 -1
  60. package/esm/utils/platform.js +2 -2
  61. package/esm/utils/undo.d.ts +19 -0
  62. package/esm/utils/undo.js +10 -0
  63. package/package.json +15 -1
  64. package/tag/tag-store/package.json +8 -0
  65. package/utils/undo/package.json +8 -0
@@ -1,16 +1,16 @@
1
1
  "use client";
2
2
  import {
3
3
  createCompositeStore
4
- } from "../__chunks/2H5K47H4.js";
5
- import "../__chunks/URUD7X4C.js";
4
+ } from "../__chunks/YVUNPQHS.js";
5
+ import "../__chunks/ABMC67JW.js";
6
+ import "../__chunks/7PRQYBBV.js";
6
7
  import {
7
8
  createStore
8
9
  } from "../__chunks/R676XYVY.js";
9
10
  import {
10
11
  defaultValue
11
12
  } from "../__chunks/22HHDS5F.js";
12
- import "../__chunks/RRSZHCH6.js";
13
- import "../__chunks/7PRQYBBV.js";
13
+ import "../__chunks/IUORCTET.js";
14
14
  import {
15
15
  __objRest,
16
16
  __spreadProps,
@@ -1,13 +1,16 @@
1
1
  "use client";
2
+ import {
3
+ createCompositeStore
4
+ } from "../__chunks/YVUNPQHS.js";
5
+ import "../__chunks/ABMC67JW.js";
6
+ import {
7
+ toArray
8
+ } from "../__chunks/7PRQYBBV.js";
2
9
  import {
3
10
  createPopoverStore
4
11
  } from "../__chunks/MFZZDIHG.js";
5
12
  import "../__chunks/5RJNXXU2.js";
6
13
  import "../__chunks/WCKXDMU7.js";
7
- import {
8
- createCompositeStore
9
- } from "../__chunks/2H5K47H4.js";
10
- import "../__chunks/URUD7X4C.js";
11
14
  import {
12
15
  batch,
13
16
  createStore,
@@ -20,10 +23,7 @@ import {
20
23
  import {
21
24
  defaultValue
22
25
  } from "../__chunks/22HHDS5F.js";
23
- import "../__chunks/RRSZHCH6.js";
24
- import {
25
- toArray
26
- } from "../__chunks/7PRQYBBV.js";
26
+ import "../__chunks/IUORCTET.js";
27
27
  import {
28
28
  __objRest,
29
29
  __spreadProps,
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  createCompositeStore
4
- } from "../__chunks/2H5K47H4.js";
4
+ } from "../__chunks/YVUNPQHS.js";
5
5
  import {
6
6
  createCollectionStore
7
- } from "../__chunks/URUD7X4C.js";
7
+ } from "../__chunks/ABMC67JW.js";
8
+ import "../__chunks/7PRQYBBV.js";
8
9
  import {
9
10
  batch,
10
11
  createStore,
@@ -16,8 +17,7 @@ import {
16
17
  import {
17
18
  defaultValue
18
19
  } from "../__chunks/22HHDS5F.js";
19
- import "../__chunks/RRSZHCH6.js";
20
- import "../__chunks/7PRQYBBV.js";
20
+ import "../__chunks/IUORCTET.js";
21
21
  import {
22
22
  __objRest,
23
23
  __spreadProps,
@@ -0,0 +1,80 @@
1
+ import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
+ import type { SetState } from "../utils/types.js";
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/YVUNPQHS.js";
5
+ import "../__chunks/ABMC67JW.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/IUORCTET.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,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/YVUNPQHS.js";
5
+ import "../__chunks/ABMC67JW.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/IUORCTET.js";
12
12
  import {
13
13
  __spreadProps,
14
14
  __spreadValues
@@ -76,13 +76,14 @@ export declare function closest<T extends Element = Element>(element: Element, s
76
76
  */
77
77
  export declare function isTextField(element: Element): element is HTMLInputElement | HTMLTextAreaElement;
78
78
  /**
79
- * Returns the element's role attribute, if it has one.
79
+ * Check whether the given element is a text field or a content editable
80
+ * element.
80
81
  */
81
- export declare function getPopupRole(element?: Element | null, fallback?: AriaHasPopup): AriaHasPopup;
82
+ export declare function isTextbox(element: HTMLElement): boolean;
82
83
  /**
83
- * Returns the item role attribute based on the popup's role.
84
+ * Returns the value of the text field or content editable element as a string.
84
85
  */
85
- export declare function getPopupItemRole(element?: Element | null, fallback?: AriaRole): string | undefined;
86
+ export declare function getTextboxValue(element: HTMLElement): string;
86
87
  /**
87
88
  * Returns the start and end offsets of the selection in the element.
88
89
  */
@@ -90,6 +91,14 @@ export declare function getTextboxSelection(element: HTMLElement): {
90
91
  start: number;
91
92
  end: number;
92
93
  };
94
+ /**
95
+ * Returns the element's role attribute, if it has one.
96
+ */
97
+ export declare function getPopupRole(element?: Element | null, fallback?: AriaHasPopup): AriaHasPopup;
98
+ /**
99
+ * Returns the item role attribute based on the popup's role.
100
+ */
101
+ export declare function getPopupItemRole(element?: Element | null, fallback?: AriaRole): string | undefined;
93
102
  /**
94
103
  * Calls `element.scrollIntoView()` if the element is hidden or partly hidden in
95
104
  * the viewport.
@@ -112,4 +121,4 @@ export declare function isPartiallyHidden(element: Element): boolean;
112
121
  * @see
113
122
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
114
123
  */
115
- export declare function setSelectionRange(element: HTMLInputElement, ...args: Parameters<typeof HTMLInputElement.prototype.setSelectionRange>): void;
124
+ export declare function setSelectionRange(element: HTMLInputElement | HTMLTextAreaElement, ...args: Parameters<typeof HTMLInputElement.prototype.setSelectionRange>): void;
package/esm/utils/dom.js CHANGED
@@ -9,16 +9,18 @@ import {
9
9
  getPopupRole,
10
10
  getScrollingElement,
11
11
  getTextboxSelection,
12
+ getTextboxValue,
12
13
  getWindow,
13
14
  isButton,
14
15
  isFrame,
15
16
  isPartiallyHidden,
16
17
  isTextField,
18
+ isTextbox,
17
19
  isVisible,
18
20
  matches,
19
21
  scrollIntoViewIfNeeded,
20
22
  setSelectionRange
21
- } from "../__chunks/RRSZHCH6.js";
23
+ } from "../__chunks/IUORCTET.js";
22
24
  import "../__chunks/4R3V3JGP.js";
23
25
  export {
24
26
  canUseDOM,
@@ -30,11 +32,13 @@ export {
30
32
  getPopupRole,
31
33
  getScrollingElement,
32
34
  getTextboxSelection,
35
+ getTextboxValue,
33
36
  getWindow,
34
37
  isButton,
35
38
  isFrame,
36
39
  isPartiallyHidden,
37
40
  isTextField,
41
+ isTextbox,
38
42
  isVisible,
39
43
  matches,
40
44
  scrollIntoViewIfNeeded,
@@ -62,6 +62,12 @@ 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
  */
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  isApple
4
- } from "../__chunks/VDNATJW2.js";
4
+ } from "../__chunks/QAI5BPCY.js";
5
5
  import {
6
6
  contains
7
- } from "../__chunks/RRSZHCH6.js";
7
+ } from "../__chunks/IUORCTET.js";
8
8
  import {
9
9
  __spreadProps,
10
10
  __spreadValues
@@ -83,6 +83,16 @@ function isFocusEventOutside(event, container) {
83
83
  const relatedTarget = event.relatedTarget;
84
84
  return !relatedTarget || !contains(containerElement, relatedTarget);
85
85
  }
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
+ }
86
96
  function queueBeforeEvent(element, type, callback) {
87
97
  const raf = requestAnimationFrame(() => {
88
98
  element.removeEventListener(type, callImmediately, true);
@@ -123,6 +133,7 @@ export {
123
133
  fireEvent,
124
134
  fireFocusEvent,
125
135
  fireKeyboardEvent,
136
+ getInputType,
126
137
  isDownloading,
127
138
  isFocusEventOutside,
128
139
  isOpeningInNewTab,
@@ -6,7 +6,7 @@ import {
6
6
  isFrame,
7
7
  isVisible,
8
8
  matches
9
- } from "../__chunks/RRSZHCH6.js";
9
+ } from "../__chunks/IUORCTET.js";
10
10
  import {
11
11
  __spreadValues
12
12
  } from "../__chunks/4R3V3JGP.js";
@@ -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/QAI5BPCY.js";
9
+ import "../__chunks/IUORCTET.js";
10
10
  import "../__chunks/4R3V3JGP.js";
11
11
  export {
12
12
  isApple,
@@ -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.5",
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": {
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@ariakit/core/tag/tag-store",
3
+ "private": true,
4
+ "sideEffects": false,
5
+ "main": "../../cjs/tag/tag-store.cjs",
6
+ "module": "../../esm/tag/tag-store.js",
7
+ "types": "../../cjs/tag/tag-store.d.ts"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@ariakit/core/utils/undo",
3
+ "private": true,
4
+ "sideEffects": false,
5
+ "main": "../../cjs/utils/undo.cjs",
6
+ "module": "../../esm/utils/undo.js",
7
+ "types": "../../cjs/utils/undo.d.ts"
8
+ }