@svgrid/grid 2.2.33 → 2.4.0
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 +178 -139
- package/dist/GridMenus.svelte +705 -705
- package/dist/SvAutoComplete.svelte +165 -165
- package/dist/SvAvatar.svelte +75 -75
- package/dist/SvCalendar.svelte +503 -503
- package/dist/SvCarousel.svelte +141 -141
- package/dist/SvCheckBox.svelte +102 -102
- package/dist/SvCircularProgress.svelte +109 -109
- 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 -254
- 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.css +2814 -2804
- package/dist/SvGrid.svelte +3490 -3490
- package/dist/SvGridChart.svelte +1716 -1716
- package/dist/SvGridChartPanel.svelte +485 -485
- package/dist/SvGridChartView.svelte +70 -70
- package/dist/SvGridDropdown.svelte +728 -728
- package/dist/SvGridSelect.svelte +266 -266
- package/dist/SvGroupCell.svelte +116 -116
- package/dist/SvListBox.svelte +326 -326
- package/dist/SvMaskedInput.svelte +122 -122
- package/dist/SvMenu.svelte +124 -124
- package/dist/SvMenuList.svelte +146 -146
- package/dist/SvMultiSelect.svelte +289 -289
- package/dist/SvNumberInput.svelte +168 -168
- package/dist/SvOtpInput.svelte +158 -158
- package/dist/SvPasswordInput.svelte +151 -151
- package/dist/SvPhoneInput.svelte +133 -133
- package/dist/SvPopover.svelte +197 -197
- package/dist/SvProgress.svelte +116 -116
- package/dist/SvRadioGroup.svelte +107 -107
- package/dist/SvRating.svelte +112 -112
- package/dist/SvResult.svelte +73 -73
- package/dist/SvRichText.svelte +211 -211
- package/dist/SvRowGroupPanel.svelte +170 -170
- package/dist/SvScrollArea.svelte +61 -61
- package/dist/SvSlider.svelte +200 -200
- package/dist/SvSwitchButton.svelte +108 -108
- 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 +208 -208
- package/dist/SvTree.svelte +444 -444
- package/dist/SvTreeSelect.svelte +235 -235
- package/dist/cdn/{GridMenus-B7XhhqdN.js → GridMenus-BpVcKyUr.js} +4 -4
- package/dist/cdn/{GridMenus-BxmIvCJh.js → GridMenus-CeXL5IW4.js} +153 -150
- package/dist/cdn/{SvDateTimePicker-ClqtVIj3.js → SvDateTimePicker-DSUhIta8.js} +165 -165
- package/dist/cdn/{SvDateTimePicker-o94wfSUa.js → SvDateTimePicker-h9kPyszT.js} +572 -555
- package/dist/cdn/{SvGridChart-Cr_90pPD.js → SvGridChart-Bs2GIR2Q.js} +28 -21
- package/dist/cdn/{SvGridChart-BhnFdLd0.js → SvGridChart-CwhFz7GV.js} +2 -2
- package/dist/cdn/{SvGridChartPanel-Cmx9DHAS.js → SvGridChartPanel-1WXuStzM.js} +2 -2
- package/dist/cdn/{SvGridChartPanel-ICbxiUvK.js → SvGridChartPanel-e5_nqNP9.js} +20 -12
- package/dist/cdn/{SvGridChartView-Bx42PMvf.js → SvGridChartView-SmPW10dI.js} +3 -3
- package/dist/cdn/{SvGridChartView-B40DTJSX.js → SvGridChartView-eSPuJE6g.js} +2 -2
- package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-B1ZcLpgs.js} +1 -1
- package/dist/cdn/{SvGridDropdown-CUOdm7YA.js → SvGridDropdown-CtdbHcIS.js} +6 -5
- package/dist/cdn/{chart-T1usDN0o.js → chart-i4XcXyHJ.js} +12 -10
- package/dist/cdn/{disclose-version-DljhZohK.js → disclose-version-Dr7rEVv-.js} +989 -1081
- package/dist/cdn/{export-format-JT5pWVT8.js → export-format-Cv1Dll6k.js} +66 -245
- package/dist/cdn/{src-erjBRYfX.js → src-DbeN1ReZ.js} +9221 -8925
- package/dist/cdn/{src-ktbQVOk-.js → src-DmEQFW5_.js} +9021 -8809
- 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/columns.js +9 -2
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
- package/dist/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
- package/package.json +11 -11
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +178 -139
- package/src/GridMenus.svelte +705 -705
- package/src/SvAutoComplete.svelte +165 -165
- package/src/SvAvatar.svelte +75 -75
- package/src/SvCalendar.svelte +503 -503
- package/src/SvCalendar.test.ts +226 -226
- package/src/SvCarousel.svelte +141 -141
- package/src/SvCheckBox.svelte +102 -102
- package/src/SvCircularProgress.svelte +109 -109
- 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 -254
- 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 +3680 -3680
- package/src/SvGrid.css +2814 -2804
- package/src/SvGrid.svelte +3490 -3490
- package/src/SvGrid.types.ts +1708 -1708
- package/src/SvGridChart.svelte +1716 -1716
- package/src/SvGridChartPanel.svelte +485 -485
- package/src/SvGridChartView.svelte +70 -70
- package/src/SvGridDropdown.svelte +728 -728
- package/src/SvGridSelect.svelte +266 -266
- package/src/SvGroupCell.svelte +116 -116
- package/src/SvListBox.svelte +326 -326
- 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 +289 -289
- package/src/SvNumberInput.svelte +168 -168
- package/src/SvOtpInput.svelte +158 -158
- package/src/SvPasswordInput.svelte +151 -151
- package/src/SvPhoneInput.svelte +133 -133
- package/src/SvPopover.svelte +197 -197
- package/src/SvProgress.svelte +116 -116
- package/src/SvRadioGroup.svelte +107 -107
- package/src/SvRating.svelte +112 -112
- package/src/SvResult.svelte +73 -73
- package/src/SvRichText.svelte +211 -211
- package/src/SvRowGroupPanel.svelte +170 -170
- package/src/SvScrollArea.svelte +61 -61
- package/src/SvSlider.svelte +200 -200
- package/src/SvSwitchButton.svelte +108 -108
- 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 +208 -208
- package/src/SvTree.svelte +444 -444
- package/src/SvTreeSelect.svelte +235 -235
- 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 +805 -805
- package/src/builtin-editors.grid.test.ts +85 -85
- package/src/cell-formatting.ts +169 -169
- package/src/cell-render.test.ts +513 -513
- package/src/cell-render.ts +496 -496
- package/src/cell-values.ts +118 -118
- package/src/chart-export.ts +201 -201
- package/src/chart-view.svelte.ts +36 -36
- package/src/chart.ts +2295 -2295
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/columns.ts +7 -2
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1261 -1261
- 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 +250 -250
- package/src/createMenu.svelte.ts +224 -224
- 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 -949
- package/src/editing.ts +606 -606
- package/src/editor-contract.ts +164 -164
- package/src/editor-registry.grid.test.ts +144 -144
- package/src/editor-registry.ts +122 -122
- package/src/export-data-api.test.ts +126 -126
- package/src/export-format.test.ts +107 -107
- package/src/export-format.ts +601 -601
- package/src/filter-operators.ts +157 -157
- package/src/flex-render.ts +3 -3
- package/src/form-field.ts +127 -127
- package/src/group-display.test.ts +167 -167
- package/src/group-display.ts +200 -200
- package/src/index.ts +724 -724
- package/src/js-scroller.svelte.ts +173 -173
- package/src/keyboard-handlers.ts +270 -270
- 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.ts +567 -567
- package/src/merge-objects.ts +48 -48
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/_svelte_metadata.json +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/_metadata.json +178 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js +3843 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/attachments-qzRy9DX4.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js +23 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/constants-RLNOXCpz.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js +1925 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/dev-DPd12uEU.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js +206 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/events-CDC4DKuQ.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js +20 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/flags-BD-lYX7s.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js +264 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/hydration-D3UBU2t8.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js +698 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/legacy-client-B0ZUlbSQ.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/package.json +3 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js +135 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js +57 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_animate.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_attachments.js +2 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js +46691 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_compiler.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js +239 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_easing.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_events.js +2 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js +6 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_client.js +7 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js +6 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_disclose-version.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js +7 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_async.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js +7 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_legacy.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js +7 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_flags_tracing.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_internal_server.js +6 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js +85 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_legacy.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js +561 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_motion.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js +26 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js +124 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_reactivity_window.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_server.js +2 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js +91 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_store.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js +242 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/svelte_transition.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js +497 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-lObbumRX.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js +4929 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/utils-mR9mAWyK.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js +192 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/validate-CezNmRkM.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js +10 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/version-BHHo0WE-.js.map +1 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js +140 -0
- package/src/node_modules/.vite/vitest/67d8ed22ed986c5e2e948f64d892f30be166cc36/deps___vitest__/warnings-yiExAB06.js.map +1 -0
- package/src/overlays.test.ts +90 -90
- package/src/render-component.ts +28 -28
- package/src/row-resize.ts +210 -210
- 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 +491 -491
- 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 +488 -488
- 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 +526 -526
- package/src/svgrid.async-editor-options.test.ts +271 -271
- package/src/svgrid.auto-row-height.test.ts +204 -204
- package/src/svgrid.behavior.test.ts +705 -705
- package/src/svgrid.charting.test.ts +534 -534
- package/src/svgrid.comments-autocomplete.test.ts +123 -123
- package/src/svgrid.context-menu.test.ts +147 -147
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.filter-depth.test.ts +163 -163
- package/src/svgrid.filter-menu-listbox.svelte.test.ts +322 -322
- package/src/svgrid.filter-menu-scroll.test.ts +112 -112
- package/src/svgrid.footer-pagesize.svelte.test.ts +86 -0
- package/src/svgrid.grand-total.test.ts +188 -188
- package/src/svgrid.group-display-mode.test.ts +171 -171
- package/src/svgrid.group-footers.test.ts +121 -121
- package/src/svgrid.group-pagination.test.ts +153 -153
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.tree-data.test.ts +186 -186
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
- package/src/test-setup.ts +62 -62
- package/src/themes/index.ts +257 -257
- package/src/toast-store.svelte.ts +246 -246
- package/src/toast-store.test.ts +147 -147
- package/src/tree-row-model.test.ts +168 -168
- package/src/ui-buttons.test.ts +144 -144
- package/src/ui-inputs.test.ts +118 -118
- package/src/ui-localization.test.ts +113 -113
- 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/src/build-api.ts
CHANGED
|
@@ -1,805 +1,805 @@
|
|
|
1
|
-
// build-api handlers extracted from the controller. Imperative event handlers
|
|
2
|
-
// reading/writing controller state via the `ctx` handle; the reactive core
|
|
3
|
-
// ($state/$derived/$effect) stays in the controller.
|
|
4
|
-
import {
|
|
5
|
-
type RowData,
|
|
6
|
-
type SvGridApi,
|
|
7
|
-
type TableFeatures,
|
|
8
|
-
} from "./index";
|
|
9
|
-
import "./sv-grid-scrollbar";
|
|
10
|
-
import { untrack } from "svelte";
|
|
11
|
-
// The export serializers load lazily (their own chunk) so export-format.ts stays
|
|
12
|
-
// out of the base bundle - it is fetched only when an export/copy method is
|
|
13
|
-
// actually invoked (an explicit, already-async user action).
|
|
14
|
-
import type {
|
|
15
|
-
GridExportColumn,
|
|
16
|
-
GridExportScope,
|
|
17
|
-
GridExportOptions,
|
|
18
|
-
GridClipboardOptions,
|
|
19
|
-
} from "./export-format";
|
|
20
|
-
import type {
|
|
21
|
-
FilterOperator,
|
|
22
|
-
} from "./SvGrid.types";
|
|
23
|
-
import {
|
|
24
|
-
isGroupRow,
|
|
25
|
-
getColumnAlign,
|
|
26
|
-
columnDefMatchesId,
|
|
27
|
-
} from "./cell-values";
|
|
28
|
-
|
|
29
|
-
export function createGridApi<
|
|
30
|
-
TFeatures extends TableFeatures = TableFeatures,
|
|
31
|
-
TData extends RowData = RowData,
|
|
32
|
-
>(ctx: any) {
|
|
33
|
-
function buildApi(): SvGridApi<TFeatures, TData> {
|
|
34
|
-
const findColumn = (columnId: string) =>
|
|
35
|
-
ctx.grid.getAllColumns().find((column: any) => column.id === columnId);
|
|
36
|
-
|
|
37
|
-
// --- Free data export (CSV / TSV / JSON + clipboard) helpers ----------
|
|
38
|
-
// Snapshot the VISIBLE columns (field + label + format + align) so the
|
|
39
|
-
// exporter reproduces on-screen values. Mirrors getColumns()'s visible set.
|
|
40
|
-
const exportColumns = (): GridExportColumn[] =>
|
|
41
|
-
ctx.allColumns
|
|
42
|
-
.map((c: any) => ({
|
|
43
|
-
field: (c.columnDef as { field?: string }).field as string,
|
|
44
|
-
header:
|
|
45
|
-
typeof c.columnDef.header === "string" ? c.columnDef.header : c.id,
|
|
46
|
-
format: c.columnDef.format,
|
|
47
|
-
align: getColumnAlign(c),
|
|
48
|
-
}))
|
|
49
|
-
.filter((c: GridExportColumn) => !!c.field);
|
|
50
|
-
// Rows for the requested scope: current view / checked / full dataset.
|
|
51
|
-
const exportScopeRows = (scope: GridExportScope): TData[] => {
|
|
52
|
-
if (scope === "all") return ctx.internalData as TData[];
|
|
53
|
-
const out: TData[] = [];
|
|
54
|
-
for (const row of ctx.allRows) {
|
|
55
|
-
if (isGroupRow(row)) continue;
|
|
56
|
-
if (scope === "selected" && !ctx.rowSelectionState[row.id]) continue;
|
|
57
|
-
out.push(row.original as TData);
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
};
|
|
61
|
-
const projectForExport = async (
|
|
62
|
-
scope: GridExportScope,
|
|
63
|
-
columns: ReadonlyArray<string> | undefined,
|
|
64
|
-
rawValues: boolean | undefined,
|
|
65
|
-
) => {
|
|
66
|
-
const { projectGridRows } = await import("./export-format");
|
|
67
|
-
return projectGridRows(
|
|
68
|
-
exportScopeRows(scope) as ReadonlyArray<Record<string, unknown>>,
|
|
69
|
-
exportColumns(),
|
|
70
|
-
{ columns, rawValues },
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
getCellValue(rowIndex, columnId) {
|
|
76
|
-
const row = ctx.internalData[rowIndex];
|
|
77
|
-
const column = findColumn(columnId);
|
|
78
|
-
if (!row || !column) return undefined;
|
|
79
|
-
if (column.columnDef.fieldFn)
|
|
80
|
-
return column.columnDef.fieldFn(row);
|
|
81
|
-
if (column.columnDef.field)
|
|
82
|
-
return (row as Record<string, unknown>)[column.columnDef.field];
|
|
83
|
-
return undefined;
|
|
84
|
-
},
|
|
85
|
-
setCellValue(rowIndex, columnId, value) {
|
|
86
|
-
const row = ctx.internalData[rowIndex];
|
|
87
|
-
const column = findColumn(columnId);
|
|
88
|
-
if (!row || !column?.columnDef.field) return;
|
|
89
|
-
const next = ctx.internalData.slice() as Array<TData>;
|
|
90
|
-
next[rowIndex] = { ...row, [column.columnDef.field]: value } as TData;
|
|
91
|
-
ctx.internalData = next;
|
|
92
|
-
},
|
|
93
|
-
startEditing(rowIndex, columnId) {
|
|
94
|
-
return ctx.startEditing(rowIndex, columnId);
|
|
95
|
-
},
|
|
96
|
-
stopEditing(cancel) {
|
|
97
|
-
return ctx.stopEditing(cancel ?? false);
|
|
98
|
-
},
|
|
99
|
-
selectCells(ranges) {
|
|
100
|
-
// Multiple rectangles are supported. Empty array clears everything.
|
|
101
|
-
if (!ranges || ranges.length === 0) {
|
|
102
|
-
ctx.selectionRange = { anchor: null, focus: null };
|
|
103
|
-
ctx.selectionRanges = [];
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const rowCount = ctx.internalData.length;
|
|
107
|
-
const colCount = ctx.allColumns.length;
|
|
108
|
-
if (rowCount === 0 || colCount === 0) return;
|
|
109
|
-
// Clamp to the visible grid bounds so callers can pass open-ended
|
|
110
|
-
// values like `[0, 0, Infinity, Infinity]` to mean "select all".
|
|
111
|
-
const toRange = ([r1, c1, r2, c2]: readonly [number, number, number, number]) => ({
|
|
112
|
-
anchor: {
|
|
113
|
-
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.min(r1, r2))),
|
|
114
|
-
colIndex: Math.max(0, Math.min(colCount - 1, Math.min(c1, c2))),
|
|
115
|
-
},
|
|
116
|
-
focus: {
|
|
117
|
-
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.max(r1, r2))),
|
|
118
|
-
colIndex: Math.max(0, Math.min(colCount - 1, Math.max(c1, c2))),
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
const built = ranges.map(toRange);
|
|
122
|
-
// Last range is the active one; the rest are committed extras.
|
|
123
|
-
ctx.selectionRanges = built.slice(0, -1);
|
|
124
|
-
const active = built[built.length - 1]!;
|
|
125
|
-
ctx.selectionRange = active;
|
|
126
|
-
// Move the active cell to the last range's top-left so keyboard
|
|
127
|
-
// navigation continues from there.
|
|
128
|
-
ctx.setActiveCell(active.anchor.rowIndex, active.anchor.colIndex);
|
|
129
|
-
},
|
|
130
|
-
getSelected() {
|
|
131
|
-
return ctx
|
|
132
|
-
.getSelectionRects()
|
|
133
|
-
.map((r: { minRow: number; minCol: number; maxRow: number; maxCol: number }) =>
|
|
134
|
-
[r.minRow, r.minCol, r.maxRow, r.maxCol] as [number, number, number, number],
|
|
135
|
-
);
|
|
136
|
-
},
|
|
137
|
-
openChart() {
|
|
138
|
-
ctx.chartPanelOpen = true;
|
|
139
|
-
},
|
|
140
|
-
closeChart() {
|
|
141
|
-
ctx.chartPanelOpen = false;
|
|
142
|
-
},
|
|
143
|
-
getChartSpec() {
|
|
144
|
-
return ctx.chartSpec;
|
|
145
|
-
},
|
|
146
|
-
chartRange(ranges) {
|
|
147
|
-
if (ranges && ranges.length) this.selectCells(ranges);
|
|
148
|
-
ctx.chartPanelOpen = true;
|
|
149
|
-
},
|
|
150
|
-
configureChart(config) {
|
|
151
|
-
if (ctx.chartingEnabled) ctx.applyChartConfig(config);
|
|
152
|
-
},
|
|
153
|
-
setChartAiHandler(handler) {
|
|
154
|
-
ctx.chartAiHandler = handler ?? null;
|
|
155
|
-
},
|
|
156
|
-
addRow(row, position = "bottom") {
|
|
157
|
-
this.addRows([row], position);
|
|
158
|
-
},
|
|
159
|
-
addRows(rows, position = "bottom") {
|
|
160
|
-
const next = ctx.internalData.slice() as Array<TData>;
|
|
161
|
-
if (position === "top") next.unshift(...rows);
|
|
162
|
-
else if (position === "bottom") next.push(...rows);
|
|
163
|
-
else if (typeof position === "number")
|
|
164
|
-
next.splice(Math.max(0, Math.min(position, next.length)), 0, ...rows);
|
|
165
|
-
ctx.internalData = next;
|
|
166
|
-
},
|
|
167
|
-
removeRow(rowIndex) {
|
|
168
|
-
this.removeRows([rowIndex]);
|
|
169
|
-
},
|
|
170
|
-
removeRows(rowIndices) {
|
|
171
|
-
const drop = new Set(rowIndices);
|
|
172
|
-
ctx.internalData = ctx.internalData.filter((_: any, i: any) => !drop.has(i));
|
|
173
|
-
},
|
|
174
|
-
applyTransaction(tx) {
|
|
175
|
-
const getId = ctx.props.getRowId;
|
|
176
|
-
let next = ctx.internalData.slice() as Array<TData>;
|
|
177
|
-
let added = 0;
|
|
178
|
-
let updated = 0;
|
|
179
|
-
let removed = 0;
|
|
180
|
-
|
|
181
|
-
if (tx.remove?.length) {
|
|
182
|
-
const removeIds = new Set<string>();
|
|
183
|
-
const removeRefs = new Set<TData>();
|
|
184
|
-
for (const r of tx.remove) {
|
|
185
|
-
if (typeof r === "string") removeIds.add(r);
|
|
186
|
-
else removeRefs.add(r as TData);
|
|
187
|
-
}
|
|
188
|
-
next = next.filter((row, i) => {
|
|
189
|
-
const hit =
|
|
190
|
-
removeRefs.has(row) ||
|
|
191
|
-
(getId ? removeIds.has(getId(row, i)) : false);
|
|
192
|
-
if (hit) removed += 1;
|
|
193
|
-
return !hit;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (tx.update?.length && getId) {
|
|
198
|
-
const byId = new Map<string, TData>();
|
|
199
|
-
for (const u of tx.update) byId.set(getId(u, 0), u);
|
|
200
|
-
next = next.map((row, i) => {
|
|
201
|
-
const u = byId.get(getId(row, i));
|
|
202
|
-
if (u) {
|
|
203
|
-
updated += 1;
|
|
204
|
-
return u;
|
|
205
|
-
}
|
|
206
|
-
return row;
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (tx.add?.length) {
|
|
211
|
-
next.push(...(tx.add as Array<TData>));
|
|
212
|
-
added += tx.add.length;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
ctx.internalData = next;
|
|
216
|
-
return { added, updated, removed };
|
|
217
|
-
},
|
|
218
|
-
addColumn(column, position = "right") {
|
|
219
|
-
this.addColumns([column], position);
|
|
220
|
-
},
|
|
221
|
-
addColumns(columns, position = "right") {
|
|
222
|
-
const next = ctx.internalColumns.slice();
|
|
223
|
-
if (position === "left") next.unshift(...columns);
|
|
224
|
-
else if (position === "right") next.push(...columns);
|
|
225
|
-
else if (typeof position === "number")
|
|
226
|
-
next.splice(
|
|
227
|
-
Math.max(0, Math.min(position, next.length)),
|
|
228
|
-
0,
|
|
229
|
-
...columns,
|
|
230
|
-
);
|
|
231
|
-
ctx.internalColumns = next;
|
|
232
|
-
},
|
|
233
|
-
removeColumn(columnId) {
|
|
234
|
-
ctx.internalColumns = ctx.internalColumns.filter(
|
|
235
|
-
(def: any) => !columnDefMatchesId(def, columnId),
|
|
236
|
-
);
|
|
237
|
-
},
|
|
238
|
-
setColumnVisible(columnId, visible) {
|
|
239
|
-
if (visible) {
|
|
240
|
-
const next = { ...ctx.hiddenColumns };
|
|
241
|
-
delete next[columnId];
|
|
242
|
-
ctx.hiddenColumns = next;
|
|
243
|
-
} else {
|
|
244
|
-
ctx.hiddenColumns = { ...ctx.hiddenColumns, [columnId]: true };
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
isColumnVisible(columnId) {
|
|
248
|
-
return !ctx.hiddenColumns[columnId];
|
|
249
|
-
},
|
|
250
|
-
setSort(columnId, direction) {
|
|
251
|
-
// Honour the column's `sortable` opt-out. Asking the engine
|
|
252
|
-
// whether the column can sort folds in both the feature toggle
|
|
253
|
-
// AND the per-column flag.
|
|
254
|
-
const col = ctx.allColumns.find((c: any) => c.id === columnId);
|
|
255
|
-
if (col && !col.getCanSort?.()) return;
|
|
256
|
-
const clauses = direction
|
|
257
|
-
? [{ id: columnId, desc: direction === "desc" }]
|
|
258
|
-
: (ctx.grid.getState().sorting ?? []).filter(
|
|
259
|
-
(entry: { id: string }) => entry.id !== columnId,
|
|
260
|
-
);
|
|
261
|
-
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: clauses }));
|
|
262
|
-
},
|
|
263
|
-
clearSort() {
|
|
264
|
-
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: [] }));
|
|
265
|
-
},
|
|
266
|
-
setGroupBy(columnIds) {
|
|
267
|
-
ctx.grid.setGrouping([...columnIds]);
|
|
268
|
-
},
|
|
269
|
-
setOption(key, value) {
|
|
270
|
-
// Runtime prop override. Writes into the controller's `optionOverrides`
|
|
271
|
-
// store, which the effective-props proxy merges over the incoming prop, so
|
|
272
|
-
// the grid re-renders exactly as if the parent had changed that prop.
|
|
273
|
-
// `undefined` clears the override (falls back to the prop). Reassign the
|
|
274
|
-
// whole object for reliable reactivity; `untrack` per the `setFilter` note.
|
|
275
|
-
untrack(() => {
|
|
276
|
-
const next: Record<string, unknown> = { ...ctx.optionOverrides };
|
|
277
|
-
if (value === undefined) delete next[key as string];
|
|
278
|
-
else next[key as string] = value;
|
|
279
|
-
ctx.optionOverrides = next;
|
|
280
|
-
});
|
|
281
|
-
},
|
|
282
|
-
getOption(key) {
|
|
283
|
-
// The effective value: the override if set, otherwise the incoming prop.
|
|
284
|
-
return (ctx.props as Record<string, unknown>)[key as string] as never;
|
|
285
|
-
},
|
|
286
|
-
resetOptions() {
|
|
287
|
-
untrack(() => {
|
|
288
|
-
ctx.optionOverrides = {};
|
|
289
|
-
});
|
|
290
|
-
},
|
|
291
|
-
setFilter(columnId, filter) {
|
|
292
|
-
// `untrack`: these imperative mutators read the same filter state they
|
|
293
|
-
// write (read-modify-write on `filterMenuValues`). When a consumer
|
|
294
|
-
// calls them from inside a reactive `$effect`, that internal read would
|
|
295
|
-
// otherwise be captured as a dependency of the caller's effect, and the
|
|
296
|
-
// write would re-dirty it - an infinite update loop. Untracking the
|
|
297
|
-
// body keeps the API safe to drive from an effect.
|
|
298
|
-
untrack(() => {
|
|
299
|
-
// Honour the column's `filterable` opt-out. Same approach as
|
|
300
|
-
// `setSort` - `getCanFilter()` already combines the feature flag
|
|
301
|
-
// and the per-column field.
|
|
302
|
-
const col = ctx.allColumns.find((c: any) => c.id === columnId);
|
|
303
|
-
if (col && !col.getCanFilter?.()) return;
|
|
304
|
-
if (!filter) {
|
|
305
|
-
this.clearFilter(columnId);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
ctx.filterMenuValues = {
|
|
309
|
-
...ctx.filterMenuValues,
|
|
310
|
-
[columnId]: {
|
|
311
|
-
operator: filter.operator,
|
|
312
|
-
value: filter.value ?? "",
|
|
313
|
-
...(filter.operator === "between"
|
|
314
|
-
? { valueTo: filter.valueTo ?? "" }
|
|
315
|
-
: {}),
|
|
316
|
-
// Optional second condition + join (multi-condition filtering).
|
|
317
|
-
...(filter.operator2
|
|
318
|
-
? {
|
|
319
|
-
operator2: filter.operator2,
|
|
320
|
-
value2: filter.value2 ?? "",
|
|
321
|
-
join: filter.join ?? "AND",
|
|
322
|
-
...(filter.operator2 === "between"
|
|
323
|
-
? { valueTo2: filter.valueTo2 ?? "" }
|
|
324
|
-
: {}),
|
|
325
|
-
}
|
|
326
|
-
: {}),
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
});
|
|
330
|
-
},
|
|
331
|
-
setFacetFilter(columnId, values) {
|
|
332
|
-
// See `setFilter` for why the read-modify-write is untracked.
|
|
333
|
-
untrack(() => {
|
|
334
|
-
// Empty array OR null both mean "clear this column's facet" -
|
|
335
|
-
// mirrors how the column menu treats unchecking the last value.
|
|
336
|
-
if (!values || values.length === 0) {
|
|
337
|
-
if (ctx.valueFilters[columnId]) {
|
|
338
|
-
const next = { ...ctx.valueFilters };
|
|
339
|
-
delete next[columnId];
|
|
340
|
-
ctx.valueFilters = next;
|
|
341
|
-
}
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
ctx.valueFilters = {
|
|
345
|
-
...ctx.valueFilters,
|
|
346
|
-
[columnId]: new Set(values),
|
|
347
|
-
};
|
|
348
|
-
});
|
|
349
|
-
},
|
|
350
|
-
clearFilter(columnId) {
|
|
351
|
-
ctx.clearColumnFilter(columnId);
|
|
352
|
-
},
|
|
353
|
-
refreshEditorOptions(columnId) {
|
|
354
|
-
// Async `editorOptions` are cached per column (or per column+row for a
|
|
355
|
-
// per-row source) so opening an editor twice does not refetch. This
|
|
356
|
-
// drops those entries, so the next render re-runs the source - use it
|
|
357
|
-
// when the underlying list changed server-side.
|
|
358
|
-
if (columnId == null) {
|
|
359
|
-
ctx.asyncEditorOptions = {};
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const next = { ...ctx.asyncEditorOptions };
|
|
363
|
-
for (const key of Object.keys(next)) {
|
|
364
|
-
if (key === columnId || key.startsWith(`${columnId}::`)) delete next[key];
|
|
365
|
-
}
|
|
366
|
-
ctx.asyncEditorOptions = next;
|
|
367
|
-
},
|
|
368
|
-
clearAllFilters() {
|
|
369
|
-
// See `setFilter` for why the read-modify-write is untracked.
|
|
370
|
-
untrack(() => {
|
|
371
|
-
// Wipe every filter surface in one go: column-menu, filter-row, set
|
|
372
|
-
// filters, and the global search box.
|
|
373
|
-
ctx.filterMenuValues = {};
|
|
374
|
-
ctx.filterRowValues = {};
|
|
375
|
-
ctx.valueFilters = {};
|
|
376
|
-
if (ctx.globalFilter !== "") ctx.globalFilter = "";
|
|
377
|
-
});
|
|
378
|
-
},
|
|
379
|
-
getFilters() {
|
|
380
|
-
// Return a defensive copy so callers can't mutate internal state.
|
|
381
|
-
const out: Record<
|
|
382
|
-
string,
|
|
383
|
-
{ operator: FilterOperator; value: string; valueTo?: string }
|
|
384
|
-
> = {};
|
|
385
|
-
for (const [columnId, filter] of Object.entries(ctx.filterMenuValues as Record<string, { operator: FilterOperator; value: string; valueTo?: string }>)) {
|
|
386
|
-
out[columnId] = {
|
|
387
|
-
operator: filter.operator,
|
|
388
|
-
value: filter.value,
|
|
389
|
-
...(filter.operator === "between" && filter.valueTo
|
|
390
|
-
? { valueTo: filter.valueTo }
|
|
391
|
-
: {}),
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
return out;
|
|
395
|
-
},
|
|
396
|
-
getDisplayedRows() {
|
|
397
|
-
// `allRows` is the final, post-filter, post-sort, post-group,
|
|
398
|
-
// post-pagination list - exactly what the body renders. Skip group
|
|
399
|
-
// header rows (they wrap an aggregate, not a TData row).
|
|
400
|
-
const out: TData[] = [];
|
|
401
|
-
for (const row of ctx.allRows) {
|
|
402
|
-
if (row.subRows && row.subRows.length > 0) continue;
|
|
403
|
-
out.push(row.original as TData);
|
|
404
|
-
}
|
|
405
|
-
return out;
|
|
406
|
-
},
|
|
407
|
-
getData() {
|
|
408
|
-
return ctx.internalData;
|
|
409
|
-
},
|
|
410
|
-
getColumns() {
|
|
411
|
-
// Snapshot every column with its human-readable label and
|
|
412
|
-
// visibility flag. Used by external code (exporters, column
|
|
413
|
-
// pickers) so they don't have to re-walk the columnDef tree.
|
|
414
|
-
// Hidden columns ARE included (with `visible: false`) so a column
|
|
415
|
-
// picker can re-enable them - callers that only want what's
|
|
416
|
-
// rendered filter by `.visible` (e.g. the exporter does).
|
|
417
|
-
const describe = (c: any, visible: boolean) => ({
|
|
418
|
-
id: c.id,
|
|
419
|
-
field: (c.columnDef as { field?: string }).field,
|
|
420
|
-
header:
|
|
421
|
-
typeof c.columnDef.header === "string"
|
|
422
|
-
? c.columnDef.header
|
|
423
|
-
: c.id,
|
|
424
|
-
visible,
|
|
425
|
-
// Surface the format + alignment so exporters can reproduce the
|
|
426
|
-
// on-screen display value (currency symbol, date pattern, etc.)
|
|
427
|
-
// instead of dumping raw values. `getColumnAlign` applies the same
|
|
428
|
-
// editorType-based default the body uses.
|
|
429
|
-
format: c.columnDef.format,
|
|
430
|
-
align: getColumnAlign(c),
|
|
431
|
-
});
|
|
432
|
-
// Visible columns first, in their current visual order...
|
|
433
|
-
const out = ctx.allColumns.map((c: any) => describe(c, true));
|
|
434
|
-
// ...then any column hidden via `visible: false` / setColumnVisible.
|
|
435
|
-
// Those aren't in `allColumns` (that list is visible-only), so pull
|
|
436
|
-
// them straight from the engine's leaf set.
|
|
437
|
-
const visibleIds = new Set(out.map((c: { id: string }) => c.id));
|
|
438
|
-
for (const c of ctx.grid.getAllColumns() as any[]) {
|
|
439
|
-
if (!visibleIds.has(c.id)) out.push(describe(c, false));
|
|
440
|
-
}
|
|
441
|
-
return out;
|
|
442
|
-
},
|
|
443
|
-
// ---- Free data export (CSV / TSV / JSON + clipboard) -----------------
|
|
444
|
-
async exportCsv(options: GridExportOptions = {}) {
|
|
445
|
-
const { serializeDelimited, downloadTextFile } = await import("./export-format");
|
|
446
|
-
const { records, fields } = await projectForExport(
|
|
447
|
-
options.rows ?? "displayed",
|
|
448
|
-
options.columns,
|
|
449
|
-
options.rawValues,
|
|
450
|
-
);
|
|
451
|
-
const text = await serializeDelimited(records, fields, {
|
|
452
|
-
csv: { delimiter: ",", bom: options.bom ?? true },
|
|
453
|
-
signal: options.signal,
|
|
454
|
-
onProgress: options.onProgress,
|
|
455
|
-
});
|
|
456
|
-
if (options.download !== false)
|
|
457
|
-
downloadTextFile(text, `${options.filename ?? "grid"}.csv`, "text/csv;charset=utf-8");
|
|
458
|
-
return text;
|
|
459
|
-
},
|
|
460
|
-
async exportTsv(options: GridExportOptions = {}) {
|
|
461
|
-
const { serializeDelimited, downloadTextFile } = await import("./export-format");
|
|
462
|
-
const { records, fields } = await projectForExport(
|
|
463
|
-
options.rows ?? "displayed",
|
|
464
|
-
options.columns,
|
|
465
|
-
options.rawValues,
|
|
466
|
-
);
|
|
467
|
-
const text = await serializeDelimited(records, fields, {
|
|
468
|
-
csv: { delimiter: "\t", bom: options.bom ?? true },
|
|
469
|
-
signal: options.signal,
|
|
470
|
-
onProgress: options.onProgress,
|
|
471
|
-
});
|
|
472
|
-
if (options.download !== false)
|
|
473
|
-
downloadTextFile(text, `${options.filename ?? "grid"}.tsv`, "text/tab-separated-values;charset=utf-8");
|
|
474
|
-
return text;
|
|
475
|
-
},
|
|
476
|
-
async exportJson(options: GridExportOptions = {}) {
|
|
477
|
-
const { serializeJson, downloadTextFile } = await import("./export-format");
|
|
478
|
-
const { records, fields } = await projectForExport(
|
|
479
|
-
options.rows ?? "displayed",
|
|
480
|
-
options.columns,
|
|
481
|
-
options.rawValues,
|
|
482
|
-
);
|
|
483
|
-
const text = await serializeJson(records, fields, {
|
|
484
|
-
signal: options.signal,
|
|
485
|
-
onProgress: options.onProgress,
|
|
486
|
-
});
|
|
487
|
-
if (options.download !== false)
|
|
488
|
-
downloadTextFile(text, `${options.filename ?? "grid"}.json`, "application/json");
|
|
489
|
-
return text;
|
|
490
|
-
},
|
|
491
|
-
async copyToClipboard(options: GridClipboardOptions = {}) {
|
|
492
|
-
const { serializeDelimited, serializeMarkdown, copyTextToClipboard } = await import("./export-format");
|
|
493
|
-
const { records, fields, align } = await projectForExport(
|
|
494
|
-
options.rows ?? "displayed",
|
|
495
|
-
options.columns,
|
|
496
|
-
options.rawValues,
|
|
497
|
-
);
|
|
498
|
-
const format = options.format ?? "tsv";
|
|
499
|
-
const text =
|
|
500
|
-
format === "markdown"
|
|
501
|
-
? await serializeMarkdown(records, fields, { align })
|
|
502
|
-
: await serializeDelimited(records, fields, {
|
|
503
|
-
csv: { delimiter: format === "csv" ? "," : "\t", bom: false },
|
|
504
|
-
});
|
|
505
|
-
await copyTextToClipboard(text);
|
|
506
|
-
return text;
|
|
507
|
-
},
|
|
508
|
-
clearRowSelection() {
|
|
509
|
-
// Wipe the internal selection map AND emit the change so any
|
|
510
|
-
// consumer holding a derived `selectedRows` resets too.
|
|
511
|
-
ctx.grid.setRowSelection(() => ({}));
|
|
512
|
-
ctx.props.onRowSelectionChange?.({}, []);
|
|
513
|
-
},
|
|
514
|
-
setColumnWidth(columnId: string, width: number) {
|
|
515
|
-
const clamped = Math.max(ctx.MIN_COLUMN_WIDTH, Math.floor(width));
|
|
516
|
-
ctx.columnWidths = { ...ctx.columnWidths, [columnId]: clamped };
|
|
517
|
-
},
|
|
518
|
-
getColumnWidths() {
|
|
519
|
-
// Resolve every column's effective width by consulting both the
|
|
520
|
-
// resize overrides (`columnWidths`) AND the columnDef defaults,
|
|
521
|
-
// so the snapshot is round-trippable through setColumnWidth.
|
|
522
|
-
const out: Record<string, number> = {};
|
|
523
|
-
for (const c of ctx.allColumns) out[c.id] = ctx.getColumnWidth(c.id);
|
|
524
|
-
return out;
|
|
525
|
-
},
|
|
526
|
-
autosizeColumn(columnId: string) {
|
|
527
|
-
ctx.autosizeColumn(columnId);
|
|
528
|
-
},
|
|
529
|
-
autosizeAllColumns() {
|
|
530
|
-
ctx.autosizeAllColumns();
|
|
531
|
-
},
|
|
532
|
-
setColumnPinning(pinning) {
|
|
533
|
-
// Defensive copy + dedupe so callers can't mutate our state.
|
|
534
|
-
const left = Array.from(new Set(pinning.left ?? []));
|
|
535
|
-
const right = Array.from(new Set(pinning.right ?? []));
|
|
536
|
-
ctx.columnPinning = { left, right };
|
|
537
|
-
},
|
|
538
|
-
getColumnPinning() {
|
|
539
|
-
return {
|
|
540
|
-
left: ctx.columnPinning.left.slice(),
|
|
541
|
-
right: ctx.columnPinning.right.slice(),
|
|
542
|
-
};
|
|
543
|
-
},
|
|
544
|
-
// ---- Column reorder
|
|
545
|
-
setColumnOrder(order) {
|
|
546
|
-
ctx.setColumnOrderInternal(order);
|
|
547
|
-
},
|
|
548
|
-
getColumnOrder() {
|
|
549
|
-
return ctx.getCurrentColumnOrder();
|
|
550
|
-
},
|
|
551
|
-
setRowExpanded(id, expanded) {
|
|
552
|
-
ctx.grid.setExpanded((prev: any) => ({ ...prev, [id]: !!expanded }));
|
|
553
|
-
},
|
|
554
|
-
expandAllGroups() {
|
|
555
|
-
// Walk the current grouped row model and flip every group node on.
|
|
556
|
-
const next: Record<string, boolean> = {};
|
|
557
|
-
const walk = (rows: ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>) => {
|
|
558
|
-
for (const row of rows) {
|
|
559
|
-
if (row.getCanExpand?.()) next[row.id] = true;
|
|
560
|
-
const sub = row.subRows as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }> | undefined;
|
|
561
|
-
if (sub && sub.length > 0) walk(sub);
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
walk(ctx.grid.getRowModel().rows as unknown as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>);
|
|
565
|
-
ctx.grid.setExpanded(() => next);
|
|
566
|
-
},
|
|
567
|
-
collapseAllGroups() {
|
|
568
|
-
ctx.grid.setExpanded(() => ({}));
|
|
569
|
-
},
|
|
570
|
-
// ---- Undo / redo (history + pointer)
|
|
571
|
-
undo() {
|
|
572
|
-
if (ctx.historyPtr < 0) return false
|
|
573
|
-
const step = ctx.history[ctx.historyPtr]
|
|
574
|
-
if (!step) return false
|
|
575
|
-
ctx.applyHistoryStep(step, 'undo')
|
|
576
|
-
ctx.historyPtr -= 1
|
|
577
|
-
ctx.historyVersion += 1
|
|
578
|
-
return true
|
|
579
|
-
},
|
|
580
|
-
redo() {
|
|
581
|
-
if (ctx.historyPtr >= ctx.history.length - 1) return false
|
|
582
|
-
const step = ctx.history[ctx.historyPtr + 1]
|
|
583
|
-
if (!step) return false
|
|
584
|
-
ctx.applyHistoryStep(step, 'redo')
|
|
585
|
-
ctx.historyPtr += 1
|
|
586
|
-
ctx.historyVersion += 1
|
|
587
|
-
return true
|
|
588
|
-
},
|
|
589
|
-
canUndo() { void ctx.historyVersion; return ctx.historyPtr >= 0 },
|
|
590
|
-
canRedo() { void ctx.historyVersion; return ctx.historyPtr < ctx.history.length - 1 },
|
|
591
|
-
clearHistory() { ctx.history = []; ctx.historyPtr = -1; ctx.historyVersion += 1 },
|
|
592
|
-
// ---- Find
|
|
593
|
-
openFind() { ctx.findOpen = true },
|
|
594
|
-
closeFind() { ctx.findOpen = false; ctx.findQuery = '' },
|
|
595
|
-
setFindQuery(q: string) { ctx.findQuery = q; ctx.findHitIndex = 0 },
|
|
596
|
-
getFindHits() { return ctx.findHits.slice() },
|
|
597
|
-
// ---- Row selection (read + write)
|
|
598
|
-
getSelectedRows() {
|
|
599
|
-
const out: TData[] = [];
|
|
600
|
-
for (const row of ctx.allRows) {
|
|
601
|
-
if (isGroupRow(row)) continue;
|
|
602
|
-
if (ctx.rowSelectionState[row.id]) out.push(row.original as TData);
|
|
603
|
-
}
|
|
604
|
-
return out;
|
|
605
|
-
},
|
|
606
|
-
getSelectedRowIds() {
|
|
607
|
-
const out: string[] = [];
|
|
608
|
-
for (const row of ctx.allRows) {
|
|
609
|
-
if (!isGroupRow(row) && ctx.rowSelectionState[row.id]) out.push(row.id);
|
|
610
|
-
}
|
|
611
|
-
return out;
|
|
612
|
-
},
|
|
613
|
-
selectRows(ids, additive = false) {
|
|
614
|
-
const set = new Set(ids);
|
|
615
|
-
ctx.grid.setRowSelection((prev: any) => {
|
|
616
|
-
const next: Record<string, boolean> = additive ? { ...prev } : {};
|
|
617
|
-
for (const id of set) next[id] = true;
|
|
618
|
-
return next;
|
|
619
|
-
});
|
|
620
|
-
},
|
|
621
|
-
selectAllRows() {
|
|
622
|
-
const next: Record<string, boolean> = {};
|
|
623
|
-
for (const row of ctx.allRows) if (!isGroupRow(row)) next[row.id] = true;
|
|
624
|
-
ctx.grid.setRowSelection(() => next);
|
|
625
|
-
},
|
|
626
|
-
toggleRowSelected(id) {
|
|
627
|
-
ctx.toggleRowSelectionById(id);
|
|
628
|
-
},
|
|
629
|
-
// ---- Pagination
|
|
630
|
-
getPageInfo() {
|
|
631
|
-
const { pageIndex, pageSize } = ctx.paginationState;
|
|
632
|
-
const total = ctx.allRowsBeforePagination.length;
|
|
633
|
-
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
634
|
-
return { pageIndex, pageSize, pageCount, total };
|
|
635
|
-
},
|
|
636
|
-
setPage(pageIndex) {
|
|
637
|
-
const total = ctx.allRowsBeforePagination.length;
|
|
638
|
-
const pageCount = Math.max(
|
|
639
|
-
1,
|
|
640
|
-
Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
|
|
641
|
-
);
|
|
642
|
-
ctx.goToPage(Math.max(0, Math.min(pageIndex, pageCount - 1)));
|
|
643
|
-
},
|
|
644
|
-
nextPage() {
|
|
645
|
-
this.setPage(ctx.paginationState.pageIndex + 1);
|
|
646
|
-
},
|
|
647
|
-
prevPage() {
|
|
648
|
-
this.setPage(ctx.paginationState.pageIndex - 1);
|
|
649
|
-
},
|
|
650
|
-
firstPage() {
|
|
651
|
-
this.setPage(0);
|
|
652
|
-
},
|
|
653
|
-
lastPage() {
|
|
654
|
-
const total = ctx.allRowsBeforePagination.length;
|
|
655
|
-
const pageCount = Math.max(
|
|
656
|
-
1,
|
|
657
|
-
Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
|
|
658
|
-
);
|
|
659
|
-
this.setPage(pageCount - 1);
|
|
660
|
-
},
|
|
661
|
-
setPageSize(size) {
|
|
662
|
-
// Calls the component-level helper (lexical scope), not this method.
|
|
663
|
-
ctx.setPageSize(Math.max(1, Math.floor(size)));
|
|
664
|
-
},
|
|
665
|
-
// ---- Navigation / scrolling
|
|
666
|
-
scrollToRow(rowIndex) {
|
|
667
|
-
if (!ctx.scrollContainer) return;
|
|
668
|
-
const maxIndex = Math.max(0, ctx.allRows.length - 1);
|
|
669
|
-
const clamped = Math.max(0, Math.min(rowIndex, maxIndex));
|
|
670
|
-
// Logical offset from the virtualizer (honors uniform OR per-row
|
|
671
|
-
// sizing), then mapped into the capped DOM scroll space so it lands
|
|
672
|
-
// correctly on huge grids where the DOM height is scaled down.
|
|
673
|
-
const logical = ctx.virtualizer.getOffsetForIndex(clamped);
|
|
674
|
-
ctx.scrollContainer.scrollTop = ctx.logicalToDomRowOffset(logical);
|
|
675
|
-
ctx.scheduleScrollSync(
|
|
676
|
-
ctx.scrollContainer.scrollTop,
|
|
677
|
-
ctx.scrollContainer.scrollLeft,
|
|
678
|
-
);
|
|
679
|
-
},
|
|
680
|
-
getActiveCell() {
|
|
681
|
-
const a = ctx.activeCell;
|
|
682
|
-
if (!a || a.rowIndex < 0 || a.colIndex < 0) return null;
|
|
683
|
-
const col = ctx.allColumns[a.colIndex];
|
|
684
|
-
return {
|
|
685
|
-
rowIndex: a.rowIndex,
|
|
686
|
-
colIndex: a.colIndex,
|
|
687
|
-
columnId: col?.id ?? "",
|
|
688
|
-
};
|
|
689
|
-
},
|
|
690
|
-
setActiveCell(rowIndex, colIndex) {
|
|
691
|
-
const r = Math.max(0, Math.min(rowIndex, Math.max(0, ctx.allRows.length - 1)));
|
|
692
|
-
const c = Math.max(
|
|
693
|
-
0,
|
|
694
|
-
Math.min(colIndex, Math.max(0, ctx.allColumns.length - 1)),
|
|
695
|
-
);
|
|
696
|
-
// Calls the component-level helper (lexical scope), not this method.
|
|
697
|
-
ctx.setActiveCell(r, c);
|
|
698
|
-
},
|
|
699
|
-
// ---- View state (save / restore)
|
|
700
|
-
getState() {
|
|
701
|
-
return {
|
|
702
|
-
sorting: (ctx.grid.getState().sorting ?? []).map(
|
|
703
|
-
(s: { id: string; desc: boolean }) => ({ id: s.id, desc: s.desc }),
|
|
704
|
-
),
|
|
705
|
-
grouping: [...(ctx.grid.getState().grouping ?? [])],
|
|
706
|
-
pagination: {
|
|
707
|
-
pageIndex: ctx.paginationState.pageIndex,
|
|
708
|
-
pageSize: ctx.paginationState.pageSize,
|
|
709
|
-
},
|
|
710
|
-
columnWidths: this.getColumnWidths(),
|
|
711
|
-
columnPinning: this.getColumnPinning(),
|
|
712
|
-
columnOrder: ctx.getCurrentColumnOrder(),
|
|
713
|
-
hiddenColumns: Object.keys(ctx.hiddenColumns).filter(
|
|
714
|
-
(k) => ctx.hiddenColumns[k],
|
|
715
|
-
),
|
|
716
|
-
globalFilter: ctx.globalFilter,
|
|
717
|
-
columnFilters: this.getFilters(),
|
|
718
|
-
facetFilters: Object.fromEntries(
|
|
719
|
-
Object.entries(ctx.valueFilters).map(([k, set]: [string, any]) => [
|
|
720
|
-
k,
|
|
721
|
-
Array.from(set),
|
|
722
|
-
]),
|
|
723
|
-
),
|
|
724
|
-
...(ctx.chartingEnabled
|
|
725
|
-
? {
|
|
726
|
-
chart: {
|
|
727
|
-
open: ctx.chartPanelOpen,
|
|
728
|
-
type: ctx.chartType,
|
|
729
|
-
dimension: ctx.chartDimensionId,
|
|
730
|
-
series: ctx.chartSeriesId,
|
|
731
|
-
measure: ctx.chartMeasureId,
|
|
732
|
-
reduce: ctx.chartReduce,
|
|
733
|
-
stacked: ctx.chartStacked,
|
|
734
|
-
},
|
|
735
|
-
charts: ctx.getChartsState(),
|
|
736
|
-
chartActive: ctx.activeChartIndex,
|
|
737
|
-
}
|
|
738
|
-
: {}),
|
|
739
|
-
};
|
|
740
|
-
},
|
|
741
|
-
setState(state) {
|
|
742
|
-
if (state.sorting) {
|
|
743
|
-
const sorting = state.sorting.map((s) => ({ id: s.id, desc: s.desc }));
|
|
744
|
-
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting }));
|
|
745
|
-
}
|
|
746
|
-
if (state.grouping) {
|
|
747
|
-
// Drop grouping by columns that no longer exist (#53) - otherwise a
|
|
748
|
-
// saved view collapses every row into a group named 'undefined'.
|
|
749
|
-
const existing = new Set((ctx.grid.getAllColumns() as any[]).map((c) => c.id));
|
|
750
|
-
ctx.grid.setGrouping(state.grouping.filter((id: string) => existing.has(id)));
|
|
751
|
-
}
|
|
752
|
-
if (state.pagination) {
|
|
753
|
-
const p = state.pagination;
|
|
754
|
-
ctx.grid.setPagination((prev: any) => ({ ...prev, ...p }));
|
|
755
|
-
}
|
|
756
|
-
if (state.columnWidths) ctx.columnWidths = { ...state.columnWidths };
|
|
757
|
-
if (state.columnPinning)
|
|
758
|
-
ctx.columnPinning = {
|
|
759
|
-
left: [...(state.columnPinning.left ?? [])],
|
|
760
|
-
right: [...(state.columnPinning.right ?? [])],
|
|
761
|
-
};
|
|
762
|
-
if (state.columnOrder) ctx.setColumnOrderInternal(state.columnOrder);
|
|
763
|
-
if (state.hiddenColumns) {
|
|
764
|
-
// Seed from columns declared `visible: false` so a partial/empty saved
|
|
765
|
-
// state never un-hides an app-declared-hidden column (#54); then layer
|
|
766
|
-
// the saved user-driven hides on top.
|
|
767
|
-
const next: Record<string, boolean> = { ...ctx.declaredHiddenColumns };
|
|
768
|
-
for (const id of state.hiddenColumns) next[id] = true;
|
|
769
|
-
ctx.hiddenColumns = next;
|
|
770
|
-
}
|
|
771
|
-
if (state.globalFilter !== undefined) ctx.globalFilter = state.globalFilter;
|
|
772
|
-
if (state.columnFilters)
|
|
773
|
-
ctx.filterMenuValues = { ...state.columnFilters };
|
|
774
|
-
if (state.facetFilters) {
|
|
775
|
-
const next: Record<string, Set<string>> = {};
|
|
776
|
-
for (const [k, arr] of Object.entries(state.facetFilters))
|
|
777
|
-
next[k] = new Set(arr);
|
|
778
|
-
ctx.valueFilters = next;
|
|
779
|
-
}
|
|
780
|
-
if ((state.chart || state.charts) && ctx.chartingEnabled) {
|
|
781
|
-
if (Array.isArray(state.charts) && state.charts.length) {
|
|
782
|
-
ctx.applyChartsState(state.charts, state.chartActive);
|
|
783
|
-
}
|
|
784
|
-
if (state.chart) {
|
|
785
|
-
const c = state.chart;
|
|
786
|
-
ctx.chartPanelOpen = c.open;
|
|
787
|
-
ctx.chartType = c.type;
|
|
788
|
-
ctx.chartDimensionId = c.dimension;
|
|
789
|
-
ctx.chartSeriesId = c.series;
|
|
790
|
-
ctx.chartMeasureId = c.measure;
|
|
791
|
-
ctx.chartReduce = c.reduce;
|
|
792
|
-
ctx.chartStacked = c.stacked;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
},
|
|
796
|
-
refresh() {
|
|
797
|
-
ctx.grid.store.setState((prev: any) => ({ ...prev }));
|
|
798
|
-
},
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return {
|
|
803
|
-
buildApi,
|
|
804
|
-
};
|
|
805
|
-
}
|
|
1
|
+
// build-api handlers extracted from the controller. Imperative event handlers
|
|
2
|
+
// reading/writing controller state via the `ctx` handle; the reactive core
|
|
3
|
+
// ($state/$derived/$effect) stays in the controller.
|
|
4
|
+
import {
|
|
5
|
+
type RowData,
|
|
6
|
+
type SvGridApi,
|
|
7
|
+
type TableFeatures,
|
|
8
|
+
} from "./index";
|
|
9
|
+
import "./sv-grid-scrollbar";
|
|
10
|
+
import { untrack } from "svelte";
|
|
11
|
+
// The export serializers load lazily (their own chunk) so export-format.ts stays
|
|
12
|
+
// out of the base bundle - it is fetched only when an export/copy method is
|
|
13
|
+
// actually invoked (an explicit, already-async user action).
|
|
14
|
+
import type {
|
|
15
|
+
GridExportColumn,
|
|
16
|
+
GridExportScope,
|
|
17
|
+
GridExportOptions,
|
|
18
|
+
GridClipboardOptions,
|
|
19
|
+
} from "./export-format";
|
|
20
|
+
import type {
|
|
21
|
+
FilterOperator,
|
|
22
|
+
} from "./SvGrid.types";
|
|
23
|
+
import {
|
|
24
|
+
isGroupRow,
|
|
25
|
+
getColumnAlign,
|
|
26
|
+
columnDefMatchesId,
|
|
27
|
+
} from "./cell-values";
|
|
28
|
+
|
|
29
|
+
export function createGridApi<
|
|
30
|
+
TFeatures extends TableFeatures = TableFeatures,
|
|
31
|
+
TData extends RowData = RowData,
|
|
32
|
+
>(ctx: any) {
|
|
33
|
+
function buildApi(): SvGridApi<TFeatures, TData> {
|
|
34
|
+
const findColumn = (columnId: string) =>
|
|
35
|
+
ctx.grid.getAllColumns().find((column: any) => column.id === columnId);
|
|
36
|
+
|
|
37
|
+
// --- Free data export (CSV / TSV / JSON + clipboard) helpers ----------
|
|
38
|
+
// Snapshot the VISIBLE columns (field + label + format + align) so the
|
|
39
|
+
// exporter reproduces on-screen values. Mirrors getColumns()'s visible set.
|
|
40
|
+
const exportColumns = (): GridExportColumn[] =>
|
|
41
|
+
ctx.allColumns
|
|
42
|
+
.map((c: any) => ({
|
|
43
|
+
field: (c.columnDef as { field?: string }).field as string,
|
|
44
|
+
header:
|
|
45
|
+
typeof c.columnDef.header === "string" ? c.columnDef.header : c.id,
|
|
46
|
+
format: c.columnDef.format,
|
|
47
|
+
align: getColumnAlign(c),
|
|
48
|
+
}))
|
|
49
|
+
.filter((c: GridExportColumn) => !!c.field);
|
|
50
|
+
// Rows for the requested scope: current view / checked / full dataset.
|
|
51
|
+
const exportScopeRows = (scope: GridExportScope): TData[] => {
|
|
52
|
+
if (scope === "all") return ctx.internalData as TData[];
|
|
53
|
+
const out: TData[] = [];
|
|
54
|
+
for (const row of ctx.allRows) {
|
|
55
|
+
if (isGroupRow(row)) continue;
|
|
56
|
+
if (scope === "selected" && !ctx.rowSelectionState[row.id]) continue;
|
|
57
|
+
out.push(row.original as TData);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
};
|
|
61
|
+
const projectForExport = async (
|
|
62
|
+
scope: GridExportScope,
|
|
63
|
+
columns: ReadonlyArray<string> | undefined,
|
|
64
|
+
rawValues: boolean | undefined,
|
|
65
|
+
) => {
|
|
66
|
+
const { projectGridRows } = await import("./export-format");
|
|
67
|
+
return projectGridRows(
|
|
68
|
+
exportScopeRows(scope) as ReadonlyArray<Record<string, unknown>>,
|
|
69
|
+
exportColumns(),
|
|
70
|
+
{ columns, rawValues },
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
getCellValue(rowIndex, columnId) {
|
|
76
|
+
const row = ctx.internalData[rowIndex];
|
|
77
|
+
const column = findColumn(columnId);
|
|
78
|
+
if (!row || !column) return undefined;
|
|
79
|
+
if (column.columnDef.fieldFn)
|
|
80
|
+
return column.columnDef.fieldFn(row);
|
|
81
|
+
if (column.columnDef.field)
|
|
82
|
+
return (row as Record<string, unknown>)[column.columnDef.field];
|
|
83
|
+
return undefined;
|
|
84
|
+
},
|
|
85
|
+
setCellValue(rowIndex, columnId, value) {
|
|
86
|
+
const row = ctx.internalData[rowIndex];
|
|
87
|
+
const column = findColumn(columnId);
|
|
88
|
+
if (!row || !column?.columnDef.field) return;
|
|
89
|
+
const next = ctx.internalData.slice() as Array<TData>;
|
|
90
|
+
next[rowIndex] = { ...row, [column.columnDef.field]: value } as TData;
|
|
91
|
+
ctx.internalData = next;
|
|
92
|
+
},
|
|
93
|
+
startEditing(rowIndex, columnId) {
|
|
94
|
+
return ctx.startEditing(rowIndex, columnId);
|
|
95
|
+
},
|
|
96
|
+
stopEditing(cancel) {
|
|
97
|
+
return ctx.stopEditing(cancel ?? false);
|
|
98
|
+
},
|
|
99
|
+
selectCells(ranges) {
|
|
100
|
+
// Multiple rectangles are supported. Empty array clears everything.
|
|
101
|
+
if (!ranges || ranges.length === 0) {
|
|
102
|
+
ctx.selectionRange = { anchor: null, focus: null };
|
|
103
|
+
ctx.selectionRanges = [];
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const rowCount = ctx.internalData.length;
|
|
107
|
+
const colCount = ctx.allColumns.length;
|
|
108
|
+
if (rowCount === 0 || colCount === 0) return;
|
|
109
|
+
// Clamp to the visible grid bounds so callers can pass open-ended
|
|
110
|
+
// values like `[0, 0, Infinity, Infinity]` to mean "select all".
|
|
111
|
+
const toRange = ([r1, c1, r2, c2]: readonly [number, number, number, number]) => ({
|
|
112
|
+
anchor: {
|
|
113
|
+
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.min(r1, r2))),
|
|
114
|
+
colIndex: Math.max(0, Math.min(colCount - 1, Math.min(c1, c2))),
|
|
115
|
+
},
|
|
116
|
+
focus: {
|
|
117
|
+
rowIndex: Math.max(0, Math.min(rowCount - 1, Math.max(r1, r2))),
|
|
118
|
+
colIndex: Math.max(0, Math.min(colCount - 1, Math.max(c1, c2))),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const built = ranges.map(toRange);
|
|
122
|
+
// Last range is the active one; the rest are committed extras.
|
|
123
|
+
ctx.selectionRanges = built.slice(0, -1);
|
|
124
|
+
const active = built[built.length - 1]!;
|
|
125
|
+
ctx.selectionRange = active;
|
|
126
|
+
// Move the active cell to the last range's top-left so keyboard
|
|
127
|
+
// navigation continues from there.
|
|
128
|
+
ctx.setActiveCell(active.anchor.rowIndex, active.anchor.colIndex);
|
|
129
|
+
},
|
|
130
|
+
getSelected() {
|
|
131
|
+
return ctx
|
|
132
|
+
.getSelectionRects()
|
|
133
|
+
.map((r: { minRow: number; minCol: number; maxRow: number; maxCol: number }) =>
|
|
134
|
+
[r.minRow, r.minCol, r.maxRow, r.maxCol] as [number, number, number, number],
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
openChart() {
|
|
138
|
+
ctx.chartPanelOpen = true;
|
|
139
|
+
},
|
|
140
|
+
closeChart() {
|
|
141
|
+
ctx.chartPanelOpen = false;
|
|
142
|
+
},
|
|
143
|
+
getChartSpec() {
|
|
144
|
+
return ctx.chartSpec;
|
|
145
|
+
},
|
|
146
|
+
chartRange(ranges) {
|
|
147
|
+
if (ranges && ranges.length) this.selectCells(ranges);
|
|
148
|
+
ctx.chartPanelOpen = true;
|
|
149
|
+
},
|
|
150
|
+
configureChart(config) {
|
|
151
|
+
if (ctx.chartingEnabled) ctx.applyChartConfig(config);
|
|
152
|
+
},
|
|
153
|
+
setChartAiHandler(handler) {
|
|
154
|
+
ctx.chartAiHandler = handler ?? null;
|
|
155
|
+
},
|
|
156
|
+
addRow(row, position = "bottom") {
|
|
157
|
+
this.addRows([row], position);
|
|
158
|
+
},
|
|
159
|
+
addRows(rows, position = "bottom") {
|
|
160
|
+
const next = ctx.internalData.slice() as Array<TData>;
|
|
161
|
+
if (position === "top") next.unshift(...rows);
|
|
162
|
+
else if (position === "bottom") next.push(...rows);
|
|
163
|
+
else if (typeof position === "number")
|
|
164
|
+
next.splice(Math.max(0, Math.min(position, next.length)), 0, ...rows);
|
|
165
|
+
ctx.internalData = next;
|
|
166
|
+
},
|
|
167
|
+
removeRow(rowIndex) {
|
|
168
|
+
this.removeRows([rowIndex]);
|
|
169
|
+
},
|
|
170
|
+
removeRows(rowIndices) {
|
|
171
|
+
const drop = new Set(rowIndices);
|
|
172
|
+
ctx.internalData = ctx.internalData.filter((_: any, i: any) => !drop.has(i));
|
|
173
|
+
},
|
|
174
|
+
applyTransaction(tx) {
|
|
175
|
+
const getId = ctx.props.getRowId;
|
|
176
|
+
let next = ctx.internalData.slice() as Array<TData>;
|
|
177
|
+
let added = 0;
|
|
178
|
+
let updated = 0;
|
|
179
|
+
let removed = 0;
|
|
180
|
+
|
|
181
|
+
if (tx.remove?.length) {
|
|
182
|
+
const removeIds = new Set<string>();
|
|
183
|
+
const removeRefs = new Set<TData>();
|
|
184
|
+
for (const r of tx.remove) {
|
|
185
|
+
if (typeof r === "string") removeIds.add(r);
|
|
186
|
+
else removeRefs.add(r as TData);
|
|
187
|
+
}
|
|
188
|
+
next = next.filter((row, i) => {
|
|
189
|
+
const hit =
|
|
190
|
+
removeRefs.has(row) ||
|
|
191
|
+
(getId ? removeIds.has(getId(row, i)) : false);
|
|
192
|
+
if (hit) removed += 1;
|
|
193
|
+
return !hit;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (tx.update?.length && getId) {
|
|
198
|
+
const byId = new Map<string, TData>();
|
|
199
|
+
for (const u of tx.update) byId.set(getId(u, 0), u);
|
|
200
|
+
next = next.map((row, i) => {
|
|
201
|
+
const u = byId.get(getId(row, i));
|
|
202
|
+
if (u) {
|
|
203
|
+
updated += 1;
|
|
204
|
+
return u;
|
|
205
|
+
}
|
|
206
|
+
return row;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (tx.add?.length) {
|
|
211
|
+
next.push(...(tx.add as Array<TData>));
|
|
212
|
+
added += tx.add.length;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
ctx.internalData = next;
|
|
216
|
+
return { added, updated, removed };
|
|
217
|
+
},
|
|
218
|
+
addColumn(column, position = "right") {
|
|
219
|
+
this.addColumns([column], position);
|
|
220
|
+
},
|
|
221
|
+
addColumns(columns, position = "right") {
|
|
222
|
+
const next = ctx.internalColumns.slice();
|
|
223
|
+
if (position === "left") next.unshift(...columns);
|
|
224
|
+
else if (position === "right") next.push(...columns);
|
|
225
|
+
else if (typeof position === "number")
|
|
226
|
+
next.splice(
|
|
227
|
+
Math.max(0, Math.min(position, next.length)),
|
|
228
|
+
0,
|
|
229
|
+
...columns,
|
|
230
|
+
);
|
|
231
|
+
ctx.internalColumns = next;
|
|
232
|
+
},
|
|
233
|
+
removeColumn(columnId) {
|
|
234
|
+
ctx.internalColumns = ctx.internalColumns.filter(
|
|
235
|
+
(def: any) => !columnDefMatchesId(def, columnId),
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
setColumnVisible(columnId, visible) {
|
|
239
|
+
if (visible) {
|
|
240
|
+
const next = { ...ctx.hiddenColumns };
|
|
241
|
+
delete next[columnId];
|
|
242
|
+
ctx.hiddenColumns = next;
|
|
243
|
+
} else {
|
|
244
|
+
ctx.hiddenColumns = { ...ctx.hiddenColumns, [columnId]: true };
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
isColumnVisible(columnId) {
|
|
248
|
+
return !ctx.hiddenColumns[columnId];
|
|
249
|
+
},
|
|
250
|
+
setSort(columnId, direction) {
|
|
251
|
+
// Honour the column's `sortable` opt-out. Asking the engine
|
|
252
|
+
// whether the column can sort folds in both the feature toggle
|
|
253
|
+
// AND the per-column flag.
|
|
254
|
+
const col = ctx.allColumns.find((c: any) => c.id === columnId);
|
|
255
|
+
if (col && !col.getCanSort?.()) return;
|
|
256
|
+
const clauses = direction
|
|
257
|
+
? [{ id: columnId, desc: direction === "desc" }]
|
|
258
|
+
: (ctx.grid.getState().sorting ?? []).filter(
|
|
259
|
+
(entry: { id: string }) => entry.id !== columnId,
|
|
260
|
+
);
|
|
261
|
+
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: clauses }));
|
|
262
|
+
},
|
|
263
|
+
clearSort() {
|
|
264
|
+
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting: [] }));
|
|
265
|
+
},
|
|
266
|
+
setGroupBy(columnIds) {
|
|
267
|
+
ctx.grid.setGrouping([...columnIds]);
|
|
268
|
+
},
|
|
269
|
+
setOption(key, value) {
|
|
270
|
+
// Runtime prop override. Writes into the controller's `optionOverrides`
|
|
271
|
+
// store, which the effective-props proxy merges over the incoming prop, so
|
|
272
|
+
// the grid re-renders exactly as if the parent had changed that prop.
|
|
273
|
+
// `undefined` clears the override (falls back to the prop). Reassign the
|
|
274
|
+
// whole object for reliable reactivity; `untrack` per the `setFilter` note.
|
|
275
|
+
untrack(() => {
|
|
276
|
+
const next: Record<string, unknown> = { ...ctx.optionOverrides };
|
|
277
|
+
if (value === undefined) delete next[key as string];
|
|
278
|
+
else next[key as string] = value;
|
|
279
|
+
ctx.optionOverrides = next;
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
getOption(key) {
|
|
283
|
+
// The effective value: the override if set, otherwise the incoming prop.
|
|
284
|
+
return (ctx.props as Record<string, unknown>)[key as string] as never;
|
|
285
|
+
},
|
|
286
|
+
resetOptions() {
|
|
287
|
+
untrack(() => {
|
|
288
|
+
ctx.optionOverrides = {};
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
setFilter(columnId, filter) {
|
|
292
|
+
// `untrack`: these imperative mutators read the same filter state they
|
|
293
|
+
// write (read-modify-write on `filterMenuValues`). When a consumer
|
|
294
|
+
// calls them from inside a reactive `$effect`, that internal read would
|
|
295
|
+
// otherwise be captured as a dependency of the caller's effect, and the
|
|
296
|
+
// write would re-dirty it - an infinite update loop. Untracking the
|
|
297
|
+
// body keeps the API safe to drive from an effect.
|
|
298
|
+
untrack(() => {
|
|
299
|
+
// Honour the column's `filterable` opt-out. Same approach as
|
|
300
|
+
// `setSort` - `getCanFilter()` already combines the feature flag
|
|
301
|
+
// and the per-column field.
|
|
302
|
+
const col = ctx.allColumns.find((c: any) => c.id === columnId);
|
|
303
|
+
if (col && !col.getCanFilter?.()) return;
|
|
304
|
+
if (!filter) {
|
|
305
|
+
this.clearFilter(columnId);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
ctx.filterMenuValues = {
|
|
309
|
+
...ctx.filterMenuValues,
|
|
310
|
+
[columnId]: {
|
|
311
|
+
operator: filter.operator,
|
|
312
|
+
value: filter.value ?? "",
|
|
313
|
+
...(filter.operator === "between"
|
|
314
|
+
? { valueTo: filter.valueTo ?? "" }
|
|
315
|
+
: {}),
|
|
316
|
+
// Optional second condition + join (multi-condition filtering).
|
|
317
|
+
...(filter.operator2
|
|
318
|
+
? {
|
|
319
|
+
operator2: filter.operator2,
|
|
320
|
+
value2: filter.value2 ?? "",
|
|
321
|
+
join: filter.join ?? "AND",
|
|
322
|
+
...(filter.operator2 === "between"
|
|
323
|
+
? { valueTo2: filter.valueTo2 ?? "" }
|
|
324
|
+
: {}),
|
|
325
|
+
}
|
|
326
|
+
: {}),
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
setFacetFilter(columnId, values) {
|
|
332
|
+
// See `setFilter` for why the read-modify-write is untracked.
|
|
333
|
+
untrack(() => {
|
|
334
|
+
// Empty array OR null both mean "clear this column's facet" -
|
|
335
|
+
// mirrors how the column menu treats unchecking the last value.
|
|
336
|
+
if (!values || values.length === 0) {
|
|
337
|
+
if (ctx.valueFilters[columnId]) {
|
|
338
|
+
const next = { ...ctx.valueFilters };
|
|
339
|
+
delete next[columnId];
|
|
340
|
+
ctx.valueFilters = next;
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
ctx.valueFilters = {
|
|
345
|
+
...ctx.valueFilters,
|
|
346
|
+
[columnId]: new Set(values),
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
clearFilter(columnId) {
|
|
351
|
+
ctx.clearColumnFilter(columnId);
|
|
352
|
+
},
|
|
353
|
+
refreshEditorOptions(columnId) {
|
|
354
|
+
// Async `editorOptions` are cached per column (or per column+row for a
|
|
355
|
+
// per-row source) so opening an editor twice does not refetch. This
|
|
356
|
+
// drops those entries, so the next render re-runs the source - use it
|
|
357
|
+
// when the underlying list changed server-side.
|
|
358
|
+
if (columnId == null) {
|
|
359
|
+
ctx.asyncEditorOptions = {};
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const next = { ...ctx.asyncEditorOptions };
|
|
363
|
+
for (const key of Object.keys(next)) {
|
|
364
|
+
if (key === columnId || key.startsWith(`${columnId}::`)) delete next[key];
|
|
365
|
+
}
|
|
366
|
+
ctx.asyncEditorOptions = next;
|
|
367
|
+
},
|
|
368
|
+
clearAllFilters() {
|
|
369
|
+
// See `setFilter` for why the read-modify-write is untracked.
|
|
370
|
+
untrack(() => {
|
|
371
|
+
// Wipe every filter surface in one go: column-menu, filter-row, set
|
|
372
|
+
// filters, and the global search box.
|
|
373
|
+
ctx.filterMenuValues = {};
|
|
374
|
+
ctx.filterRowValues = {};
|
|
375
|
+
ctx.valueFilters = {};
|
|
376
|
+
if (ctx.globalFilter !== "") ctx.globalFilter = "";
|
|
377
|
+
});
|
|
378
|
+
},
|
|
379
|
+
getFilters() {
|
|
380
|
+
// Return a defensive copy so callers can't mutate internal state.
|
|
381
|
+
const out: Record<
|
|
382
|
+
string,
|
|
383
|
+
{ operator: FilterOperator; value: string; valueTo?: string }
|
|
384
|
+
> = {};
|
|
385
|
+
for (const [columnId, filter] of Object.entries(ctx.filterMenuValues as Record<string, { operator: FilterOperator; value: string; valueTo?: string }>)) {
|
|
386
|
+
out[columnId] = {
|
|
387
|
+
operator: filter.operator,
|
|
388
|
+
value: filter.value,
|
|
389
|
+
...(filter.operator === "between" && filter.valueTo
|
|
390
|
+
? { valueTo: filter.valueTo }
|
|
391
|
+
: {}),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return out;
|
|
395
|
+
},
|
|
396
|
+
getDisplayedRows() {
|
|
397
|
+
// `allRows` is the final, post-filter, post-sort, post-group,
|
|
398
|
+
// post-pagination list - exactly what the body renders. Skip group
|
|
399
|
+
// header rows (they wrap an aggregate, not a TData row).
|
|
400
|
+
const out: TData[] = [];
|
|
401
|
+
for (const row of ctx.allRows) {
|
|
402
|
+
if (row.subRows && row.subRows.length > 0) continue;
|
|
403
|
+
out.push(row.original as TData);
|
|
404
|
+
}
|
|
405
|
+
return out;
|
|
406
|
+
},
|
|
407
|
+
getData() {
|
|
408
|
+
return ctx.internalData;
|
|
409
|
+
},
|
|
410
|
+
getColumns() {
|
|
411
|
+
// Snapshot every column with its human-readable label and
|
|
412
|
+
// visibility flag. Used by external code (exporters, column
|
|
413
|
+
// pickers) so they don't have to re-walk the columnDef tree.
|
|
414
|
+
// Hidden columns ARE included (with `visible: false`) so a column
|
|
415
|
+
// picker can re-enable them - callers that only want what's
|
|
416
|
+
// rendered filter by `.visible` (e.g. the exporter does).
|
|
417
|
+
const describe = (c: any, visible: boolean) => ({
|
|
418
|
+
id: c.id,
|
|
419
|
+
field: (c.columnDef as { field?: string }).field,
|
|
420
|
+
header:
|
|
421
|
+
typeof c.columnDef.header === "string"
|
|
422
|
+
? c.columnDef.header
|
|
423
|
+
: c.id,
|
|
424
|
+
visible,
|
|
425
|
+
// Surface the format + alignment so exporters can reproduce the
|
|
426
|
+
// on-screen display value (currency symbol, date pattern, etc.)
|
|
427
|
+
// instead of dumping raw values. `getColumnAlign` applies the same
|
|
428
|
+
// editorType-based default the body uses.
|
|
429
|
+
format: c.columnDef.format,
|
|
430
|
+
align: getColumnAlign(c),
|
|
431
|
+
});
|
|
432
|
+
// Visible columns first, in their current visual order...
|
|
433
|
+
const out = ctx.allColumns.map((c: any) => describe(c, true));
|
|
434
|
+
// ...then any column hidden via `visible: false` / setColumnVisible.
|
|
435
|
+
// Those aren't in `allColumns` (that list is visible-only), so pull
|
|
436
|
+
// them straight from the engine's leaf set.
|
|
437
|
+
const visibleIds = new Set(out.map((c: { id: string }) => c.id));
|
|
438
|
+
for (const c of ctx.grid.getAllColumns() as any[]) {
|
|
439
|
+
if (!visibleIds.has(c.id)) out.push(describe(c, false));
|
|
440
|
+
}
|
|
441
|
+
return out;
|
|
442
|
+
},
|
|
443
|
+
// ---- Free data export (CSV / TSV / JSON + clipboard) -----------------
|
|
444
|
+
async exportCsv(options: GridExportOptions = {}) {
|
|
445
|
+
const { serializeDelimited, downloadTextFile } = await import("./export-format");
|
|
446
|
+
const { records, fields } = await projectForExport(
|
|
447
|
+
options.rows ?? "displayed",
|
|
448
|
+
options.columns,
|
|
449
|
+
options.rawValues,
|
|
450
|
+
);
|
|
451
|
+
const text = await serializeDelimited(records, fields, {
|
|
452
|
+
csv: { delimiter: ",", bom: options.bom ?? true },
|
|
453
|
+
signal: options.signal,
|
|
454
|
+
onProgress: options.onProgress,
|
|
455
|
+
});
|
|
456
|
+
if (options.download !== false)
|
|
457
|
+
downloadTextFile(text, `${options.filename ?? "grid"}.csv`, "text/csv;charset=utf-8");
|
|
458
|
+
return text;
|
|
459
|
+
},
|
|
460
|
+
async exportTsv(options: GridExportOptions = {}) {
|
|
461
|
+
const { serializeDelimited, downloadTextFile } = await import("./export-format");
|
|
462
|
+
const { records, fields } = await projectForExport(
|
|
463
|
+
options.rows ?? "displayed",
|
|
464
|
+
options.columns,
|
|
465
|
+
options.rawValues,
|
|
466
|
+
);
|
|
467
|
+
const text = await serializeDelimited(records, fields, {
|
|
468
|
+
csv: { delimiter: "\t", bom: options.bom ?? true },
|
|
469
|
+
signal: options.signal,
|
|
470
|
+
onProgress: options.onProgress,
|
|
471
|
+
});
|
|
472
|
+
if (options.download !== false)
|
|
473
|
+
downloadTextFile(text, `${options.filename ?? "grid"}.tsv`, "text/tab-separated-values;charset=utf-8");
|
|
474
|
+
return text;
|
|
475
|
+
},
|
|
476
|
+
async exportJson(options: GridExportOptions = {}) {
|
|
477
|
+
const { serializeJson, downloadTextFile } = await import("./export-format");
|
|
478
|
+
const { records, fields } = await projectForExport(
|
|
479
|
+
options.rows ?? "displayed",
|
|
480
|
+
options.columns,
|
|
481
|
+
options.rawValues,
|
|
482
|
+
);
|
|
483
|
+
const text = await serializeJson(records, fields, {
|
|
484
|
+
signal: options.signal,
|
|
485
|
+
onProgress: options.onProgress,
|
|
486
|
+
});
|
|
487
|
+
if (options.download !== false)
|
|
488
|
+
downloadTextFile(text, `${options.filename ?? "grid"}.json`, "application/json");
|
|
489
|
+
return text;
|
|
490
|
+
},
|
|
491
|
+
async copyToClipboard(options: GridClipboardOptions = {}) {
|
|
492
|
+
const { serializeDelimited, serializeMarkdown, copyTextToClipboard } = await import("./export-format");
|
|
493
|
+
const { records, fields, align } = await projectForExport(
|
|
494
|
+
options.rows ?? "displayed",
|
|
495
|
+
options.columns,
|
|
496
|
+
options.rawValues,
|
|
497
|
+
);
|
|
498
|
+
const format = options.format ?? "tsv";
|
|
499
|
+
const text =
|
|
500
|
+
format === "markdown"
|
|
501
|
+
? await serializeMarkdown(records, fields, { align })
|
|
502
|
+
: await serializeDelimited(records, fields, {
|
|
503
|
+
csv: { delimiter: format === "csv" ? "," : "\t", bom: false },
|
|
504
|
+
});
|
|
505
|
+
await copyTextToClipboard(text);
|
|
506
|
+
return text;
|
|
507
|
+
},
|
|
508
|
+
clearRowSelection() {
|
|
509
|
+
// Wipe the internal selection map AND emit the change so any
|
|
510
|
+
// consumer holding a derived `selectedRows` resets too.
|
|
511
|
+
ctx.grid.setRowSelection(() => ({}));
|
|
512
|
+
ctx.props.onRowSelectionChange?.({}, []);
|
|
513
|
+
},
|
|
514
|
+
setColumnWidth(columnId: string, width: number) {
|
|
515
|
+
const clamped = Math.max(ctx.MIN_COLUMN_WIDTH, Math.floor(width));
|
|
516
|
+
ctx.columnWidths = { ...ctx.columnWidths, [columnId]: clamped };
|
|
517
|
+
},
|
|
518
|
+
getColumnWidths() {
|
|
519
|
+
// Resolve every column's effective width by consulting both the
|
|
520
|
+
// resize overrides (`columnWidths`) AND the columnDef defaults,
|
|
521
|
+
// so the snapshot is round-trippable through setColumnWidth.
|
|
522
|
+
const out: Record<string, number> = {};
|
|
523
|
+
for (const c of ctx.allColumns) out[c.id] = ctx.getColumnWidth(c.id);
|
|
524
|
+
return out;
|
|
525
|
+
},
|
|
526
|
+
autosizeColumn(columnId: string) {
|
|
527
|
+
ctx.autosizeColumn(columnId);
|
|
528
|
+
},
|
|
529
|
+
autosizeAllColumns() {
|
|
530
|
+
ctx.autosizeAllColumns();
|
|
531
|
+
},
|
|
532
|
+
setColumnPinning(pinning) {
|
|
533
|
+
// Defensive copy + dedupe so callers can't mutate our state.
|
|
534
|
+
const left = Array.from(new Set(pinning.left ?? []));
|
|
535
|
+
const right = Array.from(new Set(pinning.right ?? []));
|
|
536
|
+
ctx.columnPinning = { left, right };
|
|
537
|
+
},
|
|
538
|
+
getColumnPinning() {
|
|
539
|
+
return {
|
|
540
|
+
left: ctx.columnPinning.left.slice(),
|
|
541
|
+
right: ctx.columnPinning.right.slice(),
|
|
542
|
+
};
|
|
543
|
+
},
|
|
544
|
+
// ---- Column reorder
|
|
545
|
+
setColumnOrder(order) {
|
|
546
|
+
ctx.setColumnOrderInternal(order);
|
|
547
|
+
},
|
|
548
|
+
getColumnOrder() {
|
|
549
|
+
return ctx.getCurrentColumnOrder();
|
|
550
|
+
},
|
|
551
|
+
setRowExpanded(id, expanded) {
|
|
552
|
+
ctx.grid.setExpanded((prev: any) => ({ ...prev, [id]: !!expanded }));
|
|
553
|
+
},
|
|
554
|
+
expandAllGroups() {
|
|
555
|
+
// Walk the current grouped row model and flip every group node on.
|
|
556
|
+
const next: Record<string, boolean> = {};
|
|
557
|
+
const walk = (rows: ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>) => {
|
|
558
|
+
for (const row of rows) {
|
|
559
|
+
if (row.getCanExpand?.()) next[row.id] = true;
|
|
560
|
+
const sub = row.subRows as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }> | undefined;
|
|
561
|
+
if (sub && sub.length > 0) walk(sub);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
walk(ctx.grid.getRowModel().rows as unknown as ReadonlyArray<{ id: string; getCanExpand?: () => boolean; subRows?: ReadonlyArray<unknown> }>);
|
|
565
|
+
ctx.grid.setExpanded(() => next);
|
|
566
|
+
},
|
|
567
|
+
collapseAllGroups() {
|
|
568
|
+
ctx.grid.setExpanded(() => ({}));
|
|
569
|
+
},
|
|
570
|
+
// ---- Undo / redo (history + pointer)
|
|
571
|
+
undo() {
|
|
572
|
+
if (ctx.historyPtr < 0) return false
|
|
573
|
+
const step = ctx.history[ctx.historyPtr]
|
|
574
|
+
if (!step) return false
|
|
575
|
+
ctx.applyHistoryStep(step, 'undo')
|
|
576
|
+
ctx.historyPtr -= 1
|
|
577
|
+
ctx.historyVersion += 1
|
|
578
|
+
return true
|
|
579
|
+
},
|
|
580
|
+
redo() {
|
|
581
|
+
if (ctx.historyPtr >= ctx.history.length - 1) return false
|
|
582
|
+
const step = ctx.history[ctx.historyPtr + 1]
|
|
583
|
+
if (!step) return false
|
|
584
|
+
ctx.applyHistoryStep(step, 'redo')
|
|
585
|
+
ctx.historyPtr += 1
|
|
586
|
+
ctx.historyVersion += 1
|
|
587
|
+
return true
|
|
588
|
+
},
|
|
589
|
+
canUndo() { void ctx.historyVersion; return ctx.historyPtr >= 0 },
|
|
590
|
+
canRedo() { void ctx.historyVersion; return ctx.historyPtr < ctx.history.length - 1 },
|
|
591
|
+
clearHistory() { ctx.history = []; ctx.historyPtr = -1; ctx.historyVersion += 1 },
|
|
592
|
+
// ---- Find
|
|
593
|
+
openFind() { ctx.findOpen = true },
|
|
594
|
+
closeFind() { ctx.findOpen = false; ctx.findQuery = '' },
|
|
595
|
+
setFindQuery(q: string) { ctx.findQuery = q; ctx.findHitIndex = 0 },
|
|
596
|
+
getFindHits() { return ctx.findHits.slice() },
|
|
597
|
+
// ---- Row selection (read + write)
|
|
598
|
+
getSelectedRows() {
|
|
599
|
+
const out: TData[] = [];
|
|
600
|
+
for (const row of ctx.allRows) {
|
|
601
|
+
if (isGroupRow(row)) continue;
|
|
602
|
+
if (ctx.rowSelectionState[row.id]) out.push(row.original as TData);
|
|
603
|
+
}
|
|
604
|
+
return out;
|
|
605
|
+
},
|
|
606
|
+
getSelectedRowIds() {
|
|
607
|
+
const out: string[] = [];
|
|
608
|
+
for (const row of ctx.allRows) {
|
|
609
|
+
if (!isGroupRow(row) && ctx.rowSelectionState[row.id]) out.push(row.id);
|
|
610
|
+
}
|
|
611
|
+
return out;
|
|
612
|
+
},
|
|
613
|
+
selectRows(ids, additive = false) {
|
|
614
|
+
const set = new Set(ids);
|
|
615
|
+
ctx.grid.setRowSelection((prev: any) => {
|
|
616
|
+
const next: Record<string, boolean> = additive ? { ...prev } : {};
|
|
617
|
+
for (const id of set) next[id] = true;
|
|
618
|
+
return next;
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
selectAllRows() {
|
|
622
|
+
const next: Record<string, boolean> = {};
|
|
623
|
+
for (const row of ctx.allRows) if (!isGroupRow(row)) next[row.id] = true;
|
|
624
|
+
ctx.grid.setRowSelection(() => next);
|
|
625
|
+
},
|
|
626
|
+
toggleRowSelected(id) {
|
|
627
|
+
ctx.toggleRowSelectionById(id);
|
|
628
|
+
},
|
|
629
|
+
// ---- Pagination
|
|
630
|
+
getPageInfo() {
|
|
631
|
+
const { pageIndex, pageSize } = ctx.paginationState;
|
|
632
|
+
const total = ctx.allRowsBeforePagination.length;
|
|
633
|
+
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
634
|
+
return { pageIndex, pageSize, pageCount, total };
|
|
635
|
+
},
|
|
636
|
+
setPage(pageIndex) {
|
|
637
|
+
const total = ctx.allRowsBeforePagination.length;
|
|
638
|
+
const pageCount = Math.max(
|
|
639
|
+
1,
|
|
640
|
+
Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
|
|
641
|
+
);
|
|
642
|
+
ctx.goToPage(Math.max(0, Math.min(pageIndex, pageCount - 1)));
|
|
643
|
+
},
|
|
644
|
+
nextPage() {
|
|
645
|
+
this.setPage(ctx.paginationState.pageIndex + 1);
|
|
646
|
+
},
|
|
647
|
+
prevPage() {
|
|
648
|
+
this.setPage(ctx.paginationState.pageIndex - 1);
|
|
649
|
+
},
|
|
650
|
+
firstPage() {
|
|
651
|
+
this.setPage(0);
|
|
652
|
+
},
|
|
653
|
+
lastPage() {
|
|
654
|
+
const total = ctx.allRowsBeforePagination.length;
|
|
655
|
+
const pageCount = Math.max(
|
|
656
|
+
1,
|
|
657
|
+
Math.ceil(total / Math.max(1, ctx.paginationState.pageSize)),
|
|
658
|
+
);
|
|
659
|
+
this.setPage(pageCount - 1);
|
|
660
|
+
},
|
|
661
|
+
setPageSize(size) {
|
|
662
|
+
// Calls the component-level helper (lexical scope), not this method.
|
|
663
|
+
ctx.setPageSize(Math.max(1, Math.floor(size)));
|
|
664
|
+
},
|
|
665
|
+
// ---- Navigation / scrolling
|
|
666
|
+
scrollToRow(rowIndex) {
|
|
667
|
+
if (!ctx.scrollContainer) return;
|
|
668
|
+
const maxIndex = Math.max(0, ctx.allRows.length - 1);
|
|
669
|
+
const clamped = Math.max(0, Math.min(rowIndex, maxIndex));
|
|
670
|
+
// Logical offset from the virtualizer (honors uniform OR per-row
|
|
671
|
+
// sizing), then mapped into the capped DOM scroll space so it lands
|
|
672
|
+
// correctly on huge grids where the DOM height is scaled down.
|
|
673
|
+
const logical = ctx.virtualizer.getOffsetForIndex(clamped);
|
|
674
|
+
ctx.scrollContainer.scrollTop = ctx.logicalToDomRowOffset(logical);
|
|
675
|
+
ctx.scheduleScrollSync(
|
|
676
|
+
ctx.scrollContainer.scrollTop,
|
|
677
|
+
ctx.scrollContainer.scrollLeft,
|
|
678
|
+
);
|
|
679
|
+
},
|
|
680
|
+
getActiveCell() {
|
|
681
|
+
const a = ctx.activeCell;
|
|
682
|
+
if (!a || a.rowIndex < 0 || a.colIndex < 0) return null;
|
|
683
|
+
const col = ctx.allColumns[a.colIndex];
|
|
684
|
+
return {
|
|
685
|
+
rowIndex: a.rowIndex,
|
|
686
|
+
colIndex: a.colIndex,
|
|
687
|
+
columnId: col?.id ?? "",
|
|
688
|
+
};
|
|
689
|
+
},
|
|
690
|
+
setActiveCell(rowIndex, colIndex) {
|
|
691
|
+
const r = Math.max(0, Math.min(rowIndex, Math.max(0, ctx.allRows.length - 1)));
|
|
692
|
+
const c = Math.max(
|
|
693
|
+
0,
|
|
694
|
+
Math.min(colIndex, Math.max(0, ctx.allColumns.length - 1)),
|
|
695
|
+
);
|
|
696
|
+
// Calls the component-level helper (lexical scope), not this method.
|
|
697
|
+
ctx.setActiveCell(r, c);
|
|
698
|
+
},
|
|
699
|
+
// ---- View state (save / restore)
|
|
700
|
+
getState() {
|
|
701
|
+
return {
|
|
702
|
+
sorting: (ctx.grid.getState().sorting ?? []).map(
|
|
703
|
+
(s: { id: string; desc: boolean }) => ({ id: s.id, desc: s.desc }),
|
|
704
|
+
),
|
|
705
|
+
grouping: [...(ctx.grid.getState().grouping ?? [])],
|
|
706
|
+
pagination: {
|
|
707
|
+
pageIndex: ctx.paginationState.pageIndex,
|
|
708
|
+
pageSize: ctx.paginationState.pageSize,
|
|
709
|
+
},
|
|
710
|
+
columnWidths: this.getColumnWidths(),
|
|
711
|
+
columnPinning: this.getColumnPinning(),
|
|
712
|
+
columnOrder: ctx.getCurrentColumnOrder(),
|
|
713
|
+
hiddenColumns: Object.keys(ctx.hiddenColumns).filter(
|
|
714
|
+
(k) => ctx.hiddenColumns[k],
|
|
715
|
+
),
|
|
716
|
+
globalFilter: ctx.globalFilter,
|
|
717
|
+
columnFilters: this.getFilters(),
|
|
718
|
+
facetFilters: Object.fromEntries(
|
|
719
|
+
Object.entries(ctx.valueFilters).map(([k, set]: [string, any]) => [
|
|
720
|
+
k,
|
|
721
|
+
Array.from(set),
|
|
722
|
+
]),
|
|
723
|
+
),
|
|
724
|
+
...(ctx.chartingEnabled
|
|
725
|
+
? {
|
|
726
|
+
chart: {
|
|
727
|
+
open: ctx.chartPanelOpen,
|
|
728
|
+
type: ctx.chartType,
|
|
729
|
+
dimension: ctx.chartDimensionId,
|
|
730
|
+
series: ctx.chartSeriesId,
|
|
731
|
+
measure: ctx.chartMeasureId,
|
|
732
|
+
reduce: ctx.chartReduce,
|
|
733
|
+
stacked: ctx.chartStacked,
|
|
734
|
+
},
|
|
735
|
+
charts: ctx.getChartsState(),
|
|
736
|
+
chartActive: ctx.activeChartIndex,
|
|
737
|
+
}
|
|
738
|
+
: {}),
|
|
739
|
+
};
|
|
740
|
+
},
|
|
741
|
+
setState(state) {
|
|
742
|
+
if (state.sorting) {
|
|
743
|
+
const sorting = state.sorting.map((s) => ({ id: s.id, desc: s.desc }));
|
|
744
|
+
ctx.grid.store.setState((prev: any) => ({ ...prev, sorting }));
|
|
745
|
+
}
|
|
746
|
+
if (state.grouping) {
|
|
747
|
+
// Drop grouping by columns that no longer exist (#53) - otherwise a
|
|
748
|
+
// saved view collapses every row into a group named 'undefined'.
|
|
749
|
+
const existing = new Set((ctx.grid.getAllColumns() as any[]).map((c) => c.id));
|
|
750
|
+
ctx.grid.setGrouping(state.grouping.filter((id: string) => existing.has(id)));
|
|
751
|
+
}
|
|
752
|
+
if (state.pagination) {
|
|
753
|
+
const p = state.pagination;
|
|
754
|
+
ctx.grid.setPagination((prev: any) => ({ ...prev, ...p }));
|
|
755
|
+
}
|
|
756
|
+
if (state.columnWidths) ctx.columnWidths = { ...state.columnWidths };
|
|
757
|
+
if (state.columnPinning)
|
|
758
|
+
ctx.columnPinning = {
|
|
759
|
+
left: [...(state.columnPinning.left ?? [])],
|
|
760
|
+
right: [...(state.columnPinning.right ?? [])],
|
|
761
|
+
};
|
|
762
|
+
if (state.columnOrder) ctx.setColumnOrderInternal(state.columnOrder);
|
|
763
|
+
if (state.hiddenColumns) {
|
|
764
|
+
// Seed from columns declared `visible: false` so a partial/empty saved
|
|
765
|
+
// state never un-hides an app-declared-hidden column (#54); then layer
|
|
766
|
+
// the saved user-driven hides on top.
|
|
767
|
+
const next: Record<string, boolean> = { ...ctx.declaredHiddenColumns };
|
|
768
|
+
for (const id of state.hiddenColumns) next[id] = true;
|
|
769
|
+
ctx.hiddenColumns = next;
|
|
770
|
+
}
|
|
771
|
+
if (state.globalFilter !== undefined) ctx.globalFilter = state.globalFilter;
|
|
772
|
+
if (state.columnFilters)
|
|
773
|
+
ctx.filterMenuValues = { ...state.columnFilters };
|
|
774
|
+
if (state.facetFilters) {
|
|
775
|
+
const next: Record<string, Set<string>> = {};
|
|
776
|
+
for (const [k, arr] of Object.entries(state.facetFilters))
|
|
777
|
+
next[k] = new Set(arr);
|
|
778
|
+
ctx.valueFilters = next;
|
|
779
|
+
}
|
|
780
|
+
if ((state.chart || state.charts) && ctx.chartingEnabled) {
|
|
781
|
+
if (Array.isArray(state.charts) && state.charts.length) {
|
|
782
|
+
ctx.applyChartsState(state.charts, state.chartActive);
|
|
783
|
+
}
|
|
784
|
+
if (state.chart) {
|
|
785
|
+
const c = state.chart;
|
|
786
|
+
ctx.chartPanelOpen = c.open;
|
|
787
|
+
ctx.chartType = c.type;
|
|
788
|
+
ctx.chartDimensionId = c.dimension;
|
|
789
|
+
ctx.chartSeriesId = c.series;
|
|
790
|
+
ctx.chartMeasureId = c.measure;
|
|
791
|
+
ctx.chartReduce = c.reduce;
|
|
792
|
+
ctx.chartStacked = c.stacked;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
refresh() {
|
|
797
|
+
ctx.grid.store.setState((prev: any) => ({ ...prev }));
|
|
798
|
+
},
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return {
|
|
803
|
+
buildApi,
|
|
804
|
+
};
|
|
805
|
+
}
|