@object-ui/plugin-charts 3.1.5 → 3.3.1

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 (36) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +24 -0
  3. package/dist/{AdvancedChartImpl-DmHTUUVD.js → AdvancedChartImpl-DxaZtNlE.js} +1214 -1206
  4. package/dist/{BarChart-XZkfLmcU.js → BarChart-BQS4sYHd.js} +3859 -3766
  5. package/dist/{ChartImpl-0VlpsMWG.js → ChartImpl-BaXisyXJ.js} +6 -6
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +207 -63
  8. package/dist/index.umd.cjs +19 -19
  9. package/dist/{jsx-runtime-C8d0IhUE.js → jsx-runtime-Caia9pQX.js} +1 -1
  10. package/dist/packages/plugin-charts/src/ObjectChart.d.ts +31 -0
  11. package/package.json +34 -10
  12. package/.turbo/turbo-build.log +0 -26
  13. package/dist/src/ObjectChart.d.ts +0 -12
  14. package/examples/chart-examples.ts +0 -54
  15. package/src/AdvancedChartImpl.tsx +0 -309
  16. package/src/ChartContainerImpl.tsx +0 -353
  17. package/src/ChartImpl.tsx +0 -91
  18. package/src/ChartRenderer.tsx +0 -112
  19. package/src/ObjectChart.stories.tsx +0 -104
  20. package/src/ObjectChart.tsx +0 -145
  21. package/src/__tests__/ObjectChart.aggregation.test.ts +0 -166
  22. package/src/__tests__/ObjectChart.dataFetch.test.tsx +0 -303
  23. package/src/index.test.ts +0 -136
  24. package/src/index.tsx +0 -172
  25. package/src/types.ts +0 -68
  26. package/tsconfig.json +0 -17
  27. package/vite.config.ts +0 -61
  28. package/vitest.config.ts +0 -13
  29. package/vitest.setup.ts +0 -1
  30. /package/dist/{src → packages/plugin-charts/src}/AdvancedChartImpl.d.ts +0 -0
  31. /package/dist/{src → packages/plugin-charts/src}/ChartContainerImpl.d.ts +0 -0
  32. /package/dist/{src → packages/plugin-charts/src}/ChartImpl.d.ts +0 -0
  33. /package/dist/{src → packages/plugin-charts/src}/ChartRenderer.d.ts +0 -0
  34. /package/dist/{src → packages/plugin-charts/src}/ObjectChart.stories.d.ts +0 -0
  35. /package/dist/{src → packages/plugin-charts/src}/index.d.ts +0 -0
  36. /package/dist/{src → packages/plugin-charts/src}/types.d.ts +0 -0
@@ -1,14 +1,14 @@
1
- import { t as e } from "./jsx-runtime-C8d0IhUE.js";
2
- import { Y as t, d as n, en as r, f as i, sn as a, t as o, u as s, v as c } from "./BarChart-XZkfLmcU.js";
1
+ import { t as e } from "./jsx-runtime-Caia9pQX.js";
2
+ import { Y as t, cn as n, d as r, f as i, t as a, tn as o, u as s, v as c } from "./BarChart-BQS4sYHd.js";
3
3
  //#region src/ChartImpl.tsx
4
4
  var l = e();
5
5
  function u({ data: e = [], dataKey: u = "value", xAxisKey: d = "name", height: f = 400, className: p = "", color: m = "hsl(var(--primary))" }) {
6
6
  return /* @__PURE__ */ (0, l.jsx)("div", {
7
7
  className: `p-2 sm:p-3 md:p-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm shadow-lg shadow-background/5 ${p}`,
8
- children: /* @__PURE__ */ (0, l.jsx)(a, {
8
+ children: /* @__PURE__ */ (0, l.jsx)(n, {
9
9
  width: "100%",
10
10
  height: f,
11
- children: /* @__PURE__ */ (0, l.jsxs)(o, {
11
+ children: /* @__PURE__ */ (0, l.jsxs)(a, {
12
12
  data: e,
13
13
  margin: {
14
14
  top: 10,
@@ -74,7 +74,7 @@ function u({ data: e = [], dataKey: u = "value", xAxisKey: d = "name", height: f
74
74
  stroke: "hsl(var(--border))",
75
75
  vertical: !1
76
76
  }),
77
- /* @__PURE__ */ (0, l.jsx)(n, {
77
+ /* @__PURE__ */ (0, l.jsx)(r, {
78
78
  dataKey: d,
79
79
  tick: {
80
80
  fill: "hsl(var(--muted-foreground))",
@@ -109,7 +109,7 @@ function u({ data: e = [], dataKey: u = "value", xAxisKey: d = "name", height: f
109
109
  },
110
110
  itemStyle: { color: "hsl(var(--primary))" }
111
111
  }),
112
- /* @__PURE__ */ (0, l.jsx)(r, { wrapperStyle: {
112
+ /* @__PURE__ */ (0, l.jsx)(o, { wrapperStyle: {
113
113
  paddingTop: "20px",
114
114
  fontFamily: "monospace"
115
115
  } }),
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './src/index'
1
+ export * from './packages/plugin-charts/src/index'
2
2
  export {}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { t as e } from "./jsx-runtime-C8d0IhUE.js";
1
+ import { t as e } from "./jsx-runtime-Caia9pQX.js";
2
2
  import { ComponentRegistry as t, extractRecords as n } from "@object-ui/core";
3
- import r, { Suspense as i, useContext as a, useEffect as o, useState as s } from "react";
4
- import { Skeleton as c } from "@object-ui/components";
5
- import { SchemaRendererContext as l, useDataScope as u } from "@object-ui/react";
3
+ import r, { Suspense as i, createContext as a, createElement as o, forwardRef as s, useCallback as c, useContext as l, useEffect as u, useState as d } from "react";
4
+ import { Skeleton as f } from "@object-ui/components";
5
+ import { SchemaRendererContext as p, useDataScope as m } from "@object-ui/react";
6
6
  //#region src/ChartRenderer.tsx
7
- var d = e(), f = r.lazy(() => import("./ChartImpl-0VlpsMWG.js")), p = r.lazy(() => import("./AdvancedChartImpl-DmHTUUVD.js")), m = ({ schema: e }) => /* @__PURE__ */ (0, d.jsx)(i, {
8
- fallback: /* @__PURE__ */ (0, d.jsx)(c, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
9
- children: /* @__PURE__ */ (0, d.jsx)(f, {
7
+ var h = e(), g = r.lazy(() => import("./ChartImpl-BaXisyXJ.js")), _ = r.lazy(() => import("./AdvancedChartImpl-DxaZtNlE.js")), v = ({ schema: e }) => /* @__PURE__ */ (0, h.jsx)(i, {
8
+ fallback: /* @__PURE__ */ (0, h.jsx)(f, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
9
+ children: /* @__PURE__ */ (0, h.jsx)(g, {
10
10
  data: e.data,
11
11
  dataKey: e.dataKey,
12
12
  xAxisKey: e.xAxisKey,
@@ -14,7 +14,7 @@ var d = e(), f = r.lazy(() => import("./ChartImpl-0VlpsMWG.js")), p = r.lazy(()
14
14
  className: e.className,
15
15
  color: e.color
16
16
  })
17
- }), h = ({ schema: e }) => {
17
+ }), y = ({ schema: e }) => {
18
18
  let t = r.useMemo(() => {
19
19
  let t = e.series, n = e.xAxisKey, r = e.config;
20
20
  if (n || (e.index ? n = e.index : e.category && (n = e.category)), t || (e.categories ? t = e.categories.map((e) => ({ dataKey: e })) : e.value && (t = [{ dataKey: e.value }])), !r && t) {
@@ -39,9 +39,9 @@ var d = e(), f = r.lazy(() => import("./ChartImpl-0VlpsMWG.js")), p = r.lazy(()
39
39
  className: e.className
40
40
  };
41
41
  }, [e]);
42
- return /* @__PURE__ */ (0, d.jsx)(i, {
43
- fallback: /* @__PURE__ */ (0, d.jsx)(c, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
44
- children: /* @__PURE__ */ (0, d.jsx)(p, {
42
+ return /* @__PURE__ */ (0, h.jsx)(i, {
43
+ fallback: /* @__PURE__ */ (0, h.jsx)(f, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
44
+ children: /* @__PURE__ */ (0, h.jsx)(_, {
45
45
  chartType: t.chartType,
46
46
  data: t.data,
47
47
  config: t.config,
@@ -50,10 +50,71 @@ var d = e(), f = r.lazy(() => import("./ChartImpl-0VlpsMWG.js")), p = r.lazy(()
50
50
  className: t.className
51
51
  })
52
52
  });
53
- };
53
+ }, b = (...e) => e.filter((e, t, n) => !!e && e.trim() !== "" && n.indexOf(e) === t).join(" ").trim(), x = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), S = (e) => e.replace(/^([A-Z])|[\s-_]+(\w)/g, (e, t, n) => n ? n.toUpperCase() : t.toLowerCase()), C = (e) => {
54
+ let t = S(e);
55
+ return t.charAt(0).toUpperCase() + t.slice(1);
56
+ }, w = {
57
+ xmlns: "http://www.w3.org/2000/svg",
58
+ width: 24,
59
+ height: 24,
60
+ viewBox: "0 0 24 24",
61
+ fill: "none",
62
+ stroke: "currentColor",
63
+ strokeWidth: 2,
64
+ strokeLinecap: "round",
65
+ strokeLinejoin: "round"
66
+ }, T = (e) => {
67
+ for (let t in e) if (t.startsWith("aria-") || t === "role" || t === "title") return !0;
68
+ return !1;
69
+ }, E = a({}), D = () => l(E), O = s(({ color: e, size: t, strokeWidth: n, absoluteStrokeWidth: r, className: i = "", children: a, iconNode: s, ...c }, l) => {
70
+ let { size: u = 24, strokeWidth: d = 2, absoluteStrokeWidth: f = !1, color: p = "currentColor", className: m = "" } = D() ?? {}, h = r ?? f ? Number(n ?? d) * 24 / Number(t ?? u) : n ?? d;
71
+ return o("svg", {
72
+ ref: l,
73
+ ...w,
74
+ width: t ?? u ?? w.width,
75
+ height: t ?? u ?? w.height,
76
+ stroke: e ?? p,
77
+ strokeWidth: h,
78
+ className: b("lucide", m, i),
79
+ ...!a && !T(c) && { "aria-hidden": "true" },
80
+ ...c
81
+ }, [...s.map(([e, t]) => o(e, t)), ...Array.isArray(a) ? a : [a]]);
82
+ }), k = ((e, t) => {
83
+ let n = s(({ className: n, ...r }, i) => o(O, {
84
+ ref: i,
85
+ iconNode: t,
86
+ className: b(`lucide-${x(C(e))}`, `lucide-${e}`, n),
87
+ ...r
88
+ }));
89
+ return n.displayName = C(e), n;
90
+ })("circle-alert", [
91
+ ["circle", {
92
+ cx: "12",
93
+ cy: "12",
94
+ r: "10",
95
+ key: "1mglay"
96
+ }],
97
+ ["line", {
98
+ x1: "12",
99
+ x2: "12",
100
+ y1: "8",
101
+ y2: "12",
102
+ key: "1pkeuh"
103
+ }],
104
+ ["line", {
105
+ x1: "12",
106
+ x2: "12.01",
107
+ y1: "16",
108
+ y2: "16",
109
+ key: "4dfq90"
110
+ }]
111
+ ]);
54
112
  //#endregion
55
113
  //#region src/ObjectChart.tsx
56
- function g(e, t) {
114
+ function A(e) {
115
+ return e.replace(/[_-]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
116
+ }
117
+ function j(e, t) {
57
118
  let { field: n, function: r, groupBy: i } = t, a = {};
58
119
  for (let t of e) {
59
120
  let e = String(t[i] ?? "Unknown");
@@ -84,63 +145,146 @@ function g(e, t) {
84
145
  };
85
146
  });
86
147
  }
87
- var _ = (e) => {
88
- let { schema: t } = e, r = a(l), i = e.dataSource || r?.dataSource, c = u(t.bind), [f, p] = s([]), [m, _] = s(!1);
89
- o(() => {
90
- let e = !0;
91
- return t.objectName && !c && !t.data && (async () => {
92
- if (!(!i || !t.objectName)) {
93
- e && _(!0);
94
- try {
95
- let r;
96
- if (t.aggregate && typeof i.aggregate == "function") {
97
- let e = await i.aggregate(t.objectName, {
98
- field: t.aggregate.field,
99
- function: t.aggregate.function,
100
- groupBy: t.aggregate.groupBy,
101
- filter: t.filter
102
- });
103
- r = Array.isArray(e) ? e : [];
104
- } else if (typeof i.find == "function") r = n(await i.find(t.objectName, { $filter: t.filter })), t.aggregate && r.length > 0 && (r = g(r, t.aggregate));
105
- else return;
106
- e && p(r);
107
- } catch (e) {
108
- console.error("[ObjectChart] Fetch error:", e);
109
- } finally {
110
- e && _(!1);
111
- }
148
+ async function M(e, t, r, i) {
149
+ if (!e.length || !t) return e;
150
+ let a = r?.fields?.[t];
151
+ if (!a) return e.map((e) => ({
152
+ ...e,
153
+ [t]: A(String(e[t] ?? ""))
154
+ }));
155
+ let o = a.type;
156
+ if (o === "select" || o === "picklist" || o === "dropdown") {
157
+ let n = a.options || [];
158
+ if (n.length === 0) return e.map((e) => ({
159
+ ...e,
160
+ [t]: A(String(e[t] ?? ""))
161
+ }));
162
+ let r = {};
163
+ for (let e of n) typeof e == "string" ? r[e] = e : e && typeof e == "object" && (r[String(e.value)] = e.label || String(e.value));
164
+ return e.map((e) => {
165
+ let n = String(e[t] ?? "");
166
+ return {
167
+ ...e,
168
+ [t]: r[n] || A(n)
169
+ };
170
+ });
171
+ }
172
+ if (o === "lookup" || o === "master_detail") {
173
+ let r = a.reference_to || a.reference;
174
+ if (!r || !i || typeof i.find != "function") return e;
175
+ let o = [...new Set(e.map((e) => e[t]).filter((e) => e != null))];
176
+ if (o.length === 0) return e;
177
+ let s = a.id_field || "id";
178
+ try {
179
+ let c = n(await i.find(r, {
180
+ $filter: { [s]: { $in: o } },
181
+ $top: o.length
182
+ })), l = a.reference_field || a.display_field || "name", u = {};
183
+ for (let e of c) {
184
+ let t = String(e[s] ?? e.id ?? e._id ?? ""), n = e[l] || e.name || e.label || e.title || t;
185
+ t && (u[t] = String(n));
186
+ }
187
+ return e.map((e) => {
188
+ let n = String(e[t] ?? "");
189
+ return {
190
+ ...e,
191
+ [t]: u[n] || n
192
+ };
193
+ });
194
+ } catch (t) {
195
+ return console.warn("[ObjectChart] Failed to resolve lookup labels:", t), e;
196
+ }
197
+ }
198
+ return e.map((e) => ({
199
+ ...e,
200
+ [t]: A(String(e[t] ?? ""))
201
+ }));
202
+ }
203
+ var N = (e) => {
204
+ let { schema: t } = e, r = l(p), i = e.dataSource || r?.dataSource, a = m(t.bind), [o, s] = d([]), [f, g] = d(!1), [_, v] = d(null), b = c(async (e, r) => {
205
+ if (!(!e || !t.objectName)) {
206
+ r.current && (g(!0), v(null));
207
+ try {
208
+ let i;
209
+ if (t.aggregate && typeof e.aggregate == "function") {
210
+ let n = await e.aggregate(t.objectName, {
211
+ field: t.aggregate.field,
212
+ function: t.aggregate.function,
213
+ groupBy: t.aggregate.groupBy,
214
+ filter: t.filter
215
+ });
216
+ i = Array.isArray(n) ? n : [];
217
+ } else if (typeof e.find == "function") i = n(await e.find(t.objectName, { $filter: t.filter })), t.aggregate && i.length > 0 && (i = j(i, t.aggregate));
218
+ else return;
219
+ let a = t.aggregate?.groupBy || t.xAxisKey;
220
+ if (a && typeof e.getObjectSchema == "function") try {
221
+ let n = await e.getObjectSchema(t.objectName);
222
+ i = await M(i, a, n, e);
223
+ } catch {}
224
+ r.current && s(i);
225
+ } catch (e) {
226
+ console.error("[ObjectChart] Fetch error:", e), r.current && v(e instanceof Error ? e.message : "Failed to load chart data");
227
+ } finally {
228
+ r.current && g(!1);
112
229
  }
113
- })(), () => {
114
- e = !1;
230
+ }
231
+ }, [
232
+ t.objectName,
233
+ t.aggregate,
234
+ t.filter,
235
+ t.xAxisKey
236
+ ]);
237
+ u(() => {
238
+ let e = { current: !0 };
239
+ return t.objectName && !a && !t.data && b(i, e), () => {
240
+ e.current = !1;
115
241
  };
116
242
  }, [
117
243
  t.objectName,
118
244
  i,
119
- c,
245
+ a,
120
246
  t.data,
121
247
  t.filter,
122
- t.aggregate
248
+ t.aggregate,
249
+ b
123
250
  ]);
124
- let v = c || t.data || f, y = Array.isArray(v) ? v : [], b = {
251
+ let x = a || t.data || o, S = Array.isArray(x) ? x : [], C = {
125
252
  ...t,
126
- data: y
253
+ data: S
127
254
  };
128
- return m && y.length === 0 ? /* @__PURE__ */ (0, d.jsx)("div", {
255
+ return f && S.length === 0 ? /* @__PURE__ */ (0, h.jsx)("div", {
129
256
  className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (t.className || ""),
257
+ "data-testid": "chart-loading",
130
258
  children: "Loading chart data…"
131
- }) : !i && t.objectName && y.length === 0 ? /* @__PURE__ */ (0, d.jsxs)("div", {
259
+ }) : _ ? /* @__PURE__ */ (0, h.jsxs)("div", {
260
+ className: "flex flex-col items-center justify-center gap-2 p-4 " + (t.className || ""),
261
+ "data-testid": "chart-error",
262
+ role: "alert",
263
+ children: [
264
+ /* @__PURE__ */ (0, h.jsx)(k, { className: "h-6 w-6 text-destructive opacity-60" }),
265
+ /* @__PURE__ */ (0, h.jsx)("p", {
266
+ className: "text-xs text-destructive font-medium",
267
+ children: "Failed to load chart data"
268
+ }),
269
+ /* @__PURE__ */ (0, h.jsx)("p", {
270
+ className: "text-xs text-muted-foreground max-w-xs text-center",
271
+ children: _
272
+ })
273
+ ]
274
+ }) : !i && t.objectName && S.length === 0 ? /* @__PURE__ */ (0, h.jsxs)("div", {
132
275
  className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (t.className || ""),
276
+ "data-testid": "chart-no-datasource",
133
277
  children: [
134
- "No data source available for \"",
278
+ "No data source available for ",
135
279
  t.objectName,
136
- "\""
280
+ ""
137
281
  ]
138
- }) : /* @__PURE__ */ (0, d.jsx)(h, {
282
+ }) : /* @__PURE__ */ (0, h.jsx)(y, {
139
283
  ...e,
140
- schema: b
284
+ schema: C
141
285
  });
142
286
  };
143
- t.register("object-chart", _, {
287
+ t.register("object-chart", N, {
144
288
  namespace: "plugin-charts",
145
289
  label: "Object Chart",
146
290
  category: "view",
@@ -172,11 +316,11 @@ t.register("object-chart", _, {
172
316
  });
173
317
  //#endregion
174
318
  //#region src/index.tsx
175
- var v = {
176
- "bar-chart": m,
177
- chart: h
319
+ var P = {
320
+ "bar-chart": v,
321
+ chart: y
178
322
  };
179
- t.register("bar-chart", m, {
323
+ t.register("bar-chart", v, {
180
324
  namespace: "plugin-charts",
181
325
  label: "Bar Chart",
182
326
  category: "plugin",
@@ -240,7 +384,7 @@ t.register("bar-chart", m, {
240
384
  height: 400,
241
385
  color: "#8884d8"
242
386
  }
243
- }), t.register("chart", _, {
387
+ }), t.register("chart", N, {
244
388
  namespace: "view",
245
389
  category: "view",
246
390
  label: "Chart",
@@ -267,7 +411,7 @@ t.register("bar-chart", m, {
267
411
  label: "Value Field"
268
412
  }
269
413
  ]
270
- }), t.register("chart", h, {
414
+ }), t.register("chart", y, {
271
415
  namespace: "plugin-charts",
272
416
  label: "Chart",
273
417
  category: "plugin",
@@ -379,31 +523,31 @@ t.register("bar-chart", m, {
379
523
  xAxisKey: "name",
380
524
  series: [{ dataKey: "sales" }, { dataKey: "revenue" }]
381
525
  }
382
- }), t.register("chart:bar", h, {
526
+ }), t.register("chart:bar", y, {
383
527
  namespace: "plugin-charts",
384
528
  label: "Bar Chart (Alias)",
385
529
  category: "plugin",
386
530
  defaultProps: { chartType: "bar" }
387
- }), t.register("pie-chart", h, {
531
+ }), t.register("pie-chart", y, {
388
532
  namespace: "plugin-charts",
389
533
  label: "Pie Chart",
390
534
  category: "plugin",
391
535
  defaultProps: { chartType: "pie" }
392
- }), t.register("donut-chart", h, {
536
+ }), t.register("donut-chart", y, {
393
537
  namespace: "plugin-charts",
394
538
  label: "Donut Chart",
395
539
  category: "plugin",
396
540
  defaultProps: { chartType: "donut" }
397
- }), t.register("radar-chart", h, {
541
+ }), t.register("radar-chart", y, {
398
542
  namespace: "plugin-charts",
399
543
  label: "Radar Chart",
400
544
  category: "plugin",
401
545
  defaultProps: { chartType: "radar" }
402
- }), t.register("scatter-chart", h, {
546
+ }), t.register("scatter-chart", y, {
403
547
  namespace: "plugin-charts",
404
548
  label: "Scatter Chart",
405
549
  category: "plugin",
406
550
  defaultProps: { chartType: "scatter" }
407
551
  });
408
552
  //#endregion
409
- export { m as ChartBarRenderer, h as ChartRenderer, _ as ObjectChart, v as chartComponents };
553
+ export { v as ChartBarRenderer, y as ChartRenderer, N as ObjectChart, P as chartComponents };