@dashspec/renderer 0.1.32 → 0.1.34

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
@@ -116,7 +116,7 @@ import {
116
116
  translator,
117
117
  validateDocument,
118
118
  widgetChecks
119
- } from "./chunk-6N525TLR.js";
119
+ } from "./chunk-6QOH5C36.js";
120
120
  import {
121
121
  createStateProxy,
122
122
  getPath,
@@ -164,12 +164,12 @@ function useTree(select, isEqual = shallowEqual) {
164
164
  import {
165
165
  createElement,
166
166
  forwardRef,
167
- useCallback as useCallback8,
167
+ useCallback as useCallback9,
168
168
  useEffect as useEffect12,
169
169
  useImperativeHandle,
170
170
  useMemo as useMemo8,
171
171
  useRef as useRef14,
172
- useState as useState10
172
+ useState as useState11
173
173
  } from "react";
174
174
 
175
175
  // src/designSystem.ts
@@ -1808,6 +1808,10 @@ function themeCssVars(theme, mode) {
1808
1808
  if (s.control?.iconSize) out["--ds-filter-icon-size"] = `${s.control.iconSize}px`;
1809
1809
  if (s.control?.stepBackground && !UNSAFE_CSS.test(s.control.stepBackground))
1810
1810
  out["--ds-control-step-bg"] = s.control.stepBackground;
1811
+ if (s.control?.menuWidth === "trigger") {
1812
+ out["--ds-menu-width"] = "var(--ds-trigger-width)";
1813
+ out["--ds-menu-min-width"] = "0px";
1814
+ }
1811
1815
  if (s.control?.iconColor && !UNSAFE_CSS.test(s.control.iconColor))
1812
1816
  out["--ds-filter-icon-color"] = s.control.iconColor;
1813
1817
  if (s.control?.valueColor && !UNSAFE_CSS.test(s.control.valueColor))
@@ -2444,7 +2448,9 @@ function Floating({
2444
2448
  position: "fixed",
2445
2449
  top: pos?.top ?? -9999,
2446
2450
  left: pos?.left ?? -9999,
2447
- minWidth: anchor.current?.offsetWidth
2451
+ minWidth: anchor.current?.offsetWidth,
2452
+ // The trigger's width, for themes that size option menus to it (`scale.control.menuWidth: "trigger"`).
2453
+ ["--ds-trigger-width"]: `${anchor.current?.offsetWidth ?? 0}px`
2448
2454
  },
2449
2455
  children
2450
2456
  }
@@ -5612,7 +5618,8 @@ var Button = defineWidget({
5612
5618
  });
5613
5619
 
5614
5620
  // src/widgets/builtins/charts.tsx
5615
- import { useMemo as useMemo6 } from "react";
5621
+ import { useCallback as useCallback5, useMemo as useMemo6, useState as useState7 } from "react";
5622
+ import { createPortal as createPortal3 } from "react-dom";
5616
5623
  import "zod";
5617
5624
 
5618
5625
  // src/widgets/shared/EChart.tsx
@@ -6082,35 +6089,43 @@ var BarChart2 = defineWidget({
6082
6089
  const avgText = spec.averageLine && c.avg !== void 0 ? typeof spec.averageLine === "string" ? spec.averageLine.replace(/\$\{avg\}/g, helpers.fmt.number(c.avg, 1)) : `Avg: ${helpers.fmt.number(c.avg, 1)}` : void 0;
6083
6090
  const series = tokens?.theme[tokens.mode].chart.series ?? [];
6084
6091
  const legend = c.coloured || avgText || c.legend.length > 0;
6085
- return /* @__PURE__ */ jsxs19("div", { className: "ds-chart", children: [
6086
- legend && /* @__PURE__ */ jsxs19("ul", { className: "ds-chart-legend", children: [
6087
- c.coloured && /* @__PURE__ */ jsxs19(Fragment8, { children: [
6088
- /* @__PURE__ */ jsxs19("li", { children: [
6089
- /* @__PURE__ */ jsx25("span", { className: "ds-swatch", style: { background: colors?.good } }),
6090
- spec.legendLabels?.above ?? "At or above avg"
6091
- ] }),
6092
- /* @__PURE__ */ jsxs19("li", { children: [
6093
- /* @__PURE__ */ jsx25("span", { className: "ds-swatch", style: { background: colors?.bad } }),
6094
- spec.legendLabels?.below ?? "Below avg"
6095
- ] })
6092
+ const [head, setHead] = useState7(null);
6093
+ const findHead = useCallback5(
6094
+ (el) => setHead(
6095
+ spec.legendStyle === "html" ? el?.closest(".ds-panel")?.querySelector(":scope > .ds-panel-head .ds-panel-tools") ?? null : null
6096
+ ),
6097
+ [spec.legendStyle]
6098
+ );
6099
+ const list = legend ? /* @__PURE__ */ jsxs19("ul", { className: "ds-chart-legend", children: [
6100
+ c.coloured && /* @__PURE__ */ jsxs19(Fragment8, { children: [
6101
+ /* @__PURE__ */ jsxs19("li", { children: [
6102
+ /* @__PURE__ */ jsx25("span", { className: "ds-swatch", style: { background: colors?.good } }),
6103
+ spec.legendLabels?.above ?? "At or above avg"
6096
6104
  ] }),
6097
- c.legend.map((l, i) => /* @__PURE__ */ jsxs19("li", { children: [
6098
- /* @__PURE__ */ jsx25(
6099
- "span",
6100
- {
6101
- className: "ds-swatch",
6102
- style: {
6103
- background: (l.key !== void 0 && spec.seriesColors && Object.hasOwn(spec.seriesColors, l.key) ? spec.seriesColors[l.key] : void 0) ?? series[i % Math.max(series.length, 1)]
6104
- }
6105
- }
6106
- ),
6107
- l.name
6108
- ] }, l.name)),
6109
- avgText && /* @__PURE__ */ jsxs19("li", { children: [
6110
- /* @__PURE__ */ jsx25("span", { className: "ds-swatch-line" }),
6111
- avgText
6105
+ /* @__PURE__ */ jsxs19("li", { children: [
6106
+ /* @__PURE__ */ jsx25("span", { className: "ds-swatch", style: { background: colors?.bad } }),
6107
+ spec.legendLabels?.below ?? "Below avg"
6112
6108
  ] })
6113
6109
  ] }),
6110
+ c.legend.map((l, i) => /* @__PURE__ */ jsxs19("li", { children: [
6111
+ /* @__PURE__ */ jsx25(
6112
+ "span",
6113
+ {
6114
+ className: "ds-swatch",
6115
+ style: {
6116
+ background: (l.key !== void 0 && spec.seriesColors && Object.hasOwn(spec.seriesColors, l.key) ? spec.seriesColors[l.key] : void 0) ?? series[i % Math.max(series.length, 1)]
6117
+ }
6118
+ }
6119
+ ),
6120
+ l.name
6121
+ ] }, l.name)),
6122
+ avgText && /* @__PURE__ */ jsxs19("li", { children: [
6123
+ /* @__PURE__ */ jsx25("span", { className: "ds-swatch-line" }),
6124
+ avgText
6125
+ ] })
6126
+ ] }) : null;
6127
+ return /* @__PURE__ */ jsxs19("div", { className: "ds-chart", ref: findHead, children: [
6128
+ head && list ? createPortal3(list, head) : list,
6114
6129
  /* @__PURE__ */ jsx25(
6115
6130
  EChart,
6116
6131
  {
@@ -6119,7 +6134,7 @@ var BarChart2 = defineWidget({
6119
6134
  emit,
6120
6135
  part: "bar",
6121
6136
  rows: c.rows,
6122
- height: size2.height - (legend ? 24 : 0),
6137
+ height: size2.height - (legend && !head ? 24 : 0),
6123
6138
  hiddenSeries: state.hiddenSeries,
6124
6139
  highlightIndex: hi,
6125
6140
  ariaLabel: spec.title
@@ -6495,7 +6510,7 @@ var builtInWidgets = [
6495
6510
  ];
6496
6511
 
6497
6512
  // src/components/Grid.tsx
6498
- import { useEffect as useEffect8, useMemo as useMemo7, useRef as useRef9, useState as useState7 } from "react";
6513
+ import { useEffect as useEffect8, useMemo as useMemo7, useRef as useRef9, useState as useState8 } from "react";
6499
6514
  import { Responsive, WidthProvider } from "react-grid-layout";
6500
6515
  import { jsx as jsx27 } from "react/jsx-runtime";
6501
6516
  var ResponsiveGrid = WidthProvider(Responsive);
@@ -6553,8 +6568,8 @@ function Grid({
6553
6568
  dragOnto
6554
6569
  }) {
6555
6570
  const bpRef = useRef9("desktop");
6556
- const [wrapEl, setWrapEl] = useState7(null);
6557
- const [measured, setMeasured] = useState7("desktop");
6571
+ const [wrapEl, setWrapEl] = useState8(null);
6572
+ const [measured, setMeasured] = useState8("desktop");
6558
6573
  useEffect8(() => {
6559
6574
  if (!wrapEl || typeof ResizeObserver === "undefined") return;
6560
6575
  const ro = new ResizeObserver(([e]) => {
@@ -6581,7 +6596,7 @@ function Grid({
6581
6596
  cols: base.cols
6582
6597
  };
6583
6598
  }, [base, hidden, editable, exact, unit]);
6584
- const [fitRows, setFitRows] = useState7({});
6599
+ const [fitRows, setFitRows] = useState8({});
6585
6600
  const fitted = useMemo7(() => {
6586
6601
  if (editable || base.fit.size === 0) return rgl;
6587
6602
  return Object.fromEntries(
@@ -6610,6 +6625,7 @@ function Grid({
6610
6625
  if (!el || editable || !base.fit.has(panel) || typeof ResizeObserver === "undefined") return;
6611
6626
  const measure = () => {
6612
6627
  const target2 = el.firstElementChild;
6628
+ if (target2?.querySelector('[aria-busy="true"]')) return;
6613
6629
  el.setAttribute("data-measuring", "");
6614
6630
  const px = target2?.offsetHeight ?? 0;
6615
6631
  el.removeAttribute("data-measuring");
@@ -6722,7 +6738,7 @@ function Grid({
6722
6738
  }
6723
6739
 
6724
6740
  // src/components/ModalHost.tsx
6725
- import { useCallback as useCallback5, useEffect as useEffect9, useRef as useRef10 } from "react";
6741
+ import { useCallback as useCallback6, useEffect as useEffect9, useRef as useRef10 } from "react";
6726
6742
  import { jsx as jsx28, jsxs as jsxs21 } from "react/jsx-runtime";
6727
6743
  var WIDTH = { sm: "420px", md: "720px", lg: "1040px", xl: "1320px", full: "100%" };
6728
6744
  var FOCUSABLE2 = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
@@ -6731,11 +6747,11 @@ function ModalHost() {
6731
6747
  const modals = runtime.doc.spec.modals ?? {};
6732
6748
  const open = useTree(
6733
6749
  // biome-ignore lint/correctness/useExhaustiveDependencies: modals are fixed per runtime
6734
- useCallback5((t) => t.modal ? { id: t.modal.id, title: titleOf(t, t.modal.id) } : null, [runtime])
6750
+ useCallback6((t) => t.modal ? { id: t.modal.id, title: titleOf(t, t.modal.id) } : null, [runtime])
6735
6751
  );
6736
6752
  const byExpression = useTree(
6737
6753
  // biome-ignore lint/correctness/useExhaustiveDependencies: modals are fixed per runtime
6738
- useCallback5(
6754
+ useCallback6(
6739
6755
  (t) => Object.entries(modals).filter(([, m2]) => {
6740
6756
  if (typeof m2.open !== "string") return false;
6741
6757
  try {
@@ -6773,7 +6789,7 @@ function ModalHost() {
6773
6789
  const dialog = useRef10(null);
6774
6790
  const scrim = useRef10(null);
6775
6791
  const openId = open?.id;
6776
- const close = useCallback5(() => {
6792
+ const close = useCallback6(() => {
6777
6793
  if (!openId) return;
6778
6794
  void runtime.emit({ type: "close", modal: openId });
6779
6795
  const on = modals[openId]?.on;
@@ -6915,7 +6931,7 @@ function pickTheme(name, themes, fallback) {
6915
6931
  }
6916
6932
 
6917
6933
  // src/components/Tour.tsx
6918
- import { useCallback as useCallback6, useEffect as useEffect10, useId as useId5, useLayoutEffect as useLayoutEffect3, useRef as useRef12, useState as useState8 } from "react";
6934
+ import { useCallback as useCallback7, useEffect as useEffect10, useId as useId5, useLayoutEffect as useLayoutEffect3, useRef as useRef12, useState as useState9 } from "react";
6919
6935
  import { Fragment as Fragment10, jsx as jsx30, jsxs as jsxs22 } from "react/jsx-runtime";
6920
6936
  var useClientLayoutEffect = typeof window === "undefined" ? useEffect10 : useLayoutEffect3;
6921
6937
  function panelElement(root, id) {
@@ -6926,16 +6942,16 @@ function panelElement(root, id) {
6926
6942
  }
6927
6943
  function TourButton({ steps }) {
6928
6944
  const { runtime } = useDashboard();
6929
- const [at, setAt] = useState8(null);
6945
+ const [at, setAt] = useState9(null);
6930
6946
  const button = useRef12(null);
6931
6947
  const dialog = useRef12(null);
6932
6948
  const next = useRef12(null);
6933
- const [pos, setPos] = useState8(null);
6949
+ const [pos, setPos] = useState9(null);
6934
6950
  const titleId = useId5();
6935
6951
  const textId = useId5();
6936
6952
  const step = at === null ? void 0 : steps[at];
6937
6953
  const text = useTree(
6938
- useCallback6(
6954
+ useCallback7(
6939
6955
  (t) => {
6940
6956
  if (!step) return null;
6941
6957
  const sc = rootScope(t, runtime.helpers);
@@ -6953,7 +6969,7 @@ function TourButton({ steps }) {
6953
6969
  ),
6954
6970
  (a, b) => a?.title === b?.title && a?.text === b?.text
6955
6971
  );
6956
- const close = useCallback6(() => {
6972
+ const close = useCallback7(() => {
6957
6973
  setAt(null);
6958
6974
  button.current?.focus();
6959
6975
  }, []);
@@ -7055,7 +7071,7 @@ function TourButton({ steps }) {
7055
7071
  }
7056
7072
 
7057
7073
  // src/components/registryHooks.ts
7058
- import { useCallback as useCallback7, useEffect as useEffect11, useRef as useRef13, useState as useState9, useSyncExternalStore as useSyncExternalStore3 } from "react";
7074
+ import { useCallback as useCallback8, useEffect as useEffect11, useRef as useRef13, useState as useState10, useSyncExternalStore as useSyncExternalStore3 } from "react";
7059
7075
  var live = /* @__PURE__ */ new Map();
7060
7076
  var listeners = /* @__PURE__ */ new Set();
7061
7077
  var notify = () => {
@@ -7083,7 +7099,7 @@ function useRuntimeById(id) {
7083
7099
  }
7084
7100
  function useDashboardState(id, select) {
7085
7101
  const rt = useRuntimeById(id);
7086
- const [value, setValue] = useState9(() => rt ? select(rt.getTree()) : void 0);
7102
+ const [value, setValue] = useState10(() => rt ? select(rt.getTree()) : void 0);
7087
7103
  const sel = useRef13(select);
7088
7104
  sel.current = select;
7089
7105
  useEffect11(() => {
@@ -7098,17 +7114,17 @@ function useDashboardActions(id) {
7098
7114
  const rt = useRuntimeById(id);
7099
7115
  return {
7100
7116
  ready: Boolean(rt),
7101
- setVariable: useCallback7(
7117
+ setVariable: useCallback8(
7102
7118
  (name, value) => rt?.store.dispatch(stateActions.setFilter({ name, value })),
7103
7119
  [rt]
7104
7120
  ),
7105
- setState: useCallback7(
7121
+ setState: useCallback8(
7106
7122
  (path, value) => rt?.store.dispatch(stateActions.set({ path, value })),
7107
7123
  [rt]
7108
7124
  ),
7109
- setView: useCallback7((view) => rt?.store.dispatch(stateActions.setView(view)), [rt]),
7110
- run: useCallback7((action) => rt?.runAction(action), [rt]),
7111
- refresh: useCallback7(
7125
+ setView: useCallback8((view) => rt?.store.dispatch(stateActions.setView(view)), [rt]),
7126
+ run: useCallback8((action) => rt?.runAction(action), [rt]),
7127
+ refresh: useCallback8(
7112
7128
  (source) => rt?.engine.refresh(source === void 0 ? void 0 : Array.isArray(source) ? source : [source]),
7113
7129
  [rt]
7114
7130
  )
@@ -7348,6 +7364,7 @@ var RENDERER_CSS = `
7348
7364
 
7349
7365
  .ds-chart { display: flex; flex-direction: column; height: 100%; }
7350
7366
  .ds-chart-legend { list-style: none; margin: -38px 0 14px auto; padding: 0; display: flex; gap: var(--ds-space-lg); font-size: var(--ds-type-label-size); color: var(--ds-color-text-subtle); position: relative; z-index: 1; max-width: 70%; flex-wrap: wrap; justify-content: flex-end; }
7367
+ .ds-panel-tools .ds-chart-legend { margin: 0; max-width: none; }
7351
7368
  .ds-chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
7352
7369
  .ds-swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
7353
7370
  .ds-swatch-line { width: 16px; border-top: 2px dashed var(--ds-color-text-subtle); display: inline-block; }
@@ -7424,7 +7441,8 @@ var RENDERER_CSS = `
7424
7441
 
7425
7442
  .ds-pop { z-index: calc(var(--ds-z-overlay) + 10); max-width: min(92vw, 640px); background: var(--ds-color-surface-overlay); border: 1px solid color-mix(in srgb, var(--ds-color-border-default) 70%, transparent); border-radius: 12px; box-shadow: 0 14px 36px rgba(13,13,13,.16), 0 2px 6px rgba(13,13,13,.06); padding: 6px; animation: ds-pop-in 180ms cubic-bezier(.2,.7,.2,1) both; transform-origin: top left; }
7426
7443
  @keyframes ds-pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
7427
- .ds-menu { display: grid; gap: 2px; max-height: 300px; overflow: auto; outline: none; min-width: 200px; }
7444
+ .ds-menu { display: grid; gap: 2px; max-height: 300px; overflow: auto; outline: none; min-width: var(--ds-menu-min-width, 200px); }
7445
+ .ds-pop:has(> .ds-menu) { width: var(--ds-menu-width, auto); }
7428
7446
  .ds-menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ds-color-text-primary); font: 400 var(--ds-control-font-size, 13px)/18px var(--ds-font-body); text-align: left; cursor: pointer; transition: background 120ms ease, color 120ms ease; }
7429
7447
  .ds-menu-item:hover, .ds-menu-item:focus-visible { background: color-mix(in srgb, var(--ds-color-action-primary) 8%, transparent); outline: none; }
7430
7448
  .ds-menu-item[aria-selected="true"], .ds-menu-item[aria-pressed="true"] { color: var(--ds-color-action-primary); font-weight: 600; background: var(--ds-color-surface-selection); }
@@ -7865,8 +7883,8 @@ var DashboardRenderer = forwardRef(
7865
7883
  const forRuntime = useMemo8(() => loaded, [runtimeKey]);
7866
7884
  const mode = props.scripts ?? "sandbox";
7867
7885
  const needsSandbox = loaded.status === "valid" && mode === "sandbox" && usesScripts(loaded.document);
7868
- const [sandbox, setSandbox] = useState10(null);
7869
- const [sandboxError, setSandboxError] = useState10(null);
7886
+ const [sandbox, setSandbox] = useState11(null);
7887
+ const [sandboxError, setSandboxError] = useState11(null);
7870
7888
  useEffect12(() => {
7871
7889
  if (!needsSandbox || sandbox) return;
7872
7890
  let cancelled = false;
@@ -8188,7 +8206,7 @@ function DashboardBody({
8188
8206
  return () => clearInterval(timer);
8189
8207
  }, [tv, runtime]);
8190
8208
  const head = useTree(
8191
- useCallback8(
8209
+ useCallback9(
8192
8210
  (t) => {
8193
8211
  const sc = rootScope(t, runtime.helpers);
8194
8212
  const text = (v) => {