@proyecto-viviana/solid-stately 0.2.2 → 0.2.3
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/dist/index.js +43 -43
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/src/autocomplete/createAutocompleteState.d.ts +46 -0
- package/src/autocomplete/createAutocompleteState.d.ts.map +1 -0
- package/src/autocomplete/createAutocompleteState.ts +90 -0
- package/src/autocomplete/index.d.ts +2 -0
- package/src/autocomplete/index.d.ts.map +1 -0
- package/src/autocomplete/index.ts +5 -0
- package/src/calendar/createCalendarState.d.ts +130 -0
- package/src/calendar/createCalendarState.d.ts.map +1 -0
- package/src/calendar/createCalendarState.ts +461 -0
- package/src/calendar/createDateFieldState.d.ts +110 -0
- package/src/calendar/createDateFieldState.d.ts.map +1 -0
- package/src/calendar/createDateFieldState.ts +562 -0
- package/src/calendar/createRangeCalendarState.d.ts +146 -0
- package/src/calendar/createRangeCalendarState.d.ts.map +1 -0
- package/src/calendar/createRangeCalendarState.ts +535 -0
- package/src/calendar/createTimeFieldState.d.ts +95 -0
- package/src/calendar/createTimeFieldState.d.ts.map +1 -0
- package/src/calendar/createTimeFieldState.ts +483 -0
- package/src/calendar/index.d.ts +7 -0
- package/src/calendar/index.d.ts.map +1 -0
- package/src/calendar/index.ts +81 -0
- package/src/checkbox/createCheckboxGroupState.d.ts +71 -0
- package/src/checkbox/createCheckboxGroupState.d.ts.map +1 -0
- package/src/checkbox/createCheckboxGroupState.ts +193 -0
- package/src/checkbox/index.d.ts +2 -0
- package/src/checkbox/index.d.ts.map +1 -0
- package/src/checkbox/index.ts +5 -0
- package/src/collections/ListCollection.d.ts +37 -0
- package/src/collections/ListCollection.d.ts.map +1 -0
- package/src/collections/ListCollection.ts +146 -0
- package/src/collections/createListState.d.ts +79 -0
- package/src/collections/createListState.d.ts.map +1 -0
- package/src/collections/createListState.ts +264 -0
- package/src/collections/createMenuState.d.ts +50 -0
- package/src/collections/createMenuState.d.ts.map +1 -0
- package/src/collections/createMenuState.ts +106 -0
- package/src/collections/createSelectionState.d.ts +76 -0
- package/src/collections/createSelectionState.d.ts.map +1 -0
- package/src/collections/createSelectionState.ts +336 -0
- package/src/collections/index.d.ts +6 -0
- package/src/collections/index.d.ts.map +1 -0
- package/src/collections/index.ts +46 -0
- package/src/collections/types.d.ts +147 -0
- package/src/collections/types.d.ts.map +1 -0
- package/src/collections/types.ts +169 -0
- package/src/color/Color.d.ts +28 -0
- package/src/color/Color.d.ts.map +1 -0
- package/src/color/Color.ts +951 -0
- package/src/color/createColorAreaState.d.ts +76 -0
- package/src/color/createColorAreaState.d.ts.map +1 -0
- package/src/color/createColorAreaState.ts +293 -0
- package/src/color/createColorFieldState.d.ts +55 -0
- package/src/color/createColorFieldState.d.ts.map +1 -0
- package/src/color/createColorFieldState.ts +292 -0
- package/src/color/createColorSliderState.d.ts +67 -0
- package/src/color/createColorSliderState.d.ts.map +1 -0
- package/src/color/createColorSliderState.ts +241 -0
- package/src/color/createColorWheelState.d.ts +51 -0
- package/src/color/createColorWheelState.d.ts.map +1 -0
- package/src/color/createColorWheelState.ts +211 -0
- package/src/color/index.d.ts +10 -0
- package/src/color/index.d.ts.map +1 -0
- package/src/color/index.ts +47 -0
- package/src/color/types.d.ts +106 -0
- package/src/color/types.d.ts.map +1 -0
- package/src/color/types.ts +127 -0
- package/src/combobox/createComboBoxState.d.ts +125 -0
- package/src/combobox/createComboBoxState.d.ts.map +1 -0
- package/src/combobox/createComboBoxState.ts +703 -0
- package/src/combobox/index.d.ts +5 -0
- package/src/combobox/index.d.ts.map +1 -0
- package/src/combobox/index.ts +13 -0
- package/src/disclosure/createDisclosureState.d.ts +64 -0
- package/src/disclosure/createDisclosureState.d.ts.map +1 -0
- package/src/disclosure/createDisclosureState.ts +193 -0
- package/src/disclosure/index.d.ts +2 -0
- package/src/disclosure/index.d.ts.map +1 -0
- package/src/disclosure/index.ts +9 -0
- package/src/dnd/createDragState.d.ts +59 -0
- package/src/dnd/createDragState.d.ts.map +1 -0
- package/src/dnd/createDragState.ts +153 -0
- package/src/dnd/createDraggableCollectionState.d.ts +57 -0
- package/src/dnd/createDraggableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDraggableCollectionState.ts +165 -0
- package/src/dnd/createDropState.d.ts +61 -0
- package/src/dnd/createDropState.d.ts.map +1 -0
- package/src/dnd/createDropState.ts +212 -0
- package/src/dnd/createDroppableCollectionState.d.ts +78 -0
- package/src/dnd/createDroppableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDroppableCollectionState.ts +357 -0
- package/src/dnd/index.d.ts +11 -0
- package/src/dnd/index.d.ts.map +1 -0
- package/src/dnd/index.ts +76 -0
- package/src/dnd/types.d.ts +264 -0
- package/src/dnd/types.d.ts.map +1 -0
- package/src/dnd/types.ts +317 -0
- package/src/form/createFormValidationState.d.ts +100 -0
- package/src/form/createFormValidationState.d.ts.map +1 -0
- package/src/form/createFormValidationState.ts +389 -0
- package/src/form/index.d.ts +2 -0
- package/src/form/index.d.ts.map +1 -0
- package/src/form/index.ts +15 -0
- package/src/grid/createGridState.d.ts +12 -0
- package/src/grid/createGridState.d.ts.map +1 -0
- package/src/grid/createGridState.ts +327 -0
- package/src/grid/index.d.ts +7 -0
- package/src/grid/index.d.ts.map +1 -0
- package/src/grid/index.ts +13 -0
- package/src/grid/types.d.ts +156 -0
- package/src/grid/types.d.ts.map +1 -0
- package/src/grid/types.ts +179 -0
- package/src/index.d.ts +26 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +383 -0
- package/src/numberfield/createNumberFieldState.d.ts +65 -0
- package/src/numberfield/createNumberFieldState.d.ts.map +1 -0
- package/src/numberfield/createNumberFieldState.ts +383 -0
- package/src/numberfield/index.d.ts +2 -0
- package/src/numberfield/index.d.ts.map +1 -0
- package/src/numberfield/index.ts +5 -0
- package/src/overlays/createOverlayTriggerState.d.ts +32 -0
- package/src/overlays/createOverlayTriggerState.d.ts.map +1 -0
- package/src/overlays/createOverlayTriggerState.ts +67 -0
- package/src/overlays/index.d.ts +2 -0
- package/src/overlays/index.d.ts.map +1 -0
- package/src/overlays/index.ts +5 -0
- package/src/radio/createRadioGroupState.d.ts +77 -0
- package/src/radio/createRadioGroupState.d.ts.map +1 -0
- package/src/radio/createRadioGroupState.ts +201 -0
- package/src/radio/index.d.ts +2 -0
- package/src/radio/index.d.ts.map +1 -0
- package/src/radio/index.ts +6 -0
- package/src/searchfield/createSearchFieldState.d.ts +25 -0
- package/src/searchfield/createSearchFieldState.d.ts.map +1 -0
- package/src/searchfield/createSearchFieldState.ts +62 -0
- package/src/searchfield/index.d.ts +3 -0
- package/src/searchfield/index.d.ts.map +1 -0
- package/src/searchfield/index.ts +5 -0
- package/src/select/createSelectState.d.ts +73 -0
- package/src/select/createSelectState.d.ts.map +1 -0
- package/src/select/createSelectState.ts +181 -0
- package/src/select/index.d.ts +2 -0
- package/src/select/index.d.ts.map +1 -0
- package/src/select/index.ts +5 -0
- package/src/slider/createSliderState.d.ts +72 -0
- package/src/slider/createSliderState.d.ts.map +1 -0
- package/src/slider/createSliderState.ts +211 -0
- package/src/slider/index.d.ts +3 -0
- package/src/slider/index.d.ts.map +1 -0
- package/src/slider/index.ts +6 -0
- package/src/ssr/index.d.ts +28 -0
- package/src/ssr/index.d.ts.map +1 -0
- package/src/ssr/index.ts +41 -0
- package/src/table/TableCollection.d.ts +52 -0
- package/src/table/TableCollection.d.ts.map +1 -0
- package/src/table/TableCollection.ts +388 -0
- package/src/table/createTableState.d.ts +12 -0
- package/src/table/createTableState.d.ts.map +1 -0
- package/src/table/createTableState.ts +127 -0
- package/src/table/index.d.ts +8 -0
- package/src/table/index.d.ts.map +1 -0
- package/src/table/index.ts +18 -0
- package/src/table/types.d.ts +139 -0
- package/src/table/types.d.ts.map +1 -0
- package/src/table/types.ts +150 -0
- package/src/tabs/createTabListState.d.ts +68 -0
- package/src/tabs/createTabListState.d.ts.map +1 -0
- package/src/tabs/createTabListState.ts +240 -0
- package/src/tabs/index.d.ts +2 -0
- package/src/tabs/index.d.ts.map +1 -0
- package/src/tabs/index.ts +7 -0
- package/src/textfield/createTextFieldState.d.ts +30 -0
- package/src/textfield/createTextFieldState.d.ts.map +1 -0
- package/src/textfield/createTextFieldState.ts +75 -0
- package/src/textfield/index.d.ts +2 -0
- package/src/textfield/index.d.ts.map +1 -0
- package/src/textfield/index.ts +5 -0
- package/src/toast/createToastState.d.ts +118 -0
- package/src/toast/createToastState.d.ts.map +1 -0
- package/src/toast/createToastState.ts +316 -0
- package/src/toast/index.d.ts +2 -0
- package/src/toast/index.d.ts.map +1 -0
- package/src/toast/index.ts +11 -0
- package/src/toggle/createToggleState.d.ts +34 -0
- package/src/toggle/createToggleState.d.ts.map +1 -0
- package/src/toggle/createToggleState.ts +94 -0
- package/src/toggle/index.d.ts +2 -0
- package/src/toggle/index.d.ts.map +1 -0
- package/src/toggle/index.ts +5 -0
- package/src/tooltip/createTooltipTriggerState.d.ts +39 -0
- package/src/tooltip/createTooltipTriggerState.d.ts.map +1 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -0
- package/src/tooltip/index.d.ts +2 -0
- package/src/tooltip/index.d.ts.map +1 -0
- package/src/tooltip/index.ts +6 -0
- package/src/tree/TreeCollection.d.ts +40 -0
- package/src/tree/TreeCollection.d.ts.map +1 -0
- package/src/tree/TreeCollection.ts +175 -0
- package/src/tree/createTreeState.d.ts +14 -0
- package/src/tree/createTreeState.d.ts.map +1 -0
- package/src/tree/createTreeState.ts +392 -0
- package/src/tree/index.d.ts +7 -0
- package/src/tree/index.d.ts.map +1 -0
- package/src/tree/index.ts +13 -0
- package/src/tree/types.d.ts +157 -0
- package/src/tree/types.d.ts.map +1 -0
- package/src/tree/types.ts +174 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/reactivity.d.ts +28 -0
- package/src/utils/reactivity.d.ts.map +1 -0
- package/src/utils/reactivity.ts +36 -0
- package/dist/index.jsx +0 -6408
- package/dist/index.jsx.map +0 -7
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkbox group state for Solid Stately
|
|
3
|
+
*
|
|
4
|
+
* Provides state management for a checkbox group component.
|
|
5
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
6
|
+
*
|
|
7
|
+
* This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createSignal, Accessor } from 'solid-js';
|
|
11
|
+
import { type MaybeAccessor, access } from '../utils';
|
|
12
|
+
|
|
13
|
+
// ============================================
|
|
14
|
+
// TYPES
|
|
15
|
+
// ============================================
|
|
16
|
+
|
|
17
|
+
export interface CheckboxGroupProps {
|
|
18
|
+
/** The current selected values (controlled). */
|
|
19
|
+
value?: string[];
|
|
20
|
+
/** The default selected values (uncontrolled). */
|
|
21
|
+
defaultValue?: string[];
|
|
22
|
+
/** Handler that is called when the value changes. */
|
|
23
|
+
onChange?: (value: string[]) => void;
|
|
24
|
+
/** Whether the checkbox group is disabled. */
|
|
25
|
+
isDisabled?: boolean;
|
|
26
|
+
/** Whether the checkbox group is read only. */
|
|
27
|
+
isReadOnly?: boolean;
|
|
28
|
+
/** Whether the checkbox group is required. */
|
|
29
|
+
isRequired?: boolean;
|
|
30
|
+
/** Whether the checkbox group is invalid. */
|
|
31
|
+
isInvalid?: boolean;
|
|
32
|
+
/** The name of the checkbox group, used when submitting an HTML form. */
|
|
33
|
+
name?: string;
|
|
34
|
+
/** The form to associate the checkbox group with. */
|
|
35
|
+
form?: string;
|
|
36
|
+
/** The label for the checkbox group. */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Handler that is called when the checkbox group receives focus. */
|
|
39
|
+
onFocus?: (e: FocusEvent) => void;
|
|
40
|
+
/** Handler that is called when the checkbox group loses focus. */
|
|
41
|
+
onBlur?: (e: FocusEvent) => void;
|
|
42
|
+
/** Handler that is called when the checkbox group's focus status changes. */
|
|
43
|
+
onFocusChange?: (isFocused: boolean) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CheckboxGroupState {
|
|
47
|
+
/** Current selected values. */
|
|
48
|
+
readonly value: Accessor<readonly string[]>;
|
|
49
|
+
/** Default selected values. */
|
|
50
|
+
readonly defaultValue: readonly string[];
|
|
51
|
+
/** Whether the checkbox group is disabled. */
|
|
52
|
+
readonly isDisabled: boolean;
|
|
53
|
+
/** Whether the checkbox group is read only. */
|
|
54
|
+
readonly isReadOnly: boolean;
|
|
55
|
+
/** Whether the checkbox group is invalid. */
|
|
56
|
+
readonly isInvalid: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the checkboxes in the group are required.
|
|
59
|
+
* This changes to false once at least one item is selected.
|
|
60
|
+
*/
|
|
61
|
+
readonly isRequired: Accessor<boolean>;
|
|
62
|
+
/** Returns whether the given value is selected. */
|
|
63
|
+
isSelected(value: string): boolean;
|
|
64
|
+
/** Sets the selected values. */
|
|
65
|
+
setValue(value: string[]): void;
|
|
66
|
+
/** Adds a value to the set of selected values. */
|
|
67
|
+
addValue(value: string): void;
|
|
68
|
+
/** Removes a value from the set of selected values. */
|
|
69
|
+
removeValue(value: string): void;
|
|
70
|
+
/** Toggles a value in the set of selected values. */
|
|
71
|
+
toggleValue(value: string): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================
|
|
75
|
+
// IMPLEMENTATION
|
|
76
|
+
// ============================================
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Provides state management for a checkbox group component.
|
|
80
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
81
|
+
*/
|
|
82
|
+
export function createCheckboxGroupState(
|
|
83
|
+
props: MaybeAccessor<CheckboxGroupProps> = {}
|
|
84
|
+
): CheckboxGroupState {
|
|
85
|
+
const getProps = () => access(props);
|
|
86
|
+
|
|
87
|
+
// Get initial values
|
|
88
|
+
const initialProps = getProps();
|
|
89
|
+
const initialValue = initialProps.value ?? initialProps.defaultValue ?? [];
|
|
90
|
+
|
|
91
|
+
// Create internal signal for uncontrolled mode
|
|
92
|
+
const [internalValue, setInternalValue] = createSignal<readonly string[]>(initialValue);
|
|
93
|
+
|
|
94
|
+
// Determine if controlled
|
|
95
|
+
const isControlled = () => getProps().value !== undefined;
|
|
96
|
+
|
|
97
|
+
// Get current value
|
|
98
|
+
const value: Accessor<readonly string[]> = () => {
|
|
99
|
+
const p = getProps();
|
|
100
|
+
return isControlled() ? (p.value ?? []) : internalValue();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Check if required (true if isRequired and no items selected)
|
|
104
|
+
const isRequired: Accessor<boolean> = () => {
|
|
105
|
+
const p = getProps();
|
|
106
|
+
return !!p.isRequired && value().length === 0;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Check if invalid
|
|
110
|
+
const isInvalid = () => {
|
|
111
|
+
return getProps().isInvalid ?? false;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Set value
|
|
115
|
+
function setValue(newValue: string[]): void {
|
|
116
|
+
const p = getProps();
|
|
117
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!isControlled()) {
|
|
122
|
+
setInternalValue(newValue);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
p.onChange?.(newValue);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Check if value is selected
|
|
129
|
+
function isSelected(checkValue: string): boolean {
|
|
130
|
+
return value().includes(checkValue);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Add value
|
|
134
|
+
function addValue(addVal: string): void {
|
|
135
|
+
const p = getProps();
|
|
136
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const current = value();
|
|
141
|
+
if (!current.includes(addVal)) {
|
|
142
|
+
setValue([...current, addVal]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Remove value
|
|
147
|
+
function removeValue(removeVal: string): void {
|
|
148
|
+
const p = getProps();
|
|
149
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const current = value();
|
|
154
|
+
if (current.includes(removeVal)) {
|
|
155
|
+
setValue(current.filter((v) => v !== removeVal));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Toggle value
|
|
160
|
+
function toggleValue(toggleVal: string): void {
|
|
161
|
+
const p = getProps();
|
|
162
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const current = value();
|
|
167
|
+
if (current.includes(toggleVal)) {
|
|
168
|
+
setValue(current.filter((v) => v !== toggleVal));
|
|
169
|
+
} else {
|
|
170
|
+
setValue([...current, toggleVal]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
value,
|
|
176
|
+
defaultValue: initialProps.defaultValue ?? initialValue,
|
|
177
|
+
get isDisabled() {
|
|
178
|
+
return getProps().isDisabled ?? false;
|
|
179
|
+
},
|
|
180
|
+
get isReadOnly() {
|
|
181
|
+
return getProps().isReadOnly ?? false;
|
|
182
|
+
},
|
|
183
|
+
get isInvalid() {
|
|
184
|
+
return isInvalid();
|
|
185
|
+
},
|
|
186
|
+
isRequired,
|
|
187
|
+
isSelected,
|
|
188
|
+
setValue,
|
|
189
|
+
addValue,
|
|
190
|
+
removeValue,
|
|
191
|
+
toggleValue,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple list collection implementation.
|
|
3
|
+
* Provides a Collection interface over an array of nodes.
|
|
4
|
+
*/
|
|
5
|
+
import type { Collection, CollectionNode, Key } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* A basic implementation of Collection for list-based components.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ListCollection<T = unknown> implements Collection<T> {
|
|
10
|
+
private nodes;
|
|
11
|
+
private keyMap;
|
|
12
|
+
constructor(nodes: CollectionNode<T>[]);
|
|
13
|
+
get size(): number;
|
|
14
|
+
[Symbol.iterator](): Iterator<CollectionNode<T>>;
|
|
15
|
+
getKeys(): Iterable<Key>;
|
|
16
|
+
getItem(key: Key): CollectionNode<T> | null;
|
|
17
|
+
at(index: number): CollectionNode<T> | null;
|
|
18
|
+
getKeyBefore(key: Key): Key | null;
|
|
19
|
+
getKeyAfter(key: Key): Key | null;
|
|
20
|
+
getFirstKey(): Key | null;
|
|
21
|
+
getLastKey(): Key | null;
|
|
22
|
+
getChildren(key: Key): Iterable<CollectionNode<T>>;
|
|
23
|
+
getTextValue(key: Key): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get all items (excluding sections, including items within sections).
|
|
26
|
+
*/
|
|
27
|
+
private getAllItems;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a collection from an array of items.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createListCollection<T>(items: T[], options?: {
|
|
33
|
+
getKey?: (item: T, index: number) => Key;
|
|
34
|
+
getTextValue?: (item: T) => string;
|
|
35
|
+
getDisabled?: (item: T) => boolean;
|
|
36
|
+
}): ListCollection<T>;
|
|
37
|
+
//# sourceMappingURL=ListCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListCollection.d.ts","sourceRoot":"","sources":["ListCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,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nC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;CAC/B,GACL,cAAc,CAAC,CAAC,CAAC,CAsBnB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple list collection implementation.
|
|
3
|
+
* Provides a Collection interface over an array of nodes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Collection, CollectionNode, Key } from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A basic implementation of Collection for list-based components.
|
|
10
|
+
*/
|
|
11
|
+
export class ListCollection<T = unknown> implements Collection<T> {
|
|
12
|
+
private nodes: CollectionNode<T>[];
|
|
13
|
+
private keyMap: Map<Key, CollectionNode<T>>;
|
|
14
|
+
|
|
15
|
+
constructor(nodes: CollectionNode<T>[]) {
|
|
16
|
+
this.nodes = nodes;
|
|
17
|
+
this.keyMap = new Map();
|
|
18
|
+
|
|
19
|
+
// Build key map for O(1) lookups
|
|
20
|
+
const addToMap = (node: CollectionNode<T>) => {
|
|
21
|
+
this.keyMap.set(node.key, node);
|
|
22
|
+
if (node.childNodes) {
|
|
23
|
+
for (const child of node.childNodes) {
|
|
24
|
+
addToMap(child);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
for (const node of nodes) {
|
|
30
|
+
addToMap(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get size(): number {
|
|
35
|
+
return this.keyMap.size;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
*[Symbol.iterator](): Iterator<CollectionNode<T>> {
|
|
39
|
+
yield* this.nodes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
*getKeys(): Iterable<Key> {
|
|
43
|
+
for (const node of this.keyMap.values()) {
|
|
44
|
+
yield node.key;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getItem(key: Key): CollectionNode<T> | null {
|
|
49
|
+
return this.keyMap.get(key) ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
at(index: number): CollectionNode<T> | null {
|
|
53
|
+
// Flatten all items for indexing
|
|
54
|
+
const items = this.getAllItems();
|
|
55
|
+
return items[index] ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getKeyBefore(key: Key): Key | null {
|
|
59
|
+
const items = this.getAllItems();
|
|
60
|
+
const index = items.findIndex((item) => item.key === key);
|
|
61
|
+
if (index <= 0) return null;
|
|
62
|
+
return items[index - 1].key;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getKeyAfter(key: Key): Key | null {
|
|
66
|
+
const items = this.getAllItems();
|
|
67
|
+
const index = items.findIndex((item) => item.key === key);
|
|
68
|
+
if (index < 0 || index >= items.length - 1) return null;
|
|
69
|
+
return items[index + 1].key;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getFirstKey(): Key | null {
|
|
73
|
+
const items = this.getAllItems();
|
|
74
|
+
return items[0]?.key ?? null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getLastKey(): Key | null {
|
|
78
|
+
const items = this.getAllItems();
|
|
79
|
+
return items[items.length - 1]?.key ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
*getChildren(key: Key): Iterable<CollectionNode<T>> {
|
|
83
|
+
const node = this.getItem(key);
|
|
84
|
+
if (node?.childNodes) {
|
|
85
|
+
yield* node.childNodes;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getTextValue(key: Key): string {
|
|
90
|
+
return this.getItem(key)?.textValue ?? '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get all items (excluding sections, including items within sections).
|
|
95
|
+
*/
|
|
96
|
+
private getAllItems(): CollectionNode<T>[] {
|
|
97
|
+
const items: CollectionNode<T>[] = [];
|
|
98
|
+
|
|
99
|
+
const addItems = (nodes: CollectionNode<T>[]) => {
|
|
100
|
+
for (const node of nodes) {
|
|
101
|
+
if (node.type === 'item') {
|
|
102
|
+
items.push(node);
|
|
103
|
+
} else if (node.type === 'section' && node.childNodes) {
|
|
104
|
+
addItems(node.childNodes);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
addItems(this.nodes);
|
|
110
|
+
return items;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create a collection from an array of items.
|
|
116
|
+
*/
|
|
117
|
+
export function createListCollection<T>(
|
|
118
|
+
items: T[],
|
|
119
|
+
options: {
|
|
120
|
+
getKey?: (item: T, index: number) => Key;
|
|
121
|
+
getTextValue?: (item: T) => string;
|
|
122
|
+
getDisabled?: (item: T) => boolean;
|
|
123
|
+
} = {}
|
|
124
|
+
): ListCollection<T> {
|
|
125
|
+
const {
|
|
126
|
+
getKey = (item: T, index: number) => (item as any).key ?? (item as any).id ?? index,
|
|
127
|
+
getTextValue = (item: T) => (item as any).textValue ?? (item as any).label ?? String(item),
|
|
128
|
+
getDisabled = (item: T) => (item as any).isDisabled ?? false,
|
|
129
|
+
} = options;
|
|
130
|
+
|
|
131
|
+
const nodes: CollectionNode<T>[] = items.map((item, index) => ({
|
|
132
|
+
type: 'item' as const,
|
|
133
|
+
key: getKey(item, index),
|
|
134
|
+
value: item,
|
|
135
|
+
textValue: getTextValue(item),
|
|
136
|
+
rendered: null as any, // Will be set by component
|
|
137
|
+
level: 0,
|
|
138
|
+
index,
|
|
139
|
+
parentKey: null,
|
|
140
|
+
hasChildNodes: false,
|
|
141
|
+
childNodes: [],
|
|
142
|
+
isDisabled: getDisabled(item),
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
return new ListCollection(nodes);
|
|
146
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State management for list-like components.
|
|
3
|
+
* Combines collection and selection state.
|
|
4
|
+
* Based on @react-stately/list.
|
|
5
|
+
*/
|
|
6
|
+
import { type Accessor } from 'solid-js';
|
|
7
|
+
import { type MaybeAccessor } from '../utils';
|
|
8
|
+
import { type SelectionState } from './createSelectionState';
|
|
9
|
+
import type { Collection, CollectionNode, DisabledBehavior, FocusStrategy, Key, SelectionBehavior, SelectionMode } from './types';
|
|
10
|
+
export interface ListStateProps<T = unknown> {
|
|
11
|
+
/** The items in the list (for dynamic rendering). */
|
|
12
|
+
items?: T[];
|
|
13
|
+
/** Function to get a key from an item. */
|
|
14
|
+
getKey?: (item: T) => Key;
|
|
15
|
+
/** Function to get text value from an item. */
|
|
16
|
+
getTextValue?: (item: T) => string;
|
|
17
|
+
/** Function to check if an item is disabled. */
|
|
18
|
+
getDisabled?: (item: T) => boolean;
|
|
19
|
+
/** Keys of disabled items. */
|
|
20
|
+
disabledKeys?: Iterable<Key>;
|
|
21
|
+
/** How disabled keys behave. */
|
|
22
|
+
disabledBehavior?: DisabledBehavior;
|
|
23
|
+
/** The selection mode. */
|
|
24
|
+
selectionMode?: SelectionMode;
|
|
25
|
+
/** How selection behaves on interaction. */
|
|
26
|
+
selectionBehavior?: SelectionBehavior;
|
|
27
|
+
/** Whether empty selection is disallowed. */
|
|
28
|
+
disallowEmptySelection?: boolean;
|
|
29
|
+
/** Currently selected keys (controlled). */
|
|
30
|
+
selectedKeys?: 'all' | Iterable<Key>;
|
|
31
|
+
/** Default selected keys (uncontrolled). */
|
|
32
|
+
defaultSelectedKeys?: 'all' | Iterable<Key>;
|
|
33
|
+
/** Handler for selection changes. */
|
|
34
|
+
onSelectionChange?: (keys: 'all' | Set<Key>) => void;
|
|
35
|
+
/** Whether to allow duplicate selection events. */
|
|
36
|
+
allowDuplicateSelectionEvents?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ListState<T = unknown> extends SelectionState {
|
|
39
|
+
/** The collection of items. */
|
|
40
|
+
readonly collection: Accessor<Collection<T>>;
|
|
41
|
+
/** Whether the collection is focused. */
|
|
42
|
+
readonly isFocused: Accessor<boolean>;
|
|
43
|
+
/** Set the focused state. */
|
|
44
|
+
setFocused(isFocused: boolean): void;
|
|
45
|
+
/** The currently focused key. */
|
|
46
|
+
readonly focusedKey: Accessor<Key | null>;
|
|
47
|
+
/** Set the focused key. */
|
|
48
|
+
setFocusedKey(key: Key | null, childStrategy?: FocusStrategy): void;
|
|
49
|
+
/** The child focus strategy. */
|
|
50
|
+
readonly childFocusStrategy: Accessor<FocusStrategy | null>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates state for a list component with selection.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createListState<T = unknown>(props: MaybeAccessor<ListStateProps<T>>): ListState<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Props for single selection list state.
|
|
58
|
+
*/
|
|
59
|
+
export interface SingleSelectListStateProps<T = unknown> extends Omit<ListStateProps<T>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'> {
|
|
60
|
+
/** The currently selected key (controlled). */
|
|
61
|
+
selectedKey?: Key | null;
|
|
62
|
+
/** The default selected key (uncontrolled). */
|
|
63
|
+
defaultSelectedKey?: Key;
|
|
64
|
+
/** Handler for selection changes. */
|
|
65
|
+
onSelectionChange?: (key: Key | null) => void;
|
|
66
|
+
}
|
|
67
|
+
export interface SingleSelectListState<T = unknown> extends ListState<T> {
|
|
68
|
+
/** The currently selected key. */
|
|
69
|
+
readonly selectedKey: Accessor<Key | null>;
|
|
70
|
+
/** Set the selected key. */
|
|
71
|
+
setSelectedKey(key: Key | null): void;
|
|
72
|
+
/** The currently selected item. */
|
|
73
|
+
readonly selectedItem: Accessor<CollectionNode<T> | null>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates state for a single-select list component.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createSingleSelectListState<T = unknown>(props: MaybeAccessor<SingleSelectListStateProps<T>>): SingleSelectListState<T>;
|
|
79
|
+
//# sourceMapp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