@ariakit/core 0.0.1 → 0.1.1

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 +24 -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 +41 -0
  44. package/cjs/radio/radio-store.d.ts +36 -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 +36 -0
  116. package/esm/radio/radio-store.js +41 -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,236 @@
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 { AnyObject, PickRequired, SetState, SetStateAction } from "../utils/types.js";
4
+ import type { DeepMap, DeepPartial, Names, StringLike } from "./types.js";
5
+ type Values = AnyObject;
6
+ type ErrorMessage = string | undefined | null;
7
+ type Item = CollectionStoreItem & {
8
+ type: "field" | "label" | "description" | "error" | "button";
9
+ name: string;
10
+ };
11
+ export declare function hasMessages(object: Values): boolean;
12
+ export declare function get<T>(values: Values, path: StringLike | string[], defaultValue?: T): T;
13
+ /**
14
+ * Creates a form store.
15
+ */
16
+ export declare function createFormStore<T extends Values = Values>(props: PickRequired<FormStoreProps<T>, "values" | "defaultValues" | "errors" | "defaultErrors" | "touched" | "defaultTouched">): FormStore<T>;
17
+ export declare function createFormStore(props: FormStoreProps): FormStore;
18
+ export type FormStoreCallback<T extends FormStoreState = FormStoreState> = (state: T) => void | Promise<void>;
19
+ export type FormStoreValues = Values;
20
+ export type FormStoreItem = Item;
21
+ export interface FormStoreState<T extends Values = Values> extends CollectionStoreState<Item> {
22
+ /**
23
+ * Form values.
24
+ * @default {}
25
+ */
26
+ values: T;
27
+ /**
28
+ * Form errors.
29
+ */
30
+ errors: DeepPartial<DeepMap<T, ErrorMessage>>;
31
+ /**
32
+ * The touched state of the form.
33
+ */
34
+ touched: DeepPartial<DeepMap<T, boolean>>;
35
+ /**
36
+ * Whether the form is valid.
37
+ */
38
+ valid: boolean;
39
+ /**
40
+ * Whether the form is validating.
41
+ */
42
+ validating: boolean;
43
+ /**
44
+ * Whether the form is submitting.
45
+ */
46
+ submitting: boolean;
47
+ /**
48
+ * The number of times `form.submit` has been called with a successful
49
+ * response.
50
+ */
51
+ submitSucceed: number;
52
+ /**
53
+ * The number of times `form.submit` has been called with an error response.
54
+ */
55
+ submitFailed: number;
56
+ }
57
+ export interface FormStoreFunctions<T extends Values = Values> extends CollectionStoreFunctions<Item> {
58
+ /**
59
+ * An object containing the names of the form fields for type-safety.
60
+ * @example
61
+ * store.names.name; // "name"
62
+ * store.names.name.first; // "name.first"
63
+ * store.names.name.last; // "name.last"
64
+ */
65
+ names: Names<T>;
66
+ /**
67
+ * Sets the `values` state.
68
+ * @example
69
+ * store.setValues({ name: "John" });
70
+ * store.setValues((values) => ({ ...values, name: "John" }));
71
+ */
72
+ setValues: SetState<FormStoreState<T>["values"]>;
73
+ /**
74
+ * Retrieves a field value.
75
+ * @param name The field name.
76
+ * @example
77
+ * const nameValue = store.getValue("name");
78
+ * // Can also use store.names for type-safety.
79
+ * const emailValue = store.getValue(store.names.email);
80
+ */
81
+ getValue: <T = any>(name: StringLike) => T;
82
+ /**
83
+ * Sets a field value.
84
+ * @param name The field name.
85
+ * @param value The field value.
86
+ * @example
87
+ * store.setValue("name", "John");
88
+ * store.setValue("name", (value) => value + " Doe");
89
+ * // Can also use store.names for type-safety.
90
+ * store.setValue(store.names.name, "John");
91
+ */
92
+ setValue: <T>(name: StringLike, value: SetStateAction<T>) => void;
93
+ /**
94
+ * Pushes a value to an array field.
95
+ * @param name The array field name.
96
+ * @param value The value to push.
97
+ * @example
98
+ * store.pushValue("tags", "new tag");
99
+ * store.pushValue("tags", { id: 1, name: "new tag" });
100
+ * // Can also use store.names for type-safety.
101
+ * store.pushValue(store.names.tags, "new tag");
102
+ */
103
+ pushValue: <T>(name: StringLike, value: T) => void;
104
+ /**
105
+ * Removes a value from an array field.
106
+ * @param name The array field name.
107
+ * @param index The index of the value to remove.
108
+ * @example
109
+ * store.removeValue("tags", 0);
110
+ * store.removeValue("tags", 1);
111
+ * // Can also use store.names for type-safety.
112
+ * store.removeValue(store.names.tags, 0);
113
+ */
114
+ removeValue: (name: StringLike, index: number) => void;
115
+ /**
116
+ * Sets the `errors` state.
117
+ * @example
118
+ * store.setErrors({ name: "Name is required" });
119
+ * store.setErrors((errors) => ({ ...errors, name: "Name is required" }));
120
+ */
121
+ setErrors: SetState<FormStoreState<T>["errors"]>;
122
+ /**
123
+ * Retrieves a field error.
124
+ * @param name The field name.
125
+ * @example
126
+ * const nameError = store.getError("name");
127
+ * // Can also use store.names for type-safety.
128
+ * const emailError = store.getError(store.names.email);
129
+ */
130
+ getError: (name: StringLike) => ErrorMessage;
131
+ /**
132
+ * Sets a field error.
133
+ * @param name The field name.
134
+ * @param error The field error.
135
+ * @example
136
+ * store.setError("name", "Name is required");
137
+ * store.setError("name", (error) => error + "!");
138
+ * // Can also use store.names for type-safety.
139
+ * store.setError(store.names.name, "Name is required");
140
+ */
141
+ setError: (name: StringLike, error: SetStateAction<ErrorMessage>) => void;
142
+ /**
143
+ * Sets the `touched` state.
144
+ * @example
145
+ * store.setTouched({ name: true });
146
+ * store.setTouched((touched) => ({ ...touched, name: true }));
147
+ */
148
+ setTouched: SetState<FormStoreState<T>["touched"]>;
149
+ /**
150
+ * Retrieves a field touched state.
151
+ * @param name The field name.
152
+ * @example
153
+ * const nameTouched = store.getFieldTouched("name");
154
+ * // Can also use store.names for type-safety.
155
+ * const emailTouched = store.getFieldTouched(store.names.email);
156
+ */
157
+ getFieldTouched: (name: StringLike) => boolean;
158
+ /**
159
+ * Sets a field touched state.
160
+ * @param name The field name.
161
+ * @param value The field touched state.
162
+ * @example
163
+ * store.setFieldTouched("name", true);
164
+ * store.setFieldTouched("name", (value) => !value);
165
+ * // Can also use store.names for type-safety.
166
+ * store.setFieldTouched(store.names.name, true);
167
+ */
168
+ setFieldTouched: (name: StringLike, value: SetStateAction<boolean>) => void;
169
+ /**
170
+ * Function that accepts a callback that will be used to validate the form
171
+ * when `validate` is called. It returns a cleanup function that will remove
172
+ * the callback.
173
+ * @param callback The callback function.
174
+ * @example
175
+ * const cleanup = store.onValidate(async (state) => {
176
+ * const errors = await api.validate(state.values);
177
+ * if (errors) {
178
+ * store.setErrors(errors);
179
+ * }
180
+ * });
181
+ */
182
+ onValidate: (callback: FormStoreCallback<FormStoreState<T>>) => void;
183
+ /**
184
+ * Function that accepts a callback that will be used to submit the form
185
+ * when `submit` is called. It returns a cleanup function that will remove
186
+ * the callback.
187
+ * @param callback The callback function.
188
+ * @example
189
+ * const cleanup = store.onSubmit(async (state) => {
190
+ * try {
191
+ * await api.submit(state.values);
192
+ * } catch (errors) {
193
+ * store.setErrors(errors);
194
+ * }
195
+ * });
196
+ */
197
+ onSubmit: (callback: FormStoreCallback<FormStoreState<T>>) => void;
198
+ /**
199
+ * Validates the form.
200
+ * @example
201
+ * if (await store.validate()) {
202
+ * // Form is valid.
203
+ * }
204
+ */
205
+ validate: () => Promise<boolean>;
206
+ /**
207
+ * Submits the form. This also triggers validation.
208
+ * @example
209
+ * if (await form.submit()) {
210
+ * // Form is submitted.
211
+ * }
212
+ */
213
+ submit: () => Promise<boolean>;
214
+ /**
215
+ * Resets the form to its default values.
216
+ */
217
+ reset: () => void;
218
+ }
219
+ export interface FormStoreOptions<T extends Values = Values> extends StoreOptions<FormStoreState<T>, "values" | "errors" | "touched">, CollectionStoreOptions<Item> {
220
+ /**
221
+ * The default values of the form.
222
+ * @default {}
223
+ */
224
+ defaultValues?: FormStoreState<T>["values"];
225
+ /**
226
+ * The default errors of the form.
227
+ */
228
+ defaultErrors?: FormStoreState<T>["errors"];
229
+ /**
230
+ * The default touched state of the form.
231
+ */
232
+ defaultTouched?: FormStoreState<T>["touched"];
233
+ }
234
+ export type FormStoreProps<T extends Values = Values> = FormStoreOptions<T> & StoreProps<FormStoreState<T>>;
235
+ export type FormStore<T extends Values = Values> = FormStoreFunctions<T> & Store<FormStoreState<T>>;
236
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,38 @@
1
+ import type { AnyObject } from "../utils/types.js";
2
+ /**
3
+ * An object or primitive value that can be converted to a string.
4
+ */
5
+ export type StringLike = {
6
+ toString: () => string;
7
+ valueOf: () => string;
8
+ };
9
+ /**
10
+ * Maps through an object `T` or array and defines the leaf values to the given
11
+ * type `V`.
12
+ * @template T Object
13
+ * @template V Value
14
+ */
15
+ export type DeepMap<T, V> = {
16
+ [K in keyof T]: T[K] extends AnyObject ? DeepMap<T[K], V> : V;
17
+ };
18
+ /**
19
+ * Similar to `Partial<T>`, but recursively maps through the object and makes
20
+ * nested object properties optional.
21
+ * @template T Object
22
+ */
23
+ export type DeepPartial<T> = {
24
+ [K in keyof T]?: T[K] extends AnyObject ? DeepPartial<T[K]> : T[K];
25
+ };
26
+ /**
27
+ * Maps through the values object `T` and defines all properties into a string
28
+ * like type. That is, a type that is an object that can contain other
29
+ * properties but can also be converted into a string with the path name.
30
+ * @template T Values object
31
+ */
32
+ export type Names<T> = {
33
+ [K in keyof T]: T[K] extends Array<infer U> ? U extends AnyObject ? {
34
+ [key: number]: Names<U>;
35
+ } & StringLike : {
36
+ [key: number]: U & StringLike;
37
+ } & StringLike : T[K] extends AnyObject ? Names<T[K]> : StringLike;
38
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _EIDN2CWHcjs = require('../__chunks/EIDN2CWH.cjs');
4
+ require('../__chunks/3KP2MDG6.cjs');
5
+ require('../__chunks/EFEGT32M.cjs');
6
+ require('../__chunks/7ZXWQTAY.cjs');
7
+ require('../__chunks/3BBA3Z5G.cjs');
8
+ require('../__chunks/5D5Y5EI4.cjs');
9
+
10
+
11
+ exports.createHovercardStore = _EIDN2CWHcjs.createHovercardStore;
@@ -0,0 +1,45 @@
1
+ import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
+ import type { SetState } from "../utils/types.js";
4
+ /**
5
+ * Creates a hovercard store.
6
+ */
7
+ export declare function createHovercardStore(props?: HovercardStoreProps): HovercardStore;
8
+ export interface HovercardStoreState extends PopoverStoreState {
9
+ /**
10
+ * @default "bottom"
11
+ */
12
+ placement: PopoverStoreState["placement"];
13
+ /**
14
+ * The amount of time in milliseconds to wait before showing or hiding the
15
+ * popover.
16
+ * @default 500
17
+ */
18
+ timeout: number;
19
+ /**
20
+ * The amount of time in milliseconds to wait before **showing** the popover.
21
+ * It defaults to the value passed to `timeout`.
22
+ */
23
+ showTimeout: number;
24
+ /**
25
+ * The amount of time in milliseconds to wait before **hiding** the popover.
26
+ * It defaults to the value passed to `timeout`.
27
+ */
28
+ hideTimeout: number;
29
+ /**
30
+ * Whether the popover or an element inside it should be focused when it is
31
+ * shown.
32
+ * @default false
33
+ */
34
+ autoFocusOnShow: boolean;
35
+ }
36
+ export interface HovercardStoreFunctions extends PopoverStoreFunctions {
37
+ /**
38
+ * Sets the `autoFocusOnShow` state.
39
+ */
40
+ setAutoFocusOnShow: SetState<HovercardStoreState["autoFocusOnShow"]>;
41
+ }
42
+ export interface HovercardStoreOptions extends StoreOptions<HovercardStoreState, "placement" | "timeout" | "showTimeout" | "hideTimeout">, PopoverStoreOptions {
43
+ }
44
+ export type HovercardStoreProps = HovercardStoreOptions & StoreProps<HovercardStoreState>;
45
+ export type HovercardStore = HovercardStoreFunctions & Store<HovercardStoreState>;
package/cjs/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
2
+ var src_default = {};
3
+
4
+
5
+ exports.default = src_default;
package/cjs/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
4
+ require('../__chunks/NX5OHIMM.cjs');
5
+ require('../__chunks/3BBA3Z5G.cjs');
6
+
7
+
8
+ var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
9
+ require('../__chunks/OFNGELMA.cjs');
10
+ require('../__chunks/GDZQUFNP.cjs');
11
+
12
+ // src/menu/menu-bar-store.ts
13
+ function createMenuBarStore(props = {}) {
14
+ const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
15
+ return _AZVDLKO3cjs.createCompositeStore.call(void 0, {
16
+ ...props,
17
+ orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
18
+ props.orientation,
19
+ _optionalChain([syncState, 'optionalAccess', _4 => _4.orientation]),
20
+ "horizontal"
21
+ ),
22
+ focusLoop: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusLoop, _optionalChain([syncState, 'optionalAccess', _5 => _5.focusLoop]), true)
23
+ });
24
+ }
25
+
26
+
27
+ exports.createMenuBarStore = createMenuBarStore;
@@ -0,0 +1,10 @@
1
+ import type { CompositeStore, CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreProps, CompositeStoreState } from "../composite/composite-store.js";
2
+ /**
3
+ * Creates a menu bar store.
4
+ */
5
+ export declare function createMenuBarStore(props?: MenuBarStoreProps): MenuBarStore;
6
+ export type MenuBarStoreState = CompositeStoreState;
7
+ export type MenuBarStoreFunctions = CompositeStoreFunctions;
8
+ export type MenuBarStoreOptions = CompositeStoreOptions;
9
+ export type MenuBarStoreProps = CompositeStoreProps;
10
+ export type MenuBarStore = CompositeStore;
@@ -0,0 +1,108 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _EIDN2CWHcjs = require('../__chunks/EIDN2CWH.cjs');
4
+ require('../__chunks/3KP2MDG6.cjs');
5
+ require('../__chunks/EFEGT32M.cjs');
6
+ require('../__chunks/7ZXWQTAY.cjs');
7
+
8
+
9
+ var _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
10
+ require('../__chunks/NX5OHIMM.cjs');
11
+
12
+
13
+
14
+ var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
15
+
16
+
17
+
18
+ var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
19
+ require('../__chunks/OFNGELMA.cjs');
20
+ require('../__chunks/GDZQUFNP.cjs');
21
+
22
+ // src/menu/menu-store.ts
23
+ function createMenuStore({
24
+ combobox,
25
+ ...props
26
+ } = {}) {
27
+ const store = _3BBA3Z5Gcjs.mergeStore.call(void 0,
28
+ props.store,
29
+ _optionalChain([combobox, 'optionalAccess', _ => _.omit, 'call', _2 => _2(
30
+ "baseElement",
31
+ "arrowElement",
32
+ "anchorElement",
33
+ "contentElement",
34
+ "popoverElement",
35
+ "disclosureElement"
36
+ )])
37
+ );
38
+ const syncState = store.getState();
39
+ const composite = _AZVDLKO3cjs.createCompositeStore.call(void 0, {
40
+ ...props,
41
+ store,
42
+ orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
43
+ props.orientation,
44
+ syncState.orientation,
45
+ "vertical"
46
+ )
47
+ });
48
+ const hovercard = _EIDN2CWHcjs.createHovercardStore.call(void 0, {
49
+ ...props,
50
+ store,
51
+ placement: _5D5Y5EI4cjs.defaultValue.call(void 0,
52
+ props.placement,
53
+ syncState.placement,
54
+ "bottom-start"
55
+ ),
56
+ hideTimeout: _5D5Y5EI4cjs.defaultValue.call(void 0, props.hideTimeout, syncState.hideTimeout, 0)
57
+ });
58
+ const initialState = {
59
+ ...composite.getState(),
60
+ ...hovercard.getState(),
61
+ initialFocus: _5D5Y5EI4cjs.defaultValue.call(void 0, syncState.initialFocus, "container"),
62
+ values: _5D5Y5EI4cjs.defaultValue.call(void 0,
63
+ props.values,
64
+ syncState.values,
65
+ props.defaultValues,
66
+ {}
67
+ )
68
+ };
69
+ const menu = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, composite, hovercard, store);
70
+ menu.setup(
71
+ () => menu.sync(
72
+ (state) => {
73
+ if (state.mounted)
74
+ return;
75
+ menu.setState("activeId", null);
76
+ },
77
+ ["mounted"]
78
+ )
79
+ );
80
+ return {
81
+ ...composite,
82
+ ...hovercard,
83
+ ...menu,
84
+ setInitialFocus: (value) => menu.setState("initialFocus", value),
85
+ setValues: (values) => menu.setState("values", values),
86
+ setValue: (name, value) => {
87
+ if (name === "__proto__")
88
+ return;
89
+ if (name === "constructor")
90
+ return;
91
+ if (Array.isArray(name))
92
+ return;
93
+ menu.setState("values", (values) => {
94
+ const prevValue = values[name];
95
+ const nextValue = _5D5Y5EI4cjs.applyState.call(void 0, value, prevValue);
96
+ if (nextValue === prevValue)
97
+ return values;
98
+ return {
99
+ ...values,
100
+ [name]: nextValue !== void 0 && nextValue
101
+ };
102
+ });
103
+ }
104
+ };
105
+ }
106
+
107
+
108
+ exports.createMenuStore = createMenuStore;
@@ -0,0 +1,70 @@
1
+ import type { ComboboxStore } from "../combobox/combobox-store.js";
2
+ import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
3
+ import type { HovercardStoreFunctions, HovercardStoreOptions, HovercardStoreState } from "../hovercard/hovercard-store.js";
4
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
5
+ import type { BivariantCallback, PickRequired, SetState, SetStateAction } from "../utils/types.js";
6
+ type Values = Record<string, string | boolean | number | Array<string | number>>;
7
+ export declare function createMenuStore<T extends Values = Values>(props: PickRequired<MenuStoreProps<T>, "values" | "defaultValues">): MenuStore<T>;
8
+ export declare function createMenuStore(props?: MenuStoreProps): MenuStore;
9
+ export type MenuStoreValues = Record<string, string | boolean | number | Array<string | number>>;
10
+ export interface MenuStoreState<T extends Values = Values> extends CompositeStoreState, HovercardStoreState {
11
+ /**
12
+ * @default "vertical"
13
+ */
14
+ orientation: CompositeStoreState["orientation"];
15
+ /**
16
+ * @default "bottom-start"
17
+ */
18
+ placement: HovercardStoreState["placement"];
19
+ /**
20
+ * @default 0
21
+ */
22
+ hideTimeout: HovercardStoreState["hideTimeout"];
23
+ /**
24
+ * Determines the element that should be focused when the menu is opened.
25
+ */
26
+ initialFocus: "container" | "first" | "last";
27
+ /**
28
+ * A map of names and values that will be used by the `MenuItemCheckbox` and
29
+ * `MenuItemRadio` components.
30
+ */
31
+ values: T;
32
+ }
33
+ export interface MenuStoreFunctions<T extends Values = Values> extends CompositeStoreFunctions, HovercardStoreFunctions {
34
+ /**
35
+ * Sets the `initialFocus` state.
36
+ */
37
+ setInitialFocus: SetState<MenuStoreState<T>["initialFocus"]>;
38
+ /**
39
+ * Sets the `values` state.
40
+ * @example
41
+ * store.setValues({ watching: ["issues"] });
42
+ * store.setValues((values) => ({ ...values, watching: ["issues"] }));
43
+ */
44
+ setValues: SetState<MenuStoreState<T>["values"]>;
45
+ /**
46
+ * Sets a specific menu value.
47
+ * @param name The name.
48
+ * @param value The value.
49
+ * @example
50
+ * store.setValue("watching", ["issues"]);
51
+ * store.setValue("watching", (value) => [...value, "issues"]);
52
+ */
53
+ setValue: BivariantCallback<(name: string, value: SetStateAction<MenuStoreState<T>["values"][string]>) => void>;
54
+ }
55
+ export interface MenuStoreOptions<T extends Values = Values> extends StoreOptions<MenuStoreState<T>, "orientation" | "placement" | "hideTimeout" | "values">, CompositeStoreOptions, HovercardStoreOptions {
56
+ /**
57
+ * A reference to a combobox store. This is used when combining the combobox
58
+ * with a menu (e.g., dropdown menu with a search input). The stores will
59
+ * share the same state.
60
+ */
61
+ combobox?: ComboboxStore;
62
+ /**
63
+ * The default values for the `values` state.
64
+ * @default {}
65
+ */
66
+ defaultValues?: MenuStoreState<T>["values"];
67
+ }
68
+ export type MenuStoreProps<T extends Values = Values> = MenuStoreOptions<T> & StoreProps<MenuStoreState<T>>;
69
+ export type MenuStore<T extends Values = Values> = MenuStoreFunctions<T> & Store<MenuStoreState<T>>;
70
+ export {};
@@ -0,0 +1,10 @@
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
+
10
+ exports.createPopoverStore = _3KP2MDG6cjs.createPopoverStore;