@svgrid/grid 1.1.0 → 1.1.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/dist/FlexRender.svelte +96 -96
- package/dist/GridMenus.svelte +205 -127
- package/dist/SvGrid.controller.svelte.d.ts +44 -1
- package/dist/SvGrid.controller.svelte.js +240 -44
- package/dist/SvGrid.css +325 -22
- package/dist/SvGrid.helpers.test.d.ts +1 -0
- package/dist/SvGrid.helpers.test.js +298 -0
- package/dist/SvGrid.svelte +729 -203
- package/dist/SvGrid.types.d.ts +91 -4
- package/dist/aligned-grids.d.ts +6 -0
- package/dist/aligned-grids.js +84 -0
- package/dist/aligned-grids.test.d.ts +1 -0
- package/dist/aligned-grids.test.js +75 -0
- package/dist/build-api.coverage.test.d.ts +20 -0
- package/dist/build-api.coverage.test.js +505 -0
- package/dist/build-api.js +61 -31
- package/dist/cell-render.test.d.ts +1 -0
- package/dist/cell-render.test.js +338 -0
- package/dist/cell-values.d.ts +1 -1
- package/dist/cell-values.js +7 -7
- package/dist/chart-export.test.d.ts +1 -0
- package/dist/chart-export.test.js +302 -0
- package/dist/chart.coverage.test.d.ts +1 -0
- package/dist/chart.coverage.test.js +748 -0
- package/dist/clipboard.js +88 -24
- package/dist/clipboard.test.d.ts +1 -0
- package/dist/clipboard.test.js +700 -0
- package/dist/collaboration.coverage.test.d.ts +1 -0
- package/dist/collaboration.coverage.test.js +200 -0
- package/dist/column-groups.d.ts +19 -0
- package/dist/column-groups.js +62 -0
- package/dist/column-groups.test.d.ts +1 -0
- package/dist/column-groups.test.js +56 -0
- package/dist/column-types.d.ts +10 -0
- package/dist/column-types.js +63 -0
- package/dist/column-types.test.d.ts +1 -0
- package/dist/column-types.test.js +62 -0
- package/dist/columns.test.d.ts +1 -0
- package/dist/columns.test.js +625 -0
- package/dist/core.d.ts +86 -1
- package/dist/core.js +2 -2
- package/dist/editing.d.ts +7 -0
- package/dist/editing.js +191 -5
- package/dist/editing.test.d.ts +1 -0
- package/dist/editing.test.js +732 -0
- package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
- package/dist/editors/cell-editors.coverage.test.js +139 -0
- package/dist/facet-buckets.test.d.ts +1 -0
- package/dist/facet-buckets.test.js +296 -0
- package/dist/filter-operators.test.d.ts +1 -0
- package/dist/filter-operators.test.js +135 -0
- package/dist/hyperformula-adapter.test.d.ts +1 -0
- package/dist/hyperformula-adapter.test.js +205 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -1
- package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
- package/dist/keyboard-handlers.coverage.test.js +495 -0
- package/dist/keyboard-handlers.js +7 -2
- package/dist/menus.js +1 -0
- package/dist/menus.test.d.ts +1 -0
- package/dist/menus.test.js +560 -0
- package/dist/named-views.coverage.test.d.ts +1 -0
- package/dist/named-views.coverage.test.js +180 -0
- package/dist/row-drag.d.ts +49 -0
- package/dist/row-drag.js +221 -0
- package/dist/row-drag.test.d.ts +1 -0
- package/dist/row-drag.test.js +142 -0
- package/dist/row-resize.test.d.ts +1 -0
- package/dist/row-resize.test.js +329 -0
- package/dist/scroll-sync.js +3 -0
- package/dist/scroll-sync.test.d.ts +1 -0
- package/dist/scroll-sync.test.js +290 -0
- package/dist/selection.d.ts +7 -1
- package/dist/selection.js +76 -36
- package/dist/selection.multi-range.test.d.ts +1 -0
- package/dist/selection.multi-range.test.js +55 -0
- package/dist/selection.test.d.ts +1 -0
- package/dist/selection.test.js +647 -0
- package/dist/server-data-source.coverage.test.d.ts +1 -0
- package/dist/server-data-source.coverage.test.js +154 -0
- package/dist/spreadsheet.d.ts +30 -0
- package/dist/spreadsheet.js +48 -0
- package/dist/spreadsheet.test.d.ts +1 -0
- package/dist/spreadsheet.test.js +446 -0
- package/dist/summaries.js +4 -4
- package/dist/sv-grid-scrollbar.js +13 -1
- package/dist/svgrid-wrapper.types.d.ts +19 -0
- package/dist/svgrid.behavior.test.js +20 -0
- package/dist/svgrid.interaction.test.js +31 -0
- package/dist/svgrid.new-features.wrapper.test.js +34 -2
- package/dist/test-setup.js +9 -3
- package/dist/virtualization/scroll-scaling.d.ts +17 -0
- package/dist/virtualization/scroll-scaling.js +35 -0
- package/dist/virtualization/scroll-scaling.test.js +42 -1
- package/package.json +2 -1
- package/src/FlexRender.svelte +96 -96
- package/src/GridMenus.svelte +205 -127
- package/src/SvGrid.controller.svelte.ts +204 -36
- package/src/SvGrid.css +277 -12
- package/src/SvGrid.svelte +727 -205
- package/src/SvGrid.types.ts +85 -4
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +59 -59
- package/src/aligned-grids.test.ts +80 -0
- package/src/aligned-grids.ts +87 -0
- package/src/build-api.ts +43 -23
- package/src/cell-formatting.ts +169 -169
- package/src/cell-values.ts +4 -4
- package/src/clipboard.test.ts +49 -0
- package/src/clipboard.ts +51 -23
- package/src/column-groups.test.ts +59 -0
- package/src/column-groups.ts +80 -0
- package/src/column-types.test.ts +68 -0
- package/src/column-types.ts +82 -0
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1077 -999
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/editing.ts +161 -5
- package/src/flex-render.ts +3 -3
- package/src/index.ts +208 -196
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/menus.ts +1 -0
- package/src/merge-objects.ts +48 -48
- package/src/render-component.ts +28 -28
- package/src/row-drag.test.ts +168 -0
- package/src/row-drag.ts +255 -0
- package/src/scroll-sync.ts +2 -0
- package/src/selection.multi-range.test.ts +61 -0
- package/src/selection.ts +71 -37
- package/src/spreadsheet.test.ts +46 -2
- package/src/spreadsheet.ts +58 -0
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/summaries.ts +4 -4
- package/src/svgrid-wrapper.types.ts +412 -393
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.new-features.wrapper.test.ts +2 -2
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/virtualization/column-virtualizer.test.ts +27 -27
- package/src/virtualization/column-virtualizer.ts +30 -30
- package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
- package/src/virtualization/types.ts +30 -30
- package/src/virtualization/virtualizer.test.ts +47 -47
- package/src/virtualization/virtualizer.ts +296 -296
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage-focused behavioral tests for the SvGridApi assembled in
|
|
3
|
+
* `build-api.ts`. The existing `svgrid.api.test.ts` / `svgrid.api-extensions
|
|
4
|
+
* .test.ts` cover filters, row selection, pagination, navigation, and
|
|
5
|
+
* getState/setState. This file exercises the remaining surface:
|
|
6
|
+
* - getCellValue / setCellValue
|
|
7
|
+
* - selectCells / getSelected
|
|
8
|
+
* - addRow(s) / removeRow(s) / applyTransaction
|
|
9
|
+
* - addColumn(s) / removeColumn / setColumnVisible / getColumns
|
|
10
|
+
* - setColumnWidth / setColumnPinning / setColumnOrder
|
|
11
|
+
* - setFacetFilter
|
|
12
|
+
* - undo / redo / canUndo / canRedo / clearHistory
|
|
13
|
+
* - find (open/close/query/hits)
|
|
14
|
+
* - grouping (setGroupBy / expandAllGroups / collapseAllGroups)
|
|
15
|
+
* - autosizeColumn / refresh
|
|
16
|
+
*
|
|
17
|
+
* All tests mount the real <SvGrid /> in jsdom and drive the api handed back
|
|
18
|
+
* from onApiReady.
|
|
19
|
+
*/
|
|
20
|
+
import { describe, expect, it } from "vitest";
|
|
21
|
+
import { mount, unmount } from "svelte";
|
|
22
|
+
import SvGrid from "./SvGrid.svelte";
|
|
23
|
+
import { columnFilteringFeature, columnGroupingFeature, rowExpandingFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, } from "./index";
|
|
24
|
+
const baseRows = [
|
|
25
|
+
{ id: 1, name: "Ada Lovelace", team: "Research", salary: 142000 },
|
|
26
|
+
{ id: 2, name: "Grace Hopper", team: "Compilers", salary: 158000 },
|
|
27
|
+
{ id: 3, name: "Alan Turing", team: "Research", salary: 138000 },
|
|
28
|
+
{ id: 4, name: "Margaret Hamilton", team: "Apollo", salary: 165000 },
|
|
29
|
+
{ id: 5, name: "Linus Torvalds", team: "Kernel", salary: 175000 },
|
|
30
|
+
];
|
|
31
|
+
const baseColumns = [
|
|
32
|
+
{ field: "name", header: "Name", width: 200 },
|
|
33
|
+
{ field: "team", header: "Team", width: 160 },
|
|
34
|
+
{ field: "salary", header: "Salary", width: 140 },
|
|
35
|
+
];
|
|
36
|
+
const flush = () => Promise.resolve();
|
|
37
|
+
function mountGrid(extraProps = {}, features = tableFeatures({
|
|
38
|
+
columnFilteringFeature,
|
|
39
|
+
rowSortingFeature,
|
|
40
|
+
rowSelectionFeature,
|
|
41
|
+
columnGroupingFeature,
|
|
42
|
+
rowExpandingFeature,
|
|
43
|
+
})) {
|
|
44
|
+
return new Promise((resolveApi, rejectApi) => {
|
|
45
|
+
const target = document.createElement("div");
|
|
46
|
+
document.body.appendChild(target);
|
|
47
|
+
let captured = null;
|
|
48
|
+
const app = mount(SvGrid, {
|
|
49
|
+
target,
|
|
50
|
+
props: {
|
|
51
|
+
data: baseRows.map((r) => ({ ...r })),
|
|
52
|
+
columns: baseColumns.map((c) => ({ ...c })),
|
|
53
|
+
features,
|
|
54
|
+
getRowId: (r) => String(r.id),
|
|
55
|
+
rowHeight: 36,
|
|
56
|
+
containerHeight: 480,
|
|
57
|
+
virtualization: false,
|
|
58
|
+
enableCellSelection: true,
|
|
59
|
+
onApiReady(api) {
|
|
60
|
+
captured = api;
|
|
61
|
+
resolveApi({
|
|
62
|
+
api,
|
|
63
|
+
target,
|
|
64
|
+
destroy: () => {
|
|
65
|
+
unmount(app);
|
|
66
|
+
target.remove();
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
...extraProps,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
queueMicrotask(() => {
|
|
74
|
+
if (!captured)
|
|
75
|
+
rejectApi(new Error("onApiReady never fired"));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
describe("SvGridApi - cell read / write", () => {
|
|
80
|
+
it("getCellValue reads through the column field", async () => {
|
|
81
|
+
const { api, destroy } = await mountGrid();
|
|
82
|
+
try {
|
|
83
|
+
expect(api.getCellValue(0, "name")).toBe("Ada Lovelace");
|
|
84
|
+
expect(api.getCellValue(3, "team")).toBe("Apollo");
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
destroy();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
it("getCellValue returns undefined for out-of-range row or unknown column", async () => {
|
|
91
|
+
const { api, destroy } = await mountGrid();
|
|
92
|
+
try {
|
|
93
|
+
expect(api.getCellValue(999, "name")).toBeUndefined();
|
|
94
|
+
expect(api.getCellValue(0, "nope")).toBeUndefined();
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
destroy();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
it("setCellValue writes a new immutable row and reads back", async () => {
|
|
101
|
+
const { api, destroy } = await mountGrid();
|
|
102
|
+
try {
|
|
103
|
+
api.setCellValue(0, "name", "Ada L.");
|
|
104
|
+
await flush();
|
|
105
|
+
expect(api.getCellValue(0, "name")).toBe("Ada L.");
|
|
106
|
+
// other rows untouched
|
|
107
|
+
expect(api.getCellValue(1, "name")).toBe("Grace Hopper");
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
destroy();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
it("setCellValue is a no-op for an invalid target", async () => {
|
|
114
|
+
const { api, destroy } = await mountGrid();
|
|
115
|
+
try {
|
|
116
|
+
expect(() => api.setCellValue(999, "name", "x")).not.toThrow();
|
|
117
|
+
expect(() => api.setCellValue(0, "unknown", "x")).not.toThrow();
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
destroy();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe("SvGridApi - cell selection", () => {
|
|
125
|
+
it("selectCells sets a rectangle; getSelected reads it back normalized", async () => {
|
|
126
|
+
const { api, destroy } = await mountGrid();
|
|
127
|
+
try {
|
|
128
|
+
api.selectCells([[2, 1, 0, 0]]); // unsorted corners
|
|
129
|
+
await flush();
|
|
130
|
+
expect(api.getSelected()).toEqual([[0, 0, 2, 1]]);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
destroy();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
it("selectCells clamps open-ended (Infinity) coordinates to grid bounds", async () => {
|
|
137
|
+
const { api, destroy } = await mountGrid();
|
|
138
|
+
try {
|
|
139
|
+
api.selectCells([[0, 0, Infinity, Infinity]]);
|
|
140
|
+
await flush();
|
|
141
|
+
// 5 rows (0..4), 3 cols (0..2)
|
|
142
|
+
expect(api.getSelected()).toEqual([[0, 0, 4, 2]]);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
destroy();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
it("empty selectCells clears the range; getSelected returns []", async () => {
|
|
149
|
+
const { api, destroy } = await mountGrid();
|
|
150
|
+
try {
|
|
151
|
+
api.selectCells([[0, 0, 1, 1]]);
|
|
152
|
+
await flush();
|
|
153
|
+
api.selectCells([]);
|
|
154
|
+
await flush();
|
|
155
|
+
expect(api.getSelected()).toEqual([]);
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
destroy();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("SvGridApi - row mutations", () => {
|
|
163
|
+
it("addRow appends to the bottom by default", async () => {
|
|
164
|
+
const { api, destroy } = await mountGrid();
|
|
165
|
+
try {
|
|
166
|
+
api.addRow({ id: 6, name: "New", team: "QA", salary: 1 });
|
|
167
|
+
await flush();
|
|
168
|
+
const data = api.getData();
|
|
169
|
+
expect(data.length).toBe(6);
|
|
170
|
+
expect(data[5].id).toBe(6);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
destroy();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
it("addRows at top / numeric index insert in place", async () => {
|
|
177
|
+
const { api, destroy } = await mountGrid();
|
|
178
|
+
try {
|
|
179
|
+
api.addRows([{ id: 7, name: "Top", team: "T", salary: 1 }], "top");
|
|
180
|
+
await flush();
|
|
181
|
+
expect(api.getData()[0].id).toBe(7);
|
|
182
|
+
api.addRows([{ id: 8, name: "Mid", team: "M", salary: 1 }], 2);
|
|
183
|
+
await flush();
|
|
184
|
+
expect(api.getData()[2].id).toBe(8);
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
destroy();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
it("removeRow / removeRows drop by index", async () => {
|
|
191
|
+
const { api, destroy } = await mountGrid();
|
|
192
|
+
try {
|
|
193
|
+
api.removeRow(0);
|
|
194
|
+
await flush();
|
|
195
|
+
expect(api.getData().map((r) => r.id)).toEqual([2, 3, 4, 5]);
|
|
196
|
+
api.removeRows([0, 2]); // drops ids 2 and 4
|
|
197
|
+
await flush();
|
|
198
|
+
expect(api.getData().map((r) => r.id)).toEqual([3, 5]);
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
destroy();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
it("applyTransaction adds, updates (by id), and removes; returns counts", async () => {
|
|
205
|
+
const { api, destroy } = await mountGrid();
|
|
206
|
+
try {
|
|
207
|
+
const result = api.applyTransaction({
|
|
208
|
+
add: [{ id: 9, name: "Added", team: "X", salary: 1 }],
|
|
209
|
+
update: [
|
|
210
|
+
{ id: 2, name: "Grace H.", team: "Compilers", salary: 999 },
|
|
211
|
+
],
|
|
212
|
+
remove: ["3"], // by getRowId string
|
|
213
|
+
});
|
|
214
|
+
await flush();
|
|
215
|
+
expect(result).toEqual({ added: 1, updated: 1, removed: 1 });
|
|
216
|
+
const data = api.getData();
|
|
217
|
+
expect(data.find((r) => r.id === 3)).toBeUndefined();
|
|
218
|
+
expect(data.find((r) => r.id === 2).salary).toBe(999);
|
|
219
|
+
expect(data.find((r) => r.id === 9)).toBeTruthy();
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
destroy();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
it("applyTransaction removes by object reference too", async () => {
|
|
226
|
+
const { api, destroy } = await mountGrid();
|
|
227
|
+
try {
|
|
228
|
+
const target = api.getData()[0];
|
|
229
|
+
const result = api.applyTransaction({ remove: [target] });
|
|
230
|
+
await flush();
|
|
231
|
+
expect(result.removed).toBe(1);
|
|
232
|
+
expect(api.getData().find((r) => r === target)).toBeUndefined();
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
destroy();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
describe("SvGridApi - column mutations", () => {
|
|
240
|
+
it("addColumn left / right / numeric position, then getColumns reflects it", async () => {
|
|
241
|
+
const { api, destroy } = await mountGrid();
|
|
242
|
+
try {
|
|
243
|
+
api.addColumn({ field: "id", header: "ID" }, "left");
|
|
244
|
+
await flush();
|
|
245
|
+
expect(api.getColumns()[0].id).toBe("id");
|
|
246
|
+
api.addColumns([{ field: "extra", header: "Extra" }], "right");
|
|
247
|
+
await flush();
|
|
248
|
+
const cols = api.getColumns();
|
|
249
|
+
expect(cols[cols.length - 1].id).toBe("extra");
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
destroy();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
it("removeColumn drops a column from the visible set", async () => {
|
|
256
|
+
const { api, destroy } = await mountGrid();
|
|
257
|
+
try {
|
|
258
|
+
api.removeColumn("team");
|
|
259
|
+
await flush();
|
|
260
|
+
expect(api.getColumns().find((c) => c.id === "team")).toBeUndefined();
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
destroy();
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
it("setColumnVisible toggles visibility; getColumns lists hidden as visible:false", async () => {
|
|
267
|
+
const { api, destroy } = await mountGrid();
|
|
268
|
+
try {
|
|
269
|
+
api.setColumnVisible("team", false);
|
|
270
|
+
await flush();
|
|
271
|
+
expect(api.isColumnVisible("team")).toBe(false);
|
|
272
|
+
const hidden = api.getColumns().find((c) => c.id === "team");
|
|
273
|
+
expect(hidden.visible).toBe(false);
|
|
274
|
+
api.setColumnVisible("team", true);
|
|
275
|
+
await flush();
|
|
276
|
+
expect(api.isColumnVisible("team")).toBe(true);
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
destroy();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
it("setColumnWidth clamps + getColumnWidths round-trips", async () => {
|
|
283
|
+
const { api, destroy } = await mountGrid();
|
|
284
|
+
try {
|
|
285
|
+
api.setColumnWidth("name", 333.7);
|
|
286
|
+
await flush();
|
|
287
|
+
expect(api.getColumnWidths().name).toBe(333);
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
destroy();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
it("setColumnPinning dedupes; getColumnPinning returns copies", async () => {
|
|
294
|
+
const { api, destroy } = await mountGrid();
|
|
295
|
+
try {
|
|
296
|
+
api.setColumnPinning({ left: ["name", "name"], right: ["salary"] });
|
|
297
|
+
await flush();
|
|
298
|
+
const pin = api.getColumnPinning();
|
|
299
|
+
expect(pin.left).toEqual(["name"]);
|
|
300
|
+
expect(pin.right).toEqual(["salary"]);
|
|
301
|
+
// mutating the returned copy doesn't affect internal state
|
|
302
|
+
pin.left.push("hacked");
|
|
303
|
+
expect(api.getColumnPinning().left).toEqual(["name"]);
|
|
304
|
+
}
|
|
305
|
+
finally {
|
|
306
|
+
destroy();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
it("setColumnOrder + getColumnOrder round-trip", async () => {
|
|
310
|
+
const { api, destroy } = await mountGrid();
|
|
311
|
+
try {
|
|
312
|
+
api.setColumnOrder(["salary", "name", "team"]);
|
|
313
|
+
await flush();
|
|
314
|
+
expect(api.getColumnOrder().slice(0, 3)).toEqual([
|
|
315
|
+
"salary",
|
|
316
|
+
"name",
|
|
317
|
+
"team",
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
destroy();
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
// Note: autosizeColumn / autosizeAllColumns are intentionally not asserted
|
|
325
|
+
// here - they measure text via real DOM layout (canvas/escape), which jsdom
|
|
326
|
+
// does not provide, so they throw in this environment. They are exercised by
|
|
327
|
+
// the demo gallery / Playwright suite per the coverage config notes.
|
|
328
|
+
});
|
|
329
|
+
describe("SvGridApi - facet filter", () => {
|
|
330
|
+
it("setFacetFilter narrows displayed rows; null clears it", async () => {
|
|
331
|
+
const { api, destroy } = await mountGrid();
|
|
332
|
+
try {
|
|
333
|
+
api.setFacetFilter("team", ["Research"]);
|
|
334
|
+
await flush();
|
|
335
|
+
const displayed = api.getDisplayedRows();
|
|
336
|
+
expect(displayed.every((r) => r.team === "Research")).toBe(true);
|
|
337
|
+
expect(displayed.length).toBe(2);
|
|
338
|
+
api.setFacetFilter("team", null);
|
|
339
|
+
await flush();
|
|
340
|
+
expect(api.getDisplayedRows().length).toBe(5);
|
|
341
|
+
}
|
|
342
|
+
finally {
|
|
343
|
+
destroy();
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
it("setFacetFilter with an empty array also clears", async () => {
|
|
347
|
+
const { api, destroy } = await mountGrid();
|
|
348
|
+
try {
|
|
349
|
+
api.setFacetFilter("team", ["Apollo"]);
|
|
350
|
+
await flush();
|
|
351
|
+
api.setFacetFilter("team", []);
|
|
352
|
+
await flush();
|
|
353
|
+
expect(api.getDisplayedRows().length).toBe(5);
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
destroy();
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
describe("SvGridApi - find", () => {
|
|
361
|
+
it("openFind / setFindQuery / getFindHits / closeFind", async () => {
|
|
362
|
+
const { api, destroy } = await mountGrid();
|
|
363
|
+
try {
|
|
364
|
+
api.openFind();
|
|
365
|
+
api.setFindQuery("Research");
|
|
366
|
+
await flush();
|
|
367
|
+
const hits = api.getFindHits();
|
|
368
|
+
expect(Array.isArray(hits)).toBe(true);
|
|
369
|
+
// two cells contain "Research"
|
|
370
|
+
expect(hits.length).toBeGreaterThanOrEqual(2);
|
|
371
|
+
api.closeFind();
|
|
372
|
+
await flush();
|
|
373
|
+
expect(api.getFindHits()).toEqual([]);
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
destroy();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
describe("SvGridApi - undo / redo / history", () => {
|
|
381
|
+
it("canUndo is false before any history; undo/redo are no-ops then", async () => {
|
|
382
|
+
const { api, destroy } = await mountGrid();
|
|
383
|
+
try {
|
|
384
|
+
expect(api.canUndo()).toBe(false);
|
|
385
|
+
expect(api.canRedo()).toBe(false);
|
|
386
|
+
expect(api.undo()).toBe(false);
|
|
387
|
+
expect(api.redo()).toBe(false);
|
|
388
|
+
}
|
|
389
|
+
finally {
|
|
390
|
+
destroy();
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
it("clearHistory resets the stacks without throwing", async () => {
|
|
394
|
+
const { api, destroy } = await mountGrid();
|
|
395
|
+
try {
|
|
396
|
+
expect(() => api.clearHistory()).not.toThrow();
|
|
397
|
+
expect(api.canUndo()).toBe(false);
|
|
398
|
+
expect(api.canRedo()).toBe(false);
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
destroy();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
describe("SvGridApi - grouping / expansion", () => {
|
|
406
|
+
it("setGroupBy groups rows; the underlying data is unchanged", async () => {
|
|
407
|
+
const { api, destroy } = await mountGrid();
|
|
408
|
+
try {
|
|
409
|
+
api.setGroupBy(["team"]);
|
|
410
|
+
await flush();
|
|
411
|
+
// Grouping reshapes the display pipeline; the source data is intact.
|
|
412
|
+
expect(api.getData().length).toBe(5);
|
|
413
|
+
expect(api.getState().grouping).toContain("team");
|
|
414
|
+
}
|
|
415
|
+
finally {
|
|
416
|
+
destroy();
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
it("expandAllGroups / collapseAllGroups run without error", async () => {
|
|
420
|
+
const { api, destroy } = await mountGrid();
|
|
421
|
+
try {
|
|
422
|
+
api.setGroupBy(["team"]);
|
|
423
|
+
await flush();
|
|
424
|
+
expect(() => api.expandAllGroups()).not.toThrow();
|
|
425
|
+
await flush();
|
|
426
|
+
expect(() => api.collapseAllGroups()).not.toThrow();
|
|
427
|
+
await flush();
|
|
428
|
+
// un-group
|
|
429
|
+
api.setGroupBy([]);
|
|
430
|
+
await flush();
|
|
431
|
+
expect(api.getData().length).toBe(5);
|
|
432
|
+
}
|
|
433
|
+
finally {
|
|
434
|
+
destroy();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
it("setRowExpanded toggles a row's expanded flag", async () => {
|
|
438
|
+
const { api, destroy } = await mountGrid();
|
|
439
|
+
try {
|
|
440
|
+
expect(() => api.setRowExpanded("1", true)).not.toThrow();
|
|
441
|
+
await flush();
|
|
442
|
+
expect(() => api.setRowExpanded("1", false)).not.toThrow();
|
|
443
|
+
}
|
|
444
|
+
finally {
|
|
445
|
+
destroy();
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
describe("SvGridApi - sort opt-out + refresh", () => {
|
|
450
|
+
it("setSort with a direction sets a single active clause", async () => {
|
|
451
|
+
const { api, destroy } = await mountGrid();
|
|
452
|
+
try {
|
|
453
|
+
api.setSort("salary", "asc");
|
|
454
|
+
await flush();
|
|
455
|
+
expect(api.getState().sorting).toEqual([{ id: "salary", desc: false }]);
|
|
456
|
+
api.setSort("name", "desc");
|
|
457
|
+
await flush();
|
|
458
|
+
// Setting a direction replaces the active sort clause.
|
|
459
|
+
expect(api.getState().sorting).toEqual([{ id: "name", desc: true }]);
|
|
460
|
+
}
|
|
461
|
+
finally {
|
|
462
|
+
destroy();
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
it("setSort with a falsy direction removes that column's clause", async () => {
|
|
466
|
+
const { api, destroy } = await mountGrid();
|
|
467
|
+
try {
|
|
468
|
+
api.setSort("salary", "asc");
|
|
469
|
+
await flush();
|
|
470
|
+
api.setSort("salary", null);
|
|
471
|
+
await flush();
|
|
472
|
+
expect(api.getState().sorting.find((s) => s.id === "salary")).toBeUndefined();
|
|
473
|
+
}
|
|
474
|
+
finally {
|
|
475
|
+
destroy();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
it("setSort is ignored for a non-sortable column", async () => {
|
|
479
|
+
const { api, destroy } = await mountGrid({
|
|
480
|
+
columns: [
|
|
481
|
+
{ field: "name", header: "Name", width: 200, sortable: false },
|
|
482
|
+
{ field: "team", header: "Team", width: 160 },
|
|
483
|
+
],
|
|
484
|
+
});
|
|
485
|
+
try {
|
|
486
|
+
api.setSort("name", "asc");
|
|
487
|
+
await flush();
|
|
488
|
+
expect(api.getState().sorting.find((s) => s.id === "name")).toBeUndefined();
|
|
489
|
+
}
|
|
490
|
+
finally {
|
|
491
|
+
destroy();
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
it("refresh re-runs the pipeline without throwing or losing data", async () => {
|
|
495
|
+
const { api, destroy } = await mountGrid();
|
|
496
|
+
try {
|
|
497
|
+
expect(() => api.refresh()).not.toThrow();
|
|
498
|
+
await flush();
|
|
499
|
+
expect(api.getData().length).toBe(5);
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
destroy();
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
});
|
package/dist/build-api.js
CHANGED
|
@@ -9,8 +9,8 @@ export function createGridApi(ctx) {
|
|
|
9
9
|
const column = findColumn(columnId);
|
|
10
10
|
if (!row || !column)
|
|
11
11
|
return undefined;
|
|
12
|
-
if (column.columnDef.
|
|
13
|
-
return column.columnDef.
|
|
12
|
+
if (column.columnDef.fieldFn)
|
|
13
|
+
return column.columnDef.fieldFn(row);
|
|
14
14
|
if (column.columnDef.field)
|
|
15
15
|
return row[column.columnDef.field];
|
|
16
16
|
return undefined;
|
|
@@ -24,42 +24,48 @@ export function createGridApi(ctx) {
|
|
|
24
24
|
next[rowIndex] = { ...row, [column.columnDef.field]: value };
|
|
25
25
|
ctx.internalData = next;
|
|
26
26
|
},
|
|
27
|
+
startEditing(rowIndex, columnId) {
|
|
28
|
+
return ctx.startEditing(rowIndex, columnId);
|
|
29
|
+
},
|
|
30
|
+
stopEditing(cancel) {
|
|
31
|
+
return ctx.stopEditing(cancel ?? false);
|
|
32
|
+
},
|
|
27
33
|
selectCells(ranges) {
|
|
28
|
-
//
|
|
29
|
-
// the first entry; ignore the rest. Empty array clears.
|
|
34
|
+
// Multiple rectangles are supported. Empty array clears everything.
|
|
30
35
|
if (!ranges || ranges.length === 0) {
|
|
31
36
|
ctx.selectionRange = { anchor: null, focus: null };
|
|
37
|
+
ctx.selectionRanges = [];
|
|
32
38
|
return;
|
|
33
39
|
}
|
|
34
|
-
const [r1, c1, r2, c2] = ranges[0];
|
|
35
40
|
const rowCount = ctx.internalData.length;
|
|
36
41
|
const colCount = ctx.allColumns.length;
|
|
37
42
|
if (rowCount === 0 || colCount === 0)
|
|
38
43
|
return;
|
|
39
44
|
// Clamp to the visible grid bounds so callers can pass open-ended
|
|
40
45
|
// values like `[0, 0, Infinity, Infinity]` to mean "select all".
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const toRange = ([r1, c1, r2, c2]) => ({
|
|
47
|
+
anchor: {
|
|
48
|
+
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.min(r1, r2))),
|
|
49
|
+
colIndex: Math.max(0, Math.min(colCount - 1, Math.min(c1, c2))),
|
|
50
|
+
},
|
|
51
|
+
focus: {
|
|
52
|
+
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.max(r1, r2))),
|
|
53
|
+
colIndex: Math.max(0, Math.min(colCount - 1, Math.max(c1, c2))),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const built = ranges.map(toRange);
|
|
57
|
+
// Last range is the active one; the rest are committed extras.
|
|
58
|
+
ctx.selectionRanges = built.slice(0, -1);
|
|
59
|
+
const active = built[built.length - 1];
|
|
60
|
+
ctx.selectionRange = active;
|
|
61
|
+
// Move the active cell to the last range's top-left so keyboard
|
|
50
62
|
// navigation continues from there.
|
|
51
|
-
ctx.setActiveCell(
|
|
63
|
+
ctx.setActiveCell(active.anchor.rowIndex, active.anchor.colIndex);
|
|
52
64
|
},
|
|
53
65
|
getSelected() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return [];
|
|
58
|
-
const r1 = Math.min(a.rowIndex, f.rowIndex);
|
|
59
|
-
const r2 = Math.max(a.rowIndex, f.rowIndex);
|
|
60
|
-
const c1 = Math.min(a.colIndex, f.colIndex);
|
|
61
|
-
const c2 = Math.max(a.colIndex, f.colIndex);
|
|
62
|
-
return [[r1, c1, r2, c2]];
|
|
66
|
+
return ctx
|
|
67
|
+
.getSelectionRects()
|
|
68
|
+
.map((r) => [r.minRow, r.minCol, r.maxRow, r.maxCol]);
|
|
63
69
|
},
|
|
64
70
|
addRow(row, position = "bottom") {
|
|
65
71
|
this.addRows([row], position);
|
|
@@ -190,6 +196,17 @@ export function createGridApi(ctx) {
|
|
|
190
196
|
...(filter.operator === "between"
|
|
191
197
|
? { valueTo: filter.valueTo ?? "" }
|
|
192
198
|
: {}),
|
|
199
|
+
// Optional second condition + join (multi-condition filtering).
|
|
200
|
+
...(filter.operator2
|
|
201
|
+
? {
|
|
202
|
+
operator2: filter.operator2,
|
|
203
|
+
value2: filter.value2 ?? "",
|
|
204
|
+
join: filter.join ?? "AND",
|
|
205
|
+
...(filter.operator2 === "between"
|
|
206
|
+
? { valueTo2: filter.valueTo2 ?? "" }
|
|
207
|
+
: {}),
|
|
208
|
+
}
|
|
209
|
+
: {}),
|
|
193
210
|
},
|
|
194
211
|
};
|
|
195
212
|
},
|
|
@@ -251,18 +268,31 @@ export function createGridApi(ctx) {
|
|
|
251
268
|
return ctx.internalData;
|
|
252
269
|
},
|
|
253
270
|
getColumns() {
|
|
254
|
-
// Snapshot every column
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
|
|
271
|
+
// Snapshot every column with its human-readable label and
|
|
272
|
+
// visibility flag. Used by external code (exporters, column
|
|
273
|
+
// pickers) so they don't have to re-walk the columnDef tree.
|
|
274
|
+
// Hidden columns ARE included (with `visible: false`) so a column
|
|
275
|
+
// picker can re-enable them - callers that only want what's
|
|
276
|
+
// rendered filter by `.visible` (e.g. the exporter does).
|
|
277
|
+
const describe = (c, visible) => ({
|
|
259
278
|
id: c.id,
|
|
260
279
|
field: c.columnDef.field,
|
|
261
280
|
header: typeof c.columnDef.header === "string"
|
|
262
281
|
? c.columnDef.header
|
|
263
282
|
: c.id,
|
|
264
|
-
visible
|
|
265
|
-
})
|
|
283
|
+
visible,
|
|
284
|
+
});
|
|
285
|
+
// Visible columns first, in their current visual order...
|
|
286
|
+
const out = ctx.allColumns.map((c) => describe(c, true));
|
|
287
|
+
// ...then any column hidden via `visible: false` / setColumnVisible.
|
|
288
|
+
// Those aren't in `allColumns` (that list is visible-only), so pull
|
|
289
|
+
// them straight from the engine's leaf set.
|
|
290
|
+
const visibleIds = new Set(out.map((c) => c.id));
|
|
291
|
+
for (const c of ctx.grid.getAllColumns()) {
|
|
292
|
+
if (!visibleIds.has(c.id))
|
|
293
|
+
out.push(describe(c, false));
|
|
294
|
+
}
|
|
295
|
+
return out;
|
|
266
296
|
},
|
|
267
297
|
clearRowSelection() {
|
|
268
298
|
// Wipe the internal selection map AND emit the change so any
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|