@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,150 @@
1
+ import type { DialogStoreFunctions, DialogStoreOptions, DialogStoreState } from "../dialog/dialog-store.js";
2
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
+ import type { SetState } from "../utils/types.js";
4
+ type BasePlacement = "top" | "bottom" | "left" | "right";
5
+ type Placement = BasePlacement | `${BasePlacement}-start` | `${BasePlacement}-end`;
6
+ type AnchorRect = {
7
+ x?: number;
8
+ y?: number;
9
+ width?: number;
10
+ height?: number;
11
+ };
12
+ /**
13
+ * Creates a popover store.
14
+ */
15
+ export declare function createPopoverStore({ getAnchorRect, renderCallback, popover: otherPopover, ...props }?: PopoverStoreProps): PopoverStore;
16
+ export interface PopoverStoreRenderCallbackProps extends Pick<PopoverStoreState, "anchorElement" | "popoverElement" | "arrowElement" | "mounted" | "placement" | "fixed" | "gutter" | "shift" | "overlap" | "flip" | "sameWidth" | "fitViewport" | "arrowPadding" | "overflowPadding"> {
17
+ /**
18
+ * A method that updates the `currentPlacement` state.
19
+ */
20
+ setPlacement: SetState<Placement>;
21
+ /**
22
+ * The default render callback that will be called when the `renderCallback`
23
+ * prop is not provided.
24
+ */
25
+ defaultRenderCallback: () => () => void;
26
+ }
27
+ export interface PopoverStoreState extends DialogStoreState {
28
+ /**
29
+ * The anchor element.
30
+ */
31
+ anchorElement: HTMLElement | null;
32
+ /**
33
+ * The popover element that will render the placement attributes.
34
+ */
35
+ popoverElement: HTMLElement | null;
36
+ /**
37
+ * The arrow element.
38
+ */
39
+ arrowElement: HTMLElement | null;
40
+ /**
41
+ * The current temporary placement state of the popover. This may be different
42
+ * from the the `placement` state if the popover has needed to update its
43
+ * position on the fly.
44
+ */
45
+ currentPlacement: Placement;
46
+ /**
47
+ * The placement of the popover.
48
+ * @default "bottom"
49
+ */
50
+ placement: Placement;
51
+ /**
52
+ * Whether the popover has `position: fixed` or not.
53
+ * @default false
54
+ */
55
+ fixed: boolean;
56
+ /**
57
+ * The distance between the popover and the anchor element. By default, it's 0
58
+ * plus half of the arrow offset, if it exists.
59
+ */
60
+ gutter: number | undefined;
61
+ /**
62
+ * The skidding of the popover along the anchor element.
63
+ * @default 0
64
+ */
65
+ shift: number;
66
+ /**
67
+ * Controls the behavior of the popover when it overflows the viewport:
68
+ * - If a `boolean`, specifies whether the popover should flip to the
69
+ * opposite side when it overflows.
70
+ * - If a `string`, indicates the preferred fallback placements when it
71
+ * overflows. The placements must be spaced-delimited, e.g. "top left".
72
+ * @default true
73
+ */
74
+ flip: boolean | string;
75
+ /**
76
+ * Whether the popover should slide when it overflows.
77
+ * @default true
78
+ */
79
+ slide: boolean;
80
+ /**
81
+ * Whether the popover can overlap the anchor element when it overflows.
82
+ * @default false
83
+ */
84
+ overlap: boolean;
85
+ /**
86
+ * Whether the popover should have the same width as the anchor element. This
87
+ * will be exposed to CSS as `--popover-anchor-width`.
88
+ * @default false
89
+ */
90
+ sameWidth: boolean;
91
+ /**
92
+ * Whether the popover should fit the viewport. If this is set to true, the
93
+ * popover wrapper will have `maxWidth` and `maxHeight` set to the viewport
94
+ * size. This will be exposed to CSS as `--popover-available-width` and
95
+ * `--popover-available-height`.
96
+ * @default false
97
+ */
98
+ fitViewport: boolean;
99
+ /**
100
+ * The minimum padding between the arrow and the popover corner.
101
+ * @default 4
102
+ */
103
+ arrowPadding: number;
104
+ /**
105
+ * The minimum padding between the popover and the viewport edge. This will be
106
+ * exposed to CSS as `--popover-overflow-padding`.
107
+ * @default 8
108
+ */
109
+ overflowPadding: number;
110
+ }
111
+ export interface PopoverStoreFunctions extends DialogStoreFunctions {
112
+ /**
113
+ * Sets the anchor element.
114
+ */
115
+ setAnchorElement: SetState<PopoverStoreState["anchorElement"]>;
116
+ /**
117
+ * Sets the popover element.
118
+ */
119
+ setPopoverElement: SetState<PopoverStoreState["popoverElement"]>;
120
+ /**
121
+ * Sets the arrow element.
122
+ */
123
+ setArrowElement: SetState<PopoverStoreState["arrowElement"]>;
124
+ /**
125
+ * Function that returns the anchor element's DOMRect. If this is explicitly
126
+ * passed, it will override the anchor `getBoundingClientRect` method.
127
+ * @param anchor The anchor element.
128
+ */
129
+ getAnchorRect?: (anchor: HTMLElement | null) => AnchorRect | null;
130
+ /**
131
+ * A function that will be called when the popover needs to calculate its
132
+ * styles. It will override the internal behavior.
133
+ */
134
+ renderCallback?: (props: PopoverStoreRenderCallbackProps) => void | (() => void);
135
+ /**
136
+ * A function that can be used to recompute the popover styles. This is useful
137
+ * when the popover anchor changes in a way that affects the popover position.
138
+ */
139
+ render: () => void;
140
+ }
141
+ export interface PopoverStoreOptions extends StoreOptions<PopoverStoreState, "placement" | "fixed" | "gutter" | "shift" | "flip" | "slide" | "overlap" | "sameWidth" | "fitViewport" | "arrowPadding" | "overflowPadding">, Partial<Pick<PopoverStoreFunctions, "getAnchorRect" | "renderCallback">>, DialogStoreOptions {
142
+ /**
143
+ * A reference to another popover store that's controlling another popover to
144
+ * keep them in sync.
145
+ */
146
+ popover?: PopoverStore;
147
+ }
148
+ export type PopoverStoreProps = PopoverStoreOptions & StoreProps<PopoverStoreState>;
149
+ export type PopoverStore = PopoverStoreFunctions & Store<PopoverStoreState>;
150
+ export {};
@@ -0,0 +1,10 @@
1
+ import {
2
+ createPopoverStore
3
+ } from "../__chunks/6UPCMUXT.js";
4
+ import "../__chunks/ADRUFBEO.js";
5
+ import "../__chunks/HCKYJLMC.js";
6
+ import "../__chunks/UOJSZ35L.js";
7
+ import "../__chunks/KLKI3AIB.js";
8
+ export {
9
+ createPopoverStore
10
+ };
@@ -0,0 +1,36 @@
1
+ import type { CompositeStoreFunctions, 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 radio store.
6
+ */
7
+ export declare function createRadioStore({ ...props }?: RadioStoreProps): RadioStore;
8
+ export interface RadioStoreState extends CompositeStoreState {
9
+ /**
10
+ * @default true
11
+ */
12
+ focusLoop: CompositeStoreState["focusLoop"];
13
+ /**
14
+ * The value of the radio group.
15
+ * @default null
16
+ */
17
+ value: string | number | null;
18
+ }
19
+ export interface RadioStoreFunctions extends CompositeStoreFunctions {
20
+ /**
21
+ * Sets the `value` state.
22
+ * @example
23
+ * store.setValue("apple");
24
+ * store.setValue((value) => value === "apple" ? "orange" : "apple");
25
+ */
26
+ setValue: SetState<RadioStoreState["value"]>;
27
+ }
28
+ export interface RadioStoreOptions extends StoreOptions<RadioStoreState, "focusLoop" | "value">, CompositeStoreOptions {
29
+ /**
30
+ * The default value of the radio group.
31
+ * @default null
32
+ */
33
+ defaultValue?: RadioStoreState["value"];
34
+ }
35
+ export type RadioStoreProps = RadioStoreOptions & StoreProps<RadioStoreState>;
36
+ export type RadioStore = RadioStoreFunctions & Store<RadioStoreState>;
@@ -0,0 +1,41 @@
1
+ import {
2
+ createCompositeStore
3
+ } from "../__chunks/6U25WEDX.js";
4
+ import "../__chunks/L7KN5AYP.js";
5
+ import {
6
+ createStore
7
+ } from "../__chunks/UOJSZ35L.js";
8
+ import {
9
+ defaultValue
10
+ } from "../__chunks/KLKI3AIB.js";
11
+ import "../__chunks/UVCATTRC.js";
12
+ import "../__chunks/5XEKIOCW.js";
13
+
14
+ // src/radio/radio-store.ts
15
+ function createRadioStore({
16
+ ...props
17
+ } = {}) {
18
+ const syncState = props.store?.getState();
19
+ const composite = createCompositeStore({
20
+ ...props,
21
+ focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true)
22
+ });
23
+ const initialState = {
24
+ ...composite.getState(),
25
+ value: defaultValue(
26
+ props.value,
27
+ syncState?.value,
28
+ props.defaultValue,
29
+ null
30
+ )
31
+ };
32
+ const radio = createStore(initialState, composite, props.store);
33
+ return {
34
+ ...composite,
35
+ ...radio,
36
+ setValue: (value) => radio.setState("value", value)
37
+ };
38
+ }
39
+ export {
40
+ createRadioStore
41
+ };
@@ -0,0 +1,87 @@
1
+ import type { ComboboxStore } from "../combobox/combobox-store.js";
2
+ import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
3
+ import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
4
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
5
+ import type { PickRequired, SetState } from "../utils/types.js";
6
+ type Value = string | string[];
7
+ type MutableValue<T extends Value = Value> = T extends string ? string : T;
8
+ type Item = CompositeStoreItem & {
9
+ value?: string;
10
+ };
11
+ export declare function createSelectStore<T extends Value = Value>(props: PickRequired<SelectStoreProps<T>, "value" | "defaultValue">): SelectStore<T>;
12
+ export declare function createSelectStore(props?: SelectStoreProps): SelectStore;
13
+ export type SelectStoreItem = Item;
14
+ export type SelectStoreValue = Value;
15
+ export interface SelectStoreState<T extends Value = Value> extends CompositeStoreState<Item>, PopoverStoreState {
16
+ /**
17
+ * @default true
18
+ */
19
+ virtualFocus: CompositeStoreState<Item>["virtualFocus"];
20
+ /**
21
+ * @default false
22
+ */
23
+ includesBaseElement: CompositeStoreState<Item>["includesBaseElement"];
24
+ /**
25
+ * @default null
26
+ */
27
+ activeId: CompositeStoreState<Item>["activeId"];
28
+ /**
29
+ * @default "vertical"
30
+ */
31
+ orientation: CompositeStoreState<Item>["orientation"];
32
+ /**
33
+ * @default "bottom-start"
34
+ */
35
+ placement: PopoverStoreState["placement"];
36
+ /**
37
+ * The select value.
38
+ */
39
+ value: MutableValue<T>;
40
+ /**
41
+ * Whether the select value should be set when the active item changes by
42
+ * moving (which usually happens when moving to an item using the keyboard).
43
+ * @default false
44
+ */
45
+ setValueOnMove: boolean;
46
+ /**
47
+ * The select button element.
48
+ */
49
+ selectElement: HTMLElement | null;
50
+ /**
51
+ * The select label element.
52
+ */
53
+ labelElement: HTMLElement | null;
54
+ }
55
+ export interface SelectStoreFunctions<T extends Value = Value> extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
56
+ /**
57
+ * Sets the `value` state.
58
+ * @example
59
+ * store.setValue("Apple");
60
+ * store.setValue(["Apple", "Banana"]);
61
+ * store.setValue((value) => value === "Apple" ? "Banana" : "Apple"));
62
+ */
63
+ setValue: SetState<SelectStoreState<T>["value"]>;
64
+ /**
65
+ * Sets the `selectElement` state.
66
+ */
67
+ setSelectElement: SetState<SelectStoreState<T>["selectElement"]>;
68
+ /**
69
+ * Sets the `labelElement` state.
70
+ */
71
+ setLabelElement: SetState<SelectStoreState<T>["labelElement"]>;
72
+ }
73
+ export interface SelectStoreOptions<T extends Value = Value> extends StoreOptions<SelectStoreState<T>, "virtualFocus" | "includesBaseElement" | "activeId" | "orientation" | "placement" | "value" | "setValueOnMove">, CompositeStoreOptions<Item>, PopoverStoreOptions {
74
+ /**
75
+ * A reference to a combobox store. This is used when combining the combobox
76
+ * with a select (e.g., select with a search input). The stores will share the
77
+ * same state.
78
+ */
79
+ combobox?: ComboboxStore;
80
+ /**
81
+ * The default value. If not set, the first non-disabled item will be used.
82
+ */
83
+ defaultValue?: SelectStoreState<T>["value"];
84
+ }
85
+ export type SelectStoreProps<T extends Value = Value> = SelectStoreOptions<T> & StoreProps<SelectStoreState<T>>;
86
+ export type SelectStore<T extends Value = Value> = SelectStoreFunctions<T> & Store<SelectStoreState<T>>;
87
+ export {};
@@ -0,0 +1,164 @@
1
+ import {
2
+ createPopoverStore
3
+ } from "../__chunks/6UPCMUXT.js";
4
+ import "../__chunks/ADRUFBEO.js";
5
+ import "../__chunks/HCKYJLMC.js";
6
+ import {
7
+ createCompositeStore
8
+ } from "../__chunks/6U25WEDX.js";
9
+ import "../__chunks/L7KN5AYP.js";
10
+ import {
11
+ createStore,
12
+ mergeStore
13
+ } from "../__chunks/UOJSZ35L.js";
14
+ import {
15
+ defaultValue
16
+ } from "../__chunks/KLKI3AIB.js";
17
+ import "../__chunks/UVCATTRC.js";
18
+ import {
19
+ toArray
20
+ } from "../__chunks/5XEKIOCW.js";
21
+
22
+ // src/select/select-store.ts
23
+ function createSelectStore({
24
+ combobox,
25
+ ...props
26
+ } = {}) {
27
+ const store = mergeStore(
28
+ props.store,
29
+ combobox?.omit(
30
+ "value",
31
+ "items",
32
+ "renderedItems",
33
+ "baseElement",
34
+ "arrowElement",
35
+ "anchorElement",
36
+ "contentElement",
37
+ "popoverElement",
38
+ "disclosureElement"
39
+ )
40
+ );
41
+ const syncState = store.getState();
42
+ const composite = createCompositeStore({
43
+ ...props,
44
+ store,
45
+ virtualFocus: defaultValue(
46
+ props.virtualFocus,
47
+ syncState.virtualFocus,
48
+ true
49
+ ),
50
+ includesBaseElement: defaultValue(
51
+ props.includesBaseElement,
52
+ syncState.includesBaseElement,
53
+ false
54
+ ),
55
+ activeId: defaultValue(
56
+ props.activeId,
57
+ syncState.activeId,
58
+ props.defaultActiveId,
59
+ null
60
+ ),
61
+ orientation: defaultValue(
62
+ props.orientation,
63
+ syncState.orientation,
64
+ "vertical"
65
+ )
66
+ });
67
+ const popover = createPopoverStore({
68
+ ...props,
69
+ store,
70
+ placement: defaultValue(
71
+ props.placement,
72
+ syncState.placement,
73
+ "bottom-start"
74
+ )
75
+ });
76
+ const initialValue = new String("");
77
+ const initialState = {
78
+ ...composite.getState(),
79
+ ...popover.getState(),
80
+ value: defaultValue(
81
+ props.value,
82
+ syncState.value,
83
+ props.defaultValue,
84
+ initialValue
85
+ ),
86
+ setValueOnMove: defaultValue(
87
+ props.setValueOnMove,
88
+ syncState.setValueOnMove,
89
+ false
90
+ ),
91
+ selectElement: defaultValue(syncState.selectElement, null),
92
+ labelElement: defaultValue(syncState.labelElement, null)
93
+ };
94
+ const select = createStore(initialState, composite, popover, store);
95
+ select.setup(
96
+ () => select.sync(
97
+ (state) => {
98
+ if (state.value !== initialValue)
99
+ return;
100
+ if (!state.items.length)
101
+ return;
102
+ const item = state.items.find(
103
+ (item2) => !item2.disabled && item2.value != null
104
+ );
105
+ if (item?.value == null)
106
+ return;
107
+ select.setState("value", item.value);
108
+ },
109
+ ["value", "items"]
110
+ )
111
+ );
112
+ select.setup(
113
+ () => select.sync(
114
+ (state) => {
115
+ if (combobox)
116
+ return;
117
+ if (state.mounted)
118
+ return;
119
+ const values = toArray(state.value);
120
+ const lastValue = values[values.length - 1];
121
+ if (lastValue == null)
122
+ return;
123
+ const item = state.items.find(
124
+ (item2) => !item2.disabled && item2.value === lastValue
125
+ );
126
+ if (!item)
127
+ return;
128
+ select.setState("activeId", item.id);
129
+ },
130
+ ["mounted", "items", "value"]
131
+ )
132
+ );
133
+ select.setup(
134
+ () => select.syncBatch(
135
+ (state) => {
136
+ const { mounted, value, activeId } = select.getState();
137
+ if (!state.setValueOnMove && mounted)
138
+ return;
139
+ if (Array.isArray(value))
140
+ return;
141
+ if (!state.moves)
142
+ return;
143
+ if (!activeId)
144
+ return;
145
+ const item = composite.item(activeId);
146
+ if (!item || item.disabled || item.value == null)
147
+ return;
148
+ select.setState("value", item.value);
149
+ },
150
+ ["setValueOnMove", "moves"]
151
+ )
152
+ );
153
+ return {
154
+ ...composite,
155
+ ...popover,
156
+ ...select,
157
+ setValue: (value) => select.setState("value", value),
158
+ setSelectElement: (element) => select.setState("selectElement", element),
159
+ setLabelElement: (element) => select.setState("labelElement", element)
160
+ };
161
+ }
162
+ export {
163
+ createSelectStore
164
+ };
@@ -0,0 +1,78 @@
1
+ import type { CollectionStore, CollectionStoreItem } from "../collection/collection-store.js";
2
+ import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
3
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
4
+ import type { SetState } from "../utils/types.js";
5
+ type Item = CompositeStoreItem & {
6
+ dimmed?: boolean;
7
+ };
8
+ type Panel = CollectionStoreItem & {
9
+ tabId?: string | null;
10
+ };
11
+ export declare function createTabStore(props?: TabStoreProps): TabStore;
12
+ export type TabStoreItem = Item;
13
+ export type TabStorePanel = Panel;
14
+ export interface TabStoreState extends CompositeStoreState<Item> {
15
+ /**
16
+ * @default "horizontal"
17
+ */
18
+ orientation: CompositeStoreState<Item>["orientation"];
19
+ /**
20
+ * @default true
21
+ */
22
+ focusLoop: CompositeStoreState<Item>["focusLoop"];
23
+ /**
24
+ * The id of the tab whose panel is currently visible. If it's `undefined`, it
25
+ * will be automatically set to the first enabled tab.
26
+ */
27
+ selectedId: TabStoreState["activeId"];
28
+ /**
29
+ * Whether the tab should be selected when it receives focus. If it's set to
30
+ * `false`, the tab will be selected only when it's clicked.
31
+ * @default true
32
+ */
33
+ selectOnMove?: boolean;
34
+ }
35
+ export interface TabStoreFunctions extends CompositeStoreFunctions<Item> {
36
+ /**
37
+ * Sets the `selectedId` state without moving focus. If you want to move focus,
38
+ * use the `select` function instead.
39
+ * @example
40
+ * // Selects the tab with id "tab-1"
41
+ * store.setSelectedId("tab-1");
42
+ * // Toggles between "tab-1" and "tab-2"
43
+ * store.setSelectedId((id) => id === "tab-1" ? "tab-2" : "tab-1"));
44
+ * // Selects the first tab
45
+ * store.setSelectedId(store.first());
46
+ * // Selects the next tab
47
+ * store.setSelectedId(store.next());
48
+ */
49
+ setSelectedId: SetState<TabStoreState["selectedId"]>;
50
+ /**
51
+ * A collection store containing the tab panels.
52
+ */
53
+ panels: CollectionStore<Panel>;
54
+ /**
55
+ * Selects the tab for the given id and moves focus to it. If you want to set
56
+ * the `selectedId` state without moving focus, use the `setSelectedId`
57
+ * function instead.
58
+ * @param id The id of the tab to select.
59
+ * @example
60
+ * // Selects the tab with id "tab-1"
61
+ * store.select("tab-1");
62
+ * // Selects the first tab
63
+ * store.select(store.first());
64
+ * // Selects the next tab
65
+ * store.select(store.next());
66
+ */
67
+ select: TabStore["move"];
68
+ }
69
+ export interface TabStoreOptions extends StoreOptions<TabStoreState, "orientation" | "focusLoop" | "selectedId" | "selectOnMove">, CompositeStoreOptions<Item> {
70
+ /**
71
+ * The id of the tab whose panel is currently visible. If it's `undefined`, it
72
+ * will be automatically set to the first enabled tab.
73
+ */
74
+ defaultSelectedId?: TabStoreState["selectedId"];
75
+ }
76
+ export type TabStoreProps = TabStoreOptions & StoreProps<TabStoreState>;
77
+ export type TabStore = TabStoreFunctions & Store<TabStoreState>;
78
+ export {};
@@ -0,0 +1,126 @@
1
+ import {
2
+ createCompositeStore
3
+ } from "../__chunks/6U25WEDX.js";
4
+ import {
5
+ createCollectionStore
6
+ } from "../__chunks/L7KN5AYP.js";
7
+ import {
8
+ createStore
9
+ } from "../__chunks/UOJSZ35L.js";
10
+ import {
11
+ defaultValue
12
+ } from "../__chunks/KLKI3AIB.js";
13
+ import "../__chunks/UVCATTRC.js";
14
+ import "../__chunks/5XEKIOCW.js";
15
+
16
+ // src/tab/tab-store.ts
17
+ function createTabStore(props = {}) {
18
+ const syncState = props.store?.getState();
19
+ const composite = createCompositeStore({
20
+ ...props,
21
+ orientation: defaultValue(
22
+ props.orientation,
23
+ syncState?.orientation,
24
+ "horizontal"
25
+ ),
26
+ focusLoop: defaultValue(props.focusLoop, syncState?.focusLoop, true)
27
+ });
28
+ const panels = createCollectionStore();
29
+ const initialState = {
30
+ ...composite.getState(),
31
+ selectedId: defaultValue(
32
+ props.selectedId,
33
+ syncState?.selectedId,
34
+ props.defaultSelectedId,
35
+ void 0
36
+ ),
37
+ selectOnMove: defaultValue(
38
+ props.selectOnMove,
39
+ syncState?.selectOnMove,
40
+ true
41
+ )
42
+ };
43
+ const tab = createStore(initialState, composite, props.store);
44
+ tab.setup(
45
+ () => tab.sync(() => {
46
+ const { activeId, selectOnMove } = tab.getState();
47
+ if (!selectOnMove)
48
+ return;
49
+ if (!activeId)
50
+ return;
51
+ const tabItem = composite.item(activeId);
52
+ if (!tabItem)
53
+ return;
54
+ if (tabItem.dimmed)
55
+ return;
56
+ if (tabItem.disabled)
57
+ return;
58
+ tab.setState("selectedId", tabItem.id);
59
+ }, ["moves"])
60
+ );
61
+ tab.setup(
62
+ () => tab.sync(
63
+ (state) => tab.setState("activeId", state.selectedId),
64
+ ["selectedId"]
65
+ )
66
+ );
67
+ tab.setup(
68
+ () => tab.sync(
69
+ (state) => {
70
+ if (state.selectedId !== void 0)
71
+ return;
72
+ const { activeId, renderedItems } = tab.getState();
73
+ const tabItem = composite.item(activeId);
74
+ if (tabItem && !tabItem.disabled && !tabItem.dimmed) {
75
+ tab.setState("selectedId", tabItem.id);
76
+ } else {
77
+ const tabItem2 = renderedItems.find(
78
+ (item) => !item.disabled && !item.dimmed
79
+ );
80
+ tab.setState("selectedId", tabItem2?.id);
81
+ }
82
+ },
83
+ ["selectedId", "renderedItems"]
84
+ )
85
+ );
86
+ tab.setup(
87
+ () => tab.sync(
88
+ (state) => {
89
+ const tabs = state.renderedItems;
90
+ if (!tabs.length)
91
+ return;
92
+ return panels.sync(
93
+ (state2) => {
94
+ const items = state2.renderedItems;
95
+ const hasOrphanPanels = items.some((panel) => !panel.tabId);
96
+ if (!hasOrphanPanels)
97
+ return;
98
+ items.forEach((panel, i) => {
99
+ if (panel.tabId)
100
+ return;
101
+ const tabItem = tabs[i];
102
+ if (!tabItem)
103
+ return;
104
+ panels.renderItem({ ...panel, tabId: tabItem.id });
105
+ });
106
+ },
107
+ ["renderedItems"]
108
+ );
109
+ },
110
+ ["renderedItems"]
111
+ )
112
+ );
113
+ return {
114
+ ...composite,
115
+ ...tab,
116
+ panels,
117
+ setSelectedId: (id) => tab.setState("selectedId", id),
118
+ select: (id) => {
119
+ tab.setState("selectedId", id);
120
+ composite.move(id);
121
+ }
122
+ };
123
+ }
124
+ export {
125
+ createTabStore
126
+ };