@flowuent-org/diagramming-core 1.1.4 → 1.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowuent-org/diagramming-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -95,6 +95,7 @@ export * from './lib/utils/object';
95
95
  export * from './lib/utils/nodeutils';
96
96
  export * from './lib/utils/utilities';
97
97
  export * from './lib/utils/vhToPixels';
98
+ export * from './lib/utils/nodeOrderByEdges';
98
99
  export * from './lib/assets/markers/markers.param';
99
100
  export * from './lib/assets/markers/markers.type';
100
101
  export * from './lib/organisms/Card/card.params';
@@ -8,6 +8,7 @@ import { ICardNode } from '../types/card-node';
8
8
  import { setPannable } from './setPannable';
9
9
  import { setSelectedNode } from './setSelectedNode';
10
10
  import { onConnect } from './onConnect';
11
+ import { onReconnect } from './onReconnect';
11
12
  import { setNodes } from './setNodes';
12
13
  import { setEdges } from './setEdges';
13
14
  import { setContentHeight } from './setContentHeight';
@@ -99,6 +100,9 @@ const createDiagramStore = ({
99
100
  goToHistoryIndex(set, get as () => DiagramStore, index),
100
101
  onConnect: (connection: Connection) =>
101
102
  onConnect(set, onChange)(connection),
103
+ onReconnect: (oldEdge: Edge, newConnection: Connection) => {
104
+ onReconnect(set, onChange)(oldEdge, newConnection);
105
+ },
102
106
  setNodes: (nodes: ICardNode[]) => {
103
107
  setNodes(set)(nodes);
104
108
  },
@@ -373,3 +377,16 @@ export const useEditFunction = (): ((func: FunctionSignature) => void) =>
373
377
 
374
378
  export const useDeleteFunction = (): ((id: string) => void) =>
375
379
  useDiagram((state) => state.deleteFunction);
380
+
381
+ // Undo/Redo hooks
382
+ export const useUndo = (): (() => void) =>
383
+ useDiagram((state) => state.undo);
384
+
385
+ export const useRedo = (): (() => void) =>
386
+ useDiagram((state) => state.redo);
387
+
388
+ export const useCanUndo = (): boolean =>
389
+ useDiagram((state) => state.historyIndex >= 0);
390
+
391
+ export const useCanRedo = (): boolean =>
392
+ useDiagram((state) => state.historyIndex < state.history.length - 1);
@@ -90,6 +90,7 @@ export interface DiagramActions {
90
90
  onNodesChange: (changes: NodeChange[]) => void;
91
91
  onEdgesChange: (changes: EdgeChange[]) => void;
92
92
  onConnect: (connection: Connection) => void;
93
+ onReconnect: (oldEdge: Edge, newConnection: Connection) => void;
93
94
  setNodes: (nodes: ICardNode[]) => void;
94
95
  setEdges: (edges: Edge[]) => void;
95
96
  setContentHeight: (id: string, height: number) => void;
@@ -0,0 +1,59 @@
1
+ // onReconnect.ts
2
+ import { Edge, Connection } from '@xyflow/react';
3
+ import { DiagramStore, OnChangeEventHandler } from './diagramStoreTypes';
4
+
5
+ export const onReconnect =
6
+ (
7
+ set: (fn: (state: DiagramStore) => DiagramStore) => void,
8
+ onChange?: OnChangeEventHandler,
9
+ ) =>
10
+ (oldEdge: Edge, newConnection: Connection) => {
11
+ if (!newConnection.source || !newConnection.target) {
12
+ // If connection is invalid, remove the edge
13
+ set((state) => {
14
+ const updatedEdges = state.edges.filter((edge) => edge.id !== oldEdge.id);
15
+ return { ...state, edges: updatedEdges };
16
+ });
17
+
18
+ if (onChange) {
19
+ onChange({
20
+ t: 'edge-change',
21
+ type: 'remove',
22
+ id: oldEdge.id,
23
+ message: 'Edge disconnected',
24
+ });
25
+ }
26
+ return;
27
+ }
28
+
29
+ set((state) => {
30
+ // Manually update the edge with new connection
31
+ const updatedEdges = state.edges.map((edge) => {
32
+ if (edge.id === oldEdge.id) {
33
+ return {
34
+ ...edge,
35
+ source: newConnection.source,
36
+ target: newConnection.target,
37
+ sourceHandle: newConnection.sourceHandle || edge.sourceHandle,
38
+ targetHandle: newConnection.targetHandle || edge.targetHandle,
39
+ };
40
+ }
41
+ return edge;
42
+ });
43
+
44
+ const reconnectedEdge = updatedEdges.find((edge) => edge.id === oldEdge.id);
45
+
46
+ if (onChange && reconnectedEdge) {
47
+ onChange({
48
+ t: 'edge-change',
49
+ type: 'replace',
50
+ id: reconnectedEdge.id,
51
+ item: reconnectedEdge,
52
+ message: 'Edge reconnected',
53
+ });
54
+ }
55
+
56
+ return { ...state, edges: updatedEdges };
57
+ });
58
+ };
59
+