@svgrid/grid 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +137 -39
- package/dist/GridFooter.svelte +164 -0
- package/dist/GridFooter.svelte.d.ts +29 -0
- package/dist/GridMenus.svelte +648 -0
- package/dist/GridMenus.svelte.d.ts +31 -0
- package/dist/SvGrid.controller.svelte.d.ts +472 -0
- package/dist/SvGrid.controller.svelte.js +1917 -0
- package/dist/SvGrid.css +2012 -0
- package/dist/SvGrid.helpers.d.ts +35 -0
- package/dist/SvGrid.helpers.js +160 -0
- package/dist/SvGrid.helpers.test.d.ts +1 -0
- package/dist/SvGrid.helpers.test.js +298 -0
- package/dist/SvGrid.svelte +2346 -8742
- package/dist/SvGrid.svelte.d.ts +4 -357
- package/dist/SvGrid.types.d.ts +523 -0
- package/dist/SvGrid.types.js +1 -0
- package/dist/SvGridChart.svelte +1060 -23
- package/dist/SvGridChart.svelte.d.ts +17 -0
- 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.d.ts +5 -0
- package/dist/build-api.js +557 -0
- package/dist/cell-render.d.ts +15 -0
- package/dist/cell-render.js +246 -0
- package/dist/cell-render.test.d.ts +1 -0
- package/dist/cell-render.test.js +338 -0
- package/dist/cell-values.d.ts +28 -0
- package/dist/cell-values.js +89 -0
- 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/chart.d.ts +370 -3
- package/dist/chart.js +1135 -42
- package/dist/clipboard.d.ts +15 -0
- package/dist/clipboard.js +420 -0
- 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.d.ts +30 -0
- package/dist/columns.js +277 -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/css.d.ts +3 -0
- package/dist/editing.d.ts +31 -0
- package/dist/editing.js +529 -0
- 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/editors/cell-editors.d.ts +1 -1
- package/dist/facet-buckets.d.ts +13 -0
- package/dist/facet-buckets.js +54 -0
- package/dist/facet-buckets.test.d.ts +1 -0
- package/dist/facet-buckets.test.js +296 -0
- package/dist/features.d.ts +5 -0
- package/dist/features.js +30 -0
- package/dist/filter-operators.d.ts +16 -0
- package/dist/filter-operators.js +69 -0
- package/dist/filter-operators.test.d.ts +1 -0
- package/dist/filter-operators.test.js +135 -0
- package/dist/hyperformula-adapter.d.ts +82 -0
- package/dist/hyperformula-adapter.js +73 -0
- package/dist/hyperformula-adapter.test.d.ts +1 -0
- package/dist/hyperformula-adapter.test.js +205 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +8 -2
- package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
- package/dist/keyboard-handlers.coverage.test.js +495 -0
- package/dist/keyboard-handlers.d.ts +7 -0
- package/dist/keyboard-handlers.js +202 -0
- package/dist/menus.d.ts +40 -0
- package/dist/menus.js +390 -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/named-views.d.ts +27 -0
- package/dist/named-views.js +39 -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.d.ts +43 -0
- package/dist/row-resize.js +158 -0
- package/dist/row-resize.test.d.ts +1 -0
- package/dist/row-resize.test.js +329 -0
- package/dist/scroll-sync.d.ts +9 -0
- package/dist/scroll-sync.js +89 -0
- package/dist/scroll-sync.test.d.ts +1 -0
- package/dist/scroll-sync.test.js +290 -0
- package/dist/selection.d.ts +32 -0
- package/dist/selection.js +427 -0
- 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 +110 -0
- package/dist/spreadsheet.js +242 -0
- package/dist/spreadsheet.test.d.ts +1 -0
- package/dist/spreadsheet.test.js +446 -0
- package/dist/summaries.d.ts +12 -0
- package/dist/summaries.js +65 -0
- package/dist/sv-grid-scrollbar.js +13 -1
- package/dist/svgrid-wrapper.types.d.ts +31 -1
- package/dist/svgrid.behavior.test.js +20 -0
- package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
- package/dist/svgrid.comments-autocomplete.test.js +96 -0
- package/dist/svgrid.context-menu.test.d.ts +1 -0
- package/dist/svgrid.context-menu.test.js +102 -0
- package/dist/svgrid.interaction.test.js +31 -0
- package/dist/svgrid.new-features.wrapper.test.js +64 -6
- package/dist/svgrid.wrapper.test.js +27 -1
- package/dist/test-setup.js +9 -3
- package/dist/virtualization/column-virtualizer.d.ts +2 -0
- package/dist/virtualization/scroll-scaling.d.ts +45 -0
- package/dist/virtualization/scroll-scaling.js +99 -0
- package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
- package/dist/virtualization/scroll-scaling.test.js +127 -0
- package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
- package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
- package/dist/virtualization/virtualizer.d.ts +7 -0
- package/dist/virtualization/virtualizer.js +30 -0
- package/package.json +2 -1
- package/src/GridFooter.svelte +164 -0
- package/src/GridMenus.svelte +648 -0
- package/src/SvGrid.controller.svelte.ts +2352 -0
- package/src/SvGrid.css +2012 -0
- package/src/SvGrid.helpers.test.ts +415 -0
- package/src/SvGrid.helpers.ts +185 -0
- package/src/SvGrid.svelte +2346 -8742
- package/src/SvGrid.types.ts +537 -0
- package/src/SvGridChart.svelte +1060 -23
- package/src/aligned-grids.test.ts +80 -0
- package/src/aligned-grids.ts +87 -0
- package/src/build-api.coverage.test.ts +532 -0
- package/src/build-api.ts +683 -0
- package/src/cell-render.test.ts +451 -0
- package/src/cell-render.ts +426 -0
- package/src/cell-values.ts +114 -0
- package/src/chart-export.test.ts +370 -0
- package/src/chart.coverage.test.ts +814 -0
- package/src/chart.ts +1352 -47
- package/src/clipboard.test.ts +780 -0
- package/src/clipboard.ts +552 -0
- package/src/collaboration.coverage.test.ts +220 -0
- 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/columns.test.ts +702 -0
- package/src/columns.ts +419 -0
- package/src/core.ts +86 -0
- package/src/css.d.ts +3 -0
- package/src/editing.test.ts +837 -0
- package/src/editing.ts +669 -0
- package/src/editors/cell-editors.coverage.test.ts +156 -0
- package/src/editors/cell-editors.ts +1 -0
- package/src/facet-buckets.test.ts +353 -0
- package/src/facet-buckets.ts +67 -0
- package/src/features.ts +128 -0
- package/src/filter-operators.test.ts +174 -0
- package/src/filter-operators.ts +87 -0
- package/src/hyperformula-adapter.test.ts +256 -0
- package/src/hyperformula-adapter.ts +124 -0
- package/src/index.ts +49 -0
- package/src/keyboard-handlers.coverage.test.ts +560 -0
- package/src/keyboard-handlers.ts +353 -0
- package/src/keyboard.ts +97 -97
- package/src/menus.test.ts +620 -0
- package/src/menus.ts +555 -0
- package/src/named-views.coverage.test.ts +210 -0
- package/src/named-views.ts +48 -0
- package/src/row-drag.test.ts +168 -0
- package/src/row-drag.ts +255 -0
- package/src/row-resize.test.ts +369 -0
- package/src/row-resize.ts +171 -0
- package/src/scroll-sync.test.ts +330 -0
- package/src/scroll-sync.ts +218 -0
- package/src/selection.multi-range.test.ts +61 -0
- package/src/selection.test.ts +722 -0
- package/src/selection.ts +579 -0
- package/src/server-data-source.coverage.test.ts +180 -0
- package/src/spreadsheet.test.ts +489 -0
- package/src/spreadsheet.ts +304 -0
- package/src/summaries.ts +204 -0
- package/src/sv-grid-scrollbar.ts +13 -1
- package/src/svgrid-wrapper.types.ts +31 -1
- package/src/svgrid.behavior.test.ts +22 -0
- package/src/svgrid.comments-autocomplete.test.ts +112 -0
- package/src/svgrid.context-menu.test.ts +126 -0
- package/src/svgrid.interaction.test.ts +30 -0
- package/src/svgrid.new-features.wrapper.test.ts +67 -6
- package/src/svgrid.wrapper.test.ts +27 -1
- package/src/test-setup.ts +9 -6
- package/src/virtualization/scroll-scaling.test.ts +148 -0
- package/src/virtualization/scroll-scaling.ts +121 -0
- package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
- package/src/virtualization/virtualizer.ts +26 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { spreadsheetLayout, spansToMerges } from './spreadsheet';
|
|
3
|
+
// jsdom does not implement the global `CSS` object, which `findCell` uses via
|
|
4
|
+
// `CSS.escape`. Provide a minimal polyfill so the action's selector queries
|
|
5
|
+
// run. (A real browser ships CSS.escape; this is purely an env gap.)
|
|
6
|
+
if (typeof globalThis.CSS === 'undefined') {
|
|
7
|
+
// @ts-expect-error - minimal shim for the test environment
|
|
8
|
+
globalThis.CSS = { escape: (s) => s.replace(/["\\]/g, '\\$&') };
|
|
9
|
+
}
|
|
10
|
+
else if (typeof globalThis.CSS.escape !== 'function') {
|
|
11
|
+
// @ts-expect-error - augment partial CSS object
|
|
12
|
+
globalThis.CSS.escape = (s) => s.replace(/["\\]/g, '\\$&');
|
|
13
|
+
}
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/** Flush a queued requestAnimationFrame callback. The action batches its
|
|
18
|
+
* work into one rAF, so tests must advance a frame to observe the effect. */
|
|
19
|
+
function flushFrame() {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
// Two rAFs: the first lets any already-queued callback run, the second
|
|
22
|
+
// guarantees we resolve AFTER that callback has executed.
|
|
23
|
+
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Build a `<table>` with a header-less body of `rows` x `cols`. Each TD is
|
|
27
|
+
* tagged with `data-svgrid-row` (display index) + `data-col-id` exactly the
|
|
28
|
+
* way SvGrid emits them, which is what the layout helper queries on. */
|
|
29
|
+
function buildGrid(rows, columnOrder) {
|
|
30
|
+
const host = document.createElement('div');
|
|
31
|
+
const table = document.createElement('table');
|
|
32
|
+
const tbody = document.createElement('tbody');
|
|
33
|
+
for (let r = 0; r < rows; r += 1) {
|
|
34
|
+
const tr = document.createElement('tr');
|
|
35
|
+
for (const colId of columnOrder) {
|
|
36
|
+
const td = document.createElement('td');
|
|
37
|
+
td.setAttribute('data-svgrid-row', String(r));
|
|
38
|
+
td.setAttribute('data-col-id', colId);
|
|
39
|
+
td.textContent = `${colId}-${r}`;
|
|
40
|
+
tr.appendChild(td);
|
|
41
|
+
}
|
|
42
|
+
tbody.appendChild(tr);
|
|
43
|
+
}
|
|
44
|
+
table.appendChild(tbody);
|
|
45
|
+
host.appendChild(table);
|
|
46
|
+
document.body.appendChild(host);
|
|
47
|
+
const cellAt = (r, colId) => {
|
|
48
|
+
const el = host.querySelector(`td[data-svgrid-row="${r}"][data-col-id="${colId}"]`);
|
|
49
|
+
if (!el)
|
|
50
|
+
throw new Error(`no cell at row=${r} col=${colId}`);
|
|
51
|
+
return el;
|
|
52
|
+
};
|
|
53
|
+
return { host, cellAt };
|
|
54
|
+
}
|
|
55
|
+
let hosts = [];
|
|
56
|
+
function track(host) {
|
|
57
|
+
hosts.push(host);
|
|
58
|
+
return host;
|
|
59
|
+
}
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
hosts = [];
|
|
62
|
+
});
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
for (const h of hosts)
|
|
65
|
+
h.remove();
|
|
66
|
+
document.body.innerHTML = '';
|
|
67
|
+
});
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Merges
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
describe('spreadsheetLayout - merges', () => {
|
|
72
|
+
it('applies colspan + hides covered cells horizontally', async () => {
|
|
73
|
+
const cols = ['a', 'b', 'c'];
|
|
74
|
+
const { host, cellAt } = buildGrid(2, cols);
|
|
75
|
+
track(host);
|
|
76
|
+
const action = spreadsheetLayout(host, {
|
|
77
|
+
columnOrder: cols,
|
|
78
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
|
|
79
|
+
});
|
|
80
|
+
await flushFrame();
|
|
81
|
+
const origin = cellAt(0, 'a');
|
|
82
|
+
expect(origin.getAttribute('colspan')).toBe('2');
|
|
83
|
+
expect(origin.hasAttribute('rowspan')).toBe(false);
|
|
84
|
+
expect(origin.getAttribute('data-svgrid-sheet')).toBe('');
|
|
85
|
+
// Covered neighbour to the right is hidden + marked.
|
|
86
|
+
expect(cellAt(0, 'b').style.display).toBe('none');
|
|
87
|
+
expect(cellAt(0, 'b').getAttribute('data-svgrid-sheet')).toBe('');
|
|
88
|
+
// Untouched cells stay visible.
|
|
89
|
+
expect(cellAt(0, 'c').style.display).toBe('');
|
|
90
|
+
expect(cellAt(1, 'a').style.display).toBe('');
|
|
91
|
+
action.destroy();
|
|
92
|
+
});
|
|
93
|
+
it('applies rowspan + hides covered cells vertically', async () => {
|
|
94
|
+
const cols = ['a', 'b'];
|
|
95
|
+
const { host, cellAt } = buildGrid(3, cols);
|
|
96
|
+
track(host);
|
|
97
|
+
const action = spreadsheetLayout(host, {
|
|
98
|
+
columnOrder: cols,
|
|
99
|
+
merges: [{ rowIndex: 0, columnId: 'a', rowspan: 2 }],
|
|
100
|
+
});
|
|
101
|
+
await flushFrame();
|
|
102
|
+
const origin = cellAt(0, 'a');
|
|
103
|
+
expect(origin.getAttribute('rowspan')).toBe('2');
|
|
104
|
+
expect(origin.hasAttribute('colspan')).toBe(false);
|
|
105
|
+
expect(cellAt(1, 'a').style.display).toBe('none');
|
|
106
|
+
expect(cellAt(2, 'a').style.display).toBe(''); // outside the span
|
|
107
|
+
action.destroy();
|
|
108
|
+
});
|
|
109
|
+
it('handles a rectangular colspan + rowspan block', async () => {
|
|
110
|
+
const cols = ['a', 'b', 'c'];
|
|
111
|
+
const { host, cellAt } = buildGrid(3, cols);
|
|
112
|
+
track(host);
|
|
113
|
+
const action = spreadsheetLayout(host, {
|
|
114
|
+
columnOrder: cols,
|
|
115
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
|
|
116
|
+
});
|
|
117
|
+
await flushFrame();
|
|
118
|
+
expect(cellAt(0, 'a').getAttribute('colspan')).toBe('2');
|
|
119
|
+
expect(cellAt(0, 'a').getAttribute('rowspan')).toBe('2');
|
|
120
|
+
// All covered cells except the origin are hidden.
|
|
121
|
+
expect(cellAt(0, 'b').style.display).toBe('none');
|
|
122
|
+
expect(cellAt(1, 'a').style.display).toBe('none');
|
|
123
|
+
expect(cellAt(1, 'b').style.display).toBe('none');
|
|
124
|
+
// c column + row 2 untouched.
|
|
125
|
+
expect(cellAt(0, 'c').style.display).toBe('');
|
|
126
|
+
expect(cellAt(2, 'a').style.display).toBe('');
|
|
127
|
+
action.destroy();
|
|
128
|
+
});
|
|
129
|
+
it('clamps zero/negative span to a minimum of 1 (no colspan/rowspan attr)', async () => {
|
|
130
|
+
const cols = ['a', 'b'];
|
|
131
|
+
const { host, cellAt } = buildGrid(2, cols);
|
|
132
|
+
track(host);
|
|
133
|
+
const action = spreadsheetLayout(host, {
|
|
134
|
+
columnOrder: cols,
|
|
135
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 0, rowspan: -5 }],
|
|
136
|
+
});
|
|
137
|
+
await flushFrame();
|
|
138
|
+
const origin = cellAt(0, 'a');
|
|
139
|
+
// Clamped to 1, so no span attributes are written, but it is still marked.
|
|
140
|
+
expect(origin.hasAttribute('colspan')).toBe(false);
|
|
141
|
+
expect(origin.hasAttribute('rowspan')).toBe(false);
|
|
142
|
+
expect(origin.getAttribute('data-svgrid-sheet')).toBe('');
|
|
143
|
+
expect(cellAt(0, 'b').style.display).toBe(''); // nothing covered
|
|
144
|
+
action.destroy();
|
|
145
|
+
});
|
|
146
|
+
it('skips a merge whose columnId is not in columnOrder', async () => {
|
|
147
|
+
const cols = ['a', 'b'];
|
|
148
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
149
|
+
track(host);
|
|
150
|
+
const action = spreadsheetLayout(host, {
|
|
151
|
+
columnOrder: cols,
|
|
152
|
+
merges: [{ rowIndex: 0, columnId: 'ghost', colspan: 2 }],
|
|
153
|
+
});
|
|
154
|
+
await flushFrame();
|
|
155
|
+
expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
|
|
156
|
+
expect(cellAt(0, 'b').style.display).toBe('');
|
|
157
|
+
action.destroy();
|
|
158
|
+
});
|
|
159
|
+
it('skips a merge whose origin cell is not rendered', async () => {
|
|
160
|
+
const cols = ['a', 'b'];
|
|
161
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
162
|
+
track(host);
|
|
163
|
+
const action = spreadsheetLayout(host, {
|
|
164
|
+
columnOrder: cols,
|
|
165
|
+
merges: [{ rowIndex: 99, columnId: 'a', colspan: 2 }],
|
|
166
|
+
});
|
|
167
|
+
await flushFrame();
|
|
168
|
+
// Nothing marked anywhere.
|
|
169
|
+
expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
|
|
170
|
+
expect(cellAt(0, 'a').style.display).toBe('');
|
|
171
|
+
action.destroy();
|
|
172
|
+
});
|
|
173
|
+
it('ignores covered cells that fall outside the columnOrder or render window', async () => {
|
|
174
|
+
const cols = ['a', 'b'];
|
|
175
|
+
// Only 1 row rendered, but ask for a colspan that runs off the column
|
|
176
|
+
// list AND a rowspan that runs off the rendered rows.
|
|
177
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
178
|
+
track(host);
|
|
179
|
+
const action = spreadsheetLayout(host, {
|
|
180
|
+
columnOrder: cols,
|
|
181
|
+
merges: [{ rowIndex: 0, columnId: 'b', colspan: 3, rowspan: 3 }],
|
|
182
|
+
});
|
|
183
|
+
await flushFrame();
|
|
184
|
+
const origin = cellAt(0, 'b');
|
|
185
|
+
expect(origin.getAttribute('colspan')).toBe('3');
|
|
186
|
+
expect(origin.getAttribute('rowspan')).toBe('3');
|
|
187
|
+
// No sibling to the right of b, and rows 1/2 don't exist - so the only
|
|
188
|
+
// marked cell is the origin itself.
|
|
189
|
+
expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(1);
|
|
190
|
+
action.destroy();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// Selection-edge inheritance
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
describe('spreadsheetLayout - selection edge inheritance', () => {
|
|
197
|
+
it('mirrors range-right / range-bottom / selected-range flags onto the origin', async () => {
|
|
198
|
+
const cols = ['a', 'b'];
|
|
199
|
+
const { host, cellAt } = buildGrid(2, cols);
|
|
200
|
+
track(host);
|
|
201
|
+
// Mark the far covered cell with range edge flags BEFORE applying.
|
|
202
|
+
cellAt(1, 'b').setAttribute('data-range-right', 'true');
|
|
203
|
+
cellAt(1, 'b').setAttribute('data-range-bottom', 'true');
|
|
204
|
+
cellAt(0, 'b').setAttribute('data-selected-range', 'true');
|
|
205
|
+
const action = spreadsheetLayout(host, {
|
|
206
|
+
columnOrder: cols,
|
|
207
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
|
|
208
|
+
});
|
|
209
|
+
await flushFrame();
|
|
210
|
+
const origin = cellAt(0, 'a');
|
|
211
|
+
expect(origin.classList.contains('sv-merge-edge-right')).toBe(true);
|
|
212
|
+
expect(origin.classList.contains('sv-merge-edge-bottom')).toBe(true);
|
|
213
|
+
expect(origin.classList.contains('sv-merge-in-range')).toBe(true);
|
|
214
|
+
action.destroy();
|
|
215
|
+
});
|
|
216
|
+
it('leaves edge classes off when no range flags are present', async () => {
|
|
217
|
+
const cols = ['a', 'b'];
|
|
218
|
+
const { host, cellAt } = buildGrid(2, cols);
|
|
219
|
+
track(host);
|
|
220
|
+
const action = spreadsheetLayout(host, {
|
|
221
|
+
columnOrder: cols,
|
|
222
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: 2 }],
|
|
223
|
+
});
|
|
224
|
+
await flushFrame();
|
|
225
|
+
const origin = cellAt(0, 'a');
|
|
226
|
+
expect(origin.classList.contains('sv-merge-edge-right')).toBe(false);
|
|
227
|
+
expect(origin.classList.contains('sv-merge-edge-bottom')).toBe(false);
|
|
228
|
+
expect(origin.classList.contains('sv-merge-in-range')).toBe(false);
|
|
229
|
+
action.destroy();
|
|
230
|
+
});
|
|
231
|
+
it('treats the origin own selected-range flag as in-range', async () => {
|
|
232
|
+
const cols = ['a'];
|
|
233
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
234
|
+
track(host);
|
|
235
|
+
cellAt(0, 'a').setAttribute('data-selected-range', 'true');
|
|
236
|
+
const action = spreadsheetLayout(host, {
|
|
237
|
+
columnOrder: cols,
|
|
238
|
+
merges: [{ rowIndex: 0, columnId: 'a' }],
|
|
239
|
+
});
|
|
240
|
+
await flushFrame();
|
|
241
|
+
expect(cellAt(0, 'a').classList.contains('sv-merge-in-range')).toBe(true);
|
|
242
|
+
action.destroy();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// Borders
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
describe('spreadsheetLayout - borders', () => {
|
|
249
|
+
it('injects an overlay with the requested edge styles', async () => {
|
|
250
|
+
const cols = ['a'];
|
|
251
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
252
|
+
track(host);
|
|
253
|
+
const action = spreadsheetLayout(host, {
|
|
254
|
+
columnOrder: cols,
|
|
255
|
+
borders: [
|
|
256
|
+
{
|
|
257
|
+
rowIndex: 0,
|
|
258
|
+
columnId: 'a',
|
|
259
|
+
top: { width: 3, style: 'dashed', color: 'red' },
|
|
260
|
+
bottom: {}, // defaults: 2px solid currentColor
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
});
|
|
264
|
+
await flushFrame();
|
|
265
|
+
const td = cellAt(0, 'a');
|
|
266
|
+
const overlay = td.querySelector('.sv-cell-border-overlay');
|
|
267
|
+
expect(overlay).not.toBeNull();
|
|
268
|
+
expect(overlay.style.borderTop).toBe('3px dashed red');
|
|
269
|
+
// jsdom's CSSOM drops the `currentColor` keyword from the border
|
|
270
|
+
// shorthand, but the width + style survive, confirming the default
|
|
271
|
+
// (2px solid) edge was emitted.
|
|
272
|
+
expect(overlay.style.borderBottom).toContain('2px solid');
|
|
273
|
+
// No left/right set.
|
|
274
|
+
expect(overlay.style.borderLeft).toBe('');
|
|
275
|
+
expect(td.getAttribute('data-svgrid-sheet')).toBe('');
|
|
276
|
+
// The TD becomes a positioning context.
|
|
277
|
+
expect(td.style.position).toBe('relative');
|
|
278
|
+
action.destroy();
|
|
279
|
+
});
|
|
280
|
+
it('skips a border spec with no edges set (no overlay injected)', async () => {
|
|
281
|
+
const cols = ['a'];
|
|
282
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
283
|
+
track(host);
|
|
284
|
+
const action = spreadsheetLayout(host, {
|
|
285
|
+
columnOrder: cols,
|
|
286
|
+
borders: [{ rowIndex: 0, columnId: 'a' }],
|
|
287
|
+
});
|
|
288
|
+
await flushFrame();
|
|
289
|
+
expect(cellAt(0, 'a').querySelector('.sv-cell-border-overlay')).toBeNull();
|
|
290
|
+
expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
|
|
291
|
+
action.destroy();
|
|
292
|
+
});
|
|
293
|
+
it('skips a border spec whose target cell is absent', async () => {
|
|
294
|
+
const cols = ['a'];
|
|
295
|
+
const { host } = buildGrid(1, cols);
|
|
296
|
+
track(host);
|
|
297
|
+
const action = spreadsheetLayout(host, {
|
|
298
|
+
columnOrder: cols,
|
|
299
|
+
borders: [{ rowIndex: 5, columnId: 'a', top: { width: 1 } }],
|
|
300
|
+
});
|
|
301
|
+
await flushFrame();
|
|
302
|
+
expect(host.querySelectorAll('.sv-cell-border-overlay').length).toBe(0);
|
|
303
|
+
action.destroy();
|
|
304
|
+
});
|
|
305
|
+
it('does not override an already-positioned TD', async () => {
|
|
306
|
+
const cols = ['a'];
|
|
307
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
308
|
+
track(host);
|
|
309
|
+
cellAt(0, 'a').style.position = 'absolute';
|
|
310
|
+
const action = spreadsheetLayout(host, {
|
|
311
|
+
columnOrder: cols,
|
|
312
|
+
borders: [{ rowIndex: 0, columnId: 'a', left: { color: 'blue' } }],
|
|
313
|
+
});
|
|
314
|
+
await flushFrame();
|
|
315
|
+
expect(cellAt(0, 'a').style.position).toBe('absolute');
|
|
316
|
+
action.destroy();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
// Cleanup + update + destroy
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
describe('spreadsheetLayout - update + cleanup', () => {
|
|
323
|
+
it('clears prior decorations on the next apply (update path)', async () => {
|
|
324
|
+
const cols = ['a', 'b'];
|
|
325
|
+
const { host, cellAt } = buildGrid(2, cols);
|
|
326
|
+
track(host);
|
|
327
|
+
const action = spreadsheetLayout(host, {
|
|
328
|
+
columnOrder: cols,
|
|
329
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
|
|
330
|
+
borders: [{ rowIndex: 1, columnId: 'a', top: { width: 1 } }],
|
|
331
|
+
});
|
|
332
|
+
await flushFrame();
|
|
333
|
+
expect(cellAt(0, 'a').getAttribute('colspan')).toBe('2');
|
|
334
|
+
expect(cellAt(1, 'a').querySelector('.sv-cell-border-overlay')).not.toBeNull();
|
|
335
|
+
// Update to an empty spec - everything from the previous run is removed.
|
|
336
|
+
action.update({ columnOrder: cols, merges: [], borders: [] });
|
|
337
|
+
await flushFrame();
|
|
338
|
+
expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
|
|
339
|
+
expect(cellAt(0, 'b').style.display).toBe('');
|
|
340
|
+
expect(cellAt(0, 'a').hasAttribute('data-svgrid-sheet')).toBe(false);
|
|
341
|
+
expect(cellAt(1, 'a').querySelector('.sv-cell-border-overlay')).toBeNull();
|
|
342
|
+
action.destroy();
|
|
343
|
+
});
|
|
344
|
+
it('re-applies decorations when the grid body mutates (MutationObserver)', async () => {
|
|
345
|
+
const cols = ['a', 'b'];
|
|
346
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
347
|
+
track(host);
|
|
348
|
+
const action = spreadsheetLayout(host, {
|
|
349
|
+
columnOrder: cols,
|
|
350
|
+
merges: [{ rowIndex: 1, columnId: 'a', colspan: 2 }],
|
|
351
|
+
});
|
|
352
|
+
await flushFrame();
|
|
353
|
+
// Row 1 does not exist yet - nothing applied.
|
|
354
|
+
expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
|
|
355
|
+
// Simulate the grid rendering a new row -> observer schedules apply.
|
|
356
|
+
const tbody = host.querySelector('tbody');
|
|
357
|
+
const tr = document.createElement('tr');
|
|
358
|
+
for (const colId of cols) {
|
|
359
|
+
const td = document.createElement('td');
|
|
360
|
+
td.setAttribute('data-svgrid-row', '1');
|
|
361
|
+
td.setAttribute('data-col-id', colId);
|
|
362
|
+
tr.appendChild(td);
|
|
363
|
+
}
|
|
364
|
+
tbody.appendChild(tr);
|
|
365
|
+
await flushFrame();
|
|
366
|
+
await flushFrame();
|
|
367
|
+
expect(cellAt(1, 'a').getAttribute('colspan')).toBe('2');
|
|
368
|
+
action.destroy();
|
|
369
|
+
});
|
|
370
|
+
it('destroy disconnects the observer and cancels a pending frame', async () => {
|
|
371
|
+
const cols = ['a', 'b'];
|
|
372
|
+
const { host, cellAt } = buildGrid(1, cols);
|
|
373
|
+
track(host);
|
|
374
|
+
// Destroy immediately - the first scheduled frame is pending.
|
|
375
|
+
const action = spreadsheetLayout(host, {
|
|
376
|
+
columnOrder: cols,
|
|
377
|
+
merges: [{ rowIndex: 0, columnId: 'a', colspan: 2 }],
|
|
378
|
+
});
|
|
379
|
+
action.destroy();
|
|
380
|
+
await flushFrame();
|
|
381
|
+
await flushFrame();
|
|
382
|
+
// Frame was cancelled before apply ran.
|
|
383
|
+
expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
|
|
384
|
+
// After destroy, mutations no longer trigger apply.
|
|
385
|
+
const tbody = host.querySelector('tbody');
|
|
386
|
+
tbody.appendChild(document.createElement('tr'));
|
|
387
|
+
await flushFrame();
|
|
388
|
+
await flushFrame();
|
|
389
|
+
expect(cellAt(0, 'a').hasAttribute('colspan')).toBe(false);
|
|
390
|
+
});
|
|
391
|
+
it('treats null merges / borders as empty (no throw)', async () => {
|
|
392
|
+
const cols = ['a'];
|
|
393
|
+
const { host } = buildGrid(1, cols);
|
|
394
|
+
track(host);
|
|
395
|
+
const opts = {
|
|
396
|
+
columnOrder: cols,
|
|
397
|
+
merges: null,
|
|
398
|
+
borders: null,
|
|
399
|
+
};
|
|
400
|
+
const action = spreadsheetLayout(host, opts);
|
|
401
|
+
await flushFrame();
|
|
402
|
+
expect(host.querySelectorAll('[data-svgrid-sheet]').length).toBe(0);
|
|
403
|
+
action.destroy();
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
describe('spansToMerges - declarative colSpan/rowSpan -> MergeSpec[]', () => {
|
|
407
|
+
const rows = [
|
|
408
|
+
{ region: 'AMER', q: 'Q1', amt: 1 },
|
|
409
|
+
{ region: 'AMER', q: 'Q2', amt: 2 },
|
|
410
|
+
{ region: 'AMER', q: 'Q3', amt: 3 },
|
|
411
|
+
{ region: 'EMEA', q: 'Q1', amt: 4 },
|
|
412
|
+
{ region: 'EMEA', q: 'Q2', amt: 5 },
|
|
413
|
+
];
|
|
414
|
+
// Merge each run of equal `region` values downward.
|
|
415
|
+
function regionRowSpan() {
|
|
416
|
+
return ({ data, rowIndex }) => {
|
|
417
|
+
if (rowIndex > 0 && rows[rowIndex - 1].region === data.region)
|
|
418
|
+
return 1; // covered
|
|
419
|
+
let n = 1;
|
|
420
|
+
while (rows[rowIndex + n]?.region === data.region)
|
|
421
|
+
n += 1;
|
|
422
|
+
return n;
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
it('emits a rowspan merge at each run origin and skips covered rows', () => {
|
|
426
|
+
const columns = [{ id: 'region', field: 'region', rowSpan: regionRowSpan() }];
|
|
427
|
+
const merges = spansToMerges(rows, columns);
|
|
428
|
+
// AMER spans rows 0..2 (rowspan 3), EMEA spans rows 3..4 (rowspan 2).
|
|
429
|
+
expect(merges).toEqual([
|
|
430
|
+
{ rowIndex: 0, columnId: 'region', colspan: undefined, rowspan: 3 },
|
|
431
|
+
{ rowIndex: 3, columnId: 'region', colspan: undefined, rowspan: 2 },
|
|
432
|
+
]);
|
|
433
|
+
});
|
|
434
|
+
it('supports colSpan and marks covered columns', () => {
|
|
435
|
+
const columns = [
|
|
436
|
+
{ id: 'a', field: 'region', colSpan: ({ rowIndex }) => (rowIndex === 0 ? 2 : 1) },
|
|
437
|
+
{ id: 'b', field: 'q' },
|
|
438
|
+
{ id: 'c', field: 'amt' },
|
|
439
|
+
];
|
|
440
|
+
const merges = spansToMerges(rows.slice(0, 1), columns);
|
|
441
|
+
expect(merges).toEqual([{ rowIndex: 0, columnId: 'a', colspan: 2, rowspan: undefined }]);
|
|
442
|
+
});
|
|
443
|
+
it('returns no merges when no column defines spans', () => {
|
|
444
|
+
expect(spansToMerges(rows, [{ id: 'region', field: 'region' }])).toEqual([]);
|
|
445
|
+
});
|
|
446
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Column, type Row, type RowData, type TableFeatures } from "./index";
|
|
2
|
+
import "./sv-grid-scrollbar";
|
|
3
|
+
export declare function createSummaries<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
|
|
4
|
+
computeSummaries: (rows: ReadonlyArray<Row<TData>>, columns: ReadonlyArray<Column<TData>>) => Record<string, string>;
|
|
5
|
+
hasRenderedColumn: (entry: {
|
|
6
|
+
item: (typeof ctx.renderedColumnItems)[number];
|
|
7
|
+
column: (typeof ctx.allColumns)[number] | undefined;
|
|
8
|
+
}) => entry is {
|
|
9
|
+
item: (typeof ctx.renderedColumnItems)[number];
|
|
10
|
+
column: (typeof ctx.allColumns)[number];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import "./sv-grid-scrollbar";
|
|
2
|
+
import { getCellKey, } from "./SvGrid.helpers";
|
|
3
|
+
import { formatSummaryNumeric, } from "./cell-values";
|
|
4
|
+
export function createSummaries(ctx) {
|
|
5
|
+
/**
|
|
6
|
+
* Aggregate every row into a per-column footer summary (sum for numeric
|
|
7
|
+
* columns, `Count: N` otherwise). This loop is the hottest path on a
|
|
8
|
+
* large grid - it is rows x columns iterations - so two things keep the
|
|
9
|
+
* constant factor down:
|
|
10
|
+
*
|
|
11
|
+
* 1. The edited-cell overlay is only consulted when an edit actually
|
|
12
|
+
* exists. `key in editedCellValues` hits a reactive-proxy `has`
|
|
13
|
+
* trap for every cell otherwise - 5M no-op trap calls on a
|
|
14
|
+
* 100k x 50 grid. Skipping it when the map is empty is the single
|
|
15
|
+
* biggest win here.
|
|
16
|
+
* 2. The column's accessor (`accessorFn` / `field`) is resolved once
|
|
17
|
+
* per column, not re-read off `columnDef` for every cell.
|
|
18
|
+
*/
|
|
19
|
+
function computeSummaries(rows, columns) {
|
|
20
|
+
const summary = {};
|
|
21
|
+
const rowCount = rows.length;
|
|
22
|
+
const hasEdits = Object.keys(ctx.editedCellValues).length > 0;
|
|
23
|
+
for (const column of columns) {
|
|
24
|
+
const def = column.columnDef;
|
|
25
|
+
const accessorFn = def.accessorFn;
|
|
26
|
+
const field = def.field;
|
|
27
|
+
const columnId = column.id;
|
|
28
|
+
let numericSum = 0;
|
|
29
|
+
let numericCount = 0;
|
|
30
|
+
for (let i = 0; i < rowCount; i += 1) {
|
|
31
|
+
const row = rows[i];
|
|
32
|
+
let value;
|
|
33
|
+
const base = accessorFn
|
|
34
|
+
? accessorFn(row.original)
|
|
35
|
+
: field
|
|
36
|
+
? row.original[field]
|
|
37
|
+
: row.getCellValueByColumnId(columnId);
|
|
38
|
+
if (hasEdits) {
|
|
39
|
+
const key = getCellKey(row.id, columnId);
|
|
40
|
+
value = key in ctx.editedCellValues ? ctx.editedCellValues[key] : base;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
value = base;
|
|
44
|
+
}
|
|
45
|
+
const asNumber = Number(value);
|
|
46
|
+
if (Number.isFinite(asNumber)) {
|
|
47
|
+
numericSum += asNumber;
|
|
48
|
+
numericCount += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
summary[columnId] =
|
|
52
|
+
numericCount > 0
|
|
53
|
+
? formatSummaryNumeric(column, numericSum)
|
|
54
|
+
: `Count: ${rowCount}`;
|
|
55
|
+
}
|
|
56
|
+
return summary;
|
|
57
|
+
}
|
|
58
|
+
function hasRenderedColumn(entry) {
|
|
59
|
+
return entry.column !== undefined;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
computeSummaries,
|
|
63
|
+
hasRenderedColumn,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -30,7 +30,11 @@ const STYLE_TEMPLATE = `
|
|
|
30
30
|
display: flex;
|
|
31
31
|
user-select: none;
|
|
32
32
|
background: var(--sg-scrollbar-bg, #eef2f8);
|
|
33
|
-
|
|
33
|
+
/* The 1px separator is drawn on the INNER edge only (the edge facing
|
|
34
|
+
the grid body) via the orientation rules below. A full inset box
|
|
35
|
+
here doubled up with the grid's own frame border on the outer edge,
|
|
36
|
+
reading as a 2px border - most visible in dense-gridline themes
|
|
37
|
+
like Excel, which should show a single 1px line. */
|
|
34
38
|
/* Start hidden + non-interactive - viewport/content sizes are 0 until
|
|
35
39
|
after the first layout pass, so without this default the scrollbar
|
|
36
40
|
paints visible for one frame and then JS hides it on mount. That
|
|
@@ -44,10 +48,18 @@ const STYLE_TEMPLATE = `
|
|
|
44
48
|
:host([orientation="vertical"]) {
|
|
45
49
|
flex-direction: column;
|
|
46
50
|
width: ${ARROW_SIZE}px;
|
|
51
|
+
/* LTR: vertical scrollbar sits at the right, inner edge is the left. */
|
|
52
|
+
box-shadow: inset 1px 0 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
|
|
53
|
+
}
|
|
54
|
+
:host([orientation="vertical"]:dir(rtl)) {
|
|
55
|
+
/* RTL flips the scrollbar to the left, so the inner edge is the right. */
|
|
56
|
+
box-shadow: inset -1px 0 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
|
|
47
57
|
}
|
|
48
58
|
:host([orientation="horizontal"]) {
|
|
49
59
|
flex-direction: row;
|
|
50
60
|
height: ${ARROW_SIZE}px;
|
|
61
|
+
/* Horizontal scrollbar sits at the bottom, inner edge is the top. */
|
|
62
|
+
box-shadow: inset 0 1px 0 0 var(--sg-scrollbar-border, rgba(15, 23, 42, 0.04));
|
|
51
63
|
}
|
|
52
64
|
.arrow {
|
|
53
65
|
flex: none;
|
|
@@ -58,6 +58,16 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
|
|
|
58
58
|
getCellValue(rowIndex: number, columnId: string): unknown;
|
|
59
59
|
/** Write a cell value through the column's field. */
|
|
60
60
|
setCellValue(rowIndex: number, columnId: string, value: unknown): void;
|
|
61
|
+
/**
|
|
62
|
+
* Programmatically begin editing a cell (as a double-click would). Returns
|
|
63
|
+
* `true` if editing started (cell exists, editable, editing enabled).
|
|
64
|
+
*/
|
|
65
|
+
startEditing(rowIndex: number, columnId: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Commit (default) or, with `cancel: true`, discard the active edit.
|
|
68
|
+
* Returns `true` if there was an edit in progress.
|
|
69
|
+
*/
|
|
70
|
+
stopEditing(cancel?: boolean): boolean;
|
|
61
71
|
/**
|
|
62
72
|
* Programmatically select one or more rectangular cell ranges. Each
|
|
63
73
|
* range is `[rowStart, colStart, rowEnd, colEnd]` in 0-indexed grid
|
|
@@ -105,6 +115,15 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
|
|
|
105
115
|
value?: string;
|
|
106
116
|
/** Upper bound for the `between` operator. Required when `operator === 'between'`. */
|
|
107
117
|
valueTo?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Optional SECOND condition on the same column, joined by `join`
|
|
120
|
+
* (multi-condition filtering, e.g. "> 100 AND < 500").
|
|
121
|
+
*/
|
|
122
|
+
operator2?: SvGridFilterOperator;
|
|
123
|
+
value2?: string;
|
|
124
|
+
valueTo2?: string;
|
|
125
|
+
/** How to combine the two conditions. Defaults to `'AND'`. */
|
|
126
|
+
join?: 'AND' | 'OR';
|
|
108
127
|
} | null): void;
|
|
109
128
|
/**
|
|
110
129
|
* Set the facet (set-list, Excel-style multi-select) filter for a column.
|
|
@@ -164,6 +183,15 @@ export type SvGridApi<TFeatures extends TableFeatures, TData extends RowData> =
|
|
|
164
183
|
* default. Useful for "save view" + URL persistence.
|
|
165
184
|
*/
|
|
166
185
|
getColumnWidths(): Record<string, number>;
|
|
186
|
+
/**
|
|
187
|
+
* Snap one column's width to its widest visible cell (header text +
|
|
188
|
+
* any rendered body cell). Equivalent to double-clicking the column's
|
|
189
|
+
* resize handle. The grid also exposes this through the column menu's
|
|
190
|
+
* "Autosize" item.
|
|
191
|
+
*/
|
|
192
|
+
autosizeColumn(columnId: string): void;
|
|
193
|
+
/** Run `autosizeColumn` on every column. */
|
|
194
|
+
autosizeAllColumns(): void;
|
|
167
195
|
/**
|
|
168
196
|
* Replace the column-pinning state in one call. Each entry is a
|
|
169
197
|
* column id; the order in the array becomes the visible order along
|
|
@@ -325,7 +353,9 @@ export type SvGridWrapperProps<TFeatures extends TableFeatures, TData extends Ro
|
|
|
325
353
|
showRowSelection?: boolean;
|
|
326
354
|
showPagination?: boolean;
|
|
327
355
|
virtualization?: boolean;
|
|
328
|
-
|
|
356
|
+
/** Row height in pixels. Pass a function `(rowIndex) => px` for per-row
|
|
357
|
+
* variable heights (e.g. when wiring up an interactive row-resize). */
|
|
358
|
+
rowHeight?: number | ((rowIndex: number) => number);
|
|
329
359
|
overscan?: number;
|
|
330
360
|
containerHeight?: number;
|
|
331
361
|
columnVirtualization?: boolean;
|
|
@@ -389,6 +389,26 @@ describe('SvGrid - column add / remove / visibility', () => {
|
|
|
389
389
|
destroy();
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
|
+
it('columns marked `visible: false` start hidden but stay listed', async () => {
|
|
393
|
+
const columns = personColumns.map((c) => (c.field === 'team' ? { ...c, visible: false } : c));
|
|
394
|
+
const { api, destroy } = await mountGrid({ columns });
|
|
395
|
+
try {
|
|
396
|
+
// Starts hidden...
|
|
397
|
+
expect(api.isColumnVisible('team')).toBe(false);
|
|
398
|
+
// ...but is still listed in getColumns() (so a Choose Columns UI
|
|
399
|
+
// can offer it), just with visible=false.
|
|
400
|
+
const team = api.getColumns().find((c) => c.id === 'team');
|
|
401
|
+
expect(team).toBeDefined();
|
|
402
|
+
expect(team?.visible).toBe(false);
|
|
403
|
+
// A later user toggle wins over the initial flag.
|
|
404
|
+
api.setColumnVisible('team', true);
|
|
405
|
+
await tick();
|
|
406
|
+
expect(api.isColumnVisible('team')).toBe(true);
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
destroy();
|
|
410
|
+
}
|
|
411
|
+
});
|
|
392
412
|
});
|
|
393
413
|
describe('SvGrid - row add / remove', () => {
|
|
394
414
|
it('addRow at top / bottom / specific index', async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|