@operato/data-grist 10.29.68 → 10.29.70

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/src/data-card/data-card-gutter.js +3 -15
  3. package/dist/src/data-card/data-card-gutter.js.map +1 -1
  4. package/dist/src/data-consumer.d.ts +4 -1
  5. package/dist/src/data-consumer.js.map +1 -1
  6. package/dist/src/data-grid/data-grid-accum-field.js +2 -0
  7. package/dist/src/data-grid/data-grid-accum-field.js.map +1 -1
  8. package/dist/src/data-grid/data-grid-body-style.js +2 -0
  9. package/dist/src/data-grid/data-grid-body-style.js.map +1 -1
  10. package/dist/src/data-grid/data-grid-field.js +7 -12
  11. package/dist/src/data-grid/data-grid-field.js.map +1 -1
  12. package/dist/src/data-grid/data-grid-header.js +7 -1
  13. package/dist/src/data-grid/data-grid-header.js.map +1 -1
  14. package/dist/src/data-grid/data-grid.d.ts +1 -1
  15. package/dist/src/data-grid/data-grid.js +44 -18
  16. package/dist/src/data-grid/data-grid.js.map +1 -1
  17. package/dist/src/data-grist.d.ts +5 -1
  18. package/dist/src/data-grist.js +3 -0
  19. package/dist/src/data-grist.js.map +1 -1
  20. package/dist/src/data-list/data-list-gutter.js +3 -0
  21. package/dist/src/data-list/data-list-gutter.js.map +1 -1
  22. package/dist/src/data-provider.d.ts +2 -0
  23. package/dist/src/data-provider.js +28 -9
  24. package/dist/src/data-provider.js.map +1 -1
  25. package/dist/src/data-report/data-report-header.js +10 -11
  26. package/dist/src/data-report/data-report-header.js.map +1 -1
  27. package/dist/src/editors/ox-grist-editor-select.js +8 -1
  28. package/dist/src/editors/ox-grist-editor-select.js.map +1 -1
  29. package/dist/src/filters/filter-select-buttons.js +3 -1
  30. package/dist/src/filters/filter-select-buttons.js.map +1 -1
  31. package/dist/src/filters/filters-form.d.ts +2 -0
  32. package/dist/src/filters/filters-form.js +5 -0
  33. package/dist/src/filters/filters-form.js.map +1 -1
  34. package/dist/src/types.d.ts +7 -0
  35. package/dist/src/types.js.map +1 -1
  36. package/dist/test/count-handler.test.d.ts +1 -0
  37. package/dist/test/count-handler.test.js +56 -0
  38. package/dist/test/count-handler.test.js.map +1 -0
  39. package/dist/test/destructive-actions.test.d.ts +11 -0
  40. package/dist/test/destructive-actions.test.js +147 -0
  41. package/dist/test/destructive-actions.test.js.map +1 -0
  42. package/dist/test/flexible-columns.test.d.ts +1 -0
  43. package/dist/test/flexible-columns.test.js +134 -0
  44. package/dist/test/flexible-columns.test.js.map +1 -0
  45. package/dist/test/request-generation.test.js +15 -0
  46. package/dist/test/request-generation.test.js.map +1 -1
  47. package/dist/test/select-empty-value.test.d.ts +1 -0
  48. package/dist/test/select-empty-value.test.js +61 -0
  49. package/dist/test/select-empty-value.test.js.map +1 -0
  50. package/dist/test/wheel-one-scroller.test.d.ts +2 -0
  51. package/dist/test/wheel-one-scroller.test.js +275 -0
  52. package/dist/test/wheel-one-scroller.test.js.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +9 -9
  55. package/test/count-handler.test.ts +61 -0
  56. package/test/destructive-actions.test.ts +137 -0
  57. package/test/flexible-columns.test.ts +181 -0
  58. package/test/request-generation.test.ts +16 -0
  59. package/test/select-empty-value.test.ts +71 -0
  60. package/test/wheel-one-scroller.test.ts +359 -0
@@ -0,0 +1,147 @@
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { sendMouse } from '@web/test-runner-commands';
3
+ import { css, html, LitElement } from 'lit';
4
+ import { ButtonStyles, ButtonContainerStyles, CommonHeaderStyles } from '@operato/styles';
5
+ import '@material/web/icon/icon.js';
6
+ import '@material/web/button/filled-button.js';
7
+ import '@material/web/button/filled-tonal-button.js';
8
+ import '@material/web/button/elevated-button.js';
9
+ import '@material/web/button/outlined-button.js';
10
+ import '@material/web/button/text-button.js';
11
+ import '@material/web/chips/assist-chip.js';
12
+ import '@operato/popup/ox-popup-actions.js';
13
+ import '../src/data-grid/data-grid-field.js';
14
+ import '../src/data-card/data-card-gutter.js';
15
+ import '../src/data-list/data-list-gutter.js';
16
+ class BodyProbe extends LitElement {
17
+ render() { var _a; return (_a = this.content) !== null && _a !== void 0 ? _a : html `<button type="button" danger><md-icon>delete</md-icon>Delete</button>`; }
18
+ }
19
+ BodyProbe.properties = { content: { attribute: false } };
20
+ BodyProbe.styles = [ButtonStyles, css `:host { display: block }`];
21
+ class BarProbe extends BodyProbe {
22
+ }
23
+ BarProbe.styles = [ButtonContainerStyles];
24
+ class HeaderProbe extends BodyProbe {
25
+ render() { return html `<div class="header"><div class="actions"><button type="button" danger class="textbtn"><md-icon>delete</md-icon>Delete</button></div></div>`; }
26
+ }
27
+ HeaderProbe.styles = [CommonHeaderStyles];
28
+ customElements.define('danger-body-probe', BodyProbe);
29
+ customElements.define('danger-bar-probe', BarProbe);
30
+ customElements.define('danger-header-probe', HeaderProbe);
31
+ const column = { type: 'gutter', name: 'delete', danger: true, record: { renderer: () => html `<button type="button"><md-icon>delete</md-icon><span>Delete</span></button>` } };
32
+ const cases = [
33
+ ['form', html `<danger-body-probe></danger-body-probe>`],
34
+ ['quiet form', html `<danger-body-probe .content=${html `<button type="button" quiet danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],
35
+ ['raised form', html `<danger-body-probe .content=${html `<button type="button" raised danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],
36
+ ['toolbar', html `<danger-bar-probe></danger-bar-probe>`],
37
+ ['header', html `<danger-header-probe></danger-header-probe>`],
38
+ ['grid', html `<ox-grid-field danger .column=${column}></ox-grid-field>`],
39
+ ['card', html `<ox-card-gutter .column=${column}></ox-card-gutter>`],
40
+ ['mobile list', html `<ox-list-gutter .column=${column}></ox-list-gutter>`],
41
+ ['filled', html `<danger-body-probe .content=${html `<md-filled-button danger><md-icon slot="icon">delete</md-icon>Delete</md-filled-button>`}></danger-body-probe>`],
42
+ ['tonal', html `<danger-body-probe .content=${html `<md-filled-tonal-button danger><md-icon slot="icon">delete</md-icon>Delete</md-filled-tonal-button>`}></danger-body-probe>`],
43
+ ['elevated', html `<danger-body-probe .content=${html `<md-elevated-button danger><md-icon slot="icon">delete</md-icon>Delete</md-elevated-button>`}></danger-body-probe>`],
44
+ ['outlined', html `<danger-body-probe .content=${html `<md-outlined-button danger><md-icon slot="icon">delete</md-icon>Delete</md-outlined-button>`}></danger-body-probe>`],
45
+ ['text', html `<danger-body-probe .content=${html `<md-text-button danger><md-icon slot="icon">delete</md-icon>Delete</md-text-button>`}></danger-body-probe>`],
46
+ ['assist chip', html `<danger-bar-probe .content=${html `<md-assist-chip danger label="Delete"><md-icon slot="icon">delete</md-icon></md-assist-chip>`}></danger-bar-probe>`],
47
+ ['popup native', html `<ox-popup-actions><button type="button" slot="start" destructive><md-icon>delete</md-icon>Delete</button></ox-popup-actions>`],
48
+ ['popup filled', html `<ox-popup-actions><md-filled-button slot="confirm" destructive><md-icon slot="icon">delete</md-icon>Delete</md-filled-button></ox-popup-actions>`],
49
+ ['popup text', html `<ox-popup-actions><md-text-button slot="start" destructive><md-icon slot="icon">delete</md-icon>Delete</md-text-button></ox-popup-actions>`],
50
+ ['popup outlined', html `<ox-popup-actions><md-outlined-button slot="start" destructive><md-icon slot="icon">delete</md-icon>Delete</md-outlined-button></ox-popup-actions>`],
51
+ ];
52
+ const themes = {
53
+ light: { error: '#ba1a1a', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' },
54
+ dark: { error: '#ffb4ab', onError: '#690005', container: '#93000a', onContainer: '#ffdad6', surface: '#121212' },
55
+ boardDark: { error: '#fbafa9', onError: '#a3000c', container: '#a3000c', onContainer: '#fbafa9', surface: '#121318' },
56
+ custom: { error: '#a00000', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' }
57
+ };
58
+ const settle = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
59
+ function rgb(value) { const channels = value.match(/[\d.]+/g).slice(0, 3).map(Number); return value.startsWith('color(srgb') ? channels.map(n => n * 255) : channels; }
60
+ function contrast(a, b) {
61
+ const light = (color) => rgb(color).map(n => n / 255).map(n => n <= .04045 ? n / 12.92 : ((n + .055) / 1.055) ** 2.4).reduce((sum, n, i) => sum + n * [.2126, .7152, .0722][i], 0);
62
+ const x = light(a), y = light(b);
63
+ return (Math.max(x, y) + .05) / (Math.min(x, y) + .05);
64
+ }
65
+ function background(node) {
66
+ var _a, _b;
67
+ for (let current = node; current; current = (_b = (_a = current.parentElement) !== null && _a !== void 0 ? _a : current.getRootNode().host) !== null && _b !== void 0 ? _b : null) {
68
+ const color = getComputedStyle(current).backgroundColor;
69
+ if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent')
70
+ return color;
71
+ }
72
+ return 'rgb(255, 255, 255)';
73
+ }
74
+ for (const [themeName, theme] of Object.entries(themes)) {
75
+ describe(`destructive action contrast: ${themeName}`, () => {
76
+ for (const [kind, template] of cases) {
77
+ it(`${kind}: icon follows the label before hover, on hover, focus, press and disabled`, async () => {
78
+ var _a, _b, _c, _d, _e, _f;
79
+ await sendMouse({ type: 'move', position: [0, 0] });
80
+ const root = await fixture(html `<div style="padding:30px; min-width:320px">${template}</div>`);
81
+ for (const [name, value] of Object.entries({
82
+ '--md-sys-color-error': theme.error, '--md-sys-color-on-error': theme.onError,
83
+ '--md-sys-color-error-container': theme.container, '--md-sys-color-on-error-container': theme.onContainer,
84
+ '--md-sys-color-surface-container-lowest': theme.surface, '--md-sys-color-on-surface': themeName === 'dark' || themeName === 'boardDark' ? '#ffffff' : '#111111',
85
+ '--md-sys-color-primary': '#005566', '--md-sys-color-secondary': '#006677', '--md-sys-color-secondary-container': '#aaffff', '--md-sys-color-on-secondary-container': '#001122'
86
+ }))
87
+ root.style.setProperty(name, value);
88
+ if (themeName === 'custom') {
89
+ root.style.setProperty('--danger-button-background', '#520000');
90
+ root.style.setProperty('--danger-button-color', '#fff0f0');
91
+ root.style.setProperty('--danger-button-hover-background', '#fff0f0');
92
+ root.style.setProperty('--danger-button-hover-color', '#520000');
93
+ }
94
+ if (themeName === 'boardDark') {
95
+ root.style.setProperty('--danger-button-background', 'var(--md-sys-color-error-container)');
96
+ root.style.setProperty('--danger-button-color', 'var(--md-sys-color-on-error-container)');
97
+ root.style.setProperty('--danger-button-hover-background', 'color-mix(in srgb, var(--md-sys-color-error-container) 88%, black)');
98
+ root.style.setProperty('--danger-button-hover-color', 'var(--md-sys-color-on-error-container)');
99
+ }
100
+ root.style.backgroundColor = theme.surface;
101
+ await settle();
102
+ const surface = root.firstElementChild;
103
+ await surface.updateComplete;
104
+ const slotted = surface.tagName.startsWith('OX-POPUP');
105
+ const control = (slotted ? surface.firstElementChild : surface.shadowRoot.querySelector('button, md-filled-button, md-filled-tonal-button, md-elevated-button, md-outlined-button, md-text-button, md-assist-chip'));
106
+ const icon = control.querySelector('md-icon');
107
+ const label = ((_d = (_b = (_a = control.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.label')) !== null && _b !== void 0 ? _b : (_c = control.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('button')) !== null && _d !== void 0 ? _d : control);
108
+ const focusTarget = ((_f = (_e = control.shadowRoot) === null || _e === void 0 ? void 0 : _e.querySelector('button')) !== null && _f !== void 0 ? _f : control);
109
+ label.style.transition = 'none';
110
+ control.style.transition = 'none';
111
+ const check = (disabled = false) => {
112
+ const ink = getComputedStyle(label).color;
113
+ expect(getComputedStyle(icon).color, `${kind} icon/label`).to.equal(ink);
114
+ expect(icon.getBoundingClientRect().width).to.be.greaterThan(10);
115
+ if (!disabled)
116
+ expect(contrast(ink, background(control)), `${kind} contrast`).to.be.at.least(4.5);
117
+ };
118
+ check();
119
+ const box = control.getBoundingClientRect();
120
+ const position = [Math.round(box.x + box.width / 2), Math.round(box.y + box.height / 2)];
121
+ await sendMouse({ type: 'move', position });
122
+ await settle();
123
+ expect(control.matches(':hover')).to.equal(true);
124
+ check();
125
+ await sendMouse({ type: 'move', position: [0, 0] });
126
+ control.focus();
127
+ await settle();
128
+ check();
129
+ await sendMouse({ type: 'move', position });
130
+ await sendMouse({ type: 'down' });
131
+ try {
132
+ await settle();
133
+ check();
134
+ }
135
+ finally {
136
+ await sendMouse({ type: 'up' });
137
+ }
138
+ focusTarget.blur();
139
+ control.blur();
140
+ control.disabled = true;
141
+ await settle();
142
+ check(true);
143
+ });
144
+ }
145
+ });
146
+ }
147
+ //# sourceMappingURL=destructive-actions.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destructive-actions.test.js","sourceRoot":"","sources":["../../test/destructive-actions.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAuB,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzF,OAAO,4BAA4B,CAAA;AACnC,OAAO,uCAAuC,CAAA;AAC9C,OAAO,6CAA6C,CAAA;AACpD,OAAO,yCAAyC,CAAA;AAChD,OAAO,yCAAyC,CAAA;AAChD,OAAO,qCAAqC,CAAA;AAC5C,OAAO,oCAAoC,CAAA;AAC3C,OAAO,oCAAoC,CAAA;AAC3C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,sCAAsC,CAAA;AAE7C,MAAM,SAAU,SAAQ,UAAU;IAIhC,MAAM,aAAK,OAAO,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAA,uEAAuE,CAAA,CAAC,CAAC;;AAHxG,oBAAU,GAAG,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAA;AAE9C,gBAAM,GAAG,CAAC,YAAY,EAAE,GAAG,CAAA,0BAA0B,CAA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AAE,CAAC,CAAA;gBAAC,CAAC;gBAC3E,WAAW,CAAC,IAAI,EAAE,CAAC;gBAAC,OAAO,CAAC,IAAI,EAAE,CAAA;gBAClC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAA;gBACvB,MAAM,MAAM,EAAE,CAAA;gBACd,KAAK,CAAC,IAAI,CAAC,CAAA;YACb,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { expect, fixture } from '@open-wc/testing'\nimport { sendMouse } from '@web/test-runner-commands'\nimport { css, html, LitElement, type TemplateResult } from 'lit'\nimport { ButtonStyles, ButtonContainerStyles, CommonHeaderStyles } from '@operato/styles'\nimport '@material/web/icon/icon.js'\nimport '@material/web/button/filled-button.js'\nimport '@material/web/button/filled-tonal-button.js'\nimport '@material/web/button/elevated-button.js'\nimport '@material/web/button/outlined-button.js'\nimport '@material/web/button/text-button.js'\nimport '@material/web/chips/assist-chip.js'\nimport '@operato/popup/ox-popup-actions.js'\nimport '../src/data-grid/data-grid-field.js'\nimport '../src/data-card/data-card-gutter.js'\nimport '../src/data-list/data-list-gutter.js'\n\nclass BodyProbe extends LitElement {\n static properties = { content: { attribute: false } }\n content?: TemplateResult\n static styles = [ButtonStyles, css`:host { display: block }`]\n render() { return this.content ?? html`<button type=\"button\" danger><md-icon>delete</md-icon>Delete</button>` }\n}\nclass BarProbe extends BodyProbe { static styles = [ButtonContainerStyles] }\nclass HeaderProbe extends BodyProbe {\n static styles = [CommonHeaderStyles]\n render() { return html`<div class=\"header\"><div class=\"actions\"><button type=\"button\" danger class=\"textbtn\"><md-icon>delete</md-icon>Delete</button></div></div>` }\n}\ncustomElements.define('danger-body-probe', BodyProbe)\ncustomElements.define('danger-bar-probe', BarProbe)\ncustomElements.define('danger-header-probe', HeaderProbe)\n\nconst column = { type: 'gutter', name: 'delete', danger: true, record: { renderer: () => html`<button type=\"button\"><md-icon>delete</md-icon><span>Delete</span></button>` } }\nconst cases = [\n ['form', html`<danger-body-probe></danger-body-probe>`],\n ['quiet form', html`<danger-body-probe .content=${html`<button type=\"button\" quiet danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],\n ['raised form', html`<danger-body-probe .content=${html`<button type=\"button\" raised danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],\n ['toolbar', html`<danger-bar-probe></danger-bar-probe>`],\n ['header', html`<danger-header-probe></danger-header-probe>`],\n ['grid', html`<ox-grid-field danger .column=${column}></ox-grid-field>`],\n ['card', html`<ox-card-gutter .column=${column}></ox-card-gutter>`],\n ['mobile list', html`<ox-list-gutter .column=${column}></ox-list-gutter>`],\n ['filled', html`<danger-body-probe .content=${html`<md-filled-button danger><md-icon slot=\"icon\">delete</md-icon>Delete</md-filled-button>`}></danger-body-probe>`],\n ['tonal', html`<danger-body-probe .content=${html`<md-filled-tonal-button danger><md-icon slot=\"icon\">delete</md-icon>Delete</md-filled-tonal-button>`}></danger-body-probe>`],\n ['elevated', html`<danger-body-probe .content=${html`<md-elevated-button danger><md-icon slot=\"icon\">delete</md-icon>Delete</md-elevated-button>`}></danger-body-probe>`],\n ['outlined', html`<danger-body-probe .content=${html`<md-outlined-button danger><md-icon slot=\"icon\">delete</md-icon>Delete</md-outlined-button>`}></danger-body-probe>`],\n ['text', html`<danger-body-probe .content=${html`<md-text-button danger><md-icon slot=\"icon\">delete</md-icon>Delete</md-text-button>`}></danger-body-probe>`],\n ['assist chip', html`<danger-bar-probe .content=${html`<md-assist-chip danger label=\"Delete\"><md-icon slot=\"icon\">delete</md-icon></md-assist-chip>`}></danger-bar-probe>`],\n ['popup native', html`<ox-popup-actions><button type=\"button\" slot=\"start\" destructive><md-icon>delete</md-icon>Delete</button></ox-popup-actions>`],\n ['popup filled', html`<ox-popup-actions><md-filled-button slot=\"confirm\" destructive><md-icon slot=\"icon\">delete</md-icon>Delete</md-filled-button></ox-popup-actions>`],\n ['popup text', html`<ox-popup-actions><md-text-button slot=\"start\" destructive><md-icon slot=\"icon\">delete</md-icon>Delete</md-text-button></ox-popup-actions>`],\n ['popup outlined', html`<ox-popup-actions><md-outlined-button slot=\"start\" destructive><md-icon slot=\"icon\">delete</md-icon>Delete</md-outlined-button></ox-popup-actions>`],\n] as const\n\nconst themes = {\n light: { error: '#ba1a1a', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' },\n dark: { error: '#ffb4ab', onError: '#690005', container: '#93000a', onContainer: '#ffdad6', surface: '#121212' },\n boardDark: { error: '#fbafa9', onError: '#a3000c', container: '#a3000c', onContainer: '#fbafa9', surface: '#121318' },\n custom: { error: '#a00000', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' }\n}\nconst settle = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))\nfunction rgb(value: string) { const channels = value.match(/[\\d.]+/g)!.slice(0, 3).map(Number); return value.startsWith('color(srgb') ? channels.map(n => n * 255) : channels }\nfunction contrast(a: string, b: string) {\n const light = (color: string) => rgb(color).map(n => n / 255).map(n => n <= .04045 ? n / 12.92 : ((n + .055) / 1.055) ** 2.4).reduce((sum, n, i) => sum + n * [.2126, .7152, .0722][i], 0)\n const x = light(a), y = light(b)\n return (Math.max(x, y) + .05) / (Math.min(x, y) + .05)\n}\nfunction background(node: Element): string {\n for (let current: Element | null = node; current; current = current.parentElement ?? (current.getRootNode() as ShadowRoot).host ?? null) {\n const color = getComputedStyle(current).backgroundColor\n if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') return color\n }\n return 'rgb(255, 255, 255)'\n}\n\nfor (const [themeName, theme] of Object.entries(themes)) {\n describe(`destructive action contrast: ${themeName}`, () => {\n for (const [kind, template] of cases) {\n it(`${kind}: icon follows the label before hover, on hover, focus, press and disabled`, async () => {\n await sendMouse({ type: 'move', position: [0, 0] })\n const root = await fixture<HTMLElement>(html`<div style=\"padding:30px; min-width:320px\">${template}</div>`)\n for (const [name, value] of Object.entries({\n '--md-sys-color-error': theme.error, '--md-sys-color-on-error': theme.onError,\n '--md-sys-color-error-container': theme.container, '--md-sys-color-on-error-container': theme.onContainer,\n '--md-sys-color-surface-container-lowest': theme.surface, '--md-sys-color-on-surface': themeName === 'dark' || themeName === 'boardDark' ? '#ffffff' : '#111111',\n '--md-sys-color-primary': '#005566', '--md-sys-color-secondary': '#006677', '--md-sys-color-secondary-container': '#aaffff', '--md-sys-color-on-secondary-container': '#001122'\n })) root.style.setProperty(name, value)\n if (themeName === 'custom') {\n root.style.setProperty('--danger-button-background', '#520000')\n root.style.setProperty('--danger-button-color', '#fff0f0')\n root.style.setProperty('--danger-button-hover-background', '#fff0f0')\n root.style.setProperty('--danger-button-hover-color', '#520000')\n }\n if (themeName === 'boardDark') {\n root.style.setProperty('--danger-button-background', 'var(--md-sys-color-error-container)')\n root.style.setProperty('--danger-button-color', 'var(--md-sys-color-on-error-container)')\n root.style.setProperty('--danger-button-hover-background', 'color-mix(in srgb, var(--md-sys-color-error-container) 88%, black)')\n root.style.setProperty('--danger-button-hover-color', 'var(--md-sys-color-on-error-container)')\n }\n root.style.backgroundColor = theme.surface\n await settle()\n const surface = root.firstElementChild as HTMLElement & { updateComplete?: Promise<unknown> }\n await surface.updateComplete\n const slotted = surface.tagName.startsWith('OX-POPUP')\n const control = (slotted ? surface.firstElementChild : surface.shadowRoot!.querySelector('button, md-filled-button, md-filled-tonal-button, md-elevated-button, md-outlined-button, md-text-button, md-assist-chip')) as HTMLElement & { disabled: boolean }\n const icon = control.querySelector('md-icon')!\n const label = (control.shadowRoot?.querySelector('.label') ?? control.shadowRoot?.querySelector('button') ?? control) as HTMLElement\n const focusTarget = (control.shadowRoot?.querySelector('button') ?? control) as HTMLElement\n label.style.transition = 'none'\n control.style.transition = 'none'\n const check = (disabled = false) => {\n const ink = getComputedStyle(label).color\n expect(getComputedStyle(icon).color, `${kind} icon/label`).to.equal(ink)\n expect(icon.getBoundingClientRect().width).to.be.greaterThan(10)\n if (!disabled) expect(contrast(ink, background(control)), `${kind} contrast`).to.be.at.least(4.5)\n }\n check()\n const box = control.getBoundingClientRect()\n const position: [number, number] = [Math.round(box.x + box.width / 2), Math.round(box.y + box.height / 2)]\n await sendMouse({ type: 'move', position })\n await settle()\n expect(control.matches(':hover')).to.equal(true)\n check()\n await sendMouse({ type: 'move', position: [0, 0] })\n control.focus()\n await settle()\n check()\n await sendMouse({ type: 'move', position })\n await sendMouse({ type: 'down' })\n try { await settle(); check() } finally { await sendMouse({ type: 'up' }) }\n focusTarget.blur(); control.blur()\n control.disabled = true\n await settle()\n check(true)\n })\n }\n })\n}\n"]}
@@ -0,0 +1 @@
1
+ import '../src/data-grist.js';
@@ -0,0 +1,134 @@
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 { sendMouse } from '@web/test-runner-commands';
4
+ import { html } from 'lit';
5
+ import '../src/data-grist.js';
6
+ const settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms));
7
+ const LONG = 'A very long account name that is far wider than any room the table has left for it';
8
+ async function grid(widths, width = 700, editable = false) {
9
+ var _a, _b;
10
+ const columns = [
11
+ { type: 'string', name: 'id', hidden: true },
12
+ { type: 'string', name: 'name', header: 'name', width: (_a = widths.name) !== null && _a !== void 0 ? _a : 150, record: { editable } },
13
+ { type: 'string', name: 'code', header: 'code', width: 100 },
14
+ { type: 'string', name: 'memo', header: 'memo', width: (_b = widths.memo) !== null && _b !== void 0 ? _b : 120 }
15
+ ];
16
+ const records = Array.from({ length: 5 }, (_, r) => ({ id: String(r), name: r % 2 ? LONG : 'short', code: 'C-' + r, memo: 'note ' + r }));
17
+ const el = (await fixture(html `
18
+ <ox-grist
19
+ style=${`width: ${width}px; height: 320px`}
20
+ mode="GRID"
21
+ .config=${{ columns, pagination: { infinite: true }, rows: { appendable: false, selectable: false } }}
22
+ .data=${{ records }}
23
+ ></ox-grist>
24
+ `));
25
+ await settle();
26
+ await el.updateComplete;
27
+ const ox = el.renderRoot.querySelector('#grist');
28
+ await ox.updateComplete;
29
+ const scroller = ox.renderRoot.querySelector('div[grid]');
30
+ const header = ox.renderRoot.querySelector('ox-grid-header');
31
+ const body = ox.renderRoot.querySelector('ox-grid-body');
32
+ await body.updateComplete;
33
+ await settle(50);
34
+ return { ox, scroller, header, body };
35
+ }
36
+ function heads(header) {
37
+ return Array.from(header.renderRoot.querySelectorAll('[role=columnheader]'));
38
+ }
39
+ function width(element) {
40
+ return Math.round(element.getBoundingClientRect().width);
41
+ }
42
+ /** The largest distance, in left or in width, between a header cell and a cell of its column, over every row. */
43
+ function misalignment(header, body) {
44
+ const hs = heads(header);
45
+ let worst = 0;
46
+ for (const row of Array.from(body.renderRoot.querySelectorAll('div[grid-row]'))) {
47
+ const cells = Array.from(row.querySelectorAll(':scope > ox-grid-field'));
48
+ hs.forEach((h, i) => {
49
+ const cell = cells[i];
50
+ if (!cell)
51
+ return;
52
+ const a = h.getBoundingClientRect();
53
+ const b = cell.getBoundingClientRect();
54
+ worst = Math.max(worst, Math.abs(a.left - b.left), Math.abs(a.width - b.width));
55
+ });
56
+ }
57
+ return Math.round(worst);
58
+ }
59
+ /** Whether the text of a column's cell is cut in any row. */
60
+ function cut(body, index) {
61
+ return Array.from(body.renderRoot.querySelectorAll('div[grid-row]')).some(row => {
62
+ const cell = row.querySelectorAll(':scope > ox-grid-field')[index];
63
+ return !!cell && [cell, ...Array.from(cell.renderRoot.querySelectorAll('*'))].some(e => e.scrollWidth > e.clientWidth + 1);
64
+ });
65
+ }
66
+ describe('a flexible column', () => {
67
+ /* Resizing the grid body inside a fixture trips Chrome's benign "ResizeObserver loop" error. */
68
+ const ignoreResizeLoop = (e) => {
69
+ if (String(e.message).includes('ResizeObserver loop')) {
70
+ e.stopImmediatePropagation();
71
+ e.preventDefault();
72
+ }
73
+ };
74
+ let previousOnError = null;
75
+ before(() => {
76
+ window.addEventListener('error', ignoreResizeLoop, true);
77
+ previousOnError = window.onerror;
78
+ window.onerror = (message, ...rest) => String(message).includes('ResizeObserver loop') ? true : previousOnError === null || previousOnError === void 0 ? void 0 : previousOnError.call(window, message, ...rest);
79
+ });
80
+ after(async () => {
81
+ window.removeEventListener('error', ignoreResizeLoop, true);
82
+ window.onerror = previousOnError;
83
+ await sendMouse({ type: 'move', position: [0, 0] });
84
+ });
85
+ it('with room, takes the room on the right and stays under its header', async () => {
86
+ const { scroller, header, body } = await grid({ name: 'minmax(150px, 1fr)' }, 1200);
87
+ const name = heads(header)[0];
88
+ expect(width(name), 'the column takes the room').to.be.greaterThan(500);
89
+ expect(scroller.scrollWidth, 'nothing overflows').to.be.at.most(scroller.clientWidth);
90
+ expect(misalignment(header, body)).to.equal(0);
91
+ });
92
+ it('without room, stays at its floor, cuts its text and stays under its header', async () => {
93
+ const { header, body } = await grid({ name: 'minmax(150px, 1fr)', memo: 600 }, 700);
94
+ expect(width(heads(header)[0])).to.equal(150);
95
+ expect(cut(body, 0), 'the long name is cut').to.equal(true);
96
+ expect(misalignment(header, body)).to.equal(0);
97
+ });
98
+ it('two flexible columns share the room one to two and stay under their headers', async () => {
99
+ const { header, body } = await grid({ name: 'minmax(100px, 1fr)', memo: 'minmax(100px, 2fr)' }, 900);
100
+ const [name, , memo] = heads(header);
101
+ /* fr shares the whole width of the tracks, not what is above their floors: 1fr and 2fr are x and 2x. */
102
+ const share = width(memo) / width(name);
103
+ expect(share).to.be.within(1.9, 2.1);
104
+ expect(misalignment(header, body)).to.equal(0);
105
+ });
106
+ it('leaves a table of fixed columns as it was', async () => {
107
+ const { body } = await grid({}, 700);
108
+ const cell = body.renderRoot.querySelector('ox-grid-field');
109
+ expect(getComputedStyle(cell).contain).to.equal('none');
110
+ });
111
+ it('prints with a valid template', async () => {
112
+ const { ox } = await grid({ name: 'minmax(150px, 1fr)' }, 700);
113
+ const print = ox.style.getPropertyValue('--grid-template-print-columns');
114
+ expect(CSS.supports('grid-template-columns', print), print).to.equal(true);
115
+ expect(print).to.contain('150fr');
116
+ });
117
+ it('dragging its edge gives it a width in px from where it stood', async () => {
118
+ const { header } = await grid({ name: 'minmax(150px, 1fr)' }, 1000, true);
119
+ const name = heads(header)[0];
120
+ const before = width(name);
121
+ const splitter = name.querySelector('span[splitter]');
122
+ expect(!!splitter, 'an editable column has a handle').to.equal(true);
123
+ const r = splitter.getBoundingClientRect();
124
+ const x = Math.round(r.left + r.width / 2);
125
+ const y = Math.round(r.top + r.height / 2);
126
+ await sendMouse({ type: 'move', position: [x, y] });
127
+ await sendMouse({ type: 'down' });
128
+ await sendMouse({ type: 'move', position: [x - 40, y] });
129
+ await sendMouse({ type: 'up' });
130
+ await settle(300);
131
+ expect(width(heads(header)[0])).to.be.within(before - 45, before - 35);
132
+ });
133
+ });
134
+ //# sourceMappingURL=flexible-columns.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flexible-columns.test.js","sourceRoot":"","sources":["../../test/flexible-columns.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,sBAAsB,CAAA;AAuB7B,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5E,MAAM,IAAI,GAAG,oFAAoF,CAAA;AAEjG,KAAK,UAAU,IAAI,CAAC,MAAkC,EAAE,KAAK,GAAG,GAAG,EAAE,QAAQ,GAAG,KAAK;;IACnF,MAAM,OAAO,GAAU;QACrB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;QAC5C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM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,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 { sendMouse } from '@web/test-runner-commands'\nimport { html } from 'lit'\n\nimport '../src/data-grist.js'\n\n/**\n * A column that takes the room left over: `width: 'minmax(150px, 1fr)'`.\n *\n * A string width goes into grid-template-columns as it is, so fr was always accepted — and broke the\n * table. The header and the body are two CSS grids with the same template. A flexible track is sized\n * from what its cells hold, and the two grids hold different things: the body grew the column to its\n * longest text while the header kept it at its floor. Measured on the balance screen: 182px apart with\n * one fr column whose text was longer than the room, 251px with two fr columns.\n *\n * ```\n * aligned every cell sits under its header, room or no room\n * room a flexible column takes the room on the right; the filler after the last column gets none\n * no room it stays at its floor and its text is cut (\"…\"), as a fixed column's is\n * ratio 1fr and 2fr share the room one to two\n * print the print template is a valid template (px became fr letter by letter: minmax(150fr, 1fr))\n * resize dragging a flexible column's edge gives it a width in px from where it stood\n * ```\n */\n\ntype Root = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }\n\nconst settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms))\n\nconst LONG = 'A very long account name that is far wider than any room the table has left for it'\n\nasync function grid(widths: { name?: any; memo?: any }, width = 700, editable = false) {\n const columns: any[] = [\n { type: 'string', name: 'id', hidden: true },\n { type: 'string', name: 'name', header: 'name', width: widths.name ?? 150, record: { editable } },\n { type: 'string', name: 'code', header: 'code', width: 100 },\n { type: 'string', name: 'memo', header: 'memo', width: widths.memo ?? 120 }\n ]\n\n const records = Array.from({ length: 5 }, (_, r) => ({ id: String(r), name: r % 2 ? LONG : 'short', code: 'C-' + r, memo: 'note ' + r }))\n\n const el = (await fixture(html`\n <ox-grist\n style=${`width: ${width}px; height: 320px`}\n mode=\"GRID\"\n .config=${{ columns, pagination: { infinite: true }, rows: { appendable: false, selectable: false } }}\n .data=${{ records }}\n ></ox-grist>\n `)) as Root\n\n await settle()\n await el.updateComplete\n\n const ox = el.renderRoot.querySelector('#grist') as Root\n await ox.updateComplete\n const scroller = ox.renderRoot.querySelector('div[grid]') as HTMLElement\n const header = ox.renderRoot.querySelector('ox-grid-header') as Root\n const body = ox.renderRoot.querySelector('ox-grid-body') as Root\n await body.updateComplete\n await settle(50)\n\n return { ox, scroller, header, body }\n}\n\nfunction heads(header: Root) {\n return Array.from(header.renderRoot.querySelectorAll('[role=columnheader]')) as HTMLElement[]\n}\n\nfunction width(element: Element) {\n return Math.round(element.getBoundingClientRect().width)\n}\n\n/** The largest distance, in left or in width, between a header cell and a cell of its column, over every row. */\nfunction misalignment(header: Root, body: Root) {\n const hs = heads(header)\n let worst = 0\n for (const row of Array.from(body.renderRoot.querySelectorAll('div[grid-row]'))) {\n const cells = Array.from(row.querySelectorAll(':scope > ox-grid-field')) as HTMLElement[]\n hs.forEach((h, i) => {\n const cell = cells[i]\n if (!cell) return\n const a = h.getBoundingClientRect()\n const b = cell.getBoundingClientRect()\n worst = Math.max(worst, Math.abs(a.left - b.left), Math.abs(a.width - b.width))\n })\n }\n return Math.round(worst)\n}\n\n/** Whether the text of a column's cell is cut in any row. */\nfunction cut(body: Root, index: number) {\n return Array.from(body.renderRoot.querySelectorAll('div[grid-row]')).some(row => {\n const cell = row.querySelectorAll(':scope > ox-grid-field')[index] as Root | undefined\n return !!cell && [cell, ...Array.from(cell.renderRoot.querySelectorAll('*'))].some(e => e.scrollWidth > e.clientWidth + 1)\n })\n}\n\ndescribe('a flexible column', () => {\n /* Resizing the grid body inside a fixture trips Chrome's benign \"ResizeObserver loop\" error. */\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 () => {\n window.removeEventListener('error', ignoreResizeLoop, true)\n window.onerror = previousOnError\n await sendMouse({ type: 'move', position: [0, 0] })\n })\n\n it('with room, takes the room on the right and stays under its header', async () => {\n const { scroller, header, body } = await grid({ name: 'minmax(150px, 1fr)' }, 1200)\n\n const name = heads(header)[0]\n expect(width(name), 'the column takes the room').to.be.greaterThan(500)\n expect(scroller.scrollWidth, 'nothing overflows').to.be.at.most(scroller.clientWidth)\n expect(misalignment(header, body)).to.equal(0)\n })\n\n it('without room, stays at its floor, cuts its text and stays under its header', async () => {\n const { header, body } = await grid({ name: 'minmax(150px, 1fr)', memo: 600 }, 700)\n\n expect(width(heads(header)[0])).to.equal(150)\n expect(cut(body, 0), 'the long name is cut').to.equal(true)\n expect(misalignment(header, body)).to.equal(0)\n })\n\n it('two flexible columns share the room one to two and stay under their headers', async () => {\n const { header, body } = await grid({ name: 'minmax(100px, 1fr)', memo: 'minmax(100px, 2fr)' }, 900)\n\n const [name, , memo] = heads(header)\n /* fr shares the whole width of the tracks, not what is above their floors: 1fr and 2fr are x and 2x. */\n const share = width(memo) / width(name)\n expect(share).to.be.within(1.9, 2.1)\n expect(misalignment(header, body)).to.equal(0)\n })\n\n it('leaves a table of fixed columns as it was', async () => {\n const { body } = await grid({}, 700)\n\n const cell = body.renderRoot.querySelector('ox-grid-field') as HTMLElement\n expect(getComputedStyle(cell).contain).to.equal('none')\n })\n\n it('prints with a valid template', async () => {\n const { ox } = await grid({ name: 'minmax(150px, 1fr)' }, 700)\n\n const print = ox.style.getPropertyValue('--grid-template-print-columns')\n expect(CSS.supports('grid-template-columns', print), print).to.equal(true)\n expect(print).to.contain('150fr')\n })\n\n it('dragging its edge gives it a width in px from where it stood', async () => {\n const { header } = await grid({ name: 'minmax(150px, 1fr)' }, 1000, true)\n\n const name = heads(header)[0]\n const before = width(name)\n const splitter = name.querySelector('span[splitter]') as HTMLElement\n expect(!!splitter, 'an editable column has a handle').to.equal(true)\n\n const r = splitter.getBoundingClientRect()\n const x = Math.round(r.left + r.width / 2)\n const y = Math.round(r.top + r.height / 2)\n await sendMouse({ type: 'move', position: [x, y] })\n await sendMouse({ type: 'down' })\n await sendMouse({ type: 'move', position: [x - 40, y] })\n await sendMouse({ type: 'up' })\n await settle(300)\n\n expect(width(heads(header)[0])).to.be.within(before - 45, before - 35)\n })\n})\n"]}
@@ -46,6 +46,21 @@ function setup() {
46
46
  }
47
47
  const answer = (...ids) => ({ total: 100, records: ids.map(id => ({ id })) });
48
48
  describe('query generations', () => {
49
+ it('hands each read a signal that a replacement or an invalidation aborts, an append sharing its generation', async () => {
50
+ const { provider, calls } = setup();
51
+ void provider.fetch();
52
+ const first = calls[0].options.signal;
53
+ expect(first.aborted).to.equal(false);
54
+ void provider.fetch();
55
+ expect(first.aborted).to.equal(true);
56
+ calls[1].result.resolve(answer('one'));
57
+ await Promise.resolve();
58
+ await Promise.resolve();
59
+ void provider.attach();
60
+ expect(calls[2].options.signal).to.equal(calls[1].options.signal);
61
+ provider.invalidate();
62
+ expect(calls[2].options.signal.aborted).to.equal(true);
63
+ });
49
64
  it('never appends an old query page to a replacement', async () => {
50
65
  const { provider, calls, events } = setup();
51
66
  const initial = provider.fetch();
@@ -1 +1 @@
1
- {"version":3,"file":"request-generation.test.js","sourceRoot":"","sources":["../../test/request-generation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAItD,SAAS,OAAO;IACd,IAAI,OAAuC,CAAA;IAC3C,IAAI,MAA+B,CAAA;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAc,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACnD,OAAO,GAAG,GAAG,CAAA;QACb,MAAM,GAAG,EAAE,CAAA;IACb,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC;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KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACtC,MAAM,WAAW,CAAA;QACjB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from '@open-wc/testing'\nimport { DataProvider } from '../src/data-provider.js'\nimport type { DataConsumer } from '../src/data-consumer.js'\nimport type { FetchOption, FetchResult } from '../src/types.js'\n\nfunction pending() {\n let resolve!: (result: FetchResult) => void\n let reject!: (error: Error) => void\n const promise = new Promise<FetchResult>((yes, no) => {\n resolve = yes\n reject = no\n })\n return { promise, resolve, reject }\n}\n\nfunction setup() {\n const calls: { options: FetchOption; result: ReturnType<typeof pending> }[] = []\n const events: any[] = []\n let data: any = { records: [] }\n let spinning = false\n const consumer = Object.assign(new EventTarget(), {\n shownMode: 'GRID' as const,\n get data() {\n return data\n },\n set data(next) {\n data = next\n },\n _data: data,\n checkDirties() {},\n showSpinner() {\n spinning = true\n },\n hideSpinner() {\n spinning = false\n },\n fetchHandler(options: FetchOption) {\n const result = pending()\n calls.push({ options, result })\n return result.promise\n }\n }) as DataConsumer\n // The grid's dirty copy follows adoption; an append must preserve its edited values.\n consumer.addEventListener('list-adopted', event => {\n const detail = (event as CustomEvent).detail\n events.push(detail)\n consumer._data = { ...detail }\n })\n return { provider: new DataProvider(consumer), consumer, calls, events, spinning: () => spinning }\n}\n\nconst answer = (...ids: string[]): FetchResult => ({ total: 100, records: ids.map(id => ({ id })) })\n\ndescribe('query generations', () => {\n it('never appends an old query page to a replacement', async () => {\n const { provider, calls, events } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('old-1'))\n await initial\n const oldPage = provider.attach()\n const replacement = provider.fetch()\n calls[2].result.resolve(answer('new-1'))\n await replacement\n calls[1].result.resolve(answer('old-2'))\n await oldPage\n expect(provider.records.map(row => row.id)).to.deep.equal(['new-1'])\n expect(events.map(event => event.kind)).to.deep.equal(['replace', 'replace'])\n })\n\n it('coalesces next-page triggers and preserves edits and legitimate repeated ids', async () => {\n const { provider, consumer, calls, events } = setup()\n const initial = provider.attach(true)\n calls[0].result.resolve(answer('one'))\n await initial\n consumer._data.records[0].edited = true\n const a = provider.attach()\n const b = provider.attach()\n expect(a).to.equal(b)\n expect(calls.length).to.equal(2)\n calls[1].result.resolve(answer('one', 'two', 'two'))\n await a\n expect(provider.records).to.deep.equal([{ id: 'one', edited: true }, { id: 'one' }, { id: 'two' }, { id: 'two' }])\n expect(events[1].page).to.equal(2)\n expect(events[1].records.length).to.equal(4)\n expect(events[1].pageRecords.length).to.equal(3)\n })\n\n it('keeps rows and retries the same page after a failed append', async () => {\n const { provider, calls } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('one'))\n await initial\n const append = provider.attach()\n calls[1].result.reject(new Error('offline'))\n try {\n await append\n } catch {}\n expect(provider.records.map(row => row.id)).to.deep.equal(['one'])\n const retry = provider.attach()\n expect(calls[2].options.page).to.equal(2)\n calls[2].result.resolve(answer('two'))\n await retry\n expect(provider.records.map(row => row.id)).to.deep.equal(['one', 'two'])\n })\n\n it('a stale response cannot stop the current spinner or announce adoption', async () => {\n const { provider, calls, events, spinning } = setup()\n const old = provider.fetch()\n const next = provider.fetch()\n calls[0].result.resolve(answer('old'))\n await old\n expect(spinning()).to.equal(true)\n expect(events.length).to.equal(0)\n calls[1].result.resolve(answer('new'))\n await next\n expect(spinning()).to.equal(false)\n expect(events.length).to.equal(1)\n })\n\n it('disposal invalidates replacement and append responses', async () => {\n const { provider, calls, events, spinning } = setup()\n const request = provider.fetch()\n provider.dispose()\n expect(spinning()).to.equal(false)\n calls[0].result.resolve(answer('late'))\n await request\n expect(events.length).to.equal(0)\n })\n\n it('deactivation ends an append spinner and a late result cannot disturb a new read', async () => {\n const { provider, calls, spinning } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('one'))\n await initial\n const append = provider.attach()\n provider.invalidate()\n expect(spinning()).to.equal(false)\n const replacement = provider.fetch()\n calls[1].result.resolve(answer('old'))\n await append\n expect(spinning()).to.equal(true)\n calls[2].result.resolve(answer('new'))\n await replacement\n expect(spinning()).to.equal(false)\n expect(provider.records.map(row => row.id)).to.deep.equal(['new'])\n })\n})\n"]}
1
+ {"version":3,"file":"request-generation.test.js","sourceRoot":"","sources":["../../test/request-generation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAItD,SAAS,OAAO;IACd,IAAI,OAAuC,CAAA;IAC3C,IAAI,MAA+B,CAAA;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAc,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACnD,OAAO,GAAG,GAAG,CAAA;QACb,MAAM,GAAG,EAAE,CAAA;IACb,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAmE,EAAE,CAAA;IAChF,MAAM,MAAM,GAAU,EAAE,CAAA;IACxB,IAAI,IAAI,GAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IAC/B,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,EAAE;QAChD,SAAS,EAAE,MAAe;QAC1B,IAAI,IAAI;YACN,OAAO,IAAI,CAAA;QACb,C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AAE;QAC/F,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAA;QAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QAChC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACtC,MAAM,OAAO,CAAA;QACb,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAA;QAChC,QAAQ,CAAC,UAAU,EAAE,CAAA;QACrB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAClC,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QACpC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACtC,MAAM,MAAM,CAAA;QACZ,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACjC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACtC,MAAM,WAAW,CAAA;QACjB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from '@open-wc/testing'\nimport { DataProvider } from '../src/data-provider.js'\nimport type { DataConsumer } from '../src/data-consumer.js'\nimport type { FetchOption, FetchResult } from '../src/types.js'\n\nfunction pending() {\n let resolve!: (result: FetchResult) => void\n let reject!: (error: Error) => void\n const promise = new Promise<FetchResult>((yes, no) => {\n resolve = yes\n reject = no\n })\n return { promise, resolve, reject }\n}\n\nfunction setup() {\n const calls: { options: FetchOption; result: ReturnType<typeof pending> }[] = []\n const events: any[] = []\n let data: any = { records: [] }\n let spinning = false\n const consumer = Object.assign(new EventTarget(), {\n shownMode: 'GRID' as const,\n get data() {\n return data\n },\n set data(next) {\n data = next\n },\n _data: data,\n checkDirties() {},\n showSpinner() {\n spinning = true\n },\n hideSpinner() {\n spinning = false\n },\n fetchHandler(options: FetchOption) {\n const result = pending()\n calls.push({ options, result })\n return result.promise\n }\n }) as DataConsumer\n // The grid's dirty copy follows adoption; an append must preserve its edited values.\n consumer.addEventListener('list-adopted', event => {\n const detail = (event as CustomEvent).detail\n events.push(detail)\n consumer._data = { ...detail }\n })\n return { provider: new DataProvider(consumer), consumer, calls, events, spinning: () => spinning }\n}\n\nconst answer = (...ids: string[]): FetchResult => ({ total: 100, records: ids.map(id => ({ id })) })\n\ndescribe('query generations', () => {\n it('hands each read a signal that a replacement or an invalidation aborts, an append sharing its generation', async () => {\n const { provider, calls } = setup()\n void provider.fetch()\n const first = calls[0].options.signal!\n expect(first.aborted).to.equal(false)\n void provider.fetch()\n expect(first.aborted).to.equal(true)\n calls[1].result.resolve(answer('one'))\n await Promise.resolve()\n await Promise.resolve()\n void provider.attach()\n expect(calls[2].options.signal).to.equal(calls[1].options.signal)\n provider.invalidate()\n expect(calls[2].options.signal!.aborted).to.equal(true)\n })\n\n it('never appends an old query page to a replacement', async () => {\n const { provider, calls, events } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('old-1'))\n await initial\n const oldPage = provider.attach()\n const replacement = provider.fetch()\n calls[2].result.resolve(answer('new-1'))\n await replacement\n calls[1].result.resolve(answer('old-2'))\n await oldPage\n expect(provider.records.map(row => row.id)).to.deep.equal(['new-1'])\n expect(events.map(event => event.kind)).to.deep.equal(['replace', 'replace'])\n })\n\n it('coalesces next-page triggers and preserves edits and legitimate repeated ids', async () => {\n const { provider, consumer, calls, events } = setup()\n const initial = provider.attach(true)\n calls[0].result.resolve(answer('one'))\n await initial\n consumer._data.records[0].edited = true\n const a = provider.attach()\n const b = provider.attach()\n expect(a).to.equal(b)\n expect(calls.length).to.equal(2)\n calls[1].result.resolve(answer('one', 'two', 'two'))\n await a\n expect(provider.records).to.deep.equal([{ id: 'one', edited: true }, { id: 'one' }, { id: 'two' }, { id: 'two' }])\n expect(events[1].page).to.equal(2)\n expect(events[1].records.length).to.equal(4)\n expect(events[1].pageRecords.length).to.equal(3)\n })\n\n it('keeps rows and retries the same page after a failed append', async () => {\n const { provider, calls } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('one'))\n await initial\n const append = provider.attach()\n calls[1].result.reject(new Error('offline'))\n try {\n await append\n } catch {}\n expect(provider.records.map(row => row.id)).to.deep.equal(['one'])\n const retry = provider.attach()\n expect(calls[2].options.page).to.equal(2)\n calls[2].result.resolve(answer('two'))\n await retry\n expect(provider.records.map(row => row.id)).to.deep.equal(['one', 'two'])\n })\n\n it('a stale response cannot stop the current spinner or announce adoption', async () => {\n const { provider, calls, events, spinning } = setup()\n const old = provider.fetch()\n const next = provider.fetch()\n calls[0].result.resolve(answer('old'))\n await old\n expect(spinning()).to.equal(true)\n expect(events.length).to.equal(0)\n calls[1].result.resolve(answer('new'))\n await next\n expect(spinning()).to.equal(false)\n expect(events.length).to.equal(1)\n })\n\n it('disposal invalidates replacement and append responses', async () => {\n const { provider, calls, events, spinning } = setup()\n const request = provider.fetch()\n provider.dispose()\n expect(spinning()).to.equal(false)\n calls[0].result.resolve(answer('late'))\n await request\n expect(events.length).to.equal(0)\n })\n\n it('deactivation ends an append spinner and a late result cannot disturb a new read', async () => {\n const { provider, calls, spinning } = setup()\n const initial = provider.fetch()\n calls[0].result.resolve(answer('one'))\n await initial\n const append = provider.attach()\n provider.invalidate()\n expect(spinning()).to.equal(false)\n const replacement = provider.fetch()\n calls[1].result.resolve(answer('old'))\n await append\n expect(spinning()).to.equal(true)\n calls[2].result.resolve(answer('new'))\n await replacement\n expect(spinning()).to.equal(false)\n expect(provider.records.map(row => row.id)).to.deep.equal(['new'])\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import '../src/editors/ox-grist-editor-select.js';
@@ -0,0 +1,61 @@
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 { html } from 'lit';
4
+ import '../src/editors/ox-grist-editor-select.js';
5
+ import { buildColumn } from '../src/configure/column-builder.js';
6
+ /*
7
+ * An empty cell of a select column (the new row at the bottom of an appendable grid) must take its first option. The
8
+ * browser tells a change only when the picked option differs from the shown one, so the editor must not open showing
9
+ * the first option as picked (2026-11-08, 물품 대장 「종류」: 「처음에 "노트북.PC"를 선택해도 변화 이벤트가 발생하지 않아서」).
10
+ */
11
+ const KINDS = [
12
+ { display: '노트북.PC', value: 'COMPUTER' },
13
+ { display: '모니터', value: 'MONITOR' }
14
+ ];
15
+ const mount = async (record, mandatory = true) => {
16
+ const editor = (await fixture(html `${Object.assign(document.createElement('ox-grist-editor-select'), {
17
+ column: buildColumn({ type: 'select', name: 'kind', record: { editable: true, mandatory, options: KINDS } }),
18
+ record,
19
+ row: 0
20
+ })}`));
21
+ await editor.updateComplete;
22
+ const changes = [];
23
+ editor.addEventListener('field-change', event => changes.push(event.detail));
24
+ return { editor, changes, select: editor.renderRoot.querySelector('select') };
25
+ };
26
+ /* What the browser does on a pick: it tells input and change only when the picked option is not the shown one. */
27
+ const pick = (select, value) => {
28
+ if (select.value === value)
29
+ return;
30
+ select.value = value;
31
+ select.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
32
+ select.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
33
+ };
34
+ describe('a select cell with no value', () => {
35
+ for (const record of [{}, { kind: null }, { kind: '' }]) {
36
+ it(`takes the first option when it is picked (${JSON.stringify(record)})`, async () => {
37
+ const { editor, changes, select } = await mount(record);
38
+ pick(select, 'COMPUTER');
39
+ editor.flush();
40
+ expect(changes.length).to.equal(1);
41
+ expect(changes[0].after).to.equal('COMPUTER');
42
+ });
43
+ }
44
+ it('lists only the real options to pick from', async () => {
45
+ const { select } = await mount({});
46
+ const pickable = Array.from(select.options).filter(option => !option.hidden);
47
+ expect(pickable.map(option => option.value)).to.deep.equal(['COMPUTER', 'MONITOR']);
48
+ });
49
+ it('an untouched empty cell commits nothing', async () => {
50
+ const { editor, changes } = await mount({});
51
+ editor.flush();
52
+ editor._onfocusout();
53
+ expect(changes.length).to.equal(0);
54
+ });
55
+ it('a cell with a value opens on that value, with no blank option', async () => {
56
+ const { select } = await mount({ kind: 'MONITOR' });
57
+ expect(select.value).to.equal('MONITOR');
58
+ expect(select.options.length).to.equal(2);
59
+ });
60
+ });
61
+ //# sourceMappingURL=select-empty-value.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-empty-value.test.js","sourceRoot":"","sources":["../../test/select-empty-value.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,0CAA0C,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAGhE;;;;GAIG;AAEH,MAAM,KAAK,GAAG;IACZ,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACxC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;CACrC,CAAA;AAED,MAAM,KAAK,GAAG,KAAK,EAAE,MAAW,EAAE,SAAS,GAAG,IAAI,EAAE,EAAE;IACpD,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAC3B,IAAI,CAAA,GAAG,MAA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AC,WAAW,EAAE,CAAA;QACpB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QACxC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3C,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 { html } from 'lit'\n\nimport '../src/editors/ox-grist-editor-select.js'\nimport { buildColumn } from '../src/configure/column-builder.js'\nimport { OxGristEditor } from '../src/editors/ox-grist-editor.js'\n\n/*\n * An empty cell of a select column (the new row at the bottom of an appendable grid) must take its first option. The\n * browser tells a change only when the picked option differs from the shown one, so the editor must not open showing\n * the first option as picked (2026-11-08, 물품 대장 「종류」: 「처음에 \"노트북.PC\"를 선택해도 변화 이벤트가 발생하지 않아서」).\n */\n\nconst KINDS = [\n { display: '노트북.PC', value: 'COMPUTER' },\n { display: '모니터', value: 'MONITOR' }\n]\n\nconst mount = async (record: any, mandatory = true) => {\n const editor = (await fixture(\n html`${Object.assign(document.createElement('ox-grist-editor-select'), {\n column: buildColumn({ type: 'select', name: 'kind', record: { editable: true, mandatory, options: KINDS } }),\n record,\n row: 0\n })}`\n )) as OxGristEditor\n await editor.updateComplete\n const changes: any[] = []\n editor.addEventListener('field-change', event => changes.push((event as CustomEvent).detail))\n return { editor, changes, select: editor.renderRoot.querySelector('select') as HTMLSelectElement }\n}\n\n/* What the browser does on a pick: it tells input and change only when the picked option is not the shown one. */\nconst pick = (select: HTMLSelectElement, value: string) => {\n if (select.value === value) return\n select.value = value\n select.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n select.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n}\n\ndescribe('a select cell with no value', () => {\n for (const record of [{}, { kind: null }, { kind: '' }]) {\n it(`takes the first option when it is picked (${JSON.stringify(record)})`, async () => {\n const { editor, changes, select } = await mount(record)\n pick(select, 'COMPUTER')\n editor.flush()\n expect(changes.length).to.equal(1)\n expect(changes[0].after).to.equal('COMPUTER')\n })\n }\n\n it('lists only the real options to pick from', async () => {\n const { select } = await mount({})\n const pickable = Array.from(select.options).filter(option => !option.hidden)\n expect(pickable.map(option => option.value)).to.deep.equal(['COMPUTER', 'MONITOR'])\n })\n\n it('an untouched empty cell commits nothing', async () => {\n const { editor, changes } = await mount({})\n editor.flush()\n editor._onfocusout()\n expect(changes.length).to.equal(0)\n })\n\n it('a cell with a value opens on that value, with no blank option', async () => {\n const { select } = await mount({ kind: 'MONITOR' })\n expect(select.value).to.equal('MONITOR')\n expect(select.options.length).to.equal(2)\n })\n})\n"]}
@@ -0,0 +1,2 @@
1
+ import '../src/data-grist.js';
2
+ import '../src/data-report.js';