@proyecto-viviana/solid-stately 0.2.7 → 0.4.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.
- package/README.md +30 -283
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -2
- package/dist/autocomplete/index.d.ts +1 -1
- package/dist/calendar/IncompleteDate.d.ts +61 -0
- package/dist/calendar/createCalendarState.d.ts +41 -16
- package/dist/calendar/createDateFieldState.d.ts +39 -9
- package/dist/calendar/createDatePickerState.d.ts +60 -0
- package/dist/calendar/createRangeCalendarState.d.ts +37 -10
- package/dist/calendar/createTimeFieldState.d.ts +34 -7
- package/dist/calendar/index.d.ts +7 -6
- package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/collections/ListCollection.d.ts +1 -1
- package/dist/collections/createListState.d.ts +11 -8
- package/dist/collections/createMenuState.d.ts +7 -7
- package/dist/collections/createSelectionState.d.ts +22 -10
- package/dist/collections/getChildNodes.d.ts +11 -0
- package/dist/collections/index.d.ts +6 -5
- package/dist/collections/types.d.ts +12 -12
- package/dist/color/Color.d.ts +1 -1
- package/dist/color/createColorAreaState.d.ts +4 -2
- package/dist/color/createColorFieldState.d.ts +38 -12
- package/dist/color/createColorSliderState.d.ts +9 -2
- package/dist/color/createColorWheelState.d.ts +13 -2
- package/dist/color/getColorChannels.d.ts +1 -1
- package/dist/color/index.d.ts +6 -6
- package/dist/color/types.d.ts +4 -4
- package/dist/combobox/createComboBoxState.d.ts +34 -13
- package/dist/combobox/index.d.ts +1 -1
- package/dist/data/createAsyncList.d.ts +4 -4
- package/dist/data/createListData.d.ts +2 -2
- package/dist/data/createTreeData.d.ts +6 -2
- package/dist/data/index.d.ts +3 -3
- package/dist/datepicker/index.d.ts +2 -4
- package/dist/disclosure/createDisclosureState.d.ts +2 -2
- package/dist/disclosure/index.d.ts +1 -1
- package/dist/dnd/createDragState.d.ts +2 -2
- package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
- package/dist/dnd/createDropState.d.ts +2 -2
- package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
- package/dist/dnd/index.d.ts +5 -5
- package/dist/dnd/types.d.ts +19 -17
- package/dist/form/createFormValidationState.d.ts +3 -3
- package/dist/form/index.d.ts +1 -1
- package/dist/grid/createGridState.d.ts +2 -2
- package/dist/grid/index.d.ts +2 -2
- package/dist/grid/types.d.ts +27 -11
- package/dist/index.d.ts +31 -30
- package/dist/index.js +9077 -7246
- package/dist/index.js.map +1 -1
- package/dist/menu/index.d.ts +2 -2
- package/dist/numberfield/createNumberFieldState.d.ts +2 -2
- package/dist/numberfield/index.d.ts +1 -1
- package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
- package/dist/overlays/index.d.ts +1 -1
- package/dist/radio/createRadioGroupState.d.ts +7 -7
- package/dist/radio/index.d.ts +1 -1
- package/dist/searchfield/createSearchFieldState.d.ts +2 -2
- package/dist/searchfield/index.d.ts +2 -2
- package/dist/select/createSelectState.d.ts +14 -8
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/Selection.d.ts +16 -0
- package/dist/selection/SelectionManager.d.ts +110 -0
- package/dist/selection/createMultipleSelectionState.d.ts +59 -0
- package/dist/selection/index.d.ts +6 -5
- package/dist/slider/createSliderState.d.ts +3 -3
- package/dist/slider/index.d.ts +2 -2
- package/dist/steplist/createStepListState.d.ts +48 -0
- package/dist/steplist/index.d.ts +1 -0
- package/dist/table/TableCollection.d.ts +33 -3
- package/dist/table/createTableColumnResizeState.d.ts +54 -0
- package/dist/table/createTableState.d.ts +2 -2
- package/dist/table/createTreeGridState.d.ts +15 -0
- package/dist/table/index.d.ts +6 -3
- package/dist/table/types.d.ts +68 -10
- package/dist/tabs/createTabListState.d.ts +5 -5
- package/dist/tabs/index.d.ts +1 -1
- package/dist/textfield/createTextFieldState.d.ts +2 -2
- package/dist/textfield/index.d.ts +1 -1
- package/dist/toast/createToastState.d.ts +24 -2
- package/dist/toast/index.d.ts +1 -1
- package/dist/toggle/createToggleGroupState.d.ts +4 -4
- package/dist/toggle/createToggleState.d.ts +2 -2
- package/dist/toggle/index.d.ts +2 -2
- package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tree/TreeCollection.d.ts +2 -2
- package/dist/tree/createTreeState.d.ts +2 -2
- package/dist/tree/index.d.ts +3 -3
- package/dist/tree/types.d.ts +27 -13
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/reactivity.d.ts +1 -1
- package/package.json +29 -30
- package/src/autocomplete/createAutocompleteState.d.ts +19 -17
- package/src/autocomplete/createAutocompleteState.ts +24 -30
- package/src/autocomplete/index.d.ts +6 -2
- package/src/autocomplete/index.ts +1 -1
- package/src/calendar/IncompleteDate.ts +430 -0
- package/src/calendar/createCalendarState.d.ts +139 -117
- package/src/calendar/createCalendarState.ts +308 -94
- package/src/calendar/createDateFieldState.d.ts +130 -95
- package/src/calendar/createDateFieldState.ts +447 -334
- package/src/calendar/createDatePickerState.ts +347 -0
- package/src/calendar/createRangeCalendarState.d.ts +154 -129
- package/src/calendar/createRangeCalendarState.ts +411 -85
- package/src/calendar/createTimeFieldState.d.ts +81 -79
- package/src/calendar/createTimeFieldState.ts +187 -108
- package/src/calendar/index.d.ts +80 -7
- package/src/calendar/index.ts +23 -12
- package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
- package/src/checkbox/createCheckboxGroupState.ts +20 -29
- package/src/checkbox/index.d.ts +6 -2
- package/src/checkbox/index.ts +1 -1
- package/src/collections/ListCollection.d.ts +25 -22
- package/src/collections/ListCollection.ts +6 -6
- package/src/collections/createListState.d.ts +73 -58
- package/src/collections/createListState.ts +67 -35
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +21 -12
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +66 -52
- package/src/collections/getChildNodes.ts +98 -0
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +14 -10
- package/src/collections/types.d.ts +101 -101
- package/src/collections/types.ts +12 -12
- package/src/color/Color.d.ts +20 -5
- package/src/color/Color.ts +357 -254
- package/src/color/createColorAreaState.d.ts +67 -65
- package/src/color/createColorAreaState.ts +21 -13
- package/src/color/createColorFieldState.d.ts +46 -44
- package/src/color/createColorFieldState.ts +285 -149
- package/src/color/createColorSliderState.d.ts +58 -56
- package/src/color/createColorSliderState.ts +45 -14
- package/src/color/createColorWheelState.d.ts +42 -40
- package/src/color/createColorWheelState.ts +101 -64
- package/src/color/getColorChannels.ts +7 -5
- package/src/color/index.d.ts +36 -7
- package/src/color/index.ts +6 -9
- package/src/color/types.d.ts +68 -63
- package/src/color/types.ts +11 -19
- package/src/combobox/createComboBoxState.d.ts +107 -105
- package/src/combobox/createComboBoxState.ts +184 -89
- package/src/combobox/index.d.ts +10 -2
- package/src/combobox/index.ts +1 -1
- package/src/data/createAsyncList.ts +89 -63
- package/src/data/createListData.ts +67 -67
- package/src/data/createTreeData.ts +304 -91
- package/src/data/index.ts +3 -3
- package/src/datepicker/index.ts +6 -10
- package/src/disclosure/createDisclosureState.d.ts +47 -43
- package/src/disclosure/createDisclosureState.ts +7 -21
- package/src/disclosure/index.d.ts +10 -2
- package/src/disclosure/index.ts +1 -1
- package/src/dnd/createDragState.d.ts +51 -42
- package/src/dnd/createDragState.ts +12 -14
- package/src/dnd/createDraggableCollectionState.d.ts +52 -41
- package/src/dnd/createDraggableCollectionState.ts +14 -21
- package/src/dnd/createDropState.d.ts +64 -45
- package/src/dnd/createDropState.ts +22 -32
- package/src/dnd/createDroppableCollectionState.d.ts +88 -59
- package/src/dnd/createDroppableCollectionState.ts +40 -43
- package/src/dnd/index.d.ts +55 -6
- package/src/dnd/index.ts +6 -18
- package/src/dnd/types.d.ts +170 -157
- package/src/dnd/types.ts +24 -22
- package/src/form/createFormValidationState.d.ts +47 -45
- package/src/form/createFormValidationState.ts +30 -63
- package/src/form/index.d.ts +16 -2
- package/src/form/index.ts +1 -1
- package/src/grid/createGridState.d.ts +7 -4
- package/src/grid/createGridState.ts +78 -51
- package/src/grid/index.d.ts +3 -3
- package/src/grid/index.ts +2 -8
- package/src/grid/types.d.ts +136 -129
- package/src/grid/types.ts +34 -18
- package/src/index.d.ts +311 -26
- package/src/index.ts +59 -89
- package/src/menu/index.ts +2 -4
- package/src/numberfield/createNumberFieldState.d.ts +56 -54
- package/src/numberfield/createNumberFieldState.ts +26 -31
- package/src/numberfield/index.d.ts +6 -2
- package/src/numberfield/index.ts +1 -1
- package/src/overlays/createOverlayTriggerState.d.ts +22 -20
- package/src/overlays/createOverlayTriggerState.ts +3 -4
- package/src/overlays/index.d.ts +6 -2
- package/src/overlays/index.ts +1 -1
- package/src/radio/createRadioGroupState.d.ts +54 -52
- package/src/radio/createRadioGroupState.ts +27 -29
- package/src/radio/index.d.ts +7 -2
- package/src/radio/index.ts +1 -1
- package/src/searchfield/createSearchFieldState.d.ts +16 -14
- package/src/searchfield/createSearchFieldState.ts +5 -11
- package/src/searchfield/index.d.ts +3 -3
- package/src/searchfield/index.ts +2 -5
- package/src/select/createSelectState.d.ts +63 -61
- package/src/select/createSelectState.ts +42 -29
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/Selection.ts +28 -0
- package/src/selection/SelectionManager.ts +526 -0
- package/src/selection/createMultipleSelectionState.ts +247 -0
- package/src/selection/index.ts +12 -7
- package/src/slider/createSliderState.d.ts +60 -60
- package/src/slider/createSliderState.ts +55 -33
- package/src/slider/index.d.ts +3 -3
- package/src/slider/index.ts +2 -6
- package/src/ssr/index.d.ts +1 -1
- package/src/ssr/index.ts +2 -2
- package/src/steplist/createStepListState.ts +191 -0
- package/src/steplist/index.ts +5 -0
- package/src/table/TableCollection.d.ts +42 -40
- package/src/table/TableCollection.ts +266 -99
- package/src/table/createTableColumnResizeState.ts +242 -0
- package/src/table/createTableState.d.ts +7 -4
- package/src/table/createTableState.ts +30 -7
- package/src/table/createTreeGridState.ts +146 -0
- package/src/table/index.d.ts +14 -4
- package/src/table/index.ts +13 -3
- package/src/table/types.d.ts +98 -92
- package/src/table/types.ts +83 -13
- package/src/tabs/createTabListState.d.ts +59 -57
- package/src/tabs/createTabListState.ts +34 -39
- package/src/tabs/index.d.ts +8 -2
- package/src/tabs/index.ts +1 -1
- package/src/textfield/createTextFieldState.d.ts +16 -14
- package/src/textfield/createTextFieldState.ts +7 -18
- package/src/textfield/index.d.ts +6 -2
- package/src/textfield/index.ts +1 -1
- package/src/toast/createToastState.d.ts +92 -86
- package/src/toast/createToastState.ts +90 -52
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +2 -1
- package/src/toggle/createToggleGroupState.ts +11 -21
- package/src/toggle/createToggleState.d.ts +19 -19
- package/src/toggle/createToggleState.ts +2 -16
- package/src/toggle/index.d.ts +2 -2
- package/src/toggle/index.ts +2 -6
- package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
- package/src/tooltip/createTooltipTriggerState.ts +12 -11
- package/src/tooltip/index.d.ts +7 -2
- package/src/tooltip/index.ts +1 -1
- package/src/tree/TreeCollection.d.ts +26 -23
- package/src/tree/TreeCollection.ts +29 -22
- package/src/tree/createTreeState.d.ts +7 -4
- package/src/tree/createTreeState.ts +70 -41
- package/src/tree/index.d.ts +10 -4
- package/src/tree/index.ts +3 -3
- package/src/tree/types.d.ts +131 -126
- package/src/tree/types.ts +30 -13
- package/src/utils/index.d.ts +2 -2
- package/src/utils/index.ts +1 -1
- package/src/utils/reactivity.d.ts +2 -2
- package/src/utils/reactivity.ts +3 -3
|
@@ -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
|
|
6
|
-
import type { TableState, TableStateOptions, TableCollection } from
|
|
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<
|
|
12
|
-
|
|
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
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
* Based on @react-stately/table/useTableState.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { createMemo, type Accessor } from
|
|
7
|
-
import { createGridState } from
|
|
8
|
-
import type { Key } from
|
|
6
|
+
import { createMemo, type Accessor } from "solid-js";
|
|
7
|
+
import { createGridState } from "../grid/createGridState";
|
|
8
|
+
import type { Key } from "../collections/types";
|
|
9
9
|
import type {
|
|
10
10
|
TableState,
|
|
11
11
|
TableStateOptions,
|
|
12
12
|
TableCollection,
|
|
13
13
|
SortDescriptor,
|
|
14
14
|
SortDirection,
|
|
15
|
-
} from
|
|
15
|
+
} from "./types";
|
|
16
16
|
|
|
17
17
|
const OPPOSITE_SORT_DIRECTION: Record<SortDirection, SortDirection> = {
|
|
18
|
-
ascending:
|
|
19
|
-
descending:
|
|
18
|
+
ascending: "descending",
|
|
19
|
+
descending: "ascending",
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -33,6 +33,7 @@ export function createTableState<
|
|
|
33
33
|
const gridState = createGridState<T, C>(() => ({
|
|
34
34
|
collection: getOptions().collection,
|
|
35
35
|
disabledKeys: getOptions().disabledKeys,
|
|
36
|
+
disabledBehavior: getOptions().disabledBehavior,
|
|
36
37
|
focusMode: getOptions().focusMode,
|
|
37
38
|
selectionMode: getOptions().selectionMode,
|
|
38
39
|
selectionBehavior: getOptions().selectionBehavior,
|
|
@@ -66,7 +67,7 @@ export function createTableState<
|
|
|
66
67
|
newDirection = OPPOSITE_SORT_DIRECTION[currentSort.direction];
|
|
67
68
|
} else {
|
|
68
69
|
// Default to ascending for new column
|
|
69
|
-
newDirection =
|
|
70
|
+
newDirection = "ascending";
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
opts.onSortChange?.({
|
|
@@ -83,6 +84,9 @@ export function createTableState<
|
|
|
83
84
|
get disabledKeys() {
|
|
84
85
|
return gridState.disabledKeys;
|
|
85
86
|
},
|
|
87
|
+
get disabledBehavior() {
|
|
88
|
+
return gridState.disabledBehavior;
|
|
89
|
+
},
|
|
86
90
|
get isKeyboardNavigationDisabled() {
|
|
87
91
|
return gridState.isKeyboardNavigationDisabled;
|
|
88
92
|
},
|
|
@@ -98,6 +102,12 @@ export function createTableState<
|
|
|
98
102
|
get selectionMode() {
|
|
99
103
|
return gridState.selectionMode;
|
|
100
104
|
},
|
|
105
|
+
get selectionBehavior() {
|
|
106
|
+
return gridState.selectionBehavior;
|
|
107
|
+
},
|
|
108
|
+
get disallowEmptySelection() {
|
|
109
|
+
return gridState.disallowEmptySelection;
|
|
110
|
+
},
|
|
101
111
|
get selectedKeys() {
|
|
102
112
|
return gridState.selectedKeys;
|
|
103
113
|
},
|
|
@@ -109,6 +119,8 @@ export function createTableState<
|
|
|
109
119
|
setFocused: gridState.setFocused,
|
|
110
120
|
toggleSelection: gridState.toggleSelection,
|
|
111
121
|
replaceSelection: gridState.replaceSelection,
|
|
122
|
+
setSelectionBehavior: gridState.setSelectionBehavior,
|
|
123
|
+
setSelectedKeys: gridState.setSelectedKeys,
|
|
112
124
|
extendSelection: gridState.extendSelection,
|
|
113
125
|
selectAll: gridState.selectAll,
|
|
114
126
|
clearSelection: gridState.clearSelection,
|
|
@@ -123,5 +135,16 @@ export function createTableState<
|
|
|
123
135
|
return sortDescriptor();
|
|
124
136
|
},
|
|
125
137
|
sort,
|
|
138
|
+
|
|
139
|
+
// A plain table has no expandable rows.
|
|
140
|
+
get expandedKeys(): "all" | Set<Key> {
|
|
141
|
+
return EMPTY_EXPANDED_KEYS;
|
|
142
|
+
},
|
|
143
|
+
get treeColumn(): Key | null {
|
|
144
|
+
return getOptions().collection.treeColumn ?? null;
|
|
145
|
+
},
|
|
146
|
+
toggleKey: () => {},
|
|
126
147
|
};
|
|
127
148
|
}
|
|
149
|
+
|
|
150
|
+
const EMPTY_EXPANDED_KEYS: Set<Key> = new Set();
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree grid state management for expandable Table rows.
|
|
3
|
+
* Based on @react-stately/table/useTreeGridState (the `UNSTABLE_` tree-grid feature).
|
|
4
|
+
*
|
|
5
|
+
* Owns the expanded-keys signal (controlled or uncontrolled), rebuilds the table
|
|
6
|
+
* collection from it, and layers the expansion API on top of {@link createTableState}.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createMemo, createSignal, type Accessor } from "solid-js";
|
|
10
|
+
import { createTableState } from "./createTableState";
|
|
11
|
+
import { createTableCollection, TableCollection } from "./TableCollection";
|
|
12
|
+
import type { Key } from "../collections/types";
|
|
13
|
+
import type { TreeGridState, TreeGridStateOptions } from "./types";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates state management for a tree grid (a table with expandable rows). Handles the
|
|
17
|
+
* expanded rows in addition to the selection, sort and focus handled by the table state.
|
|
18
|
+
*/
|
|
19
|
+
export function createTreeGridState<
|
|
20
|
+
T extends object,
|
|
21
|
+
C extends TableCollection<T> = TableCollection<T>,
|
|
22
|
+
>(options: Accessor<TreeGridStateOptions<T, C>>): TreeGridState<T, C> {
|
|
23
|
+
const getOptions = () => options();
|
|
24
|
+
|
|
25
|
+
// Expanded keys: controlled via `UNSTABLE_expandedKeys`, otherwise the internal signal
|
|
26
|
+
// seeded from `UNSTABLE_defaultExpandedKeys`.
|
|
27
|
+
const [internalExpandedKeys, setInternalExpandedKeys] = createSignal<"all" | Set<Key>>(
|
|
28
|
+
getInitialExpanded(getOptions().UNSTABLE_defaultExpandedKeys),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const expandedKeys = createMemo<"all" | Set<Key>>(() => {
|
|
32
|
+
const controlled = getOptions().UNSTABLE_expandedKeys;
|
|
33
|
+
if (controlled !== undefined) {
|
|
34
|
+
return convertExpanded(controlled);
|
|
35
|
+
}
|
|
36
|
+
return internalExpandedKeys();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Rebuild the tree collection whenever the expanded keys (or the data) change.
|
|
40
|
+
const collection = createMemo(
|
|
41
|
+
() =>
|
|
42
|
+
createTableCollection<T>({
|
|
43
|
+
columns: getOptions().columns,
|
|
44
|
+
rows: getOptions().rows,
|
|
45
|
+
getKey: getOptions().getKey,
|
|
46
|
+
getTextValue: getOptions().getTextValue,
|
|
47
|
+
showSelectionCheckboxes: getOptions().showSelectionCheckboxes ?? false,
|
|
48
|
+
rowHeaderColumnKeys: getOptions().rowHeaderColumnKeys,
|
|
49
|
+
expandedKeys: expandedKeys(),
|
|
50
|
+
}) as unknown as C,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const tableState = createTableState<T, C>(() => ({
|
|
54
|
+
collection: collection(),
|
|
55
|
+
disabledKeys: getOptions().disabledKeys,
|
|
56
|
+
focusMode: getOptions().focusMode,
|
|
57
|
+
selectionMode: getOptions().selectionMode,
|
|
58
|
+
selectionBehavior: getOptions().selectionBehavior,
|
|
59
|
+
disallowEmptySelection: getOptions().disallowEmptySelection,
|
|
60
|
+
selectedKeys: getOptions().selectedKeys,
|
|
61
|
+
defaultSelectedKeys: getOptions().defaultSelectedKeys,
|
|
62
|
+
onSelectionChange: getOptions().onSelectionChange,
|
|
63
|
+
sortDescriptor: getOptions().sortDescriptor,
|
|
64
|
+
onSortChange: getOptions().onSortChange,
|
|
65
|
+
showSelectionCheckboxes: getOptions().showSelectionCheckboxes,
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
const toggleKey = (key: Key) => {
|
|
69
|
+
const updated = toggleExpandedKey(expandedKeys(), key, collection());
|
|
70
|
+
|
|
71
|
+
// Only own the value when uncontrolled.
|
|
72
|
+
if (getOptions().UNSTABLE_expandedKeys === undefined) {
|
|
73
|
+
setInternalExpandedKeys(updated);
|
|
74
|
+
}
|
|
75
|
+
getOptions().UNSTABLE_onExpandedChange?.(updated);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Layer the expansion API onto the table state object, preserving the reactive getters
|
|
79
|
+
// already defined on it (spreading would eagerly evaluate them and break reactivity).
|
|
80
|
+
const treeGridState = tableState as TreeGridState<T, C>;
|
|
81
|
+
Object.defineProperty(treeGridState, "expandedKeys", {
|
|
82
|
+
get: () => expandedKeys(),
|
|
83
|
+
configurable: true,
|
|
84
|
+
enumerable: true,
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(treeGridState, "treeColumn", {
|
|
87
|
+
get: () => collection().treeColumn ?? null,
|
|
88
|
+
configurable: true,
|
|
89
|
+
enumerable: true,
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(treeGridState, "keyMap", {
|
|
92
|
+
get: () => collection().keyMap,
|
|
93
|
+
configurable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(treeGridState, "userColumnCount", {
|
|
97
|
+
get: () => collection().userColumnCount,
|
|
98
|
+
configurable: true,
|
|
99
|
+
enumerable: true,
|
|
100
|
+
});
|
|
101
|
+
treeGridState.toggleKey = toggleKey;
|
|
102
|
+
|
|
103
|
+
return treeGridState;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Computes the next expanded-key set when a row is toggled. Mirrors the upstream
|
|
108
|
+
* `toggleKey`: collapsing from `'all'` materialises every expandable row first.
|
|
109
|
+
*/
|
|
110
|
+
function toggleExpandedKey<T>(
|
|
111
|
+
current: "all" | Set<Key>,
|
|
112
|
+
key: Key,
|
|
113
|
+
collection: TableCollection<T>,
|
|
114
|
+
): Set<Key> {
|
|
115
|
+
let updated: Set<Key>;
|
|
116
|
+
if (current === "all") {
|
|
117
|
+
updated = new Set(
|
|
118
|
+
collection.rows
|
|
119
|
+
.filter((row) => row.type === "item" && row.isExpandable)
|
|
120
|
+
.map((row) => row.key),
|
|
121
|
+
);
|
|
122
|
+
updated.delete(key);
|
|
123
|
+
} else {
|
|
124
|
+
updated = new Set(current);
|
|
125
|
+
if (updated.has(key)) {
|
|
126
|
+
updated.delete(key);
|
|
127
|
+
} else {
|
|
128
|
+
updated.add(key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return updated;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getInitialExpanded(defaultExpanded?: "all" | Iterable<Key>): "all" | Set<Key> {
|
|
135
|
+
if (defaultExpanded === undefined) {
|
|
136
|
+
return new Set();
|
|
137
|
+
}
|
|
138
|
+
return convertExpanded(defaultExpanded);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function convertExpanded(expanded: "all" | Iterable<Key>): "all" | Set<Key> {
|
|
142
|
+
if (!expanded) {
|
|
143
|
+
return new Set<Key>();
|
|
144
|
+
}
|
|
145
|
+
return expanded === "all" ? "all" : new Set(expanded);
|
|
146
|
+
}
|
package/src/table/index.d.ts
CHANGED
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
* Table state management module.
|
|
3
3
|
* Provides state hooks for Table components.
|
|
4
4
|
*/
|
|
5
|
-
export { createTableState } from
|
|
6
|
-
export { TableCollection, createTableCollection } from
|
|
7
|
-
export type {
|
|
8
|
-
|
|
5
|
+
export { createTableState } from "./createTableState";
|
|
6
|
+
export { TableCollection, createTableCollection } from "./TableCollection";
|
|
7
|
+
export type {
|
|
8
|
+
TableState,
|
|
9
|
+
TableStateOptions,
|
|
10
|
+
TableCollection as ITableCollection,
|
|
11
|
+
SortDescriptor,
|
|
12
|
+
SortDirection,
|
|
13
|
+
Sortable,
|
|
14
|
+
ColumnDefinition,
|
|
15
|
+
RowDefinition,
|
|
16
|
+
TableCollectionOptions,
|
|
17
|
+
} from "./types";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/table/index.ts
CHANGED
|
@@ -3,16 +3,26 @@
|
|
|
3
3
|
* Provides state hooks for Table components.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export { createTableState } from
|
|
7
|
-
export {
|
|
6
|
+
export { createTableState } from "./createTableState";
|
|
7
|
+
export { createTreeGridState } from "./createTreeGridState";
|
|
8
|
+
export { createTableColumnResizeState } from "./createTableColumnResizeState";
|
|
9
|
+
export { TableCollection, createTableCollection } from "./TableCollection";
|
|
8
10
|
export type {
|
|
9
11
|
TableState,
|
|
10
12
|
TableStateOptions,
|
|
11
13
|
TableCollection as ITableCollection,
|
|
14
|
+
TreeGridState,
|
|
15
|
+
TreeGridStateOptions,
|
|
12
16
|
SortDescriptor,
|
|
13
17
|
SortDirection,
|
|
14
18
|
Sortable,
|
|
15
19
|
ColumnDefinition,
|
|
16
20
|
RowDefinition,
|
|
17
21
|
TableCollectionOptions,
|
|
18
|
-
} from
|
|
22
|
+
} from "./types";
|
|
23
|
+
export type {
|
|
24
|
+
ColumnSize,
|
|
25
|
+
ColumnResizeDefinition,
|
|
26
|
+
TableColumnResizeStateProps,
|
|
27
|
+
TableColumnResizeState,
|
|
28
|
+
} from "./createTableColumnResizeState";
|