@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.
Files changed (217) hide show
  1. package/{src → dist}/autocomplete/createAutocompleteState.d.ts +0 -1
  2. package/{src → dist}/autocomplete/index.d.ts +0 -1
  3. package/{src → dist}/calendar/createCalendarState.d.ts +0 -1
  4. package/{src → dist}/calendar/createDateFieldState.d.ts +0 -1
  5. package/{src → dist}/calendar/createRangeCalendarState.d.ts +0 -1
  6. package/{src → dist}/calendar/createTimeFieldState.d.ts +0 -1
  7. package/{src → dist}/calendar/index.d.ts +0 -1
  8. package/{src → dist}/checkbox/createCheckboxGroupState.d.ts +0 -1
  9. package/{src → dist}/checkbox/index.d.ts +0 -1
  10. package/{src → dist}/collections/ListCollection.d.ts +0 -1
  11. package/{src → dist}/collections/createListState.d.ts +0 -1
  12. package/{src → dist}/collections/createMenuState.d.ts +0 -1
  13. package/{src → dist}/collections/createSelectionState.d.ts +0 -1
  14. package/{src → dist}/collections/index.d.ts +0 -1
  15. package/{src → dist}/collections/types.d.ts +0 -1
  16. package/{src → dist}/color/Color.d.ts +0 -1
  17. package/{src → dist}/color/createColorAreaState.d.ts +0 -1
  18. package/{src → dist}/color/createColorFieldState.d.ts +0 -1
  19. package/{src → dist}/color/createColorSliderState.d.ts +0 -1
  20. package/{src → dist}/color/createColorWheelState.d.ts +0 -1
  21. package/{src → dist}/color/index.d.ts +0 -1
  22. package/{src → dist}/color/types.d.ts +0 -1
  23. package/{src → dist}/combobox/createComboBoxState.d.ts +0 -1
  24. package/{src → dist}/combobox/index.d.ts +0 -1
  25. package/{src → dist}/disclosure/createDisclosureState.d.ts +0 -1
  26. package/{src → dist}/disclosure/index.d.ts +0 -1
  27. package/{src → dist}/dnd/createDragState.d.ts +0 -1
  28. package/{src → dist}/dnd/createDraggableCollectionState.d.ts +0 -1
  29. package/{src → dist}/dnd/createDropState.d.ts +0 -1
  30. package/{src → dist}/dnd/createDroppableCollectionState.d.ts +0 -1
  31. package/{src → dist}/dnd/index.d.ts +0 -1
  32. package/{src → dist}/dnd/types.d.ts +0 -1
  33. package/{src → dist}/form/createFormValidationState.d.ts +0 -1
  34. package/{src → dist}/form/index.d.ts +0 -1
  35. package/{src → dist}/grid/createGridState.d.ts +0 -1
  36. package/{src → dist}/grid/index.d.ts +0 -1
  37. package/{src → dist}/grid/types.d.ts +0 -1
  38. package/dist/index.d.ts +25 -3363
  39. package/dist/index.js +2 -2
  40. package/dist/index.js.map +7 -1
  41. package/{src → dist}/numberfield/createNumberFieldState.d.ts +0 -1
  42. package/{src → dist}/numberfield/index.d.ts +0 -1
  43. package/{src → dist}/overlays/createOverlayTriggerState.d.ts +0 -1
  44. package/{src → dist}/overlays/index.d.ts +0 -1
  45. package/{src → dist}/radio/createRadioGroupState.d.ts +0 -1
  46. package/{src → dist}/radio/index.d.ts +0 -1
  47. package/{src → dist}/searchfield/createSearchFieldState.d.ts +0 -1
  48. package/{src → dist}/searchfield/index.d.ts +0 -1
  49. package/{src → dist}/select/createSelectState.d.ts +0 -1
  50. package/{src → dist}/select/index.d.ts +0 -1
  51. package/{src → dist}/slider/createSliderState.d.ts +0 -1
  52. package/{src → dist}/slider/index.d.ts +0 -1
  53. package/{src → dist}/ssr/index.d.ts +0 -1
  54. package/{src → dist}/table/TableCollection.d.ts +0 -1
  55. package/{src → dist}/table/createTableState.d.ts +0 -1
  56. package/{src → dist}/table/index.d.ts +0 -1
  57. package/{src → dist}/table/types.d.ts +0 -1
  58. package/{src → dist}/tabs/createTabListState.d.ts +0 -1
  59. package/{src → dist}/tabs/index.d.ts +0 -1
  60. package/{src → dist}/textfield/createTextFieldState.d.ts +0 -1
  61. package/{src → dist}/textfield/index.d.ts +0 -1
  62. package/{src → dist}/toast/createToastState.d.ts +0 -1
  63. package/{src → dist}/toast/index.d.ts +0 -1
  64. package/{src → dist}/toggle/createToggleState.d.ts +0 -1
  65. package/{src → dist}/toggle/index.d.ts +0 -1
  66. package/{src → dist}/tooltip/createTooltipTriggerState.d.ts +0 -1
  67. package/{src → dist}/tooltip/index.d.ts +0 -1
  68. package/{src → dist}/tree/TreeCollection.d.ts +0 -1
  69. package/{src → dist}/tree/createTreeState.d.ts +0 -1
  70. package/{src → dist}/tree/index.d.ts +0 -1
  71. package/{src → dist}/tree/types.d.ts +0 -1
  72. package/{src → dist}/utils/reactivity.d.ts +0 -1
  73. package/package.json +5 -7
  74. package/src/autocomplete/createAutocompleteState.d.ts.map +0 -1
  75. package/src/autocomplete/createAutocompleteState.ts +0 -90
  76. package/src/autocomplete/index.d.ts.map +0 -1
  77. package/src/autocomplete/index.ts +0 -5
  78. package/src/calendar/createCalendarState.d.ts.map +0 -1
  79. package/src/calendar/createCalendarState.ts +0 -461
  80. package/src/calendar/createDateFieldState.d.ts.map +0 -1
  81. package/src/calendar/createDateFieldState.ts +0 -562
  82. package/src/calendar/createRangeCalendarState.d.ts.map +0 -1
  83. package/src/calendar/createRangeCalendarState.ts +0 -535
  84. package/src/calendar/createTimeFieldState.d.ts.map +0 -1
  85. package/src/calendar/createTimeFieldState.ts +0 -483
  86. package/src/calendar/index.d.ts.map +0 -1
  87. package/src/calendar/index.ts +0 -81
  88. package/src/checkbox/createCheckboxGroupState.d.ts.map +0 -1
  89. package/src/checkbox/createCheckboxGroupState.ts +0 -193
  90. package/src/checkbox/index.d.ts.map +0 -1
  91. package/src/checkbox/index.ts +0 -5
  92. package/src/collections/ListCollection.d.ts.map +0 -1
  93. package/src/collections/ListCollection.ts +0 -146
  94. package/src/collections/createListState.d.ts.map +0 -1
  95. package/src/collections/createListState.ts +0 -264
  96. package/src/collections/createMenuState.d.ts.map +0 -1
  97. package/src/collections/createMenuState.ts +0 -106
  98. package/src/collections/createSelectionState.d.ts.map +0 -1
  99. package/src/collections/createSelectionState.ts +0 -336
  100. package/src/collections/index.d.ts.map +0 -1
  101. package/src/collections/index.ts +0 -46
  102. package/src/collections/types.d.ts.map +0 -1
  103. package/src/collections/types.ts +0 -169
  104. package/src/color/Color.d.ts.map +0 -1
  105. package/src/color/Color.ts +0 -951
  106. package/src/color/createColorAreaState.d.ts.map +0 -1
  107. package/src/color/createColorAreaState.ts +0 -293
  108. package/src/color/createColorFieldState.d.ts.map +0 -1
  109. package/src/color/createColorFieldState.ts +0 -292
  110. package/src/color/createColorSliderState.d.ts.map +0 -1
  111. package/src/color/createColorSliderState.ts +0 -241
  112. package/src/color/createColorWheelState.d.ts.map +0 -1
  113. package/src/color/createColorWheelState.ts +0 -211
  114. package/src/color/index.d.ts.map +0 -1
  115. package/src/color/index.ts +0 -47
  116. package/src/color/types.d.ts.map +0 -1
  117. package/src/color/types.ts +0 -127
  118. package/src/combobox/createComboBoxState.d.ts.map +0 -1
  119. package/src/combobox/createComboBoxState.ts +0 -703
  120. package/src/combobox/index.d.ts.map +0 -1
  121. package/src/combobox/index.ts +0 -13
  122. package/src/disclosure/createDisclosureState.d.ts.map +0 -1
  123. package/src/disclosure/createDisclosureState.ts +0 -193
  124. package/src/disclosure/index.d.ts.map +0 -1
  125. package/src/disclosure/index.ts +0 -9
  126. package/src/dnd/createDragState.d.ts.map +0 -1
  127. package/src/dnd/createDragState.ts +0 -153
  128. package/src/dnd/createDraggableCollectionState.d.ts.map +0 -1
  129. package/src/dnd/createDraggableCollectionState.ts +0 -165
  130. package/src/dnd/createDropState.d.ts.map +0 -1
  131. package/src/dnd/createDropState.ts +0 -212
  132. package/src/dnd/createDroppableCollectionState.d.ts.map +0 -1
  133. package/src/dnd/createDroppableCollectionState.ts +0 -357
  134. package/src/dnd/index.d.ts.map +0 -1
  135. package/src/dnd/index.ts +0 -76
  136. package/src/dnd/types.d.ts.map +0 -1
  137. package/src/dnd/types.ts +0 -317
  138. package/src/form/createFormValidationState.d.ts.map +0 -1
  139. package/src/form/createFormValidationState.ts +0 -389
  140. package/src/form/index.d.ts.map +0 -1
  141. package/src/form/index.ts +0 -15
  142. package/src/grid/createGridState.d.ts.map +0 -1
  143. package/src/grid/createGridState.ts +0 -327
  144. package/src/grid/index.d.ts.map +0 -1
  145. package/src/grid/index.ts +0 -13
  146. package/src/grid/types.d.ts.map +0 -1
  147. package/src/grid/types.ts +0 -179
  148. package/src/index.d.ts +0 -26
  149. package/src/index.d.ts.map +0 -1
  150. package/src/index.ts +0 -383
  151. package/src/numberfield/createNumberFieldState.d.ts.map +0 -1
  152. package/src/numberfield/createNumberFieldState.ts +0 -383
  153. package/src/numberfield/index.d.ts.map +0 -1
  154. package/src/numberfield/index.ts +0 -5
  155. package/src/overlays/createOverlayTriggerState.d.ts.map +0 -1
  156. package/src/overlays/createOverlayTriggerState.ts +0 -67
  157. package/src/overlays/index.d.ts.map +0 -1
  158. package/src/overlays/index.ts +0 -5
  159. package/src/radio/createRadioGroupState.d.ts.map +0 -1
  160. package/src/radio/createRadioGroupState.ts +0 -201
  161. package/src/radio/index.d.ts.map +0 -1
  162. package/src/radio/index.ts +0 -6
  163. package/src/searchfield/createSearchFieldState.d.ts.map +0 -1
  164. package/src/searchfield/createSearchFieldState.ts +0 -62
  165. package/src/searchfield/index.d.ts.map +0 -1
  166. package/src/searchfield/index.ts +0 -5
  167. package/src/select/createSelectState.d.ts.map +0 -1
  168. package/src/select/createSelectState.ts +0 -181
  169. package/src/select/index.d.ts.map +0 -1
  170. package/src/select/index.ts +0 -5
  171. package/src/slider/createSliderState.d.ts.map +0 -1
  172. package/src/slider/createSliderState.ts +0 -211
  173. package/src/slider/index.d.ts.map +0 -1
  174. package/src/slider/index.ts +0 -6
  175. package/src/ssr/index.d.ts.map +0 -1
  176. package/src/ssr/index.ts +0 -41
  177. package/src/table/TableCollection.d.ts.map +0 -1
  178. package/src/table/TableCollection.ts +0 -388
  179. package/src/table/createTableState.d.ts.map +0 -1
  180. package/src/table/createTableState.ts +0 -127
  181. package/src/table/index.d.ts.map +0 -1
  182. package/src/table/index.ts +0 -18
  183. package/src/table/types.d.ts.map +0 -1
  184. package/src/table/types.ts +0 -150
  185. package/src/tabs/createTabListState.d.ts.map +0 -1
  186. package/src/tabs/createTabListState.ts +0 -240
  187. package/src/tabs/index.d.ts.map +0 -1
  188. package/src/tabs/index.ts +0 -7
  189. package/src/textfield/createTextFieldState.d.ts.map +0 -1
  190. package/src/textfield/createTextFieldState.ts +0 -75
  191. package/src/textfield/index.d.ts.map +0 -1
  192. package/src/textfield/index.ts +0 -5
  193. package/src/toast/createToastState.d.ts.map +0 -1
  194. package/src/toast/createToastState.ts +0 -316
  195. package/src/toast/index.d.ts.map +0 -1
  196. package/src/toast/index.ts +0 -11
  197. package/src/toggle/createToggleState.d.ts.map +0 -1
  198. package/src/toggle/createToggleState.ts +0 -94
  199. package/src/toggle/index.d.ts.map +0 -1
  200. package/src/toggle/index.ts +0 -5
  201. package/src/tooltip/createTooltipTriggerState.d.ts.map +0 -1
  202. package/src/tooltip/createTooltipTriggerState.ts +0 -183
  203. package/src/tooltip/index.d.ts.map +0 -1
  204. package/src/tooltip/index.ts +0 -6
  205. package/src/tree/TreeCollection.d.ts.map +0 -1
  206. package/src/tree/TreeCollection.ts +0 -175
  207. package/src/tree/createTreeState.d.ts.map +0 -1
  208. package/src/tree/createTreeState.ts +0 -392
  209. package/src/tree/index.d.ts.map +0 -1
  210. package/src/tree/index.ts +0 -13
  211. package/src/tree/types.d.ts.map +0 -1
  212. package/src/tree/types.ts +0 -174
  213. package/src/utils/index.d.ts +0 -2
  214. package/src/utils/index.d.ts.map +0 -1
  215. package/src/utils/reactivity.d.ts.map +0 -1
  216. package/src/utils/reactivity.ts +0 -36
  217. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -1,193 +0,0 @@
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
- }
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
1
- export {
2
- createCheckboxGroupState,
3
- type CheckboxGroupProps,
4
- type CheckboxGroupState,
5
- } from './createCheckboxGroupState';
@@ -1 +0,0 @@
1
- {"version":3,"file":"ListCollection.d.ts","sourceRoot":"","sources":["ListCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,qBAAa,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,MAAM,CAA8B;gBAEhC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE;IAmBtC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEA,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAIhD,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC;IAMzB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;IAI3C,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;IAM3C,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAOlC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAOjC,WAAW,IAAI,GAAG,GAAG,IAAI;IAKzB,UAAU,IAAI,GAAG,GAAG,IAAI;IAKvB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAOnD,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM;IAI9B;;OAEG;IACH,OAAO,CAAC,WAAW;CAgBpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IACzC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;CAC/B,GACL,cAAc,CAAC,CAAC,CAAC,CAsBnB"}
@@ -1,146 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"createListState.d.ts","sourceRoot":"","sources":["createListState.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,GAAG,EACH,iBAAiB,EACjB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,qDAAqD;IACrD,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACZ,0CAA0C;IAC1C,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Aa,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,GAClD,qBAAqB,CAAC,CAAC,CAAC,CAmE1B"}
@@ -1,264 +0,0 @@
1
- /**
2
- * State management for list-like components.
3
- * Combines collection and selection state.
4
- * Based on @react-stately/list.
5
- */
6
-
7
- import { createSignal, type Accessor } from 'solid-js';
8
- import { access, type MaybeAccessor } from '../utils';
9
- import { ListCollection } from './ListCollection';
10
- import { createSelectionState, type SelectionState } from './createSelectionState';
11
- import type {
12
- Collection,
13
- CollectionNode,
14
- DisabledBehavior,
15
- FocusStrategy,
16
- Key,
17
- SelectionBehavior,
18
- SelectionMode,
19
- } from './types';
20
-
21
- export interface ListStateProps<T = unknown> {
22
- /** The items in the list (for dynamic rendering). */
23
- items?: T[];
24
- /** Function to get a key from an item. */
25
- getKey?: (item: T) => Key;
26
- /** Function to get text value from an item. */
27
- getTextValue?: (item: T) => string;
28
- /** Function to check if an item is disabled. */
29
- getDisabled?: (item: T) => boolean;
30
- /** Keys of disabled items. */
31
- disabledKeys?: Iterable<Key>;
32
- /** How disabled keys behave. */
33
- disabledBehavior?: DisabledBehavior;
34
- /** The selection mode. */
35
- selectionMode?: SelectionMode;
36
- /** How selection behaves on interaction. */
37
- selectionBehavior?: SelectionBehavior;
38
- /** Whether empty selection is disallowed. */
39
- disallowEmptySelection?: boolean;
40
- /** Currently selected keys (controlled). */
41
- selectedKeys?: 'all' | Iterable<Key>;
42
- /** Default selected keys (uncontrolled). */
43
- defaultSelectedKeys?: 'all' | Iterable<Key>;
44
- /** Handler for selection changes. */
45
- onSelectionChange?: (keys: 'all' | Set<Key>) => void;
46
- /** Whether to allow duplicate selection events. */
47
- allowDuplicateSelectionEvents?: boolean;
48
- }
49
-
50
- export interface ListState<T = unknown> extends SelectionState {
51
- /** The collection of items. */
52
- readonly collection: Accessor<Collection<T>>;
53
- /** Whether the collection is focused. */
54
- readonly isFocused: Accessor<boolean>;
55
- /** Set the focused state. */
56
- setFocused(isFocused: boolean): void;
57
- /** The currently focused key. */
58
- readonly focusedKey: Accessor<Key | null>;
59
- /** Set the focused key. */
60
- setFocusedKey(key: Key | null, childStrategy?: FocusStrategy): void;
61
- /** The child focus strategy. */
62
- readonly childFocusStrategy: Accessor<FocusStrategy | null>;
63
- }
64
-
65
- /**
66
- * Creates state for a list component with selection.
67
- */
68
- export function createListState<T = unknown>(
69
- props: MaybeAccessor<ListStateProps<T>>
70
- ): ListState<T> {
71
- const getProps = () => access(props);
72
-
73
- // Build collection from items
74
- const collection: Accessor<Collection<T>> = () => {
75
- const p = getProps();
76
- const items = p.items ?? [];
77
-
78
- const nodes: CollectionNode<T>[] = items.map((item, index) => {
79
- const key = p.getKey?.(item) ?? (item as any).key ?? (item as any).id ?? index;
80
- const textValue =
81
- p.getTextValue?.(item) ?? (item as any).textValue ?? (item as any).label ?? String(item);
82
- const isDisabled = p.getDisabled?.(item) ?? (item as any).isDisabled ?? false;
83
-
84
- return {
85
- type: 'item' as const,
86
- key,
87
- value: item,
88
- textValue,
89
- rendered: null as any,
90
- level: 0,
91
- index,
92
- parentKey: null,
93
- hasChildNodes: false,
94
- childNodes: [],
95
- isDisabled,
96
- };
97
- });
98
-
99
- return new ListCollection(nodes);
100
- };
101
-
102
- // Combine disabled keys from props and items
103
- const combinedDisabledKeys = (): Iterable<Key> => {
104
- const p = getProps();
105
- const propsDisabled = p.disabledKeys ? [...p.disabledKeys] : [];
106
- const itemDisabled: Key[] = [];
107
-
108
- const coll = collection();
109
- for (const node of coll) {
110
- if (node.isDisabled) {
111
- itemDisabled.push(node.key);
112
- }
113
- }
114
-
115
- return [...new Set([...propsDisabled, ...itemDisabled])];
116
- };
117
-
118
- // Create selection state
119
- const selectionState = createSelectionState({
120
- get selectionMode() {
121
- return getProps().selectionMode;
122
- },
123
- get selectionBehavior() {
124
- return getProps().selectionBehavior;
125
- },
126
- get disallowEmptySelection() {
127
- return getProps().disallowEmptySelection;
128
- },
129
- get selectedKeys() {
130
- return getProps().selectedKeys;
131
- },
132
- get defaultSelectedKeys() {
133
- return getProps().defaultSelectedKeys;
134
- },
135
- get onSelectionChange() {
136
- return getProps().onSelectionChange;
137
- },
138
- get disabledKeys() {
139
- return combinedDisabledKeys();
140
- },
141
- get disabledBehavior() {
142
- return getProps().disabledBehavior;
143
- },
144
- get allowDuplicateSelectionEvents() {
145
- return getProps().allowDuplicateSelectionEvents;
146
- },
147
- });
148
-
149
- // Focus state
150
- const [isFocused, setIsFocused] = createSignal(false);
151
- const [focusedKey, setFocusedKeyInternal] = createSignal<Key | null>(null);
152
- const [childFocusStrategy, setChildFocusStrategy] = createSignal<FocusStrategy | null>(null);
153
-
154
- const setFocusedKey = (key: Key | null, childStrategy?: FocusStrategy) => {
155
- setFocusedKeyInternal(key);
156
- setChildFocusStrategy(childStrategy ?? null);
157
- };
158
-
159
- return {
160
- collection,
161
- isFocused,
162
- setFocused: setIsFocused,
163
- focusedKey,
164
- setFocusedKey,
165
- childFocusStrategy,
166
- ...selectionState,
167
- };
168
- }
169
-
170
- /**
171
- * Props for single selection list state.
172
- */
173
- export interface SingleSelectListStateProps<T = unknown>
174
- extends Omit<ListStateProps<T>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'> {
175
- /** The currently selected key (controlled). */
176
- selectedKey?: Key | null;
177
- /** The default selected key (uncontrolled). */
178
- defaultSelectedKey?: Key;
179
- /** Handler for selection changes. */
180
- onSelectionChange?: (key: Key | null) => void;
181
- }
182
-
183
- export interface SingleSelectListState<T = unknown> extends ListState<T> {
184
- /** The currently selected key. */
185
- readonly selectedKey: Accessor<Key | null>;
186
- /** Set the selected key. */
187
- setSelectedKey(key: Key | null): void;
188
- /** The currently selected item. */
189
- readonly selectedItem: Accessor<CollectionNode<T> | null>;
190
- }
191
-
192
- /**
193
- * Creates state for a single-select list component.
194
- */
195
- export function createSingleSelectListState<T = unknown>(
196
- props: MaybeAccessor<SingleSelectListStateProps<T>>
197
- ): SingleSelectListState<T> {
198
- const getProps = () => access(props);
199
-
200
- // Convert single selection props to multiple selection props
201
- const listState = createListState<T>({
202
- get items() {
203
- return getProps().items;
204
- },
205
- get getKey() {
206
- return getProps().getKey;
207
- },
208
- get getTextValue() {
209
- return getProps().getTextValue;
210
- },
211
- get getDisabled() {
212
- return getProps().getDisabled;
213
- },
214
- get disabledKeys() {
215
- return getProps().disabledKeys;
216
- },
217
- get disabledBehavior() {
218
- return getProps().disabledBehavior;
219
- },
220
- selectionMode: 'single',
221
- disallowEmptySelection: true,
222
- allowDuplicateSelectionEvents: true,
223
- get selectedKeys() {
224
- const key = getProps().selectedKey;
225
- return key != null ? [key] : [];
226
- },
227
- get defaultSelectedKeys() {
228
- const key = getProps().defaultSelectedKey;
229
- return key != null ? [key] : undefined;
230
- },
231
- onSelectionChange(keys) {
232
- if (keys === 'all') return;
233
- const key = keys.values().next().value ?? null;
234
- getProps().onSelectionChange?.(key);
235
- },
236
- });
237
-
238
- const selectedKey: Accessor<Key | null> = () => {
239
- const keys = listState.selectedKeys();
240
- if (keys === 'all') return null;
241
- return keys.values().next().value ?? null;
242
- };
243
-
244
- const setSelectedKey = (key: Key | null) => {
245
- if (key === null) {
246
- listState.clearSelection();
247
- } else {
248
- listState.replaceSelection(key);
249
- }
250
- };
251
-
252
- const selectedItem: Accessor<CollectionNode<T> | null> = () => {
253
- const key = selectedKey();
254
- if (key === null) return null;
255
- return listState.collection().getItem(key);
256
- };
257
-
258
- return {
259
- ...listState,
260
- selectedKey,
261
- setSelectedKey,
262
- selectedItem,
263
- };
264
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMenuState.d.ts","sourceRoot":"","sources":["createMenuState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,M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