@operato/data-grist 10.29.69 → 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 (38) hide show
  1. package/CHANGELOG.md +16 -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-grid/data-grid-accum-field.js +2 -0
  5. package/dist/src/data-grid/data-grid-accum-field.js.map +1 -1
  6. package/dist/src/data-grid/data-grid-body-style.js +2 -0
  7. package/dist/src/data-grid/data-grid-body-style.js.map +1 -1
  8. package/dist/src/data-grid/data-grid-field.js +5 -12
  9. package/dist/src/data-grid/data-grid-field.js.map +1 -1
  10. package/dist/src/data-grid/data-grid-header.js +7 -1
  11. package/dist/src/data-grid/data-grid-header.js.map +1 -1
  12. package/dist/src/data-grid/data-grid.d.ts +1 -1
  13. package/dist/src/data-grid/data-grid.js +44 -18
  14. package/dist/src/data-grid/data-grid.js.map +1 -1
  15. package/dist/src/data-list/data-list-gutter.js +3 -0
  16. package/dist/src/data-list/data-list-gutter.js.map +1 -1
  17. package/dist/src/data-report/data-report-header.js +10 -11
  18. package/dist/src/data-report/data-report-header.js.map +1 -1
  19. package/dist/src/editors/ox-grist-editor-select.js +8 -1
  20. package/dist/src/editors/ox-grist-editor-select.js.map +1 -1
  21. package/dist/test/destructive-actions.test.d.ts +11 -0
  22. package/dist/test/destructive-actions.test.js +147 -0
  23. package/dist/test/destructive-actions.test.js.map +1 -0
  24. package/dist/test/flexible-columns.test.d.ts +1 -0
  25. package/dist/test/flexible-columns.test.js +134 -0
  26. package/dist/test/flexible-columns.test.js.map +1 -0
  27. package/dist/test/select-empty-value.test.d.ts +1 -0
  28. package/dist/test/select-empty-value.test.js +61 -0
  29. package/dist/test/select-empty-value.test.js.map +1 -0
  30. package/dist/test/wheel-one-scroller.test.d.ts +2 -0
  31. package/dist/test/wheel-one-scroller.test.js +275 -0
  32. package/dist/test/wheel-one-scroller.test.js.map +1 -0
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +7 -7
  35. package/test/destructive-actions.test.ts +137 -0
  36. package/test/flexible-columns.test.ts +181 -0
  37. package/test/select-empty-value.test.ts +71 -0
  38. package/test/wheel-one-scroller.test.ts +359 -0
@@ -0,0 +1,359 @@
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 { executeServerCommand, sendMouse } from '@web/test-runner-commands'
4
+ import { html } from 'lit'
5
+
6
+ import '../src/data-grist.js'
7
+ import '../src/data-report.js'
8
+
9
+ /**
10
+ * One wheel turn moves one box.
11
+ *
12
+ * A grid inside a page has two scrollers above each other: its own and the page's. Whatever a turn
13
+ * does, the worst outcome is both moving at once — the eye loses the row it was on and the place on
14
+ * the page together. So:
15
+ *
16
+ * ```
17
+ * rows a turn over the rows moves the rows; once they are at their end, the next turn moves
18
+ * the page (the browser hands it on — a turn that reaches the end stops there)
19
+ * sideways a sideways turn never leaves the grid (at the end of the columns it would otherwise
20
+ * become the browser's back gesture)
21
+ * header a vertical turn over the header or footer moves the columns (down = right); when the
22
+ * columns are already at that end the turn is left to the browser untouched
23
+ * ```
24
+ *
25
+ * These turns are real input through the browser (`send-wheel` in web-test-runner.config.mjs). A
26
+ * WheelEvent dispatched from the page runs the listeners but scrolls nothing.
27
+ */
28
+
29
+ type Root = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }
30
+
31
+ const settle = (ms = 400) => new Promise(resolve => setTimeout(resolve, ms))
32
+
33
+ /** The step a vertical turn over the header moves the columns by. */
34
+ const STEP = 30
35
+
36
+ async function page() {
37
+ const columns: any[] = [
38
+ { type: 'gutter', gutterName: 'sequence' },
39
+ { type: 'string', name: 'id', hidden: true },
40
+ { type: 'string', name: 'code', header: 'code', width: 120, fixed: true }
41
+ ]
42
+ for (let i = 0; i < 12; i++) {
43
+ columns.push({ type: 'string', name: 'c' + i, header: 'col ' + i, width: 110 })
44
+ }
45
+
46
+ const records = Array.from({ length: 60 }, (_, r) => {
47
+ const record: any = { id: String(r), code: 'C-' + r }
48
+ for (let i = 0; i < 12; i++) record['c' + i] = `v${r}-${i}`
49
+ return record
50
+ })
51
+
52
+ const outer = (await fixture(html`
53
+ <div style="position: fixed; left: 0; top: 0; width: 700px; height: 400px; overflow: auto">
54
+ <div style="height: 50px"></div>
55
+ <ox-grist
56
+ style="width: 600px; height: 300px"
57
+ mode="GRID"
58
+ .config=${{ columns, pagination: { pages: [100] } }}
59
+ .fetchHandler=${async () => ({ total: records.length, records })}
60
+ ></ox-grist>
61
+ <div style="height: 1000px"></div>
62
+ </div>
63
+ `)) as HTMLElement
64
+
65
+ const el = outer.querySelector('ox-grist') as Root & { fetch(): Promise<void> }
66
+ await el.fetch()
67
+ await settle(150)
68
+ await el.updateComplete
69
+
70
+ const grist = el.renderRoot.querySelector('#grist') as Root
71
+ const scroller = grist.renderRoot.querySelector('div[grid]') as HTMLElement
72
+ const header = grist.renderRoot.querySelector('ox-grid-header') as Root
73
+ const body = grist.renderRoot.querySelector('ox-grid-body') as Root
74
+ await body.updateComplete
75
+
76
+ /*
77
+ * The ends as the browser lets the grid reach them. scrollWidth - clientWidth overshoots by the
78
+ * vertical scrollbar's gutter here (885 measured, 880 reachable), so it is not trusted.
79
+ */
80
+ scroller.scrollTop = scroller.scrollLeft = 1e6
81
+ const maxTop = Math.round(scroller.scrollTop)
82
+ const maxLeft = Math.round(scroller.scrollLeft)
83
+ scroller.scrollTop = scroller.scrollLeft = 0
84
+ expect(maxTop, 'the rows must overflow, or this measures nothing').to.be.greaterThan(200)
85
+ expect(maxLeft, 'the columns must overflow, or this measures nothing').to.be.greaterThan(200)
86
+
87
+ return { outer, scroller, header, body, maxTop, maxLeft }
88
+ }
89
+
90
+ /** Where every box stands: the page, and the grid both ways. */
91
+ function where(outer: HTMLElement, scroller: HTMLElement) {
92
+ return { page: Math.round(outer.scrollTop), top: Math.round(scroller.scrollTop), left: Math.round(scroller.scrollLeft) }
93
+ }
94
+
95
+ /*
96
+ * Where to put the pointer, in the viewport. Header and body are as wide as all the columns and the body
97
+ * as tall as all the rows, so their own boxes reach off screen once the grid scrolls — the point is taken
98
+ * from the grid's visible box instead.
99
+ */
100
+ function overRows(scroller: HTMLElement, header: HTMLElement) {
101
+ const r = scroller.getBoundingClientRect()
102
+ return { x: Math.round(r.left + r.width / 2), y: Math.round(header.getBoundingClientRect().bottom + 100) }
103
+ }
104
+
105
+ function overHeader(scroller: HTMLElement, header: HTMLElement) {
106
+ const r = scroller.getBoundingClientRect()
107
+ const h = header.getBoundingClientRect()
108
+ return { x: Math.round(r.left + r.width / 2), y: Math.round(h.top + h.height / 2) }
109
+ }
110
+
111
+ async function turn(at: { x: number; y: number }, deltaY: number, deltaX = 0) {
112
+ await executeServerCommand('send-wheel', { ...at, deltaX, deltaY })
113
+ await settle()
114
+ }
115
+
116
+ describe('one wheel turn moves one box', () => {
117
+ /* Resizing the grid body inside a fixture trips Chrome's benign "ResizeObserver loop" error. */
118
+ const ignoreResizeLoop = (e: ErrorEvent) => {
119
+ if (String(e.message).includes('ResizeObserver loop')) {
120
+ e.stopImmediatePropagation()
121
+ e.preventDefault()
122
+ }
123
+ }
124
+ let previousOnError: OnErrorEventHandler = null
125
+ before(() => {
126
+ window.addEventListener('error', ignoreResizeLoop, true)
127
+ previousOnError = window.onerror
128
+ window.onerror = (message, ...rest) =>
129
+ String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest)
130
+ })
131
+ after(async () => {
132
+ window.removeEventListener('error', ignoreResizeLoop, true)
133
+ window.onerror = previousOnError
134
+ await sendMouse({ type: 'move', position: [0, 0] })
135
+ })
136
+
137
+ describe('over the rows', () => {
138
+ it('a turn moves the rows, nothing else', async () => {
139
+ const { outer, scroller, header } = await page()
140
+
141
+ await turn(overRows(scroller, header), 100)
142
+
143
+ const now = where(outer, scroller)
144
+ expect(now.top).to.be.greaterThan(0)
145
+ expect(now.page).to.equal(0)
146
+ expect(now.left).to.equal(0)
147
+ })
148
+
149
+ it('the turn that reaches the last row stops there', async () => {
150
+ const { outer, scroller, header, maxTop } = await page()
151
+ scroller.scrollTop = maxTop - 10
152
+ await settle(100)
153
+
154
+ await turn(overRows(scroller, header), 100)
155
+
156
+ const now = where(outer, scroller)
157
+ expect(now.top).to.be.within(maxTop - 1, maxTop)
158
+ expect(now.page).to.equal(0)
159
+ })
160
+
161
+ it('with the rows at their end, the next turn moves the page', async () => {
162
+ const { outer, scroller, header, maxTop } = await page()
163
+ scroller.scrollTop = maxTop
164
+ scroller.scrollLeft = 100
165
+ await settle(100)
166
+
167
+ await turn(overRows(scroller, header), 100)
168
+
169
+ const now = where(outer, scroller)
170
+ expect(now.page).to.be.greaterThan(0)
171
+ expect(now.top).to.be.within(maxTop - 1, maxTop)
172
+ expect(now.left, 'the turn does not become a sideways move').to.equal(100)
173
+ })
174
+
175
+ it('with the rows at their start, a turn up moves the page', async () => {
176
+ const { outer, scroller, header } = await page()
177
+ outer.scrollTop = 40
178
+ await settle(100)
179
+
180
+ await turn(overRows(scroller, header), -100)
181
+
182
+ const now = where(outer, scroller)
183
+ expect(now.page).to.be.lessThan(40)
184
+ expect(now.top).to.equal(0)
185
+ })
186
+
187
+ it('a sideways turn at the last column stays in the grid', async () => {
188
+ const { scroller } = await page()
189
+
190
+ const style = getComputedStyle(scroller)
191
+ expect(style.overscrollBehaviorX).to.equal('contain')
192
+ expect(style.overscrollBehaviorY).to.equal('auto')
193
+ })
194
+ })
195
+
196
+ describe('over the header', () => {
197
+ it('a turn down moves the columns right, nothing else', async () => {
198
+ const { outer, scroller, header } = await page()
199
+ scroller.scrollLeft = 100
200
+ await settle(100)
201
+
202
+ await turn(overHeader(scroller, header), 100)
203
+
204
+ expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 0, left: 100 + STEP })
205
+ })
206
+
207
+ it('a turn up moves the columns left, nothing else', async () => {
208
+ const { outer, scroller, header } = await page()
209
+ scroller.scrollLeft = 100
210
+ await settle(100)
211
+
212
+ await turn(overHeader(scroller, header), -100)
213
+
214
+ expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 0, left: 100 - STEP })
215
+ })
216
+
217
+ it('the turn that brings the columns to their last one stops there', async () => {
218
+ const { outer, scroller, header, maxLeft } = await page()
219
+ scroller.scrollLeft = maxLeft - 10
220
+ await settle(100)
221
+
222
+ await turn(overHeader(scroller, header), 100)
223
+
224
+ const now = where(outer, scroller)
225
+ expect(now.left).to.be.within(maxLeft - 1, maxLeft)
226
+ expect(now.top, 'the rows stay').to.equal(0)
227
+ expect(now.page, 'the page stays').to.equal(0)
228
+ })
229
+
230
+ it('the turn that brings the columns to their first one stops there', async () => {
231
+ const { outer, scroller, header } = await page()
232
+ scroller.scrollTop = 100
233
+ scroller.scrollLeft = 10
234
+ await settle(100)
235
+
236
+ await turn(overHeader(scroller, header), -100)
237
+
238
+ expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 100, left: 0 })
239
+ })
240
+
241
+ it('with the columns at their last one, a turn down is left to the browser', async () => {
242
+ const { outer, scroller, header, maxLeft } = await page()
243
+ scroller.scrollLeft = maxLeft
244
+ await settle(100)
245
+
246
+ await turn(overHeader(scroller, header), 100)
247
+
248
+ const now = where(outer, scroller)
249
+ expect(now.left).to.be.within(maxLeft - 1, maxLeft)
250
+ expect(now.top, 'the rows take the turn').to.be.greaterThan(0)
251
+ expect(now.page).to.equal(0)
252
+ })
253
+ })
254
+
255
+ /*
256
+ * The report's header is a box of its own beside the body (they copy each other's scrollLeft), so
257
+ * a turn the header leaves alone goes to the boxes around it. The same rule holds: the columns, or
258
+ * the rest — never both.
259
+ */
260
+ describe('over the report header', () => {
261
+ async function report() {
262
+ const columns: any[] = [
263
+ { type: 'string', name: 'id', hidden: true },
264
+ { type: 'string', name: 'kind', header: 'kind', width: 110 }
265
+ ]
266
+ for (let i = 0; i < 12; i++) {
267
+ columns.push({ type: 'string', name: 'c' + i, header: 'col ' + i, width: 110 })
268
+ }
269
+ const records = Array.from({ length: 60 }, (_, r) => {
270
+ const record: any = { id: String(r), kind: 'K' + (r % 4) }
271
+ for (let i = 0; i < 12; i++) record['c' + i] = `v${r}-${i}`
272
+ return record
273
+ })
274
+
275
+ const outer = (await fixture(html`
276
+ <div style="position: fixed; left: 0; top: 0; width: 700px; height: 400px; overflow: auto">
277
+ <div style="height: 50px"></div>
278
+ <ox-report
279
+ style="width: 600px; height: 300px"
280
+ .config=${{ columns, rows: { groups: [{ column: 'kind' }], totals: [] }, pagination: { pages: [100] } }}
281
+ .fetchHandler=${async () => ({ total: records.length, records })}
282
+ ></ox-report>
283
+ <div style="height: 1000px"></div>
284
+ </div>
285
+ `)) as HTMLElement
286
+
287
+ const el = outer.querySelector('ox-report') as Root & { fetch(): Promise<void> }
288
+ await el.fetch()
289
+ await settle(150)
290
+ await el.updateComplete
291
+
292
+ const component = el.renderRoot.querySelector('#report') as Root
293
+ await component.updateComplete
294
+ const header = component.renderRoot.querySelector('ox-report-header') as HTMLElement
295
+ const body = component.renderRoot.querySelector('ox-report-body') as HTMLElement
296
+
297
+ header.scrollLeft = 1e6
298
+ const maxLeft = Math.round(header.scrollLeft)
299
+ header.scrollLeft = 0
300
+ await settle(100)
301
+ expect(maxLeft, 'the columns must overflow, or this measures nothing').to.be.greaterThan(200)
302
+
303
+ const r = header.getBoundingClientRect()
304
+ const at = { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) }
305
+
306
+ /* Everything a turn could move. */
307
+ const boxes = () => ({
308
+ page: Math.round(outer.scrollTop),
309
+ left: Math.round(header.scrollLeft),
310
+ rows: Math.round(body.scrollTop),
311
+ wrap: Math.round((el.renderRoot.querySelector('#wrap') as HTMLElement).scrollTop)
312
+ })
313
+
314
+ return { header, body, maxLeft, at, boxes }
315
+ }
316
+
317
+ it('a turn down moves the columns right, nothing else', async () => {
318
+ const { header, at, boxes } = await report()
319
+ header.scrollLeft = 100
320
+ await settle(100)
321
+
322
+ await turn(at, 100)
323
+
324
+ expect(boxes()).to.deep.equal({ page: 0, left: 140, rows: 0, wrap: 0 })
325
+ })
326
+
327
+ it('the turn that brings the columns to their last one stops there', async () => {
328
+ const { header, maxLeft, at, boxes } = await report()
329
+ header.scrollLeft = maxLeft - 10
330
+ await settle(100)
331
+
332
+ await turn(at, 100)
333
+
334
+ expect(boxes()).to.deep.equal({ page: 0, left: maxLeft, rows: 0, wrap: 0 })
335
+ })
336
+
337
+ it('the turn that brings the columns to their first one stops there', async () => {
338
+ const { header, at, boxes } = await report()
339
+ header.scrollLeft = 10
340
+ await settle(100)
341
+
342
+ await turn(at, -100)
343
+
344
+ expect(boxes()).to.deep.equal({ page: 0, left: 0, rows: 0, wrap: 0 })
345
+ })
346
+
347
+ it('with the columns at their last one, a turn down is left to the browser', async () => {
348
+ const { header, maxLeft, at, boxes } = await report()
349
+ header.scrollLeft = maxLeft
350
+ await settle(100)
351
+
352
+ await turn(at, 100)
353
+
354
+ const now = boxes()
355
+ expect(now.left).to.equal(maxLeft)
356
+ expect(now.page + now.wrap, 'a box around the header takes the turn').to.be.greaterThan(0)
357
+ })
358
+ })
359
+ })