@proyecto-viviana/solid-stately 0.1.5 → 0.2.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 (217) hide show
  1. package/dist/index.js +226 -504
  2. package/dist/index.jsx +6407 -0
  3. package/package.json +3 -5
  4. package/dist/index.js.map +0 -1
  5. package/src/autocomplete/createAutocompleteState.d.ts +0 -46
  6. package/src/autocomplete/createAutocompleteState.d.ts.map +0 -1
  7. package/src/autocomplete/createAutocompleteState.ts +0 -90
  8. package/src/autocomplete/index.d.ts +0 -2
  9. package/src/autocomplete/index.d.ts.map +0 -1
  10. package/src/autocomplete/index.ts +0 -5
  11. package/src/calendar/createCalendarState.d.ts +0 -130
  12. package/src/calendar/createCalendarState.d.ts.map +0 -1
  13. package/src/calendar/createCalendarState.ts +0 -461
  14. package/src/calendar/createDateFieldState.d.ts +0 -110
  15. package/src/calendar/createDateFieldState.d.ts.map +0 -1
  16. package/src/calendar/createDateFieldState.ts +0 -562
  17. package/src/calendar/createRangeCalendarState.d.ts +0 -146
  18. package/src/calendar/createRangeCalendarState.d.ts.map +0 -1
  19. package/src/calendar/createRangeCalendarState.ts +0 -535
  20. package/src/calendar/createTimeFieldState.d.ts +0 -95
  21. package/src/calendar/createTimeFieldState.d.ts.map +0 -1
  22. package/src/calendar/createTimeFieldState.ts +0 -483
  23. package/src/calendar/index.d.ts +0 -7
  24. package/src/calendar/index.d.ts.map +0 -1
  25. package/src/calendar/index.ts +0 -81
  26. package/src/checkbox/createCheckboxGroupState.d.ts +0 -71
  27. package/src/checkbox/createCheckboxGroupState.d.ts.map +0 -1
  28. package/src/checkbox/createCheckboxGroupState.ts +0 -193
  29. package/src/checkbox/index.d.ts +0 -2
  30. package/src/checkbox/index.d.ts.map +0 -1
  31. package/src/checkbox/index.ts +0 -5
  32. package/src/collections/ListCollection.d.ts +0 -37
  33. package/src/collections/ListCollection.d.ts.map +0 -1
  34. package/src/collections/ListCollection.ts +0 -146
  35. package/src/collections/createListState.d.ts +0 -79
  36. package/src/collections/createListState.d.ts.map +0 -1
  37. package/src/collections/createListState.ts +0 -264
  38. package/src/collections/createMenuState.d.ts +0 -50
  39. package/src/collections/createMenuState.d.ts.map +0 -1
  40. package/src/collections/createMenuState.ts +0 -106
  41. package/src/collections/createSelectionState.d.ts +0 -76
  42. package/src/collections/createSelectionState.d.ts.map +0 -1
  43. package/src/collections/createSelectionState.ts +0 -336
  44. package/src/collections/index.d.ts +0 -6
  45. package/src/collections/index.d.ts.map +0 -1
  46. package/src/collections/index.ts +0 -46
  47. package/src/collections/types.d.ts +0 -147
  48. package/src/collections/types.d.ts.map +0 -1
  49. package/src/collections/types.ts +0 -169
  50. package/src/color/Color.d.ts +0 -28
  51. package/src/color/Color.d.ts.map +0 -1
  52. package/src/color/Color.ts +0 -951
  53. package/src/color/createColorAreaState.d.ts +0 -76
  54. package/src/color/createColorAreaState.d.ts.map +0 -1
  55. package/src/color/createColorAreaState.ts +0 -293
  56. package/src/color/createColorFieldState.d.ts +0 -55
  57. package/src/color/createColorFieldState.d.ts.map +0 -1
  58. package/src/color/createColorFieldState.ts +0 -292
  59. package/src/color/createColorSliderState.d.ts +0 -67
  60. package/src/color/createColorSliderState.d.ts.map +0 -1
  61. package/src/color/createColorSliderState.ts +0 -241
  62. package/src/color/createColorWheelState.d.ts +0 -51
  63. package/src/color/createColorWheelState.d.ts.map +0 -1
  64. package/src/color/createColorWheelState.ts +0 -211
  65. package/src/color/index.d.ts +0 -10
  66. package/src/color/index.d.ts.map +0 -1
  67. package/src/color/index.ts +0 -47
  68. package/src/color/types.d.ts +0 -106
  69. package/src/color/types.d.ts.map +0 -1
  70. package/src/color/types.ts +0 -127
  71. package/src/combobox/createComboBoxState.d.ts +0 -125
  72. package/src/combobox/createComboBoxState.d.ts.map +0 -1
  73. package/src/combobox/createComboBoxState.ts +0 -703
  74. package/src/combobox/index.d.ts +0 -5
  75. package/src/combobox/index.d.ts.map +0 -1
  76. package/src/combobox/index.ts +0 -13
  77. package/src/disclosure/createDisclosureState.d.ts +0 -64
  78. package/src/disclosure/createDisclosureState.d.ts.map +0 -1
  79. package/src/disclosure/createDisclosureState.ts +0 -193
  80. package/src/disclosure/index.d.ts +0 -2
  81. package/src/disclosure/index.d.ts.map +0 -1
  82. package/src/disclosure/index.ts +0 -9
  83. package/src/dnd/createDragState.d.ts +0 -59
  84. package/src/dnd/createDragState.d.ts.map +0 -1
  85. package/src/dnd/createDragState.ts +0 -153
  86. package/src/dnd/createDraggableCollectionState.d.ts +0 -57
  87. package/src/dnd/createDraggableCollectionState.d.ts.map +0 -1
  88. package/src/dnd/createDraggableCollectionState.ts +0 -165
  89. package/src/dnd/createDropState.d.ts +0 -61
  90. package/src/dnd/createDropState.d.ts.map +0 -1
  91. package/src/dnd/createDropState.ts +0 -212
  92. package/src/dnd/createDroppableCollectionState.d.ts +0 -78
  93. package/src/dnd/createDroppableCollectionState.d.ts.map +0 -1
  94. package/src/dnd/createDroppableCollectionState.ts +0 -357
  95. package/src/dnd/index.d.ts +0 -11
  96. package/src/dnd/index.d.ts.map +0 -1
  97. package/src/dnd/index.ts +0 -76
  98. package/src/dnd/types.d.ts +0 -264
  99. package/src/dnd/types.d.ts.map +0 -1
  100. package/src/dnd/types.ts +0 -317
  101. package/src/form/createFormValidationState.d.ts +0 -100
  102. package/src/form/createFormValidationState.d.ts.map +0 -1
  103. package/src/form/createFormValidationState.ts +0 -389
  104. package/src/form/index.d.ts +0 -2
  105. package/src/form/index.d.ts.map +0 -1
  106. package/src/form/index.ts +0 -15
  107. package/src/grid/createGridState.d.ts +0 -12
  108. package/src/grid/createGridState.d.ts.map +0 -1
  109. package/src/grid/createGridState.ts +0 -327
  110. package/src/grid/index.d.ts +0 -7
  111. package/src/grid/index.d.ts.map +0 -1
  112. package/src/grid/index.ts +0 -13
  113. package/src/grid/types.d.ts +0 -156
  114. package/src/grid/types.d.ts.map +0 -1
  115. package/src/grid/types.ts +0 -179
  116. package/src/index.d.ts +0 -26
  117. package/src/index.d.ts.map +0 -1
  118. package/src/index.ts +0 -383
  119. package/src/numberfield/createNumberFieldState.d.ts +0 -65
  120. package/src/numberfield/createNumberFieldState.d.ts.map +0 -1
  121. package/src/numberfield/createNumberFieldState.ts +0 -383
  122. package/src/numberfield/index.d.ts +0 -2
  123. package/src/numberfield/index.d.ts.map +0 -1
  124. package/src/numberfield/index.ts +0 -5
  125. package/src/overlays/createOverlayTriggerState.d.ts +0 -32
  126. package/src/overlays/createOverlayTriggerState.d.ts.map +0 -1
  127. package/src/overlays/createOverlayTriggerState.ts +0 -67
  128. package/src/overlays/index.d.ts +0 -2
  129. package/src/overlays/index.d.ts.map +0 -1
  130. package/src/overlays/index.ts +0 -5
  131. package/src/radio/createRadioGroupState.d.ts +0 -77
  132. package/src/radio/createRadioGroupState.d.ts.map +0 -1
  133. package/src/radio/createRadioGroupState.ts +0 -201
  134. package/src/radio/index.d.ts +0 -2
  135. package/src/radio/index.d.ts.map +0 -1
  136. package/src/radio/index.ts +0 -6
  137. package/src/searchfield/createSearchFieldState.d.ts +0 -25
  138. package/src/searchfield/createSearchFieldState.d.ts.map +0 -1
  139. package/src/searchfield/createSearchFieldState.ts +0 -62
  140. package/src/searchfield/index.d.ts +0 -3
  141. package/src/searchfield/index.d.ts.map +0 -1
  142. package/src/searchfield/index.ts +0 -5
  143. package/src/select/createSelectState.d.ts +0 -73
  144. package/src/select/createSelectState.d.ts.map +0 -1
  145. package/src/select/createSelectState.ts +0 -181
  146. package/src/select/index.d.ts +0 -2
  147. package/src/select/index.d.ts.map +0 -1
  148. package/src/select/index.ts +0 -5
  149. package/src/slider/createSliderState.d.ts +0 -72
  150. package/src/slider/createSliderState.d.ts.map +0 -1
  151. package/src/slider/createSliderState.ts +0 -211
  152. package/src/slider/index.d.ts +0 -3
  153. package/src/slider/index.d.ts.map +0 -1
  154. package/src/slider/index.ts +0 -6
  155. package/src/ssr/index.d.ts +0 -28
  156. package/src/ssr/index.d.ts.map +0 -1
  157. package/src/ssr/index.ts +0 -41
  158. package/src/table/TableCollection.d.ts +0 -52
  159. package/src/table/TableCollection.d.ts.map +0 -1
  160. package/src/table/TableCollection.ts +0 -388
  161. package/src/table/createTableState.d.ts +0 -12
  162. package/src/table/createTableState.d.ts.map +0 -1
  163. package/src/table/createTableState.ts +0 -127
  164. package/src/table/index.d.ts +0 -8
  165. package/src/table/index.d.ts.map +0 -1
  166. package/src/table/index.ts +0 -18
  167. package/src/table/types.d.ts +0 -139
  168. package/src/table/types.d.ts.map +0 -1
  169. package/src/table/types.ts +0 -150
  170. package/src/tabs/createTabListState.d.ts +0 -68
  171. package/src/tabs/createTabListState.d.ts.map +0 -1
  172. package/src/tabs/createTabListState.ts +0 -240
  173. package/src/tabs/index.d.ts +0 -2
  174. package/src/tabs/index.d.ts.map +0 -1
  175. package/src/tabs/index.ts +0 -7
  176. package/src/textfield/createTextFieldState.d.ts +0 -30
  177. package/src/textfield/createTextFieldState.d.ts.map +0 -1
  178. package/src/textfield/createTextFieldState.ts +0 -75
  179. package/src/textfield/index.d.ts +0 -2
  180. package/src/textfield/index.d.ts.map +0 -1
  181. package/src/textfield/index.ts +0 -5
  182. package/src/toast/createToastState.d.ts +0 -118
  183. package/src/toast/createToastState.d.ts.map +0 -1
  184. package/src/toast/createToastState.ts +0 -316
  185. package/src/toast/index.d.ts +0 -2
  186. package/src/toast/index.d.ts.map +0 -1
  187. package/src/toast/index.ts +0 -11
  188. package/src/toggle/createToggleState.d.ts +0 -34
  189. package/src/toggle/createToggleState.d.ts.map +0 -1
  190. package/src/toggle/createToggleState.ts +0 -94
  191. package/src/toggle/index.d.ts +0 -2
  192. package/src/toggle/index.d.ts.map +0 -1
  193. package/src/toggle/index.ts +0 -5
  194. package/src/tooltip/createTooltipTriggerState.d.ts +0 -39
  195. package/src/tooltip/createTooltipTriggerState.d.ts.map +0 -1
  196. package/src/tooltip/createTooltipTriggerState.ts +0 -183
  197. package/src/tooltip/index.d.ts +0 -2
  198. package/src/tooltip/index.d.ts.map +0 -1
  199. package/src/tooltip/index.ts +0 -6
  200. package/src/tree/TreeCollection.d.ts +0 -40
  201. package/src/tree/TreeCollection.d.ts.map +0 -1
  202. package/src/tree/TreeCollection.ts +0 -175
  203. package/src/tree/createTreeState.d.ts +0 -14
  204. package/src/tree/createTreeState.d.ts.map +0 -1
  205. package/src/tree/createTreeState.ts +0 -392
  206. package/src/tree/index.d.ts +0 -7
  207. package/src/tree/index.d.ts.map +0 -1
  208. package/src/tree/index.ts +0 -13
  209. package/src/tree/types.d.ts +0 -157
  210. package/src/tree/types.d.ts.map +0 -1
  211. package/src/tree/types.ts +0 -174
  212. package/src/utils/index.d.ts +0 -2
  213. package/src/utils/index.d.ts.map +0 -1
  214. package/src/utils/index.ts +0 -1
  215. package/src/utils/reactivity.d.ts +0 -28
  216. package/src/utils/reactivity.d.ts.map +0 -1
  217. package/src/utils/reactivity.ts +0 -36
@@ -1,392 +0,0 @@
1
- /**
2
- * Tree state management for Tree components.
3
- * Based on @react-stately/tree/useTreeState.
4
- *
5
- * Manages expansion state, selection, and focus for hierarchical tree data.
6
- */
7
-
8
- import { createSignal, createEffect, createMemo, on, type Accessor } from 'solid-js';
9
- import type {
10
- TreeState,
11
- TreeStateOptions,
12
- TreeCollection,
13
- TreeNode,
14
- } from './types';
15
- import type { Key, FocusStrategy } from '../collections/types';
16
-
17
- /**
18
- * Creates state management for a tree component.
19
- * Handles expansion, selection, focus management, and keyboard navigation state.
20
- */
21
- export function createTreeState<T extends object, C extends TreeCollection<T> = TreeCollection<T>>(
22
- options: Accessor<TreeStateOptions<T, C>>
23
- ): TreeState<T, C> {
24
- const getOptions = () => options();
25
-
26
- // Disabled keys as a Set
27
- const disabledKeys = createMemo(() => {
28
- const keys = getOptions().disabledKeys;
29
- return keys ? new Set(keys) : new Set<Key>();
30
- });
31
-
32
- // Expansion state (uncontrolled)
33
- const [internalExpandedKeys, setInternalExpandedKeys] = createSignal<Set<Key>>(
34
- getInitialExpandedKeys(getOptions().defaultExpandedKeys)
35
- );
36
-
37
- // Computed expanded keys (controlled or uncontrolled)
38
- const expandedKeys = createMemo(() => {
39
- const opts = getOptions();
40
- if (opts.expandedKeys !== undefined) {
41
- return new Set(opts.expandedKeys);
42
- }
43
- return internalExpandedKeys();
44
- });
45
-
46
- // Collection - rebuilt when expanded keys change
47
- const collection = createMemo(() => {
48
- const opts = getOptions();
49
- return opts.collectionFactory(expandedKeys());
50
- });
51
-
52
- // Focus state
53
- const [isFocused, setIsFocused] = createSignal(false);
54
- const [focusedKey, setFocusedKeyInternal] = createSignal<Key | null>(null);
55
- const [childFocusStrategy, setChildFocusStrategy] = createSignal<FocusStrategy | null>(null);
56
- const [isKeyboardNavigationDisabled, setKeyboardNavigationDisabled] = createSignal(false);
57
-
58
- // Selection state
59
- const [internalSelectedKeys, setInternalSelectedKeys] = createSignal<'all' | Set<Key>>(
60
- getInitialSelection(getOptions().defaultSelectedKeys)
61
- );
62
- const [anchorKey, setAnchorKey] = createSignal<Key | null>(null);
63
-
64
- // Computed selection
65
- const selectedKeys = createMemo(() => {
66
- const opts = getOptions();
67
- if (opts.selectedKeys !== undefined) {
68
- return normalizeSelection(opts.selectedKeys);
69
- }
70
- return internalSelectedKeys();
71
- });
72
-
73
- const selectionMode = createMemo(() => getOptions().selectionMode ?? 'none');
74
- const selectionBehavior = createMemo(() => getOptions().selectionBehavior ?? 'toggle');
75
- const disallowEmptySelection = createMemo(() => getOptions().disallowEmptySelection ?? false);
76
- const disabledBehavior = createMemo(() => getOptions().disabledBehavior ?? 'all');
77
-
78
- // Set focused key
79
- const setFocusedKey = (key: Key | null, strategy: FocusStrategy = 'first') => {
80
- setFocusedKeyInternal(key);
81
- setChildFocusStrategy(strategy);
82
- };
83
-
84
- // Reset focused key if the item is removed from visible collection
85
- let cachedCollection: C | null = null;
86
-
87
- createEffect(
88
- on(collection, (coll) => {
89
- const currentFocusedKey = focusedKey();
90
-
91
- if (currentFocusedKey != null && cachedCollection) {
92
- // Check if the focused item is still visible
93
- const visibleKeys = [...coll.getKeys()];
94
- if (!visibleKeys.includes(currentFocusedKey)) {
95
- // The focused item was collapsed or removed, find a new one to focus
96
- // Try to find the parent and focus it
97
- const node = cachedCollection.getItem(currentFocusedKey);
98
- if (node?.parentKey != null) {
99
- const parent = coll.getItem(node.parentKey);
100
- if (parent && visibleKeys.includes(parent.key)) {
101
- setFocusedKeyInternal(parent.key);
102
- cachedCollection = coll;
103
- return;
104
- }
105
- }
106
-
107
- // Otherwise, find the nearest visible sibling or previous item
108
- const rows = coll.rows;
109
- if (rows.length > 0) {
110
- // Find the closest item to where the focused item was
111
- const cachedNode = cachedCollection.getItem(currentFocusedKey);
112
- if (cachedNode?.rowIndex !== undefined) {
113
- const newIndex = Math.min(cachedNode.rowIndex, rows.length - 1);
114
- const newNode = rows[newIndex];
115
- if (newNode && !disabledKeys().has(newNode.key)) {
116
- setFocusedKeyInternal(newNode.key);
117
- cachedCollection = coll;
118
- return;
119
- }
120
- }
121
- // Fall back to first non-disabled item
122
- for (const row of rows) {
123
- if (!disabledKeys().has(row.key)) {
124
- setFocusedKeyInternal(row.key);
125
- break;
126
- }
127
- }
128
- } else {
129
- setFocusedKeyInternal(null);
130
- }
131
- }
132
- }
133
-
134
- cachedCollection = coll;
135
- })
136
- );
137
-
138
- // Selection methods
139
- const isSelected = (key: Key): boolean => {
140
- const keys = selectedKeys();
141
- if (keys === 'all') return true;
142
- return keys.has(key);
143
- };
144
-
145
- const isDisabled = (key: Key): boolean => {
146
- return disabledKeys().has(key);
147
- };
148
-
149
- const isExpanded = (key: Key): boolean => {
150
- return expandedKeys().has(key);
151
- };
152
-
153
- const updateSelection = (newSelection: 'all' | Set<Key>) => {
154
- const opts = getOptions();
155
-
156
- // Controlled mode
157
- if (opts.selectedKeys !== undefined) {
158
- opts.onSelectionChange?.(newSelection);
159
- return;
160
- }
161
-
162
- // Uncontrolled mode
163
- const current = internalSelectedKeys();
164
- const isDifferent =
165
- current === 'all' ||
166
- newSelection === 'all' ||
167
- current.size !== (newSelection as Set<Key>).size ||
168
- ![...current].every((k) => (newSelection as Set<Key>).has(k));
169
-
170
- if (isDifferent) {
171
- setInternalSelectedKeys(newSelection);
172
- opts.onSelectionChange?.(newSelection);
173
- }
174
- };
175
-
176
- const toggleSelection = (key: Key) => {
177
- if (isDisabled(key) && disabledBehavior() === 'all') return;
178
- if (selectionMode() === 'none') return;
179
-
180
- const current = selectedKeys();
181
-
182
- if (selectionMode() === 'single') {
183
- if (isSelected(key) && !disallowEmptySelection()) {
184
- updateSelection(new Set());
185
- } else {
186
- updateSelection(new Set([key]));
187
- }
188
- return;
189
- }
190
-
191
- // Multiple selection
192
- if (current === 'all') {
193
- // Can't toggle when all selected without knowing all keys
194
- return;
195
- }
196
-
197
- const newSelection = new Set(current);
198
- if (newSelection.has(key)) {
199
- if (newSelection.size > 1 || !disallowEmptySelection()) {
200
- newSelection.delete(key);
201
- }
202
- } else {
203
- newSelection.add(key);
204
- }
205
-
206
- updateSelection(newSelection);
207
- setAnchorKey(key);
208
- };
209
-
210
- const replaceSelection = (key: Key) => {
211
- if (isDisabled(key) && disabledBehavior() === 'all') return;
212
- if (selectionMode() === 'none') return;
213
-
214
- updateSelection(new Set([key]));
215
- setAnchorKey(key);
216
- };
217
-
218
- const extendSelection = (toKey: Key) => {
219
- if (isDisabled(toKey) && disabledBehavior() === 'all') return;
220
- if (selectionMode() !== 'multiple') {
221
- replaceSelection(toKey);
222
- return;
223
- }
224
-
225
- const anchor = anchorKey();
226
- if (!anchor) {
227
- replaceSelection(toKey);
228
- return;
229
- }
230
-
231
- const coll = collection();
232
- const rows = coll.rows.filter((r) => r.type === 'item');
233
- const keys = rows.map((r) => r.key);
234
- const anchorIndex = keys.indexOf(anchor);
235
- const toIndex = keys.indexOf(toKey);
236
-
237
- if (anchorIndex === -1 || toIndex === -1) {
238
- replaceSelection(toKey);
239
- return;
240
- }
241
-
242
- const start = Math.min(anchorIndex, toIndex);
243
- const end = Math.max(anchorIndex, toIndex);
244
- const rangeKeys = keys.slice(start, end + 1).filter((k) => !isDisabled(k));
245
-
246
- updateSelection(new Set(rangeKeys));
247
- };
248
-
249
- const selectAll = () => {
250
- if (selectionMode() !== 'multiple') return;
251
- updateSelection('all');
252
- };
253
-
254
- const clearSelection = () => {
255
- if (disallowEmptySelection()) return;
256
- updateSelection(new Set());
257
- };
258
-
259
- const toggleSelectAll = () => {
260
- if (selectionMode() !== 'multiple') return;
261
-
262
- if (selectedKeys() === 'all') {
263
- clearSelection();
264
- } else {
265
- selectAll();
266
- }
267
- };
268
-
269
- // Expansion methods
270
- const updateExpandedKeys = (newKeys: Set<Key>) => {
271
- const opts = getOptions();
272
-
273
- // Controlled mode
274
- if (opts.expandedKeys !== undefined) {
275
- opts.onExpandedChange?.(newKeys);
276
- return;
277
- }
278
-
279
- // Uncontrolled mode
280
- setInternalExpandedKeys(newKeys);
281
- opts.onExpandedChange?.(newKeys);
282
- };
283
-
284
- const toggleKey = (key: Key) => {
285
- const node = collection().getItem(key);
286
- if (!node || !node.isExpandable) return;
287
- if (isDisabled(key) && disabledBehavior() === 'all') return;
288
-
289
- const current = expandedKeys();
290
- const newKeys = new Set(current);
291
-
292
- if (newKeys.has(key)) {
293
- newKeys.delete(key);
294
- } else {
295
- newKeys.add(key);
296
- }
297
-
298
- updateExpandedKeys(newKeys);
299
- };
300
-
301
- const expandKey = (key: Key) => {
302
- const node = collection().getItem(key);
303
- if (!node || !node.isExpandable) return;
304
- if (isDisabled(key) && disabledBehavior() === 'all') return;
305
-
306
- const current = expandedKeys();
307
- if (current.has(key)) return;
308
-
309
- const newKeys = new Set(current);
310
- newKeys.add(key);
311
- updateExpandedKeys(newKeys);
312
- };
313
-
314
- const collapseKey = (key: Key) => {
315
- const node = collection().getItem(key);
316
- if (!node || !node.isExpandable) return;
317
- if (isDisabled(key) && disabledBehavior() === 'all') return;
318
-
319
- const current = expandedKeys();
320
- if (!current.has(key)) return;
321
-
322
- const newKeys = new Set(current);
323
- newKeys.delete(key);
324
- updateExpandedKeys(newKeys);
325
- };
326
-
327
- const setExpandedKeys = (keys: Set<Key>) => {
328
- updateExpandedKeys(keys);
329
- };
330
-
331
- return {
332
- get collection() {
333
- return collection();
334
- },
335
- get disabledKeys() {
336
- return disabledKeys();
337
- },
338
- get expandedKeys() {
339
- return expandedKeys();
340
- },
341
- get isKeyboardNavigationDisabled() {
342
- return isKeyboardNavigationDisabled();
343
- },
344
- get focusedKey() {
345
- return focusedKey();
346
- },
347
- get childFocusStrategy() {
348
- return childFocusStrategy();
349
- },
350
- get isFocused() {
351
- return isFocused();
352
- },
353
- get selectionMode() {
354
- return selectionMode();
355
- },
356
- get selectedKeys() {
357
- return selectedKeys();
358
- },
359
- isSelected,
360
- isDisabled,
361
- isExpanded,
362
- setFocusedKey,
363
- setFocused: setIsFocused,
364
- toggleSelection,
365
- replaceSelection,
366
- extendSelection,
367
- selectAll,
368
- clearSelection,
369
- toggleSelectAll,
370
- toggleKey,
371
- expandKey,
372
- collapseKey,
373
- setExpandedKeys,
374
- setKeyboardNavigationDisabled,
375
- };
376
- }
377
-
378
- // Helper functions
379
- function getInitialSelection(defaultKeys?: 'all' | Iterable<Key>): 'all' | Set<Key> {
380
- if (defaultKeys === undefined) return new Set();
381
- return normalizeSelection(defaultKeys);
382
- }
383
-
384
- function normalizeSelection(keys: 'all' | Iterable<Key>): 'all' | Set<Key> {
385
- if (keys === 'all') return 'all';
386
- return new Set(keys);
387
- }
388
-
389
- function getInitialExpandedKeys(defaultKeys?: Iterable<Key>): Set<Key> {
390
- if (defaultKeys === undefined) return new Set();
391
- return new Set(defaultKeys);
392
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Tree state management exports.
3
- */
4
- export { createTreeState } from './createTreeState';
5
- export { TreeCollection, createTreeCollection } from './TreeCollection';
6
- export type { TreeState, TreeStateOptions, TreeCollection as TreeCollectionInterface, TreeNode, TreeItemData, } from './types';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,cAAc,IAAI,uBAAuB,EACzC,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC"}
package/src/tree/index.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Tree state management exports.
3
- */
4
-
5
- export { createTreeState } from './createTreeState';
6
- export { TreeCollection, createTreeCollection } from './TreeCollection';
7
- export type {
8
- TreeState,
9
- TreeStateOptions,
10
- TreeCollection as TreeCollectionInterface,
11
- TreeNode,
12
- TreeItemData,
13
- } from './types';
@@ -1,157 +0,0 @@
1
- /**
2
- * Tree collection types for Tree components.
3
- * Based on @react-stately/tree.
4
- */
5
- import type { Key, FocusStrategy } from '../collections/types';
6
- import type { GridNode, GridCollection } from '../grid/types';
7
- /**
8
- * Represents a node in a tree collection.
9
- * Extends GridNode with tree-specific properties.
10
- */
11
- export interface TreeNode<T = unknown> extends GridNode<T> {
12
- /** Whether this node has child nodes that can be expanded. */
13
- hasChildNodes: boolean;
14
- /** Child nodes of this tree item. */
15
- childNodes: TreeNode<T>[];
16
- /** The level of nesting (0 for root items). */
17
- level: number;
18
- /** The key of the parent node, if any. */
19
- parentKey?: Key | null;
20
- /** Whether this node is expandable. */
21
- isExpandable?: boolean;
22
- /** Whether this node is currently expanded (only meaningful if expandable). */
23
- isExpanded?: boolean;
24
- }
25
- /**
26
- * A collection of tree nodes with tree-specific navigation.
27
- * Only includes visible nodes (respects expanded state).
28
- */
29
- export interface TreeCollection<T = unknown> extends Omit<GridCollection<T>, 'rows' | 'columns' | 'headerRows' | 'columnCount' | 'getCell'> {
30
- /** All visible rows in the tree (respects expanded state). */
31
- readonly rows: TreeNode<T>[];
32
- /** Number of visible rows. */
33
- readonly rowCount: number;
34
- /** Get all keys in the collection (visible only). */
35
- getKeys(): Iterable<Key>;
36
- /** Get a node by its key (any node, visible or not). */
37
- getItem(key: Key): TreeNode<T> | null;
38
- /** Get a node by index (visible nodes only). */
39
- at(index: number): TreeNode<T> | null;
40
- /** Get the key before the given key (visible nodes only). */
41
- getKeyBefore(key: Key): Key | null;
42
- /** Get the key after the given key (visible nodes only). */
43
- getKeyAfter(key: Key): Key | null;
44
- /** Get the first key in the collection. */
45
- getFirstKey(): Key | null;
46
- /** Get the last key in the collection. */
47
- getLastKey(): Key | null;
48
- /** Get the children of a node. */
49
- getChildren(key: Key): Iterable<TreeNode<T>>;
50
- /** Get the text value for a key. */
51
- getTextValue(key: Key): string;
52
- /** Get the parent key for a node. */
53
- getParentKey(key: Key): Key | null;
54
- /** Iterator over visible nodes. */
55
- [Symbol.iterator](): Iterator<TreeNode<T>>;
56
- }
57
- /**
58
- * State for a tree component.
59
- * Extends grid state with expansion management.
60
- */
61
- export interface TreeState<T, C extends TreeCollection<T> = TreeCollection<T>> {
62
- /** The tree collection (only visible nodes). */
63
- readonly collection: C;
64
- /** Keys of disabled items. */
65
- readonly disabledKeys: Set<Key>;
66
- /** Keys of expanded items. */
67
- readonly expandedKeys: Set<Key>;
68
- /** Whether keyboard navigation is disabled. */
69
- readonly isKeyboardNavigationDisabled: boolean;
70
- /** Currently focused key. */
71
- readonly focusedKey: Key | null;
72
- /** Focus strategy for child focus. */
73
- readonly childFocusStrategy: FocusStrategy | null;
74
- /** Whether the tree is focused. */
75
- readonly isFocused: boolean;
76
- /** The selection mode. */
77
- readonly selectionMode: 'none' | 'single' | 'multiple';
78
- /** The currently selected keys. */
79
- readonly selectedKeys: 'all' | Set<Key>;
80
- /** Check if a key is selected. */
81
- isSelected(key: Key): boolean;
82
- /** Check if a key is disabled. */
83
- isDisabled(key: Key): boolean;
84
- /** Check if a key is expanded. */
85
- isExpanded(key: Key): boolean;
86
- /** Set the focused key. */
87
- setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void;
88
- /** Set focused state. */
89
- setFocused(isFocused: boolean): void;
90
- /** Toggle selection for a key. */
91
- toggleSelection(key: Key): void;
92
- /** Replace selection with a key. */
93
- replaceSelection(key: Key): void;
94
- /** Extend selection to a key (shift-click). */
95
- extendSelection(toKey: Key): void;
96
- /** Select all visible items. */
97
- selectAll(): void;
98
- /** Clear selection. */
99
- clearSelection(): void;
100
- /** Toggle select all. */
101
- toggleSelectAll(): void;
102
- /** Toggle expansion for a key. */
103
- toggleKey(key: Key): void;
104
- /** Expand a key. */
105
- expandKey(key: Key): void;
106
- /** Collapse a key. */
107
- collapseKey(key: Key): void;
108
- /** Set the expanded keys. */
109
- setExpandedKeys(keys: Set<Key>): void;
110
- /** Set keyboard navigation disabled. */
111
- setKeyboardNavigationDisabled(isDisabled: boolean): void;
112
- }
113
- /**
114
- * Options for creating tree state.
115
- */
116
- export interface TreeStateOptions<T, C extends TreeCollection<T> = TreeCollection<T>> {
117
- /** The tree collection builder - receives expanded keys and returns collection. */
118
- collectionFactory: (expandedKeys: Set<Key>) => C;
119
- /** Keys of disabled items. */
120
- disabledKeys?: Iterable<Key>;
121
- /** Disabled behavior: 'selection' only or 'all' interactions. */
122
- disabledBehavior?: 'selection' | 'all';
123
- /** Selection mode. */
124
- selectionMode?: 'none' | 'single' | 'multiple';
125
- /** Selection behavior. */
126
- selectionBehavior?: 'toggle' | 'replace';
127
- /** Whether empty selection is disallowed. */
128
- disallowEmptySelection?: boolean;
129
- /** Currently selected keys (controlled). */
130
- selectedKeys?: 'all' | Iterable<Key>;
131
- /** Default selected keys (uncontrolled). */
132
- defaultSelectedKeys?: 'all' | Iterable<Key>;
133
- /** Handler for selection changes. */
134
- onSelectionChange?: (keys: 'all' | Set<Key>) => void;
135
- /** Currently expanded keys (controlled). */
136
- expandedKeys?: Iterable<Key>;
137
- /** Default expanded keys (uncontrolled). */
138
- defaultExpandedKeys?: Iterable<Key>;
139
- /** Handler for expansion changes. */
140
- onExpandedChange?: (keys: Set<Key>) => void;
141
- }
142
- /**
143
- * Item representation for building tree collections.
144
- */
145
- export interface TreeItemData<T = unknown> {
146
- /** Unique key for this item. */
147
- key: Key;
148
- /** The data value for this item. */
149
- value: T;
150
- /** Text content for accessibility and search. */
151
- textValue?: string;
152
- /** Child items (makes this item expandable). */
153
- children?: TreeItemData<T>[];
154
- /** Whether this item is disabled. */
155
- isDisabled?: boolean;
156
- }
157
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IACxD,8DAA8D;IAC9D,aAAa,EAAE,OAAO,CAAC;IACvB,qCAAqC;IACrC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1B,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,SAAS,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACvB,uCAAuC;IACvC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,CAAC;IACzI,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B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