@proyecto-viviana/solid-stately 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -283
  3. package/dist/autocomplete/createAutocompleteState.d.ts +3 -2
  4. package/dist/autocomplete/index.d.ts +1 -1
  5. package/dist/calendar/createCalendarState.d.ts +22 -7
  6. package/dist/calendar/createDateFieldState.d.ts +30 -7
  7. package/dist/calendar/createDatePickerState.d.ts +60 -0
  8. package/dist/calendar/createRangeCalendarState.d.ts +27 -8
  9. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  10. package/dist/calendar/index.d.ts +7 -6
  11. package/dist/checkbox/createCheckboxGroupState.d.ts +12 -3
  12. package/dist/checkbox/index.d.ts +1 -1
  13. package/dist/collections/ListCollection.d.ts +1 -1
  14. package/dist/collections/createListState.d.ts +8 -8
  15. package/dist/collections/createMenuState.d.ts +7 -7
  16. package/dist/collections/createSelectionState.d.ts +5 -5
  17. package/dist/collections/index.d.ts +5 -5
  18. package/dist/collections/types.d.ts +23 -12
  19. package/dist/color/Color.d.ts +1 -1
  20. package/dist/color/createColorAreaState.d.ts +4 -2
  21. package/dist/color/createColorFieldState.d.ts +38 -12
  22. package/dist/color/createColorSliderState.d.ts +9 -2
  23. package/dist/color/createColorWheelState.d.ts +13 -2
  24. package/dist/color/getColorChannels.d.ts +20 -0
  25. package/dist/color/index.d.ts +6 -6
  26. package/dist/color/types.d.ts +4 -4
  27. package/dist/combobox/createComboBoxState.d.ts +27 -13
  28. package/dist/combobox/index.d.ts +1 -1
  29. package/dist/data/createAsyncList.d.ts +111 -0
  30. package/dist/data/createListData.d.ts +65 -0
  31. package/dist/data/createTreeData.d.ts +65 -0
  32. package/dist/data/index.d.ts +3 -0
  33. package/dist/datepicker/index.d.ts +8 -0
  34. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  35. package/dist/disclosure/index.d.ts +1 -1
  36. package/dist/dnd/createDragState.d.ts +2 -2
  37. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  38. package/dist/dnd/createDropState.d.ts +2 -2
  39. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  40. package/dist/dnd/index.d.ts +5 -5
  41. package/dist/dnd/types.d.ts +16 -16
  42. package/dist/form/createFormValidationState.d.ts +3 -3
  43. package/dist/form/index.d.ts +1 -1
  44. package/dist/grid/createGridState.d.ts +2 -2
  45. package/dist/grid/index.d.ts +2 -2
  46. package/dist/grid/types.d.ts +17 -11
  47. package/dist/index.d.ts +31 -25
  48. package/dist/index.js +7990 -6264
  49. package/dist/index.js.map +1 -7
  50. package/dist/menu/index.d.ts +8 -0
  51. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  52. package/dist/numberfield/index.d.ts +1 -1
  53. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  54. package/dist/overlays/index.d.ts +1 -1
  55. package/dist/radio/createRadioGroupState.d.ts +13 -4
  56. package/dist/radio/index.d.ts +1 -1
  57. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  58. package/dist/searchfield/index.d.ts +2 -2
  59. package/dist/select/createSelectState.d.ts +20 -3
  60. package/dist/select/index.d.ts +1 -1
  61. package/dist/selection/index.d.ts +11 -0
  62. package/dist/slider/createSliderState.d.ts +3 -3
  63. package/dist/slider/index.d.ts +2 -2
  64. package/dist/steplist/createStepListState.d.ts +48 -0
  65. package/dist/steplist/index.d.ts +1 -0
  66. package/dist/table/TableCollection.d.ts +3 -3
  67. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  68. package/dist/table/createTableState.d.ts +2 -2
  69. package/dist/table/index.d.ts +5 -3
  70. package/dist/table/types.d.ts +10 -10
  71. package/dist/tabs/createTabListState.d.ts +5 -5
  72. package/dist/tabs/index.d.ts +1 -1
  73. package/dist/textfield/createTextFieldState.d.ts +2 -2
  74. package/dist/textfield/index.d.ts +1 -1
  75. package/dist/toast/createToastState.d.ts +15 -3
  76. package/dist/toast/index.d.ts +1 -1
  77. package/dist/toggle/createToggleGroupState.d.ts +45 -0
  78. package/dist/toggle/createToggleState.d.ts +2 -2
  79. package/dist/toggle/index.d.ts +2 -1
  80. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  81. package/dist/tooltip/index.d.ts +1 -1
  82. package/dist/tree/TreeCollection.d.ts +5 -4
  83. package/dist/tree/createTreeState.d.ts +2 -2
  84. package/dist/tree/index.d.ts +3 -3
  85. package/dist/tree/types.d.ts +19 -13
  86. package/dist/utils/index.d.ts +1 -1
  87. package/dist/utils/reactivity.d.ts +1 -1
  88. package/package.json +30 -30
  89. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  90. package/src/autocomplete/createAutocompleteState.ts +25 -32
  91. package/src/autocomplete/index.d.ts +6 -2
  92. package/src/autocomplete/index.ts +1 -1
  93. package/src/calendar/createCalendarState.d.ts +139 -117
  94. package/src/calendar/createCalendarState.ts +221 -74
  95. package/src/calendar/createDateFieldState.d.ts +130 -95
  96. package/src/calendar/createDateFieldState.ts +286 -151
  97. package/src/calendar/createDatePickerState.ts +347 -0
  98. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  99. package/src/calendar/createRangeCalendarState.ts +293 -79
  100. package/src/calendar/createTimeFieldState.d.ts +81 -79
  101. package/src/calendar/createTimeFieldState.ts +187 -108
  102. package/src/calendar/index.d.ts +80 -7
  103. package/src/calendar/index.ts +21 -12
  104. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  105. package/src/checkbox/createCheckboxGroupState.ts +57 -30
  106. package/src/checkbox/index.d.ts +6 -2
  107. package/src/checkbox/index.ts +1 -1
  108. package/src/collections/ListCollection.d.ts +25 -22
  109. package/src/collections/ListCollection.ts +152 -146
  110. package/src/collections/createListState.d.ts +73 -58
  111. package/src/collections/createListState.ts +267 -264
  112. package/src/collections/createMenuState.d.ts +36 -31
  113. package/src/collections/createMenuState.ts +112 -106
  114. package/src/collections/createSelectionState.d.ts +78 -65
  115. package/src/collections/createSelectionState.ts +340 -336
  116. package/src/collections/index.d.ts +38 -6
  117. package/src/collections/index.ts +41 -46
  118. package/src/collections/types.d.ts +101 -101
  119. package/src/collections/types.ts +181 -169
  120. package/src/color/Color.d.ts +20 -5
  121. package/src/color/Color.ts +1054 -951
  122. package/src/color/createColorAreaState.d.ts +67 -65
  123. package/src/color/createColorAreaState.ts +301 -293
  124. package/src/color/createColorFieldState.d.ts +46 -44
  125. package/src/color/createColorFieldState.ts +428 -292
  126. package/src/color/createColorSliderState.d.ts +58 -56
  127. package/src/color/createColorSliderState.ts +272 -241
  128. package/src/color/createColorWheelState.d.ts +42 -40
  129. package/src/color/createColorWheelState.ts +248 -211
  130. package/src/color/getColorChannels.ts +36 -0
  131. package/src/color/index.d.ts +36 -7
  132. package/src/color/index.ts +44 -47
  133. package/src/color/types.d.ts +68 -63
  134. package/src/color/types.ts +119 -127
  135. package/src/combobox/createComboBoxState.d.ts +107 -105
  136. package/src/combobox/createComboBoxState.ts +790 -703
  137. package/src/combobox/index.d.ts +10 -2
  138. package/src/combobox/index.ts +13 -13
  139. package/src/data/createAsyncList.ts +403 -0
  140. package/src/data/createListData.ts +298 -0
  141. package/src/data/createTreeData.ts +646 -0
  142. package/src/data/index.ts +25 -0
  143. package/src/datepicker/index.ts +32 -0
  144. package/src/disclosure/createDisclosureState.d.ts +47 -43
  145. package/src/disclosure/createDisclosureState.ts +9 -23
  146. package/src/disclosure/index.d.ts +10 -2
  147. package/src/disclosure/index.ts +1 -1
  148. package/src/dnd/createDragState.d.ts +51 -42
  149. package/src/dnd/createDragState.ts +151 -153
  150. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  151. package/src/dnd/createDraggableCollectionState.ts +158 -165
  152. package/src/dnd/createDropState.d.ts +64 -45
  153. package/src/dnd/createDropState.ts +202 -212
  154. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  155. package/src/dnd/createDroppableCollectionState.ts +354 -357
  156. package/src/dnd/index.d.ts +54 -6
  157. package/src/dnd/index.ts +63 -76
  158. package/src/dnd/types.d.ts +167 -156
  159. package/src/dnd/types.ts +316 -317
  160. package/src/form/createFormValidationState.d.ts +47 -45
  161. package/src/form/createFormValidationState.ts +356 -389
  162. package/src/form/index.d.ts +16 -2
  163. package/src/form/index.ts +15 -15
  164. package/src/grid/createGridState.d.ts +7 -4
  165. package/src/grid/createGridState.ts +44 -51
  166. package/src/grid/index.d.ts +3 -3
  167. package/src/grid/index.ts +2 -8
  168. package/src/grid/types.d.ts +136 -129
  169. package/src/grid/types.ts +24 -17
  170. package/src/index.d.ts +310 -26
  171. package/src/index.ts +87 -79
  172. package/src/menu/index.ts +17 -0
  173. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  174. package/src/numberfield/createNumberFieldState.ts +422 -383
  175. package/src/numberfield/index.d.ts +6 -2
  176. package/src/numberfield/index.ts +5 -5
  177. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  178. package/src/overlays/createOverlayTriggerState.ts +66 -67
  179. package/src/overlays/index.d.ts +6 -2
  180. package/src/overlays/index.ts +5 -5
  181. package/src/radio/createRadioGroupState.d.ts +54 -52
  182. package/src/radio/createRadioGroupState.ts +66 -30
  183. package/src/radio/index.d.ts +7 -2
  184. package/src/radio/index.ts +1 -1
  185. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  186. package/src/searchfield/createSearchFieldState.ts +56 -62
  187. package/src/searchfield/index.d.ts +3 -3
  188. package/src/searchfield/index.ts +2 -5
  189. package/src/select/createSelectState.d.ts +63 -61
  190. package/src/select/createSelectState.ts +290 -181
  191. package/src/select/index.d.ts +2 -2
  192. package/src/select/index.ts +1 -5
  193. package/src/selection/index.ts +27 -0
  194. package/src/slider/createSliderState.d.ts +60 -60
  195. package/src/slider/createSliderState.ts +233 -211
  196. package/src/slider/index.d.ts +3 -3
  197. package/src/slider/index.ts +2 -6
  198. package/src/ssr/index.d.ts +1 -1
  199. package/src/ssr/index.ts +2 -2
  200. package/src/steplist/createStepListState.ts +191 -0
  201. package/src/steplist/index.ts +5 -0
  202. package/src/table/TableCollection.d.ts +42 -40
  203. package/src/table/TableCollection.ts +61 -64
  204. package/src/table/createTableColumnResizeState.ts +242 -0
  205. package/src/table/createTableState.d.ts +7 -4
  206. package/src/table/createTableState.ts +10 -7
  207. package/src/table/index.d.ts +14 -4
  208. package/src/table/index.ts +10 -3
  209. package/src/table/types.d.ts +98 -92
  210. package/src/table/types.ts +17 -13
  211. package/src/tabs/createTabListState.d.ts +59 -57
  212. package/src/tabs/createTabListState.ts +58 -39
  213. package/src/tabs/index.d.ts +8 -2
  214. package/src/tabs/index.ts +1 -1
  215. package/src/textfield/createTextFieldState.d.ts +16 -14
  216. package/src/textfield/createTextFieldState.ts +7 -18
  217. package/src/textfield/index.d.ts +6 -2
  218. package/src/textfield/index.ts +1 -1
  219. package/src/toast/createToastState.d.ts +92 -81
  220. package/src/toast/createToastState.ts +56 -44
  221. package/src/toast/index.d.ts +12 -2
  222. package/src/toast/index.ts +1 -1
  223. package/src/toggle/createToggleGroupState.ts +117 -0
  224. package/src/toggle/createToggleState.d.ts +19 -19
  225. package/src/toggle/createToggleState.ts +2 -16
  226. package/src/toggle/index.d.ts +2 -2
  227. package/src/toggle/index.ts +6 -4
  228. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  229. package/src/tooltip/createTooltipTriggerState.ts +184 -183
  230. package/src/tooltip/index.d.ts +7 -2
  231. package/src/tooltip/index.ts +6 -6
  232. package/src/tree/TreeCollection.d.ts +26 -23
  233. package/src/tree/TreeCollection.ts +215 -175
  234. package/src/tree/createTreeState.d.ts +7 -4
  235. package/src/tree/createTreeState.ts +390 -392
  236. package/src/tree/index.d.ts +10 -4
  237. package/src/tree/index.ts +13 -13
  238. package/src/tree/types.d.ts +131 -126
  239. package/src/tree/types.ts +183 -174
  240. package/src/utils/index.d.ts +2 -2
  241. package/src/utils/index.ts +1 -1
  242. package/src/utils/reactivity.d.ts +2 -2
  243. package/src/utils/reactivity.ts +3 -3
@@ -0,0 +1,5 @@
1
+ export {
2
+ createStepListState,
3
+ type StepListStateProps,
4
+ type StepListState,
5
+ } from "./createStepListState";
@@ -2,51 +2,53 @@
2
2
  * TableCollection - A collection class for table data.
3
3
  * Based on @react-stately/table/TableCollection.
4
4
  */
5
- import type { Key } from '../collections/types';
6
- import type { GridNode } from '../grid/types';
7
- import type { TableCollection as ITableCollection, TableCollectionOptions } from './types';
5
+ import type { Key } from "../collections/types";
6
+ import type { GridNode } from "../grid/types";
7
+ import type { TableCollection as ITableCollection, TableCollectionOptions } from "./types";
8
8
  /**
9
9
  * Creates a table collection from column and row definitions.
10
10
  */
11
11
  export declare class TableCollection<T = unknown> implements ITableCollection<T> {
12
- private _columns;
13
- private _rows;
14
- private _headerRows;
15
- private _body;
16
- private _head;
17
- private _keyMap;
18
- private _rowHeaderColumnKeys;
19
- private _size;
20
- constructor(options: TableCollectionOptions<T>);
21
- private buildColumns;
22
- private buildColumnNode;
23
- private getDefaultRowHeaderColumnKeys;
24
- private buildHeaderRows;
25
- private buildRows;
26
- private isRowDefinition;
27
- get size(): number;
28
- get rows(): GridNode<T>[];
29
- get columns(): GridNode<T>[];
30
- get headerRows(): GridNode<T>[];
31
- get head(): GridNode<T> | undefined;
32
- get body(): GridNode<T>;
33
- get rowCount(): number;
34
- get columnCount(): number;
35
- get rowHeaderColumnKeys(): Set<Key>;
36
- getKeys(): Iterable<Key>;
37
- getItem(key: Key): GridNode<T> | null;
38
- at(index: number): GridNode<T> | null;
39
- getChildren(key: Key): Iterable<GridNode<T>>;
40
- getTextValue(key: Key): string;
41
- getCell(rowKey: Key, columnKey: Key): GridNode<T> | null;
42
- getFirstKey(): Key | null;
43
- getLastKey(): Key | null;
44
- getKeyBefore(key: Key): Key | null;
45
- getKeyAfter(key: Key): Key | null;
46
- [Symbol.iterator](): Iterator<GridNode<T>>;
12
+ private _columns;
13
+ private _rows;
14
+ private _headerRows;
15
+ private _body;
16
+ private _head;
17
+ private _keyMap;
18
+ private _rowHeaderColumnKeys;
19
+ private _size;
20
+ constructor(options: TableCollectionOptions<T>);
21
+ private buildColumns;
22
+ private buildColumnNode;
23
+ private getDefaultRowHeaderColumnKeys;
24
+ private buildHeaderRows;
25
+ private buildRows;
26
+ private isRowDefinition;
27
+ get size(): number;
28
+ get rows(): GridNode<T>[];
29
+ get columns(): GridNode<T>[];
30
+ get headerRows(): GridNode<T>[];
31
+ get head(): GridNode<T> | undefined;
32
+ get body(): GridNode<T>;
33
+ get rowCount(): number;
34
+ get columnCount(): number;
35
+ get rowHeaderColumnKeys(): Set<Key>;
36
+ getKeys(): Iterable<Key>;
37
+ getItem(key: Key): GridNode<T> | null;
38
+ at(index: number): GridNode<T> | null;
39
+ getChildren(key: Key): Iterable<GridNode<T>>;
40
+ getTextValue(key: Key): string;
41
+ getCell(rowKey: Key, columnKey: Key): GridNode<T> | null;
42
+ getFirstKey(): Key | null;
43
+ getLastKey(): Key | null;
44
+ getKeyBefore(key: Key): Key | null;
45
+ getKeyAfter(key: Key): Key | null;
46
+ [Symbol.iterator](): Iterator<GridNode<T>>;
47
47
  }
48
48
  /**
49
49
  * Creates a table collection from options.
50
50
  */
51
- export declare function createTableCollection<T>(options: TableCollectionOptions<T>): TableCollection<T>;
52
- //# sourceMappingURL=TableCollection.d.ts.map
51
+ export declare function createTableCollection<T>(
52
+ options: TableCollectionOptions<T>,
53
+ ): TableCollection<T>;
54
+ //# sourceMappingURL=TableCollection.d.ts.map
@@ -3,14 +3,14 @@
3
3
  * Based on @react-stately/table/TableCollection.
4
4
  */
5
5
 
6
- import type { Key } from '../collections/types';
7
- import type { GridNode, GridNodeType } from '../grid/types';
6
+ import type { Key } from "../collections/types";
7
+ import type { GridNode, GridNodeType } from "../grid/types";
8
8
  import type {
9
9
  TableCollection as ITableCollection,
10
10
  TableCollectionOptions,
11
11
  ColumnDefinition,
12
12
  RowDefinition,
13
- } from './types';
13
+ } from "./types";
14
14
 
15
15
  /**
16
16
  * Creates a table collection from column and row definitions.
@@ -35,77 +35,68 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
35
35
  rowHeaderColumnKeys,
36
36
  } = options;
37
37
 
38
- // Build columns
39
38
  this._columns = this.buildColumns(columns, showSelectionCheckboxes);
40
39
 
41
- // Determine row header column keys
42
40
  this._rowHeaderColumnKeys = rowHeaderColumnKeys ?? this.getDefaultRowHeaderColumnKeys();
43
41
 
44
- // Build header rows
45
42
  this._headerRows = this.buildHeaderRows();
46
43
 
47
- // Build head node
48
44
  if (this._headerRows.length > 0) {
49
45
  this._head = {
50
- type: 'headerrow' as GridNodeType,
51
- key: 'header',
46
+ type: "headerrow" as GridNodeType,
47
+ key: "header",
52
48
  index: 0,
53
49
  level: 0,
54
50
  hasChildNodes: true,
55
51
  childNodes: this._headerRows,
56
52
  value: null,
57
- textValue: '',
53
+ textValue: "",
58
54
  };
59
- this._keyMap.set('header', this._head);
55
+ this._keyMap.set("header", this._head);
60
56
  }
61
57
 
62
- // Build body rows
63
58
  const bodyRows = this.buildRows(rows, getKey, getTextValue);
64
59
  this._size = bodyRows.length;
65
60
 
66
- // Build body node
67
61
  this._body = {
68
- type: 'item' as GridNodeType,
69
- key: 'body',
62
+ type: "item" as GridNodeType,
63
+ key: "body",
70
64
  index: this._headerRows.length,
71
65
  level: 0,
72
66
  hasChildNodes: true,
73
67
  childNodes: bodyRows,
74
68
  value: null,
75
- textValue: '',
69
+ textValue: "",
76
70
  };
77
- this._keyMap.set('body', this._body);
71
+ this._keyMap.set("body", this._body);
78
72
 
79
- // Combine all rows
80
73
  this._rows = [...this._headerRows, ...bodyRows];
81
74
  }
82
75
 
83
76
  private buildColumns(
84
77
  columns: ColumnDefinition<T>[],
85
- showSelectionCheckboxes: boolean
78
+ showSelectionCheckboxes: boolean,
86
79
  ): GridNode<T>[] {
87
80
  const result: GridNode<T>[] = [];
88
81
  let colIndex = 0;
89
82
 
90
- // Add selection column if needed
91
83
  if (showSelectionCheckboxes) {
92
84
  const selectionColumn: GridNode<T> = {
93
- type: 'column' as GridNodeType,
94
- key: '__selection__',
85
+ type: "column" as GridNodeType,
86
+ key: "__selection__",
95
87
  index: colIndex,
96
88
  column: 0,
97
89
  level: 0,
98
90
  hasChildNodes: false,
99
91
  childNodes: [],
100
92
  value: null,
101
- textValue: 'Selection',
93
+ textValue: "Selection",
102
94
  };
103
95
  result.push(selectionColumn);
104
96
  this._keyMap.set(selectionColumn.key, selectionColumn);
105
97
  colIndex++;
106
98
  }
107
99
 
108
- // Build user columns
109
100
  for (const col of columns) {
110
101
  const node = this.buildColumnNode(col, colIndex);
111
102
  result.push(node);
@@ -116,24 +107,25 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
116
107
  }
117
108
 
118
109
  private buildColumnNode(col: ColumnDefinition<T>, index: number): GridNode<T> {
110
+ const key = col.key ?? (col as ColumnDefinition<T> & { id?: Key }).id ?? index;
119
111
  const node: GridNode<T> = {
120
- type: 'column' as GridNodeType,
121
- key: col.key,
112
+ type: "column" as GridNodeType,
113
+ key,
122
114
  index,
123
115
  column: index,
124
116
  level: 0,
125
117
  hasChildNodes: (col.children?.length ?? 0) > 0,
126
118
  childNodes: [],
127
119
  value: null,
128
- textValue: col.textValue ?? col.name ?? String(col.key),
120
+ props: { columnDefinition: { ...col, key } },
121
+ textValue: col.textValue ?? col.name ?? String(key),
129
122
  };
130
123
 
131
- // Build child columns if present (for column groups)
132
124
  if (col.children && col.children.length > 0) {
133
125
  let childIndex = 0;
134
126
  for (const child of col.children) {
135
127
  const childNode = this.buildColumnNode(child, childIndex);
136
- childNode.parentKey = col.key;
128
+ childNode.parentKey = key;
137
129
  childNode.level = 1;
138
130
  node.childNodes.push(childNode);
139
131
  childIndex++;
@@ -145,9 +137,21 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
145
137
  }
146
138
 
147
139
  private getDefaultRowHeaderColumnKeys(): Set<Key> {
148
- // Default to first non-selection column as row header
140
+ const explicitRowHeaderKeys = this._columns
141
+ .filter((col) => col.key !== "__selection__")
142
+ .filter((col) => {
143
+ const definition = col.props?.columnDefinition as ColumnDefinition<T> | undefined;
144
+ return !!definition?.isRowHeader;
145
+ })
146
+ .map((col) => col.key);
147
+
148
+ if (explicitRowHeaderKeys.length > 0) {
149
+ return new Set(explicitRowHeaderKeys);
150
+ }
151
+
152
+ // Default to first non-selection column as row header.
149
153
  for (const col of this._columns) {
150
- if (col.key !== '__selection__') {
154
+ if (col.key !== "__selection__") {
151
155
  return new Set([col.key]);
152
156
  }
153
157
  }
@@ -159,9 +163,8 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
159
163
  return [];
160
164
  }
161
165
 
162
- // Build a single header row containing all columns
163
166
  const headerCells: GridNode<T>[] = this._columns.map((col, index) => ({
164
- type: 'column' as GridNodeType,
167
+ type: "column" as GridNodeType,
165
168
  key: `header-${col.key}`,
166
169
  index,
167
170
  column: index,
@@ -170,19 +173,19 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
170
173
  childNodes: [],
171
174
  value: null,
172
175
  textValue: col.textValue,
173
- parentKey: 'headerrow-0',
176
+ parentKey: "headerrow-0",
174
177
  }));
175
178
 
176
179
  const headerRow: GridNode<T> = {
177
- type: 'headerrow' as GridNodeType,
178
- key: 'headerrow-0',
180
+ type: "headerrow" as GridNodeType,
181
+ key: "headerrow-0",
179
182
  index: 0,
180
183
  rowIndex: 0,
181
184
  level: 0,
182
185
  hasChildNodes: true,
183
186
  childNodes: headerCells,
184
187
  value: null,
185
- textValue: '',
188
+ textValue: "",
186
189
  };
187
190
 
188
191
  this._keyMap.set(headerRow.key, headerRow);
@@ -194,7 +197,7 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
194
197
  private buildRows(
195
198
  rows: RowDefinition<T>[] | T[],
196
199
  getKey?: (item: T) => Key,
197
- getTextValue?: (item: T, column: ColumnDefinition<T>) => string
200
+ getTextValue?: (item: T, column: ColumnDefinition<T>) => string,
198
201
  ): GridNode<T>[] {
199
202
  const result: GridNode<T>[] = [];
200
203
  const rowIndexOffset = this._headerRows.length;
@@ -203,24 +206,30 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
203
206
  const row = rows[i];
204
207
  const isRowDef = this.isRowDefinition(row);
205
208
 
206
- const key = isRowDef ? row.key : getKey?.(row as T) ?? i;
209
+ const key = isRowDef ? row.key : (getKey?.(row as T) ?? i);
207
210
  const value = isRowDef ? row.value : (row as T);
208
- const textValue = isRowDef ? row.textValue : undefined;
211
+ const textValue = isRowDef
212
+ ? row.textValue
213
+ : typeof (row as Record<string, unknown>)?.textValue === "string"
214
+ ? ((row as Record<string, unknown>).textValue as string)
215
+ : undefined;
209
216
 
210
- // Build cells for this row
211
217
  const cells: GridNode<T>[] = this._columns.map((col, colIndex) => {
212
218
  const cellKey = `${key}-${col.key}`;
219
+ const columnDefinition =
220
+ (col.props?.columnDefinition as ColumnDefinition<T> | undefined) ??
221
+ ({ key: col.key } as ColumnDefinition<T>);
213
222
  const cellTextValue =
214
- col.key === '__selection__'
215
- ? 'Selection'
223
+ col.key === "__selection__"
224
+ ? "Selection"
216
225
  : getTextValue
217
- ? getTextValue(value, { key: col.key } as ColumnDefinition<T>)
218
- : String((value as Record<string, unknown>)?.[String(col.key)] ?? '');
226
+ ? getTextValue(value, columnDefinition)
227
+ : String((value as Record<string, unknown>)?.[String(col.key)] ?? "");
219
228
 
220
229
  const cell: GridNode<T> = {
221
230
  type: this._rowHeaderColumnKeys.has(col.key)
222
- ? ('rowheader' as GridNodeType)
223
- : ('cell' as GridNodeType),
231
+ ? ("rowheader" as GridNodeType)
232
+ : ("cell" as GridNodeType),
224
233
  key: cellKey,
225
234
  index: colIndex,
226
235
  column: colIndex,
@@ -237,7 +246,7 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
237
246
  });
238
247
 
239
248
  const rowNode: GridNode<T> = {
240
- type: 'item' as GridNodeType,
249
+ type: "item" as GridNodeType,
241
250
  key,
242
251
  index: i,
243
252
  rowIndex: rowIndexOffset + i,
@@ -245,7 +254,7 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
245
254
  hasChildNodes: true,
246
255
  childNodes: cells,
247
256
  value,
248
- textValue: textValue ?? cells.map((c) => c.textValue).join(' '),
257
+ textValue: textValue ?? cells.map((c) => c.textValue).join(" "),
249
258
  };
250
259
 
251
260
  this._keyMap.set(key, rowNode);
@@ -256,15 +265,9 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
256
265
  }
257
266
 
258
267
  private isRowDefinition(row: unknown): row is RowDefinition<T> {
259
- return (
260
- typeof row === 'object' &&
261
- row !== null &&
262
- 'key' in row &&
263
- 'value' in row
264
- );
268
+ return typeof row === "object" && row !== null && "key" in row && "value" in row;
265
269
  }
266
270
 
267
- // Collection interface implementation
268
271
  get size(): number {
269
272
  return this._size;
270
273
  }
@@ -324,7 +327,7 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
324
327
 
325
328
  getTextValue(key: Key): string {
326
329
  const node = this._keyMap.get(key);
327
- return node?.textValue ?? '';
330
+ return node?.textValue ?? "";
328
331
  }
329
332
 
330
333
  getCell(rowKey: Key, columnKey: Key): GridNode<T> | null {
@@ -333,13 +336,11 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
333
336
  }
334
337
 
335
338
  getFirstKey(): Key | null {
336
- // Return first body row key
337
339
  const bodyRows = this._body.childNodes;
338
340
  return bodyRows.length > 0 ? bodyRows[0].key : null;
339
341
  }
340
342
 
341
343
  getLastKey(): Key | null {
342
- // Return last body row key
343
344
  const bodyRows = this._body.childNodes;
344
345
  return bodyRows.length > 0 ? bodyRows[bodyRows.length - 1].key : null;
345
346
  }
@@ -348,7 +349,6 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
348
349
  const node = this._keyMap.get(key);
349
350
  if (!node) return null;
350
351
 
351
- // Find in body rows
352
352
  const bodyRows = this._body.childNodes;
353
353
  const index = bodyRows.findIndex((r) => r.key === key);
354
354
  if (index > 0) {
@@ -361,7 +361,6 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
361
361
  const node = this._keyMap.get(key);
362
362
  if (!node) return null;
363
363
 
364
- // Find in body rows
365
364
  const bodyRows = this._body.childNodes;
366
365
  const index = bodyRows.findIndex((r) => r.key === key);
367
366
  if (index >= 0 && index < bodyRows.length - 1) {
@@ -381,8 +380,6 @@ export class TableCollection<T = unknown> implements ITableCollection<T> {
381
380
  /**
382
381
  * Creates a table collection from options.
383
382
  */
384
- export function createTableCollection<T>(
385
- options: TableCollectionOptions<T>
386
- ): TableCollection<T> {
383
+ export function createTableCollection<T>(options: TableCollectionOptions<T>): TableCollection<T> {
387
384
  return new TableCollection(options);
388
385
  }
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Table column resize state management.
3
+ * Based on @react-stately/table/useTableColumnResizeState.
4
+ *
5
+ * Provides column width state management for a table with column resizing.
6
+ * Tracks column widths, the currently resizing column, and handles
7
+ * width distribution and clamping.
8
+ */
9
+
10
+ import { createSignal, createMemo, type Accessor } from "solid-js";
11
+ import type { Key } from "../collections/types";
12
+
13
+ /** Column size: a number (px) or a string ('100px', '50%', '1fr'). */
14
+ export type ColumnSize = number | string;
15
+
16
+ export interface ColumnResizeDefinition {
17
+ /** The column key. */
18
+ key: Key;
19
+ /** The width of the column. Numbers are px, strings can be 'Xfr', 'Xpx', or 'X%'. */
20
+ width?: ColumnSize;
21
+ /** Minimum width in pixels. Default: 75. */
22
+ minWidth?: number;
23
+ /** Maximum width in pixels. Default: Infinity. */
24
+ maxWidth?: number;
25
+ }
26
+
27
+ export interface TableColumnResizeStateProps {
28
+ /** Current width of the table or table viewport. */
29
+ tableWidth: number;
30
+ /** Column definitions with width/min/max. */
31
+ columns: ColumnResizeDefinition[];
32
+ }
33
+
34
+ export interface TableColumnResizeState {
35
+ /** The key of the column currently being resized, or null. */
36
+ readonly resizingColumn: Accessor<Key | null>;
37
+ /** A reactive map of computed column widths in pixels. */
38
+ readonly columnWidths: Accessor<Map<Key, number>>;
39
+ /** Begin a resize operation for the given column. */
40
+ startResize(key: Key): void;
41
+ /** End the current resize operation. */
42
+ endResize(): void;
43
+ /** Update column widths during a resize drag. Returns the new widths map. */
44
+ updateResizedColumns(key: Key, width: number): Map<Key, number>;
45
+ /** Get the current computed width for a column. */
46
+ getColumnWidth(key: Key): number;
47
+ /** Get the minimum width for a column. */
48
+ getColumnMinWidth(key: Key): number;
49
+ /** Get the maximum width for a column. */
50
+ getColumnMaxWidth(key: Key): number;
51
+ }
52
+
53
+ const DEFAULT_MIN_WIDTH = 75;
54
+ const DEFAULT_MAX_WIDTH = Infinity;
55
+
56
+ interface ParsedColumn {
57
+ key: Key;
58
+ /** Fraction units (from 'Xfr' or unspecified width). 0 if fixed. */
59
+ fr: number;
60
+ /** Fixed pixel width, or 0 if fractional. */
61
+ fixedPx: number;
62
+ minWidth: number;
63
+ maxWidth: number;
64
+ }
65
+
66
+ function parseColumnDef(col: ColumnResizeDefinition, tableWidth: number): ParsedColumn {
67
+ const minWidth = col.minWidth ?? DEFAULT_MIN_WIDTH;
68
+ const maxWidth = col.maxWidth ?? DEFAULT_MAX_WIDTH;
69
+
70
+ if (col.width == null) {
71
+ // Default: 1fr
72
+ return { key: col.key, fr: 1, fixedPx: 0, minWidth, maxWidth };
73
+ }
74
+
75
+ if (typeof col.width === "number") {
76
+ return { key: col.key, fr: 0, fixedPx: col.width, minWidth, maxWidth };
77
+ }
78
+
79
+ const str = col.width.trim();
80
+
81
+ // Fractional: '2fr', '1.5fr'
82
+ if (str.endsWith("fr")) {
83
+ const val = parseFloat(str);
84
+ return { key: col.key, fr: isNaN(val) ? 1 : val, fixedPx: 0, minWidth, maxWidth };
85
+ }
86
+
87
+ // Percentage: '25%'
88
+ if (str.endsWith("%")) {
89
+ const pct = parseFloat(str);
90
+ const px = isNaN(pct) ? 0 : (pct / 100) * tableWidth;
91
+ return { key: col.key, fr: 0, fixedPx: px, minWidth, maxWidth };
92
+ }
93
+
94
+ // Pixel: '200px' or just a numeric string
95
+ const px = parseFloat(str);
96
+ return { key: col.key, fr: 0, fixedPx: isNaN(px) ? 0 : px, minWidth, maxWidth };
97
+ }
98
+
99
+ /**
100
+ * Distribute `tableWidth` among columns:
101
+ * 1. Fixed-width columns get their declared width (clamped to min/max).
102
+ * 2. Remaining space is distributed among fractional columns proportionally.
103
+ */
104
+ function distributeWidths(columns: ColumnResizeDefinition[], tableWidth: number): Map<Key, number> {
105
+ const parsed = columns.map((c) => parseColumnDef(c, tableWidth));
106
+
107
+ // Pass 1 — allocate fixed columns
108
+ let usedSpace = 0;
109
+ let totalFr = 0;
110
+ for (const p of parsed) {
111
+ if (p.fr > 0) {
112
+ totalFr += p.fr;
113
+ } else {
114
+ const w = Math.max(p.minWidth, Math.min(p.maxWidth, p.fixedPx));
115
+ usedSpace += w;
116
+ }
117
+ }
118
+
119
+ const remainingSpace = Math.max(0, tableWidth - usedSpace);
120
+ const perFr = totalFr > 0 ? remainingSpace / totalFr : 0;
121
+
122
+ // Pass 2 — build map
123
+ const widths = new Map<Key, number>();
124
+ for (const p of parsed) {
125
+ let w: number;
126
+ if (p.fr > 0) {
127
+ w = p.fr * perFr;
128
+ } else {
129
+ w = p.fixedPx;
130
+ }
131
+ // Clamp
132
+ w = Math.max(p.minWidth, Math.min(p.maxWidth, w));
133
+ widths.set(p.key, Math.round(w));
134
+ }
135
+
136
+ return widths;
137
+ }
138
+
139
+ /**
140
+ * Creates column resize state for a table component.
141
+ *
142
+ * Builds an initial column width map from column definitions + table width,
143
+ * then tracks resize operations that clamp to min/max and redistribute
144
+ * remaining space among flex columns.
145
+ */
146
+ export function createTableColumnResizeState(
147
+ props: Accessor<TableColumnResizeStateProps>,
148
+ ): TableColumnResizeState {
149
+ const getProps = () => props();
150
+
151
+ // Memoize initial width distribution (re-distributes when table width or columns change)
152
+ const initialWidths = createMemo(() =>
153
+ distributeWidths(getProps().columns, getProps().tableWidth),
154
+ );
155
+
156
+ // User-overridden widths (set during/after resize)
157
+ const [overrides, setOverrides] = createSignal<Map<Key, number>>(new Map());
158
+ const [resizingColumn, setResizingColumn] = createSignal<Key | null>(null);
159
+
160
+ // Computed widths: initial merged with overrides
161
+ const columnWidths = createMemo(() => {
162
+ const base = initialWidths();
163
+ const over = overrides();
164
+ if (over.size === 0) return base;
165
+
166
+ const merged = new Map(base);
167
+ for (const [key, width] of over) {
168
+ if (merged.has(key)) {
169
+ merged.set(key, width);
170
+ }
171
+ }
172
+ return merged;
173
+ });
174
+
175
+ // Build min/max lookup
176
+ const minWidthMap = createMemo(() => {
177
+ const map = new Map<Key, number>();
178
+ for (const col of getProps().columns) {
179
+ map.set(col.key, col.minWidth ?? DEFAULT_MIN_WIDTH);
180
+ }
181
+ return map;
182
+ });
183
+
184
+ const maxWidthMap = createMemo(() => {
185
+ const map = new Map<Key, number>();
186
+ for (const col of getProps().columns) {
187
+ map.set(col.key, col.maxWidth ?? DEFAULT_MAX_WIDTH);
188
+ }
189
+ return map;
190
+ });
191
+
192
+ const getColumnWidth = (key: Key): number => {
193
+ return columnWidths().get(key) ?? 0;
194
+ };
195
+
196
+ const getColumnMinWidth = (key: Key): number => {
197
+ return minWidthMap().get(key) ?? DEFAULT_MIN_WIDTH;
198
+ };
199
+
200
+ const getColumnMaxWidth = (key: Key): number => {
201
+ return maxWidthMap().get(key) ?? DEFAULT_MAX_WIDTH;
202
+ };
203
+
204
+ const startResize = (key: Key) => {
205
+ setResizingColumn(key);
206
+ };
207
+
208
+ const endResize = () => {
209
+ setResizingColumn(null);
210
+ };
211
+
212
+ const updateResizedColumns = (key: Key, width: number): Map<Key, number> => {
213
+ const minW = getColumnMinWidth(key);
214
+ const maxW = getColumnMaxWidth(key);
215
+ const clampedWidth = Math.round(Math.max(minW, Math.min(maxW, width)));
216
+
217
+ const newOverrides = new Map(overrides());
218
+ newOverrides.set(key, clampedWidth);
219
+ setOverrides(newOverrides);
220
+
221
+ // Return the resulting widths
222
+ const base = initialWidths();
223
+ const merged = new Map(base);
224
+ for (const [k, w] of newOverrides) {
225
+ if (merged.has(k)) {
226
+ merged.set(k, w);
227
+ }
228
+ }
229
+ return merged;
230
+ };
231
+
232
+ return {
233
+ resizingColumn,
234
+ columnWidths,
235
+ startResize,
236
+ endResize,
237
+ updateResizedColumns,
238
+ getColumnWidth,
239
+ getColumnMinWidth,
240
+ getColumnMaxWidth,
241
+ };
242
+ }
@@ -2,11 +2,14 @@
2
2
  * Table state management for Table components.
3
3
  * Based on @react-stately/table/useTableState.
4
4
  */
5
- import { type Accessor } from 'solid-js';
6
- import type { TableState, TableStateOptions, TableCollection } from './types';
5
+ import { type Accessor } from "solid-js";
6
+ import type { TableState, TableStateOptions, TableCollection } from "./types";
7
7
  /**
8
8
  * Creates state management for a table component.
9
9
  * Extends grid state with sorting and table-specific features.
10
10
  */
11
- export declare function createTableState<T extends object, C extends TableCollection<T> = TableCollection<T>>(options: Accessor<TableStateOptions<T, C>>): TableState<T, C>;
12
- //# sourceMappingURL=createTableState.d.ts.map
11
+ export declare function createTableState<
12
+ T extends object,
13
+ C extends TableCollection<T> = TableCollection<T>,
14
+ >(options: Accessor<TableStateOptions<T, C>>): TableState<T, C>;
15
+ //# sourceMappingURL=createTableState.d.ts.map