@proyecto-viviana/solid-stately 0.2.7 → 0.3.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 (242) hide show
  1. package/README.md +30 -283
  2. package/dist/autocomplete/createAutocompleteState.d.ts +2 -2
  3. package/dist/autocomplete/index.d.ts +1 -1
  4. package/dist/calendar/createCalendarState.d.ts +22 -7
  5. package/dist/calendar/createDateFieldState.d.ts +30 -7
  6. package/dist/calendar/createDatePickerState.d.ts +60 -0
  7. package/dist/calendar/createRangeCalendarState.d.ts +27 -8
  8. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  9. package/dist/calendar/index.d.ts +7 -6
  10. package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
  11. package/dist/checkbox/index.d.ts +1 -1
  12. package/dist/collections/ListCollection.d.ts +1 -1
  13. package/dist/collections/createListState.d.ts +8 -8
  14. package/dist/collections/createMenuState.d.ts +7 -7
  15. package/dist/collections/createSelectionState.d.ts +5 -5
  16. package/dist/collections/index.d.ts +5 -5
  17. package/dist/collections/types.d.ts +12 -12
  18. package/dist/color/Color.d.ts +1 -1
  19. package/dist/color/createColorAreaState.d.ts +4 -2
  20. package/dist/color/createColorFieldState.d.ts +38 -12
  21. package/dist/color/createColorSliderState.d.ts +9 -2
  22. package/dist/color/createColorWheelState.d.ts +13 -2
  23. package/dist/color/getColorChannels.d.ts +1 -1
  24. package/dist/color/index.d.ts +6 -6
  25. package/dist/color/types.d.ts +4 -4
  26. package/dist/combobox/createComboBoxState.d.ts +27 -13
  27. package/dist/combobox/index.d.ts +1 -1
  28. package/dist/data/createAsyncList.d.ts +4 -4
  29. package/dist/data/createListData.d.ts +2 -2
  30. package/dist/data/createTreeData.d.ts +6 -2
  31. package/dist/data/index.d.ts +3 -3
  32. package/dist/datepicker/index.d.ts +2 -4
  33. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  34. package/dist/disclosure/index.d.ts +1 -1
  35. package/dist/dnd/createDragState.d.ts +2 -2
  36. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  37. package/dist/dnd/createDropState.d.ts +2 -2
  38. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  39. package/dist/dnd/index.d.ts +5 -5
  40. package/dist/dnd/types.d.ts +16 -16
  41. package/dist/form/createFormValidationState.d.ts +3 -3
  42. package/dist/form/index.d.ts +1 -1
  43. package/dist/grid/createGridState.d.ts +2 -2
  44. package/dist/grid/index.d.ts +2 -2
  45. package/dist/grid/types.d.ts +13 -11
  46. package/dist/index.d.ts +31 -30
  47. package/dist/index.js +7924 -7238
  48. package/dist/index.js.map +1 -1
  49. package/dist/menu/index.d.ts +2 -2
  50. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  51. package/dist/numberfield/index.d.ts +1 -1
  52. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  53. package/dist/overlays/index.d.ts +1 -1
  54. package/dist/radio/createRadioGroupState.d.ts +7 -7
  55. package/dist/radio/index.d.ts +1 -1
  56. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  57. package/dist/searchfield/index.d.ts +2 -2
  58. package/dist/select/createSelectState.d.ts +8 -8
  59. package/dist/select/index.d.ts +1 -1
  60. package/dist/selection/index.d.ts +5 -5
  61. package/dist/slider/createSliderState.d.ts +3 -3
  62. package/dist/slider/index.d.ts +2 -2
  63. package/dist/steplist/createStepListState.d.ts +48 -0
  64. package/dist/steplist/index.d.ts +1 -0
  65. package/dist/table/TableCollection.d.ts +3 -3
  66. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  67. package/dist/table/createTableState.d.ts +2 -2
  68. package/dist/table/index.d.ts +5 -3
  69. package/dist/table/types.d.ts +10 -10
  70. package/dist/tabs/createTabListState.d.ts +5 -5
  71. package/dist/tabs/index.d.ts +1 -1
  72. package/dist/textfield/createTextFieldState.d.ts +2 -2
  73. package/dist/textfield/index.d.ts +1 -1
  74. package/dist/toast/createToastState.d.ts +8 -2
  75. package/dist/toast/index.d.ts +1 -1
  76. package/dist/toggle/createToggleGroupState.d.ts +4 -4
  77. package/dist/toggle/createToggleState.d.ts +2 -2
  78. package/dist/toggle/index.d.ts +2 -2
  79. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  80. package/dist/tooltip/index.d.ts +1 -1
  81. package/dist/tree/TreeCollection.d.ts +2 -2
  82. package/dist/tree/createTreeState.d.ts +2 -2
  83. package/dist/tree/index.d.ts +3 -3
  84. package/dist/tree/types.d.ts +19 -13
  85. package/dist/utils/index.d.ts +1 -1
  86. package/dist/utils/reactivity.d.ts +1 -1
  87. package/package.json +29 -30
  88. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  89. package/src/autocomplete/createAutocompleteState.ts +24 -30
  90. package/src/autocomplete/index.d.ts +6 -2
  91. package/src/autocomplete/index.ts +1 -1
  92. package/src/calendar/createCalendarState.d.ts +139 -117
  93. package/src/calendar/createCalendarState.ts +221 -74
  94. package/src/calendar/createDateFieldState.d.ts +130 -95
  95. package/src/calendar/createDateFieldState.ts +263 -151
  96. package/src/calendar/createDatePickerState.ts +347 -0
  97. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  98. package/src/calendar/createRangeCalendarState.ts +293 -79
  99. package/src/calendar/createTimeFieldState.d.ts +81 -79
  100. package/src/calendar/createTimeFieldState.ts +187 -108
  101. package/src/calendar/index.d.ts +80 -7
  102. package/src/calendar/index.ts +21 -12
  103. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  104. package/src/checkbox/createCheckboxGroupState.ts +20 -29
  105. package/src/checkbox/index.d.ts +6 -2
  106. package/src/checkbox/index.ts +1 -1
  107. package/src/collections/ListCollection.d.ts +25 -22
  108. package/src/collections/ListCollection.ts +6 -6
  109. package/src/collections/createListState.d.ts +73 -58
  110. package/src/collections/createListState.ts +19 -18
  111. package/src/collections/createMenuState.d.ts +36 -31
  112. package/src/collections/createMenuState.ts +18 -12
  113. package/src/collections/createSelectionState.d.ts +78 -65
  114. package/src/collections/createSelectionState.ts +36 -32
  115. package/src/collections/index.d.ts +38 -6
  116. package/src/collections/index.ts +5 -10
  117. package/src/collections/types.d.ts +101 -101
  118. package/src/collections/types.ts +12 -12
  119. package/src/color/Color.d.ts +20 -5
  120. package/src/color/Color.ts +357 -254
  121. package/src/color/createColorAreaState.d.ts +67 -65
  122. package/src/color/createColorAreaState.ts +21 -13
  123. package/src/color/createColorFieldState.d.ts +46 -44
  124. package/src/color/createColorFieldState.ts +285 -149
  125. package/src/color/createColorSliderState.d.ts +58 -56
  126. package/src/color/createColorSliderState.ts +45 -14
  127. package/src/color/createColorWheelState.d.ts +42 -40
  128. package/src/color/createColorWheelState.ts +101 -64
  129. package/src/color/getColorChannels.ts +7 -5
  130. package/src/color/index.d.ts +36 -7
  131. package/src/color/index.ts +6 -9
  132. package/src/color/types.d.ts +68 -63
  133. package/src/color/types.ts +11 -19
  134. package/src/combobox/createComboBoxState.d.ts +107 -105
  135. package/src/combobox/createComboBoxState.ts +176 -89
  136. package/src/combobox/index.d.ts +10 -2
  137. package/src/combobox/index.ts +1 -1
  138. package/src/data/createAsyncList.ts +89 -63
  139. package/src/data/createListData.ts +67 -67
  140. package/src/data/createTreeData.ts +304 -91
  141. package/src/data/index.ts +3 -3
  142. package/src/datepicker/index.ts +6 -10
  143. package/src/disclosure/createDisclosureState.d.ts +47 -43
  144. package/src/disclosure/createDisclosureState.ts +7 -21
  145. package/src/disclosure/index.d.ts +10 -2
  146. package/src/disclosure/index.ts +1 -1
  147. package/src/dnd/createDragState.d.ts +51 -42
  148. package/src/dnd/createDragState.ts +12 -14
  149. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  150. package/src/dnd/createDraggableCollectionState.ts +14 -21
  151. package/src/dnd/createDropState.d.ts +64 -45
  152. package/src/dnd/createDropState.ts +22 -32
  153. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  154. package/src/dnd/createDroppableCollectionState.ts +40 -43
  155. package/src/dnd/index.d.ts +54 -6
  156. package/src/dnd/index.ts +5 -18
  157. package/src/dnd/types.d.ts +167 -156
  158. package/src/dnd/types.ts +20 -21
  159. package/src/form/createFormValidationState.d.ts +47 -45
  160. package/src/form/createFormValidationState.ts +30 -63
  161. package/src/form/index.d.ts +16 -2
  162. package/src/form/index.ts +1 -1
  163. package/src/grid/createGridState.d.ts +7 -4
  164. package/src/grid/createGridState.ts +44 -51
  165. package/src/grid/index.d.ts +3 -3
  166. package/src/grid/index.ts +2 -8
  167. package/src/grid/types.d.ts +136 -129
  168. package/src/grid/types.ts +20 -18
  169. package/src/index.d.ts +310 -26
  170. package/src/index.ts +48 -89
  171. package/src/menu/index.ts +2 -4
  172. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  173. package/src/numberfield/createNumberFieldState.ts +26 -31
  174. package/src/numberfield/index.d.ts +6 -2
  175. package/src/numberfield/index.ts +1 -1
  176. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  177. package/src/overlays/createOverlayTriggerState.ts +3 -4
  178. package/src/overlays/index.d.ts +6 -2
  179. package/src/overlays/index.ts +1 -1
  180. package/src/radio/createRadioGroupState.d.ts +54 -52
  181. package/src/radio/createRadioGroupState.ts +27 -29
  182. package/src/radio/index.d.ts +7 -2
  183. package/src/radio/index.ts +1 -1
  184. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  185. package/src/searchfield/createSearchFieldState.ts +5 -11
  186. package/src/searchfield/index.d.ts +3 -3
  187. package/src/searchfield/index.ts +2 -5
  188. package/src/select/createSelectState.d.ts +63 -61
  189. package/src/select/createSelectState.ts +27 -27
  190. package/src/select/index.d.ts +2 -2
  191. package/src/select/index.ts +1 -5
  192. package/src/selection/index.ts +6 -7
  193. package/src/slider/createSliderState.d.ts +60 -60
  194. package/src/slider/createSliderState.ts +55 -33
  195. package/src/slider/index.d.ts +3 -3
  196. package/src/slider/index.ts +2 -6
  197. package/src/ssr/index.d.ts +1 -1
  198. package/src/ssr/index.ts +2 -2
  199. package/src/steplist/createStepListState.ts +191 -0
  200. package/src/steplist/index.ts +5 -0
  201. package/src/table/TableCollection.d.ts +42 -40
  202. package/src/table/TableCollection.ts +61 -64
  203. package/src/table/createTableColumnResizeState.ts +242 -0
  204. package/src/table/createTableState.d.ts +7 -4
  205. package/src/table/createTableState.ts +10 -7
  206. package/src/table/index.d.ts +14 -4
  207. package/src/table/index.ts +10 -3
  208. package/src/table/types.d.ts +98 -92
  209. package/src/table/types.ts +17 -13
  210. package/src/tabs/createTabListState.d.ts +59 -57
  211. package/src/tabs/createTabListState.ts +24 -31
  212. package/src/tabs/index.d.ts +8 -2
  213. package/src/tabs/index.ts +1 -1
  214. package/src/textfield/createTextFieldState.d.ts +16 -14
  215. package/src/textfield/createTextFieldState.ts +7 -18
  216. package/src/textfield/index.d.ts +6 -2
  217. package/src/textfield/index.ts +1 -1
  218. package/src/toast/createToastState.d.ts +92 -86
  219. package/src/toast/createToastState.ts +48 -43
  220. package/src/toast/index.d.ts +12 -2
  221. package/src/toast/index.ts +1 -1
  222. package/src/toggle/createToggleGroupState.ts +11 -21
  223. package/src/toggle/createToggleState.d.ts +19 -19
  224. package/src/toggle/createToggleState.ts +2 -16
  225. package/src/toggle/index.d.ts +2 -2
  226. package/src/toggle/index.ts +2 -6
  227. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  228. package/src/tooltip/createTooltipTriggerState.ts +12 -11
  229. package/src/tooltip/index.d.ts +7 -2
  230. package/src/tooltip/index.ts +1 -1
  231. package/src/tree/TreeCollection.d.ts +26 -23
  232. package/src/tree/TreeCollection.ts +29 -22
  233. package/src/tree/createTreeState.d.ts +7 -4
  234. package/src/tree/createTreeState.ts +39 -41
  235. package/src/tree/index.d.ts +10 -4
  236. package/src/tree/index.ts +3 -3
  237. package/src/tree/types.d.ts +131 -126
  238. package/src/tree/types.ts +22 -13
  239. package/src/utils/index.d.ts +2 -2
  240. package/src/utils/index.ts +1 -1
  241. package/src/utils/reactivity.d.ts +2 -2
  242. package/src/utils/reactivity.ts +3 -3
@@ -3,10 +3,10 @@
3
3
  * Based on @react-stately/slider useSliderState.
4
4
  */
5
5
 
6
- import { type Accessor, createSignal, createMemo } from 'solid-js';
7
- import { access, type MaybeAccessor } from '../utils';
6
+ import { type Accessor, createSignal, createMemo } from "solid-js";
7
+ import { access, type MaybeAccessor } from "../utils";
8
8
 
9
- export type SliderOrientation = 'horizontal' | 'vertical';
9
+ export type SliderOrientation = "horizontal" | "vertical";
10
10
 
11
11
  export interface SliderStateProps {
12
12
  /** The current value (controlled). */
@@ -87,7 +87,7 @@ function clamp(value: number, min: number, max: number): number {
87
87
  function snapToStep(value: number, min: number, max: number, step: number): number {
88
88
  const snapped = Math.round((value - min) / step) * step + min;
89
89
  // Handle floating point precision issues
90
- const decimalPlaces = (step.toString().split('.')[1] || '').length;
90
+ const decimalPlaces = (step.toString().split(".")[1] || "").length;
91
91
  const rounded = parseFloat(snapped.toFixed(decimalPlaces));
92
92
  return clamp(rounded, min, max);
93
93
  }
@@ -95,27 +95,37 @@ function snapToStep(value: number, min: number, max: number, step: number): numb
95
95
  /**
96
96
  * Provides state management for a slider component.
97
97
  */
98
- export function createSliderState(
99
- props: MaybeAccessor<SliderStateProps>
100
- ): SliderState {
98
+ export function createSliderState(props: MaybeAccessor<SliderStateProps>): SliderState {
101
99
  const getProps = () => access(props);
102
100
 
103
- // Get static values with defaults
104
- const minValue = getProps().minValue ?? DEFAULT_MIN;
105
- const maxValue = getProps().maxValue ?? DEFAULT_MAX;
106
- const step = getProps().step ?? DEFAULT_STEP;
107
- const orientation = getProps().orientation ?? 'horizontal';
108
- const isDisabled = getProps().isDisabled ?? false;
109
-
110
- // Calculate page step (10% of range, snapped to step)
111
- const pageStep = Math.max(step, snapToStep((maxValue - minValue) / 10, 0, maxValue - minValue, step));
101
+ const initialProps = getProps();
102
+ const initialMinValue = initialProps.minValue ?? DEFAULT_MIN;
103
+ const initialMaxValue = initialProps.maxValue ?? DEFAULT_MAX;
104
+ const initialStep = initialProps.step ?? DEFAULT_STEP;
105
+
106
+ const minValue = createMemo(() => getProps().minValue ?? DEFAULT_MIN);
107
+ const maxValue = createMemo(() => getProps().maxValue ?? DEFAULT_MAX);
108
+ const step = createMemo(() => getProps().step ?? DEFAULT_STEP);
109
+ const orientation = createMemo(() => getProps().orientation ?? "horizontal");
110
+ const isDisabled = createMemo(() => getProps().isDisabled ?? false);
111
+ const pageStep = createMemo(() =>
112
+ Math.max(
113
+ step(),
114
+ snapToStep((maxValue() - minValue()) / 10, 0, maxValue() - minValue(), step()),
115
+ ),
116
+ );
112
117
 
113
118
  // Controlled vs uncontrolled
114
119
  const isControlled = () => getProps().value !== undefined;
115
120
 
116
121
  // Internal signal for uncontrolled mode
117
122
  const [internalValue, setInternalValue] = createSignal(
118
- snapToStep(getProps().defaultValue ?? minValue, minValue, maxValue, step)
123
+ snapToStep(
124
+ initialProps.defaultValue ?? initialMinValue,
125
+ initialMinValue,
126
+ initialMaxValue,
127
+ initialStep,
128
+ ),
119
129
  );
120
130
 
121
131
  // Dragging and focus state
@@ -125,13 +135,13 @@ export function createSliderState(
125
135
  // Current value accessor
126
136
  const value = createMemo(() => {
127
137
  const p = getProps();
128
- const rawValue = isControlled() ? (p.value ?? minValue) : internalValue();
129
- return snapToStep(rawValue, minValue, maxValue, step);
138
+ const rawValue = isControlled() ? (p.value ?? minValue()) : internalValue();
139
+ return snapToStep(rawValue, minValue(), maxValue(), step());
130
140
  });
131
141
 
132
142
  // Value as percent (0-1)
133
143
  const getValuePercent = createMemo(() => {
134
- return (value() - minValue) / (maxValue - minValue);
144
+ return (value() - minValue()) / (maxValue() - minValue());
135
145
  });
136
146
 
137
147
  // Formatted value
@@ -143,10 +153,10 @@ export function createSliderState(
143
153
 
144
154
  // Set value function
145
155
  const setValue = (newValue: number) => {
146
- if (isDisabled) return;
156
+ if (isDisabled()) return;
147
157
 
148
158
  const p = getProps();
149
- const snappedValue = snapToStep(newValue, minValue, maxValue, step);
159
+ const snappedValue = snapToStep(newValue, minValue(), maxValue(), step());
150
160
 
151
161
  if (!isControlled()) {
152
162
  setInternalValue(snappedValue);
@@ -158,7 +168,7 @@ export function createSliderState(
158
168
  // Set value by percent
159
169
  const setValuePercent = (percent: number) => {
160
170
  const clampedPercent = clamp(percent, 0, 1);
161
- const newValue = clampedPercent * (maxValue - minValue) + minValue;
171
+ const newValue = clampedPercent * (maxValue() - minValue()) + minValue();
162
172
  setValue(newValue);
163
173
  };
164
174
 
@@ -175,13 +185,13 @@ export function createSliderState(
175
185
 
176
186
  // Increment/decrement
177
187
  const increment = (stepMultiplier = 1) => {
178
- if (isDisabled) return;
179
- setValue(value() + step * stepMultiplier);
188
+ if (isDisabled()) return;
189
+ setValue(value() + step() * stepMultiplier);
180
190
  };
181
191
 
182
192
  const decrement = (stepMultiplier = 1) => {
183
- if (isDisabled) return;
184
- setValue(value() - step * stepMultiplier);
193
+ if (isDisabled()) return;
194
+ setValue(value() - step() * stepMultiplier);
185
195
  };
186
196
 
187
197
  // Set focused state
@@ -201,11 +211,23 @@ export function createSliderState(
201
211
  setFocused,
202
212
  increment,
203
213
  decrement,
204
- minValue,
205
- maxValue,
206
- step,
207
- pageStep,
208
- orientation,
209
- isDisabled,
214
+ get minValue() {
215
+ return minValue();
216
+ },
217
+ get maxValue() {
218
+ return maxValue();
219
+ },
220
+ get step() {
221
+ return step();
222
+ },
223
+ get pageStep() {
224
+ return pageStep();
225
+ },
226
+ get orientation() {
227
+ return orientation();
228
+ },
229
+ get isDisabled() {
230
+ return isDisabled();
231
+ },
210
232
  };
211
233
  }
@@ -1,3 +1,3 @@
1
- export { createSliderState } from './createSliderState';
2
- export type { SliderState, SliderStateProps, SliderOrientation, } from './createSliderState';
3
- //# sourceMappingURL=index.d.ts.map
1
+ export { createSliderState } from "./createSliderState";
2
+ export type { SliderState, SliderStateProps, SliderOrientation } from "./createSliderState";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,2 @@
1
- export { createSliderState } from './createSliderState';
2
- export type {
3
- SliderState,
4
- SliderStateProps,
5
- SliderOrientation,
6
- } from './createSliderState';
1
+ export { createSliderState } from "./createSliderState";
2
+ export type { SliderState, SliderStateProps, SliderOrientation } from "./createSliderState";
@@ -25,4 +25,4 @@ export declare function createId(defaultId?: string): string;
25
25
  * This is useful for code that needs to run only in the browser.
26
26
  */
27
27
  export declare const canUseDOM: boolean;
28
- //# sourceMappingURL=index.d.ts.map
28
+ //# sourceMappingURL=index.d.ts.map
package/src/ssr/index.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  * These utilities provide a consistent API matching React-Stately's patterns.
6
6
  */
7
7
 
8
- import { createUniqueId } from 'solid-js';
9
- import { isServer as _isServer } from 'solid-js/web';
8
+ import { createUniqueId } from "solid-js";
9
+ import { isServer as _isServer } from "solid-js/web";
10
10
 
11
11
  /**
12
12
  * Re-export isServer from solid-js/web for convenience.
@@ -0,0 +1,191 @@
1
+ /**
2
+ * State management for step list components.
3
+ * Tracks selected step, completion status, and selectability.
4
+ */
5
+
6
+ import { createMemo, createSignal, type Accessor } from "solid-js";
7
+ import type { Key } from "../collections/types";
8
+
9
+ export interface StepListStateProps {
10
+ /** The currently selected step key (controlled). */
11
+ selectedKey?: Key;
12
+ /** The default selected step key (uncontrolled). */
13
+ defaultSelectedKey?: Key;
14
+ /** Called when the selected step changes. */
15
+ onSelectionChange?: (key: Key) => void;
16
+ /** The last completed step key (controlled). */
17
+ lastCompletedStep?: Key;
18
+ /** The default last completed step key (uncontrolled). */
19
+ defaultLastCompletedStep?: Key;
20
+ /** Called when last completed step changes. */
21
+ onLastCompletedStepChange?: (key: Key | null) => void;
22
+ /** Whether all steps are disabled. */
23
+ isDisabled?: boolean;
24
+ /** Whether all steps are read-only. */
25
+ isReadOnly?: boolean;
26
+ /** Keys of individually disabled steps. */
27
+ disabledKeys?: Iterable<Key>;
28
+ /** The step items. */
29
+ items: Array<{ key: Key; [key: string]: any }>;
30
+ }
31
+
32
+ export interface StepListState {
33
+ readonly selectedKey: Accessor<Key | null>;
34
+ readonly lastCompletedStep: Accessor<Key | null>;
35
+ readonly items: Accessor<Array<{ key: Key }>>;
36
+ setSelectedKey(key: Key): void;
37
+ setLastCompletedStep(key: Key): void;
38
+ isCompleted(key: Key): boolean;
39
+ isSelectable(key: Key): boolean;
40
+ isDisabled: Accessor<boolean>;
41
+ isReadOnly: Accessor<boolean>;
42
+ }
43
+
44
+ /**
45
+ * Creates state for a step list component.
46
+ */
47
+ export function createStepListState(props: StepListStateProps): StepListState {
48
+ const items = () => props.items;
49
+
50
+ // Build an index map: Key -> index
51
+ const indexMap = createMemo(() => {
52
+ const map = new Map<Key, number>();
53
+ const currentItems = items();
54
+ for (let i = 0; i < currentItems.length; i++) {
55
+ map.set(currentItems[i].key, i);
56
+ }
57
+ return map;
58
+ });
59
+
60
+ // Disabled keys set
61
+ const disabledKeysSet = createMemo(() => new Set<Key>(props.disabledKeys ?? []));
62
+
63
+ const isDisabled: Accessor<boolean> = () => props.isDisabled ?? false;
64
+ const isReadOnly: Accessor<boolean> = () => props.isReadOnly ?? false;
65
+
66
+ // Last completed step signal (uncontrolled)
67
+ const [lastCompletedStepInternal, setLastCompletedStepInternal] = createSignal<Key | null>(
68
+ props.defaultLastCompletedStep ?? null,
69
+ );
70
+
71
+ const lastCompletedStep: Accessor<Key | null> = () => {
72
+ if (props.lastCompletedStep !== undefined) {
73
+ return props.lastCompletedStep;
74
+ }
75
+ return lastCompletedStepInternal();
76
+ };
77
+
78
+ const setLastCompletedStep = (key: Key) => {
79
+ const currentIndex = indexMap().get(key);
80
+ const prevIndex = lastCompletedStep() !== null ? indexMap().get(lastCompletedStep()!) : -1;
81
+
82
+ // Only advance completion, never go back
83
+ if (
84
+ currentIndex !== undefined &&
85
+ (prevIndex === undefined || currentIndex > (prevIndex ?? -1))
86
+ ) {
87
+ if (props.lastCompletedStep === undefined) {
88
+ setLastCompletedStepInternal(key);
89
+ }
90
+ props.onLastCompletedStepChange?.(key);
91
+ }
92
+ };
93
+
94
+ const isCompleted = (key: Key): boolean => {
95
+ const completed = lastCompletedStep();
96
+ if (completed === null) return false;
97
+ const keyIndex = indexMap().get(key);
98
+ const completedIndex = indexMap().get(completed);
99
+ if (keyIndex === undefined || completedIndex === undefined) return false;
100
+ return keyIndex <= completedIndex;
101
+ };
102
+
103
+ const isStepDisabled = (key: Key): boolean => {
104
+ if (isDisabled()) return true;
105
+ return disabledKeysSet().has(key);
106
+ };
107
+
108
+ const isSelectable = (key: Key): boolean => {
109
+ if (isDisabled() || isReadOnly() || isStepDisabled(key)) return false;
110
+ // Completed steps are always selectable
111
+ if (isCompleted(key)) return true;
112
+ // First step is always selectable
113
+ const keyIndex = indexMap().get(key);
114
+ if (keyIndex === 0) return true;
115
+ // A step is selectable if the previous step is completed OR is the currently selected step
116
+ const currentItems = items();
117
+ if (keyIndex !== undefined && keyIndex > 0) {
118
+ const prevKey = currentItems[keyIndex - 1].key;
119
+ if (isCompleted(prevKey)) return true;
120
+ // Allow advancing to the step immediately after the selected step
121
+ if (prevKey === selectedKey()) return true;
122
+ }
123
+ return false;
124
+ };
125
+
126
+ // Find the first selectable non-completed step
127
+ const findDefaultSelectedKey = (): Key | null => {
128
+ const currentItems = items();
129
+ for (const item of currentItems) {
130
+ if (!isCompleted(item.key) && !isStepDisabled(item.key)) {
131
+ return item.key;
132
+ }
133
+ }
134
+ // All completed - select first non-disabled
135
+ for (const item of currentItems) {
136
+ if (!isStepDisabled(item.key)) {
137
+ return item.key;
138
+ }
139
+ }
140
+ return currentItems.length > 0 ? currentItems[0].key : null;
141
+ };
142
+
143
+ // Selected key signal (uncontrolled)
144
+ const [selectedKeyInternal, setSelectedKeyInternal] = createSignal<Key | null>(
145
+ props.defaultSelectedKey ?? findDefaultSelectedKey(),
146
+ );
147
+
148
+ const selectedKey: Accessor<Key | null> = () => {
149
+ if (props.selectedKey !== undefined) {
150
+ return props.selectedKey;
151
+ }
152
+ return selectedKeyInternal();
153
+ };
154
+
155
+ const setSelectedKey = (key: Key) => {
156
+ if (isReadOnly() || isDisabled()) return;
157
+ if (!isSelectable(key)) return;
158
+
159
+ // Mark previous selected step as completed if advancing
160
+ const currentSelected = selectedKey();
161
+ if (currentSelected !== null) {
162
+ const currentIndex = indexMap().get(currentSelected);
163
+ const newIndex = indexMap().get(key);
164
+ if (
165
+ currentIndex !== undefined &&
166
+ newIndex !== undefined &&
167
+ newIndex > currentIndex &&
168
+ !isCompleted(currentSelected)
169
+ ) {
170
+ setLastCompletedStep(currentSelected);
171
+ }
172
+ }
173
+
174
+ if (props.selectedKey === undefined) {
175
+ setSelectedKeyInternal(key);
176
+ }
177
+ props.onSelectionChange?.(key);
178
+ };
179
+
180
+ return {
181
+ selectedKey,
182
+ lastCompletedStep,
183
+ items,
184
+ setSelectedKey,
185
+ setLastCompletedStep,
186
+ isCompleted,
187
+ isSelectable,
188
+ isDisabled,
189
+ isReadOnly,
190
+ };
191
+ }
@@ -0,0 +1,5 @@
1
+ export {
2
+ createStepListState,
3
+ type StepListStateProps,
4
+ type StepListState,
5
+ } from "./createStepListState";
@@ -2,51 +2,53 @@
2
2
  * TableCollection - A collection class for table data.
3
3
  * Based on @react-stately/table/TableCollection.
4
4
  */
5
- import type { Key } from '../collections/types';
6
- import type { GridNode } from '../grid/types';
7
- import type { TableCollection as ITableCollection, TableCollectionOptions } from './types';
5
+ import type { Key } from "../collections/types";
6
+ import type { GridNode } from "../grid/types";
7
+ import type { TableCollection as ITableCollection, TableCollectionOptions } from "./types";
8
8
  /**
9
9
  * Creates a table collection from column and row definitions.
10
10
  */
11
11
  export declare class TableCollection<T = unknown> implements ITableCollection<T> {
12
- private _columns;
13
- private _rows;
14
- private _headerRows;
15
- private _body;
16
- private _head;
17
- private _keyMap;
18
- private _rowHeaderColumnKeys;
19
- private _size;
20
- constructor(options: TableCollectionOptions<T>);
21
- private buildColumns;
22
- private buildColumnNode;
23
- private getDefaultRowHeaderColumnKeys;
24
- private buildHeaderRows;
25
- private buildRows;
26
- private isRowDefinition;
27
- get size(): number;
28
- get rows(): GridNode<T>[];
29
- get columns(): GridNode<T>[];
30
- get headerRows(): GridNode<T>[];
31
- get head(): GridNode<T> | undefined;
32
- get body(): GridNode<T>;
33
- get rowCount(): number;
34
- get columnCount(): number;
35
- get rowHeaderColumnKeys(): Set<Key>;
36
- getKeys(): Iterable<Key>;
37
- getItem(key: Key): GridNode<T> | null;
38
- at(index: number): GridNode<T> | null;
39
- getChildren(key: Key): Iterable<GridNode<T>>;
40
- getTextValue(key: Key): string;
41
- getCell(rowKey: Key, columnKey: Key): GridNode<T> | null;
42
- getFirstKey(): Key | null;
43
- getLastKey(): Key | null;
44
- getKeyBefore(key: Key): Key | null;
45
- getKeyAfter(key: Key): Key | null;
46
- [Symbol.iterator](): Iterator<GridNode<T>>;
12
+ private _columns;
13
+ private _rows;
14
+ private _headerRows;
15
+ private _body;
16
+ private _head;
17
+ private _keyMap;
18
+ private _rowHeaderColumnKeys;
19
+ private _size;
20
+ constructor(options: TableCollectionOptions<T>);
21
+ private buildColumns;
22
+ private buildColumnNode;
23
+ private getDefaultRowHeaderColumnKeys;
24
+ private buildHeaderRows;
25
+ private buildRows;
26
+ private isRowDefinition;
27
+ get size(): number;
28
+ get rows(): GridNode<T>[];
29
+ get columns(): GridNode<T>[];
30
+ get headerRows(): GridNode<T>[];
31
+ get head(): GridNode<T> | undefined;
32
+ get body(): GridNode<T>;
33
+ get rowCount(): number;
34
+ get columnCount(): number;
35
+ get rowHeaderColumnKeys(): Set<Key>;
36
+ getKeys(): Iterable<Key>;
37
+ getItem(key: Key): GridNode<T> | null;
38
+ at(index: number): GridNode<T> | null;
39
+ getChildren(key: Key): Iterable<GridNode<T>>;
40
+ getTextValue(key: Key): string;
41
+ getCell(rowKey: Key, columnKey: Key): GridNode<T> | null;
42
+ getFirstKey(): Key | null;
43
+ getLastKey(): Key | null;
44
+ getKeyBefore(key: Key): Key | null;
45
+ getKeyAfter(key: Key): Key | null;
46
+ [Symbol.iterator](): Iterator<GridNode<T>>;
47
47
  }
48
48
  /**
49
49
  * Creates a table collection from options.
50
50
  */
51
- export declare function createTableCollection<T>(options: TableCollectionOptions<T>): TableCollection<T>;
52
- //# sourceMappingURL=TableCollection.d.ts.map
51
+ export declare function createTableCollection<T>(
52
+ options: TableCollectionOptions<T>,
53
+ ): TableCollection<T>;
54
+ //# sourceMappingURL=TableCollection.d.ts.map