@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
package/dist/canvas/index.d.cts
CHANGED
|
@@ -11,6 +11,7 @@ export { useCanvasExplosion, type CanvasGraphTarget } from './useCanvasExplosion
|
|
|
11
11
|
export { useCanvasArrange, useCanvasArrangeShortcuts, type CanvasArrange, type UseCanvasArrangeOptions, type UseCanvasArrangeShortcutsOptions } from './useCanvasArrange.cjs';
|
|
12
12
|
export { useCanvasScenes, type CanvasScenes, type UseCanvasScenesOptions } from './useCanvasScenes.cjs';
|
|
13
13
|
export { useCanvasCapture, type UseCanvasCaptureOptions } from './useCanvasCapture.cjs';
|
|
14
|
+
export { useCanvasEditorDocument, type UseCanvasEditorDocumentOptions } from './useCanvasEditorDocument.cjs';
|
|
14
15
|
export { CanvasGuidesLayer, type CanvasGuidesLayerProps } from './CanvasGuidesLayer.cjs';
|
|
15
16
|
export { useCanvasDraw, type CanvasDraw, type CanvasDrawState, type CanvasDrawActions, type UseCanvasDrawOptions } from './useCanvasDraw.cjs';
|
|
16
17
|
export { CanvasDrawLayer, type CanvasDrawLayerProps } from './CanvasDrawLayer.cjs';
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { useCanvasExplosion, type CanvasGraphTarget } from './useCanvasExplosion
|
|
|
11
11
|
export { useCanvasArrange, useCanvasArrangeShortcuts, type CanvasArrange, type UseCanvasArrangeOptions, type UseCanvasArrangeShortcutsOptions } from './useCanvasArrange.js';
|
|
12
12
|
export { useCanvasScenes, type CanvasScenes, type UseCanvasScenesOptions } from './useCanvasScenes.js';
|
|
13
13
|
export { useCanvasCapture, type UseCanvasCaptureOptions } from './useCanvasCapture.js';
|
|
14
|
+
export { useCanvasEditorDocument, type UseCanvasEditorDocumentOptions } from './useCanvasEditorDocument.js';
|
|
14
15
|
export { CanvasGuidesLayer, type CanvasGuidesLayerProps } from './CanvasGuidesLayer.js';
|
|
15
16
|
export { useCanvasDraw, type CanvasDraw, type CanvasDrawState, type CanvasDrawActions, type UseCanvasDrawOptions } from './useCanvasDraw.js';
|
|
16
17
|
export { CanvasDrawLayer, type CanvasDrawLayerProps } from './CanvasDrawLayer.js';
|
package/dist/canvas/index.js
CHANGED
|
@@ -989,6 +989,47 @@ function useCanvasCapture(options) {
|
|
|
989
989
|
}, [options.id, options.namespace]);
|
|
990
990
|
}
|
|
991
991
|
|
|
992
|
+
// src/canvas/useCanvasEditorDocument.ts
|
|
993
|
+
import { useEffect as useEffect4, useMemo as useMemo5, useRef as useRef9 } from "react";
|
|
994
|
+
import {
|
|
995
|
+
createCanvasEditorDocument
|
|
996
|
+
} from "@pixerate/editor/canvas";
|
|
997
|
+
var contentKey = (nodes, edges) => JSON.stringify([
|
|
998
|
+
nodes.map(({ selected: _s, dragging: _d, measured: _m, resizing: _r, ...rest }) => rest),
|
|
999
|
+
edges.map(({ selected: _s, ...rest }) => rest)
|
|
1000
|
+
]);
|
|
1001
|
+
function useCanvasEditorDocument(options) {
|
|
1002
|
+
const latest = useRef9(options);
|
|
1003
|
+
latest.current = options;
|
|
1004
|
+
const listeners = useRef9(/* @__PURE__ */ new Set());
|
|
1005
|
+
const doc = useMemo5(
|
|
1006
|
+
() => createCanvasEditorDocument({
|
|
1007
|
+
getNodes: () => latest.current.nodes,
|
|
1008
|
+
setNodes: (nodes) => latest.current.setNodes(nodes),
|
|
1009
|
+
getEdges: () => latest.current.edges,
|
|
1010
|
+
setEdges: (edges) => latest.current.setEdges(edges),
|
|
1011
|
+
history: options.history,
|
|
1012
|
+
scenes: options.scenes,
|
|
1013
|
+
readOnly: () => latest.current.readOnly?.() ?? false,
|
|
1014
|
+
subscribe: (listener) => {
|
|
1015
|
+
listeners.current.add(listener);
|
|
1016
|
+
return () => listeners.current.delete(listener);
|
|
1017
|
+
}
|
|
1018
|
+
}),
|
|
1019
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1020
|
+
[options.history, options.scenes]
|
|
1021
|
+
);
|
|
1022
|
+
useEffect4(() => () => doc.destroy(), [doc]);
|
|
1023
|
+
const lastKey = useRef9(null);
|
|
1024
|
+
useEffect4(() => {
|
|
1025
|
+
if (options.nodes.some((n) => n.dragging)) return;
|
|
1026
|
+
const key = contentKey(options.nodes, options.edges);
|
|
1027
|
+
if (lastKey.current !== null && key !== lastKey.current) listeners.current.forEach((listener) => listener());
|
|
1028
|
+
lastKey.current = key;
|
|
1029
|
+
}, [options.nodes, options.edges]);
|
|
1030
|
+
return doc;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
992
1033
|
// src/canvas/CanvasGuidesLayer.tsx
|
|
993
1034
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
994
1035
|
var DEFAULT_VIEWPORT = { x: 0, y: 0, zoom: 1 };
|
|
@@ -1073,18 +1114,18 @@ function CanvasGuidesLayer({
|
|
|
1073
1114
|
}
|
|
1074
1115
|
|
|
1075
1116
|
// src/canvas/useCanvasDraw.ts
|
|
1076
|
-
import { useEffect as
|
|
1117
|
+
import { useEffect as useEffect5, useMemo as useMemo6, useRef as useRef10, useState as useState3 } from "react";
|
|
1077
1118
|
import {
|
|
1078
1119
|
createCanvasDrawController
|
|
1079
1120
|
} from "@pixerate/editor/canvas";
|
|
1080
1121
|
function useCanvasDraw(options) {
|
|
1081
|
-
const nodesRef =
|
|
1122
|
+
const nodesRef = useRef10(options.nodes);
|
|
1082
1123
|
nodesRef.current = options.nodes;
|
|
1083
|
-
const optionsRef =
|
|
1124
|
+
const optionsRef = useRef10(options);
|
|
1084
1125
|
optionsRef.current = options;
|
|
1085
1126
|
const [tool, setToolState] = useState3(options.initialTool ?? "select");
|
|
1086
1127
|
const [activeStroke, setActiveStroke] = useState3(null);
|
|
1087
|
-
const controller =
|
|
1128
|
+
const controller = useMemo6(
|
|
1088
1129
|
() => createCanvasDrawController({
|
|
1089
1130
|
getNodes: () => nodesRef.current,
|
|
1090
1131
|
setNodes: (next) => {
|
|
@@ -1107,12 +1148,12 @@ function useCanvasDraw(options) {
|
|
|
1107
1148
|
[]
|
|
1108
1149
|
);
|
|
1109
1150
|
const [style, setStyleState] = useState3(controller.style);
|
|
1110
|
-
|
|
1151
|
+
useEffect5(() => {
|
|
1111
1152
|
if (options.initialTool && options.initialTool !== controller.tool) {
|
|
1112
1153
|
controller.setTool(options.initialTool);
|
|
1113
1154
|
}
|
|
1114
1155
|
}, [options.initialTool, controller]);
|
|
1115
|
-
return
|
|
1156
|
+
return useMemo6(
|
|
1116
1157
|
() => ({
|
|
1117
1158
|
tool,
|
|
1118
1159
|
style,
|
|
@@ -1133,7 +1174,7 @@ function useCanvasDraw(options) {
|
|
|
1133
1174
|
}
|
|
1134
1175
|
|
|
1135
1176
|
// src/canvas/CanvasDrawLayer.tsx
|
|
1136
|
-
import { useCallback as useCallback7, useEffect as
|
|
1177
|
+
import { useCallback as useCallback7, useEffect as useEffect6, useRef as useRef11, useState as useState4 } from "react";
|
|
1137
1178
|
import {
|
|
1138
1179
|
pointerPenSample,
|
|
1139
1180
|
strokePointsToPathData,
|
|
@@ -1150,10 +1191,10 @@ function CanvasDrawLayer({
|
|
|
1150
1191
|
cursor,
|
|
1151
1192
|
eraserRadius = 12
|
|
1152
1193
|
}) {
|
|
1153
|
-
const svgRef =
|
|
1194
|
+
const svgRef = useRef11(null);
|
|
1154
1195
|
const [spaceHeld, setSpaceHeld] = useState4(false);
|
|
1155
1196
|
const [eraserPos, setEraserPos] = useState4(null);
|
|
1156
|
-
|
|
1197
|
+
useEffect6(() => {
|
|
1157
1198
|
function onKeyDown(e) {
|
|
1158
1199
|
if (e.code === "Space" && !e.repeat) {
|
|
1159
1200
|
const tag = e.target?.tagName;
|
|
@@ -1290,7 +1331,7 @@ function CanvasDrawLayer({
|
|
|
1290
1331
|
}
|
|
1291
1332
|
|
|
1292
1333
|
// src/canvas/useCanvasMeasure.ts
|
|
1293
|
-
import { useCallback as useCallback8, useEffect as
|
|
1334
|
+
import { useCallback as useCallback8, useEffect as useEffect7, useMemo as useMemo7, useRef as useRef12, useState as useState5 } from "react";
|
|
1294
1335
|
import {
|
|
1295
1336
|
isMeasureModifierHeld,
|
|
1296
1337
|
measureSelection
|
|
@@ -1300,9 +1341,9 @@ function useCanvasMeasure(options) {
|
|
|
1300
1341
|
const { nodes, enabled = true, requireModifier = true, targetElement, rectOptions } = options;
|
|
1301
1342
|
const [hoveredId, setHoveredId] = useState5(null);
|
|
1302
1343
|
const [modifier, setModifier] = useState5(false);
|
|
1303
|
-
const optionsRef =
|
|
1344
|
+
const optionsRef = useRef12(options);
|
|
1304
1345
|
optionsRef.current = options;
|
|
1305
|
-
|
|
1346
|
+
useEffect7(() => {
|
|
1306
1347
|
if (!enabled) return;
|
|
1307
1348
|
const target = targetElement ?? (typeof window !== "undefined" ? window : null);
|
|
1308
1349
|
if (!target) return;
|
|
@@ -1319,7 +1360,7 @@ function useCanvasMeasure(options) {
|
|
|
1319
1360
|
};
|
|
1320
1361
|
}, [enabled, targetElement]);
|
|
1321
1362
|
const active = enabled && (!requireModifier || modifier);
|
|
1322
|
-
const result =
|
|
1363
|
+
const result = useMemo7(() => {
|
|
1323
1364
|
if (!active) return EMPTY;
|
|
1324
1365
|
const ids = optionsRef.current.getSelectedIds?.() ?? nodes.filter((n) => n.selected).map((n) => n.id);
|
|
1325
1366
|
return measureSelection(nodes, ids, hoveredId, rectOptions);
|
|
@@ -1409,7 +1450,7 @@ import {
|
|
|
1409
1450
|
import { getShapeRenderData, isShapeDescription as isShapeDescription2 } from "@pixerate/editor/canvas";
|
|
1410
1451
|
|
|
1411
1452
|
// src/canvas/useShapeBrushstroke.tsx
|
|
1412
|
-
import { createContext, useContext, useEffect as
|
|
1453
|
+
import { createContext, useContext, useEffect as useEffect8, useMemo as useMemo8, useState as useState6 } from "react";
|
|
1413
1454
|
import {
|
|
1414
1455
|
brushstrokeScaleBucket,
|
|
1415
1456
|
isBrushedShape,
|
|
@@ -1434,7 +1475,7 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1434
1475
|
const ox = Math.round((position?.x ?? 0) - (vb?.[0] ?? 0) * unit);
|
|
1435
1476
|
const oy = Math.round((position?.y ?? 0) - (vb?.[1] ?? 0) * unit);
|
|
1436
1477
|
const [image, setImage] = useState6(null);
|
|
1437
|
-
|
|
1478
|
+
useEffect8(() => {
|
|
1438
1479
|
if (!brushed) {
|
|
1439
1480
|
setImage(null);
|
|
1440
1481
|
return;
|
|
@@ -1457,7 +1498,7 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1457
1498
|
function useCanvasBrushes(options = {}) {
|
|
1458
1499
|
const [state, setState] = useState6({ brushes: [], loading: true, error: null });
|
|
1459
1500
|
const swatches = options.swatches ? JSON.stringify(options.swatches) : "";
|
|
1460
|
-
|
|
1501
|
+
useEffect8(() => {
|
|
1461
1502
|
let live = true;
|
|
1462
1503
|
const opts = swatches ? JSON.parse(swatches) : null;
|
|
1463
1504
|
listCanvasBrushes().then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await renderCanvasBrushSwatch(b.id, opts) }))) : list).then(
|
|
@@ -1468,11 +1509,11 @@ function useCanvasBrushes(options = {}) {
|
|
|
1468
1509
|
live = false;
|
|
1469
1510
|
};
|
|
1470
1511
|
}, [swatches]);
|
|
1471
|
-
return
|
|
1512
|
+
return useMemo8(() => state, [state]);
|
|
1472
1513
|
}
|
|
1473
1514
|
|
|
1474
1515
|
// src/canvas/CanvasEffects.tsx
|
|
1475
|
-
import { createContext as createContext2, useContext as useContext2, useEffect as
|
|
1516
|
+
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect9, useMemo as useMemo9, useRef as useRef13, useState as useState7 } from "react";
|
|
1476
1517
|
import {
|
|
1477
1518
|
createCanvasEffectsController,
|
|
1478
1519
|
createCanvasEffectsToolProvider,
|
|
@@ -1487,20 +1528,20 @@ function CanvasEffectsProvider({ provider, children }) {
|
|
|
1487
1528
|
var useCanvasEffectsProviderContext = () => useContext2(ProviderContext);
|
|
1488
1529
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
1489
1530
|
const provider = useCanvasEffectsProviderContext();
|
|
1490
|
-
const ref =
|
|
1531
|
+
const ref = useRef13(null);
|
|
1491
1532
|
const [failed, setFailed] = useState7(false);
|
|
1492
1533
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
1493
1534
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
1494
1535
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
1495
1536
|
const key = JSON.stringify(effect);
|
|
1496
|
-
|
|
1537
|
+
useEffect9(() => {
|
|
1497
1538
|
const canvas2 = ref.current;
|
|
1498
1539
|
if (!provider || !canvas2) return;
|
|
1499
1540
|
setFailed(false);
|
|
1500
1541
|
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: () => setFailed(true) });
|
|
1501
1542
|
return () => run.stop();
|
|
1502
1543
|
}, [provider, key, pw, ph]);
|
|
1503
|
-
const clipId =
|
|
1544
|
+
const clipId = useMemo9(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
1504
1545
|
if (!provider || failed || !(width > 0 && height > 0)) return null;
|
|
1505
1546
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
1506
1547
|
const canvas = /* @__PURE__ */ jsx5("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
@@ -1511,9 +1552,9 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
1511
1552
|
] });
|
|
1512
1553
|
}
|
|
1513
1554
|
function useCanvasEffects(options) {
|
|
1514
|
-
const opts =
|
|
1555
|
+
const opts = useRef13(options);
|
|
1515
1556
|
opts.current = options;
|
|
1516
|
-
const controller =
|
|
1557
|
+
const controller = useMemo9(
|
|
1517
1558
|
() => createCanvasEffectsController({
|
|
1518
1559
|
getNodes: () => opts.current.getNodes(),
|
|
1519
1560
|
setNodes: (n) => opts.current.setNodes(n),
|
|
@@ -1524,7 +1565,7 @@ function useCanvasEffects(options) {
|
|
|
1524
1565
|
}),
|
|
1525
1566
|
[]
|
|
1526
1567
|
);
|
|
1527
|
-
|
|
1568
|
+
useEffect9(() => {
|
|
1528
1569
|
if (!options.effects) return;
|
|
1529
1570
|
return controller.useEffects(options.effects);
|
|
1530
1571
|
}, [controller, options.effects]);
|
|
@@ -1532,7 +1573,7 @@ function useCanvasEffects(options) {
|
|
|
1532
1573
|
}
|
|
1533
1574
|
function useCanvasEffectsTools(registry, controller, options = {}) {
|
|
1534
1575
|
const { id, namespace, readOnly, subscribe } = options;
|
|
1535
|
-
|
|
1576
|
+
useEffect9(() => {
|
|
1536
1577
|
if (!registry) return;
|
|
1537
1578
|
return registry.register(createCanvasEffectsToolProvider(controller, { id, namespace, readOnly, subscribe }));
|
|
1538
1579
|
}, [registry, controller, id, namespace, readOnly, subscribe]);
|
|
@@ -1560,7 +1601,7 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
1560
1601
|
}
|
|
1561
1602
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
1562
1603
|
const [, setTick] = useState7(0);
|
|
1563
|
-
|
|
1604
|
+
useEffect9(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
1564
1605
|
const provider = controller.effectsProvider;
|
|
1565
1606
|
const [browse, setBrowse] = useState7(null);
|
|
1566
1607
|
const [message, setMessage] = useState7(null);
|
|
@@ -1811,17 +1852,17 @@ import {
|
|
|
1811
1852
|
} from "@pixerate/editor/canvas";
|
|
1812
1853
|
|
|
1813
1854
|
// src/canvas/useCanvasAutoLayout.ts
|
|
1814
|
-
import { useLayoutEffect, useMemo as
|
|
1855
|
+
import { useLayoutEffect, useMemo as useMemo10, useRef as useRef14, useState as useState8 } from "react";
|
|
1815
1856
|
import {
|
|
1816
1857
|
createCanvasAutoLayoutController
|
|
1817
1858
|
} from "@pixerate/editor/canvas";
|
|
1818
1859
|
function useCanvasAutoLayout(options) {
|
|
1819
1860
|
const [guides, setGuides] = useState8([]);
|
|
1820
|
-
const nodesRef =
|
|
1861
|
+
const nodesRef = useRef14(options.nodes);
|
|
1821
1862
|
nodesRef.current = options.nodes;
|
|
1822
|
-
const optionsRef =
|
|
1863
|
+
const optionsRef = useRef14(options);
|
|
1823
1864
|
optionsRef.current = options;
|
|
1824
|
-
const controller =
|
|
1865
|
+
const controller = useMemo10(
|
|
1825
1866
|
() => createCanvasAutoLayoutController({
|
|
1826
1867
|
getNodes: () => nodesRef.current,
|
|
1827
1868
|
setNodes: (next) => {
|
|
@@ -1850,7 +1891,7 @@ function useCanvasAutoLayout(options) {
|
|
|
1850
1891
|
useLayoutEffect(() => {
|
|
1851
1892
|
if (controller.hasPending) controller.flush();
|
|
1852
1893
|
}, [options.nodes, controller]);
|
|
1853
|
-
return
|
|
1894
|
+
return useMemo10(
|
|
1854
1895
|
() => ({
|
|
1855
1896
|
...controller,
|
|
1856
1897
|
/** Drop marker of the active reorder drag (flow coordinates). */
|
|
@@ -1864,7 +1905,7 @@ function useCanvasAutoLayout(options) {
|
|
|
1864
1905
|
}
|
|
1865
1906
|
|
|
1866
1907
|
// src/canvas/useCanvasTokens.ts
|
|
1867
|
-
import { useCallback as useCallback9, useEffect as
|
|
1908
|
+
import { useCallback as useCallback9, useEffect as useEffect10, useRef as useRef15, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
1868
1909
|
import {
|
|
1869
1910
|
bindCanvasToken,
|
|
1870
1911
|
detachTokenBindings,
|
|
@@ -1875,10 +1916,10 @@ import {
|
|
|
1875
1916
|
function useCanvasTokens(options) {
|
|
1876
1917
|
const { store, nodes, setNodes, modes, properties } = options;
|
|
1877
1918
|
const state = useSyncExternalStore2(store.subscribe, store.getState, store.getState);
|
|
1878
|
-
const latest =
|
|
1919
|
+
const latest = useRef15({ nodes, setNodes, modes, properties });
|
|
1879
1920
|
latest.current = { nodes, setNodes, modes, properties };
|
|
1880
1921
|
const opts = () => ({ modes: latest.current.modes, properties: latest.current.properties });
|
|
1881
|
-
|
|
1922
|
+
useEffect10(
|
|
1882
1923
|
() => store.subscribe((event) => {
|
|
1883
1924
|
if (event.deletedVariableIds.length === 0) return;
|
|
1884
1925
|
latest.current.setNodes((prev) => detachTokenBindings(prev, event.previous, event.deletedVariableIds, opts()));
|
|
@@ -1887,7 +1928,7 @@ function useCanvasTokens(options) {
|
|
|
1887
1928
|
[store]
|
|
1888
1929
|
);
|
|
1889
1930
|
const modesKey = JSON.stringify(modes ?? {});
|
|
1890
|
-
|
|
1931
|
+
useEffect10(() => {
|
|
1891
1932
|
const next = resolveCanvasTokens(nodes, state, opts());
|
|
1892
1933
|
if (next !== nodes) setNodes(next);
|
|
1893
1934
|
}, [nodes, state, modesKey, properties]);
|
|
@@ -2058,16 +2099,16 @@ import {
|
|
|
2058
2099
|
} from "@pixerate/editor/canvas";
|
|
2059
2100
|
|
|
2060
2101
|
// src/canvas/useCanvasAnimation.ts
|
|
2061
|
-
import { useEffect as
|
|
2102
|
+
import { useEffect as useEffect11, useMemo as useMemo11, useRef as useRef16, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
2062
2103
|
import {
|
|
2063
2104
|
createCanvasAnimationController
|
|
2064
2105
|
} from "@pixerate/editor/canvas";
|
|
2065
2106
|
function useCanvasAnimation(options) {
|
|
2066
|
-
const nodesRef =
|
|
2107
|
+
const nodesRef = useRef16(options.nodes);
|
|
2067
2108
|
nodesRef.current = options.nodes;
|
|
2068
|
-
const optionsRef =
|
|
2109
|
+
const optionsRef = useRef16(options);
|
|
2069
2110
|
optionsRef.current = options;
|
|
2070
|
-
const controller =
|
|
2111
|
+
const controller = useMemo11(
|
|
2071
2112
|
() => createCanvasAnimationController({
|
|
2072
2113
|
getNodes: () => nodesRef.current,
|
|
2073
2114
|
setNodes: (next) => {
|
|
@@ -2094,14 +2135,14 @@ function useCanvasAnimation(options) {
|
|
|
2094
2135
|
}),
|
|
2095
2136
|
[]
|
|
2096
2137
|
);
|
|
2097
|
-
|
|
2098
|
-
|
|
2138
|
+
useEffect11(() => () => controller.destroy(), [controller]);
|
|
2139
|
+
useEffect11(() => {
|
|
2099
2140
|
if (options.loop !== void 0) controller.setLoop(options.loop);
|
|
2100
2141
|
}, [controller, options.loop]);
|
|
2101
|
-
|
|
2142
|
+
useEffect11(() => {
|
|
2102
2143
|
if (options.playbackRate !== void 0) controller.setPlaybackRate(options.playbackRate);
|
|
2103
2144
|
}, [controller, options.playbackRate]);
|
|
2104
|
-
|
|
2145
|
+
useEffect11(() => {
|
|
2105
2146
|
if (options.recording !== void 0) controller.setRecording(options.recording);
|
|
2106
2147
|
}, [controller, options.recording]);
|
|
2107
2148
|
const state = useSyncExternalStore3(
|
|
@@ -2109,11 +2150,11 @@ function useCanvasAnimation(options) {
|
|
|
2109
2150
|
() => controller.getState(),
|
|
2110
2151
|
() => controller.getState()
|
|
2111
2152
|
);
|
|
2112
|
-
|
|
2153
|
+
useEffect11(() => {
|
|
2113
2154
|
controller.refresh();
|
|
2114
2155
|
}, [controller, options.nodes]);
|
|
2115
|
-
const displayNodes =
|
|
2116
|
-
return
|
|
2156
|
+
const displayNodes = useMemo11(() => controller.display(options.nodes), [controller, options.nodes, state.time]);
|
|
2157
|
+
return useMemo11(
|
|
2117
2158
|
() => ({
|
|
2118
2159
|
...controller,
|
|
2119
2160
|
state,
|
|
@@ -2134,7 +2175,7 @@ function useCanvasAnimation(options) {
|
|
|
2134
2175
|
}
|
|
2135
2176
|
|
|
2136
2177
|
// src/canvas/AnimationTimeline.tsx
|
|
2137
|
-
import { useEffect as
|
|
2178
|
+
import { useEffect as useEffect12, useRef as useRef17 } from "react";
|
|
2138
2179
|
import {
|
|
2139
2180
|
ANIMATION_EASING_LABELS,
|
|
2140
2181
|
ANIMATION_EASING_PRESETS,
|
|
@@ -2157,8 +2198,8 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
2157
2198
|
for (const row of rows) for (const k of row.keyframes) if (k.selected && k.ref.property === first.property && k.ref.nodeId === first.nodeId) return easingValue(k.easing);
|
|
2158
2199
|
return "";
|
|
2159
2200
|
})();
|
|
2160
|
-
const dragRef =
|
|
2161
|
-
|
|
2201
|
+
const dragRef = useRef17(null);
|
|
2202
|
+
useEffect12(() => {
|
|
2162
2203
|
const onKey = (event) => {
|
|
2163
2204
|
if (event.key === "Escape" && dragRef.current) {
|
|
2164
2205
|
dragRef.current = null;
|
|
@@ -2396,16 +2437,16 @@ import {
|
|
|
2396
2437
|
} from "@pixerate/editor/canvas";
|
|
2397
2438
|
|
|
2398
2439
|
// src/canvas/useCanvasComponents.ts
|
|
2399
|
-
import { useLayoutEffect as useLayoutEffect2, useMemo as
|
|
2440
|
+
import { useLayoutEffect as useLayoutEffect2, useMemo as useMemo12, useRef as useRef18 } from "react";
|
|
2400
2441
|
import {
|
|
2401
2442
|
createCanvasComponentsController
|
|
2402
2443
|
} from "@pixerate/editor/canvas";
|
|
2403
2444
|
function useCanvasComponents(options) {
|
|
2404
|
-
const nodesRef =
|
|
2445
|
+
const nodesRef = useRef18(options.nodes);
|
|
2405
2446
|
nodesRef.current = options.nodes;
|
|
2406
|
-
const optionsRef =
|
|
2447
|
+
const optionsRef = useRef18(options);
|
|
2407
2448
|
optionsRef.current = options;
|
|
2408
|
-
const controller =
|
|
2449
|
+
const controller = useMemo12(
|
|
2409
2450
|
() => createCanvasComponentsController({
|
|
2410
2451
|
getNodes: () => nodesRef.current,
|
|
2411
2452
|
setNodes: (next) => {
|
|
@@ -3002,7 +3043,7 @@ function MermaidFamilyScene({
|
|
|
3002
3043
|
}
|
|
3003
3044
|
|
|
3004
3045
|
// src/canvas/useMermaidDiagram.ts
|
|
3005
|
-
import { useEffect as
|
|
3046
|
+
import { useEffect as useEffect13, useMemo as useMemo13, useRef as useRef19, useState as useState10, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
3006
3047
|
import {
|
|
3007
3048
|
DiagramController,
|
|
3008
3049
|
createDiagramEditorDocument
|
|
@@ -3021,7 +3062,7 @@ function useDiagramState(controller) {
|
|
|
3021
3062
|
return useSyncExternalStore4(controller.subscribe, controller.getState, controller.getState);
|
|
3022
3063
|
}
|
|
3023
3064
|
function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
3024
|
-
const own =
|
|
3065
|
+
const own = useRef19(null);
|
|
3025
3066
|
let controller;
|
|
3026
3067
|
if (controllerOrOptions instanceof DiagramController) controller = controllerOrOptions;
|
|
3027
3068
|
else {
|
|
@@ -3031,21 +3072,21 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3031
3072
|
const layoutOptions = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
|
|
3032
3073
|
const sceneTheme = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
|
|
3033
3074
|
const state = useDiagramState(controller);
|
|
3034
|
-
const editorDocument =
|
|
3035
|
-
|
|
3036
|
-
const canvas =
|
|
3075
|
+
const editorDocument = useMemo13(() => createDiagramEditorDocument(controller), [controller]);
|
|
3076
|
+
useEffect13(() => () => editorDocument.destroy(), [editorDocument]);
|
|
3077
|
+
const canvas = useMemo13(
|
|
3037
3078
|
() => mermaidToCanvas(state.document, { ...layoutOptions, editable: state.editable }),
|
|
3038
3079
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3039
3080
|
[state.document, state.editable]
|
|
3040
3081
|
);
|
|
3041
|
-
const scene =
|
|
3082
|
+
const scene = useMemo13(
|
|
3042
3083
|
() => state.document.tier === "editable" ? familySceneFromLayout(state.document.family, state.document.graph, canvas.layout, { theme: { ...CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
|
|
3043
3084
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3044
3085
|
[state.document, canvas.layout, state.selection]
|
|
3045
3086
|
);
|
|
3046
|
-
const layoutRef =
|
|
3087
|
+
const layoutRef = useRef19(canvas.layout);
|
|
3047
3088
|
layoutRef.current = canvas.layout;
|
|
3048
|
-
const actions =
|
|
3089
|
+
const actions = useMemo13(
|
|
3049
3090
|
() => ({
|
|
3050
3091
|
apply: (ops, label) => controller.apply(ops, label),
|
|
3051
3092
|
load: (source, options) => controller.load(source, options),
|
|
@@ -3082,13 +3123,13 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3082
3123
|
}
|
|
3083
3124
|
function useMermaidStream(source, options = {}) {
|
|
3084
3125
|
const { complete = false, duration = 300, ...layoutOptions } = options;
|
|
3085
|
-
const stream =
|
|
3126
|
+
const stream = useRef19(null);
|
|
3086
3127
|
if (!stream.current) stream.current = new DiagramStream(layoutOptions);
|
|
3087
|
-
const result =
|
|
3128
|
+
const result = useMemo13(() => stream.current.update(source, complete), [source, complete]);
|
|
3088
3129
|
const [shown, setShown] = useState10({ layout: result.layout, settled: true });
|
|
3089
|
-
const shownRef =
|
|
3130
|
+
const shownRef = useRef19(shown.layout);
|
|
3090
3131
|
shownRef.current = shown.layout;
|
|
3091
|
-
|
|
3132
|
+
useEffect13(() => {
|
|
3092
3133
|
const target = result.layout;
|
|
3093
3134
|
if (!target) return setShown({ layout: null, settled: true });
|
|
3094
3135
|
const from = shownRef.current;
|
|
@@ -3105,7 +3146,7 @@ function useMermaidStream(source, options = {}) {
|
|
|
3105
3146
|
return () => cancelAnimationFrame(frame);
|
|
3106
3147
|
}, [result.layout, duration]);
|
|
3107
3148
|
const doc = result.document.tier === "editable" ? result.document : null;
|
|
3108
|
-
const canvas =
|
|
3149
|
+
const canvas = useMemo13(() => {
|
|
3109
3150
|
if (!doc || !shown.layout) return { nodes: [], edges: [] };
|
|
3110
3151
|
const placed = new Set(Object.keys(shown.layout.positions));
|
|
3111
3152
|
const graph = {
|
|
@@ -3181,14 +3222,14 @@ function MermaidDiagramGroup({ data, selected, className = "", children }) {
|
|
|
3181
3222
|
}
|
|
3182
3223
|
|
|
3183
3224
|
// src/canvas/MermaidThumbnail.tsx
|
|
3184
|
-
import { useMemo as
|
|
3225
|
+
import { useMemo as useMemo14 } from "react";
|
|
3185
3226
|
import { parseMermaid } from "@pixerate/editor/diagram";
|
|
3186
3227
|
import { mermaidThumbnailSvg } from "@pixerate/editor/canvas";
|
|
3187
3228
|
import { Fragment as Fragment3, jsx as jsx12 } from "react/jsx-runtime";
|
|
3188
3229
|
function MermaidThumbnail({ source, className = "", fallback = null, ...options }) {
|
|
3189
|
-
const doc =
|
|
3230
|
+
const doc = useMemo14(() => typeof source === "string" ? parseMermaid(source) : source, [source]);
|
|
3190
3231
|
const key = JSON.stringify(options);
|
|
3191
|
-
const drawn =
|
|
3232
|
+
const drawn = useMemo14(
|
|
3192
3233
|
() => doc.tier === "editable" && doc.graph.nodes.length ? mermaidThumbnailSvg(doc, options) : null,
|
|
3193
3234
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3194
3235
|
[doc, key]
|
|
@@ -3198,12 +3239,12 @@ function MermaidThumbnail({ source, className = "", fallback = null, ...options
|
|
|
3198
3239
|
}
|
|
3199
3240
|
|
|
3200
3241
|
// src/canvas/useDiagramDirector.ts
|
|
3201
|
-
import { useRef as
|
|
3242
|
+
import { useRef as useRef20, useSyncExternalStore as useSyncExternalStore5 } from "react";
|
|
3202
3243
|
import { DiagramDirector, PresenceStore } from "@pixerate/editor/diagram";
|
|
3203
3244
|
function useDiagramDirector(controller, options) {
|
|
3204
|
-
const placement =
|
|
3245
|
+
const placement = useRef20(options.placement);
|
|
3205
3246
|
placement.current = options.placement;
|
|
3206
|
-
const ref =
|
|
3247
|
+
const ref = useRef20(null);
|
|
3207
3248
|
if (!ref.current) {
|
|
3208
3249
|
const presence = new PresenceStore();
|
|
3209
3250
|
ref.current = {
|
|
@@ -3569,6 +3610,7 @@ export {
|
|
|
3569
3610
|
useCanvasComponents,
|
|
3570
3611
|
useCanvasDocking,
|
|
3571
3612
|
useCanvasDraw,
|
|
3613
|
+
useCanvasEditorDocument,
|
|
3572
3614
|
useCanvasEffects,
|
|
3573
3615
|
useCanvasEffectsProviderContext,
|
|
3574
3616
|
useCanvasEffectsTools,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CanvasEdge, type CanvasEdgeLike, type CanvasEditorDocument, type CanvasEditorDocumentOptions, type CanvasNode } from '@pixerate/editor/canvas';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
|
+
export interface UseCanvasEditorDocumentOptions<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdgeLike = CanvasEdge> extends Pick<CanvasEditorDocumentOptions<TNode, TEdge>, 'history' | 'scenes' | 'readOnly'> {
|
|
4
|
+
nodes: TNode[];
|
|
5
|
+
edges: TEdge[];
|
|
6
|
+
setNodes: (nodes: TNode[]) => void;
|
|
7
|
+
setEdges: (edges: TEdge[]) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The save / load / undo contract (kind `canvas`) for nodes and edges held in React state, for
|
|
11
|
+
* `useEditorAutosave` or `createDocumentToolProvider`. Besides the history, it counts changes
|
|
12
|
+
* the history does not see (a finished drag, an edge removed by React Flow), but not selection
|
|
13
|
+
* or measuring, and not the frames of a drag in progress. Pass a stable `history` and `scenes`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useCanvasEditorDocument<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdgeLike = CanvasEdge>(options: UseCanvasEditorDocumentOptions<TNode, TEdge>): EditorDocument<CanvasEditorDocument<TNode, TEdge>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CanvasEdge, type CanvasEdgeLike, type CanvasEditorDocument, type CanvasEditorDocumentOptions, type CanvasNode } from '@pixerate/editor/canvas';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
|
+
export interface UseCanvasEditorDocumentOptions<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdgeLike = CanvasEdge> extends Pick<CanvasEditorDocumentOptions<TNode, TEdge>, 'history' | 'scenes' | 'readOnly'> {
|
|
4
|
+
nodes: TNode[];
|
|
5
|
+
edges: TEdge[];
|
|
6
|
+
setNodes: (nodes: TNode[]) => void;
|
|
7
|
+
setEdges: (edges: TEdge[]) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The save / load / undo contract (kind `canvas`) for nodes and edges held in React state, for
|
|
11
|
+
* `useEditorAutosave` or `createDocumentToolProvider`. Besides the history, it counts changes
|
|
12
|
+
* the history does not see (a finished drag, an edge removed by React Flow), but not selection
|
|
13
|
+
* or measuring, and not the frames of a drag in progress. Pass a stable `history` and `scenes`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useCanvasEditorDocument<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdgeLike = CanvasEdge>(options: UseCanvasEditorDocumentOptions<TNode, TEdge>): EditorDocument<CanvasEditorDocument<TNode, TEdge>>;
|
|
@@ -106,14 +106,20 @@ function useAutosave(options) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// src/persistence/useEditorAutosave.ts
|
|
109
|
-
import { useCallback as useCallback2 } from "react";
|
|
109
|
+
import { useCallback as useCallback2, useMemo } from "react";
|
|
110
110
|
import {
|
|
111
111
|
parseEditorDocument,
|
|
112
|
-
toEditorDocumentFile
|
|
112
|
+
toEditorDocumentFile,
|
|
113
|
+
withEditorAssets
|
|
113
114
|
} from "@pixerate/editor/persistence";
|
|
114
115
|
function useEditorAutosave(doc, options) {
|
|
116
|
+
const storage = useMemo(
|
|
117
|
+
() => doc.assets ? withEditorAssets(options.storage, doc.assets) : options.storage,
|
|
118
|
+
[options.storage, doc.assets]
|
|
119
|
+
);
|
|
115
120
|
const autosave = useAutosave({
|
|
116
121
|
...options,
|
|
122
|
+
storage,
|
|
117
123
|
key: options.key ?? doc.kind,
|
|
118
124
|
getSnapshot: () => toEditorDocumentFile(doc),
|
|
119
125
|
deserialize: (text) => parseEditorDocument(text, { kind: doc.kind }),
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
18
18
|
import {
|
|
19
19
|
ImageEditorController,
|
|
20
|
+
createImageEditorDocument,
|
|
20
21
|
createImageEffectsToolProvider
|
|
21
22
|
} from "@pixerate/editor/image-editor";
|
|
22
23
|
function useImageEditor(options = {}) {
|
|
@@ -119,9 +120,12 @@ function useImageEditor(options = {}) {
|
|
|
119
120
|
(newDataUrl, options2) => controller.applyBackgroundRemovedImage(newDataUrl, options2),
|
|
120
121
|
[controller]
|
|
121
122
|
);
|
|
123
|
+
const editorDocument = useMemo(() => createImageEditorDocument(controller), [controller]);
|
|
124
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
122
125
|
return useMemo(
|
|
123
126
|
() => ({
|
|
124
127
|
controller,
|
|
128
|
+
editorDocument,
|
|
125
129
|
state,
|
|
126
130
|
canUndo: controller.canUndo,
|
|
127
131
|
canRedo: controller.canRedo,
|
|
@@ -170,7 +174,7 @@ function useImageEditor(options = {}) {
|
|
|
170
174
|
applyBackgroundRemovedImage
|
|
171
175
|
}),
|
|
172
176
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
-
[controller, state, historyTicks, histogram]
|
|
177
|
+
[controller, editorDocument, state, historyTicks, histogram]
|
|
174
178
|
);
|
|
175
179
|
}
|
|
176
180
|
function useImageEffectsTools(registry, controller, options = {}) {
|
|
@@ -158,9 +158,12 @@ function useImageEditor(options = {}) {
|
|
|
158
158
|
(newDataUrl, options2) => controller.applyBackgroundRemovedImage(newDataUrl, options2),
|
|
159
159
|
[controller]
|
|
160
160
|
);
|
|
161
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_image_editor.createImageEditorDocument)(controller), [controller]);
|
|
162
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
161
163
|
return (0, import_react.useMemo)(
|
|
162
164
|
() => ({
|
|
163
165
|
controller,
|
|
166
|
+
editorDocument,
|
|
164
167
|
state,
|
|
165
168
|
canUndo: controller.canUndo,
|
|
166
169
|
canRedo: controller.canRedo,
|
|
@@ -209,7 +212,7 @@ function useImageEditor(options = {}) {
|
|
|
209
212
|
applyBackgroundRemovedImage
|
|
210
213
|
}),
|
|
211
214
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
-
[controller, state, historyTicks, histogram]
|
|
215
|
+
[controller, editorDocument, state, historyTicks, histogram]
|
|
213
216
|
);
|
|
214
217
|
}
|
|
215
218
|
function useImageEffectsTools(registry, controller, options = {}) {
|
|
@@ -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;
|