@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.
- package/CHANGELOG.md +34 -0
- package/dist/src/data-card/data-card-gutter.js +3 -15
- package/dist/src/data-card/data-card-gutter.js.map +1 -1
- package/dist/src/data-consumer.d.ts +4 -1
- package/dist/src/data-consumer.js.map +1 -1
- package/dist/src/data-grid/data-grid-accum-field.js +2 -0
- package/dist/src/data-grid/data-grid-accum-field.js.map +1 -1
- package/dist/src/data-grid/data-grid-body-style.js +2 -0
- package/dist/src/data-grid/data-grid-body-style.js.map +1 -1
- package/dist/src/data-grid/data-grid-field.js +7 -12
- package/dist/src/data-grid/data-grid-field.js.map +1 -1
- package/dist/src/data-grid/data-grid-header.js +7 -1
- package/dist/src/data-grid/data-grid-header.js.map +1 -1
- package/dist/src/data-grid/data-grid.d.ts +1 -1
- package/dist/src/data-grid/data-grid.js +44 -18
- package/dist/src/data-grid/data-grid.js.map +1 -1
- package/dist/src/data-grist.d.ts +5 -1
- package/dist/src/data-grist.js +3 -0
- package/dist/src/data-grist.js.map +1 -1
- package/dist/src/data-list/data-list-gutter.js +3 -0
- package/dist/src/data-list/data-list-gutter.js.map +1 -1
- package/dist/src/data-provider.d.ts +2 -0
- package/dist/src/data-provider.js +28 -9
- package/dist/src/data-provider.js.map +1 -1
- package/dist/src/data-report/data-report-header.js +10 -11
- package/dist/src/data-report/data-report-header.js.map +1 -1
- package/dist/src/editors/ox-grist-editor-select.js +8 -1
- package/dist/src/editors/ox-grist-editor-select.js.map +1 -1
- package/dist/src/filters/filter-select-buttons.js +3 -1
- package/dist/src/filters/filter-select-buttons.js.map +1 -1
- package/dist/src/filters/filters-form.d.ts +2 -0
- package/dist/src/filters/filters-form.js +5 -0
- package/dist/src/filters/filters-form.js.map +1 -1
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.js.map +1 -1
- package/dist/test/count-handler.test.d.ts +1 -0
- package/dist/test/count-handler.test.js +56 -0
- package/dist/test/count-handler.test.js.map +1 -0
- package/dist/test/destructive-actions.test.d.ts +11 -0
- package/dist/test/destructive-actions.test.js +147 -0
- package/dist/test/destructive-actions.test.js.map +1 -0
- package/dist/test/flexible-columns.test.d.ts +1 -0
- package/dist/test/flexible-columns.test.js +134 -0
- package/dist/test/flexible-columns.test.js.map +1 -0
- package/dist/test/request-generation.test.js +15 -0
- package/dist/test/request-generation.test.js.map +1 -1
- package/dist/test/select-empty-value.test.d.ts +1 -0
- package/dist/test/select-empty-value.test.js +61 -0
- package/dist/test/select-empty-value.test.js.map +1 -0
- package/dist/test/wheel-one-scroller.test.d.ts +2 -0
- package/dist/test/wheel-one-scroller.test.js +275 -0
- package/dist/test/wheel-one-scroller.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/test/count-handler.test.ts +61 -0
- package/test/destructive-actions.test.ts +137 -0
- package/test/flexible-columns.test.ts +181 -0
- package/test/request-generation.test.ts +16 -0
- package/test/select-empty-value.test.ts +71 -0
- package/test/wheel-one-scroller.test.ts +359 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/data-grist",
|
|
3
|
-
"version": "10.29.
|
|
3
|
+
"version": "10.29.70",
|
|
4
4
|
"description": "User interface for grid (desktop) and list (mobile)",
|
|
5
5
|
"author": "heartyoh",
|
|
6
6
|
"type": "module",
|
|
@@ -78,15 +78,15 @@
|
|
|
78
78
|
"@material/web": "^2.0.0",
|
|
79
79
|
"@operato/headroom": "^10.29.1",
|
|
80
80
|
"@operato/i18n": "^10.29.27",
|
|
81
|
-
"@operato/input": "^10.29.
|
|
82
|
-
"@operato/layout": "^10.29.
|
|
83
|
-
"@operato/list-state": "^10.29.
|
|
84
|
-
"@operato/p13n": "^10.29.
|
|
85
|
-
"@operato/popup": "^10.29.
|
|
81
|
+
"@operato/input": "^10.29.70",
|
|
82
|
+
"@operato/layout": "^10.29.70",
|
|
83
|
+
"@operato/list-state": "^10.29.69",
|
|
84
|
+
"@operato/p13n": "^10.29.70",
|
|
85
|
+
"@operato/popup": "^10.29.70",
|
|
86
86
|
"@operato/pull-to-refresh": "^10.29.23",
|
|
87
|
-
"@operato/styles": "^10.29.
|
|
87
|
+
"@operato/styles": "^10.29.70",
|
|
88
88
|
"@operato/time-calculator": "^10.29.1",
|
|
89
|
-
"@operato/utils": "^10.29.
|
|
89
|
+
"@operato/utils": "^10.29.69",
|
|
90
90
|
"i18next": "^24.2.1",
|
|
91
91
|
"json5": "^2.2.0",
|
|
92
92
|
"lit": "^3.1.2",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"prettier --write"
|
|
126
126
|
]
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "7451d7242ca5e396bbdeb89fc46470d52c89e8cd"
|
|
129
129
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
2
|
+
import { html, render } from 'lit'
|
|
3
|
+
|
|
4
|
+
import { DataProvider } from '../src/data-provider.js'
|
|
5
|
+
import type { DataConsumer } from '../src/data-consumer.js'
|
|
6
|
+
import { FilterSelectButtons } from '../src/filters/filter-select-buttons.js'
|
|
7
|
+
import type { FetchOption, FetchResult } from '../src/types.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The counts beside a list's filter choices (ADR-0190): read with the conditions of each fetch that replaces the rows,
|
|
11
|
+
* under its signal - only the counts of the current read land, and a chip shows them when its option has none.
|
|
12
|
+
*/
|
|
13
|
+
function deferred<T>() {
|
|
14
|
+
let resolve!: (value: T) => void
|
|
15
|
+
const promise = new Promise<T>(yes => (resolve = yes))
|
|
16
|
+
return { promise, resolve }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function setup() {
|
|
20
|
+
const counted: { options: FetchOption; answer: ReturnType<typeof deferred<Record<string, Record<string, number>>>> }[] = []
|
|
21
|
+
const consumer = Object.assign(new EventTarget(), {
|
|
22
|
+
shownMode: 'GRID' as const,
|
|
23
|
+
data: { records: [] },
|
|
24
|
+
_data: { records: [] },
|
|
25
|
+
checkDirties() {},
|
|
26
|
+
showSpinner() {},
|
|
27
|
+
hideSpinner() {},
|
|
28
|
+
fetchHandler: async (): Promise<FetchResult> => ({ total: 0, records: [] }),
|
|
29
|
+
countHandler(options: FetchOption) {
|
|
30
|
+
const answer = deferred<Record<string, Record<string, number>>>()
|
|
31
|
+
counted.push({ options, answer })
|
|
32
|
+
return answer.promise
|
|
33
|
+
}
|
|
34
|
+
}) as unknown as DataConsumer
|
|
35
|
+
return { provider: new DataProvider(consumer), consumer, counted }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('countHandler', () => {
|
|
39
|
+
it("is read with the fetch's conditions and signal; a count of a read replaced never lands", async () => {
|
|
40
|
+
const { provider, consumer, counted } = setup()
|
|
41
|
+
provider.filters = [{ name: 'state', operator: 'in', value: ['draft'] }] as any
|
|
42
|
+
void provider.fetch()
|
|
43
|
+
void provider.fetch()
|
|
44
|
+
expect(counted.length).to.equal(2)
|
|
45
|
+
expect(counted[0].options.filters).to.deep.equal([{ name: 'state', operator: 'in', value: ['draft'] }])
|
|
46
|
+
expect(counted[0].options.signal?.aborted).to.equal(true)
|
|
47
|
+
counted[1].answer.resolve({ state: { draft: 2 } })
|
|
48
|
+
await Promise.resolve()
|
|
49
|
+
counted[0].answer.resolve({ state: { draft: 99 } })
|
|
50
|
+
await Promise.resolve()
|
|
51
|
+
expect(consumer.counts).to.deep.equal({ state: { draft: 2 } })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('a chip shows the grid count for its column and value, unless the option gives its own', async () => {
|
|
55
|
+
const column = { name: 'state', filter: { operator: 'in', options: [{ display: 'Draft', value: 'draft' }, { display: 'Released', value: 'released', count: 7 }] }, record: {} } as any
|
|
56
|
+
const host = await fixture<HTMLElement>(html`<div></div>`)
|
|
57
|
+
render(FilterSelectButtons(column, [], { counts: { state: { draft: 3, released: 1 } } } as any), host)
|
|
58
|
+
const buttons = host.querySelector('ox-input-select-buttons') as any
|
|
59
|
+
expect(buttons.options.map((one: any) => one.count)).to.deep.equal([3, 7])
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
2
|
+
import { sendMouse } from '@web/test-runner-commands'
|
|
3
|
+
import { css, html, LitElement, type TemplateResult } 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
|
+
|
|
17
|
+
class BodyProbe extends LitElement {
|
|
18
|
+
static properties = { content: { attribute: false } }
|
|
19
|
+
content?: TemplateResult
|
|
20
|
+
static styles = [ButtonStyles, css`:host { display: block }`]
|
|
21
|
+
render() { return this.content ?? html`<button type="button" danger><md-icon>delete</md-icon>Delete</button>` }
|
|
22
|
+
}
|
|
23
|
+
class BarProbe extends BodyProbe { static styles = [ButtonContainerStyles] }
|
|
24
|
+
class HeaderProbe extends BodyProbe {
|
|
25
|
+
static styles = [CommonHeaderStyles]
|
|
26
|
+
render() { return html`<div class="header"><div class="actions"><button type="button" danger class="textbtn"><md-icon>delete</md-icon>Delete</button></div></div>` }
|
|
27
|
+
}
|
|
28
|
+
customElements.define('danger-body-probe', BodyProbe)
|
|
29
|
+
customElements.define('danger-bar-probe', BarProbe)
|
|
30
|
+
customElements.define('danger-header-probe', HeaderProbe)
|
|
31
|
+
|
|
32
|
+
const column = { type: 'gutter', name: 'delete', danger: true, record: { renderer: () => html`<button type="button"><md-icon>delete</md-icon><span>Delete</span></button>` } }
|
|
33
|
+
const cases = [
|
|
34
|
+
['form', html`<danger-body-probe></danger-body-probe>`],
|
|
35
|
+
['quiet form', html`<danger-body-probe .content=${html`<button type="button" quiet danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],
|
|
36
|
+
['raised form', html`<danger-body-probe .content=${html`<button type="button" raised danger><md-icon>delete</md-icon>Delete</button>`}></danger-body-probe>`],
|
|
37
|
+
['toolbar', html`<danger-bar-probe></danger-bar-probe>`],
|
|
38
|
+
['header', html`<danger-header-probe></danger-header-probe>`],
|
|
39
|
+
['grid', html`<ox-grid-field danger .column=${column}></ox-grid-field>`],
|
|
40
|
+
['card', html`<ox-card-gutter .column=${column}></ox-card-gutter>`],
|
|
41
|
+
['mobile list', html`<ox-list-gutter .column=${column}></ox-list-gutter>`],
|
|
42
|
+
['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>`],
|
|
43
|
+
['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>`],
|
|
44
|
+
['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>`],
|
|
45
|
+
['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>`],
|
|
46
|
+
['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>`],
|
|
47
|
+
['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>`],
|
|
48
|
+
['popup native', html`<ox-popup-actions><button type="button" slot="start" destructive><md-icon>delete</md-icon>Delete</button></ox-popup-actions>`],
|
|
49
|
+
['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>`],
|
|
50
|
+
['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>`],
|
|
51
|
+
['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>`],
|
|
52
|
+
] as const
|
|
53
|
+
|
|
54
|
+
const themes = {
|
|
55
|
+
light: { error: '#ba1a1a', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' },
|
|
56
|
+
dark: { error: '#ffb4ab', onError: '#690005', container: '#93000a', onContainer: '#ffdad6', surface: '#121212' },
|
|
57
|
+
boardDark: { error: '#fbafa9', onError: '#a3000c', container: '#a3000c', onContainer: '#fbafa9', surface: '#121318' },
|
|
58
|
+
custom: { error: '#a00000', onError: '#ffffff', container: '#ffdad6', onContainer: '#410002', surface: '#ffffff' }
|
|
59
|
+
}
|
|
60
|
+
const settle = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))
|
|
61
|
+
function 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 }
|
|
62
|
+
function contrast(a: string, b: string) {
|
|
63
|
+
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)
|
|
64
|
+
const x = light(a), y = light(b)
|
|
65
|
+
return (Math.max(x, y) + .05) / (Math.min(x, y) + .05)
|
|
66
|
+
}
|
|
67
|
+
function background(node: Element): string {
|
|
68
|
+
for (let current: Element | null = node; current; current = current.parentElement ?? (current.getRootNode() as ShadowRoot).host ?? null) {
|
|
69
|
+
const color = getComputedStyle(current).backgroundColor
|
|
70
|
+
if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') return color
|
|
71
|
+
}
|
|
72
|
+
return 'rgb(255, 255, 255)'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const [themeName, theme] of Object.entries(themes)) {
|
|
76
|
+
describe(`destructive action contrast: ${themeName}`, () => {
|
|
77
|
+
for (const [kind, template] of cases) {
|
|
78
|
+
it(`${kind}: icon follows the label before hover, on hover, focus, press and disabled`, async () => {
|
|
79
|
+
await sendMouse({ type: 'move', position: [0, 0] })
|
|
80
|
+
const root = await fixture<HTMLElement>(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
|
+
})) root.style.setProperty(name, value)
|
|
87
|
+
if (themeName === 'custom') {
|
|
88
|
+
root.style.setProperty('--danger-button-background', '#520000')
|
|
89
|
+
root.style.setProperty('--danger-button-color', '#fff0f0')
|
|
90
|
+
root.style.setProperty('--danger-button-hover-background', '#fff0f0')
|
|
91
|
+
root.style.setProperty('--danger-button-hover-color', '#520000')
|
|
92
|
+
}
|
|
93
|
+
if (themeName === 'boardDark') {
|
|
94
|
+
root.style.setProperty('--danger-button-background', 'var(--md-sys-color-error-container)')
|
|
95
|
+
root.style.setProperty('--danger-button-color', 'var(--md-sys-color-on-error-container)')
|
|
96
|
+
root.style.setProperty('--danger-button-hover-background', 'color-mix(in srgb, var(--md-sys-color-error-container) 88%, black)')
|
|
97
|
+
root.style.setProperty('--danger-button-hover-color', 'var(--md-sys-color-on-error-container)')
|
|
98
|
+
}
|
|
99
|
+
root.style.backgroundColor = theme.surface
|
|
100
|
+
await settle()
|
|
101
|
+
const surface = root.firstElementChild as HTMLElement & { updateComplete?: Promise<unknown> }
|
|
102
|
+
await surface.updateComplete
|
|
103
|
+
const slotted = surface.tagName.startsWith('OX-POPUP')
|
|
104
|
+
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 }
|
|
105
|
+
const icon = control.querySelector('md-icon')!
|
|
106
|
+
const label = (control.shadowRoot?.querySelector('.label') ?? control.shadowRoot?.querySelector('button') ?? control) as HTMLElement
|
|
107
|
+
const focusTarget = (control.shadowRoot?.querySelector('button') ?? control) as HTMLElement
|
|
108
|
+
label.style.transition = 'none'
|
|
109
|
+
control.style.transition = 'none'
|
|
110
|
+
const check = (disabled = false) => {
|
|
111
|
+
const ink = getComputedStyle(label).color
|
|
112
|
+
expect(getComputedStyle(icon).color, `${kind} icon/label`).to.equal(ink)
|
|
113
|
+
expect(icon.getBoundingClientRect().width).to.be.greaterThan(10)
|
|
114
|
+
if (!disabled) expect(contrast(ink, background(control)), `${kind} contrast`).to.be.at.least(4.5)
|
|
115
|
+
}
|
|
116
|
+
check()
|
|
117
|
+
const box = control.getBoundingClientRect()
|
|
118
|
+
const position: [number, number] = [Math.round(box.x + box.width / 2), Math.round(box.y + box.height / 2)]
|
|
119
|
+
await sendMouse({ type: 'move', position })
|
|
120
|
+
await settle()
|
|
121
|
+
expect(control.matches(':hover')).to.equal(true)
|
|
122
|
+
check()
|
|
123
|
+
await sendMouse({ type: 'move', position: [0, 0] })
|
|
124
|
+
control.focus()
|
|
125
|
+
await settle()
|
|
126
|
+
check()
|
|
127
|
+
await sendMouse({ type: 'move', position })
|
|
128
|
+
await sendMouse({ type: 'down' })
|
|
129
|
+
try { await settle(); check() } finally { await sendMouse({ type: 'up' }) }
|
|
130
|
+
focusTarget.blur(); control.blur()
|
|
131
|
+
control.disabled = true
|
|
132
|
+
await settle()
|
|
133
|
+
check(true)
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
|
|
6
|
+
import '../src/data-grist.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A column that takes the room left over: `width: 'minmax(150px, 1fr)'`.
|
|
10
|
+
*
|
|
11
|
+
* A string width goes into grid-template-columns as it is, so fr was always accepted — and broke the
|
|
12
|
+
* table. The header and the body are two CSS grids with the same template. A flexible track is sized
|
|
13
|
+
* from what its cells hold, and the two grids hold different things: the body grew the column to its
|
|
14
|
+
* longest text while the header kept it at its floor. Measured on the balance screen: 182px apart with
|
|
15
|
+
* one fr column whose text was longer than the room, 251px with two fr columns.
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* aligned every cell sits under its header, room or no room
|
|
19
|
+
* room a flexible column takes the room on the right; the filler after the last column gets none
|
|
20
|
+
* no room it stays at its floor and its text is cut ("…"), as a fixed column's is
|
|
21
|
+
* ratio 1fr and 2fr share the room one to two
|
|
22
|
+
* print the print template is a valid template (px became fr letter by letter: minmax(150fr, 1fr))
|
|
23
|
+
* resize dragging a flexible column's edge gives it a width in px from where it stood
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
type Root = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }
|
|
28
|
+
|
|
29
|
+
const settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms))
|
|
30
|
+
|
|
31
|
+
const LONG = 'A very long account name that is far wider than any room the table has left for it'
|
|
32
|
+
|
|
33
|
+
async function grid(widths: { name?: any; memo?: any }, width = 700, editable = false) {
|
|
34
|
+
const columns: any[] = [
|
|
35
|
+
{ type: 'string', name: 'id', hidden: true },
|
|
36
|
+
{ type: 'string', name: 'name', header: 'name', width: widths.name ?? 150, record: { editable } },
|
|
37
|
+
{ type: 'string', name: 'code', header: 'code', width: 100 },
|
|
38
|
+
{ type: 'string', name: 'memo', header: 'memo', width: widths.memo ?? 120 }
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
const records = Array.from({ length: 5 }, (_, r) => ({ id: String(r), name: r % 2 ? LONG : 'short', code: 'C-' + r, memo: 'note ' + r }))
|
|
42
|
+
|
|
43
|
+
const el = (await fixture(html`
|
|
44
|
+
<ox-grist
|
|
45
|
+
style=${`width: ${width}px; height: 320px`}
|
|
46
|
+
mode="GRID"
|
|
47
|
+
.config=${{ columns, pagination: { infinite: true }, rows: { appendable: false, selectable: false } }}
|
|
48
|
+
.data=${{ records }}
|
|
49
|
+
></ox-grist>
|
|
50
|
+
`)) as Root
|
|
51
|
+
|
|
52
|
+
await settle()
|
|
53
|
+
await el.updateComplete
|
|
54
|
+
|
|
55
|
+
const ox = el.renderRoot.querySelector('#grist') as Root
|
|
56
|
+
await ox.updateComplete
|
|
57
|
+
const scroller = ox.renderRoot.querySelector('div[grid]') as HTMLElement
|
|
58
|
+
const header = ox.renderRoot.querySelector('ox-grid-header') as Root
|
|
59
|
+
const body = ox.renderRoot.querySelector('ox-grid-body') as Root
|
|
60
|
+
await body.updateComplete
|
|
61
|
+
await settle(50)
|
|
62
|
+
|
|
63
|
+
return { ox, scroller, header, body }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function heads(header: Root) {
|
|
67
|
+
return Array.from(header.renderRoot.querySelectorAll('[role=columnheader]')) as HTMLElement[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function width(element: Element) {
|
|
71
|
+
return Math.round(element.getBoundingClientRect().width)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The largest distance, in left or in width, between a header cell and a cell of its column, over every row. */
|
|
75
|
+
function misalignment(header: Root, body: Root) {
|
|
76
|
+
const hs = heads(header)
|
|
77
|
+
let worst = 0
|
|
78
|
+
for (const row of Array.from(body.renderRoot.querySelectorAll('div[grid-row]'))) {
|
|
79
|
+
const cells = Array.from(row.querySelectorAll(':scope > ox-grid-field')) as HTMLElement[]
|
|
80
|
+
hs.forEach((h, i) => {
|
|
81
|
+
const cell = cells[i]
|
|
82
|
+
if (!cell) return
|
|
83
|
+
const a = h.getBoundingClientRect()
|
|
84
|
+
const b = cell.getBoundingClientRect()
|
|
85
|
+
worst = Math.max(worst, Math.abs(a.left - b.left), Math.abs(a.width - b.width))
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
return Math.round(worst)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Whether the text of a column's cell is cut in any row. */
|
|
92
|
+
function cut(body: Root, index: number) {
|
|
93
|
+
return Array.from(body.renderRoot.querySelectorAll('div[grid-row]')).some(row => {
|
|
94
|
+
const cell = row.querySelectorAll(':scope > ox-grid-field')[index] as Root | undefined
|
|
95
|
+
return !!cell && [cell, ...Array.from(cell.renderRoot.querySelectorAll('*'))].some(e => e.scrollWidth > e.clientWidth + 1)
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
describe('a flexible column', () => {
|
|
100
|
+
/* Resizing the grid body inside a fixture trips Chrome's benign "ResizeObserver loop" error. */
|
|
101
|
+
const ignoreResizeLoop = (e: ErrorEvent) => {
|
|
102
|
+
if (String(e.message).includes('ResizeObserver loop')) {
|
|
103
|
+
e.stopImmediatePropagation()
|
|
104
|
+
e.preventDefault()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let previousOnError: OnErrorEventHandler = null
|
|
108
|
+
before(() => {
|
|
109
|
+
window.addEventListener('error', ignoreResizeLoop, true)
|
|
110
|
+
previousOnError = window.onerror
|
|
111
|
+
window.onerror = (message, ...rest) =>
|
|
112
|
+
String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest)
|
|
113
|
+
})
|
|
114
|
+
after(async () => {
|
|
115
|
+
window.removeEventListener('error', ignoreResizeLoop, true)
|
|
116
|
+
window.onerror = previousOnError
|
|
117
|
+
await sendMouse({ type: 'move', position: [0, 0] })
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('with room, takes the room on the right and stays under its header', async () => {
|
|
121
|
+
const { scroller, header, body } = await grid({ name: 'minmax(150px, 1fr)' }, 1200)
|
|
122
|
+
|
|
123
|
+
const name = heads(header)[0]
|
|
124
|
+
expect(width(name), 'the column takes the room').to.be.greaterThan(500)
|
|
125
|
+
expect(scroller.scrollWidth, 'nothing overflows').to.be.at.most(scroller.clientWidth)
|
|
126
|
+
expect(misalignment(header, body)).to.equal(0)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('without room, stays at its floor, cuts its text and stays under its header', async () => {
|
|
130
|
+
const { header, body } = await grid({ name: 'minmax(150px, 1fr)', memo: 600 }, 700)
|
|
131
|
+
|
|
132
|
+
expect(width(heads(header)[0])).to.equal(150)
|
|
133
|
+
expect(cut(body, 0), 'the long name is cut').to.equal(true)
|
|
134
|
+
expect(misalignment(header, body)).to.equal(0)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('two flexible columns share the room one to two and stay under their headers', async () => {
|
|
138
|
+
const { header, body } = await grid({ name: 'minmax(100px, 1fr)', memo: 'minmax(100px, 2fr)' }, 900)
|
|
139
|
+
|
|
140
|
+
const [name, , memo] = heads(header)
|
|
141
|
+
/* fr shares the whole width of the tracks, not what is above their floors: 1fr and 2fr are x and 2x. */
|
|
142
|
+
const share = width(memo) / width(name)
|
|
143
|
+
expect(share).to.be.within(1.9, 2.1)
|
|
144
|
+
expect(misalignment(header, body)).to.equal(0)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('leaves a table of fixed columns as it was', async () => {
|
|
148
|
+
const { body } = await grid({}, 700)
|
|
149
|
+
|
|
150
|
+
const cell = body.renderRoot.querySelector('ox-grid-field') as HTMLElement
|
|
151
|
+
expect(getComputedStyle(cell).contain).to.equal('none')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('prints with a valid template', async () => {
|
|
155
|
+
const { ox } = await grid({ name: 'minmax(150px, 1fr)' }, 700)
|
|
156
|
+
|
|
157
|
+
const print = ox.style.getPropertyValue('--grid-template-print-columns')
|
|
158
|
+
expect(CSS.supports('grid-template-columns', print), print).to.equal(true)
|
|
159
|
+
expect(print).to.contain('150fr')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('dragging its edge gives it a width in px from where it stood', async () => {
|
|
163
|
+
const { header } = await grid({ name: 'minmax(150px, 1fr)' }, 1000, true)
|
|
164
|
+
|
|
165
|
+
const name = heads(header)[0]
|
|
166
|
+
const before = width(name)
|
|
167
|
+
const splitter = name.querySelector('span[splitter]') as HTMLElement
|
|
168
|
+
expect(!!splitter, 'an editable column has a handle').to.equal(true)
|
|
169
|
+
|
|
170
|
+
const r = splitter.getBoundingClientRect()
|
|
171
|
+
const x = Math.round(r.left + r.width / 2)
|
|
172
|
+
const y = Math.round(r.top + r.height / 2)
|
|
173
|
+
await sendMouse({ type: 'move', position: [x, y] })
|
|
174
|
+
await sendMouse({ type: 'down' })
|
|
175
|
+
await sendMouse({ type: 'move', position: [x - 40, y] })
|
|
176
|
+
await sendMouse({ type: 'up' })
|
|
177
|
+
await settle(300)
|
|
178
|
+
|
|
179
|
+
expect(width(heads(header)[0])).to.be.within(before - 45, before - 35)
|
|
180
|
+
})
|
|
181
|
+
})
|
|
@@ -52,6 +52,22 @@ function setup() {
|
|
|
52
52
|
const answer = (...ids: string[]): FetchResult => ({ total: 100, records: ids.map(id => ({ id })) })
|
|
53
53
|
|
|
54
54
|
describe('query generations', () => {
|
|
55
|
+
it('hands each read a signal that a replacement or an invalidation aborts, an append sharing its generation', async () => {
|
|
56
|
+
const { provider, calls } = setup()
|
|
57
|
+
void provider.fetch()
|
|
58
|
+
const first = calls[0].options.signal!
|
|
59
|
+
expect(first.aborted).to.equal(false)
|
|
60
|
+
void provider.fetch()
|
|
61
|
+
expect(first.aborted).to.equal(true)
|
|
62
|
+
calls[1].result.resolve(answer('one'))
|
|
63
|
+
await Promise.resolve()
|
|
64
|
+
await Promise.resolve()
|
|
65
|
+
void provider.attach()
|
|
66
|
+
expect(calls[2].options.signal).to.equal(calls[1].options.signal)
|
|
67
|
+
provider.invalidate()
|
|
68
|
+
expect(calls[2].options.signal!.aborted).to.equal(true)
|
|
69
|
+
})
|
|
70
|
+
|
|
55
71
|
it('never appends an old query page to a replacement', async () => {
|
|
56
72
|
const { provider, calls, events } = setup()
|
|
57
73
|
const initial = provider.fetch()
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
|
|
5
|
+
import '../src/editors/ox-grist-editor-select.js'
|
|
6
|
+
import { buildColumn } from '../src/configure/column-builder.js'
|
|
7
|
+
import { OxGristEditor } from '../src/editors/ox-grist-editor.js'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* An empty cell of a select column (the new row at the bottom of an appendable grid) must take its first option. The
|
|
11
|
+
* browser tells a change only when the picked option differs from the shown one, so the editor must not open showing
|
|
12
|
+
* the first option as picked (2026-11-08, 물품 대장 「종류」: 「처음에 "노트북.PC"를 선택해도 변화 이벤트가 발생하지 않아서」).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const KINDS = [
|
|
16
|
+
{ display: '노트북.PC', value: 'COMPUTER' },
|
|
17
|
+
{ display: '모니터', value: 'MONITOR' }
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const mount = async (record: any, mandatory = true) => {
|
|
21
|
+
const editor = (await fixture(
|
|
22
|
+
html`${Object.assign(document.createElement('ox-grist-editor-select'), {
|
|
23
|
+
column: buildColumn({ type: 'select', name: 'kind', record: { editable: true, mandatory, options: KINDS } }),
|
|
24
|
+
record,
|
|
25
|
+
row: 0
|
|
26
|
+
})}`
|
|
27
|
+
)) as OxGristEditor
|
|
28
|
+
await editor.updateComplete
|
|
29
|
+
const changes: any[] = []
|
|
30
|
+
editor.addEventListener('field-change', event => changes.push((event as CustomEvent).detail))
|
|
31
|
+
return { editor, changes, select: editor.renderRoot.querySelector('select') as HTMLSelectElement }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* What the browser does on a pick: it tells input and change only when the picked option is not the shown one. */
|
|
35
|
+
const pick = (select: HTMLSelectElement, value: string) => {
|
|
36
|
+
if (select.value === value) return
|
|
37
|
+
select.value = value
|
|
38
|
+
select.dispatchEvent(new Event('input', { bubbles: true, composed: true }))
|
|
39
|
+
select.dispatchEvent(new Event('change', { bubbles: true, composed: true }))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('a select cell with no value', () => {
|
|
43
|
+
for (const record of [{}, { kind: null }, { kind: '' }]) {
|
|
44
|
+
it(`takes the first option when it is picked (${JSON.stringify(record)})`, async () => {
|
|
45
|
+
const { editor, changes, select } = await mount(record)
|
|
46
|
+
pick(select, 'COMPUTER')
|
|
47
|
+
editor.flush()
|
|
48
|
+
expect(changes.length).to.equal(1)
|
|
49
|
+
expect(changes[0].after).to.equal('COMPUTER')
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
it('lists only the real options to pick from', async () => {
|
|
54
|
+
const { select } = await mount({})
|
|
55
|
+
const pickable = Array.from(select.options).filter(option => !option.hidden)
|
|
56
|
+
expect(pickable.map(option => option.value)).to.deep.equal(['COMPUTER', 'MONITOR'])
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('an untouched empty cell commits nothing', async () => {
|
|
60
|
+
const { editor, changes } = await mount({})
|
|
61
|
+
editor.flush()
|
|
62
|
+
editor._onfocusout()
|
|
63
|
+
expect(changes.length).to.equal(0)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('a cell with a value opens on that value, with no blank option', async () => {
|
|
67
|
+
const { select } = await mount({ kind: 'MONITOR' })
|
|
68
|
+
expect(select.value).to.equal('MONITOR')
|
|
69
|
+
expect(select.options.length).to.equal(2)
|
|
70
|
+
})
|
|
71
|
+
})
|