@pretable/core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.cjs +455 -35
- package/dist/index.d.cts +198 -47
- package/dist/index.d.ts +198 -47
- package/dist/index.mjs +455 -35
- package/package.json +14 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Half-open row index range — `start` inclusive, `end` exclusive — used to
|
|
3
|
+
* describe the visible row window in {@link PretableGridSnapshot.visibleRange}.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
interface PretableRowRange {
|
|
2
8
|
start: number;
|
|
3
9
|
end: number;
|
|
4
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Tuning knobs for column autosize calculations.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
5
16
|
interface AutosizeOptions {
|
|
6
17
|
maxWidthPx?: number;
|
|
7
18
|
minWidthPx?: number;
|
|
@@ -9,9 +20,24 @@ interface AutosizeOptions {
|
|
|
9
20
|
cellPaddingPx?: number;
|
|
10
21
|
}
|
|
11
22
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Base row constraint — every row is at minimum a string-keyed record.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
type PretableRow = Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Sort direction — `null` means unsorted.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
type PretableSortDirection = "asc" | "desc" | null;
|
|
35
|
+
/**
|
|
36
|
+
* Engine-level column definition. `@pretable/react` extends this with React-specific render fields.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
interface PretableColumn<TRow extends PretableRow = PretableRow> {
|
|
15
41
|
id: string;
|
|
16
42
|
header?: string;
|
|
17
43
|
wrap?: boolean;
|
|
@@ -19,82 +45,207 @@ interface GridCoreColumn<TRow extends GridCoreRow = GridCoreRow> {
|
|
|
19
45
|
pinned?: "left";
|
|
20
46
|
sortable?: boolean;
|
|
21
47
|
filterable?: boolean;
|
|
22
|
-
|
|
48
|
+
value?: (row: TRow) => unknown;
|
|
49
|
+
format?: (input: PretableFormatInput<TRow>) => string;
|
|
50
|
+
minWidthPx?: number;
|
|
51
|
+
maxWidthPx?: number;
|
|
52
|
+
resizable?: boolean;
|
|
53
|
+
reorderable?: boolean;
|
|
23
54
|
}
|
|
24
|
-
|
|
25
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Input passed to a column's `format` function.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
interface PretableFormatInput<TRow extends PretableRow = PretableRow> {
|
|
61
|
+
value: unknown;
|
|
62
|
+
row: TRow;
|
|
63
|
+
column: PretableColumn<TRow>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options accepted by `createGrid`.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
interface PretableGridOptions<TRow extends PretableRow = PretableRow> {
|
|
71
|
+
columns: PretableColumn<TRow>[];
|
|
26
72
|
rows: TRow[];
|
|
27
73
|
getRowId?: (row: TRow, index: number) => string;
|
|
28
74
|
autosize?: boolean | AutosizeOptions;
|
|
29
75
|
}
|
|
30
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Active sort. `columnId` is null when no column is sorted.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface PretableSortState {
|
|
31
82
|
columnId: string | null;
|
|
32
|
-
direction:
|
|
83
|
+
direction: PretableSortDirection;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Cell address — the (rowId, columnId) pair that uniquely identifies a cell.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
interface PretableCellAddress {
|
|
91
|
+
rowId: string;
|
|
92
|
+
columnId: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Inclusive cell range — both bounds (start and end) are inside the selection.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
interface PretableCellRange {
|
|
100
|
+
startRowId: string;
|
|
101
|
+
endRowId: string;
|
|
102
|
+
startColumnId: string;
|
|
103
|
+
endColumnId: string;
|
|
33
104
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Cell-range selection state including the optional anchor for shift-extension.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
interface PretableSelectionState {
|
|
111
|
+
ranges: PretableCellRange[];
|
|
112
|
+
anchor: PretableCellAddress | null;
|
|
37
113
|
}
|
|
38
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Currently focused cell — both fields are null when nothing is focused.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
interface PretableFocusState {
|
|
39
120
|
rowId: string | null;
|
|
40
121
|
columnId: string | null;
|
|
41
122
|
}
|
|
42
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Viewport-level scroll + size state.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
interface PretableViewportState {
|
|
43
129
|
scrollTop: number;
|
|
44
130
|
scrollLeft: number;
|
|
45
131
|
height: number;
|
|
46
132
|
width: number;
|
|
47
133
|
}
|
|
48
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Streaming transaction — incremental row mutations applied via `PretableGrid.applyTransaction`.
|
|
136
|
+
*
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
interface PretableTransaction<TRow extends PretableRow = PretableRow> {
|
|
49
140
|
add?: TRow[];
|
|
50
141
|
update?: Partial<TRow>[];
|
|
51
142
|
remove?: string[];
|
|
52
143
|
}
|
|
53
|
-
|
|
144
|
+
/**
|
|
145
|
+
* A row currently in the visible window — includes its source-array index for stable identity.
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
interface PretableVisibleRow<TRow extends PretableRow = PretableRow> {
|
|
54
150
|
id: string;
|
|
55
151
|
row: TRow;
|
|
56
152
|
sourceIndex: number;
|
|
57
153
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Read-only state observed via `PretableGrid.getSnapshot`.
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
interface PretableGridSnapshot<TRow extends PretableRow = PretableRow> {
|
|
160
|
+
viewport: PretableViewportState;
|
|
161
|
+
sort: PretableSortState;
|
|
61
162
|
filters: Record<string, string>;
|
|
62
|
-
selection:
|
|
63
|
-
focus:
|
|
163
|
+
selection: PretableSelectionState;
|
|
164
|
+
focus: PretableFocusState;
|
|
64
165
|
totalRowCount: number;
|
|
65
|
-
visibleRows:
|
|
66
|
-
visibleRange:
|
|
166
|
+
visibleRows: PretableVisibleRow<TRow>[];
|
|
167
|
+
visibleRange: PretableRowRange;
|
|
67
168
|
}
|
|
68
|
-
|
|
69
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Direction passed to `PretableGrid.moveFocus`.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
type PretableFocusDirection = "up" | "down" | "left" | "right";
|
|
175
|
+
/**
|
|
176
|
+
* Optional behavior modifiers for `PretableGrid.moveFocus`.
|
|
177
|
+
*
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
interface PretableMoveFocusOptions {
|
|
181
|
+
extend?: boolean;
|
|
182
|
+
jumpToEdge?: boolean;
|
|
183
|
+
byPage?: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Per-row selection state — "selected" means fully, "indeterminate" means partial.
|
|
188
|
+
*
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
type PretableRowSelectionTriState = "selected" | "indeterminate";
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Public handle returned by {@link createGrid}. Exposes every action and
|
|
195
|
+
* observation pretable promises to support; does not extend the internal
|
|
196
|
+
* engine type, so private methods cannot leak through the public surface.
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
interface PretableGrid<TRow extends PretableRow = PretableRow> {
|
|
201
|
+
/** Discriminator — distinguishes `PretableGrid` from arbitrary objects. */
|
|
202
|
+
readonly kind: "pretable-grid";
|
|
203
|
+
/** The options the grid was constructed with. */
|
|
204
|
+
readonly options: PretableGridOptions<TRow>;
|
|
205
|
+
/** Subscribe to grid mutations. Returns an unsubscribe function. */
|
|
70
206
|
subscribe(listener: () => void): () => void;
|
|
71
|
-
|
|
72
|
-
|
|
207
|
+
/** Read the current snapshot. Stable reference until the next mutation. */
|
|
208
|
+
getSnapshot(): PretableGridSnapshot<TRow>;
|
|
209
|
+
setSort(columnId: string | null, direction: PretableSortDirection): void;
|
|
73
210
|
setFilter(columnId: string, value: string): void;
|
|
74
211
|
clearFilters(): void;
|
|
75
212
|
replaceFilters(nextFilters: Record<string, string>): void;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type PretableColumn<TRow extends PretableRow = PretableRow> = GridCoreColumn<TRow>;
|
|
87
|
-
type PretableGridOptions<TRow extends PretableRow = PretableRow> = GridCoreOptions<TRow>;
|
|
88
|
-
type PretableTransaction<TRow extends PretableRow = PretableRow> = GridCoreTransaction<TRow>;
|
|
89
|
-
interface PretableGrid<TRow extends PretableRow = PretableRow> extends Omit<GridCoreStore<TRow>, "options"> {
|
|
90
|
-
kind: "pretable-grid";
|
|
91
|
-
options: PretableGridOptions<TRow>;
|
|
92
|
-
getSnapshot(): GridCoreSnapshot<TRow>;
|
|
93
|
-
setSort(columnId: string | null, direction: GridCoreSortDirection): void;
|
|
213
|
+
setSelection(state: PretableSelectionState): void;
|
|
214
|
+
selectAll(): void;
|
|
215
|
+
clearSelection(): void;
|
|
216
|
+
addRange(range: PretableCellRange): void;
|
|
217
|
+
extendRangeFromAnchor(addr: PretableCellAddress): void;
|
|
218
|
+
toggleRowSelection(rowId: string): void;
|
|
219
|
+
setSelectAllVisible(checked: boolean): void;
|
|
220
|
+
setFocus(addr: PretableCellAddress | null): void;
|
|
221
|
+
moveFocus(direction: PretableFocusDirection, options?: PretableMoveFocusOptions): void;
|
|
222
|
+
setViewport(viewport: PretableViewportState): void;
|
|
94
223
|
autosizeColumns(options?: AutosizeOptions): void;
|
|
224
|
+
setColumnWidth(columnId: string, width: number): void;
|
|
225
|
+
moveColumn(columnId: string, toIndex: number): void;
|
|
226
|
+
setColumnPinned(columnId: string, pinned: "left" | null): void;
|
|
227
|
+
autosizeColumn(columnId: string, options?: AutosizeOptions): void;
|
|
228
|
+
resetColumnLayout(): void;
|
|
229
|
+
mergeColumnsFromProps(nextColumns: PretableColumn<TRow>[]): void;
|
|
95
230
|
applyTransaction(transaction: PretableTransaction<TRow>): void;
|
|
96
231
|
}
|
|
97
232
|
|
|
98
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Create a pretable grid instance. Returns a {@link PretableGrid} handle
|
|
235
|
+
* that exposes every action and observation pretable supports.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const grid = createGrid({
|
|
240
|
+
* columns: [{ id: "name" }, { id: "age" }],
|
|
241
|
+
* rows: [{ id: "1", name: "Ada", age: 36 }],
|
|
242
|
+
* });
|
|
243
|
+
* grid.setSort("age", "desc");
|
|
244
|
+
* const snapshot = grid.getSnapshot();
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
declare function createGrid<TRow extends PretableRow = PretableRow>(options: PretableGridOptions<TRow>): PretableGrid<TRow>;
|
|
99
250
|
|
|
100
|
-
export { type AutosizeOptions, type PretableColumn, type
|
|
251
|
+
export { type AutosizeOptions, type PretableCellAddress, type PretableCellRange, type PretableColumn, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGrid, type PretableGridOptions, type PretableGridSnapshot, type PretableMoveFocusOptions, type PretableRow, type PretableRowRange, type PretableRowSelectionTriState, type PretableSelectionState, type PretableSortDirection, type PretableSortState, type PretableTransaction, type PretableViewportState, type PretableVisibleRow, createGrid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Half-open row index range — `start` inclusive, `end` exclusive — used to
|
|
3
|
+
* describe the visible row window in {@link PretableGridSnapshot.visibleRange}.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
interface PretableRowRange {
|
|
2
8
|
start: number;
|
|
3
9
|
end: number;
|
|
4
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Tuning knobs for column autosize calculations.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
5
16
|
interface AutosizeOptions {
|
|
6
17
|
maxWidthPx?: number;
|
|
7
18
|
minWidthPx?: number;
|
|
@@ -9,9 +20,24 @@ interface AutosizeOptions {
|
|
|
9
20
|
cellPaddingPx?: number;
|
|
10
21
|
}
|
|
11
22
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Base row constraint — every row is at minimum a string-keyed record.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
type PretableRow = Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Sort direction — `null` means unsorted.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
type PretableSortDirection = "asc" | "desc" | null;
|
|
35
|
+
/**
|
|
36
|
+
* Engine-level column definition. `@pretable/react` extends this with React-specific render fields.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
interface PretableColumn<TRow extends PretableRow = PretableRow> {
|
|
15
41
|
id: string;
|
|
16
42
|
header?: string;
|
|
17
43
|
wrap?: boolean;
|
|
@@ -19,82 +45,207 @@ interface GridCoreColumn<TRow extends GridCoreRow = GridCoreRow> {
|
|
|
19
45
|
pinned?: "left";
|
|
20
46
|
sortable?: boolean;
|
|
21
47
|
filterable?: boolean;
|
|
22
|
-
|
|
48
|
+
value?: (row: TRow) => unknown;
|
|
49
|
+
format?: (input: PretableFormatInput<TRow>) => string;
|
|
50
|
+
minWidthPx?: number;
|
|
51
|
+
maxWidthPx?: number;
|
|
52
|
+
resizable?: boolean;
|
|
53
|
+
reorderable?: boolean;
|
|
23
54
|
}
|
|
24
|
-
|
|
25
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Input passed to a column's `format` function.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
interface PretableFormatInput<TRow extends PretableRow = PretableRow> {
|
|
61
|
+
value: unknown;
|
|
62
|
+
row: TRow;
|
|
63
|
+
column: PretableColumn<TRow>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options accepted by `createGrid`.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
interface PretableGridOptions<TRow extends PretableRow = PretableRow> {
|
|
71
|
+
columns: PretableColumn<TRow>[];
|
|
26
72
|
rows: TRow[];
|
|
27
73
|
getRowId?: (row: TRow, index: number) => string;
|
|
28
74
|
autosize?: boolean | AutosizeOptions;
|
|
29
75
|
}
|
|
30
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Active sort. `columnId` is null when no column is sorted.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface PretableSortState {
|
|
31
82
|
columnId: string | null;
|
|
32
|
-
direction:
|
|
83
|
+
direction: PretableSortDirection;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Cell address — the (rowId, columnId) pair that uniquely identifies a cell.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
interface PretableCellAddress {
|
|
91
|
+
rowId: string;
|
|
92
|
+
columnId: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Inclusive cell range — both bounds (start and end) are inside the selection.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
interface PretableCellRange {
|
|
100
|
+
startRowId: string;
|
|
101
|
+
endRowId: string;
|
|
102
|
+
startColumnId: string;
|
|
103
|
+
endColumnId: string;
|
|
33
104
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Cell-range selection state including the optional anchor for shift-extension.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
interface PretableSelectionState {
|
|
111
|
+
ranges: PretableCellRange[];
|
|
112
|
+
anchor: PretableCellAddress | null;
|
|
37
113
|
}
|
|
38
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Currently focused cell — both fields are null when nothing is focused.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
interface PretableFocusState {
|
|
39
120
|
rowId: string | null;
|
|
40
121
|
columnId: string | null;
|
|
41
122
|
}
|
|
42
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Viewport-level scroll + size state.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
interface PretableViewportState {
|
|
43
129
|
scrollTop: number;
|
|
44
130
|
scrollLeft: number;
|
|
45
131
|
height: number;
|
|
46
132
|
width: number;
|
|
47
133
|
}
|
|
48
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Streaming transaction — incremental row mutations applied via `PretableGrid.applyTransaction`.
|
|
136
|
+
*
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
interface PretableTransaction<TRow extends PretableRow = PretableRow> {
|
|
49
140
|
add?: TRow[];
|
|
50
141
|
update?: Partial<TRow>[];
|
|
51
142
|
remove?: string[];
|
|
52
143
|
}
|
|
53
|
-
|
|
144
|
+
/**
|
|
145
|
+
* A row currently in the visible window — includes its source-array index for stable identity.
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
interface PretableVisibleRow<TRow extends PretableRow = PretableRow> {
|
|
54
150
|
id: string;
|
|
55
151
|
row: TRow;
|
|
56
152
|
sourceIndex: number;
|
|
57
153
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Read-only state observed via `PretableGrid.getSnapshot`.
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
interface PretableGridSnapshot<TRow extends PretableRow = PretableRow> {
|
|
160
|
+
viewport: PretableViewportState;
|
|
161
|
+
sort: PretableSortState;
|
|
61
162
|
filters: Record<string, string>;
|
|
62
|
-
selection:
|
|
63
|
-
focus:
|
|
163
|
+
selection: PretableSelectionState;
|
|
164
|
+
focus: PretableFocusState;
|
|
64
165
|
totalRowCount: number;
|
|
65
|
-
visibleRows:
|
|
66
|
-
visibleRange:
|
|
166
|
+
visibleRows: PretableVisibleRow<TRow>[];
|
|
167
|
+
visibleRange: PretableRowRange;
|
|
67
168
|
}
|
|
68
|
-
|
|
69
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Direction passed to `PretableGrid.moveFocus`.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
type PretableFocusDirection = "up" | "down" | "left" | "right";
|
|
175
|
+
/**
|
|
176
|
+
* Optional behavior modifiers for `PretableGrid.moveFocus`.
|
|
177
|
+
*
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
interface PretableMoveFocusOptions {
|
|
181
|
+
extend?: boolean;
|
|
182
|
+
jumpToEdge?: boolean;
|
|
183
|
+
byPage?: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Per-row selection state — "selected" means fully, "indeterminate" means partial.
|
|
188
|
+
*
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
type PretableRowSelectionTriState = "selected" | "indeterminate";
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Public handle returned by {@link createGrid}. Exposes every action and
|
|
195
|
+
* observation pretable promises to support; does not extend the internal
|
|
196
|
+
* engine type, so private methods cannot leak through the public surface.
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
interface PretableGrid<TRow extends PretableRow = PretableRow> {
|
|
201
|
+
/** Discriminator — distinguishes `PretableGrid` from arbitrary objects. */
|
|
202
|
+
readonly kind: "pretable-grid";
|
|
203
|
+
/** The options the grid was constructed with. */
|
|
204
|
+
readonly options: PretableGridOptions<TRow>;
|
|
205
|
+
/** Subscribe to grid mutations. Returns an unsubscribe function. */
|
|
70
206
|
subscribe(listener: () => void): () => void;
|
|
71
|
-
|
|
72
|
-
|
|
207
|
+
/** Read the current snapshot. Stable reference until the next mutation. */
|
|
208
|
+
getSnapshot(): PretableGridSnapshot<TRow>;
|
|
209
|
+
setSort(columnId: string | null, direction: PretableSortDirection): void;
|
|
73
210
|
setFilter(columnId: string, value: string): void;
|
|
74
211
|
clearFilters(): void;
|
|
75
212
|
replaceFilters(nextFilters: Record<string, string>): void;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type PretableColumn<TRow extends PretableRow = PretableRow> = GridCoreColumn<TRow>;
|
|
87
|
-
type PretableGridOptions<TRow extends PretableRow = PretableRow> = GridCoreOptions<TRow>;
|
|
88
|
-
type PretableTransaction<TRow extends PretableRow = PretableRow> = GridCoreTransaction<TRow>;
|
|
89
|
-
interface PretableGrid<TRow extends PretableRow = PretableRow> extends Omit<GridCoreStore<TRow>, "options"> {
|
|
90
|
-
kind: "pretable-grid";
|
|
91
|
-
options: PretableGridOptions<TRow>;
|
|
92
|
-
getSnapshot(): GridCoreSnapshot<TRow>;
|
|
93
|
-
setSort(columnId: string | null, direction: GridCoreSortDirection): void;
|
|
213
|
+
setSelection(state: PretableSelectionState): void;
|
|
214
|
+
selectAll(): void;
|
|
215
|
+
clearSelection(): void;
|
|
216
|
+
addRange(range: PretableCellRange): void;
|
|
217
|
+
extendRangeFromAnchor(addr: PretableCellAddress): void;
|
|
218
|
+
toggleRowSelection(rowId: string): void;
|
|
219
|
+
setSelectAllVisible(checked: boolean): void;
|
|
220
|
+
setFocus(addr: PretableCellAddress | null): void;
|
|
221
|
+
moveFocus(direction: PretableFocusDirection, options?: PretableMoveFocusOptions): void;
|
|
222
|
+
setViewport(viewport: PretableViewportState): void;
|
|
94
223
|
autosizeColumns(options?: AutosizeOptions): void;
|
|
224
|
+
setColumnWidth(columnId: string, width: number): void;
|
|
225
|
+
moveColumn(columnId: string, toIndex: number): void;
|
|
226
|
+
setColumnPinned(columnId: string, pinned: "left" | null): void;
|
|
227
|
+
autosizeColumn(columnId: string, options?: AutosizeOptions): void;
|
|
228
|
+
resetColumnLayout(): void;
|
|
229
|
+
mergeColumnsFromProps(nextColumns: PretableColumn<TRow>[]): void;
|
|
95
230
|
applyTransaction(transaction: PretableTransaction<TRow>): void;
|
|
96
231
|
}
|
|
97
232
|
|
|
98
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Create a pretable grid instance. Returns a {@link PretableGrid} handle
|
|
235
|
+
* that exposes every action and observation pretable supports.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const grid = createGrid({
|
|
240
|
+
* columns: [{ id: "name" }, { id: "age" }],
|
|
241
|
+
* rows: [{ id: "1", name: "Ada", age: 36 }],
|
|
242
|
+
* });
|
|
243
|
+
* grid.setSort("age", "desc");
|
|
244
|
+
* const snapshot = grid.getSnapshot();
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
declare function createGrid<TRow extends PretableRow = PretableRow>(options: PretableGridOptions<TRow>): PretableGrid<TRow>;
|
|
99
250
|
|
|
100
|
-
export { type AutosizeOptions, type PretableColumn, type
|
|
251
|
+
export { type AutosizeOptions, type PretableCellAddress, type PretableCellRange, type PretableColumn, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGrid, type PretableGridOptions, type PretableGridSnapshot, type PretableMoveFocusOptions, type PretableRow, type PretableRowRange, type PretableRowSelectionTriState, type PretableSelectionState, type PretableSortDirection, type PretableSortState, type PretableTransaction, type PretableViewportState, type PretableVisibleRow, createGrid };
|