@nubitio/dashboard 0.11.4 → 1.0.0-rc.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.
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
+ import { i as formatDashboardValue, n as resolveArray, r as resolvePath, t as DEFAULT_CHART_COLORS } from "./chartPalette-VDQwLcM-.mjs";
1
2
  import { AppToolbar, Badge, DateRangePicker, EmptyState, IconButton, Popover, SegmentedControl, StatCard } from "@nubitio/ui";
2
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useCallback, useMemo, useState } from "react";
4
+ import { Suspense, lazy, useCallback, useMemo, useState } from "react";
4
5
  import { Link, useSearchParams } from "react-router-dom";
5
6
  import { useQuery } from "@tanstack/react-query";
6
- import { getCoreCurrency, getCoreLocale, useCoreHttpClient } from "@nubitio/core";
7
- import { Area, AreaChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
7
+ import { useCoreHttpClient } from "@nubitio/core";
8
8
  //#region packages/dashboard/dashboard/defineDashboard.ts
9
9
  const dashboardCache = /* @__PURE__ */ new Map();
10
10
  function cacheKey(config) {
@@ -299,202 +299,6 @@ function isWidgetTypeRegistered(type) {
299
299
  return registry.has(type);
300
300
  }
301
301
  //#endregion
302
- //#region packages/dashboard/dashboard/chartPalette.ts
303
- const DEFAULT_CHART_COLORS = [
304
- "var(--accent-color)",
305
- "var(--success-color)",
306
- "var(--warning-color)",
307
- "var(--info-color)",
308
- "#6b4fc8",
309
- "#c2410c"
310
- ];
311
- //#endregion
312
- //#region packages/dashboard/dashboard/formatValue.ts
313
- function formatDashboardValue(value, format = "text") {
314
- if (value === null || value === void 0) return "—";
315
- if (format === "text") return String(value);
316
- if (format === "date" || format === "datetime") {
317
- const date = value instanceof Date ? value : new Date(String(value));
318
- if (Number.isNaN(date.getTime())) return String(value);
319
- return new Intl.DateTimeFormat(getCoreLocale(), {
320
- dateStyle: format === "date" ? "medium" : void 0,
321
- timeStyle: format === "datetime" ? "short" : void 0
322
- }).format(date);
323
- }
324
- const numeric = typeof value === "number" ? value : Number(value);
325
- if (!Number.isFinite(numeric)) return String(value);
326
- const baseOptions = {
327
- minimumFractionDigits: format === "currency" ? 2 : void 0,
328
- maximumFractionDigits: format === "currency" ? 2 : void 0
329
- };
330
- if (format === "currency") {
331
- const currency = getCoreCurrency();
332
- if (!currency) return new Intl.NumberFormat(getCoreLocale(), baseOptions).format(numeric);
333
- return new Intl.NumberFormat(getCoreLocale(), {
334
- ...baseOptions,
335
- style: "currency",
336
- currency,
337
- currencyDisplay: "narrowSymbol"
338
- }).format(numeric);
339
- }
340
- if (format === "percent") {
341
- const normalized = Math.abs(numeric) <= 1 ? numeric : numeric / 100;
342
- return new Intl.NumberFormat(getCoreLocale(), {
343
- style: "percent",
344
- minimumFractionDigits: 1,
345
- maximumFractionDigits: 1
346
- }).format(normalized);
347
- }
348
- return new Intl.NumberFormat(getCoreLocale()).format(numeric);
349
- }
350
- //#endregion
351
- //#region packages/dashboard/dashboard/resolvePath.ts
352
- function resolvePath(source, path) {
353
- if (path === void 0 || path === "") return source;
354
- if (source === null || source === void 0) return void 0;
355
- return path.split(".").reduce((current, segment) => {
356
- if (current === null || current === void 0) return void 0;
357
- if (typeof current !== "object") return void 0;
358
- return current[segment];
359
- }, source);
360
- }
361
- function resolveArray(source, path) {
362
- const value = resolvePath(source, path);
363
- if (!Array.isArray(value)) return [];
364
- return value.filter((item) => item !== null && typeof item === "object");
365
- }
366
- //#endregion
367
- //#region packages/dashboard/dashboard/widgets/ChartTooltip.tsx
368
- function ChartTooltip({ active, label, payload, labelFormat, series }) {
369
- if (!active || !payload?.length) return null;
370
- return /* @__PURE__ */ jsxs("div", {
371
- className: "nb-dashboard-chart-tooltip",
372
- children: [label !== void 0 && /* @__PURE__ */ jsx("div", {
373
- className: "nb-dashboard-chart-tooltip__label",
374
- children: label
375
- }), /* @__PURE__ */ jsx("ul", {
376
- className: "nb-dashboard-chart-tooltip__items",
377
- children: payload.map((item) => {
378
- const seriesConfig = series?.find((s) => s.key === item.dataKey);
379
- return /* @__PURE__ */ jsxs("li", {
380
- className: "nb-dashboard-chart-tooltip__item",
381
- children: [
382
- /* @__PURE__ */ jsx("span", {
383
- className: "nb-dashboard-chart-tooltip__swatch",
384
- style: { background: item.color }
385
- }),
386
- /* @__PURE__ */ jsx("span", {
387
- className: "nb-dashboard-chart-tooltip__name",
388
- children: item.name
389
- }),
390
- /* @__PURE__ */ jsx("span", {
391
- className: "nb-dashboard-chart-tooltip__value",
392
- children: formatDashboardValue(item.value, seriesConfig?.valueFormat ?? labelFormat)
393
- })
394
- ]
395
- }, String(item.dataKey));
396
- })
397
- })]
398
- });
399
- }
400
- //#endregion
401
- //#region packages/dashboard/dashboard/widgets/AreaChartWidgetView.tsx
402
- function AreaChartWidgetView({ widget, data, loading }) {
403
- const rows = resolveArray(data, widget.dataPath);
404
- const height = widget.height ?? 240;
405
- return /* @__PURE__ */ jsx(StatCard, {
406
- title: widget.title,
407
- headerExtra: widget.subtitle ? /* @__PURE__ */ jsx("span", {
408
- className: "nb-dashboard-widget__subtitle",
409
- children: widget.subtitle
410
- }) : void 0,
411
- menuVisible: widget.menuVisible,
412
- isLoading: loading,
413
- className: "nb-dashboard-chart-card",
414
- children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
415
- className: "nb-dashboard-chart-empty",
416
- children: "No data"
417
- }) : /* @__PURE__ */ jsx("div", {
418
- style: { height },
419
- children: /* @__PURE__ */ jsx(ResponsiveContainer, {
420
- width: "100%",
421
- height: "100%",
422
- children: /* @__PURE__ */ jsxs(AreaChart, {
423
- data: rows,
424
- margin: {
425
- top: 4,
426
- right: 8,
427
- bottom: 0,
428
- left: 0
429
- },
430
- children: [
431
- /* @__PURE__ */ jsx("defs", { children: widget.series.map((series, index) => {
432
- const color = series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length];
433
- return /* @__PURE__ */ jsxs("linearGradient", {
434
- id: `nb-area-${widget.id}-${series.key}`,
435
- x1: "0",
436
- y1: "0",
437
- x2: "0",
438
- y2: "1",
439
- children: [/* @__PURE__ */ jsx("stop", {
440
- offset: "5%",
441
- stopColor: color,
442
- stopOpacity: .35
443
- }), /* @__PURE__ */ jsx("stop", {
444
- offset: "95%",
445
- stopColor: color,
446
- stopOpacity: .02
447
- })]
448
- }, series.key);
449
- }) }),
450
- widget.showGrid !== false && /* @__PURE__ */ jsx(CartesianGrid, {
451
- strokeDasharray: "3 3",
452
- stroke: "var(--border-color)",
453
- vertical: false
454
- }),
455
- /* @__PURE__ */ jsx(XAxis, {
456
- dataKey: widget.xKey,
457
- tick: {
458
- fontSize: 11,
459
- fill: "var(--text-tertiary)"
460
- },
461
- axisLine: { stroke: "var(--border-color)" },
462
- tickLine: false
463
- }),
464
- /* @__PURE__ */ jsx(YAxis, {
465
- tick: {
466
- fontSize: 11,
467
- fill: "var(--text-tertiary)"
468
- },
469
- axisLine: false,
470
- tickLine: false,
471
- width: 48,
472
- tickFormatter: (v) => formatDashboardValue(v, widget.valueFormat)
473
- }),
474
- /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltip, {
475
- labelFormat: widget.valueFormat,
476
- series: widget.series
477
- }) }),
478
- widget.showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 } }),
479
- widget.series.map((series, index) => {
480
- const color = series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length];
481
- return /* @__PURE__ */ jsx(Area, {
482
- type: "monotone",
483
- dataKey: series.key,
484
- name: series.label ?? series.key,
485
- stroke: color,
486
- strokeWidth: 2,
487
- fill: `url(#nb-area-${widget.id}-${series.key})`,
488
- stackId: widget.stacked ? "stack" : void 0
489
- }, series.key);
490
- })
491
- ]
492
- })
493
- })
494
- })
495
- });
496
- }
497
- //#endregion
498
302
  //#region packages/dashboard/dashboard/widgets/BarChartWidgetView.tsx
499
303
  function toNumber$2(value) {
500
304
  const numeric = typeof value === "number" ? value : Number(value);
@@ -646,81 +450,6 @@ function DonutChartWidgetView({ widget, data, loading }) {
646
450
  });
647
451
  }
648
452
  //#endregion
649
- //#region packages/dashboard/dashboard/widgets/LineChartWidgetView.tsx
650
- function LineChartWidgetView({ widget, data, loading }) {
651
- const rows = resolveArray(data, widget.dataPath);
652
- const height = widget.height ?? 240;
653
- return /* @__PURE__ */ jsx(StatCard, {
654
- title: widget.title,
655
- headerExtra: widget.subtitle ? /* @__PURE__ */ jsx("span", {
656
- className: "nb-dashboard-widget__subtitle",
657
- children: widget.subtitle
658
- }) : void 0,
659
- menuVisible: widget.menuVisible,
660
- isLoading: loading,
661
- className: "nb-dashboard-chart-card",
662
- children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
663
- className: "nb-dashboard-chart-empty",
664
- children: "No data"
665
- }) : /* @__PURE__ */ jsx("div", {
666
- style: { height },
667
- children: /* @__PURE__ */ jsx(ResponsiveContainer, {
668
- width: "100%",
669
- height: "100%",
670
- children: /* @__PURE__ */ jsxs(LineChart, {
671
- data: rows,
672
- margin: {
673
- top: 4,
674
- right: 8,
675
- bottom: 0,
676
- left: 0
677
- },
678
- children: [
679
- widget.showGrid !== false && /* @__PURE__ */ jsx(CartesianGrid, {
680
- strokeDasharray: "3 3",
681
- stroke: "var(--border-color)",
682
- vertical: false
683
- }),
684
- /* @__PURE__ */ jsx(XAxis, {
685
- dataKey: widget.xKey,
686
- tick: {
687
- fontSize: 11,
688
- fill: "var(--text-tertiary)"
689
- },
690
- axisLine: { stroke: "var(--border-color)" },
691
- tickLine: false
692
- }),
693
- /* @__PURE__ */ jsx(YAxis, {
694
- tick: {
695
- fontSize: 11,
696
- fill: "var(--text-tertiary)"
697
- },
698
- axisLine: false,
699
- tickLine: false,
700
- width: 48,
701
- tickFormatter: (v) => formatDashboardValue(v, widget.valueFormat)
702
- }),
703
- /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltip, {
704
- labelFormat: widget.valueFormat,
705
- series: widget.series
706
- }) }),
707
- widget.showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 } }),
708
- widget.series.map((series, index) => /* @__PURE__ */ jsx(Line, {
709
- type: widget.curved === false ? "linear" : "monotone",
710
- dataKey: series.key,
711
- name: series.label ?? series.key,
712
- stroke: series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length],
713
- strokeWidth: 2,
714
- dot: false,
715
- activeDot: { r: 4 }
716
- }, series.key))
717
- ]
718
- })
719
- })
720
- })
721
- });
722
- }
723
- //#endregion
724
453
  //#region packages/dashboard/dashboard/widgets/ProgressWidgetView.tsx
725
454
  function toNumber(value, fallback) {
726
455
  const numeric = typeof value === "number" ? value : Number(value);
@@ -864,8 +593,8 @@ function TableWidgetView({ widget, data, loading }) {
864
593
  registerWidgetType("stat", StatWidgetView);
865
594
  registerWidgetType("bar-chart", BarChartWidgetView);
866
595
  registerWidgetType("donut-chart", DonutChartWidgetView);
867
- registerWidgetType("line-chart", LineChartWidgetView);
868
- registerWidgetType("area-chart", AreaChartWidgetView);
596
+ registerWidgetType("line-chart", lazy(() => import("./LineChartWidgetView-gNlby0Gq.mjs").then((m) => ({ default: m.LineChartWidgetView }))));
597
+ registerWidgetType("area-chart", lazy(() => import("./AreaChartWidgetView-BBp9C1bD.mjs").then((m) => ({ default: m.AreaChartWidgetView }))));
869
598
  registerWidgetType("progress", ProgressWidgetView);
870
599
  registerWidgetType("table", TableWidgetView);
871
600
  //#endregion
@@ -877,10 +606,16 @@ function WidgetRenderer({ widget, data, loading }) {
877
606
  if (isDev) console.warn(`[@nubitio/dashboard] No widget registered for type "${widget.type}".`);
878
607
  return null;
879
608
  }
880
- return /* @__PURE__ */ jsx(Component, {
881
- widget,
882
- data,
883
- loading
609
+ return /* @__PURE__ */ jsx(Suspense, {
610
+ fallback: /* @__PURE__ */ jsx("div", {
611
+ className: "nb-dashboard-widget-loading",
612
+ style: { height: "100%" }
613
+ }),
614
+ children: /* @__PURE__ */ jsx(Component, {
615
+ widget,
616
+ data,
617
+ loading
618
+ })
884
619
  });
885
620
  }
886
621
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/dashboard",
3
- "version": "0.11.4",
3
+ "version": "1.0.0-rc.1",
4
4
  "type": "module",
5
5
  "description": "Declarative dashboard engine with stat cards, charts, and data tables for Nubit admin apps.",
6
6
  "license": "MIT",
@@ -54,13 +54,18 @@
54
54
  "@tanstack/react-query": "^5.0.0",
55
55
  "react": "^18.2.0 || ^19.0.0",
56
56
  "react-dom": "^18.2.0 || ^19.0.0",
57
- "react-router-dom": "^6.0.0",
57
+ "react-router-dom": "^6.0.0 || ^7.0.0",
58
58
  "recharts": "^3.0.0",
59
- "@nubitio/core": "^0.11.4",
60
- "@nubitio/ui": "^0.11.4"
59
+ "@nubitio/core": "^1.0.0-rc.1",
60
+ "@nubitio/ui": "^1.0.0-rc.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@tanstack/react-query": "^5.0.0",
64
64
  "recharts": "^3.9.2"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "recharts": {
68
+ "optional": true
69
+ }
65
70
  }
66
71
  }