@proyecto-viviana/solid-stately 0.1.5 → 0.2.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.
- package/{src → dist}/autocomplete/createAutocompleteState.d.ts +0 -1
- package/{src → dist}/autocomplete/index.d.ts +0 -1
- package/{src → dist}/calendar/createCalendarState.d.ts +0 -1
- package/{src → dist}/calendar/createDateFieldState.d.ts +0 -1
- package/{src → dist}/calendar/createRangeCalendarState.d.ts +0 -1
- package/{src → dist}/calendar/createTimeFieldState.d.ts +0 -1
- package/{src → dist}/calendar/index.d.ts +0 -1
- package/{src → dist}/checkbox/createCheckboxGroupState.d.ts +0 -1
- package/{src → dist}/checkbox/index.d.ts +0 -1
- package/{src → dist}/collections/ListCollection.d.ts +0 -1
- package/{src → dist}/collections/createListState.d.ts +0 -1
- package/{src → dist}/collections/createMenuState.d.ts +0 -1
- package/{src → dist}/collections/createSelectionState.d.ts +0 -1
- package/{src → dist}/collections/index.d.ts +0 -1
- package/{src → dist}/collections/types.d.ts +0 -1
- package/{src → dist}/color/Color.d.ts +0 -1
- package/{src → dist}/color/createColorAreaState.d.ts +0 -1
- package/{src → dist}/color/createColorFieldState.d.ts +0 -1
- package/{src → dist}/color/createColorSliderState.d.ts +0 -1
- package/{src → dist}/color/createColorWheelState.d.ts +0 -1
- package/{src → dist}/color/index.d.ts +0 -1
- package/{src → dist}/color/types.d.ts +0 -1
- package/{src → dist}/combobox/createComboBoxState.d.ts +0 -1
- package/{src → dist}/combobox/index.d.ts +0 -1
- package/{src → dist}/disclosure/createDisclosureState.d.ts +0 -1
- package/{src → dist}/disclosure/index.d.ts +0 -1
- package/{src → dist}/dnd/createDragState.d.ts +0 -1
- package/{src → dist}/dnd/createDraggableCollectionState.d.ts +0 -1
- package/{src → dist}/dnd/createDropState.d.ts +0 -1
- package/{src → dist}/dnd/createDroppableCollectionState.d.ts +0 -1
- package/{src → dist}/dnd/index.d.ts +0 -1
- package/{src → dist}/dnd/types.d.ts +0 -1
- package/{src → dist}/form/createFormValidationState.d.ts +0 -1
- package/{src → dist}/form/index.d.ts +0 -1
- package/{src → dist}/grid/createGridState.d.ts +0 -1
- package/{src → dist}/grid/index.d.ts +0 -1
- package/{src → dist}/grid/types.d.ts +0 -1
- package/dist/index.d.ts +25 -3363
- package/dist/index.js +2 -2
- package/dist/index.js.map +7 -1
- package/{src → dist}/numberfield/createNumberFieldState.d.ts +0 -1
- package/{src → dist}/numberfield/index.d.ts +0 -1
- package/{src → dist}/overlays/createOverlayTriggerState.d.ts +0 -1
- package/{src → dist}/overlays/index.d.ts +0 -1
- package/{src → dist}/radio/createRadioGroupState.d.ts +0 -1
- package/{src → dist}/radio/index.d.ts +0 -1
- package/{src → dist}/searchfield/createSearchFieldState.d.ts +0 -1
- package/{src → dist}/searchfield/index.d.ts +0 -1
- package/{src → dist}/select/createSelectState.d.ts +0 -1
- package/{src → dist}/select/index.d.ts +0 -1
- package/{src → dist}/slider/createSliderState.d.ts +0 -1
- package/{src → dist}/slider/index.d.ts +0 -1
- package/{src → dist}/ssr/index.d.ts +0 -1
- package/{src → dist}/table/TableCollection.d.ts +0 -1
- package/{src → dist}/table/createTableState.d.ts +0 -1
- package/{src → dist}/table/index.d.ts +0 -1
- package/{src → dist}/table/types.d.ts +0 -1
- package/{src → dist}/tabs/createTabListState.d.ts +0 -1
- package/{src → dist}/tabs/index.d.ts +0 -1
- package/{src → dist}/textfield/createTextFieldState.d.ts +0 -1
- package/{src → dist}/textfield/index.d.ts +0 -1
- package/{src → dist}/toast/createToastState.d.ts +0 -1
- package/{src → dist}/toast/index.d.ts +0 -1
- package/{src → dist}/toggle/createToggleState.d.ts +0 -1
- package/{src → dist}/toggle/index.d.ts +0 -1
- package/{src → dist}/tooltip/createTooltipTriggerState.d.ts +0 -1
- package/{src → dist}/tooltip/index.d.ts +0 -1
- package/{src → dist}/tree/TreeCollection.d.ts +0 -1
- package/{src → dist}/tree/createTreeState.d.ts +0 -1
- package/{src → dist}/tree/index.d.ts +0 -1
- package/{src → dist}/tree/types.d.ts +0 -1
- package/{src → dist}/utils/reactivity.d.ts +0 -1
- package/package.json +5 -7
- package/src/autocomplete/createAutocompleteState.d.ts.map +0 -1
- package/src/autocomplete/createAutocompleteState.ts +0 -90
- package/src/autocomplete/index.d.ts.map +0 -1
- package/src/autocomplete/index.ts +0 -5
- package/src/calendar/createCalendarState.d.ts.map +0 -1
- package/src/calendar/createCalendarState.ts +0 -461
- package/src/calendar/createDateFieldState.d.ts.map +0 -1
- package/src/calendar/createDateFieldState.ts +0 -562
- package/src/calendar/createRangeCalendarState.d.ts.map +0 -1
- package/src/calendar/createRangeCalendarState.ts +0 -535
- package/src/calendar/createTimeFieldState.d.ts.map +0 -1
- package/src/calendar/createTimeFieldState.ts +0 -483
- package/src/calendar/index.d.ts.map +0 -1
- package/src/calendar/index.ts +0 -81
- package/src/checkbox/createCheckboxGroupState.d.ts.map +0 -1
- package/src/checkbox/createCheckboxGroupState.ts +0 -193
- package/src/checkbox/index.d.ts.map +0 -1
- package/src/checkbox/index.ts +0 -5
- package/src/collections/ListCollection.d.ts.map +0 -1
- package/src/collections/ListCollection.ts +0 -146
- package/src/collections/createListState.d.ts.map +0 -1
- package/src/collections/createListState.ts +0 -264
- package/src/collections/createMenuState.d.ts.map +0 -1
- package/src/collections/createMenuState.ts +0 -106
- package/src/collections/createSelectionState.d.ts.map +0 -1
- package/src/collections/createSelectionState.ts +0 -336
- package/src/collections/index.d.ts.map +0 -1
- package/src/collections/index.ts +0 -46
- package/src/collections/types.d.ts.map +0 -1
- package/src/collections/types.ts +0 -169
- package/src/color/Color.d.ts.map +0 -1
- package/src/color/Color.ts +0 -951
- package/src/color/createColorAreaState.d.ts.map +0 -1
- package/src/color/createColorAreaState.ts +0 -293
- package/src/color/createColorFieldState.d.ts.map +0 -1
- package/src/color/createColorFieldState.ts +0 -292
- package/src/color/createColorSliderState.d.ts.map +0 -1
- package/src/color/createColorSliderState.ts +0 -241
- package/src/color/createColorWheelState.d.ts.map +0 -1
- package/src/color/createColorWheelState.ts +0 -211
- package/src/color/index.d.ts.map +0 -1
- package/src/color/index.ts +0 -47
- package/src/color/types.d.ts.map +0 -1
- package/src/color/types.ts +0 -127
- package/src/combobox/createComboBoxState.d.ts.map +0 -1
- package/src/combobox/createComboBoxState.ts +0 -703
- package/src/combobox/index.d.ts.map +0 -1
- package/src/combobox/index.ts +0 -13
- package/src/disclosure/createDisclosureState.d.ts.map +0 -1
- package/src/disclosure/createDisclosureState.ts +0 -193
- package/src/disclosure/index.d.ts.map +0 -1
- package/src/disclosure/index.ts +0 -9
- package/src/dnd/createDragState.d.ts.map +0 -1
- package/src/dnd/createDragState.ts +0 -153
- package/src/dnd/createDraggableCollectionState.d.ts.map +0 -1
- package/src/dnd/createDraggableCollectionState.ts +0 -165
- package/src/dnd/createDropState.d.ts.map +0 -1
- package/src/dnd/createDropState.ts +0 -212
- package/src/dnd/createDroppableCollectionState.d.ts.map +0 -1
- package/src/dnd/createDroppableCollectionState.ts +0 -357
- package/src/dnd/index.d.ts.map +0 -1
- package/src/dnd/index.ts +0 -76
- package/src/dnd/types.d.ts.map +0 -1
- package/src/dnd/types.ts +0 -317
- package/src/form/createFormValidationState.d.ts.map +0 -1
- package/src/form/createFormValidationState.ts +0 -389
- package/src/form/index.d.ts.map +0 -1
- package/src/form/index.ts +0 -15
- package/src/grid/createGridState.d.ts.map +0 -1
- package/src/grid/createGridState.ts +0 -327
- package/src/grid/index.d.ts.map +0 -1
- package/src/grid/index.ts +0 -13
- package/src/grid/types.d.ts.map +0 -1
- package/src/grid/types.ts +0 -179
- package/src/index.d.ts +0 -26
- package/src/index.d.ts.map +0 -1
- package/src/index.ts +0 -383
- package/src/numberfield/createNumberFieldState.d.ts.map +0 -1
- package/src/numberfield/createNumberFieldState.ts +0 -383
- package/src/numberfield/index.d.ts.map +0 -1
- package/src/numberfield/index.ts +0 -5
- package/src/overlays/createOverlayTriggerState.d.ts.map +0 -1
- package/src/overlays/createOverlayTriggerState.ts +0 -67
- package/src/overlays/index.d.ts.map +0 -1
- package/src/overlays/index.ts +0 -5
- package/src/radio/createRadioGroupState.d.ts.map +0 -1
- package/src/radio/createRadioGroupState.ts +0 -201
- package/src/radio/index.d.ts.map +0 -1
- package/src/radio/index.ts +0 -6
- package/src/searchfield/createSearchFieldState.d.ts.map +0 -1
- package/src/searchfield/createSearchFieldState.ts +0 -62
- package/src/searchfield/index.d.ts.map +0 -1
- package/src/searchfield/index.ts +0 -5
- package/src/select/createSelectState.d.ts.map +0 -1
- package/src/select/createSelectState.ts +0 -181
- package/src/select/index.d.ts.map +0 -1
- package/src/select/index.ts +0 -5
- package/src/slider/createSliderState.d.ts.map +0 -1
- package/src/slider/createSliderState.ts +0 -211
- package/src/slider/index.d.ts.map +0 -1
- package/src/slider/index.ts +0 -6
- package/src/ssr/index.d.ts.map +0 -1
- package/src/ssr/index.ts +0 -41
- package/src/table/TableCollection.d.ts.map +0 -1
- package/src/table/TableCollection.ts +0 -388
- package/src/table/createTableState.d.ts.map +0 -1
- package/src/table/createTableState.ts +0 -127
- package/src/table/index.d.ts.map +0 -1
- package/src/table/index.ts +0 -18
- package/src/table/types.d.ts.map +0 -1
- package/src/table/types.ts +0 -150
- package/src/tabs/createTabListState.d.ts.map +0 -1
- package/src/tabs/createTabListState.ts +0 -240
- package/src/tabs/index.d.ts.map +0 -1
- package/src/tabs/index.ts +0 -7
- package/src/textfield/createTextFieldState.d.ts.map +0 -1
- package/src/textfield/createTextFieldState.ts +0 -75
- package/src/textfield/index.d.ts.map +0 -1
- package/src/textfield/index.ts +0 -5
- package/src/toast/createToastState.d.ts.map +0 -1
- package/src/toast/createToastState.ts +0 -316
- package/src/toast/index.d.ts.map +0 -1
- package/src/toast/index.ts +0 -11
- package/src/toggle/createToggleState.d.ts.map +0 -1
- package/src/toggle/createToggleState.ts +0 -94
- package/src/toggle/index.d.ts.map +0 -1
- package/src/toggle/index.ts +0 -5
- package/src/tooltip/createTooltipTriggerState.d.ts.map +0 -1
- package/src/tooltip/createTooltipTriggerState.ts +0 -183
- package/src/tooltip/index.d.ts.map +0 -1
- package/src/tooltip/index.ts +0 -6
- package/src/tree/TreeCollection.d.ts.map +0 -1
- package/src/tree/TreeCollection.ts +0 -175
- package/src/tree/createTreeState.d.ts.map +0 -1
- package/src/tree/createTreeState.ts +0 -392
- package/src/tree/index.d.ts.map +0 -1
- package/src/tree/index.ts +0 -13
- package/src/tree/types.d.ts.map +0 -1
- package/src/tree/types.ts +0 -174
- package/src/utils/index.d.ts +0 -2
- package/src/utils/index.d.ts.map +0 -1
- package/src/utils/reactivity.d.ts.map +0 -1
- package/src/utils/reactivity.ts +0 -36
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -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
|
-
}
|
package/src/tree/index.d.ts.map
DELETED
|
@@ -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';
|
package/src/tree/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","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AAC;IACT,oCAAoC;IACpC,KAAK,EAAE,CAAC,CAAC;IACT,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,qCAAqC;IACrC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
package/src/tree/types.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tree collection types for Tree components.
|
|
3
|
-
* Based on @react-stately/tree.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Key, FocusStrategy } from '../collections/types';
|
|
7
|
-
import type { GridNode, GridCollection } from '../grid/types';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents a node in a tree collection.
|
|
11
|
-
* Extends GridNode with tree-specific properties.
|
|
12
|
-
*/
|
|
13
|
-
export interface TreeNode<T = unknown> extends GridNode<T> {
|
|
14
|
-
/** Whether this node has child nodes that can be expanded. */
|
|
15
|
-
hasChildNodes: boolean;
|
|
16
|
-
/** Child nodes of this tree item. */
|
|
17
|
-
childNodes: TreeNode<T>[];
|
|
18
|
-
/** The level of nesting (0 for root items). */
|
|
19
|
-
level: number;
|
|
20
|
-
/** The key of the parent node, if any. */
|
|
21
|
-
parentKey?: Key | null;
|
|
22
|
-
/** Whether this node is expandable. */
|
|
23
|
-
isExpandable?: boolean;
|
|
24
|
-
/** Whether this node is currently expanded (only meaningful if expandable). */
|
|
25
|
-
isExpanded?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A collection of tree nodes with tree-specific navigation.
|
|
30
|
-
* Only includes visible nodes (respects expanded state).
|
|
31
|
-
*/
|
|
32
|
-
export interface TreeCollection<T = unknown> extends Omit<GridCollection<T>, 'rows' | 'columns' | 'headerRows' | 'columnCount' | 'getCell'> {
|
|
33
|
-
/** All visible rows in the tree (respects expanded state). */
|
|
34
|
-
readonly rows: TreeNode<T>[];
|
|
35
|
-
/** Number of visible rows. */
|
|
36
|
-
readonly rowCount: number;
|
|
37
|
-
|
|
38
|
-
/** Get all keys in the collection (visible only). */
|
|
39
|
-
getKeys(): Iterable<Key>;
|
|
40
|
-
|
|
41
|
-
/** Get a node by its key (any node, visible or not). */
|
|
42
|
-
getItem(key: Key): TreeNode<T> | null;
|
|
43
|
-
|
|
44
|
-
/** Get a node by index (visible nodes only). */
|
|
45
|
-
at(index: number): TreeNode<T> | null;
|
|
46
|
-
|
|
47
|
-
/** Get the key before the given key (visible nodes only). */
|
|
48
|
-
getKeyBefore(key: Key): Key | null;
|
|
49
|
-
|
|
50
|
-
/** Get the key after the given key (visible nodes only). */
|
|
51
|
-
getKeyAfter(key: Key): Key | null;
|
|
52
|
-
|
|
53
|
-
/** Get the first key in the collection. */
|
|
54
|
-
getFirstKey(): Key | null;
|
|
55
|
-
|
|
56
|
-
/** Get the last key in the collection. */
|
|
57
|
-
getLastKey(): Key | null;
|
|
58
|
-
|
|
59
|
-
/** Get the children of a node. */
|
|
60
|
-
getChildren(key: Key): Iterable<TreeNode<T>>;
|
|
61
|
-
|
|
62
|
-
/** Get the text value for a key. */
|
|
63
|
-
getTextValue(key: Key): string;
|
|
64
|
-
|
|
65
|
-
/** Get the parent key for a node. */
|
|
66
|
-
getParentKey(key: Key): Key | null;
|
|
67
|
-
|
|
68
|
-
/** Iterator over visible nodes. */
|
|
69
|
-
[Symbol.iterator](): Iterator<TreeNode<T>>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* State for a tree component.
|
|
74
|
-
* Extends grid state with expansion management.
|
|
75
|
-
*/
|
|
76
|
-
export interface TreeState<T, C extends TreeCollection<T> = TreeCollection<T>> {
|
|
77
|
-
/** The tree collection (only visible nodes). */
|
|
78
|
-
readonly collection: C;
|
|
79
|
-
/** Keys of disabled items. */
|
|
80
|
-
readonly disabledKeys: Set<Key>;
|
|
81
|
-
/** Keys of expanded items. */
|
|
82
|
-
readonly expandedKeys: Set<Key>;
|
|
83
|
-
/** Whether keyboard navigation is disabled. */
|
|
84
|
-
readonly isKeyboardNavigationDisabled: boolean;
|
|
85
|
-
/** Currently focused key. */
|
|
86
|
-
readonly focusedKey: Key | null;
|
|
87
|
-
/** Focus strategy for child focus. */
|
|
88
|
-
readonly childFocusStrategy: FocusStrategy | null;
|
|
89
|
-
/** Whether the tree is focused. */
|
|
90
|
-
readonly isFocused: boolean;
|
|
91
|
-
/** The selection mode. */
|
|
92
|
-
readonly selectionMode: 'none' | 'single' | 'multiple';
|
|
93
|
-
/** The currently selected keys. */
|
|
94
|
-
readonly selectedKeys: 'all' | Set<Key>;
|
|
95
|
-
|
|
96
|
-
/** Check if a key is selected. */
|
|
97
|
-
isSelected(key: Key): boolean;
|
|
98
|
-
/** Check if a key is disabled. */
|
|
99
|
-
isDisabled(key: Key): boolean;
|
|
100
|
-
/** Check if a key is expanded. */
|
|
101
|
-
isExpanded(key: Key): boolean;
|
|
102
|
-
/** Set the focused key. */
|
|
103
|
-
setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void;
|
|
104
|
-
/** Set focused state. */
|
|
105
|
-
setFocused(isFocused: boolean): void;
|
|
106
|
-
/** Toggle selection for a key. */
|
|
107
|
-
toggleSelection(key: Key): void;
|
|
108
|
-
/** Replace selection with a key. */
|
|
109
|
-
replaceSelection(key: Key): void;
|
|
110
|
-
/** Extend selection to a key (shift-click). */
|
|
111
|
-
extendSelection(toKey: Key): void;
|
|
112
|
-
/** Select all visible items. */
|
|
113
|
-
selectAll(): void;
|
|
114
|
-
/** Clear selection. */
|
|
115
|
-
clearSelection(): void;
|
|
116
|
-
/** Toggle select all. */
|
|
117
|
-
toggleSelectAll(): void;
|
|
118
|
-
/** Toggle expansion for a key. */
|
|
119
|
-
toggleKey(key: Key): void;
|
|
120
|
-
/** Expand a key. */
|
|
121
|
-
expandKey(key: Key): void;
|
|
122
|
-
/** Collapse a key. */
|
|
123
|
-
collapseKey(key: Key): void;
|
|
124
|
-
/** Set the expanded keys. */
|
|
125
|
-
setExpandedKeys(keys: Set<Key>): void;
|
|
126
|
-
/** Set keyboard navigation disabled. */
|
|
127
|
-
setKeyboardNavigationDisabled(isDisabled: boolean): void;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Options for creating tree state.
|
|
132
|
-
*/
|
|
133
|
-
export interface TreeStateOptions<T, C extends TreeCollection<T> = TreeCollection<T>> {
|
|
134
|
-
/** The tree collection builder - receives expanded keys and returns collection. */
|
|
135
|
-
collectionFactory: (expandedKeys: Set<Key>) => C;
|
|
136
|
-
/** Keys of disabled items. */
|
|
137
|
-
disabledKeys?: Iterable<Key>;
|
|
138
|
-
/** Disabled behavior: 'selection' only or 'all' interactions. */
|
|
139
|
-
disabledBehavior?: 'selection' | 'all';
|
|
140
|
-
/** Selection mode. */
|
|
141
|
-
selectionMode?: 'none' | 'single' | 'multiple';
|
|
142
|
-
/** Selection behavior. */
|
|
143
|
-
selectionBehavior?: 'toggle' | 'replace';
|
|
144
|
-
/** Whether empty selection is disallowed. */
|
|
145
|
-
disallowEmptySelection?: boolean;
|
|
146
|
-
/** Currently selected keys (controlled). */
|
|
147
|
-
selectedKeys?: 'all' | Iterable<Key>;
|
|
148
|
-
/** Default selected keys (uncontrolled). */
|
|
149
|
-
defaultSelectedKeys?: 'all' | Iterable<Key>;
|
|
150
|
-
/** Handler for selection changes. */
|
|
151
|
-
onSelectionChange?: (keys: 'all' | Set<Key>) => void;
|
|
152
|
-
/** Currently expanded keys (controlled). */
|
|
153
|
-
expandedKeys?: Iterable<Key>;
|
|
154
|
-
/** Default expanded keys (uncontrolled). */
|
|
155
|
-
defaultExpandedKeys?: Iterable<Key>;
|
|
156
|
-
/** Handler for expansion changes. */
|
|
157
|
-
onExpandedChange?: (keys: Set<Key>) => void;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Item representation for building tree collections.
|
|
162
|
-
*/
|
|
163
|
-
export interface TreeItemData<T = unknown> {
|
|
164
|
-
/** Unique key for this item. */
|
|
165
|
-
key: Key;
|
|
166
|
-
/** The data value for this item. */
|
|
167
|
-
value: T;
|
|
168
|
-
/** Text content for accessibility and search. */
|
|
169
|
-
textValue?: string;
|
|
170
|
-
/** Child items (makes this item expandable). */
|
|
171
|
-
children?: TreeItemData<T>[];
|
|
172
|
-
/** Whether this item is disabled. */
|
|
173
|
-
isDisabled?: boolean;
|
|
174
|
-
}
|
package/src/utils/index.d.ts
DELETED
package/src/utils/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity.d.ts","sourceRoot":"","sources":["reactivity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAEpD;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAE3E"}
|
package/src/utils/reactivity.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reactivity utilities for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides type-safe utilities for working with SolidJS reactivity patterns.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Accessor } from 'solid-js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A value that may be either a raw value or an accessor function.
|
|
11
|
-
* This is a common pattern in SolidJS for props that may be reactive.
|
|
12
|
-
*/
|
|
13
|
-
export type MaybeAccessor<T> = T | Accessor<T>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Unwraps a MaybeAccessor to get the underlying value.
|
|
17
|
-
* If the input is a function, it calls it to get the value.
|
|
18
|
-
* Otherwise, it returns the value directly.
|
|
19
|
-
*
|
|
20
|
-
* @param value - The value or accessor to unwrap.
|
|
21
|
-
*/
|
|
22
|
-
export function access<T>(value: MaybeAccessor<T>): T {
|
|
23
|
-
return typeof value === 'function' ? (value as Accessor<T>)() : value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A value that may be undefined or an accessor that returns the value or undefined.
|
|
28
|
-
*/
|
|
29
|
-
export type MaybeAccessorValue<T> = T | undefined | Accessor<T | undefined>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Checks if a value is an accessor function.
|
|
33
|
-
*/
|
|
34
|
-
export function isAccessor<T>(value: MaybeAccessor<T>): value is Accessor<T> {
|
|
35
|
-
return typeof value === 'function';
|
|
36
|
-
}
|
|
File without changes
|