@ariakit/core 0.0.1 → 0.1.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 (163) hide show
  1. package/.eslintignore +6 -0
  2. package/CHANGELOG.md +18 -0
  3. package/checkbox/checkbox-store/package.json +7 -0
  4. package/cjs/__chunks/2YFRPUZP.cjs +30 -0
  5. package/cjs/__chunks/3BBA3Z5G.cjs +143 -0
  6. package/cjs/__chunks/3KP2MDG6.cjs +1491 -0
  7. package/cjs/__chunks/5D5Y5EI4.cjs +146 -0
  8. package/cjs/__chunks/7ZXWQTAY.cjs +71 -0
  9. package/cjs/__chunks/AZVDLKO3.cjs +286 -0
  10. package/cjs/__chunks/EFEGT32M.cjs +12 -0
  11. package/cjs/__chunks/EIDN2CWH.cjs +57 -0
  12. package/cjs/__chunks/GDZQUFNP.cjs +30 -0
  13. package/cjs/__chunks/NX5OHIMM.cjs +169 -0
  14. package/cjs/__chunks/OFNGELMA.cjs +182 -0
  15. package/cjs/checkbox/checkbox-store.cjs +27 -0
  16. package/cjs/checkbox/checkbox-store.d.ts +34 -0
  17. package/cjs/collection/collection-store.cjs +9 -0
  18. package/cjs/collection/collection-store.d.ts +65 -0
  19. package/cjs/combobox/combobox-store.cjs +163 -0
  20. package/cjs/combobox/combobox-store.d.ts +67 -0
  21. package/cjs/composite/composite-overflow-store.cjs +15 -0
  22. package/cjs/composite/composite-overflow-store.d.ts +10 -0
  23. package/cjs/composite/composite-store.cjs +11 -0
  24. package/cjs/composite/composite-store.d.ts +202 -0
  25. package/cjs/dialog/dialog-store.cjs +9 -0
  26. package/cjs/dialog/dialog-store.d.ts +10 -0
  27. package/cjs/disclosure/disclosure-store.cjs +8 -0
  28. package/cjs/disclosure/disclosure-store.d.ts +87 -0
  29. package/cjs/form/form-store.cjs +241 -0
  30. package/cjs/form/form-store.d.ts +236 -0
  31. package/cjs/form/types.cjs +1 -0
  32. package/cjs/form/types.d.ts +38 -0
  33. package/cjs/hovercard/hovercard-store.cjs +11 -0
  34. package/cjs/hovercard/hovercard-store.d.ts +45 -0
  35. package/cjs/index.cjs +5 -0
  36. package/cjs/index.d.ts +2 -0
  37. package/cjs/menu/menu-bar-store.cjs +27 -0
  38. package/cjs/menu/menu-bar-store.d.ts +10 -0
  39. package/cjs/menu/menu-store.cjs +108 -0
  40. package/cjs/menu/menu-store.d.ts +70 -0
  41. package/cjs/popover/popover-store.cjs +10 -0
  42. package/cjs/popover/popover-store.d.ts +150 -0
  43. package/cjs/radio/radio-store.cjs +36 -0
  44. package/cjs/radio/radio-store.d.ts +31 -0
  45. package/cjs/select/select-store.cjs +164 -0
  46. package/cjs/select/select-store.d.ts +87 -0
  47. package/cjs/tab/tab-store.cjs +126 -0
  48. package/cjs/tab/tab-store.d.ts +78 -0
  49. package/cjs/toolbar/toolbar-store.cjs +27 -0
  50. package/cjs/toolbar/toolbar-store.d.ts +21 -0
  51. package/cjs/tooltip/tooltip-store.cjs +98 -0
  52. package/cjs/tooltip/tooltip-store.d.ts +28 -0
  53. package/cjs/tsconfig.build.tsbuildinfo +1 -0
  54. package/cjs/utils/array.cjs +12 -0
  55. package/cjs/utils/array.d.ts +29 -0
  56. package/cjs/utils/dom.cjs +38 -0
  57. package/cjs/utils/dom.d.ts +105 -0
  58. package/cjs/utils/events.cjs +132 -0
  59. package/cjs/utils/events.d.ts +73 -0
  60. package/cjs/utils/focus.cjs +222 -0
  61. package/cjs/utils/focus.d.ts +117 -0
  62. package/cjs/utils/misc.cjs +40 -0
  63. package/cjs/utils/misc.d.ts +111 -0
  64. package/cjs/utils/platform.cjs +15 -0
  65. package/cjs/utils/platform.d.ts +20 -0
  66. package/cjs/utils/store.cjs +9 -0
  67. package/cjs/utils/store.d.ts +99 -0
  68. package/cjs/utils/types.cjs +1 -0
  69. package/cjs/utils/types.d.ts +72 -0
  70. package/collection/collection-store/package.json +7 -0
  71. package/combobox/combobox-store/package.json +7 -0
  72. package/composite/composite-overflow-store/package.json +7 -0
  73. package/composite/composite-store/package.json +7 -0
  74. package/dialog/dialog-store/package.json +7 -0
  75. package/disclosure/disclosure-store/package.json +7 -0
  76. package/esm/__chunks/5XEKIOCW.js +30 -0
  77. package/esm/__chunks/6U25WEDX.js +286 -0
  78. package/esm/__chunks/6UPCMUXT.js +1491 -0
  79. package/esm/__chunks/ADRUFBEO.js +12 -0
  80. package/esm/__chunks/DXA3K2FY.js +30 -0
  81. package/esm/__chunks/HCKYJLMC.js +71 -0
  82. package/esm/__chunks/KLKI3AIB.js +146 -0
  83. package/esm/__chunks/L7KN5AYP.js +169 -0
  84. package/esm/__chunks/RX3ZUQ6U.js +57 -0
  85. package/esm/__chunks/UOJSZ35L.js +143 -0
  86. package/esm/__chunks/UVCATTRC.js +182 -0
  87. package/esm/checkbox/checkbox-store.d.ts +34 -0
  88. package/esm/checkbox/checkbox-store.js +27 -0
  89. package/esm/collection/collection-store.d.ts +65 -0
  90. package/esm/collection/collection-store.js +9 -0
  91. package/esm/combobox/combobox-store.d.ts +67 -0
  92. package/esm/combobox/combobox-store.js +163 -0
  93. package/esm/composite/composite-overflow-store.d.ts +10 -0
  94. package/esm/composite/composite-overflow-store.js +15 -0
  95. package/esm/composite/composite-store.d.ts +202 -0
  96. package/esm/composite/composite-store.js +11 -0
  97. package/esm/dialog/dialog-store.d.ts +10 -0
  98. package/esm/dialog/dialog-store.js +9 -0
  99. package/esm/disclosure/disclosure-store.d.ts +87 -0
  100. package/esm/disclosure/disclosure-store.js +8 -0
  101. package/esm/form/form-store.d.ts +236 -0
  102. package/esm/form/form-store.js +241 -0
  103. package/esm/form/types.d.ts +38 -0
  104. package/esm/form/types.js +0 -0
  105. package/esm/hovercard/hovercard-store.d.ts +45 -0
  106. package/esm/hovercard/hovercard-store.js +11 -0
  107. package/esm/index.d.ts +2 -0
  108. package/esm/index.js +5 -0
  109. package/esm/menu/menu-bar-store.d.ts +10 -0
  110. package/esm/menu/menu-bar-store.js +27 -0
  111. package/esm/menu/menu-store.d.ts +70 -0
  112. package/esm/menu/menu-store.js +108 -0
  113. package/esm/popover/popover-store.d.ts +150 -0
  114. package/esm/popover/popover-store.js +10 -0
  115. package/esm/radio/radio-store.d.ts +31 -0
  116. package/esm/radio/radio-store.js +36 -0
  117. package/esm/select/select-store.d.ts +87 -0
  118. package/esm/select/select-store.js +164 -0
  119. package/esm/tab/tab-store.d.ts +78 -0
  120. package/esm/tab/tab-store.js +126 -0
  121. package/esm/toolbar/toolbar-store.d.ts +21 -0
  122. package/esm/toolbar/toolbar-store.js +27 -0
  123. package/esm/tooltip/tooltip-store.d.ts +28 -0
  124. package/esm/tooltip/tooltip-store.js +98 -0
  125. package/esm/tsconfig.build.tsbuildinfo +1 -0
  126. package/esm/utils/array.d.ts +29 -0
  127. package/esm/utils/array.js +12 -0
  128. package/esm/utils/dom.d.ts +105 -0
  129. package/esm/utils/dom.js +38 -0
  130. package/esm/utils/events.d.ts +73 -0
  131. package/esm/utils/events.js +132 -0
  132. package/esm/utils/focus.d.ts +117 -0
  133. package/esm/utils/focus.js +222 -0
  134. package/esm/utils/misc.d.ts +111 -0
  135. package/esm/utils/misc.js +40 -0
  136. package/esm/utils/platform.d.ts +20 -0
  137. package/esm/utils/platform.js +15 -0
  138. package/esm/utils/store.d.ts +99 -0
  139. package/esm/utils/store.js +9 -0
  140. package/esm/utils/types.d.ts +72 -0
  141. package/esm/utils/types.js +0 -0
  142. package/form/form-store/package.json +7 -0
  143. package/form/types/package.json +7 -0
  144. package/hovercard/hovercard-store/package.json +7 -0
  145. package/license +21 -0
  146. package/menu/menu-bar-store/package.json +7 -0
  147. package/menu/menu-store/package.json +7 -0
  148. package/package.json +137 -6
  149. package/popover/popover-store/package.json +7 -0
  150. package/radio/radio-store/package.json +7 -0
  151. package/select/select-store/package.json +7 -0
  152. package/tab/tab-store/package.json +7 -0
  153. package/toolbar/toolbar-store/package.json +7 -0
  154. package/tooltip/tooltip-store/package.json +7 -0
  155. package/tsconfig.build.json +4 -0
  156. package/utils/array/package.json +7 -0
  157. package/utils/dom/package.json +7 -0
  158. package/utils/events/package.json +7 -0
  159. package/utils/focus/package.json +7 -0
  160. package/utils/misc/package.json +7 -0
  161. package/utils/platform/package.json +7 -0
  162. package/utils/store/package.json +7 -0
  163. package/utils/types/package.json +7 -0
@@ -0,0 +1,67 @@
1
+ import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
+ import type { MenuStore } from "../menu/menu-store.js";
3
+ import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
4
+ import type { SelectStore } from "../select/select-store.js";
5
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
6
+ import type { SetState } from "../utils/types.js";
7
+ type Item = CompositeStoreItem & {
8
+ value?: string;
9
+ };
10
+ /**
11
+ * Creates a combobox store.
12
+ */
13
+ export declare function createComboboxStore({ menu, select, ...props }?: ComboboxStoreProps): ComboboxStore;
14
+ export type ComboboxStoreItem = Item;
15
+ export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverStoreState {
16
+ /**
17
+ * @default true
18
+ */
19
+ includesBaseElement: boolean;
20
+ /**
21
+ * The input value.
22
+ */
23
+ value: string;
24
+ /**
25
+ * The value of the current active item.
26
+ */
27
+ activeValue: string | undefined;
28
+ /**
29
+ * Whether to reset the value when the combobox popover is hidden.
30
+ */
31
+ resetValueOnHide: boolean;
32
+ }
33
+ export interface ComboboxStoreFunctions extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
34
+ /**
35
+ * Sets the `value` state.
36
+ * @example
37
+ * store.setValue("Hello world");
38
+ * store.setValue((value) => value + "!");
39
+ */
40
+ setValue: SetState<ComboboxStoreState["value"]>;
41
+ }
42
+ export interface ComboboxStoreOptions extends StoreOptions<ComboboxStoreState, "includesBaseElement" | "value" | "resetValueOnHide">, CompositeStoreOptions<Item>, PopoverStoreOptions {
43
+ /**
44
+ * @default null
45
+ */
46
+ defaultActiveId?: CompositeStoreOptions<Item>["activeId"];
47
+ /**
48
+ * A reference to a menu store. This is used when combining the combobox with
49
+ * a menu (e.g., dropdown menu with a search input). The stores will share the
50
+ * same state.
51
+ */
52
+ menu?: MenuStore;
53
+ /**
54
+ * A reference to a select store. This is used when combining the combobox
55
+ * with a select (e.g., select with a search input). The stores will share the
56
+ * same state.
57
+ */
58
+ select?: SelectStore;
59
+ /**
60
+ * The combobox initial value.
61
+ * @default ""
62
+ */
63
+ defaultValue?: ComboboxStoreState["value"];
64
+ }
65
+ export type ComboboxStoreProps = ComboboxStoreOptions & StoreProps<ComboboxStoreState>;
66
+ export type ComboboxStore = ComboboxStoreFunctions & Store<ComboboxStoreState>;
67
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _3KP2MDG6cjs = require('../__chunks/3KP2MDG6.cjs');
4
+ require('../__chunks/EFEGT32M.cjs');
5
+ require('../__chunks/7ZXWQTAY.cjs');
6
+ require('../__chunks/3BBA3Z5G.cjs');
7
+ require('../__chunks/5D5Y5EI4.cjs');
8
+
9
+ // src/composite/composite-overflow-store.ts
10
+ function createCompositeOverflowStore(props = {}) {
11
+ return _3KP2MDG6cjs.createPopoverStore.call(void 0, props);
12
+ }
13
+
14
+
15
+ exports.createCompositeOverflowStore = createCompositeOverflowStore;
@@ -0,0 +1,10 @@
1
+ import type { PopoverStore, PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreProps, PopoverStoreState } from "../popover/popover-store.js";
2
+ /**
3
+ * Creates a composite overflow store.
4
+ */
5
+ export declare function createCompositeOverflowStore(props?: CompositeOverflowStoreProps): CompositeOverflowStore;
6
+ export type CompositeOverflowStoreState = PopoverStoreState;
7
+ export type CompositeOverflowStoreFunctions = PopoverStoreFunctions;
8
+ export type CompositeOverflowStoreOptions = PopoverStoreOptions;
9
+ export type CompositeOverflowStoreProps = PopoverStoreProps;
10
+ export type CompositeOverflowStore = PopoverStore;
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
4
+ require('../__chunks/NX5OHIMM.cjs');
5
+ require('../__chunks/3BBA3Z5G.cjs');
6
+ require('../__chunks/5D5Y5EI4.cjs');
7
+ require('../__chunks/OFNGELMA.cjs');
8
+ require('../__chunks/GDZQUFNP.cjs');
9
+
10
+
11
+ exports.createCompositeStore = _AZVDLKO3cjs.createCompositeStore;
@@ -0,0 +1,202 @@
1
+ import type { CollectionStoreFunctions, CollectionStoreItem, CollectionStoreOptions, CollectionStoreState } from "../collection/collection-store.js";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
+ import type { SetState } from "../utils/types.js";
4
+ type Orientation = "horizontal" | "vertical" | "both";
5
+ type Item = CollectionStoreItem & {
6
+ rowId?: string;
7
+ disabled?: boolean;
8
+ children?: string;
9
+ };
10
+ /**
11
+ * Creates a composite store.
12
+ */
13
+ export declare function createCompositeStore<T extends Item = Item>(props?: CompositeStoreProps<T>): CompositeStore<T>;
14
+ export type CompositeStoreOrientation = Orientation;
15
+ export type CompositeStoreItem = Item;
16
+ export interface CompositeStoreState<T extends Item = Item> extends CollectionStoreState<T> {
17
+ /**
18
+ * The composite element.
19
+ */
20
+ baseElement: HTMLElement | null;
21
+ /**
22
+ * If enabled, the composite element will act as an
23
+ * [aria-activedescendant](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_focus_activedescendant)
24
+ * container instead of [roving
25
+ * tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex).
26
+ * DOM focus will remain on the composite element while its items receive
27
+ * virtual focus.
28
+ * @default false
29
+ */
30
+ virtualFocus: boolean;
31
+ /**
32
+ * Defines the orientation of the composite widget. If the composite has a
33
+ * single row or column (one-dimensional), the `orientation` value determines
34
+ * which arrow keys can be used to move focus:
35
+ * - `both`: all arrow keys work.
36
+ * - `horizontal`: only left and right arrow keys work.
37
+ * - `vertical`: only up and down arrow keys work.
38
+ *
39
+ * It doesn't have any effect on two-dimensional composites.
40
+ * @default "both"
41
+ */
42
+ orientation: Orientation;
43
+ /**
44
+ * Determines how the `next` and `previous` functions will behave. If `rtl` is
45
+ * set to `true`, they will be inverted. This only affects the composite
46
+ * widget behavior. You still need to set `dir="rtl"` on HTML/CSS.
47
+ * @default false
48
+ */
49
+ rtl: boolean;
50
+ /**
51
+ * Determines how the focus behaves when the user reaches the end of the
52
+ * composite widget.
53
+ *
54
+ * On one-dimensional composites:
55
+ * - `true` loops from the last item to the first item and vice-versa.
56
+ * - `horizontal` loops only if `orientation` is `horizontal` or not set.
57
+ * - `vertical` loops only if `orientation` is `vertical` or not set.
58
+ * - If `includesBaseElement` is set to `true` (or `activeId` is initially
59
+ * set to `null`), the composite element will be focused in between the
60
+ * last and first items.
61
+ *
62
+ * On two-dimensional composites (when using `CompositeRow`):
63
+ * - `true` loops from the last row/column item to the first item in the
64
+ * same row/column and vice-versa. If it's the last item in the last row,
65
+ * it moves to the first item in the first row and vice-versa.
66
+ * - `horizontal` loops only from the last row item to the first item in the
67
+ * same row.
68
+ * - `vertical` loops only from the last column item to the first item in
69
+ * the column row.
70
+ * - If `includesBaseElement` is set to `true` (or `activeId` is initially
71
+ * set to `null`), vertical loop will have no effect as moving down from
72
+ * the last row or up from the first row will focus the composite element.
73
+ * - If `focusWrap` matches the value of `focusLoop`, it'll wrap between the
74
+ * last item in the last row or column and the first item in the first row
75
+ * or column and vice-versa.
76
+ * @default false
77
+ */
78
+ focusLoop: boolean | Orientation;
79
+ /**
80
+ * **Works only on two-dimensional composites**. If enabled, moving to the
81
+ * next item from the last one in a row or column will focus the first item in
82
+ * the next row or column and vice-versa.
83
+ * - `true` wraps between rows and columns.
84
+ * - `horizontal` wraps only between rows.
85
+ * - `vertical` wraps only between columns.
86
+ * - If `focusLoop` matches the value of `focusWrap`, it'll wrap between the
87
+ * last item in the last row or column and the first item in the first row
88
+ * or column and vice-versa.
89
+ * @default false
90
+ */
91
+ focusWrap: boolean | Orientation;
92
+ /**
93
+ * **Works only on two-dimensional composites**. If enabled, moving up or down
94
+ * when there's no next item or when the next item is disabled will shift to
95
+ * the item right before it.
96
+ * @default false
97
+ */
98
+ focusShift: boolean;
99
+ /**
100
+ * The number of times the `move` function has been called.
101
+ */
102
+ moves: number;
103
+ /**
104
+ * Indicates whether the composite element should be included in the focus
105
+ * order.
106
+ * @default false
107
+ */
108
+ includesBaseElement: boolean;
109
+ /**
110
+ * The current focused item `id`.
111
+ * - `null` focuses the base composite element and users will be able to
112
+ * navigate out of it using arrow keys.
113
+ * - If `activeId` is initially set to `null`, the `includesBaseElement`
114
+ * prop will also default to `true`, which means the base composite
115
+ * element itself will have focus and users will be able to navigate to it
116
+ * using arrow keys.
117
+ */
118
+ activeId: string | null | undefined;
119
+ }
120
+ export interface CompositeStoreFunctions<T extends Item = Item> extends CollectionStoreFunctions<T> {
121
+ /**
122
+ * Sets the `baseElement`.
123
+ */
124
+ setBaseElement: SetState<CompositeStoreState<T>["baseElement"]>;
125
+ /**
126
+ * Sets the `activeId` state without moving focus. If you want to move focus,
127
+ * use the `move` function instead.
128
+ * @example
129
+ * // Sets the composite element as the active item
130
+ * store.setActiveId(null);
131
+ * // Sets the item with id "item-1" as the active item
132
+ * store.setActiveId("item-1");
133
+ * // Sets the next item as the active item
134
+ * store.setActiveId(store.next());
135
+ */
136
+ setActiveId: SetState<CompositeStoreState<T>["activeId"]>;
137
+ /**
138
+ * Moves focus to a given item id and sets it as the active item. Passing
139
+ * `null` will focus the composite element itself.
140
+ * @param id The item id to move focus to.
141
+ * @example
142
+ * // Moves focus to the composite element
143
+ * store.move(null);
144
+ * // Moves focus to the item with id "item-1"
145
+ * store.move("item-1");
146
+ * // Moves focus to the next item
147
+ * store.move(store.next());
148
+ */
149
+ move: (id?: string | null) => void;
150
+ /**
151
+ * Returns the id of the next item based on the current `activeId` state.
152
+ * @param skip The number of items to skip. Defaults to 1.
153
+ * @example
154
+ * const nextId = store.next();
155
+ * const nextNextId = store.next(2);
156
+ */
157
+ next: (skip?: number) => string | null | undefined;
158
+ /**
159
+ * Returns the id of the previous item based on the current `activeId` state.
160
+ * @param skip The number of items to skip. Defaults to 1.
161
+ * @example
162
+ * const previousId = store.previous();
163
+ * const previousPreviousId = store.previous(2);
164
+ */
165
+ previous: (skip?: number) => string | null | undefined;
166
+ /**
167
+ * Returns the id of the item above based on the current `activeId` state.
168
+ * @param skip The number of items to skip. Defaults to 1.
169
+ * @example
170
+ * const upId = store.up();
171
+ * const upUpId = store.up(2);
172
+ */
173
+ up: (skip?: number) => string | null | undefined;
174
+ /**
175
+ * Returns the id of the item below based on the current `activeId` state.
176
+ * @param skip The number of items to skip. Defaults to 1.
177
+ * @example
178
+ * const downId = store.down();
179
+ * const downDownId = store.down(2);
180
+ */
181
+ down: (skip?: number) => string | null | undefined;
182
+ /**
183
+ * Returns the id of the first item.
184
+ */
185
+ first: () => string | null | undefined;
186
+ /**
187
+ * Returns the id of the last item.
188
+ */
189
+ last: () => string | null | undefined;
190
+ }
191
+ export interface CompositeStoreOptions<T extends Item = Item> extends StoreOptions<CompositeStoreState<T>, "virtualFocus" | "orientation" | "rtl" | "focusLoop" | "focusWrap" | "focusShift" | "includesBaseElement" | "activeId">, CollectionStoreOptions<T> {
192
+ /**
193
+ * The composite item id that should be active by default when the composite
194
+ * widget is rendered. If `null`, the composite element itself will have focus
195
+ * and users will be able to navigate to it using arrow keys. If `undefined`,
196
+ * the first enabled item will be focused.
197
+ */
198
+ defaultActiveId?: CompositeStoreState<T>["activeId"];
199
+ }
200
+ export type CompositeStoreProps<T extends Item = Item> = CompositeStoreOptions<T> & StoreProps<CompositeStoreState<T>>;
201
+ export type CompositeStore<T extends Item = Item> = CompositeStoreFunctions<T> & Store<CompositeStoreState<T>>;
202
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _EFEGT32Mcjs = require('../__chunks/EFEGT32M.cjs');
4
+ require('../__chunks/7ZXWQTAY.cjs');
5
+ require('../__chunks/3BBA3Z5G.cjs');
6
+ require('../__chunks/5D5Y5EI4.cjs');
7
+
8
+
9
+ exports.createDialogStore = _EFEGT32Mcjs.createDialogStore;
@@ -0,0 +1,10 @@
1
+ import type { DisclosureStore, DisclosureStoreFunctions, DisclosureStoreOptions, DisclosureStoreProps, DisclosureStoreState } from "../disclosure/disclosure-store.js";
2
+ /**
3
+ * Creates a dialog store.
4
+ */
5
+ export declare function createDialogStore(props?: DialogStoreProps): DialogStore;
6
+ export type DialogStoreState = DisclosureStoreState;
7
+ export type DialogStoreFunctions = DisclosureStoreFunctions;
8
+ export type DialogStoreOptions = DisclosureStoreOptions;
9
+ export type DialogStoreProps = DisclosureStoreProps;
10
+ export type DialogStore = DisclosureStore;
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _7ZXWQTAYcjs = require('../__chunks/7ZXWQTAY.cjs');
4
+ require('../__chunks/3BBA3Z5G.cjs');
5
+ require('../__chunks/5D5Y5EI4.cjs');
6
+
7
+
8
+ exports.createDisclosureStore = _7ZXWQTAYcjs.createDisclosureStore;
@@ -0,0 +1,87 @@
1
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
+ import type { SetState } from "../utils/types.js";
3
+ /**
4
+ * Creates a disclosure store.
5
+ */
6
+ export declare function createDisclosureStore(props?: DisclosureStoreProps): DisclosureStore;
7
+ export interface DisclosureStoreState {
8
+ /**
9
+ * The visibility state of the content.
10
+ * @default false
11
+ */
12
+ open: boolean;
13
+ /**
14
+ * The mounted state of the content. If `animated` is `false` or not defined,
15
+ * this will be the same as `open`. Otherwise, it will wait for the animation
16
+ * to complete before becoming `false` so the content is not unmounted while
17
+ * animating.
18
+ */
19
+ mounted: boolean;
20
+ /**
21
+ * Determines whether the content should animate when it is shown or hidden.
22
+ * - If `true`, the `animating` state will be `true` when the content is
23
+ * shown or hidden and it will wait for `stopAnimation` to be called or a
24
+ * CSS animation/transition to end before becoming `false`.
25
+ * - If it's set to a number, the `animating` state will be `true` when the
26
+ * content is shown or hidden and it will wait for the number of
27
+ * milliseconds to pass before becoming `false`.
28
+ * @default false
29
+ */
30
+ animated: boolean | number;
31
+ /**
32
+ * Whether the content is currently animating.
33
+ */
34
+ animating: boolean;
35
+ /**
36
+ * The content element that is being shown or hidden.
37
+ */
38
+ contentElement: HTMLElement | null;
39
+ /**
40
+ * The disclosure button element that toggles the content.
41
+ */
42
+ disclosureElement: HTMLElement | null;
43
+ }
44
+ export interface DisclosureStoreFunctions {
45
+ /**
46
+ * Sets the `open` state.
47
+ * @example
48
+ * store.setOpen(true);
49
+ * store.setOpen((open) => !open);
50
+ */
51
+ setOpen: SetState<DisclosureStoreState["open"]>;
52
+ /**
53
+ * Sets the `open` state to `true`.
54
+ */
55
+ show: () => void;
56
+ /**
57
+ * Sets the `open` state to `false`.
58
+ */
59
+ hide: () => void;
60
+ /**
61
+ * Toggles the `open` state.
62
+ */
63
+ toggle: () => void;
64
+ /**
65
+ * Sets the `animating` state to `false`, which will automatically set the
66
+ * `mounted` state to `false` if it was `true`. This means that the content
67
+ * element can be safely unmounted.
68
+ */
69
+ stopAnimation: () => void;
70
+ /**
71
+ * Sets the `contentElement` state.
72
+ */
73
+ setContentElement: SetState<DisclosureStoreState["contentElement"]>;
74
+ /**
75
+ * Sets the `disclosureElement` state.
76
+ */
77
+ setDisclosureElement: SetState<DisclosureStoreState["disclosureElement"]>;
78
+ }
79
+ export interface DisclosureStoreOptions extends StoreOptions<DisclosureStoreState, "open" | "animated"> {
80
+ /**
81
+ * The default visibility state of the content.
82
+ * @default false
83
+ */
84
+ defaultOpen?: DisclosureStoreState["open"];
85
+ }
86
+ export type DisclosureStoreProps = DisclosureStoreOptions & StoreProps<DisclosureStoreState>;
87
+ export type DisclosureStore = DisclosureStoreFunctions & Store<DisclosureStoreState>;
@@ -0,0 +1,241 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _NX5OHIMMcjs = require('../__chunks/NX5OHIMM.cjs');
4
+
5
+
6
+ var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
7
+
8
+
9
+
10
+
11
+
12
+ var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
13
+ require('../__chunks/OFNGELMA.cjs');
14
+
15
+ // src/form/form-store.ts
16
+ function nextFrame() {
17
+ return new Promise((resolve) => requestAnimationFrame(() => resolve()));
18
+ }
19
+ function hasMessages(object) {
20
+ return Object.keys(object).some((key) => {
21
+ if (_5D5Y5EI4cjs.isObject.call(void 0, object[key])) {
22
+ return hasMessages(object[key]);
23
+ }
24
+ return !!object[key];
25
+ });
26
+ }
27
+ function get(values, path, defaultValue2) {
28
+ const [key, ...rest] = Array.isArray(path) ? path : `${path}`.split(".");
29
+ if (key == null || !values) {
30
+ return defaultValue2;
31
+ }
32
+ if (!rest.length) {
33
+ return _nullishCoalesce(values[key], () => ( defaultValue2));
34
+ }
35
+ return get(values[key], rest, defaultValue2);
36
+ }
37
+ function set(values, path, value) {
38
+ const [k, ...rest] = Array.isArray(path) ? path : `${path}`.split(".");
39
+ if (k == null)
40
+ return values;
41
+ const key = k;
42
+ const isIntegerKey = _5D5Y5EI4cjs.isInteger.call(void 0, key);
43
+ const nextValues = isIntegerKey ? values || [] : values || {};
44
+ const nestedValues = nextValues[key];
45
+ const result = rest.length && (Array.isArray(nestedValues) || _5D5Y5EI4cjs.isObject.call(void 0, nestedValues)) ? set(nestedValues, rest, value) : value;
46
+ if (isIntegerKey) {
47
+ const index = Number(key);
48
+ if (values) {
49
+ return [
50
+ ...values.slice(0, index),
51
+ result,
52
+ ...values.slice(index + 1)
53
+ ];
54
+ }
55
+ const nextValues2 = [];
56
+ nextValues2[index] = result;
57
+ return nextValues2;
58
+ }
59
+ return { ...values, [key]: result };
60
+ }
61
+ function setAll(values, value) {
62
+ const result = {};
63
+ const keys = Object.keys(values);
64
+ for (const key of keys) {
65
+ const currentValue = values[key];
66
+ if (Array.isArray(currentValue)) {
67
+ result[key] = currentValue.map((v) => {
68
+ if (_5D5Y5EI4cjs.isObject.call(void 0, v)) {
69
+ return setAll(v, value);
70
+ }
71
+ return value;
72
+ });
73
+ } else if (_5D5Y5EI4cjs.isObject.call(void 0, currentValue)) {
74
+ result[key] = setAll(currentValue, value);
75
+ } else {
76
+ result[key] = value;
77
+ }
78
+ }
79
+ return result;
80
+ }
81
+ function getNameHandler(cache, prevKeys = []) {
82
+ const handler = {
83
+ get(target, key) {
84
+ if (["toString", "valueOf", Symbol.toPrimitive].includes(key)) {
85
+ return () => prevKeys.join(".");
86
+ }
87
+ const nextKeys = [...prevKeys, key];
88
+ const nextKey = nextKeys.join(".");
89
+ if (cache[nextKey]) {
90
+ return cache[nextKey];
91
+ }
92
+ const nextProxy = new Proxy(target, getNameHandler(cache, nextKeys));
93
+ cache[nextKey] = nextProxy;
94
+ return nextProxy;
95
+ }
96
+ };
97
+ return handler;
98
+ }
99
+ function createNames() {
100
+ const cache = /* @__PURE__ */ Object.create(null);
101
+ return new Proxy(/* @__PURE__ */ Object.create(null), getNameHandler(cache));
102
+ }
103
+ function createFormStore(props = {}) {
104
+ const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
105
+ const collection = _NX5OHIMMcjs.createCollectionStore.call(void 0, props);
106
+ const values = _5D5Y5EI4cjs.defaultValue.call(void 0,
107
+ props.values,
108
+ _optionalChain([syncState, 'optionalAccess', _4 => _4.values]),
109
+ props.defaultValues,
110
+ {}
111
+ );
112
+ const errors = _5D5Y5EI4cjs.defaultValue.call(void 0,
113
+ props.errors,
114
+ _optionalChain([syncState, 'optionalAccess', _5 => _5.errors]),
115
+ props.defaultErrors,
116
+ {}
117
+ );
118
+ const touched = _5D5Y5EI4cjs.defaultValue.call(void 0,
119
+ props.touched,
120
+ _optionalChain([syncState, 'optionalAccess', _6 => _6.touched]),
121
+ props.defaultTouched,
122
+ {}
123
+ );
124
+ const initialState = {
125
+ ...collection.getState(),
126
+ values,
127
+ errors,
128
+ touched,
129
+ validating: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _7 => _7.validating]), false),
130
+ submitting: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _8 => _8.submitting]), false),
131
+ submitSucceed: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _9 => _9.submitSucceed]), 0),
132
+ submitFailed: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _10 => _10.submitFailed]), 0),
133
+ valid: !hasMessages(errors)
134
+ };
135
+ const form = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, collection, props.store);
136
+ const validateCallbacks = /* @__PURE__ */ new Set();
137
+ const submitCallbacks = /* @__PURE__ */ new Set();
138
+ const validate = async () => {
139
+ form.setState("validating", true);
140
+ form.setState("errors", {});
141
+ try {
142
+ const callbacks = [...validateCallbacks];
143
+ const results = callbacks.map((callback) => callback(form.getState()));
144
+ await Promise.all(results).then(nextFrame);
145
+ return !hasMessages(form.getState().errors);
146
+ } finally {
147
+ form.setState("validating", false);
148
+ }
149
+ };
150
+ return {
151
+ ...collection,
152
+ ...form,
153
+ names: createNames(),
154
+ setValues: (values2) => form.setState("values", values2),
155
+ getValue: (name) => get(form.getState().values, name),
156
+ setValue: (name, value) => form.setState("values", (values2) => {
157
+ const prevValue = get(values2, name);
158
+ const nextValue = _5D5Y5EI4cjs.applyState.call(void 0, value, prevValue);
159
+ if (nextValue === prevValue)
160
+ return values2;
161
+ return set(values2, name, nextValue);
162
+ }),
163
+ pushValue: (name, value) => form.setState("values", (values2) => {
164
+ const array = get(values2, name, []);
165
+ return set(values2, name, [...array, value]);
166
+ }),
167
+ removeValue: (name, index) => form.setState("values", (values2) => {
168
+ const array = get(values2, name, []);
169
+ return set(values2, name, [
170
+ ...array.slice(0, index),
171
+ null,
172
+ ...array.slice(index + 1)
173
+ ]);
174
+ }),
175
+ setErrors: (errors2) => form.setState("errors", errors2),
176
+ getError: (name) => get(form.getState().errors, name),
177
+ setError: (name, error) => form.setState("errors", (errors2) => {
178
+ const prevError = get(errors2, name);
179
+ const nextError = _5D5Y5EI4cjs.applyState.call(void 0, error, prevError);
180
+ if (nextError === prevError)
181
+ return errors2;
182
+ return set(errors2, name, nextError);
183
+ }),
184
+ setTouched: (touched2) => form.setState("touched", touched2),
185
+ getFieldTouched: (name) => !!get(form.getState().touched, name),
186
+ setFieldTouched: (name, value) => form.setState("touched", (touched2) => {
187
+ const prevValue = get(touched2, name);
188
+ const nextValue = _5D5Y5EI4cjs.applyState.call(void 0, value, prevValue);
189
+ if (nextValue === prevValue)
190
+ return touched2;
191
+ return set(touched2, name, nextValue);
192
+ }),
193
+ onValidate: (callback) => {
194
+ validateCallbacks.add(callback);
195
+ return () => validateCallbacks.delete(callback);
196
+ },
197
+ validate,
198
+ onSubmit: (callback) => {
199
+ submitCallbacks.add(callback);
200
+ return () => submitCallbacks.delete(callback);
201
+ },
202
+ submit: async () => {
203
+ form.setState("submitting", true);
204
+ form.setState("touched", setAll(form.getState().values, true));
205
+ try {
206
+ if (await validate()) {
207
+ const callbacks = [...submitCallbacks];
208
+ const results = callbacks.map(
209
+ (callback) => callback(form.getState())
210
+ );
211
+ await Promise.all(results).then(nextFrame);
212
+ if (!hasMessages(form.getState().errors)) {
213
+ form.setState("submitSucceed", (count) => count + 1);
214
+ return true;
215
+ }
216
+ }
217
+ form.setState("submitFailed", (count) => count + 1);
218
+ return false;
219
+ } catch (error) {
220
+ form.setState("submitFailed", (count) => count + 1);
221
+ throw error;
222
+ } finally {
223
+ form.setState("submitting", false);
224
+ }
225
+ },
226
+ reset: () => {
227
+ form.setState("values", values);
228
+ form.setState("errors", errors);
229
+ form.setState("touched", touched);
230
+ form.setState("validating", false);
231
+ form.setState("submitting", false);
232
+ form.setState("submitSucceed", 0);
233
+ form.setState("submitFailed", 0);
234
+ }
235
+ };
236
+ }
237
+
238
+
239
+
240
+
241
+ exports.createFormStore = createFormStore; exports.get = get; exports.hasMessages = hasMessages;