@pixerate/editor-react 0.108.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.
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.108.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.163.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.163.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",