@veltra/sheet 2.1.1 → 2.2.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.
Files changed (202) hide show
  1. package/dist/components/report/binding-badge.js +76 -0
  2. package/dist/components/report/designer/cell-coords.js +46 -0
  3. package/dist/components/report/designer/col-widths.js +15 -0
  4. package/dist/components/report/designer/conditional-rules/helpers.js +139 -0
  5. package/dist/components/report/designer/drop-highlight-overlay.js +76 -0
  6. package/dist/components/report/designer/float-panel.js +385 -0
  7. package/dist/components/report/designer/role.js +17 -0
  8. package/dist/components/report/designer/rule-preview.js +33 -0
  9. package/dist/components/report/designer/rule-row.js +269 -0
  10. package/dist/components/report/designer/rules-dialog.js +135 -0
  11. package/dist/components/report/designer/topology-overlay.js +122 -0
  12. package/dist/components/report/designer/topology.js +64 -0
  13. package/dist/components/report/designer/use-grid-overlay.js +75 -0
  14. package/dist/components/report/designer-hub.js +177 -0
  15. package/dist/components/report/field-panel-helpers.js +33 -0
  16. package/dist/components/report/field-panel.js +132 -0
  17. package/dist/components/report/filter-bar.js +74 -0
  18. package/dist/components/report/hub-connection-form.js +145 -0
  19. package/dist/components/report/hub-dataset-editor.js +394 -0
  20. package/dist/components/report/report-designer.js +343 -0
  21. package/dist/components/report/report-viewer.js +111 -0
  22. package/dist/components/report/style.d.ts +17 -0
  23. package/dist/components/report/style.js +18 -0
  24. package/dist/components/report/style2.css +869 -0
  25. package/dist/components/report/use-report-designer.js +360 -0
  26. package/dist/components/report/use-report-viewer.js +50 -0
  27. package/dist/{vue → components/sheet}/formula-bar.js +1 -1
  28. package/dist/{vue → components/sheet}/formula-suggest-list.js +1 -1
  29. package/dist/{vue → components/sheet}/import-file.js +1 -1
  30. package/dist/{vue → components/sheet}/insert-count-menu-item.js +1 -1
  31. package/dist/{vue → components/sheet}/insert-image.js +1 -1
  32. package/dist/{vue → components/sheet}/popup-helpers.js +1 -1
  33. package/dist/{vue → components/sheet}/popups/border-popup.js +1 -1
  34. package/dist/{vue → components/sheet}/popups/border-preset-glyph.js +1 -1
  35. package/dist/{vue → components/sheet}/popups/export-popup.js +2 -2
  36. package/dist/{vue → components/sheet}/popups/fill-color-popup.js +1 -1
  37. package/dist/{vue → components/sheet}/popups/find-popup.js +1 -1
  38. package/dist/{vue → components/sheet}/popups/font-color-popup.js +1 -1
  39. package/dist/{vue → components/sheet}/popups/font-size-popup.js +1 -1
  40. package/dist/{vue → components/sheet}/popups/import.worker.d.ts +1 -1
  41. package/dist/{vue → components/sheet}/popups/import.worker.js +1 -1
  42. package/dist/{vue → components/sheet}/popups/insert-image-popup.js +1 -1
  43. package/dist/{vue → components/sheet}/sheet-context-menu.js +1 -1
  44. package/dist/{vue → components/sheet}/sheet-tabs.js +1 -1
  45. package/dist/{vue → components/sheet}/sheet-toolbar.js +1 -1
  46. package/dist/{vue → components/sheet}/sheet.js +8 -1
  47. package/dist/{vue → components/sheet}/use-find-replace.js +1 -1
  48. package/dist/{vue → components/sheet}/use-formula-ref-select.js +1 -1
  49. package/dist/{vue → components/sheet}/use-sheet-grid.js +10 -2
  50. package/dist/{vue → components/sheet}/use-sheet-state.js +3 -3
  51. package/dist/{vue → components/sheet}/use-sheet-tabs-bar.js +1 -1
  52. package/dist/{vue → components/sheet}/use-tool-groups.js +2 -2
  53. package/dist/{vue → components/sheet}/use-tool-popup.js +2 -2
  54. package/dist/{vue → components/sheet}/use-toolbar-scroll.js +1 -1
  55. package/dist/index.d.ts +17 -3
  56. package/dist/index.js +13 -3
  57. package/dist/report/binding.d.ts +45 -0
  58. package/dist/report/binding.js +175 -0
  59. package/dist/report/connector.d.ts +66 -0
  60. package/dist/report/connector.js +159 -0
  61. package/dist/report/export-xlsx.d.ts +19 -0
  62. package/dist/report/export-xlsx.js +95 -0
  63. package/dist/report/filter-bar.d.ts +10 -0
  64. package/dist/report/filter-bar.js +31 -0
  65. package/dist/report/index.d.ts +12 -0
  66. package/dist/report/params.d.ts +13 -0
  67. package/dist/report/params.js +61 -0
  68. package/dist/report/render/aggregate.js +157 -0
  69. package/dist/report/render/builder.d.ts +12 -0
  70. package/dist/report/render/builder.js +139 -0
  71. package/dist/report/render/coordinate.d.ts +25 -0
  72. package/dist/report/render/coordinate.js +733 -0
  73. package/dist/report/render/index.d.ts +14 -0
  74. package/dist/report/render/index.js +21 -0
  75. package/dist/report/render/style-resolver.js +50 -0
  76. package/dist/report/render/template-index.d.ts +24 -0
  77. package/dist/report/render/template-index.js +137 -0
  78. package/dist/report/rules/evaluate.d.ts +25 -0
  79. package/dist/report/rules/evaluate.js +82 -0
  80. package/dist/report/rules/index.d.ts +2 -0
  81. package/dist/report/template.d.ts +59 -0
  82. package/dist/report/template.js +80 -0
  83. package/dist/report/types.d.ts +85 -0
  84. package/dist/tools/context.d.ts +1 -1
  85. package/dist/types/index.d.ts +3 -2
  86. package/dist/types/report-designer.d.ts +36 -0
  87. package/dist/types/report-viewer.d.ts +38 -0
  88. package/dist/types/sheet.d.ts +17 -1
  89. package/package.json +3 -5
  90. package/src/components/report/__test__/conditional-rules-helpers.test.ts +87 -0
  91. package/src/components/report/__test__/field-panel-helpers.test.ts +65 -0
  92. package/src/components/report/__test__/float-panel-position.test.ts +45 -0
  93. package/src/components/report/__test__/report-designer.test.ts +388 -0
  94. package/src/components/report/__test__/report-viewer.test.ts +334 -0
  95. package/src/components/report/__test__/topology.test.ts +143 -0
  96. package/src/components/report/__test__/use-report-designer.test.ts +565 -0
  97. package/src/components/report/binding-badge.ts +73 -0
  98. package/src/components/report/designer/cell-coords.ts +94 -0
  99. package/src/components/report/designer/col-widths.ts +33 -0
  100. package/src/components/report/designer/conditional-rules/helpers.ts +186 -0
  101. package/src/components/report/designer/drop-highlight-overlay.vue +74 -0
  102. package/src/components/report/designer/float-panel.vue +387 -0
  103. package/src/components/report/designer/role.ts +32 -0
  104. package/src/components/report/designer/rule-preview.vue +40 -0
  105. package/src/components/report/designer/rule-row.vue +252 -0
  106. package/src/components/report/designer/rules-dialog.vue +126 -0
  107. package/src/components/report/designer/topology-overlay.vue +127 -0
  108. package/src/components/report/designer/topology.ts +124 -0
  109. package/src/components/report/designer/use-grid-overlay.ts +113 -0
  110. package/src/components/report/designer-hub.vue +198 -0
  111. package/src/components/report/field-panel-helpers.ts +44 -0
  112. package/src/components/report/field-panel.vue +136 -0
  113. package/src/components/report/filter-bar.vue +77 -0
  114. package/src/components/report/hub-connection-form.vue +124 -0
  115. package/src/components/report/hub-dataset-editor.vue +369 -0
  116. package/src/components/report/index.ts +2 -0
  117. package/src/components/report/report-designer.vue +356 -0
  118. package/src/components/report/report-viewer.vue +128 -0
  119. package/src/components/report/style-designer.scss +583 -0
  120. package/src/components/report/style-hub.scss +292 -0
  121. package/src/components/report/style-viewer.scss +104 -0
  122. package/src/components/report/style.scss +3 -0
  123. package/src/components/report/style.ts +20 -0
  124. package/src/components/report/use-report-designer.ts +547 -0
  125. package/src/components/report/use-report-viewer.ts +79 -0
  126. package/src/{vue → components/sheet}/__test__/formula-bar.test.ts +37 -18
  127. package/src/{vue → components/sheet}/__test__/insert-image-popup.test.ts +1 -1
  128. package/src/{vue → components/sheet}/__test__/insert-image.test.ts +1 -1
  129. package/src/{vue → components/sheet}/__test__/sheet-component.test.ts +40 -3
  130. package/src/{vue → components/sheet}/__test__/sheet-context-menu.test.ts +1 -1
  131. package/src/{vue → components/sheet}/formula-bar.vue +1 -1
  132. package/src/{vue → components/sheet}/insert-image.ts +1 -1
  133. package/src/{vue → components/sheet}/popup-helpers.ts +1 -1
  134. package/src/{vue → components/sheet}/popups/border-popup.vue +1 -1
  135. package/src/{vue → components/sheet}/popups/export-popup.vue +2 -2
  136. package/src/{vue → components/sheet}/popups/fill-color-popup.vue +1 -1
  137. package/src/{vue → components/sheet}/popups/find-popup.vue +1 -1
  138. package/src/{vue → components/sheet}/popups/font-color-popup.vue +1 -1
  139. package/src/{vue → components/sheet}/popups/font-size-popup.vue +1 -1
  140. package/src/{vue → components/sheet}/popups/insert-image-popup.vue +1 -1
  141. package/src/{vue → components/sheet}/sheet-context-menu.ts +2 -2
  142. package/src/{vue → components/sheet}/sheet-toolbar.vue +2 -2
  143. package/src/{vue → components/sheet}/sheet.vue +4 -3
  144. package/src/{vue → components/sheet}/use-find-replace.ts +1 -1
  145. package/src/{vue → components/sheet}/use-sheet-grid.ts +7 -3
  146. package/src/{vue → components/sheet}/use-sheet-state.ts +3 -3
  147. package/src/{vue → components/sheet}/use-tool-groups.ts +2 -2
  148. package/src/{vue → components/sheet}/use-tool-popup.ts +2 -2
  149. package/src/index.ts +24 -188
  150. package/src/report/__test__/binding.test.ts +218 -0
  151. package/src/report/__test__/connector.test.ts +218 -0
  152. package/src/report/__test__/export-xlsx.test.ts +118 -0
  153. package/src/report/__test__/filter-bar.test.ts +58 -0
  154. package/src/report/__test__/params.test.ts +156 -0
  155. package/src/report/__test__/render.test.ts +728 -0
  156. package/src/report/__test__/rules.test.ts +131 -0
  157. package/src/report/__test__/template.test.ts +355 -0
  158. package/src/report/binding.ts +243 -0
  159. package/src/report/connector.ts +205 -0
  160. package/src/report/export-xlsx.ts +118 -0
  161. package/src/report/filter-bar.ts +36 -0
  162. package/src/report/index.ts +13 -0
  163. package/src/report/params.ts +96 -0
  164. package/src/report/render/__test__/aggregate.test.ts +16 -0
  165. package/src/report/render/__test__/coordinate.test.ts +405 -0
  166. package/src/report/render/aggregate.ts +240 -0
  167. package/src/report/render/builder.ts +211 -0
  168. package/src/report/render/coordinate.ts +1239 -0
  169. package/src/report/render/index.ts +30 -0
  170. package/src/report/render/style-resolver.ts +68 -0
  171. package/src/report/render/template-index.ts +200 -0
  172. package/src/report/rules/evaluate.ts +113 -0
  173. package/src/report/rules/index.ts +7 -0
  174. package/src/report/template.ts +141 -0
  175. package/src/report/types.ts +96 -0
  176. package/src/tools/builtin.ts +2 -2
  177. package/src/types/index.ts +2 -6
  178. package/src/types/report-designer.ts +36 -0
  179. package/src/types/report-viewer.ts +37 -0
  180. package/src/types/sheet.ts +22 -1
  181. /package/dist/{vue → components/sheet}/style.d.ts +0 -0
  182. /package/dist/{vue → components/sheet}/style.js +0 -0
  183. /package/dist/{vue → components/sheet}/style2.css +0 -0
  184. /package/dist/{vue → components/sheet}/use-formula-suggest.js +0 -0
  185. /package/src/{vue → components/sheet}/__test__/import-file.test.ts +0 -0
  186. /package/src/{vue → components/sheet}/__test__/insert-count-menu-item.test.ts +0 -0
  187. /package/src/{vue → components/sheet}/__test__/use-formula-ref-select.test.ts +0 -0
  188. /package/src/{vue → components/sheet}/__test__/use-formula-suggest.test.ts +0 -0
  189. /package/src/{vue → components/sheet}/formula-suggest-list.vue +0 -0
  190. /package/src/{vue → components/sheet}/import-file.ts +0 -0
  191. /package/src/{vue → components/sheet}/index.ts +0 -0
  192. /package/src/{vue → components/sheet}/insert-count-menu-item.vue +0 -0
  193. /package/src/{vue → components/sheet}/parsing.ts +0 -0
  194. /package/src/{vue → components/sheet}/popups/border-preset-glyph.vue +0 -0
  195. /package/src/{vue → components/sheet}/popups/import.worker.ts +0 -0
  196. /package/src/{vue → components/sheet}/sheet-tabs.vue +0 -0
  197. /package/src/{vue → components/sheet}/style.scss +0 -0
  198. /package/src/{vue → components/sheet}/style.ts +0 -0
  199. /package/src/{vue → components/sheet}/use-formula-ref-select.ts +0 -0
  200. /package/src/{vue → components/sheet}/use-formula-suggest.ts +0 -0
  201. /package/src/{vue → components/sheet}/use-sheet-tabs-bar.ts +0 -0
  202. /package/src/{vue → components/sheet}/use-toolbar-scroll.ts +0 -0
@@ -0,0 +1,95 @@
1
+ import { rangeToHucre, styleToHucre } from "@veltra/sheet-core/core/io/export";
2
+ import { writeXlsx } from "hucre/xlsx";
3
+ //#region src/report/export-xlsx.ts
4
+ /** 像素 → Excel points */
5
+ function pxToPt(px) {
6
+ return px * .75;
7
+ }
8
+ /** VTable 像素列宽 → Excel 字符宽度(近似换算) */
9
+ function pxToExcelColWidth(px) {
10
+ return Math.max(1, Math.round((px - 5) / 7));
11
+ }
12
+ /** 从列宽条目构建 hucre ColumnDef */
13
+ function buildColumnDefs(colWidths) {
14
+ if (colWidths.length === 0) return [];
15
+ const maxCol = Math.max(...colWidths.map(([col]) => col));
16
+ const columns = Array.from({ length: maxCol + 1 }, () => ({}));
17
+ for (const [col, width] of colWidths) columns[col] = { width: pxToExcelColWidth(width) };
18
+ return columns;
19
+ }
20
+ /**
21
+ * 将已填充的 Sheet(Filled Report)导出为保真 XLSX(合并 / 样式 / 行高 / 列宽)。
22
+ * 条件样式颜色已在 renderReport 展开阶段打平进 StylePool(ADR-0001 决策 2)。
23
+ *
24
+ * 与 `exportWorkbookXlsx`(sheet-core)的差异:列宽未进 SheetSnapshot,
25
+ * 只能经 VTable 运行时读取,故这里接收显式列宽并写入 columns 定义。
26
+ */
27
+ async function exportFilledReportXlsx(sheet, colWidths) {
28
+ let maxRow = -1;
29
+ let maxCol = -1;
30
+ for (const [addr] of sheet.store.entries()) {
31
+ if (addr.row > maxRow) maxRow = addr.row;
32
+ if (addr.col > maxCol) maxCol = addr.col;
33
+ }
34
+ for (const [row] of sheet.getRowHeights()) if (row > maxRow) maxRow = row;
35
+ for (const [col] of colWidths) if (col > maxCol) maxCol = col;
36
+ const rows = maxRow < 0 ? [] : Array.from({ length: maxRow + 1 }, () => Array.from({ length: maxCol + 1 }, () => null));
37
+ const cells = /* @__PURE__ */ new Map();
38
+ for (const [addr, data] of sheet.store.entries()) {
39
+ const row = rows[addr.row];
40
+ const key = `${addr.row},${addr.col}`;
41
+ const cell = {};
42
+ if (data.s != null) {
43
+ const style = sheet.stylePool.get(data.s);
44
+ if (style) cell.style = styleToHucre(style);
45
+ }
46
+ if (data.f != null && data.f !== "") {
47
+ cell.formula = data.f;
48
+ if (data.v != null) cell.formulaResult = data.v;
49
+ row[addr.col] = data.v ?? null;
50
+ cells.set(key, cell);
51
+ continue;
52
+ }
53
+ if (data.t === "e") {
54
+ cell.value = data.v;
55
+ cell.type = "error";
56
+ row[addr.col] = null;
57
+ cells.set(key, cell);
58
+ continue;
59
+ }
60
+ if (data.t === "d") {
61
+ cell.value = data.v;
62
+ cell.type = "number";
63
+ cell.style = {
64
+ ...cell.style,
65
+ numFmt: "yyyy-mm-dd"
66
+ };
67
+ row[addr.col] = null;
68
+ cells.set(key, cell);
69
+ continue;
70
+ }
71
+ row[addr.col] = data.v ?? null;
72
+ if (Object.keys(cell).length > 0) cells.set(key, cell);
73
+ }
74
+ const writeSheet = {
75
+ name: sheet.name || "报表",
76
+ rows,
77
+ ...cells.size > 0 ? { cells } : {},
78
+ ...sheet.merges.size > 0 ? { merges: sheet.merges.getMerges().map((range) => rangeToHucre(range)) } : {},
79
+ ...colWidths.length > 0 ? { columns: buildColumnDefs(colWidths) } : {}
80
+ };
81
+ const frozen = sheet.frozen;
82
+ if (frozen.rows > 0 || frozen.cols > 0) writeSheet.freezePane = {
83
+ rows: frozen.rows,
84
+ columns: frozen.cols
85
+ };
86
+ const rowDefs = /* @__PURE__ */ new Map();
87
+ for (const [row, height] of sheet.getRowHeights()) rowDefs.set(row, { height: pxToPt(height) });
88
+ if (rowDefs.size > 0) writeSheet.rowDefs = rowDefs;
89
+ return writeXlsx({
90
+ sheets: [writeSheet],
91
+ activeSheet: 0
92
+ });
93
+ }
94
+ //#endregion
95
+ export { buildColumnDefs, exportFilledReportXlsx, pxToExcelColWidth };
@@ -0,0 +1,10 @@
1
+ import { ParamValues } from "./types.js";
2
+ //#region src/report/filter-bar.d.ts
3
+ /** 将运行时 date-range 参数值规范为 [from, to] 字符串元组 */
4
+ declare function parseDateRangeValue(raw: unknown): [string, string];
5
+ /** 将运行时 number 参数值规范为 UNumberInput 可接受的 number | undefined */
6
+ declare function resolveNumberParamValue(raw: unknown): number | undefined;
7
+ /** 合并单参数变更,保持其余参数值不变 */
8
+ declare function patchParamValues(values: ParamValues, id: string, value: unknown): ParamValues;
9
+ //#endregion
10
+ export { parseDateRangeValue, patchParamValues, resolveNumberParamValue };
@@ -0,0 +1,31 @@
1
+ //#region src/report/filter-bar.ts
2
+ function toParamString(value) {
3
+ if (value == null || value === "") return "";
4
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return String(value);
5
+ return "";
6
+ }
7
+ /** 将运行时 date-range 参数值规范为 [from, to] 字符串元组 */
8
+ function parseDateRangeValue(raw) {
9
+ if (Array.isArray(raw)) return [toParamString(raw[0]), toParamString(raw[1])];
10
+ if (raw && typeof raw === "object") {
11
+ const obj = raw;
12
+ return [toParamString(obj.from ?? obj.start), toParamString(obj.to ?? obj.end)];
13
+ }
14
+ return ["", ""];
15
+ }
16
+ /** 将运行时 number 参数值规范为 UNumberInput 可接受的 number | undefined */
17
+ function resolveNumberParamValue(raw) {
18
+ if (raw === "" || raw == null) return void 0;
19
+ if (typeof raw === "number" && Number.isFinite(raw)) return raw;
20
+ const parsed = Number(raw);
21
+ return Number.isFinite(parsed) ? parsed : void 0;
22
+ }
23
+ /** 合并单参数变更,保持其余参数值不变 */
24
+ function patchParamValues(values, id, value) {
25
+ return {
26
+ ...values,
27
+ [id]: value
28
+ };
29
+ }
30
+ //#endregion
31
+ export { parseDateRangeValue, patchParamValues, resolveNumberParamValue };
@@ -0,0 +1,12 @@
1
+ import { ConditionalOperator, ConditionalRule, DatasetCatalogItem, DatasetField, DatasetRecords, ParamValues, QueryParamDef, QueryParamOption, QueryParamType, ReportAggregate, ReportBinding, ReportExpand, ReportPreset, ReportSort } from "./types.js";
2
+ import { REPORT_META_NAMESPACE, applyReportPreset, createReportBinding, formatBindingPlaceholder, formatCellAddress, inferColParentCandidate, inferDropPreset, inferReportPreset, inferRowParentCandidate, isExpansionBandRow, isHorizontalExpandBinding, isVerticalExpandBinding, listColParentCandidates, listRowParentCandidates, parseCellAddress, presetBindingPatch, setBindingCatalog } from "./binding.js";
3
+ import { ConditionalEvalContext, evaluateCondition, evaluateConditionalStyle, resolveRuleCompareValue, toComparableNumber } from "./rules/evaluate.js";
4
+ import "./rules/index.js";
5
+ import { buildParamDefs, extractParamIds, resolveBoundDatasetParams } from "./params.js";
6
+ import { ReportColWidthEntry, buildColumnDefs, exportFilledReportXlsx, pxToExcelColWidth } from "./export-xlsx.js";
7
+ import { mapFilledColWidths } from "./render/builder.js";
8
+ import { renderReport, resolveFilledColWidths } from "./render/index.js";
9
+ import { ConnectionType, ConnectorError, CreateHttpConnectorOptions, DEFAULT_CONNECTION_PORTS, DataConnection, DataConnector, QueryResult, Result, createHttpConnector, resolvePortOnTypeChange } from "./connector.js";
10
+ import { IncompatibleTemplateVersionError, REPORT_TEMPLATE_VERSION, ReportDatasetDef, ReportTemplate, assertCompatibleTemplateVersion, createReportTemplate, fetchTemplateRecords, getBoundDatasetIds, getTemplateDatasets, resolveParamDefaults, resolveTemplateParams } from "./template.js";
11
+ import { parseDateRangeValue, patchParamValues, resolveNumberParamValue } from "./filter-bar.js";
12
+ export { type ConditionalEvalContext, ConditionalOperator, ConditionalRule, ConnectionType, ConnectorError, CreateHttpConnectorOptions, DEFAULT_CONNECTION_PORTS, DataConnection, DataConnector, DatasetCatalogItem, DatasetField, DatasetRecords, IncompatibleTemplateVersionError, ParamValues, QueryParamDef, QueryParamOption, QueryParamType, QueryResult, REPORT_META_NAMESPACE, REPORT_TEMPLATE_VERSION, ReportAggregate, ReportBinding, ReportColWidthEntry, ReportDatasetDef, ReportExpand, ReportPreset, ReportSort, ReportTemplate, Result, applyReportPreset, assertCompatibleTemplateVersion, buildColumnDefs, buildParamDefs, createHttpConnector, createReportBinding, createReportTemplate, evaluateCondition, evaluateConditionalStyle, exportFilledReportXlsx, extractParamIds, fetchTemplateRecords, formatBindingPlaceholder, formatCellAddress, getBoundDatasetIds, getTemplateDatasets, inferColParentCandidate, inferDropPreset, inferReportPreset, inferRowParentCandidate, isExpansionBandRow, isHorizontalExpandBinding, isVerticalExpandBinding, listColParentCandidates, listRowParentCandidates, mapFilledColWidths, parseCellAddress, parseDateRangeValue, patchParamValues, presetBindingPatch, pxToExcelColWidth, renderReport, resolveBoundDatasetParams, resolveFilledColWidths, resolveNumberParamValue, resolveParamDefaults, resolvePortOnTypeChange, resolveRuleCompareValue, resolveTemplateParams, setBindingCatalog, toComparableNumber };
@@ -0,0 +1,13 @@
1
+ import { QueryParamDef } from "./types.js";
2
+ //#region src/report/params.d.ts
3
+ /** 从 SQL 提取 `${param}` 占位符 id(ADR-0002 决策 2:前端纯函数) */
4
+ declare function extractParamIds(sql: string): string[];
5
+ /**
6
+ * 从 SQL 构建查询参数定义:提取 `${param}` 占位符 + 上下文类型推断,
7
+ * 再叠加数据集编辑器的元数据覆盖(label / 类型 / 默认值 / 选项)。
8
+ */
9
+ declare function buildParamDefs(sql: string, overrides?: Record<string, Partial<Omit<QueryParamDef, 'id'>>>): QueryParamDef[];
10
+ /** 按绑定的数据集 id 合并查询参数(同名参数先见为准) */
11
+ declare function resolveBoundDatasetParams(queryParams: QueryParamDef[], boundDatasetIds: readonly string[], getDatasetParams: (datasetId: string) => QueryParamDef[]): QueryParamDef[];
12
+ //#endregion
13
+ export { buildParamDefs, extractParamIds, resolveBoundDatasetParams };
@@ -0,0 +1,61 @@
1
+ //#region src/report/params.ts
2
+ /** 从 SQL 提取 `${param}` 占位符 id(ADR-0002 决策 2:前端纯函数) */
3
+ function extractParamIds(sql) {
4
+ const ids = [];
5
+ const re = /\$\{([^}]+)\}/g;
6
+ let match;
7
+ while ((match = re.exec(sql)) !== null) {
8
+ const id = match[1].trim();
9
+ if (id && !ids.includes(id)) ids.push(id);
10
+ }
11
+ return ids;
12
+ }
13
+ function escapeRegExp(value) {
14
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
15
+ }
16
+ /** 从 SQL 上下文推断参数控件类型(BETWEEN/LIKE/数值比较) */
17
+ function inferParamTypeFromSql(sql, paramId) {
18
+ if (new RegExp(`\\bBETWEEN\\s+\\$\\{${escapeRegExp(paramId)}\\}(?!\\s+AND)`, "i").test(sql)) return "date-range";
19
+ const pairMatch = new RegExp(`\\bBETWEEN\\s+\\$\\{${escapeRegExp(paramId)}\\}\\s+AND\\s+\\$\\{([^}]+)\\}`, "i").exec(sql);
20
+ if (pairMatch && pairMatch[1].trim() !== paramId) return "date";
21
+ if (new RegExp(`\\bLIKE\\s+\\$\\{${escapeRegExp(paramId)}\\}`, "i").test(sql)) return "text";
22
+ if (new RegExp(`[<>=]+\\s+\\$\\{${escapeRegExp(paramId)}\\}|\\$\\{${escapeRegExp(paramId)}\\}\\s*[<>=]+`, "i").test(sql)) return "number";
23
+ return "text";
24
+ }
25
+ function defaultValueForType(type) {
26
+ switch (type) {
27
+ case "number": return 0;
28
+ case "date-range": return ["", ""];
29
+ case "select": return "";
30
+ default: return "";
31
+ }
32
+ }
33
+ /**
34
+ * 从 SQL 构建查询参数定义:提取 `${param}` 占位符 + 上下文类型推断,
35
+ * 再叠加数据集编辑器的元数据覆盖(label / 类型 / 默认值 / 选项)。
36
+ */
37
+ function buildParamDefs(sql, overrides) {
38
+ return extractParamIds(sql).map((id) => {
39
+ const inferred = inferParamTypeFromSql(sql, id);
40
+ const override = overrides?.[id];
41
+ return {
42
+ id,
43
+ label: override?.label ?? id,
44
+ type: override?.type ?? inferred,
45
+ defaultValue: override?.defaultValue ?? defaultValueForType(override?.type ?? inferred),
46
+ options: override?.options
47
+ };
48
+ });
49
+ }
50
+ /** 按绑定的数据集 id 合并查询参数(同名参数先见为准) */
51
+ function resolveBoundDatasetParams(queryParams, boundDatasetIds, getDatasetParams) {
52
+ const map = /* @__PURE__ */ new Map();
53
+ for (const datasetId of boundDatasetIds) {
54
+ const params = getDatasetParams(datasetId);
55
+ for (const param of params) if (!map.has(param.id)) map.set(param.id, param);
56
+ }
57
+ if (map.size > 0) return Array.from(map.values());
58
+ return queryParams;
59
+ }
60
+ //#endregion
61
+ export { buildParamDefs, extractParamIds, resolveBoundDatasetParams };
@@ -0,0 +1,157 @@
1
+ import { enumerateExpansionInstances } from "./coordinate.js";
2
+ //#region src/report/render/aggregate.ts
3
+ function filterRows(rows, filter) {
4
+ if (Object.keys(filter).length === 0) return rows;
5
+ return rows.filter((row) => Object.entries(filter).every(([field, value]) => row[field] === value));
6
+ }
7
+ /** 对数值集求聚合;`avg` 空集返回 `undefined`,`sum` 空集仍为 `0` */
8
+ function aggregateField(rows, field, aggregate) {
9
+ if (aggregate === "count") return rows.length;
10
+ if (aggregate === "list" || aggregate === "group") return rows[0]?.[field];
11
+ const numbers = rows.map((row) => row[field]).map((value) => typeof value === "number" ? value : Number(value)).filter((value) => Number.isFinite(value));
12
+ if (numbers.length === 0) {
13
+ if (aggregate === "avg") return void 0;
14
+ return 0;
15
+ }
16
+ const sum = numbers.reduce((acc, value) => acc + value, 0);
17
+ if (aggregate === "avg") return sum / numbers.length;
18
+ if (aggregate === "max") return Math.max(...numbers);
19
+ if (aggregate === "min") return Math.min(...numbers);
20
+ return sum;
21
+ }
22
+ function isRowExpanding(binding) {
23
+ return binding.expand === "down" && (binding.aggregate === "group" || binding.aggregate === "list");
24
+ }
25
+ function isColExpanding(binding) {
26
+ return binding.expand === "right" && (binding.aggregate === "group" || binding.aggregate === "list");
27
+ }
28
+ function rowExpandingAncestors(binding, index) {
29
+ const chain = [];
30
+ let current = binding.rowParent;
31
+ while (current) {
32
+ const parentBinding = index.bindingAt(current);
33
+ if (parentBinding) chain.unshift({
34
+ addr: current,
35
+ binding: parentBinding
36
+ });
37
+ current = parentBinding?.rowParent;
38
+ }
39
+ return chain.filter((item) => isRowExpanding(item.binding));
40
+ }
41
+ function colExpandingAncestors(binding, index) {
42
+ const chain = [];
43
+ let current = binding.colParent;
44
+ while (current) {
45
+ const parentBinding = index.bindingAt(current);
46
+ if (parentBinding) chain.unshift({
47
+ addr: current,
48
+ binding: parentBinding
49
+ });
50
+ current = parentBinding?.colParent;
51
+ }
52
+ return chain.filter((item) => isColExpanding(item.binding));
53
+ }
54
+ function mergeFilters(rowFilter, colFilter) {
55
+ return {
56
+ ...rowFilter,
57
+ ...colFilter
58
+ };
59
+ }
60
+ function resolveAncestorFilters(binding, placement, index, data) {
61
+ const rowFilter = {};
62
+ const colFilter = {};
63
+ let parentFilter = {};
64
+ const rowAncestors = rowExpandingAncestors(binding, index);
65
+ for (let i = 0; i < rowAncestors.length; i++) {
66
+ const ancestor = rowAncestors[i];
67
+ if (ancestor.binding.dataset !== binding.dataset) continue;
68
+ const instances = enumerateExpansionInstances(ancestor.binding, data, parentFilter);
69
+ const pathIndex = placement.rowPath[i];
70
+ if (pathIndex === void 0) continue;
71
+ const instance = instances[pathIndex];
72
+ if (!instance) continue;
73
+ Object.assign(rowFilter, instance.filter);
74
+ parentFilter = instance.filter;
75
+ }
76
+ parentFilter = {};
77
+ const colAncestors = colExpandingAncestors(binding, index);
78
+ for (let i = 0; i < colAncestors.length; i++) {
79
+ const ancestor = colAncestors[i];
80
+ if (ancestor.binding.dataset !== binding.dataset) continue;
81
+ const instances = enumerateExpansionInstances(ancestor.binding, data, parentFilter);
82
+ const pathIndex = placement.colPath[i];
83
+ if (pathIndex === void 0) continue;
84
+ const instance = instances[pathIndex];
85
+ if (!instance) continue;
86
+ Object.assign(colFilter, instance.filter);
87
+ parentFilter = instance.filter;
88
+ }
89
+ return mergeFilters(rowFilter, colFilter);
90
+ }
91
+ function resolveOwnGroupValue(binding, placement, index, data) {
92
+ const rowAncestors = rowExpandingAncestors(binding, index);
93
+ const colAncestors = colExpandingAncestors(binding, index);
94
+ let parentFilter = {};
95
+ for (let i = 0; i < rowAncestors.length; i++) {
96
+ const ancestor = rowAncestors[i];
97
+ if (ancestor.binding.dataset !== binding.dataset) continue;
98
+ const instances = enumerateExpansionInstances(ancestor.binding, data, parentFilter);
99
+ const pathIndex = placement.rowPath[i];
100
+ if (pathIndex === void 0) continue;
101
+ const instance = instances[pathIndex];
102
+ if (instance) parentFilter = instance.filter;
103
+ }
104
+ for (let i = 0; i < colAncestors.length; i++) {
105
+ const ancestor = colAncestors[i];
106
+ if (ancestor.binding.dataset !== binding.dataset) continue;
107
+ const instances = enumerateExpansionInstances(ancestor.binding, data, parentFilter);
108
+ const pathIndex = placement.colPath[i];
109
+ if (pathIndex === void 0) continue;
110
+ const instance = instances[pathIndex];
111
+ if (instance) parentFilter = instance.filter;
112
+ }
113
+ const instances = enumerateExpansionInstances(binding, data, parentFilter);
114
+ const pathIndex = isRowExpanding(binding) ? placement.rowPath.at(-1) : placement.colPath.at(-1);
115
+ if (pathIndex === void 0) return void 0;
116
+ return instances[pathIndex]?.value;
117
+ }
118
+ /** 按分组字段建索引,避免交叉展开重复 filterRows */
119
+ var AggregateIndex = class {
120
+ datasets = /* @__PURE__ */ new Map();
121
+ filterCache = /* @__PURE__ */ new Map();
122
+ constructor(data) {
123
+ for (const [datasetId, rows] of Object.entries(data)) this.datasets.set(datasetId, rows);
124
+ }
125
+ rowsFor(dataset, filter) {
126
+ const cacheKey = `${dataset}:${JSON.stringify(filter)}`;
127
+ const cached = this.filterCache.get(cacheKey);
128
+ if (cached) return cached;
129
+ const rows = filterRows(this.datasets.get(dataset) ?? [], filter);
130
+ this.filterCache.set(cacheKey, rows);
131
+ return rows;
132
+ }
133
+ aggregate(dataset, filter, field, aggregate) {
134
+ const rows = this.rowsFor(dataset, filter);
135
+ if (aggregate === "list") return rows[0]?.[field];
136
+ return aggregateField(rows, field, aggregate);
137
+ }
138
+ };
139
+ /** 解析单个物理落点的绑定取值 */
140
+ function resolvePlacementValue(placement, index, data, aggregateIndex) {
141
+ const binding = placement.binding;
142
+ if (!binding) return void 0;
143
+ const filter = resolveAncestorFilters(binding, placement, index, data);
144
+ const rows = aggregateIndex.rowsFor(binding.dataset, filter);
145
+ if (binding.aggregate === "group") return filter[binding.field] ?? resolveOwnGroupValue(binding, placement, index, data);
146
+ if (binding.aggregate === "list") return rows[placement.listIndex]?.[binding.field];
147
+ return aggregateField(rows, binding.field, binding.aggregate);
148
+ }
149
+ /** 解析 `list` 明细落点对应的源数据行;非 list 绑定无单条记录上下文 */
150
+ function resolvePlacementRecord(placement, index, data, aggregateIndex) {
151
+ const binding = placement.binding;
152
+ if (!binding || binding.aggregate !== "list") return void 0;
153
+ const filter = resolveAncestorFilters(binding, placement, index, data);
154
+ return aggregateIndex.rowsFor(binding.dataset, filter)[placement.listIndex];
155
+ }
156
+ //#endregion
157
+ export { AggregateIndex, aggregateField, resolvePlacementRecord, resolvePlacementValue };
@@ -0,0 +1,12 @@
1
+ import "../types.js";
2
+ import { ReportColWidthEntry } from "../export-xlsx.js";
3
+ import { TemplateIndex } from "./template-index.js";
4
+ import { ExpansionLayout } from "./coordinate.js";
5
+ import { SheetSnapshot } from "@veltra/sheet-core";
6
+ //#region src/report/render/builder.d.ts
7
+ /**
8
+ * 将模板列宽映射到填充报表物理列:横向展开列继承列方向父格所在模板列宽。
9
+ */
10
+ declare function mapFilledColWidths(templateColWidths: ReadonlyArray<ReportColWidthEntry>, layout: ExpansionLayout, _index: TemplateIndex): ReportColWidthEntry[];
11
+ //#endregion
12
+ export { mapFilledColWidths };
@@ -0,0 +1,139 @@
1
+ import { physicalColSpan, physicalRowSpan } from "./coordinate.js";
2
+ import { AggregateIndex, resolvePlacementRecord, resolvePlacementValue } from "./aggregate.js";
3
+ import { StyleResolver } from "./style-resolver.js";
4
+ import { cellKey } from "@veltra/sheet-core";
5
+ //#region src/report/render/builder.ts
6
+ function toCellValue(value) {
7
+ if (value === null || value === void 0) return { v: "" };
8
+ if (typeof value === "number" && !Number.isNaN(value)) return {
9
+ v: value,
10
+ t: "n"
11
+ };
12
+ if (typeof value === "boolean") return {
13
+ v: value,
14
+ t: "b"
15
+ };
16
+ if (typeof value === "string") return {
17
+ v: value,
18
+ t: "s"
19
+ };
20
+ if (value instanceof Date) return {
21
+ v: value.toISOString().slice(0, 10),
22
+ t: "s"
23
+ };
24
+ return {
25
+ v: JSON.stringify(value),
26
+ t: "s"
27
+ };
28
+ }
29
+ function rangeCells(range) {
30
+ const cells = [];
31
+ for (let row = range.start.row; row <= range.end.row; row++) for (let col = range.start.col; col <= range.end.col; col++) cells.push({
32
+ row,
33
+ col
34
+ });
35
+ return cells;
36
+ }
37
+ function placementSourceValue(placement, template, index, data, aggregateIndex) {
38
+ if (placement.binding) return resolvePlacementValue(placement, index, data, aggregateIndex);
39
+ return index.cellAt(placement.logical)?.v;
40
+ }
41
+ function colWidthSourceLogicalCol(placement) {
42
+ const binding = placement.binding;
43
+ if (binding?.colParent) return binding.colParent.col;
44
+ return placement.logical.col;
45
+ }
46
+ /**
47
+ * 将模板列宽映射到填充报表物理列:横向展开列继承列方向父格所在模板列宽。
48
+ */
49
+ function mapFilledColWidths(templateColWidths, layout, _index) {
50
+ if (templateColWidths.length === 0 || layout.colCount === 0) return [];
51
+ const widthByTemplateCol = /* @__PURE__ */ new Map();
52
+ for (const [col, width] of templateColWidths) widthByTemplateCol.set(col, width);
53
+ const physicalWidths = /* @__PURE__ */ new Map();
54
+ for (const placement of layout.placements) {
55
+ const sourceCol = colWidthSourceLogicalCol(placement);
56
+ const width = widthByTemplateCol.get(sourceCol);
57
+ if (width === void 0) continue;
58
+ const startCol = placement.physical.start.col;
59
+ const endCol = placement.physical.end.col;
60
+ for (let col = startCol; col <= endCol; col++) physicalWidths.set(col, width);
61
+ }
62
+ return [...physicalWidths.entries()].sort((a, b) => a[0] - b[0]);
63
+ }
64
+ function placementEvalContext(placement, value, template, index, data, aggregateIndex) {
65
+ const binding = placement.binding;
66
+ return {
67
+ cellValue: value,
68
+ bindingField: binding?.field ?? "",
69
+ record: binding ? resolvePlacementRecord(placement, index, data, aggregateIndex) : void 0
70
+ };
71
+ }
72
+ function collectRowConditionalStyles(layout, template, index, data, styles) {
73
+ const aggregateIndex = new AggregateIndex(data);
74
+ for (const placement of layout.placements) {
75
+ const binding = placement.binding;
76
+ if (!binding?.conditionalRules?.some((rule) => rule.scope === "row")) continue;
77
+ const ctx = placementEvalContext(placement, placementSourceValue(placement, template, index, data, aggregateIndex), template, index, data, aggregateIndex);
78
+ for (let row = placement.physical.start.row; row <= placement.physical.end.row; row++) styles.collectRowStyle(row, ctx, binding.conditionalRules);
79
+ }
80
+ }
81
+ /** 由扩展坐标布局组装 Filled Report 快照 */
82
+ function buildFilledReport(template, index, layout, data) {
83
+ const styles = new StyleResolver(template);
84
+ collectRowConditionalStyles(layout, template, index, data, styles);
85
+ const aggregateIndex = new AggregateIndex(data);
86
+ const cells = [];
87
+ const merges = [...layout.mappedMerges];
88
+ const mergeKeys = new Set(merges.map((m) => cellKey(m.start)));
89
+ const pushMerge = (range) => {
90
+ const key = cellKey(range.start);
91
+ if (mergeKeys.has(key)) return;
92
+ mergeKeys.add(key);
93
+ merges.push(range);
94
+ };
95
+ const resolveStyleId = (placement, templateRow, templateCol, value, physicalRow) => {
96
+ const binding = placement.binding;
97
+ const ctx = placementEvalContext(placement, value, template, index, data, aggregateIndex);
98
+ const baseStyleId = binding ? styles.resolveCell(templateRow, templateCol, ctx, binding.conditionalRules) : styles.resolveStatic(templateRow, templateCol);
99
+ return styles.mergeRowStyle(baseStyleId, physicalRow);
100
+ };
101
+ for (const placement of layout.placements) {
102
+ const value = placementSourceValue(placement, template, index, data, aggregateIndex);
103
+ const { row: templateRow, col: templateCol } = placement.logical;
104
+ const rowSpan = physicalRowSpan(placement);
105
+ const colSpan = physicalColSpan(placement);
106
+ if (placement.mergeSpan && (rowSpan > 1 || colSpan > 1)) {
107
+ const item = {
108
+ row: placement.physical.start.row,
109
+ col: placement.physical.start.col,
110
+ ...toCellValue(value)
111
+ };
112
+ const styleId = resolveStyleId(placement, templateRow, templateCol, value, placement.physical.start.row);
113
+ if (styleId !== void 0) item.s = styleId;
114
+ cells.push(item);
115
+ if (rowSpan > 1 || colSpan > 1) pushMerge(placement.physical);
116
+ continue;
117
+ }
118
+ for (const pos of rangeCells(placement.physical)) {
119
+ const item = {
120
+ row: pos.row,
121
+ col: pos.col,
122
+ ...toCellValue(value)
123
+ };
124
+ const styleId = resolveStyleId(placement, templateRow, templateCol, value, pos.row);
125
+ if (styleId !== void 0) item.s = styleId;
126
+ cells.push(item);
127
+ }
128
+ }
129
+ return {
130
+ cells,
131
+ styles: styles.snapshot(),
132
+ merges,
133
+ frozen: template.frozen,
134
+ rows: layout.rowCount,
135
+ cols: Math.max(layout.colCount, template.cols)
136
+ };
137
+ }
138
+ //#endregion
139
+ export { buildFilledReport, mapFilledColWidths };
@@ -0,0 +1,25 @@
1
+ import { ReportBinding } from "../types.js";
2
+ import "./template-index.js";
3
+ import { CellAddress, CellRange } from "@veltra/sheet-core";
4
+ //#region src/report/render/coordinate.d.ts
5
+ /** 逻辑格 → 物理区间映射项(纯几何,不含取值) */
6
+ interface PhysicalPlacement {
7
+ logical: CellAddress;
8
+ physical: CellRange;
9
+ rowPath: readonly number[];
10
+ colPath: readonly number[];
11
+ mergeSpan: boolean;
12
+ binding?: ReportBinding;
13
+ /** `list` 明细实例下标;非 list 时为 0 */
14
+ listIndex: number;
15
+ }
16
+ /** 扩展坐标系计算结果 */
17
+ interface ExpansionLayout {
18
+ rowCount: number;
19
+ colCount: number;
20
+ placements: PhysicalPlacement[];
21
+ /** 模板合并区域映射到物理网格后的区间 */
22
+ mappedMerges: CellRange[];
23
+ }
24
+ //#endregion
25
+ export { ExpansionLayout, PhysicalPlacement };