@pixerate/editor-react 0.102.0 → 0.104.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/canvas/index.cjs +613 -572
- package/dist/canvas/index.d.cts +1 -0
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/index.js +114 -72
- package/dist/canvas/useCanvasEditorDocument.d.cts +15 -0
- package/dist/canvas/useCanvasEditorDocument.d.ts +15 -0
- package/dist/{chunk-R7MEGRPV.js → chunk-5YTP5RVI.js} +8 -2
- package/dist/{chunk-GJ2TYERJ.js → chunk-CEV4OEOY.js} +5 -1
- package/dist/image-editor/index.cjs +4 -1
- package/dist/image-editor/index.js +1 -1
- package/dist/image-editor/useImageEditor.d.cts +3 -0
- package/dist/image-editor/useImageEditor.d.ts +3 -0
- package/dist/index.cjs +9 -1
- package/dist/index.js +2 -2
- package/dist/paint-editor/index.cjs +3 -1
- package/dist/paint-editor/index.js +19 -17
- package/dist/paint-editor/usePaintEditor.d.cts +4 -1
- package/dist/paint-editor/usePaintEditor.d.ts +4 -1
- package/dist/persistence/index.cjs +5 -0
- package/dist/persistence/index.js +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
2
2
|
import { ImageEditorController, type ImageEffectsToolProviderOptions, type ImageEditorOptions, type ImageEditorState, type ImageEditorTool, type CropBox, type AspectRatio, type ImageAdjustments, type DepthMaskOptions, type Annotation, type CreateAnnotationPayload, type ExportOptions, type SerializedImageEditorState, type AIResultOptions, type ImagePoint, type AdjustmentKind, type AdjustmentLayerInit, type AdjustmentLayerUpdate, type ImageHistogram } from '@pixerate/editor/image-editor';
|
|
3
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
4
|
export interface UseImageEditorReturn {
|
|
4
5
|
controller: ImageEditorController;
|
|
6
|
+
/** The save / load / undo contract, with layer pixels as asset references (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
7
|
+
editorDocument: EditorDocument<SerializedImageEditorState>;
|
|
5
8
|
state: ImageEditorState;
|
|
6
9
|
canUndo: boolean;
|
|
7
10
|
canRedo: boolean;
|
package/dist/index.cjs
CHANGED
|
@@ -3960,9 +3960,12 @@ function useImageEditor(options = {}) {
|
|
|
3960
3960
|
(newDataUrl, options2) => controller.applyBackgroundRemovedImage(newDataUrl, options2),
|
|
3961
3961
|
[controller]
|
|
3962
3962
|
);
|
|
3963
|
+
const editorDocument = (0, import_react40.useMemo)(() => (0, import_image_editor.createImageEditorDocument)(controller), [controller]);
|
|
3964
|
+
(0, import_react40.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
3963
3965
|
return (0, import_react40.useMemo)(
|
|
3964
3966
|
() => ({
|
|
3965
3967
|
controller,
|
|
3968
|
+
editorDocument,
|
|
3966
3969
|
state,
|
|
3967
3970
|
canUndo: controller.canUndo,
|
|
3968
3971
|
canRedo: controller.canRedo,
|
|
@@ -4011,7 +4014,7 @@ function useImageEditor(options = {}) {
|
|
|
4011
4014
|
applyBackgroundRemovedImage
|
|
4012
4015
|
}),
|
|
4013
4016
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4014
|
-
[controller, state, historyTicks, histogram]
|
|
4017
|
+
[controller, editorDocument, state, historyTicks, histogram]
|
|
4015
4018
|
);
|
|
4016
4019
|
}
|
|
4017
4020
|
function useImageEffectsTools(registry, controller, options = {}) {
|
|
@@ -10333,8 +10336,13 @@ function useAutosave(options) {
|
|
|
10333
10336
|
var import_react72 = require("react");
|
|
10334
10337
|
var import_persistence2 = require("@pixerate/editor/persistence");
|
|
10335
10338
|
function useEditorAutosave(doc, options) {
|
|
10339
|
+
const storage = (0, import_react72.useMemo)(
|
|
10340
|
+
() => doc.assets ? (0, import_persistence2.withEditorAssets)(options.storage, doc.assets) : options.storage,
|
|
10341
|
+
[options.storage, doc.assets]
|
|
10342
|
+
);
|
|
10336
10343
|
const autosave = useAutosave({
|
|
10337
10344
|
...options,
|
|
10345
|
+
storage,
|
|
10338
10346
|
key: options.key ?? doc.kind,
|
|
10339
10347
|
getSnapshot: () => (0, import_persistence2.toEditorDocumentFile)(doc),
|
|
10340
10348
|
deserialize: (text) => (0, import_persistence2.parseEditorDocument)(text, { kind: doc.kind }),
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
useImageEditor,
|
|
45
45
|
useImageEffectsTools,
|
|
46
46
|
useImageHistogram
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-CEV4OEOY.js";
|
|
48
48
|
import "./chunk-AJCWF6SN.js";
|
|
49
49
|
import "./chunk-Q7LAFHGP.js";
|
|
50
50
|
import "./chunk-5LFQ2UQZ.js";
|
|
@@ -66,7 +66,7 @@ import {
|
|
|
66
66
|
RecoveryPrompt,
|
|
67
67
|
useAutosave,
|
|
68
68
|
useEditorAutosave
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-5YTP5RVI.js";
|
|
70
70
|
import {
|
|
71
71
|
AssetMentionChips,
|
|
72
72
|
GenerationHistory,
|
|
@@ -58,7 +58,9 @@ var import_paint_editor = require("@pixerate/editor/paint-editor");
|
|
|
58
58
|
function usePaintEditor(options = {}) {
|
|
59
59
|
const [controller] = (0, import_react.useState)(() => options instanceof import_paint_editor.PaintEditorController ? options : new import_paint_editor.PaintEditorController(options));
|
|
60
60
|
const state = usePaintEditorState(controller);
|
|
61
|
-
|
|
61
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_paint_editor.createPaintEditorDocument)(controller), [controller]);
|
|
62
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
63
|
+
return (0, import_react.useMemo)(() => ({ controller, state, editorDocument }), [controller, state, editorDocument]);
|
|
62
64
|
}
|
|
63
65
|
function usePaintEditorState(controller) {
|
|
64
66
|
return (0, import_react.useSyncExternalStore)(
|
|
@@ -16,12 +16,14 @@ import {
|
|
|
16
16
|
} from "../chunk-GNO54NFG.js";
|
|
17
17
|
|
|
18
18
|
// src/paint-editor/usePaintEditor.ts
|
|
19
|
-
import { useMemo, useState, useSyncExternalStore } from "react";
|
|
20
|
-
import { PaintDirector, PaintEditorController, PaintPresence } from "@pixerate/editor/paint-editor";
|
|
19
|
+
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
20
|
+
import { PaintDirector, PaintEditorController, PaintPresence, createPaintEditorDocument } from "@pixerate/editor/paint-editor";
|
|
21
21
|
function usePaintEditor(options = {}) {
|
|
22
22
|
const [controller] = useState(() => options instanceof PaintEditorController ? options : new PaintEditorController(options));
|
|
23
23
|
const state = usePaintEditorState(controller);
|
|
24
|
-
|
|
24
|
+
const editorDocument = useMemo(() => createPaintEditorDocument(controller), [controller]);
|
|
25
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
26
|
+
return useMemo(() => ({ controller, state, editorDocument }), [controller, state, editorDocument]);
|
|
25
27
|
}
|
|
26
28
|
function usePaintEditorState(controller) {
|
|
27
29
|
return useSyncExternalStore(
|
|
@@ -39,7 +41,7 @@ function usePaintDirector(controller, options = {}) {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
// src/paint-editor/PaintCanvas.tsx
|
|
42
|
-
import { useEffect, useMemo as useMemo2, useRef, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
44
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
43
45
|
import {
|
|
44
46
|
PaintCanvasPresenter,
|
|
45
47
|
PaintGesture,
|
|
@@ -72,7 +74,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
|
|
|
72
74
|
);
|
|
73
75
|
gesture.tool = tool;
|
|
74
76
|
const { canvas: doc } = state.document;
|
|
75
|
-
|
|
77
|
+
useEffect2(() => {
|
|
76
78
|
const el = viewport.current;
|
|
77
79
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
78
80
|
const ro = new ResizeObserver(() => {
|
|
@@ -84,24 +86,24 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
|
|
|
84
86
|
return () => ro.disconnect();
|
|
85
87
|
}, []);
|
|
86
88
|
const fitted = useRef(null);
|
|
87
|
-
|
|
89
|
+
useEffect2(() => {
|
|
88
90
|
const key = `${doc.width}x${doc.height}`;
|
|
89
91
|
if (!fitOnMount || fitted.current === key) return;
|
|
90
92
|
if (typeof ResizeObserver !== "undefined" && !measured.current) return;
|
|
91
93
|
fitted.current = key;
|
|
92
94
|
controller.setView({ zoom: fitZoom(doc, size), pan: { x: 0, y: 0 } });
|
|
93
95
|
}, [controller, doc, size, fitOnMount]);
|
|
94
|
-
|
|
96
|
+
useEffect2(() => {
|
|
95
97
|
const ctx = canvas.current?.getContext("2d");
|
|
96
98
|
if (ctx && typeof ctx.createImageData === "function") presenter.render(ctx);
|
|
97
99
|
else controller.takeDirty();
|
|
98
100
|
}, [state, presenter, controller]);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
useEffect2(() => startWetClock(controller), [controller]);
|
|
102
|
+
useEffect2(() => {
|
|
101
103
|
const ctx = water.current?.getContext("2d");
|
|
102
104
|
if (ctx && typeof ctx.createImageData === "function") drawWaterOverlay(controller, ctx);
|
|
103
105
|
}, [state, controller]);
|
|
104
|
-
|
|
106
|
+
useEffect2(() => {
|
|
105
107
|
const el = viewport.current;
|
|
106
108
|
if (!el) return;
|
|
107
109
|
const onWheel = (e) => {
|
|
@@ -265,14 +267,14 @@ import { useRef as useRef3, useState as useState4 } from "react";
|
|
|
265
267
|
import { PAINT_TOOLS, SYMMETRY_MODES, decodeImageBlob, downloadBytes, quickStencil, timeLapseZip } from "@pixerate/editor/paint-editor";
|
|
266
268
|
|
|
267
269
|
// src/paint-editor/shared.tsx
|
|
268
|
-
import { useEffect as
|
|
270
|
+
import { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
269
271
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
270
272
|
var chip = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
271
273
|
var button = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-200 hover:bg-slate-700 disabled:opacity-40";
|
|
272
274
|
var panel = "flex flex-col gap-2 text-xs text-slate-200";
|
|
273
275
|
var PixelCanvas = ({ pixels, label, className, style }) => {
|
|
274
276
|
const ref = useRef2(null);
|
|
275
|
-
|
|
277
|
+
useEffect3(() => {
|
|
276
278
|
const canvas = ref.current;
|
|
277
279
|
const ctx = canvas?.getContext("2d");
|
|
278
280
|
if (!canvas || !ctx || !pixels || typeof ctx.createImageData !== "function") return;
|
|
@@ -290,7 +292,7 @@ var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
|
290
292
|
const ref = useRef2(null);
|
|
291
293
|
const commit = useRef2(onCommit);
|
|
292
294
|
commit.current = onCommit;
|
|
293
|
-
|
|
295
|
+
useEffect3(() => {
|
|
294
296
|
const el = ref.current;
|
|
295
297
|
if (!el) return;
|
|
296
298
|
const done = () => {
|
|
@@ -344,7 +346,7 @@ var CommitColorInput = ({ value, label, onCommit, className }) => {
|
|
|
344
346
|
const ref = useRef2(null);
|
|
345
347
|
const commit = useRef2(onCommit);
|
|
346
348
|
commit.current = onCommit;
|
|
347
|
-
|
|
349
|
+
useEffect3(() => {
|
|
348
350
|
const el = ref.current;
|
|
349
351
|
if (!el) return;
|
|
350
352
|
const done = () => commit.current(el.value);
|
|
@@ -1226,12 +1228,12 @@ import { useRef as useRef7, useState as useState10 } from "react";
|
|
|
1226
1228
|
import { PaintPresence as PaintPresence2, documentToScreen as documentToScreen2, screenToDocument } from "@pixerate/editor/paint-editor";
|
|
1227
1229
|
|
|
1228
1230
|
// src/paint-editor/PaintEffectsPanel.tsx
|
|
1229
|
-
import { useEffect as
|
|
1231
|
+
import { useEffect as useEffect4, useRef as useRef6, useState as useState9 } from "react";
|
|
1230
1232
|
import { createPaintEffectsToolProvider, PAPER_EFFECT_BLENDS } from "@pixerate/editor/paint-editor";
|
|
1231
1233
|
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1232
1234
|
function usePaintEffectsProvider(controller) {
|
|
1233
1235
|
const [provider, setProvider] = useState9(controller.effectsProvider);
|
|
1234
|
-
|
|
1236
|
+
useEffect4(() => {
|
|
1235
1237
|
setProvider(controller.effectsProvider);
|
|
1236
1238
|
return controller.effects.subscribe(setProvider);
|
|
1237
1239
|
}, [controller]);
|
|
@@ -1239,7 +1241,7 @@ function usePaintEffectsProvider(controller) {
|
|
|
1239
1241
|
}
|
|
1240
1242
|
function usePaintEffectsTools(registry, controller, options = {}) {
|
|
1241
1243
|
const { id, namespace, readOnly, playbackSurface } = options;
|
|
1242
|
-
|
|
1244
|
+
useEffect4(() => {
|
|
1243
1245
|
if (!registry) return;
|
|
1244
1246
|
return registry.register(createPaintEffectsToolProvider(controller, { id, namespace, readOnly, playbackSurface }));
|
|
1245
1247
|
}, [registry, controller, id, namespace, readOnly, playbackSurface]);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState } from '@pixerate/editor/paint-editor';
|
|
1
|
+
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
export interface UsePaintEditorReturn {
|
|
3
4
|
controller: PaintEditorController;
|
|
4
5
|
/** The controller's snapshot (a new object after every change). */
|
|
5
6
|
state: PaintEditorState;
|
|
7
|
+
/** The save / load / undo contract, with every image as an asset reference (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
8
|
+
editorDocument: EditorDocument<SerializedPaintDocument>;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Creates a `PaintEditorController` once (from `options`, read on the first render) or uses the
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState } from '@pixerate/editor/paint-editor';
|
|
1
|
+
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
export interface UsePaintEditorReturn {
|
|
3
4
|
controller: PaintEditorController;
|
|
4
5
|
/** The controller's snapshot (a new object after every change). */
|
|
5
6
|
state: PaintEditorState;
|
|
7
|
+
/** The save / load / undo contract, with every image as an asset reference (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
8
|
+
editorDocument: EditorDocument<SerializedPaintDocument>;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Creates a `PaintEditorController` once (from `options`, read on the first render) or uses the
|
|
@@ -134,8 +134,13 @@ function useAutosave(options) {
|
|
|
134
134
|
var import_react2 = require("react");
|
|
135
135
|
var import_persistence2 = require("@pixerate/editor/persistence");
|
|
136
136
|
function useEditorAutosave(doc, options) {
|
|
137
|
+
const storage = (0, import_react2.useMemo)(
|
|
138
|
+
() => doc.assets ? (0, import_persistence2.withEditorAssets)(options.storage, doc.assets) : options.storage,
|
|
139
|
+
[options.storage, doc.assets]
|
|
140
|
+
);
|
|
137
141
|
const autosave = useAutosave({
|
|
138
142
|
...options,
|
|
143
|
+
storage,
|
|
139
144
|
key: options.key ?? doc.kind,
|
|
140
145
|
getSnapshot: () => (0, import_persistence2.toEditorDocumentFile)(doc),
|
|
141
146
|
deserialize: (text) => (0, import_persistence2.parseEditorDocument)(text, { kind: doc.kind }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.104.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
},
|
|
246
246
|
"peerDependencies": {
|
|
247
247
|
"@dagrejs/dagre": "^1.1.8",
|
|
248
|
-
"@pixerate/editor": ">=0.
|
|
248
|
+
"@pixerate/editor": ">=0.155.0 <1.0.0-0",
|
|
249
249
|
"@tiptap/core": "^2.27.3",
|
|
250
250
|
"@tiptap/pm": "^2.27.3",
|
|
251
251
|
"@tiptap/react": "^2.27.3",
|
|
@@ -272,7 +272,7 @@
|
|
|
272
272
|
"tsup": "^9.0.0",
|
|
273
273
|
"typescript": "^5.7.3",
|
|
274
274
|
"vitest": "^5.0.5",
|
|
275
|
-
"@pixerate/editor": "0.
|
|
275
|
+
"@pixerate/editor": "0.155.0"
|
|
276
276
|
},
|
|
277
277
|
"scripts": {
|
|
278
278
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|