@object-ui/plugin-report 7.0.0 → 7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @object-ui/plugin-report
2
2
 
3
+ ## 7.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8e7c1da]
8
+ - Updated dependencies [0caea33]
9
+ - Updated dependencies [d23db5c]
10
+ - @object-ui/i18n@7.2.0
11
+ - @object-ui/plugin-grid@7.2.0
12
+ - @object-ui/types@7.2.0
13
+ - @object-ui/components@7.2.0
14
+ - @object-ui/fields@7.2.0
15
+ - @object-ui/react@7.2.0
16
+ - @object-ui/core@7.2.0
17
+
18
+ ## 7.1.0
19
+
20
+ ### Patch Changes
21
+
22
+ - b419a7c: fix(studio): enable report authoring (create flow, chart render, dataset-aware inspector)
23
+
24
+ Found dogfooding report design in Studio as a business user — you could not create a report at all, plus several follow-on gaps.
25
+
26
+ - **Report create now uses the canvas + `ReportDefaultInspector`.** Only `object` was in `CREATE_MODE_CANVAS_TYPES`, so report-create fell back to a stale name-first form whose create-config (`objectName`, `columns: []`) predates the ADR-0021 dataset-bound model — saving failed server validation (_"a report needs `dataset` + `values`"_) with no field to fix it. Add `'report'` to the canvas set; the inspector exposes an auto-derived snake_case Name in create mode; fix the create-config (drop `objectName`/`columns`, seed `type: 'summary'` + `drilldown: true`).
27
+ - **Preserve `?package=` on post-create navigation** — it was dropped, so the editor reloaded a blank draft in the user's default package.
28
+ - **Render a report's embedded `chart`** in `DatasetReportRenderer` (authorable in Studio but never rendered) via the lazily-registered generic chart component; requests a non-animated render for export/background-tab safety.
29
+ - **Dedicated Chart panel in the inspector** — chart type + dataset-aware X-Axis (dimension) / Y-Axis (measure) dropdowns + title, replacing free-text axis fields and the vague "Chart: Required text value" validation.
30
+
31
+ - Updated dependencies [677f7ed]
32
+ - Updated dependencies [08c47da]
33
+ - Updated dependencies [a71be60]
34
+ - Updated dependencies [cb03bc3]
35
+ - @object-ui/types@7.1.0
36
+ - @object-ui/core@7.1.0
37
+ - @object-ui/react@7.1.0
38
+ - @object-ui/components@7.1.0
39
+ - @object-ui/fields@7.1.0
40
+ - @object-ui/plugin-grid@7.1.0
41
+ - @object-ui/i18n@7.1.0
42
+
3
43
  ## 7.0.0
4
44
 
5
45
  ### Major Changes
@@ -71,6 +71,8 @@ interface DatasetReportLike {
71
71
  filter?: Record<string, unknown>;
72
72
  /** Click-through to underlying records (default true). */
73
73
  drilldown?: boolean;
74
+ /** Embedded chart visualization (ADR-0021): type + xAxis/yAxis over the dataset. */
75
+ chart?: Record<string, unknown>;
74
76
  label?: unknown;
75
77
  description?: unknown;
76
78
  blocks?: DatasetReportLike[];
package/dist/index.js CHANGED
@@ -67,9 +67,9 @@ var j = ({ schema: t }) => {
67
67
  function M(e, t, n) {
68
68
  let r = e.fields || [], i = r.map((e) => e.label || e.name), a = t.map((e) => r.map((t) => {
69
69
  let n = e[t.name];
70
- return n = L(n), typeof n == "string" && (n.includes(",") || n.includes("\"") || n.includes("\n")) ? `"${n.replace(/"/g, "\"\"")}"` : n ?? "";
70
+ return n = R(n), typeof n == "string" && (n.includes(",") || n.includes("\"") || n.includes("\n")) ? `"${n.replace(/"/g, "\"\"")}"` : n ?? "";
71
71
  }));
72
- B([...n?.includeHeaders === !1 ? [] : [i.join(",")], ...a.map((e) => e.join(","))].join("\n"), n?.filename || `${e.title || "report"}.csv`, "text/csv");
72
+ V([...n?.includeHeaders === !1 ? [] : [i.join(",")], ...a.map((e) => e.join(","))].join("\n"), n?.filename || `${e.title || "report"}.csv`, "text/csv");
73
73
  }
74
74
  function ee(e, t, n) {
75
75
  let r = {
@@ -78,15 +78,15 @@ function ee(e, t, n) {
78
78
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
79
79
  data: t
80
80
  };
81
- B(JSON.stringify(r, null, 2), n?.filename || `${e.title || "report"}.json`, "application/json");
81
+ V(JSON.stringify(r, null, 2), n?.filename || `${e.title || "report"}.json`, "application/json");
82
82
  }
83
83
  function N(e, t, n) {
84
- let r = e.fields || [], i = z(n?.orientation), a = R(n?.pageSize);
85
- B(`<!DOCTYPE html>
84
+ let r = e.fields || [], i = B(n?.orientation), a = z(n?.pageSize);
85
+ V(`<!DOCTYPE html>
86
86
  <html>
87
87
  <head>
88
88
  <meta charset="utf-8">
89
- <title>${I(e.title || "Report")}</title>
89
+ <title>${L(e.title || "Report")}</title>
90
90
  <style>
91
91
  @page { size: ${a} ${i}; margin: 20mm; }
92
92
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
@@ -100,18 +100,18 @@ function N(e, t, n) {
100
100
  </style>
101
101
  </head>
102
102
  <body>
103
- <h1>${I(e.title || "Report")}</h1>
104
- ${e.description ? `<p class="description">${I(e.description)}</p>` : ""}
103
+ <h1>${L(e.title || "Report")}</h1>
104
+ ${e.description ? `<p class="description">${L(e.description)}</p>` : ""}
105
105
  <p class="meta">Generated: ${(/* @__PURE__ */ new Date()).toLocaleString()}</p>
106
106
  <table>
107
- <thead><tr>${r.map((e) => `<th>${I(e.label || e.name)}</th>`).join("")}</tr></thead>
108
- <tbody>${t.map((e) => `<tr>${r.map((t) => `<td>${I(String(e[t.name] ?? ""))}</td>`).join("")}</tr>`).join("")}</tbody>
107
+ <thead><tr>${r.map((e) => `<th>${L(e.label || e.name)}</th>`).join("")}</tr></thead>
108
+ <tbody>${t.map((e) => `<tr>${r.map((t) => `<td>${L(String(e[t.name] ?? ""))}</td>`).join("")}</tr>`).join("")}</tbody>
109
109
  </table>
110
110
  </body>
111
111
  </html>`, n?.filename || `${e.title || "report"}.html`, "text/html");
112
112
  }
113
113
  function P(e, t, n) {
114
- let r = e.fields || [], i = z(n?.orientation), a = R(n?.pageSize), o = window.open("", "_blank");
114
+ let r = e.fields || [], i = B(n?.orientation), a = z(n?.pageSize), o = window.open("", "_blank");
115
115
  if (!o) {
116
116
  N(e, t, {
117
117
  ...n,
@@ -124,7 +124,7 @@ function P(e, t, n) {
124
124
  <html>
125
125
  <head>
126
126
  <meta charset="utf-8">
127
- <title>${I(e.title || "Report")}</title>
127
+ <title>${L(e.title || "Report")}</title>
128
128
  <style>
129
129
  @page { size: ${a} ${i}; margin: 20mm; }
130
130
  @media print { .no-print { display: none; } }
@@ -139,26 +139,26 @@ function P(e, t, n) {
139
139
  </style>
140
140
  </head>
141
141
  <body>
142
- <h1>${I(e.title || "Report")}</h1>
143
- ${e.description ? `<p class="description">${I(e.description)}</p>` : ""}
142
+ <h1>${L(e.title || "Report")}</h1>
143
+ ${e.description ? `<p class="description">${L(e.description)}</p>` : ""}
144
144
  <p class="meta">Generated: ${(/* @__PURE__ */ new Date()).toLocaleString()}</p>
145
145
  <table>
146
- <thead><tr>${r.map((e) => `<th>${I(e.label || e.name)}</th>`).join("")}</tr></thead>
147
- <tbody>${t.map((e) => `<tr>${r.map((t) => `<td>${I(String(e[t.name] ?? ""))}</td>`).join("")}</tr>`).join("")}</tbody>
146
+ <thead><tr>${r.map((e) => `<th>${L(e.label || e.name)}</th>`).join("")}</tr></thead>
147
+ <tbody>${t.map((e) => `<tr>${r.map((t) => `<td>${L(String(e[t.name] ?? ""))}</td>`).join("")}</tr>`).join("")}</tbody>
148
148
  </table>
149
149
  </body>
150
150
  </html>`), o.document.close(), o.onload = () => {
151
151
  o.print();
152
152
  };
153
153
  }
154
- function te(e, t, n) {
154
+ function F(e, t, n) {
155
155
  let r = e.fields || [], i = r.map((e) => e.label || e.name), a = t.map((e) => r.map((t) => {
156
156
  let n = e[t.name];
157
- return n = L(n), typeof n == "string" && (n.includes(",") || n.includes("\"") || n.includes("\n") || n.includes(" ")) ? `"${n.replace(/"/g, "\"\"")}"` : n ?? "";
157
+ return n = R(n), typeof n == "string" && (n.includes(",") || n.includes("\"") || n.includes("\n") || n.includes(" ")) ? `"${n.replace(/"/g, "\"\"")}"` : n ?? "";
158
158
  }));
159
- B("" + [...n?.includeHeaders === !1 ? [] : [i.join(" ")], ...a.map((e) => e.join(" "))].join("\n"), n?.filename || `${e.title || "report"}.tsv`, "text/tab-separated-values");
159
+ V("" + [...n?.includeHeaders === !1 ? [] : [i.join(" ")], ...a.map((e) => e.join(" "))].join("\n"), n?.filename || `${e.title || "report"}.tsv`, "text/tab-separated-values");
160
160
  }
161
- function F(e, t, n, r) {
161
+ function I(e, t, n, r) {
162
162
  switch (e) {
163
163
  case "csv":
164
164
  M(t, n, r);
@@ -173,22 +173,22 @@ function F(e, t, n, r) {
173
173
  P(t, n, r);
174
174
  break;
175
175
  case "excel":
176
- te(t, n, r);
176
+ F(t, n, r);
177
177
  break;
178
178
  default: console.warn(`Unsupported export format: ${e}`);
179
179
  }
180
180
  }
181
- function I(e) {
181
+ function L(e) {
182
182
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
183
183
  }
184
- function L(e) {
184
+ function R(e) {
185
185
  if (typeof e == "string" && e.length > 0) {
186
186
  let t = e.charAt(0);
187
187
  if (t === "=" || t === "+" || t === "-" || t === "@" || t === "|") return `\t${e}`;
188
188
  }
189
189
  return e;
190
190
  }
191
- function R(e) {
191
+ function z(e) {
192
192
  return [
193
193
  "A4",
194
194
  "A3",
@@ -196,19 +196,19 @@ function R(e) {
196
196
  "Legal"
197
197
  ].includes(e || "") ? e : "A4";
198
198
  }
199
- function z(e) {
199
+ function B(e) {
200
200
  return e === "landscape" ? "landscape" : "portrait";
201
201
  }
202
- function B(e, t, n) {
202
+ function V(e, t, n) {
203
203
  let r = new Blob([e], { type: `${n};charset=utf-8` }), i = URL.createObjectURL(r), a = document.createElement("a");
204
204
  a.href = i, a.download = t, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(i);
205
205
  }
206
206
  //#endregion
207
207
  //#region src/formatValue.ts
208
- function V(e, t) {
208
+ function H(e, t) {
209
209
  if (e == null || e === "") return "";
210
210
  let n = t?.type, r = t?.format;
211
- if (n === "date" || r === "date" || ne(e)) return re(e);
211
+ if (n === "date" || r === "date" || te(e)) return ne(e);
212
212
  if (n === "number" || typeof e == "number") {
213
213
  let t = typeof e == "number" ? e : Number(e);
214
214
  return isNaN(t) ? String(e) : r === "currency" || r === "currency_cny" ? `¥${t.toLocaleString("en-US", {
@@ -224,10 +224,10 @@ function V(e, t) {
224
224
  }
225
225
  return String(e);
226
226
  }
227
- function ne(e) {
227
+ function te(e) {
228
228
  return typeof e == "string" ? /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e) : !1;
229
229
  }
230
- function re(e) {
230
+ function ne(e) {
231
231
  try {
232
232
  let t = new Date(e);
233
233
  return isNaN(t.getTime()) ? String(e) : `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")}`;
@@ -237,7 +237,7 @@ function re(e) {
237
237
  }
238
238
  //#endregion
239
239
  //#region src/ReportViewer.tsx
240
- function ie(e, t) {
240
+ function re(e, t) {
241
241
  if (!t || t.length === 0 || !e || e.length === 0) return null;
242
242
  let n = t[0], r = n.field, i = /* @__PURE__ */ new Map();
243
243
  for (let t of e) {
@@ -253,13 +253,13 @@ function ie(e, t) {
253
253
  let o = n.sort === "desc" ? -1 : 1;
254
254
  return a.sort((e, t) => e.key.localeCompare(t.key) * o), a;
255
255
  }
256
- var H = ({ schema: t, onRefresh: n }) => {
256
+ var U = ({ schema: t, onRefresh: n }) => {
257
257
  let { report: r, data: i, showToolbar: a = !0, allowExport: s = !0, allowPrint: c = !0, loading: u = !1 } = t, x = (e) => {
258
258
  if (!r) {
259
259
  console.warn("ReportViewer: Cannot export, no report defined");
260
260
  return;
261
261
  }
262
- F(e, r, i || [], r.exportConfigs?.[e]);
262
+ I(e, r, i || [], r.exportConfigs?.[e]);
263
263
  }, C = () => {
264
264
  window.print();
265
265
  }, E = () => {
@@ -308,7 +308,7 @@ var H = ({ schema: t, onRefresh: n }) => {
308
308
  className: t.colorMap?.[String(e)] || "",
309
309
  children: String(e)
310
310
  });
311
- if (t.aggregation) return V(e, t);
311
+ if (t.aggregation) return H(e, t);
312
312
  if (t.type) {
313
313
  let n = { ...t };
314
314
  return t.colorMap && !n.options && (n.options = Object.entries(t.colorMap).map(([e, t]) => ({
@@ -320,7 +320,7 @@ var H = ({ schema: t, onRefresh: n }) => {
320
320
  field: n
321
321
  });
322
322
  }
323
- return V(e, t);
323
+ return H(e, t);
324
324
  };
325
325
  return r ? /* @__PURE__ */ b("div", {
326
326
  className: "space-y-4",
@@ -418,7 +418,7 @@ var H = ({ schema: t, onRefresh: n }) => {
418
418
  children: e.label || e.name
419
419
  }), /* @__PURE__ */ y("div", {
420
420
  className: "text-2xl font-bold",
421
- children: V(k(e.name, e.aggregation), e)
421
+ children: H(k(e.name, e.aggregation), e)
422
422
  })]
423
423
  }) }, t))
424
424
  }),
@@ -452,7 +452,7 @@ var H = ({ schema: t, onRefresh: n }) => {
452
452
  children: e.label || e.name
453
453
  }, t)) })
454
454
  }), /* @__PURE__ */ y("tbody", { children: (() => {
455
- let e = ie(i || [], r.groupBy || []);
455
+ let e = re(i || [], r.groupBy || []);
456
456
  return e ? e.map((e) => /* @__PURE__ */ b(o.Fragment, { children: [/* @__PURE__ */ y("tr", {
457
457
  className: "bg-muted/60",
458
458
  children: /* @__PURE__ */ b("td", {
@@ -520,7 +520,7 @@ var H = ({ schema: t, onRefresh: n }) => {
520
520
  };
521
521
  //#endregion
522
522
  //#region src/mergeFilters.ts
523
- function U(e, t) {
523
+ function W(e, t) {
524
524
  let n = e && Object.keys(e).length > 0, r = t && Object.keys(t).length > 0;
525
525
  if (n && r) return { $and: [e, t] };
526
526
  if (n) return e;
@@ -528,18 +528,18 @@ function U(e, t) {
528
528
  }
529
529
  //#endregion
530
530
  //#region src/DatasetReportRenderer.tsx
531
- function W(e) {
531
+ function G(e) {
532
532
  if (!e || typeof e != "object") return !1;
533
533
  let t = e;
534
534
  return typeof t.dataset == "string" && t.dataset.length > 0 ? !0 : t.type === "joined" && Array.isArray(t.blocks) && t.blocks.some((e) => typeof e?.dataset == "string");
535
535
  }
536
- function G(e, t) {
536
+ function K(e, t) {
537
537
  return e ? typeof e == "string" ? e : typeof e == "object" && typeof e.default == "string" ? e.default : t : t;
538
538
  }
539
- function K(e) {
539
+ function q(e) {
540
540
  return Array.isArray(e) ? e.filter((e) => typeof e == "string" && !!e) : [];
541
541
  }
542
- function q(e, t, n, r, i, o) {
542
+ function J(e, t, n, r, i, o) {
543
543
  let [s, c] = a.useState({
544
544
  status: "idle",
545
545
  rows: []
@@ -591,7 +591,7 @@ function q(e, t, n, r, i, o) {
591
591
  };
592
592
  }, [d]), s;
593
593
  }
594
- function J({ dataset: e }) {
594
+ function Y({ dataset: e }) {
595
595
  return /* @__PURE__ */ b("div", {
596
596
  className: "flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground",
597
597
  children: [
@@ -601,7 +601,7 @@ function J({ dataset: e }) {
601
601
  ]
602
602
  });
603
603
  }
604
- function Y({ status: e, error: t }) {
604
+ function X({ status: e, error: t }) {
605
605
  return e === "error" ? /* @__PURE__ */ b("div", {
606
606
  role: "alert",
607
607
  className: "flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",
@@ -614,22 +614,22 @@ function Y({ status: e, error: t }) {
614
614
  children: [/* @__PURE__ */ y(C, { className: "h-4 w-4 animate-spin" }), " Running report…"]
615
615
  });
616
616
  }
617
- function X() {
617
+ function Z() {
618
618
  return /* @__PURE__ */ b("div", {
619
619
  className: "flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground",
620
620
  children: [/* @__PURE__ */ y(E, { className: "h-6 w-6" }), " The dataset returned no rows for this report’s scope."]
621
621
  });
622
622
  }
623
- var Z = "cursor-pointer hover:bg-accent/40";
623
+ var ie = "cursor-pointer hover:bg-accent/40";
624
624
  function ae({ dataset: e, rows: a, values: o, runtimeFilter: s, dataSource: c, onDrill: l }) {
625
- let u = q(e, a, o, s, c), { fieldLabel: d } = k();
626
- if (o.length === 0) return /* @__PURE__ */ y(J, { dataset: e });
627
- if (u.status === "loading" || u.status === "idle") return /* @__PURE__ */ y(Y, { status: u.status });
628
- if (u.status === "error") return /* @__PURE__ */ y(Y, {
625
+ let u = J(e, a, o, s, c), { fieldLabel: d } = k();
626
+ if (o.length === 0) return /* @__PURE__ */ y(Y, { dataset: e });
627
+ if (u.status === "loading" || u.status === "idle") return /* @__PURE__ */ y(X, { status: u.status });
628
+ if (u.status === "error") return /* @__PURE__ */ y(X, {
629
629
  status: "error",
630
630
  error: u.error
631
631
  });
632
- if (u.rows.length === 0) return /* @__PURE__ */ y(X, {});
632
+ if (u.rows.length === 0) return /* @__PURE__ */ y(Z, {});
633
633
  let f = !!l && a.length > 0, p = u.dimensionFields ? a.filter((e) => e in u.dimensionFields) : [], m = (n, r) => {
634
634
  let i = {};
635
635
  for (let e of a) i[e] = n[e];
@@ -653,7 +653,7 @@ function ae({ dataset: e, rows: a, values: o, runtimeFilter: s, dataSource: c, o
653
653
  children: g(e)
654
654
  }, e)) })
655
655
  }), /* @__PURE__ */ y("tbody", { children: u.rows.map((e, t) => /* @__PURE__ */ y("tr", {
656
- className: `border-t${f ? ` ${Z}` : ""}`,
656
+ className: `border-t${f ? ` ${ie}` : ""}`,
657
657
  "data-testid": f ? "dataset-drill-row" : void 0,
658
658
  onClick: f ? () => m(e, t) : void 0,
659
659
  children: _.map((t) => /* @__PURE__ */ y("td", {
@@ -664,14 +664,60 @@ function ae({ dataset: e, rows: a, values: o, runtimeFilter: s, dataSource: c, o
664
664
  })
665
665
  });
666
666
  }
667
+ function oe(e) {
668
+ switch (e) {
669
+ case "line": return "line";
670
+ case "area": return "area";
671
+ case "pie": return "pie";
672
+ case "donut": return "donut";
673
+ case "radar": return "radar";
674
+ case "scatter": return "scatter";
675
+ default: return "bar";
676
+ }
677
+ }
678
+ function se(t) {
679
+ let [, n] = a.useReducer((e) => e + 1, 0);
680
+ return a.useEffect(() => {
681
+ if (e.get(t)) return;
682
+ let r = typeof e.subscribe == "function" ? e.subscribe(() => {
683
+ e.get(t) && n();
684
+ }) : void 0, i = e.loadLazy?.(t);
685
+ return i && typeof i.then == "function" && i.then(() => n()).catch(() => {}), r;
686
+ }, [t]), e.get(t);
687
+ }
688
+ function ce({ dataset: e, chart: t, runtimeFilter: n, dataSource: r }) {
689
+ let i = typeof t.xAxis == "string" ? t.xAxis : "", a = typeof t.yAxis == "string" ? t.yAxis : "", o = J(e, i ? [i] : [], a ? [a] : [], n, r), s = se("chart");
690
+ if (!i || !a) return null;
691
+ if (o.status === "loading" || o.status === "idle") return /* @__PURE__ */ b("div", {
692
+ className: "flex items-center gap-2 p-4 text-xs text-muted-foreground",
693
+ children: [/* @__PURE__ */ y(C, { className: "h-4 w-4 animate-spin" }), " Loading chart…"]
694
+ });
695
+ if (o.status === "error" || o.rows.length === 0 || !s) return null;
696
+ let c = typeof t.title == "string" ? t.title : void 0;
697
+ return /* @__PURE__ */ b("div", {
698
+ className: "rounded-md border bg-card p-3",
699
+ "data-testid": "dataset-report-chart",
700
+ children: [c ? /* @__PURE__ */ y("h3", {
701
+ className: "mb-2 text-sm font-semibold",
702
+ children: c
703
+ }) : null, /* @__PURE__ */ y(s, { schema: {
704
+ chartType: oe(t.type),
705
+ data: o.rows,
706
+ xAxisKey: i,
707
+ series: [{ dataKey: a }],
708
+ height: typeof t.height == "number" ? t.height : 280,
709
+ isAnimationActive: !1
710
+ } })]
711
+ });
712
+ }
667
713
  function Q(e, t) {
668
714
  return e.map((e) => String(t[e] ?? "∅")).join("");
669
715
  }
670
- function oe(e, t) {
716
+ function le(e, t) {
671
717
  return e.map((e) => r(t[e])).join(" / ");
672
718
  }
673
- function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l, dataSource: u, onDrill: d }) {
674
- let f = q(e, [...o, ...s], c, l, u, [
719
+ function ue({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l, dataSource: u, onDrill: d }) {
720
+ let f = J(e, [...o, ...s], c, l, u, [
675
721
  o,
676
722
  s,
677
723
  []
@@ -686,7 +732,7 @@ function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l
686
732
  for (let e of o) t[e] = a[e];
687
733
  e.push({
688
734
  id: l,
689
- label: oe(o, a),
735
+ label: le(o, a),
690
736
  key: t
691
737
  });
692
738
  }
@@ -696,7 +742,7 @@ function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l
696
742
  for (let t of s) e[t] = a[t];
697
743
  t.push({
698
744
  id: u,
699
- label: oe(s, a),
745
+ label: le(s, a),
700
746
  key: e
701
747
  });
702
748
  }
@@ -714,13 +760,13 @@ function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l
714
760
  o,
715
761
  s
716
762
  ]);
717
- if (c.length === 0) return /* @__PURE__ */ y(J, { dataset: e });
718
- if (f.status === "loading" || f.status === "idle") return /* @__PURE__ */ y(Y, { status: f.status });
719
- if (f.status === "error") return /* @__PURE__ */ y(Y, {
763
+ if (c.length === 0) return /* @__PURE__ */ y(Y, { dataset: e });
764
+ if (f.status === "loading" || f.status === "idle") return /* @__PURE__ */ y(X, { status: f.status });
765
+ if (f.status === "error") return /* @__PURE__ */ y(X, {
720
766
  status: "error",
721
767
  error: f.error
722
768
  });
723
- if (!h || h.rowHeaders.length === 0) return /* @__PURE__ */ y(X, {});
769
+ if (!h || h.rowHeaders.length === 0) return /* @__PURE__ */ y(Z, {});
724
770
  let { measureField: g, headerLabel: _ } = n(f.fields, f.object, m), v = p("report.total", "Total"), x = !!d, S = f.dimensionFields ? [...o, ...s].filter((e) => e in f.dimensionFields) : [], C = (n, r, i) => {
725
771
  let a = f.object && f.dimensionFields && S.length > 0 ? t(f.drillRawRows?.[i], S, f.dimensionFields, l) : void 0;
726
772
  d({
@@ -774,7 +820,7 @@ function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l
774
820
  w.map((t) => {
775
821
  let n = h.cells.get(`${e.id} ${t.col.id}`), r = n?.row[t.measure], a = x && n != null;
776
822
  return /* @__PURE__ */ y("td", {
777
- className: `px-2 py-1 text-right tabular-nums whitespace-nowrap${a ? ` ${Z}` : ""}`,
823
+ className: `px-2 py-1 text-right tabular-nums whitespace-nowrap${a ? ` ${ie}` : ""}`,
778
824
  "data-testid": a ? "dataset-drill-cell" : void 0,
779
825
  onClick: a ? () => C(e.key, t.col.key, n.index) : void 0,
780
826
  children: i(r, g(t.measure)?.format, g(t.measure)?.currency)
@@ -809,8 +855,8 @@ function se({ dataset: e, rows: o, columnsAcross: s, values: c, runtimeFilter: l
809
855
  })
810
856
  });
811
857
  }
812
- var ce = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i }) => {
813
- let a = U(e.runtimeFilter ?? e.filter, n), o = e.drilldown === !1 ? void 0 : r;
858
+ var de = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i }) => {
859
+ let a = W(e.runtimeFilter ?? e.filter, n), o = e.drilldown === !1 ? void 0 : r;
814
860
  if (e.type === "joined" && Array.isArray(e.blocks)) return /* @__PURE__ */ y("div", {
815
861
  className: i,
816
862
  "data-testid": "dataset-joined-report",
@@ -821,18 +867,18 @@ var ce = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i
821
867
  gap: 24
822
868
  },
823
869
  children: e.blocks.map((e, n) => {
824
- let r = U(a, e.runtimeFilter ?? e.filter), i = K(e.columns), s = e.type === "matrix" && i.length > 0 ? /* @__PURE__ */ y(se, {
870
+ let r = W(a, e.runtimeFilter ?? e.filter), i = q(e.columns), s = e.type === "matrix" && i.length > 0 ? /* @__PURE__ */ y(ue, {
825
871
  dataset: String(e.dataset ?? ""),
826
- rows: K(e.rows),
872
+ rows: q(e.rows),
827
873
  columnsAcross: i,
828
- values: K(e.values),
874
+ values: q(e.values),
829
875
  runtimeFilter: r,
830
876
  dataSource: t,
831
877
  onDrill: o
832
878
  }) : /* @__PURE__ */ y(ae, {
833
879
  dataset: String(e.dataset ?? ""),
834
- rows: K(e.rows),
835
- values: K(e.values),
880
+ rows: q(e.rows),
881
+ values: q(e.values),
836
882
  runtimeFilter: r,
837
883
  dataSource: t,
838
884
  onDrill: o
@@ -845,45 +891,52 @@ var ce = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i
845
891
  className: "flex flex-col gap-0.5",
846
892
  children: [/* @__PURE__ */ y("h3", {
847
893
  className: "text-sm font-semibold",
848
- children: G(e.label, e.name ?? `Block ${n + 1}`)
894
+ children: K(e.label, e.name ?? `Block ${n + 1}`)
849
895
  }), e.description ? /* @__PURE__ */ y("p", {
850
896
  className: "text-xs text-muted-foreground",
851
- children: G(e.description, "")
897
+ children: K(e.description, "")
852
898
  }) : null]
853
899
  }), s]
854
900
  }, e.name ?? `block-${n}`);
855
901
  })
856
902
  });
857
- let s = K(e.columns);
858
- return e.type === "matrix" && s.length > 0 ? /* @__PURE__ */ y("div", {
903
+ let s = q(e.columns);
904
+ if (e.type === "matrix" && s.length > 0) return /* @__PURE__ */ y("div", {
859
905
  className: i,
860
906
  "data-testid": "dataset-report",
861
907
  "data-report-name": e.name,
862
- children: /* @__PURE__ */ y(se, {
908
+ children: /* @__PURE__ */ y(ue, {
863
909
  dataset: String(e.dataset ?? ""),
864
- rows: K(e.rows),
910
+ rows: q(e.rows),
865
911
  columnsAcross: s,
866
- values: K(e.values),
912
+ values: q(e.values),
867
913
  runtimeFilter: a,
868
914
  dataSource: t,
869
915
  onDrill: o
870
916
  })
871
- }) : /* @__PURE__ */ y("div", {
872
- className: i,
917
+ });
918
+ let c = e.chart && typeof e.chart == "object" && e.chart.type ? e.chart : null;
919
+ return /* @__PURE__ */ b("div", {
920
+ className: `${i ?? ""} flex flex-col gap-3`,
873
921
  "data-testid": "dataset-report",
874
922
  "data-report-name": e.name,
875
- children: /* @__PURE__ */ y(ae, {
923
+ children: [c ? /* @__PURE__ */ y(ce, {
876
924
  dataset: String(e.dataset ?? ""),
877
- rows: K(e.rows),
878
- values: K(e.values),
925
+ chart: c,
926
+ runtimeFilter: a,
927
+ dataSource: t
928
+ }) : null, /* @__PURE__ */ y(ae, {
929
+ dataset: String(e.dataset ?? ""),
930
+ rows: q(e.rows),
931
+ values: q(e.values),
879
932
  runtimeFilter: a,
880
933
  dataSource: t,
881
934
  onDrill: o
882
- })
935
+ })]
883
936
  });
884
937
  }, $ = (e) => {
885
938
  let { dataSource: t, rows: n, runtimeFilter: r, onDrill: i, className: o } = e, l = a.useContext(u), d = t ?? l?.dataSource, f = e.schema;
886
- return f && typeof f == "object" && f.type === "spec-report" && f.report && typeof f.report == "object" && (f = f.report), W(f) ? /* @__PURE__ */ y(ce, {
939
+ return f && typeof f == "object" && f.type === "spec-report" && f.report && typeof f.report == "object" && (f = f.report), G(f) ? /* @__PURE__ */ y(de, {
887
940
  report: f,
888
941
  dataSource: d,
889
942
  runtimeFilter: r,
@@ -892,7 +945,7 @@ var ce = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i
892
945
  }) : s(f) ? /* @__PURE__ */ y("div", {
893
946
  className: o,
894
947
  "data-testid": "report-presentation-bridge",
895
- children: /* @__PURE__ */ y(H, { schema: {
948
+ children: /* @__PURE__ */ y(U, { schema: {
896
949
  type: "report-viewer",
897
950
  report: c(f),
898
951
  data: n ?? [],
@@ -902,11 +955,11 @@ var ce = ({ report: e, dataSource: t, runtimeFilter: n, onDrill: r, className: i
902
955
  };
903
956
  //#endregion
904
957
  //#region src/LiveReportExporter.ts
905
- async function le(e, t) {
958
+ async function fe(e, t) {
906
959
  let { dataSource: n, resource: r, queryParams: i, format: a, exportConfig: o } = t, s = a || e.defaultExportFormat || "pdf";
907
960
  try {
908
961
  let t = (await n.find(r, i)).data || [];
909
- return F(s, e, t, {
962
+ return I(s, e, t, {
910
963
  format: s,
911
964
  ...e.exportConfigs?.[s],
912
965
  ...o
@@ -924,17 +977,17 @@ async function le(e, t) {
924
977
  };
925
978
  }
926
979
  }
927
- function ue(e, t, n = {}) {
928
- let { columns: r, filename: i, includeAggregationRow: a = !1 } = n, o = r || (e.fields || []).map(fe), s = o.map((e) => e.header), c = t.map((e, t) => o.map((n) => {
980
+ function pe(e, t, n = {}) {
981
+ let { columns: r, filename: i, includeAggregationRow: a = !1 } = n, o = r || (e.fields || []).map(he), s = o.map((e) => e.header), c = t.map((e, t) => o.map((n) => {
929
982
  if (n.formula) return n.formula.replace(/\{ROW\}/g, String(t + 2));
930
983
  let r = e[n.name];
931
- return pe(r, n.numberFormat);
984
+ return ge(r, n.numberFormat);
932
985
  }));
933
986
  if (a && t.length > 0) {
934
987
  let n = o.map((n, r) => {
935
988
  let i = (e.fields || []).find((e) => e.name === n.name);
936
989
  if (i?.aggregation) {
937
- let e = he(r), n = t.length + 1;
990
+ let e = ve(r), n = t.length + 1;
938
991
  switch (i.aggregation) {
939
992
  case "sum": return `=SUM(${e}2:${e}${n})`;
940
993
  case "avg": return `=AVERAGE(${e}2:${e}${n})`;
@@ -948,15 +1001,15 @@ function ue(e, t, n = {}) {
948
1001
  });
949
1002
  c.push(n);
950
1003
  }
951
- _e("" + [s.join(" "), ...c.map((e) => e.join(" "))].join("\n"), i || `${e.title || "report"}.tsv`, "text/tab-separated-values");
1004
+ be("" + [s.join(" "), ...c.map((e) => e.join(" "))].join("\n"), i || `${e.title || "report"}.tsv`, "text/tab-separated-values");
952
1005
  }
953
- function de(e, t, n, r) {
1006
+ function me(e, t, n, r) {
954
1007
  return async () => {
955
1008
  let i = e.schedule;
956
1009
  if (!i?.enabled) return [];
957
1010
  let a = i.formats || [e.defaultExportFormat || "pdf"], o = [];
958
1011
  for (let r of a) {
959
- let i = await le(e, {
1012
+ let i = await fe(e, {
960
1013
  dataSource: t,
961
1014
  resource: n,
962
1015
  format: r
@@ -966,16 +1019,16 @@ function de(e, t, n, r) {
966
1019
  return r(e, i), o;
967
1020
  };
968
1021
  }
969
- function fe(e) {
1022
+ function he(e) {
970
1023
  return {
971
1024
  name: e.name,
972
1025
  header: e.label || e.name
973
1026
  };
974
1027
  }
975
- function pe(e, t) {
976
- return e == null ? "" : typeof e == "number" && t ? e.toLocaleString("en-US", me(t)) : ge(String(e));
1028
+ function ge(e, t) {
1029
+ return e == null ? "" : typeof e == "number" && t ? e.toLocaleString("en-US", _e(t)) : ye(String(e));
977
1030
  }
978
- function me(e) {
1031
+ function _e(e) {
979
1032
  if (e.includes("%")) return {
980
1033
  style: "percent",
981
1034
  minimumFractionDigits: 0
@@ -986,19 +1039,19 @@ function me(e) {
986
1039
  maximumFractionDigits: Math.max(0, t - 1)
987
1040
  };
988
1041
  }
989
- function he(e) {
1042
+ function ve(e) {
990
1043
  let t = "", n = e;
991
1044
  for (; n >= 0;) t = String.fromCharCode(n % 26 + 65) + t, n = Math.floor(n / 26) - 1;
992
1045
  return t;
993
1046
  }
994
- function ge(e) {
1047
+ function ye(e) {
995
1048
  if (e.length > 0) {
996
1049
  let t = e.charAt(0);
997
1050
  if (t === "=" || t === "+" || t === "-" || t === "@" || t === "|") return `'${e}`;
998
1051
  }
999
1052
  return e;
1000
1053
  }
1001
- function _e(e, t, n) {
1054
+ function be(e, t, n) {
1002
1055
  let r = new Blob([e], { type: `${n};charset=utf-8` }), i = URL.createObjectURL(r), a = document.createElement("a");
1003
1056
  a.href = i, a.download = t, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(i);
1004
1057
  }
@@ -1036,7 +1089,7 @@ e.register("report", $, {
1036
1089
  type: "string",
1037
1090
  label: "Report Type"
1038
1091
  }]
1039
- }), e.register("report-viewer", H, {
1092
+ }), e.register("report-viewer", U, {
1040
1093
  namespace: "report",
1041
1094
  label: "Report Viewer",
1042
1095
  category: "Report",
@@ -1051,4 +1104,4 @@ e.register("report", $, {
1051
1104
  }]
1052
1105
  });
1053
1106
  //#endregion
1054
- export { ce as DatasetReportRenderer, j as LegacyReportRenderer, $ as ReportRenderer, H as ReportViewer, de as createScheduleTrigger, M as exportAsCSV, te as exportAsExcel, N as exportAsHTML, ee as exportAsJSON, P as exportAsPDF, ue as exportExcelWithFormulas, F as exportReport, le as exportWithLiveData, V as formatValue, W as isDatasetReport, U as mergeFilters };
1107
+ export { de as DatasetReportRenderer, j as LegacyReportRenderer, $ as ReportRenderer, U as ReportViewer, me as createScheduleTrigger, M as exportAsCSV, F as exportAsExcel, N as exportAsHTML, ee as exportAsJSON, P as exportAsPDF, pe as exportExcelWithFormulas, I as exportReport, fe as exportWithLiveData, H as formatValue, G as isDatasetReport, W as mergeFilters };
@@ -55,5 +55,5 @@ ${e.description?`<p class="description">${w(e.description)}</p>`:``}
55
55
  </body>
56
56
  </html>`),o.document.close(),o.onload=()=>{o.print()}}function S(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
57
  `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
- `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function T(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function A(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function j(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function M(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var N=({schema:e,onRefresh:r})=>{let{report:l,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!l){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!u)return 0;let n=u.map(t=>Number(t[e])||0);switch(t){case`count`:return u.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=l?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return k(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,c.getCellRenderer)((0,c.resolveCellRendererType)(n)),{value:e,field:n})}return k(e,t)};return l?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!d&&l.title&&(0,o.jsx)(a.CardTitle,{children:l.title}),!d&&l.description&&(0,o.jsx)(a.CardDescription,{children:l.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:k(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=M(u||[],l.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):u?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!l.sections&&u&&u.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:u.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})};function P(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function F(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0?!0:t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function I(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function R(e,t,r,i,a,o){let[s,c]=n.useState({status:`idle`,rows:[]}),l=JSON.stringify(i??null),u=JSON.stringify(o??null),d=`${e}|${t.join(`,`)}|${r.join(`,`)}|${l}|${u}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){c({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){c({status:`idle`,rows:[]});return}let s=!1;return c({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{}}).then(e=>{s||c({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||c({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[d]),s}function z({dataset:e}){return(0,o.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]})}function B({status:e,error:t}){return e===`error`?(0,o.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,o.jsx)(s.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{className:`break-words`,children:t})]}):(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Running report…`]})}function V(){return(0,o.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Table2,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]})}var H=`cursor-pointer hover:bg-accent/40`;function U({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s}){let c=R(e,n,r,i,a),{fieldLabel:u}=(0,l.useSafeFieldLabel)();if(r.length===0)return(0,o.jsx)(z,{dataset:e});if(c.status===`loading`||c.status===`idle`)return(0,o.jsx)(B,{status:c.status});if(c.status===`error`)return(0,o.jsx)(B,{status:`error`,error:c.error});if(c.rows.length===0)return(0,o.jsx)(V,{});let d=!!s&&n.length>0,f=c.dimensionFields?n.filter(e=>e in c.dimensionFields):[],p=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let l=c.object&&c.dimensionFields&&f.length>0?(0,t.buildDatasetDrillFilter)(c.drillRawRows?.[a],f,c.dimensionFields,i):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:c.object,objectFilter:l})},{measureField:m,headerLabel:h}=(0,t.buildDatasetFieldHelpers)(c.fields,c.object,u),g=[...n,...r];return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsx)(`tr`,{children:g.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:h(e)},e))})}),(0,o.jsx)(`tbody`,{children:c.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${d?` ${H}`:``}`,"data-testid":d?`dataset-drill-row`:void 0,onClick:d?()=>p(e,n):void 0,children:g.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],m(n)?.format,m(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]})})}function W(e,t){return e.map(e=>String(t[e]??`∅`)).join(``)}function G(e,n){return e.map(e=>(0,t.formatDimensionValue)(n[e])).join(` / `)}function K({dataset:e,rows:r,columnsAcross:i,values:a,runtimeFilter:s,dataSource:c,onDrill:u}){let d=R(e,[...r,...i],a,s,c,[r,i,[]]),f=(0,l.useSafeTranslate)(),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=n.useMemo(()=>{if(d.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return d.rows.forEach((s,c)=>{let l=W(r,s),u=W(i,s);if(!n.has(l)){n.add(l);let t={};for(let e of r)t[e]=s[e];e.push({id:l,label:G(r,s),key:t})}if(!a.has(u)){a.add(u);let e={};for(let t of i)e[t]=s[t];t.push({id:u,label:G(i,s),key:e})}o.set(`${l} ${u}`,{row:s,index:c})}),{rowHeaders:e,colHeaders:t,cells:o}},[d,r,i]);if(a.length===0)return(0,o.jsx)(z,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(B,{status:d.status});if(d.status===`error`)return(0,o.jsx)(B,{status:`error`,error:d.error});if(!m||m.rowHeaders.length===0)return(0,o.jsx)(V,{});let{measureField:h,headerLabel:g}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,p),_=f(`report.total`,`Total`),v=!!u,y=d.dimensionFields?[...r,...i].filter(e=>e in d.dimensionFields):[],b=(n,r,i)=>{let a=d.object&&d.dimensionFields&&y.length>0?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[i],y,d.dimensionFields,s):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:d.object,objectFilter:a})},x=m.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${g(t)}`}))),S=e=>d.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,C=new Map;for(let e of S(r)??[])C.set(W(r,e),e);let w=new Map;for(let e of S(i)??[])w.set(W(i,e),e);let T=S([])?.[0],E=C.size>0,D=w.size>0;return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,"data-testid":`dataset-matrix`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsxs)(`tr`,{children:[r.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e)),x.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:a.length===1?_:`${_} · ${g(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[m.rowHeaders.map(e=>(0,o.jsxs)(`tr`,{className:`border-t`,children:[r.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:(0,t.formatDimensionValue)(e.key[n])},n)),x.map(n=>{let r=m.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=v&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${H}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>b(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,h(n.measure)?.format,h(n.measure)?.currency)},`${n.col.id}-${n.measure}`)}),E&&a.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:(0,t.formatMeasure)(C.get(e.id)?.[n],h(n)?.format,h(n)?.currency)},`total-${n}`))]},e.id)),D&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[r.length>0&&(0,o.jsx)(`td`,{colSpan:r.length,className:`px-2 py-1 whitespace-nowrap`,children:_}),x.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w.get(e.col.id)?.[e.measure],h(e.measure)?.format,h(e.measure)?.currency)},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:(0,t.formatMeasure)(T?.[e],h(e)?.format,h(e)?.currency)},`grand-${e}`))]})]})]})})}var q=({report:e,dataSource:t,runtimeFilter:n,onDrill:r,className:i})=>{let a=P(e.runtimeFilter??e.filter,n),s=e.drilldown===!1?void 0:r;if(e.type===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=P(a,e.runtimeFilter??e.filter),i=L(e.columns),c=e.type===`matrix`&&i.length>0?(0,o.jsx)(K,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:i,values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s}):(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,o.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`h3`,{className:`text-sm font-semibold`,children:I(e.label,e.name??`Block ${n+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I(e.description,``)}):null]}),c]},e.name??`block-${n}`)})});let c=L(e.columns);return e.type===`matrix`&&c.length>0?(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(K,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:c,values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})}):(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})})},J=e=>{let{dataSource:t,rows:a,runtimeFilter:s,onDrill:c,className:l}=e,u=n.useContext(i.SchemaRendererContext),d=t??u?.dataSource,f=e.schema;return f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),F(f)?(0,o.jsx)(q,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l}):(0,r.isSpecReport)(f)?(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:{type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1}})}):(0,o.jsx)(_,{schema:f})};async function Y(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return C(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function X(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(Q),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return $(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=te(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}re(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
- `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function Z(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Y(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Q(e){return{name:e.name,header:e.label||e.name}}function $(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,ee(t)):ne(String(e))}function ee(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function te(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ne(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function re(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,J,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`spec-report`,J,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`dataset`,type:`string`,label:`Dataset`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,N,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),e.DatasetReportRenderer=q,e.LegacyReportRenderer=_,e.ReportRenderer=J,e.ReportViewer=N,e.createScheduleTrigger=Z,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=X,e.exportReport=C,e.exportWithLiveData=Y,e.formatValue=k,e.isDatasetReport=F,e.mergeFilters=P});
58
+ `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function T(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function A(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function j(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function M(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var N=({schema:e,onRefresh:r})=>{let{report:l,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!l){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!u)return 0;let n=u.map(t=>Number(t[e])||0);switch(t){case`count`:return u.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=l?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return k(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,c.getCellRenderer)((0,c.resolveCellRendererType)(n)),{value:e,field:n})}return k(e,t)};return l?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!d&&l.title&&(0,o.jsx)(a.CardTitle,{children:l.title}),!d&&l.description&&(0,o.jsx)(a.CardDescription,{children:l.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:k(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=M(u||[],l.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):u?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!l.sections&&u&&u.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:u.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})};function P(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function F(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0?!0:t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function I(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function R(e,t,r,i,a,o){let[s,c]=n.useState({status:`idle`,rows:[]}),l=JSON.stringify(i??null),u=JSON.stringify(o??null),d=`${e}|${t.join(`,`)}|${r.join(`,`)}|${l}|${u}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){c({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){c({status:`idle`,rows:[]});return}let s=!1;return c({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{}}).then(e=>{s||c({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||c({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[d]),s}function z({dataset:e}){return(0,o.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]})}function B({status:e,error:t}){return e===`error`?(0,o.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,o.jsx)(s.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{className:`break-words`,children:t})]}):(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Running report…`]})}function V(){return(0,o.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Table2,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]})}var H=`cursor-pointer hover:bg-accent/40`;function U({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s}){let c=R(e,n,r,i,a),{fieldLabel:u}=(0,l.useSafeFieldLabel)();if(r.length===0)return(0,o.jsx)(z,{dataset:e});if(c.status===`loading`||c.status===`idle`)return(0,o.jsx)(B,{status:c.status});if(c.status===`error`)return(0,o.jsx)(B,{status:`error`,error:c.error});if(c.rows.length===0)return(0,o.jsx)(V,{});let d=!!s&&n.length>0,f=c.dimensionFields?n.filter(e=>e in c.dimensionFields):[],p=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let l=c.object&&c.dimensionFields&&f.length>0?(0,t.buildDatasetDrillFilter)(c.drillRawRows?.[a],f,c.dimensionFields,i):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:c.object,objectFilter:l})},{measureField:m,headerLabel:h}=(0,t.buildDatasetFieldHelpers)(c.fields,c.object,u),g=[...n,...r];return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsx)(`tr`,{children:g.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:h(e)},e))})}),(0,o.jsx)(`tbody`,{children:c.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${d?` ${H}`:``}`,"data-testid":d?`dataset-drill-row`:void 0,onClick:d?()=>p(e,n):void 0,children:g.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],m(n)?.format,m(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]})})}function W(e){switch(e){case`line`:return`line`;case`area`:return`area`;case`pie`:return`pie`;case`donut`:return`donut`;case`radar`:return`radar`;case`scatter`:return`scatter`;default:return`bar`}}function G(e){let[,r]=n.useReducer(e=>e+1,0);return n.useEffect(()=>{if(t.ComponentRegistry.get(e))return;let n=typeof t.ComponentRegistry.subscribe==`function`?t.ComponentRegistry.subscribe(()=>{t.ComponentRegistry.get(e)&&r()}):void 0,i=t.ComponentRegistry.loadLazy?.(e);return i&&typeof i.then==`function`&&i.then(()=>r()).catch(()=>{}),n},[e]),t.ComponentRegistry.get(e)}function K({dataset:e,chart:t,runtimeFilter:n,dataSource:r}){let i=typeof t.xAxis==`string`?t.xAxis:``,a=typeof t.yAxis==`string`?t.yAxis:``,c=R(e,i?[i]:[],a?[a]:[],n,r),l=G(`chart`);if(!i||!a)return null;if(c.status===`loading`||c.status===`idle`)return(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Loading chart…`]});if(c.status===`error`||c.rows.length===0||!l)return null;let u=typeof t.title==`string`?t.title:void 0;return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[u?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:u}):null,(0,o.jsx)(l,{schema:{chartType:W(t.type),data:c.rows,xAxisKey:i,series:[{dataKey:a}],height:typeof t.height==`number`?t.height:280,isAnimationActive:!1}})]})}function q(e,t){return e.map(e=>String(t[e]??`∅`)).join(``)}function J(e,n){return e.map(e=>(0,t.formatDimensionValue)(n[e])).join(` / `)}function Y({dataset:e,rows:r,columnsAcross:i,values:a,runtimeFilter:s,dataSource:c,onDrill:u}){let d=R(e,[...r,...i],a,s,c,[r,i,[]]),f=(0,l.useSafeTranslate)(),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=n.useMemo(()=>{if(d.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return d.rows.forEach((s,c)=>{let l=q(r,s),u=q(i,s);if(!n.has(l)){n.add(l);let t={};for(let e of r)t[e]=s[e];e.push({id:l,label:J(r,s),key:t})}if(!a.has(u)){a.add(u);let e={};for(let t of i)e[t]=s[t];t.push({id:u,label:J(i,s),key:e})}o.set(`${l} ${u}`,{row:s,index:c})}),{rowHeaders:e,colHeaders:t,cells:o}},[d,r,i]);if(a.length===0)return(0,o.jsx)(z,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(B,{status:d.status});if(d.status===`error`)return(0,o.jsx)(B,{status:`error`,error:d.error});if(!m||m.rowHeaders.length===0)return(0,o.jsx)(V,{});let{measureField:h,headerLabel:g}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,p),_=f(`report.total`,`Total`),v=!!u,y=d.dimensionFields?[...r,...i].filter(e=>e in d.dimensionFields):[],b=(n,r,i)=>{let a=d.object&&d.dimensionFields&&y.length>0?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[i],y,d.dimensionFields,s):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:d.object,objectFilter:a})},x=m.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${g(t)}`}))),S=e=>d.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,C=new Map;for(let e of S(r)??[])C.set(q(r,e),e);let w=new Map;for(let e of S(i)??[])w.set(q(i,e),e);let T=S([])?.[0],E=C.size>0,D=w.size>0;return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,"data-testid":`dataset-matrix`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsxs)(`tr`,{children:[r.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e)),x.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:a.length===1?_:`${_} · ${g(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[m.rowHeaders.map(e=>(0,o.jsxs)(`tr`,{className:`border-t`,children:[r.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:(0,t.formatDimensionValue)(e.key[n])},n)),x.map(n=>{let r=m.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=v&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${H}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>b(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,h(n.measure)?.format,h(n.measure)?.currency)},`${n.col.id}-${n.measure}`)}),E&&a.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:(0,t.formatMeasure)(C.get(e.id)?.[n],h(n)?.format,h(n)?.currency)},`total-${n}`))]},e.id)),D&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[r.length>0&&(0,o.jsx)(`td`,{colSpan:r.length,className:`px-2 py-1 whitespace-nowrap`,children:_}),x.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w.get(e.col.id)?.[e.measure],h(e.measure)?.format,h(e.measure)?.currency)},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:(0,t.formatMeasure)(T?.[e],h(e)?.format,h(e)?.currency)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:t,runtimeFilter:n,onDrill:r,className:i})=>{let a=P(e.runtimeFilter??e.filter,n),s=e.drilldown===!1?void 0:r;if(e.type===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=P(a,e.runtimeFilter??e.filter),i=L(e.columns),c=e.type===`matrix`&&i.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:i,values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s}):(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,o.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`h3`,{className:`text-sm font-semibold`,children:I(e.label,e.name??`Block ${n+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I(e.description,``)}):null]}),c]},e.name??`block-${n}`)})});let c=L(e.columns);if(e.type===`matrix`&&c.length>0)return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:c,values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})});let l=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${i??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,children:[l?(0,o.jsx)(K,{dataset:String(e.dataset??``),chart:l,runtimeFilter:a,dataSource:t}):null,(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})]})},Z=e=>{let{dataSource:t,rows:a,runtimeFilter:s,onDrill:c,className:l}=e,u=n.useContext(i.SchemaRendererContext),d=t??u?.dataSource,f=e.schema;return f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),F(f)?(0,o.jsx)(X,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l}):(0,r.isSpecReport)(f)?(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:{type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1}})}):(0,o.jsx)(_,{schema:f})};async function Q(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return C(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function $(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(te),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return ne(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=ie(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}oe(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
+ `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ee(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Q(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function te(e){return{name:e.name,header:e.label||e.name}}function ne(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,re(t)):ae(String(e))}function re(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function ie(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ae(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function oe(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,Z,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`spec-report`,Z,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`dataset`,type:`string`,label:`Dataset`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,N,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),e.DatasetReportRenderer=X,e.LegacyReportRenderer=_,e.ReportRenderer=Z,e.ReportViewer=N,e.createScheduleTrigger=ee,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=$,e.exportReport=C,e.exportWithLiveData=Q,e.formatValue=k,e.isDatasetReport=F,e.mergeFilters=P});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-report",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -23,13 +23,13 @@
23
23
  "lucide-react": "^1.21.0",
24
24
  "react-i18next": "^17.0.8",
25
25
  "tailwind-merge": "^3.6.0",
26
- "@object-ui/components": "7.0.0",
27
- "@object-ui/core": "7.0.0",
28
- "@object-ui/fields": "7.0.0",
29
- "@object-ui/i18n": "7.0.0",
30
- "@object-ui/plugin-grid": "7.0.0",
31
- "@object-ui/react": "7.0.0",
32
- "@object-ui/types": "7.0.0"
26
+ "@object-ui/components": "7.2.0",
27
+ "@object-ui/core": "7.2.0",
28
+ "@object-ui/fields": "7.2.0",
29
+ "@object-ui/i18n": "7.2.0",
30
+ "@object-ui/plugin-grid": "7.2.0",
31
+ "@object-ui/react": "7.2.0",
32
+ "@object-ui/types": "7.2.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^18.0.0",