@pixerate/editor-react 0.109.0 → 0.110.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,
@@ -403,8 +404,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
403
404
  ] })
404
405
  ] });
405
406
  }
407
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
408
+ const { spec } = useChartState(controller);
409
+ const links = spec.links;
410
+ const commit = (next) => controller.setLinks(next).ok;
411
+ 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: [
412
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { className: "w-full border-collapse text-xs", children: [
413
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { className: "bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
414
+ ["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)),
415
+ /* @__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" }),
416
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-8 border-b border-border" })
417
+ ] }) }),
418
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tbody", { children: links.map((link, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { "data-link-row": i, children: [
419
+ ["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)),
420
+ /* @__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 }) }),
421
+ !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" }) })
422
+ ] }, i)) })
423
+ ] }),
424
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-wrap gap-1 p-1", children: [
425
+ /* @__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" }),
426
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "flex-1" }),
427
+ 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" })
428
+ ] })
429
+ ] });
430
+ }
406
431
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
407
432
  const { spec, selection } = useChartState(controller);
433
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLinksGrid, { controller, readOnly, className });
408
434
  if (spec.tree.length) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartTreeGrid, { controller, readOnly, className });
409
435
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
410
436
  const paste = (row, column) => (e) => {
@@ -753,6 +779,7 @@ function ChartInspector({ controller, sections, className }) {
753
779
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
754
780
  }
755
781
  ) }),
782
+ 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
783
  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
784
  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
785
  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 +1188,7 @@ function ChartSparkline({ values, width = 80, height = 20, label, className, ...
1161
1188
  ChartDataGrid,
1162
1189
  ChartEditor,
1163
1190
  ChartInspector,
1191
+ ChartLinksGrid,
1164
1192
  ChartPresenceLayer,
1165
1193
  ChartSceneSvg,
1166
1194
  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-MST2H6JB.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
@@ -272,6 +272,7 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
272
272
  // src/chart/ChartDataGrid.tsx
273
273
  import { useEffect as useEffect3, useRef as useRef3, useState as useState2 } from "react";
274
274
  import {
275
+ addChartLink,
275
276
  addChartTreeRow,
276
277
  chartColorInputValue,
277
278
  chartSeriesColor,
@@ -281,6 +282,7 @@ import {
281
282
  chartTreeToRows,
282
283
  formatChartNumber,
283
284
  removeChartTreeRow,
285
+ setChartLinkField,
284
286
  setChartTreeRowName,
285
287
  setChartTreeRowValue
286
288
  } from "@pixerate/editor/chart";
@@ -374,8 +376,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
374
376
  ] })
375
377
  ] });
376
378
  }
379
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
380
+ const { spec } = useChartState(controller);
381
+ const links = spec.links;
382
+ const commit = (next) => controller.setLinks(next).ok;
383
+ return /* @__PURE__ */ jsxs2("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", "data-chart-links-grid": "", children: [
384
+ /* @__PURE__ */ jsxs2("table", { className: "w-full border-collapse text-xs", children: [
385
+ /* @__PURE__ */ jsx2("thead", { className: "bg-muted/50", children: /* @__PURE__ */ jsxs2("tr", { children: [
386
+ ["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)),
387
+ /* @__PURE__ */ jsx2("th", { className: "border-b border-r border-border px-2 py-1 text-right font-medium text-muted-foreground", children: "Value" }),
388
+ !readOnly && /* @__PURE__ */ jsx2("th", { className: "w-8 border-b border-border" })
389
+ ] }) }),
390
+ /* @__PURE__ */ jsx2("tbody", { children: links.map((link, i) => /* @__PURE__ */ jsxs2("tr", { "data-link-row": i, children: [
391
+ ["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)),
392
+ /* @__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 }) }),
393
+ !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" }) })
394
+ ] }, i)) })
395
+ ] }),
396
+ !readOnly && /* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap gap-1 p-1", children: [
397
+ /* @__PURE__ */ jsx2("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "link-add", onClick: () => commit(addChartLink(links)), children: "+ Add flow" }),
398
+ /* @__PURE__ */ jsx2("span", { className: "flex-1" }),
399
+ 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" })
400
+ ] })
401
+ ] });
402
+ }
377
403
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
378
404
  const { spec, selection } = useChartState(controller);
405
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ jsx2(ChartLinksGrid, { controller, readOnly, className });
379
406
  if (spec.tree.length) return /* @__PURE__ */ jsx2(ChartTreeGrid, { controller, readOnly, className });
380
407
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
381
408
  const paste = (row, column) => (e) => {
@@ -505,6 +532,7 @@ import {
505
532
  chartTrendlineName,
506
533
  CHART_CURVES,
507
534
  CHART_RADAR_GRATICULES,
535
+ CHART_SANKEY_LINK_COLORS,
508
536
  CHART_LEGEND_POSITIONS,
509
537
  CHART_LIKERT_NEUTRALS,
510
538
  CHART_LIKERT_SORTS,
@@ -756,6 +784,7 @@ function ChartInspector({ controller, sections, className }) {
756
784
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
757
785
  }
758
786
  ) }),
787
+ 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
788
  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
789
  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
790
  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 +972,7 @@ export {
943
972
  chartCellClass,
944
973
  ChartCommitInput,
945
974
  ChartTreeGrid,
975
+ ChartLinksGrid,
946
976
  ChartDataGrid,
947
977
  ChartInspector
948
978
  };
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
@@ -11501,8 +11516,33 @@ function ChartTreeGrid({ controller, readOnly = false, className }) {
11501
11516
  ] })
11502
11517
  ] });
11503
11518
  }
11519
+ function ChartLinksGrid({ controller, readOnly = false, className }) {
11520
+ const { spec } = useChartState(controller);
11521
+ const links = spec.links;
11522
+ const commit = (next) => controller.setLinks(next).ok;
11523
+ 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: [
11524
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("table", { className: "w-full border-collapse text-xs", children: [
11525
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("thead", { className: "bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("tr", { children: [
11526
+ ["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)),
11527
+ /* @__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" }),
11528
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("th", { className: "w-8 border-b border-border" })
11529
+ ] }) }),
11530
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("tbody", { children: links.map((link, i) => /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("tr", { "data-link-row": i, children: [
11531
+ ["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)),
11532
+ /* @__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 }) }),
11533
+ !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" }) })
11534
+ ] }, i)) })
11535
+ ] }),
11536
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("div", { className: "flex flex-wrap gap-1 p-1", children: [
11537
+ /* @__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" }),
11538
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("span", { className: "flex-1" }),
11539
+ 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" })
11540
+ ] })
11541
+ ] });
11542
+ }
11504
11543
  function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
11505
11544
  const { spec, selection } = useChartState(controller);
11545
+ if (spec.links.length || spec.type === "sankey") return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartLinksGrid, { controller, readOnly, className });
11506
11546
  if (spec.tree.length) return /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ChartTreeGrid, { controller, readOnly, className });
11507
11547
  const canGroup = spec.type === "treemap" || spec.type === "sunburst";
11508
11548
  const paste = (row, column) => (e) => {
@@ -11851,6 +11891,7 @@ function ChartInspector({ controller, sections, className }) {
11851
11891
  onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
11852
11892
  }
11853
11893
  ) }),
11894
+ 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
11895
  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
11896
  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
11897
  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 +12129,117 @@ function createReactChartNodeView(options = {}) {
12088
12129
  };
12089
12130
  };
12090
12131
  }
12132
+
12133
+ // src/style/useStyle.ts
12134
+ var import_react86 = require("react");
12135
+ var message = (error) => error instanceof Error ? error.message : String(error);
12136
+ function useResolverTask(styles, run, deliver, deps) {
12137
+ (0, import_react86.useEffect)(() => {
12138
+ if (!styles || !run) {
12139
+ deliver({ value: null, error: null });
12140
+ return;
12141
+ }
12142
+ let latest = 0;
12143
+ let active = true;
12144
+ const go = () => {
12145
+ const call = ++latest;
12146
+ run(styles).then(
12147
+ (value) => {
12148
+ if (active && call === latest) deliver({ value, error: null });
12149
+ },
12150
+ (error) => {
12151
+ if (active && call === latest) deliver({ value: null, error: message(error) });
12152
+ }
12153
+ );
12154
+ };
12155
+ go();
12156
+ const unsubscribe = styles.subscribe(go);
12157
+ return () => {
12158
+ active = false;
12159
+ unsubscribe();
12160
+ };
12161
+ }, [styles, ...deps]);
12162
+ }
12163
+ function useStyle(styles, domain) {
12164
+ const [result, setResult] = (0, import_react86.useState)({ style: null, error: null });
12165
+ useResolverTask(
12166
+ styles,
12167
+ (s) => s.resolve(domain),
12168
+ ({ value, error }) => setResult({ style: value, error }),
12169
+ [domain]
12170
+ );
12171
+ return result;
12172
+ }
12173
+ function useStyleFindings(styles, domain, state) {
12174
+ const [result, setResult] = (0, import_react86.useState)({ report: null, style: null, error: null });
12175
+ useResolverTask(
12176
+ styles,
12177
+ (s) => s.check(domain, state),
12178
+ ({ value, error }) => {
12179
+ if (!value) setResult({ report: null, style: null, error });
12180
+ else {
12181
+ const { style, ...report } = value;
12182
+ setResult({ report, style, error: null });
12183
+ }
12184
+ },
12185
+ [domain, state]
12186
+ );
12187
+ return result;
12188
+ }
12189
+
12190
+ // src/style/StyleFindings.tsx
12191
+ var import_jsx_runtime62 = require("react/jsx-runtime");
12192
+ var SEVERITY_CLASS = {
12193
+ error: "text-destructive",
12194
+ warning: "text-amber-600",
12195
+ info: "text-muted-foreground"
12196
+ };
12197
+ function StyleFindings({ report, onSelect, title = "House style", className = "" }) {
12198
+ if (!report) return null;
12199
+ const { findings, ran, skipped } = report;
12200
+ 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: [
12201
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("h3", { className: "text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: title }),
12202
+ findings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("ul", { className: "flex flex-col gap-1", children: findings.map((finding, i) => {
12203
+ const selectable = finding.target !== void 0 && !!onSelect;
12204
+ const body = /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(import_jsx_runtime62.Fragment, { children: [
12205
+ /* @__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 }),
12206
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("span", { className: "flex min-w-0 flex-col", children: [
12207
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { "data-style-message": "", children: finding.message }),
12208
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("span", { className: "text-[10px] text-muted-foreground", children: [
12209
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("code", { children: finding.check }),
12210
+ finding.layer && /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(import_jsx_runtime62.Fragment, { children: [
12211
+ " \xB7 ",
12212
+ finding.layer
12213
+ ] })
12214
+ ] })
12215
+ ] })
12216
+ ] });
12217
+ return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("li", { "data-style-finding": finding.check, children: selectable ? /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
12218
+ "button",
12219
+ {
12220
+ type: "button",
12221
+ className: "flex w-full items-start gap-2 rounded border border-border px-2 py-1 text-left hover:bg-muted",
12222
+ onClick: () => onSelect(finding),
12223
+ children: body
12224
+ }
12225
+ ) : /* @__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}`);
12226
+ }) }),
12227
+ findings.length === 0 && ran.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("p", { "data-style-clear": "", className: "text-emerald-600", children: [
12228
+ "All clear: ",
12229
+ ran.length,
12230
+ " ",
12231
+ ran.length === 1 ? "check" : "checks",
12232
+ " passed."
12233
+ ] }),
12234
+ 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." }),
12235
+ 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: [
12236
+ "Skipped ",
12237
+ /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("code", { children: s.check }),
12238
+ ": ",
12239
+ s.reason
12240
+ ] }, s.check)) })
12241
+ ] });
12242
+ }
12091
12243
  // Annotate the CommonJS export names for ESM import in node:
12092
12244
  0 && (module.exports = {
12093
12245
  AdjustmentLayersPanel,
@@ -12138,6 +12290,7 @@ function createReactChartNodeView(options = {}) {
12138
12290
  SpreadsheetEditor,
12139
12291
  SpreadsheetGroupRow,
12140
12292
  SpreadsheetValidationDialog,
12293
+ StyleFindings,
12141
12294
  StylesGallery,
12142
12295
  TableBubbleMenu,
12143
12296
  TableToolbar,
@@ -12186,6 +12339,8 @@ function createReactChartNodeView(options = {}) {
12186
12339
  useSpreadsheetClipboard,
12187
12340
  useSpreadsheetEditor,
12188
12341
  useSpreadsheetViewport,
12342
+ useStyle,
12343
+ useStyleFindings,
12189
12344
  useTableMenu,
12190
12345
  useToolBridge,
12191
12346
  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-MST2H6JB.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.110.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.165.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.165.0"
289
289
  },
290
290
  "scripts": {
291
291
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",