@pixerate/editor-react 0.109.0 → 0.111.0

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.
@@ -25,5 +25,7 @@ export interface ChartDataGridProps {
25
25
  * a name moves the item (a new name starts a new group); `+ Level` adds a column for deeper groups.
26
26
  */
27
27
  export declare function ChartTreeGrid({ controller, readOnly, className }: Omit<ChartDataGridProps, 'categoryHeader'>): React.JSX.Element;
28
+ /** Flows as a table: source, target and value per row. Edits are checked as a whole (no loops, no repeated pairs). */
29
+ export declare function ChartLinksGrid({ controller, readOnly, className }: Omit<ChartDataGridProps, 'categoryHeader'>): React.JSX.Element;
28
30
  export declare function ChartDataGrid({ controller, categoryHeader, readOnly, className }: ChartDataGridProps): React.JSX.Element;
29
31
  export {};
@@ -25,5 +25,7 @@ export interface ChartDataGridProps {
25
25
  * a name moves the item (a new name starts a new group); `+ Level` adds a column for deeper groups.
26
26
  */
27
27
  export declare function ChartTreeGrid({ controller, readOnly, className }: Omit<ChartDataGridProps, 'categoryHeader'>): React.JSX.Element;
28
+ /** Flows as a table: source, target and value per row. Edits are checked as a whole (no loops, no repeated pairs). */
29
+ export declare function ChartLinksGrid({ controller, readOnly, className }: Omit<ChartDataGridProps, 'categoryHeader'>): React.JSX.Element;
28
30
  export declare function ChartDataGrid({ controller, categoryHeader, readOnly, className }: ChartDataGridProps): React.JSX.Element;
29
31
  export {};
@@ -35,6 +35,7 @@ __export(chart_exports, {
35
35
  ChartDataGrid: () => ChartDataGrid,
36
36
  ChartEditor: () => ChartEditor,
37
37
  ChartInspector: () => ChartInspector,
38
+ ChartLinksGrid: () => ChartLinksGrid,
38
39
  ChartPresenceLayer: () => ChartPresenceLayer,
39
40
  ChartSceneSvg: () => ChartSceneSvg,
40
41
  ChartSparkline: () => ChartSparkline,
@@ -247,9 +248,10 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
247
248
  valueDomain: frozen?.valueDomain,
248
249
  valueDomain2: frozen?.valueDomain2,
249
250
  xDomain: frozen?.xDomain,
250
- readout: frozen?.readout
251
+ readout: frozen?.readout,
252
+ raceFrame: state.raceFrame
251
253
  }),
252
- [state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
254
+ [state.spec, state.selection, state.raceFrame, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
253
255
  );
254
256
  if (sceneRef) sceneRef.current = scene;
255
257
  const byKey = (0, import_react2.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
@@ -403,8 +405,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
403
405
  ] })
404
406
  ] });
405
407
  }
408
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
409
+ const { spec } = useChartState(controller);
410
+ const links = spec.links;
411
+ const commit = (next) => controller.setLinks(next).ok;
412
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", "data-chart-links-grid": "", children: [
413
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { className: "w-full border-collapse text-xs", children: [
414
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { className: "bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
415
+ ["Source", "Target"].map((label) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "border-b border-r border-border px-2 py-1 text-left font-medium text-muted-foreground", children: label }, label)),
416
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "border-b border-r border-border px-2 py-1 text-right font-medium text-muted-foreground", children: "Value" }),
417
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-8 border-b border-border" })
418
+ ] }) }),
419
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tbody", { children: links.map((link, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { "data-link-row": i, children: [
420
+ ["source", "target"].map((field) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartCommitInput, { value: link[field], "aria-label": `${field === "source" ? "Source" : "Target"} of flow ${i + 1}`, "data-link-cell": `${i}:${field}`, readOnly, onCommit: (text) => commit((0, import_chart3.setChartLinkField)(links, i, field, text)), className: `${chartCellClass} text-left` }) }, field)),
421
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartCommitInput, { value: String(link.value), inputMode: "decimal", "aria-label": `Value of ${link.source} \u2192 ${link.target}`, "data-link-cell": `${i}:value`, readOnly, onCommit: (text) => commit((0, import_chart3.setChartLinkField)(links, i, "value", text)), className: chartCellClass }) }),
422
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { className: "border-b border-border px-1", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: chartIconButtonClass, title: "Delete flow", "aria-label": `Delete ${link.source} \u2192 ${link.target}`, "data-action": "link-remove", onClick: () => controller.removeLink(i), children: "\xD7" }) })
423
+ ] }, i)) })
424
+ ] }),
425
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-wrap gap-1 p-1", children: [
426
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "link-add", onClick: () => commit((0, import_chart3.addChartLink)(links)), children: "+ Add flow" }),
427
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "flex-1" }),
428
+ links.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: `${chartButtonClass} h-6`, "data-action": "links-clear", title: "Keep how much passes through each node as plain data", onClick: () => controller.setLinks([]), children: "Remove flows" })
429
+ ] })
430
+ ] });
431
+ }
406
432
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
407
433
  const { spec, selection } = useChartState(controller);
434
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLinksGrid, { controller, readOnly, className });
408
435
  if (spec.tree.length) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartTreeGrid, { controller, readOnly, className });
409
436
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
410
437
  const paste = (row, column) => (e) => {
@@ -682,7 +709,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
682
709
  ] });
683
710
  }
684
711
  function ChartInspector({ controller, sections, className }) {
685
- const { spec, selectedSeries, selection } = useChartState(controller);
712
+ const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
686
713
  const idBase = (0, import_react4.useId)();
687
714
  const show = (section) => !sections || sections.includes(section);
688
715
  const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
@@ -753,6 +780,27 @@ function ChartInspector({ controller, sections, className }) {
753
780
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
754
781
  }
755
782
  ) }),
783
+ spec.type === "barrace" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Bars", htmlFor: `${idBase}-race-top`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${idBase}-race-top`, value: String(spec.raceTopN), inputMode: "numeric", "data-option": "raceTopN", className: chartInputClass, onCommit: (text) => controller.update({ raceTopN: Number(text) }).ok }) }),
784
+ spec.type === "barrace" && spec.categories.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Time", htmlFor: `${idBase}-race-frame`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1", children: [
785
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "race-play", "aria-label": racePlaying ? "Pause the race" : "Play the race", onClick: () => racePlaying ? controller.pauseRace() : controller.playRace(), children: racePlaying ? "Pause" : "Play" }),
786
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
787
+ "input",
788
+ {
789
+ id: `${idBase}-race-frame`,
790
+ type: "range",
791
+ min: 0,
792
+ max: spec.categories.length - 1,
793
+ step: 0.01,
794
+ value: raceFrame ?? spec.categories.length - 1,
795
+ "data-option": "raceFrame",
796
+ "aria-valuetext": spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)],
797
+ className: "min-w-0 flex-1 accent-primary",
798
+ onChange: (e) => controller.setRaceFrame(Number(e.currentTarget.value))
799
+ }
800
+ ),
801
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "w-12 shrink-0 truncate text-right tabular-nums text-muted-foreground", "data-race-time": "", children: spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)] })
802
+ ] }) }),
803
+ spec.type === "sankey" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Flows", htmlFor: `${idBase}-sankey-color`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Select, { id: `${idBase}-sankey-color`, name: "sankeyLinkColor", value: spec.sankeyLinkColor, options: import_chart4.CHART_SANKEY_LINK_COLORS, labels: { source: "Coloured by source", target: "Coloured by target", gray: "Grey" }, onChange: (sankeyLinkColor) => controller.update({ sankeyLinkColor }) }) }),
756
804
  spec.type === "sunburst" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Caption", htmlFor: `${idBase}-sunburst-label`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${idBase}-sunburst-label`, value: spec.sunburstLabel, placeholder: "Under the total", "data-option": "sunburstLabel", className: chartInputClass, onCommit: (sunburstLabel) => controller.update({ sunburstLabel }).ok }) }),
757
805
  spec.type === "likert" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Neutral", htmlFor: `${idBase}-likert-neutral`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Select, { id: `${idBase}-likert-neutral`, name: "likertNeutral", value: spec.likertNeutral, options: import_chart4.CHART_LIKERT_NEUTRALS, labels: { split: "Across the centre", separate: "In its own column" }, onChange: (likertNeutral) => controller.update({ likertNeutral }) }) }),
758
806
  spec.type === "likert" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Order", htmlFor: `${idBase}-likert-sort`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Select, { id: `${idBase}-likert-sort`, name: "likertSort", value: spec.likertSort, options: import_chart4.CHART_LIKERT_SORTS, labels: { none: "As entered", positive: "Most agreement first", negative: "Most disagreement first" }, onChange: (likertSort) => controller.update({ likertSort }) }) }),
@@ -1161,6 +1209,7 @@ function ChartSparkline({ values, width = 80, height = 20, label, className, ...
1161
1209
  ChartDataGrid,
1162
1210
  ChartEditor,
1163
1211
  ChartInspector,
1212
+ ChartLinksGrid,
1164
1213
  ChartPresenceLayer,
1165
1214
  ChartSceneSvg,
1166
1215
  ChartSparkline,
@@ -3,6 +3,7 @@ import {
3
3
  ChartCommitInput,
4
4
  ChartDataGrid,
5
5
  ChartInspector,
6
+ ChartLinksGrid,
6
7
  ChartPresenceLayer,
7
8
  ChartSceneSvg,
8
9
  ChartTreeGrid,
@@ -21,7 +22,7 @@ import {
21
22
  useChartState,
22
23
  useChartToolProvider,
23
24
  useOfficeChartToolProvider
24
- } from "../chunk-GJ3IMZQW.js";
25
+ } from "../chunk-VTLCQXIY.js";
25
26
  import {
26
27
  PresenceLayer,
27
28
  useAgentPlayback,
@@ -183,6 +184,7 @@ export {
183
184
  ChartDataGrid,
184
185
  ChartEditor,
185
186
  ChartInspector,
187
+ ChartLinksGrid,
186
188
  ChartPresenceLayer,
187
189
  ChartSceneSvg,
188
190
  ChartSparkline,
@@ -106,13 +106,14 @@ function useAutosave(options) {
106
106
  }
107
107
 
108
108
  // src/persistence/useEditorAutosave.ts
109
- import { useCallback as useCallback2, useMemo } from "react";
109
+ import { useCallback as useCallback2, useMemo, useRef as useRef2 } from "react";
110
110
  import {
111
+ collectRetiredEditorAssets,
111
112
  parseEditorDocument,
112
113
  toEditorDocumentFile,
113
114
  withEditorAssets
114
115
  } from "@pixerate/editor/persistence";
115
- function useEditorAutosave(doc, options) {
116
+ function useEditorAutosave(doc, { collectAssetGarbage, ...options }) {
116
117
  const storage = useMemo(
117
118
  () => doc.assets ? withEditorAssets(options.storage, doc.assets) : options.storage,
118
119
  [options.storage, doc.assets]
@@ -130,7 +131,19 @@ function useEditorAutosave(doc, options) {
130
131
  const snapshot = take();
131
132
  return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
132
133
  }, [take, doc]);
133
- return { ...autosave, restore };
134
+ const { markClean: clean, discard: drop } = autosave;
135
+ const rawStorage = options.storage;
136
+ const gcRef = useRef2(collectAssetGarbage);
137
+ gcRef.current = collectAssetGarbage;
138
+ const markClean = useCallback2(async () => {
139
+ await clean();
140
+ await collectRetiredEditorAssets(rawStorage, doc, gcRef.current);
141
+ }, [clean, rawStorage, doc]);
142
+ const discard = useCallback2(async () => {
143
+ await drop();
144
+ await collectRetiredEditorAssets(rawStorage, doc, gcRef.current);
145
+ }, [drop, rawStorage, doc]);
146
+ return { ...autosave, restore, markClean, discard };
134
147
  }
135
148
 
136
149
  // src/persistence/RecoveryPrompt.tsx
@@ -197,9 +197,10 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
197
197
  valueDomain: frozen?.valueDomain,
198
198
  valueDomain2: frozen?.valueDomain2,
199
199
  xDomain: frozen?.xDomain,
200
- readout: frozen?.readout
200
+ readout: frozen?.readout,
201
+ raceFrame: state.raceFrame
201
202
  }),
202
- [state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
203
+ [state.spec, state.selection, state.raceFrame, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
203
204
  );
204
205
  if (sceneRef) sceneRef.current = scene;
205
206
  const byKey = useMemo2(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
@@ -272,6 +273,7 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
272
273
  // src/chart/ChartDataGrid.tsx
273
274
  import { useEffect as useEffect3, useRef as useRef3, useState as useState2 } from "react";
274
275
  import {
276
+ addChartLink,
275
277
  addChartTreeRow,
276
278
  chartColorInputValue,
277
279
  chartSeriesColor,
@@ -281,6 +283,7 @@ import {
281
283
  chartTreeToRows,
282
284
  formatChartNumber,
283
285
  removeChartTreeRow,
286
+ setChartLinkField,
284
287
  setChartTreeRowName,
285
288
  setChartTreeRowValue
286
289
  } from "@pixerate/editor/chart";
@@ -374,8 +377,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
374
377
  ] })
375
378
  ] });
376
379
  }
380
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
381
+ const { spec } = useChartState(controller);
382
+ const links = spec.links;
383
+ const commit = (next) => controller.setLinks(next).ok;
384
+ return /* @__PURE__ */ jsxs2("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", "data-chart-links-grid": "", children: [
385
+ /* @__PURE__ */ jsxs2("table", { className: "w-full border-collapse text-xs", children: [
386
+ /* @__PURE__ */ jsx2("thead", { className: "bg-muted/50", children: /* @__PURE__ */ jsxs2("tr", { children: [
387
+ ["Source", "Target"].map((label) => /* @__PURE__ */ jsx2("th", { className: "border-b border-r border-border px-2 py-1 text-left font-medium text-muted-foreground", children: label }, label)),
388
+ /* @__PURE__ */ jsx2("th", { className: "border-b border-r border-border px-2 py-1 text-right font-medium text-muted-foreground", children: "Value" }),
389
+ !readOnly && /* @__PURE__ */ jsx2("th", { className: "w-8 border-b border-border" })
390
+ ] }) }),
391
+ /* @__PURE__ */ jsx2("tbody", { children: links.map((link, i) => /* @__PURE__ */ jsxs2("tr", { "data-link-row": i, children: [
392
+ ["source", "target"].map((field) => /* @__PURE__ */ jsx2("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ jsx2(ChartCommitInput, { value: link[field], "aria-label": `${field === "source" ? "Source" : "Target"} of flow ${i + 1}`, "data-link-cell": `${i}:${field}`, readOnly, onCommit: (text) => commit(setChartLinkField(links, i, field, text)), className: `${chartCellClass} text-left` }) }, field)),
393
+ /* @__PURE__ */ jsx2("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ jsx2(ChartCommitInput, { value: String(link.value), inputMode: "decimal", "aria-label": `Value of ${link.source} \u2192 ${link.target}`, "data-link-cell": `${i}:value`, readOnly, onCommit: (text) => commit(setChartLinkField(links, i, "value", text)), className: chartCellClass }) }),
394
+ !readOnly && /* @__PURE__ */ jsx2("td", { className: "border-b border-border px-1", children: /* @__PURE__ */ jsx2("button", { type: "button", className: chartIconButtonClass, title: "Delete flow", "aria-label": `Delete ${link.source} \u2192 ${link.target}`, "data-action": "link-remove", onClick: () => controller.removeLink(i), children: "\xD7" }) })
395
+ ] }, i)) })
396
+ ] }),
397
+ !readOnly && /* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap gap-1 p-1", children: [
398
+ /* @__PURE__ */ jsx2("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "link-add", onClick: () => commit(addChartLink(links)), children: "+ Add flow" }),
399
+ /* @__PURE__ */ jsx2("span", { className: "flex-1" }),
400
+ links.length > 0 && /* @__PURE__ */ jsx2("button", { type: "button", className: `${chartButtonClass} h-6`, "data-action": "links-clear", title: "Keep how much passes through each node as plain data", onClick: () => controller.setLinks([]), children: "Remove flows" })
401
+ ] })
402
+ ] });
403
+ }
377
404
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
378
405
  const { spec, selection } = useChartState(controller);
406
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ jsx2(ChartLinksGrid, { controller, readOnly, className });
379
407
  if (spec.tree.length) return /* @__PURE__ */ jsx2(ChartTreeGrid, { controller, readOnly, className });
380
408
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
381
409
  const paste = (row, column) => (e) => {
@@ -505,6 +533,7 @@ import {
505
533
  chartTrendlineName,
506
534
  CHART_CURVES,
507
535
  CHART_RADAR_GRATICULES,
536
+ CHART_SANKEY_LINK_COLORS,
508
537
  CHART_LEGEND_POSITIONS,
509
538
  CHART_LIKERT_NEUTRALS,
510
539
  CHART_LIKERT_SORTS,
@@ -685,7 +714,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
685
714
  ] });
686
715
  }
687
716
  function ChartInspector({ controller, sections, className }) {
688
- const { spec, selectedSeries, selection } = useChartState(controller);
717
+ const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
689
718
  const idBase = useId();
690
719
  const show = (section) => !sections || sections.includes(section);
691
720
  const cartesian = isCartesianChart(spec.type);
@@ -756,6 +785,27 @@ function ChartInspector({ controller, sections, className }) {
756
785
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
757
786
  }
758
787
  ) }),
788
+ spec.type === "barrace" && /* @__PURE__ */ jsx3(Field, { label: "Bars", htmlFor: `${idBase}-race-top`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-race-top`, value: String(spec.raceTopN), inputMode: "numeric", "data-option": "raceTopN", className: chartInputClass, onCommit: (text) => controller.update({ raceTopN: Number(text) }).ok }) }),
789
+ spec.type === "barrace" && spec.categories.length > 1 && /* @__PURE__ */ jsx3(Field, { label: "Time", htmlFor: `${idBase}-race-frame`, children: /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
790
+ /* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "data-action": "race-play", "aria-label": racePlaying ? "Pause the race" : "Play the race", onClick: () => racePlaying ? controller.pauseRace() : controller.playRace(), children: racePlaying ? "Pause" : "Play" }),
791
+ /* @__PURE__ */ jsx3(
792
+ "input",
793
+ {
794
+ id: `${idBase}-race-frame`,
795
+ type: "range",
796
+ min: 0,
797
+ max: spec.categories.length - 1,
798
+ step: 0.01,
799
+ value: raceFrame ?? spec.categories.length - 1,
800
+ "data-option": "raceFrame",
801
+ "aria-valuetext": spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)],
802
+ className: "min-w-0 flex-1 accent-primary",
803
+ onChange: (e) => controller.setRaceFrame(Number(e.currentTarget.value))
804
+ }
805
+ ),
806
+ /* @__PURE__ */ jsx3("span", { className: "w-12 shrink-0 truncate text-right tabular-nums text-muted-foreground", "data-race-time": "", children: spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)] })
807
+ ] }) }),
808
+ spec.type === "sankey" && /* @__PURE__ */ jsx3(Field, { label: "Flows", htmlFor: `${idBase}-sankey-color`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-sankey-color`, name: "sankeyLinkColor", value: spec.sankeyLinkColor, options: CHART_SANKEY_LINK_COLORS, labels: { source: "Coloured by source", target: "Coloured by target", gray: "Grey" }, onChange: (sankeyLinkColor) => controller.update({ sankeyLinkColor }) }) }),
759
809
  spec.type === "sunburst" && /* @__PURE__ */ jsx3(Field, { label: "Caption", htmlFor: `${idBase}-sunburst-label`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-sunburst-label`, value: spec.sunburstLabel, placeholder: "Under the total", "data-option": "sunburstLabel", className: chartInputClass, onCommit: (sunburstLabel) => controller.update({ sunburstLabel }).ok }) }),
760
810
  spec.type === "likert" && /* @__PURE__ */ jsx3(Field, { label: "Neutral", htmlFor: `${idBase}-likert-neutral`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-likert-neutral`, name: "likertNeutral", value: spec.likertNeutral, options: CHART_LIKERT_NEUTRALS, labels: { split: "Across the centre", separate: "In its own column" }, onChange: (likertNeutral) => controller.update({ likertNeutral }) }) }),
761
811
  spec.type === "likert" && /* @__PURE__ */ jsx3(Field, { label: "Order", htmlFor: `${idBase}-likert-sort`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-likert-sort`, name: "likertSort", value: spec.likertSort, options: CHART_LIKERT_SORTS, labels: { none: "As entered", positive: "Most agreement first", negative: "Most disagreement first" }, onChange: (likertSort) => controller.update({ likertSort }) }) }),
@@ -943,6 +993,7 @@ export {
943
993
  chartCellClass,
944
994
  ChartCommitInput,
945
995
  ChartTreeGrid,
996
+ ChartLinksGrid,
946
997
  ChartDataGrid,
947
998
  ChartInspector
948
999
  };
package/dist/index.cjs CHANGED
@@ -79,6 +79,7 @@ __export(src_exports, {
79
79
  SpreadsheetEditor: () => SpreadsheetEditor,
80
80
  SpreadsheetGroupRow: () => SpreadsheetGroupRow,
81
81
  SpreadsheetValidationDialog: () => SpreadsheetValidationDialog,
82
+ StyleFindings: () => StyleFindings,
82
83
  StylesGallery: () => StylesGallery,
83
84
  TableBubbleMenu: () => TableBubbleMenu,
84
85
  TableToolbar: () => TableToolbar,
@@ -127,6 +128,8 @@ __export(src_exports, {
127
128
  useSpreadsheetClipboard: () => useSpreadsheetClipboard,
128
129
  useSpreadsheetEditor: () => useSpreadsheetEditor,
129
130
  useSpreadsheetViewport: () => useSpreadsheetViewport,
131
+ useStyle: () => useStyle,
132
+ useStyleFindings: () => useStyleFindings,
130
133
  useTableMenu: () => useTableMenu,
131
134
  useToolBridge: () => useToolBridge,
132
135
  useToolRegistryView: () => useToolRegistryView,
@@ -4067,7 +4070,7 @@ var ImageEditorCanvas = ({
4067
4070
  modeRef.current = mode;
4068
4071
  const latest = (0, import_react41.useRef)({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
4069
4072
  latest.current = { onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal };
4070
- const report = (source, message) => latest.current.onError?.(source, message);
4073
+ const report = (source, message2) => latest.current.onError?.(source, message2);
4071
4074
  const ambientPlayback = useAgentPlayback();
4072
4075
  const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
4073
4076
  const locateLayer = (0, import_react41.useMemo)(() => (0, import_image_editor2.createImagePlaybackLocator)(controller), [controller]);
@@ -7469,7 +7472,7 @@ function ImageProviderEffectsPanel({ controller, className = "" }) {
7469
7472
  const [, setTick] = (0, import_react55.useState)(0);
7470
7473
  (0, import_react55.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
7471
7474
  const [browse, setBrowse] = (0, import_react55.useState)(null);
7472
- const [message, setMessage] = (0, import_react55.useState)(null);
7475
+ const [message2, setMessage] = (0, import_react55.useState)(null);
7473
7476
  const [open, setOpen] = (0, import_react55.useState)(null);
7474
7477
  const provider = controller.effectsProvider;
7475
7478
  const state = controller.getState();
@@ -7569,7 +7572,7 @@ function ImageProviderEffectsPanel({ controller, className = "" }) {
7569
7572
  ] }, f.id);
7570
7573
  }) }),
7571
7574
  !layer && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Select a layer to apply effects to it." }),
7572
- message && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
7575
+ message2 && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message2 })
7573
7576
  ] });
7574
7577
  }
7575
7578
 
@@ -8651,10 +8654,10 @@ var ImageEditor = ({
8651
8654
  const [selectionError, setSelectionError] = (0, import_react64.useState)(null);
8652
8655
  const [paintError, setPaintError] = (0, import_react64.useState)(null);
8653
8656
  const [shapeTypeError, setShapeTypeError] = (0, import_react64.useState)(null);
8654
- const handleCanvasError = (source, message) => {
8655
- if (source === "paint") setPaintError(message);
8656
- else if (source === "select") setSelectionError(message);
8657
- else setShapeTypeError(message);
8657
+ const handleCanvasError = (source, message2) => {
8658
+ if (source === "paint") setPaintError(message2);
8659
+ else if (source === "select") setSelectionError(message2);
8660
+ else setShapeTypeError(message2);
8658
8661
  };
8659
8662
  const finishTyping = () => setTypeSession(null);
8660
8663
  const transformToolRef = (0, import_react64.useRef)(null);
@@ -10336,7 +10339,7 @@ function useAutosave(options) {
10336
10339
  // src/persistence/useEditorAutosave.ts
10337
10340
  var import_react72 = require("react");
10338
10341
  var import_persistence2 = require("@pixerate/editor/persistence");
10339
- function useEditorAutosave(doc, options) {
10342
+ function useEditorAutosave(doc, { collectAssetGarbage, ...options }) {
10340
10343
  const storage = (0, import_react72.useMemo)(
10341
10344
  () => doc.assets ? (0, import_persistence2.withEditorAssets)(options.storage, doc.assets) : options.storage,
10342
10345
  [options.storage, doc.assets]
@@ -10354,7 +10357,19 @@ function useEditorAutosave(doc, options) {
10354
10357
  const snapshot = take();
10355
10358
  return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
10356
10359
  }, [take, doc]);
10357
- return { ...autosave, restore };
10360
+ const { markClean: clean, discard: drop } = autosave;
10361
+ const rawStorage = options.storage;
10362
+ const gcRef = (0, import_react72.useRef)(collectAssetGarbage);
10363
+ gcRef.current = collectAssetGarbage;
10364
+ const markClean = (0, import_react72.useCallback)(async () => {
10365
+ await clean();
10366
+ await (0, import_persistence2.collectRetiredEditorAssets)(rawStorage, doc, gcRef.current);
10367
+ }, [clean, rawStorage, doc]);
10368
+ const discard = (0, import_react72.useCallback)(async () => {
10369
+ await drop();
10370
+ await (0, import_persistence2.collectRetiredEditorAssets)(rawStorage, doc, gcRef.current);
10371
+ }, [drop, rawStorage, doc]);
10372
+ return { ...autosave, restore, markClean, discard };
10358
10373
  }
10359
10374
 
10360
10375
  // src/persistence/RecoveryPrompt.tsx
@@ -11334,9 +11349,10 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
11334
11349
  valueDomain: frozen?.valueDomain,
11335
11350
  valueDomain2: frozen?.valueDomain2,
11336
11351
  xDomain: frozen?.xDomain,
11337
- readout: frozen?.readout
11352
+ readout: frozen?.readout,
11353
+ raceFrame: state.raceFrame
11338
11354
  }),
11339
- [state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
11355
+ [state.spec, state.selection, state.raceFrame, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
11340
11356
  );
11341
11357
  if (sceneRef) sceneRef.current = scene;
11342
11358
  const byKey = (0, import_react83.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
@@ -11501,8 +11517,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
11501
11517
  ] })
11502
11518
  ] });
11503
11519
  }
11520
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
11521
+ const { spec } = useChartState(controller);
11522
+ const links = spec.links;
11523
+ const commit = (next) => controller.setLinks(next).ok;
11524
+ return /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", "data-chart-links-grid": "", children: [
11525
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("table", { className: "w-full border-collapse text-xs", children: [
11526
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("thead", { className: "bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("tr", { children: [
11527
+ ["Source", "Target"].map((label) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("th", { className: "border-b border-r border-border px-2 py-1 text-left font-medium text-muted-foreground", children: label }, label)),
11528
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("th", { className: "border-b border-r border-border px-2 py-1 text-right font-medium text-muted-foreground", children: "Value" }),
11529
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("th", { className: "w-8 border-b border-border" })
11530
+ ] }) }),
11531
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("tbody", { children: links.map((link, i) => /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("tr", { "data-link-row": i, children: [
11532
+ ["source", "target"].map((field) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartCommitInput, { value: link[field], "aria-label": `${field === "source" ? "Source" : "Target"} of flow ${i + 1}`, "data-link-cell": `${i}:${field}`, readOnly, onCommit: (text) => commit((0, import_chart3.setChartLinkField)(links, i, field, text)), className: `${chartCellClass} text-left` }) }, field)),
11533
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("td", { className: "border-b border-r border-border p-0", children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartCommitInput, { value: String(link.value), inputMode: "decimal", "aria-label": `Value of ${link.source} \u2192 ${link.target}`, "data-link-cell": `${i}:value`, readOnly, onCommit: (text) => commit((0, import_chart3.setChartLinkField)(links, i, "value", text)), className: chartCellClass }) }),
11534
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("td", { className: "border-b border-border px-1", children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("button", { type: "button", className: chartIconButtonClass, title: "Delete flow", "aria-label": `Delete ${link.source} \u2192 ${link.target}`, "data-action": "link-remove", onClick: () => controller.removeLink(i), children: "\xD7" }) })
11535
+ ] }, i)) })
11536
+ ] }),
11537
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("div", { className: "flex flex-wrap gap-1 p-1", children: [
11538
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "link-add", onClick: () => commit((0, import_chart3.addChartLink)(links)), children: "+ Add flow" }),
11539
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("span", { className: "flex-1" }),
11540
+ links.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("button", { type: "button", className: `${chartButtonClass} h-6`, "data-action": "links-clear", title: "Keep how much passes through each node as plain data", onClick: () => controller.setLinks([]), children: "Remove flows" })
11541
+ ] })
11542
+ ] });
11543
+ }
11504
11544
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
11505
11545
  const { spec, selection } = useChartState(controller);
11546
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartLinksGrid, { controller, readOnly, className });
11506
11547
  if (spec.tree.length) return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartTreeGrid, { controller, readOnly, className });
11507
11548
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
11508
11549
  const paste = (row, column) => (e) => {
@@ -11780,7 +11821,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
11780
11821
  ] });
11781
11822
  }
11782
11823
  function ChartInspector({ controller, sections, className }) {
11783
- const { spec, selectedSeries, selection } = useChartState(controller);
11824
+ const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
11784
11825
  const idBase = (0, import_react85.useId)();
11785
11826
  const show = (section) => !sections || sections.includes(section);
11786
11827
  const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
@@ -11851,6 +11892,27 @@ function ChartInspector({ controller, sections, className }) {
11851
11892
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
11852
11893
  }
11853
11894
  ) }),
11895
+ spec.type === "barrace" && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Bars", htmlFor: `${idBase}-race-top`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ChartCommitInput, { id: `${idBase}-race-top`, value: String(spec.raceTopN), inputMode: "numeric", "data-option": "raceTopN", className: chartInputClass, onCommit: (text) => controller.update({ raceTopN: Number(text) }).ok }) }),
11896
+ spec.type === "barrace" && spec.categories.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Time", htmlFor: `${idBase}-race-frame`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)("div", { className: "flex items-center gap-1", children: [
11897
+ /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "race-play", "aria-label": racePlaying ? "Pause the race" : "Play the race", onClick: () => racePlaying ? controller.pauseRace() : controller.playRace(), children: racePlaying ? "Pause" : "Play" }),
11898
+ /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
11899
+ "input",
11900
+ {
11901
+ id: `${idBase}-race-frame`,
11902
+ type: "range",
11903
+ min: 0,
11904
+ max: spec.categories.length - 1,
11905
+ step: 0.01,
11906
+ value: raceFrame ?? spec.categories.length - 1,
11907
+ "data-option": "raceFrame",
11908
+ "aria-valuetext": spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)],
11909
+ className: "min-w-0 flex-1 accent-primary",
11910
+ onChange: (e) => controller.setRaceFrame(Number(e.currentTarget.value))
11911
+ }
11912
+ ),
11913
+ /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("span", { className: "w-12 shrink-0 truncate text-right tabular-nums text-muted-foreground", "data-race-time": "", children: spec.categories[Math.round(raceFrame ?? spec.categories.length - 1)] })
11914
+ ] }) }),
11915
+ spec.type === "sankey" && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Flows", htmlFor: `${idBase}-sankey-color`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Select, { id: `${idBase}-sankey-color`, name: "sankeyLinkColor", value: spec.sankeyLinkColor, options: import_chart4.CHART_SANKEY_LINK_COLORS, labels: { source: "Coloured by source", target: "Coloured by target", gray: "Grey" }, onChange: (sankeyLinkColor) => controller.update({ sankeyLinkColor }) }) }),
11854
11916
  spec.type === "sunburst" && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Caption", htmlFor: `${idBase}-sunburst-label`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ChartCommitInput, { id: `${idBase}-sunburst-label`, value: spec.sunburstLabel, placeholder: "Under the total", "data-option": "sunburstLabel", className: chartInputClass, onCommit: (sunburstLabel) => controller.update({ sunburstLabel }).ok }) }),
11855
11917
  spec.type === "likert" && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Neutral", htmlFor: `${idBase}-likert-neutral`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Select, { id: `${idBase}-likert-neutral`, name: "likertNeutral", value: spec.likertNeutral, options: import_chart4.CHART_LIKERT_NEUTRALS, labels: { split: "Across the centre", separate: "In its own column" }, onChange: (likertNeutral) => controller.update({ likertNeutral }) }) }),
11856
11918
  spec.type === "likert" && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Field, { label: "Order", htmlFor: `${idBase}-likert-sort`, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Select, { id: `${idBase}-likert-sort`, name: "likertSort", value: spec.likertSort, options: import_chart4.CHART_LIKERT_SORTS, labels: { none: "As entered", positive: "Most agreement first", negative: "Most disagreement first" }, onChange: (likertSort) => controller.update({ likertSort }) }) }),
@@ -12088,6 +12150,117 @@ function createReactChartNodeView(options = {}) {
12088
12150
  };
12089
12151
  };
12090
12152
  }
12153
+
12154
+ // src/style/useStyle.ts
12155
+ var import_react86 = require("react");
12156
+ var message = (error) => error instanceof Error ? error.message : String(error);
12157
+ function useResolverTask(styles, run, deliver, deps) {
12158
+ (0, import_react86.useEffect)(() => {
12159
+ if (!styles || !run) {
12160
+ deliver({ value: null, error: null });
12161
+ return;
12162
+ }
12163
+ let latest = 0;
12164
+ let active = true;
12165
+ const go = () => {
12166
+ const call = ++latest;
12167
+ run(styles).then(
12168
+ (value) => {
12169
+ if (active && call === latest) deliver({ value, error: null });
12170
+ },
12171
+ (error) => {
12172
+ if (active && call === latest) deliver({ value: null, error: message(error) });
12173
+ }
12174
+ );
12175
+ };
12176
+ go();
12177
+ const unsubscribe = styles.subscribe(go);
12178
+ return () => {
12179
+ active = false;
12180
+ unsubscribe();
12181
+ };
12182
+ }, [styles, ...deps]);
12183
+ }
12184
+ function useStyle(styles, domain) {
12185
+ const [result, setResult] = (0, import_react86.useState)({ style: null, error: null });
12186
+ useResolverTask(
12187
+ styles,
12188
+ (s) => s.resolve(domain),
12189
+ ({ value, error }) => setResult({ style: value, error }),
12190
+ [domain]
12191
+ );
12192
+ return result;
12193
+ }
12194
+ function useStyleFindings(styles, domain, state) {
12195
+ const [result, setResult] = (0, import_react86.useState)({ report: null, style: null, error: null });
12196
+ useResolverTask(
12197
+ styles,
12198
+ (s) => s.check(domain, state),
12199
+ ({ value, error }) => {
12200
+ if (!value) setResult({ report: null, style: null, error });
12201
+ else {
12202
+ const { style, ...report } = value;
12203
+ setResult({ report, style, error: null });
12204
+ }
12205
+ },
12206
+ [domain, state]
12207
+ );
12208
+ return result;
12209
+ }
12210
+
12211
+ // src/style/StyleFindings.tsx
12212
+ var import_jsx_runtime62 = require("react/jsx-runtime");
12213
+ var SEVERITY_CLASS = {
12214
+ error: "text-destructive",
12215
+ warning: "text-amber-600",
12216
+ info: "text-muted-foreground"
12217
+ };
12218
+ function StyleFindings({ report, onSelect, title = "House style", className = "" }) {
12219
+ if (!report) return null;
12220
+ const { findings, ran, skipped } = report;
12221
+ return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("section", { "data-style-findings": "", "aria-label": title, className: `flex flex-col gap-1.5 text-xs text-foreground ${className}`, children: [
12222
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("h3", { className: "text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: title }),
12223
+ findings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("ul", { className: "flex flex-col gap-1", children: findings.map((finding, i) => {
12224
+ const selectable = finding.target !== void 0 && !!onSelect;
12225
+ const body = /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(import_jsx_runtime62.Fragment, { children: [
12226
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { "data-style-severity": finding.severity, className: `shrink-0 font-semibold uppercase text-[10px] ${SEVERITY_CLASS[finding.severity]}`, children: finding.severity }),
12227
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("span", { className: "flex min-w-0 flex-col", children: [
12228
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { "data-style-message": "", children: finding.message }),
12229
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("span", { className: "text-[10px] text-muted-foreground", children: [
12230
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("code", { children: finding.check }),
12231
+ finding.layer && /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(import_jsx_runtime62.Fragment, { children: [
12232
+ " \xB7 ",
12233
+ finding.layer
12234
+ ] })
12235
+ ] })
12236
+ ] })
12237
+ ] });
12238
+ return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("li", { "data-style-finding": finding.check, children: selectable ? /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
12239
+ "button",
12240
+ {
12241
+ type: "button",
12242
+ className: "flex w-full items-start gap-2 rounded border border-border px-2 py-1 text-left hover:bg-muted",
12243
+ onClick: () => onSelect(finding),
12244
+ children: body
12245
+ }
12246
+ ) : /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "flex items-start gap-2 rounded border border-border px-2 py-1", children: body }) }, `${finding.check}-${i}`);
12247
+ }) }),
12248
+ findings.length === 0 && ran.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("p", { "data-style-clear": "", className: "text-emerald-600", children: [
12249
+ "All clear: ",
12250
+ ran.length,
12251
+ " ",
12252
+ ran.length === 1 ? "check" : "checks",
12253
+ " passed."
12254
+ ] }),
12255
+ findings.length === 0 && ran.length === 0 && skipped.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("p", { className: "text-muted-foreground", children: "No house-style checks apply." }),
12256
+ skipped.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("ul", { "data-style-skipped": "", "aria-label": "Skipped checks", className: "flex flex-col gap-0.5 text-muted-foreground", children: skipped.map((s) => /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("li", { "data-style-skipped-check": s.check, children: [
12257
+ "Skipped ",
12258
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("code", { children: s.check }),
12259
+ ": ",
12260
+ s.reason
12261
+ ] }, s.check)) })
12262
+ ] });
12263
+ }
12091
12264
  // Annotate the CommonJS export names for ESM import in node:
12092
12265
  0 && (module.exports = {
12093
12266
  AdjustmentLayersPanel,
@@ -12138,6 +12311,7 @@ function createReactChartNodeView(options = {}) {
12138
12311
  SpreadsheetEditor,
12139
12312
  SpreadsheetGroupRow,
12140
12313
  SpreadsheetValidationDialog,
12314
+ StyleFindings,
12141
12315
  StylesGallery,
12142
12316
  TableBubbleMenu,
12143
12317
  TableToolbar,
@@ -12186,6 +12360,8 @@ function createReactChartNodeView(options = {}) {
12186
12360
  useSpreadsheetClipboard,
12187
12361
  useSpreadsheetEditor,
12188
12362
  useSpreadsheetViewport,
12363
+ useStyle,
12364
+ useStyleFindings,
12189
12365
  useTableMenu,
12190
12366
  useToolBridge,
12191
12367
  useToolRegistryView,
package/dist/index.d.cts CHANGED
@@ -36,3 +36,4 @@ export * from "./generation/index.cjs";
36
36
  export * from "./find-replace/index.cjs";
37
37
  export * from "./tables/index.cjs";
38
38
  export * from "./chart-node/index.cjs";
39
+ export * from "./style/index.cjs";
package/dist/index.d.ts CHANGED
@@ -36,3 +36,4 @@ export * from "./generation/index.js";
36
36
  export * from "./find-replace/index.js";
37
37
  export * from "./tables/index.js";
38
38
  export * from "./chart-node/index.js";
39
+ export * from "./style/index.js";
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  ChartDataGrid,
7
7
  ChartInspector,
8
8
  chartButtonClass
9
- } from "./chunk-GJ3IMZQW.js";
9
+ } from "./chunk-VTLCQXIY.js";
10
10
  import {
11
11
  FormulaHints,
12
12
  NameManager,
@@ -66,7 +66,7 @@ import {
66
66
  RecoveryPrompt,
67
67
  useAutosave,
68
68
  useEditorAutosave
69
- } from "./chunk-5YTP5RVI.js";
69
+ } from "./chunk-2JNRWM6S.js";
70
70
  import {
71
71
  AssetMentionChips,
72
72
  GenerationHistory,
@@ -2403,6 +2403,117 @@ function createReactChartNodeView(options = {}) {
2403
2403
  };
2404
2404
  };
2405
2405
  }
2406
+
2407
+ // src/style/useStyle.ts
2408
+ import { useEffect as useEffect13, useState as useState14 } from "react";
2409
+ var message = (error) => error instanceof Error ? error.message : String(error);
2410
+ function useResolverTask(styles, run, deliver, deps) {
2411
+ useEffect13(() => {
2412
+ if (!styles || !run) {
2413
+ deliver({ value: null, error: null });
2414
+ return;
2415
+ }
2416
+ let latest = 0;
2417
+ let active = true;
2418
+ const go = () => {
2419
+ const call = ++latest;
2420
+ run(styles).then(
2421
+ (value) => {
2422
+ if (active && call === latest) deliver({ value, error: null });
2423
+ },
2424
+ (error) => {
2425
+ if (active && call === latest) deliver({ value: null, error: message(error) });
2426
+ }
2427
+ );
2428
+ };
2429
+ go();
2430
+ const unsubscribe = styles.subscribe(go);
2431
+ return () => {
2432
+ active = false;
2433
+ unsubscribe();
2434
+ };
2435
+ }, [styles, ...deps]);
2436
+ }
2437
+ function useStyle(styles, domain) {
2438
+ const [result, setResult] = useState14({ style: null, error: null });
2439
+ useResolverTask(
2440
+ styles,
2441
+ (s) => s.resolve(domain),
2442
+ ({ value, error }) => setResult({ style: value, error }),
2443
+ [domain]
2444
+ );
2445
+ return result;
2446
+ }
2447
+ function useStyleFindings(styles, domain, state) {
2448
+ const [result, setResult] = useState14({ report: null, style: null, error: null });
2449
+ useResolverTask(
2450
+ styles,
2451
+ (s) => s.check(domain, state),
2452
+ ({ value, error }) => {
2453
+ if (!value) setResult({ report: null, style: null, error });
2454
+ else {
2455
+ const { style, ...report } = value;
2456
+ setResult({ report, style, error: null });
2457
+ }
2458
+ },
2459
+ [domain, state]
2460
+ );
2461
+ return result;
2462
+ }
2463
+
2464
+ // src/style/StyleFindings.tsx
2465
+ import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
2466
+ var SEVERITY_CLASS = {
2467
+ error: "text-destructive",
2468
+ warning: "text-amber-600",
2469
+ info: "text-muted-foreground"
2470
+ };
2471
+ function StyleFindings({ report, onSelect, title = "House style", className = "" }) {
2472
+ if (!report) return null;
2473
+ const { findings, ran, skipped } = report;
2474
+ return /* @__PURE__ */ jsxs14("section", { "data-style-findings": "", "aria-label": title, className: `flex flex-col gap-1.5 text-xs text-foreground ${className}`, children: [
2475
+ /* @__PURE__ */ jsx18("h3", { className: "text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: title }),
2476
+ findings.length > 0 && /* @__PURE__ */ jsx18("ul", { className: "flex flex-col gap-1", children: findings.map((finding, i) => {
2477
+ const selectable = finding.target !== void 0 && !!onSelect;
2478
+ const body = /* @__PURE__ */ jsxs14(Fragment2, { children: [
2479
+ /* @__PURE__ */ jsx18("span", { "data-style-severity": finding.severity, className: `shrink-0 font-semibold uppercase text-[10px] ${SEVERITY_CLASS[finding.severity]}`, children: finding.severity }),
2480
+ /* @__PURE__ */ jsxs14("span", { className: "flex min-w-0 flex-col", children: [
2481
+ /* @__PURE__ */ jsx18("span", { "data-style-message": "", children: finding.message }),
2482
+ /* @__PURE__ */ jsxs14("span", { className: "text-[10px] text-muted-foreground", children: [
2483
+ /* @__PURE__ */ jsx18("code", { children: finding.check }),
2484
+ finding.layer && /* @__PURE__ */ jsxs14(Fragment2, { children: [
2485
+ " \xB7 ",
2486
+ finding.layer
2487
+ ] })
2488
+ ] })
2489
+ ] })
2490
+ ] });
2491
+ return /* @__PURE__ */ jsx18("li", { "data-style-finding": finding.check, children: selectable ? /* @__PURE__ */ jsx18(
2492
+ "button",
2493
+ {
2494
+ type: "button",
2495
+ className: "flex w-full items-start gap-2 rounded border border-border px-2 py-1 text-left hover:bg-muted",
2496
+ onClick: () => onSelect(finding),
2497
+ children: body
2498
+ }
2499
+ ) : /* @__PURE__ */ jsx18("div", { className: "flex items-start gap-2 rounded border border-border px-2 py-1", children: body }) }, `${finding.check}-${i}`);
2500
+ }) }),
2501
+ findings.length === 0 && ran.length > 0 && /* @__PURE__ */ jsxs14("p", { "data-style-clear": "", className: "text-emerald-600", children: [
2502
+ "All clear: ",
2503
+ ran.length,
2504
+ " ",
2505
+ ran.length === 1 ? "check" : "checks",
2506
+ " passed."
2507
+ ] }),
2508
+ findings.length === 0 && ran.length === 0 && skipped.length === 0 && /* @__PURE__ */ jsx18("p", { className: "text-muted-foreground", children: "No house-style checks apply." }),
2509
+ skipped.length > 0 && /* @__PURE__ */ jsx18("ul", { "data-style-skipped": "", "aria-label": "Skipped checks", className: "flex flex-col gap-0.5 text-muted-foreground", children: skipped.map((s) => /* @__PURE__ */ jsxs14("li", { "data-style-skipped-check": s.check, children: [
2510
+ "Skipped ",
2511
+ /* @__PURE__ */ jsx18("code", { children: s.check }),
2512
+ ": ",
2513
+ s.reason
2514
+ ] }, s.check)) })
2515
+ ] });
2516
+ }
2406
2517
  export {
2407
2518
  AdjustmentLayersPanel,
2408
2519
  AgentPlaybackProvider,
@@ -2452,6 +2563,7 @@ export {
2452
2563
  SpreadsheetEditor,
2453
2564
  SpreadsheetGroupRow,
2454
2565
  SpreadsheetValidationDialog,
2566
+ StyleFindings,
2455
2567
  StylesGallery,
2456
2568
  TableBubbleMenu,
2457
2569
  TableToolbar,
@@ -2500,6 +2612,8 @@ export {
2500
2612
  useSpreadsheetClipboard,
2501
2613
  useSpreadsheetEditor,
2502
2614
  useSpreadsheetViewport,
2615
+ useStyle,
2616
+ useStyleFindings,
2503
2617
  useTableMenu,
2504
2618
  useToolBridge,
2505
2619
  useToolRegistryView,
@@ -133,7 +133,7 @@ function useAutosave(options) {
133
133
  // src/persistence/useEditorAutosave.ts
134
134
  var import_react2 = require("react");
135
135
  var import_persistence2 = require("@pixerate/editor/persistence");
136
- function useEditorAutosave(doc, options) {
136
+ function useEditorAutosave(doc, { collectAssetGarbage, ...options }) {
137
137
  const storage = (0, import_react2.useMemo)(
138
138
  () => doc.assets ? (0, import_persistence2.withEditorAssets)(options.storage, doc.assets) : options.storage,
139
139
  [options.storage, doc.assets]
@@ -151,7 +151,19 @@ function useEditorAutosave(doc, options) {
151
151
  const snapshot = take();
152
152
  return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
153
153
  }, [take, doc]);
154
- return { ...autosave, restore };
154
+ const { markClean: clean, discard: drop } = autosave;
155
+ const rawStorage = options.storage;
156
+ const gcRef = (0, import_react2.useRef)(collectAssetGarbage);
157
+ gcRef.current = collectAssetGarbage;
158
+ const markClean = (0, import_react2.useCallback)(async () => {
159
+ await clean();
160
+ await (0, import_persistence2.collectRetiredEditorAssets)(rawStorage, doc, gcRef.current);
161
+ }, [clean, rawStorage, doc]);
162
+ const discard = (0, import_react2.useCallback)(async () => {
163
+ await drop();
164
+ await (0, import_persistence2.collectRetiredEditorAssets)(rawStorage, doc, gcRef.current);
165
+ }, [drop, rawStorage, doc]);
166
+ return { ...autosave, restore, markClean, discard };
155
167
  }
156
168
 
157
169
  // src/persistence/RecoveryPrompt.tsx
@@ -2,7 +2,7 @@ import {
2
2
  RecoveryPrompt,
3
3
  useAutosave,
4
4
  useEditorAutosave
5
- } from "../chunk-5YTP5RVI.js";
5
+ } from "../chunk-2JNRWM6S.js";
6
6
  export {
7
7
  RecoveryPrompt,
8
8
  useAutosave,
@@ -1,8 +1,14 @@
1
- import { type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
1
+ import { type EditorAssetGarbageOptions, type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
2
2
  import { type UseAutosaveOptions, type UseAutosaveResult } from './useAutosave.cjs';
3
3
  export interface UseEditorAutosaveOptions extends Omit<UseAutosaveOptions<EditorDocumentFile>, 'key' | 'getSnapshot' | 'serialize' | 'deserialize' | 'history'> {
4
4
  /** Snapshot key (default the document's `kind`). */
5
5
  key?: string;
6
+ /**
7
+ * For documents with `assets`: after `markClean` or `discard` retire a snapshot, delete the
8
+ * stored assets nothing refers to any more (`collectEditorAssetGarbage`, best effort, keeping
9
+ * the assets the document uses now; default `true`). Needs `storage.keys`; `false` turns it off.
10
+ */
11
+ collectAssetGarbage?: boolean | Omit<EditorAssetGarbageOptions, 'dryRun' | 'only'>;
6
12
  }
7
13
  export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDocumentFile>, 'restore'> {
8
14
  /** Loads the recovered snapshot into the document and starts autosaving. */
@@ -14,4 +20,4 @@ export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDo
14
20
  * recovered snapshot straight into the editor. Render `<RecoveryPrompt>` with
15
21
  * `recovery`, `restore` and `discard`. Pass a stable `doc`.
16
22
  */
17
- export declare function useEditorAutosave(doc: EditorDocument, options: UseEditorAutosaveOptions): UseEditorAutosaveResult;
23
+ export declare function useEditorAutosave(doc: EditorDocument, { collectAssetGarbage, ...options }: UseEditorAutosaveOptions): UseEditorAutosaveResult;
@@ -1,8 +1,14 @@
1
- import { type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
1
+ import { type EditorAssetGarbageOptions, type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
2
2
  import { type UseAutosaveOptions, type UseAutosaveResult } from './useAutosave.js';
3
3
  export interface UseEditorAutosaveOptions extends Omit<UseAutosaveOptions<EditorDocumentFile>, 'key' | 'getSnapshot' | 'serialize' | 'deserialize' | 'history'> {
4
4
  /** Snapshot key (default the document's `kind`). */
5
5
  key?: string;
6
+ /**
7
+ * For documents with `assets`: after `markClean` or `discard` retire a snapshot, delete the
8
+ * stored assets nothing refers to any more (`collectEditorAssetGarbage`, best effort, keeping
9
+ * the assets the document uses now; default `true`). Needs `storage.keys`; `false` turns it off.
10
+ */
11
+ collectAssetGarbage?: boolean | Omit<EditorAssetGarbageOptions, 'dryRun' | 'only'>;
6
12
  }
7
13
  export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDocumentFile>, 'restore'> {
8
14
  /** Loads the recovered snapshot into the document and starts autosaving. */
@@ -14,4 +20,4 @@ export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDo
14
20
  * recovered snapshot straight into the editor. Render `<RecoveryPrompt>` with
15
21
  * `recovery`, `restore` and `discard`. Pass a stable `doc`.
16
22
  */
17
- export declare function useEditorAutosave(doc: EditorDocument, options: UseEditorAutosaveOptions): UseEditorAutosaveResult;
23
+ export declare function useEditorAutosave(doc: EditorDocument, { collectAssetGarbage, ...options }: UseEditorAutosaveOptions): UseEditorAutosaveResult;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { StyleCheckReport, StyleFinding } from '@pixerate/editor/tools';
3
+ export interface StyleFindingsProps {
4
+ /** A check report (`useStyleFindings(...).report`, or a `check_*_style` tool result). Renders nothing while `null`. */
5
+ report: StyleCheckReport | null | undefined;
6
+ /** Called when a finding with a `target` is clicked, e.g. to select that series in the chart. */
7
+ onSelect?: (finding: StyleFinding) => void;
8
+ /** Heading (default "House style"). */
9
+ title?: string;
10
+ className?: string;
11
+ }
12
+ /** The house-style findings for the current state, with the checks that could not run. */
13
+ export declare function StyleFindings({ report, onSelect, title, className }: StyleFindingsProps): React.JSX.Element | null;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { StyleCheckReport, StyleFinding } from '@pixerate/editor/tools';
3
+ export interface StyleFindingsProps {
4
+ /** A check report (`useStyleFindings(...).report`, or a `check_*_style` tool result). Renders nothing while `null`. */
5
+ report: StyleCheckReport | null | undefined;
6
+ /** Called when a finding with a `target` is clicked, e.g. to select that series in the chart. */
7
+ onSelect?: (finding: StyleFinding) => void;
8
+ /** Heading (default "House style"). */
9
+ title?: string;
10
+ className?: string;
11
+ }
12
+ /** The house-style findings for the current state, with the checks that could not run. */
13
+ export declare function StyleFindings({ report, onSelect, title, className }: StyleFindingsProps): React.JSX.Element | null;
@@ -0,0 +1,2 @@
1
+ export * from './useStyle.cjs';
2
+ export * from './StyleFindings.cjs';
@@ -0,0 +1,2 @@
1
+ export * from './useStyle.js';
2
+ export * from './StyleFindings.js';
@@ -0,0 +1,22 @@
1
+ import type { ResolvedStyle, StyleCheckReport, StyleResolver } from '@pixerate/editor/tools';
2
+ export interface UseStyleResult {
3
+ /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
+ style: ResolvedStyle | null;
5
+ /** Why the last resolve failed (e.g. an unknown domain), or `null`. */
6
+ error: string | null;
7
+ }
8
+ export interface UseStyleFindingsResult extends UseStyleResult {
9
+ /** The last check report for `state`, or `null` before the first check (or without a resolver). */
10
+ report: StyleCheckReport | null;
11
+ }
12
+ /**
13
+ * The house style for one domain (`chart`, `tokens`, ...), merged across the resolver's layers.
14
+ * Re-resolves when a style store or the token source changes (`styles.subscribe`).
15
+ */
16
+ export declare function useStyle(styles: StyleResolver | null | undefined, domain: string): UseStyleResult;
17
+ /**
18
+ * Runs the domain's house-style checks against `state` (e.g. a chart spec) whenever `state`
19
+ * changes by reference, the domain or resolver changes, or the resolver notifies. Results of
20
+ * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
+ */
22
+ export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
@@ -0,0 +1,22 @@
1
+ import type { ResolvedStyle, StyleCheckReport, StyleResolver } from '@pixerate/editor/tools';
2
+ export interface UseStyleResult {
3
+ /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
+ style: ResolvedStyle | null;
5
+ /** Why the last resolve failed (e.g. an unknown domain), or `null`. */
6
+ error: string | null;
7
+ }
8
+ export interface UseStyleFindingsResult extends UseStyleResult {
9
+ /** The last check report for `state`, or `null` before the first check (or without a resolver). */
10
+ report: StyleCheckReport | null;
11
+ }
12
+ /**
13
+ * The house style for one domain (`chart`, `tokens`, ...), merged across the resolver's layers.
14
+ * Re-resolves when a style store or the token source changes (`styles.subscribe`).
15
+ */
16
+ export declare function useStyle(styles: StyleResolver | null | undefined, domain: string): UseStyleResult;
17
+ /**
18
+ * Runs the domain's house-style checks against `state` (e.g. a chart spec) whenever `state`
19
+ * changes by reference, the domain or resolver changes, or the resolver notifies. Results of
20
+ * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
+ */
22
+ export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.109.0",
3
+ "version": "0.111.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -258,7 +258,7 @@
258
258
  },
259
259
  "peerDependencies": {
260
260
  "@dagrejs/dagre": "^1.1.8",
261
- "@pixerate/editor": ">=0.164.0 <1.0.0-0",
261
+ "@pixerate/editor": ">=0.166.0 <1.0.0-0",
262
262
  "@tiptap/core": "^2.27.3",
263
263
  "@tiptap/pm": "^2.27.3",
264
264
  "@tiptap/react": "^2.27.3",
@@ -285,7 +285,7 @@
285
285
  "tsup": "^9.0.0",
286
286
  "typescript": "^5.7.3",
287
287
  "vitest": "^5.0.5",
288
- "@pixerate/editor": "0.164.0"
288
+ "@pixerate/editor": "0.166.0"
289
289
  },
290
290
  "scripts": {
291
291
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",