@svgrid/grid 2.2.27 → 2.2.29
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/README.md +199 -199
- package/dist/FlexRender.svelte +96 -96
- package/dist/GridFooter.svelte +179 -179
- package/dist/GridMenus.svelte +782 -734
- package/dist/SvAutoComplete.svelte +165 -165
- package/dist/SvCalendar.svelte +503 -503
- package/dist/SvCarousel.svelte +141 -141
- package/dist/SvCheckBox.svelte +101 -101
- package/dist/SvColorInput.svelte +181 -181
- package/dist/SvComboBox.svelte +275 -275
- package/dist/SvContextMenu.svelte +116 -116
- package/dist/SvCountryInput.svelte +160 -160
- package/dist/SvDrawer.svelte +254 -250
- package/dist/SvDropDownList.svelte +374 -374
- package/dist/SvDurationInput.svelte +126 -126
- package/dist/SvField.svelte +293 -293
- package/dist/SvForm.svelte +437 -437
- package/dist/SvGrid.controller.svelte.d.ts +14 -1
- package/dist/SvGrid.controller.svelte.js +112 -28
- package/dist/SvGrid.css +2704 -2723
- package/dist/SvGrid.svelte +3361 -3333
- package/dist/SvGrid.types.d.ts +20 -5
- package/dist/SvGridChart.svelte +1724 -1724
- package/dist/SvGridChartPanel.svelte +485 -485
- package/dist/SvGridChartView.svelte +70 -70
- package/dist/SvGridDropdown.svelte +696 -696
- package/dist/SvGridSelect.svelte +259 -259
- package/dist/SvGroupCell.svelte +109 -109
- package/dist/SvListBox.svelte +326 -287
- package/dist/SvListBox.svelte.d.ts +10 -1
- package/dist/SvMaskedInput.svelte +122 -122
- package/dist/SvMenu.svelte +124 -124
- package/dist/SvMenuList.svelte +146 -146
- package/dist/SvMultiSelect.svelte +281 -281
- package/dist/SvNumberInput.svelte +168 -168
- package/dist/SvOtpInput.svelte +158 -158
- package/dist/SvPasswordInput.svelte +151 -151
- package/dist/SvPhoneInput.svelte +133 -131
- package/dist/SvPopover.svelte +197 -197
- package/dist/SvRadioGroup.svelte +107 -107
- package/dist/SvRowGroupPanel.svelte +170 -170
- package/dist/SvScrollArea.svelte +61 -61
- package/dist/SvSlider.svelte +200 -200
- package/dist/SvSwitchButton.svelte +107 -107
- package/dist/SvTagsInput.svelte +112 -112
- package/dist/SvTextInput.svelte +147 -147
- package/dist/SvTimePicker.svelte +245 -245
- package/dist/SvToaster.svelte +159 -159
- package/dist/SvToggleButton.svelte +85 -85
- package/dist/SvTooltip.svelte +161 -161
- package/dist/SvTour.svelte +204 -204
- package/dist/SvTree.svelte +437 -437
- package/dist/SvTreeSelect.svelte +233 -233
- package/dist/cdn/GridMenus-Da_p7SKS.js +486 -0
- package/dist/cdn/GridMenus-Ds3OpzZT.js +490 -0
- package/dist/cdn/{SvDateTimePicker-B1sDc9Pz.js → SvDateTimePicker-B8GopjhC.js} +2 -2
- package/dist/cdn/{SvDateTimePicker-Bh0FTs1E.js → SvDateTimePicker-DB0aIEk8.js} +2 -2
- package/dist/cdn/{SvGridChart-Bgk4hDs8.js → SvGridChart-BcLCYvw9.js} +1 -1
- package/dist/cdn/{SvGridChart-BKQsO5fZ.js → SvGridChart-BhnFdLd0.js} +1 -1
- package/dist/cdn/{SvGridChartPanel-DkCc2Z7b.js → SvGridChartPanel-Cmx9DHAS.js} +1 -1
- package/dist/cdn/{SvGridChartPanel-DSkHIQDd.js → SvGridChartPanel-DvjwxLvK.js} +1 -1
- package/dist/cdn/{SvGridChartView-BrbVaELm.js → SvGridChartView-B40DTJSX.js} +1 -1
- package/dist/cdn/{SvGridChartView-i9rWvSKg.js → SvGridChartView-PwqI4s02.js} +1 -1
- package/dist/cdn/{SvGridDropdown-D08sVmAy.js → SvGridDropdown-DjALc_4f.js} +1 -1
- package/dist/cdn/{SvGridDropdown-CGxxopQ4.js → SvGridDropdown-hpnHvOGt.js} +1 -1
- package/dist/cdn/{src-cgs1wcUS.js → src-BLJfdyL0.js} +4034 -3889
- package/dist/cdn/{src-Cw8d9U8j.js → src-DYDCiC0D.js} +7053 -6908
- package/dist/cdn/svgrid.js +9 -9
- package/dist/cdn/svgrid.svelte-external.js +9 -9
- package/dist/chart-export.js +8 -8
- package/dist/column-groups.js +8 -10
- package/dist/column-id.d.ts +9 -0
- package/dist/column-id.js +25 -0
- package/dist/core.js +2 -1
- package/dist/createListbox.svelte.d.ts +15 -2
- package/dist/createListbox.svelte.js +27 -6
- package/dist/editing.d.ts +1 -0
- package/dist/editing.js +45 -10
- package/dist/filtering/excel-filters.d.ts +30 -10
- package/dist/filtering/excel-filters.js +96 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/menus.d.ts +2 -0
- package/dist/menus.js +25 -0
- package/dist/row-resize.js +40 -0
- package/dist/selection.js +1 -1
- package/package.json +10 -10
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +179 -179
- package/src/GridMenus.svelte +782 -734
- package/src/SvAutoComplete.svelte +165 -165
- package/src/SvCalendar.svelte +503 -503
- package/src/SvCalendar.test.ts +226 -226
- package/src/SvCarousel.svelte +141 -141
- package/src/SvCheckBox.svelte +101 -101
- package/src/SvColorInput.svelte +181 -181
- package/src/SvComboBox.svelte +275 -275
- package/src/SvContextMenu.svelte +116 -116
- package/src/SvCountryInput.svelte +160 -160
- package/src/SvDrawer.svelte +254 -250
- package/src/SvDrawer.test.ts +18 -1
- package/src/SvDropDownList.svelte +374 -374
- package/src/SvDurationInput.svelte +126 -126
- package/src/SvField.svelte +293 -293
- package/src/SvForm.svelte +437 -437
- package/src/SvForm.test.ts +411 -411
- package/src/SvGrid.controller.svelte.ts +3335 -3239
- package/src/SvGrid.css +2704 -2723
- package/src/SvGrid.svelte +3361 -3333
- package/src/SvGrid.types.ts +1628 -1613
- package/src/SvGridChart.svelte +1724 -1724
- package/src/SvGridChartPanel.svelte +485 -485
- package/src/SvGridChartView.svelte +70 -70
- package/src/SvGridDropdown.svelte +696 -696
- package/src/SvGridSelect.svelte +259 -259
- package/src/SvGroupCell.svelte +109 -109
- package/src/SvListBox.svelte +326 -287
- package/src/SvMaskedInput.svelte +122 -122
- package/src/SvMenu.svelte +124 -124
- package/src/SvMenu.test.ts +97 -97
- package/src/SvMenuList.svelte +146 -146
- package/src/SvMultiSelect.svelte +281 -281
- package/src/SvNavPane.test.ts +15 -4
- package/src/SvNumberInput.svelte +168 -168
- package/src/SvOtpInput.svelte +158 -158
- package/src/SvPasswordInput.svelte +151 -151
- package/src/SvPhoneInput.svelte +133 -131
- package/src/SvPopover.svelte +197 -197
- package/src/SvRadioGroup.svelte +107 -107
- package/src/SvRowGroupPanel.svelte +170 -170
- package/src/SvScrollArea.svelte +61 -61
- package/src/SvSlider.svelte +200 -200
- package/src/SvSwitchButton.svelte +107 -107
- package/src/SvTagsInput.svelte +112 -112
- package/src/SvTextInput.svelte +147 -147
- package/src/SvTimePicker.svelte +245 -245
- package/src/SvToaster.svelte +159 -159
- package/src/SvToaster.test.ts +95 -95
- package/src/SvToggleButton.svelte +85 -85
- package/src/SvTooltip.svelte +161 -161
- package/src/SvTour.svelte +204 -204
- package/src/SvTree.svelte +437 -437
- package/src/SvTreeSelect.svelte +233 -233
- package/src/a11y/dismissable.test.ts +119 -119
- package/src/a11y/dismissable.ts +114 -114
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +61 -61
- package/src/ai.test.ts +502 -502
- package/src/ai.ts +1391 -1391
- package/src/build-api.coverage.test.ts +633 -633
- package/src/build-api.ts +895 -895
- package/src/builtin-editors.grid.test.ts +85 -85
- package/src/cell-formatting.ts +169 -169
- package/src/cell-render.ts +469 -469
- package/src/chart-export.ts +201 -201
- package/src/chart-view.svelte.ts +36 -36
- package/src/chart.ts +2296 -2296
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/column-groups.test.ts +48 -0
- package/src/column-groups.ts +8 -10
- package/src/column-id.ts +30 -0
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1112 -1111
- package/src/createAutocomplete.svelte.ts +132 -132
- package/src/createCombobox.svelte.ts +191 -191
- package/src/createCountryInput.svelte.ts +157 -157
- package/src/createDropdownList.svelte.ts +168 -168
- package/src/createForm.svelte.ts +386 -386
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/createListbox.svelte.ts +39 -7
- package/src/createMenu.svelte.ts +225 -225
- package/src/createPopoverSelect.svelte.ts +213 -213
- package/src/createSlider.svelte.ts +191 -191
- package/src/createTooltip.svelte.ts +144 -144
- package/src/createTree.svelte.ts +319 -319
- package/src/editing.test.ts +949 -859
- package/src/editing.ts +709 -675
- package/src/editor-contract.ts +157 -157
- package/src/export-data-api.test.ts +126 -126
- package/src/export-format.test.ts +107 -107
- package/src/export-format.ts +598 -598
- package/src/filter-operators.ts +157 -157
- package/src/filtering/excel-filters.test.ts +44 -1
- package/src/filtering/excel-filters.ts +91 -14
- package/src/flex-render.ts +3 -3
- package/src/form-field.ts +127 -127
- package/src/index.ts +715 -713
- package/src/js-scroller.svelte.ts +173 -173
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/list-nav.test.ts +49 -49
- package/src/list-nav.ts +29 -29
- package/src/list-option.test.ts +56 -56
- package/src/list-option.ts +172 -172
- package/src/menus.test.ts +736 -700
- package/src/menus.ts +679 -652
- package/src/merge-objects.ts +48 -48
- package/src/overlays.test.ts +90 -90
- package/src/render-component.ts +28 -28
- package/src/row-resize.test.ts +100 -0
- package/src/row-resize.ts +36 -0
- package/src/scheduler-model.test.ts +562 -562
- package/src/scheduler-model.ts +872 -872
- package/src/selection.test.ts +754 -754
- package/src/selection.ts +600 -600
- package/src/server-data-source.test.ts +289 -289
- package/src/server-data-source.ts +413 -413
- package/src/sparkline.test.ts +68 -68
- package/src/sparkline.ts +169 -169
- package/src/spreadsheet.test.ts +489 -489
- package/src/spreadsheet.ts +312 -312
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/svgrid-wrapper.types.ts +524 -524
- package/src/svgrid.api-extensions.test.ts +8 -3
- package/src/svgrid.behavior.test.ts +706 -706
- package/src/svgrid.cell-dom-ids.test.ts +96 -0
- package/src/svgrid.charting.test.ts +534 -534
- package/src/svgrid.conditional-stat-scope.test.ts +111 -0
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.filter-menu-listbox.svelte.test.ts +308 -0
- package/src/svgrid.filter-menu-scroll.test.ts +3 -1
- package/src/svgrid.group-header-ids.test.ts +121 -0
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/test-setup.ts +62 -62
- package/src/themes/index.ts +215 -215
- package/src/toast-store.svelte.ts +246 -246
- package/src/toast-store.test.ts +147 -147
- package/src/ui-buttons.test.ts +144 -144
- package/src/ui-inputs.test.ts +118 -118
- package/src/ui-range.test.ts +70 -70
- package/src/ui-selection.test.ts +155 -155
- package/src/ui-tier1.test.ts +142 -142
- package/src/virtual.test.ts +88 -88
- package/src/virtualization/column-virtualizer.test.ts +27 -27
- package/src/virtualization/column-virtualizer.ts +30 -30
- package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
- package/src/virtualization/types.ts +30 -30
- package/src/virtualization/virtualizer.test.ts +47 -47
- package/src/virtualization/virtualizer.ts +296 -296
- package/themes/ember.css +71 -71
- package/dist/cdn/GridMenus-BzxEYNtW.js +0 -421
- package/dist/cdn/GridMenus-Dr-nGEXn.js +0 -417
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
broadcastChannelTransport,
|
|
4
|
-
createCollaboration,
|
|
5
|
-
type CollabMessage,
|
|
6
|
-
type CollabTransport,
|
|
7
|
-
} from './collaboration'
|
|
8
|
-
|
|
9
|
-
/** An in-memory bus so two controllers can talk in a test. */
|
|
10
|
-
function makeBus() {
|
|
11
|
-
const handlers = new Set<(m: CollabMessage) => void>()
|
|
12
|
-
const transportFor = (): CollabTransport => ({
|
|
13
|
-
post: (msg) => {
|
|
14
|
-
// deliver async-ish to every subscriber except none (real channels echo
|
|
15
|
-
// to other tabs, not self; our controllers ignore their own id anyway).
|
|
16
|
-
for (const h of [...handlers]) h(msg)
|
|
17
|
-
},
|
|
18
|
-
subscribe: (h) => {
|
|
19
|
-
handlers.add(h)
|
|
20
|
-
return () => handlers.delete(h)
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
return { transportFor }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const userA = { id: 'a', name: 'Ada', color: '#f00' }
|
|
27
|
-
const userB = { id: 'b', name: 'Bob', color: '#00f' }
|
|
28
|
-
|
|
29
|
-
describe('createCollaboration', () => {
|
|
30
|
-
it('peers see each other after hello', () => {
|
|
31
|
-
const bus = makeBus()
|
|
32
|
-
const a = createCollaboration({ user: userA, transport: bus.transportFor() })
|
|
33
|
-
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
34
|
-
// A is announced; B's hello reaches A; A replies presence.
|
|
35
|
-
expect(a.peers().map((p) => p.id)).toEqual(['b'])
|
|
36
|
-
expect(b.peers().map((p) => p.id)).toEqual(['a'])
|
|
37
|
-
a.dispose()
|
|
38
|
-
b.dispose()
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('closes the transport channel on dispose (#82)', () => {
|
|
42
|
-
// The controller now forwards dispose to the transport...
|
|
43
|
-
const disposeSpy = vi.fn()
|
|
44
|
-
const collab = createCollaboration({
|
|
45
|
-
user: userA,
|
|
46
|
-
transport: { post: vi.fn(), subscribe: () => () => {}, dispose: disposeSpy },
|
|
47
|
-
})
|
|
48
|
-
collab.dispose()
|
|
49
|
-
expect(disposeSpy).toHaveBeenCalledTimes(1)
|
|
50
|
-
|
|
51
|
-
// ...and broadcastChannelTransport.dispose() closes the BroadcastChannel.
|
|
52
|
-
const close = vi.fn()
|
|
53
|
-
class FakeBroadcastChannel {
|
|
54
|
-
postMessage = vi.fn()
|
|
55
|
-
addEventListener = vi.fn()
|
|
56
|
-
removeEventListener = vi.fn()
|
|
57
|
-
close = close
|
|
58
|
-
constructor(public name: string) {}
|
|
59
|
-
}
|
|
60
|
-
const Orig = (globalThis as { BroadcastChannel?: unknown }).BroadcastChannel
|
|
61
|
-
;(globalThis as { BroadcastChannel?: unknown }).BroadcastChannel = FakeBroadcastChannel
|
|
62
|
-
try {
|
|
63
|
-
broadcastChannelTransport('room').dispose?.()
|
|
64
|
-
expect(close).toHaveBeenCalledTimes(1)
|
|
65
|
-
} finally {
|
|
66
|
-
;(globalThis as { BroadcastChannel?: unknown }).BroadcastChannel = Orig
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('setCell propagates a remote cursor', () => {
|
|
71
|
-
const bus = makeBus()
|
|
72
|
-
const onPeers = vi.fn()
|
|
73
|
-
const a = createCollaboration({ user: userA, transport: bus.transportFor(), onPeersChange: onPeers })
|
|
74
|
-
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
75
|
-
b.setCell({ rowId: 'r1', columnId: 'salary' })
|
|
76
|
-
const peerB = a.peers().find((p) => p.id === 'b')
|
|
77
|
-
expect(peerB?.cell).toEqual({ rowId: 'r1', columnId: 'salary' })
|
|
78
|
-
a.dispose()
|
|
79
|
-
b.dispose()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('sendEdit fires onRemoteEdit on the other peer only', () => {
|
|
83
|
-
const bus = makeBus()
|
|
84
|
-
const aEdits = vi.fn()
|
|
85
|
-
const bEdits = vi.fn()
|
|
86
|
-
const a = createCollaboration({ user: userA, transport: bus.transportFor(), onRemoteEdit: aEdits })
|
|
87
|
-
const b = createCollaboration({ user: userB, transport: bus.transportFor(), onRemoteEdit: bEdits })
|
|
88
|
-
a.sendEdit('r2', 'name', 'Grace')
|
|
89
|
-
expect(bEdits).toHaveBeenCalledWith(expect.objectContaining({ rowId: 'r2', columnId: 'name', value: 'Grace' }))
|
|
90
|
-
expect(aEdits).not.toHaveBeenCalled() // not echoed to self
|
|
91
|
-
a.dispose()
|
|
92
|
-
b.dispose()
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('bye removes a peer', () => {
|
|
96
|
-
const bus = makeBus()
|
|
97
|
-
const a = createCollaboration({ user: userA, transport: bus.transportFor() })
|
|
98
|
-
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
99
|
-
expect(a.peers()).toHaveLength(1)
|
|
100
|
-
b.dispose()
|
|
101
|
-
expect(a.peers()).toHaveLength(0)
|
|
102
|
-
a.dispose()
|
|
103
|
-
})
|
|
104
|
-
})
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
broadcastChannelTransport,
|
|
4
|
+
createCollaboration,
|
|
5
|
+
type CollabMessage,
|
|
6
|
+
type CollabTransport,
|
|
7
|
+
} from './collaboration'
|
|
8
|
+
|
|
9
|
+
/** An in-memory bus so two controllers can talk in a test. */
|
|
10
|
+
function makeBus() {
|
|
11
|
+
const handlers = new Set<(m: CollabMessage) => void>()
|
|
12
|
+
const transportFor = (): CollabTransport => ({
|
|
13
|
+
post: (msg) => {
|
|
14
|
+
// deliver async-ish to every subscriber except none (real channels echo
|
|
15
|
+
// to other tabs, not self; our controllers ignore their own id anyway).
|
|
16
|
+
for (const h of [...handlers]) h(msg)
|
|
17
|
+
},
|
|
18
|
+
subscribe: (h) => {
|
|
19
|
+
handlers.add(h)
|
|
20
|
+
return () => handlers.delete(h)
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
return { transportFor }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const userA = { id: 'a', name: 'Ada', color: '#f00' }
|
|
27
|
+
const userB = { id: 'b', name: 'Bob', color: '#00f' }
|
|
28
|
+
|
|
29
|
+
describe('createCollaboration', () => {
|
|
30
|
+
it('peers see each other after hello', () => {
|
|
31
|
+
const bus = makeBus()
|
|
32
|
+
const a = createCollaboration({ user: userA, transport: bus.transportFor() })
|
|
33
|
+
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
34
|
+
// A is announced; B's hello reaches A; A replies presence.
|
|
35
|
+
expect(a.peers().map((p) => p.id)).toEqual(['b'])
|
|
36
|
+
expect(b.peers().map((p) => p.id)).toEqual(['a'])
|
|
37
|
+
a.dispose()
|
|
38
|
+
b.dispose()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('closes the transport channel on dispose (#82)', () => {
|
|
42
|
+
// The controller now forwards dispose to the transport...
|
|
43
|
+
const disposeSpy = vi.fn()
|
|
44
|
+
const collab = createCollaboration({
|
|
45
|
+
user: userA,
|
|
46
|
+
transport: { post: vi.fn(), subscribe: () => () => {}, dispose: disposeSpy },
|
|
47
|
+
})
|
|
48
|
+
collab.dispose()
|
|
49
|
+
expect(disposeSpy).toHaveBeenCalledTimes(1)
|
|
50
|
+
|
|
51
|
+
// ...and broadcastChannelTransport.dispose() closes the BroadcastChannel.
|
|
52
|
+
const close = vi.fn()
|
|
53
|
+
class FakeBroadcastChannel {
|
|
54
|
+
postMessage = vi.fn()
|
|
55
|
+
addEventListener = vi.fn()
|
|
56
|
+
removeEventListener = vi.fn()
|
|
57
|
+
close = close
|
|
58
|
+
constructor(public name: string) {}
|
|
59
|
+
}
|
|
60
|
+
const Orig = (globalThis as { BroadcastChannel?: unknown }).BroadcastChannel
|
|
61
|
+
;(globalThis as { BroadcastChannel?: unknown }).BroadcastChannel = FakeBroadcastChannel
|
|
62
|
+
try {
|
|
63
|
+
broadcastChannelTransport('room').dispose?.()
|
|
64
|
+
expect(close).toHaveBeenCalledTimes(1)
|
|
65
|
+
} finally {
|
|
66
|
+
;(globalThis as { BroadcastChannel?: unknown }).BroadcastChannel = Orig
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('setCell propagates a remote cursor', () => {
|
|
71
|
+
const bus = makeBus()
|
|
72
|
+
const onPeers = vi.fn()
|
|
73
|
+
const a = createCollaboration({ user: userA, transport: bus.transportFor(), onPeersChange: onPeers })
|
|
74
|
+
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
75
|
+
b.setCell({ rowId: 'r1', columnId: 'salary' })
|
|
76
|
+
const peerB = a.peers().find((p) => p.id === 'b')
|
|
77
|
+
expect(peerB?.cell).toEqual({ rowId: 'r1', columnId: 'salary' })
|
|
78
|
+
a.dispose()
|
|
79
|
+
b.dispose()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('sendEdit fires onRemoteEdit on the other peer only', () => {
|
|
83
|
+
const bus = makeBus()
|
|
84
|
+
const aEdits = vi.fn()
|
|
85
|
+
const bEdits = vi.fn()
|
|
86
|
+
const a = createCollaboration({ user: userA, transport: bus.transportFor(), onRemoteEdit: aEdits })
|
|
87
|
+
const b = createCollaboration({ user: userB, transport: bus.transportFor(), onRemoteEdit: bEdits })
|
|
88
|
+
a.sendEdit('r2', 'name', 'Grace')
|
|
89
|
+
expect(bEdits).toHaveBeenCalledWith(expect.objectContaining({ rowId: 'r2', columnId: 'name', value: 'Grace' }))
|
|
90
|
+
expect(aEdits).not.toHaveBeenCalled() // not echoed to self
|
|
91
|
+
a.dispose()
|
|
92
|
+
b.dispose()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('bye removes a peer', () => {
|
|
96
|
+
const bus = makeBus()
|
|
97
|
+
const a = createCollaboration({ user: userA, transport: bus.transportFor() })
|
|
98
|
+
const b = createCollaboration({ user: userB, transport: bus.transportFor() })
|
|
99
|
+
expect(a.peers()).toHaveLength(1)
|
|
100
|
+
b.dispose()
|
|
101
|
+
expect(a.peers()).toHaveLength(0)
|
|
102
|
+
a.dispose()
|
|
103
|
+
})
|
|
104
|
+
})
|
package/src/collaboration.ts
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Real-time collaboration. Presence (who else is here + where their cursor
|
|
3
|
-
* is) and live edits (a change in one client lands in every other), over a
|
|
4
|
-
* pluggable transport. The transport is the only thing tied to infrastructure
|
|
5
|
-
* - swap `broadcastChannelTransport` (same-browser tabs, zero backend) for a
|
|
6
|
-
* WebSocket / WebRTC / CRDT adapter and the controller is unchanged.
|
|
7
|
-
*
|
|
8
|
-
* This is also the natural "multiple agents on one grid" substrate: an AI
|
|
9
|
-
* agent is just another peer posting `edit` messages.
|
|
10
|
-
*/
|
|
11
|
-
export type CollabUser = {
|
|
12
|
-
id: string
|
|
13
|
-
name: string
|
|
14
|
-
/** A CSS color for this user's cursor / avatar. */
|
|
15
|
-
color: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type CollabCell = { rowId: string; columnId: string }
|
|
19
|
-
|
|
20
|
-
export type CollabPresence = CollabUser & {
|
|
21
|
-
cell: CollabCell | null
|
|
22
|
-
/** Last time we heard from this peer (ms). Used to prune the gone. */
|
|
23
|
-
ts: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type CollabMessage =
|
|
27
|
-
| { kind: 'hello'; user: CollabUser }
|
|
28
|
-
| { kind: 'presence'; user: CollabUser; cell: CollabCell | null }
|
|
29
|
-
| { kind: 'edit'; user: CollabUser; rowId: string; columnId: string; value: unknown }
|
|
30
|
-
| { kind: 'bye'; userId: string }
|
|
31
|
-
|
|
32
|
-
export type CollabTransport = {
|
|
33
|
-
post(msg: CollabMessage): void
|
|
34
|
-
subscribe(handler: (msg: CollabMessage) => void): () => void
|
|
35
|
-
/** Release any underlying resource (e.g. a BroadcastChannel). Optional. */
|
|
36
|
-
dispose?(): void
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type Collaboration = {
|
|
40
|
-
/** Broadcast where this user's cursor is (or null when it leaves). */
|
|
41
|
-
setCell(cell: CollabCell | null): void
|
|
42
|
-
/** Broadcast a cell edit to every peer. */
|
|
43
|
-
sendEdit(rowId: string, columnId: string, value: unknown): void
|
|
44
|
-
/** The peers currently present (excludes self). */
|
|
45
|
-
peers(): CollabPresence[]
|
|
46
|
-
dispose(): void
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type CollaborationOptions = {
|
|
50
|
-
user: CollabUser
|
|
51
|
-
transport: CollabTransport
|
|
52
|
-
/** Fired (with self excluded) whenever the peer set or a cursor changes. */
|
|
53
|
-
onPeersChange?: (peers: CollabPresence[]) => void
|
|
54
|
-
/** Fired when another user edits a cell - apply it to your data. */
|
|
55
|
-
onRemoteEdit?: (edit: {
|
|
56
|
-
rowId: string
|
|
57
|
-
columnId: string
|
|
58
|
-
value: unknown
|
|
59
|
-
user: CollabUser
|
|
60
|
-
}) => void
|
|
61
|
-
/** Drop peers we haven't heard from in this many ms. Default 15000. */
|
|
62
|
-
peerTimeoutMs?: number
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** BroadcastChannel transport - live across tabs of the same browser, no
|
|
66
|
-
* backend. No-ops where BroadcastChannel is unavailable (SSR / old env). */
|
|
67
|
-
export function broadcastChannelTransport(name: string): CollabTransport {
|
|
68
|
-
const available = typeof BroadcastChannel !== 'undefined'
|
|
69
|
-
const channel = available ? new BroadcastChannel(name) : null
|
|
70
|
-
return {
|
|
71
|
-
post(msg) {
|
|
72
|
-
channel?.postMessage(msg)
|
|
73
|
-
},
|
|
74
|
-
subscribe(handler) {
|
|
75
|
-
if (!channel) return () => {}
|
|
76
|
-
const listener = (e: MessageEvent) => handler(e.data as CollabMessage)
|
|
77
|
-
channel.addEventListener('message', listener)
|
|
78
|
-
return () => channel.removeEventListener('message', listener)
|
|
79
|
-
},
|
|
80
|
-
dispose() {
|
|
81
|
-
channel?.close()
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function createCollaboration(options: CollaborationOptions): Collaboration {
|
|
87
|
-
const { user, transport } = options
|
|
88
|
-
const timeout = options.peerTimeoutMs ?? 15_000
|
|
89
|
-
const peers = new Map<string, CollabPresence>()
|
|
90
|
-
let ownCell: CollabCell | null = null
|
|
91
|
-
let disposed = false
|
|
92
|
-
|
|
93
|
-
const list = () => [...peers.values()].sort((a, b) => a.name.localeCompare(b.name))
|
|
94
|
-
const notify = () => options.onPeersChange?.(list())
|
|
95
|
-
|
|
96
|
-
function upsert(u: CollabUser, cell: CollabCell | null) {
|
|
97
|
-
if (u.id === user.id) return
|
|
98
|
-
peers.set(u.id, { ...u, cell, ts: Date.now() })
|
|
99
|
-
notify()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const unsubscribe = transport.subscribe((msg) => {
|
|
103
|
-
if (disposed) return
|
|
104
|
-
switch (msg.kind) {
|
|
105
|
-
case 'hello':
|
|
106
|
-
upsert(msg.user, null)
|
|
107
|
-
// Let the newcomer know we're here (and where our cursor is).
|
|
108
|
-
transport.post({ kind: 'presence', user, cell: ownCell })
|
|
109
|
-
break
|
|
110
|
-
case 'presence':
|
|
111
|
-
upsert(msg.user, msg.cell)
|
|
112
|
-
break
|
|
113
|
-
case 'edit':
|
|
114
|
-
upsert(msg.user, { rowId: msg.rowId, columnId: msg.columnId })
|
|
115
|
-
if (msg.user.id !== user.id) {
|
|
116
|
-
options.onRemoteEdit?.({
|
|
117
|
-
rowId: msg.rowId,
|
|
118
|
-
columnId: msg.columnId,
|
|
119
|
-
value: msg.value,
|
|
120
|
-
user: msg.user,
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
break
|
|
124
|
-
case 'bye':
|
|
125
|
-
if (peers.delete(msg.userId)) notify()
|
|
126
|
-
break
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// Prune peers that went silent (closed tab without a `bye`).
|
|
131
|
-
const pruneTimer =
|
|
132
|
-
typeof setInterval !== 'undefined'
|
|
133
|
-
? setInterval(() => {
|
|
134
|
-
const now = Date.now()
|
|
135
|
-
let changed = false
|
|
136
|
-
for (const [id, p] of peers) {
|
|
137
|
-
if (now - p.ts > timeout) {
|
|
138
|
-
peers.delete(id)
|
|
139
|
-
changed = true
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (changed) notify()
|
|
143
|
-
}, Math.max(1000, timeout / 3))
|
|
144
|
-
: null
|
|
145
|
-
|
|
146
|
-
// Announce ourselves.
|
|
147
|
-
transport.post({ kind: 'hello', user })
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
setCell(cell) {
|
|
151
|
-
ownCell = cell
|
|
152
|
-
transport.post({ kind: 'presence', user, cell })
|
|
153
|
-
},
|
|
154
|
-
sendEdit(rowId, columnId, value) {
|
|
155
|
-
transport.post({ kind: 'edit', user, rowId, columnId, value })
|
|
156
|
-
},
|
|
157
|
-
peers: list,
|
|
158
|
-
dispose() {
|
|
159
|
-
if (disposed) return
|
|
160
|
-
disposed = true
|
|
161
|
-
transport.post({ kind: 'bye', userId: user.id })
|
|
162
|
-
unsubscribe()
|
|
163
|
-
if (pruneTimer) clearInterval(pruneTimer)
|
|
164
|
-
transport.dispose?.() // release the channel (BroadcastChannel etc.)
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Real-time collaboration. Presence (who else is here + where their cursor
|
|
3
|
+
* is) and live edits (a change in one client lands in every other), over a
|
|
4
|
+
* pluggable transport. The transport is the only thing tied to infrastructure
|
|
5
|
+
* - swap `broadcastChannelTransport` (same-browser tabs, zero backend) for a
|
|
6
|
+
* WebSocket / WebRTC / CRDT adapter and the controller is unchanged.
|
|
7
|
+
*
|
|
8
|
+
* This is also the natural "multiple agents on one grid" substrate: an AI
|
|
9
|
+
* agent is just another peer posting `edit` messages.
|
|
10
|
+
*/
|
|
11
|
+
export type CollabUser = {
|
|
12
|
+
id: string
|
|
13
|
+
name: string
|
|
14
|
+
/** A CSS color for this user's cursor / avatar. */
|
|
15
|
+
color: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CollabCell = { rowId: string; columnId: string }
|
|
19
|
+
|
|
20
|
+
export type CollabPresence = CollabUser & {
|
|
21
|
+
cell: CollabCell | null
|
|
22
|
+
/** Last time we heard from this peer (ms). Used to prune the gone. */
|
|
23
|
+
ts: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type CollabMessage =
|
|
27
|
+
| { kind: 'hello'; user: CollabUser }
|
|
28
|
+
| { kind: 'presence'; user: CollabUser; cell: CollabCell | null }
|
|
29
|
+
| { kind: 'edit'; user: CollabUser; rowId: string; columnId: string; value: unknown }
|
|
30
|
+
| { kind: 'bye'; userId: string }
|
|
31
|
+
|
|
32
|
+
export type CollabTransport = {
|
|
33
|
+
post(msg: CollabMessage): void
|
|
34
|
+
subscribe(handler: (msg: CollabMessage) => void): () => void
|
|
35
|
+
/** Release any underlying resource (e.g. a BroadcastChannel). Optional. */
|
|
36
|
+
dispose?(): void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Collaboration = {
|
|
40
|
+
/** Broadcast where this user's cursor is (or null when it leaves). */
|
|
41
|
+
setCell(cell: CollabCell | null): void
|
|
42
|
+
/** Broadcast a cell edit to every peer. */
|
|
43
|
+
sendEdit(rowId: string, columnId: string, value: unknown): void
|
|
44
|
+
/** The peers currently present (excludes self). */
|
|
45
|
+
peers(): CollabPresence[]
|
|
46
|
+
dispose(): void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type CollaborationOptions = {
|
|
50
|
+
user: CollabUser
|
|
51
|
+
transport: CollabTransport
|
|
52
|
+
/** Fired (with self excluded) whenever the peer set or a cursor changes. */
|
|
53
|
+
onPeersChange?: (peers: CollabPresence[]) => void
|
|
54
|
+
/** Fired when another user edits a cell - apply it to your data. */
|
|
55
|
+
onRemoteEdit?: (edit: {
|
|
56
|
+
rowId: string
|
|
57
|
+
columnId: string
|
|
58
|
+
value: unknown
|
|
59
|
+
user: CollabUser
|
|
60
|
+
}) => void
|
|
61
|
+
/** Drop peers we haven't heard from in this many ms. Default 15000. */
|
|
62
|
+
peerTimeoutMs?: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** BroadcastChannel transport - live across tabs of the same browser, no
|
|
66
|
+
* backend. No-ops where BroadcastChannel is unavailable (SSR / old env). */
|
|
67
|
+
export function broadcastChannelTransport(name: string): CollabTransport {
|
|
68
|
+
const available = typeof BroadcastChannel !== 'undefined'
|
|
69
|
+
const channel = available ? new BroadcastChannel(name) : null
|
|
70
|
+
return {
|
|
71
|
+
post(msg) {
|
|
72
|
+
channel?.postMessage(msg)
|
|
73
|
+
},
|
|
74
|
+
subscribe(handler) {
|
|
75
|
+
if (!channel) return () => {}
|
|
76
|
+
const listener = (e: MessageEvent) => handler(e.data as CollabMessage)
|
|
77
|
+
channel.addEventListener('message', listener)
|
|
78
|
+
return () => channel.removeEventListener('message', listener)
|
|
79
|
+
},
|
|
80
|
+
dispose() {
|
|
81
|
+
channel?.close()
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function createCollaboration(options: CollaborationOptions): Collaboration {
|
|
87
|
+
const { user, transport } = options
|
|
88
|
+
const timeout = options.peerTimeoutMs ?? 15_000
|
|
89
|
+
const peers = new Map<string, CollabPresence>()
|
|
90
|
+
let ownCell: CollabCell | null = null
|
|
91
|
+
let disposed = false
|
|
92
|
+
|
|
93
|
+
const list = () => [...peers.values()].sort((a, b) => a.name.localeCompare(b.name))
|
|
94
|
+
const notify = () => options.onPeersChange?.(list())
|
|
95
|
+
|
|
96
|
+
function upsert(u: CollabUser, cell: CollabCell | null) {
|
|
97
|
+
if (u.id === user.id) return
|
|
98
|
+
peers.set(u.id, { ...u, cell, ts: Date.now() })
|
|
99
|
+
notify()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const unsubscribe = transport.subscribe((msg) => {
|
|
103
|
+
if (disposed) return
|
|
104
|
+
switch (msg.kind) {
|
|
105
|
+
case 'hello':
|
|
106
|
+
upsert(msg.user, null)
|
|
107
|
+
// Let the newcomer know we're here (and where our cursor is).
|
|
108
|
+
transport.post({ kind: 'presence', user, cell: ownCell })
|
|
109
|
+
break
|
|
110
|
+
case 'presence':
|
|
111
|
+
upsert(msg.user, msg.cell)
|
|
112
|
+
break
|
|
113
|
+
case 'edit':
|
|
114
|
+
upsert(msg.user, { rowId: msg.rowId, columnId: msg.columnId })
|
|
115
|
+
if (msg.user.id !== user.id) {
|
|
116
|
+
options.onRemoteEdit?.({
|
|
117
|
+
rowId: msg.rowId,
|
|
118
|
+
columnId: msg.columnId,
|
|
119
|
+
value: msg.value,
|
|
120
|
+
user: msg.user,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
break
|
|
124
|
+
case 'bye':
|
|
125
|
+
if (peers.delete(msg.userId)) notify()
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// Prune peers that went silent (closed tab without a `bye`).
|
|
131
|
+
const pruneTimer =
|
|
132
|
+
typeof setInterval !== 'undefined'
|
|
133
|
+
? setInterval(() => {
|
|
134
|
+
const now = Date.now()
|
|
135
|
+
let changed = false
|
|
136
|
+
for (const [id, p] of peers) {
|
|
137
|
+
if (now - p.ts > timeout) {
|
|
138
|
+
peers.delete(id)
|
|
139
|
+
changed = true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (changed) notify()
|
|
143
|
+
}, Math.max(1000, timeout / 3))
|
|
144
|
+
: null
|
|
145
|
+
|
|
146
|
+
// Announce ourselves.
|
|
147
|
+
transport.post({ kind: 'hello', user })
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
setCell(cell) {
|
|
151
|
+
ownCell = cell
|
|
152
|
+
transport.post({ kind: 'presence', user, cell })
|
|
153
|
+
},
|
|
154
|
+
sendEdit(rowId, columnId, value) {
|
|
155
|
+
transport.post({ kind: 'edit', user, rowId, columnId, value })
|
|
156
|
+
},
|
|
157
|
+
peers: list,
|
|
158
|
+
dispose() {
|
|
159
|
+
if (disposed) return
|
|
160
|
+
disposed = true
|
|
161
|
+
transport.post({ kind: 'bye', userId: user.id })
|
|
162
|
+
unsubscribe()
|
|
163
|
+
if (pruneTimer) clearInterval(pruneTimer)
|
|
164
|
+
transport.dispose?.() // release the channel (BroadcastChannel etc.)
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { computeColumnGroupMeta, hiddenLeavesForCollapse } from './column-groups'
|
|
3
|
+
import { resolveColumnId } from './column-id'
|
|
3
4
|
|
|
4
5
|
// A group "Q1" with an always-on Total plus Jan/Feb that only show when open.
|
|
5
6
|
const columns = [
|
|
@@ -57,3 +58,50 @@ describe('hiddenLeavesForCollapse', () => {
|
|
|
57
58
|
expect(hidden.apr).toBeUndefined() // 'open' shows when expanded
|
|
58
59
|
})
|
|
59
60
|
})
|
|
61
|
+
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Id agreement with the engine
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
describe('unnamed columns', () => {
|
|
67
|
+
// Columns with neither `id` nor `field` get an id synthesized from their
|
|
68
|
+
// position. The engine, this module, and the group-header derivation all
|
|
69
|
+
// have to synthesize the SAME one - they used to disagree (`q1_d_1` here vs
|
|
70
|
+
// `q1_1_1` in the engine), so `columnGroupShow` on an unnamed column looked
|
|
71
|
+
// wired up but never actually hid anything.
|
|
72
|
+
const unnamed = [
|
|
73
|
+
{ field: 'name' },
|
|
74
|
+
{
|
|
75
|
+
id: 'q1',
|
|
76
|
+
header: 'Q1',
|
|
77
|
+
columns: [
|
|
78
|
+
{ field: 'jan', columnGroupShow: 'open' },
|
|
79
|
+
{ header: 'Closed', columnGroupShow: 'closed' },
|
|
80
|
+
{ header: 'Always' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
it('keys leafControl by the id the engine assigns', () => {
|
|
86
|
+
const meta = computeColumnGroupMeta(unnamed)
|
|
87
|
+
// `<parentId>_<depth>_<index>`: depth 1 under "q1", index 1 in its siblings.
|
|
88
|
+
expect(meta.leafControl.has('q1_1_1')).toBe(true)
|
|
89
|
+
expect(meta.leafControl.get('q1_1_1')).toEqual({ groupId: 'q1', show: 'closed' })
|
|
90
|
+
// The untagged sibling is not controlled, and no stale `_d_` key survives.
|
|
91
|
+
expect(meta.leafControl.has('q1_1_2')).toBe(false)
|
|
92
|
+
expect([...meta.leafControl.keys()].some((k) => k.includes('_d_'))).toBe(false)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('hides an unnamed closed-mode leaf once the group is expanded', () => {
|
|
96
|
+
const meta = computeColumnGroupMeta(unnamed)
|
|
97
|
+
expect(hiddenLeavesForCollapse(meta, new Set<string>())).toEqual({ q1_1_1: true })
|
|
98
|
+
expect(hiddenLeavesForCollapse(meta, new Set(['q1']))).toEqual({ jan: true })
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('matches resolveColumnId at every depth', () => {
|
|
102
|
+
expect(resolveColumnId({ field: 'jan' }, 'q1', 1, 0)).toBe('jan')
|
|
103
|
+
expect(resolveColumnId({ id: 'q1' }, undefined, 0, 1)).toBe('q1')
|
|
104
|
+
expect(resolveColumnId({ header: 'X' }, 'q1', 1, 2)).toBe('q1_1_2')
|
|
105
|
+
expect(resolveColumnId({ header: 'X' }, undefined, 0, 3)).toBe('col_0_3')
|
|
106
|
+
})
|
|
107
|
+
})
|
package/src/column-groups.ts
CHANGED
|
@@ -20,12 +20,7 @@ export type ColumnGroupMeta = {
|
|
|
20
20
|
leafControl: Map<string, { groupId: string; show: ColumnGroupShow }>;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
// leaf ids line up across both.
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
function idOf(def: any, parentId: string | undefined, ix: number): string {
|
|
27
|
-
return def.id ?? def.field ?? `${parentId ?? "col"}_d_${ix}`;
|
|
28
|
-
}
|
|
23
|
+
import { resolveColumnId } from "./column-id";
|
|
29
24
|
|
|
30
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
26
|
export function computeColumnGroupMeta(columns: ReadonlyArray<any>): ColumnGroupMeta {
|
|
@@ -33,10 +28,13 @@ export function computeColumnGroupMeta(columns: ReadonlyArray<any>): ColumnGroup
|
|
|
33
28
|
const defaultOpen = new Map<string, boolean>();
|
|
34
29
|
const leafControl = new Map<string, { groupId: string; show: ColumnGroupShow }>();
|
|
35
30
|
|
|
31
|
+
// `depth` is threaded because it is part of the id of an unnamed column -
|
|
32
|
+
// drop it and the ids here stop matching the ones the engine assigns, so
|
|
33
|
+
// `leafControl` lookups silently miss for those columns.
|
|
36
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
function walk(defs: ReadonlyArray<any>, parentId: string | undefined, controllingGroup: string | undefined) {
|
|
35
|
+
function walk(defs: ReadonlyArray<any>, parentId: string | undefined, controllingGroup: string | undefined, depth: number) {
|
|
38
36
|
defs.forEach((def, ix) => {
|
|
39
|
-
const id =
|
|
37
|
+
const id = resolveColumnId(def, parentId, depth, ix);
|
|
40
38
|
if (def.columns?.length) {
|
|
41
39
|
// A group is collapsible when any DIRECT child declares columnGroupShow.
|
|
42
40
|
const collapsible = def.columns.some(
|
|
@@ -47,7 +45,7 @@ export function computeColumnGroupMeta(columns: ReadonlyArray<any>): ColumnGroup
|
|
|
47
45
|
collapsibleGroupIds.add(id);
|
|
48
46
|
defaultOpen.set(id, def.openByDefault === true);
|
|
49
47
|
}
|
|
50
|
-
walk(def.columns, id, collapsible ? id : controllingGroup);
|
|
48
|
+
walk(def.columns, id, collapsible ? id : controllingGroup, depth + 1);
|
|
51
49
|
} else {
|
|
52
50
|
const show = def.columnGroupShow;
|
|
53
51
|
if ((show === "open" || show === "closed") && controllingGroup) {
|
|
@@ -57,7 +55,7 @@ export function computeColumnGroupMeta(columns: ReadonlyArray<any>): ColumnGroup
|
|
|
57
55
|
});
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
walk(columns, undefined, undefined);
|
|
58
|
+
walk(columns, undefined, undefined, 0);
|
|
61
59
|
return { collapsibleGroupIds, defaultOpen, leafControl };
|
|
62
60
|
}
|
|
63
61
|
|