@dashspec/renderer 0.1.4 → 0.1.6

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.js CHANGED
@@ -115,7 +115,7 @@ import {
115
115
  translator,
116
116
  validateDocument,
117
117
  widgetChecks
118
- } from "./chunk-2HHYJ5WX.js";
118
+ } from "./chunk-U4JCC3MX.js";
119
119
  import {
120
120
  createStateProxy,
121
121
  getPath,
@@ -1644,6 +1644,12 @@ function themeCssVars(theme, mode) {
1644
1644
  out["--ds-control-height"] = `${d.control}px`;
1645
1645
  out["--ds-density"] = density;
1646
1646
  flatten("--ds-radius", s.radius, out, "px");
1647
+ out["--ds-chip-radius"] = `${s.chip?.radius ?? 6}px`;
1648
+ out["--ds-chip-border"] = `${s.chip?.border ?? 1}px`;
1649
+ out["--ds-chip-weight"] = String(s.chip?.weight ?? 600);
1650
+ out["--ds-chip-padding-x"] = `${s.chip?.paddingX ?? 8}px`;
1651
+ out["--ds-chip-height"] = `${s.chip?.height ?? 22}px`;
1652
+ out["--ds-chip-font-size"] = `${s.chip?.fontSize ?? 11}px`;
1647
1653
  flatten("--ds-shadow", s.shadow, out);
1648
1654
  flatten("--ds-z", s.z, out);
1649
1655
  out["--ds-motion-fast"] = `${s.motion.fast}ms`;
@@ -3148,13 +3154,14 @@ function FilterBar() {
3148
3154
  useCallback2(
3149
3155
  (t) => ({
3150
3156
  filters: t.filters,
3157
+ view: t.view,
3151
3158
  visible: variables.filter(
3152
3159
  (v) => typeof v.visibleWhen !== "string" || Boolean(evaluateSafe(v.visibleWhen, rootScope(t, runtime.helpers), true))
3153
3160
  ).map((v) => v.name).join("\0")
3154
3161
  }),
3155
3162
  [variables, runtime]
3156
3163
  ),
3157
- (a, b) => a.filters === b.filters && a.visible === b.visible
3164
+ (a, b) => a.filters === b.filters && a.visible === b.visible && a.view === b.view
3158
3165
  );
3159
3166
  const visibleNames = new Set(state.visible.split("\0"));
3160
3167
  const [draft, setDraft] = useState2(null);
@@ -3179,6 +3186,48 @@ function FilterBar() {
3179
3186
  if (shown.length === 0 || bar.show === false) return null;
3180
3187
  const values = { ...state.filters, ...draft };
3181
3188
  const set = (name, value, apply) => apply ? runtime.store.dispatch(stateActions.setFilter({ name, value })) : setDraft((d) => ({ ...d, [name]: value }));
3189
+ const Custom = options.ui?.FilterBar;
3190
+ if (Custom && !options.onFilterSelect) {
3191
+ const layouts = runtime.doc.spec.layouts ?? [];
3192
+ const views = [];
3193
+ for (const l of layouts)
3194
+ if (l.view && !views.some((v) => v.name === l.view)) views.push({ name: l.view, label: l.label ?? l.view });
3195
+ const byName = new Map(variables.map((v) => [v.name, v]));
3196
+ return /* @__PURE__ */ jsx8(
3197
+ Custom,
3198
+ {
3199
+ filters: shown.map((v) => ({
3200
+ name: v.name,
3201
+ kind: v.kind,
3202
+ ...typeof v.label === "string" ? { label: v.label } : {},
3203
+ config: v
3204
+ })),
3205
+ values,
3206
+ setFilter: (name, value) => runtime.store.dispatch(stateActions.setFilter({ name, value })),
3207
+ reset: () => {
3208
+ setDraft(null);
3209
+ for (const [name, value] of Object.entries(defaults()))
3210
+ runtime.store.dispatch(stateActions.setFilter({ name, value }));
3211
+ },
3212
+ isDefault,
3213
+ views,
3214
+ view: state.view,
3215
+ setView: (view) => runtime.store.dispatch(stateActions.setView(view)),
3216
+ renderControl: (name) => {
3217
+ const def = byName.get(name);
3218
+ return def ? /* @__PURE__ */ jsx8(
3219
+ ControlField,
3220
+ {
3221
+ compact: true,
3222
+ def,
3223
+ value: values[name],
3224
+ onChange: (val) => set(name, val, applyMode(def) === "change")
3225
+ }
3226
+ ) : null;
3227
+ }
3228
+ }
3229
+ );
3230
+ }
3182
3231
  const toolbar = /* @__PURE__ */ jsxs5(
3183
3232
  "div",
3184
3233
  {
@@ -3519,1494 +3568,1499 @@ function InfoTip({ text }) {
3519
3568
  );
3520
3569
  }
3521
3570
 
3522
- // src/widgets/shared/motion.ts
3523
- import { useEffect as useEffect3, useRef as useRef5, useState as useState4 } from "react";
3524
- var reduced = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
3525
- var easeOut = (t) => 1 - (1 - t) ** 3;
3526
- function useCountUp(target, ms = 700) {
3527
- const [shown, setShown] = useState4(() => typeof target === "number" && !reduced() ? 0 : target);
3528
- const from = useRef5(0);
3529
- useEffect3(() => {
3530
- if (typeof target !== "number" || !Number.isFinite(target) || reduced()) {
3531
- setShown(target);
3532
- return;
3533
- }
3534
- const start = performance.now();
3535
- const a = from.current;
3536
- let raf = 0;
3537
- const step = (now) => {
3538
- const t = Math.min(1, (now - start) / ms);
3539
- const v = a + (target - a) * easeOut(t);
3540
- setShown(Number.isInteger(target) && t === 1 ? target : v);
3541
- if (t < 1) raf = requestAnimationFrame(step);
3542
- else from.current = target;
3543
- };
3544
- raf = requestAnimationFrame(step);
3545
- return () => {
3546
- cancelAnimationFrame(raf);
3547
- from.current = typeof target === "number" ? target : 0;
3548
- };
3549
- }, [target, ms]);
3550
- return shown;
3551
- }
3571
+ // src/widgets/shared/clickable.ts
3572
+ import { useContext as useContext4 } from "react";
3552
3573
 
3553
- // src/widgets/builtins/Kpi.tsx
3554
- import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
3555
- var Kpi = defineWidget({
3556
- ...KpiContract,
3557
- implements: "kpi",
3558
- header: "widget",
3559
- empty: "widget",
3560
- meta: { label: "KPI", icon: "kpi", category: "Numbers", size: { w: 3, h: 4, minW: 2, minH: 3 } },
3561
- events: ["click", "hover"],
3562
- parts: ["value"],
3563
- defaults: { title: "New KPI", goodWhen: "up" },
3564
- component: function KpiWidget({ spec, data, source, emit, helpers }) {
3565
- const num = (v) => typeof v === "number" ? v : toNumber(field(source, v));
3566
- const value = toNumber(data) ?? data;
3567
- const animated = useCountUp(value);
3568
- const n = toNumber(value);
3569
- const fmt = (v) => formatValue(v, helpers, spec.format, spec.decimals);
3570
- const unit = spec.format === "duration" ? void 0 : spec.unit;
3571
- const empty = spec.empty === true || value === void 0 || value === null || value === "";
3572
- const hasTarget = spec.target !== void 0;
3573
- const target = hasTarget ? num(spec.target) : void 0;
3574
- const op = spec.goodWhen === "down" ? "\u2264 " : spec.goodWhen === "up" ? "\u2265 " : "";
3575
- const targetText = spec.targetLabel ?? (target !== void 0 ? `Target: ${op}${fmt(target)}${unit ? spec.format === "percent" ? "" : ` ${unit.toLowerCase()}` : ""}` : void 0);
3576
- const met = target === void 0 || n === void 0 || spec.goodWhen === "none" ? void 0 : spec.goodWhen === "down" ? n <= target : n >= target;
3577
- const labels = { good: spec.statusLabels?.good ?? "On track", bad: spec.statusLabels?.bad ?? "Action needed" };
3578
- const ref = spec.compare === void 0 ? void 0 : typeof spec.compare === "number" ? spec.compare : spec.compare.value !== void 0 ? toNumber(spec.compare.value) : toNumber(field(source, spec.compare.path));
3579
- const delta = n !== void 0 && ref !== void 0 ? n - ref : void 0;
3580
- const better = delta === void 0 || delta === 0 || spec.goodWhen === "none" ? void 0 : delta > 0 === (spec.goodWhen === "up");
3581
- const low = spec.band ? num(spec.band.low) : void 0;
3582
- const high = spec.band ? num(spec.band.high) : void 0;
3583
- const outside = n !== void 0 && (low !== void 0 && n < low || high !== void 0 && n > high);
3584
- const pTarget = spec.progress ? num(spec.progress.target) : void 0;
3585
- const ratio = n !== void 0 && pTarget ? Math.min(spec.progress?.cap ?? Number.POSITIVE_INFINITY, n / pTarget * 100) : void 0;
3586
- return /* @__PURE__ */ jsxs8("div", { className: "ds-kpi", "data-size": spec.size, children: [
3587
- /* @__PURE__ */ jsxs8("div", { className: "ds-kpi-label", children: [
3588
- /* @__PURE__ */ jsx13("span", { children: spec.title }),
3589
- spec.info && /* @__PURE__ */ jsx13(InfoTip, { text: spec.info })
3590
- ] }),
3591
- /* @__PURE__ */ jsx13(
3592
- "button",
3593
- {
3594
- type: "button",
3595
- className: "ds-kpi-main",
3596
- onClick: () => emit("click", "value", { datum: source, value }),
3597
- onMouseEnter: () => emit("hover", "value", { datum: source, value }),
3598
- "aria-label": `${spec.title ?? "Value"}: ${empty ? spec.emptyText ?? "no value" : fmt(value)}${unit ? ` ${unit}` : ""}`,
3599
- children: empty ? (
3600
- // No value is not zero: the author's text, else a dash.
3601
- /* @__PURE__ */ jsx13("span", { className: "ds-kpi-empty", children: spec.emptyText || "\u2014" })
3602
- ) : /* @__PURE__ */ jsxs8(Fragment4, { children: [
3603
- /* @__PURE__ */ jsx13(
3604
- "span",
3605
- {
3606
- className: "ds-kpi-value",
3607
- style: { color: spec.tone ? tone(spec.tone).fg : outside ? tone("bad").fg : void 0 },
3608
- children: fmt(animated)
3609
- }
3610
- ),
3611
- unit && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-unit", children: unit })
3612
- ] })
3613
- }
3614
- ),
3615
- delta !== void 0 && /* @__PURE__ */ jsxs8(
3616
- "span",
3617
- {
3618
- className: "ds-kpi-delta",
3619
- style: { color: tone(better === void 0 ? "neutral" : better ? "good" : "bad").fg },
3620
- children: [
3621
- delta > 0 ? "\u2191" : delta < 0 ? "\u2193" : "\u2192",
3622
- " ",
3623
- spec.format === "duration" ? helpers.fmt.duration(Math.abs(delta)) : `${helpers.fmt.number(Math.abs(ref ? delta / Math.abs(ref) * 100 : 0), 1)}%`,
3624
- typeof spec.compare === "object" && spec.compare.label && /* @__PURE__ */ jsxs8("span", { className: "ds-kpi-sub", children: [
3625
- " ",
3626
- spec.compare.label
3627
- ] })
3628
- ]
3629
- }
3630
- ),
3631
- spec.note && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-sub", children: spec.note }),
3632
- spec.sublabel && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-sub", children: spec.sublabel }),
3633
- low !== void 0 && high !== void 0 && /* @__PURE__ */ jsxs8("span", { className: "ds-kpi-sub", children: [
3634
- "Expected ",
3635
- fmt(low),
3636
- "\u2013",
3637
- fmt(high)
3638
- ] }),
3639
- ratio !== void 0 && // biome-ignore lint/a11y/useFocusableInteractive: a progress bar is read-only, not interactive
3640
- /* @__PURE__ */ jsx13(
3641
- "span",
3642
- {
3643
- className: "ds-progress",
3644
- role: "progressbar",
3645
- "aria-valuenow": Math.round(ratio),
3646
- "aria-valuemin": 0,
3647
- "aria-valuemax": 100,
3648
- children: /* @__PURE__ */ jsx13(
3649
- "span",
3650
- {
3651
- style: { width: `${Math.min(100, ratio)}%`, background: tone(ratio >= 100 ? "good" : "info").solid }
3652
- }
3653
- )
3654
- }
3655
- ),
3656
- (hasTarget || targetText) && /* @__PURE__ */ jsxs8("div", { className: "ds-kpi-foot", children: [
3657
- hasTarget && target === void 0 ? /* @__PURE__ */ jsx13("span", { className: "ds-chip", "data-tone": "bad", children: spec.targetMissing }) : /* @__PURE__ */ jsx13("span", { "data-ds-part": "target", children: targetText }),
3658
- spec.badge !== false && met !== void 0 && !empty && /* @__PURE__ */ jsx13("span", { className: "ds-chip", "data-tone": met ? "good" : "bad", "data-ds-part": "badge", children: met ? labels.good : labels.bad })
3659
- ] })
3660
- ] });
3661
- }
3662
- });
3574
+ // src/components/PanelFrame.tsx
3575
+ import { useCallback as useCallback4, useEffect as useEffect3, useId as useId3, useMemo as useMemo3, useRef as useRef5, useState as useState4 } from "react";
3663
3576
 
3664
- // src/widgets/builtins/Sparkline.tsx
3665
- import "zod";
3666
- import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
3667
- function sparkPath(values, w, h, pad = 2) {
3668
- if (values.length === 0) return { line: "", area: "" };
3669
- const min = values.reduce((a, b) => Math.min(a, b));
3670
- const max = values.reduce((a, b) => Math.max(a, b));
3671
- const span = max - min || 1;
3672
- const step = values.length > 1 ? (w - pad * 2) / (values.length - 1) : 0;
3673
- const pts = values.map((v, i) => [pad + i * step, h - pad - (v - min) / span * (h - pad * 2)]);
3674
- const line = pts.map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
3675
- const last = pts[pts.length - 1];
3676
- return { line, area: `${line} L${last[0].toFixed(1)},${h} L${pad},${h} Z` };
3677
- }
3678
- function SparkSvg({
3679
- values,
3680
- area = true,
3681
- height = 32,
3682
- color: color2 = "var(--ds-series-1)"
3683
- }) {
3684
- const w = 120;
3685
- const { line, area: fill } = sparkPath(values, w, height);
3686
- return /* @__PURE__ */ jsxs9("svg", { viewBox: `0 0 ${w} ${height}`, preserveAspectRatio: "none", style: { width: "100%", height }, "aria-hidden": "true", children: [
3687
- area && /* @__PURE__ */ jsx14("path", { d: fill, fill: color2, opacity: 0.15 }),
3688
- /* @__PURE__ */ jsx14("path", { d: line, fill: "none", stroke: color2, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" })
3689
- ] });
3577
+ // src/widgets/parseProps.ts
3578
+ function without(value, path) {
3579
+ if (path.length === 0 || value === null || typeof value !== "object") return value;
3580
+ const [head, ...rest] = path;
3581
+ if (Array.isArray(value)) {
3582
+ if (typeof head !== "number" || head < 0 || head >= value.length) return value;
3583
+ const copy2 = [...value];
3584
+ if (rest.length === 0) copy2.splice(head, 1);
3585
+ else copy2[head] = without(copy2[head], rest);
3586
+ return copy2;
3587
+ }
3588
+ if (!Object.hasOwn(value, head)) return value;
3589
+ const copy = { ...value };
3590
+ if (rest.length === 0) delete copy[head];
3591
+ else copy[head] = without(copy[head], rest);
3592
+ return copy;
3690
3593
  }
3691
- var Sparkline = defineWidget({
3692
- ...SparklineContract,
3693
- implements: "chart",
3694
- meta: { label: "Sparkline", icon: "sparkline", category: "Charts", size: { w: 3, h: 2, minW: 2, minH: 1 } },
3695
- events: ["hover"],
3696
- defaults: { y: "value" },
3697
- component: function SparklineWidget({ spec, data, size: size2, emit }) {
3698
- const rows = asRows(data);
3699
- const values = rows.map((r) => toNumber(field(r, spec.y)) ?? 0);
3700
- return /* @__PURE__ */ jsx14(
3701
- "div",
3702
- {
3703
- onMouseEnter: () => emit("hover", "line", { value: values[values.length - 1] }),
3704
- style: { height: "100%" },
3705
- role: "img",
3706
- "aria-label": `${spec.title ?? spec.y}: ${values.length} points`,
3707
- children: /* @__PURE__ */ jsx14(SparkSvg, { values, area: spec.area, height: Math.max(24, size2.height || 32) })
3708
- }
3709
- );
3594
+ function parseWidgetProps(schema, props) {
3595
+ let current = props;
3596
+ const dropped = [];
3597
+ for (let round = 0; round < 25; round++) {
3598
+ const r = schema.safeParse(current);
3599
+ if (r.success) return { props: r.data, dropped };
3600
+ const issue = r.error.issues.find((i) => i.path.length > 0);
3601
+ if (!issue) break;
3602
+ const lastIndex = issue.path.reduce((at, k, i) => typeof k === "number" ? i : at, -1);
3603
+ const path = lastIndex >= 0 ? issue.path.slice(0, lastIndex + 1) : issue.path;
3604
+ const next = without(current, path);
3605
+ if (next === current) break;
3606
+ dropped.push(path.join("."));
3607
+ current = next;
3710
3608
  }
3711
- });
3609
+ return { props, dropped };
3610
+ }
3712
3611
 
3713
- // src/widgets/builtins/StageTracker.tsx
3714
- import "zod";
3715
- import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
3716
- var StageTracker = defineWidget({
3717
- ...StageTrackerContract,
3718
- implements: "stages",
3719
- meta: { label: "Stage tracker", icon: "stages", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
3720
- events: ["click"],
3721
- parts: ["stage"],
3722
- component: function StageTrackerWidget({ spec, data, emit }) {
3723
- const raw = typeof data === "string" || typeof data === "number" ? data : field(data, spec.current);
3724
- const idx = typeof raw === "number" ? raw : spec.stages.findIndex((s) => s.toLowerCase() === String(raw ?? "").toLowerCase());
3725
- return /* @__PURE__ */ jsx15("ol", { className: "ds-stages", children: spec.stages.map((s, i) => {
3726
- const state = i < idx ? "done" : i === idx ? "current" : "todo";
3727
- return /* @__PURE__ */ jsx15("li", { "data-state": state, children: /* @__PURE__ */ jsxs10(
3728
- "button",
3729
- {
3730
- type: "button",
3731
- onClick: () => emit("click", "stage", { value: s, index: i, datum: data }),
3732
- "aria-current": state === "current" ? "step" : void 0,
3733
- children: [
3734
- /* @__PURE__ */ jsx15("span", { className: "ds-stage-dot", "aria-hidden": "true", children: state === "done" ? "\u2713" : i + 1 }),
3735
- s
3736
- ]
3737
- }
3738
- ) }, s);
3739
- }) });
3612
+ // src/components/Boundary.tsx
3613
+ import { Component } from "react";
3614
+ var sameKeys = (a, b) => a.length === b.length && a.every((x, i) => Object.is(x, b[i]));
3615
+ var Boundary = class extends Component {
3616
+ state = { error: null };
3617
+ static getDerivedStateFromError(error) {
3618
+ return { error };
3740
3619
  }
3741
- });
3620
+ componentDidCatch(error, _info) {
3621
+ this.props.onError?.(error);
3622
+ }
3623
+ componentDidUpdate(prev) {
3624
+ if (this.state.error && !sameKeys(prev.resetKeys ?? [], this.props.resetKeys ?? [])) this.setState({ error: null });
3625
+ }
3626
+ render() {
3627
+ return this.state.error ? this.props.fallback(this.state.error) : this.props.children;
3628
+ }
3629
+ };
3742
3630
 
3743
- // src/widgets/builtins/StateTimeline.tsx
3744
- import "zod";
3745
- import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
3746
- var StateTimeline = defineWidget({
3747
- ...StateTimelineContract,
3748
- implements: "timeline",
3749
- meta: { label: "State timeline", icon: "timeline", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
3750
- events: ["click", "hover"],
3751
- parts: ["segment"],
3752
- component: function StateTimelineWidget({ spec, data, emit, helpers }) {
3753
- const all = asRows(data).map((r) => ({ r, t: Number(field(r, spec.time)), raw: String(field(r, spec.value) ?? "") })).filter((x) => Number.isFinite(x.t)).sort((a, b) => a.t - b.t);
3754
- const end = helpers.now();
3755
- const start = spec.window ? end - parseDuration(spec.window) : all[0]?.t ?? end;
3756
- const lanes = spec.rows ? [...new Set(all.map((x) => String(field(x.r, spec.rows))))] : [""];
3757
- const span = Math.max(1, end - start);
3758
- const states = /* @__PURE__ */ new Map();
3759
- return /* @__PURE__ */ jsxs11("div", { className: "ds-timeline", children: [
3760
- lanes.map((lane) => {
3761
- const pts = all.filter((x) => !spec.rows || String(field(x.r, spec.rows)) === lane);
3762
- const segs = pts.map((p, i) => {
3763
- const from = Math.max(start, p.t);
3764
- const to = Math.min(end, pts[i + 1]?.t ?? end);
3765
- const state = spec.stateMap?.[p.raw] ?? p.raw;
3766
- states.set(state, (states.get(state) ?? 0) + Math.max(0, to - from));
3767
- return { p, from, to, state };
3768
- });
3769
- return /* @__PURE__ */ jsxs11("div", { className: "ds-timeline-lane", children: [
3770
- lane && /* @__PURE__ */ jsx16("span", { className: "ds-timeline-name", children: lane }),
3771
- /* @__PURE__ */ jsx16("div", { className: "ds-timeline-bar", role: "img", "aria-label": `${spec.title ?? "Timeline"} ${lane}`, children: segs.filter((s) => s.to > s.from).map((s) => (
3772
- // biome-ignore lint/a11y/useKeyWithClickEvents: the per-state totals below summarise the same data for keyboard users
3773
- /* @__PURE__ */ jsx16(
3774
- "span",
3775
- {
3776
- title: `${s.state} \xB7 ${helpers.fmt.date(s.from, "time")}\u2013${helpers.fmt.date(s.to, "time")} (${helpers.fmt.duration((s.to - s.from) / 1e3)})`,
3777
- style: {
3778
- left: `${(s.from - start) / span * 100}%`,
3779
- width: `${(s.to - s.from) / span * 100}%`,
3780
- background: tone(spec.tones?.[s.state] ?? "neutral").solid
3781
- },
3782
- onClick: () => emit("click", "segment", { datum: s.p.r, value: s.state, x: s.from }),
3783
- onMouseEnter: () => emit("hover", "segment", { datum: s.p.r, value: s.state, x: s.from })
3784
- },
3785
- `${s.from}-${s.state}`
3786
- )
3787
- )) })
3788
- ] }, lane);
3789
- }),
3790
- /* @__PURE__ */ jsxs11("div", { className: "ds-timeline-axis", children: [
3791
- /* @__PURE__ */ jsx16("span", { children: helpers.fmt.date(start, "time") }),
3792
- /* @__PURE__ */ jsx16("span", { children: spec.endLabel ?? helpers.fmt.date(end, "time") })
3793
- ] }),
3794
- /* @__PURE__ */ jsx16("ul", { className: "ds-legend", children: [...states.entries()].map(([s, ms]) => /* @__PURE__ */ jsxs11("li", { children: [
3795
- /* @__PURE__ */ jsx16(
3796
- "span",
3797
- {
3798
- className: "ds-dot",
3799
- style: { background: tone(spec.tones?.[s] ?? "neutral").solid },
3800
- "aria-hidden": "true"
3801
- }
3802
- ),
3803
- s,
3804
- " ",
3805
- /* @__PURE__ */ jsx16("strong", { children: helpers.fmt.duration(ms / 1e3) })
3806
- ] }, s)) })
3807
- ] });
3808
- }
3809
- });
3631
+ // src/components/Slot.tsx
3632
+ import { createContext as createContext3, useContext as useContext3 } from "react";
3633
+ import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
3634
+ var NodeScopeContext = createContext3({});
3635
+ var useNodeScope = () => useContext3(NodeScopeContext);
3636
+ var SlotOwnerContext = createContext3(null);
3637
+ var SlotChildContext = createContext3(null);
3638
+ function slotChildren(def, name) {
3639
+ const slots = def?.slots;
3640
+ const list = slots?.[name];
3641
+ return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
3642
+ }
3643
+ function Slot({
3644
+ name,
3645
+ className,
3646
+ style,
3647
+ data,
3648
+ item,
3649
+ index,
3650
+ empty
3651
+ }) {
3652
+ const { options } = useDashboard();
3653
+ const owner = useContext3(SlotOwnerContext);
3654
+ const outer = useNodeScope();
3655
+ const renderChild = useContext3(SlotChildContext);
3656
+ if (!owner || !renderChild) return null;
3657
+ const ids = slotChildren(owner.def, name);
3658
+ const editing = options.mode === "edit";
3659
+ if (ids.length === 0 && !editing) return null;
3660
+ const hasItem = item !== void 0 || outer.hasItem;
3661
+ const scope2 = {
3662
+ parentId: owner.id,
3663
+ parentData: owner.data,
3664
+ data: data !== void 0 ? data : item !== void 0 ? item : owner.data,
3665
+ hasItem: Boolean(hasItem),
3666
+ item: item !== void 0 ? item : outer.item,
3667
+ index: index !== void 0 ? index : outer.index
3668
+ };
3669
+ return /* @__PURE__ */ jsx13(NodeScopeContext.Provider, { value: scope2, children: /* @__PURE__ */ jsxs8(
3670
+ "div",
3671
+ {
3672
+ className: className ? `ds-slot ${className}` : "ds-slot",
3673
+ style,
3674
+ "data-slot": name,
3675
+ "data-owner": owner.id,
3676
+ "data-empty": ids.length === 0 || void 0,
3677
+ children: [
3678
+ ids.map((id) => /* @__PURE__ */ jsx13(SlotItem, { children: renderChild(id) }, id)),
3679
+ ids.length === 0 && editing && (empty ?? /* @__PURE__ */ jsx13("span", { className: "ds-slot-hint", children: "Drop here" }))
3680
+ ]
3681
+ }
3682
+ ) });
3683
+ }
3684
+ var SlotItem = ({ children }) => /* @__PURE__ */ jsx13(Fragment4, { children });
3810
3685
 
3811
- // src/widgets/builtins/Status.tsx
3812
- import "zod";
3813
- import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
3814
- var Status = defineWidget({
3815
- ...StatusContract,
3816
- implements: "badge",
3817
- // A badge, not a card: it can sit anywhere, including in another widget's header.
3818
- frame: "plain",
3819
- meta: { label: "Status badge", icon: "status", category: "Numbers", size: { w: 3, h: 2, minW: 1, minH: 1 } },
3820
- events: ["click"],
3821
- component: function StatusWidget({ spec, data, emit }) {
3822
- const row = asRows(data)[0] ?? {};
3823
- const state = String(field(row, spec.state) ?? "unknown");
3824
- const t = spec.text ? spec.tone ?? "info" : spec.stateMap?.[state] ?? spec.tone ?? "neutral";
3825
- const text = spec.text ?? spec.labels?.[state] ?? state.charAt(0).toUpperCase() + state.slice(1);
3826
- return /* @__PURE__ */ jsxs12("button", { type: "button", className: "ds-status", onClick: () => emit("click", "status", { datum: row, value: state }), children: [
3827
- /* @__PURE__ */ jsxs12("span", { className: "ds-pill", style: { background: tone(t).bg, color: tone(t).fg, borderColor: tone(t).border }, children: [
3828
- /* @__PURE__ */ jsx17("span", { className: "ds-dot", style: { background: tone(t).solid }, "aria-hidden": "true" }),
3829
- text
3830
- ] }),
3831
- spec.label && /* @__PURE__ */ jsx17("span", { className: "ds-status-label", children: String(field(row, spec.label) ?? "") })
3832
- ] });
3686
+ // src/components/PanelFrame.tsx
3687
+ import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
3688
+ var isEmpty = (d) => d === void 0 || d === null || Array.isArray(d) && d.length === 0 || typeof d === "object" && !Array.isArray(d) && Object.keys(d).length === 0;
3689
+ function useSize() {
3690
+ const [size2, setSize] = useState4({ width: 0, height: 0 });
3691
+ const observer = useRef5(null);
3692
+ const ref = useCallback4((el) => {
3693
+ observer.current?.disconnect();
3694
+ observer.current = null;
3695
+ if (!el || typeof ResizeObserver === "undefined") return;
3696
+ const ro = new ResizeObserver(([e]) => {
3697
+ const r = e?.contentRect;
3698
+ if (r)
3699
+ setSize(
3700
+ (s) => s.width === Math.round(r.width) && s.height === Math.round(r.height) ? s : { width: Math.round(r.width), height: Math.round(r.height) }
3701
+ );
3702
+ });
3703
+ ro.observe(el);
3704
+ observer.current = ro;
3705
+ }, []);
3706
+ return [ref, size2];
3707
+ }
3708
+ var DEFERRED = /(^|[^\w.$])(row|item|avg)\b/;
3709
+ var DEFERRED_IN_ITEM = /(^|[^\w.$])(row|avg)\b/;
3710
+ function interpolateMarkdown(v, scope2) {
3711
+ const bodies = placeholders(v);
3712
+ const whole = bodies.length === 1 && v.trim() === `\${${bodies[0]}}`;
3713
+ const r = interpolate(v, scope2, escapeMarkdown);
3714
+ if (!whole) return r;
3715
+ return r === null || r === void 0 ? "" : escapeMarkdown(typeof r === "object" ? JSON.stringify(r) : String(r));
3716
+ }
3717
+ function resolvePanel(v, scope2, inItem = false, key) {
3718
+ const deferred = inItem ? DEFERRED_IN_ITEM : DEFERRED;
3719
+ if (typeof v === "string") {
3720
+ if (placeholders(v).some((b) => deferred.test(stripStrings(b)))) return v;
3721
+ return key === "markdown" ? interpolateMarkdown(v, scope2) : interpolate(v, scope2);
3833
3722
  }
3834
- });
3835
-
3836
- // src/widgets/builtins/Table.tsx
3837
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef6, useState as useState5 } from "react";
3838
- import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
3839
- var ROW_H = 36;
3840
- function pageList(current, pages) {
3841
- if (pages <= 7) return Array.from({ length: pages }, (_, i) => i + 1);
3842
- const set = new Set([1, pages, current - 1, current, current + 1].filter((n) => n >= 1 && n <= pages));
3843
- const sorted = [...set].sort((a, b) => a - b);
3844
- const out = [];
3845
- sorted.forEach((n, i) => {
3846
- if (i > 0 && n - sorted[i - 1] > 1) out.push(0);
3847
- out.push(n);
3848
- });
3849
- return out;
3723
+ if (Array.isArray(v)) return v.map((x) => resolvePanel(x, scope2, inItem));
3724
+ if (v && typeof v === "object")
3725
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolvePanel(x, scope2, inItem, k)]));
3726
+ return v;
3850
3727
  }
3851
- var Table = defineWidget({
3852
- ...TableContract,
3853
- implements: "table",
3854
- exposes: { selection: "the clicked row", page: "current page (ui.page)", search: "search text (ui.search)" },
3855
- meta: { label: "Table", icon: "table", category: "Lists", size: { w: 12, h: 8, minW: 4, minH: 4 } },
3856
- events: ["rowClick", "cellClick", "hover"],
3857
- parts: ["row", "cell"],
3858
- rows: (data) => asRows(data),
3859
- component: function TableWidget({ spec, data, source, emit, helpers, size: size2, state, setUi, status }) {
3860
- const tpl = (t, row, item) => {
3861
- try {
3862
- const v = interpolate(t, scope({ row, item, datum: row }, helpers));
3863
- return v === null || v === void 0 ? "" : String(v);
3864
- } catch {
3865
- return "";
3866
- }
3867
- };
3868
- const base = useMemo3(() => {
3869
- const rows2 = asRows(data);
3870
- return spec.pivot ? applyTransform(rows2, [{ pivot: spec.pivot }], scope()) : rows2;
3871
- }, [data, spec.pivot]);
3872
- const columns = useMemo3(() => {
3873
- if (spec.columns?.length) return spec.columns;
3874
- if (spec.columnsFrom) {
3875
- const cf = spec.columnsFrom;
3876
- return asRows(field(source, cf.path)).map((c) => ({
3877
- key: String(field(c, cf.key)),
3878
- label: String(field(c, cf.label) ?? field(c, cf.key)),
3879
- ...cf.type ? { type: cf.type } : {},
3880
- ...cf.format ? { format: cf.format } : {}
3881
- }));
3882
- }
3883
- return Object.keys(base[0] ?? {}).map((k) => ({ key: k }));
3884
- }, [spec.columns, spec.columnsFrom, source, base]);
3885
- const pg = spec.pagination && spec.pagination.enabled !== false ? spec.pagination : void 0;
3886
- const sr = spec.search === true ? { enabled: true, mode: "client" } : spec.search && spec.search.enabled !== false ? spec.search : void 0;
3887
- const so = spec.sorting ?? { enabled: true, mode: "client" };
3888
- const fl = spec.filtering && spec.filtering.enabled !== false ? spec.filtering : void 0;
3889
- const server = {
3890
- paging: pg?.mode === "server",
3891
- search: sr?.mode === "server",
3892
- sort: so.mode === "server",
3893
- filter: fl?.mode === "server"
3894
- };
3895
- const anyServer = server.paging || server.search || server.sort || server.filter;
3896
- const ui = state.ui ?? {};
3897
- const [view, setView] = useState5(() => ({
3898
- page: Number(ui.page ?? 1),
3899
- pageSize: Number(ui.pageSize ?? pg?.pageSize ?? 20),
3900
- search: String(ui.search ?? ""),
3901
- sortKey: ui.sortKey ?? so.default?.key,
3902
- sortOrder: ui.sortOrder ?? so.default?.order ?? "asc",
3903
- filters: ui.filters ?? {}
3904
- }));
3905
- const update = (patch) => {
3906
- const next = { ...view, ...patch };
3907
- setView(next);
3908
- if (anyServer)
3909
- setUi({
3910
- page: next.page,
3911
- pageSize: next.pageSize,
3912
- offset: (next.page - 1) * next.pageSize,
3913
- search: next.search || void 0,
3914
- sortKey: next.sortKey,
3915
- sortOrder: next.sortKey ? next.sortOrder : void 0,
3916
- ordering: next.sortKey ? `${next.sortOrder === "desc" ? "-" : ""}${next.sortKey}` : void 0,
3917
- filters: Object.fromEntries(Object.entries(next.filters).filter(([, v]) => v !== ""))
3918
- });
3919
- };
3920
- const [searchText, setSearchText] = useState5(view.search);
3921
- const searchTimer = useRef6(void 0);
3922
- useEffect4(() => () => clearTimeout(searchTimer.current), []);
3923
- const [scrollTop, setScrollTop] = useState5(0);
3924
- const scroller = useRef6(null);
3925
- const sort = view.sortKey ? { key: view.sortKey, order: view.sortOrder } : void 0;
3926
- const rows = useMemo3(() => {
3927
- let r = base;
3928
- if (fl && !server.filter)
3929
- for (const [k, v] of Object.entries(view.filters)) {
3930
- if (v === "") continue;
3931
- const c = columns.find((x) => x.key === k);
3932
- if (c?.filter === "min")
3933
- r = r.filter((row) => (toNumber(field(row, k)) ?? Number.NEGATIVE_INFINITY) >= Number(v));
3934
- else if (c?.filter === "select") r = r.filter((row) => String(field(row, k) ?? "") === v);
3935
- else
3936
- r = r.filter(
3937
- (row) => String(field(row, k) ?? "").toLowerCase().includes(v.toLowerCase())
3938
- );
3939
- }
3940
- if (sr && !server.search && view.search) {
3941
- const q = view.search.toLowerCase();
3942
- const fields = sr.mode === "client" && "fields" in sr ? sr.fields : void 0;
3943
- r = r.filter(
3944
- (row) => (fields ? fields.map((f) => field(row, f)) : Object.values(row)).some(
3945
- (v) => v !== null && v !== void 0 && typeof v !== "object" && String(v).toLowerCase().includes(q)
3946
- )
3947
- );
3948
- }
3949
- if (sort && !server.sort) {
3950
- const dir = sort.order === "desc" ? -1 : 1;
3951
- r = [...r].sort((a, b) => {
3952
- const x = field(a, sort.key);
3953
- const y = field(b, sort.key);
3954
- if (x === y) return 0;
3955
- if (x === null || x === void 0) return 1;
3956
- if (y === null || y === void 0) return -1;
3957
- const nx = toNumber(x);
3958
- const ny = toNumber(y);
3959
- return (nx !== void 0 && ny !== void 0 ? nx - ny : String(x).localeCompare(String(y), void 0, { numeric: true })) * dir;
3728
+ function withFunctions(v, make) {
3729
+ if (Array.isArray(v)) return v.map((x) => withFunctions(x, make));
3730
+ if (v && typeof v === "object") {
3731
+ const o = v;
3732
+ if (typeof o.fn === "string" && Object.keys(o).length === 1) return make(o.fn);
3733
+ return Object.fromEntries(Object.entries(o).map(([k, x]) => [k, withFunctions(x, make)]));
3734
+ }
3735
+ return v;
3736
+ }
3737
+ var SHADOWS = {
3738
+ none: "none",
3739
+ sm: "0 1px 3px rgba(13, 13, 13, 0.08)",
3740
+ md: "0 6px 16px rgba(13, 13, 13, 0.10)",
3741
+ lg: "0 14px 36px rgba(13, 13, 13, 0.14)"
3742
+ };
3743
+ var PADDING = { none: "0", compact: "8px", roomy: "24px" };
3744
+ var colour = (v) => {
3745
+ if (typeof v !== "string" || !v) return void 0;
3746
+ if (/^[a-z]+(-[a-z]+)+$/.test(v) && !v.includes("(")) return `var(--ds-color-${v})`;
3747
+ return /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\)|[a-z]+)$/i.test(v) ? v : void 0;
3748
+ };
3749
+ var size = (v) => typeof v === "number" ? `${v}px` : typeof v === "string" && /^[\d.]+(px|%|rem|em|vw)?$/.test(v) ? v : void 0;
3750
+ var PART_CLASSES = [
3751
+ [".ds-panel-title, .ds-kpi-label", "title"],
3752
+ [".ds-info", "info"],
3753
+ [".ds-panel-meta, .ds-live", "meta"],
3754
+ [".ds-kpi-foot", "target"],
3755
+ [".ds-chip", "badge"],
3756
+ [".ds-kpi-main, .ds-kpi-value, .ds-kpi-unit", "value"],
3757
+ [".ds-kpi-sub, .ds-kpi-delta", "note"],
3758
+ [".ds-tile", "tile"],
3759
+ [".ds-meters > *, .ds-segbar, .ds-legend", "bars"],
3760
+ [".ds-status, .ds-pill", "state"],
3761
+ [".ds-table-tools", "tools"],
3762
+ [".ds-pager", "pager"]
3763
+ ];
3764
+ var PART_SELECTOR = ["[data-ds-part]", ...PART_CLASSES.map(([sel]) => sel)].join(", ");
3765
+ function partAt(target, frame) {
3766
+ let el = target?.closest(PART_SELECTOR) ?? null;
3767
+ while (el && frame?.contains(el)) {
3768
+ if (el.closest(".ds-panel") !== frame) return void 0;
3769
+ const own = el.getAttribute("data-ds-part");
3770
+ if (own) return { part: own, node: el };
3771
+ const hit = PART_CLASSES.find(([sel]) => el?.matches(sel));
3772
+ if (hit) return { part: hit[1], node: el };
3773
+ el = el.parentElement?.closest(PART_SELECTOR) ?? null;
3774
+ }
3775
+ return void 0;
3776
+ }
3777
+ function markPart(frame, node) {
3778
+ const root = frame?.closest(".ds-root") ?? frame?.ownerDocument;
3779
+ for (const n of root?.querySelectorAll(".ds-part-selected") ?? []) n.classList.remove("ds-part-selected");
3780
+ node?.classList.add("ds-part-selected");
3781
+ }
3782
+ function panelStyle(s) {
3783
+ if (!s) return void 0;
3784
+ const out = {};
3785
+ const bg = colour(s.background);
3786
+ if (bg) out.background = bg;
3787
+ if (typeof s.borderWidth === "number" || s.borderColor)
3788
+ out.border = `${s.borderWidth ?? 1}px solid ${colour(s.borderColor) ?? "var(--ds-color-border-default)"}`;
3789
+ if (typeof s.radius === "number") out.borderRadius = s.radius;
3790
+ if (typeof s.shadow === "string" && SHADOWS[s.shadow]) out.boxShadow = SHADOWS[s.shadow];
3791
+ if (typeof s.padding === "number") out.padding = s.padding;
3792
+ else if (typeof s.padding === "string" && PADDING[s.padding]) out.padding = PADDING[s.padding];
3793
+ if (typeof s.minHeight === "number") out.minHeight = s.minHeight;
3794
+ if (typeof s.flex === "string" && /^[\d.\s]*(auto|[\d.]+(px|%|rem)?)?$/.test(s.flex)) out.flex = s.flex;
3795
+ const minW = size(s.minWidth);
3796
+ const maxW = size(s.maxWidth);
3797
+ if (minW) out.minWidth = minW;
3798
+ if (maxW) out.maxWidth = maxW;
3799
+ if (typeof s.align === "string")
3800
+ out.alignSelf = s.align === "start" ? "flex-start" : s.align === "end" ? "flex-end" : s.align;
3801
+ return Object.keys(out).length ? out : void 0;
3802
+ }
3803
+ var samePanelView = (a, b) => Object.keys(a).every(
3804
+ (k) => k === "data" || k === "sourceData" ? Object.is(a[k], b[k]) : Object.is(a[k], b[k]) || JSON.stringify(a[k]) === JSON.stringify(b[k])
3805
+ );
3806
+ var RESERVED = /^(filters|panels|view|modal|highlight|datasources|context)(\.|$)/;
3807
+ function widgetStore(runtime) {
3808
+ const get = (path) => getPath(runtime.getTree(), path);
3809
+ return {
3810
+ get,
3811
+ use: function useStoreValue(pathOrSelect) {
3812
+ return useTree(
3813
+ useCallback4(
3814
+ (t) => typeof pathOrSelect === "string" ? getPath(t, pathOrSelect) : pathOrSelect(t),
3815
+ [pathOrSelect]
3816
+ ),
3817
+ (a, b) => Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b)
3818
+ );
3819
+ },
3820
+ set: (path, value) => {
3821
+ if (RESERVED.test(path)) throw new Error(`"${path}" belongs to the runtime; use setFilter or an action`);
3822
+ runtime.store.dispatch(stateActions.set({ path, value }));
3823
+ },
3824
+ setFilter: (name, value) => runtime.store.dispatch(stateActions.setFilter({ name, value })),
3825
+ subscribe: (path, fn) => {
3826
+ let prev = get(path);
3827
+ return runtime.store.subscribe(() => {
3828
+ const next = get(path);
3829
+ if (!Object.is(next, prev) && JSON.stringify(next) !== JSON.stringify(prev)) {
3830
+ prev = next;
3831
+ fn(next);
3832
+ }
3833
+ });
3834
+ }
3835
+ };
3836
+ }
3837
+ function findPanel(doc, id) {
3838
+ const top = doc.spec.panels[id];
3839
+ if (top) return top;
3840
+ for (const m of Object.values(doc.spec.modals ?? {})) if (m.panels[id]) return m.panels[id];
3841
+ return void 0;
3842
+ }
3843
+ function useHiddenPanels(ids) {
3844
+ const { runtime } = useDashboard();
3845
+ const key = ids.join(",");
3846
+ const list = useTree(
3847
+ // biome-ignore lint/correctness/useExhaustiveDependencies: ids are compared by key
3848
+ useCallback4(
3849
+ (tree) => ids.filter((id) => {
3850
+ const def = findPanel(runtime.doc, id);
3851
+ if (!def) return false;
3852
+ if (tree.panels[id]?.hidden) return true;
3853
+ if (typeof def.visibleWhen !== "string") return false;
3854
+ try {
3855
+ return !evaluate(
3856
+ def.visibleWhen,
3857
+ rootScope(tree, runtime.helpers, { panel: tree.panels[id] ?? {}, drill: drillValues(tree, id) })
3858
+ );
3859
+ } catch {
3860
+ return false;
3861
+ }
3862
+ }),
3863
+ [key, runtime]
3864
+ ),
3865
+ (a, b) => a.join(",") === b.join(",")
3866
+ );
3867
+ return useMemo3(() => new Set(list), [list]);
3868
+ }
3869
+ function panelUnder(x, y, exclude) {
3870
+ if (typeof document === "undefined") return void 0;
3871
+ for (const el of document.elementsFromPoint(x, y)) {
3872
+ const p = el.closest(".ds-panel[data-panel]");
3873
+ if (p && (!exclude || !exclude.contains(p) && !p.contains(exclude))) return p;
3874
+ }
3875
+ return void 0;
3876
+ }
3877
+ function indexIn(box, x, y) {
3878
+ const row = getComputedStyle(box).flexDirection === "row";
3879
+ const kids = [...box.children].filter((c) => c.classList.contains("ds-panel"));
3880
+ return kids.filter((k) => {
3881
+ const r = k.getBoundingClientRect();
3882
+ return row ? r.left + r.width / 2 < x && r.top < y : r.top + r.height / 2 < y;
3883
+ }).length;
3884
+ }
3885
+ function dropIndexAt(panel, x, y) {
3886
+ const id = panel.getAttribute("data-panel") ?? "";
3887
+ const under = document.elementsFromPoint(x, y).find((el) => el.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`));
3888
+ const box = under?.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`) ?? panel.querySelector(`[data-slot][data-owner="${CSS.escape(id)}"]`);
3889
+ if (!box) return {};
3890
+ return { slot: box.getAttribute("data-slot") ?? void 0, index: indexIn(box, x, y) };
3891
+ }
3892
+ function PanelFrame({ id, nested = false }) {
3893
+ return /* @__PURE__ */ jsx14(Boundary, { resetKeys: [id], fallback: (e) => /* @__PURE__ */ jsx14(PanelCrash, { id, error: e }), children: /* @__PURE__ */ jsx14(PanelFrameInner, { id, nested }) });
3894
+ }
3895
+ function PanelCrash({ id, error }) {
3896
+ const { options } = useDashboard();
3897
+ let custom;
3898
+ try {
3899
+ custom = options.renderError?.({ code: "render", message: error.message }, id);
3900
+ } catch {
3901
+ custom = void 0;
3902
+ }
3903
+ return /* @__PURE__ */ jsx14("section", { className: "ds-panel", "data-panel": id, "aria-label": id, children: /* @__PURE__ */ jsx14("div", { className: "ds-panel-body", children: custom ?? /* @__PURE__ */ jsxs9("div", { className: "ds-state ds-state-error", role: "alert", children: [
3904
+ "This panel could not be shown: ",
3905
+ error.message
3906
+ ] }) }) });
3907
+ }
3908
+ function PanelFrameInner({ id, nested }) {
3909
+ const { runtime, registry, options, visibility } = useDashboard();
3910
+ const instance = `${id}\0${useId3()}`;
3911
+ const inherited = useNodeScope();
3912
+ const def = findPanel(runtime.doc, id);
3913
+ const widget = registry.byKind.get(def.kind);
3914
+ const spec = def.spec ?? {};
3915
+ const binding = spec.data;
3916
+ const drillLevels = def.drill?.levels ?? [];
3917
+ const view = useTree(
3918
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the panel definition is fixed for a runtime
3919
+ useCallback4(
3920
+ (tree) => {
3921
+ const ps = tree.panels[id] ?? {};
3922
+ const level = drillLevels[(ps.drill ?? []).length];
3923
+ const baseSource = level?.source ?? binding?.source;
3924
+ const drillId = baseSource && level?.query ? drillSourceId(baseSource, id, level.name) : void 0;
3925
+ const source = drillId && runtime.datasourceIds.has(drillId) ? drillId : baseSource;
3926
+ const scope2 = rootScope(tree, runtime.helpers, {
3927
+ panel: { ...ps, controls: ps.controls ?? {} },
3928
+ drill: drillValues(tree, id),
3929
+ parent: inherited.parentData,
3930
+ ...inherited.hasItem ? { item: inherited.item, index: inherited.index } : {}
3960
3931
  });
3961
- }
3962
- return r;
3963
- }, [base, view, columns]);
3964
- const pageSize = pg ? view.pageSize : void 0;
3965
- const rowTotal = server.paging ? toNumber(field(source, pg?.totalPath ?? "count")) ?? rows.length : rows.length;
3966
- const pages = pageSize ? Math.max(1, Math.ceil(rowTotal / pageSize)) : 1;
3967
- const current = Math.min(view.page, pages);
3968
- const shown = pageSize && !server.paging ? rows.slice((current - 1) * pageSize, current * pageSize) : rows;
3969
- const hasFilters = Boolean(fl) && columns.some((c) => c.filter);
3970
- const height = Math.max(120, (size2.height || 300) - (sr ? 48 : 0) - (pageSize ? 48 : 0));
3971
- const windowed = spec.virtual && shown.length > 60;
3972
- const first = windowed ? Math.max(0, Math.floor(scrollTop / ROW_H) - 10) : 0;
3973
- const last = windowed ? Math.min(shown.length, first + Math.ceil(height / ROW_H) + 20) : shown.length;
3974
- const busy = status === "loading" && base.length > 0;
3975
- const filterChoices = (c) => c.filterOptions ?? [
3976
- ...new Set(
3977
- base.map((r) => field(r, c.key)).filter((v) => v !== null && v !== void 0 && v !== "").map(String)
3978
- )
3979
- ].sort();
3980
- const cell = (c, row) => {
3981
- const v = field(row, c.key);
3982
- if (c.type === "badge") {
3983
- const text = c.template ? tpl(c.template, row) : v === null || v === void 0 || v === "" ? "" : String(v);
3984
- if (!text) return c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "";
3985
- let t = c.map?.[String(v)] ?? "neutral";
3986
- if (c.tone) {
3932
+ let visible = true;
3933
+ if (typeof def.visibleWhen === "string") {
3987
3934
  try {
3988
- t = String(
3989
- evaluate(c.tone, scope({ row, value: v }, helpers))
3990
- );
3935
+ visible = Boolean(evaluate(def.visibleWhen, scope2));
3991
3936
  } catch {
3937
+ visible = true;
3992
3938
  }
3993
3939
  }
3994
- return /* @__PURE__ */ jsx18("span", { className: "ds-chip", "data-tone": t, children: text });
3995
- }
3996
- if (c.template) return tpl(c.template, row) || (c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "");
3997
- if (c.list !== void 0) {
3998
- const items = Array.isArray(v) ? v : [];
3999
- if (items.length === 0) return c.empty ?? "";
4000
- return /* @__PURE__ */ jsx18("span", { className: "ds-cell-list", children: items.map((it, i) => (
4001
- // biome-ignore lint/suspicious/noArrayIndexKey: list items have no id and never reorder within a render
4002
- /* @__PURE__ */ jsx18("span", { children: tpl(c.list, row, it) }, i)
4003
- )) });
4004
- }
4005
- if (v === null || v === void 0 || v === "")
4006
- return c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "";
4007
- switch (c.type) {
4008
- case "link": {
4009
- const href = safeLink(c.href ? tpl(c.href, row) : String(v));
4010
- return href ? /* @__PURE__ */ jsx18("a", { className: "ds-link", href, onClick: (e) => e.stopPropagation(), children: String(v) }) : String(v);
4011
- }
4012
- case "image":
4013
- return safeImageSrc(v) ? /* @__PURE__ */ jsx18("img", { src: v, alt: "", style: { height: 28, borderRadius: 4 } }) : null;
4014
- case "progress": {
4015
- const n = toNumber(v) ?? 0;
4016
- const pct = Math.min(100, n / (c.max ?? 100) * 100);
4017
- return /* @__PURE__ */ jsxs13("span", { className: "ds-inline", children: [
4018
- /* @__PURE__ */ jsx18("span", { className: "ds-progress", style: { flex: 1, minWidth: 40 }, children: /* @__PURE__ */ jsx18("span", { style: { width: `${pct}%`, background: "var(--ds-series-1)" } }) }),
4019
- formatValue(n, helpers, c.format, c.decimals),
4020
- c.suffix
4021
- ] });
4022
- }
4023
- case "sparkline":
4024
- return /* @__PURE__ */ jsx18(
4025
- SparkSvg,
4026
- {
4027
- values: (Array.isArray(v) ? v : []).map(
4028
- (x) => toNumber(typeof x === "object" ? field(x, "value") : x) ?? 0
4029
- ),
4030
- height: 24,
4031
- area: false
4032
- }
4033
- );
4034
- default:
4035
- return `${c.prefix ?? ""}${typeof v === "number" || c.format ? formatValue(v, helpers, c.format, c.decimals) : String(v)}${c.suffix ?? ""}`;
4036
- }
4037
- };
4038
- const total = (c) => {
4039
- const how = spec.totals?.columns[c.key];
4040
- if (!how) return null;
4041
- const nums = rows.map((r) => toNumber(field(r, c.key))).filter((n) => n !== void 0);
4042
- if (how !== "count" && nums.length === 0) return "";
4043
- const v = how === "count" ? rows.length : how === "sum" ? nums.reduce((a, b) => a + b, 0) : how === "avg" ? nums.reduce((a, b) => a + b, 0) / (nums.length || 1) : how === "min" ? nums.reduce((a, b) => Math.min(a, b)) : nums.reduce((a, b) => Math.max(a, b));
4044
- return `${c.prefix ?? ""}${formatValue(v, helpers, c.format === "date" ? "number" : c.format, c.decimals)}${c.suffix ?? ""}`;
4045
- };
4046
- const muted = (row) => {
4047
- if (!spec.rowMutedWhen) return false;
4048
- try {
4049
- return Boolean(evaluate(spec.rowMutedWhen, scope({ row }, helpers)));
4050
- } catch {
4051
- return false;
4052
- }
4053
- };
4054
- const align = (c) => c.align ?? (c.type === "number" || c.format && c.format !== "date" && c.format !== "text" ? "right" : "left");
4055
- return /* @__PURE__ */ jsxs13("div", { className: "ds-table-wrap", "data-density": spec.density, children: [
4056
- sr && /* @__PURE__ */ jsxs13("div", { className: "ds-table-tools", children: [
4057
- /* @__PURE__ */ jsxs13("label", { className: "ds-search", children: [
4058
- /* @__PURE__ */ jsxs13("svg", { viewBox: "0 0 16 16", width: "15", height: "15", "aria-hidden": "true", children: [
4059
- /* @__PURE__ */ jsx18("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.5" }),
4060
- /* @__PURE__ */ jsx18("path", { d: "m10.5 10.5 3 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
4061
- ] }),
4062
- /* @__PURE__ */ jsx18(
4063
- "input",
4064
- {
4065
- type: "search",
4066
- "aria-label": "Search table",
4067
- placeholder: "placeholder" in sr && sr.placeholder || "Search",
4068
- value: searchText,
4069
- onChange: (e) => {
4070
- const v = e.target.value;
4071
- setSearchText(v);
4072
- clearTimeout(searchTimer.current);
4073
- searchTimer.current = setTimeout(() => update({ search: v, page: 1 }), server.search ? 350 : 120);
4074
- }
4075
- }
4076
- )
4077
- ] }),
4078
- /* @__PURE__ */ jsxs13("span", { className: "ds-table-count", children: [
4079
- helpers.fmt.number(rowTotal),
4080
- " rows"
4081
- ] })
4082
- ] }),
4083
- /* @__PURE__ */ jsxs13(
4084
- "div",
4085
- {
4086
- className: "ds-table-scroll",
4087
- ref: scroller,
4088
- style: { maxHeight: height },
4089
- onScroll: windowed ? (e) => setScrollTop(e.currentTarget.scrollTop) : void 0,
4090
- children: [
4091
- busy && /* @__PURE__ */ jsx18("div", { className: "ds-table-busy", "aria-hidden": "true" }),
4092
- /* @__PURE__ */ jsxs13("table", { className: "ds-table", "aria-busy": busy || void 0, children: [
4093
- /* @__PURE__ */ jsxs13("thead", { "data-sticky": spec.sticky || void 0, children: [
4094
- /* @__PURE__ */ jsx18("tr", { children: columns.map((c, i) => {
4095
- const sorted = sort?.key === c.key ? sort.order : void 0;
4096
- return /* @__PURE__ */ jsx18(
4097
- "th",
4098
- {
4099
- "data-ds-part": `column:${i}`,
4100
- style: { textAlign: align(c), width: c.width },
4101
- "aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
4102
- children: so.enabled === false || c.sortable === false || c.list !== void 0 ? c.label ?? c.key : /* @__PURE__ */ jsxs13(
4103
- "button",
4104
- {
4105
- type: "button",
4106
- onClick: () => update(
4107
- sorted === "asc" ? { sortKey: c.key, sortOrder: "desc", page: 1 } : sorted === "desc" ? { sortKey: void 0, page: 1 } : { sortKey: c.key, sortOrder: "asc", page: 1 }
4108
- ),
4109
- children: [
4110
- c.label ?? c.key,
4111
- /* @__PURE__ */ jsx18("span", { className: "ds-sort", "data-dir": sorted, "aria-hidden": "true" })
4112
- ]
4113
- }
4114
- )
4115
- },
4116
- `${c.key}-${i}`
4117
- );
4118
- }) }),
4119
- hasFilters && /* @__PURE__ */ jsx18("tr", { className: "ds-filter-row", children: columns.map((c, i) => /* @__PURE__ */ jsx18("th", { children: c.filter === "select" ? /* @__PURE__ */ jsx18(
4120
- SelectControl,
4121
- {
4122
- size: "sm",
4123
- block: true,
4124
- plain: true,
4125
- ariaLabel: `Filter ${c.label ?? c.key}`,
4126
- options: [
4127
- { value: "", label: "All" },
4128
- ...filterChoices(c).map((o) => ({ value: o, label: o }))
4129
- ],
4130
- value: view.filters[c.key] ?? "",
4131
- onChange: (v) => update({ filters: { ...view.filters, [c.key]: String(v ?? "") }, page: 1 })
4132
- }
4133
- ) : c.filter ? /* @__PURE__ */ jsx18(
4134
- "input",
4135
- {
4136
- className: "ds-cell-filter",
4137
- type: c.filter === "min" ? "number" : "text",
4138
- placeholder: c.filter === "min" ? "Min" : "Filter",
4139
- "aria-label": `Filter ${c.label ?? c.key}`,
4140
- value: view.filters[c.key] ?? "",
4141
- onChange: (e) => update({ filters: { ...view.filters, [c.key]: e.target.value }, page: 1 })
4142
- }
4143
- ) : null }, `f-${c.key}-${i}`)) })
4144
- ] }),
4145
- /* @__PURE__ */ jsxs13("tbody", { children: [
4146
- windowed && first > 0 && /* @__PURE__ */ jsx18("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx18("td", { colSpan: columns.length, style: { height: first * ROW_H, padding: 0 } }) }),
4147
- shown.slice(first, last).map((row, k) => {
4148
- const i = first + k;
4149
- const key = spec.rowKey ? String(field(row, spec.rowKey)) : String(i);
4150
- return /* @__PURE__ */ jsx18(
4151
- "tr",
4152
- {
4153
- "data-muted": muted(row) || void 0,
4154
- onClick: () => emit("rowClick", "row", { datum: row, index: i }),
4155
- onMouseEnter: () => emit("hover", "row", { datum: row, index: i }),
4156
- tabIndex: 0,
4157
- onKeyDown: (e) => e.key === "Enter" && emit("rowClick", "row", { datum: row, index: i }),
4158
- children: columns.map((c, j) => (
4159
- // biome-ignore lint/a11y/useKeyWithClickEvents: rows are focusable and open with Enter; cell clicks add detail for pointer users
4160
- /* @__PURE__ */ jsx18(
4161
- "td",
4162
- {
4163
- style: { textAlign: align(c) },
4164
- onClick: () => emit("cellClick", "cell", { datum: row, index: i, value: field(row, c.key), column: c.key }),
4165
- children: cell(c, row)
4166
- },
4167
- `${c.key}-${j}`
4168
- )
4169
- ))
4170
- },
4171
- key
4172
- );
4173
- }),
4174
- windowed && last < shown.length && /* @__PURE__ */ jsx18("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx18("td", { colSpan: columns.length, style: { height: (shown.length - last) * ROW_H, padding: 0 } }) })
4175
- ] }),
4176
- spec.totals && /* @__PURE__ */ jsx18("tfoot", { children: /* @__PURE__ */ jsx18("tr", { children: columns.map((c, j) => /* @__PURE__ */ jsx18("td", { style: { textAlign: align(c) }, children: j === 0 && !spec.totals?.columns[c.key] ? spec.totals?.label : total(c) }, `${c.key}-${j}`)) }) })
4177
- ] })
4178
- ]
3940
+ let data;
3941
+ let sourceData;
3942
+ let status = "success";
3943
+ let error;
3944
+ let stale = false;
3945
+ let updatedAt;
3946
+ if (source) {
3947
+ const s = tree.datasources[source];
3948
+ status = s?.status ?? "idle";
3949
+ error = s?.error;
3950
+ stale = Boolean(s?.stale);
3951
+ updatedAt = s?.updatedAt;
3952
+ sourceData = s?.data;
3953
+ data = typeof binding?.path === "string" ? getPath(s?.data, binding.path) : s?.data;
3954
+ } else if (binding && typeof binding.panel === "string")
3955
+ data = getPath(tree.panels[binding.panel], binding.path ?? "selection");
3956
+ else if (binding && typeof binding.state === "string") data = getPath(tree, binding.state);
3957
+ else if (binding && "value" in binding) data = binding.value;
3958
+ else if (!binding && inherited.parentId) data = inherited.data;
3959
+ const { data: _d, ...rest } = spec;
3960
+ let props2 = {};
3961
+ try {
3962
+ props2 = resolvePanel(rest, scope2, Boolean(inherited.hasItem));
3963
+ } catch (e) {
3964
+ error = { code: "template", message: e.message };
4179
3965
  }
4180
- ),
4181
- pageSize && /* @__PURE__ */ jsxs13("div", { className: "ds-pager", children: [
4182
- /* @__PURE__ */ jsxs13("span", { className: "ds-pager-size", children: [
4183
- "Rows",
4184
- /* @__PURE__ */ jsx18(
4185
- SelectControl,
4186
- {
4187
- size: "sm",
4188
- plain: true,
4189
- ariaLabel: "Rows per page",
4190
- options: (pg?.pageSizes ?? [10, 20, 50, 100]).map((n) => ({ value: n, label: String(n) })),
4191
- value: pageSize,
4192
- onChange: (v) => update({ pageSize: Number(v), page: 1 })
4193
- }
4194
- )
4195
- ] }),
4196
- /* @__PURE__ */ jsxs13("span", { children: [
4197
- rowTotal === 0 ? 0 : (current - 1) * pageSize + 1,
4198
- "\u2013",
4199
- Math.min(current * pageSize, rowTotal),
4200
- " of",
4201
- " ",
4202
- helpers.fmt.number(rowTotal)
4203
- ] }),
4204
- /* @__PURE__ */ jsxs13("span", { className: "ds-pages", children: [
4205
- /* @__PURE__ */ jsx18(
4206
- "button",
4207
- {
4208
- type: "button",
4209
- "aria-label": "Previous page",
4210
- disabled: current <= 1,
4211
- onClick: () => update({ page: current - 1 }),
4212
- children: "\u2039"
4213
- }
4214
- ),
4215
- pageList(current, pages).map(
4216
- (n, i) => n === 0 ? /* @__PURE__ */ jsx18("span", { className: "ds-page-gap", children: "\u2026" }, `gap-${i < 3 ? "a" : "b"}`) : /* @__PURE__ */ jsx18(
4217
- "button",
4218
- {
4219
- type: "button",
4220
- "aria-current": n === current ? "page" : void 0,
4221
- onClick: () => update({ page: n }),
4222
- children: n
4223
- },
4224
- n
4225
- )
4226
- ),
4227
- /* @__PURE__ */ jsx18(
4228
- "button",
4229
- {
4230
- type: "button",
4231
- "aria-label": "Next page",
4232
- disabled: current >= pages,
4233
- onClick: () => update({ page: current + 1 }),
4234
- children: "\u203A"
4235
- }
4236
- )
4237
- ] })
4238
- ] })
4239
- ] });
4240
- }
4241
- });
4242
-
4243
- // src/widgets/builtins/Tiles.tsx
4244
- import "zod";
4245
- import { Fragment as Fragment5, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
4246
- var Tiles = defineWidget({
4247
- ...TilesContract,
4248
- implements: "tiles",
4249
- exposes: { selection: "the clicked tile's row" },
4250
- meta: { label: "Tiles", icon: "tiles", category: "Numbers", size: { w: 12, h: 4, minW: 3, minH: 3 } },
4251
- events: ["click", "hover", "select"],
4252
- parts: ["tile"],
4253
- defaults: { label: "name", value: "value" },
4254
- component: function TilesWidget({ spec, data, emit, helpers }) {
4255
- const rows = asRows(data);
4256
- const caption = (row) => {
4257
- if (!spec.caption) return void 0;
4258
- try {
4259
- return String(interpolate(spec.caption, scope({ row }, helpers)) ?? "");
4260
- } catch {
4261
- return spec.caption;
4262
- }
3966
+ const msg = def.messages;
3967
+ const messages = msg ? resolvePanel(msg, scope2) : void 0;
3968
+ const group = props2.highlight ?? void 0;
3969
+ return {
3970
+ visible,
3971
+ hidden: Boolean(ps.hidden),
3972
+ panel: ps,
3973
+ source,
3974
+ data,
3975
+ sourceData,
3976
+ status,
3977
+ error,
3978
+ stale,
3979
+ updatedAt,
3980
+ props: props2,
3981
+ messages,
3982
+ highlight: group ? tree.highlight[group] : void 0,
3983
+ x: level?.x ?? void 0
3984
+ };
3985
+ },
3986
+ [id, runtime, inherited.parentId, inherited.data, inherited.parentData, inherited.item, inherited.index]
3987
+ ),
3988
+ samePanelView
3989
+ );
3990
+ const renderNested = useCallback4((child) => /* @__PURE__ */ jsx14(PanelFrame, { id: child, nested: true }, child), []);
3991
+ const store = useMemo3(() => widgetStore(runtime), [runtime]);
3992
+ const [bodyRef, size2] = useSize();
3993
+ const frameRef = useRef5(null);
3994
+ useEffect3(() => {
3995
+ if (!view.visible || view.hidden) {
3996
+ visibility.set(instance, null);
3997
+ return;
3998
+ }
3999
+ const el = frameRef.current;
4000
+ if (!el || typeof IntersectionObserver === "undefined") {
4001
+ visibility.set(instance, view.source ? [view.source] : []);
4002
+ return () => visibility.set(instance, null);
4003
+ }
4004
+ const io = new IntersectionObserver(
4005
+ ([e]) => visibility.set(instance, e?.isIntersecting && view.source ? [view.source] : []),
4006
+ { rootMargin: "200px" }
4007
+ );
4008
+ io.observe(el);
4009
+ return () => {
4010
+ io.disconnect();
4011
+ visibility.set(instance, null);
4263
4012
  };
4264
- return /* @__PURE__ */ jsx19(
4265
- "div",
4013
+ }, [instance, view.visible, view.hidden, view.source, visibility]);
4014
+ const emit = useCallback4(
4015
+ (type, part, detail) => {
4016
+ const event = { type, panel: id, ...part ? { part } : {}, ...detail };
4017
+ options.onEvent?.(event);
4018
+ void runtime.emit(event);
4019
+ },
4020
+ [id, options, runtime]
4021
+ );
4022
+ const run = useCallback4(
4023
+ (action, detail) => void runtime.runAction(action, { type: "click", panel: id, ...detail }),
4024
+ [runtime, id]
4025
+ );
4026
+ const setUi = useCallback4(
4027
+ (patch) => runtime.store.dispatch(
4028
+ stateActions.patchPanel({ id, patch: { ui: { ...runtime.getTree().panels[id]?.ui, ...patch } } })
4029
+ ),
4030
+ [runtime, id]
4031
+ );
4032
+ const dataRef = useRef5(view.data);
4033
+ dataRef.current = view.data;
4034
+ const props = useMemo3(() => {
4035
+ let p = { ...view.props, ...view.panel.props ?? {} };
4036
+ if (view.x) p = { ...p, x: view.x };
4037
+ p = withFunctions(p, (code) => {
4038
+ const f = runtime.scripts.fnProp(code, ["p", "data"]);
4039
+ return (arg) => {
4040
+ try {
4041
+ return f(arg, dataRef.current);
4042
+ } catch (e) {
4043
+ console.warn(`[dashspec] ${id}: function prop failed: ${e.message}`);
4044
+ return "";
4045
+ }
4046
+ };
4047
+ });
4048
+ return widget ? parseWidgetProps(widget.schema, p).props : p;
4049
+ }, [view.props, view.panel.props, view.x, runtime, widget, id]);
4050
+ if (!view.visible || view.hidden) return null;
4051
+ const ownHeader = widget?.header === "widget";
4052
+ const title = ownHeader ? void 0 : props.title;
4053
+ const info = ownHeader ? void 0 : props.info;
4054
+ const meta2 = props.meta;
4055
+ const live2 = Boolean(props.live);
4056
+ const drill = view.panel.drill ?? [];
4057
+ const controls = def.controls ?? [];
4058
+ const tone2 = def.style?.tone ?? (widget?.frame === "plain" ? "plain" : "default");
4059
+ const headerKids = slotChildren(def, "header");
4060
+ const footerKids = slotChildren(def, "footer");
4061
+ const hideHeader = Boolean(def.style?.hideHeader) || !title && !meta2 && !live2 && drill.length === 0 && controls.length === 0 && !view.stale && headerKids.length === 0;
4062
+ const dnd = Boolean(options.onDropOnPanel);
4063
+ let body;
4064
+ if (!widget) body = /* @__PURE__ */ jsxs9("div", { className: "ds-state", children: [
4065
+ "Unknown widget \u201C",
4066
+ String(def.kind),
4067
+ "\u201D"
4068
+ ] });
4069
+ else if (view.error && view.data === void 0)
4070
+ body = options.renderError?.(view.error, id) ?? /* @__PURE__ */ jsx14("div", { className: "ds-state ds-state-error", role: "alert", children: view.messages?.error ?? view.error.message });
4071
+ else if (view.source && view.data === void 0 && (view.status === "loading" || view.status === "idle"))
4072
+ body = options.renderLoading?.(id, loadingText(view.messages)) ?? /* @__PURE__ */ jsx14(LoadingState, { text: loadingText(view.messages) });
4073
+ else if (view.source && isEmpty(view.data) && widget.empty !== "widget")
4074
+ body = options.renderEmpty?.(id) ?? /* @__PURE__ */ jsx14("div", { className: "ds-state", children: view.messages?.empty ?? "No data" });
4075
+ else {
4076
+ const W = widget.component;
4077
+ body = /* @__PURE__ */ jsx14(
4078
+ Boundary,
4266
4079
  {
4267
- className: "ds-tiles",
4268
- role: spec.selectable ? "radiogroup" : "list",
4269
- "aria-label": spec.title,
4270
- "data-wrap": spec.wrap === false ? "off" : void 0,
4271
- style: {
4272
- "--ds-tile-min": `${spec.minTileWidth ?? 128}px`,
4273
- ...spec.columns ? { "--ds-tile-cols": spec.columns } : {}
4274
- },
4275
- children: rows.map((r, i) => {
4276
- const label = field(r, spec.label);
4277
- const v = field(r, spec.value);
4278
- const n = toNumber(v);
4279
- const status = spec.status ? String(field(r, spec.status)) : void 0;
4280
- const st = status ? spec.statusMap?.[status] ?? status : void 0;
4281
- const vt = n === void 0 || !spec.valueTone ? void 0 : n > 0 ? spec.valueTone.positive : n < 0 ? spec.valueTone.negative : spec.valueTone.zero;
4282
- const active = spec.selectable && spec.selected !== void 0 && spec.selected === label;
4283
- return /* @__PURE__ */ jsxs14(
4284
- "button",
4285
- {
4286
- type: "button",
4287
- className: "ds-tile",
4288
- role: spec.selectable ? "radio" : "listitem",
4289
- "aria-checked": spec.selectable ? active : void 0,
4290
- "data-active": active || void 0,
4291
- onClick: () => {
4292
- emit("click", "tile", { datum: r, value: label, index: i });
4293
- if (spec.selectable) emit("select", "tile", { datum: r, value: label, index: i });
4294
- },
4295
- onMouseEnter: () => emit("hover", "tile", { datum: r, value: label, index: i }),
4296
- children: [
4297
- /* @__PURE__ */ jsxs14("span", { className: "ds-tile-label", children: [
4298
- st && /* @__PURE__ */ jsx19("span", { className: "ds-dot", style: { background: tone(st).solid }, "aria-hidden": "true" }),
4299
- String(label ?? ""),
4300
- spec.count && /* @__PURE__ */ jsx19("span", { className: "ds-chip-count", children: String(field(r, spec.count) ?? "") })
4301
- ] }),
4302
- /* @__PURE__ */ jsxs14(
4303
- "span",
4304
- {
4305
- className: "ds-tile-value",
4306
- style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
4307
- children: [
4308
- /* @__PURE__ */ jsx19(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
4309
- spec.unit && /* @__PURE__ */ jsx19("span", { className: "ds-kpi-unit", children: spec.unit })
4310
- ]
4311
- }
4312
- ),
4313
- spec.caption && /* @__PURE__ */ jsx19("span", { className: "ds-tile-caption", children: caption(r) })
4314
- ]
4315
- },
4316
- `${String(label)}-${i}`
4317
- );
4318
- })
4080
+ resetKeys: [view.data, props],
4081
+ fallback: (e) => /* @__PURE__ */ jsxs9("div", { className: "ds-state ds-state-error", role: "alert", children: [
4082
+ "This panel could not be shown: ",
4083
+ e.message
4084
+ ] }),
4085
+ children: /* @__PURE__ */ jsx14(
4086
+ W,
4087
+ {
4088
+ spec: props,
4089
+ data: view.data,
4090
+ source: view.sourceData,
4091
+ run,
4092
+ emit,
4093
+ state: view.panel,
4094
+ setUi,
4095
+ status: view.status,
4096
+ highlight: view.highlight,
4097
+ size: size2,
4098
+ mode: options.mode,
4099
+ helpers: runtime.helpers,
4100
+ panelId: id,
4101
+ renderSlot: (name, o) => /* @__PURE__ */ jsx14(Slot, { name, ...o }),
4102
+ store
4103
+ }
4104
+ )
4319
4105
  }
4320
4106
  );
4321
4107
  }
4322
- });
4323
- function CountUp({ value, render }) {
4324
- const n = toNumber(value);
4325
- const shown = useCountUp(n ?? value);
4326
- return /* @__PURE__ */ jsx19(Fragment5, { children: render(n === void 0 ? value : shown) });
4327
- }
4328
-
4329
- // src/widgets/builtins/atoms.tsx
4330
- import "zod";
4331
-
4332
- // src/widgets/shared/clickable.ts
4333
- import { useContext as useContext4 } from "react";
4334
-
4335
- // src/components/PanelFrame.tsx
4336
- import { useCallback as useCallback4, useEffect as useEffect5, useId as useId3, useMemo as useMemo4, useRef as useRef7, useState as useState6 } from "react";
4337
-
4338
- // src/widgets/parseProps.ts
4339
- function without(value, path) {
4340
- if (path.length === 0 || value === null || typeof value !== "object") return value;
4341
- const [head, ...rest] = path;
4342
- if (Array.isArray(value)) {
4343
- if (typeof head !== "number" || head < 0 || head >= value.length) return value;
4344
- const copy2 = [...value];
4345
- if (rest.length === 0) copy2.splice(head, 1);
4346
- else copy2[head] = without(copy2[head], rest);
4347
- return copy2;
4348
- }
4349
- if (!Object.hasOwn(value, head)) return value;
4350
- const copy = { ...value };
4351
- if (rest.length === 0) delete copy[head];
4352
- else copy[head] = without(copy[head], rest);
4353
- return copy;
4354
- }
4355
- function parseWidgetProps(schema, props) {
4356
- let current = props;
4357
- const dropped = [];
4358
- for (let round = 0; round < 25; round++) {
4359
- const r = schema.safeParse(current);
4360
- if (r.success) return { props: r.data, dropped };
4361
- const issue = r.error.issues.find((i) => i.path.length > 0);
4362
- if (!issue) break;
4363
- const lastIndex = issue.path.reduce((at, k, i) => typeof k === "number" ? i : at, -1);
4364
- const path = lastIndex >= 0 ? issue.path.slice(0, lastIndex + 1) : issue.path;
4365
- const next = without(current, path);
4366
- if (next === current) break;
4367
- dropped.push(path.join("."));
4368
- current = next;
4369
- }
4370
- return { props, dropped };
4371
- }
4372
-
4373
- // src/components/Boundary.tsx
4374
- import { Component } from "react";
4375
- var sameKeys = (a, b) => a.length === b.length && a.every((x, i) => Object.is(x, b[i]));
4376
- var Boundary = class extends Component {
4377
- state = { error: null };
4378
- static getDerivedStateFromError(error) {
4379
- return { error };
4380
- }
4381
- componentDidCatch(error, _info) {
4382
- this.props.onError?.(error);
4383
- }
4384
- componentDidUpdate(prev) {
4385
- if (this.state.error && !sameKeys(prev.resetKeys ?? [], this.props.resetKeys ?? [])) this.setState({ error: null });
4386
- }
4387
- render() {
4388
- return this.state.error ? this.props.fallback(this.state.error) : this.props.children;
4389
- }
4390
- };
4391
-
4392
- // src/components/Slot.tsx
4393
- import { createContext as createContext3, useContext as useContext3 } from "react";
4394
- import { Fragment as Fragment6, jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
4395
- var NodeScopeContext = createContext3({});
4396
- var useNodeScope = () => useContext3(NodeScopeContext);
4397
- var SlotOwnerContext = createContext3(null);
4398
- var SlotChildContext = createContext3(null);
4399
- function slotChildren(def, name) {
4400
- const slots = def?.slots;
4401
- const list = slots?.[name];
4402
- return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
4403
- }
4404
- function Slot({
4405
- name,
4406
- className,
4407
- style,
4408
- data,
4409
- item,
4410
- index,
4411
- empty
4412
- }) {
4413
- const { options } = useDashboard();
4414
- const owner = useContext3(SlotOwnerContext);
4415
- const outer = useNodeScope();
4416
- const renderChild = useContext3(SlotChildContext);
4417
- if (!owner || !renderChild) return null;
4418
- const ids = slotChildren(owner.def, name);
4419
- const editing = options.mode === "edit";
4420
- if (ids.length === 0 && !editing) return null;
4421
- const hasItem = item !== void 0 || outer.hasItem;
4422
- const scope2 = {
4423
- parentId: owner.id,
4424
- parentData: owner.data,
4425
- data: data !== void 0 ? data : item !== void 0 ? item : owner.data,
4426
- hasItem: Boolean(hasItem),
4427
- item: item !== void 0 ? item : outer.item,
4428
- index: index !== void 0 ? index : outer.index
4429
- };
4430
- return /* @__PURE__ */ jsx20(NodeScopeContext.Provider, { value: scope2, children: /* @__PURE__ */ jsxs15(
4431
- "div",
4432
- {
4433
- className: className ? `ds-slot ${className}` : "ds-slot",
4434
- style,
4435
- "data-slot": name,
4436
- "data-owner": owner.id,
4437
- "data-empty": ids.length === 0 || void 0,
4108
+ const selected = options.selectedPanel === id;
4109
+ const defaultSlot = widget?.slots ? Object.keys(widget.slots)[0] ?? "header" : "header";
4110
+ const dropTarget = (target, x, y) => {
4111
+ const own = `[data-slot][data-owner="${CSS.escape(id)}"]`;
4112
+ const el = target?.closest(own) ?? frameRef.current?.querySelector(`${own}:not([data-slot="header"]):not([data-slot="footer"])`) ?? void 0;
4113
+ const name = el?.getAttribute("data-slot") ?? defaultSlot;
4114
+ return { slot: name, index: el ? indexIn(el, x, y) : void 0 };
4115
+ };
4116
+ return /* @__PURE__ */ jsx14(SlotOwnerContext.Provider, { value: { id, data: view.data, def }, children: /* @__PURE__ */ jsx14(SlotChildContext.Provider, { value: renderNested, children: /* @__PURE__ */ jsxs9(
4117
+ "section",
4118
+ {
4119
+ ref: frameRef,
4120
+ className: "ds-panel",
4121
+ style: panelStyle(def.style),
4122
+ "data-tone": tone2,
4123
+ "data-panel": id,
4124
+ "data-selected": selected || void 0,
4125
+ "data-nested": nested || void 0,
4126
+ "aria-label": title ?? id,
4127
+ draggable: dnd && nested ? true : void 0,
4128
+ onDragStart: dnd && nested ? (e) => {
4129
+ e.stopPropagation();
4130
+ e.dataTransfer.setData("text/plain", id);
4131
+ e.dataTransfer.effectAllowed = "move";
4132
+ options.onDragPanelStart?.(id);
4133
+ } : void 0,
4134
+ onDragOver: dnd ? (e) => {
4135
+ const t = dropTarget(e.target, e.clientX, e.clientY);
4136
+ if (!options.canDropOn?.(id, void 0, t.slot)) return;
4137
+ e.preventDefault();
4138
+ e.stopPropagation();
4139
+ frameRef.current?.setAttribute("data-drop-over", t.slot);
4140
+ } : void 0,
4141
+ onDragLeave: dnd ? (e) => {
4142
+ if (!frameRef.current?.contains(e.relatedTarget))
4143
+ frameRef.current?.removeAttribute("data-drop-over");
4144
+ } : void 0,
4145
+ onDrop: dnd ? (e) => {
4146
+ frameRef.current?.removeAttribute("data-drop-over");
4147
+ const t = dropTarget(e.target, e.clientX, e.clientY);
4148
+ if (!options.canDropOn?.(id, void 0, t.slot)) return;
4149
+ e.preventDefault();
4150
+ e.stopPropagation();
4151
+ options.onDropOnPanel?.(id, t.index, void 0, t.slot);
4152
+ } : void 0,
4153
+ onPointerDownCapture: options.onPanelSelect ? (e) => {
4154
+ const el = partAt(e.target, frameRef.current);
4155
+ markPart(frameRef.current, el?.node);
4156
+ options.onPanelSelect?.(id, el?.part);
4157
+ } : void 0,
4158
+ onClickCapture: options.onPanelSelect ? (e) => {
4159
+ e.preventDefault();
4160
+ e.stopPropagation();
4161
+ } : void 0,
4438
4162
  children: [
4439
- ids.map((id) => /* @__PURE__ */ jsx20(SlotItem, { children: renderChild(id) }, id)),
4440
- ids.length === 0 && editing && (empty ?? /* @__PURE__ */ jsx20("span", { className: "ds-slot-hint", children: "Drop here" }))
4163
+ !hideHeader && /* @__PURE__ */ jsxs9("header", { className: "ds-panel-head", children: [
4164
+ /* @__PURE__ */ jsxs9("div", { style: { minWidth: 0 }, children: [
4165
+ title && /* @__PURE__ */ jsxs9("h3", { className: "ds-panel-title", children: [
4166
+ title,
4167
+ info && /* @__PURE__ */ jsx14(InfoTip, { text: info })
4168
+ ] }),
4169
+ drill.length > 0 && /* @__PURE__ */ jsxs9("nav", { className: "ds-crumbs", "aria-label": "Drill path", children: [
4170
+ /* @__PURE__ */ jsx14("button", { type: "button", onClick: () => runtime.runAction({ do: "drillReset", panel: id }), children: "All" }),
4171
+ drill.map((d, i) => /* @__PURE__ */ jsxs9("span", { children: [
4172
+ "\u203A",
4173
+ " ",
4174
+ i < drill.length - 1 ? /* @__PURE__ */ jsx14(
4175
+ "button",
4176
+ {
4177
+ type: "button",
4178
+ onClick: () => runtime.store.dispatch(
4179
+ stateActions.patchPanel({ id, patch: { drill: drill.slice(0, i + 1) } })
4180
+ ),
4181
+ children: String(d.value)
4182
+ }
4183
+ ) : String(d.value)
4184
+ ] }, `${d.level}-${i}`))
4185
+ ] })
4186
+ ] }),
4187
+ /* @__PURE__ */ jsxs9("div", { className: "ds-panel-tools", children: [
4188
+ headerKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "header", className: "ds-panel-addons" }),
4189
+ meta2 && /* @__PURE__ */ jsx14("span", { className: "ds-panel-meta", children: meta2 }),
4190
+ live2 ? /* @__PURE__ */ jsxs9("span", { className: "ds-live", "data-stale": view.stale || void 0, title: view.error?.message, children: [
4191
+ /* @__PURE__ */ jsx14("span", { "aria-hidden": "true" }),
4192
+ "Live, updated ",
4193
+ view.updatedAt ? runtime.helpers.fmt.ago(view.updatedAt) : "\u2026"
4194
+ ] }) : view.stale && /* @__PURE__ */ jsx14("span", { className: "ds-badge ds-badge-stale", title: view.error?.message, children: "Stale" }),
4195
+ controls.map((c) => /* @__PURE__ */ jsx14(
4196
+ ControlField,
4197
+ {
4198
+ def: c,
4199
+ compact: true,
4200
+ value: view.panel.controls?.[c.name],
4201
+ onChange: (v) => runtime.store.dispatch(
4202
+ stateActions.patchPanel({
4203
+ id,
4204
+ patch: { controls: { ...view.panel.controls, [c.name]: v } }
4205
+ })
4206
+ )
4207
+ },
4208
+ c.name
4209
+ ))
4210
+ ] })
4211
+ ] }),
4212
+ /* @__PURE__ */ jsx14("div", { className: "ds-panel-body", ref: bodyRef, children: body }),
4213
+ footerKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "footer", className: "ds-panel-foot" })
4441
4214
  ]
4442
4215
  }
4443
- ) });
4444
- }
4445
- var SlotItem = ({ children }) => /* @__PURE__ */ jsx20(Fragment6, { children });
4446
-
4447
- // src/components/PanelFrame.tsx
4448
- import { jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
4449
- var isEmpty = (d) => d === void 0 || d === null || Array.isArray(d) && d.length === 0 || typeof d === "object" && !Array.isArray(d) && Object.keys(d).length === 0;
4450
- function useSize() {
4451
- const [size2, setSize] = useState6({ width: 0, height: 0 });
4452
- const observer = useRef7(null);
4453
- const ref = useCallback4((el) => {
4454
- observer.current?.disconnect();
4455
- observer.current = null;
4456
- if (!el || typeof ResizeObserver === "undefined") return;
4457
- const ro = new ResizeObserver(([e]) => {
4458
- const r = e?.contentRect;
4459
- if (r)
4460
- setSize(
4461
- (s) => s.width === Math.round(r.width) && s.height === Math.round(r.height) ? s : { width: Math.round(r.width), height: Math.round(r.height) }
4462
- );
4463
- });
4464
- ro.observe(el);
4465
- observer.current = ro;
4466
- }, []);
4467
- return [ref, size2];
4468
- }
4469
- var DEFERRED = /(^|[^\w.$])(row|item|avg)\b/;
4470
- var DEFERRED_IN_ITEM = /(^|[^\w.$])(row|avg)\b/;
4471
- function interpolateMarkdown(v, scope2) {
4472
- const bodies = placeholders(v);
4473
- const whole = bodies.length === 1 && v.trim() === `\${${bodies[0]}}`;
4474
- const r = interpolate(v, scope2, escapeMarkdown);
4475
- if (!whole) return r;
4476
- return r === null || r === void 0 ? "" : escapeMarkdown(typeof r === "object" ? JSON.stringify(r) : String(r));
4477
- }
4478
- function resolvePanel(v, scope2, inItem = false, key) {
4479
- const deferred = inItem ? DEFERRED_IN_ITEM : DEFERRED;
4480
- if (typeof v === "string") {
4481
- if (placeholders(v).some((b) => deferred.test(stripStrings(b)))) return v;
4482
- return key === "markdown" ? interpolateMarkdown(v, scope2) : interpolate(v, scope2);
4483
- }
4484
- if (Array.isArray(v)) return v.map((x) => resolvePanel(x, scope2, inItem));
4485
- if (v && typeof v === "object")
4486
- return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolvePanel(x, scope2, inItem, k)]));
4487
- return v;
4488
- }
4489
- function withFunctions(v, make) {
4490
- if (Array.isArray(v)) return v.map((x) => withFunctions(x, make));
4491
- if (v && typeof v === "object") {
4492
- const o = v;
4493
- if (typeof o.fn === "string" && Object.keys(o).length === 1) return make(o.fn);
4494
- return Object.fromEntries(Object.entries(o).map(([k, x]) => [k, withFunctions(x, make)]));
4495
- }
4496
- return v;
4497
- }
4498
- var SHADOWS = {
4499
- none: "none",
4500
- sm: "0 1px 3px rgba(13, 13, 13, 0.08)",
4501
- md: "0 6px 16px rgba(13, 13, 13, 0.10)",
4502
- lg: "0 14px 36px rgba(13, 13, 13, 0.14)"
4503
- };
4504
- var PADDING = { none: "0", compact: "8px", roomy: "24px" };
4505
- var colour = (v) => {
4506
- if (typeof v !== "string" || !v) return void 0;
4507
- if (/^[a-z]+(-[a-z]+)+$/.test(v) && !v.includes("(")) return `var(--ds-color-${v})`;
4508
- return /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\)|[a-z]+)$/i.test(v) ? v : void 0;
4509
- };
4510
- var size = (v) => typeof v === "number" ? `${v}px` : typeof v === "string" && /^[\d.]+(px|%|rem|em|vw)?$/.test(v) ? v : void 0;
4511
- var PART_CLASSES = [
4512
- [".ds-panel-title, .ds-kpi-label", "title"],
4513
- [".ds-info", "info"],
4514
- [".ds-panel-meta, .ds-live", "meta"],
4515
- [".ds-kpi-foot", "target"],
4516
- [".ds-chip", "badge"],
4517
- [".ds-kpi-main, .ds-kpi-value, .ds-kpi-unit", "value"],
4518
- [".ds-kpi-sub, .ds-kpi-delta", "note"],
4519
- [".ds-tile", "tile"],
4520
- [".ds-meters > *, .ds-segbar, .ds-legend", "bars"],
4521
- [".ds-status, .ds-pill", "state"],
4522
- [".ds-table-tools", "tools"],
4523
- [".ds-pager", "pager"]
4524
- ];
4525
- var PART_SELECTOR = ["[data-ds-part]", ...PART_CLASSES.map(([sel]) => sel)].join(", ");
4526
- function partAt(target, frame) {
4527
- let el = target?.closest(PART_SELECTOR) ?? null;
4528
- while (el && frame?.contains(el)) {
4529
- if (el.closest(".ds-panel") !== frame) return void 0;
4530
- const own = el.getAttribute("data-ds-part");
4531
- if (own) return { part: own, node: el };
4532
- const hit = PART_CLASSES.find(([sel]) => el?.matches(sel));
4533
- if (hit) return { part: hit[1], node: el };
4534
- el = el.parentElement?.closest(PART_SELECTOR) ?? null;
4535
- }
4536
- return void 0;
4216
+ ) }) });
4537
4217
  }
4538
- function markPart(frame, node) {
4539
- const root = frame?.closest(".ds-root") ?? frame?.ownerDocument;
4540
- for (const n of root?.querySelectorAll(".ds-part-selected") ?? []) n.classList.remove("ds-part-selected");
4541
- node?.classList.add("ds-part-selected");
4218
+ function loadingText(messages) {
4219
+ const v = messages?.loading;
4220
+ return v === void 0 || v === null || v === "" ? void 0 : String(v);
4542
4221
  }
4543
- function panelStyle(s) {
4544
- if (!s) return void 0;
4545
- const out = {};
4546
- const bg = colour(s.background);
4547
- if (bg) out.background = bg;
4548
- if (typeof s.borderWidth === "number" || s.borderColor)
4549
- out.border = `${s.borderWidth ?? 1}px solid ${colour(s.borderColor) ?? "var(--ds-color-border-default)"}`;
4550
- if (typeof s.radius === "number") out.borderRadius = s.radius;
4551
- if (typeof s.shadow === "string" && SHADOWS[s.shadow]) out.boxShadow = SHADOWS[s.shadow];
4552
- if (typeof s.padding === "number") out.padding = s.padding;
4553
- else if (typeof s.padding === "string" && PADDING[s.padding]) out.padding = PADDING[s.padding];
4554
- if (typeof s.minHeight === "number") out.minHeight = s.minHeight;
4555
- if (typeof s.flex === "string" && /^[\d.\s]*(auto|[\d.]+(px|%|rem)?)?$/.test(s.flex)) out.flex = s.flex;
4556
- const minW = size(s.minWidth);
4557
- const maxW = size(s.maxWidth);
4558
- if (minW) out.minWidth = minW;
4559
- if (maxW) out.maxWidth = maxW;
4560
- if (typeof s.align === "string")
4561
- out.alignSelf = s.align === "start" ? "flex-start" : s.align === "end" ? "flex-end" : s.align;
4562
- return Object.keys(out).length ? out : void 0;
4222
+ function LoadingState({ text }) {
4223
+ if (!text) return /* @__PURE__ */ jsx14("div", { className: "ds-skeleton", "aria-busy": "true", "aria-label": "Loading" });
4224
+ return /* @__PURE__ */ jsxs9("output", { className: "ds-loading", "aria-busy": "true", children: [
4225
+ /* @__PURE__ */ jsx14("div", { className: "ds-skeleton", "aria-hidden": "true" }),
4226
+ /* @__PURE__ */ jsx14("span", { className: "ds-loading-text", children: text })
4227
+ ] });
4563
4228
  }
4564
- var samePanelView = (a, b) => Object.keys(a).every(
4565
- (k) => k === "data" || k === "sourceData" ? Object.is(a[k], b[k]) : Object.is(a[k], b[k]) || JSON.stringify(a[k]) === JSON.stringify(b[k])
4566
- );
4567
- var RESERVED = /^(filters|panels|view|modal|highlight|datasources|context)(\.|$)/;
4568
- function widgetStore(runtime) {
4569
- const get = (path) => getPath(runtime.getTree(), path);
4229
+
4230
+ // src/widgets/shared/clickable.ts
4231
+ function useClickable(panelId, activate) {
4232
+ const ctx = useContext4(DashboardContext);
4233
+ const def = ctx && panelId ? findPanel(ctx.runtime.doc, panelId) : void 0;
4234
+ const on = def?.on;
4235
+ if (on?.click === void 0) return { onClick: activate };
4570
4236
  return {
4571
- get,
4572
- use: function useStoreValue(pathOrSelect) {
4573
- return useTree(
4574
- useCallback4(
4575
- (t) => typeof pathOrSelect === "string" ? getPath(t, pathOrSelect) : pathOrSelect(t),
4576
- [pathOrSelect]
4577
- ),
4578
- (a, b) => Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b)
4579
- );
4580
- },
4581
- set: (path, value) => {
4582
- if (RESERVED.test(path)) throw new Error(`"${path}" belongs to the runtime; use setFilter or an action`);
4583
- runtime.store.dispatch(stateActions.set({ path, value }));
4584
- },
4585
- setFilter: (name, value) => runtime.store.dispatch(stateActions.setFilter({ name, value })),
4586
- subscribe: (path, fn) => {
4587
- let prev = get(path);
4588
- return runtime.store.subscribe(() => {
4589
- const next = get(path);
4590
- if (!Object.is(next, prev) && JSON.stringify(next) !== JSON.stringify(prev)) {
4591
- prev = next;
4592
- fn(next);
4237
+ onClick: activate,
4238
+ role: "button",
4239
+ tabIndex: 0,
4240
+ onKeyDown: (e) => {
4241
+ if (e.key !== "Enter" && e.key !== " ") return;
4242
+ e.preventDefault();
4243
+ activate();
4244
+ }
4245
+ };
4246
+ }
4247
+
4248
+ // src/widgets/shared/motion.ts
4249
+ import { useEffect as useEffect4, useRef as useRef6, useState as useState5 } from "react";
4250
+ var reduced = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4251
+ var easeOut = (t) => 1 - (1 - t) ** 3;
4252
+ function useCountUp(target, ms = 700) {
4253
+ const [shown, setShown] = useState5(() => typeof target === "number" && !reduced() ? 0 : target);
4254
+ const from = useRef6(0);
4255
+ useEffect4(() => {
4256
+ if (typeof target !== "number" || !Number.isFinite(target) || reduced()) {
4257
+ setShown(target);
4258
+ return;
4259
+ }
4260
+ const start = performance.now();
4261
+ const a = from.current;
4262
+ let raf = 0;
4263
+ const step = (now) => {
4264
+ const t = Math.min(1, (now - start) / ms);
4265
+ const v = a + (target - a) * easeOut(t);
4266
+ setShown(Number.isInteger(target) && t === 1 ? target : v);
4267
+ if (t < 1) raf = requestAnimationFrame(step);
4268
+ else from.current = target;
4269
+ };
4270
+ raf = requestAnimationFrame(step);
4271
+ return () => {
4272
+ cancelAnimationFrame(raf);
4273
+ from.current = typeof target === "number" ? target : 0;
4274
+ };
4275
+ }, [target, ms]);
4276
+ return shown;
4277
+ }
4278
+
4279
+ // src/widgets/builtins/Kpi.tsx
4280
+ import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
4281
+ var Kpi = defineWidget({
4282
+ ...KpiContract,
4283
+ implements: "kpi",
4284
+ header: "widget",
4285
+ empty: "widget",
4286
+ meta: { label: "KPI", icon: "kpi", category: "Numbers", size: { w: 3, h: 4, minW: 2, minH: 3 } },
4287
+ events: ["click", "hover"],
4288
+ parts: ["value"],
4289
+ defaults: { title: "New KPI", goodWhen: "up" },
4290
+ component: function KpiWidget({ spec, data, source, emit, helpers, panelId }) {
4291
+ const clickable = useClickable(panelId, () => {
4292
+ }).role === "button";
4293
+ const num = (v) => typeof v === "number" ? v : toNumber(field(source, v));
4294
+ const value = toNumber(data) ?? data;
4295
+ const animated = useCountUp(value);
4296
+ const n = toNumber(value);
4297
+ const fmt = (v) => formatValue(v, helpers, spec.format, spec.decimals);
4298
+ const unit = spec.format === "duration" ? void 0 : spec.unit;
4299
+ const empty = spec.empty === true || value === void 0 || value === null || value === "";
4300
+ const hasTarget = spec.target !== void 0;
4301
+ const target = hasTarget ? num(spec.target) : void 0;
4302
+ const op = spec.goodWhen === "down" ? "\u2264 " : spec.goodWhen === "up" ? "\u2265 " : "";
4303
+ const targetText = spec.targetLabel ?? (target !== void 0 ? `Target: ${op}${fmt(target)}${unit ? spec.format === "percent" ? "" : ` ${unit.toLowerCase()}` : ""}` : void 0);
4304
+ const met = target === void 0 || n === void 0 || spec.goodWhen === "none" ? void 0 : spec.goodWhen === "down" ? n <= target : n >= target;
4305
+ const labels = { good: spec.statusLabels?.good ?? "On track", bad: spec.statusLabels?.bad ?? "Action needed" };
4306
+ const ref = spec.compare === void 0 ? void 0 : typeof spec.compare === "number" ? spec.compare : spec.compare.value !== void 0 ? toNumber(spec.compare.value) : toNumber(field(source, spec.compare.path));
4307
+ const delta = n !== void 0 && ref !== void 0 ? n - ref : void 0;
4308
+ const better = delta === void 0 || delta === 0 || spec.goodWhen === "none" ? void 0 : delta > 0 === (spec.goodWhen === "up");
4309
+ const low = spec.band ? num(spec.band.low) : void 0;
4310
+ const high = spec.band ? num(spec.band.high) : void 0;
4311
+ const outside = n !== void 0 && (low !== void 0 && n < low || high !== void 0 && n > high);
4312
+ const pTarget = spec.progress ? num(spec.progress.target) : void 0;
4313
+ const ratio = n !== void 0 && pTarget ? Math.min(spec.progress?.cap ?? Number.POSITIVE_INFINITY, n / pTarget * 100) : void 0;
4314
+ return /* @__PURE__ */ jsxs10("div", { className: "ds-kpi", "data-size": spec.size, children: [
4315
+ /* @__PURE__ */ jsxs10("div", { className: "ds-kpi-label", children: [
4316
+ /* @__PURE__ */ jsx15("span", { children: spec.title }),
4317
+ spec.info && /* @__PURE__ */ jsx15(InfoTip, { text: spec.info })
4318
+ ] }),
4319
+ /* @__PURE__ */ jsx15(
4320
+ "button",
4321
+ {
4322
+ type: "button",
4323
+ className: "ds-kpi-main",
4324
+ "data-clickable": clickable || void 0,
4325
+ onClick: () => emit("click", "value", { datum: source, value }),
4326
+ onMouseEnter: () => emit("hover", "value", { datum: source, value }),
4327
+ "aria-label": `${spec.title ?? "Value"}: ${empty ? spec.emptyText ?? "no value" : fmt(value)}${unit ? ` ${unit}` : ""}`,
4328
+ children: empty ? (
4329
+ // No value is not zero: the author's text, else a dash.
4330
+ /* @__PURE__ */ jsx15("span", { className: "ds-kpi-empty", children: spec.emptyText || "\u2014" })
4331
+ ) : /* @__PURE__ */ jsxs10(Fragment5, { children: [
4332
+ /* @__PURE__ */ jsxs10(
4333
+ "span",
4334
+ {
4335
+ className: "ds-kpi-value",
4336
+ style: { color: spec.tone ? tone(spec.tone).fg : outside ? tone("bad").fg : void 0 },
4337
+ children: [
4338
+ fmt(animated),
4339
+ unit && spec.unitStyle === "value" ? unit : null
4340
+ ]
4341
+ }
4342
+ ),
4343
+ unit && spec.unitStyle !== "value" && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-unit", children: unit })
4344
+ ] })
4593
4345
  }
4594
- });
4595
- }
4596
- };
4346
+ ),
4347
+ delta !== void 0 && /* @__PURE__ */ jsxs10(
4348
+ "span",
4349
+ {
4350
+ className: "ds-kpi-delta",
4351
+ style: { color: tone(better === void 0 ? "neutral" : better ? "good" : "bad").fg },
4352
+ children: [
4353
+ delta > 0 ? "\u2191" : delta < 0 ? "\u2193" : "\u2192",
4354
+ " ",
4355
+ spec.format === "duration" ? helpers.fmt.duration(Math.abs(delta)) : `${helpers.fmt.number(Math.abs(ref ? delta / Math.abs(ref) * 100 : 0), 1)}%`,
4356
+ typeof spec.compare === "object" && spec.compare.label && /* @__PURE__ */ jsxs10("span", { className: "ds-kpi-sub", children: [
4357
+ " ",
4358
+ spec.compare.label
4359
+ ] })
4360
+ ]
4361
+ }
4362
+ ),
4363
+ spec.note && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-sub", children: spec.note }),
4364
+ spec.sublabel && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-sub", children: spec.sublabel }),
4365
+ low !== void 0 && high !== void 0 && /* @__PURE__ */ jsxs10("span", { className: "ds-kpi-sub", children: [
4366
+ "Expected ",
4367
+ fmt(low),
4368
+ "\u2013",
4369
+ fmt(high)
4370
+ ] }),
4371
+ ratio !== void 0 && // biome-ignore lint/a11y/useFocusableInteractive: a progress bar is read-only, not interactive
4372
+ /* @__PURE__ */ jsx15(
4373
+ "span",
4374
+ {
4375
+ className: "ds-progress",
4376
+ role: "progressbar",
4377
+ "aria-valuenow": Math.round(ratio),
4378
+ "aria-valuemin": 0,
4379
+ "aria-valuemax": 100,
4380
+ children: /* @__PURE__ */ jsx15(
4381
+ "span",
4382
+ {
4383
+ style: { width: `${Math.min(100, ratio)}%`, background: tone(ratio >= 100 ? "good" : "info").solid }
4384
+ }
4385
+ )
4386
+ }
4387
+ ),
4388
+ (hasTarget || targetText) && /* @__PURE__ */ jsxs10("div", { className: "ds-kpi-foot", children: [
4389
+ hasTarget && target === void 0 ? /* @__PURE__ */ jsx15("span", { className: "ds-chip", "data-tone": "bad", children: spec.targetMissing }) : /* @__PURE__ */ jsx15("span", { "data-ds-part": "target", children: targetText }),
4390
+ spec.badge !== false && met !== void 0 && !empty && /* @__PURE__ */ jsx15("span", { className: "ds-chip", "data-tone": met ? "good" : "bad", "data-ds-part": "badge", children: met ? labels.good : labels.bad })
4391
+ ] })
4392
+ ] });
4393
+ }
4394
+ });
4395
+
4396
+ // src/widgets/builtins/Sparkline.tsx
4397
+ import "zod";
4398
+ import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
4399
+ function sparkPath(values, w, h, pad = 2) {
4400
+ if (values.length === 0) return { line: "", area: "" };
4401
+ const min = values.reduce((a, b) => Math.min(a, b));
4402
+ const max = values.reduce((a, b) => Math.max(a, b));
4403
+ const span = max - min || 1;
4404
+ const step = values.length > 1 ? (w - pad * 2) / (values.length - 1) : 0;
4405
+ const pts = values.map((v, i) => [pad + i * step, h - pad - (v - min) / span * (h - pad * 2)]);
4406
+ const line = pts.map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
4407
+ const last = pts[pts.length - 1];
4408
+ return { line, area: `${line} L${last[0].toFixed(1)},${h} L${pad},${h} Z` };
4597
4409
  }
4598
- function findPanel(doc, id) {
4599
- const top = doc.spec.panels[id];
4600
- if (top) return top;
4601
- for (const m of Object.values(doc.spec.modals ?? {})) if (m.panels[id]) return m.panels[id];
4602
- return void 0;
4410
+ function SparkSvg({
4411
+ values,
4412
+ area = true,
4413
+ height = 32,
4414
+ color: color2 = "var(--ds-series-1)"
4415
+ }) {
4416
+ const w = 120;
4417
+ const { line, area: fill } = sparkPath(values, w, height);
4418
+ return /* @__PURE__ */ jsxs11("svg", { viewBox: `0 0 ${w} ${height}`, preserveAspectRatio: "none", style: { width: "100%", height }, "aria-hidden": "true", children: [
4419
+ area && /* @__PURE__ */ jsx16("path", { d: fill, fill: color2, opacity: 0.15 }),
4420
+ /* @__PURE__ */ jsx16("path", { d: line, fill: "none", stroke: color2, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" })
4421
+ ] });
4603
4422
  }
4604
- function useHiddenPanels(ids) {
4605
- const { runtime } = useDashboard();
4606
- const key = ids.join(",");
4607
- const list = useTree(
4608
- // biome-ignore lint/correctness/useExhaustiveDependencies: ids are compared by key
4609
- useCallback4(
4610
- (tree) => ids.filter((id) => {
4611
- const def = findPanel(runtime.doc, id);
4612
- if (!def) return false;
4613
- if (tree.panels[id]?.hidden) return true;
4614
- if (typeof def.visibleWhen !== "string") return false;
4615
- try {
4616
- return !evaluate(
4617
- def.visibleWhen,
4618
- rootScope(tree, runtime.helpers, { panel: tree.panels[id] ?? {}, drill: drillValues(tree, id) })
4619
- );
4620
- } catch {
4621
- return false;
4423
+ var Sparkline = defineWidget({
4424
+ ...SparklineContract,
4425
+ implements: "chart",
4426
+ meta: { label: "Sparkline", icon: "sparkline", category: "Charts", size: { w: 3, h: 2, minW: 2, minH: 1 } },
4427
+ events: ["hover"],
4428
+ defaults: { y: "value" },
4429
+ component: function SparklineWidget({ spec, data, size: size2, emit }) {
4430
+ const rows = asRows(data);
4431
+ const values = rows.map((r) => toNumber(field(r, spec.y)) ?? 0);
4432
+ return /* @__PURE__ */ jsx16(
4433
+ "div",
4434
+ {
4435
+ onMouseEnter: () => emit("hover", "line", { value: values[values.length - 1] }),
4436
+ style: { height: "100%" },
4437
+ role: "img",
4438
+ "aria-label": `${spec.title ?? spec.y}: ${values.length} points`,
4439
+ children: /* @__PURE__ */ jsx16(SparkSvg, { values, area: spec.area, height: Math.max(24, size2.height || 32) })
4440
+ }
4441
+ );
4442
+ }
4443
+ });
4444
+
4445
+ // src/widgets/builtins/StageTracker.tsx
4446
+ import "zod";
4447
+ import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
4448
+ var StageTracker = defineWidget({
4449
+ ...StageTrackerContract,
4450
+ implements: "stages",
4451
+ meta: { label: "Stage tracker", icon: "stages", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
4452
+ events: ["click"],
4453
+ parts: ["stage"],
4454
+ component: function StageTrackerWidget({ spec, data, emit }) {
4455
+ const raw = typeof data === "string" || typeof data === "number" ? data : field(data, spec.current);
4456
+ const idx = typeof raw === "number" ? raw : spec.stages.findIndex((s) => s.toLowerCase() === String(raw ?? "").toLowerCase());
4457
+ return /* @__PURE__ */ jsx17("ol", { className: "ds-stages", children: spec.stages.map((s, i) => {
4458
+ const state = i < idx ? "done" : i === idx ? "current" : "todo";
4459
+ return /* @__PURE__ */ jsx17("li", { "data-state": state, children: /* @__PURE__ */ jsxs12(
4460
+ "button",
4461
+ {
4462
+ type: "button",
4463
+ onClick: () => emit("click", "stage", { value: s, index: i, datum: data }),
4464
+ "aria-current": state === "current" ? "step" : void 0,
4465
+ children: [
4466
+ /* @__PURE__ */ jsx17("span", { className: "ds-stage-dot", "aria-hidden": "true", children: state === "done" ? "\u2713" : i + 1 }),
4467
+ s
4468
+ ]
4622
4469
  }
4470
+ ) }, s);
4471
+ }) });
4472
+ }
4473
+ });
4474
+
4475
+ // src/widgets/builtins/StateTimeline.tsx
4476
+ import "zod";
4477
+ import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
4478
+ var StateTimeline = defineWidget({
4479
+ ...StateTimelineContract,
4480
+ implements: "timeline",
4481
+ meta: { label: "State timeline", icon: "timeline", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
4482
+ events: ["click", "hover"],
4483
+ parts: ["segment"],
4484
+ component: function StateTimelineWidget({ spec, data, emit, helpers }) {
4485
+ const all = asRows(data).map((r) => ({ r, t: Number(field(r, spec.time)), raw: String(field(r, spec.value) ?? "") })).filter((x) => Number.isFinite(x.t)).sort((a, b) => a.t - b.t);
4486
+ const end = helpers.now();
4487
+ const start = spec.window ? end - parseDuration(spec.window) : all[0]?.t ?? end;
4488
+ const lanes = spec.rows ? [...new Set(all.map((x) => String(field(x.r, spec.rows))))] : [""];
4489
+ const span = Math.max(1, end - start);
4490
+ const states = /* @__PURE__ */ new Map();
4491
+ return /* @__PURE__ */ jsxs13("div", { className: "ds-timeline", children: [
4492
+ lanes.map((lane) => {
4493
+ const pts = all.filter((x) => !spec.rows || String(field(x.r, spec.rows)) === lane);
4494
+ const segs = pts.map((p, i) => {
4495
+ const from = Math.max(start, p.t);
4496
+ const to = Math.min(end, pts[i + 1]?.t ?? end);
4497
+ const state = spec.stateMap?.[p.raw] ?? p.raw;
4498
+ states.set(state, (states.get(state) ?? 0) + Math.max(0, to - from));
4499
+ return { p, from, to, state };
4500
+ });
4501
+ return /* @__PURE__ */ jsxs13("div", { className: "ds-timeline-lane", children: [
4502
+ lane && /* @__PURE__ */ jsx18("span", { className: "ds-timeline-name", children: lane }),
4503
+ /* @__PURE__ */ jsx18("div", { className: "ds-timeline-bar", role: "img", "aria-label": `${spec.title ?? "Timeline"} ${lane}`, children: segs.filter((s) => s.to > s.from).map((s) => (
4504
+ // biome-ignore lint/a11y/useKeyWithClickEvents: the per-state totals below summarise the same data for keyboard users
4505
+ /* @__PURE__ */ jsx18(
4506
+ "span",
4507
+ {
4508
+ title: `${s.state} \xB7 ${helpers.fmt.date(s.from, "time")}\u2013${helpers.fmt.date(s.to, "time")} (${helpers.fmt.duration((s.to - s.from) / 1e3)})`,
4509
+ style: {
4510
+ left: `${(s.from - start) / span * 100}%`,
4511
+ width: `${(s.to - s.from) / span * 100}%`,
4512
+ background: tone(spec.tones?.[s.state] ?? "neutral").solid
4513
+ },
4514
+ onClick: () => emit("click", "segment", { datum: s.p.r, value: s.state, x: s.from }),
4515
+ onMouseEnter: () => emit("hover", "segment", { datum: s.p.r, value: s.state, x: s.from })
4516
+ },
4517
+ `${s.from}-${s.state}`
4518
+ )
4519
+ )) })
4520
+ ] }, lane);
4623
4521
  }),
4624
- [key, runtime]
4625
- ),
4626
- (a, b) => a.join(",") === b.join(",")
4627
- );
4628
- return useMemo4(() => new Set(list), [list]);
4629
- }
4630
- function panelUnder(x, y, exclude) {
4631
- if (typeof document === "undefined") return void 0;
4632
- for (const el of document.elementsFromPoint(x, y)) {
4633
- const p = el.closest(".ds-panel[data-panel]");
4634
- if (p && (!exclude || !exclude.contains(p) && !p.contains(exclude))) return p;
4522
+ /* @__PURE__ */ jsxs13("div", { className: "ds-timeline-axis", children: [
4523
+ /* @__PURE__ */ jsx18("span", { children: helpers.fmt.date(start, "time") }),
4524
+ /* @__PURE__ */ jsx18("span", { children: spec.endLabel ?? helpers.fmt.date(end, "time") })
4525
+ ] }),
4526
+ /* @__PURE__ */ jsx18("ul", { className: "ds-legend", children: [...states.entries()].map(([s, ms]) => /* @__PURE__ */ jsxs13("li", { children: [
4527
+ /* @__PURE__ */ jsx18(
4528
+ "span",
4529
+ {
4530
+ className: "ds-dot",
4531
+ style: { background: tone(spec.tones?.[s] ?? "neutral").solid },
4532
+ "aria-hidden": "true"
4533
+ }
4534
+ ),
4535
+ s,
4536
+ " ",
4537
+ /* @__PURE__ */ jsx18("strong", { children: helpers.fmt.duration(ms / 1e3) })
4538
+ ] }, s)) })
4539
+ ] });
4635
4540
  }
4636
- return void 0;
4637
- }
4638
- function indexIn(box, x, y) {
4639
- const row = getComputedStyle(box).flexDirection === "row";
4640
- const kids = [...box.children].filter((c) => c.classList.contains("ds-panel"));
4641
- return kids.filter((k) => {
4642
- const r = k.getBoundingClientRect();
4643
- return row ? r.left + r.width / 2 < x && r.top < y : r.top + r.height / 2 < y;
4644
- }).length;
4645
- }
4646
- function dropIndexAt(panel, x, y) {
4647
- const id = panel.getAttribute("data-panel") ?? "";
4648
- const under = document.elementsFromPoint(x, y).find((el) => el.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`));
4649
- const box = under?.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`) ?? panel.querySelector(`[data-slot][data-owner="${CSS.escape(id)}"]`);
4650
- if (!box) return {};
4651
- return { slot: box.getAttribute("data-slot") ?? void 0, index: indexIn(box, x, y) };
4652
- }
4653
- function PanelFrame({ id, nested = false }) {
4654
- return /* @__PURE__ */ jsx21(Boundary, { resetKeys: [id], fallback: (e) => /* @__PURE__ */ jsx21(PanelCrash, { id, error: e }), children: /* @__PURE__ */ jsx21(PanelFrameInner, { id, nested }) });
4655
- }
4656
- function PanelCrash({ id, error }) {
4657
- const { options } = useDashboard();
4658
- let custom;
4659
- try {
4660
- custom = options.renderError?.({ code: "render", message: error.message }, id);
4661
- } catch {
4662
- custom = void 0;
4541
+ });
4542
+
4543
+ // src/widgets/builtins/Status.tsx
4544
+ import "zod";
4545
+ import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
4546
+ var Status = defineWidget({
4547
+ ...StatusContract,
4548
+ implements: "badge",
4549
+ // A badge, not a card: it can sit anywhere, including in another widget's header.
4550
+ frame: "plain",
4551
+ meta: { label: "Status badge", icon: "status", category: "Numbers", size: { w: 3, h: 2, minW: 1, minH: 1 } },
4552
+ events: ["click"],
4553
+ component: function StatusWidget({ spec, data, emit }) {
4554
+ const row = asRows(data)[0] ?? {};
4555
+ const state = String(field(row, spec.state) ?? "unknown");
4556
+ const t = spec.text ? spec.tone ?? "info" : spec.stateMap?.[state] ?? spec.tone ?? "neutral";
4557
+ const text = spec.text ?? spec.labels?.[state] ?? state.charAt(0).toUpperCase() + state.slice(1);
4558
+ return /* @__PURE__ */ jsxs14("button", { type: "button", className: "ds-status", onClick: () => emit("click", "status", { datum: row, value: state }), children: [
4559
+ /* @__PURE__ */ jsxs14("span", { className: "ds-pill", style: { background: tone(t).bg, color: tone(t).fg, borderColor: tone(t).border }, children: [
4560
+ /* @__PURE__ */ jsx19("span", { className: "ds-dot", style: { background: tone(t).solid }, "aria-hidden": "true" }),
4561
+ text
4562
+ ] }),
4563
+ spec.label && /* @__PURE__ */ jsx19("span", { className: "ds-status-label", children: String(field(row, spec.label) ?? "") })
4564
+ ] });
4663
4565
  }
4664
- return /* @__PURE__ */ jsx21("section", { className: "ds-panel", "data-panel": id, "aria-label": id, children: /* @__PURE__ */ jsx21("div", { className: "ds-panel-body", children: custom ?? /* @__PURE__ */ jsxs16("div", { className: "ds-state ds-state-error", role: "alert", children: [
4665
- "This panel could not be shown: ",
4666
- error.message
4667
- ] }) }) });
4566
+ });
4567
+
4568
+ // src/widgets/builtins/Table.tsx
4569
+ import { useEffect as useEffect5, useMemo as useMemo4, useRef as useRef7, useState as useState6 } from "react";
4570
+ import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
4571
+ var ROW_H = 36;
4572
+ function pageList(current, pages) {
4573
+ if (pages <= 7) return Array.from({ length: pages }, (_, i) => i + 1);
4574
+ const set = new Set([1, pages, current - 1, current, current + 1].filter((n) => n >= 1 && n <= pages));
4575
+ const sorted = [...set].sort((a, b) => a - b);
4576
+ const out = [];
4577
+ sorted.forEach((n, i) => {
4578
+ if (i > 0 && n - sorted[i - 1] > 1) out.push(0);
4579
+ out.push(n);
4580
+ });
4581
+ return out;
4668
4582
  }
4669
- function PanelFrameInner({ id, nested }) {
4670
- const { runtime, registry, options, visibility } = useDashboard();
4671
- const instance = `${id}\0${useId3()}`;
4672
- const inherited = useNodeScope();
4673
- const def = findPanel(runtime.doc, id);
4674
- const widget = registry.byKind.get(def.kind);
4675
- const spec = def.spec ?? {};
4676
- const binding = spec.data;
4677
- const drillLevels = def.drill?.levels ?? [];
4678
- const view = useTree(
4679
- // biome-ignore lint/correctness/useExhaustiveDependencies: the panel definition is fixed for a runtime
4680
- useCallback4(
4681
- (tree) => {
4682
- const ps = tree.panels[id] ?? {};
4683
- const level = drillLevels[(ps.drill ?? []).length];
4684
- const baseSource = level?.source ?? binding?.source;
4685
- const drillId = baseSource && level?.query ? drillSourceId(baseSource, id, level.name) : void 0;
4686
- const source = drillId && runtime.datasourceIds.has(drillId) ? drillId : baseSource;
4687
- const scope2 = rootScope(tree, runtime.helpers, {
4688
- panel: { ...ps, controls: ps.controls ?? {} },
4689
- drill: drillValues(tree, id),
4690
- parent: inherited.parentData,
4691
- ...inherited.hasItem ? { item: inherited.item, index: inherited.index } : {}
4692
- });
4693
- let visible = true;
4694
- if (typeof def.visibleWhen === "string") {
4695
- try {
4696
- visible = Boolean(evaluate(def.visibleWhen, scope2));
4697
- } catch {
4698
- visible = true;
4699
- }
4700
- }
4701
- let data;
4702
- let sourceData;
4703
- let status = "success";
4704
- let error;
4705
- let stale = false;
4706
- let updatedAt;
4707
- if (source) {
4708
- const s = tree.datasources[source];
4709
- status = s?.status ?? "idle";
4710
- error = s?.error;
4711
- stale = Boolean(s?.stale);
4712
- updatedAt = s?.updatedAt;
4713
- sourceData = s?.data;
4714
- data = typeof binding?.path === "string" ? getPath(s?.data, binding.path) : s?.data;
4715
- } else if (binding && typeof binding.panel === "string")
4716
- data = getPath(tree.panels[binding.panel], binding.path ?? "selection");
4717
- else if (binding && typeof binding.state === "string") data = getPath(tree, binding.state);
4718
- else if (binding && "value" in binding) data = binding.value;
4719
- else if (!binding && inherited.parentId) data = inherited.data;
4720
- const { data: _d, ...rest } = spec;
4721
- let props2 = {};
4722
- try {
4723
- props2 = resolvePanel(rest, scope2, Boolean(inherited.hasItem));
4724
- } catch (e) {
4725
- error = { code: "template", message: e.message };
4726
- }
4727
- const msg = def.messages;
4728
- const messages = msg ? resolvePanel(msg, scope2) : void 0;
4729
- const group = props2.highlight ?? void 0;
4730
- return {
4731
- visible,
4732
- hidden: Boolean(ps.hidden),
4733
- panel: ps,
4734
- source,
4735
- data,
4736
- sourceData,
4737
- status,
4738
- error,
4739
- stale,
4740
- updatedAt,
4741
- props: props2,
4742
- messages,
4743
- highlight: group ? tree.highlight[group] : void 0,
4744
- x: level?.x ?? void 0
4745
- };
4746
- },
4747
- [id, runtime, inherited.parentId, inherited.data, inherited.parentData, inherited.item, inherited.index]
4748
- ),
4749
- samePanelView
4750
- );
4751
- const renderNested = useCallback4((child) => /* @__PURE__ */ jsx21(PanelFrame, { id: child, nested: true }, child), []);
4752
- const store = useMemo4(() => widgetStore(runtime), [runtime]);
4753
- const [bodyRef, size2] = useSize();
4754
- const frameRef = useRef7(null);
4755
- useEffect5(() => {
4756
- if (!view.visible || view.hidden) {
4757
- visibility.set(instance, null);
4758
- return;
4759
- }
4760
- const el = frameRef.current;
4761
- if (!el || typeof IntersectionObserver === "undefined") {
4762
- visibility.set(instance, view.source ? [view.source] : []);
4763
- return () => visibility.set(instance, null);
4764
- }
4765
- const io = new IntersectionObserver(
4766
- ([e]) => visibility.set(instance, e?.isIntersecting && view.source ? [view.source] : []),
4767
- { rootMargin: "200px" }
4768
- );
4769
- io.observe(el);
4770
- return () => {
4771
- io.disconnect();
4772
- visibility.set(instance, null);
4583
+ var Table = defineWidget({
4584
+ ...TableContract,
4585
+ implements: "table",
4586
+ exposes: { selection: "the clicked row", page: "current page (ui.page)", search: "search text (ui.search)" },
4587
+ meta: { label: "Table", icon: "table", category: "Lists", size: { w: 12, h: 8, minW: 4, minH: 4 } },
4588
+ events: ["rowClick", "cellClick", "hover"],
4589
+ parts: ["row", "cell"],
4590
+ rows: (data) => asRows(data),
4591
+ component: function TableWidget({ spec, data, source, emit, helpers, size: size2, state, setUi, status }) {
4592
+ const tpl = (t, row, item) => {
4593
+ try {
4594
+ const v = interpolate(t, scope({ row, item, datum: row }, helpers));
4595
+ return v === null || v === void 0 ? "" : String(v);
4596
+ } catch {
4597
+ return "";
4598
+ }
4773
4599
  };
4774
- }, [instance, view.visible, view.hidden, view.source, visibility]);
4775
- const emit = useCallback4(
4776
- (type, part, detail) => {
4777
- const event = { type, panel: id, ...part ? { part } : {}, ...detail };
4778
- options.onEvent?.(event);
4779
- void runtime.emit(event);
4780
- },
4781
- [id, options, runtime]
4782
- );
4783
- const run = useCallback4(
4784
- (action, detail) => void runtime.runAction(action, { type: "click", panel: id, ...detail }),
4785
- [runtime, id]
4786
- );
4787
- const setUi = useCallback4(
4788
- (patch) => runtime.store.dispatch(
4789
- stateActions.patchPanel({ id, patch: { ui: { ...runtime.getTree().panels[id]?.ui, ...patch } } })
4790
- ),
4791
- [runtime, id]
4792
- );
4793
- const dataRef = useRef7(view.data);
4794
- dataRef.current = view.data;
4795
- const props = useMemo4(() => {
4796
- let p = { ...view.props, ...view.panel.props ?? {} };
4797
- if (view.x) p = { ...p, x: view.x };
4798
- p = withFunctions(p, (code) => {
4799
- const f = runtime.scripts.fnProp(code, ["p", "data"]);
4800
- return (arg) => {
4801
- try {
4802
- return f(arg, dataRef.current);
4803
- } catch (e) {
4804
- console.warn(`[dashspec] ${id}: function prop failed: ${e.message}`);
4805
- return "";
4600
+ const base = useMemo4(() => {
4601
+ const rows2 = asRows(data);
4602
+ return spec.pivot ? applyTransform(rows2, [{ pivot: spec.pivot }], scope()) : rows2;
4603
+ }, [data, spec.pivot]);
4604
+ const columns = useMemo4(() => {
4605
+ if (spec.columns?.length) return spec.columns;
4606
+ if (spec.columnsFrom) {
4607
+ const cf = spec.columnsFrom;
4608
+ return asRows(field(source, cf.path)).map((c) => ({
4609
+ key: String(field(c, cf.key)),
4610
+ label: String(field(c, cf.label) ?? field(c, cf.key)),
4611
+ ...cf.type ? { type: cf.type } : {},
4612
+ ...cf.format ? { format: cf.format } : {}
4613
+ }));
4614
+ }
4615
+ return Object.keys(base[0] ?? {}).map((k) => ({ key: k }));
4616
+ }, [spec.columns, spec.columnsFrom, source, base]);
4617
+ const pg = spec.pagination && spec.pagination.enabled !== false ? spec.pagination : void 0;
4618
+ const sr = spec.search === true ? { enabled: true, mode: "client" } : spec.search && spec.search.enabled !== false ? spec.search : void 0;
4619
+ const so = spec.sorting ?? { enabled: true, mode: "client" };
4620
+ const fl = spec.filtering && spec.filtering.enabled !== false ? spec.filtering : void 0;
4621
+ const server = {
4622
+ paging: pg?.mode === "server",
4623
+ search: sr?.mode === "server",
4624
+ sort: so.mode === "server",
4625
+ filter: fl?.mode === "server"
4626
+ };
4627
+ const anyServer = server.paging || server.search || server.sort || server.filter;
4628
+ const ui = state.ui ?? {};
4629
+ const [view, setView] = useState6(() => ({
4630
+ page: Number(ui.page ?? 1),
4631
+ pageSize: Number(ui.pageSize ?? pg?.pageSize ?? 20),
4632
+ search: String(ui.search ?? ""),
4633
+ sortKey: ui.sortKey ?? so.default?.key,
4634
+ sortOrder: ui.sortOrder ?? so.default?.order ?? "asc",
4635
+ filters: ui.filters ?? {}
4636
+ }));
4637
+ const update = (patch) => {
4638
+ const next = { ...view, ...patch };
4639
+ setView(next);
4640
+ if (anyServer)
4641
+ setUi({
4642
+ page: next.page,
4643
+ pageSize: next.pageSize,
4644
+ offset: (next.page - 1) * next.pageSize,
4645
+ search: next.search || void 0,
4646
+ sortKey: next.sortKey,
4647
+ sortOrder: next.sortKey ? next.sortOrder : void 0,
4648
+ ordering: next.sortKey ? `${next.sortOrder === "desc" ? "-" : ""}${next.sortKey}` : void 0,
4649
+ filters: Object.fromEntries(Object.entries(next.filters).filter(([, v]) => v !== ""))
4650
+ });
4651
+ };
4652
+ const [searchText, setSearchText] = useState6(view.search);
4653
+ const searchTimer = useRef7(void 0);
4654
+ useEffect5(() => () => clearTimeout(searchTimer.current), []);
4655
+ const [scrollTop, setScrollTop] = useState6(0);
4656
+ const scroller = useRef7(null);
4657
+ const sort = view.sortKey ? { key: view.sortKey, order: view.sortOrder } : void 0;
4658
+ const rows = useMemo4(() => {
4659
+ let r = base;
4660
+ if (fl && !server.filter)
4661
+ for (const [k, v] of Object.entries(view.filters)) {
4662
+ if (v === "") continue;
4663
+ const c = columns.find((x) => x.key === k);
4664
+ if (c?.filter === "min")
4665
+ r = r.filter((row) => (toNumber(field(row, k)) ?? Number.NEGATIVE_INFINITY) >= Number(v));
4666
+ else if (c?.filter === "select") r = r.filter((row) => String(field(row, k) ?? "") === v);
4667
+ else
4668
+ r = r.filter(
4669
+ (row) => String(field(row, k) ?? "").toLowerCase().includes(v.toLowerCase())
4670
+ );
4806
4671
  }
4807
- };
4808
- });
4809
- return widget ? parseWidgetProps(widget.schema, p).props : p;
4810
- }, [view.props, view.panel.props, view.x, runtime, widget, id]);
4811
- if (!view.visible || view.hidden) return null;
4812
- const ownHeader = widget?.header === "widget";
4813
- const title = ownHeader ? void 0 : props.title;
4814
- const info = ownHeader ? void 0 : props.info;
4815
- const meta2 = props.meta;
4816
- const live2 = Boolean(props.live);
4817
- const drill = view.panel.drill ?? [];
4818
- const controls = def.controls ?? [];
4819
- const tone2 = def.style?.tone ?? (widget?.frame === "plain" ? "plain" : "default");
4820
- const headerKids = slotChildren(def, "header");
4821
- const footerKids = slotChildren(def, "footer");
4822
- const hideHeader = Boolean(def.style?.hideHeader) || !title && !meta2 && !live2 && drill.length === 0 && controls.length === 0 && !view.stale && headerKids.length === 0;
4823
- const dnd = Boolean(options.onDropOnPanel);
4824
- let body;
4825
- if (!widget) body = /* @__PURE__ */ jsxs16("div", { className: "ds-state", children: [
4826
- "Unknown widget \u201C",
4827
- String(def.kind),
4828
- "\u201D"
4829
- ] });
4830
- else if (view.error && view.data === void 0)
4831
- body = options.renderError?.(view.error, id) ?? /* @__PURE__ */ jsx21("div", { className: "ds-state ds-state-error", role: "alert", children: view.messages?.error ?? view.error.message });
4832
- else if (view.source && view.data === void 0 && (view.status === "loading" || view.status === "idle"))
4833
- body = options.renderLoading?.(id, loadingText(view.messages)) ?? /* @__PURE__ */ jsx21(LoadingState, { text: loadingText(view.messages) });
4834
- else if (view.source && isEmpty(view.data) && widget.empty !== "widget")
4835
- body = options.renderEmpty?.(id) ?? /* @__PURE__ */ jsx21("div", { className: "ds-state", children: view.messages?.empty ?? "No data" });
4836
- else {
4837
- const W = widget.component;
4838
- body = /* @__PURE__ */ jsx21(
4839
- Boundary,
4840
- {
4841
- resetKeys: [view.data, props],
4842
- fallback: (e) => /* @__PURE__ */ jsxs16("div", { className: "ds-state ds-state-error", role: "alert", children: [
4843
- "This panel could not be shown: ",
4844
- e.message
4845
- ] }),
4846
- children: /* @__PURE__ */ jsx21(
4847
- W,
4848
- {
4849
- spec: props,
4850
- data: view.data,
4851
- source: view.sourceData,
4852
- run,
4853
- emit,
4854
- state: view.panel,
4855
- setUi,
4856
- status: view.status,
4857
- highlight: view.highlight,
4858
- size: size2,
4859
- mode: options.mode,
4860
- helpers: runtime.helpers,
4861
- panelId: id,
4862
- renderSlot: (name, o) => /* @__PURE__ */ jsx21(Slot, { name, ...o }),
4863
- store
4672
+ if (sr && !server.search && view.search) {
4673
+ const q = view.search.toLowerCase();
4674
+ const fields = sr.mode === "client" && "fields" in sr ? sr.fields : void 0;
4675
+ r = r.filter(
4676
+ (row) => (fields ? fields.map((f) => field(row, f)) : Object.values(row)).some(
4677
+ (v) => v !== null && v !== void 0 && typeof v !== "object" && String(v).toLowerCase().includes(q)
4678
+ )
4679
+ );
4680
+ }
4681
+ if (sort && !server.sort) {
4682
+ const dir = sort.order === "desc" ? -1 : 1;
4683
+ r = [...r].sort((a, b) => {
4684
+ const x = field(a, sort.key);
4685
+ const y = field(b, sort.key);
4686
+ if (x === y) return 0;
4687
+ if (x === null || x === void 0) return 1;
4688
+ if (y === null || y === void 0) return -1;
4689
+ const nx = toNumber(x);
4690
+ const ny = toNumber(y);
4691
+ return (nx !== void 0 && ny !== void 0 ? nx - ny : String(x).localeCompare(String(y), void 0, { numeric: true })) * dir;
4692
+ });
4693
+ }
4694
+ return r;
4695
+ }, [base, view, columns]);
4696
+ const pageSize = pg ? view.pageSize : void 0;
4697
+ const rowTotal = server.paging ? toNumber(field(source, pg?.totalPath ?? "count")) ?? rows.length : rows.length;
4698
+ const pages = pageSize ? Math.max(1, Math.ceil(rowTotal / pageSize)) : 1;
4699
+ const current = Math.min(view.page, pages);
4700
+ const shown = pageSize && !server.paging ? rows.slice((current - 1) * pageSize, current * pageSize) : rows;
4701
+ const hasFilters = Boolean(fl) && columns.some((c) => c.filter);
4702
+ const height = spec.maxHeight ?? Math.max(120, (size2.height || 300) - (sr ? 48 : 0) - (pageSize ? 48 : 0));
4703
+ const windowed = spec.virtual && shown.length > 60;
4704
+ const first = windowed ? Math.max(0, Math.floor(scrollTop / ROW_H) - 10) : 0;
4705
+ const last = windowed ? Math.min(shown.length, first + Math.ceil(height / ROW_H) + 20) : shown.length;
4706
+ const busy = status === "loading" && base.length > 0;
4707
+ const filterChoices = (c) => c.filterOptions ?? [
4708
+ ...new Set(
4709
+ base.map((r) => field(r, c.key)).filter((v) => v !== null && v !== void 0 && v !== "").map(String)
4710
+ )
4711
+ ].sort();
4712
+ const cell = (c, row) => {
4713
+ const v = field(row, c.key);
4714
+ if (c.type === "badge") {
4715
+ const text = c.template ? tpl(c.template, row) : v === null || v === void 0 || v === "" ? "" : String(v);
4716
+ if (!text) return c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "";
4717
+ let t = c.map?.[String(v)] ?? "neutral";
4718
+ if (c.tone) {
4719
+ try {
4720
+ t = String(
4721
+ evaluate(c.tone, scope({ row, value: v }, helpers))
4722
+ );
4723
+ } catch {
4864
4724
  }
4865
- )
4725
+ }
4726
+ return /* @__PURE__ */ jsx20("span", { className: "ds-chip", "data-tone": t, children: text });
4866
4727
  }
4867
- );
4868
- }
4869
- const selected = options.selectedPanel === id;
4870
- const defaultSlot = widget?.slots ? Object.keys(widget.slots)[0] ?? "header" : "header";
4871
- const dropTarget = (target, x, y) => {
4872
- const own = `[data-slot][data-owner="${CSS.escape(id)}"]`;
4873
- const el = target?.closest(own) ?? frameRef.current?.querySelector(`${own}:not([data-slot="header"]):not([data-slot="footer"])`) ?? void 0;
4874
- const name = el?.getAttribute("data-slot") ?? defaultSlot;
4875
- return { slot: name, index: el ? indexIn(el, x, y) : void 0 };
4876
- };
4877
- return /* @__PURE__ */ jsx21(SlotOwnerContext.Provider, { value: { id, data: view.data, def }, children: /* @__PURE__ */ jsx21(SlotChildContext.Provider, { value: renderNested, children: /* @__PURE__ */ jsxs16(
4878
- "section",
4879
- {
4880
- ref: frameRef,
4881
- className: "ds-panel",
4882
- style: panelStyle(def.style),
4883
- "data-tone": tone2,
4884
- "data-panel": id,
4885
- "data-selected": selected || void 0,
4886
- "data-nested": nested || void 0,
4887
- "aria-label": title ?? id,
4888
- draggable: dnd && nested ? true : void 0,
4889
- onDragStart: dnd && nested ? (e) => {
4890
- e.stopPropagation();
4891
- e.dataTransfer.setData("text/plain", id);
4892
- e.dataTransfer.effectAllowed = "move";
4893
- options.onDragPanelStart?.(id);
4894
- } : void 0,
4895
- onDragOver: dnd ? (e) => {
4896
- const t = dropTarget(e.target, e.clientX, e.clientY);
4897
- if (!options.canDropOn?.(id, void 0, t.slot)) return;
4898
- e.preventDefault();
4899
- e.stopPropagation();
4900
- frameRef.current?.setAttribute("data-drop-over", t.slot);
4901
- } : void 0,
4902
- onDragLeave: dnd ? (e) => {
4903
- if (!frameRef.current?.contains(e.relatedTarget))
4904
- frameRef.current?.removeAttribute("data-drop-over");
4905
- } : void 0,
4906
- onDrop: dnd ? (e) => {
4907
- frameRef.current?.removeAttribute("data-drop-over");
4908
- const t = dropTarget(e.target, e.clientX, e.clientY);
4909
- if (!options.canDropOn?.(id, void 0, t.slot)) return;
4910
- e.preventDefault();
4911
- e.stopPropagation();
4912
- options.onDropOnPanel?.(id, t.index, void 0, t.slot);
4913
- } : void 0,
4914
- onPointerDownCapture: options.onPanelSelect ? (e) => {
4915
- const el = partAt(e.target, frameRef.current);
4916
- markPart(frameRef.current, el?.node);
4917
- options.onPanelSelect?.(id, el?.part);
4918
- } : void 0,
4919
- onClickCapture: options.onPanelSelect ? (e) => {
4920
- e.preventDefault();
4921
- e.stopPropagation();
4922
- } : void 0,
4923
- children: [
4924
- !hideHeader && /* @__PURE__ */ jsxs16("header", { className: "ds-panel-head", children: [
4925
- /* @__PURE__ */ jsxs16("div", { style: { minWidth: 0 }, children: [
4926
- title && /* @__PURE__ */ jsxs16("h3", { className: "ds-panel-title", children: [
4927
- title,
4928
- info && /* @__PURE__ */ jsx21(InfoTip, { text: info })
4929
- ] }),
4930
- drill.length > 0 && /* @__PURE__ */ jsxs16("nav", { className: "ds-crumbs", "aria-label": "Drill path", children: [
4931
- /* @__PURE__ */ jsx21("button", { type: "button", onClick: () => runtime.runAction({ do: "drillReset", panel: id }), children: "All" }),
4932
- drill.map((d, i) => /* @__PURE__ */ jsxs16("span", { children: [
4933
- "\u203A",
4934
- " ",
4935
- i < drill.length - 1 ? /* @__PURE__ */ jsx21(
4936
- "button",
4728
+ if (c.template) return tpl(c.template, row) || (c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "");
4729
+ if (c.list !== void 0) {
4730
+ const items = Array.isArray(v) ? v : [];
4731
+ if (items.length === 0) return c.empty ?? "";
4732
+ return /* @__PURE__ */ jsx20("span", { className: "ds-cell-list", children: items.map((it, i) => (
4733
+ // biome-ignore lint/suspicious/noArrayIndexKey: list items have no id and never reorder within a render
4734
+ /* @__PURE__ */ jsx20("span", { children: tpl(c.list, row, it) }, i)
4735
+ )) });
4736
+ }
4737
+ if (v === null || v === void 0 || v === "")
4738
+ return c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "";
4739
+ switch (c.type) {
4740
+ case "link": {
4741
+ const href = safeLink(c.href ? tpl(c.href, row) : String(v));
4742
+ return href ? /* @__PURE__ */ jsx20("a", { className: "ds-link", href, onClick: (e) => e.stopPropagation(), children: String(v) }) : String(v);
4743
+ }
4744
+ case "image":
4745
+ return safeImageSrc(v) ? /* @__PURE__ */ jsx20("img", { src: v, alt: "", style: { height: 28, borderRadius: 4 } }) : null;
4746
+ case "progress": {
4747
+ const n = toNumber(v) ?? 0;
4748
+ const pct = Math.min(100, n / (c.max ?? 100) * 100);
4749
+ return /* @__PURE__ */ jsxs15("span", { className: "ds-inline", children: [
4750
+ /* @__PURE__ */ jsx20("span", { className: "ds-progress", style: { flex: 1, minWidth: 40 }, children: /* @__PURE__ */ jsx20("span", { style: { width: `${pct}%`, background: "var(--ds-series-1)" } }) }),
4751
+ formatValue(n, helpers, c.format, c.decimals),
4752
+ c.suffix
4753
+ ] });
4754
+ }
4755
+ case "sparkline":
4756
+ return /* @__PURE__ */ jsx20(
4757
+ SparkSvg,
4758
+ {
4759
+ values: (Array.isArray(v) ? v : []).map(
4760
+ (x) => toNumber(typeof x === "object" ? field(x, "value") : x) ?? 0
4761
+ ),
4762
+ height: 24,
4763
+ area: false
4764
+ }
4765
+ );
4766
+ default:
4767
+ return `${c.prefix ?? ""}${typeof v === "number" || c.format ? formatValue(v, helpers, c.format, c.decimals) : String(v)}${c.suffix ?? ""}`;
4768
+ }
4769
+ };
4770
+ const total = (c) => {
4771
+ const how = spec.totals?.columns[c.key];
4772
+ if (!how) return null;
4773
+ const nums = rows.map((r) => toNumber(field(r, c.key))).filter((n) => n !== void 0);
4774
+ if (how !== "count" && nums.length === 0) return "";
4775
+ const v = how === "count" ? rows.length : how === "sum" ? nums.reduce((a, b) => a + b, 0) : how === "avg" ? nums.reduce((a, b) => a + b, 0) / (nums.length || 1) : how === "min" ? nums.reduce((a, b) => Math.min(a, b)) : nums.reduce((a, b) => Math.max(a, b));
4776
+ return `${c.prefix ?? ""}${formatValue(v, helpers, c.format === "date" ? "number" : c.format, c.decimals)}${c.suffix ?? ""}`;
4777
+ };
4778
+ const muted = (row) => {
4779
+ if (!spec.rowMutedWhen) return false;
4780
+ try {
4781
+ return Boolean(evaluate(spec.rowMutedWhen, scope({ row }, helpers)));
4782
+ } catch {
4783
+ return false;
4784
+ }
4785
+ };
4786
+ const align = (c) => c.align ?? (c.type === "number" || c.format && c.format !== "date" && c.format !== "text" ? "right" : "left");
4787
+ return /* @__PURE__ */ jsxs15("div", { className: "ds-table-wrap", "data-density": spec.density, children: [
4788
+ sr && /* @__PURE__ */ jsxs15("div", { className: "ds-table-tools", children: [
4789
+ /* @__PURE__ */ jsxs15("label", { className: "ds-search", children: [
4790
+ /* @__PURE__ */ jsxs15("svg", { viewBox: "0 0 16 16", width: "15", height: "15", "aria-hidden": "true", children: [
4791
+ /* @__PURE__ */ jsx20("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.5" }),
4792
+ /* @__PURE__ */ jsx20("path", { d: "m10.5 10.5 3 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
4793
+ ] }),
4794
+ /* @__PURE__ */ jsx20(
4795
+ "input",
4796
+ {
4797
+ type: "search",
4798
+ "aria-label": "Search table",
4799
+ placeholder: "placeholder" in sr && sr.placeholder || "Search",
4800
+ value: searchText,
4801
+ onChange: (e) => {
4802
+ const v = e.target.value;
4803
+ setSearchText(v);
4804
+ clearTimeout(searchTimer.current);
4805
+ searchTimer.current = setTimeout(() => update({ search: v, page: 1 }), server.search ? 350 : 120);
4806
+ }
4807
+ }
4808
+ )
4809
+ ] }),
4810
+ /* @__PURE__ */ jsxs15("span", { className: "ds-table-count", children: [
4811
+ helpers.fmt.number(rowTotal),
4812
+ " rows"
4813
+ ] })
4814
+ ] }),
4815
+ /* @__PURE__ */ jsxs15(
4816
+ "div",
4817
+ {
4818
+ className: "ds-table-scroll",
4819
+ "data-max": spec.maxHeight !== void 0 || void 0,
4820
+ ref: scroller,
4821
+ style: { maxHeight: height },
4822
+ onScroll: windowed ? (e) => setScrollTop(e.currentTarget.scrollTop) : void 0,
4823
+ children: [
4824
+ busy && /* @__PURE__ */ jsx20("div", { className: "ds-table-busy", "aria-hidden": "true" }),
4825
+ /* @__PURE__ */ jsxs15("table", { className: "ds-table", "aria-busy": busy || void 0, children: [
4826
+ /* @__PURE__ */ jsxs15("thead", { "data-sticky": spec.sticky || void 0, children: [
4827
+ /* @__PURE__ */ jsx20("tr", { children: columns.map((c, i) => {
4828
+ const sorted = sort?.key === c.key ? sort.order : void 0;
4829
+ return /* @__PURE__ */ jsx20(
4830
+ "th",
4831
+ {
4832
+ "data-ds-part": `column:${i}`,
4833
+ style: { textAlign: align(c), width: c.width },
4834
+ "aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
4835
+ children: so.enabled === false || c.sortable === false || c.list !== void 0 ? c.label ?? c.key : /* @__PURE__ */ jsxs15(
4836
+ "button",
4837
+ {
4838
+ type: "button",
4839
+ onClick: () => update(
4840
+ sorted === "asc" ? { sortKey: c.key, sortOrder: "desc", page: 1 } : sorted === "desc" ? { sortKey: void 0, page: 1 } : { sortKey: c.key, sortOrder: "asc", page: 1 }
4841
+ ),
4842
+ children: [
4843
+ c.label ?? c.key,
4844
+ /* @__PURE__ */ jsx20("span", { className: "ds-sort", "data-dir": sorted, "aria-hidden": "true" })
4845
+ ]
4846
+ }
4847
+ )
4848
+ },
4849
+ `${c.key}-${i}`
4850
+ );
4851
+ }) }),
4852
+ hasFilters && /* @__PURE__ */ jsx20("tr", { className: "ds-filter-row", children: columns.map((c, i) => /* @__PURE__ */ jsx20("th", { children: c.filter === "select" ? /* @__PURE__ */ jsx20(
4853
+ SelectControl,
4937
4854
  {
4938
- type: "button",
4939
- onClick: () => runtime.store.dispatch(
4940
- stateActions.patchPanel({ id, patch: { drill: drill.slice(0, i + 1) } })
4941
- ),
4942
- children: String(d.value)
4855
+ size: "sm",
4856
+ block: true,
4857
+ plain: true,
4858
+ ariaLabel: `Filter ${c.label ?? c.key}`,
4859
+ options: [
4860
+ { value: "", label: "All" },
4861
+ ...filterChoices(c).map((o) => ({ value: o, label: o }))
4862
+ ],
4863
+ value: view.filters[c.key] ?? "",
4864
+ onChange: (v) => update({ filters: { ...view.filters, [c.key]: String(v ?? "") }, page: 1 })
4943
4865
  }
4944
- ) : String(d.value)
4945
- ] }, `${d.level}-${i}`))
4866
+ ) : c.filter ? /* @__PURE__ */ jsx20(
4867
+ "input",
4868
+ {
4869
+ className: "ds-cell-filter",
4870
+ type: c.filter === "min" ? "number" : "text",
4871
+ placeholder: c.filter === "min" ? "Min" : "Filter",
4872
+ "aria-label": `Filter ${c.label ?? c.key}`,
4873
+ value: view.filters[c.key] ?? "",
4874
+ onChange: (e) => update({ filters: { ...view.filters, [c.key]: e.target.value }, page: 1 })
4875
+ }
4876
+ ) : null }, `f-${c.key}-${i}`)) })
4877
+ ] }),
4878
+ /* @__PURE__ */ jsxs15("tbody", { children: [
4879
+ windowed && first > 0 && /* @__PURE__ */ jsx20("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx20("td", { colSpan: columns.length, style: { height: first * ROW_H, padding: 0 } }) }),
4880
+ shown.slice(first, last).map((row, k) => {
4881
+ const i = first + k;
4882
+ const key = spec.rowKey ? String(field(row, spec.rowKey)) : String(i);
4883
+ return /* @__PURE__ */ jsx20(
4884
+ "tr",
4885
+ {
4886
+ "data-muted": muted(row) || void 0,
4887
+ onClick: () => emit("rowClick", "row", { datum: row, index: i }),
4888
+ onMouseEnter: () => emit("hover", "row", { datum: row, index: i }),
4889
+ tabIndex: 0,
4890
+ onKeyDown: (e) => e.key === "Enter" && emit("rowClick", "row", { datum: row, index: i }),
4891
+ children: columns.map((c, j) => (
4892
+ // biome-ignore lint/a11y/useKeyWithClickEvents: rows are focusable and open with Enter; cell clicks add detail for pointer users
4893
+ /* @__PURE__ */ jsx20(
4894
+ "td",
4895
+ {
4896
+ style: { textAlign: align(c) },
4897
+ onClick: () => emit("cellClick", "cell", { datum: row, index: i, value: field(row, c.key), column: c.key }),
4898
+ children: cell(c, row)
4899
+ },
4900
+ `${c.key}-${j}`
4901
+ )
4902
+ ))
4903
+ },
4904
+ key
4905
+ );
4906
+ }),
4907
+ windowed && last < shown.length && /* @__PURE__ */ jsx20("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx20("td", { colSpan: columns.length, style: { height: (shown.length - last) * ROW_H, padding: 0 } }) })
4908
+ ] }),
4909
+ spec.totals && /* @__PURE__ */ jsx20("tfoot", { children: /* @__PURE__ */ jsx20("tr", { children: columns.map((c, j) => /* @__PURE__ */ jsx20("td", { style: { textAlign: align(c) }, children: j === 0 && !spec.totals?.columns[c.key] ? spec.totals?.label : total(c) }, `${c.key}-${j}`)) }) })
4946
4910
  ] })
4947
- ] }),
4948
- /* @__PURE__ */ jsxs16("div", { className: "ds-panel-tools", children: [
4949
- headerKids.length > 0 && /* @__PURE__ */ jsx21(Slot, { name: "header", className: "ds-panel-addons" }),
4950
- meta2 && /* @__PURE__ */ jsx21("span", { className: "ds-panel-meta", children: meta2 }),
4951
- live2 ? /* @__PURE__ */ jsxs16("span", { className: "ds-live", "data-stale": view.stale || void 0, title: view.error?.message, children: [
4952
- /* @__PURE__ */ jsx21("span", { "aria-hidden": "true" }),
4953
- "Live, updated ",
4954
- view.updatedAt ? runtime.helpers.fmt.ago(view.updatedAt) : "\u2026"
4955
- ] }) : view.stale && /* @__PURE__ */ jsx21("span", { className: "ds-badge ds-badge-stale", title: view.error?.message, children: "Stale" }),
4956
- controls.map((c) => /* @__PURE__ */ jsx21(
4957
- ControlField,
4911
+ ]
4912
+ }
4913
+ ),
4914
+ pageSize && /* @__PURE__ */ jsxs15("div", { className: "ds-pager", children: [
4915
+ /* @__PURE__ */ jsxs15("span", { className: "ds-pager-size", children: [
4916
+ "Rows",
4917
+ /* @__PURE__ */ jsx20(
4918
+ SelectControl,
4919
+ {
4920
+ size: "sm",
4921
+ plain: true,
4922
+ ariaLabel: "Rows per page",
4923
+ options: (pg?.pageSizes ?? [10, 20, 50, 100]).map((n) => ({ value: n, label: String(n) })),
4924
+ value: pageSize,
4925
+ onChange: (v) => update({ pageSize: Number(v), page: 1 })
4926
+ }
4927
+ )
4928
+ ] }),
4929
+ /* @__PURE__ */ jsxs15("span", { children: [
4930
+ rowTotal === 0 ? 0 : (current - 1) * pageSize + 1,
4931
+ "\u2013",
4932
+ Math.min(current * pageSize, rowTotal),
4933
+ " of",
4934
+ " ",
4935
+ helpers.fmt.number(rowTotal)
4936
+ ] }),
4937
+ /* @__PURE__ */ jsxs15("span", { className: "ds-pages", children: [
4938
+ /* @__PURE__ */ jsx20(
4939
+ "button",
4940
+ {
4941
+ type: "button",
4942
+ "aria-label": "Previous page",
4943
+ disabled: current <= 1,
4944
+ onClick: () => update({ page: current - 1 }),
4945
+ children: "\u2039"
4946
+ }
4947
+ ),
4948
+ pageList(current, pages).map(
4949
+ (n, i) => n === 0 ? /* @__PURE__ */ jsx20("span", { className: "ds-page-gap", children: "\u2026" }, `gap-${i < 3 ? "a" : "b"}`) : /* @__PURE__ */ jsx20(
4950
+ "button",
4958
4951
  {
4959
- def: c,
4960
- compact: true,
4961
- value: view.panel.controls?.[c.name],
4962
- onChange: (v) => runtime.store.dispatch(
4963
- stateActions.patchPanel({
4964
- id,
4965
- patch: { controls: { ...view.panel.controls, [c.name]: v } }
4966
- })
4967
- )
4952
+ type: "button",
4953
+ "aria-current": n === current ? "page" : void 0,
4954
+ onClick: () => update({ page: n }),
4955
+ children: n
4968
4956
  },
4969
- c.name
4970
- ))
4971
- ] })
4972
- ] }),
4973
- /* @__PURE__ */ jsx21("div", { className: "ds-panel-body", ref: bodyRef, children: body }),
4974
- footerKids.length > 0 && /* @__PURE__ */ jsx21(Slot, { name: "footer", className: "ds-panel-foot" })
4975
- ]
4976
- }
4977
- ) }) });
4978
- }
4979
- function loadingText(messages) {
4980
- const v = messages?.loading;
4981
- return v === void 0 || v === null || v === "" ? void 0 : String(v);
4982
- }
4983
- function LoadingState({ text }) {
4984
- if (!text) return /* @__PURE__ */ jsx21("div", { className: "ds-skeleton", "aria-busy": "true", "aria-label": "Loading" });
4985
- return /* @__PURE__ */ jsxs16("output", { className: "ds-loading", "aria-busy": "true", children: [
4986
- /* @__PURE__ */ jsx21("div", { className: "ds-skeleton", "aria-hidden": "true" }),
4987
- /* @__PURE__ */ jsx21("span", { className: "ds-loading-text", children: text })
4988
- ] });
4989
- }
4957
+ n
4958
+ )
4959
+ ),
4960
+ /* @__PURE__ */ jsx20(
4961
+ "button",
4962
+ {
4963
+ type: "button",
4964
+ "aria-label": "Next page",
4965
+ disabled: current >= pages,
4966
+ onClick: () => update({ page: current + 1 }),
4967
+ children: "\u203A"
4968
+ }
4969
+ )
4970
+ ] })
4971
+ ] })
4972
+ ] });
4973
+ }
4974
+ });
4990
4975
 
4991
- // src/widgets/shared/clickable.ts
4992
- function useClickable(panelId, activate) {
4993
- const ctx = useContext4(DashboardContext);
4994
- const def = ctx && panelId ? findPanel(ctx.runtime.doc, panelId) : void 0;
4995
- const on = def?.on;
4996
- if (on?.click === void 0) return { onClick: activate };
4997
- return {
4998
- onClick: activate,
4999
- role: "button",
5000
- tabIndex: 0,
5001
- onKeyDown: (e) => {
5002
- if (e.key !== "Enter" && e.key !== " ") return;
5003
- e.preventDefault();
5004
- activate();
5005
- }
5006
- };
4976
+ // src/widgets/builtins/Tiles.tsx
4977
+ import "zod";
4978
+ import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
4979
+ var Tiles = defineWidget({
4980
+ ...TilesContract,
4981
+ implements: "tiles",
4982
+ exposes: { selection: "the clicked tile's row" },
4983
+ meta: { label: "Tiles", icon: "tiles", category: "Numbers", size: { w: 12, h: 4, minW: 3, minH: 3 } },
4984
+ events: ["click", "hover", "select"],
4985
+ parts: ["tile"],
4986
+ defaults: { label: "name", value: "value" },
4987
+ component: function TilesWidget({ spec, data, emit, helpers }) {
4988
+ const rows = asRows(data);
4989
+ const caption = (row) => {
4990
+ if (!spec.caption) return void 0;
4991
+ try {
4992
+ return String(interpolate(spec.caption, scope({ row }, helpers)) ?? "");
4993
+ } catch {
4994
+ return spec.caption;
4995
+ }
4996
+ };
4997
+ return /* @__PURE__ */ jsx21(
4998
+ "div",
4999
+ {
5000
+ className: "ds-tiles",
5001
+ role: spec.selectable ? "radiogroup" : "list",
5002
+ "aria-label": spec.title,
5003
+ "data-wrap": spec.wrap === false ? "off" : void 0,
5004
+ style: {
5005
+ "--ds-tile-min": `${spec.minTileWidth ?? 128}px`,
5006
+ ...spec.columns ? { "--ds-tile-cols": spec.columns } : {}
5007
+ },
5008
+ children: rows.map((r, i) => {
5009
+ const label = field(r, spec.label);
5010
+ const v = field(r, spec.value);
5011
+ const n = toNumber(v);
5012
+ const status = spec.status ? String(field(r, spec.status)) : void 0;
5013
+ const st = status ? spec.statusMap?.[status] ?? status : void 0;
5014
+ const vt = n === void 0 || !spec.valueTone ? void 0 : n > 0 ? spec.valueTone.positive : n < 0 ? spec.valueTone.negative : spec.valueTone.zero;
5015
+ const active = spec.selectable && spec.selected !== void 0 && spec.selected === label;
5016
+ return /* @__PURE__ */ jsxs16(
5017
+ "button",
5018
+ {
5019
+ type: "button",
5020
+ className: "ds-tile",
5021
+ role: spec.selectable ? "radio" : "listitem",
5022
+ "aria-checked": spec.selectable ? active : void 0,
5023
+ "data-active": active || void 0,
5024
+ onClick: () => {
5025
+ emit("click", "tile", { datum: r, value: label, index: i });
5026
+ if (spec.selectable) emit("select", "tile", { datum: r, value: label, index: i });
5027
+ },
5028
+ onMouseEnter: () => emit("hover", "tile", { datum: r, value: label, index: i }),
5029
+ children: [
5030
+ /* @__PURE__ */ jsxs16("span", { className: "ds-tile-label", children: [
5031
+ st && /* @__PURE__ */ jsx21("span", { className: "ds-dot", style: { background: tone(st).solid }, "aria-hidden": "true" }),
5032
+ String(label ?? ""),
5033
+ spec.count && /* @__PURE__ */ jsx21("span", { className: "ds-chip-count", children: String(field(r, spec.count) ?? "") })
5034
+ ] }),
5035
+ /* @__PURE__ */ jsxs16(
5036
+ "span",
5037
+ {
5038
+ className: "ds-tile-value",
5039
+ style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
5040
+ children: [
5041
+ /* @__PURE__ */ jsx21(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
5042
+ spec.unit && /* @__PURE__ */ jsx21("span", { className: "ds-kpi-unit", children: spec.unit })
5043
+ ]
5044
+ }
5045
+ ),
5046
+ spec.caption && /* @__PURE__ */ jsx21("span", { className: "ds-tile-caption", children: caption(r) })
5047
+ ]
5048
+ },
5049
+ `${String(label)}-${i}`
5050
+ );
5051
+ })
5052
+ }
5053
+ );
5054
+ }
5055
+ });
5056
+ function CountUp({ value, render }) {
5057
+ const n = toNumber(value);
5058
+ const shown = useCountUp(n ?? value);
5059
+ return /* @__PURE__ */ jsx21(Fragment6, { children: render(n === void 0 ? value : shown) });
5007
5060
  }
5008
5061
 
5009
5062
  // src/widgets/builtins/atoms.tsx
5063
+ import "zod";
5010
5064
  import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
5011
5065
  var color = (t) => t === "subtle" ? "var(--ds-color-text-subtle)" : t === "primary" ? "var(--ds-color-action-primary)" : t && t !== "default" ? tone(t).fg : void 0;
5012
5066
  var boundValue = (data, path) => {
@@ -5993,10 +6047,17 @@ function Grid({
5993
6047
  return Object.fromEntries(
5994
6048
  Object.entries(rgl).map(([bp, l]) => [
5995
6049
  bp,
5996
- (l ?? []).map((i) => {
5997
- const want = base.fit.has(i.i) ? fitRows[i.i] : void 0;
5998
- return want && want > i.h ? { ...i, h: want } : i;
5999
- })
6050
+ (() => {
6051
+ const rowWant = /* @__PURE__ */ new Map();
6052
+ for (const i of l ?? []) {
6053
+ const want = base.fit.has(i.i) ? fitRows[i.i] : void 0;
6054
+ if (want) rowWant.set(i.y, Math.max(rowWant.get(i.y) ?? 0, want));
6055
+ }
6056
+ return (l ?? []).map((i) => {
6057
+ const want = base.fit.has(i.i) ? rowWant.get(i.y) : void 0;
6058
+ return want && want > i.h ? { ...i, h: want } : i;
6059
+ });
6060
+ })()
6000
6061
  ])
6001
6062
  );
6002
6063
  }, [rgl, base.fit, fitRows, editable]);
@@ -6641,7 +6702,7 @@ var RENDERER_CSS = `
6641
6702
  .ds-tip::after { content: ""; position: absolute; left: var(--ds-tip-arrow); top: 100%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--ds-color-chart-tooltip-bg); }
6642
6703
  .ds-tip[data-below]::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--ds-color-chart-tooltip-bg); }
6643
6704
 
6644
- .ds-chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font: 600 11px/1 var(--ds-font-body); white-space: nowrap; background: var(--ds-color-status-neutral-bg); color: var(--ds-color-status-neutral-fg); }
6705
+ .ds-chip { display: inline-flex; align-items: center; height: var(--ds-chip-height, 22px); padding: 0 var(--ds-chip-padding-x, 8px); border-radius: var(--ds-chip-radius, 6px); border-width: var(--ds-chip-border, 1px); font: var(--ds-chip-weight, 600) var(--ds-chip-font-size, 11px)/1 var(--ds-font-body); white-space: nowrap; background: var(--ds-color-status-neutral-bg); color: var(--ds-color-status-neutral-fg); }
6645
6706
  .ds-chip[data-tone="good"] { background: var(--ds-color-status-good-bg); color: var(--ds-color-status-good-fg); }
6646
6707
  .ds-chip[data-tone="bad"] { background: var(--ds-color-status-bad-bg); color: var(--ds-color-status-bad-fg); }
6647
6708
  .ds-chip[data-tone="warn"] { background: var(--ds-color-status-warn-bg); color: var(--ds-color-status-warn-fg); }
@@ -6664,9 +6725,13 @@ var RENDERER_CSS = `
6664
6725
  /* Grid items with fit: the panel takes its natural height (at least the cell's), so the grid can measure it. */
6665
6726
  [data-fit] > .ds-fit { height: 100%; }
6666
6727
  .ds-fit > .ds-panel { height: auto !important; min-height: 100%; }
6667
- [data-fit] .ds-panel-body { flex: none; }
6728
+ /* The body still fills a taller card, so footers (a KPI's target chip) stay at the bottom. */
6729
+ [data-fit] .ds-panel-body { flex: 1 0 auto; display: flex; flex-direction: column; }
6730
+ [data-fit] .ds-panel-body > * { flex: 1 0 auto; }
6668
6731
  [data-fit] .ds-tiles, [data-fit] .ds-table-wrap { height: auto; max-height: none; overflow-y: visible; }
6732
+ /* In a fit card the rows set the height, unless the table has its own maxHeight. */
6669
6733
  [data-fit] .ds-table-scroll { flex: none; }
6734
+ [data-fit] .ds-table-scroll:not([data-max]) { max-height: none !important; overflow-y: visible; }
6670
6735
  .ds-tiles[data-wrap="off"] { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(var(--ds-tile-min, 128px), 1fr); overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; }
6671
6736
  .ds-tiles[data-wrap="off"] > * { scroll-snap-align: start; }
6672
6737
  .ds-tile { min-width: 0; overflow-wrap: anywhere; }
@@ -6718,7 +6783,7 @@ var RENDERER_CSS = `
6718
6783
  .ds-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(21, 121, 190, .10); }
6719
6784
  .ds-tile:active { transform: translateY(0); }
6720
6785
  .ds-kpi-main { transition: opacity 160ms ease; }
6721
- .ds-kpi-main:hover .ds-kpi-value { color: var(--ds-color-action-primary); transition: color 160ms ease; }
6786
+ .ds-kpi-main[data-clickable]:hover .ds-kpi-value { color: var(--ds-color-action-primary); transition: color 160ms ease; }
6722
6787
  .ds-chip { animation: ds-fade 300ms ease both; transition: background 200ms ease, color 200ms ease; }
6723
6788
  .ds-progress > span { transform-origin: left; animation: ds-grow-x 800ms cubic-bezier(.2,.7,.2,1) both; transition: width 500ms cubic-bezier(.2,.7,.2,1); }
6724
6789
  .ds-segbar button { transform-origin: left; animation: ds-grow-x 700ms cubic-bezier(.2,.7,.2,1) both; }