@pixerate/editor-react 0.107.0 → 0.109.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 +1 -1
- package/dist/canvas/index.cjs +767 -692
- package/dist/canvas/index.d.cts +4 -2
- package/dist/canvas/index.d.ts +4 -2
- package/dist/canvas/index.js +285 -208
- package/dist/canvas/useCanvasExplosion.d.cts +23 -5
- package/dist/canvas/useCanvasExplosion.d.ts +23 -5
- package/dist/canvas/useCanvasExplosionState.d.cts +17 -0
- package/dist/canvas/useCanvasExplosionState.d.ts +17 -0
- package/dist/chart/ChartDataGrid.d.cts +5 -0
- package/dist/chart/ChartDataGrid.d.ts +5 -0
- package/dist/chart/ChartInspector.d.cts +1 -1
- package/dist/chart/ChartInspector.d.ts +1 -1
- package/dist/chart/index.cjs +136 -3
- package/dist/chart/index.js +3 -1
- package/dist/{chunk-FUR7LCDM.js → chunk-GJ3IMZQW.js} +152 -5
- package/dist/index.cjs +134 -3
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/canvas/index.js
CHANGED
|
@@ -681,9 +681,9 @@ function useCanvasDocking(options = {}) {
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
// src/canvas/useCanvasExplosion.ts
|
|
684
|
-
import { useCallback as useCallback6, useRef as useRef5 } from "react";
|
|
684
|
+
import { useCallback as useCallback6, useEffect as useEffect3, useRef as useRef5, useState as useState2 } from "react";
|
|
685
685
|
import {
|
|
686
|
-
|
|
686
|
+
computeCanvasExplosionLayout,
|
|
687
687
|
createFanOutTrajectory,
|
|
688
688
|
linearPositionTrajectory,
|
|
689
689
|
runMultiNodeTransition
|
|
@@ -693,75 +693,89 @@ function mergeById(base, updated) {
|
|
|
693
693
|
const byId = new Map(updated.map((n) => [n.id, n]));
|
|
694
694
|
return base.map((n) => byId.get(n.id) ?? n);
|
|
695
695
|
}
|
|
696
|
-
function useCanvasExplosion(target) {
|
|
696
|
+
function useCanvasExplosion(target, hookOptions = {}) {
|
|
697
697
|
const snapshotsRef = useRef5(/* @__PURE__ */ new Map());
|
|
698
|
+
const cancelRef = useRef5(null);
|
|
699
|
+
const [explodedNodeIds, setExplodedNodeIds] = useState2([]);
|
|
700
|
+
const optionsRef = useRef5(hookOptions);
|
|
701
|
+
optionsRef.current = hookOptions;
|
|
702
|
+
useEffect3(() => () => cancelRef.current?.(), []);
|
|
703
|
+
const run = (transitions, base, duration, onComplete) => {
|
|
704
|
+
cancelRef.current?.();
|
|
705
|
+
cancelRef.current = runMultiNodeTransition(transitions, {
|
|
706
|
+
styleFormat: "object",
|
|
707
|
+
defaultDuration: duration,
|
|
708
|
+
onUpdate: (updated) => target.setNodes(mergeById(base, updated)),
|
|
709
|
+
onComplete: () => {
|
|
710
|
+
cancelRef.current = null;
|
|
711
|
+
onComplete();
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
};
|
|
698
715
|
const explodeNode = useCallback6(
|
|
699
716
|
(parentNodeId, options) => {
|
|
700
717
|
const { nodes, edges, setNodes, setEdges } = target;
|
|
718
|
+
if (snapshotsRef.current.has(parentNodeId)) return false;
|
|
701
719
|
const parent = nodes.find((n) => n.id === parentNodeId);
|
|
702
|
-
if (!parent || options.childNodes.length === 0) return;
|
|
703
|
-
const
|
|
704
|
-
|
|
720
|
+
if (!parent || options.childNodes.length === 0) return false;
|
|
721
|
+
const {
|
|
722
|
+
connectParentToChildren = "all",
|
|
723
|
+
displacementStrategy = "directional",
|
|
724
|
+
duration = 500,
|
|
725
|
+
staggerDelay = 20,
|
|
726
|
+
easing
|
|
727
|
+
} = options;
|
|
728
|
+
const layout = computeCanvasExplosionLayout({
|
|
705
729
|
existingNodes: nodes,
|
|
730
|
+
existingEdges: edges,
|
|
706
731
|
originNode: parent,
|
|
707
732
|
childNodes: options.childNodes,
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
733
|
+
childEdges: options.childEdges,
|
|
734
|
+
strategy: displacementStrategy,
|
|
735
|
+
options: options.directionalOptions,
|
|
736
|
+
reflowOptions: options.reflowOptions,
|
|
737
|
+
connectParentToChildren,
|
|
738
|
+
createEdge: target.createEdge,
|
|
739
|
+
getNodesBounds: optionsRef.current.getNodesBounds
|
|
740
|
+
});
|
|
741
|
+
snapshotsRef.current.set(parentNodeId, {
|
|
711
742
|
parentId: parentNodeId,
|
|
712
|
-
childNodeIds:
|
|
713
|
-
childEdgeIds:
|
|
714
|
-
displacedNodes:
|
|
715
|
-
const node = nodes.find((n) => n.id === id);
|
|
716
|
-
return { id, originalPosition: { ...node.position } };
|
|
717
|
-
}),
|
|
743
|
+
childNodeIds: layout.childNodes.map((c) => c.id),
|
|
744
|
+
childEdgeIds: layout.childEdges.map((e) => e.id),
|
|
745
|
+
displacedNodes: [...layout.originalPositions].map(([id, originalPosition]) => ({ id, originalPosition })),
|
|
718
746
|
timestamp: Date.now()
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
const initialChildren =
|
|
722
|
-
...child,
|
|
723
|
-
position: { ...originPos }
|
|
724
|
-
}));
|
|
747
|
+
});
|
|
748
|
+
const originPos = { ...parent.position };
|
|
749
|
+
const initialChildren = layout.childNodes.map((child) => ({ ...child, position: { ...originPos } }));
|
|
725
750
|
const mergedNodes = [...nodes, ...initialChildren];
|
|
726
751
|
setNodes(mergedNodes);
|
|
727
|
-
if (
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
const trajectory = options.trajectory ?? createFanOutTrajectory();
|
|
752
|
+
if (layout.childEdges.length > 0) setEdges((prev) => [...prev, ...layout.childEdges]);
|
|
753
|
+
const trajectory = options.trajectory ?? createFanOutTrajectory({ curvature: 0.35 });
|
|
754
|
+
const stagger = duration === 0 ? 0 : staggerDelay;
|
|
731
755
|
const transitions = [];
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
});
|
|
745
|
-
}
|
|
756
|
+
layout.childNodes.forEach((child, index) => {
|
|
757
|
+
transitions.push({
|
|
758
|
+
node: initialChildren[index],
|
|
759
|
+
from: originPos,
|
|
760
|
+
to: child.position,
|
|
761
|
+
trajectory,
|
|
762
|
+
delay: index * stagger,
|
|
763
|
+
index,
|
|
764
|
+
total: layout.childNodes.length,
|
|
765
|
+
duration,
|
|
766
|
+
easing
|
|
767
|
+
});
|
|
746
768
|
});
|
|
747
|
-
|
|
769
|
+
layout.displacedPositions.forEach((to, nodeId) => {
|
|
748
770
|
const node = mergedNodes.find((n) => n.id === nodeId);
|
|
749
|
-
if (node) {
|
|
750
|
-
transitions.push({
|
|
751
|
-
node,
|
|
752
|
-
from: { ...node.position },
|
|
753
|
-
to: targetPos,
|
|
754
|
-
trajectory: linearPositionTrajectory,
|
|
755
|
-
duration: options.duration ?? 400,
|
|
756
|
-
easing: options.easing
|
|
757
|
-
});
|
|
758
|
-
}
|
|
771
|
+
if (node) transitions.push({ node, from: { ...node.position }, to, trajectory: linearPositionTrajectory, duration, easing });
|
|
759
772
|
});
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
773
|
+
run(transitions, mergedNodes, duration, () => {
|
|
774
|
+
setExplodedNodeIds((prev) => prev.includes(parentNodeId) ? prev : [...prev, parentNodeId]);
|
|
775
|
+
optionsRef.current.onSave?.();
|
|
776
|
+
options.onComplete?.();
|
|
764
777
|
});
|
|
778
|
+
return true;
|
|
765
779
|
},
|
|
766
780
|
[target]
|
|
767
781
|
);
|
|
@@ -769,71 +783,124 @@ function useCanvasExplosion(target) {
|
|
|
769
783
|
(parentNodeId, options = {}) => {
|
|
770
784
|
const { nodes, setNodes, setEdges } = target;
|
|
771
785
|
const snapshot = snapshotsRef.current.get(parentNodeId);
|
|
772
|
-
if (!snapshot) return;
|
|
786
|
+
if (!snapshot) return false;
|
|
773
787
|
const parent = nodes.find((n) => n.id === parentNodeId);
|
|
774
788
|
const originPos = parent ? { ...parent.position } : { x: 0, y: 0 };
|
|
775
789
|
const childIdSet = new Set(snapshot.childNodeIds);
|
|
776
790
|
const edgeIdSet = new Set(snapshot.childEdgeIds);
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
791
|
+
const { duration = 400, staggerDelay = 15, easing } = options;
|
|
792
|
+
const trajectory = options.trajectory ?? createFanOutTrajectory({ curvature: 0.2, startScale: 1, endScale: 0, startOpacity: 1, endOpacity: 0 });
|
|
793
|
+
const stagger = duration === 0 ? 0 : staggerDelay;
|
|
794
|
+
const children = nodes.filter((n) => childIdSet.has(n.id));
|
|
795
|
+
const transitions = children.map((node, i) => ({
|
|
796
|
+
node,
|
|
797
|
+
from: { ...node.position },
|
|
798
|
+
to: originPos,
|
|
799
|
+
trajectory,
|
|
800
|
+
delay: (children.length - 1 - i) * stagger,
|
|
801
|
+
index: i,
|
|
802
|
+
total: children.length,
|
|
803
|
+
duration,
|
|
804
|
+
easing
|
|
805
|
+
}));
|
|
790
806
|
snapshot.displacedNodes.forEach((disp) => {
|
|
791
807
|
const node = nodes.find((n) => n.id === disp.id);
|
|
792
808
|
if (node) {
|
|
793
|
-
transitions.push({
|
|
794
|
-
node,
|
|
795
|
-
from: { ...node.position },
|
|
796
|
-
to: disp.originalPosition,
|
|
797
|
-
duration: options.duration ?? 300,
|
|
798
|
-
easing: options.easing,
|
|
799
|
-
trajectory: linearPositionTrajectory
|
|
800
|
-
});
|
|
809
|
+
transitions.push({ node, from: { ...node.position }, to: disp.originalPosition, trajectory: linearPositionTrajectory, duration, easing });
|
|
801
810
|
}
|
|
802
811
|
});
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
+
run(transitions, nodes, duration, () => {
|
|
813
|
+
const restore = new Map(snapshot.displacedNodes.map((d) => [d.id, d.originalPosition]));
|
|
814
|
+
setNodes(
|
|
815
|
+
(prev) => prev.filter((n) => !childIdSet.has(n.id)).map((n) => restore.has(n.id) ? { ...n, position: { ...restore.get(n.id) } } : n)
|
|
816
|
+
);
|
|
817
|
+
setEdges((prev) => prev.filter((e) => !edgeIdSet.has(e.id)));
|
|
818
|
+
snapshotsRef.current.delete(parentNodeId);
|
|
819
|
+
setExplodedNodeIds((prev) => prev.filter((id) => id !== parentNodeId));
|
|
820
|
+
optionsRef.current.onSave?.();
|
|
821
|
+
options.onComplete?.();
|
|
812
822
|
});
|
|
823
|
+
return true;
|
|
813
824
|
},
|
|
814
825
|
[target]
|
|
815
826
|
);
|
|
827
|
+
const toggleExplode = useCallback6(
|
|
828
|
+
(parentNodeId, explodeOptions, collapseOptions) => snapshotsRef.current.has(parentNodeId) ? collapseNode(parentNodeId, collapseOptions) : explodeNode(parentNodeId, explodeOptions),
|
|
829
|
+
[explodeNode, collapseNode]
|
|
830
|
+
);
|
|
816
831
|
return {
|
|
832
|
+
/** Ids of nodes whose explosion animation has finished (and not yet collapsed). */
|
|
833
|
+
explodedNodeIds,
|
|
817
834
|
explodeNode,
|
|
818
835
|
collapseNode,
|
|
819
|
-
|
|
836
|
+
toggleExplode,
|
|
837
|
+
/** True once the node's explosion has finished, until a collapse finishes. */
|
|
838
|
+
isExploded: (parentNodeId) => explodedNodeIds.includes(parentNodeId),
|
|
820
839
|
getSnapshot: (parentNodeId) => snapshotsRef.current.get(parentNodeId)
|
|
821
840
|
};
|
|
822
841
|
}
|
|
823
842
|
|
|
843
|
+
// src/canvas/useCanvasExplosionState.ts
|
|
844
|
+
import { useEffect as useEffect4, useMemo as useMemo2, useRef as useRef6, useSyncExternalStore } from "react";
|
|
845
|
+
import {
|
|
846
|
+
createCanvasExplosionStateController
|
|
847
|
+
} from "@pixerate/editor/canvas";
|
|
848
|
+
function useCanvasExplosionState(options = {}) {
|
|
849
|
+
const optionsRef = useRef6(options);
|
|
850
|
+
optionsRef.current = options;
|
|
851
|
+
const controllerRef = useRef6(null);
|
|
852
|
+
if (controllerRef.current === null) {
|
|
853
|
+
controllerRef.current = createCanvasExplosionStateController({
|
|
854
|
+
collapseDurationMs: options.collapseDurationMs,
|
|
855
|
+
initialActiveId: options.initialActiveId,
|
|
856
|
+
onExplode: (id) => optionsRef.current.onExplode?.(id),
|
|
857
|
+
onCollapse: (id) => optionsRef.current.onCollapse?.(id)
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
const controller = controllerRef.current;
|
|
861
|
+
useEffect4(() => () => controller.finishCollapse(), [controller]);
|
|
862
|
+
const snapshot = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
|
|
863
|
+
return useMemo2(
|
|
864
|
+
() => ({
|
|
865
|
+
controller,
|
|
866
|
+
activeId: snapshot.activeId,
|
|
867
|
+
collapsingId: snapshot.collapsingId,
|
|
868
|
+
isExplodingOrCollapsing: snapshot.activeId !== null || snapshot.collapsingId !== null,
|
|
869
|
+
isExploded: (nodeId) => snapshot.activeId === nodeId,
|
|
870
|
+
isCollapsing: (nodeId) => snapshot.collapsingId === nodeId,
|
|
871
|
+
shouldRenderChildren: (nodeId) => snapshot.activeId === nodeId || snapshot.collapsingId === nodeId,
|
|
872
|
+
explode: (nodeId) => controller.explode(nodeId),
|
|
873
|
+
collapse: (nodeId) => controller.collapse(nodeId),
|
|
874
|
+
toggle: (nodeId) => controller.toggle(nodeId),
|
|
875
|
+
finishCollapse: () => controller.finishCollapse(),
|
|
876
|
+
destroy: () => controller.destroy()
|
|
877
|
+
}),
|
|
878
|
+
[controller, snapshot]
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/canvas/index.ts
|
|
883
|
+
import {
|
|
884
|
+
computeCanvasExplosionLayout as computeCanvasExplosionLayout2,
|
|
885
|
+
explosionEdgeId,
|
|
886
|
+
createCanvasExplosionStateController as createCanvasExplosionStateController2,
|
|
887
|
+
createCanvasExplosionToolProvider,
|
|
888
|
+
canvasExplosionToolTarget
|
|
889
|
+
} from "@pixerate/editor/canvas";
|
|
890
|
+
|
|
824
891
|
// src/canvas/useCanvasArrange.ts
|
|
825
|
-
import { useEffect as
|
|
892
|
+
import { useEffect as useEffect5, useMemo as useMemo3, useRef as useRef7, useState as useState3 } from "react";
|
|
826
893
|
import {
|
|
827
894
|
createCanvasArrangeController,
|
|
828
895
|
matchArrangeShortcut
|
|
829
896
|
} from "@pixerate/editor/canvas";
|
|
830
897
|
function useCanvasArrange(options) {
|
|
831
|
-
const [guides, setGuides] =
|
|
832
|
-
const nodesRef =
|
|
898
|
+
const [guides, setGuides] = useState3([]);
|
|
899
|
+
const nodesRef = useRef7(options.nodes);
|
|
833
900
|
nodesRef.current = options.nodes;
|
|
834
|
-
const optionsRef =
|
|
901
|
+
const optionsRef = useRef7(options);
|
|
835
902
|
optionsRef.current = options;
|
|
836
|
-
const controller =
|
|
903
|
+
const controller = useMemo3(
|
|
837
904
|
() => createCanvasArrangeController({
|
|
838
905
|
getNodes: () => nodesRef.current,
|
|
839
906
|
setNodes: (next) => {
|
|
@@ -861,13 +928,13 @@ function useCanvasArrange(options) {
|
|
|
861
928
|
}),
|
|
862
929
|
[]
|
|
863
930
|
);
|
|
864
|
-
return
|
|
931
|
+
return useMemo3(() => ({ ...controller, guides }), [controller, guides]);
|
|
865
932
|
}
|
|
866
933
|
function useCanvasArrangeShortcuts(options) {
|
|
867
|
-
const optionsRef =
|
|
934
|
+
const optionsRef = useRef7(options);
|
|
868
935
|
optionsRef.current = options;
|
|
869
936
|
const { targetElement, enabled = true } = options;
|
|
870
|
-
|
|
937
|
+
useEffect5(() => {
|
|
871
938
|
if (!enabled) return;
|
|
872
939
|
const target = targetElement ?? (typeof window !== "undefined" ? window : null);
|
|
873
940
|
if (!target) return;
|
|
@@ -892,24 +959,24 @@ function useCanvasArrangeShortcuts(options) {
|
|
|
892
959
|
}
|
|
893
960
|
|
|
894
961
|
// src/canvas/useCanvasScenes.ts
|
|
895
|
-
import { useMemo as
|
|
962
|
+
import { useMemo as useMemo4, useRef as useRef8, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
896
963
|
import {
|
|
897
964
|
CanvasScenesStore,
|
|
898
965
|
fitViewportToNodes,
|
|
899
966
|
transitionCanvasView
|
|
900
967
|
} from "@pixerate/editor/canvas";
|
|
901
968
|
function useCanvasScenes(options = {}) {
|
|
902
|
-
const optionsRef =
|
|
969
|
+
const optionsRef = useRef8(options);
|
|
903
970
|
optionsRef.current = options;
|
|
904
|
-
const storeRef =
|
|
971
|
+
const storeRef = useRef8(null);
|
|
905
972
|
if (!storeRef.current) storeRef.current = options.store ?? new CanvasScenesStore(options);
|
|
906
973
|
const store = storeRef.current;
|
|
907
|
-
const state =
|
|
974
|
+
const state = useSyncExternalStore2(
|
|
908
975
|
(listener) => store.subscribe(listener),
|
|
909
976
|
() => store.getState(),
|
|
910
977
|
() => store.getState()
|
|
911
978
|
);
|
|
912
|
-
const actions =
|
|
979
|
+
const actions = useMemo4(() => {
|
|
913
980
|
const show = (scene) => {
|
|
914
981
|
if (!scene) return scene;
|
|
915
982
|
const o = optionsRef.current;
|
|
@@ -962,16 +1029,16 @@ function useCanvasScenes(options = {}) {
|
|
|
962
1029
|
}
|
|
963
1030
|
|
|
964
1031
|
// src/canvas/useCanvasCapture.ts
|
|
965
|
-
import { useMemo as
|
|
1032
|
+
import { useMemo as useMemo5, useRef as useRef9 } from "react";
|
|
966
1033
|
import {
|
|
967
1034
|
canvasNodeCaptureRect,
|
|
968
1035
|
createCanvasCaptureToolProvider
|
|
969
1036
|
} from "@pixerate/editor/canvas";
|
|
970
1037
|
import { rasterizeElement } from "@pixerate/editor/tools";
|
|
971
1038
|
function useCanvasCapture(options) {
|
|
972
|
-
const optionsRef =
|
|
1039
|
+
const optionsRef = useRef9(options);
|
|
973
1040
|
optionsRef.current = options;
|
|
974
|
-
return
|
|
1041
|
+
return useMemo5(() => {
|
|
975
1042
|
const latest = () => optionsRef.current;
|
|
976
1043
|
return createCanvasCaptureToolProvider({
|
|
977
1044
|
...options,
|
|
@@ -990,7 +1057,7 @@ function useCanvasCapture(options) {
|
|
|
990
1057
|
}
|
|
991
1058
|
|
|
992
1059
|
// src/canvas/useCanvasEditorDocument.ts
|
|
993
|
-
import { useEffect as
|
|
1060
|
+
import { useEffect as useEffect6, useMemo as useMemo6, useRef as useRef10 } from "react";
|
|
994
1061
|
import {
|
|
995
1062
|
createCanvasEditorDocument
|
|
996
1063
|
} from "@pixerate/editor/canvas";
|
|
@@ -999,10 +1066,10 @@ var contentKey = (nodes, edges) => JSON.stringify([
|
|
|
999
1066
|
edges.map(({ selected: _s, ...rest }) => rest)
|
|
1000
1067
|
]);
|
|
1001
1068
|
function useCanvasEditorDocument(options) {
|
|
1002
|
-
const latest =
|
|
1069
|
+
const latest = useRef10(options);
|
|
1003
1070
|
latest.current = options;
|
|
1004
|
-
const listeners =
|
|
1005
|
-
const doc =
|
|
1071
|
+
const listeners = useRef10(/* @__PURE__ */ new Set());
|
|
1072
|
+
const doc = useMemo6(
|
|
1006
1073
|
() => createCanvasEditorDocument({
|
|
1007
1074
|
getNodes: () => latest.current.nodes,
|
|
1008
1075
|
setNodes: (nodes) => latest.current.setNodes(nodes),
|
|
@@ -1019,9 +1086,9 @@ function useCanvasEditorDocument(options) {
|
|
|
1019
1086
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1020
1087
|
[options.history, options.scenes]
|
|
1021
1088
|
);
|
|
1022
|
-
|
|
1023
|
-
const lastKey =
|
|
1024
|
-
|
|
1089
|
+
useEffect6(() => () => doc.destroy(), [doc]);
|
|
1090
|
+
const lastKey = useRef10(null);
|
|
1091
|
+
useEffect6(() => {
|
|
1025
1092
|
if (options.nodes.some((n) => n.dragging)) return;
|
|
1026
1093
|
const key = contentKey(options.nodes, options.edges);
|
|
1027
1094
|
if (lastKey.current !== null && key !== lastKey.current) listeners.current.forEach((listener) => listener());
|
|
@@ -1114,18 +1181,18 @@ function CanvasGuidesLayer({
|
|
|
1114
1181
|
}
|
|
1115
1182
|
|
|
1116
1183
|
// src/canvas/useCanvasDraw.ts
|
|
1117
|
-
import { useEffect as
|
|
1184
|
+
import { useEffect as useEffect7, useMemo as useMemo7, useRef as useRef11, useState as useState4 } from "react";
|
|
1118
1185
|
import {
|
|
1119
1186
|
createCanvasDrawController
|
|
1120
1187
|
} from "@pixerate/editor/canvas";
|
|
1121
1188
|
function useCanvasDraw(options) {
|
|
1122
|
-
const nodesRef =
|
|
1189
|
+
const nodesRef = useRef11(options.nodes);
|
|
1123
1190
|
nodesRef.current = options.nodes;
|
|
1124
|
-
const optionsRef =
|
|
1191
|
+
const optionsRef = useRef11(options);
|
|
1125
1192
|
optionsRef.current = options;
|
|
1126
|
-
const [tool, setToolState] =
|
|
1127
|
-
const [activeStroke, setActiveStroke] =
|
|
1128
|
-
const controller =
|
|
1193
|
+
const [tool, setToolState] = useState4(options.initialTool ?? "select");
|
|
1194
|
+
const [activeStroke, setActiveStroke] = useState4(null);
|
|
1195
|
+
const controller = useMemo7(
|
|
1129
1196
|
() => createCanvasDrawController({
|
|
1130
1197
|
getNodes: () => nodesRef.current,
|
|
1131
1198
|
setNodes: (next) => {
|
|
@@ -1147,13 +1214,13 @@ function useCanvasDraw(options) {
|
|
|
1147
1214
|
}),
|
|
1148
1215
|
[]
|
|
1149
1216
|
);
|
|
1150
|
-
const [style, setStyleState] =
|
|
1151
|
-
|
|
1217
|
+
const [style, setStyleState] = useState4(controller.style);
|
|
1218
|
+
useEffect7(() => {
|
|
1152
1219
|
if (options.initialTool && options.initialTool !== controller.tool) {
|
|
1153
1220
|
controller.setTool(options.initialTool);
|
|
1154
1221
|
}
|
|
1155
1222
|
}, [options.initialTool, controller]);
|
|
1156
|
-
return
|
|
1223
|
+
return useMemo7(
|
|
1157
1224
|
() => ({
|
|
1158
1225
|
tool,
|
|
1159
1226
|
style,
|
|
@@ -1174,7 +1241,7 @@ function useCanvasDraw(options) {
|
|
|
1174
1241
|
}
|
|
1175
1242
|
|
|
1176
1243
|
// src/canvas/CanvasDrawLayer.tsx
|
|
1177
|
-
import { useCallback as useCallback7, useEffect as
|
|
1244
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useRef as useRef12, useState as useState5 } from "react";
|
|
1178
1245
|
import {
|
|
1179
1246
|
pointerPenSample,
|
|
1180
1247
|
strokePointsToPathData,
|
|
@@ -1191,10 +1258,10 @@ function CanvasDrawLayer({
|
|
|
1191
1258
|
cursor,
|
|
1192
1259
|
eraserRadius = 12
|
|
1193
1260
|
}) {
|
|
1194
|
-
const svgRef =
|
|
1195
|
-
const [spaceHeld, setSpaceHeld] =
|
|
1196
|
-
const [eraserPos, setEraserPos] =
|
|
1197
|
-
|
|
1261
|
+
const svgRef = useRef12(null);
|
|
1262
|
+
const [spaceHeld, setSpaceHeld] = useState5(false);
|
|
1263
|
+
const [eraserPos, setEraserPos] = useState5(null);
|
|
1264
|
+
useEffect8(() => {
|
|
1198
1265
|
function onKeyDown(e) {
|
|
1199
1266
|
if (e.code === "Space" && !e.repeat) {
|
|
1200
1267
|
const tag = e.target?.tagName;
|
|
@@ -1331,7 +1398,7 @@ function CanvasDrawLayer({
|
|
|
1331
1398
|
}
|
|
1332
1399
|
|
|
1333
1400
|
// src/canvas/useCanvasMeasure.ts
|
|
1334
|
-
import { useCallback as useCallback8, useEffect as
|
|
1401
|
+
import { useCallback as useCallback8, useEffect as useEffect9, useMemo as useMemo8, useRef as useRef13, useState as useState6 } from "react";
|
|
1335
1402
|
import {
|
|
1336
1403
|
isMeasureModifierHeld,
|
|
1337
1404
|
measureSelection
|
|
@@ -1339,11 +1406,11 @@ import {
|
|
|
1339
1406
|
var EMPTY = { guides: [], target: null, selection: null };
|
|
1340
1407
|
function useCanvasMeasure(options) {
|
|
1341
1408
|
const { nodes, enabled = true, requireModifier = true, targetElement, rectOptions } = options;
|
|
1342
|
-
const [hoveredId, setHoveredId] =
|
|
1343
|
-
const [modifier, setModifier] =
|
|
1344
|
-
const optionsRef =
|
|
1409
|
+
const [hoveredId, setHoveredId] = useState6(null);
|
|
1410
|
+
const [modifier, setModifier] = useState6(false);
|
|
1411
|
+
const optionsRef = useRef13(options);
|
|
1345
1412
|
optionsRef.current = options;
|
|
1346
|
-
|
|
1413
|
+
useEffect9(() => {
|
|
1347
1414
|
if (!enabled) return;
|
|
1348
1415
|
const target = targetElement ?? (typeof window !== "undefined" ? window : null);
|
|
1349
1416
|
if (!target) return;
|
|
@@ -1360,7 +1427,7 @@ function useCanvasMeasure(options) {
|
|
|
1360
1427
|
};
|
|
1361
1428
|
}, [enabled, targetElement]);
|
|
1362
1429
|
const active = enabled && (!requireModifier || modifier);
|
|
1363
|
-
const result =
|
|
1430
|
+
const result = useMemo8(() => {
|
|
1364
1431
|
if (!active) return EMPTY;
|
|
1365
1432
|
const ids = optionsRef.current.getSelectedIds?.() ?? nodes.filter((n) => n.selected).map((n) => n.id);
|
|
1366
1433
|
return measureSelection(nodes, ids, hoveredId, rectOptions);
|
|
@@ -1450,7 +1517,7 @@ import {
|
|
|
1450
1517
|
import { getShapeRenderData, isShapeDescription as isShapeDescription2 } from "@pixerate/editor/canvas";
|
|
1451
1518
|
|
|
1452
1519
|
// src/canvas/useShapeBrushstroke.tsx
|
|
1453
|
-
import { createContext, useContext, useEffect as
|
|
1520
|
+
import { createContext, useContext, useEffect as useEffect10, useMemo as useMemo9, useState as useState7 } from "react";
|
|
1454
1521
|
import {
|
|
1455
1522
|
brushstrokeScaleBucket,
|
|
1456
1523
|
isBrushedShape,
|
|
@@ -1474,8 +1541,8 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1474
1541
|
const unit = vb && width && vb[2] > 0 ? width / vb[2] : 1;
|
|
1475
1542
|
const ox = Math.round((position?.x ?? 0) - (vb?.[0] ?? 0) * unit);
|
|
1476
1543
|
const oy = Math.round((position?.y ?? 0) - (vb?.[1] ?? 0) * unit);
|
|
1477
|
-
const [image, setImage] =
|
|
1478
|
-
|
|
1544
|
+
const [image, setImage] = useState7(null);
|
|
1545
|
+
useEffect10(() => {
|
|
1479
1546
|
if (!brushed) {
|
|
1480
1547
|
setImage(null);
|
|
1481
1548
|
return;
|
|
@@ -1496,9 +1563,9 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1496
1563
|
return image;
|
|
1497
1564
|
}
|
|
1498
1565
|
function useCanvasBrushes(options = {}) {
|
|
1499
|
-
const [state, setState] =
|
|
1566
|
+
const [state, setState] = useState7({ brushes: [], loading: true, error: null });
|
|
1500
1567
|
const swatches = options.swatches ? JSON.stringify(options.swatches) : "";
|
|
1501
|
-
|
|
1568
|
+
useEffect10(() => {
|
|
1502
1569
|
let live = true;
|
|
1503
1570
|
const opts = swatches ? JSON.parse(swatches) : null;
|
|
1504
1571
|
listCanvasBrushes().then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await renderCanvasBrushSwatch(b.id, opts) }))) : list).then(
|
|
@@ -1509,11 +1576,11 @@ function useCanvasBrushes(options = {}) {
|
|
|
1509
1576
|
live = false;
|
|
1510
1577
|
};
|
|
1511
1578
|
}, [swatches]);
|
|
1512
|
-
return
|
|
1579
|
+
return useMemo9(() => state, [state]);
|
|
1513
1580
|
}
|
|
1514
1581
|
|
|
1515
1582
|
// src/canvas/CanvasEffects.tsx
|
|
1516
|
-
import { createContext as createContext2, useContext as useContext2, useEffect as
|
|
1583
|
+
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect11, useMemo as useMemo10, useRef as useRef14, useState as useState8 } from "react";
|
|
1517
1584
|
import {
|
|
1518
1585
|
createCanvasEffectsController,
|
|
1519
1586
|
createCanvasEffectsToolProvider,
|
|
@@ -1528,20 +1595,20 @@ function CanvasEffectsProvider({ provider, children }) {
|
|
|
1528
1595
|
var useCanvasEffectsProviderContext = () => useContext2(ProviderContext);
|
|
1529
1596
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
1530
1597
|
const provider = useCanvasEffectsProviderContext();
|
|
1531
|
-
const ref =
|
|
1532
|
-
const [failed, setFailed] =
|
|
1598
|
+
const ref = useRef14(null);
|
|
1599
|
+
const [failed, setFailed] = useState8(false);
|
|
1533
1600
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
1534
1601
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
1535
1602
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
1536
1603
|
const key = JSON.stringify(effect);
|
|
1537
|
-
|
|
1604
|
+
useEffect11(() => {
|
|
1538
1605
|
const canvas2 = ref.current;
|
|
1539
1606
|
if (!provider || !canvas2) return;
|
|
1540
1607
|
setFailed(false);
|
|
1541
1608
|
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: () => setFailed(true) });
|
|
1542
1609
|
return () => run.stop();
|
|
1543
1610
|
}, [provider, key, pw, ph]);
|
|
1544
|
-
const clipId =
|
|
1611
|
+
const clipId = useMemo10(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
1545
1612
|
if (!provider || failed || !(width > 0 && height > 0)) return null;
|
|
1546
1613
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
1547
1614
|
const canvas = /* @__PURE__ */ jsx5("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
@@ -1552,9 +1619,9 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
1552
1619
|
] });
|
|
1553
1620
|
}
|
|
1554
1621
|
function useCanvasEffects(options) {
|
|
1555
|
-
const opts =
|
|
1622
|
+
const opts = useRef14(options);
|
|
1556
1623
|
opts.current = options;
|
|
1557
|
-
const controller =
|
|
1624
|
+
const controller = useMemo10(
|
|
1558
1625
|
() => createCanvasEffectsController({
|
|
1559
1626
|
getNodes: () => opts.current.getNodes(),
|
|
1560
1627
|
setNodes: (n) => opts.current.setNodes(n),
|
|
@@ -1565,7 +1632,7 @@ function useCanvasEffects(options) {
|
|
|
1565
1632
|
}),
|
|
1566
1633
|
[]
|
|
1567
1634
|
);
|
|
1568
|
-
|
|
1635
|
+
useEffect11(() => {
|
|
1569
1636
|
if (!options.effects) return;
|
|
1570
1637
|
return controller.useEffects(options.effects);
|
|
1571
1638
|
}, [controller, options.effects]);
|
|
@@ -1573,7 +1640,7 @@ function useCanvasEffects(options) {
|
|
|
1573
1640
|
}
|
|
1574
1641
|
function useCanvasEffectsTools(registry, controller, options = {}) {
|
|
1575
1642
|
const { id, namespace, readOnly, subscribe } = options;
|
|
1576
|
-
|
|
1643
|
+
useEffect11(() => {
|
|
1577
1644
|
if (!registry) return;
|
|
1578
1645
|
return registry.register(createCanvasEffectsToolProvider(controller, { id, namespace, readOnly, subscribe }));
|
|
1579
1646
|
}, [registry, controller, id, namespace, readOnly, subscribe]);
|
|
@@ -1581,7 +1648,7 @@ function useCanvasEffectsTools(registry, controller, options = {}) {
|
|
|
1581
1648
|
var btn = "rounded border border-border px-1.5 py-0.5 text-[11px] disabled:opacity-40";
|
|
1582
1649
|
function Controls({ controller, nodeId, effect }) {
|
|
1583
1650
|
const { description, error } = useEffectDescription(controller.effectsProvider, effect.effect);
|
|
1584
|
-
const [message, setMessage] =
|
|
1651
|
+
const [message, setMessage] = useState8(null);
|
|
1585
1652
|
const run = (work) => void work.then(() => setMessage(null), (e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
1586
1653
|
if (error) return /* @__PURE__ */ jsx5("p", { className: "text-[11px] text-amber-500", children: error });
|
|
1587
1654
|
if (!description) return /* @__PURE__ */ jsx5("p", { className: "text-[11px] text-muted-foreground", children: "Loading\u2026" });
|
|
@@ -1600,11 +1667,11 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
1600
1667
|
] });
|
|
1601
1668
|
}
|
|
1602
1669
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
1603
|
-
const [, setTick] =
|
|
1604
|
-
|
|
1670
|
+
const [, setTick] = useState8(0);
|
|
1671
|
+
useEffect11(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
1605
1672
|
const provider = controller.effectsProvider;
|
|
1606
|
-
const [browse, setBrowse] =
|
|
1607
|
-
const [message, setMessage] =
|
|
1673
|
+
const [browse, setBrowse] = useState8(null);
|
|
1674
|
+
const [message, setMessage] = useState8(null);
|
|
1608
1675
|
const run = (work) => {
|
|
1609
1676
|
setMessage(null);
|
|
1610
1677
|
Promise.resolve().then(work).then(() => setTick((n) => n + 1), (e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
@@ -1809,7 +1876,9 @@ import {
|
|
|
1809
1876
|
runMultiNodeTransition as runMultiNodeTransition2,
|
|
1810
1877
|
defaultEasing,
|
|
1811
1878
|
computeNodesBoundingBox,
|
|
1812
|
-
|
|
1879
|
+
nodeSizeOf,
|
|
1880
|
+
calculateDirectionalDisplacement,
|
|
1881
|
+
calculateReflowDisplacement,
|
|
1813
1882
|
calculateDagreReflowDisplacement,
|
|
1814
1883
|
isEventFromTextInput as isEventFromTextInput3,
|
|
1815
1884
|
isValidCanvasNode,
|
|
@@ -1852,17 +1921,17 @@ import {
|
|
|
1852
1921
|
} from "@pixerate/editor/canvas";
|
|
1853
1922
|
|
|
1854
1923
|
// src/canvas/useCanvasAutoLayout.ts
|
|
1855
|
-
import { useLayoutEffect, useMemo as
|
|
1924
|
+
import { useLayoutEffect, useMemo as useMemo11, useRef as useRef15, useState as useState9 } from "react";
|
|
1856
1925
|
import {
|
|
1857
1926
|
createCanvasAutoLayoutController
|
|
1858
1927
|
} from "@pixerate/editor/canvas";
|
|
1859
1928
|
function useCanvasAutoLayout(options) {
|
|
1860
|
-
const [guides, setGuides] =
|
|
1861
|
-
const nodesRef =
|
|
1929
|
+
const [guides, setGuides] = useState9([]);
|
|
1930
|
+
const nodesRef = useRef15(options.nodes);
|
|
1862
1931
|
nodesRef.current = options.nodes;
|
|
1863
|
-
const optionsRef =
|
|
1932
|
+
const optionsRef = useRef15(options);
|
|
1864
1933
|
optionsRef.current = options;
|
|
1865
|
-
const controller =
|
|
1934
|
+
const controller = useMemo11(
|
|
1866
1935
|
() => createCanvasAutoLayoutController({
|
|
1867
1936
|
getNodes: () => nodesRef.current,
|
|
1868
1937
|
setNodes: (next) => {
|
|
@@ -1891,7 +1960,7 @@ function useCanvasAutoLayout(options) {
|
|
|
1891
1960
|
useLayoutEffect(() => {
|
|
1892
1961
|
if (controller.hasPending) controller.flush();
|
|
1893
1962
|
}, [options.nodes, controller]);
|
|
1894
|
-
return
|
|
1963
|
+
return useMemo11(
|
|
1895
1964
|
() => ({
|
|
1896
1965
|
...controller,
|
|
1897
1966
|
/** Drop marker of the active reorder drag (flow coordinates). */
|
|
@@ -1905,7 +1974,7 @@ function useCanvasAutoLayout(options) {
|
|
|
1905
1974
|
}
|
|
1906
1975
|
|
|
1907
1976
|
// src/canvas/useCanvasTokens.ts
|
|
1908
|
-
import { useCallback as useCallback9, useEffect as
|
|
1977
|
+
import { useCallback as useCallback9, useEffect as useEffect12, useRef as useRef16, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
1909
1978
|
import {
|
|
1910
1979
|
bindCanvasToken,
|
|
1911
1980
|
detachTokenBindings,
|
|
@@ -1915,11 +1984,11 @@ import {
|
|
|
1915
1984
|
} from "@pixerate/editor/canvas";
|
|
1916
1985
|
function useCanvasTokens(options) {
|
|
1917
1986
|
const { store, nodes, setNodes, modes, properties } = options;
|
|
1918
|
-
const state =
|
|
1919
|
-
const latest =
|
|
1987
|
+
const state = useSyncExternalStore3(store.subscribe, store.getState, store.getState);
|
|
1988
|
+
const latest = useRef16({ nodes, setNodes, modes, properties });
|
|
1920
1989
|
latest.current = { nodes, setNodes, modes, properties };
|
|
1921
1990
|
const opts = () => ({ modes: latest.current.modes, properties: latest.current.properties });
|
|
1922
|
-
|
|
1991
|
+
useEffect12(
|
|
1923
1992
|
() => store.subscribe((event) => {
|
|
1924
1993
|
if (event.deletedVariableIds.length === 0) return;
|
|
1925
1994
|
latest.current.setNodes((prev) => detachTokenBindings(prev, event.previous, event.deletedVariableIds, opts()));
|
|
@@ -1928,7 +1997,7 @@ function useCanvasTokens(options) {
|
|
|
1928
1997
|
[store]
|
|
1929
1998
|
);
|
|
1930
1999
|
const modesKey = JSON.stringify(modes ?? {});
|
|
1931
|
-
|
|
2000
|
+
useEffect12(() => {
|
|
1932
2001
|
const next = resolveCanvasTokens(nodes, state, opts());
|
|
1933
2002
|
if (next !== nodes) setNodes(next);
|
|
1934
2003
|
}, [nodes, state, modesKey, properties]);
|
|
@@ -2099,16 +2168,16 @@ import {
|
|
|
2099
2168
|
} from "@pixerate/editor/canvas";
|
|
2100
2169
|
|
|
2101
2170
|
// src/canvas/useCanvasAnimation.ts
|
|
2102
|
-
import { useEffect as
|
|
2171
|
+
import { useEffect as useEffect13, useMemo as useMemo12, useRef as useRef17, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
2103
2172
|
import {
|
|
2104
2173
|
createCanvasAnimationController
|
|
2105
2174
|
} from "@pixerate/editor/canvas";
|
|
2106
2175
|
function useCanvasAnimation(options) {
|
|
2107
|
-
const nodesRef =
|
|
2176
|
+
const nodesRef = useRef17(options.nodes);
|
|
2108
2177
|
nodesRef.current = options.nodes;
|
|
2109
|
-
const optionsRef =
|
|
2178
|
+
const optionsRef = useRef17(options);
|
|
2110
2179
|
optionsRef.current = options;
|
|
2111
|
-
const controller =
|
|
2180
|
+
const controller = useMemo12(
|
|
2112
2181
|
() => createCanvasAnimationController({
|
|
2113
2182
|
getNodes: () => nodesRef.current,
|
|
2114
2183
|
setNodes: (next) => {
|
|
@@ -2135,26 +2204,26 @@ function useCanvasAnimation(options) {
|
|
|
2135
2204
|
}),
|
|
2136
2205
|
[]
|
|
2137
2206
|
);
|
|
2138
|
-
|
|
2139
|
-
|
|
2207
|
+
useEffect13(() => () => controller.destroy(), [controller]);
|
|
2208
|
+
useEffect13(() => {
|
|
2140
2209
|
if (options.loop !== void 0) controller.setLoop(options.loop);
|
|
2141
2210
|
}, [controller, options.loop]);
|
|
2142
|
-
|
|
2211
|
+
useEffect13(() => {
|
|
2143
2212
|
if (options.playbackRate !== void 0) controller.setPlaybackRate(options.playbackRate);
|
|
2144
2213
|
}, [controller, options.playbackRate]);
|
|
2145
|
-
|
|
2214
|
+
useEffect13(() => {
|
|
2146
2215
|
if (options.recording !== void 0) controller.setRecording(options.recording);
|
|
2147
2216
|
}, [controller, options.recording]);
|
|
2148
|
-
const state =
|
|
2217
|
+
const state = useSyncExternalStore4(
|
|
2149
2218
|
(listener) => controller.subscribe(listener),
|
|
2150
2219
|
() => controller.getState(),
|
|
2151
2220
|
() => controller.getState()
|
|
2152
2221
|
);
|
|
2153
|
-
|
|
2222
|
+
useEffect13(() => {
|
|
2154
2223
|
controller.refresh();
|
|
2155
2224
|
}, [controller, options.nodes]);
|
|
2156
|
-
const displayNodes =
|
|
2157
|
-
return
|
|
2225
|
+
const displayNodes = useMemo12(() => controller.display(options.nodes), [controller, options.nodes, state.time]);
|
|
2226
|
+
return useMemo12(
|
|
2158
2227
|
() => ({
|
|
2159
2228
|
...controller,
|
|
2160
2229
|
state,
|
|
@@ -2175,7 +2244,7 @@ function useCanvasAnimation(options) {
|
|
|
2175
2244
|
}
|
|
2176
2245
|
|
|
2177
2246
|
// src/canvas/AnimationTimeline.tsx
|
|
2178
|
-
import { useEffect as
|
|
2247
|
+
import { useEffect as useEffect14, useRef as useRef18 } from "react";
|
|
2179
2248
|
import {
|
|
2180
2249
|
ANIMATION_EASING_LABELS,
|
|
2181
2250
|
ANIMATION_EASING_PRESETS,
|
|
@@ -2198,8 +2267,8 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
2198
2267
|
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);
|
|
2199
2268
|
return "";
|
|
2200
2269
|
})();
|
|
2201
|
-
const dragRef =
|
|
2202
|
-
|
|
2270
|
+
const dragRef = useRef18(null);
|
|
2271
|
+
useEffect14(() => {
|
|
2203
2272
|
const onKey = (event) => {
|
|
2204
2273
|
if (event.key === "Escape" && dragRef.current) {
|
|
2205
2274
|
dragRef.current = null;
|
|
@@ -2437,16 +2506,16 @@ import {
|
|
|
2437
2506
|
} from "@pixerate/editor/canvas";
|
|
2438
2507
|
|
|
2439
2508
|
// src/canvas/useCanvasComponents.ts
|
|
2440
|
-
import { useLayoutEffect as useLayoutEffect2, useMemo as
|
|
2509
|
+
import { useLayoutEffect as useLayoutEffect2, useMemo as useMemo13, useRef as useRef19 } from "react";
|
|
2441
2510
|
import {
|
|
2442
2511
|
createCanvasComponentsController
|
|
2443
2512
|
} from "@pixerate/editor/canvas";
|
|
2444
2513
|
function useCanvasComponents(options) {
|
|
2445
|
-
const nodesRef =
|
|
2514
|
+
const nodesRef = useRef19(options.nodes);
|
|
2446
2515
|
nodesRef.current = options.nodes;
|
|
2447
|
-
const optionsRef =
|
|
2516
|
+
const optionsRef = useRef19(options);
|
|
2448
2517
|
optionsRef.current = options;
|
|
2449
|
-
const controller =
|
|
2518
|
+
const controller = useMemo13(
|
|
2450
2519
|
() => createCanvasComponentsController({
|
|
2451
2520
|
getNodes: () => nodesRef.current,
|
|
2452
2521
|
setNodes: (next) => {
|
|
@@ -2482,7 +2551,7 @@ function useCanvasComponents(options) {
|
|
|
2482
2551
|
}
|
|
2483
2552
|
|
|
2484
2553
|
// src/canvas/CanvasComponentsPanel.tsx
|
|
2485
|
-
import { useState as
|
|
2554
|
+
import { useState as useState10 } from "react";
|
|
2486
2555
|
import {
|
|
2487
2556
|
CANVAS_COMPONENT_DRAG_TYPE,
|
|
2488
2557
|
inspectCanvasInstance,
|
|
@@ -2521,10 +2590,10 @@ function CanvasComponentsPanel({
|
|
|
2521
2590
|
search = true,
|
|
2522
2591
|
className = ""
|
|
2523
2592
|
}) {
|
|
2524
|
-
const [query, setQuery] =
|
|
2525
|
-
const [propsOpen, setPropsOpen] =
|
|
2526
|
-
const [menuFor, setMenuFor] =
|
|
2527
|
-
const [editing, setEditing] =
|
|
2593
|
+
const [query, setQuery] = useState10("");
|
|
2594
|
+
const [propsOpen, setPropsOpen] = useState10(null);
|
|
2595
|
+
const [menuFor, setMenuFor] = useState10(null);
|
|
2596
|
+
const [editing, setEditing] = useState10(null);
|
|
2528
2597
|
const { components: all, sets } = listCanvasComponents(nodes);
|
|
2529
2598
|
const q = query.trim().toLowerCase();
|
|
2530
2599
|
const match = (name) => !q || name.toLowerCase().includes(q);
|
|
@@ -3043,7 +3112,7 @@ function MermaidFamilyScene({
|
|
|
3043
3112
|
}
|
|
3044
3113
|
|
|
3045
3114
|
// src/canvas/useMermaidDiagram.ts
|
|
3046
|
-
import { useEffect as
|
|
3115
|
+
import { useEffect as useEffect15, useMemo as useMemo14, useRef as useRef20, useState as useState11, useSyncExternalStore as useSyncExternalStore5 } from "react";
|
|
3047
3116
|
import {
|
|
3048
3117
|
DiagramController,
|
|
3049
3118
|
createDiagramEditorDocument
|
|
@@ -3059,10 +3128,10 @@ import {
|
|
|
3059
3128
|
mermaidToCanvas
|
|
3060
3129
|
} from "@pixerate/editor/canvas";
|
|
3061
3130
|
function useDiagramState(controller) {
|
|
3062
|
-
return
|
|
3131
|
+
return useSyncExternalStore5(controller.subscribe, controller.getState, controller.getState);
|
|
3063
3132
|
}
|
|
3064
3133
|
function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
3065
|
-
const own =
|
|
3134
|
+
const own = useRef20(null);
|
|
3066
3135
|
let controller;
|
|
3067
3136
|
if (controllerOrOptions instanceof DiagramController) controller = controllerOrOptions;
|
|
3068
3137
|
else {
|
|
@@ -3072,21 +3141,21 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3072
3141
|
const layoutOptions = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
|
|
3073
3142
|
const sceneTheme = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
|
|
3074
3143
|
const state = useDiagramState(controller);
|
|
3075
|
-
const editorDocument =
|
|
3076
|
-
|
|
3077
|
-
const canvas =
|
|
3144
|
+
const editorDocument = useMemo14(() => createDiagramEditorDocument(controller), [controller]);
|
|
3145
|
+
useEffect15(() => () => editorDocument.destroy(), [editorDocument]);
|
|
3146
|
+
const canvas = useMemo14(
|
|
3078
3147
|
() => mermaidToCanvas(state.document, { ...layoutOptions, editable: state.editable }),
|
|
3079
3148
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3080
3149
|
[state.document, state.editable]
|
|
3081
3150
|
);
|
|
3082
|
-
const scene =
|
|
3151
|
+
const scene = useMemo14(
|
|
3083
3152
|
() => state.document.tier === "editable" ? familySceneFromLayout(state.document.family, state.document.graph, canvas.layout, { theme: { ...CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
|
|
3084
3153
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3085
3154
|
[state.document, canvas.layout, state.selection]
|
|
3086
3155
|
);
|
|
3087
|
-
const layoutRef =
|
|
3156
|
+
const layoutRef = useRef20(canvas.layout);
|
|
3088
3157
|
layoutRef.current = canvas.layout;
|
|
3089
|
-
const actions =
|
|
3158
|
+
const actions = useMemo14(
|
|
3090
3159
|
() => ({
|
|
3091
3160
|
apply: (ops, label) => controller.apply(ops, label),
|
|
3092
3161
|
load: (source, options) => controller.load(source, options),
|
|
@@ -3123,13 +3192,13 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3123
3192
|
}
|
|
3124
3193
|
function useMermaidStream(source, options = {}) {
|
|
3125
3194
|
const { complete = false, duration = 300, ...layoutOptions } = options;
|
|
3126
|
-
const stream =
|
|
3195
|
+
const stream = useRef20(null);
|
|
3127
3196
|
if (!stream.current) stream.current = new DiagramStream(layoutOptions);
|
|
3128
|
-
const result =
|
|
3129
|
-
const [shown, setShown] =
|
|
3130
|
-
const shownRef =
|
|
3197
|
+
const result = useMemo14(() => stream.current.update(source, complete), [source, complete]);
|
|
3198
|
+
const [shown, setShown] = useState11({ layout: result.layout, settled: true });
|
|
3199
|
+
const shownRef = useRef20(shown.layout);
|
|
3131
3200
|
shownRef.current = shown.layout;
|
|
3132
|
-
|
|
3201
|
+
useEffect15(() => {
|
|
3133
3202
|
const target = result.layout;
|
|
3134
3203
|
if (!target) return setShown({ layout: null, settled: true });
|
|
3135
3204
|
const from = shownRef.current;
|
|
@@ -3146,7 +3215,7 @@ function useMermaidStream(source, options = {}) {
|
|
|
3146
3215
|
return () => cancelAnimationFrame(frame);
|
|
3147
3216
|
}, [result.layout, duration]);
|
|
3148
3217
|
const doc = result.document.tier === "editable" ? result.document : null;
|
|
3149
|
-
const canvas =
|
|
3218
|
+
const canvas = useMemo14(() => {
|
|
3150
3219
|
if (!doc || !shown.layout) return { nodes: [], edges: [] };
|
|
3151
3220
|
const placed = new Set(Object.keys(shown.layout.positions));
|
|
3152
3221
|
const graph = {
|
|
@@ -3222,14 +3291,14 @@ function MermaidDiagramGroup({ data, selected, className = "", children }) {
|
|
|
3222
3291
|
}
|
|
3223
3292
|
|
|
3224
3293
|
// src/canvas/MermaidThumbnail.tsx
|
|
3225
|
-
import { useMemo as
|
|
3294
|
+
import { useMemo as useMemo15 } from "react";
|
|
3226
3295
|
import { parseMermaid } from "@pixerate/editor/diagram";
|
|
3227
3296
|
import { mermaidThumbnailSvg } from "@pixerate/editor/canvas";
|
|
3228
3297
|
import { Fragment as Fragment3, jsx as jsx12 } from "react/jsx-runtime";
|
|
3229
3298
|
function MermaidThumbnail({ source, className = "", fallback = null, ...options }) {
|
|
3230
|
-
const doc =
|
|
3299
|
+
const doc = useMemo15(() => typeof source === "string" ? parseMermaid(source) : source, [source]);
|
|
3231
3300
|
const key = JSON.stringify(options);
|
|
3232
|
-
const drawn =
|
|
3301
|
+
const drawn = useMemo15(
|
|
3233
3302
|
() => doc.tier === "editable" && doc.graph.nodes.length ? mermaidThumbnailSvg(doc, options) : null,
|
|
3234
3303
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3235
3304
|
[doc, key]
|
|
@@ -3239,12 +3308,12 @@ function MermaidThumbnail({ source, className = "", fallback = null, ...options
|
|
|
3239
3308
|
}
|
|
3240
3309
|
|
|
3241
3310
|
// src/canvas/useDiagramDirector.ts
|
|
3242
|
-
import { useRef as
|
|
3311
|
+
import { useRef as useRef21, useSyncExternalStore as useSyncExternalStore6 } from "react";
|
|
3243
3312
|
import { DiagramDirector, PresenceStore } from "@pixerate/editor/diagram";
|
|
3244
3313
|
function useDiagramDirector(controller, options) {
|
|
3245
|
-
const placement =
|
|
3314
|
+
const placement = useRef21(options.placement);
|
|
3246
3315
|
placement.current = options.placement;
|
|
3247
|
-
const ref =
|
|
3316
|
+
const ref = useRef21(null);
|
|
3248
3317
|
if (!ref.current) {
|
|
3249
3318
|
const presence = new PresenceStore();
|
|
3250
3319
|
ref.current = {
|
|
@@ -3255,7 +3324,7 @@ function useDiagramDirector(controller, options) {
|
|
|
3255
3324
|
return ref.current;
|
|
3256
3325
|
}
|
|
3257
3326
|
function usePresenceState(presence) {
|
|
3258
|
-
return
|
|
3327
|
+
return useSyncExternalStore6(presence.subscribe, presence.getState, presence.getState);
|
|
3259
3328
|
}
|
|
3260
3329
|
|
|
3261
3330
|
// src/canvas/DiagramPresenceLayer.tsx
|
|
@@ -3339,10 +3408,12 @@ export {
|
|
|
3339
3408
|
brushstrokeScaleBucket2 as brushstrokeScaleBucket,
|
|
3340
3409
|
brushstrokeSeed,
|
|
3341
3410
|
calculateDagreReflowDisplacement,
|
|
3342
|
-
|
|
3411
|
+
calculateDirectionalDisplacement,
|
|
3412
|
+
calculateReflowDisplacement,
|
|
3343
3413
|
canCombineShapeNodes,
|
|
3344
3414
|
canOffsetShapeNodes,
|
|
3345
3415
|
canOutlineShapeNodeStrokes,
|
|
3416
|
+
canvasExplosionToolTarget,
|
|
3346
3417
|
canvasHeight,
|
|
3347
3418
|
centerNodes2 as centerNodes,
|
|
3348
3419
|
centre,
|
|
@@ -3350,6 +3421,7 @@ export {
|
|
|
3350
3421
|
clampLayoutSize,
|
|
3351
3422
|
combineCanvasComponentsAsVariants,
|
|
3352
3423
|
combineShapeNodes,
|
|
3424
|
+
computeCanvasExplosionLayout2 as computeCanvasExplosionLayout,
|
|
3353
3425
|
computeNodesBoundingBox,
|
|
3354
3426
|
computeSnapGuides,
|
|
3355
3427
|
connectedOnly,
|
|
@@ -3362,6 +3434,8 @@ export {
|
|
|
3362
3434
|
createCanvasComponent,
|
|
3363
3435
|
createCanvasComponentsController2 as createCanvasComponentsController,
|
|
3364
3436
|
createCanvasDrawController2 as createCanvasDrawController,
|
|
3437
|
+
createCanvasExplosionStateController2 as createCanvasExplosionStateController,
|
|
3438
|
+
createCanvasExplosionToolProvider,
|
|
3365
3439
|
createCanvasInstance,
|
|
3366
3440
|
createCanvasScenesStore,
|
|
3367
3441
|
createDefaultStrokeStyle,
|
|
@@ -3390,6 +3464,7 @@ export {
|
|
|
3390
3464
|
evaluateEasing,
|
|
3391
3465
|
evaluateTrack,
|
|
3392
3466
|
excludePaths,
|
|
3467
|
+
explosionEdgeId,
|
|
3393
3468
|
exportCssAnimation,
|
|
3394
3469
|
findConnectorSnap,
|
|
3395
3470
|
findStrokesAtPoint,
|
|
@@ -3499,6 +3574,7 @@ export {
|
|
|
3499
3574
|
multiPolygonArea,
|
|
3500
3575
|
multiPolygonBounds,
|
|
3501
3576
|
nearestHandlePositions,
|
|
3577
|
+
nodeSizeOf,
|
|
3502
3578
|
normalizeBezierPath,
|
|
3503
3579
|
normalizeKeyframes,
|
|
3504
3580
|
offsetPath,
|
|
@@ -3615,6 +3691,7 @@ export {
|
|
|
3615
3691
|
useCanvasEffectsProviderContext,
|
|
3616
3692
|
useCanvasEffectsTools,
|
|
3617
3693
|
useCanvasExplosion,
|
|
3694
|
+
useCanvasExplosionState,
|
|
3618
3695
|
useCanvasGraph,
|
|
3619
3696
|
useCanvasLayout,
|
|
3620
3697
|
useCanvasMeasure,
|