@dashspec/renderer 0.1.3 → 0.1.5

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
@@ -110,11 +110,12 @@ import {
110
110
  safeLink,
111
111
  satisfies,
112
112
  scope,
113
+ stripStrings,
113
114
  templateReferences,
114
115
  translator,
115
116
  validateDocument,
116
117
  widgetChecks
117
- } from "./chunk-HB2WSKUI.js";
118
+ } from "./chunk-7J6WHLG6.js";
118
119
  import {
119
120
  createStateProxy,
120
121
  getPath,
@@ -166,8 +167,8 @@ import {
166
167
  useEffect as useEffect11,
167
168
  useImperativeHandle,
168
169
  useMemo as useMemo8,
169
- useRef as useRef13,
170
- useState as useState9
170
+ useRef as useRef14,
171
+ useState as useState10
171
172
  } from "react";
172
173
 
173
174
  // src/designSystem.ts
@@ -1643,6 +1644,12 @@ function themeCssVars(theme, mode) {
1643
1644
  out["--ds-control-height"] = `${d.control}px`;
1644
1645
  out["--ds-density"] = density;
1645
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`;
1646
1653
  flatten("--ds-shadow", s.shadow, out);
1647
1654
  flatten("--ds-z", s.z, out);
1648
1655
  out["--ds-motion-fast"] = `${s.motion.fast}ms`;
@@ -3184,43 +3191,45 @@ function FilterBar() {
3184
3191
  className: "ds-filters",
3185
3192
  role: "toolbar",
3186
3193
  "aria-label": "Filters",
3187
- "data-look": bar.look === "plain" ? "plain" : void 0,
3194
+ "data-look": bar.look === "plain" || bar.look === "segmented" ? bar.look : void 0,
3188
3195
  "data-picked": options.selectedFilter === BAR || void 0,
3189
3196
  "data-editable": options.onFilterSelect ? "" : void 0,
3190
3197
  onPointerDown: options.onFilterSelect ? (e) => {
3191
3198
  if (!e.target.closest(".ds-filter-pick")) options.onFilterSelect?.(BAR);
3192
3199
  } : void 0,
3193
3200
  children: [
3194
- bar.icon !== "none" && /* @__PURE__ */ jsx8("span", { className: "ds-filters-icon", "aria-hidden": "true", children: BAR_ICONS[bar.icon ?? "sliders"] ?? BAR_ICONS.sliders }),
3195
- shown.map(
3196
- (v) => options.onFilterSelect ? (
3197
- // Builder: a click selects the filter to configure it instead of opening it.
3198
- /* @__PURE__ */ jsx8(
3199
- "div",
3200
- {
3201
- className: "ds-filter-pick",
3202
- "data-selected": options.selectedFilter === v.name || void 0,
3203
- onPointerDownCapture: () => options.onFilterSelect?.(v.name),
3204
- onClickCapture: (e) => {
3205
- e.preventDefault();
3206
- e.stopPropagation();
3201
+ /* @__PURE__ */ jsxs5(Track, { segmented: bar.look === "segmented", children: [
3202
+ bar.icon !== "none" && /* @__PURE__ */ jsx8("span", { className: "ds-filters-icon", "aria-hidden": "true", children: BAR_ICONS[bar.icon ?? "sliders"] ?? BAR_ICONS.sliders }),
3203
+ shown.map(
3204
+ (v) => options.onFilterSelect ? (
3205
+ // Builder: a click selects the filter to configure it instead of opening it.
3206
+ /* @__PURE__ */ jsx8(
3207
+ "div",
3208
+ {
3209
+ className: "ds-filter-pick",
3210
+ "data-selected": options.selectedFilter === v.name || void 0,
3211
+ onPointerDownCapture: () => options.onFilterSelect?.(v.name),
3212
+ onClickCapture: (e) => {
3213
+ e.preventDefault();
3214
+ e.stopPropagation();
3215
+ },
3216
+ children: /* @__PURE__ */ jsx8(ControlField, { compact: true, def: v, value: values[v.name], onChange: () => {
3217
+ } })
3207
3218
  },
3208
- children: /* @__PURE__ */ jsx8(ControlField, { compact: true, def: v, value: values[v.name], onChange: () => {
3209
- } })
3219
+ v.name
3220
+ )
3221
+ ) : /* @__PURE__ */ jsx8(
3222
+ ControlField,
3223
+ {
3224
+ compact: true,
3225
+ def: v,
3226
+ value: values[v.name],
3227
+ onChange: (val) => set(v.name, val, applyMode(v) === "change")
3210
3228
  },
3211
3229
  v.name
3212
3230
  )
3213
- ) : /* @__PURE__ */ jsx8(
3214
- ControlField,
3215
- {
3216
- compact: true,
3217
- def: v,
3218
- value: values[v.name],
3219
- onChange: (val) => set(v.name, val, applyMode(v) === "change")
3220
- },
3221
- v.name
3222
3231
  )
3223
- ),
3232
+ ] }),
3224
3233
  (needsApply || bar.reset) && /* @__PURE__ */ jsx8("span", { className: "ds-filters-spacer" }),
3225
3234
  bar.reset && /* @__PURE__ */ jsx8(
3226
3235
  "button",
@@ -3318,6 +3327,9 @@ function FilterDrawer({ active, children }) {
3318
3327
  )
3319
3328
  ] });
3320
3329
  }
3330
+ function Track({ segmented, children }) {
3331
+ return segmented ? /* @__PURE__ */ jsx8("div", { className: "ds-filters-track", children }) : /* @__PURE__ */ jsx8(Fragment3, { children });
3332
+ }
3321
3333
 
3322
3334
  // src/widgets/builtins/Filter.tsx
3323
3335
  import { jsx as jsx9 } from "react/jsx-runtime";
@@ -3445,1502 +3457,1567 @@ var ImageMap = defineWidget({
3445
3457
  import "zod";
3446
3458
 
3447
3459
  // src/widgets/shared/InfoTip.tsx
3460
+ import { useLayoutEffect as useLayoutEffect2, useRef as useRef4, useState as useState3 } from "react";
3461
+ import { createPortal as createPortal2 } from "react-dom";
3448
3462
  import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
3449
3463
  function InfoTip({ text }) {
3450
- return /* @__PURE__ */ jsx12("button", { type: "button", className: "ds-info", "aria-label": text, "data-tip": text, onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs7("svg", { viewBox: "0 0 16 16", width: "14", height: "14", "aria-hidden": "true", children: [
3451
- /* @__PURE__ */ jsx12("circle", { cx: "8", cy: "8", r: "6.5", fill: "none", stroke: "currentColor", strokeWidth: "1" }),
3452
- /* @__PURE__ */ jsx12("path", { d: "M8 7.2v3.6M8 5.2v.1", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round" })
3453
- ] }) });
3454
- }
3455
-
3456
- // src/widgets/shared/motion.ts
3457
- import { useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
3458
- var reduced = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
3459
- var easeOut = (t) => 1 - (1 - t) ** 3;
3460
- function useCountUp(target, ms = 700) {
3461
- const [shown, setShown] = useState3(() => typeof target === "number" && !reduced() ? 0 : target);
3462
- const from = useRef4(0);
3463
- useEffect3(() => {
3464
- if (typeof target !== "number" || !Number.isFinite(target) || reduced()) {
3465
- setShown(target);
3466
- return;
3467
- }
3468
- const start = performance.now();
3469
- const a = from.current;
3470
- let raf = 0;
3471
- const step = (now) => {
3472
- const t = Math.min(1, (now - start) / ms);
3473
- const v = a + (target - a) * easeOut(t);
3474
- setShown(Number.isInteger(target) && t === 1 ? target : v);
3475
- if (t < 1) raf = requestAnimationFrame(step);
3476
- else from.current = target;
3477
- };
3478
- raf = requestAnimationFrame(step);
3479
- return () => {
3480
- cancelAnimationFrame(raf);
3481
- from.current = typeof target === "number" ? target : 0;
3482
- };
3483
- }, [target, ms]);
3484
- return shown;
3485
- }
3486
-
3487
- // src/widgets/builtins/Kpi.tsx
3488
- import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
3489
- var Kpi = defineWidget({
3490
- ...KpiContract,
3491
- implements: "kpi",
3492
- header: "widget",
3493
- empty: "widget",
3494
- meta: { label: "KPI", icon: "kpi", category: "Numbers", size: { w: 3, h: 4, minW: 2, minH: 3 } },
3495
- events: ["click", "hover"],
3496
- parts: ["value"],
3497
- defaults: { title: "New KPI", goodWhen: "up" },
3498
- component: function KpiWidget({ spec, data, source, emit, helpers }) {
3499
- const num = (v) => typeof v === "number" ? v : toNumber(field(source, v));
3500
- const value = toNumber(data) ?? data;
3501
- const animated = useCountUp(value);
3502
- const n = toNumber(value);
3503
- const fmt = (v) => formatValue(v, helpers, spec.format, spec.decimals);
3504
- const unit = spec.format === "duration" ? void 0 : spec.unit;
3505
- const empty = value === void 0 || value === null || value === "";
3506
- const hasTarget = spec.target !== void 0;
3507
- const target = hasTarget ? num(spec.target) : void 0;
3508
- const op = spec.goodWhen === "down" ? "\u2264 " : spec.goodWhen === "up" ? "\u2265 " : "";
3509
- const targetText = spec.targetLabel ?? (target !== void 0 ? `Target: ${op}${fmt(target)}${unit ? spec.format === "percent" ? "" : ` ${unit.toLowerCase()}` : ""}` : void 0);
3510
- const met = target === void 0 || n === void 0 || spec.goodWhen === "none" ? void 0 : spec.goodWhen === "down" ? n <= target : n >= target;
3511
- const labels = { good: spec.statusLabels?.good ?? "On track", bad: spec.statusLabels?.bad ?? "Action needed" };
3512
- 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));
3513
- const delta = n !== void 0 && ref !== void 0 ? n - ref : void 0;
3514
- const better = delta === void 0 || delta === 0 || spec.goodWhen === "none" ? void 0 : delta > 0 === (spec.goodWhen === "up");
3515
- const low = spec.band ? num(spec.band.low) : void 0;
3516
- const high = spec.band ? num(spec.band.high) : void 0;
3517
- const outside = n !== void 0 && (low !== void 0 && n < low || high !== void 0 && n > high);
3518
- const pTarget = spec.progress ? num(spec.progress.target) : void 0;
3519
- const ratio = n !== void 0 && pTarget ? Math.min(spec.progress?.cap ?? Number.POSITIVE_INFINITY, n / pTarget * 100) : void 0;
3520
- return /* @__PURE__ */ jsxs8("div", { className: "ds-kpi", "data-size": spec.size, children: [
3521
- /* @__PURE__ */ jsxs8("div", { className: "ds-kpi-label", children: [
3522
- /* @__PURE__ */ jsx13("span", { children: spec.title }),
3523
- spec.info && /* @__PURE__ */ jsx13(InfoTip, { text: spec.info })
3524
- ] }),
3525
- /* @__PURE__ */ jsx13(
3526
- "button",
3527
- {
3528
- type: "button",
3529
- className: "ds-kpi-main",
3530
- onClick: () => emit("click", "value", { datum: source, value }),
3531
- onMouseEnter: () => emit("hover", "value", { datum: source, value }),
3532
- "aria-label": `${spec.title ?? "Value"}: ${empty ? spec.emptyText ?? "no value" : fmt(value)}${unit ? ` ${unit}` : ""}`,
3533
- children: empty ? (
3534
- // No value is not zero: the author's text, else a dash.
3535
- /* @__PURE__ */ jsx13("span", { className: "ds-kpi-empty", children: spec.emptyText || "\u2014" })
3536
- ) : /* @__PURE__ */ jsxs8(Fragment4, { children: [
3537
- /* @__PURE__ */ jsx13(
3538
- "span",
3539
- {
3540
- className: "ds-kpi-value",
3541
- style: { color: spec.tone ? tone(spec.tone).fg : outside ? tone("bad").fg : void 0 },
3542
- children: fmt(animated)
3543
- }
3544
- ),
3545
- unit && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-unit", children: unit })
3546
- ] })
3547
- }
3548
- ),
3549
- delta !== void 0 && /* @__PURE__ */ jsxs8(
3550
- "span",
3551
- {
3552
- className: "ds-kpi-delta",
3553
- style: { color: tone(better === void 0 ? "neutral" : better ? "good" : "bad").fg },
3554
- children: [
3555
- delta > 0 ? "\u2191" : delta < 0 ? "\u2193" : "\u2192",
3556
- " ",
3557
- spec.format === "duration" ? helpers.fmt.duration(Math.abs(delta)) : `${helpers.fmt.number(Math.abs(ref ? delta / Math.abs(ref) * 100 : 0), 1)}%`,
3558
- typeof spec.compare === "object" && spec.compare.label && /* @__PURE__ */ jsxs8("span", { className: "ds-kpi-sub", children: [
3559
- " ",
3560
- spec.compare.label
3561
- ] })
3562
- ]
3563
- }
3564
- ),
3565
- spec.note && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-sub", children: spec.note }),
3566
- spec.sublabel && /* @__PURE__ */ jsx13("span", { className: "ds-kpi-sub", children: spec.sublabel }),
3567
- low !== void 0 && high !== void 0 && /* @__PURE__ */ jsxs8("span", { className: "ds-kpi-sub", children: [
3568
- "Expected ",
3569
- fmt(low),
3570
- "\u2013",
3571
- fmt(high)
3572
- ] }),
3573
- ratio !== void 0 && // biome-ignore lint/a11y/useFocusableInteractive: a progress bar is read-only, not interactive
3574
- /* @__PURE__ */ jsx13(
3575
- "span",
3576
- {
3577
- className: "ds-progress",
3578
- role: "progressbar",
3579
- "aria-valuenow": Math.round(ratio),
3580
- "aria-valuemin": 0,
3581
- "aria-valuemax": 100,
3582
- children: /* @__PURE__ */ jsx13(
3464
+ const ref = useRef4(null);
3465
+ const tip = useRef4(null);
3466
+ const [open, setOpen] = useState3(false);
3467
+ const [pos, setPos] = useState3(null);
3468
+ useLayoutEffect2(() => {
3469
+ if (!open || !ref.current || !tip.current) return;
3470
+ const a = ref.current.getBoundingClientRect();
3471
+ const t = tip.current.getBoundingClientRect();
3472
+ const gap = 8;
3473
+ const margin = 8;
3474
+ const vw = window.innerWidth || document.documentElement.clientWidth;
3475
+ const below = a.top - t.height - gap < margin;
3476
+ const centre = a.left + a.width / 2;
3477
+ const left = Math.min(Math.max(centre - t.width / 2, margin), Math.max(margin, vw - t.width - margin));
3478
+ setPos({ left, top: below ? a.bottom + gap : a.top - t.height - gap, arrow: centre - left, below });
3479
+ }, [open]);
3480
+ const root = ref.current?.closest(".ds-root") ?? (typeof document !== "undefined" ? document.body : null);
3481
+ return /* @__PURE__ */ jsxs7(
3482
+ "button",
3483
+ {
3484
+ ref,
3485
+ type: "button",
3486
+ className: "ds-info",
3487
+ "aria-label": text,
3488
+ onClick: (e) => e.stopPropagation(),
3489
+ onMouseEnter: () => setOpen(true),
3490
+ onMouseLeave: () => {
3491
+ setOpen(false);
3492
+ setPos(null);
3493
+ },
3494
+ onFocus: () => setOpen(true),
3495
+ onBlur: () => {
3496
+ setOpen(false);
3497
+ setPos(null);
3498
+ },
3499
+ children: [
3500
+ /* @__PURE__ */ jsxs7("svg", { viewBox: "0 0 16 16", width: "14", height: "14", "aria-hidden": "true", children: [
3501
+ /* @__PURE__ */ jsx12("circle", { cx: "8", cy: "8", r: "6.5", fill: "none", stroke: "currentColor", strokeWidth: "1" }),
3502
+ /* @__PURE__ */ jsx12("path", { d: "M8 7.2v3.6M8 5.2v.1", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round" })
3503
+ ] }),
3504
+ open && root && createPortal2(
3505
+ /* @__PURE__ */ jsx12(
3583
3506
  "span",
3584
3507
  {
3585
- style: { width: `${Math.min(100, ratio)}%`, background: tone(ratio >= 100 ? "good" : "info").solid }
3508
+ ref: tip,
3509
+ className: "ds-tip",
3510
+ role: "tooltip",
3511
+ "data-below": pos?.below || void 0,
3512
+ style: {
3513
+ left: pos?.left ?? 0,
3514
+ top: pos?.top ?? 0,
3515
+ visibility: pos ? "visible" : "hidden",
3516
+ ["--ds-tip-arrow"]: `${pos?.arrow ?? 0}px`
3517
+ },
3518
+ children: text
3586
3519
  }
3587
- )
3588
- }
3589
- ),
3590
- (hasTarget || targetText) && /* @__PURE__ */ jsxs8("div", { className: "ds-kpi-foot", children: [
3591
- 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 }),
3592
- 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 })
3593
- ] })
3594
- ] });
3595
- }
3596
- });
3597
-
3598
- // src/widgets/builtins/Sparkline.tsx
3599
- import "zod";
3600
- import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
3601
- function sparkPath(values, w, h, pad = 2) {
3602
- if (values.length === 0) return { line: "", area: "" };
3603
- const min = values.reduce((a, b) => Math.min(a, b));
3604
- const max = values.reduce((a, b) => Math.max(a, b));
3605
- const span = max - min || 1;
3606
- const step = values.length > 1 ? (w - pad * 2) / (values.length - 1) : 0;
3607
- const pts = values.map((v, i) => [pad + i * step, h - pad - (v - min) / span * (h - pad * 2)]);
3608
- const line = pts.map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
3609
- const last = pts[pts.length - 1];
3610
- return { line, area: `${line} L${last[0].toFixed(1)},${h} L${pad},${h} Z` };
3520
+ ),
3521
+ root
3522
+ )
3523
+ ]
3524
+ }
3525
+ );
3611
3526
  }
3612
- function SparkSvg({
3613
- values,
3614
- area = true,
3615
- height = 32,
3616
- color: color2 = "var(--ds-series-1)"
3617
- }) {
3618
- const w = 120;
3619
- const { line, area: fill } = sparkPath(values, w, height);
3620
- return /* @__PURE__ */ jsxs9("svg", { viewBox: `0 0 ${w} ${height}`, preserveAspectRatio: "none", style: { width: "100%", height }, "aria-hidden": "true", children: [
3621
- area && /* @__PURE__ */ jsx14("path", { d: fill, fill: color2, opacity: 0.15 }),
3622
- /* @__PURE__ */ jsx14("path", { d: line, fill: "none", stroke: color2, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" })
3623
- ] });
3527
+
3528
+ // src/widgets/shared/clickable.ts
3529
+ import { useContext as useContext4 } from "react";
3530
+
3531
+ // src/components/PanelFrame.tsx
3532
+ import { useCallback as useCallback4, useEffect as useEffect3, useId as useId3, useMemo as useMemo3, useRef as useRef5, useState as useState4 } from "react";
3533
+
3534
+ // src/widgets/parseProps.ts
3535
+ function without(value, path) {
3536
+ if (path.length === 0 || value === null || typeof value !== "object") return value;
3537
+ const [head, ...rest] = path;
3538
+ if (Array.isArray(value)) {
3539
+ if (typeof head !== "number" || head < 0 || head >= value.length) return value;
3540
+ const copy2 = [...value];
3541
+ if (rest.length === 0) copy2.splice(head, 1);
3542
+ else copy2[head] = without(copy2[head], rest);
3543
+ return copy2;
3544
+ }
3545
+ if (!Object.hasOwn(value, head)) return value;
3546
+ const copy = { ...value };
3547
+ if (rest.length === 0) delete copy[head];
3548
+ else copy[head] = without(copy[head], rest);
3549
+ return copy;
3624
3550
  }
3625
- var Sparkline = defineWidget({
3626
- ...SparklineContract,
3627
- implements: "chart",
3628
- meta: { label: "Sparkline", icon: "sparkline", category: "Charts", size: { w: 3, h: 2, minW: 2, minH: 1 } },
3629
- events: ["hover"],
3630
- defaults: { y: "value" },
3631
- component: function SparklineWidget({ spec, data, size: size2, emit }) {
3632
- const rows = asRows(data);
3633
- const values = rows.map((r) => toNumber(field(r, spec.y)) ?? 0);
3634
- return /* @__PURE__ */ jsx14(
3635
- "div",
3636
- {
3637
- onMouseEnter: () => emit("hover", "line", { value: values[values.length - 1] }),
3638
- style: { height: "100%" },
3639
- role: "img",
3640
- "aria-label": `${spec.title ?? spec.y}: ${values.length} points`,
3641
- children: /* @__PURE__ */ jsx14(SparkSvg, { values, area: spec.area, height: Math.max(24, size2.height || 32) })
3642
- }
3643
- );
3551
+ function parseWidgetProps(schema, props) {
3552
+ let current = props;
3553
+ const dropped = [];
3554
+ for (let round = 0; round < 25; round++) {
3555
+ const r = schema.safeParse(current);
3556
+ if (r.success) return { props: r.data, dropped };
3557
+ const issue = r.error.issues.find((i) => i.path.length > 0);
3558
+ if (!issue) break;
3559
+ const lastIndex = issue.path.reduce((at, k, i) => typeof k === "number" ? i : at, -1);
3560
+ const path = lastIndex >= 0 ? issue.path.slice(0, lastIndex + 1) : issue.path;
3561
+ const next = without(current, path);
3562
+ if (next === current) break;
3563
+ dropped.push(path.join("."));
3564
+ current = next;
3644
3565
  }
3645
- });
3566
+ return { props, dropped };
3567
+ }
3646
3568
 
3647
- // src/widgets/builtins/StageTracker.tsx
3648
- import "zod";
3649
- import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
3650
- var StageTracker = defineWidget({
3651
- ...StageTrackerContract,
3652
- implements: "stages",
3653
- meta: { label: "Stage tracker", icon: "stages", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
3654
- events: ["click"],
3655
- parts: ["stage"],
3656
- component: function StageTrackerWidget({ spec, data, emit }) {
3657
- const raw = typeof data === "string" || typeof data === "number" ? data : field(data, spec.current);
3658
- const idx = typeof raw === "number" ? raw : spec.stages.findIndex((s) => s.toLowerCase() === String(raw ?? "").toLowerCase());
3659
- return /* @__PURE__ */ jsx15("ol", { className: "ds-stages", children: spec.stages.map((s, i) => {
3660
- const state = i < idx ? "done" : i === idx ? "current" : "todo";
3661
- return /* @__PURE__ */ jsx15("li", { "data-state": state, children: /* @__PURE__ */ jsxs10(
3662
- "button",
3663
- {
3664
- type: "button",
3665
- onClick: () => emit("click", "stage", { value: s, index: i, datum: data }),
3666
- "aria-current": state === "current" ? "step" : void 0,
3667
- children: [
3668
- /* @__PURE__ */ jsx15("span", { className: "ds-stage-dot", "aria-hidden": "true", children: state === "done" ? "\u2713" : i + 1 }),
3669
- s
3670
- ]
3671
- }
3672
- ) }, s);
3673
- }) });
3569
+ // src/components/Boundary.tsx
3570
+ import { Component } from "react";
3571
+ var sameKeys = (a, b) => a.length === b.length && a.every((x, i) => Object.is(x, b[i]));
3572
+ var Boundary = class extends Component {
3573
+ state = { error: null };
3574
+ static getDerivedStateFromError(error) {
3575
+ return { error };
3674
3576
  }
3675
- });
3676
-
3677
- // src/widgets/builtins/StateTimeline.tsx
3678
- import "zod";
3679
- import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
3680
- var StateTimeline = defineWidget({
3681
- ...StateTimelineContract,
3682
- implements: "timeline",
3683
- meta: { label: "State timeline", icon: "timeline", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
3684
- events: ["click", "hover"],
3685
- parts: ["segment"],
3686
- component: function StateTimelineWidget({ spec, data, emit, helpers }) {
3687
- 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);
3688
- const end = helpers.now();
3689
- const start = spec.window ? end - parseDuration(spec.window) : all[0]?.t ?? end;
3690
- const lanes = spec.rows ? [...new Set(all.map((x) => String(field(x.r, spec.rows))))] : [""];
3691
- const span = Math.max(1, end - start);
3692
- const states = /* @__PURE__ */ new Map();
3693
- return /* @__PURE__ */ jsxs11("div", { className: "ds-timeline", children: [
3694
- lanes.map((lane) => {
3695
- const pts = all.filter((x) => !spec.rows || String(field(x.r, spec.rows)) === lane);
3696
- const segs = pts.map((p, i) => {
3697
- const from = Math.max(start, p.t);
3698
- const to = Math.min(end, pts[i + 1]?.t ?? end);
3699
- const state = spec.stateMap?.[p.raw] ?? p.raw;
3700
- states.set(state, (states.get(state) ?? 0) + Math.max(0, to - from));
3701
- return { p, from, to, state };
3702
- });
3703
- return /* @__PURE__ */ jsxs11("div", { className: "ds-timeline-lane", children: [
3704
- lane && /* @__PURE__ */ jsx16("span", { className: "ds-timeline-name", children: lane }),
3705
- /* @__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) => (
3706
- // biome-ignore lint/a11y/useKeyWithClickEvents: the per-state totals below summarise the same data for keyboard users
3707
- /* @__PURE__ */ jsx16(
3708
- "span",
3709
- {
3710
- 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)})`,
3711
- style: {
3712
- left: `${(s.from - start) / span * 100}%`,
3713
- width: `${(s.to - s.from) / span * 100}%`,
3714
- background: tone(spec.tones?.[s.state] ?? "neutral").solid
3715
- },
3716
- onClick: () => emit("click", "segment", { datum: s.p.r, value: s.state, x: s.from }),
3717
- onMouseEnter: () => emit("hover", "segment", { datum: s.p.r, value: s.state, x: s.from })
3718
- },
3719
- `${s.from}-${s.state}`
3720
- )
3721
- )) })
3722
- ] }, lane);
3723
- }),
3724
- /* @__PURE__ */ jsxs11("div", { className: "ds-timeline-axis", children: [
3725
- /* @__PURE__ */ jsx16("span", { children: helpers.fmt.date(start, "time") }),
3726
- /* @__PURE__ */ jsx16("span", { children: spec.endLabel ?? helpers.fmt.date(end, "time") })
3727
- ] }),
3728
- /* @__PURE__ */ jsx16("ul", { className: "ds-legend", children: [...states.entries()].map(([s, ms]) => /* @__PURE__ */ jsxs11("li", { children: [
3729
- /* @__PURE__ */ jsx16(
3730
- "span",
3731
- {
3732
- className: "ds-dot",
3733
- style: { background: tone(spec.tones?.[s] ?? "neutral").solid },
3734
- "aria-hidden": "true"
3735
- }
3736
- ),
3737
- s,
3738
- " ",
3739
- /* @__PURE__ */ jsx16("strong", { children: helpers.fmt.duration(ms / 1e3) })
3740
- ] }, s)) })
3741
- ] });
3577
+ componentDidCatch(error, _info) {
3578
+ this.props.onError?.(error);
3742
3579
  }
3743
- });
3744
-
3745
- // src/widgets/builtins/Status.tsx
3746
- import "zod";
3747
- import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
3748
- var Status = defineWidget({
3749
- ...StatusContract,
3750
- implements: "badge",
3751
- // A badge, not a card: it can sit anywhere, including in another widget's header.
3752
- frame: "plain",
3753
- meta: { label: "Status badge", icon: "status", category: "Numbers", size: { w: 3, h: 2, minW: 1, minH: 1 } },
3754
- events: ["click"],
3755
- component: function StatusWidget({ spec, data, emit }) {
3756
- const row = asRows(data)[0] ?? {};
3757
- const state = String(field(row, spec.state) ?? "unknown");
3758
- const t = spec.text ? spec.tone ?? "info" : spec.stateMap?.[state] ?? spec.tone ?? "neutral";
3759
- const text = spec.text ?? spec.labels?.[state] ?? state.charAt(0).toUpperCase() + state.slice(1);
3760
- return /* @__PURE__ */ jsxs12("button", { type: "button", className: "ds-status", onClick: () => emit("click", "status", { datum: row, value: state }), children: [
3761
- /* @__PURE__ */ jsxs12("span", { className: "ds-pill", style: { background: tone(t).bg, color: tone(t).fg, borderColor: tone(t).border }, children: [
3762
- /* @__PURE__ */ jsx17("span", { className: "ds-dot", style: { background: tone(t).solid }, "aria-hidden": "true" }),
3763
- text
3764
- ] }),
3765
- spec.label && /* @__PURE__ */ jsx17("span", { className: "ds-status-label", children: String(field(row, spec.label) ?? "") })
3766
- ] });
3580
+ componentDidUpdate(prev) {
3581
+ if (this.state.error && !sameKeys(prev.resetKeys ?? [], this.props.resetKeys ?? [])) this.setState({ error: null });
3767
3582
  }
3768
- });
3583
+ render() {
3584
+ return this.state.error ? this.props.fallback(this.state.error) : this.props.children;
3585
+ }
3586
+ };
3769
3587
 
3770
- // src/widgets/builtins/Table.tsx
3771
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef5, useState as useState4 } from "react";
3772
- import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
3773
- var ROW_H = 36;
3774
- function pageList(current, pages) {
3775
- if (pages <= 7) return Array.from({ length: pages }, (_, i) => i + 1);
3776
- const set = new Set([1, pages, current - 1, current, current + 1].filter((n) => n >= 1 && n <= pages));
3777
- const sorted = [...set].sort((a, b) => a - b);
3778
- const out = [];
3779
- sorted.forEach((n, i) => {
3780
- if (i > 0 && n - sorted[i - 1] > 1) out.push(0);
3781
- out.push(n);
3782
- });
3783
- return out;
3588
+ // src/components/Slot.tsx
3589
+ import { createContext as createContext3, useContext as useContext3 } from "react";
3590
+ import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
3591
+ var NodeScopeContext = createContext3({});
3592
+ var useNodeScope = () => useContext3(NodeScopeContext);
3593
+ var SlotOwnerContext = createContext3(null);
3594
+ var SlotChildContext = createContext3(null);
3595
+ function slotChildren(def, name) {
3596
+ const slots = def?.slots;
3597
+ const list = slots?.[name];
3598
+ return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
3784
3599
  }
3785
- var Table = defineWidget({
3786
- ...TableContract,
3787
- implements: "table",
3788
- exposes: { selection: "the clicked row", page: "current page (ui.page)", search: "search text (ui.search)" },
3789
- meta: { label: "Table", icon: "table", category: "Lists", size: { w: 12, h: 8, minW: 4, minH: 4 } },
3790
- events: ["rowClick", "cellClick", "hover"],
3791
- parts: ["row", "cell"],
3792
- rows: (data) => asRows(data),
3793
- component: function TableWidget({ spec, data, source, emit, helpers, size: size2, state, setUi, status }) {
3794
- const tpl = (t, row, item) => {
3795
- try {
3796
- const v = interpolate(t, scope({ row, item, datum: row }, helpers));
3797
- return v === null || v === void 0 ? "" : String(v);
3798
- } catch {
3799
- return "";
3800
- }
3801
- };
3802
- const base = useMemo3(() => {
3803
- const rows2 = asRows(data);
3804
- return spec.pivot ? applyTransform(rows2, [{ pivot: spec.pivot }], scope()) : rows2;
3805
- }, [data, spec.pivot]);
3806
- const columns = useMemo3(() => {
3807
- if (spec.columns?.length) return spec.columns;
3808
- if (spec.columnsFrom) {
3809
- const cf = spec.columnsFrom;
3810
- return asRows(field(source, cf.path)).map((c) => ({
3811
- key: String(field(c, cf.key)),
3812
- label: String(field(c, cf.label) ?? field(c, cf.key)),
3813
- ...cf.type ? { type: cf.type } : {},
3814
- ...cf.format ? { format: cf.format } : {}
3815
- }));
3816
- }
3817
- return Object.keys(base[0] ?? {}).map((k) => ({ key: k }));
3818
- }, [spec.columns, spec.columnsFrom, source, base]);
3819
- const pg = spec.pagination && spec.pagination.enabled !== false ? spec.pagination : void 0;
3820
- const sr = spec.search === true ? { enabled: true, mode: "client" } : spec.search && spec.search.enabled !== false ? spec.search : void 0;
3821
- const so = spec.sorting ?? { enabled: true, mode: "client" };
3822
- const fl = spec.filtering && spec.filtering.enabled !== false ? spec.filtering : void 0;
3823
- const server = {
3824
- paging: pg?.mode === "server",
3825
- search: sr?.mode === "server",
3826
- sort: so.mode === "server",
3827
- filter: fl?.mode === "server"
3828
- };
3829
- const anyServer = server.paging || server.search || server.sort || server.filter;
3830
- const ui = state.ui ?? {};
3831
- const [view, setView] = useState4(() => ({
3832
- page: Number(ui.page ?? 1),
3833
- pageSize: Number(ui.pageSize ?? pg?.pageSize ?? 20),
3834
- search: String(ui.search ?? ""),
3835
- sortKey: ui.sortKey ?? so.default?.key,
3836
- sortOrder: ui.sortOrder ?? so.default?.order ?? "asc",
3837
- filters: ui.filters ?? {}
3838
- }));
3839
- const update = (patch) => {
3840
- const next = { ...view, ...patch };
3841
- setView(next);
3842
- if (anyServer)
3843
- setUi({
3844
- page: next.page,
3845
- pageSize: next.pageSize,
3846
- offset: (next.page - 1) * next.pageSize,
3847
- search: next.search || void 0,
3848
- sortKey: next.sortKey,
3849
- sortOrder: next.sortKey ? next.sortOrder : void 0,
3850
- ordering: next.sortKey ? `${next.sortOrder === "desc" ? "-" : ""}${next.sortKey}` : void 0,
3851
- filters: Object.fromEntries(Object.entries(next.filters).filter(([, v]) => v !== ""))
3852
- });
3853
- };
3854
- const [searchText, setSearchText] = useState4(view.search);
3855
- const searchTimer = useRef5(void 0);
3856
- useEffect4(() => () => clearTimeout(searchTimer.current), []);
3857
- const [scrollTop, setScrollTop] = useState4(0);
3858
- const scroller = useRef5(null);
3859
- const sort = view.sortKey ? { key: view.sortKey, order: view.sortOrder } : void 0;
3860
- const rows = useMemo3(() => {
3861
- let r = base;
3862
- if (fl && !server.filter)
3863
- for (const [k, v] of Object.entries(view.filters)) {
3864
- if (v === "") continue;
3865
- const c = columns.find((x) => x.key === k);
3866
- if (c?.filter === "min")
3867
- r = r.filter((row) => (toNumber(field(row, k)) ?? Number.NEGATIVE_INFINITY) >= Number(v));
3868
- else if (c?.filter === "select") r = r.filter((row) => String(field(row, k) ?? "") === v);
3869
- else
3870
- r = r.filter(
3871
- (row) => String(field(row, k) ?? "").toLowerCase().includes(v.toLowerCase())
3872
- );
3873
- }
3874
- if (sr && !server.search && view.search) {
3875
- const q = view.search.toLowerCase();
3876
- const fields = sr.mode === "client" && "fields" in sr ? sr.fields : void 0;
3877
- r = r.filter(
3878
- (row) => (fields ? fields.map((f) => field(row, f)) : Object.values(row)).some(
3879
- (v) => v !== null && v !== void 0 && typeof v !== "object" && String(v).toLowerCase().includes(q)
3880
- )
3600
+ function Slot({
3601
+ name,
3602
+ className,
3603
+ style,
3604
+ data,
3605
+ item,
3606
+ index,
3607
+ empty
3608
+ }) {
3609
+ const { options } = useDashboard();
3610
+ const owner = useContext3(SlotOwnerContext);
3611
+ const outer = useNodeScope();
3612
+ const renderChild = useContext3(SlotChildContext);
3613
+ if (!owner || !renderChild) return null;
3614
+ const ids = slotChildren(owner.def, name);
3615
+ const editing = options.mode === "edit";
3616
+ if (ids.length === 0 && !editing) return null;
3617
+ const hasItem = item !== void 0 || outer.hasItem;
3618
+ const scope2 = {
3619
+ parentId: owner.id,
3620
+ parentData: owner.data,
3621
+ data: data !== void 0 ? data : item !== void 0 ? item : owner.data,
3622
+ hasItem: Boolean(hasItem),
3623
+ item: item !== void 0 ? item : outer.item,
3624
+ index: index !== void 0 ? index : outer.index
3625
+ };
3626
+ return /* @__PURE__ */ jsx13(NodeScopeContext.Provider, { value: scope2, children: /* @__PURE__ */ jsxs8(
3627
+ "div",
3628
+ {
3629
+ className: className ? `ds-slot ${className}` : "ds-slot",
3630
+ style,
3631
+ "data-slot": name,
3632
+ "data-owner": owner.id,
3633
+ "data-empty": ids.length === 0 || void 0,
3634
+ children: [
3635
+ ids.map((id) => /* @__PURE__ */ jsx13(SlotItem, { children: renderChild(id) }, id)),
3636
+ ids.length === 0 && editing && (empty ?? /* @__PURE__ */ jsx13("span", { className: "ds-slot-hint", children: "Drop here" }))
3637
+ ]
3638
+ }
3639
+ ) });
3640
+ }
3641
+ var SlotItem = ({ children }) => /* @__PURE__ */ jsx13(Fragment4, { children });
3642
+
3643
+ // src/components/PanelFrame.tsx
3644
+ import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
3645
+ 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;
3646
+ function useSize() {
3647
+ const [size2, setSize] = useState4({ width: 0, height: 0 });
3648
+ const observer = useRef5(null);
3649
+ const ref = useCallback4((el) => {
3650
+ observer.current?.disconnect();
3651
+ observer.current = null;
3652
+ if (!el || typeof ResizeObserver === "undefined") return;
3653
+ const ro = new ResizeObserver(([e]) => {
3654
+ const r = e?.contentRect;
3655
+ if (r)
3656
+ setSize(
3657
+ (s) => s.width === Math.round(r.width) && s.height === Math.round(r.height) ? s : { width: Math.round(r.width), height: Math.round(r.height) }
3881
3658
  );
3882
- }
3883
- if (sort && !server.sort) {
3884
- const dir = sort.order === "desc" ? -1 : 1;
3885
- r = [...r].sort((a, b) => {
3886
- const x = field(a, sort.key);
3887
- const y = field(b, sort.key);
3888
- if (x === y) return 0;
3889
- if (x === null || x === void 0) return 1;
3890
- if (y === null || y === void 0) return -1;
3891
- const nx = toNumber(x);
3892
- const ny = toNumber(y);
3893
- return (nx !== void 0 && ny !== void 0 ? nx - ny : String(x).localeCompare(String(y), void 0, { numeric: true })) * dir;
3659
+ });
3660
+ ro.observe(el);
3661
+ observer.current = ro;
3662
+ }, []);
3663
+ return [ref, size2];
3664
+ }
3665
+ var DEFERRED = /(^|[^\w.$])(row|item|avg)\b/;
3666
+ var DEFERRED_IN_ITEM = /(^|[^\w.$])(row|avg)\b/;
3667
+ function interpolateMarkdown(v, scope2) {
3668
+ const bodies = placeholders(v);
3669
+ const whole = bodies.length === 1 && v.trim() === `\${${bodies[0]}}`;
3670
+ const r = interpolate(v, scope2, escapeMarkdown);
3671
+ if (!whole) return r;
3672
+ return r === null || r === void 0 ? "" : escapeMarkdown(typeof r === "object" ? JSON.stringify(r) : String(r));
3673
+ }
3674
+ function resolvePanel(v, scope2, inItem = false, key) {
3675
+ const deferred = inItem ? DEFERRED_IN_ITEM : DEFERRED;
3676
+ if (typeof v === "string") {
3677
+ if (placeholders(v).some((b) => deferred.test(stripStrings(b)))) return v;
3678
+ return key === "markdown" ? interpolateMarkdown(v, scope2) : interpolate(v, scope2);
3679
+ }
3680
+ if (Array.isArray(v)) return v.map((x) => resolvePanel(x, scope2, inItem));
3681
+ if (v && typeof v === "object")
3682
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolvePanel(x, scope2, inItem, k)]));
3683
+ return v;
3684
+ }
3685
+ function withFunctions(v, make) {
3686
+ if (Array.isArray(v)) return v.map((x) => withFunctions(x, make));
3687
+ if (v && typeof v === "object") {
3688
+ const o = v;
3689
+ if (typeof o.fn === "string" && Object.keys(o).length === 1) return make(o.fn);
3690
+ return Object.fromEntries(Object.entries(o).map(([k, x]) => [k, withFunctions(x, make)]));
3691
+ }
3692
+ return v;
3693
+ }
3694
+ var SHADOWS = {
3695
+ none: "none",
3696
+ sm: "0 1px 3px rgba(13, 13, 13, 0.08)",
3697
+ md: "0 6px 16px rgba(13, 13, 13, 0.10)",
3698
+ lg: "0 14px 36px rgba(13, 13, 13, 0.14)"
3699
+ };
3700
+ var PADDING = { none: "0", compact: "8px", roomy: "24px" };
3701
+ var colour = (v) => {
3702
+ if (typeof v !== "string" || !v) return void 0;
3703
+ if (/^[a-z]+(-[a-z]+)+$/.test(v) && !v.includes("(")) return `var(--ds-color-${v})`;
3704
+ return /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\)|[a-z]+)$/i.test(v) ? v : void 0;
3705
+ };
3706
+ var size = (v) => typeof v === "number" ? `${v}px` : typeof v === "string" && /^[\d.]+(px|%|rem|em|vw)?$/.test(v) ? v : void 0;
3707
+ var PART_CLASSES = [
3708
+ [".ds-panel-title, .ds-kpi-label", "title"],
3709
+ [".ds-info", "info"],
3710
+ [".ds-panel-meta, .ds-live", "meta"],
3711
+ [".ds-kpi-foot", "target"],
3712
+ [".ds-chip", "badge"],
3713
+ [".ds-kpi-main, .ds-kpi-value, .ds-kpi-unit", "value"],
3714
+ [".ds-kpi-sub, .ds-kpi-delta", "note"],
3715
+ [".ds-tile", "tile"],
3716
+ [".ds-meters > *, .ds-segbar, .ds-legend", "bars"],
3717
+ [".ds-status, .ds-pill", "state"],
3718
+ [".ds-table-tools", "tools"],
3719
+ [".ds-pager", "pager"]
3720
+ ];
3721
+ var PART_SELECTOR = ["[data-ds-part]", ...PART_CLASSES.map(([sel]) => sel)].join(", ");
3722
+ function partAt(target, frame) {
3723
+ let el = target?.closest(PART_SELECTOR) ?? null;
3724
+ while (el && frame?.contains(el)) {
3725
+ if (el.closest(".ds-panel") !== frame) return void 0;
3726
+ const own = el.getAttribute("data-ds-part");
3727
+ if (own) return { part: own, node: el };
3728
+ const hit = PART_CLASSES.find(([sel]) => el?.matches(sel));
3729
+ if (hit) return { part: hit[1], node: el };
3730
+ el = el.parentElement?.closest(PART_SELECTOR) ?? null;
3731
+ }
3732
+ return void 0;
3733
+ }
3734
+ function markPart(frame, node) {
3735
+ const root = frame?.closest(".ds-root") ?? frame?.ownerDocument;
3736
+ for (const n of root?.querySelectorAll(".ds-part-selected") ?? []) n.classList.remove("ds-part-selected");
3737
+ node?.classList.add("ds-part-selected");
3738
+ }
3739
+ function panelStyle(s) {
3740
+ if (!s) return void 0;
3741
+ const out = {};
3742
+ const bg = colour(s.background);
3743
+ if (bg) out.background = bg;
3744
+ if (typeof s.borderWidth === "number" || s.borderColor)
3745
+ out.border = `${s.borderWidth ?? 1}px solid ${colour(s.borderColor) ?? "var(--ds-color-border-default)"}`;
3746
+ if (typeof s.radius === "number") out.borderRadius = s.radius;
3747
+ if (typeof s.shadow === "string" && SHADOWS[s.shadow]) out.boxShadow = SHADOWS[s.shadow];
3748
+ if (typeof s.padding === "number") out.padding = s.padding;
3749
+ else if (typeof s.padding === "string" && PADDING[s.padding]) out.padding = PADDING[s.padding];
3750
+ if (typeof s.minHeight === "number") out.minHeight = s.minHeight;
3751
+ if (typeof s.flex === "string" && /^[\d.\s]*(auto|[\d.]+(px|%|rem)?)?$/.test(s.flex)) out.flex = s.flex;
3752
+ const minW = size(s.minWidth);
3753
+ const maxW = size(s.maxWidth);
3754
+ if (minW) out.minWidth = minW;
3755
+ if (maxW) out.maxWidth = maxW;
3756
+ if (typeof s.align === "string")
3757
+ out.alignSelf = s.align === "start" ? "flex-start" : s.align === "end" ? "flex-end" : s.align;
3758
+ return Object.keys(out).length ? out : void 0;
3759
+ }
3760
+ var samePanelView = (a, b) => Object.keys(a).every(
3761
+ (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])
3762
+ );
3763
+ var RESERVED = /^(filters|panels|view|modal|highlight|datasources|context)(\.|$)/;
3764
+ function widgetStore(runtime) {
3765
+ const get = (path) => getPath(runtime.getTree(), path);
3766
+ return {
3767
+ get,
3768
+ use: function useStoreValue(pathOrSelect) {
3769
+ return useTree(
3770
+ useCallback4(
3771
+ (t) => typeof pathOrSelect === "string" ? getPath(t, pathOrSelect) : pathOrSelect(t),
3772
+ [pathOrSelect]
3773
+ ),
3774
+ (a, b) => Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b)
3775
+ );
3776
+ },
3777
+ set: (path, value) => {
3778
+ if (RESERVED.test(path)) throw new Error(`"${path}" belongs to the runtime; use setFilter or an action`);
3779
+ runtime.store.dispatch(stateActions.set({ path, value }));
3780
+ },
3781
+ setFilter: (name, value) => runtime.store.dispatch(stateActions.setFilter({ name, value })),
3782
+ subscribe: (path, fn) => {
3783
+ let prev = get(path);
3784
+ return runtime.store.subscribe(() => {
3785
+ const next = get(path);
3786
+ if (!Object.is(next, prev) && JSON.stringify(next) !== JSON.stringify(prev)) {
3787
+ prev = next;
3788
+ fn(next);
3789
+ }
3790
+ });
3791
+ }
3792
+ };
3793
+ }
3794
+ function findPanel(doc, id) {
3795
+ const top = doc.spec.panels[id];
3796
+ if (top) return top;
3797
+ for (const m of Object.values(doc.spec.modals ?? {})) if (m.panels[id]) return m.panels[id];
3798
+ return void 0;
3799
+ }
3800
+ function useHiddenPanels(ids) {
3801
+ const { runtime } = useDashboard();
3802
+ const key = ids.join(",");
3803
+ const list = useTree(
3804
+ // biome-ignore lint/correctness/useExhaustiveDependencies: ids are compared by key
3805
+ useCallback4(
3806
+ (tree) => ids.filter((id) => {
3807
+ const def = findPanel(runtime.doc, id);
3808
+ if (!def) return false;
3809
+ if (tree.panels[id]?.hidden) return true;
3810
+ if (typeof def.visibleWhen !== "string") return false;
3811
+ try {
3812
+ return !evaluate(
3813
+ def.visibleWhen,
3814
+ rootScope(tree, runtime.helpers, { panel: tree.panels[id] ?? {}, drill: drillValues(tree, id) })
3815
+ );
3816
+ } catch {
3817
+ return false;
3818
+ }
3819
+ }),
3820
+ [key, runtime]
3821
+ ),
3822
+ (a, b) => a.join(",") === b.join(",")
3823
+ );
3824
+ return useMemo3(() => new Set(list), [list]);
3825
+ }
3826
+ function panelUnder(x, y, exclude) {
3827
+ if (typeof document === "undefined") return void 0;
3828
+ for (const el of document.elementsFromPoint(x, y)) {
3829
+ const p = el.closest(".ds-panel[data-panel]");
3830
+ if (p && (!exclude || !exclude.contains(p) && !p.contains(exclude))) return p;
3831
+ }
3832
+ return void 0;
3833
+ }
3834
+ function indexIn(box, x, y) {
3835
+ const row = getComputedStyle(box).flexDirection === "row";
3836
+ const kids = [...box.children].filter((c) => c.classList.contains("ds-panel"));
3837
+ return kids.filter((k) => {
3838
+ const r = k.getBoundingClientRect();
3839
+ return row ? r.left + r.width / 2 < x && r.top < y : r.top + r.height / 2 < y;
3840
+ }).length;
3841
+ }
3842
+ function dropIndexAt(panel, x, y) {
3843
+ const id = panel.getAttribute("data-panel") ?? "";
3844
+ const under = document.elementsFromPoint(x, y).find((el) => el.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`));
3845
+ const box = under?.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`) ?? panel.querySelector(`[data-slot][data-owner="${CSS.escape(id)}"]`);
3846
+ if (!box) return {};
3847
+ return { slot: box.getAttribute("data-slot") ?? void 0, index: indexIn(box, x, y) };
3848
+ }
3849
+ function PanelFrame({ id, nested = false }) {
3850
+ return /* @__PURE__ */ jsx14(Boundary, { resetKeys: [id], fallback: (e) => /* @__PURE__ */ jsx14(PanelCrash, { id, error: e }), children: /* @__PURE__ */ jsx14(PanelFrameInner, { id, nested }) });
3851
+ }
3852
+ function PanelCrash({ id, error }) {
3853
+ const { options } = useDashboard();
3854
+ let custom;
3855
+ try {
3856
+ custom = options.renderError?.({ code: "render", message: error.message }, id);
3857
+ } catch {
3858
+ custom = void 0;
3859
+ }
3860
+ 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: [
3861
+ "This panel could not be shown: ",
3862
+ error.message
3863
+ ] }) }) });
3864
+ }
3865
+ function PanelFrameInner({ id, nested }) {
3866
+ const { runtime, registry, options, visibility } = useDashboard();
3867
+ const instance = `${id}\0${useId3()}`;
3868
+ const inherited = useNodeScope();
3869
+ const def = findPanel(runtime.doc, id);
3870
+ const widget = registry.byKind.get(def.kind);
3871
+ const spec = def.spec ?? {};
3872
+ const binding = spec.data;
3873
+ const drillLevels = def.drill?.levels ?? [];
3874
+ const view = useTree(
3875
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the panel definition is fixed for a runtime
3876
+ useCallback4(
3877
+ (tree) => {
3878
+ const ps = tree.panels[id] ?? {};
3879
+ const level = drillLevels[(ps.drill ?? []).length];
3880
+ const baseSource = level?.source ?? binding?.source;
3881
+ const drillId = baseSource && level?.query ? drillSourceId(baseSource, id, level.name) : void 0;
3882
+ const source = drillId && runtime.datasourceIds.has(drillId) ? drillId : baseSource;
3883
+ const scope2 = rootScope(tree, runtime.helpers, {
3884
+ panel: { ...ps, controls: ps.controls ?? {} },
3885
+ drill: drillValues(tree, id),
3886
+ parent: inherited.parentData,
3887
+ ...inherited.hasItem ? { item: inherited.item, index: inherited.index } : {}
3894
3888
  });
3895
- }
3896
- return r;
3897
- }, [base, view, columns]);
3898
- const pageSize = pg ? view.pageSize : void 0;
3899
- const rowTotal = server.paging ? toNumber(field(source, pg?.totalPath ?? "count")) ?? rows.length : rows.length;
3900
- const pages = pageSize ? Math.max(1, Math.ceil(rowTotal / pageSize)) : 1;
3901
- const current = Math.min(view.page, pages);
3902
- const shown = pageSize && !server.paging ? rows.slice((current - 1) * pageSize, current * pageSize) : rows;
3903
- const hasFilters = Boolean(fl) && columns.some((c) => c.filter);
3904
- const height = Math.max(120, (size2.height || 300) - (sr ? 48 : 0) - (pageSize ? 48 : 0));
3905
- const windowed = spec.virtual && shown.length > 60;
3906
- const first = windowed ? Math.max(0, Math.floor(scrollTop / ROW_H) - 10) : 0;
3907
- const last = windowed ? Math.min(shown.length, first + Math.ceil(height / ROW_H) + 20) : shown.length;
3908
- const busy = status === "loading" && base.length > 0;
3909
- const filterChoices = (c) => c.filterOptions ?? [
3910
- ...new Set(
3911
- base.map((r) => field(r, c.key)).filter((v) => v !== null && v !== void 0 && v !== "").map(String)
3912
- )
3913
- ].sort();
3914
- const cell = (c, row) => {
3915
- const v = field(row, c.key);
3916
- if (c.type === "badge") {
3917
- const text = c.template ? tpl(c.template, row) : v === null || v === void 0 || v === "" ? "" : String(v);
3918
- if (!text) return c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "";
3919
- let t = c.map?.[String(v)] ?? "neutral";
3920
- if (c.tone) {
3889
+ let visible = true;
3890
+ if (typeof def.visibleWhen === "string") {
3921
3891
  try {
3922
- t = String(
3923
- evaluate(c.tone, scope({ row, value: v }, helpers))
3924
- );
3892
+ visible = Boolean(evaluate(def.visibleWhen, scope2));
3925
3893
  } catch {
3894
+ visible = true;
3926
3895
  }
3927
3896
  }
3928
- return /* @__PURE__ */ jsx18("span", { className: "ds-chip", "data-tone": t, children: text });
3929
- }
3930
- if (c.template) return tpl(c.template, row) || (c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "");
3931
- if (c.list !== void 0) {
3932
- const items = Array.isArray(v) ? v : [];
3933
- if (items.length === 0) return c.empty ?? "";
3934
- return /* @__PURE__ */ jsx18("span", { className: "ds-cell-list", children: items.map((it, i) => (
3935
- // biome-ignore lint/suspicious/noArrayIndexKey: list items have no id and never reorder within a render
3936
- /* @__PURE__ */ jsx18("span", { children: tpl(c.list, row, it) }, i)
3937
- )) });
3938
- }
3939
- if (v === null || v === void 0 || v === "")
3940
- return c.empty ? /* @__PURE__ */ jsx18("span", { className: "ds-cell-empty", children: c.empty }) : "";
3941
- switch (c.type) {
3942
- case "link": {
3943
- const href = safeLink(c.href ? tpl(c.href, row) : String(v));
3944
- return href ? /* @__PURE__ */ jsx18("a", { className: "ds-link", href, onClick: (e) => e.stopPropagation(), children: String(v) }) : String(v);
3945
- }
3946
- case "image":
3947
- return safeImageSrc(v) ? /* @__PURE__ */ jsx18("img", { src: v, alt: "", style: { height: 28, borderRadius: 4 } }) : null;
3948
- case "progress": {
3949
- const n = toNumber(v) ?? 0;
3950
- const pct = Math.min(100, n / (c.max ?? 100) * 100);
3951
- return /* @__PURE__ */ jsxs13("span", { className: "ds-inline", children: [
3952
- /* @__PURE__ */ jsx18("span", { className: "ds-progress", style: { flex: 1, minWidth: 40 }, children: /* @__PURE__ */ jsx18("span", { style: { width: `${pct}%`, background: "var(--ds-series-1)" } }) }),
3953
- formatValue(n, helpers, c.format, c.decimals),
3954
- c.suffix
3955
- ] });
3956
- }
3957
- case "sparkline":
3958
- return /* @__PURE__ */ jsx18(
3959
- SparkSvg,
3960
- {
3961
- values: (Array.isArray(v) ? v : []).map(
3962
- (x) => toNumber(typeof x === "object" ? field(x, "value") : x) ?? 0
3963
- ),
3964
- height: 24,
3965
- area: false
3966
- }
3967
- );
3968
- default:
3969
- return `${c.prefix ?? ""}${typeof v === "number" || c.format ? formatValue(v, helpers, c.format, c.decimals) : String(v)}${c.suffix ?? ""}`;
3970
- }
3971
- };
3972
- const total = (c) => {
3973
- const how = spec.totals?.columns[c.key];
3974
- if (!how) return null;
3975
- const nums = rows.map((r) => toNumber(field(r, c.key))).filter((n) => n !== void 0);
3976
- if (how !== "count" && nums.length === 0) return "";
3977
- 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));
3978
- return `${c.prefix ?? ""}${formatValue(v, helpers, c.format === "date" ? "number" : c.format, c.decimals)}${c.suffix ?? ""}`;
3979
- };
3980
- const muted = (row) => {
3981
- if (!spec.rowMutedWhen) return false;
3982
- try {
3983
- return Boolean(evaluate(spec.rowMutedWhen, scope({ row }, helpers)));
3984
- } catch {
3985
- return false;
3986
- }
3987
- };
3988
- const align = (c) => c.align ?? (c.type === "number" || c.format && c.format !== "date" && c.format !== "text" ? "right" : "left");
3989
- return /* @__PURE__ */ jsxs13("div", { className: "ds-table-wrap", "data-density": spec.density, children: [
3990
- sr && /* @__PURE__ */ jsxs13("div", { className: "ds-table-tools", children: [
3991
- /* @__PURE__ */ jsxs13("label", { className: "ds-search", children: [
3992
- /* @__PURE__ */ jsxs13("svg", { viewBox: "0 0 16 16", width: "15", height: "15", "aria-hidden": "true", children: [
3993
- /* @__PURE__ */ jsx18("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.5" }),
3994
- /* @__PURE__ */ jsx18("path", { d: "m10.5 10.5 3 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
3995
- ] }),
3996
- /* @__PURE__ */ jsx18(
3997
- "input",
3998
- {
3999
- type: "search",
4000
- "aria-label": "Search table",
4001
- placeholder: "placeholder" in sr && sr.placeholder || "Search",
4002
- value: searchText,
4003
- onChange: (e) => {
4004
- const v = e.target.value;
4005
- setSearchText(v);
4006
- clearTimeout(searchTimer.current);
4007
- searchTimer.current = setTimeout(() => update({ search: v, page: 1 }), server.search ? 350 : 120);
4008
- }
4009
- }
4010
- )
4011
- ] }),
4012
- /* @__PURE__ */ jsxs13("span", { className: "ds-table-count", children: [
4013
- helpers.fmt.number(rowTotal),
4014
- " rows"
4015
- ] })
4016
- ] }),
4017
- /* @__PURE__ */ jsxs13(
4018
- "div",
4019
- {
4020
- className: "ds-table-scroll",
4021
- ref: scroller,
4022
- style: { maxHeight: height },
4023
- onScroll: windowed ? (e) => setScrollTop(e.currentTarget.scrollTop) : void 0,
4024
- children: [
4025
- busy && /* @__PURE__ */ jsx18("div", { className: "ds-table-busy", "aria-hidden": "true" }),
4026
- /* @__PURE__ */ jsxs13("table", { className: "ds-table", "aria-busy": busy || void 0, children: [
4027
- /* @__PURE__ */ jsxs13("thead", { "data-sticky": spec.sticky || void 0, children: [
4028
- /* @__PURE__ */ jsx18("tr", { children: columns.map((c, i) => {
4029
- const sorted = sort?.key === c.key ? sort.order : void 0;
4030
- return /* @__PURE__ */ jsx18(
4031
- "th",
4032
- {
4033
- "data-ds-part": `column:${i}`,
4034
- style: { textAlign: align(c), width: c.width },
4035
- "aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
4036
- children: so.enabled === false || c.sortable === false || c.list !== void 0 ? c.label ?? c.key : /* @__PURE__ */ jsxs13(
4037
- "button",
4038
- {
4039
- type: "button",
4040
- onClick: () => update(
4041
- sorted === "asc" ? { sortKey: c.key, sortOrder: "desc", page: 1 } : sorted === "desc" ? { sortKey: void 0, page: 1 } : { sortKey: c.key, sortOrder: "asc", page: 1 }
4042
- ),
4043
- children: [
4044
- c.label ?? c.key,
4045
- /* @__PURE__ */ jsx18("span", { className: "ds-sort", "data-dir": sorted, "aria-hidden": "true" })
4046
- ]
4047
- }
4048
- )
4049
- },
4050
- `${c.key}-${i}`
4051
- );
4052
- }) }),
4053
- hasFilters && /* @__PURE__ */ jsx18("tr", { className: "ds-filter-row", children: columns.map((c, i) => /* @__PURE__ */ jsx18("th", { children: c.filter === "select" ? /* @__PURE__ */ jsx18(
4054
- SelectControl,
4055
- {
4056
- size: "sm",
4057
- block: true,
4058
- plain: true,
4059
- ariaLabel: `Filter ${c.label ?? c.key}`,
4060
- options: [
4061
- { value: "", label: "All" },
4062
- ...filterChoices(c).map((o) => ({ value: o, label: o }))
4063
- ],
4064
- value: view.filters[c.key] ?? "",
4065
- onChange: (v) => update({ filters: { ...view.filters, [c.key]: String(v ?? "") }, page: 1 })
4066
- }
4067
- ) : c.filter ? /* @__PURE__ */ jsx18(
4068
- "input",
4069
- {
4070
- className: "ds-cell-filter",
4071
- type: c.filter === "min" ? "number" : "text",
4072
- placeholder: c.filter === "min" ? "Min" : "Filter",
4073
- "aria-label": `Filter ${c.label ?? c.key}`,
4074
- value: view.filters[c.key] ?? "",
4075
- onChange: (e) => update({ filters: { ...view.filters, [c.key]: e.target.value }, page: 1 })
4076
- }
4077
- ) : null }, `f-${c.key}-${i}`)) })
4078
- ] }),
4079
- /* @__PURE__ */ jsxs13("tbody", { children: [
4080
- windowed && first > 0 && /* @__PURE__ */ jsx18("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx18("td", { colSpan: columns.length, style: { height: first * ROW_H, padding: 0 } }) }),
4081
- shown.slice(first, last).map((row, k) => {
4082
- const i = first + k;
4083
- const key = spec.rowKey ? String(field(row, spec.rowKey)) : String(i);
4084
- return /* @__PURE__ */ jsx18(
4085
- "tr",
4086
- {
4087
- "data-muted": muted(row) || void 0,
4088
- onClick: () => emit("rowClick", "row", { datum: row, index: i }),
4089
- onMouseEnter: () => emit("hover", "row", { datum: row, index: i }),
4090
- tabIndex: 0,
4091
- onKeyDown: (e) => e.key === "Enter" && emit("rowClick", "row", { datum: row, index: i }),
4092
- children: columns.map((c, j) => (
4093
- // biome-ignore lint/a11y/useKeyWithClickEvents: rows are focusable and open with Enter; cell clicks add detail for pointer users
4094
- /* @__PURE__ */ jsx18(
4095
- "td",
4096
- {
4097
- style: { textAlign: align(c) },
4098
- onClick: () => emit("cellClick", "cell", { datum: row, index: i, value: field(row, c.key), column: c.key }),
4099
- children: cell(c, row)
4100
- },
4101
- `${c.key}-${j}`
4102
- )
4103
- ))
4104
- },
4105
- key
4106
- );
4107
- }),
4108
- 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 } }) })
4109
- ] }),
4110
- 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}`)) }) })
4111
- ] })
4112
- ]
3897
+ let data;
3898
+ let sourceData;
3899
+ let status = "success";
3900
+ let error;
3901
+ let stale = false;
3902
+ let updatedAt;
3903
+ if (source) {
3904
+ const s = tree.datasources[source];
3905
+ status = s?.status ?? "idle";
3906
+ error = s?.error;
3907
+ stale = Boolean(s?.stale);
3908
+ updatedAt = s?.updatedAt;
3909
+ sourceData = s?.data;
3910
+ data = typeof binding?.path === "string" ? getPath(s?.data, binding.path) : s?.data;
3911
+ } else if (binding && typeof binding.panel === "string")
3912
+ data = getPath(tree.panels[binding.panel], binding.path ?? "selection");
3913
+ else if (binding && typeof binding.state === "string") data = getPath(tree, binding.state);
3914
+ else if (binding && "value" in binding) data = binding.value;
3915
+ else if (!binding && inherited.parentId) data = inherited.data;
3916
+ const { data: _d, ...rest } = spec;
3917
+ let props2 = {};
3918
+ try {
3919
+ props2 = resolvePanel(rest, scope2, Boolean(inherited.hasItem));
3920
+ } catch (e) {
3921
+ error = { code: "template", message: e.message };
4113
3922
  }
4114
- ),
4115
- pageSize && /* @__PURE__ */ jsxs13("div", { className: "ds-pager", children: [
4116
- /* @__PURE__ */ jsxs13("span", { className: "ds-pager-size", children: [
4117
- "Rows",
4118
- /* @__PURE__ */ jsx18(
4119
- SelectControl,
4120
- {
4121
- size: "sm",
4122
- plain: true,
4123
- ariaLabel: "Rows per page",
4124
- options: (pg?.pageSizes ?? [10, 20, 50, 100]).map((n) => ({ value: n, label: String(n) })),
4125
- value: pageSize,
4126
- onChange: (v) => update({ pageSize: Number(v), page: 1 })
4127
- }
4128
- )
4129
- ] }),
4130
- /* @__PURE__ */ jsxs13("span", { children: [
4131
- rowTotal === 0 ? 0 : (current - 1) * pageSize + 1,
4132
- "\u2013",
4133
- Math.min(current * pageSize, rowTotal),
4134
- " of",
4135
- " ",
4136
- helpers.fmt.number(rowTotal)
4137
- ] }),
4138
- /* @__PURE__ */ jsxs13("span", { className: "ds-pages", children: [
4139
- /* @__PURE__ */ jsx18(
4140
- "button",
4141
- {
4142
- type: "button",
4143
- "aria-label": "Previous page",
4144
- disabled: current <= 1,
4145
- onClick: () => update({ page: current - 1 }),
4146
- children: "\u2039"
4147
- }
4148
- ),
4149
- pageList(current, pages).map(
4150
- (n, i) => n === 0 ? /* @__PURE__ */ jsx18("span", { className: "ds-page-gap", children: "\u2026" }, `gap-${i < 3 ? "a" : "b"}`) : /* @__PURE__ */ jsx18(
4151
- "button",
4152
- {
4153
- type: "button",
4154
- "aria-current": n === current ? "page" : void 0,
4155
- onClick: () => update({ page: n }),
4156
- children: n
4157
- },
4158
- n
4159
- )
4160
- ),
4161
- /* @__PURE__ */ jsx18(
4162
- "button",
4163
- {
4164
- type: "button",
4165
- "aria-label": "Next page",
4166
- disabled: current >= pages,
4167
- onClick: () => update({ page: current + 1 }),
4168
- children: "\u203A"
4169
- }
4170
- )
4171
- ] })
4172
- ] })
4173
- ] });
4174
- }
4175
- });
4176
-
4177
- // src/widgets/builtins/Tiles.tsx
4178
- import "zod";
4179
- import { Fragment as Fragment5, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
4180
- var Tiles = defineWidget({
4181
- ...TilesContract,
4182
- implements: "tiles",
4183
- exposes: { selection: "the clicked tile's row" },
4184
- meta: { label: "Tiles", icon: "tiles", category: "Numbers", size: { w: 12, h: 4, minW: 3, minH: 3 } },
4185
- events: ["click", "hover", "select"],
4186
- parts: ["tile"],
4187
- defaults: { label: "name", value: "value" },
4188
- component: function TilesWidget({ spec, data, emit, helpers }) {
4189
- const rows = asRows(data);
4190
- const caption = (row) => {
4191
- if (!spec.caption) return void 0;
4192
- try {
4193
- return String(interpolate(spec.caption, scope({ row }, helpers)) ?? "");
4194
- } catch {
4195
- return spec.caption;
4196
- }
3923
+ const msg = def.messages;
3924
+ const messages = msg ? resolvePanel(msg, scope2) : void 0;
3925
+ const group = props2.highlight ?? void 0;
3926
+ return {
3927
+ visible,
3928
+ hidden: Boolean(ps.hidden),
3929
+ panel: ps,
3930
+ source,
3931
+ data,
3932
+ sourceData,
3933
+ status,
3934
+ error,
3935
+ stale,
3936
+ updatedAt,
3937
+ props: props2,
3938
+ messages,
3939
+ highlight: group ? tree.highlight[group] : void 0,
3940
+ x: level?.x ?? void 0
3941
+ };
3942
+ },
3943
+ [id, runtime, inherited.parentId, inherited.data, inherited.parentData, inherited.item, inherited.index]
3944
+ ),
3945
+ samePanelView
3946
+ );
3947
+ const renderNested = useCallback4((child) => /* @__PURE__ */ jsx14(PanelFrame, { id: child, nested: true }, child), []);
3948
+ const store = useMemo3(() => widgetStore(runtime), [runtime]);
3949
+ const [bodyRef, size2] = useSize();
3950
+ const frameRef = useRef5(null);
3951
+ useEffect3(() => {
3952
+ if (!view.visible || view.hidden) {
3953
+ visibility.set(instance, null);
3954
+ return;
3955
+ }
3956
+ const el = frameRef.current;
3957
+ if (!el || typeof IntersectionObserver === "undefined") {
3958
+ visibility.set(instance, view.source ? [view.source] : []);
3959
+ return () => visibility.set(instance, null);
3960
+ }
3961
+ const io = new IntersectionObserver(
3962
+ ([e]) => visibility.set(instance, e?.isIntersecting && view.source ? [view.source] : []),
3963
+ { rootMargin: "200px" }
3964
+ );
3965
+ io.observe(el);
3966
+ return () => {
3967
+ io.disconnect();
3968
+ visibility.set(instance, null);
4197
3969
  };
4198
- return /* @__PURE__ */ jsx19(
4199
- "div",
3970
+ }, [instance, view.visible, view.hidden, view.source, visibility]);
3971
+ const emit = useCallback4(
3972
+ (type, part, detail) => {
3973
+ const event = { type, panel: id, ...part ? { part } : {}, ...detail };
3974
+ options.onEvent?.(event);
3975
+ void runtime.emit(event);
3976
+ },
3977
+ [id, options, runtime]
3978
+ );
3979
+ const run = useCallback4(
3980
+ (action, detail) => void runtime.runAction(action, { type: "click", panel: id, ...detail }),
3981
+ [runtime, id]
3982
+ );
3983
+ const setUi = useCallback4(
3984
+ (patch) => runtime.store.dispatch(
3985
+ stateActions.patchPanel({ id, patch: { ui: { ...runtime.getTree().panels[id]?.ui, ...patch } } })
3986
+ ),
3987
+ [runtime, id]
3988
+ );
3989
+ const dataRef = useRef5(view.data);
3990
+ dataRef.current = view.data;
3991
+ const props = useMemo3(() => {
3992
+ let p = { ...view.props, ...view.panel.props ?? {} };
3993
+ if (view.x) p = { ...p, x: view.x };
3994
+ p = withFunctions(p, (code) => {
3995
+ const f = runtime.scripts.fnProp(code, ["p", "data"]);
3996
+ return (arg) => {
3997
+ try {
3998
+ return f(arg, dataRef.current);
3999
+ } catch (e) {
4000
+ console.warn(`[dashspec] ${id}: function prop failed: ${e.message}`);
4001
+ return "";
4002
+ }
4003
+ };
4004
+ });
4005
+ return widget ? parseWidgetProps(widget.schema, p).props : p;
4006
+ }, [view.props, view.panel.props, view.x, runtime, widget, id]);
4007
+ if (!view.visible || view.hidden) return null;
4008
+ const ownHeader = widget?.header === "widget";
4009
+ const title = ownHeader ? void 0 : props.title;
4010
+ const info = ownHeader ? void 0 : props.info;
4011
+ const meta2 = props.meta;
4012
+ const live2 = Boolean(props.live);
4013
+ const drill = view.panel.drill ?? [];
4014
+ const controls = def.controls ?? [];
4015
+ const tone2 = def.style?.tone ?? (widget?.frame === "plain" ? "plain" : "default");
4016
+ const headerKids = slotChildren(def, "header");
4017
+ const footerKids = slotChildren(def, "footer");
4018
+ const hideHeader = Boolean(def.style?.hideHeader) || !title && !meta2 && !live2 && drill.length === 0 && controls.length === 0 && !view.stale && headerKids.length === 0;
4019
+ const dnd = Boolean(options.onDropOnPanel);
4020
+ let body;
4021
+ if (!widget) body = /* @__PURE__ */ jsxs9("div", { className: "ds-state", children: [
4022
+ "Unknown widget \u201C",
4023
+ String(def.kind),
4024
+ "\u201D"
4025
+ ] });
4026
+ else if (view.error && view.data === void 0)
4027
+ body = options.renderError?.(view.error, id) ?? /* @__PURE__ */ jsx14("div", { className: "ds-state ds-state-error", role: "alert", children: view.messages?.error ?? view.error.message });
4028
+ else if (view.source && view.data === void 0 && (view.status === "loading" || view.status === "idle"))
4029
+ body = options.renderLoading?.(id, loadingText(view.messages)) ?? /* @__PURE__ */ jsx14(LoadingState, { text: loadingText(view.messages) });
4030
+ else if (view.source && isEmpty(view.data) && widget.empty !== "widget")
4031
+ body = options.renderEmpty?.(id) ?? /* @__PURE__ */ jsx14("div", { className: "ds-state", children: view.messages?.empty ?? "No data" });
4032
+ else {
4033
+ const W = widget.component;
4034
+ body = /* @__PURE__ */ jsx14(
4035
+ Boundary,
4200
4036
  {
4201
- className: "ds-tiles",
4202
- role: spec.selectable ? "radiogroup" : "list",
4203
- "aria-label": spec.title,
4204
- "data-wrap": spec.wrap === false ? "off" : void 0,
4205
- style: {
4206
- "--ds-tile-min": `${spec.minTileWidth ?? 128}px`,
4207
- ...spec.columns ? { "--ds-tile-cols": spec.columns } : {}
4208
- },
4209
- children: rows.map((r, i) => {
4210
- const label = field(r, spec.label);
4211
- const v = field(r, spec.value);
4212
- const n = toNumber(v);
4213
- const status = spec.status ? String(field(r, spec.status)) : void 0;
4214
- const st = status ? spec.statusMap?.[status] ?? status : void 0;
4215
- const vt = n === void 0 || !spec.valueTone ? void 0 : n > 0 ? spec.valueTone.positive : n < 0 ? spec.valueTone.negative : spec.valueTone.zero;
4216
- const active = spec.selectable && spec.selected !== void 0 && spec.selected === label;
4217
- return /* @__PURE__ */ jsxs14(
4218
- "button",
4219
- {
4220
- type: "button",
4221
- className: "ds-tile",
4222
- role: spec.selectable ? "radio" : "listitem",
4223
- "aria-checked": spec.selectable ? active : void 0,
4224
- "data-active": active || void 0,
4225
- onClick: () => {
4226
- emit("click", "tile", { datum: r, value: label, index: i });
4227
- if (spec.selectable) emit("select", "tile", { datum: r, value: label, index: i });
4228
- },
4229
- onMouseEnter: () => emit("hover", "tile", { datum: r, value: label, index: i }),
4230
- children: [
4231
- /* @__PURE__ */ jsxs14("span", { className: "ds-tile-label", children: [
4232
- st && /* @__PURE__ */ jsx19("span", { className: "ds-dot", style: { background: tone(st).solid }, "aria-hidden": "true" }),
4233
- String(label ?? ""),
4234
- spec.count && /* @__PURE__ */ jsx19("span", { className: "ds-chip-count", children: String(field(r, spec.count) ?? "") })
4235
- ] }),
4236
- /* @__PURE__ */ jsxs14(
4237
- "span",
4238
- {
4239
- className: "ds-tile-value",
4240
- style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
4241
- children: [
4242
- /* @__PURE__ */ jsx19(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
4243
- spec.unit && /* @__PURE__ */ jsx19("span", { className: "ds-kpi-unit", children: spec.unit })
4244
- ]
4245
- }
4246
- ),
4247
- spec.caption && /* @__PURE__ */ jsx19("span", { className: "ds-tile-caption", children: caption(r) })
4248
- ]
4249
- },
4250
- `${String(label)}-${i}`
4251
- );
4252
- })
4037
+ resetKeys: [view.data, props],
4038
+ fallback: (e) => /* @__PURE__ */ jsxs9("div", { className: "ds-state ds-state-error", role: "alert", children: [
4039
+ "This panel could not be shown: ",
4040
+ e.message
4041
+ ] }),
4042
+ children: /* @__PURE__ */ jsx14(
4043
+ W,
4044
+ {
4045
+ spec: props,
4046
+ data: view.data,
4047
+ source: view.sourceData,
4048
+ run,
4049
+ emit,
4050
+ state: view.panel,
4051
+ setUi,
4052
+ status: view.status,
4053
+ highlight: view.highlight,
4054
+ size: size2,
4055
+ mode: options.mode,
4056
+ helpers: runtime.helpers,
4057
+ panelId: id,
4058
+ renderSlot: (name, o) => /* @__PURE__ */ jsx14(Slot, { name, ...o }),
4059
+ store
4060
+ }
4061
+ )
4253
4062
  }
4254
4063
  );
4255
4064
  }
4256
- });
4257
- function CountUp({ value, render }) {
4258
- const n = toNumber(value);
4259
- const shown = useCountUp(n ?? value);
4260
- return /* @__PURE__ */ jsx19(Fragment5, { children: render(n === void 0 ? value : shown) });
4261
- }
4262
-
4263
- // src/widgets/builtins/atoms.tsx
4264
- import "zod";
4265
-
4266
- // src/widgets/shared/clickable.ts
4267
- import { useContext as useContext4 } from "react";
4268
-
4269
- // src/components/PanelFrame.tsx
4270
- import { useCallback as useCallback4, useEffect as useEffect5, useId as useId3, useMemo as useMemo4, useRef as useRef6, useState as useState5 } from "react";
4271
-
4272
- // src/widgets/parseProps.ts
4273
- function without(value, path) {
4274
- if (path.length === 0 || value === null || typeof value !== "object") return value;
4275
- const [head, ...rest] = path;
4276
- if (Array.isArray(value)) {
4277
- if (typeof head !== "number" || head < 0 || head >= value.length) return value;
4278
- const copy2 = [...value];
4279
- if (rest.length === 0) copy2.splice(head, 1);
4280
- else copy2[head] = without(copy2[head], rest);
4281
- return copy2;
4282
- }
4283
- if (!Object.hasOwn(value, head)) return value;
4284
- const copy = { ...value };
4285
- if (rest.length === 0) delete copy[head];
4286
- else copy[head] = without(copy[head], rest);
4287
- return copy;
4288
- }
4289
- function parseWidgetProps(schema, props) {
4290
- let current = props;
4291
- const dropped = [];
4292
- for (let round = 0; round < 25; round++) {
4293
- const r = schema.safeParse(current);
4294
- if (r.success) return { props: r.data, dropped };
4295
- const issue = r.error.issues.find((i) => i.path.length > 0);
4296
- if (!issue) break;
4297
- const lastIndex = issue.path.reduce((at, k, i) => typeof k === "number" ? i : at, -1);
4298
- const path = lastIndex >= 0 ? issue.path.slice(0, lastIndex + 1) : issue.path;
4299
- const next = without(current, path);
4300
- if (next === current) break;
4301
- dropped.push(path.join("."));
4302
- current = next;
4303
- }
4304
- return { props, dropped };
4305
- }
4306
-
4307
- // src/components/Boundary.tsx
4308
- import { Component } from "react";
4309
- var sameKeys = (a, b) => a.length === b.length && a.every((x, i) => Object.is(x, b[i]));
4310
- var Boundary = class extends Component {
4311
- state = { error: null };
4312
- static getDerivedStateFromError(error) {
4313
- return { error };
4314
- }
4315
- componentDidCatch(error, _info) {
4316
- this.props.onError?.(error);
4317
- }
4318
- componentDidUpdate(prev) {
4319
- if (this.state.error && !sameKeys(prev.resetKeys ?? [], this.props.resetKeys ?? [])) this.setState({ error: null });
4320
- }
4321
- render() {
4322
- return this.state.error ? this.props.fallback(this.state.error) : this.props.children;
4323
- }
4324
- };
4325
-
4326
- // src/components/Slot.tsx
4327
- import { createContext as createContext3, useContext as useContext3 } from "react";
4328
- import { Fragment as Fragment6, jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
4329
- var NodeScopeContext = createContext3({});
4330
- var useNodeScope = () => useContext3(NodeScopeContext);
4331
- var SlotOwnerContext = createContext3(null);
4332
- var SlotChildContext = createContext3(null);
4333
- function slotChildren(def, name) {
4334
- const slots = def?.slots;
4335
- const list = slots?.[name];
4336
- return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
4337
- }
4338
- function Slot({
4339
- name,
4340
- className,
4341
- style,
4342
- data,
4343
- item,
4344
- index,
4345
- empty
4346
- }) {
4347
- const { options } = useDashboard();
4348
- const owner = useContext3(SlotOwnerContext);
4349
- const outer = useNodeScope();
4350
- const renderChild = useContext3(SlotChildContext);
4351
- if (!owner || !renderChild) return null;
4352
- const ids = slotChildren(owner.def, name);
4353
- const editing = options.mode === "edit";
4354
- if (ids.length === 0 && !editing) return null;
4355
- const hasItem = item !== void 0 || outer.hasItem;
4356
- const scope2 = {
4357
- parentId: owner.id,
4358
- parentData: owner.data,
4359
- data: data !== void 0 ? data : item !== void 0 ? item : owner.data,
4360
- hasItem: Boolean(hasItem),
4361
- item: item !== void 0 ? item : outer.item,
4362
- index: index !== void 0 ? index : outer.index
4065
+ const selected = options.selectedPanel === id;
4066
+ const defaultSlot = widget?.slots ? Object.keys(widget.slots)[0] ?? "header" : "header";
4067
+ const dropTarget = (target, x, y) => {
4068
+ const own = `[data-slot][data-owner="${CSS.escape(id)}"]`;
4069
+ const el = target?.closest(own) ?? frameRef.current?.querySelector(`${own}:not([data-slot="header"]):not([data-slot="footer"])`) ?? void 0;
4070
+ const name = el?.getAttribute("data-slot") ?? defaultSlot;
4071
+ return { slot: name, index: el ? indexIn(el, x, y) : void 0 };
4363
4072
  };
4364
- return /* @__PURE__ */ jsx20(NodeScopeContext.Provider, { value: scope2, children: /* @__PURE__ */ jsxs15(
4365
- "div",
4073
+ return /* @__PURE__ */ jsx14(SlotOwnerContext.Provider, { value: { id, data: view.data, def }, children: /* @__PURE__ */ jsx14(SlotChildContext.Provider, { value: renderNested, children: /* @__PURE__ */ jsxs9(
4074
+ "section",
4366
4075
  {
4367
- className: className ? `ds-slot ${className}` : "ds-slot",
4368
- style,
4369
- "data-slot": name,
4370
- "data-owner": owner.id,
4371
- "data-empty": ids.length === 0 || void 0,
4076
+ ref: frameRef,
4077
+ className: "ds-panel",
4078
+ style: panelStyle(def.style),
4079
+ "data-tone": tone2,
4080
+ "data-panel": id,
4081
+ "data-selected": selected || void 0,
4082
+ "data-nested": nested || void 0,
4083
+ "aria-label": title ?? id,
4084
+ draggable: dnd && nested ? true : void 0,
4085
+ onDragStart: dnd && nested ? (e) => {
4086
+ e.stopPropagation();
4087
+ e.dataTransfer.setData("text/plain", id);
4088
+ e.dataTransfer.effectAllowed = "move";
4089
+ options.onDragPanelStart?.(id);
4090
+ } : void 0,
4091
+ onDragOver: dnd ? (e) => {
4092
+ const t = dropTarget(e.target, e.clientX, e.clientY);
4093
+ if (!options.canDropOn?.(id, void 0, t.slot)) return;
4094
+ e.preventDefault();
4095
+ e.stopPropagation();
4096
+ frameRef.current?.setAttribute("data-drop-over", t.slot);
4097
+ } : void 0,
4098
+ onDragLeave: dnd ? (e) => {
4099
+ if (!frameRef.current?.contains(e.relatedTarget))
4100
+ frameRef.current?.removeAttribute("data-drop-over");
4101
+ } : void 0,
4102
+ onDrop: dnd ? (e) => {
4103
+ frameRef.current?.removeAttribute("data-drop-over");
4104
+ const t = dropTarget(e.target, e.clientX, e.clientY);
4105
+ if (!options.canDropOn?.(id, void 0, t.slot)) return;
4106
+ e.preventDefault();
4107
+ e.stopPropagation();
4108
+ options.onDropOnPanel?.(id, t.index, void 0, t.slot);
4109
+ } : void 0,
4110
+ onPointerDownCapture: options.onPanelSelect ? (e) => {
4111
+ const el = partAt(e.target, frameRef.current);
4112
+ markPart(frameRef.current, el?.node);
4113
+ options.onPanelSelect?.(id, el?.part);
4114
+ } : void 0,
4115
+ onClickCapture: options.onPanelSelect ? (e) => {
4116
+ e.preventDefault();
4117
+ e.stopPropagation();
4118
+ } : void 0,
4372
4119
  children: [
4373
- ids.map((id) => /* @__PURE__ */ jsx20(SlotItem, { children: renderChild(id) }, id)),
4374
- ids.length === 0 && editing && (empty ?? /* @__PURE__ */ jsx20("span", { className: "ds-slot-hint", children: "Drop here" }))
4120
+ !hideHeader && /* @__PURE__ */ jsxs9("header", { className: "ds-panel-head", children: [
4121
+ /* @__PURE__ */ jsxs9("div", { style: { minWidth: 0 }, children: [
4122
+ title && /* @__PURE__ */ jsxs9("h3", { className: "ds-panel-title", children: [
4123
+ title,
4124
+ info && /* @__PURE__ */ jsx14(InfoTip, { text: info })
4125
+ ] }),
4126
+ drill.length > 0 && /* @__PURE__ */ jsxs9("nav", { className: "ds-crumbs", "aria-label": "Drill path", children: [
4127
+ /* @__PURE__ */ jsx14("button", { type: "button", onClick: () => runtime.runAction({ do: "drillReset", panel: id }), children: "All" }),
4128
+ drill.map((d, i) => /* @__PURE__ */ jsxs9("span", { children: [
4129
+ "\u203A",
4130
+ " ",
4131
+ i < drill.length - 1 ? /* @__PURE__ */ jsx14(
4132
+ "button",
4133
+ {
4134
+ type: "button",
4135
+ onClick: () => runtime.store.dispatch(
4136
+ stateActions.patchPanel({ id, patch: { drill: drill.slice(0, i + 1) } })
4137
+ ),
4138
+ children: String(d.value)
4139
+ }
4140
+ ) : String(d.value)
4141
+ ] }, `${d.level}-${i}`))
4142
+ ] })
4143
+ ] }),
4144
+ /* @__PURE__ */ jsxs9("div", { className: "ds-panel-tools", children: [
4145
+ headerKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "header", className: "ds-panel-addons" }),
4146
+ meta2 && /* @__PURE__ */ jsx14("span", { className: "ds-panel-meta", children: meta2 }),
4147
+ live2 ? /* @__PURE__ */ jsxs9("span", { className: "ds-live", "data-stale": view.stale || void 0, title: view.error?.message, children: [
4148
+ /* @__PURE__ */ jsx14("span", { "aria-hidden": "true" }),
4149
+ "Live, updated ",
4150
+ view.updatedAt ? runtime.helpers.fmt.ago(view.updatedAt) : "\u2026"
4151
+ ] }) : view.stale && /* @__PURE__ */ jsx14("span", { className: "ds-badge ds-badge-stale", title: view.error?.message, children: "Stale" }),
4152
+ controls.map((c) => /* @__PURE__ */ jsx14(
4153
+ ControlField,
4154
+ {
4155
+ def: c,
4156
+ compact: true,
4157
+ value: view.panel.controls?.[c.name],
4158
+ onChange: (v) => runtime.store.dispatch(
4159
+ stateActions.patchPanel({
4160
+ id,
4161
+ patch: { controls: { ...view.panel.controls, [c.name]: v } }
4162
+ })
4163
+ )
4164
+ },
4165
+ c.name
4166
+ ))
4167
+ ] })
4168
+ ] }),
4169
+ /* @__PURE__ */ jsx14("div", { className: "ds-panel-body", ref: bodyRef, children: body }),
4170
+ footerKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "footer", className: "ds-panel-foot" })
4375
4171
  ]
4376
4172
  }
4377
- ) });
4378
- }
4379
- var SlotItem = ({ children }) => /* @__PURE__ */ jsx20(Fragment6, { children });
4380
-
4381
- // src/components/PanelFrame.tsx
4382
- import { jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
4383
- 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;
4384
- function useSize() {
4385
- const [size2, setSize] = useState5({ width: 0, height: 0 });
4386
- const observer = useRef6(null);
4387
- const ref = useCallback4((el) => {
4388
- observer.current?.disconnect();
4389
- observer.current = null;
4390
- if (!el || typeof ResizeObserver === "undefined") return;
4391
- const ro = new ResizeObserver(([e]) => {
4392
- const r = e?.contentRect;
4393
- if (r)
4394
- setSize(
4395
- (s) => s.width === Math.round(r.width) && s.height === Math.round(r.height) ? s : { width: Math.round(r.width), height: Math.round(r.height) }
4396
- );
4397
- });
4398
- ro.observe(el);
4399
- observer.current = ro;
4400
- }, []);
4401
- return [ref, size2];
4402
- }
4403
- var DEFERRED = /(^|[^\w.$])(row|item|avg)\b/;
4404
- var DEFERRED_IN_ITEM = /(^|[^\w.$])(row|avg)\b/;
4405
- function interpolateMarkdown(v, scope2) {
4406
- const bodies = placeholders(v);
4407
- const whole = bodies.length === 1 && v.trim() === `\${${bodies[0]}}`;
4408
- const r = interpolate(v, scope2, escapeMarkdown);
4409
- if (!whole) return r;
4410
- return r === null || r === void 0 ? "" : escapeMarkdown(typeof r === "object" ? JSON.stringify(r) : String(r));
4411
- }
4412
- function resolvePanel(v, scope2, inItem = false, key) {
4413
- const deferred = inItem ? DEFERRED_IN_ITEM : DEFERRED;
4414
- if (typeof v === "string") {
4415
- if (placeholders(v).some((b) => deferred.test(b))) return v;
4416
- return key === "markdown" ? interpolateMarkdown(v, scope2) : interpolate(v, scope2);
4417
- }
4418
- if (Array.isArray(v)) return v.map((x) => resolvePanel(x, scope2, inItem));
4419
- if (v && typeof v === "object")
4420
- return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolvePanel(x, scope2, inItem, k)]));
4421
- return v;
4422
- }
4423
- function withFunctions(v, make) {
4424
- if (Array.isArray(v)) return v.map((x) => withFunctions(x, make));
4425
- if (v && typeof v === "object") {
4426
- const o = v;
4427
- if (typeof o.fn === "string" && Object.keys(o).length === 1) return make(o.fn);
4428
- return Object.fromEntries(Object.entries(o).map(([k, x]) => [k, withFunctions(x, make)]));
4429
- }
4430
- return v;
4431
- }
4432
- var SHADOWS = {
4433
- none: "none",
4434
- sm: "0 1px 3px rgba(13, 13, 13, 0.08)",
4435
- md: "0 6px 16px rgba(13, 13, 13, 0.10)",
4436
- lg: "0 14px 36px rgba(13, 13, 13, 0.14)"
4437
- };
4438
- var PADDING = { none: "0", compact: "8px", roomy: "24px" };
4439
- var colour = (v) => {
4440
- if (typeof v !== "string" || !v) return void 0;
4441
- if (/^[a-z]+(-[a-z]+)+$/.test(v) && !v.includes("(")) return `var(--ds-color-${v})`;
4442
- return /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\)|[a-z]+)$/i.test(v) ? v : void 0;
4443
- };
4444
- var size = (v) => typeof v === "number" ? `${v}px` : typeof v === "string" && /^[\d.]+(px|%|rem|em|vw)?$/.test(v) ? v : void 0;
4445
- var PART_CLASSES = [
4446
- [".ds-panel-title, .ds-kpi-label", "title"],
4447
- [".ds-info", "info"],
4448
- [".ds-panel-meta, .ds-live", "meta"],
4449
- [".ds-kpi-foot", "target"],
4450
- [".ds-chip", "badge"],
4451
- [".ds-kpi-main, .ds-kpi-value, .ds-kpi-unit", "value"],
4452
- [".ds-kpi-sub, .ds-kpi-delta", "note"],
4453
- [".ds-tile", "tile"],
4454
- [".ds-meters > *, .ds-segbar, .ds-legend", "bars"],
4455
- [".ds-status, .ds-pill", "state"],
4456
- [".ds-table-tools", "tools"],
4457
- [".ds-pager", "pager"]
4458
- ];
4459
- var PART_SELECTOR = ["[data-ds-part]", ...PART_CLASSES.map(([sel]) => sel)].join(", ");
4460
- function partAt(target, frame) {
4461
- let el = target?.closest(PART_SELECTOR) ?? null;
4462
- while (el && frame?.contains(el)) {
4463
- if (el.closest(".ds-panel") !== frame) return void 0;
4464
- const own = el.getAttribute("data-ds-part");
4465
- if (own) return { part: own, node: el };
4466
- const hit = PART_CLASSES.find(([sel]) => el?.matches(sel));
4467
- if (hit) return { part: hit[1], node: el };
4468
- el = el.parentElement?.closest(PART_SELECTOR) ?? null;
4469
- }
4470
- return void 0;
4173
+ ) }) });
4471
4174
  }
4472
- function markPart(frame, node) {
4473
- const root = frame?.closest(".ds-root") ?? frame?.ownerDocument;
4474
- for (const n of root?.querySelectorAll(".ds-part-selected") ?? []) n.classList.remove("ds-part-selected");
4475
- node?.classList.add("ds-part-selected");
4175
+ function loadingText(messages) {
4176
+ const v = messages?.loading;
4177
+ return v === void 0 || v === null || v === "" ? void 0 : String(v);
4476
4178
  }
4477
- function panelStyle(s) {
4478
- if (!s) return void 0;
4479
- const out = {};
4480
- const bg = colour(s.background);
4481
- if (bg) out.background = bg;
4482
- if (typeof s.borderWidth === "number" || s.borderColor)
4483
- out.border = `${s.borderWidth ?? 1}px solid ${colour(s.borderColor) ?? "var(--ds-color-border-default)"}`;
4484
- if (typeof s.radius === "number") out.borderRadius = s.radius;
4485
- if (typeof s.shadow === "string" && SHADOWS[s.shadow]) out.boxShadow = SHADOWS[s.shadow];
4486
- if (typeof s.padding === "number") out.padding = s.padding;
4487
- else if (typeof s.padding === "string" && PADDING[s.padding]) out.padding = PADDING[s.padding];
4488
- if (typeof s.minHeight === "number") out.minHeight = s.minHeight;
4489
- if (typeof s.flex === "string" && /^[\d.\s]*(auto|[\d.]+(px|%|rem)?)?$/.test(s.flex)) out.flex = s.flex;
4490
- const minW = size(s.minWidth);
4491
- const maxW = size(s.maxWidth);
4492
- if (minW) out.minWidth = minW;
4493
- if (maxW) out.maxWidth = maxW;
4494
- if (typeof s.align === "string")
4495
- out.alignSelf = s.align === "start" ? "flex-start" : s.align === "end" ? "flex-end" : s.align;
4496
- return Object.keys(out).length ? out : void 0;
4179
+ function LoadingState({ text }) {
4180
+ if (!text) return /* @__PURE__ */ jsx14("div", { className: "ds-skeleton", "aria-busy": "true", "aria-label": "Loading" });
4181
+ return /* @__PURE__ */ jsxs9("output", { className: "ds-loading", "aria-busy": "true", children: [
4182
+ /* @__PURE__ */ jsx14("div", { className: "ds-skeleton", "aria-hidden": "true" }),
4183
+ /* @__PURE__ */ jsx14("span", { className: "ds-loading-text", children: text })
4184
+ ] });
4497
4185
  }
4498
- var samePanelView = (a, b) => Object.keys(a).every(
4499
- (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])
4500
- );
4501
- var RESERVED = /^(filters|panels|view|modal|highlight|datasources|context)(\.|$)/;
4502
- function widgetStore(runtime) {
4503
- const get = (path) => getPath(runtime.getTree(), path);
4186
+
4187
+ // src/widgets/shared/clickable.ts
4188
+ function useClickable(panelId, activate) {
4189
+ const ctx = useContext4(DashboardContext);
4190
+ const def = ctx && panelId ? findPanel(ctx.runtime.doc, panelId) : void 0;
4191
+ const on = def?.on;
4192
+ if (on?.click === void 0) return { onClick: activate };
4504
4193
  return {
4505
- get,
4506
- use: function useStoreValue(pathOrSelect) {
4507
- return useTree(
4508
- useCallback4(
4509
- (t) => typeof pathOrSelect === "string" ? getPath(t, pathOrSelect) : pathOrSelect(t),
4510
- [pathOrSelect]
4511
- ),
4512
- (a, b) => Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b)
4513
- );
4514
- },
4515
- set: (path, value) => {
4516
- if (RESERVED.test(path)) throw new Error(`"${path}" belongs to the runtime; use setFilter or an action`);
4517
- runtime.store.dispatch(stateActions.set({ path, value }));
4518
- },
4519
- setFilter: (name, value) => runtime.store.dispatch(stateActions.setFilter({ name, value })),
4520
- subscribe: (path, fn) => {
4521
- let prev = get(path);
4522
- return runtime.store.subscribe(() => {
4523
- const next = get(path);
4524
- if (!Object.is(next, prev) && JSON.stringify(next) !== JSON.stringify(prev)) {
4525
- prev = next;
4526
- fn(next);
4194
+ onClick: activate,
4195
+ role: "button",
4196
+ tabIndex: 0,
4197
+ onKeyDown: (e) => {
4198
+ if (e.key !== "Enter" && e.key !== " ") return;
4199
+ e.preventDefault();
4200
+ activate();
4201
+ }
4202
+ };
4203
+ }
4204
+
4205
+ // src/widgets/shared/motion.ts
4206
+ import { useEffect as useEffect4, useRef as useRef6, useState as useState5 } from "react";
4207
+ var reduced = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4208
+ var easeOut = (t) => 1 - (1 - t) ** 3;
4209
+ function useCountUp(target, ms = 700) {
4210
+ const [shown, setShown] = useState5(() => typeof target === "number" && !reduced() ? 0 : target);
4211
+ const from = useRef6(0);
4212
+ useEffect4(() => {
4213
+ if (typeof target !== "number" || !Number.isFinite(target) || reduced()) {
4214
+ setShown(target);
4215
+ return;
4216
+ }
4217
+ const start = performance.now();
4218
+ const a = from.current;
4219
+ let raf = 0;
4220
+ const step = (now) => {
4221
+ const t = Math.min(1, (now - start) / ms);
4222
+ const v = a + (target - a) * easeOut(t);
4223
+ setShown(Number.isInteger(target) && t === 1 ? target : v);
4224
+ if (t < 1) raf = requestAnimationFrame(step);
4225
+ else from.current = target;
4226
+ };
4227
+ raf = requestAnimationFrame(step);
4228
+ return () => {
4229
+ cancelAnimationFrame(raf);
4230
+ from.current = typeof target === "number" ? target : 0;
4231
+ };
4232
+ }, [target, ms]);
4233
+ return shown;
4234
+ }
4235
+
4236
+ // src/widgets/builtins/Kpi.tsx
4237
+ import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
4238
+ var Kpi = defineWidget({
4239
+ ...KpiContract,
4240
+ implements: "kpi",
4241
+ header: "widget",
4242
+ empty: "widget",
4243
+ meta: { label: "KPI", icon: "kpi", category: "Numbers", size: { w: 3, h: 4, minW: 2, minH: 3 } },
4244
+ events: ["click", "hover"],
4245
+ parts: ["value"],
4246
+ defaults: { title: "New KPI", goodWhen: "up" },
4247
+ component: function KpiWidget({ spec, data, source, emit, helpers, panelId }) {
4248
+ const clickable = useClickable(panelId, () => {
4249
+ }).role === "button";
4250
+ const num = (v) => typeof v === "number" ? v : toNumber(field(source, v));
4251
+ const value = toNumber(data) ?? data;
4252
+ const animated = useCountUp(value);
4253
+ const n = toNumber(value);
4254
+ const fmt = (v) => formatValue(v, helpers, spec.format, spec.decimals);
4255
+ const unit = spec.format === "duration" ? void 0 : spec.unit;
4256
+ const empty = spec.empty === true || value === void 0 || value === null || value === "";
4257
+ const hasTarget = spec.target !== void 0;
4258
+ const target = hasTarget ? num(spec.target) : void 0;
4259
+ const op = spec.goodWhen === "down" ? "\u2264 " : spec.goodWhen === "up" ? "\u2265 " : "";
4260
+ const targetText = spec.targetLabel ?? (target !== void 0 ? `Target: ${op}${fmt(target)}${unit ? spec.format === "percent" ? "" : ` ${unit.toLowerCase()}` : ""}` : void 0);
4261
+ const met = target === void 0 || n === void 0 || spec.goodWhen === "none" ? void 0 : spec.goodWhen === "down" ? n <= target : n >= target;
4262
+ const labels = { good: spec.statusLabels?.good ?? "On track", bad: spec.statusLabels?.bad ?? "Action needed" };
4263
+ 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));
4264
+ const delta = n !== void 0 && ref !== void 0 ? n - ref : void 0;
4265
+ const better = delta === void 0 || delta === 0 || spec.goodWhen === "none" ? void 0 : delta > 0 === (spec.goodWhen === "up");
4266
+ const low = spec.band ? num(spec.band.low) : void 0;
4267
+ const high = spec.band ? num(spec.band.high) : void 0;
4268
+ const outside = n !== void 0 && (low !== void 0 && n < low || high !== void 0 && n > high);
4269
+ const pTarget = spec.progress ? num(spec.progress.target) : void 0;
4270
+ const ratio = n !== void 0 && pTarget ? Math.min(spec.progress?.cap ?? Number.POSITIVE_INFINITY, n / pTarget * 100) : void 0;
4271
+ return /* @__PURE__ */ jsxs10("div", { className: "ds-kpi", "data-size": spec.size, children: [
4272
+ /* @__PURE__ */ jsxs10("div", { className: "ds-kpi-label", children: [
4273
+ /* @__PURE__ */ jsx15("span", { children: spec.title }),
4274
+ spec.info && /* @__PURE__ */ jsx15(InfoTip, { text: spec.info })
4275
+ ] }),
4276
+ /* @__PURE__ */ jsx15(
4277
+ "button",
4278
+ {
4279
+ type: "button",
4280
+ className: "ds-kpi-main",
4281
+ "data-clickable": clickable || void 0,
4282
+ onClick: () => emit("click", "value", { datum: source, value }),
4283
+ onMouseEnter: () => emit("hover", "value", { datum: source, value }),
4284
+ "aria-label": `${spec.title ?? "Value"}: ${empty ? spec.emptyText ?? "no value" : fmt(value)}${unit ? ` ${unit}` : ""}`,
4285
+ children: empty ? (
4286
+ // No value is not zero: the author's text, else a dash.
4287
+ /* @__PURE__ */ jsx15("span", { className: "ds-kpi-empty", children: spec.emptyText || "\u2014" })
4288
+ ) : /* @__PURE__ */ jsxs10(Fragment5, { children: [
4289
+ /* @__PURE__ */ jsxs10(
4290
+ "span",
4291
+ {
4292
+ className: "ds-kpi-value",
4293
+ style: { color: spec.tone ? tone(spec.tone).fg : outside ? tone("bad").fg : void 0 },
4294
+ children: [
4295
+ fmt(animated),
4296
+ unit && spec.unitStyle === "value" ? unit : null
4297
+ ]
4298
+ }
4299
+ ),
4300
+ unit && spec.unitStyle !== "value" && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-unit", children: unit })
4301
+ ] })
4527
4302
  }
4528
- });
4529
- }
4530
- };
4303
+ ),
4304
+ delta !== void 0 && /* @__PURE__ */ jsxs10(
4305
+ "span",
4306
+ {
4307
+ className: "ds-kpi-delta",
4308
+ style: { color: tone(better === void 0 ? "neutral" : better ? "good" : "bad").fg },
4309
+ children: [
4310
+ delta > 0 ? "\u2191" : delta < 0 ? "\u2193" : "\u2192",
4311
+ " ",
4312
+ spec.format === "duration" ? helpers.fmt.duration(Math.abs(delta)) : `${helpers.fmt.number(Math.abs(ref ? delta / Math.abs(ref) * 100 : 0), 1)}%`,
4313
+ typeof spec.compare === "object" && spec.compare.label && /* @__PURE__ */ jsxs10("span", { className: "ds-kpi-sub", children: [
4314
+ " ",
4315
+ spec.compare.label
4316
+ ] })
4317
+ ]
4318
+ }
4319
+ ),
4320
+ spec.note && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-sub", children: spec.note }),
4321
+ spec.sublabel && /* @__PURE__ */ jsx15("span", { className: "ds-kpi-sub", children: spec.sublabel }),
4322
+ low !== void 0 && high !== void 0 && /* @__PURE__ */ jsxs10("span", { className: "ds-kpi-sub", children: [
4323
+ "Expected ",
4324
+ fmt(low),
4325
+ "\u2013",
4326
+ fmt(high)
4327
+ ] }),
4328
+ ratio !== void 0 && // biome-ignore lint/a11y/useFocusableInteractive: a progress bar is read-only, not interactive
4329
+ /* @__PURE__ */ jsx15(
4330
+ "span",
4331
+ {
4332
+ className: "ds-progress",
4333
+ role: "progressbar",
4334
+ "aria-valuenow": Math.round(ratio),
4335
+ "aria-valuemin": 0,
4336
+ "aria-valuemax": 100,
4337
+ children: /* @__PURE__ */ jsx15(
4338
+ "span",
4339
+ {
4340
+ style: { width: `${Math.min(100, ratio)}%`, background: tone(ratio >= 100 ? "good" : "info").solid }
4341
+ }
4342
+ )
4343
+ }
4344
+ ),
4345
+ (hasTarget || targetText) && /* @__PURE__ */ jsxs10("div", { className: "ds-kpi-foot", children: [
4346
+ 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 }),
4347
+ 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 })
4348
+ ] })
4349
+ ] });
4350
+ }
4351
+ });
4352
+
4353
+ // src/widgets/builtins/Sparkline.tsx
4354
+ import "zod";
4355
+ import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
4356
+ function sparkPath(values, w, h, pad = 2) {
4357
+ if (values.length === 0) return { line: "", area: "" };
4358
+ const min = values.reduce((a, b) => Math.min(a, b));
4359
+ const max = values.reduce((a, b) => Math.max(a, b));
4360
+ const span = max - min || 1;
4361
+ const step = values.length > 1 ? (w - pad * 2) / (values.length - 1) : 0;
4362
+ const pts = values.map((v, i) => [pad + i * step, h - pad - (v - min) / span * (h - pad * 2)]);
4363
+ const line = pts.map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
4364
+ const last = pts[pts.length - 1];
4365
+ return { line, area: `${line} L${last[0].toFixed(1)},${h} L${pad},${h} Z` };
4531
4366
  }
4532
- function findPanel(doc, id) {
4533
- const top = doc.spec.panels[id];
4534
- if (top) return top;
4535
- for (const m of Object.values(doc.spec.modals ?? {})) if (m.panels[id]) return m.panels[id];
4536
- return void 0;
4367
+ function SparkSvg({
4368
+ values,
4369
+ area = true,
4370
+ height = 32,
4371
+ color: color2 = "var(--ds-series-1)"
4372
+ }) {
4373
+ const w = 120;
4374
+ const { line, area: fill } = sparkPath(values, w, height);
4375
+ return /* @__PURE__ */ jsxs11("svg", { viewBox: `0 0 ${w} ${height}`, preserveAspectRatio: "none", style: { width: "100%", height }, "aria-hidden": "true", children: [
4376
+ area && /* @__PURE__ */ jsx16("path", { d: fill, fill: color2, opacity: 0.15 }),
4377
+ /* @__PURE__ */ jsx16("path", { d: line, fill: "none", stroke: color2, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" })
4378
+ ] });
4537
4379
  }
4538
- function useHiddenPanels(ids) {
4539
- const { runtime } = useDashboard();
4540
- const key = ids.join(",");
4541
- const list = useTree(
4542
- // biome-ignore lint/correctness/useExhaustiveDependencies: ids are compared by key
4543
- useCallback4(
4544
- (tree) => ids.filter((id) => {
4545
- const def = findPanel(runtime.doc, id);
4546
- if (!def) return false;
4547
- if (tree.panels[id]?.hidden) return true;
4548
- if (typeof def.visibleWhen !== "string") return false;
4549
- try {
4550
- return !evaluate(
4551
- def.visibleWhen,
4552
- rootScope(tree, runtime.helpers, { panel: tree.panels[id] ?? {}, drill: drillValues(tree, id) })
4553
- );
4554
- } catch {
4555
- return false;
4380
+ var Sparkline = defineWidget({
4381
+ ...SparklineContract,
4382
+ implements: "chart",
4383
+ meta: { label: "Sparkline", icon: "sparkline", category: "Charts", size: { w: 3, h: 2, minW: 2, minH: 1 } },
4384
+ events: ["hover"],
4385
+ defaults: { y: "value" },
4386
+ component: function SparklineWidget({ spec, data, size: size2, emit }) {
4387
+ const rows = asRows(data);
4388
+ const values = rows.map((r) => toNumber(field(r, spec.y)) ?? 0);
4389
+ return /* @__PURE__ */ jsx16(
4390
+ "div",
4391
+ {
4392
+ onMouseEnter: () => emit("hover", "line", { value: values[values.length - 1] }),
4393
+ style: { height: "100%" },
4394
+ role: "img",
4395
+ "aria-label": `${spec.title ?? spec.y}: ${values.length} points`,
4396
+ children: /* @__PURE__ */ jsx16(SparkSvg, { values, area: spec.area, height: Math.max(24, size2.height || 32) })
4397
+ }
4398
+ );
4399
+ }
4400
+ });
4401
+
4402
+ // src/widgets/builtins/StageTracker.tsx
4403
+ import "zod";
4404
+ import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
4405
+ var StageTracker = defineWidget({
4406
+ ...StageTrackerContract,
4407
+ implements: "stages",
4408
+ meta: { label: "Stage tracker", icon: "stages", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
4409
+ events: ["click"],
4410
+ parts: ["stage"],
4411
+ component: function StageTrackerWidget({ spec, data, emit }) {
4412
+ const raw = typeof data === "string" || typeof data === "number" ? data : field(data, spec.current);
4413
+ const idx = typeof raw === "number" ? raw : spec.stages.findIndex((s) => s.toLowerCase() === String(raw ?? "").toLowerCase());
4414
+ return /* @__PURE__ */ jsx17("ol", { className: "ds-stages", children: spec.stages.map((s, i) => {
4415
+ const state = i < idx ? "done" : i === idx ? "current" : "todo";
4416
+ return /* @__PURE__ */ jsx17("li", { "data-state": state, children: /* @__PURE__ */ jsxs12(
4417
+ "button",
4418
+ {
4419
+ type: "button",
4420
+ onClick: () => emit("click", "stage", { value: s, index: i, datum: data }),
4421
+ "aria-current": state === "current" ? "step" : void 0,
4422
+ children: [
4423
+ /* @__PURE__ */ jsx17("span", { className: "ds-stage-dot", "aria-hidden": "true", children: state === "done" ? "\u2713" : i + 1 }),
4424
+ s
4425
+ ]
4556
4426
  }
4427
+ ) }, s);
4428
+ }) });
4429
+ }
4430
+ });
4431
+
4432
+ // src/widgets/builtins/StateTimeline.tsx
4433
+ import "zod";
4434
+ import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
4435
+ var StateTimeline = defineWidget({
4436
+ ...StateTimelineContract,
4437
+ implements: "timeline",
4438
+ meta: { label: "State timeline", icon: "timeline", category: "Status", size: { w: 12, h: 3, minW: 4, minH: 2 } },
4439
+ events: ["click", "hover"],
4440
+ parts: ["segment"],
4441
+ component: function StateTimelineWidget({ spec, data, emit, helpers }) {
4442
+ 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);
4443
+ const end = helpers.now();
4444
+ const start = spec.window ? end - parseDuration(spec.window) : all[0]?.t ?? end;
4445
+ const lanes = spec.rows ? [...new Set(all.map((x) => String(field(x.r, spec.rows))))] : [""];
4446
+ const span = Math.max(1, end - start);
4447
+ const states = /* @__PURE__ */ new Map();
4448
+ return /* @__PURE__ */ jsxs13("div", { className: "ds-timeline", children: [
4449
+ lanes.map((lane) => {
4450
+ const pts = all.filter((x) => !spec.rows || String(field(x.r, spec.rows)) === lane);
4451
+ const segs = pts.map((p, i) => {
4452
+ const from = Math.max(start, p.t);
4453
+ const to = Math.min(end, pts[i + 1]?.t ?? end);
4454
+ const state = spec.stateMap?.[p.raw] ?? p.raw;
4455
+ states.set(state, (states.get(state) ?? 0) + Math.max(0, to - from));
4456
+ return { p, from, to, state };
4457
+ });
4458
+ return /* @__PURE__ */ jsxs13("div", { className: "ds-timeline-lane", children: [
4459
+ lane && /* @__PURE__ */ jsx18("span", { className: "ds-timeline-name", children: lane }),
4460
+ /* @__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) => (
4461
+ // biome-ignore lint/a11y/useKeyWithClickEvents: the per-state totals below summarise the same data for keyboard users
4462
+ /* @__PURE__ */ jsx18(
4463
+ "span",
4464
+ {
4465
+ 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)})`,
4466
+ style: {
4467
+ left: `${(s.from - start) / span * 100}%`,
4468
+ width: `${(s.to - s.from) / span * 100}%`,
4469
+ background: tone(spec.tones?.[s.state] ?? "neutral").solid
4470
+ },
4471
+ onClick: () => emit("click", "segment", { datum: s.p.r, value: s.state, x: s.from }),
4472
+ onMouseEnter: () => emit("hover", "segment", { datum: s.p.r, value: s.state, x: s.from })
4473
+ },
4474
+ `${s.from}-${s.state}`
4475
+ )
4476
+ )) })
4477
+ ] }, lane);
4557
4478
  }),
4558
- [key, runtime]
4559
- ),
4560
- (a, b) => a.join(",") === b.join(",")
4561
- );
4562
- return useMemo4(() => new Set(list), [list]);
4563
- }
4564
- function panelUnder(x, y, exclude) {
4565
- if (typeof document === "undefined") return void 0;
4566
- for (const el of document.elementsFromPoint(x, y)) {
4567
- const p = el.closest(".ds-panel[data-panel]");
4568
- if (p && (!exclude || !exclude.contains(p) && !p.contains(exclude))) return p;
4479
+ /* @__PURE__ */ jsxs13("div", { className: "ds-timeline-axis", children: [
4480
+ /* @__PURE__ */ jsx18("span", { children: helpers.fmt.date(start, "time") }),
4481
+ /* @__PURE__ */ jsx18("span", { children: spec.endLabel ?? helpers.fmt.date(end, "time") })
4482
+ ] }),
4483
+ /* @__PURE__ */ jsx18("ul", { className: "ds-legend", children: [...states.entries()].map(([s, ms]) => /* @__PURE__ */ jsxs13("li", { children: [
4484
+ /* @__PURE__ */ jsx18(
4485
+ "span",
4486
+ {
4487
+ className: "ds-dot",
4488
+ style: { background: tone(spec.tones?.[s] ?? "neutral").solid },
4489
+ "aria-hidden": "true"
4490
+ }
4491
+ ),
4492
+ s,
4493
+ " ",
4494
+ /* @__PURE__ */ jsx18("strong", { children: helpers.fmt.duration(ms / 1e3) })
4495
+ ] }, s)) })
4496
+ ] });
4569
4497
  }
4570
- return void 0;
4571
- }
4572
- function indexIn(box, x, y) {
4573
- const row = getComputedStyle(box).flexDirection === "row";
4574
- const kids = [...box.children].filter((c) => c.classList.contains("ds-panel"));
4575
- return kids.filter((k) => {
4576
- const r = k.getBoundingClientRect();
4577
- return row ? r.left + r.width / 2 < x && r.top < y : r.top + r.height / 2 < y;
4578
- }).length;
4579
- }
4580
- function dropIndexAt(panel, x, y) {
4581
- const id = panel.getAttribute("data-panel") ?? "";
4582
- const under = document.elementsFromPoint(x, y).find((el) => el.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`));
4583
- const box = under?.closest(`[data-slot][data-owner="${CSS.escape(id)}"]`) ?? panel.querySelector(`[data-slot][data-owner="${CSS.escape(id)}"]`);
4584
- if (!box) return {};
4585
- return { slot: box.getAttribute("data-slot") ?? void 0, index: indexIn(box, x, y) };
4586
- }
4587
- function PanelFrame({ id, nested = false }) {
4588
- return /* @__PURE__ */ jsx21(Boundary, { resetKeys: [id], fallback: (e) => /* @__PURE__ */ jsx21(PanelCrash, { id, error: e }), children: /* @__PURE__ */ jsx21(PanelFrameInner, { id, nested }) });
4589
- }
4590
- function PanelCrash({ id, error }) {
4591
- const { options } = useDashboard();
4592
- let custom;
4593
- try {
4594
- custom = options.renderError?.({ code: "render", message: error.message }, id);
4595
- } catch {
4596
- custom = void 0;
4498
+ });
4499
+
4500
+ // src/widgets/builtins/Status.tsx
4501
+ import "zod";
4502
+ import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
4503
+ var Status = defineWidget({
4504
+ ...StatusContract,
4505
+ implements: "badge",
4506
+ // A badge, not a card: it can sit anywhere, including in another widget's header.
4507
+ frame: "plain",
4508
+ meta: { label: "Status badge", icon: "status", category: "Numbers", size: { w: 3, h: 2, minW: 1, minH: 1 } },
4509
+ events: ["click"],
4510
+ component: function StatusWidget({ spec, data, emit }) {
4511
+ const row = asRows(data)[0] ?? {};
4512
+ const state = String(field(row, spec.state) ?? "unknown");
4513
+ const t = spec.text ? spec.tone ?? "info" : spec.stateMap?.[state] ?? spec.tone ?? "neutral";
4514
+ const text = spec.text ?? spec.labels?.[state] ?? state.charAt(0).toUpperCase() + state.slice(1);
4515
+ return /* @__PURE__ */ jsxs14("button", { type: "button", className: "ds-status", onClick: () => emit("click", "status", { datum: row, value: state }), children: [
4516
+ /* @__PURE__ */ jsxs14("span", { className: "ds-pill", style: { background: tone(t).bg, color: tone(t).fg, borderColor: tone(t).border }, children: [
4517
+ /* @__PURE__ */ jsx19("span", { className: "ds-dot", style: { background: tone(t).solid }, "aria-hidden": "true" }),
4518
+ text
4519
+ ] }),
4520
+ spec.label && /* @__PURE__ */ jsx19("span", { className: "ds-status-label", children: String(field(row, spec.label) ?? "") })
4521
+ ] });
4597
4522
  }
4598
- 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: [
4599
- "This panel could not be shown: ",
4600
- error.message
4601
- ] }) }) });
4523
+ });
4524
+
4525
+ // src/widgets/builtins/Table.tsx
4526
+ import { useEffect as useEffect5, useMemo as useMemo4, useRef as useRef7, useState as useState6 } from "react";
4527
+ import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
4528
+ var ROW_H = 36;
4529
+ function pageList(current, pages) {
4530
+ if (pages <= 7) return Array.from({ length: pages }, (_, i) => i + 1);
4531
+ const set = new Set([1, pages, current - 1, current, current + 1].filter((n) => n >= 1 && n <= pages));
4532
+ const sorted = [...set].sort((a, b) => a - b);
4533
+ const out = [];
4534
+ sorted.forEach((n, i) => {
4535
+ if (i > 0 && n - sorted[i - 1] > 1) out.push(0);
4536
+ out.push(n);
4537
+ });
4538
+ return out;
4602
4539
  }
4603
- function PanelFrameInner({ id, nested }) {
4604
- const { runtime, registry, options, visibility } = useDashboard();
4605
- const instance = `${id}\0${useId3()}`;
4606
- const inherited = useNodeScope();
4607
- const def = findPanel(runtime.doc, id);
4608
- const widget = registry.byKind.get(def.kind);
4609
- const spec = def.spec ?? {};
4610
- const binding = spec.data;
4611
- const drillLevels = def.drill?.levels ?? [];
4612
- const view = useTree(
4613
- // biome-ignore lint/correctness/useExhaustiveDependencies: the panel definition is fixed for a runtime
4614
- useCallback4(
4615
- (tree) => {
4616
- const ps = tree.panels[id] ?? {};
4617
- const level = drillLevels[(ps.drill ?? []).length];
4618
- const baseSource = level?.source ?? binding?.source;
4619
- const drillId = baseSource && level?.query ? drillSourceId(baseSource, id, level.name) : void 0;
4620
- const source = drillId && runtime.datasourceIds.has(drillId) ? drillId : baseSource;
4621
- const scope2 = rootScope(tree, runtime.helpers, {
4622
- panel: { ...ps, controls: ps.controls ?? {} },
4623
- drill: drillValues(tree, id),
4624
- parent: inherited.parentData,
4625
- ...inherited.hasItem ? { item: inherited.item, index: inherited.index } : {}
4626
- });
4627
- let visible = true;
4628
- if (typeof def.visibleWhen === "string") {
4629
- try {
4630
- visible = Boolean(evaluate(def.visibleWhen, scope2));
4631
- } catch {
4632
- visible = true;
4633
- }
4634
- }
4635
- let data;
4636
- let sourceData;
4637
- let status = "success";
4638
- let error;
4639
- let stale = false;
4640
- let updatedAt;
4641
- if (source) {
4642
- const s = tree.datasources[source];
4643
- status = s?.status ?? "idle";
4644
- error = s?.error;
4645
- stale = Boolean(s?.stale);
4646
- updatedAt = s?.updatedAt;
4647
- sourceData = s?.data;
4648
- data = typeof binding?.path === "string" ? getPath(s?.data, binding.path) : s?.data;
4649
- } else if (binding && typeof binding.panel === "string")
4650
- data = getPath(tree.panels[binding.panel], binding.path ?? "selection");
4651
- else if (binding && typeof binding.state === "string") data = getPath(tree, binding.state);
4652
- else if (binding && "value" in binding) data = binding.value;
4653
- else if (!binding && inherited.parentId) data = inherited.data;
4654
- const { data: _d, ...rest } = spec;
4655
- let props2 = {};
4656
- try {
4657
- props2 = resolvePanel(rest, scope2, Boolean(inherited.hasItem));
4658
- } catch (e) {
4659
- error = { code: "template", message: e.message };
4660
- }
4661
- const msg = def.messages;
4662
- const messages = msg ? resolvePanel(msg, scope2) : void 0;
4663
- const group = props2.highlight ?? void 0;
4664
- return {
4665
- visible,
4666
- hidden: Boolean(ps.hidden),
4667
- panel: ps,
4668
- source,
4669
- data,
4670
- sourceData,
4671
- status,
4672
- error,
4673
- stale,
4674
- updatedAt,
4675
- props: props2,
4676
- messages,
4677
- highlight: group ? tree.highlight[group] : void 0,
4678
- x: level?.x ?? void 0
4679
- };
4680
- },
4681
- [id, runtime, inherited.parentId, inherited.data, inherited.parentData, inherited.item, inherited.index]
4682
- ),
4683
- samePanelView
4684
- );
4685
- const renderNested = useCallback4((child) => /* @__PURE__ */ jsx21(PanelFrame, { id: child, nested: true }, child), []);
4686
- const store = useMemo4(() => widgetStore(runtime), [runtime]);
4687
- const [bodyRef, size2] = useSize();
4688
- const frameRef = useRef6(null);
4689
- useEffect5(() => {
4690
- if (!view.visible || view.hidden) {
4691
- visibility.set(instance, null);
4692
- return;
4693
- }
4694
- const el = frameRef.current;
4695
- if (!el || typeof IntersectionObserver === "undefined") {
4696
- visibility.set(instance, view.source ? [view.source] : []);
4697
- return () => visibility.set(instance, null);
4698
- }
4699
- const io = new IntersectionObserver(
4700
- ([e]) => visibility.set(instance, e?.isIntersecting && view.source ? [view.source] : []),
4701
- { rootMargin: "200px" }
4702
- );
4703
- io.observe(el);
4704
- return () => {
4705
- io.disconnect();
4706
- visibility.set(instance, null);
4540
+ var Table = defineWidget({
4541
+ ...TableContract,
4542
+ implements: "table",
4543
+ exposes: { selection: "the clicked row", page: "current page (ui.page)", search: "search text (ui.search)" },
4544
+ meta: { label: "Table", icon: "table", category: "Lists", size: { w: 12, h: 8, minW: 4, minH: 4 } },
4545
+ events: ["rowClick", "cellClick", "hover"],
4546
+ parts: ["row", "cell"],
4547
+ rows: (data) => asRows(data),
4548
+ component: function TableWidget({ spec, data, source, emit, helpers, size: size2, state, setUi, status }) {
4549
+ const tpl = (t, row, item) => {
4550
+ try {
4551
+ const v = interpolate(t, scope({ row, item, datum: row }, helpers));
4552
+ return v === null || v === void 0 ? "" : String(v);
4553
+ } catch {
4554
+ return "";
4555
+ }
4707
4556
  };
4708
- }, [instance, view.visible, view.hidden, view.source, visibility]);
4709
- const emit = useCallback4(
4710
- (type, part, detail) => {
4711
- const event = { type, panel: id, ...part ? { part } : {}, ...detail };
4712
- options.onEvent?.(event);
4713
- void runtime.emit(event);
4714
- },
4715
- [id, options, runtime]
4716
- );
4717
- const run = useCallback4(
4718
- (action, detail) => void runtime.runAction(action, { type: "click", panel: id, ...detail }),
4719
- [runtime, id]
4720
- );
4721
- const setUi = useCallback4(
4722
- (patch) => runtime.store.dispatch(
4723
- stateActions.patchPanel({ id, patch: { ui: { ...runtime.getTree().panels[id]?.ui, ...patch } } })
4724
- ),
4725
- [runtime, id]
4726
- );
4727
- const dataRef = useRef6(view.data);
4728
- dataRef.current = view.data;
4729
- const props = useMemo4(() => {
4730
- let p = { ...view.props, ...view.panel.props ?? {} };
4731
- if (view.x) p = { ...p, x: view.x };
4732
- p = withFunctions(p, (code) => {
4733
- const f = runtime.scripts.fnProp(code, ["p", "data"]);
4734
- return (arg) => {
4735
- try {
4736
- return f(arg, dataRef.current);
4737
- } catch (e) {
4738
- console.warn(`[dashspec] ${id}: function prop failed: ${e.message}`);
4739
- return "";
4557
+ const base = useMemo4(() => {
4558
+ const rows2 = asRows(data);
4559
+ return spec.pivot ? applyTransform(rows2, [{ pivot: spec.pivot }], scope()) : rows2;
4560
+ }, [data, spec.pivot]);
4561
+ const columns = useMemo4(() => {
4562
+ if (spec.columns?.length) return spec.columns;
4563
+ if (spec.columnsFrom) {
4564
+ const cf = spec.columnsFrom;
4565
+ return asRows(field(source, cf.path)).map((c) => ({
4566
+ key: String(field(c, cf.key)),
4567
+ label: String(field(c, cf.label) ?? field(c, cf.key)),
4568
+ ...cf.type ? { type: cf.type } : {},
4569
+ ...cf.format ? { format: cf.format } : {}
4570
+ }));
4571
+ }
4572
+ return Object.keys(base[0] ?? {}).map((k) => ({ key: k }));
4573
+ }, [spec.columns, spec.columnsFrom, source, base]);
4574
+ const pg = spec.pagination && spec.pagination.enabled !== false ? spec.pagination : void 0;
4575
+ const sr = spec.search === true ? { enabled: true, mode: "client" } : spec.search && spec.search.enabled !== false ? spec.search : void 0;
4576
+ const so = spec.sorting ?? { enabled: true, mode: "client" };
4577
+ const fl = spec.filtering && spec.filtering.enabled !== false ? spec.filtering : void 0;
4578
+ const server = {
4579
+ paging: pg?.mode === "server",
4580
+ search: sr?.mode === "server",
4581
+ sort: so.mode === "server",
4582
+ filter: fl?.mode === "server"
4583
+ };
4584
+ const anyServer = server.paging || server.search || server.sort || server.filter;
4585
+ const ui = state.ui ?? {};
4586
+ const [view, setView] = useState6(() => ({
4587
+ page: Number(ui.page ?? 1),
4588
+ pageSize: Number(ui.pageSize ?? pg?.pageSize ?? 20),
4589
+ search: String(ui.search ?? ""),
4590
+ sortKey: ui.sortKey ?? so.default?.key,
4591
+ sortOrder: ui.sortOrder ?? so.default?.order ?? "asc",
4592
+ filters: ui.filters ?? {}
4593
+ }));
4594
+ const update = (patch) => {
4595
+ const next = { ...view, ...patch };
4596
+ setView(next);
4597
+ if (anyServer)
4598
+ setUi({
4599
+ page: next.page,
4600
+ pageSize: next.pageSize,
4601
+ offset: (next.page - 1) * next.pageSize,
4602
+ search: next.search || void 0,
4603
+ sortKey: next.sortKey,
4604
+ sortOrder: next.sortKey ? next.sortOrder : void 0,
4605
+ ordering: next.sortKey ? `${next.sortOrder === "desc" ? "-" : ""}${next.sortKey}` : void 0,
4606
+ filters: Object.fromEntries(Object.entries(next.filters).filter(([, v]) => v !== ""))
4607
+ });
4608
+ };
4609
+ const [searchText, setSearchText] = useState6(view.search);
4610
+ const searchTimer = useRef7(void 0);
4611
+ useEffect5(() => () => clearTimeout(searchTimer.current), []);
4612
+ const [scrollTop, setScrollTop] = useState6(0);
4613
+ const scroller = useRef7(null);
4614
+ const sort = view.sortKey ? { key: view.sortKey, order: view.sortOrder } : void 0;
4615
+ const rows = useMemo4(() => {
4616
+ let r = base;
4617
+ if (fl && !server.filter)
4618
+ for (const [k, v] of Object.entries(view.filters)) {
4619
+ if (v === "") continue;
4620
+ const c = columns.find((x) => x.key === k);
4621
+ if (c?.filter === "min")
4622
+ r = r.filter((row) => (toNumber(field(row, k)) ?? Number.NEGATIVE_INFINITY) >= Number(v));
4623
+ else if (c?.filter === "select") r = r.filter((row) => String(field(row, k) ?? "") === v);
4624
+ else
4625
+ r = r.filter(
4626
+ (row) => String(field(row, k) ?? "").toLowerCase().includes(v.toLowerCase())
4627
+ );
4740
4628
  }
4741
- };
4742
- });
4743
- return widget ? parseWidgetProps(widget.schema, p).props : p;
4744
- }, [view.props, view.panel.props, view.x, runtime, widget, id]);
4745
- if (!view.visible || view.hidden) return null;
4746
- const ownHeader = widget?.header === "widget";
4747
- const title = ownHeader ? void 0 : props.title;
4748
- const info = ownHeader ? void 0 : props.info;
4749
- const meta2 = props.meta;
4750
- const live2 = Boolean(props.live);
4751
- const drill = view.panel.drill ?? [];
4752
- const controls = def.controls ?? [];
4753
- const tone2 = def.style?.tone ?? (widget?.frame === "plain" ? "plain" : "default");
4754
- const headerKids = slotChildren(def, "header");
4755
- const footerKids = slotChildren(def, "footer");
4756
- const hideHeader = Boolean(def.style?.hideHeader) || !title && !meta2 && !live2 && drill.length === 0 && controls.length === 0 && !view.stale && headerKids.length === 0;
4757
- const dnd = Boolean(options.onDropOnPanel);
4758
- let body;
4759
- if (!widget) body = /* @__PURE__ */ jsxs16("div", { className: "ds-state", children: [
4760
- "Unknown widget \u201C",
4761
- String(def.kind),
4762
- "\u201D"
4763
- ] });
4764
- else if (view.error && view.data === void 0)
4765
- body = options.renderError?.(view.error, id) ?? /* @__PURE__ */ jsx21("div", { className: "ds-state ds-state-error", role: "alert", children: view.messages?.error ?? view.error.message });
4766
- else if (view.source && view.data === void 0 && (view.status === "loading" || view.status === "idle"))
4767
- body = options.renderLoading?.(id, loadingText(view.messages)) ?? /* @__PURE__ */ jsx21(LoadingState, { text: loadingText(view.messages) });
4768
- else if (view.source && isEmpty(view.data) && widget.empty !== "widget")
4769
- body = options.renderEmpty?.(id) ?? /* @__PURE__ */ jsx21("div", { className: "ds-state", children: view.messages?.empty ?? "No data" });
4770
- else {
4771
- const W = widget.component;
4772
- body = /* @__PURE__ */ jsx21(
4773
- Boundary,
4774
- {
4775
- resetKeys: [view.data, props],
4776
- fallback: (e) => /* @__PURE__ */ jsxs16("div", { className: "ds-state ds-state-error", role: "alert", children: [
4777
- "This panel could not be shown: ",
4778
- e.message
4779
- ] }),
4780
- children: /* @__PURE__ */ jsx21(
4781
- W,
4782
- {
4783
- spec: props,
4784
- data: view.data,
4785
- source: view.sourceData,
4786
- run,
4787
- emit,
4788
- state: view.panel,
4789
- setUi,
4790
- status: view.status,
4791
- highlight: view.highlight,
4792
- size: size2,
4793
- mode: options.mode,
4794
- helpers: runtime.helpers,
4795
- panelId: id,
4796
- renderSlot: (name, o) => /* @__PURE__ */ jsx21(Slot, { name, ...o }),
4797
- store
4629
+ if (sr && !server.search && view.search) {
4630
+ const q = view.search.toLowerCase();
4631
+ const fields = sr.mode === "client" && "fields" in sr ? sr.fields : void 0;
4632
+ r = r.filter(
4633
+ (row) => (fields ? fields.map((f) => field(row, f)) : Object.values(row)).some(
4634
+ (v) => v !== null && v !== void 0 && typeof v !== "object" && String(v).toLowerCase().includes(q)
4635
+ )
4636
+ );
4637
+ }
4638
+ if (sort && !server.sort) {
4639
+ const dir = sort.order === "desc" ? -1 : 1;
4640
+ r = [...r].sort((a, b) => {
4641
+ const x = field(a, sort.key);
4642
+ const y = field(b, sort.key);
4643
+ if (x === y) return 0;
4644
+ if (x === null || x === void 0) return 1;
4645
+ if (y === null || y === void 0) return -1;
4646
+ const nx = toNumber(x);
4647
+ const ny = toNumber(y);
4648
+ return (nx !== void 0 && ny !== void 0 ? nx - ny : String(x).localeCompare(String(y), void 0, { numeric: true })) * dir;
4649
+ });
4650
+ }
4651
+ return r;
4652
+ }, [base, view, columns]);
4653
+ const pageSize = pg ? view.pageSize : void 0;
4654
+ const rowTotal = server.paging ? toNumber(field(source, pg?.totalPath ?? "count")) ?? rows.length : rows.length;
4655
+ const pages = pageSize ? Math.max(1, Math.ceil(rowTotal / pageSize)) : 1;
4656
+ const current = Math.min(view.page, pages);
4657
+ const shown = pageSize && !server.paging ? rows.slice((current - 1) * pageSize, current * pageSize) : rows;
4658
+ const hasFilters = Boolean(fl) && columns.some((c) => c.filter);
4659
+ const height = spec.maxHeight ?? Math.max(120, (size2.height || 300) - (sr ? 48 : 0) - (pageSize ? 48 : 0));
4660
+ const windowed = spec.virtual && shown.length > 60;
4661
+ const first = windowed ? Math.max(0, Math.floor(scrollTop / ROW_H) - 10) : 0;
4662
+ const last = windowed ? Math.min(shown.length, first + Math.ceil(height / ROW_H) + 20) : shown.length;
4663
+ const busy = status === "loading" && base.length > 0;
4664
+ const filterChoices = (c) => c.filterOptions ?? [
4665
+ ...new Set(
4666
+ base.map((r) => field(r, c.key)).filter((v) => v !== null && v !== void 0 && v !== "").map(String)
4667
+ )
4668
+ ].sort();
4669
+ const cell = (c, row) => {
4670
+ const v = field(row, c.key);
4671
+ if (c.type === "badge") {
4672
+ const text = c.template ? tpl(c.template, row) : v === null || v === void 0 || v === "" ? "" : String(v);
4673
+ if (!text) return c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "";
4674
+ let t = c.map?.[String(v)] ?? "neutral";
4675
+ if (c.tone) {
4676
+ try {
4677
+ t = String(
4678
+ evaluate(c.tone, scope({ row, value: v }, helpers))
4679
+ );
4680
+ } catch {
4798
4681
  }
4799
- )
4682
+ }
4683
+ return /* @__PURE__ */ jsx20("span", { className: "ds-chip", "data-tone": t, children: text });
4800
4684
  }
4801
- );
4802
- }
4803
- const selected = options.selectedPanel === id;
4804
- const defaultSlot = widget?.slots ? Object.keys(widget.slots)[0] ?? "header" : "header";
4805
- const dropTarget = (target, x, y) => {
4806
- const own = `[data-slot][data-owner="${CSS.escape(id)}"]`;
4807
- const el = target?.closest(own) ?? frameRef.current?.querySelector(`${own}:not([data-slot="header"]):not([data-slot="footer"])`) ?? void 0;
4808
- const name = el?.getAttribute("data-slot") ?? defaultSlot;
4809
- return { slot: name, index: el ? indexIn(el, x, y) : void 0 };
4810
- };
4811
- return /* @__PURE__ */ jsx21(SlotOwnerContext.Provider, { value: { id, data: view.data, def }, children: /* @__PURE__ */ jsx21(SlotChildContext.Provider, { value: renderNested, children: /* @__PURE__ */ jsxs16(
4812
- "section",
4813
- {
4814
- ref: frameRef,
4815
- className: "ds-panel",
4816
- style: panelStyle(def.style),
4817
- "data-tone": tone2,
4818
- "data-panel": id,
4819
- "data-selected": selected || void 0,
4820
- "data-nested": nested || void 0,
4821
- "aria-label": title ?? id,
4822
- draggable: dnd && nested ? true : void 0,
4823
- onDragStart: dnd && nested ? (e) => {
4824
- e.stopPropagation();
4825
- e.dataTransfer.setData("text/plain", id);
4826
- e.dataTransfer.effectAllowed = "move";
4827
- options.onDragPanelStart?.(id);
4828
- } : void 0,
4829
- onDragOver: dnd ? (e) => {
4830
- const t = dropTarget(e.target, e.clientX, e.clientY);
4831
- if (!options.canDropOn?.(id, void 0, t.slot)) return;
4832
- e.preventDefault();
4833
- e.stopPropagation();
4834
- frameRef.current?.setAttribute("data-drop-over", t.slot);
4835
- } : void 0,
4836
- onDragLeave: dnd ? (e) => {
4837
- if (!frameRef.current?.contains(e.relatedTarget))
4838
- frameRef.current?.removeAttribute("data-drop-over");
4839
- } : void 0,
4840
- onDrop: dnd ? (e) => {
4841
- frameRef.current?.removeAttribute("data-drop-over");
4842
- const t = dropTarget(e.target, e.clientX, e.clientY);
4843
- if (!options.canDropOn?.(id, void 0, t.slot)) return;
4844
- e.preventDefault();
4845
- e.stopPropagation();
4846
- options.onDropOnPanel?.(id, t.index, void 0, t.slot);
4847
- } : void 0,
4848
- onPointerDownCapture: options.onPanelSelect ? (e) => {
4849
- const el = partAt(e.target, frameRef.current);
4850
- markPart(frameRef.current, el?.node);
4851
- options.onPanelSelect?.(id, el?.part);
4852
- } : void 0,
4853
- onClickCapture: options.onPanelSelect ? (e) => {
4854
- e.preventDefault();
4855
- e.stopPropagation();
4856
- } : void 0,
4857
- children: [
4858
- !hideHeader && /* @__PURE__ */ jsxs16("header", { className: "ds-panel-head", children: [
4859
- /* @__PURE__ */ jsxs16("div", { style: { minWidth: 0 }, children: [
4860
- title && /* @__PURE__ */ jsxs16("h3", { className: "ds-panel-title", children: [
4861
- title,
4862
- info && /* @__PURE__ */ jsx21(InfoTip, { text: info })
4863
- ] }),
4864
- drill.length > 0 && /* @__PURE__ */ jsxs16("nav", { className: "ds-crumbs", "aria-label": "Drill path", children: [
4865
- /* @__PURE__ */ jsx21("button", { type: "button", onClick: () => runtime.runAction({ do: "drillReset", panel: id }), children: "All" }),
4866
- drill.map((d, i) => /* @__PURE__ */ jsxs16("span", { children: [
4867
- "\u203A",
4868
- " ",
4869
- i < drill.length - 1 ? /* @__PURE__ */ jsx21(
4870
- "button",
4685
+ if (c.template) return tpl(c.template, row) || (c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "");
4686
+ if (c.list !== void 0) {
4687
+ const items = Array.isArray(v) ? v : [];
4688
+ if (items.length === 0) return c.empty ?? "";
4689
+ return /* @__PURE__ */ jsx20("span", { className: "ds-cell-list", children: items.map((it, i) => (
4690
+ // biome-ignore lint/suspicious/noArrayIndexKey: list items have no id and never reorder within a render
4691
+ /* @__PURE__ */ jsx20("span", { children: tpl(c.list, row, it) }, i)
4692
+ )) });
4693
+ }
4694
+ if (v === null || v === void 0 || v === "")
4695
+ return c.empty ? /* @__PURE__ */ jsx20("span", { className: "ds-cell-empty", children: c.empty }) : "";
4696
+ switch (c.type) {
4697
+ case "link": {
4698
+ const href = safeLink(c.href ? tpl(c.href, row) : String(v));
4699
+ return href ? /* @__PURE__ */ jsx20("a", { className: "ds-link", href, onClick: (e) => e.stopPropagation(), children: String(v) }) : String(v);
4700
+ }
4701
+ case "image":
4702
+ return safeImageSrc(v) ? /* @__PURE__ */ jsx20("img", { src: v, alt: "", style: { height: 28, borderRadius: 4 } }) : null;
4703
+ case "progress": {
4704
+ const n = toNumber(v) ?? 0;
4705
+ const pct = Math.min(100, n / (c.max ?? 100) * 100);
4706
+ return /* @__PURE__ */ jsxs15("span", { className: "ds-inline", children: [
4707
+ /* @__PURE__ */ jsx20("span", { className: "ds-progress", style: { flex: 1, minWidth: 40 }, children: /* @__PURE__ */ jsx20("span", { style: { width: `${pct}%`, background: "var(--ds-series-1)" } }) }),
4708
+ formatValue(n, helpers, c.format, c.decimals),
4709
+ c.suffix
4710
+ ] });
4711
+ }
4712
+ case "sparkline":
4713
+ return /* @__PURE__ */ jsx20(
4714
+ SparkSvg,
4715
+ {
4716
+ values: (Array.isArray(v) ? v : []).map(
4717
+ (x) => toNumber(typeof x === "object" ? field(x, "value") : x) ?? 0
4718
+ ),
4719
+ height: 24,
4720
+ area: false
4721
+ }
4722
+ );
4723
+ default:
4724
+ return `${c.prefix ?? ""}${typeof v === "number" || c.format ? formatValue(v, helpers, c.format, c.decimals) : String(v)}${c.suffix ?? ""}`;
4725
+ }
4726
+ };
4727
+ const total = (c) => {
4728
+ const how = spec.totals?.columns[c.key];
4729
+ if (!how) return null;
4730
+ const nums = rows.map((r) => toNumber(field(r, c.key))).filter((n) => n !== void 0);
4731
+ if (how !== "count" && nums.length === 0) return "";
4732
+ 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));
4733
+ return `${c.prefix ?? ""}${formatValue(v, helpers, c.format === "date" ? "number" : c.format, c.decimals)}${c.suffix ?? ""}`;
4734
+ };
4735
+ const muted = (row) => {
4736
+ if (!spec.rowMutedWhen) return false;
4737
+ try {
4738
+ return Boolean(evaluate(spec.rowMutedWhen, scope({ row }, helpers)));
4739
+ } catch {
4740
+ return false;
4741
+ }
4742
+ };
4743
+ const align = (c) => c.align ?? (c.type === "number" || c.format && c.format !== "date" && c.format !== "text" ? "right" : "left");
4744
+ return /* @__PURE__ */ jsxs15("div", { className: "ds-table-wrap", "data-density": spec.density, children: [
4745
+ sr && /* @__PURE__ */ jsxs15("div", { className: "ds-table-tools", children: [
4746
+ /* @__PURE__ */ jsxs15("label", { className: "ds-search", children: [
4747
+ /* @__PURE__ */ jsxs15("svg", { viewBox: "0 0 16 16", width: "15", height: "15", "aria-hidden": "true", children: [
4748
+ /* @__PURE__ */ jsx20("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.5" }),
4749
+ /* @__PURE__ */ jsx20("path", { d: "m10.5 10.5 3 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
4750
+ ] }),
4751
+ /* @__PURE__ */ jsx20(
4752
+ "input",
4753
+ {
4754
+ type: "search",
4755
+ "aria-label": "Search table",
4756
+ placeholder: "placeholder" in sr && sr.placeholder || "Search",
4757
+ value: searchText,
4758
+ onChange: (e) => {
4759
+ const v = e.target.value;
4760
+ setSearchText(v);
4761
+ clearTimeout(searchTimer.current);
4762
+ searchTimer.current = setTimeout(() => update({ search: v, page: 1 }), server.search ? 350 : 120);
4763
+ }
4764
+ }
4765
+ )
4766
+ ] }),
4767
+ /* @__PURE__ */ jsxs15("span", { className: "ds-table-count", children: [
4768
+ helpers.fmt.number(rowTotal),
4769
+ " rows"
4770
+ ] })
4771
+ ] }),
4772
+ /* @__PURE__ */ jsxs15(
4773
+ "div",
4774
+ {
4775
+ className: "ds-table-scroll",
4776
+ "data-max": spec.maxHeight !== void 0 || void 0,
4777
+ ref: scroller,
4778
+ style: { maxHeight: height },
4779
+ onScroll: windowed ? (e) => setScrollTop(e.currentTarget.scrollTop) : void 0,
4780
+ children: [
4781
+ busy && /* @__PURE__ */ jsx20("div", { className: "ds-table-busy", "aria-hidden": "true" }),
4782
+ /* @__PURE__ */ jsxs15("table", { className: "ds-table", "aria-busy": busy || void 0, children: [
4783
+ /* @__PURE__ */ jsxs15("thead", { "data-sticky": spec.sticky || void 0, children: [
4784
+ /* @__PURE__ */ jsx20("tr", { children: columns.map((c, i) => {
4785
+ const sorted = sort?.key === c.key ? sort.order : void 0;
4786
+ return /* @__PURE__ */ jsx20(
4787
+ "th",
4788
+ {
4789
+ "data-ds-part": `column:${i}`,
4790
+ style: { textAlign: align(c), width: c.width },
4791
+ "aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
4792
+ children: so.enabled === false || c.sortable === false || c.list !== void 0 ? c.label ?? c.key : /* @__PURE__ */ jsxs15(
4793
+ "button",
4794
+ {
4795
+ type: "button",
4796
+ onClick: () => update(
4797
+ sorted === "asc" ? { sortKey: c.key, sortOrder: "desc", page: 1 } : sorted === "desc" ? { sortKey: void 0, page: 1 } : { sortKey: c.key, sortOrder: "asc", page: 1 }
4798
+ ),
4799
+ children: [
4800
+ c.label ?? c.key,
4801
+ /* @__PURE__ */ jsx20("span", { className: "ds-sort", "data-dir": sorted, "aria-hidden": "true" })
4802
+ ]
4803
+ }
4804
+ )
4805
+ },
4806
+ `${c.key}-${i}`
4807
+ );
4808
+ }) }),
4809
+ hasFilters && /* @__PURE__ */ jsx20("tr", { className: "ds-filter-row", children: columns.map((c, i) => /* @__PURE__ */ jsx20("th", { children: c.filter === "select" ? /* @__PURE__ */ jsx20(
4810
+ SelectControl,
4871
4811
  {
4872
- type: "button",
4873
- onClick: () => runtime.store.dispatch(
4874
- stateActions.patchPanel({ id, patch: { drill: drill.slice(0, i + 1) } })
4875
- ),
4876
- children: String(d.value)
4812
+ size: "sm",
4813
+ block: true,
4814
+ plain: true,
4815
+ ariaLabel: `Filter ${c.label ?? c.key}`,
4816
+ options: [
4817
+ { value: "", label: "All" },
4818
+ ...filterChoices(c).map((o) => ({ value: o, label: o }))
4819
+ ],
4820
+ value: view.filters[c.key] ?? "",
4821
+ onChange: (v) => update({ filters: { ...view.filters, [c.key]: String(v ?? "") }, page: 1 })
4877
4822
  }
4878
- ) : String(d.value)
4879
- ] }, `${d.level}-${i}`))
4823
+ ) : c.filter ? /* @__PURE__ */ jsx20(
4824
+ "input",
4825
+ {
4826
+ className: "ds-cell-filter",
4827
+ type: c.filter === "min" ? "number" : "text",
4828
+ placeholder: c.filter === "min" ? "Min" : "Filter",
4829
+ "aria-label": `Filter ${c.label ?? c.key}`,
4830
+ value: view.filters[c.key] ?? "",
4831
+ onChange: (e) => update({ filters: { ...view.filters, [c.key]: e.target.value }, page: 1 })
4832
+ }
4833
+ ) : null }, `f-${c.key}-${i}`)) })
4834
+ ] }),
4835
+ /* @__PURE__ */ jsxs15("tbody", { children: [
4836
+ windowed && first > 0 && /* @__PURE__ */ jsx20("tr", { className: "ds-spacer", children: /* @__PURE__ */ jsx20("td", { colSpan: columns.length, style: { height: first * ROW_H, padding: 0 } }) }),
4837
+ shown.slice(first, last).map((row, k) => {
4838
+ const i = first + k;
4839
+ const key = spec.rowKey ? String(field(row, spec.rowKey)) : String(i);
4840
+ return /* @__PURE__ */ jsx20(
4841
+ "tr",
4842
+ {
4843
+ "data-muted": muted(row) || void 0,
4844
+ onClick: () => emit("rowClick", "row", { datum: row, index: i }),
4845
+ onMouseEnter: () => emit("hover", "row", { datum: row, index: i }),
4846
+ tabIndex: 0,
4847
+ onKeyDown: (e) => e.key === "Enter" && emit("rowClick", "row", { datum: row, index: i }),
4848
+ children: columns.map((c, j) => (
4849
+ // biome-ignore lint/a11y/useKeyWithClickEvents: rows are focusable and open with Enter; cell clicks add detail for pointer users
4850
+ /* @__PURE__ */ jsx20(
4851
+ "td",
4852
+ {
4853
+ style: { textAlign: align(c) },
4854
+ onClick: () => emit("cellClick", "cell", { datum: row, index: i, value: field(row, c.key), column: c.key }),
4855
+ children: cell(c, row)
4856
+ },
4857
+ `${c.key}-${j}`
4858
+ )
4859
+ ))
4860
+ },
4861
+ key
4862
+ );
4863
+ }),
4864
+ 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 } }) })
4865
+ ] }),
4866
+ 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}`)) }) })
4880
4867
  ] })
4881
- ] }),
4882
- /* @__PURE__ */ jsxs16("div", { className: "ds-panel-tools", children: [
4883
- headerKids.length > 0 && /* @__PURE__ */ jsx21(Slot, { name: "header", className: "ds-panel-addons" }),
4884
- meta2 && /* @__PURE__ */ jsx21("span", { className: "ds-panel-meta", children: meta2 }),
4885
- live2 ? /* @__PURE__ */ jsxs16("span", { className: "ds-live", "data-stale": view.stale || void 0, title: view.error?.message, children: [
4886
- /* @__PURE__ */ jsx21("span", { "aria-hidden": "true" }),
4887
- "Live, updated ",
4888
- view.updatedAt ? runtime.helpers.fmt.ago(view.updatedAt) : "\u2026"
4889
- ] }) : view.stale && /* @__PURE__ */ jsx21("span", { className: "ds-badge ds-badge-stale", title: view.error?.message, children: "Stale" }),
4890
- controls.map((c) => /* @__PURE__ */ jsx21(
4891
- ControlField,
4868
+ ]
4869
+ }
4870
+ ),
4871
+ pageSize && /* @__PURE__ */ jsxs15("div", { className: "ds-pager", children: [
4872
+ /* @__PURE__ */ jsxs15("span", { className: "ds-pager-size", children: [
4873
+ "Rows",
4874
+ /* @__PURE__ */ jsx20(
4875
+ SelectControl,
4876
+ {
4877
+ size: "sm",
4878
+ plain: true,
4879
+ ariaLabel: "Rows per page",
4880
+ options: (pg?.pageSizes ?? [10, 20, 50, 100]).map((n) => ({ value: n, label: String(n) })),
4881
+ value: pageSize,
4882
+ onChange: (v) => update({ pageSize: Number(v), page: 1 })
4883
+ }
4884
+ )
4885
+ ] }),
4886
+ /* @__PURE__ */ jsxs15("span", { children: [
4887
+ rowTotal === 0 ? 0 : (current - 1) * pageSize + 1,
4888
+ "\u2013",
4889
+ Math.min(current * pageSize, rowTotal),
4890
+ " of",
4891
+ " ",
4892
+ helpers.fmt.number(rowTotal)
4893
+ ] }),
4894
+ /* @__PURE__ */ jsxs15("span", { className: "ds-pages", children: [
4895
+ /* @__PURE__ */ jsx20(
4896
+ "button",
4897
+ {
4898
+ type: "button",
4899
+ "aria-label": "Previous page",
4900
+ disabled: current <= 1,
4901
+ onClick: () => update({ page: current - 1 }),
4902
+ children: "\u2039"
4903
+ }
4904
+ ),
4905
+ pageList(current, pages).map(
4906
+ (n, i) => n === 0 ? /* @__PURE__ */ jsx20("span", { className: "ds-page-gap", children: "\u2026" }, `gap-${i < 3 ? "a" : "b"}`) : /* @__PURE__ */ jsx20(
4907
+ "button",
4892
4908
  {
4893
- def: c,
4894
- compact: true,
4895
- value: view.panel.controls?.[c.name],
4896
- onChange: (v) => runtime.store.dispatch(
4897
- stateActions.patchPanel({
4898
- id,
4899
- patch: { controls: { ...view.panel.controls, [c.name]: v } }
4900
- })
4901
- )
4909
+ type: "button",
4910
+ "aria-current": n === current ? "page" : void 0,
4911
+ onClick: () => update({ page: n }),
4912
+ children: n
4902
4913
  },
4903
- c.name
4904
- ))
4905
- ] })
4906
- ] }),
4907
- /* @__PURE__ */ jsx21("div", { className: "ds-panel-body", ref: bodyRef, children: body }),
4908
- footerKids.length > 0 && /* @__PURE__ */ jsx21(Slot, { name: "footer", className: "ds-panel-foot" })
4909
- ]
4910
- }
4911
- ) }) });
4912
- }
4913
- function loadingText(messages) {
4914
- const v = messages?.loading;
4915
- return v === void 0 || v === null || v === "" ? void 0 : String(v);
4916
- }
4917
- function LoadingState({ text }) {
4918
- if (!text) return /* @__PURE__ */ jsx21("div", { className: "ds-skeleton", "aria-busy": "true", "aria-label": "Loading" });
4919
- return /* @__PURE__ */ jsxs16("output", { className: "ds-loading", "aria-busy": "true", children: [
4920
- /* @__PURE__ */ jsx21("div", { className: "ds-skeleton", "aria-hidden": "true" }),
4921
- /* @__PURE__ */ jsx21("span", { className: "ds-loading-text", children: text })
4922
- ] });
4923
- }
4914
+ n
4915
+ )
4916
+ ),
4917
+ /* @__PURE__ */ jsx20(
4918
+ "button",
4919
+ {
4920
+ type: "button",
4921
+ "aria-label": "Next page",
4922
+ disabled: current >= pages,
4923
+ onClick: () => update({ page: current + 1 }),
4924
+ children: "\u203A"
4925
+ }
4926
+ )
4927
+ ] })
4928
+ ] })
4929
+ ] });
4930
+ }
4931
+ });
4924
4932
 
4925
- // src/widgets/shared/clickable.ts
4926
- function useClickable(panelId, activate) {
4927
- const ctx = useContext4(DashboardContext);
4928
- const def = ctx && panelId ? findPanel(ctx.runtime.doc, panelId) : void 0;
4929
- const on = def?.on;
4930
- if (on?.click === void 0) return { onClick: activate };
4931
- return {
4932
- onClick: activate,
4933
- role: "button",
4934
- tabIndex: 0,
4935
- onKeyDown: (e) => {
4936
- if (e.key !== "Enter" && e.key !== " ") return;
4937
- e.preventDefault();
4938
- activate();
4939
- }
4940
- };
4933
+ // src/widgets/builtins/Tiles.tsx
4934
+ import "zod";
4935
+ import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
4936
+ var Tiles = defineWidget({
4937
+ ...TilesContract,
4938
+ implements: "tiles",
4939
+ exposes: { selection: "the clicked tile's row" },
4940
+ meta: { label: "Tiles", icon: "tiles", category: "Numbers", size: { w: 12, h: 4, minW: 3, minH: 3 } },
4941
+ events: ["click", "hover", "select"],
4942
+ parts: ["tile"],
4943
+ defaults: { label: "name", value: "value" },
4944
+ component: function TilesWidget({ spec, data, emit, helpers }) {
4945
+ const rows = asRows(data);
4946
+ const caption = (row) => {
4947
+ if (!spec.caption) return void 0;
4948
+ try {
4949
+ return String(interpolate(spec.caption, scope({ row }, helpers)) ?? "");
4950
+ } catch {
4951
+ return spec.caption;
4952
+ }
4953
+ };
4954
+ return /* @__PURE__ */ jsx21(
4955
+ "div",
4956
+ {
4957
+ className: "ds-tiles",
4958
+ role: spec.selectable ? "radiogroup" : "list",
4959
+ "aria-label": spec.title,
4960
+ "data-wrap": spec.wrap === false ? "off" : void 0,
4961
+ style: {
4962
+ "--ds-tile-min": `${spec.minTileWidth ?? 128}px`,
4963
+ ...spec.columns ? { "--ds-tile-cols": spec.columns } : {}
4964
+ },
4965
+ children: rows.map((r, i) => {
4966
+ const label = field(r, spec.label);
4967
+ const v = field(r, spec.value);
4968
+ const n = toNumber(v);
4969
+ const status = spec.status ? String(field(r, spec.status)) : void 0;
4970
+ const st = status ? spec.statusMap?.[status] ?? status : void 0;
4971
+ const vt = n === void 0 || !spec.valueTone ? void 0 : n > 0 ? spec.valueTone.positive : n < 0 ? spec.valueTone.negative : spec.valueTone.zero;
4972
+ const active = spec.selectable && spec.selected !== void 0 && spec.selected === label;
4973
+ return /* @__PURE__ */ jsxs16(
4974
+ "button",
4975
+ {
4976
+ type: "button",
4977
+ className: "ds-tile",
4978
+ role: spec.selectable ? "radio" : "listitem",
4979
+ "aria-checked": spec.selectable ? active : void 0,
4980
+ "data-active": active || void 0,
4981
+ onClick: () => {
4982
+ emit("click", "tile", { datum: r, value: label, index: i });
4983
+ if (spec.selectable) emit("select", "tile", { datum: r, value: label, index: i });
4984
+ },
4985
+ onMouseEnter: () => emit("hover", "tile", { datum: r, value: label, index: i }),
4986
+ children: [
4987
+ /* @__PURE__ */ jsxs16("span", { className: "ds-tile-label", children: [
4988
+ st && /* @__PURE__ */ jsx21("span", { className: "ds-dot", style: { background: tone(st).solid }, "aria-hidden": "true" }),
4989
+ String(label ?? ""),
4990
+ spec.count && /* @__PURE__ */ jsx21("span", { className: "ds-chip-count", children: String(field(r, spec.count) ?? "") })
4991
+ ] }),
4992
+ /* @__PURE__ */ jsxs16(
4993
+ "span",
4994
+ {
4995
+ className: "ds-tile-value",
4996
+ style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
4997
+ children: [
4998
+ /* @__PURE__ */ jsx21(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
4999
+ spec.unit && /* @__PURE__ */ jsx21("span", { className: "ds-kpi-unit", children: spec.unit })
5000
+ ]
5001
+ }
5002
+ ),
5003
+ spec.caption && /* @__PURE__ */ jsx21("span", { className: "ds-tile-caption", children: caption(r) })
5004
+ ]
5005
+ },
5006
+ `${String(label)}-${i}`
5007
+ );
5008
+ })
5009
+ }
5010
+ );
5011
+ }
5012
+ });
5013
+ function CountUp({ value, render }) {
5014
+ const n = toNumber(value);
5015
+ const shown = useCountUp(n ?? value);
5016
+ return /* @__PURE__ */ jsx21(Fragment6, { children: render(n === void 0 ? value : shown) });
4941
5017
  }
4942
5018
 
4943
5019
  // src/widgets/builtins/atoms.tsx
5020
+ import "zod";
4944
5021
  import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
4945
5022
  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;
4946
5023
  var boundValue = (data, path) => {
@@ -5079,7 +5156,7 @@ import {
5079
5156
  } from "echarts/components";
5080
5157
  import * as echarts from "echarts/core";
5081
5158
  import { CanvasRenderer } from "echarts/renderers";
5082
- import { useEffect as useEffect6, useMemo as useMemo5, useRef as useRef7 } from "react";
5159
+ import { useEffect as useEffect6, useMemo as useMemo5, useRef as useRef8 } from "react";
5083
5160
 
5084
5161
  // src/theme/echartsTheme.ts
5085
5162
  function echartsTheme(theme, mode) {
@@ -5153,11 +5230,11 @@ function EChart({
5153
5230
  height,
5154
5231
  ariaLabel
5155
5232
  }) {
5156
- const el = useRef7(null);
5157
- const chart = useRef7(null);
5233
+ const el = useRef8(null);
5234
+ const chart = useRef8(null);
5158
5235
  const tokens = useThemeTokens();
5159
5236
  const theme = useMemo5(() => tokens ? echartsTheme(tokens.theme, tokens.mode) : void 0, [tokens]);
5160
- const handlers = useRef7({ emit, rows });
5237
+ const handlers = useRef8({ emit, rows });
5161
5238
  handlers.current = { emit, rows };
5162
5239
  useEffect6(() => {
5163
5240
  if (!el.current) return;
@@ -5840,7 +5917,7 @@ var builtInWidgets = [
5840
5917
  ];
5841
5918
 
5842
5919
  // src/components/Grid.tsx
5843
- import { useEffect as useEffect7, useMemo as useMemo7, useRef as useRef8, useState as useState6 } from "react";
5920
+ import { useEffect as useEffect7, useMemo as useMemo7, useRef as useRef9, useState as useState7 } from "react";
5844
5921
  import { Responsive, WidthProvider } from "react-grid-layout";
5845
5922
  import { jsx as jsx26 } from "react/jsx-runtime";
5846
5923
  var ResponsiveGrid = WidthProvider(Responsive);
@@ -5876,7 +5953,8 @@ function layoutsForView(layouts, view, columns) {
5876
5953
  } else out[bp] = desktop.map((i) => ({ i: i.panel, x: i.x, y: i.y, w: i.w, h: i.h }));
5877
5954
  }
5878
5955
  const panels = [...new Set(desktop.map((i) => i.panel))];
5879
- return { layouts: out, cols, panels, modes, ordered: ordered.map((i) => ({ panel: i.panel, h: i.h })) };
5956
+ const fit = new Set(forView.flatMap((l) => (l.items ?? []).filter((i) => i.fit).map((i) => i.panel)));
5957
+ return { layouts: out, cols, panels, modes, fit, ordered: ordered.map((i) => ({ panel: i.panel, h: i.h })) };
5880
5958
  }
5881
5959
  var toItems = (l) => l.filter((i) => i.i !== "__drop__").map((i) => ({ panel: i.i, x: i.x, y: i.y, w: i.w, h: i.h }));
5882
5960
  function Grid({
@@ -5895,9 +5973,9 @@ function Grid({
5895
5973
  flowStyle,
5896
5974
  dragOnto
5897
5975
  }) {
5898
- const bpRef = useRef8("desktop");
5899
- const [wrapEl, setWrapEl] = useState6(null);
5900
- const [measured, setMeasured] = useState6("desktop");
5976
+ const bpRef = useRef9("desktop");
5977
+ const [wrapEl, setWrapEl] = useState7(null);
5978
+ const [measured, setMeasured] = useState7("desktop");
5901
5979
  useEffect7(() => {
5902
5980
  if (!wrapEl || typeof ResizeObserver === "undefined") return;
5903
5981
  const ro = new ResizeObserver(([e]) => {
@@ -5920,6 +5998,51 @@ function Grid({
5920
5998
  cols: base.cols
5921
5999
  };
5922
6000
  }, [base, hidden, editable]);
6001
+ const [fitRows, setFitRows] = useState7({});
6002
+ const fitted = useMemo7(() => {
6003
+ if (editable || base.fit.size === 0) return rgl;
6004
+ return Object.fromEntries(
6005
+ Object.entries(rgl).map(([bp, l]) => [
6006
+ bp,
6007
+ (() => {
6008
+ const rowWant = /* @__PURE__ */ new Map();
6009
+ for (const i of l ?? []) {
6010
+ const want = base.fit.has(i.i) ? fitRows[i.i] : void 0;
6011
+ if (want) rowWant.set(i.y, Math.max(rowWant.get(i.y) ?? 0, want));
6012
+ }
6013
+ return (l ?? []).map((i) => {
6014
+ const want = base.fit.has(i.i) ? rowWant.get(i.y) : void 0;
6015
+ return want && want > i.h ? { ...i, h: want } : i;
6016
+ });
6017
+ })()
6018
+ ])
6019
+ );
6020
+ }, [rgl, base.fit, fitRows, editable]);
6021
+ const observeFit = (panel) => (el) => {
6022
+ const prev = fitObservers.current.get(panel);
6023
+ if (prev) {
6024
+ prev.disconnect();
6025
+ fitObservers.current.delete(panel);
6026
+ }
6027
+ if (!el || editable || !base.fit.has(panel) || typeof ResizeObserver === "undefined") return;
6028
+ const ro = new ResizeObserver(() => {
6029
+ const target2 = el.firstElementChild;
6030
+ const px = target2?.offsetHeight ?? 0;
6031
+ if (!px) return;
6032
+ const rows = Math.ceil((px + gap) / (rowHeight + gap));
6033
+ setFitRows((r) => r[panel] === rows ? r : { ...r, [panel]: rows });
6034
+ });
6035
+ const target = el.firstElementChild;
6036
+ if (target) ro.observe(target);
6037
+ fitObservers.current.set(panel, ro);
6038
+ };
6039
+ const fitObservers = useRef9(/* @__PURE__ */ new Map());
6040
+ useEffect7(() => {
6041
+ const observers = fitObservers.current;
6042
+ return () => {
6043
+ for (const ro of observers.values()) ro.disconnect();
6044
+ };
6045
+ }, []);
5923
6046
  const active = breakpoint ?? measured;
5924
6047
  if (base.modes[active] === "flow") {
5925
6048
  const hide = editable ? void 0 : hidden;
@@ -5941,7 +6064,7 @@ function Grid({
5941
6064
  ResponsiveGrid,
5942
6065
  {
5943
6066
  className: editable ? "ds-grid ds-grid-edit" : "ds-grid",
5944
- layouts: breakpoint ? { [breakpoint]: rgl[breakpoint] ?? [] } : rgl,
6067
+ layouts: breakpoint ? { [breakpoint]: rgl[breakpoint] ?? [] } : fitted,
5945
6068
  breakpoints: breakpoint ? { [breakpoint]: 0 } : BREAKPOINT_MIN,
5946
6069
  cols: breakpoint ? { [breakpoint]: cols[breakpoint] } : cols,
5947
6070
  rowHeight,
@@ -5975,13 +6098,16 @@ function Grid({
5975
6098
  onLayoutChange?.(toItems(current), breakpoint ?? bpRef.current);
5976
6099
  },
5977
6100
  onResizeStop: (current) => editable && onLayoutChange?.(toItems(current), breakpoint ?? bpRef.current),
5978
- children: panels.map((p, i) => /* @__PURE__ */ jsx26("div", { style: { ["--ds-i"]: i }, children: children(p) }, p))
6101
+ children: panels.map((p, i) => /* @__PURE__ */ jsx26("div", { "data-fit": base.fit.has(p) && !editable ? "" : void 0, style: { ["--ds-i"]: i }, children: base.fit.has(p) && !editable ? (
6102
+ // react-grid-layout replaces the ref of its own children, so the measuring ref sits one level down.
6103
+ /* @__PURE__ */ jsx26("div", { className: "ds-fit", ref: observeFit(p), children: children(p) })
6104
+ ) : children(p) }, p))
5979
6105
  }
5980
6106
  ) });
5981
6107
  }
5982
6108
 
5983
6109
  // src/components/ModalHost.tsx
5984
- import { useCallback as useCallback5, useEffect as useEffect8, useRef as useRef9 } from "react";
6110
+ import { useCallback as useCallback5, useEffect as useEffect8, useRef as useRef10 } from "react";
5985
6111
  import { jsx as jsx27, jsxs as jsxs20 } from "react/jsx-runtime";
5986
6112
  var WIDTH = { sm: "420px", md: "720px", lg: "1040px", xl: "1320px", full: "100%" };
5987
6113
  var FOCUSABLE2 = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
@@ -6007,7 +6133,7 @@ function ModalHost() {
6007
6133
  ),
6008
6134
  Object.is
6009
6135
  );
6010
- const latched = useRef9(/* @__PURE__ */ new Set());
6136
+ const latched = useRef10(/* @__PURE__ */ new Set());
6011
6137
  useEffect8(() => {
6012
6138
  const now = new Set(byExpression ? byExpression.split("\0") : []);
6013
6139
  for (const id of [...latched.current])
@@ -6029,8 +6155,8 @@ function ModalHost() {
6029
6155
  return "";
6030
6156
  }
6031
6157
  }
6032
- const dialog = useRef9(null);
6033
- const scrim = useRef9(null);
6158
+ const dialog = useRef10(null);
6159
+ const scrim = useRef10(null);
6034
6160
  const openId = open?.id;
6035
6161
  const close = useCallback5(() => {
6036
6162
  if (!openId) return;
@@ -6039,7 +6165,7 @@ function ModalHost() {
6039
6165
  if (on?.close) void runtime.runAction({ do: "sequence", steps: on.close });
6040
6166
  runtime.store.dispatch(stateActions.closeModal());
6041
6167
  }, [openId, runtime, modals]);
6042
- const closeRef = useRef9(close);
6168
+ const closeRef = useRef10(close);
6043
6169
  closeRef.current = close;
6044
6170
  useEffect8(() => {
6045
6171
  if (!openId) return;
@@ -6125,12 +6251,12 @@ function ModalHost() {
6125
6251
  }
6126
6252
 
6127
6253
  // src/components/Provider.tsx
6128
- import { createContext as createContext4, useContext as useContext5, useRef as useRef10 } from "react";
6254
+ import { createContext as createContext4, useContext as useContext5, useRef as useRef11 } from "react";
6129
6255
  import { jsx as jsx28 } from "react/jsx-runtime";
6130
6256
  var SettingsContext = createContext4({});
6131
6257
  function DashSpecProvider({ children, ...settings }) {
6132
6258
  const outer = useContext5(SettingsContext);
6133
- const last = useRef10(
6259
+ const last = useRef11(
6134
6260
  void 0
6135
6261
  );
6136
6262
  if (!last.current || last.current.outer !== outer || !shallowEqual2(last.current.settings, settings))
@@ -6173,9 +6299,9 @@ function pickTheme(name, themes, fallback) {
6173
6299
  }
6174
6300
 
6175
6301
  // src/components/Tour.tsx
6176
- import { useCallback as useCallback6, useEffect as useEffect9, useId as useId4, useLayoutEffect as useLayoutEffect2, useRef as useRef11, useState as useState7 } from "react";
6302
+ import { useCallback as useCallback6, useEffect as useEffect9, useId as useId4, useLayoutEffect as useLayoutEffect3, useRef as useRef12, useState as useState8 } from "react";
6177
6303
  import { Fragment as Fragment9, jsx as jsx29, jsxs as jsxs21 } from "react/jsx-runtime";
6178
- var useClientLayoutEffect = typeof window === "undefined" ? useEffect9 : useLayoutEffect2;
6304
+ var useClientLayoutEffect = typeof window === "undefined" ? useEffect9 : useLayoutEffect3;
6179
6305
  function panelElement(root, id) {
6180
6306
  if (!root || !id) return null;
6181
6307
  for (const el of root.querySelectorAll("[data-panel]"))
@@ -6184,11 +6310,11 @@ function panelElement(root, id) {
6184
6310
  }
6185
6311
  function TourButton({ steps }) {
6186
6312
  const { runtime } = useDashboard();
6187
- const [at, setAt] = useState7(null);
6188
- const button = useRef11(null);
6189
- const dialog = useRef11(null);
6190
- const next = useRef11(null);
6191
- const [pos, setPos] = useState7(null);
6313
+ const [at, setAt] = useState8(null);
6314
+ const button = useRef12(null);
6315
+ const dialog = useRef12(null);
6316
+ const next = useRef12(null);
6317
+ const [pos, setPos] = useState8(null);
6192
6318
  const titleId = useId4();
6193
6319
  const textId = useId4();
6194
6320
  const step = at === null ? void 0 : steps[at];
@@ -6313,7 +6439,7 @@ function TourButton({ steps }) {
6313
6439
  }
6314
6440
 
6315
6441
  // src/components/registryHooks.ts
6316
- import { useCallback as useCallback7, useEffect as useEffect10, useRef as useRef12, useState as useState8, useSyncExternalStore as useSyncExternalStore3 } from "react";
6442
+ import { useCallback as useCallback7, useEffect as useEffect10, useRef as useRef13, useState as useState9, useSyncExternalStore as useSyncExternalStore3 } from "react";
6317
6443
  var live = /* @__PURE__ */ new Map();
6318
6444
  var listeners = /* @__PURE__ */ new Set();
6319
6445
  var notify = () => {
@@ -6341,8 +6467,8 @@ function useRuntimeById(id) {
6341
6467
  }
6342
6468
  function useDashboardState(id, select) {
6343
6469
  const rt = useRuntimeById(id);
6344
- const [value, setValue] = useState8(() => rt ? select(rt.getTree()) : void 0);
6345
- const sel = useRef12(select);
6470
+ const [value, setValue] = useState9(() => rt ? select(rt.getTree()) : void 0);
6471
+ const sel = useRef13(select);
6346
6472
  sel.current = select;
6347
6473
  useEffect10(() => {
6348
6474
  if (!rt) return setValue(void 0);
@@ -6529,10 +6655,11 @@ var RENDERER_CSS = `
6529
6655
  .ds-live[data-stale] > span { background: var(--ds-color-status-warn-fg); }
6530
6656
  .ds-info { position: relative; display: inline-flex; color: var(--ds-color-text-disabled); cursor: help; outline: none; background: none; border: 0; padding: 0; font: inherit; }
6531
6657
  .ds-info:hover, .ds-info:focus-visible { color: var(--ds-color-text-subtle); }
6532
- .ds-info::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%); width: max-content; max-width: 260px; white-space: normal; padding: 8px 10px; border-radius: var(--ds-radius-control); background: var(--ds-color-chart-tooltip-bg); color: var(--ds-color-chart-tooltip-text); font: 400 12px/16px var(--ds-font-body); letter-spacing: 0; text-transform: none; opacity: 0; pointer-events: none; transition: opacity 120ms; z-index: var(--ds-z-tooltip); }
6533
- .ds-info:hover::after, .ds-info:focus-visible::after { opacity: 1; }
6658
+ .ds-tip { position: fixed; z-index: var(--ds-z-tooltip); width: max-content; max-width: 320px; padding: var(--ds-space-sm) var(--ds-space-md); border-radius: var(--ds-radius-control); background: var(--ds-color-chart-tooltip-bg); color: var(--ds-color-chart-tooltip-text); font: 500 var(--ds-type-caption-size)/1.5 var(--ds-font-body); text-align: left; white-space: normal; pointer-events: none; animation: ds-fade 120ms ease both; }
6659
+ .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); }
6660
+ .ds-tip[data-below]::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--ds-color-chart-tooltip-bg); }
6534
6661
 
6535
- .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); }
6662
+ .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); }
6536
6663
  .ds-chip[data-tone="good"] { background: var(--ds-color-status-good-bg); color: var(--ds-color-status-good-fg); }
6537
6664
  .ds-chip[data-tone="bad"] { background: var(--ds-color-status-bad-bg); color: var(--ds-color-status-bad-fg); }
6538
6665
  .ds-chip[data-tone="warn"] { background: var(--ds-color-status-warn-bg); color: var(--ds-color-status-warn-fg); }
@@ -6552,6 +6679,16 @@ var RENDERER_CSS = `
6552
6679
  .ds-tiles { overflow-y: auto; scrollbar-width: thin; grid-auto-rows: max-content; padding: 5px; margin: -5px; }
6553
6680
  .ds-tiles > .ds-tile { min-height: max-content; }
6554
6681
  .ds-flow .ds-tiles { height: auto; overflow-y: visible; }
6682
+ /* Grid items with fit: the panel takes its natural height (at least the cell's), so the grid can measure it. */
6683
+ [data-fit] > .ds-fit { height: 100%; }
6684
+ .ds-fit > .ds-panel { height: auto !important; min-height: 100%; }
6685
+ /* The body still fills a taller card, so footers (a KPI's target chip) stay at the bottom. */
6686
+ [data-fit] .ds-panel-body { flex: 1 0 auto; display: flex; flex-direction: column; }
6687
+ [data-fit] .ds-panel-body > * { flex: 1 0 auto; }
6688
+ [data-fit] .ds-tiles, [data-fit] .ds-table-wrap { height: auto; max-height: none; overflow-y: visible; }
6689
+ /* In a fit card the rows set the height, unless the table has its own maxHeight. */
6690
+ [data-fit] .ds-table-scroll { flex: none; }
6691
+ [data-fit] .ds-table-scroll:not([data-max]) { max-height: none !important; overflow-y: visible; }
6555
6692
  .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; }
6556
6693
  .ds-tiles[data-wrap="off"] > * { scroll-snap-align: start; }
6557
6694
  .ds-tile { min-width: 0; overflow-wrap: anywhere; }
@@ -6603,7 +6740,7 @@ var RENDERER_CSS = `
6603
6740
  .ds-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(21, 121, 190, .10); }
6604
6741
  .ds-tile:active { transform: translateY(0); }
6605
6742
  .ds-kpi-main { transition: opacity 160ms ease; }
6606
- .ds-kpi-main:hover .ds-kpi-value { color: var(--ds-color-action-primary); transition: color 160ms ease; }
6743
+ .ds-kpi-main[data-clickable]:hover .ds-kpi-value { color: var(--ds-color-action-primary); transition: color 160ms ease; }
6607
6744
  .ds-chip { animation: ds-fade 300ms ease both; transition: background 200ms ease, color 200ms ease; }
6608
6745
  .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); }
6609
6746
  .ds-segbar button { transform-origin: left; animation: ds-grow-x 700ms cubic-bezier(.2,.7,.2,1) both; }
@@ -6621,8 +6758,6 @@ var RENDERER_CSS = `
6621
6758
  .ds-scrim[data-presentation="drawer"] .ds-dialog { animation: ds-slide-in 300ms cubic-bezier(.2,.7,.2,1) both; }
6622
6759
  .ds-select, .ds-input, .ds-btn, .ds-chip, .ds-link { transition: border-color 140ms ease, background 140ms ease, color 140ms ease, box-shadow 140ms ease; }
6623
6760
  .ds-select:hover, .ds-input:hover { border-color: var(--ds-color-action-primary); }
6624
- .ds-info::after { transform: translateX(-50%) translateY(-2px); transition: opacity 140ms ease, transform 140ms ease; }
6625
- .ds-info:hover::after, .ds-info:focus-visible::after { transform: translateX(-50%) translateY(0); }
6626
6761
  .ds-grid-edit .react-grid-item > .ds-panel { animation: none; }
6627
6762
  @media (prefers-reduced-motion: reduce) {
6628
6763
  .ds-root *, .ds-root *::before, .ds-root *::after { animation: none !important; transition: none !important; }
@@ -6674,6 +6809,11 @@ var RENDERER_CSS = `
6674
6809
 
6675
6810
  .ds-stepper { display: inline-flex; align-items: stretch; gap: 0; }
6676
6811
  .ds-stepper .ds-pill-btn { border-radius: 0; border-left: 0; border-right: 0; }
6812
+ /* Between the arrows the select is one piece of the group: no border or ring of its own (square corners would
6813
+ draw a box inside the rounded group); keyboard focus gets an inset ring instead. */
6814
+ .ds-stepper .ds-pill-btn, .ds-stepper .ds-pill-btn:hover, .ds-stepper .ds-pill-btn[aria-expanded="true"] { border-color: transparent; box-shadow: none; }
6815
+ .ds-stepper .ds-pill-btn:focus { outline: none; }
6816
+ .ds-stepper .ds-pill-btn:focus-visible, .ds-stepper .ds-step:focus-visible { outline: 2px solid var(--ds-color-border-focus); outline-offset: -2px; }
6677
6817
  .ds-step { display: inline-grid; place-items: center; width: var(--ds-control-height, 36px); height: var(--ds-control-height, 36px); border: 1px solid transparent; background: var(--ds-color-surface-selection); color: var(--ds-color-action-primary); cursor: pointer; transition: background 140ms ease, opacity 140ms ease; }
6678
6818
  .ds-stepper > .ds-step:first-child { border-radius: var(--ds-radius-control) 0 0 var(--ds-radius-control); }
6679
6819
  .ds-stepper > .ds-step:last-child { border-radius: 0 var(--ds-radius-control) var(--ds-radius-control) 0; }
@@ -6814,6 +6954,14 @@ var RENDERER_CSS = `
6814
6954
  .ds-filter-pick[data-selected] { outline-color: var(--ds-color-action-primary); }
6815
6955
  .ds-filter-pick * { pointer-events: none; }
6816
6956
  .ds-filters[data-look="plain"] { background: transparent; padding-left: 0; padding-right: 0; box-shadow: none; }
6957
+ /* look "segmented": the icon and the filters share one sunken track; each filter is a borderless chip on the card
6958
+ colour, with no leading icon; the page stepper's arrows use the selection colour. */
6959
+ .ds-filters-track { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 2px; border-radius: var(--ds-radius-control); background: var(--ds-color-surface-sunken); }
6960
+ .ds-filters[data-look="segmented"] .ds-filters-icon { border: 0; width: auto; padding: 0 var(--ds-space-sm); }
6961
+ .ds-filters[data-look="segmented"] .ds-pill-btn { border: 0; border-radius: calc(var(--ds-radius-control) / 2); background: var(--ds-color-surface-card); box-shadow: none; padding: 0 var(--ds-space-sm); font-family: var(--ds-font-heading); }
6962
+ .ds-filters[data-look="segmented"] .ds-pill-btn > svg:first-child:not(:last-child) { display: none; }
6963
+ .ds-filters[data-look="segmented"] .ds-stepper { gap: 2px; }
6964
+ .ds-filters[data-look="segmented"] .ds-step { border: 0; border-radius: calc(var(--ds-radius-control) / 2); background: var(--ds-color-surface-selection); width: 32px; }
6817
6965
  .ds-filters[data-editable] { cursor: pointer; outline: 1.5px dashed transparent; outline-offset: 2px; transition: outline-color 120ms; }
6818
6966
  .ds-filters[data-editable]:hover { outline-color: color-mix(in srgb, var(--ds-color-action-primary) 45%, transparent); }
6819
6967
  .ds-filters[data-picked] { outline: 2px solid var(--ds-color-action-primary) !important; }
@@ -6961,14 +7109,14 @@ function usesScripts(doc) {
6961
7109
  }
6962
7110
  var sameJson = (a, b) => Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b);
6963
7111
  function useStableList(list) {
6964
- const ref = useRef13(list);
7112
+ const ref = useRef14(list);
6965
7113
  const prev = ref.current;
6966
7114
  const same = prev === list || prev && list && prev.length === list.length && prev.every((x, i) => x === list[i]);
6967
7115
  if (!same) ref.current = list;
6968
7116
  return ref.current;
6969
7117
  }
6970
7118
  function useStableUi(ui) {
6971
- const ref = useRef13(ui);
7119
+ const ref = useRef14(ui);
6972
7120
  const prev = ref.current;
6973
7121
  const next = ui;
6974
7122
  const flat = (a, b) => a === b || !!a && !!b && Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((k) => Object.is(a[k], b[k]));
@@ -7054,8 +7202,8 @@ var DashboardRenderer = forwardRef(
7054
7202
  const forRuntime = useMemo8(() => loaded, [runtimeKey]);
7055
7203
  const mode = props.scripts ?? "sandbox";
7056
7204
  const needsSandbox = loaded.status === "valid" && mode === "sandbox" && usesScripts(loaded.document);
7057
- const [sandbox, setSandbox] = useState9(null);
7058
- const [sandboxError, setSandboxError] = useState9(null);
7205
+ const [sandbox, setSandbox] = useState10(null);
7206
+ const [sandboxError, setSandboxError] = useState10(null);
7059
7207
  useEffect11(() => {
7060
7208
  if (!needsSandbox || sandbox) return;
7061
7209
  let cancelled = false;
@@ -7064,11 +7212,11 @@ var DashboardRenderer = forwardRef(
7064
7212
  cancelled = true;
7065
7213
  };
7066
7214
  }, [needsSandbox, sandbox]);
7067
- const latest = useRef13(props);
7215
+ const latest = useRef14(props);
7068
7216
  latest.current = props;
7069
7217
  const prefix = props.id ? `${props.id}.` : "v.";
7070
7218
  const useUrl = (props.urlSync ?? !props.editable) && typeof window !== "undefined";
7071
- const urlOwner = useRef13({});
7219
+ const urlOwner = useRef14({});
7072
7220
  const runtime = useMemo8(() => {
7073
7221
  if (forRuntime.status !== "valid") return null;
7074
7222
  if (needsSandbox && !sandbox) return null;
@@ -7177,7 +7325,7 @@ var DashboardRenderer = forwardRef(
7177
7325
  }, [runtime, stateKey]);
7178
7326
  const hostDataKey = props.data ? JSON.stringify(props.data) : "";
7179
7327
  const contextKey = props.context ? JSON.stringify(props.context) : "";
7180
- const hostInputsSeen = useRef13(null);
7328
+ const hostInputsSeen = useRef14(null);
7181
7329
  useEffect11(() => {
7182
7330
  if (!runtime) return;
7183
7331
  const seen = hostInputsSeen.current;
@@ -7625,6 +7773,7 @@ export {
7625
7773
  safeLink,
7626
7774
  satisfies,
7627
7775
  scope,
7776
+ stripStrings,
7628
7777
  templateReferences,
7629
7778
  themeCssVars,
7630
7779
  themeStylesheet,