@bemedev/mind-flow 0.3.0 → 0.3.2
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/lib/index.cjs.js +1 -1
- package/lib/index.es.js +244 -268
- package/lib/server.cjs.js +153 -189
- package/lib/server.es.js +153 -189
- package/lib/services/main.machine.d.ts +994 -14
- package/lib/services/main.machine.d.ts.map +1 -1
- package/lib/ui/components/EdgeComponent.d.ts.map +1 -1
- package/lib/ui/components/FlowChart.context.d.ts +994 -14
- package/lib/ui/components/FlowChart.context.d.ts.map +1 -1
- package/lib/ui/components/NodeComponent.d.ts.map +1 -1
- package/lib/ui/components/NodesBoard.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/main.machine.ts +148 -41
- package/src/ui/components/EdgeComponent.tsx +46 -56
- package/src/ui/components/FlowChart.context.ts +2 -131
- package/src/ui/components/FlowChart.tsx +10 -10
- package/src/ui/components/NodeComponent.tsx +13 -14
- package/src/ui/components/NodesBoard.tsx +32 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowChart.context.d.ts","sourceRoot":"","sources":["../../../src/ui/components/FlowChart.context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FlowChart.context.d.ts","sourceRoot":"","sources":["../../../src/ui/components/FlowChart.context.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;;;;GAKG;AACH,eAAO,MAAO,QAAQ,sCAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAkHkF,CAAC;;;;mBAAmE,CAAC;;;;oBAAoE,CAAC;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAA1I,CAAC;;;;2BAAmE,CAAC;;;;4BAAoE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAD1P,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeComponent.d.ts","sourceRoot":"","sources":["../../../src/ui/components/NodeComponent.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAQ,MAAM,UAAU,CAAC;AAU3C,OAAO,QAAQ,UAAU,CAAC;IACxB,UAAU,GAAG,CAAC;QACZ,UAAU,UAAU;YAClB,SAAS,EAAE,GAAG,CAAC;SAChB;KACF;CACF;AAED,uEAAuE;AACvE,KAAK,KAAK,GAAG;IACX,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"NodeComponent.d.ts","sourceRoot":"","sources":["../../../src/ui/components/NodeComponent.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAQ,MAAM,UAAU,CAAC;AAU3C,OAAO,QAAQ,UAAU,CAAC;IACxB,UAAU,GAAG,CAAC;QACZ,UAAU,UAAU;YAClB,SAAS,EAAE,GAAG,CAAC;SAChB;KACF;CACF;AAED,uEAAuE;AACvE,KAAK,KAAK,GAAG;IACX,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,KAAK,CA+L1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodesBoard.d.ts","sourceRoot":"","sources":["../../../src/ui/components/NodesBoard.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,SAAS,EAOV,MAAM,UAAU,CAAC;AAQlB;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"NodesBoard.d.ts","sourceRoot":"","sources":["../../../src/ui/components/NodesBoard.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,SAAS,EAOV,MAAM,UAAU,CAAC;AAQlB;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,SA4RxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemedev/mind-flow",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Flow Chart UI library for Solid.js applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"diagram",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"globals": "^17.11.0",
|
|
78
78
|
"husky": "^9.1.7",
|
|
79
79
|
"onchange": "^7.1.0",
|
|
80
|
-
"oxfmt": "^0.
|
|
81
|
-
"oxlint": "^1.
|
|
80
|
+
"oxfmt": "^0.65.0",
|
|
81
|
+
"oxlint": "^1.80.0",
|
|
82
82
|
"pretty-quick": "^4.2.2",
|
|
83
83
|
"rimraf": "^6.1.3",
|
|
84
84
|
"rolldown": "^1.2.5",
|
|
@@ -6,7 +6,11 @@ import { nanoid } from 'nanoid';
|
|
|
6
6
|
/** Type alias for drag-drop state extracted from {@linkcode useDragDropContext}. */
|
|
7
7
|
export type DragDropState = Exclude<ReturnType<typeof useDragDropContext>, null>[0];
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_INPUT_OFFSET,
|
|
11
|
+
getDefaultOutputOffset,
|
|
12
|
+
PARENT_CHILD_GAP_WIDTH,
|
|
13
|
+
} from './main.machine.data';
|
|
10
14
|
import {
|
|
11
15
|
buildEdgeId,
|
|
12
16
|
buildNodeID,
|
|
@@ -195,6 +199,12 @@ export const machine = createMachine(
|
|
|
195
199
|
}),
|
|
196
200
|
),
|
|
197
201
|
|
|
202
|
+
setBoard: assign('board', { SET_BOARD: ({ payload }) => payload }),
|
|
203
|
+
generateID: action(({ pContext }) => (pContext.generatedId = nanoid())),
|
|
204
|
+
select: assign('selected', { SELECT: ({ payload }) => payload }),
|
|
205
|
+
clearNewEdge: erase('newEdge'),
|
|
206
|
+
deselect: erase('selected'),
|
|
207
|
+
|
|
198
208
|
startNewEdge: assign('newEdge', {
|
|
199
209
|
START_NEW_EDGE: ({ payload: from, pContext: { dimensions } }) => {
|
|
200
210
|
const { x, y } = dimensions[from].output;
|
|
@@ -202,8 +212,6 @@ export const machine = createMachine(
|
|
|
202
212
|
},
|
|
203
213
|
}),
|
|
204
214
|
|
|
205
|
-
setBoard: assign('board', { SET_BOARD: ({ payload }) => payload }),
|
|
206
|
-
|
|
207
215
|
buildUI: batch(
|
|
208
216
|
assign('edgesPositions', {
|
|
209
217
|
MOVE: ({
|
|
@@ -247,6 +255,7 @@ export const machine = createMachine(
|
|
|
247
255
|
|
|
248
256
|
return edgesPositions;
|
|
249
257
|
},
|
|
258
|
+
|
|
250
259
|
MOVE_IMMEDIATE: ({
|
|
251
260
|
context: { data, edgesPositions },
|
|
252
261
|
payload,
|
|
@@ -255,41 +264,36 @@ export const machine = createMachine(
|
|
|
255
264
|
const edges = data?.edges;
|
|
256
265
|
|
|
257
266
|
edges?.forEach(({ from, to, id }) => {
|
|
267
|
+
const dimension = dimensions[payload.id];
|
|
268
|
+
const edgePosition = edgesPositions[id];
|
|
269
|
+
if (!edgePosition || !dimension) return;
|
|
270
|
+
|
|
258
271
|
if (from === payload.id) {
|
|
259
|
-
const dimension = dimensions[payload.id];
|
|
260
272
|
const offset =
|
|
261
|
-
dimension
|
|
273
|
+
dimension.outputOffset ?? getDefaultOutputOffset(dimension.width);
|
|
262
274
|
|
|
263
275
|
const x0 = payload.x + offset.x;
|
|
264
276
|
const y0 = payload.y + offset.y;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (dimension) {
|
|
269
|
-
dimension.output.x = x0;
|
|
270
|
-
dimension.output.y = y0;
|
|
271
|
-
}
|
|
277
|
+
edgePosition.x0 = x0;
|
|
278
|
+
edgePosition.y0 = y0;
|
|
279
|
+
dimension.output = { x: x0, y: y0 };
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
if (to === payload.id) {
|
|
275
|
-
const dimension = dimensions[payload.id];
|
|
276
283
|
const offset = dimension?.inputOffset ?? DEFAULT_INPUT_OFFSET;
|
|
277
|
-
|
|
278
284
|
const x1 = payload.x + offset.x;
|
|
279
285
|
const y1 = payload.y + offset.y;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (dimension) {
|
|
284
|
-
dimension.input = { x: x1, y: y1 };
|
|
285
|
-
}
|
|
286
|
+
edgePosition.x1 = x1;
|
|
287
|
+
edgePosition.y1 = y1;
|
|
288
|
+
dimension.input = { x: x1, y: y1 };
|
|
286
289
|
}
|
|
287
290
|
});
|
|
288
291
|
|
|
289
292
|
return edgesPositions;
|
|
290
293
|
},
|
|
294
|
+
|
|
291
295
|
else: ({ context: { data, edgesPositions }, pContext: { dimensions } }) => {
|
|
292
|
-
const edges = data?.edges
|
|
296
|
+
const edges = toArray.typed(data?.edges);
|
|
293
297
|
edgesPositions = {};
|
|
294
298
|
|
|
295
299
|
edges.forEach(({ from, id, to }) => {
|
|
@@ -321,10 +325,6 @@ export const machine = createMachine(
|
|
|
321
325
|
},
|
|
322
326
|
}),
|
|
323
327
|
|
|
324
|
-
generateID: action(({ pContext }) => {
|
|
325
|
-
pContext.generatedId = nanoid();
|
|
326
|
-
}),
|
|
327
|
-
|
|
328
328
|
linkChild: batch(
|
|
329
329
|
assign('data.edges', {
|
|
330
330
|
ADD_CHILD: ({ context: { data }, pContext, payload }) => {
|
|
@@ -368,22 +368,14 @@ export const machine = createMachine(
|
|
|
368
368
|
),
|
|
369
369
|
|
|
370
370
|
moveNode: assign('data.nodes', {
|
|
371
|
-
MOVE: ({ context: { data }, payload }) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (d.id === id) {
|
|
377
|
-
return { ...d, position: { x, y } };
|
|
378
|
-
}
|
|
379
|
-
return d;
|
|
380
|
-
}) ?? []
|
|
381
|
-
);
|
|
371
|
+
MOVE: ({ context: { data }, payload: { id, x, y } }) => {
|
|
372
|
+
return data?.nodes?.map(node => {
|
|
373
|
+
if (node.id === id) return { ...node, position: { x, y } };
|
|
374
|
+
return node;
|
|
375
|
+
});
|
|
382
376
|
},
|
|
383
377
|
}),
|
|
384
378
|
|
|
385
|
-
select: assign('selected', { SELECT: ({ payload }) => payload }),
|
|
386
|
-
|
|
387
379
|
delete: batch(
|
|
388
380
|
filter('data.edges', {
|
|
389
381
|
DELETE: ({ id, from, to }, _, { payload }) => {
|
|
@@ -408,9 +400,6 @@ export const machine = createMachine(
|
|
|
408
400
|
erase('newEdge'),
|
|
409
401
|
),
|
|
410
402
|
|
|
411
|
-
clearNewEdge: erase('newEdge'),
|
|
412
|
-
deselect: erase('selected'),
|
|
413
|
-
|
|
414
403
|
zoom: assign('zoom', {
|
|
415
404
|
ZOOM: ({ context: { zoom }, payload, pContext }) => {
|
|
416
405
|
const next = zoom + payload;
|
|
@@ -433,5 +422,123 @@ export const machine = createMachine(
|
|
|
433
422
|
return 1;
|
|
434
423
|
},
|
|
435
424
|
}),
|
|
425
|
+
|
|
426
|
+
// #region UI
|
|
427
|
+
placeChild: assign('data.nodes', {
|
|
428
|
+
ADD_CHILD: ({ payload, context: { data, board }, pContext }) => {
|
|
429
|
+
if (!board) return data?.nodes;
|
|
430
|
+
const nodes = data?.nodes;
|
|
431
|
+
if (!payload) return nodes;
|
|
432
|
+
|
|
433
|
+
const parentNode = nodes?.find(node => node.id === payload);
|
|
434
|
+
if (!parentNode) return nodes;
|
|
435
|
+
|
|
436
|
+
const parentDimension = pContext.dimensions[payload];
|
|
437
|
+
|
|
438
|
+
const id = `node-${pContext.generatedId}`;
|
|
439
|
+
const width = parentDimension?.width ?? 192;
|
|
440
|
+
const height = parentDimension?.height ?? 50;
|
|
441
|
+
const initialX = parentNode.position.x + width + PARENT_CHILD_GAP_WIDTH;
|
|
442
|
+
const initialY = parentNode.position.y;
|
|
443
|
+
const position = pContext.clampPosition(
|
|
444
|
+
board,
|
|
445
|
+
initialX,
|
|
446
|
+
initialY,
|
|
447
|
+
width,
|
|
448
|
+
height,
|
|
449
|
+
);
|
|
450
|
+
const dimension = pContext.calculateDimensions(position, parentDimension);
|
|
451
|
+
|
|
452
|
+
nodes?.push({
|
|
453
|
+
id,
|
|
454
|
+
data: { content: '<Nouveau nœud>' },
|
|
455
|
+
input: true,
|
|
456
|
+
position,
|
|
457
|
+
});
|
|
458
|
+
pContext.dimensions[id] = dimension;
|
|
459
|
+
|
|
460
|
+
return nodes;
|
|
461
|
+
},
|
|
462
|
+
}),
|
|
463
|
+
|
|
464
|
+
placeParent: assign('data.nodes', {
|
|
465
|
+
ADD_PARENT: ({ context: { data, zoom = 1, board }, pContext }) => {
|
|
466
|
+
if (!board) return data?.nodes;
|
|
467
|
+
const nodes = data?.nodes;
|
|
468
|
+
const id = `node-${pContext.generatedId}`;
|
|
469
|
+
const container = board.parent;
|
|
470
|
+
const scrollLeft = container?.scrollLeft ?? 0;
|
|
471
|
+
const scrollTop = container?.scrollTop ?? 0;
|
|
472
|
+
const width = container?.width ?? 0;
|
|
473
|
+
const height = container?.height ?? 0;
|
|
474
|
+
const currentZoom = zoom;
|
|
475
|
+
const x = (scrollLeft + width / 2) / currentZoom;
|
|
476
|
+
const y = (scrollTop + height / 2) / currentZoom;
|
|
477
|
+
const position = pContext.clampPosition(board, x, y);
|
|
478
|
+
const dimension = pContext.calculateDimensions(position);
|
|
479
|
+
|
|
480
|
+
nodes?.push({
|
|
481
|
+
id,
|
|
482
|
+
data: { content: '<Nouveau nœud>' },
|
|
483
|
+
input: false,
|
|
484
|
+
position,
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
pContext.dimensions[id] = dimension;
|
|
488
|
+
return nodes;
|
|
489
|
+
},
|
|
490
|
+
}),
|
|
491
|
+
|
|
492
|
+
placeSibling: assign('data.nodes', {
|
|
493
|
+
ADD_SIBLING: ({ payload, context: { data, board }, pContext }) => {
|
|
494
|
+
if (!board) return data?.nodes;
|
|
495
|
+
const edges = data?.edges;
|
|
496
|
+
const nodes = data?.nodes;
|
|
497
|
+
const parentID = edges?.find(edge => edge.to === payload)?.from;
|
|
498
|
+
if (!parentID) return nodes;
|
|
499
|
+
|
|
500
|
+
const parentNode = nodes?.find(node => node.id === parentID);
|
|
501
|
+
if (!parentNode) return nodes;
|
|
502
|
+
|
|
503
|
+
const parentDimension = pContext.dimensions[parentID];
|
|
504
|
+
const id = `node-${pContext.generatedId}`;
|
|
505
|
+
const width = parentDimension?.width ?? 192;
|
|
506
|
+
const height = parentDimension?.height ?? 50;
|
|
507
|
+
const initialX = parentNode.position.x + width + PARENT_CHILD_GAP_WIDTH;
|
|
508
|
+
const initialY = parentNode.position.y + PARENT_CHILD_GAP_WIDTH;
|
|
509
|
+
const position = pContext.clampPosition(
|
|
510
|
+
board,
|
|
511
|
+
initialX,
|
|
512
|
+
initialY,
|
|
513
|
+
width,
|
|
514
|
+
height,
|
|
515
|
+
);
|
|
516
|
+
const dimension = pContext.calculateDimensions(position, parentDimension);
|
|
517
|
+
|
|
518
|
+
nodes?.push({
|
|
519
|
+
id,
|
|
520
|
+
data: { content: '<Nouveau nœud>' },
|
|
521
|
+
input: true,
|
|
522
|
+
position,
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
pContext.dimensions[id] = dimension;
|
|
526
|
+
return nodes;
|
|
527
|
+
},
|
|
528
|
+
}),
|
|
529
|
+
|
|
530
|
+
moveNewEdge: assign('newEdge', {
|
|
531
|
+
MOVE_NEW_EDGE: ({ context: { newEdge, board }, payload, pContext }) => {
|
|
532
|
+
if (!board) return undefined;
|
|
533
|
+
if (!newEdge) return undefined;
|
|
534
|
+
const { x: x1, y: y1 } = pContext.getBoardPosition(
|
|
535
|
+
payload.x,
|
|
536
|
+
payload.y,
|
|
537
|
+
board,
|
|
538
|
+
);
|
|
539
|
+
return { ...newEdge, x1, y1 };
|
|
540
|
+
},
|
|
541
|
+
}),
|
|
542
|
+
// #endregion
|
|
436
543
|
},
|
|
437
544
|
}));
|
|
@@ -51,13 +51,9 @@ export const EdgeComponent: Component<Props> = props => {
|
|
|
51
51
|
const service = useFlow();
|
|
52
52
|
|
|
53
53
|
const vector = createState(service, {
|
|
54
|
-
selector: ({ context }) => {
|
|
55
|
-
if (props.isNew)
|
|
56
|
-
|
|
57
|
-
if (!edge) return undefined;
|
|
58
|
-
return { x0: edge.x0, y0: edge.y0, x1: edge.x1, y1: edge.y1 };
|
|
59
|
-
}
|
|
60
|
-
return context.edgesPositions[props.id];
|
|
54
|
+
selector: ({ context: { newEdge, edgesPositions } }) => {
|
|
55
|
+
if (props.isNew) return newEdge!;
|
|
56
|
+
return edgesPositions[props.id];
|
|
61
57
|
},
|
|
62
58
|
equals: dequal,
|
|
63
59
|
});
|
|
@@ -69,59 +65,53 @@ export const EdgeComponent: Component<Props> = props => {
|
|
|
69
65
|
/** Computes the 2D midpoint coordinate of the edge curve for handle placement. */
|
|
70
66
|
const middlePoint = () => {
|
|
71
67
|
const v = vector();
|
|
72
|
-
if (!v) return { x: 0, y: 0 };
|
|
73
68
|
return { x: v.x0 + (v.x1 - v.x0) / 2, y: v.y0 + (v.y1 - v.y0) / 2 };
|
|
74
69
|
};
|
|
75
70
|
|
|
76
71
|
return (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}}
|
|
88
|
-
style={{ 'pointer-events': props.isNew ? 'none' : 'all' }}
|
|
89
|
-
d={draw(v())}
|
|
72
|
+
<>
|
|
73
|
+
<path
|
|
74
|
+
class='relative cursor-pointer fill-transparent'
|
|
75
|
+
classList={{
|
|
76
|
+
'stroke-[rgba(168,168,168,0.4)] stroke-3 z-200': !!props.isNew,
|
|
77
|
+
'stroke-[rgba(168,168,168,1)] stroke-4 z-100': selected() && !props.isNew,
|
|
78
|
+
'stroke-[rgba(168,168,168,0.8)] stroke-3': !selected() && !props.isNew,
|
|
79
|
+
}}
|
|
80
|
+
style={{ 'pointer-events': props.isNew ? 'none' : 'all' }}
|
|
81
|
+
d={draw(vector())}
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)}
|
|
125
|
-
</Show>
|
|
83
|
+
onMouseDown={e => {
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
return service.send({ type: 'SELECT', payload: props.id });
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
<Show when={selected()}>
|
|
89
|
+
<g
|
|
90
|
+
cursor='pointer'
|
|
91
|
+
transform={`translate(${middlePoint().x}, ${middlePoint().y})`}
|
|
92
|
+
onMouseDown={e => {
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
service.send({ type: 'DELETE', payload: props.id });
|
|
95
|
+
}}
|
|
96
|
+
style={{ 'pointer-events': 'all', 'z-index': '30' }}
|
|
97
|
+
>
|
|
98
|
+
<circle cx='0' cy='0' r='12' fill='rgba(168, 168, 168, 1)' />
|
|
99
|
+
<svg
|
|
100
|
+
fill='currentColor'
|
|
101
|
+
stroke-width='0'
|
|
102
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
103
|
+
class='h-25 w-25 bg-white fill-white'
|
|
104
|
+
width='20'
|
|
105
|
+
height='20'
|
|
106
|
+
viewBox='0 0 20 20'
|
|
107
|
+
color='white'
|
|
108
|
+
x='-10'
|
|
109
|
+
y='-10'
|
|
110
|
+
>
|
|
111
|
+
<path d='M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z'></path>
|
|
112
|
+
</svg>
|
|
113
|
+
</g>
|
|
114
|
+
</Show>
|
|
115
|
+
</>
|
|
126
116
|
);
|
|
127
117
|
};
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
BOUNDS_CONSTRAINTS,
|
|
7
7
|
DEFAULT_INPUT_OFFSET,
|
|
8
8
|
getDefaultOutputOffset,
|
|
9
|
-
PARENT_CHILD_GAP_WIDTH,
|
|
10
9
|
} from '#services/main.machine.data';
|
|
11
10
|
import type { Dimension, Point } from '#services/main.machine.typings';
|
|
12
11
|
|
|
@@ -34,7 +33,7 @@ export const [Provider, useFlow] = createContext(
|
|
|
34
33
|
*
|
|
35
34
|
* @returns Calculated 2D coordinate of type {@linkcode Point}.
|
|
36
35
|
*/
|
|
37
|
-
getBoardPosition(clientX, clientY, el): Point {
|
|
36
|
+
getBoardPosition: (clientX, clientY, el): Point => {
|
|
38
37
|
if (!el) return { x: clientX, y: clientY };
|
|
39
38
|
const currentZoom = service.state.context.zoom;
|
|
40
39
|
const x = (clientX - el.self.left) / currentZoom;
|
|
@@ -56,7 +55,7 @@ export const [Provider, useFlow] = createContext(
|
|
|
56
55
|
*
|
|
57
56
|
* @see {@linkcode BOUNDS_CONSTRAINTS}
|
|
58
57
|
*/
|
|
59
|
-
clampPosition(board, x, y, nodeWidth = 192, nodeHeight = 50): Point {
|
|
58
|
+
clampPosition: (board, x, y, nodeWidth = 192, nodeHeight = 50): Point => {
|
|
60
59
|
const container = board?.parent;
|
|
61
60
|
if (!container) return { x, y };
|
|
62
61
|
|
|
@@ -125,134 +124,6 @@ export const [Provider, useFlow] = createContext(
|
|
|
125
124
|
},
|
|
126
125
|
});
|
|
127
126
|
|
|
128
|
-
// #endregion
|
|
129
|
-
|
|
130
|
-
service.addOptions(({ assign }) => ({
|
|
131
|
-
actions: {
|
|
132
|
-
placeChild: assign('data.nodes', {
|
|
133
|
-
ADD_CHILD: ({ payload, context: { data, board }, pContext }) => {
|
|
134
|
-
if (!board) return data?.nodes;
|
|
135
|
-
const nodes = data?.nodes;
|
|
136
|
-
if (!payload) return nodes;
|
|
137
|
-
|
|
138
|
-
const parentNode = nodes?.find(node => node.id === payload);
|
|
139
|
-
if (!parentNode) return nodes;
|
|
140
|
-
|
|
141
|
-
const parentDimension = pContext.dimensions[payload];
|
|
142
|
-
|
|
143
|
-
const id = `node-${pContext.generatedId}`;
|
|
144
|
-
const width = parentDimension?.width ?? 192;
|
|
145
|
-
const height = parentDimension?.height ?? 50;
|
|
146
|
-
const initialX = parentNode.position.x + width + PARENT_CHILD_GAP_WIDTH;
|
|
147
|
-
const initialY = parentNode.position.y;
|
|
148
|
-
const position = pContext.clampPosition(
|
|
149
|
-
board,
|
|
150
|
-
initialX,
|
|
151
|
-
initialY,
|
|
152
|
-
width,
|
|
153
|
-
height,
|
|
154
|
-
);
|
|
155
|
-
const dimension = pContext.calculateDimensions(
|
|
156
|
-
position,
|
|
157
|
-
parentDimension,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
nodes?.push({
|
|
161
|
-
id,
|
|
162
|
-
data: { content: '<Nouveau nœud>' },
|
|
163
|
-
input: true,
|
|
164
|
-
position,
|
|
165
|
-
});
|
|
166
|
-
pContext.dimensions[id] = dimension;
|
|
167
|
-
|
|
168
|
-
return nodes;
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
|
|
172
|
-
placeParent: assign('data.nodes', {
|
|
173
|
-
ADD_PARENT: ({ context: { data, zoom = 1, board }, pContext }) => {
|
|
174
|
-
if (!board) return data?.nodes;
|
|
175
|
-
const nodes = data?.nodes;
|
|
176
|
-
const id = `node-${pContext.generatedId}`;
|
|
177
|
-
const container = board.parent;
|
|
178
|
-
const scrollLeft = container?.scrollLeft ?? 0;
|
|
179
|
-
const scrollTop = container?.scrollTop ?? 0;
|
|
180
|
-
const width = container?.width ?? 0;
|
|
181
|
-
const height = container?.height ?? 0;
|
|
182
|
-
const currentZoom = zoom;
|
|
183
|
-
const x = (scrollLeft + width / 2) / currentZoom;
|
|
184
|
-
const y = (scrollTop + height / 2) / currentZoom;
|
|
185
|
-
const position = pContext.clampPosition(board, x, y);
|
|
186
|
-
const dimension = pContext.calculateDimensions(position);
|
|
187
|
-
|
|
188
|
-
nodes?.push({
|
|
189
|
-
id,
|
|
190
|
-
data: { content: '<Nouveau nœud>' },
|
|
191
|
-
input: false,
|
|
192
|
-
position,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
pContext.dimensions[id] = dimension;
|
|
196
|
-
return nodes;
|
|
197
|
-
},
|
|
198
|
-
}),
|
|
199
|
-
|
|
200
|
-
placeSibling: assign('data.nodes', {
|
|
201
|
-
ADD_SIBLING: ({ payload, context: { data, board }, pContext }) => {
|
|
202
|
-
if (!board) return data?.nodes;
|
|
203
|
-
const edges = data?.edges;
|
|
204
|
-
const nodes = data?.nodes;
|
|
205
|
-
const parentID = edges?.find(edge => edge.to === payload)?.from;
|
|
206
|
-
if (!parentID) return nodes;
|
|
207
|
-
|
|
208
|
-
const parentNode = nodes?.find(node => node.id === parentID);
|
|
209
|
-
if (!parentNode) return nodes;
|
|
210
|
-
|
|
211
|
-
const parentDimension = pContext.dimensions[parentID];
|
|
212
|
-
const id = `node-${pContext.generatedId}`;
|
|
213
|
-
const width = parentDimension?.width ?? 192;
|
|
214
|
-
const height = parentDimension?.height ?? 50;
|
|
215
|
-
const initialX = parentNode.position.x + width + PARENT_CHILD_GAP_WIDTH;
|
|
216
|
-
const initialY = parentNode.position.y + PARENT_CHILD_GAP_WIDTH;
|
|
217
|
-
const position = pContext.clampPosition(
|
|
218
|
-
board,
|
|
219
|
-
initialX,
|
|
220
|
-
initialY,
|
|
221
|
-
width,
|
|
222
|
-
height,
|
|
223
|
-
);
|
|
224
|
-
const dimension = pContext.calculateDimensions(
|
|
225
|
-
position,
|
|
226
|
-
parentDimension,
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
nodes?.push({
|
|
230
|
-
id,
|
|
231
|
-
data: { content: '<Nouveau nœud>' },
|
|
232
|
-
input: true,
|
|
233
|
-
position,
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
pContext.dimensions[id] = dimension;
|
|
237
|
-
return nodes;
|
|
238
|
-
},
|
|
239
|
-
}),
|
|
240
|
-
|
|
241
|
-
moveNewEdge: assign('newEdge', {
|
|
242
|
-
MOVE_NEW_EDGE: ({ context: { newEdge, board }, payload, pContext }) => {
|
|
243
|
-
if (!board) return undefined;
|
|
244
|
-
if (!newEdge) return undefined;
|
|
245
|
-
const { x: x1, y: y1 } = pContext.getBoardPosition(
|
|
246
|
-
payload.x,
|
|
247
|
-
payload.y,
|
|
248
|
-
board,
|
|
249
|
-
);
|
|
250
|
-
return { ...newEdge, x1, y1 };
|
|
251
|
-
},
|
|
252
|
-
}),
|
|
253
|
-
},
|
|
254
|
-
}));
|
|
255
|
-
|
|
256
127
|
service.start();
|
|
257
128
|
return service;
|
|
258
129
|
},
|
|
@@ -65,35 +65,35 @@ export type FlowProps = {
|
|
|
65
65
|
export const FlowChart: Component<FlowProps> = props => {
|
|
66
66
|
const primaryNodes = props.config?.nodes ?? DEFAULT_NODES;
|
|
67
67
|
const primaryEdges = props.config?.edges;
|
|
68
|
-
|
|
69
68
|
const service = useFlow();
|
|
70
|
-
|
|
71
69
|
const hasNewEdge = createState(service, { selector: s => !!s.context.newEdge });
|
|
70
|
+
onCleanup(service.pause);
|
|
72
71
|
|
|
73
72
|
onMount(() => {
|
|
74
73
|
service.resume();
|
|
74
|
+
|
|
75
75
|
service.send({
|
|
76
76
|
type: 'CONFIGURE',
|
|
77
77
|
payload: { nodes: primaryNodes, edges: primaryEdges ?? [] },
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
onCleanup(service.pause);
|
|
82
|
-
|
|
83
81
|
return (
|
|
84
82
|
<div
|
|
85
83
|
class='relative h-full w-full'
|
|
86
84
|
onMouseUp={() => service.send('CLEAR_NEW_EDGE')}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
|
|
86
|
+
onMouseMove={({ clientX, clientY }) => {
|
|
87
|
+
if (hasNewEdge())
|
|
88
|
+
service.send({
|
|
89
|
+
type: 'MOVE_NEW_EDGE',
|
|
90
|
+
payload: { x: clientX, y: clientY },
|
|
91
|
+
});
|
|
92
92
|
}}
|
|
93
|
-
style={{}}
|
|
94
93
|
>
|
|
95
94
|
<div
|
|
96
95
|
class='relative h-full w-full bg-white bg-size-[30px_30px]'
|
|
96
|
+
|
|
97
97
|
style={{
|
|
98
98
|
cursor: hasNewEdge() ? 'inherit' : 'crosshair',
|
|
99
99
|
'background-image':
|