@veltra/sheet 2.3.4 → 2.5.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 (129) hide show
  1. package/dist/index.d.ts +2 -17
  2. package/dist/index.js +2 -13
  3. package/dist/types/index.d.ts +1 -3
  4. package/package.json +5 -6
  5. package/src/index.ts +1 -27
  6. package/src/types/index.ts +0 -2
  7. package/dist/components/report/binding-badge.js +0 -112
  8. package/dist/components/report/designer/cell-coords.js +0 -46
  9. package/dist/components/report/designer/col-widths.js +0 -29
  10. package/dist/components/report/designer/conditional-rules/helpers.js +0 -139
  11. package/dist/components/report/designer/drop-highlight-overlay.js +0 -76
  12. package/dist/components/report/designer/float-panel.js +0 -422
  13. package/dist/components/report/designer/role.js +0 -17
  14. package/dist/components/report/designer/rule-preview.js +0 -33
  15. package/dist/components/report/designer/rule-row.js +0 -253
  16. package/dist/components/report/designer/rules-dialog.js +0 -118
  17. package/dist/components/report/designer/topology-overlay.js +0 -122
  18. package/dist/components/report/designer/topology.js +0 -64
  19. package/dist/components/report/designer/use-grid-overlay.js +0 -75
  20. package/dist/components/report/designer-hub.js +0 -177
  21. package/dist/components/report/field-panel-helpers.js +0 -33
  22. package/dist/components/report/field-panel.js +0 -132
  23. package/dist/components/report/filter-bar.js +0 -74
  24. package/dist/components/report/hub-connection-form.js +0 -145
  25. package/dist/components/report/hub-dataset-editor.js +0 -409
  26. package/dist/components/report/preview-grid-size.js +0 -32
  27. package/dist/components/report/report-designer.js +0 -393
  28. package/dist/components/report/report-viewer.js +0 -124
  29. package/dist/components/report/style.d.ts +0 -17
  30. package/dist/components/report/style.js +0 -18
  31. package/dist/components/report/style2.css +0 -874
  32. package/dist/components/report/use-report-designer.js +0 -386
  33. package/dist/components/report/use-report-viewer.js +0 -55
  34. package/dist/report/binding.d.ts +0 -83
  35. package/dist/report/binding.js +0 -334
  36. package/dist/report/connector.d.ts +0 -66
  37. package/dist/report/connector.js +0 -159
  38. package/dist/report/export-xlsx.d.ts +0 -13
  39. package/dist/report/export-xlsx.js +0 -13
  40. package/dist/report/filter-bar.d.ts +0 -10
  41. package/dist/report/filter-bar.js +0 -31
  42. package/dist/report/index.d.ts +0 -12
  43. package/dist/report/params.d.ts +0 -13
  44. package/dist/report/params.js +0 -61
  45. package/dist/report/render/aggregate.js +0 -169
  46. package/dist/report/render/builder.d.ts +0 -12
  47. package/dist/report/render/builder.js +0 -139
  48. package/dist/report/render/coordinate.d.ts +0 -25
  49. package/dist/report/render/coordinate.js +0 -733
  50. package/dist/report/render/index.d.ts +0 -14
  51. package/dist/report/render/index.js +0 -21
  52. package/dist/report/render/style-resolver.js +0 -50
  53. package/dist/report/render/template-index.d.ts +0 -24
  54. package/dist/report/render/template-index.js +0 -137
  55. package/dist/report/rules/evaluate.d.ts +0 -25
  56. package/dist/report/rules/evaluate.js +0 -82
  57. package/dist/report/rules/index.d.ts +0 -2
  58. package/dist/report/template.d.ts +0 -63
  59. package/dist/report/template.js +0 -83
  60. package/dist/report/types.d.ts +0 -85
  61. package/dist/types/report-designer.d.ts +0 -38
  62. package/dist/types/report-viewer.d.ts +0 -38
  63. package/src/components/report/__test__/binding-badge.test.ts +0 -92
  64. package/src/components/report/__test__/conditional-rules-helpers.test.ts +0 -88
  65. package/src/components/report/__test__/field-panel-helpers.test.ts +0 -65
  66. package/src/components/report/__test__/float-panel-position.test.ts +0 -45
  67. package/src/components/report/__test__/preview-grid-size.test.ts +0 -63
  68. package/src/components/report/__test__/report-designer.test.ts +0 -464
  69. package/src/components/report/__test__/report-viewer.test.ts +0 -357
  70. package/src/components/report/__test__/topology.test.ts +0 -143
  71. package/src/components/report/__test__/use-report-designer.test.ts +0 -697
  72. package/src/components/report/binding-badge.ts +0 -117
  73. package/src/components/report/designer/cell-coords.ts +0 -95
  74. package/src/components/report/designer/col-widths.ts +0 -56
  75. package/src/components/report/designer/conditional-rules/helpers.ts +0 -189
  76. package/src/components/report/designer/drop-highlight-overlay.vue +0 -75
  77. package/src/components/report/designer/float-panel.vue +0 -432
  78. package/src/components/report/designer/role.ts +0 -32
  79. package/src/components/report/designer/rule-preview.vue +0 -40
  80. package/src/components/report/designer/rule-row.vue +0 -252
  81. package/src/components/report/designer/rules-dialog.vue +0 -110
  82. package/src/components/report/designer/topology-overlay.vue +0 -128
  83. package/src/components/report/designer/topology.ts +0 -124
  84. package/src/components/report/designer/use-grid-overlay.ts +0 -114
  85. package/src/components/report/designer-hub.vue +0 -198
  86. package/src/components/report/field-panel-helpers.ts +0 -44
  87. package/src/components/report/field-panel.vue +0 -136
  88. package/src/components/report/filter-bar.vue +0 -77
  89. package/src/components/report/hub-connection-form.vue +0 -124
  90. package/src/components/report/hub-dataset-editor.vue +0 -387
  91. package/src/components/report/index.ts +0 -2
  92. package/src/components/report/preview-grid-size.ts +0 -33
  93. package/src/components/report/report-designer.vue +0 -421
  94. package/src/components/report/report-viewer.vue +0 -136
  95. package/src/components/report/style-designer.scss +0 -587
  96. package/src/components/report/style-hub.scss +0 -292
  97. package/src/components/report/style-viewer.scss +0 -104
  98. package/src/components/report/style.scss +0 -3
  99. package/src/components/report/style.ts +0 -20
  100. package/src/components/report/use-report-designer.ts +0 -602
  101. package/src/components/report/use-report-viewer.ts +0 -88
  102. package/src/report/__test__/binding.test.ts +0 -320
  103. package/src/report/__test__/connector.test.ts +0 -239
  104. package/src/report/__test__/export-xlsx.test.ts +0 -96
  105. package/src/report/__test__/filter-bar.test.ts +0 -58
  106. package/src/report/__test__/params.test.ts +0 -156
  107. package/src/report/__test__/render.test.ts +0 -856
  108. package/src/report/__test__/rules.test.ts +0 -131
  109. package/src/report/__test__/template.test.ts +0 -366
  110. package/src/report/binding.ts +0 -474
  111. package/src/report/connector.ts +0 -206
  112. package/src/report/export-xlsx.ts +0 -15
  113. package/src/report/filter-bar.ts +0 -36
  114. package/src/report/index.ts +0 -13
  115. package/src/report/params.ts +0 -96
  116. package/src/report/render/__test__/aggregate.test.ts +0 -16
  117. package/src/report/render/__test__/coordinate.test.ts +0 -405
  118. package/src/report/render/aggregate.ts +0 -261
  119. package/src/report/render/builder.ts +0 -211
  120. package/src/report/render/coordinate.ts +0 -1239
  121. package/src/report/render/index.ts +0 -30
  122. package/src/report/render/style-resolver.ts +0 -68
  123. package/src/report/render/template-index.ts +0 -200
  124. package/src/report/rules/evaluate.ts +0 -113
  125. package/src/report/rules/index.ts +0 -7
  126. package/src/report/template.ts +0 -145
  127. package/src/report/types.ts +0 -96
  128. package/src/types/report-designer.ts +0 -38
  129. package/src/types/report-viewer.ts +0 -37
@@ -1,334 +0,0 @@
1
- import { formatAddress, parseAddress } from "@veltra/sheet-core";
2
- //#region src/report/binding.ts
3
- /** 字段 label 解析用的 catalog(由宿主注入) */
4
- let bindingCatalog = [];
5
- function setBindingCatalog(catalog) {
6
- bindingCatalog = catalog;
7
- }
8
- const REPORT_META_NAMESPACE = "report";
9
- const AGGREGATE_PLACEHOLDER_TAG = {
10
- list: "明细",
11
- group: "分组",
12
- sum: "求和",
13
- avg: "平均",
14
- count: "计数",
15
- max: "最大",
16
- min: "最小"
17
- };
18
- /** 预设 → 绑定字段补丁(父格除 grandTotal 外均保留推断值) */
19
- function presetBindingPatch(preset, options) {
20
- const expand = options?.transpose ? "right" : "down";
21
- switch (preset) {
22
- case "groupHeader": return {
23
- preset,
24
- expand,
25
- aggregate: "group"
26
- };
27
- case "detail": return {
28
- preset,
29
- expand,
30
- aggregate: "list"
31
- };
32
- case "subtotal": return {
33
- preset,
34
- expand: "none",
35
- aggregate: "sum"
36
- };
37
- case "grandTotal": return {
38
- preset,
39
- expand: "none",
40
- aggregate: "sum",
41
- rowParent: void 0,
42
- colParent: void 0
43
- };
44
- case "cross": return {
45
- preset,
46
- expand: "none",
47
- aggregate: "sum"
48
- };
49
- }
50
- }
51
- /** 将预设写入绑定(grandTotal 清空双父格;其余保留既有父格) */
52
- function applyReportPreset(binding, preset, options) {
53
- const patch = presetBindingPatch(preset, options);
54
- const next = {
55
- ...binding,
56
- ...patch
57
- };
58
- if (preset === "grandTotal") {
59
- delete next.rowParent;
60
- delete next.colParent;
61
- }
62
- return next;
63
- }
64
- function isVerticalExpandBinding(binding) {
65
- return binding.expand === "down" && (binding.aggregate === "group" || binding.aggregate === "list");
66
- }
67
- function isHorizontalExpandBinding(binding) {
68
- return binding.expand === "right" && (binding.aggregate === "group" || binding.aggregate === "list");
69
- }
70
- function isRowGroupBinding(binding) {
71
- return binding.expand === "down" && binding.aggregate === "group";
72
- }
73
- function isColGroupBinding(binding) {
74
- return binding.expand === "right" && binding.aggregate === "group";
75
- }
76
- function isReductionAggregate(aggregate) {
77
- return aggregate === "sum" || aggregate === "avg" || aggregate === "count" || aggregate === "max" || aggregate === "min";
78
- }
79
- /** 小计 / 汇总 / 交叉格的父格候选只列分组头 */
80
- function prefersGroupParent(binding) {
81
- if (binding.preset === "subtotal" || binding.preset === "grandTotal" || binding.preset === "cross") return true;
82
- return binding.expand === "none" && isReductionAggregate(binding.aggregate);
83
- }
84
- /** 当前 expand / aggregate 是否仍属于已写入的预设族(同族内改聚合不掉到「自定义」) */
85
- function presetStillApplies(binding) {
86
- const preset = binding.preset;
87
- if (!preset) return false;
88
- if (preset === "groupHeader") return binding.aggregate === "group" && (binding.expand === "down" || binding.expand === "right");
89
- if (preset === "detail") return binding.aggregate === "list" && (binding.expand === "down" || binding.expand === "right");
90
- return binding.expand === "none" && isReductionAggregate(binding.aggregate);
91
- }
92
- const DEFAULT_SCAN_COLS = 64;
93
- const DEFAULT_SCAN_ROWS = 64;
94
- /** 指定模板行是否含纵向扩展绑定(展开带行) */
95
- function isExpansionBandRow(row, getBindingAt, scanCols = DEFAULT_SCAN_COLS) {
96
- for (let col = 0; col < scanCols; col++) {
97
- const binding = getBindingAt({
98
- row,
99
- col
100
- });
101
- if (binding && isVerticalExpandBinding(binding)) return true;
102
- }
103
- return false;
104
- }
105
- /** 指定模板列是否含横向扩展绑定(展开带列) */
106
- function isExpansionBandCol(col, getBindingAt, scanRows = DEFAULT_SCAN_ROWS) {
107
- for (let row = 0; row < scanRows; row++) {
108
- const binding = getBindingAt({
109
- row,
110
- col
111
- });
112
- if (binding && isHorizontalExpandBinding(binding)) return true;
113
- }
114
- return false;
115
- }
116
- /** 落格时推断预设:默认明细;数值字段且位于展开带正下方或正右相邻 → 小计 */
117
- function inferDropPreset(addr, fieldType, getBindingAt) {
118
- if (fieldType !== "number") return "detail";
119
- if (addr.row > 0 && isExpansionBandRow(addr.row - 1, getBindingAt)) return "subtotal";
120
- if (addr.col > 0 && isExpansionBandCol(addr.col - 1, getBindingAt)) return "subtotal";
121
- return "detail";
122
- }
123
- /** 同数据集纵向扩展绑定格(行方向父格下拉候选) */
124
- function listRowParentCandidates(binding, entries, options) {
125
- const preferGroup = options?.preferGroup === true;
126
- const candidates = [];
127
- for (const entry of entries) {
128
- if (entry.binding.dataset !== binding.dataset) continue;
129
- if (preferGroup) {
130
- if (!isRowGroupBinding(entry.binding)) continue;
131
- } else if (!isVerticalExpandBinding(entry.binding)) continue;
132
- candidates.push(entry.addr);
133
- }
134
- return candidates;
135
- }
136
- /** 同数据集横向扩展绑定格(列方向父格下拉候选) */
137
- function listColParentCandidates(binding, entries, options) {
138
- const preferGroup = options?.preferGroup === true;
139
- const candidates = [];
140
- for (const entry of entries) {
141
- if (entry.binding.dataset !== binding.dataset) continue;
142
- if (preferGroup) {
143
- if (!isColGroupBinding(entry.binding)) continue;
144
- } else if (!isHorizontalExpandBinding(entry.binding)) continue;
145
- candidates.push(entry.addr);
146
- }
147
- return candidates;
148
- }
149
- function betterHit(current, next) {
150
- if (!current) return true;
151
- if (next.distance !== current.distance) return next.distance < current.distance;
152
- return next.addr.col + next.addr.row < current.addr.col + current.addr.row;
153
- }
154
- function pickExpandHit(hits, preferGroup) {
155
- let group = null;
156
- let expand = null;
157
- for (const hit of hits) {
158
- if (hit.group && betterHit(group, hit)) group = hit;
159
- if (betterHit(expand, hit)) expand = hit;
160
- }
161
- if (preferGroup) return group?.addr ?? null;
162
- return group?.addr ?? expand?.addr ?? null;
163
- }
164
- function scanVerticalOnRow(row, originCol, colStart, colEnd, getBindingAt) {
165
- const hits = [];
166
- for (let col = colStart; col < colEnd; col++) {
167
- const binding = getBindingAt({
168
- row,
169
- col
170
- });
171
- if (!binding || !isVerticalExpandBinding(binding)) continue;
172
- hits.push({
173
- addr: {
174
- row,
175
- col
176
- },
177
- group: isRowGroupBinding(binding),
178
- distance: Math.abs(col - originCol)
179
- });
180
- }
181
- return hits;
182
- }
183
- function scanHorizontalOnCol(col, originRow, rowStart, rowEnd, getBindingAt) {
184
- const hits = [];
185
- for (let row = rowStart; row < rowEnd; row++) {
186
- const binding = getBindingAt({
187
- row,
188
- col
189
- });
190
- if (!binding || !isHorizontalExpandBinding(binding)) continue;
191
- hits.push({
192
- addr: {
193
- row,
194
- col
195
- },
196
- group: isColGroupBinding(binding),
197
- distance: Math.abs(row - originRow)
198
- });
199
- }
200
- return hits;
201
- }
202
- /**
203
- * 行方向父格推断:
204
- * 1. 同行向左:先找分组头,否则最近纵向扩展格
205
- * 2. 上方各行整行扫描:每行先找分组头,再退回任意纵向扩展格
206
- * 小计(preferGroup)禁止把明细当成父格
207
- */
208
- function inferRowParentCandidate(addr, getBindingAt, options) {
209
- const preferGroup = options?.preferGroup === true;
210
- const sameRow = pickExpandHit(scanVerticalOnRow(addr.row, addr.col, 0, addr.col, getBindingAt), preferGroup);
211
- if (sameRow) return sameRow;
212
- for (let row = addr.row - 1; row >= 0; row--) {
213
- const found = pickExpandHit(scanVerticalOnRow(row, addr.col, 0, DEFAULT_SCAN_COLS, getBindingAt), preferGroup);
214
- if (found) return found;
215
- }
216
- return null;
217
- }
218
- /**
219
- * 列方向父格推断(与行方向对称):
220
- * 1. 同列向上:先找列分组头,否则最近横向扩展格
221
- * 2. 左侧各列整列扫描:每列先找列分组头
222
- * 列小计(preferGroup)禁止把交叉格/明细当成列父格
223
- */
224
- function inferColParentCandidate(addr, getBindingAt, options) {
225
- const preferGroup = options?.preferGroup === true;
226
- const sameCol = pickExpandHit(scanHorizontalOnCol(addr.col, addr.row, 0, addr.row, getBindingAt), preferGroup);
227
- if (sameCol) return sameCol;
228
- for (let col = addr.col - 1; col >= 0; col--) {
229
- const found = pickExpandHit(scanHorizontalOnCol(col, addr.row, 0, DEFAULT_SCAN_ROWS, getBindingAt), preferGroup);
230
- if (found) return found;
231
- }
232
- return null;
233
- }
234
- function suggestsColumnSubtotal(above) {
235
- if (!above) return false;
236
- return isHorizontalExpandBinding(above) || !!above.colParent || above.preset === "cross";
237
- }
238
- function suggestsRowSubtotal(left) {
239
- if (!left) return false;
240
- return isVerticalExpandBinding(left) || !!left.rowParent || left.preset === "cross";
241
- }
242
- /**
243
- * 按预设写入落格父格:明细/分组/交叉双方向推断;小计按「下方行小计 / 右侧列小计」只挂对应轴。
244
- */
245
- function inferParentsForPreset(addr, preset, getBindingAt) {
246
- if (preset === "grandTotal") return {};
247
- const preferGroup = preset === "subtotal" || preset === "cross";
248
- const rowParent = inferRowParentCandidate(addr, getBindingAt, { preferGroup }) ?? void 0;
249
- const colParent = inferColParentCandidate(addr, getBindingAt, { preferGroup }) ?? void 0;
250
- if (preset !== "subtotal") return {
251
- ...rowParent ? { rowParent } : {},
252
- ...colParent ? { colParent } : {}
253
- };
254
- const above = addr.row > 0 ? getBindingAt({
255
- row: addr.row - 1,
256
- col: addr.col
257
- }) : void 0;
258
- const left = addr.col > 0 ? getBindingAt({
259
- row: addr.row,
260
- col: addr.col - 1
261
- }) : void 0;
262
- const belowBand = addr.row > 0 && isExpansionBandRow(addr.row - 1, getBindingAt);
263
- const rightOfBand = addr.col > 0 && isExpansionBandCol(addr.col - 1, getBindingAt);
264
- const columnSubtotal = suggestsColumnSubtotal(above) || rightOfBand && !suggestsRowSubtotal(left);
265
- const rowSubtotal = suggestsRowSubtotal(left) || belowBand && !columnSubtotal;
266
- const result = {};
267
- if (rowSubtotal && rowParent) result.rowParent = rowParent;
268
- if (columnSubtotal && colParent) result.colParent = colParent;
269
- if (!rowSubtotal && !columnSubtotal) {
270
- if (belowBand && rowParent) result.rowParent = rowParent;
271
- else if (rightOfBand && colParent) result.colParent = colParent;
272
- else {
273
- if (rowParent) result.rowParent = rowParent;
274
- if (colParent) result.colParent = colParent;
275
- }
276
- }
277
- return result;
278
- }
279
- /** 从绑定字段推断预设;不匹配任何预设时返回 null(自定义) */
280
- function inferReportPreset(binding) {
281
- if (binding.preset) return binding.preset;
282
- if (binding.expand === "none" && isReductionAggregate(binding.aggregate)) {
283
- if (binding.rowParent && binding.colParent) return "cross";
284
- if (binding.rowParent || binding.colParent) return "subtotal";
285
- return "grandTotal";
286
- }
287
- if (binding.aggregate === "group" && (binding.expand === "down" || binding.expand === "right")) return "groupHeader";
288
- if (binding.aggregate === "list" && (binding.expand === "down" || binding.expand === "right")) return "detail";
289
- return null;
290
- }
291
- /** 默认明细 + 纵向扩展 */
292
- function createReportBinding(dataset, fieldName) {
293
- return {
294
- dataset: dataset.id,
295
- field: fieldName,
296
- aggregate: "list",
297
- expand: "down",
298
- preset: "detail",
299
- sort: "none",
300
- conditionalRules: []
301
- };
302
- }
303
- /** 设计地址 → A1 标签(支持多字母列) */
304
- function formatCellAddress(addr) {
305
- return formatAddress(addr);
306
- }
307
- /** A1 标签 → 设计地址;非法输入返回 null */
308
- function parseCellAddress(label) {
309
- return parseAddress(label);
310
- }
311
- /** 解析字段中文标签(找不到时回退字段名);可传入报表配置中的 label */
312
- function resolveFieldLabel(datasetId, fieldName, resolveLabel) {
313
- const override = resolveLabel?.(datasetId, fieldName);
314
- if (override) return override;
315
- return (bindingCatalog.find((d) => d.id === datasetId)?.fields.find((f) => f.name === fieldName))?.label ?? fieldName;
316
- }
317
- /** Binding Placeholder 分段文案(聚合标签 + 字段标签),供徽章分色渲染等场景使用 */
318
- function formatBindingPlaceholderParts(binding, resolveLabel) {
319
- return {
320
- tag: AGGREGATE_PLACEHOLDER_TAG[binding.aggregate],
321
- label: resolveFieldLabel(binding.dataset, binding.field, resolveLabel)
322
- };
323
- }
324
- /** Binding Placeholder 中文可读文案(如「分组 · 客户」) */
325
- function formatBindingPlaceholder(binding, resolveLabel) {
326
- const { tag, label } = formatBindingPlaceholderParts(binding, resolveLabel);
327
- return `${tag} · ${label}`;
328
- }
329
- /** 父格下拉候选文案(如「分组 · 客户 (A2)」) */
330
- function formatParentCandidateLabel(addr, binding, resolveLabel) {
331
- return `${formatBindingPlaceholder(binding, resolveLabel)} (${formatCellAddress(addr)})`;
332
- }
333
- //#endregion
334
- export { REPORT_META_NAMESPACE, applyReportPreset, createReportBinding, formatBindingPlaceholder, formatBindingPlaceholderParts, formatCellAddress, formatParentCandidateLabel, inferColParentCandidate, inferDropPreset, inferParentsForPreset, inferReportPreset, inferRowParentCandidate, isColGroupBinding, isExpansionBandCol, isExpansionBandRow, isHorizontalExpandBinding, isReductionAggregate, isRowGroupBinding, isVerticalExpandBinding, listColParentCandidates, listRowParentCandidates, parseCellAddress, prefersGroupParent, presetBindingPatch, presetStillApplies, setBindingCatalog };
@@ -1,66 +0,0 @@
1
- import { DatasetField, ParamValues } from "./types.js";
2
- //#region src/report/connector.d.ts
3
- /** 数据连接类型(ADR-0003 决策 3:收敛为 MySQL / PostgreSQL) */
4
- type ConnectionType = 'mysql' | 'postgresql';
5
- /** 各连接类型的默认端口 */
6
- declare const DEFAULT_CONNECTION_PORTS: Record<ConnectionType, number>;
7
- /**
8
- * 切换连接类型时解析端口:若当前端口仍是上一类型的默认值(或 0),则切到新类型默认端口;
9
- * 用户已自定义的端口保持不变。
10
- */
11
- declare function resolvePortOnTypeChange(prevType: ConnectionType, nextType: ConnectionType, currentPort: number): number;
12
- /**
13
- * 数据连接(纯序列化对象,仅驻留内存)。
14
- * 凭据持久化与安全存储由下游负责(ADR-0003 决策 4)。
15
- */
16
- interface DataConnection {
17
- id: string;
18
- label: string;
19
- type: ConnectionType;
20
- host: string;
21
- port: number;
22
- database: string;
23
- username: string;
24
- password: string;
25
- }
26
- /** 业务错误(`200 + { ok: false, error }`)或客户端传输层错误 */
27
- interface ConnectorError {
28
- code: string;
29
- message: string;
30
- }
31
- /** 统一结果:成功携带 data;失败携带 error(连接器不抛异常,调用方只处理一条错误路径) */
32
- type Result<T> = {
33
- ok: true;
34
- data: T;
35
- } | {
36
- ok: false;
37
- error: ConnectorError;
38
- };
39
- /** query 成功结果:字段 schema + 行记录(契约 `{ fields, rows }` 归一化后) */
40
- interface QueryResult {
41
- fields: DatasetField[];
42
- rows: Record<string, unknown>[];
43
- }
44
- /**
45
- * 数据连接器(词汇表:Data Connector):test / describe / query 三方法镜像 HTTP 契约三端点。
46
- * 真实数据库访问由下游后端以任意语言实现(BYO)。
47
- */
48
- interface DataConnector {
49
- test(connection: DataConnection): Promise<Result<void>>;
50
- describe(connection: DataConnection, sql: string): Promise<Result<DatasetField[]>>;
51
- query(connection: DataConnection, sql: string, values: ParamValues): Promise<Result<QueryResult>>;
52
- }
53
- interface CreateHttpConnectorOptions {
54
- /** 契约端点前缀,如 `https://api.example.com/report`;三端点 = `{endpoint}/test|describe|query`(无版本段) */
55
- endpoint: string;
56
- }
57
- /**
58
- * 创建 HTTP 数据连接器:三方法对应 `POST {endpoint}/test|describe|query`。
59
- * - 请求体 JSON 序列化,`Content-Type: application/json`;
60
- * - 网络异常与非 2xx(传输层错误)折叠为 `{ ok: false, error }`,不抛异常;
61
- * - 业务错误(连接失败 / SQL 报错)由服务端以 `200 + { ok: false, error: { code, message } }` 返回并原样透传;
62
- * - `describe` / `query` 的 fields 归一化为内核 `DatasetField`(label 回退 name,type 缺省 string)。
63
- */
64
- declare function createHttpConnector({ endpoint }: CreateHttpConnectorOptions): DataConnector;
65
- //#endregion
66
- export { ConnectionType, ConnectorError, CreateHttpConnectorOptions, DEFAULT_CONNECTION_PORTS, DataConnection, DataConnector, QueryResult, Result, createHttpConnector, resolvePortOnTypeChange };
@@ -1,159 +0,0 @@
1
- //#region src/report/connector.ts
2
- /** 各连接类型的默认端口 */
3
- const DEFAULT_CONNECTION_PORTS = {
4
- mysql: 3306,
5
- postgresql: 5432
6
- };
7
- /**
8
- * 切换连接类型时解析端口:若当前端口仍是上一类型的默认值(或 0),则切到新类型默认端口;
9
- * 用户已自定义的端口保持不变。
10
- */
11
- function resolvePortOnTypeChange(prevType, nextType, currentPort) {
12
- if (prevType === nextType) return currentPort;
13
- if (currentPort === DEFAULT_CONNECTION_PORTS[prevType] || currentPort === 0) return DEFAULT_CONNECTION_PORTS[nextType];
14
- return currentPort;
15
- }
16
- /** 客户端错误:网络不可达 / 非 2xx / 响应不可解析(业务错误由服务端 200 透传) */
17
- function badResponse(message) {
18
- return {
19
- ok: false,
20
- error: {
21
- code: "BAD_RESPONSE",
22
- message
23
- }
24
- };
25
- }
26
- function isRecord(value) {
27
- return typeof value === "object" && value !== null && !Array.isArray(value);
28
- }
29
- function toConnectorError(value) {
30
- if (isRecord(value)) {
31
- const { code, message } = value;
32
- if (typeof code === "string" && typeof message === "string") return {
33
- code,
34
- message
35
- };
36
- }
37
- return {
38
- code: "SERVER_ERROR",
39
- message: "服务端返回未知错误"
40
- };
41
- }
42
- /** 契约字段 → 内核 DatasetField(label 缺省回退 name,type 缺省 string) */
43
- function normalizeField(field) {
44
- return {
45
- name: field.name,
46
- label: field.label ?? field.name,
47
- type: field.type ?? "string"
48
- };
49
- }
50
- /** 校验并归一化契约 fields;形状不合法返回 null */
51
- function normalizeFields(fields) {
52
- if (!Array.isArray(fields)) return null;
53
- const normalized = [];
54
- for (const field of fields) {
55
- if (!isRecord(field) || typeof field.name !== "string") return null;
56
- normalized.push(normalizeField(field));
57
- }
58
- return normalized;
59
- }
60
- /**
61
- * 创建 HTTP 数据连接器:三方法对应 `POST {endpoint}/test|describe|query`。
62
- * - 请求体 JSON 序列化,`Content-Type: application/json`;
63
- * - 网络异常与非 2xx(传输层错误)折叠为 `{ ok: false, error }`,不抛异常;
64
- * - 业务错误(连接失败 / SQL 报错)由服务端以 `200 + { ok: false, error: { code, message } }` 返回并原样透传;
65
- * - `describe` / `query` 的 fields 归一化为内核 `DatasetField`(label 回退 name,type 缺省 string)。
66
- */
67
- function createHttpConnector({ endpoint }) {
68
- async function postJson(path, body) {
69
- let response;
70
- try {
71
- response = await fetch(`${endpoint}${path}`, {
72
- method: "POST",
73
- headers: { "Content-Type": "application/json" },
74
- body: JSON.stringify(body)
75
- });
76
- } catch (error) {
77
- return {
78
- ok: false,
79
- error: {
80
- code: "NETWORK_ERROR",
81
- message: error instanceof Error ? error.message : String(error)
82
- }
83
- };
84
- }
85
- if (!response.ok) return {
86
- ok: false,
87
- error: {
88
- code: `HTTP_${response.status}`,
89
- message: `请求失败(HTTP ${response.status})`
90
- }
91
- };
92
- let payload;
93
- try {
94
- payload = await response.json();
95
- } catch {
96
- return badResponse("响应不是合法 JSON");
97
- }
98
- if (!isRecord(payload)) return badResponse("响应不是 JSON 对象");
99
- return {
100
- ok: true,
101
- data: payload
102
- };
103
- }
104
- return {
105
- async test(connection) {
106
- const result = await postJson("/test", { connection });
107
- if (!result.ok) return result;
108
- if (result.data.ok === true) return {
109
- ok: true,
110
- data: void 0
111
- };
112
- return {
113
- ok: false,
114
- error: toConnectorError(result.data.error)
115
- };
116
- },
117
- async describe(connection, sql) {
118
- const result = await postJson("/describe", {
119
- connection,
120
- sql
121
- });
122
- if (!result.ok) return result;
123
- if (result.data.ok !== true) return {
124
- ok: false,
125
- error: toConnectorError(result.data.error)
126
- };
127
- const fields = normalizeFields(result.data.fields);
128
- if (!fields) return badResponse("describe 响应缺少合法的 fields 数组");
129
- return {
130
- ok: true,
131
- data: fields
132
- };
133
- },
134
- async query(connection, sql, values) {
135
- const result = await postJson("/query", {
136
- connection,
137
- sql,
138
- values
139
- });
140
- if (!result.ok) return result;
141
- if (result.data.ok !== true) return {
142
- ok: false,
143
- error: toConnectorError(result.data.error)
144
- };
145
- const fields = normalizeFields(result.data.fields);
146
- if (!fields) return badResponse("query 响应缺少合法的 fields 数组");
147
- if (!Array.isArray(result.data.rows)) return badResponse("query 响应缺少 rows 数组");
148
- return {
149
- ok: true,
150
- data: {
151
- fields,
152
- rows: result.data.rows
153
- }
154
- };
155
- }
156
- };
157
- }
158
- //#endregion
159
- export { DEFAULT_CONNECTION_PORTS, createHttpConnector, resolvePortOnTypeChange };
@@ -1,13 +0,0 @@
1
- import { Sheet } from "@veltra/sheet-core";
2
- //#region src/report/export-xlsx.d.ts
3
- /** 列宽条目:模型列索引 → 像素宽(与 SheetSnapshot.colWidths 同构) */
4
- type ReportColWidthEntry = readonly [number, number];
5
- /**
6
- * 将已填充的 Sheet(Filled Report)导出为保真 XLSX(合并 / 样式 / 行高 / 列宽 / 浮动图)。
7
- * 组装与序列化委托 sheet-core `exportSheetXlsx`(与 `exportWorkbookXlsx` 同一套单表逻辑);
8
- * 条件样式颜色已在 renderReport 展开阶段打平进 StylePool(ADR-0001 决策 2)。
9
- * 列宽取自 sheet 模型(`getColWidths`)。
10
- */
11
- declare function exportFilledReportXlsx(sheet: Sheet): Promise<Uint8Array>;
12
- //#endregion
13
- export { ReportColWidthEntry, exportFilledReportXlsx };
@@ -1,13 +0,0 @@
1
- import { exportSheetXlsx } from "@veltra/sheet-core/core/io/export";
2
- //#region src/report/export-xlsx.ts
3
- /**
4
- * 将已填充的 Sheet(Filled Report)导出为保真 XLSX(合并 / 样式 / 行高 / 列宽 / 浮动图)。
5
- * 组装与序列化委托 sheet-core `exportSheetXlsx`(与 `exportWorkbookXlsx` 同一套单表逻辑);
6
- * 条件样式颜色已在 renderReport 展开阶段打平进 StylePool(ADR-0001 决策 2)。
7
- * 列宽取自 sheet 模型(`getColWidths`)。
8
- */
9
- function exportFilledReportXlsx(sheet) {
10
- return exportSheetXlsx(sheet, { fallbackName: "报表" });
11
- }
12
- //#endregion
13
- export { exportFilledReportXlsx };
@@ -1,10 +0,0 @@
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 };
@@ -1,31 +0,0 @@
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 };
@@ -1,12 +0,0 @@
1
- import { ConditionalOperator, ConditionalRule, DatasetCatalogItem, DatasetField, DatasetRecords, ParamValues, QueryParamDef, QueryParamOption, QueryParamType, ReportAggregate, ReportBinding, ReportExpand, ReportPreset, ReportSort } from "./types.js";
2
- import { InferParentOptions, ListParentCandidateOptions, REPORT_META_NAMESPACE, applyReportPreset, createReportBinding, formatBindingPlaceholder, formatBindingPlaceholderParts, formatCellAddress, formatParentCandidateLabel, inferColParentCandidate, inferDropPreset, inferParentsForPreset, inferReportPreset, inferRowParentCandidate, isColGroupBinding, isExpansionBandCol, isExpansionBandRow, isHorizontalExpandBinding, isReductionAggregate, isRowGroupBinding, isVerticalExpandBinding, listColParentCandidates, listRowParentCandidates, parseCellAddress, prefersGroupParent, presetBindingPatch, presetStillApplies, 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, exportFilledReportXlsx } 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, InferParentOptions, ListParentCandidateOptions, ParamValues, QueryParamDef, QueryParamOption, QueryParamType, QueryResult, REPORT_META_NAMESPACE, REPORT_TEMPLATE_VERSION, ReportAggregate, ReportBinding, ReportColWidthEntry, ReportDatasetDef, ReportExpand, ReportPreset, ReportSort, ReportTemplate, Result, applyReportPreset, assertCompatibleTemplateVersion, buildParamDefs, createHttpConnector, createReportBinding, createReportTemplate, evaluateCondition, evaluateConditionalStyle, exportFilledReportXlsx, extractParamIds, fetchTemplateRecords, formatBindingPlaceholder, formatBindingPlaceholderParts, formatCellAddress, formatParentCandidateLabel, getBoundDatasetIds, getTemplateDatasets, inferColParentCandidate, inferDropPreset, inferParentsForPreset, inferReportPreset, inferRowParentCandidate, isColGroupBinding, isExpansionBandCol, isExpansionBandRow, isHorizontalExpandBinding, isReductionAggregate, isRowGroupBinding, isVerticalExpandBinding, listColParentCandidates, listRowParentCandidates, mapFilledColWidths, parseCellAddress, parseDateRangeValue, patchParamValues, prefersGroupParent, presetBindingPatch, presetStillApplies, renderReport, resolveBoundDatasetParams, resolveFilledColWidths, resolveNumberParamValue, resolveParamDefaults, resolvePortOnTypeChange, resolveRuleCompareValue, resolveTemplateParams, setBindingCatalog, toComparableNumber };
@@ -1,13 +0,0 @@
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 };