@pixerate/editor-react 0.94.0 → 0.95.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/README.md CHANGED
@@ -99,7 +99,7 @@ useAgentToolProvider(registry, provider);
99
99
  | `@pixerate/editor-react/image-editor` | `ImageEditor`, `useImageEditor`: crop, rotate/flip, adjustments, annotations, depth masks, Select & Mask (`SelectionOptionsBar`, `RefineEdgePanel`: magic wand, marquees, lasso, Refine Edge, layer masks), and `onInpaint` / `onRemoveBackground` AI hooks |
100
100
  | `@pixerate/editor-react/paint-editor` | `PaintEditor`, `usePaintEditor`: natural-media painting with `PaintCanvas` (pen pressure, tilt and twist, coalesced and predicted events, palm rejection, view rotation and mirroring), `PaintToolbar` (tools, symmetry, perspective, tracing and reference images, save / open, PNG / JPEG / PSD), `BrushPanel` (library with thumbnails), `PaperPanel`, `ColorPanel` (wheel, harmonies, swatches, mixing pad) and `PaintLayersPanel` |
101
101
  | `@pixerate/editor-react/commands` | `CommandPalette`, `useCommandPalette` (`hotkey: "Mod+K"`), `useCommandShortcuts`, `useRegisterCommands` over a `CommandRegistry` from `@pixerate/editor/commands` (also re-exported from the root entry) |
102
- | `@pixerate/editor-react/persistence` | `useAutosave` (crash-recovery snapshots bound to a history / dirty flag, flushed on `pagehide`, with a recovery check on mount) and `<RecoveryPrompt>` (also re-exported from the root entry) |
102
+ | `@pixerate/editor-react/persistence` | `useAutosave` (crash-recovery snapshots bound to a history / dirty flag, flushed on `pagehide`, with a recovery check on mount), `useEditorAutosave` (the same for any editor's `EditorDocument`, e.g. `useMermaidDiagram().editorDocument`; `restore` loads the snapshot into the editor) and `<RecoveryPrompt>` (also re-exported from the root entry) |
103
103
  | `@pixerate/editor-react/generation` | `GenerationSettings` (controls generated from a model's capabilities, reference slots by role, plan adjustments), `useGenerationPlan`, `JobProgress`, `useJobProgress` over `@pixerate/editor/generation` (also re-exported from the root entry) |
104
104
  | `@pixerate/editor-react/vector` | `VectorEditor` (toolbar, canvas and style panel), `VectorCanvas` (SVG canvas forwarding pointer, wheel, keyboard and clipboard events), `VectorToolbar`, `VectorStylePanel`, `VectorSceneNodes`, `VectorGradientDefs`, `useVectorEditor`, `useVectorEditorController`, `useVectorEditorState` and `useVectorCommands` over `@pixerate/editor/vector` (see [the vector editor guide](../../docs/vector-editor.md)) |
105
105
  | `@pixerate/editor-react/chart` | `ChartEditor` (toolbar, chart, inspector and data grid), `ChartCanvas` (SVG chart with selection, drag-to-edit and keyboard editing), `ChartDataGrid`, `ChartInspector`, `useChartEditor`, `useChartController`, `useChartState` and `useChartCommands` over `@pixerate/editor/chart` (see [the chart editor guide](../../docs/chart-editor.md)) |
@@ -3640,6 +3640,8 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3640
3640
  const layoutOptions = (controllerOrOptions instanceof import_diagram.DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
3641
3641
  const sceneTheme = (controllerOrOptions instanceof import_diagram.DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
3642
3642
  const state = useDiagramState(controller);
3643
+ const editorDocument = (0, import_react32.useMemo)(() => (0, import_diagram.createDiagramEditorDocument)(controller), [controller]);
3644
+ (0, import_react32.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
3643
3645
  const canvas = (0, import_react32.useMemo)(
3644
3646
  () => (0, import_canvas24.mermaidToCanvas)(state.document, { ...layoutOptions, editable: state.editable }),
3645
3647
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -3685,7 +3687,7 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3685
3687
  }),
3686
3688
  [controller]
3687
3689
  );
3688
- return { controller, state, document: state.document, source: state.source, ...canvas, scene, ...actions };
3690
+ return { controller, editorDocument, state, document: state.document, source: state.source, ...canvas, scene, ...actions };
3689
3691
  }
3690
3692
  function useMermaidStream(source, options = {}) {
3691
3693
  const { complete = false, duration = 300, ...layoutOptions } = options;
@@ -2997,7 +2997,8 @@ function MermaidFamilyScene({
2997
2997
  // src/canvas/useMermaidDiagram.ts
2998
2998
  import { useEffect as useEffect12, useMemo as useMemo12, useRef as useRef18, useState as useState10, useSyncExternalStore as useSyncExternalStore4 } from "react";
2999
2999
  import {
3000
- DiagramController
3000
+ DiagramController,
3001
+ createDiagramEditorDocument
3001
3002
  } from "@pixerate/editor/diagram";
3002
3003
  import {
3003
3004
  CSS_VARIABLE_DIAGRAM_SCENE_THEME,
@@ -3023,6 +3024,8 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3023
3024
  const layoutOptions = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
3024
3025
  const sceneTheme = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
3025
3026
  const state = useDiagramState(controller);
3027
+ const editorDocument = useMemo12(() => createDiagramEditorDocument(controller), [controller]);
3028
+ useEffect12(() => () => editorDocument.destroy(), [editorDocument]);
3026
3029
  const canvas = useMemo12(
3027
3030
  () => mermaidToCanvas(state.document, { ...layoutOptions, editable: state.editable }),
3028
3031
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -3068,7 +3071,7 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3068
3071
  }),
3069
3072
  [controller]
3070
3073
  );
3071
- return { controller, state, document: state.document, source: state.source, ...canvas, scene, ...actions };
3074
+ return { controller, editorDocument, state, document: state.document, source: state.source, ...canvas, scene, ...actions };
3072
3075
  }
3073
3076
  function useMermaidStream(source, options = {}) {
3074
3077
  const { complete = false, duration = 300, ...layoutOptions } = options;
@@ -1,4 +1,5 @@
1
- import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type MermaidDocument } from '@pixerate/editor/diagram';
1
+ import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type DiagramEditorDocument, type MermaidDocument } from '@pixerate/editor/diagram';
2
+ import type { EditorDocument } from '@pixerate/editor/persistence';
2
3
  import { type DiagramLayout, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
3
4
  export interface UseMermaidDiagramOptions extends DiagramControllerOptions {
4
5
  /** Layout spacing and node measuring for new nodes (stored positions always win). */
@@ -16,6 +17,11 @@ type Placed = {
16
17
  };
17
18
  export interface UseMermaidDiagramResult {
18
19
  controller: DiagramController;
20
+ /**
21
+ * The save / load / undo contract for this diagram: pass it to `useEditorAutosave`
22
+ * (`@pixerate/editor-react/persistence`) or `createDocumentToolProvider`.
23
+ */
24
+ editorDocument: EditorDocument<DiagramEditorDocument>;
19
25
  state: DiagramState;
20
26
  document: MermaidDocument;
21
27
  /** The Mermaid text (with the `%% @pixerate` layout comment). */
@@ -1,4 +1,5 @@
1
- import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type MermaidDocument } from '@pixerate/editor/diagram';
1
+ import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type DiagramEditorDocument, type MermaidDocument } from '@pixerate/editor/diagram';
2
+ import type { EditorDocument } from '@pixerate/editor/persistence';
2
3
  import { type DiagramLayout, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
3
4
  export interface UseMermaidDiagramOptions extends DiagramControllerOptions {
4
5
  /** Layout spacing and node measuring for new nodes (stored positions always win). */
@@ -16,6 +17,11 @@ type Placed = {
16
17
  };
17
18
  export interface UseMermaidDiagramResult {
18
19
  controller: DiagramController;
20
+ /**
21
+ * The save / load / undo contract for this diagram: pass it to `useEditorAutosave`
22
+ * (`@pixerate/editor-react/persistence`) or `createDocumentToolProvider`.
23
+ */
24
+ editorDocument: EditorDocument<DiagramEditorDocument>;
19
25
  state: DiagramState;
20
26
  document: MermaidDocument;
21
27
  /** The Mermaid text (with the `%% @pixerate` layout comment). */
@@ -105,6 +105,28 @@ function useAutosave(options) {
105
105
  return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
106
106
  }
107
107
 
108
+ // src/persistence/useEditorAutosave.ts
109
+ import { useCallback as useCallback2 } from "react";
110
+ import {
111
+ parseEditorDocument,
112
+ toEditorDocumentFile
113
+ } from "@pixerate/editor/persistence";
114
+ function useEditorAutosave(doc, options) {
115
+ const autosave = useAutosave({
116
+ ...options,
117
+ key: options.key ?? doc.kind,
118
+ getSnapshot: () => toEditorDocumentFile(doc),
119
+ deserialize: (text) => parseEditorDocument(text, { kind: doc.kind }),
120
+ history: doc
121
+ });
122
+ const take = autosave.restore;
123
+ const restore = useCallback2(() => {
124
+ const snapshot = take();
125
+ return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
126
+ }, [take, doc]);
127
+ return { ...autosave, restore };
128
+ }
129
+
108
130
  // src/persistence/RecoveryPrompt.tsx
109
131
  import { formatRecoveryMessage } from "@pixerate/editor/persistence";
110
132
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -162,5 +184,6 @@ var RecoveryPrompt = ({
162
184
 
163
185
  export {
164
186
  useAutosave,
187
+ useEditorAutosave,
165
188
  RecoveryPrompt
166
189
  };
package/dist/index.cjs CHANGED
@@ -98,6 +98,7 @@ __export(src_exports, {
98
98
  useDocumentCompare: () => useDocumentCompare,
99
99
  useDocxExport: () => useDocxExport,
100
100
  useEditor: () => useEditor2,
101
+ useEditorAutosave: () => useEditorAutosave,
101
102
  useEditorSlots: () => useEditorSlots,
102
103
  useElementPlaybackSurface: () => useElementPlaybackSurface,
103
104
  useFileImport: () => useFileImport,
@@ -9146,8 +9147,27 @@ function useAutosave(options) {
9146
9147
  return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
9147
9148
  }
9148
9149
 
9149
- // src/persistence/RecoveryPrompt.tsx
9150
+ // src/persistence/useEditorAutosave.ts
9151
+ var import_react67 = require("react");
9150
9152
  var import_persistence2 = require("@pixerate/editor/persistence");
9153
+ function useEditorAutosave(doc, options) {
9154
+ const autosave = useAutosave({
9155
+ ...options,
9156
+ key: options.key ?? doc.kind,
9157
+ getSnapshot: () => (0, import_persistence2.toEditorDocumentFile)(doc),
9158
+ deserialize: (text) => (0, import_persistence2.parseEditorDocument)(text, { kind: doc.kind }),
9159
+ history: doc
9160
+ });
9161
+ const take = autosave.restore;
9162
+ const restore = (0, import_react67.useCallback)(() => {
9163
+ const snapshot = take();
9164
+ return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
9165
+ }, [take, doc]);
9166
+ return { ...autosave, restore };
9167
+ }
9168
+
9169
+ // src/persistence/RecoveryPrompt.tsx
9170
+ var import_persistence3 = require("@pixerate/editor/persistence");
9151
9171
  var import_jsx_runtime45 = require("react/jsx-runtime");
9152
9172
  var RecoveryPrompt = ({
9153
9173
  recovery,
@@ -9169,7 +9189,7 @@ var RecoveryPrompt = ({
9169
9189
  className: `flex flex-wrap items-center gap-3 rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground shadow-sm ${className}`,
9170
9190
  children: [
9171
9191
  /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { className: "min-w-0 flex-1", children: [
9172
- (0, import_persistence2.formatRecoveryMessage)(recovery.meta, formatTime),
9192
+ (0, import_persistence3.formatRecoveryMessage)(recovery.meta, formatTime),
9173
9193
  name ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { className: "ml-1 text-xs text-muted-foreground", children: [
9174
9194
  "(",
9175
9195
  name,
@@ -9202,17 +9222,17 @@ var RecoveryPrompt = ({
9202
9222
  };
9203
9223
 
9204
9224
  // src/generation/useGenerationPlan.ts
9205
- var import_react67 = require("react");
9225
+ var import_react68 = require("react");
9206
9226
  var import_generation = require("@pixerate/editor/generation");
9207
9227
  function useGenerationPlan(request, capabilities, options = {}) {
9208
9228
  const key = JSON.stringify([request, capabilities, options]);
9209
- return (0, import_react67.useMemo)(() => (0, import_generation.planGenerationRequest)(request, capabilities, options), [key]);
9229
+ return (0, import_react68.useMemo)(() => (0, import_generation.planGenerationRequest)(request, capabilities, options), [key]);
9210
9230
  }
9211
9231
  function useJobProgress(options) {
9212
9232
  const { startedAt, expectedMs, done, now, intervalMs = 1e3 } = options;
9213
- const [tick, setTick] = (0, import_react67.useState)(() => Date.now());
9233
+ const [tick, setTick] = (0, import_react68.useState)(() => Date.now());
9214
9234
  const ticking = !done && now === void 0;
9215
- (0, import_react67.useEffect)(() => {
9235
+ (0, import_react68.useEffect)(() => {
9216
9236
  if (!ticking) return;
9217
9237
  setTick(Date.now());
9218
9238
  const id = setInterval(() => setTick(Date.now()), Math.max(16, intervalMs));
@@ -9222,7 +9242,7 @@ function useJobProgress(options) {
9222
9242
  }
9223
9243
 
9224
9244
  // src/generation/GenerationSettings.tsx
9225
- var import_react68 = require("react");
9245
+ var import_react69 = require("react");
9226
9246
  var import_generation2 = require("@pixerate/editor/generation");
9227
9247
  var import_jsx_runtime46 = require("react/jsx-runtime");
9228
9248
  var inputClass2 = "w-full rounded-md border border-border bg-background px-2 py-1 text-sm outline-none focus:ring-1 focus:ring-ring";
@@ -9305,8 +9325,8 @@ var GenerationSettings = ({
9305
9325
  renderReference,
9306
9326
  className = ""
9307
9327
  }) => {
9308
- const baseId = (0, import_react68.useId)();
9309
- const controls = (0, import_react68.useMemo)(() => (0, import_generation2.getGenerationControls)(capabilities), [capabilities]);
9328
+ const baseId = (0, import_react69.useId)();
9329
+ const controls = (0, import_react69.useMemo)(() => (0, import_generation2.getGenerationControls)(capabilities), [capabilities]);
9310
9330
  const computed = useGenerationPlan(value, capabilities, { strategy });
9311
9331
  const plan = planProp ?? computed;
9312
9332
  const slots = (0, import_generation2.getReferenceSlots)(capabilities, value);
@@ -9401,7 +9421,7 @@ var JobProgress = ({ title, className = "", ...options }) => {
9401
9421
  };
9402
9422
 
9403
9423
  // src/generation/AssetMentionChips.tsx
9404
- var import_react69 = require("react");
9424
+ var import_react70 = require("react");
9405
9425
  var import_generation3 = require("@pixerate/editor/generation");
9406
9426
  var import_jsx_runtime48 = require("react/jsx-runtime");
9407
9427
  var AssetMentionChips = ({
@@ -9413,14 +9433,14 @@ var AssetMentionChips = ({
9413
9433
  renderAsset,
9414
9434
  className = ""
9415
9435
  }) => {
9416
- const [open, setOpen] = (0, import_react69.useState)(null);
9417
- const rootRef = (0, import_react69.useRef)(null);
9418
- const chips = (0, import_react69.useMemo)(
9436
+ const [open, setOpen] = (0, import_react70.useState)(null);
9437
+ const rootRef = (0, import_react70.useRef)(null);
9438
+ const chips = (0, import_react70.useMemo)(
9419
9439
  () => (0, import_generation3.describeAssetMentions)((0, import_generation3.findTextMentions)(content), assets, capabilities),
9420
9440
  [content, assets, capabilities]
9421
9441
  );
9422
9442
  const options = roles ?? (capabilities ? (0, import_generation3.getAssetRoleOptions)(capabilities) : (0, import_generation3.defaultAssetRoleOptions)());
9423
- (0, import_react69.useEffect)(() => {
9443
+ (0, import_react70.useEffect)(() => {
9424
9444
  if (open === null) return;
9425
9445
  const onPointer = (event) => {
9426
9446
  if (!rootRef.current?.contains(event.target)) setOpen(null);
@@ -9515,15 +9535,15 @@ var AssetMentionChips = ({
9515
9535
  };
9516
9536
 
9517
9537
  // src/generation/GenerationHistory.tsx
9518
- var import_react70 = require("react");
9538
+ var import_react71 = require("react");
9519
9539
  var import_generation4 = require("@pixerate/editor/generation");
9520
9540
  var import_jsx_runtime49 = require("react/jsx-runtime");
9521
9541
  function useGenerationRecords(store, filter) {
9522
- const [records, setRecords] = (0, import_react70.useState)([]);
9523
- const [loading, setLoading] = (0, import_react70.useState)(!!store);
9524
- const [error, setError] = (0, import_react70.useState)(null);
9542
+ const [records, setRecords] = (0, import_react71.useState)([]);
9543
+ const [loading, setLoading] = (0, import_react71.useState)(!!store);
9544
+ const [error, setError] = (0, import_react71.useState)(null);
9525
9545
  const filterKey = (0, import_generation4.stableStringify)(filter ?? {});
9526
- const refresh = (0, import_react70.useCallback)(async () => {
9546
+ const refresh = (0, import_react71.useCallback)(async () => {
9527
9547
  if (!store) {
9528
9548
  setRecords([]);
9529
9549
  setLoading(false);
@@ -9540,7 +9560,7 @@ function useGenerationRecords(store, filter) {
9540
9560
  setLoading(false);
9541
9561
  }
9542
9562
  }, [store, filterKey]);
9543
- (0, import_react70.useEffect)(() => {
9563
+ (0, import_react71.useEffect)(() => {
9544
9564
  void refresh();
9545
9565
  if (!store) return;
9546
9566
  return store.subscribe(() => void refresh());
@@ -9566,15 +9586,15 @@ var GenerationHistory = ({
9566
9586
  emptyText = "No generations yet.",
9567
9587
  className = ""
9568
9588
  }) => {
9569
- const [innerMode, setInnerMode] = (0, import_react70.useState)("exact");
9589
+ const [innerMode, setInnerMode] = (0, import_react71.useState)("exact");
9570
9590
  const mode = modeProp ?? innerMode;
9571
9591
  const setMode = (next) => {
9572
9592
  if (modeProp === void 0) setInnerMode(next);
9573
9593
  onModeChange?.(next);
9574
9594
  };
9575
- const options = (0, import_react70.useMemo)(() => ({ templates, capabilities, assets, mode }), [templates, capabilities, assets, mode]);
9576
- const results = (0, import_react70.useMemo)(() => records.map((record) => (0, import_generation4.recreateRequest)(record, options)), [records, options]);
9577
- const models = (0, import_react70.useMemo)(
9595
+ const options = (0, import_react71.useMemo)(() => ({ templates, capabilities, assets, mode }), [templates, capabilities, assets, mode]);
9596
+ const results = (0, import_react71.useMemo)(() => records.map((record) => (0, import_generation4.recreateRequest)(record, options)), [records, options]);
9597
+ const models = (0, import_react71.useMemo)(
9578
9598
  () => capabilities ? Array.isArray(capabilities) ? capabilities : [capabilities] : [],
9579
9599
  [capabilities]
9580
9600
  );
@@ -9685,19 +9705,19 @@ var GenerationHistory = ({
9685
9705
  };
9686
9706
 
9687
9707
  // src/find-replace/useFindReplace.ts
9688
- var import_react71 = require("react");
9708
+ var import_react72 = require("react");
9689
9709
  var import_editor16 = require("@pixerate/editor");
9690
9710
  var noopUnsubscribe2 = () => {
9691
9711
  };
9692
9712
  function useFindReplace(editor) {
9693
9713
  const store = (0, import_editor16.getFindReplaceStore)(editor ?? null);
9694
- const subscribe = (0, import_react71.useCallback)(
9714
+ const subscribe = (0, import_react72.useCallback)(
9695
9715
  (onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe2,
9696
9716
  [store]
9697
9717
  );
9698
9718
  const getSnapshot = () => store?.getSnapshot() ?? import_editor16.EMPTY_FIND_REPLACE_SNAPSHOT;
9699
- const snapshot = (0, import_react71.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
9700
- return (0, import_react71.useMemo)(() => {
9719
+ const snapshot = (0, import_react72.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
9720
+ return (0, import_react72.useMemo)(() => {
9701
9721
  const run = (fn) => {
9702
9722
  if (editor && !editor.isDestroyed && store) fn(editor);
9703
9723
  };
@@ -9721,7 +9741,7 @@ function useFindReplace(editor) {
9721
9741
  }
9722
9742
 
9723
9743
  // src/find-replace/FindReplaceBar.tsx
9724
- var import_react72 = require("react");
9744
+ var import_react73 = require("react");
9725
9745
  var import_editor17 = require("@pixerate/editor");
9726
9746
  var import_jsx_runtime50 = require("react/jsx-runtime");
9727
9747
  var inputClass3 = "min-w-0 flex-1 rounded border border-input bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring";
@@ -9736,10 +9756,10 @@ var FindReplaceBar = ({
9736
9756
  onClose
9737
9757
  }) => {
9738
9758
  const find = useFindReplace(editor);
9739
- const findInput = (0, import_react72.useRef)(null);
9740
- const [moreOpen, setMoreOpen] = (0, import_react72.useState)(false);
9759
+ const findInput = (0, import_react73.useRef)(null);
9760
+ const [moreOpen, setMoreOpen] = (0, import_react73.useState)(false);
9741
9761
  const visible = find.available && (alwaysOpen || find.open);
9742
- (0, import_react72.useEffect)(() => {
9762
+ (0, import_react73.useEffect)(() => {
9743
9763
  if (!visible || find.focusRequest === 0) return;
9744
9764
  findInput.current?.focus();
9745
9765
  findInput.current?.select();
@@ -9883,12 +9903,12 @@ var FindReplaceBar = ({
9883
9903
  };
9884
9904
 
9885
9905
  // src/tables/useTableMenu.ts
9886
- var import_react73 = require("react");
9906
+ var import_react74 = require("react");
9887
9907
  var import_editor18 = require("@pixerate/editor");
9888
9908
  function useTableMenu(editor) {
9889
- const store = (0, import_react73.useMemo)(() => (0, import_editor18.createTableStore)(editor), [editor]);
9890
- const snapshot = (0, import_react73.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
9891
- return (0, import_react73.useMemo)(
9909
+ const store = (0, import_react74.useMemo)(() => (0, import_editor18.createTableStore)(editor), [editor]);
9910
+ const snapshot = (0, import_react74.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
9911
+ return (0, import_react74.useMemo)(
9892
9912
  () => ({
9893
9913
  ...snapshot,
9894
9914
  run: (action, params) => (0, import_editor18.runTableAction)(editor, action, params, { focus: true }),
@@ -9899,7 +9919,7 @@ function useTableMenu(editor) {
9899
9919
  }
9900
9920
 
9901
9921
  // src/tables/TableToolbar.tsx
9902
- var import_react74 = __toESM(require("react"), 1);
9922
+ var import_react75 = __toESM(require("react"), 1);
9903
9923
  var import_editor19 = require("@pixerate/editor");
9904
9924
  var import_jsx_runtime51 = require("react/jsx-runtime");
9905
9925
  var keepSelection2 = (event) => event.preventDefault();
@@ -9920,7 +9940,7 @@ var TableToolbar = ({
9920
9940
  const enabled = status === true;
9921
9941
  const active = item.active?.(table);
9922
9942
  const separator = index > 0 && items[index - 1].group !== item.group;
9923
- return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(import_react74.default.Fragment, { children: [
9943
+ return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(import_react75.default.Fragment, { children: [
9924
9944
  separator && /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("span", { className: separatorClassName, "aria-hidden": "true" }),
9925
9945
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
9926
9946
  "button",
@@ -9944,7 +9964,7 @@ var TableToolbar = ({
9944
9964
  };
9945
9965
 
9946
9966
  // src/tables/InsertTableGrid.tsx
9947
- var import_react75 = require("react");
9967
+ var import_react76 = require("react");
9948
9968
  var import_jsx_runtime52 = require("react/jsx-runtime");
9949
9969
  var keepSelection3 = (event) => event.preventDefault();
9950
9970
  var InsertTableGrid = ({
@@ -9958,7 +9978,7 @@ var InsertTableGrid = ({
9958
9978
  onInsert
9959
9979
  }) => {
9960
9980
  const table = useTableMenu(editor);
9961
- const [hover, setHover] = (0, import_react75.useState)(null);
9981
+ const [hover, setHover] = (0, import_react76.useState)(null);
9962
9982
  const status = table.actions.insertTable;
9963
9983
  const disabled = !editor || !status.enabled;
9964
9984
  const insert = (size) => {
@@ -10025,14 +10045,14 @@ var TableBubbleMenu = ({
10025
10045
  var import_client = require("react-dom/client");
10026
10046
 
10027
10047
  // src/chart/ChartCanvas.tsx
10028
- var import_react77 = require("react");
10048
+ var import_react78 = require("react");
10029
10049
  var import_chart2 = require("@pixerate/editor/chart");
10030
10050
 
10031
10051
  // src/chart/useChartEditor.ts
10032
- var import_react76 = require("react");
10052
+ var import_react77 = require("react");
10033
10053
  var import_chart = require("@pixerate/editor/chart");
10034
10054
  function useChartState(controller) {
10035
- return (0, import_react76.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
10055
+ return (0, import_react77.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
10036
10056
  }
10037
10057
 
10038
10058
  // src/chart/ChartCanvas.tsx
@@ -10084,7 +10104,7 @@ function renderChartMark(mark, fontFamily, interactive) {
10084
10104
  }
10085
10105
  }
10086
10106
  function ChartPresenceLayer({ presence }) {
10087
- const { actors } = (0, import_react77.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
10107
+ const { actors } = (0, import_react78.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
10088
10108
  return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
10089
10109
  /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 }, transform: a.pressed ? "scale(0.9)" : void 0 }),
10090
10110
  /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("g", { transform: "translate(13 16)", children: [
@@ -10095,12 +10115,12 @@ function ChartPresenceLayer({ presence }) {
10095
10115
  }
10096
10116
  function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef }) {
10097
10117
  const state = useChartState(controller);
10098
- const wrapper = (0, import_react77.useRef)(null);
10099
- const svg = (0, import_react77.useRef)(null);
10100
- const drag = (0, import_react77.useRef)(null);
10101
- const [measured, setMeasured] = (0, import_react77.useState)(null);
10102
- const [frozen, setFrozen] = (0, import_react77.useState)(null);
10103
- (0, import_react77.useEffect)(() => {
10118
+ const wrapper = (0, import_react78.useRef)(null);
10119
+ const svg = (0, import_react78.useRef)(null);
10120
+ const drag = (0, import_react78.useRef)(null);
10121
+ const [measured, setMeasured] = (0, import_react78.useState)(null);
10122
+ const [frozen, setFrozen] = (0, import_react78.useState)(null);
10123
+ (0, import_react78.useEffect)(() => {
10104
10124
  const el = wrapper.current;
10105
10125
  if (!responsive || !el || typeof ResizeObserver === "undefined") return;
10106
10126
  const observer = new ResizeObserver(([entry]) => {
@@ -10111,8 +10131,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
10111
10131
  return () => observer.disconnect();
10112
10132
  }, [responsive]);
10113
10133
  const sceneWidth = responsive && measured || width;
10114
- const fullTheme = (0, import_react77.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
10115
- const scene = (0, import_react77.useMemo)(
10134
+ const fullTheme = (0, import_react78.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
10135
+ const scene = (0, import_react78.useMemo)(
10116
10136
  () => (0, import_chart2.layoutChart)(state.spec, {
10117
10137
  width: sceneWidth,
10118
10138
  height,
@@ -10128,8 +10148,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
10128
10148
  [state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
10129
10149
  );
10130
10150
  if (sceneRef) sceneRef.current = scene;
10131
- const byKey = (0, import_react77.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
10132
- (0, import_react77.useEffect)(() => () => drag.current?.end(), []);
10151
+ const byKey = (0, import_react78.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
10152
+ (0, import_react78.useEffect)(() => () => drag.current?.end(), []);
10133
10153
  const scenePoint = (e) => (0, import_chart2.chartClientToScene)(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
10134
10154
  const onPointerDown = (e) => {
10135
10155
  if (!editable || e.button !== 0) return;
@@ -10187,7 +10207,7 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
10187
10207
  }
10188
10208
 
10189
10209
  // src/chart/ChartDataGrid.tsx
10190
- var import_react78 = require("react");
10210
+ var import_react79 = require("react");
10191
10211
  var import_chart3 = require("@pixerate/editor/chart");
10192
10212
 
10193
10213
  // src/chart/styles.ts
@@ -10202,9 +10222,9 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
10202
10222
  // src/chart/ChartDataGrid.tsx
10203
10223
  var import_jsx_runtime55 = require("react/jsx-runtime");
10204
10224
  function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
10205
- const [draft, setDraft] = (0, import_react78.useState)(value);
10206
- const typing = (0, import_react78.useRef)(false);
10207
- (0, import_react78.useEffect)(() => {
10225
+ const [draft, setDraft] = (0, import_react79.useState)(value);
10226
+ const typing = (0, import_react79.useRef)(false);
10227
+ (0, import_react79.useEffect)(() => {
10208
10228
  if (!typing.current) setDraft(value);
10209
10229
  }, [value]);
10210
10230
  const commit = () => {
@@ -10340,7 +10360,7 @@ function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = fal
10340
10360
  }
10341
10361
 
10342
10362
  // src/chart/ChartInspector.tsx
10343
- var import_react79 = require("react");
10363
+ var import_react80 = require("react");
10344
10364
  var import_chart4 = require("@pixerate/editor/chart");
10345
10365
  var import_jsx_runtime56 = require("react/jsx-runtime");
10346
10366
  var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
@@ -10505,7 +10525,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
10505
10525
  }
10506
10526
  function ChartInspector({ controller, sections, className }) {
10507
10527
  const { spec, selectedSeries } = useChartState(controller);
10508
- const idBase = (0, import_react79.useId)();
10528
+ const idBase = (0, import_react80.useId)();
10509
10529
  const show = (section) => !sections || sections.includes(section);
10510
10530
  const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
10511
10531
  const family = (0, import_chart4.chartFamily)(spec);
@@ -10814,6 +10834,7 @@ function createReactChartNodeView(options = {}) {
10814
10834
  useDocumentCompare,
10815
10835
  useDocxExport,
10816
10836
  useEditor,
10837
+ useEditorAutosave,
10817
10838
  useEditorSlots,
10818
10839
  useElementPlaybackSurface,
10819
10840
  useFileImport,
package/dist/index.js CHANGED
@@ -60,8 +60,9 @@ import {
60
60
  } from "./chunk-SMLHUEEQ.js";
61
61
  import {
62
62
  RecoveryPrompt,
63
- useAutosave
64
- } from "./chunk-NNM633RN.js";
63
+ useAutosave,
64
+ useEditorAutosave
65
+ } from "./chunk-R7MEGRPV.js";
65
66
  import {
66
67
  AssetMentionChips,
67
68
  GenerationHistory,
@@ -2458,6 +2459,7 @@ export {
2458
2459
  useDocumentCompare,
2459
2460
  useDocxExport,
2460
2461
  useEditor2 as useEditor,
2462
+ useEditorAutosave,
2461
2463
  useEditorSlots,
2462
2464
  useElementPlaybackSurface,
2463
2465
  useFileImport,
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var persistence_exports = {};
22
22
  __export(persistence_exports, {
23
23
  RecoveryPrompt: () => RecoveryPrompt,
24
- useAutosave: () => useAutosave
24
+ useAutosave: () => useAutosave,
25
+ useEditorAutosave: () => useEditorAutosave
25
26
  });
26
27
  module.exports = __toCommonJS(persistence_exports);
27
28
 
@@ -129,8 +130,27 @@ function useAutosave(options) {
129
130
  return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
130
131
  }
131
132
 
132
- // src/persistence/RecoveryPrompt.tsx
133
+ // src/persistence/useEditorAutosave.ts
134
+ var import_react2 = require("react");
133
135
  var import_persistence2 = require("@pixerate/editor/persistence");
136
+ function useEditorAutosave(doc, options) {
137
+ const autosave = useAutosave({
138
+ ...options,
139
+ key: options.key ?? doc.kind,
140
+ getSnapshot: () => (0, import_persistence2.toEditorDocumentFile)(doc),
141
+ deserialize: (text) => (0, import_persistence2.parseEditorDocument)(text, { kind: doc.kind }),
142
+ history: doc
143
+ });
144
+ const take = autosave.restore;
145
+ const restore = (0, import_react2.useCallback)(() => {
146
+ const snapshot = take();
147
+ return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
148
+ }, [take, doc]);
149
+ return { ...autosave, restore };
150
+ }
151
+
152
+ // src/persistence/RecoveryPrompt.tsx
153
+ var import_persistence3 = require("@pixerate/editor/persistence");
134
154
  var import_jsx_runtime = require("react/jsx-runtime");
135
155
  var RecoveryPrompt = ({
136
156
  recovery,
@@ -152,7 +172,7 @@ var RecoveryPrompt = ({
152
172
  className: `flex flex-wrap items-center gap-3 rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground shadow-sm ${className}`,
153
173
  children: [
154
174
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "min-w-0 flex-1", children: [
155
- (0, import_persistence2.formatRecoveryMessage)(recovery.meta, formatTime),
175
+ (0, import_persistence3.formatRecoveryMessage)(recovery.meta, formatTime),
156
176
  name ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "ml-1 text-xs text-muted-foreground", children: [
157
177
  "(",
158
178
  name,
@@ -186,5 +206,6 @@ var RecoveryPrompt = ({
186
206
  // Annotate the CommonJS export names for ESM import in node:
187
207
  0 && (module.exports = {
188
208
  RecoveryPrompt,
189
- useAutosave
209
+ useAutosave,
210
+ useEditorAutosave
190
211
  });
@@ -1,2 +1,3 @@
1
1
  export * from './useAutosave.cjs';
2
+ export * from './useEditorAutosave.cjs';
2
3
  export * from './RecoveryPrompt.cjs';
@@ -1,2 +1,3 @@
1
1
  export * from './useAutosave.js';
2
+ export * from './useEditorAutosave.js';
2
3
  export * from './RecoveryPrompt.js';
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  RecoveryPrompt,
3
- useAutosave
4
- } from "../chunk-NNM633RN.js";
3
+ useAutosave,
4
+ useEditorAutosave
5
+ } from "../chunk-R7MEGRPV.js";
5
6
  export {
6
7
  RecoveryPrompt,
7
- useAutosave
8
+ useAutosave,
9
+ useEditorAutosave
8
10
  };
@@ -0,0 +1,17 @@
1
+ import { type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
2
+ import { type UseAutosaveOptions, type UseAutosaveResult } from './useAutosave.cjs';
3
+ export interface UseEditorAutosaveOptions extends Omit<UseAutosaveOptions<EditorDocumentFile>, 'key' | 'getSnapshot' | 'serialize' | 'deserialize' | 'history'> {
4
+ /** Snapshot key (default the document's `kind`). */
5
+ key?: string;
6
+ }
7
+ export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDocumentFile>, 'restore'> {
8
+ /** Loads the recovered snapshot into the document and starts autosaving. */
9
+ restore: () => LoadReport | undefined;
10
+ }
11
+ /**
12
+ * `useAutosave` for any editor's `EditorDocument` (e.g. `useMermaidDiagram().editorDocument`):
13
+ * snapshots it as an `EditorDocumentFile` after each change, and `restore` loads a
14
+ * recovered snapshot straight into the editor. Render `<RecoveryPrompt>` with
15
+ * `recovery`, `restore` and `discard`. Pass a stable `doc`.
16
+ */
17
+ export declare function useEditorAutosave(doc: EditorDocument, options: UseEditorAutosaveOptions): UseEditorAutosaveResult;
@@ -0,0 +1,17 @@
1
+ import { type EditorDocument, type EditorDocumentFile, type LoadReport } from '@pixerate/editor/persistence';
2
+ import { type UseAutosaveOptions, type UseAutosaveResult } from './useAutosave.js';
3
+ export interface UseEditorAutosaveOptions extends Omit<UseAutosaveOptions<EditorDocumentFile>, 'key' | 'getSnapshot' | 'serialize' | 'deserialize' | 'history'> {
4
+ /** Snapshot key (default the document's `kind`). */
5
+ key?: string;
6
+ }
7
+ export interface UseEditorAutosaveResult extends Omit<UseAutosaveResult<EditorDocumentFile>, 'restore'> {
8
+ /** Loads the recovered snapshot into the document and starts autosaving. */
9
+ restore: () => LoadReport | undefined;
10
+ }
11
+ /**
12
+ * `useAutosave` for any editor's `EditorDocument` (e.g. `useMermaidDiagram().editorDocument`):
13
+ * snapshots it as an `EditorDocumentFile` after each change, and `restore` loads a
14
+ * recovered snapshot straight into the editor. Render `<RecoveryPrompt>` with
15
+ * `recovery`, `restore` and `discard`. Pass a stable `doc`.
16
+ */
17
+ export declare function useEditorAutosave(doc: EditorDocument, options: UseEditorAutosaveOptions): UseEditorAutosaveResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.94.0",
3
+ "version": "0.95.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -219,7 +219,7 @@
219
219
  },
220
220
  "peerDependencies": {
221
221
  "@dagrejs/dagre": "^1.1.8",
222
- "@pixerate/editor": ">=0.145.0 <1.0.0-0",
222
+ "@pixerate/editor": ">=0.146.0 <1.0.0-0",
223
223
  "@tiptap/core": "^2.27.3",
224
224
  "@tiptap/pm": "^2.27.3",
225
225
  "@tiptap/react": "^2.27.3",
@@ -246,7 +246,7 @@
246
246
  "tsup": "^9.0.0",
247
247
  "typescript": "^5.7.3",
248
248
  "vitest": "^5.0.5",
249
- "@pixerate/editor": "0.145.0"
249
+ "@pixerate/editor": "0.146.0"
250
250
  },
251
251
  "scripts": {
252
252
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",