@operato/data-grist 10.29.50 → 10.29.51
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/CHANGELOG.md +9 -0
- package/dist/src/data-grid/data-grid.d.ts +2 -1
- package/dist/src/data-grid/data-grid.js +2 -2
- package/dist/src/data-grid/data-grid.js.map +1 -1
- package/dist/src/data-manipulator.d.ts +5 -1
- package/dist/src/data-manipulator.js +10 -5
- package/dist/src/data-manipulator.js.map +1 -1
- package/dist/src/gutters/gutter-row-selector.js +6 -1
- package/dist/src/gutters/gutter-row-selector.js.map +1 -1
- package/dist/src/handlers/select-row-toggle.d.ts +1 -1
- package/dist/src/handlers/select-row-toggle.js +7 -3
- package/dist/src/handlers/select-row-toggle.js.map +1 -1
- package/dist/src/utils/select-range.d.ts +17 -0
- package/dist/src/utils/select-range.js +20 -0
- package/dist/src/utils/select-range.js.map +1 -0
- package/dist/test/shift-range-select.test.d.ts +1 -0
- package/dist/test/shift-range-select.test.js +100 -0
- package/dist/test/shift-range-select.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/test/shift-range-select.test.ts +112 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */
|
|
2
|
+
import { expect, fixture } from '@open-wc/testing';
|
|
3
|
+
import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';
|
|
4
|
+
import { html } from 'lit';
|
|
5
|
+
import '../src/data-grist.js';
|
|
6
|
+
import { selectionChange } from '../src/utils/select-range.js';
|
|
7
|
+
const settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
describe('selection by range', () => {
|
|
9
|
+
const rows = () => Array.from({ length: 6 }, (_, i) => ({ id: String(i) }));
|
|
10
|
+
it('a plain click names its rows and becomes the anchor', () => {
|
|
11
|
+
const records = rows();
|
|
12
|
+
expect(selectionChange(records, { added: [records[2]] })).to.deep.equal({ on: [records[2]], off: [], anchor: records[2] });
|
|
13
|
+
});
|
|
14
|
+
it('a shift-click gives every row from the anchor the clicked row’s new state, either way round', () => {
|
|
15
|
+
const records = rows();
|
|
16
|
+
expect(selectionChange(records, { added: [records[4]], range: true }, records[1]).on.map(one => one.id)).to.deep.equal(['1', '2', '3', '4']);
|
|
17
|
+
expect(selectionChange(records, { added: [records[0]], range: true }, records[3]).on.map(one => one.id)).to.deep.equal(['0', '1', '2', '3']);
|
|
18
|
+
expect(selectionChange(records, { removed: [records[5]], range: true }, records[2]).off.map(one => one.id)).to.deep.equal(['2', '3', '4', '5']);
|
|
19
|
+
});
|
|
20
|
+
it('without an anchor in the rows a shift-click is a plain click', () => {
|
|
21
|
+
const records = rows();
|
|
22
|
+
expect(selectionChange(records, { added: [records[3]], range: true }).on).to.deep.equal([records[3]]);
|
|
23
|
+
expect(selectionChange(records, { added: [records[3]], range: true }, { id: 'read before' }).on).to.deep.equal([records[3]]);
|
|
24
|
+
});
|
|
25
|
+
describe('on a grid', () => {
|
|
26
|
+
const ignoreResizeLoop = (e) => {
|
|
27
|
+
if (String(e.message).includes('ResizeObserver loop')) {
|
|
28
|
+
e.stopImmediatePropagation();
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
let previousOnError = null;
|
|
33
|
+
before(() => {
|
|
34
|
+
window.addEventListener('error', ignoreResizeLoop, true);
|
|
35
|
+
previousOnError = window.onerror;
|
|
36
|
+
window.onerror = (message, ...rest) => String(message).includes('ResizeObserver loop') ? true : previousOnError === null || previousOnError === void 0 ? void 0 : previousOnError.call(window, message, ...rest);
|
|
37
|
+
});
|
|
38
|
+
after(async function () {
|
|
39
|
+
this.timeout(10000);
|
|
40
|
+
await settle(300);
|
|
41
|
+
window.removeEventListener('error', ignoreResizeLoop, true);
|
|
42
|
+
window.onerror = previousOnError;
|
|
43
|
+
await resetMouse();
|
|
44
|
+
});
|
|
45
|
+
const grid = async (rowClick) => {
|
|
46
|
+
const records = Array.from({ length: 8 }, (_, i) => ({ id: String(i), name: 'row ' + i }));
|
|
47
|
+
const el = (await fixture(html `
|
|
48
|
+
<ox-grist
|
|
49
|
+
style="display: flex; width: 500px; height: 400px"
|
|
50
|
+
mode="GRID"
|
|
51
|
+
.config=${{
|
|
52
|
+
rows: { appendable: false, selectable: { multiple: true }, ...(rowClick ? { handlers: { click: 'select-row-toggle' } } : {}) },
|
|
53
|
+
columns: [
|
|
54
|
+
{ type: 'gutter', gutterName: 'row-selector', multiple: true },
|
|
55
|
+
{ type: 'string', name: 'name', header: 'name', width: 200 }
|
|
56
|
+
],
|
|
57
|
+
pagination: { pages: [100] }
|
|
58
|
+
}}
|
|
59
|
+
.fetchHandler=${async () => ({ total: records.length, records })}
|
|
60
|
+
></ox-grist>
|
|
61
|
+
`));
|
|
62
|
+
await el.fetch();
|
|
63
|
+
await settle();
|
|
64
|
+
const grist = el.renderRoot.querySelector('#grist');
|
|
65
|
+
const body = grist.renderRoot.querySelector('ox-grid-body');
|
|
66
|
+
await body.updateComplete;
|
|
67
|
+
const row = (index) => body.renderRoot.querySelectorAll('div[grid-row]')[index];
|
|
68
|
+
const click = async (target, shift = false) => {
|
|
69
|
+
const box = target.getBoundingClientRect();
|
|
70
|
+
if (shift)
|
|
71
|
+
await sendKeys({ down: 'Shift' });
|
|
72
|
+
await sendMouse({ type: 'click', position: [Math.round(box.left + box.width / 2), Math.round(box.top + box.height / 2)] });
|
|
73
|
+
if (shift)
|
|
74
|
+
await sendKeys({ up: 'Shift' });
|
|
75
|
+
await settle();
|
|
76
|
+
};
|
|
77
|
+
return { el, row, click };
|
|
78
|
+
};
|
|
79
|
+
it('shift-click on a checkbox selects the rows between', async function () {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
81
|
+
this.timeout(10000);
|
|
82
|
+
const { el, row, click } = await grid(false);
|
|
83
|
+
await click((_b = (_a = row(1).querySelector('ox-grid-field').shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('input')) !== null && _b !== void 0 ? _b : row(1).querySelector('input'));
|
|
84
|
+
await click((_d = (_c = row(4).querySelector('ox-grid-field').shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('input')) !== null && _d !== void 0 ? _d : row(4).querySelector('input'), true);
|
|
85
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['1', '2', '3', '4']);
|
|
86
|
+
});
|
|
87
|
+
it('shift-click on a cell of a row-click grid selects the rows between, and clears them the same way', async function () {
|
|
88
|
+
this.timeout(10000);
|
|
89
|
+
const { el, row, click } = await grid(true);
|
|
90
|
+
const cell = (index) => row(index).querySelectorAll('ox-grid-field')[1];
|
|
91
|
+
await click(cell(5));
|
|
92
|
+
await click(cell(2), true);
|
|
93
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['2', '3', '4', '5']);
|
|
94
|
+
await click(cell(3));
|
|
95
|
+
await click(cell(5), true);
|
|
96
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['2']);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=shift-range-select.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift-range-select.test.js","sourceRoot":"","sources":["../../test/shift-range-select.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAS9D,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAA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,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */\nimport { expect, fixture } from '@open-wc/testing'\nimport { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands'\nimport { html } from 'lit'\n\nimport '../src/data-grist.js'\nimport { selectionChange } from '../src/utils/select-range.js'\n\n/**\n * Shift-click selects a range, as a list does: the rows from the last one clicked to the clicked one take its new\n * state - from a row's checkbox and, on a grid whose row click toggles selection, from any cell of the row.\n */\n\ntype Root = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }\n\nconst settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms))\n\ndescribe('selection by range', () => {\n const rows = () => Array.from({ length: 6 }, (_, i) => ({ id: String(i) }))\n\n it('a plain click names its rows and becomes the anchor', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[2]] })).to.deep.equal({ on: [records[2]], off: [], anchor: records[2] })\n })\n it('a shift-click gives every row from the anchor the clicked row’s new state, either way round', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[4]], range: true }, records[1]).on.map(one => one.id)).to.deep.equal(['1', '2', '3', '4'])\n expect(selectionChange(records, { added: [records[0]], range: true }, records[3]).on.map(one => one.id)).to.deep.equal(['0', '1', '2', '3'])\n expect(selectionChange(records, { removed: [records[5]], range: true }, records[2]).off.map(one => one.id)).to.deep.equal(['2', '3', '4', '5'])\n })\n it('without an anchor in the rows a shift-click is a plain click', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[3]], range: true }).on).to.deep.equal([records[3]])\n expect(selectionChange(records, { added: [records[3]], range: true }, { id: 'read before' }).on).to.deep.equal([records[3]])\n })\n\n describe('on a grid', () => {\n const ignoreResizeLoop = (e: ErrorEvent) => {\n if (String(e.message).includes('ResizeObserver loop')) {\n e.stopImmediatePropagation()\n e.preventDefault()\n }\n }\n let previousOnError: OnErrorEventHandler = null\n before(() => {\n window.addEventListener('error', ignoreResizeLoop, true)\n previousOnError = window.onerror\n window.onerror = (message, ...rest) =>\n String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest)\n })\n after(async function () {\n this.timeout(10000)\n await settle(300)\n window.removeEventListener('error', ignoreResizeLoop, true)\n window.onerror = previousOnError\n await resetMouse()\n })\n\n const grid = async (rowClick: boolean) => {\n const records = Array.from({ length: 8 }, (_, i) => ({ id: String(i), name: 'row ' + i }))\n const el = (await fixture(html`\n <ox-grist\n style=\"display: flex; width: 500px; height: 400px\"\n mode=\"GRID\"\n .config=${{\n rows: { appendable: false, selectable: { multiple: true }, ...(rowClick ? { handlers: { click: 'select-row-toggle' } } : {}) },\n columns: [\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n { type: 'string', name: 'name', header: 'name', width: 200 }\n ],\n pagination: { pages: [100] }\n }}\n .fetchHandler=${async () => ({ total: records.length, records })}\n ></ox-grist>\n `)) as Root & { fetch(): Promise<void>; selected: any[] }\n await el.fetch()\n await settle()\n const grist = el.renderRoot.querySelector('#grist') as Root\n const body = grist.renderRoot.querySelector('ox-grid-body') as Root\n await body.updateComplete\n const row = (index: number) => body.renderRoot.querySelectorAll('div[grid-row]')[index] as HTMLElement\n const click = async (target: HTMLElement, shift = false) => {\n const box = target.getBoundingClientRect()\n if (shift) await sendKeys({ down: 'Shift' })\n await sendMouse({ type: 'click', position: [Math.round(box.left + box.width / 2), Math.round(box.top + box.height / 2)] })\n if (shift) await sendKeys({ up: 'Shift' })\n await settle()\n }\n return { el, row, click }\n }\n\n it('shift-click on a checkbox selects the rows between', async function () {\n this.timeout(10000)\n const { el, row, click } = await grid(false)\n await click(row(1).querySelector('ox-grid-field')!.shadowRoot?.querySelector('input') ?? (row(1).querySelector('input') as HTMLElement))\n await click(row(4).querySelector('ox-grid-field')!.shadowRoot?.querySelector('input') ?? (row(4).querySelector('input') as HTMLElement), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['1', '2', '3', '4'])\n })\n\n it('shift-click on a cell of a row-click grid selects the rows between, and clears them the same way', async function () {\n this.timeout(10000)\n const { el, row, click } = await grid(true)\n const cell = (index: number) => row(index).querySelectorAll('ox-grid-field')[1] as HTMLElement\n await click(cell(5))\n await click(cell(2), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['2', '3', '4', '5'])\n await click(cell(3))\n await click(cell(5), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['2'])\n })\n })\n})\n"]}
|