@proyecto-viviana/solid-stately 0.2.4 → 0.2.7
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/LICENSE +21 -0
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -1
- package/dist/checkbox/createCheckboxGroupState.d.ts +10 -1
- package/dist/collections/types.d.ts +11 -0
- package/dist/color/getColorChannels.d.ts +20 -0
- package/dist/data/createAsyncList.d.ts +111 -0
- package/dist/data/createListData.d.ts +65 -0
- package/dist/data/createTreeData.d.ts +61 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/datepicker/index.d.ts +10 -0
- package/dist/grid/types.d.ts +5 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3737 -2697
- package/dist/index.js.map +1 -7
- package/dist/menu/index.d.ts +8 -0
- package/dist/radio/createRadioGroupState.d.ts +10 -1
- package/dist/select/createSelectState.d.ts +17 -0
- package/dist/selection/index.d.ts +11 -0
- package/dist/toast/createToastState.d.ts +7 -1
- package/dist/toggle/createToggleGroupState.d.ts +45 -0
- package/dist/toggle/index.d.ts +1 -0
- package/dist/tree/TreeCollection.d.ts +3 -2
- package/package.json +6 -5
- package/src/autocomplete/createAutocompleteState.ts +10 -11
- package/src/calendar/createDateFieldState.ts +24 -1
- package/src/checkbox/createCheckboxGroupState.ts +42 -6
- package/src/collections/ListCollection.ts +152 -146
- package/src/collections/createListState.ts +266 -264
- package/src/collections/createMenuState.ts +106 -106
- package/src/collections/createSelectionState.ts +336 -336
- package/src/collections/index.ts +46 -46
- package/src/collections/types.ts +181 -169
- package/src/color/Color.ts +951 -951
- package/src/color/createColorAreaState.ts +293 -293
- package/src/color/createColorFieldState.ts +292 -292
- package/src/color/createColorSliderState.ts +241 -241
- package/src/color/createColorWheelState.ts +211 -211
- package/src/color/getColorChannels.ts +34 -0
- package/src/color/index.ts +47 -47
- package/src/color/types.ts +127 -127
- package/src/combobox/createComboBoxState.ts +703 -703
- package/src/combobox/index.ts +13 -13
- package/src/data/createAsyncList.ts +377 -0
- package/src/data/createListData.ts +298 -0
- package/src/data/createTreeData.ts +433 -0
- package/src/data/index.ts +25 -0
- package/src/datepicker/index.ts +36 -0
- package/src/disclosure/createDisclosureState.ts +4 -4
- package/src/dnd/createDragState.ts +153 -153
- package/src/dnd/createDraggableCollectionState.ts +165 -165
- package/src/dnd/createDropState.ts +212 -212
- package/src/dnd/createDroppableCollectionState.ts +357 -357
- package/src/dnd/index.ts +76 -76
- package/src/dnd/types.ts +317 -317
- package/src/form/createFormValidationState.ts +389 -389
- package/src/form/index.ts +15 -15
- package/src/grid/types.ts +5 -0
- package/src/index.ts +49 -0
- package/src/menu/index.ts +19 -0
- package/src/numberfield/createNumberFieldState.ts +427 -383
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/createOverlayTriggerState.ts +67 -67
- package/src/overlays/index.ts +5 -5
- package/src/radio/createRadioGroupState.ts +44 -6
- package/src/searchfield/createSearchFieldState.ts +62 -62
- package/src/searchfield/index.ts +5 -5
- package/src/select/createSelectState.ts +290 -181
- package/src/select/index.ts +5 -5
- package/src/selection/index.ts +28 -0
- package/src/slider/createSliderState.ts +211 -211
- package/src/slider/index.ts +6 -6
- package/src/tabs/createTabListState.ts +37 -11
- package/src/toast/createToastState.d.ts +6 -1
- package/src/toast/createToastState.ts +8 -1
- package/src/toggle/createToggleGroupState.ts +127 -0
- package/src/toggle/index.ts +6 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -183
- package/src/tooltip/index.ts +6 -6
- package/src/tree/TreeCollection.ts +208 -175
- package/src/tree/createTreeState.ts +392 -392
- package/src/tree/index.ts +13 -13
- package/src/tree/types.ts +174 -174
|
@@ -1,146 +1,152 @@
|
|
|
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) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A simple list collection implementation.
|
|
3
|
+
* Provides a Collection interface over an array of nodes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Collection, CollectionItemLike, 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) => {
|
|
127
|
+
const o = item as CollectionItemLike;
|
|
128
|
+
return o.key ?? o.id ?? index;
|
|
129
|
+
},
|
|
130
|
+
getTextValue = (item: T) => {
|
|
131
|
+
const o = item as CollectionItemLike;
|
|
132
|
+
return o.textValue ?? o.label ?? String(item);
|
|
133
|
+
},
|
|
134
|
+
getDisabled = (item: T) => (item as CollectionItemLike).isDisabled ?? false,
|
|
135
|
+
} = options;
|
|
136
|
+
|
|
137
|
+
const nodes: CollectionNode<T>[] = items.map((item, index) => ({
|
|
138
|
+
type: 'item' as const,
|
|
139
|
+
key: getKey(item, index),
|
|
140
|
+
value: item,
|
|
141
|
+
textValue: getTextValue(item),
|
|
142
|
+
rendered: null!, // Will be set by component
|
|
143
|
+
level: 0,
|
|
144
|
+
index,
|
|
145
|
+
parentKey: null,
|
|
146
|
+
hasChildNodes: false,
|
|
147
|
+
childNodes: [],
|
|
148
|
+
isDisabled: getDisabled(item),
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
return new ListCollection(nodes);
|
|
152
|
+
}
|