@svgrid/enterprise 3.0.2 → 3.0.3
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/LICENSE +94 -24
- package/README.md +36 -4
- package/dist/SvAdvancedFilter.svelte +1 -1
- package/dist/SvAlertsManager.svelte +2 -1
- package/dist/SvBoard.svelte +2 -1
- package/dist/SvExportMenu.svelte +4 -1
- package/dist/SvExportMenu.svelte.d.ts +0 -13
- package/dist/SvExpressionEditor.svelte +3 -3
- package/dist/SvFormulaBar.svelte +94 -20
- package/dist/SvFormulaBar.svelte.d.ts +7 -0
- package/dist/SvGridAlerts.svelte +49 -9
- package/dist/SvGridBoard.svelte +13 -8
- package/dist/SvGridBulkEditDrawer.svelte +26 -2
- package/dist/SvGridEditPanel.svelte +3 -0
- package/dist/SvGridScheduler.svelte +69 -40
- package/dist/SvGridSelectionBar.svelte +10 -3
- package/dist/SvPivotDesigner.svelte +198 -40
- package/dist/SvPivotDesigner.svelte.d.ts +27 -20
- package/dist/SvSheet.svelte +4043 -243
- package/dist/SvSheet.svelte.d.ts +76 -3
- package/dist/SvSheetChartSetup.svelte +151 -0
- package/dist/SvSheetChartSetup.svelte.d.ts +18 -0
- package/dist/SvSheetComment.svelte +216 -31
- package/dist/SvSheetComment.svelte.d.ts +11 -11
- package/dist/SvSheetConditionalFormat.svelte +28 -31
- package/dist/SvSheetDataValidation.svelte +66 -42
- package/dist/SvSheetEditRanges.svelte +217 -0
- package/dist/SvSheetEditRanges.svelte.d.ts +15 -0
- package/dist/SvSheetErrors.svelte +125 -0
- package/dist/SvSheetErrors.svelte.d.ts +20 -0
- package/dist/SvSheetEvaluate.svelte +133 -0
- package/dist/SvSheetEvaluate.svelte.d.ts +15 -0
- package/dist/SvSheetFilterMenu.svelte +137 -34
- package/dist/SvSheetFilterMenu.svelte.d.ts +5 -0
- package/dist/SvSheetFindReplace.svelte +19 -19
- package/dist/SvSheetFormatCells.svelte +125 -81
- package/dist/SvSheetGoalSeek.svelte +17 -16
- package/dist/SvSheetInsertFunction.svelte +15 -13
- package/dist/SvSheetIteration.svelte +81 -0
- package/dist/SvSheetIteration.svelte.d.ts +10 -0
- package/dist/SvSheetLink.svelte +99 -0
- package/dist/SvSheetLink.svelte.d.ts +17 -0
- package/dist/SvSheetListPicker.svelte +4 -2
- package/dist/SvSheetListPicker.svelte.d.ts +0 -6
- package/dist/SvSheetManageRules.svelte +20 -18
- package/dist/SvSheetNameManager.svelte +17 -15
- package/dist/SvSheetPageSetup.svelte +159 -0
- package/dist/SvSheetPageSetup.svelte.d.ts +13 -0
- package/dist/SvSheetPasteSpecial.svelte +22 -20
- package/dist/SvSheetPivot.svelte +220 -0
- package/dist/SvSheetPivot.svelte.d.ts +21 -0
- package/dist/SvSheetProtectSheet.svelte +81 -0
- package/dist/SvSheetProtectSheet.svelte.d.ts +11 -0
- package/dist/SvSheetRemoveDuplicates.svelte +13 -10
- package/dist/SvSheetRibbon.svelte +104 -51
- package/dist/SvSheetSizeDialog.svelte +4 -2
- package/dist/SvSheetSort.svelte +218 -0
- package/dist/SvSheetSort.svelte.d.ts +28 -0
- package/dist/SvSheetSparklines.svelte +135 -0
- package/dist/SvSheetSparklines.svelte.d.ts +14 -0
- package/dist/SvSheetTable.svelte +160 -0
- package/dist/SvSheetTable.svelte.d.ts +24 -0
- package/dist/SvSheetTabs.svelte +161 -31
- package/dist/SvSheetTabs.svelte.d.ts +22 -8
- package/dist/SvSheetTextToColumns.svelte +20 -20
- package/dist/SvSheetValidationAlert.svelte +8 -6
- package/dist/advanced-filter-enable.js +1 -1
- package/dist/alerts/alert-engine.d.ts +6 -0
- package/dist/alerts/alert-engine.js +21 -4
- package/dist/alerts/alert-formats.js +2 -0
- package/dist/alerts/alert-types.d.ts +1 -1
- package/dist/alerts.d.ts +1 -1
- package/dist/alerts.js +2 -2
- package/dist/board.js +2 -2
- package/dist/bulk-edit.d.ts +3 -1
- package/dist/bulk-edit.js +1 -1
- package/dist/cdn/svgrid-enterprise.svelte-external.js +39827 -16429
- package/dist/designer/assets/GridMenus-8gTNssgV.js +8 -0
- package/dist/designer/assets/{SvChartMenu-D9hEeHar.js → SvChartMenu-BDoeqGz6.js} +1 -1
- package/dist/designer/assets/{SvDateTimePicker-DARvKUL2.js → SvDateTimePicker-DCPg7WGN.js} +1 -1
- package/dist/designer/assets/SvGridCellEditor-DMoWJjEI.js +4 -0
- package/dist/designer/assets/{SvGridChart-B8j1SSy3.js → SvGridChart-Cy1ATrWh.js} +2 -2
- package/dist/designer/assets/SvGridChartBuilder-eQ3mn0L9.js +1 -0
- package/dist/designer/assets/{SvGridChartPanel-pT6ITc2P.js → SvGridChartPanel-CATdVc9X.js} +3 -3
- package/dist/designer/assets/{SvGridChartView-bg281UA1.js → SvGridChartView-CmsZtCED.js} +1 -1
- package/dist/designer/assets/SvGridDropdown-Cjz0H-fI.js +1 -0
- package/dist/designer/assets/{SvTabs-UFCMTHXS.js → SvTabs-2mHC6oaz.js} +1 -1
- package/dist/designer/assets/cell-formatting-BbubJTVz.js +1 -0
- package/dist/designer/assets/{chart-cIPUsbM5.js → chart-Cn7MnNqA.js} +1 -1
- package/dist/designer/assets/{chart-panel-messages-DtTxpBUU.js → chart-panel-messages-Dz7PTIqT.js} +1 -1
- package/dist/designer/assets/{chart-summary-Czu_5epb.js → chart-summary-BD1qYB2R.js} +1 -1
- package/dist/designer/assets/{chart-trend-D5I5VEe8.js → chart-trend-B8xr5LuD.js} +1 -1
- package/dist/designer/assets/{dismissable-BO547MH9.js → dismissable-ChWRPkoa.js} +1 -1
- package/dist/designer/assets/{export-format-D-eP4b2l.js → export-format-DGckmgKr.js} +1 -1
- package/dist/designer/assets/{focus-trap-CAreAhlU.js → focus-trap-V2-6Fy9I.js} +1 -1
- package/dist/designer/assets/{index-DwU7CAMm.js → index-D5bVbuzI.js} +317 -315
- package/dist/designer/assets/index-_JVFxt02.css +1 -0
- package/dist/designer/assets/row-resize-BInFWCpr.js +1 -0
- package/dist/designer/assets/server-block-cache-CXJKkJpy.js +1 -0
- package/dist/designer/assets/src-DUQ4xE3x.js +58 -0
- package/dist/designer/assets/validate-C3B8QKsM.js +1 -0
- package/dist/designer/index.html +17 -16
- package/dist/export-pdf.d.ts +75 -0
- package/dist/export-pdf.js +216 -15
- package/dist/export.js +10 -2
- package/dist/gantt/SvGridGantt.svelte +2890 -0
- package/dist/gantt/SvGridGantt.svelte.d.ts +30 -0
- package/dist/gantt/gantt-config.d.ts +73 -0
- package/dist/gantt/gantt-config.js +1 -0
- package/dist/gantt/gantt-critical-path.d.ts +67 -0
- package/dist/gantt/gantt-critical-path.js +207 -0
- package/dist/gantt/gantt-model.d.ts +257 -0
- package/dist/gantt/gantt-model.js +651 -0
- package/dist/gantt/gantt-resources.d.ts +59 -0
- package/dist/gantt/gantt-resources.js +71 -0
- package/dist/gantt/gantt.d.ts +7 -0
- package/dist/gantt/gantt.js +36 -0
- package/dist/gantt/index.d.ts +15 -0
- package/dist/gantt/index.js +22 -0
- package/dist/gantt/timeline-arrows.d.ts +102 -0
- package/dist/gantt/timeline-arrows.js +181 -0
- package/dist/import.d.ts +2 -2
- package/dist/import.js +1 -1
- package/dist/index.d.ts +34 -7
- package/dist/index.js +44 -7
- package/dist/install.js +8 -1
- package/dist/license-core.d.ts +17 -1
- package/dist/license-core.js +16 -5
- package/dist/license.d.ts +18 -2
- package/dist/license.js +71 -6
- package/dist/node/studio.js +140 -8
- package/dist/pivot-enable.js +2 -2
- package/dist/scheduler-dependencies.d.ts +35 -0
- package/dist/scheduler-dependencies.js +36 -1
- package/dist/scheduler.js +2 -2
- package/dist/selection-bar.js +2 -2
- package/dist/server/SvGroupCell.svelte +213 -0
- package/dist/server/SvGroupCell.svelte.d.ts +62 -0
- package/dist/server/SvRowGroupPanel.svelte +322 -0
- package/dist/server/SvRowGroupPanel.svelte.d.ts +37 -0
- package/dist/server/enable.d.ts +17 -0
- package/dist/server/enable.js +49 -0
- package/dist/server/index.d.ts +22 -0
- package/dist/server/index.js +24 -0
- package/dist/server/messages.d.ts +45 -0
- package/dist/server/messages.js +35 -0
- package/dist/server/server-group-model.d.ts +104 -0
- package/dist/server/server-group-model.js +272 -0
- package/dist/server/server-pivot.d.ts +46 -0
- package/dist/server/server-pivot.js +57 -0
- package/dist/server/server-row-model.d.ts +547 -0
- package/dist/server/server-row-model.js +1551 -0
- package/dist/server/server-selection.d.ts +99 -0
- package/dist/server/server-selection.js +215 -0
- package/dist/server/svgrid-adapter.d.ts +155 -0
- package/dist/server/svgrid-adapter.js +202 -0
- package/dist/sheet/ast.d.ts +45 -1
- package/dist/sheet/ast.js +14 -0
- package/dist/sheet/auto-filter.d.ts +58 -4
- package/dist/sheet/auto-filter.js +159 -11
- package/dist/sheet/autocomplete.d.ts +9 -0
- package/dist/sheet/autocomplete.js +90 -4
- package/dist/sheet/cell-images.d.ts +39 -0
- package/dist/sheet/cell-images.js +90 -0
- package/dist/sheet/cell-types.d.ts +58 -0
- package/dist/sheet/cell-types.js +96 -0
- package/dist/sheet/coerce.d.ts +40 -0
- package/dist/sheet/coerce.js +170 -3
- package/dist/sheet/comments.d.ts +43 -9
- package/dist/sheet/comments.js +85 -27
- package/dist/sheet/conditional-formats.d.ts +29 -6
- package/dist/sheet/conditional-formats.js +37 -12
- package/dist/sheet/csv.d.ts +32 -0
- package/dist/sheet/csv.js +158 -0
- package/dist/sheet/culture.d.ts +87 -0
- package/dist/sheet/culture.js +247 -0
- package/dist/sheet/delta.d.ts +102 -0
- package/dist/sheet/delta.js +203 -0
- package/dist/sheet/deps.d.ts +45 -1
- package/dist/sheet/deps.js +77 -2
- package/dist/sheet/document.d.ts +106 -4
- package/dist/sheet/document.js +204 -3
- package/dist/sheet/engine.d.ts +67 -0
- package/dist/sheet/engine.js +19 -0
- package/dist/sheet/entry.d.ts +8 -4
- package/dist/sheet/entry.js +171 -21
- package/dist/sheet/error-check.d.ts +49 -0
- package/dist/sheet/error-check.js +83 -0
- package/dist/sheet/evaluate-steps.d.ts +48 -0
- package/dist/sheet/evaluate-steps.js +196 -0
- package/dist/sheet/evaluate.d.ts +67 -0
- package/dist/sheet/evaluate.js +725 -13
- package/dist/sheet/filter-files.d.ts +37 -0
- package/dist/sheet/filter-files.js +465 -0
- package/dist/sheet/format-store.d.ts +15 -0
- package/dist/sheet/format-store.js +11 -1
- package/dist/sheet/from-rows.d.ts +14 -0
- package/dist/sheet/from-rows.js +50 -0
- package/dist/sheet/function-catalog.d.ts +1 -1
- package/dist/sheet/function-catalog.js +296 -5
- package/dist/sheet/functions.js +363 -91
- package/dist/sheet/index.d.ts +35 -8
- package/dist/sheet/index.js +35 -8
- package/dist/sheet/links.d.ts +57 -0
- package/dist/sheet/links.js +174 -0
- package/dist/sheet/messages.d.ts +778 -0
- package/dist/sheet/messages.js +806 -0
- package/dist/sheet/number-format.d.ts +52 -5
- package/dist/sheet/number-format.js +465 -68
- package/dist/sheet/objects.d.ts +106 -0
- package/dist/sheet/objects.js +149 -0
- package/dist/sheet/ods-document.d.ts +44 -0
- package/dist/sheet/ods-document.js +1275 -0
- package/dist/sheet/open-file.d.ts +26 -0
- package/dist/sheet/open-file.js +56 -0
- package/dist/sheet/outline.d.ts +82 -0
- package/dist/sheet/outline.js +228 -0
- package/dist/sheet/packs/array.d.ts +16 -0
- package/dist/sheet/packs/array.js +172 -0
- package/dist/sheet/packs/database.d.ts +42 -0
- package/dist/sheet/packs/database.js +142 -0
- package/dist/sheet/packs/engineering.d.ts +2 -0
- package/dist/sheet/packs/engineering.js +296 -0
- package/dist/sheet/packs/financial.d.ts +5 -0
- package/dist/sheet/packs/financial.js +220 -0
- package/dist/sheet/packs/math-stats.d.ts +2 -0
- package/dist/sheet/packs/math-stats.js +372 -0
- package/dist/sheet/packs/special.d.ts +44 -0
- package/dist/sheet/packs/special.js +187 -0
- package/dist/sheet/packs/stats-dist.d.ts +2 -0
- package/dist/sheet/packs/stats-dist.js +785 -0
- package/dist/sheet/packs/text-date.d.ts +2 -0
- package/dist/sheet/packs/text-date.js +332 -0
- package/dist/sheet/packs/trig.d.ts +2 -0
- package/dist/sheet/packs/trig.js +73 -0
- package/dist/sheet/page-setup.d.ts +73 -0
- package/dist/sheet/page-setup.js +73 -0
- package/dist/sheet/parse.js +42 -10
- package/dist/sheet/paste-special.d.ts +22 -0
- package/dist/sheet/paste-special.js +14 -5
- package/dist/sheet/pivot-range.d.ts +160 -0
- package/dist/sheet/pivot-range.js +333 -0
- package/dist/sheet/presence.d.ts +73 -0
- package/dist/sheet/presence.js +79 -0
- package/dist/sheet/print.d.ts +104 -0
- package/dist/sheet/print.js +169 -0
- package/dist/sheet/protection.d.ts +55 -1
- package/dist/sheet/protection.js +55 -2
- package/dist/sheet/rects.d.ts +1 -1
- package/dist/sheet/refs.d.ts +48 -0
- package/dist/sheet/refs.js +155 -8
- package/dist/sheet/ribbon-icons.d.ts +1 -1
- package/dist/sheet/ribbon-icons.js +186 -0
- package/dist/sheet/ribbon.d.ts +1 -1
- package/dist/sheet/ribbon.js +324 -23
- package/dist/sheet/sheet-kinds.d.ts +74 -0
- package/dist/sheet/sheet-kinds.js +91 -0
- package/dist/sheet/shortcuts.d.ts +13 -3
- package/dist/sheet/shortcuts.js +63 -12
- package/dist/sheet/sort.d.ts +51 -0
- package/dist/sheet/sort.js +107 -0
- package/dist/sheet/sparklines.d.ts +111 -0
- package/dist/sheet/sparklines.js +204 -0
- package/dist/sheet/table-styles.d.ts +74 -0
- package/dist/sheet/table-styles.js +152 -0
- package/dist/sheet/tables.d.ts +19 -0
- package/dist/sheet/tables.js +31 -0
- package/dist/sheet/tokenize.d.ts +18 -1
- package/dist/sheet/tokenize.js +60 -9
- package/dist/sheet/validation.d.ts +16 -0
- package/dist/sheet/validation.js +37 -0
- package/dist/sheet/workbook.d.ts +148 -3
- package/dist/sheet/workbook.js +742 -31
- package/dist/sheet/xls-cfb.d.ts +32 -0
- package/dist/sheet/xls-cfb.js +290 -0
- package/dist/sheet/xls-document.d.ts +10 -0
- package/dist/sheet/xls-document.js +1243 -0
- package/dist/sheet/xls-formula.d.ts +40 -0
- package/dist/sheet/xls-formula.js +569 -0
- package/dist/sheet/xlsx-document.d.ts +108 -0
- package/dist/sheet/xlsx-document.js +1849 -0
- package/dist/sheet/xlsx-drawing.d.ts +99 -0
- package/dist/sheet/xlsx-drawing.js +420 -0
- package/dist/sheet-enable.js +6 -7
- package/dist/sheet-text.d.ts +7 -0
- package/dist/sheet-text.js +29 -0
- package/dist/sources/auth-supabase.js +2 -2
- package/dist/sources/realtime-supabase.js +2 -2
- package/dist/sources/rest.d.ts +6 -2
- package/dist/sources/rest.js +42 -7
- package/dist/sources/supabase.d.ts +10 -1
- package/dist/sources/supabase.js +73 -40
- package/dist/studio/emit-project.js +14 -1
- package/dist/studio/index.js +1 -1
- package/dist/studio/project.d.ts +11 -2
- package/dist/studio/project.js +5 -2
- package/dist/studio/ui-components.generated.js +107 -2
- package/dist/sveltekit/in-memory.d.ts +2 -2
- package/dist/sveltekit/in-memory.js +125 -4
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/dist/sveltekit/query-plan.d.ts +50 -4
- package/dist/sveltekit/query-plan.js +25 -3
- package/dist/sveltekit/sql-source.d.ts +6 -0
- package/dist/sveltekit/sql-source.js +34 -6
- package/dist/sveltekit/sql.d.ts +31 -0
- package/dist/sveltekit/sql.js +135 -25
- package/dist/sveltekit/transport.d.ts +10 -2
- package/dist/sveltekit/transport.js +30 -6
- package/dist/upgrade-prompt.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/watermark.js +35 -2
- package/dist/wc/GridMenus-By9vPuq0.js +1088 -0
- package/dist/wc/SvChartMenu-CQNrQGT2.js +308 -0
- package/dist/wc/SvDateRangeInput-DR6m7bSM.js +199 -0
- package/dist/wc/SvDateTimePicker-D-vRnaMo.js +771 -0
- package/dist/wc/SvField-B_kurx_P.js +149 -0
- package/dist/wc/SvGrid.helpers-BdVDtjUm.js +135 -0
- package/dist/wc/SvGridCellEditor-Bnf1Kr5C.js +560 -0
- package/dist/wc/SvGridChart-BqUJh2pG.js +3572 -0
- package/dist/wc/SvGridChartBuilder-CGycC5cn.js +988 -0
- package/dist/wc/SvGridChartPanel-CRnizsHD.js +1746 -0
- package/dist/wc/SvGridChartView-D1pa_xMy.js +47 -0
- package/dist/wc/SvGridDropdown-45WsObLL.js +259 -0
- package/dist/wc/SvModal-DrfOYYyX.js +189 -0
- package/dist/wc/cell-formatting-CBfgahv1.js +86 -0
- package/dist/wc/chart-6OXlybVT.js +4341 -0
- package/dist/wc/chart-export-CeSADGfi.js +135 -0
- package/dist/wc/chart-export-pdf-BGko7MER.js +104 -0
- package/dist/wc/chart-summary-2m3ia1-n.js +137 -0
- package/dist/wc/chart-trend-CQOQtTMl.js +50 -0
- package/dist/wc/chart-validate-CD6ptiwg.js +180 -0
- package/dist/wc/client-DQIzjDBG.js +3064 -0
- package/dist/wc/column-resize-DUPgynvc.js +101 -0
- package/dist/wc/date-format-DS-z_h9v.js +1130 -0
- package/dist/wc/dismissable-CQ6XFXsk.js +45 -0
- package/dist/wc/editor-contract-peBDxir_.js +22 -0
- package/dist/wc/editor-registry-DxGKqcvx.js +24 -0
- package/dist/wc/focus-trap-Dbb2tJxb.js +65 -0
- package/dist/wc/list-option-DrRyivWp.js +82 -0
- package/dist/wc/popover-WsGlvtQv.js +69 -0
- package/dist/wc/positioning-BiKLfu1E.js +112 -0
- package/dist/wc/react.d.ts +41 -0
- package/dist/wc/react.js +90 -0
- package/dist/wc/rolldown-runtime-Dy4uBu1J.js +11 -0
- package/dist/wc/row-drag-touch-CycRR65n.js +93 -0
- package/dist/wc/row-resize-limG_N1z.js +111 -0
- package/dist/wc/sv-sheet-element.d.ts +97 -0
- package/dist/wc/sv-sheet-element.js +44213 -0
- package/dist/wc/svelte-virtualizer.svelte-CXtQy2TQ.js +530 -0
- package/dist/wc/validate-BqDthkNr.js +88 -0
- package/dist/wc/vue.d.ts +31 -0
- package/dist/wc/vue.js +75 -0
- package/package.json +30 -5
- package/dist/designer/assets/GridMenus-BlsvL_aU.js +0 -8
- package/dist/designer/assets/SvGridCellEditor-C7uQXYds.js +0 -4
- package/dist/designer/assets/SvGridChartBuilder-kvyIU_Rl.js +0 -1
- package/dist/designer/assets/SvGridDropdown-Bb3HH2Aj.js +0 -1
- package/dist/designer/assets/cell-formatting-wr5wm7US.js +0 -1
- package/dist/designer/assets/index-CMFgAoVV.css +0 -1
- package/dist/designer/assets/row-resize-DLktcqUK.js +0 -1
- package/dist/designer/assets/src-EdI3Xqds.js +0 -58
- package/dist/designer/assets/validate-h-aslRV9.js +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side GROUP row model (SSRM grouping) - the first-class
|
|
3
|
+
* companion to `createServerDataSource`. Grouping, aggregation, and lazy
|
|
4
|
+
* expansion all flow through the SAME `ServerDataSource.getRows` contract:
|
|
5
|
+
*
|
|
6
|
+
* - The request carries `groupBy` (the columns grouped on) and `groupKeys`
|
|
7
|
+
* (the path of the group being expanded). While `groupKeys.length <
|
|
8
|
+
* groupBy.length` the server returns GROUP rows (one per distinct key at
|
|
9
|
+
* that level, carrying the key + aggregate values); at the bottom level it
|
|
10
|
+
* returns the leaf rows under that path.
|
|
11
|
+
* - Expanding a group is just another `getRows` with `groupKeys` set to that
|
|
12
|
+
* group's path. This controller owns the group tree: expand / collapse,
|
|
13
|
+
* per-node lazy fetch + cache, race-safety, and flattening to a display
|
|
14
|
+
* list the grid renders (group rows with an expander, leaves underneath).
|
|
15
|
+
*
|
|
16
|
+
* Headless and framework-agnostic on purpose: render from `state.displayRows`
|
|
17
|
+
* and call `toggleGroup` from the group cell's expander.
|
|
18
|
+
*/
|
|
19
|
+
import type { ServerAggregation, ServerDataSource, ServerDisplayRow, ServerFilterModel, ServerGroupRow, ServerSortModel } from '@svgrid/grid';
|
|
20
|
+
export type ServerGroupState<TData> = {
|
|
21
|
+
/** The flattened tree: top-level groups, with expanded groups' children spliced in. */
|
|
22
|
+
displayRows: ServerDisplayRow<TData>[];
|
|
23
|
+
groupBy: string[];
|
|
24
|
+
/** True during the initial top-level fetch (before the root has ever loaded). */
|
|
25
|
+
loading: boolean;
|
|
26
|
+
/** The rejection from the last failed top-level fetch, else null. */
|
|
27
|
+
error: unknown;
|
|
28
|
+
sortModel: ServerSortModel;
|
|
29
|
+
filterModel: ServerFilterModel;
|
|
30
|
+
/** Ids (JSON of the path) of the currently expanded groups. */
|
|
31
|
+
expandedGroups: string[];
|
|
32
|
+
};
|
|
33
|
+
export type ServerGroupControllerOptions<TData> = {
|
|
34
|
+
/** Columns to group on, outer to inner. Empty in `treeData` mode. */
|
|
35
|
+
groupBy?: string[];
|
|
36
|
+
/** Value columns to roll up per group. */
|
|
37
|
+
aggregations?: ServerAggregation[];
|
|
38
|
+
/** Max children fetched per group in one request. Default 200. */
|
|
39
|
+
pageSize?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Self-referential tree mode: instead of grouping flat rows by columns, each
|
|
42
|
+
* row is a node whose children are fetched on expand. Requires `getRowId`
|
|
43
|
+
* (the node id, which builds the `groupKeys` path) and `hasChildren` (whether
|
|
44
|
+
* a node is expandable). `getRows` receives `groupKeys` = the path to the
|
|
45
|
+
* node being expanded, and returns that node's direct children.
|
|
46
|
+
*/
|
|
47
|
+
treeData?: boolean;
|
|
48
|
+
/** Node id, used to build the `groupKeys` path. Required in `treeData` mode. */
|
|
49
|
+
getRowId?: (row: TData) => string;
|
|
50
|
+
/** Whether a node can be expanded. Required in `treeData` mode. */
|
|
51
|
+
hasChildren?: (row: TData) => boolean;
|
|
52
|
+
/** Emit a subtotal "footer" row after each expanded group's children. */
|
|
53
|
+
groupFooters?: boolean;
|
|
54
|
+
/** Placeholder rows shown while a group's first block is loading. Default 3. */
|
|
55
|
+
skeletonRows?: number;
|
|
56
|
+
onChange: (state: ServerGroupState<TData>) => void;
|
|
57
|
+
};
|
|
58
|
+
export type ServerGroupController<TData> = {
|
|
59
|
+
/** (Re-)fetch the tree from the top. Call once to load the first level. */
|
|
60
|
+
refresh(): void;
|
|
61
|
+
setSort(sortModel: ServerSortModel): void;
|
|
62
|
+
setFilter(filterModel: ServerFilterModel): void;
|
|
63
|
+
/** Change the grouping columns. Collapses everything and reloads the top level. */
|
|
64
|
+
setGroupBy(groupBy: string[]): void;
|
|
65
|
+
/** Expand or collapse a group row (from its expander). */
|
|
66
|
+
toggleGroup(row: ServerGroupRow<TData>): void;
|
|
67
|
+
expandGroup(path: string[]): void;
|
|
68
|
+
collapseGroup(path: string[]): void;
|
|
69
|
+
/** Fetch the next block of a group's children (intra-group paging). */
|
|
70
|
+
loadMoreChildren(path: string[]): void;
|
|
71
|
+
isExpanded(path: string[]): boolean;
|
|
72
|
+
getState(): ServerGroupState<TData>;
|
|
73
|
+
/** Stop accepting in-flight responses. Call on unmount. */
|
|
74
|
+
dispose(): void;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Map a `ServerGroupState.displayRows` to grid rows: each row's data spread at
|
|
78
|
+
* the top level (so normal `field` columns show group subtotals on group rows
|
|
79
|
+
* and cell values on leaves) plus a `__group` marker the built-in `SvGroupCell`
|
|
80
|
+
* reads to draw the expander + indentation. Feed the result to `<SvGrid data>`.
|
|
81
|
+
*/
|
|
82
|
+
export type ServerGroupGridRow<TData> = TData & {
|
|
83
|
+
__group: ServerDisplayRow<TData>;
|
|
84
|
+
};
|
|
85
|
+
export declare function serverGroupRows<TData>(state: ServerGroupState<TData> | undefined | null): ServerGroupGridRow<TData>[];
|
|
86
|
+
/**
|
|
87
|
+
* Build the `serverGroup` prop for `<SvGrid>` from a controller, so the grid's
|
|
88
|
+
* built-in tree keyboard (ArrowRight / ArrowLeft expand / collapse) and treegrid
|
|
89
|
+
* a11y work with no app-level key handling. Reads the `__group` marker that
|
|
90
|
+
* `serverGroupRows` attaches. Usage: `<SvGrid ... serverGroup={serverGroupNav(ctl)} />`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function serverGroupNav<TData>(ctl: ServerGroupController<TData>): {
|
|
93
|
+
isGroup: (row: ServerGroupGridRow<TData>) => boolean;
|
|
94
|
+
level: (row: ServerGroupGridRow<TData>) => number;
|
|
95
|
+
expanded: (row: ServerGroupGridRow<TData>) => boolean;
|
|
96
|
+
onToggle: (row: ServerGroupGridRow<TData>) => void;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated Use `createServerRowModel`: every level scrolls, blocks are
|
|
100
|
+
* cached and evicted, failed blocks retry, and `<SvGrid rowModel={ctl} />`
|
|
101
|
+
* wires it in one prop. This model stays for the "Load N more" button it
|
|
102
|
+
* renders, and is otherwise unchanged.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createServerGroupModel<TData>(source: ServerDataSource<TData>, options: ServerGroupControllerOptions<TData>): ServerGroupController<TData>;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { nudgeServerRowModel } from './enable.js';
|
|
2
|
+
export function serverGroupRows(state) {
|
|
3
|
+
return (state?.displayRows ?? []).map((r) => ({ ...('data' in r ? r.data : {}), __group: r }));
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Build the `serverGroup` prop for `<SvGrid>` from a controller, so the grid's
|
|
7
|
+
* built-in tree keyboard (ArrowRight / ArrowLeft expand / collapse) and treegrid
|
|
8
|
+
* a11y work with no app-level key handling. Reads the `__group` marker that
|
|
9
|
+
* `serverGroupRows` attaches. Usage: `<SvGrid ... serverGroup={serverGroupNav(ctl)} />`.
|
|
10
|
+
*/
|
|
11
|
+
export function serverGroupNav(ctl) {
|
|
12
|
+
return {
|
|
13
|
+
isGroup: (row) => row.__group?.kind === 'group',
|
|
14
|
+
level: (row) => row.__group?.level ?? 0,
|
|
15
|
+
expanded: (row) => row.__group?.kind === 'group' ? row.__group.expanded : false,
|
|
16
|
+
onToggle: (row) => {
|
|
17
|
+
if (row.__group?.kind === 'group')
|
|
18
|
+
ctl.toggleGroup(row.__group);
|
|
19
|
+
else if (row.__group?.kind === 'more')
|
|
20
|
+
ctl.loadMoreChildren(row.__group.path);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const keyOf = (path) => JSON.stringify(path);
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `createServerRowModel`: every level scrolls, blocks are
|
|
27
|
+
* cached and evicted, failed blocks retry, and `<SvGrid rowModel={ctl} />`
|
|
28
|
+
* wires it in one prop. This model stays for the "Load N more" button it
|
|
29
|
+
* renders, and is otherwise unchanged.
|
|
30
|
+
*/
|
|
31
|
+
export function createServerGroupModel(source, options) {
|
|
32
|
+
// Runs without a key; shows the watermark + one console notice.
|
|
33
|
+
nudgeServerRowModel();
|
|
34
|
+
let groupBy = [...(options.groupBy ?? [])];
|
|
35
|
+
const aggregations = options.aggregations ?? [];
|
|
36
|
+
const pageSize = options.pageSize ?? 200;
|
|
37
|
+
const treeData = !!options.treeData;
|
|
38
|
+
if (treeData && (!options.getRowId || !options.hasChildren)) {
|
|
39
|
+
throw new Error('createServerGroupModel: treeData requires getRowId and hasChildren');
|
|
40
|
+
}
|
|
41
|
+
const getRowId = options.getRowId;
|
|
42
|
+
const hasChildren = options.hasChildren;
|
|
43
|
+
const groupFooters = !!options.groupFooters;
|
|
44
|
+
const skeletonRows = Math.max(0, options.skeletonRows ?? 3);
|
|
45
|
+
let sortModel = [];
|
|
46
|
+
let filterModel = {};
|
|
47
|
+
const nodes = new Map();
|
|
48
|
+
const expanded = new Set(); // path keys
|
|
49
|
+
// Generation guard: bumped on any tree reset so every fetch in flight for the
|
|
50
|
+
// previous shape is discarded when it lands (the classic stale-response bug).
|
|
51
|
+
let generation = 0;
|
|
52
|
+
let disposed = false;
|
|
53
|
+
const rootKey = keyOf([]);
|
|
54
|
+
function ensureNode(key) {
|
|
55
|
+
let node = nodes.get(key);
|
|
56
|
+
if (!node) {
|
|
57
|
+
node = { loaded: false, loading: false, error: null, count: 0, children: [] };
|
|
58
|
+
nodes.set(key, node);
|
|
59
|
+
}
|
|
60
|
+
return node;
|
|
61
|
+
}
|
|
62
|
+
// Walk the loaded tree from the root, splicing expanded groups' children in.
|
|
63
|
+
function flatten() {
|
|
64
|
+
const out = [];
|
|
65
|
+
const walk = (path) => {
|
|
66
|
+
const node = nodes.get(keyOf(path));
|
|
67
|
+
if (!node?.loaded)
|
|
68
|
+
return;
|
|
69
|
+
for (const child of node.children) {
|
|
70
|
+
if (child.kind === 'leaf') {
|
|
71
|
+
out.push({ kind: 'leaf', id: child.id, level: child.level, data: child.data });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const cid = keyOf(child.path);
|
|
75
|
+
const cnode = nodes.get(cid);
|
|
76
|
+
const isExp = expanded.has(cid);
|
|
77
|
+
out.push({
|
|
78
|
+
kind: 'group',
|
|
79
|
+
id: cid,
|
|
80
|
+
path: child.path,
|
|
81
|
+
field: child.field,
|
|
82
|
+
key: child.key,
|
|
83
|
+
level: child.level,
|
|
84
|
+
expanded: isExp,
|
|
85
|
+
loading: !!cnode?.loading,
|
|
86
|
+
aggregates: child.aggregates,
|
|
87
|
+
data: child.data,
|
|
88
|
+
});
|
|
89
|
+
if (isExp) {
|
|
90
|
+
if (cnode?.loaded) {
|
|
91
|
+
walk(child.path);
|
|
92
|
+
// Subtotal row after the group's children.
|
|
93
|
+
if (groupFooters) {
|
|
94
|
+
out.push({
|
|
95
|
+
kind: 'footer',
|
|
96
|
+
id: cid + 'footer',
|
|
97
|
+
level: child.level + 1,
|
|
98
|
+
path: child.path,
|
|
99
|
+
key: child.key,
|
|
100
|
+
aggregates: child.aggregates,
|
|
101
|
+
data: child.data,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (cnode?.loading) {
|
|
106
|
+
// First block in flight: placeholder skeleton rows.
|
|
107
|
+
for (let i = 0; i < skeletonRows; i += 1) {
|
|
108
|
+
out.push({ kind: 'skeleton', id: cid + 'sk' + i, level: child.level + 1 });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Intra-group paging: emit a "load more" affordance when only part of this
|
|
114
|
+
// node's children have been fetched.
|
|
115
|
+
if (node.children.length < node.count) {
|
|
116
|
+
out.push({
|
|
117
|
+
kind: 'more',
|
|
118
|
+
id: keyOf([...path, 'more']),
|
|
119
|
+
level: path.length,
|
|
120
|
+
path,
|
|
121
|
+
remaining: node.count - node.children.length,
|
|
122
|
+
loading: node.loading,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
walk([]);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
function emit() {
|
|
130
|
+
if (disposed)
|
|
131
|
+
return;
|
|
132
|
+
const root = nodes.get(rootKey);
|
|
133
|
+
options.onChange({
|
|
134
|
+
displayRows: flatten(),
|
|
135
|
+
groupBy: [...groupBy],
|
|
136
|
+
loading: !!root?.loading && !root?.loaded,
|
|
137
|
+
error: root?.error ?? null,
|
|
138
|
+
sortModel,
|
|
139
|
+
filterModel,
|
|
140
|
+
expandedGroups: [...expanded],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// append=false loads the first block of a node's children (on expand);
|
|
144
|
+
// append=true fetches the NEXT block and concatenates (intra-group paging).
|
|
145
|
+
async function fetchNode(path, append = false) {
|
|
146
|
+
if (disposed)
|
|
147
|
+
return;
|
|
148
|
+
const gen = generation;
|
|
149
|
+
const key = keyOf(path);
|
|
150
|
+
const node = ensureNode(key);
|
|
151
|
+
if (node.loading)
|
|
152
|
+
return; // a fetch for this node is already in flight
|
|
153
|
+
node.loading = true;
|
|
154
|
+
node.error = null;
|
|
155
|
+
emit();
|
|
156
|
+
const level = path.length;
|
|
157
|
+
const groupField = groupBy[level];
|
|
158
|
+
const startRow = append ? node.children.length : 0;
|
|
159
|
+
try {
|
|
160
|
+
const res = await source.getRows({
|
|
161
|
+
startRow,
|
|
162
|
+
endRow: startRow + pageSize,
|
|
163
|
+
pageIndex: Math.floor(startRow / pageSize),
|
|
164
|
+
pageSize,
|
|
165
|
+
sortModel,
|
|
166
|
+
filterModel,
|
|
167
|
+
groupBy,
|
|
168
|
+
groupKeys: path,
|
|
169
|
+
aggregations,
|
|
170
|
+
});
|
|
171
|
+
if (disposed || gen !== generation)
|
|
172
|
+
return; // stale: the tree was reset
|
|
173
|
+
node.count = res.rowCount;
|
|
174
|
+
const block = res.rows.map((data, i) => {
|
|
175
|
+
// A row is an expandable "group" when: (tree mode) the source says it has
|
|
176
|
+
// children, or (grouping mode) we are above the innermost groupBy level.
|
|
177
|
+
const isGroup = treeData ? hasChildren(data) : level < groupBy.length;
|
|
178
|
+
if (isGroup) {
|
|
179
|
+
const gk = treeData
|
|
180
|
+
? getRowId(data)
|
|
181
|
+
: ((v) => (v == null ? '' : String(v)))(data[groupField]);
|
|
182
|
+
const aggregates = {};
|
|
183
|
+
for (const a of aggregations)
|
|
184
|
+
aggregates[a.col] = data[a.col];
|
|
185
|
+
return { kind: 'group', path: [...path, gk], field: treeData ? '' : groupField, key: gk, level, aggregates, data };
|
|
186
|
+
}
|
|
187
|
+
const id = treeData && getRowId ? `${key}:${getRowId(data)}` : `${key}:${startRow + i}`;
|
|
188
|
+
return { kind: 'leaf', id, level, data };
|
|
189
|
+
});
|
|
190
|
+
node.children = append ? [...node.children, ...block] : block;
|
|
191
|
+
node.loaded = true;
|
|
192
|
+
node.loading = false;
|
|
193
|
+
emit();
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
if (disposed || gen !== generation)
|
|
197
|
+
return;
|
|
198
|
+
node.error = err;
|
|
199
|
+
if (!append)
|
|
200
|
+
node.loaded = false;
|
|
201
|
+
node.loading = false;
|
|
202
|
+
emit();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Clear the cache and reload the root plus any still-expanded paths (in
|
|
206
|
+
// parallel; flatten only descends into loaded nodes, so children appear as
|
|
207
|
+
// each level lands).
|
|
208
|
+
function resetTree() {
|
|
209
|
+
generation += 1;
|
|
210
|
+
nodes.clear();
|
|
211
|
+
void fetchNode([]);
|
|
212
|
+
for (const k of expanded)
|
|
213
|
+
void fetchNode(JSON.parse(k));
|
|
214
|
+
}
|
|
215
|
+
function expandGroup(path) {
|
|
216
|
+
const key = keyOf(path);
|
|
217
|
+
if (expanded.has(key))
|
|
218
|
+
return;
|
|
219
|
+
expanded.add(key);
|
|
220
|
+
const node = nodes.get(key);
|
|
221
|
+
if (!node?.loaded && !node?.loading)
|
|
222
|
+
void fetchNode(path);
|
|
223
|
+
else
|
|
224
|
+
emit();
|
|
225
|
+
}
|
|
226
|
+
function collapseGroup(path) {
|
|
227
|
+
if (expanded.delete(keyOf(path)))
|
|
228
|
+
emit();
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
refresh: resetTree,
|
|
232
|
+
setSort(next) {
|
|
233
|
+
sortModel = next;
|
|
234
|
+
resetTree();
|
|
235
|
+
},
|
|
236
|
+
setFilter(next) {
|
|
237
|
+
filterModel = next;
|
|
238
|
+
resetTree();
|
|
239
|
+
},
|
|
240
|
+
setGroupBy(next) {
|
|
241
|
+
groupBy = [...next];
|
|
242
|
+
expanded.clear();
|
|
243
|
+
resetTree();
|
|
244
|
+
},
|
|
245
|
+
toggleGroup(row) {
|
|
246
|
+
if (expanded.has(row.id))
|
|
247
|
+
collapseGroup(row.path);
|
|
248
|
+
else
|
|
249
|
+
expandGroup(row.path);
|
|
250
|
+
},
|
|
251
|
+
expandGroup,
|
|
252
|
+
collapseGroup,
|
|
253
|
+
loadMoreChildren: (path) => void fetchNode(path, true),
|
|
254
|
+
isExpanded: (path) => expanded.has(keyOf(path)),
|
|
255
|
+
getState() {
|
|
256
|
+
const root = nodes.get(rootKey);
|
|
257
|
+
return {
|
|
258
|
+
displayRows: flatten(),
|
|
259
|
+
groupBy: [...groupBy],
|
|
260
|
+
loading: !!root?.loading && !root?.loaded,
|
|
261
|
+
error: root?.error ?? null,
|
|
262
|
+
sortModel,
|
|
263
|
+
filterModel,
|
|
264
|
+
expandedGroups: [...expanded],
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
dispose() {
|
|
268
|
+
disposed = true;
|
|
269
|
+
generation += 1;
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side pivot: turning the fields a backend answered with into the
|
|
3
|
+
* column tree the grid renders.
|
|
4
|
+
*
|
|
5
|
+
* The backend does the pivoting. With `pivotMode` on, each group row it
|
|
6
|
+
* returns carries one value per (pivot key x aggregation), under a field
|
|
7
|
+
* named from the keys and the column joined by a separator - `2024_amount`,
|
|
8
|
+
* or `2024_Q1_amount` with two pivot columns - and the response lists those
|
|
9
|
+
* fields in `pivotResultFields`. This module builds, from that list alone, the
|
|
10
|
+
* header groups per key level with a value column under each, in the same
|
|
11
|
+
* shape the client-side pivot engine produces (`{ id, header, columns }`).
|
|
12
|
+
*
|
|
13
|
+
* The one thing the list cannot say is which trailing segment is the value
|
|
14
|
+
* column when the separator also appears in a key, so the aggregations are
|
|
15
|
+
* matched by suffix: `2024_gross_amount` with an aggregation on `amount`
|
|
16
|
+
* splits as key `2024_gross` + value `amount`.
|
|
17
|
+
*/
|
|
18
|
+
import type { ColumnDef } from '@svgrid/grid';
|
|
19
|
+
import type { ServerAggregation } from '@svgrid/grid/server';
|
|
20
|
+
/** How `buildPivotResultColumns` names, sizes and post-processes the generated value columns. */
|
|
21
|
+
export type PivotResultColumnOptions = {
|
|
22
|
+
/** The string between key segments and the value column. Default `_`. */
|
|
23
|
+
separator?: string;
|
|
24
|
+
/** Header text for a value column. Default: the aggregation as `sum(amount)`. */
|
|
25
|
+
valueHeader?: (aggregation: ServerAggregation) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Post-process each generated leaf column - set a width, a format, an align.
|
|
28
|
+
* Receives the field it reads and the default definition.
|
|
29
|
+
*/
|
|
30
|
+
pivotResultColumn?: (field: string, column: ColumnDef<any, any>) => ColumnDef<any, any>;
|
|
31
|
+
/** Width for a generated value column. Default 120. */
|
|
32
|
+
width?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Append a header group of row totals after the pivot keys: one column
|
|
35
|
+
* per aggregation reading the plain aggregate field (`amount`, not
|
|
36
|
+
* `2024_amount`), which the backend puts on every group row in pivot
|
|
37
|
+
* mode beside the per-key fields. `true` labels the group `Total`; a
|
|
38
|
+
* string is the label.
|
|
39
|
+
*/
|
|
40
|
+
rowTotals?: boolean | string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Parse `pivotResultFields` into a column tree. Fields whose suffix matches no
|
|
44
|
+
* aggregation are skipped - they are not pivoted values.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildPivotResultColumns(fields: ReadonlyArray<string>, aggregations: ReadonlyArray<ServerAggregation>, options?: PivotResultColumnOptions): Array<ColumnDef<any, any>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse `pivotResultFields` into a column tree. Fields whose suffix matches no
|
|
3
|
+
* aggregation are skipped - they are not pivoted values.
|
|
4
|
+
*/
|
|
5
|
+
export function buildPivotResultColumns(fields, aggregations, options = {}) {
|
|
6
|
+
const sep = options.separator ?? '_';
|
|
7
|
+
const width = options.width ?? 120;
|
|
8
|
+
const header = options.valueHeader ?? ((a) => `${a.fn}(${a.col})`);
|
|
9
|
+
const root = { key: '', children: new Map(), leaves: [] };
|
|
10
|
+
// Longest aggregation column first, so `net_amount` wins over `amount` for
|
|
11
|
+
// a field ending in `_net_amount`.
|
|
12
|
+
const aggs = [...aggregations].sort((a, b) => b.col.length - a.col.length);
|
|
13
|
+
for (const field of fields) {
|
|
14
|
+
const agg = aggs.find((a) => field === a.col || field.endsWith(sep + a.col));
|
|
15
|
+
if (!agg)
|
|
16
|
+
continue;
|
|
17
|
+
const keyPart = field === agg.col ? '' : field.slice(0, field.length - agg.col.length - sep.length);
|
|
18
|
+
const keys = keyPart === '' ? [] : keyPart.split(sep);
|
|
19
|
+
let node = root;
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
let next = node.children.get(key);
|
|
22
|
+
if (!next) {
|
|
23
|
+
next = { key, children: new Map(), leaves: [] };
|
|
24
|
+
node.children.set(key, next);
|
|
25
|
+
}
|
|
26
|
+
node = next;
|
|
27
|
+
}
|
|
28
|
+
node.leaves.push({ field, agg });
|
|
29
|
+
}
|
|
30
|
+
const leafColumn = (field, agg) => {
|
|
31
|
+
const base = { id: field, field, header: header(agg), width, align: 'right' };
|
|
32
|
+
return options.pivotResultColumn ? options.pivotResultColumn(field, base) : base;
|
|
33
|
+
};
|
|
34
|
+
const emit = (node, path) => {
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const child of node.children.values()) {
|
|
37
|
+
const childPath = [...path, child.key];
|
|
38
|
+
out.push({
|
|
39
|
+
id: `pv_group_${childPath.join(sep)}`,
|
|
40
|
+
header: child.key,
|
|
41
|
+
columns: emit(child, childPath),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
for (const leaf of node.leaves)
|
|
45
|
+
out.push(leafColumn(leaf.field, leaf.agg));
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
const out = emit(root, []);
|
|
49
|
+
if (options.rowTotals) {
|
|
50
|
+
out.push({
|
|
51
|
+
id: 'pv_group_total',
|
|
52
|
+
header: typeof options.rowTotals === 'string' ? options.rowTotals : 'Total',
|
|
53
|
+
columns: aggregations.map((a) => leafColumn(a.col, a)),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|