@next-bricks/diagram 0.28.1 → 0.30.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.
Files changed (71) hide show
  1. package/dist/bricks.json +3 -3
  2. package/dist/chunks/1728.cf49ae61.js +2 -0
  3. package/dist/chunks/1728.cf49ae61.js.map +1 -0
  4. package/dist/chunks/1860.4fd60630.js +2 -0
  5. package/dist/chunks/1860.4fd60630.js.map +1 -0
  6. package/dist/chunks/{1972.8418a5c0.js → 1972.d6fea46c.js} +2 -2
  7. package/dist/chunks/{1972.8418a5c0.js.map → 1972.d6fea46c.js.map} +1 -1
  8. package/dist/chunks/5481.d6977dfc.js +3 -0
  9. package/dist/chunks/5481.d6977dfc.js.map +1 -0
  10. package/dist/chunks/7034.286dd8ae.js +3 -0
  11. package/dist/chunks/7034.286dd8ae.js.map +1 -0
  12. package/dist/chunks/709.bc74a999.js +2 -0
  13. package/dist/chunks/709.bc74a999.js.map +1 -0
  14. package/dist/chunks/{9591.d3a952ac.js → 9591.c5101110.js} +2 -2
  15. package/dist/chunks/{9591.d3a952ac.js.map → 9591.c5101110.js.map} +1 -1
  16. package/dist/chunks/editable-label.e37e189e.js +3 -0
  17. package/dist/chunks/{editable-label.8e6f528c.js.map → editable-label.e37e189e.js.map} +1 -1
  18. package/dist/chunks/{eo-diagram.40f64d0f.js → eo-diagram.5f32fd41.js} +2 -2
  19. package/dist/chunks/eo-diagram.5f32fd41.js.map +1 -0
  20. package/dist/chunks/eo-display-canvas.74087b7e.js +2 -0
  21. package/dist/chunks/eo-display-canvas.74087b7e.js.map +1 -0
  22. package/dist/chunks/eo-draw-canvas.5602b10d.js +2 -0
  23. package/dist/chunks/eo-draw-canvas.5602b10d.js.map +1 -0
  24. package/dist/chunks/main.229129b2.js +2 -0
  25. package/dist/chunks/main.229129b2.js.map +1 -0
  26. package/dist/examples.json +2 -2
  27. package/dist/index.439a5d8f.js +2 -0
  28. package/dist/index.439a5d8f.js.map +1 -0
  29. package/dist/manifest.json +59 -41
  30. package/dist/types.json +1234 -552
  31. package/dist-types/display-canvas/index.d.ts +5 -1
  32. package/dist-types/draw-canvas/CellComponent.d.ts +4 -4
  33. package/dist-types/draw-canvas/EdgeComponent.d.ts +3 -4
  34. package/dist-types/draw-canvas/constants.d.ts +4 -0
  35. package/dist-types/draw-canvas/index.d.ts +5 -1
  36. package/dist-types/draw-canvas/interfaces.d.ts +43 -2
  37. package/dist-types/draw-canvas/processors/asserts.d.ts +1 -0
  38. package/dist-types/draw-canvas/processors/handleMouseDown.d.ts +3 -2
  39. package/dist-types/draw-canvas/processors/updateCells.d.ts +3 -2
  40. package/dist-types/shared/canvas/useAutoCenter.d.ts +2 -1
  41. package/dist-types/shared/canvas/useLayout.d.ts +19 -0
  42. package/dist-types/shared/canvas/useLineMarkers.d.ts +10 -0
  43. package/dist-types/shared/canvas/useReady.d.ts +7 -0
  44. package/docs/eo-display-canvas.md +276 -0
  45. package/docs/eo-draw-canvas.md +770 -0
  46. package/package.json +2 -2
  47. package/dist/chunks/1728.8cc54faa.js +0 -2
  48. package/dist/chunks/1728.8cc54faa.js.map +0 -1
  49. package/dist/chunks/4456.3fd8ee7c.js +0 -2
  50. package/dist/chunks/4456.3fd8ee7c.js.map +0 -1
  51. package/dist/chunks/5816.f6e1a89e.js +0 -3
  52. package/dist/chunks/5816.f6e1a89e.js.map +0 -1
  53. package/dist/chunks/730.3f786ebf.js +0 -3
  54. package/dist/chunks/730.3f786ebf.js.map +0 -1
  55. package/dist/chunks/8304.613a484c.js +0 -2
  56. package/dist/chunks/8304.613a484c.js.map +0 -1
  57. package/dist/chunks/9061.cbb65689.js +0 -2
  58. package/dist/chunks/9061.cbb65689.js.map +0 -1
  59. package/dist/chunks/editable-label.8e6f528c.js +0 -3
  60. package/dist/chunks/eo-diagram.40f64d0f.js.map +0 -1
  61. package/dist/chunks/eo-display-canvas.ab282773.js +0 -2
  62. package/dist/chunks/eo-display-canvas.ab282773.js.map +0 -1
  63. package/dist/chunks/eo-draw-canvas.ef0d61bd.js +0 -2
  64. package/dist/chunks/eo-draw-canvas.ef0d61bd.js.map +0 -1
  65. package/dist/chunks/main.660ee53e.js +0 -2
  66. package/dist/chunks/main.660ee53e.js.map +0 -1
  67. package/dist/index.3e204276.js +0 -2
  68. package/dist/index.3e204276.js.map +0 -1
  69. /package/dist/chunks/{5816.f6e1a89e.js.LICENSE.txt → 5481.d6977dfc.js.LICENSE.txt} +0 -0
  70. /package/dist/chunks/{730.3f786ebf.js.LICENSE.txt → 7034.286dd8ae.js.LICENSE.txt} +0 -0
  71. /package/dist/chunks/{editable-label.8e6f528c.js.LICENSE.txt → editable-label.e37e189e.js.LICENSE.txt} +0 -0
@@ -2,9 +2,11 @@ import React from "react";
2
2
  import { ReactNextElement } from "@next-core/react-element";
3
3
  import "@next-core/theme";
4
4
  import type { RangeTuple, SizeTuple } from "../diagram/interfaces";
5
- import type { ActiveTarget, InitialCell, NodeBrickConf, CellContextMenuDetail, EdgeLineConf } from "../draw-canvas/interfaces";
5
+ import type { ActiveTarget, InitialCell, NodeBrickConf, CellContextMenuDetail, EdgeLineConf, LayoutType, LayoutOptions } from "../draw-canvas/interfaces";
6
6
  export interface EoDisplayCanvasProps {
7
7
  cells: InitialCell[] | undefined;
8
+ layout: LayoutType;
9
+ layoutOptions?: LayoutOptions;
8
10
  defaultNodeSize: SizeTuple;
9
11
  defaultNodeBricks?: NodeBrickConf[];
10
12
  defaultEdgeLines?: EdgeLineConf[];
@@ -24,6 +26,8 @@ export declare class EoDisplayCanvas extends ReactNextElement implements EoDispl
24
26
  * 仅当初始化时使用,渲染后重新设置 `cells` 将无效。
25
27
  */
26
28
  accessor cells: InitialCell[] | undefined;
29
+ accessor layout: LayoutType;
30
+ accessor layoutOptions: LayoutOptions | undefined;
27
31
  accessor defaultNodeSize: SizeTuple;
28
32
  accessor defaultNodeBricks: NodeBrickConf[] | undefined;
29
33
  /**
@@ -1,14 +1,14 @@
1
1
  /// <reference types="react" />
2
- import type { ActiveTarget, Cell, CellContextMenuDetail, DecoratorTextChangeDetail, EdgeLineConf, NodeBrickConf } from "./interfaces";
2
+ import type { ActiveTarget, Cell, CellContextMenuDetail, ComputedEdgeLineConf, DecoratorTextChangeDetail, EdgeCell, LayoutType, NodeBrickConf } from "./interfaces";
3
3
  import type { MoveCellPayload, ResizeCellPayload } from "./reducers/interfaces";
4
4
  import type { SizeTuple, TransformLiteral } from "../diagram/interfaces";
5
5
  export interface CellComponentProps {
6
+ layout: LayoutType;
6
7
  cell: Cell;
7
8
  cells: Cell[];
8
9
  defaultNodeBricks?: NodeBrickConf[];
9
- defaultEdgeLines?: EdgeLineConf[];
10
10
  transform: TransformLiteral;
11
- markerEnd: string;
11
+ lineConfMap: WeakMap<EdgeCell, ComputedEdgeLineConf>;
12
12
  active: boolean;
13
13
  readOnly?: boolean;
14
14
  unrelatedCells: Cell[];
@@ -27,4 +27,4 @@ export interface CellComponentProps {
27
27
  onCellMouseEnter?(cell: Cell): void;
28
28
  onCellMouseLeave?(cell: Cell): void;
29
29
  }
30
- export declare function CellComponent({ cell, cells, defaultNodeBricks, defaultEdgeLines, markerEnd, active, readOnly, transform, unrelatedCells, onCellMoving, onCellMoved, onCellResizing, onCellResized, onSwitchActiveTarget, onCellContextMenu, onDecoratorTextEditing, onDecoratorTextChange, onNodeBrickResize, onCellMouseEnter, onCellMouseLeave, }: CellComponentProps): JSX.Element | null;
30
+ export declare function CellComponent({ layout, cell, cells, defaultNodeBricks, lineConfMap, active, readOnly, transform, unrelatedCells, onCellMoving, onCellMoved, onCellResizing, onCellResized, onSwitchActiveTarget, onCellContextMenu, onDecoratorTextEditing, onDecoratorTextChange, onNodeBrickResize, onCellMouseEnter, onCellMouseLeave, }: CellComponentProps): JSX.Element | null;
@@ -1,9 +1,8 @@
1
1
  /// <reference types="react" />
2
- import type { Cell, EdgeCell, EdgeLineConf } from "./interfaces";
2
+ import type { Cell, ComputedEdgeLineConf, EdgeCell } from "./interfaces";
3
3
  export interface EdgeComponentProps {
4
4
  edge: EdgeCell;
5
5
  cells: Cell[];
6
- markerEnd: string;
7
- defaultEdgeLines?: EdgeLineConf[];
6
+ lineConfMap: WeakMap<EdgeCell, ComputedEdgeLineConf>;
8
7
  }
9
- export declare function EdgeComponent({ edge, cells, markerEnd, defaultEdgeLines, }: EdgeComponentProps): JSX.Element | null;
8
+ export declare function EdgeComponent({ edge, cells, lineConfMap, }: EdgeComponentProps): JSX.Element | null;
@@ -1,7 +1,11 @@
1
1
  export declare const SYMBOL_FOR_SIZE_INITIALIZED: unique symbol;
2
+ export declare const SYMBOL_FOR_LAYOUT_INITIALIZED: unique symbol;
2
3
  export declare const DEFAULT_NODE_SIZE = 20;
3
4
  export declare const DEFAULT_NODE_GAP = 36;
4
5
  export declare const DEFAULT_AREA_WIDTH = 100;
5
6
  export declare const DEFAULT_AREA_HEIGHT = 60;
6
7
  export declare const DEFAULT_SCALE_RANGE_MIN = 0.5;
7
8
  export declare const DEFAULT_SCALE_RANGE_MAX = 2;
9
+ export declare const DEFAULT_LINE_STROKE_COLOR = "gray";
10
+ export declare const DEFAULT_LINE_STROKE_WIDTH = 1;
11
+ export declare const DEFAULT_LINE_INTERACT_STROKE_WIDTH = 15;
@@ -3,10 +3,12 @@ import { ReactNextElement } from "@next-core/react-element";
3
3
  import type { UseSingleBrickConf } from "@next-core/react-runtime";
4
4
  import "@next-core/theme";
5
5
  import type { PositionTuple, RangeTuple, SizeTuple, TransformLiteral } from "../diagram/interfaces";
6
- import type { ActiveTarget, Cell, EdgeCell, InitialCell, NodeBrickConf, NodeCell, NodeId, DecoratorCell, DecoratorType, CellContextMenuDetail, ConnectNodesDetail, EdgeLineConf, DecoratorTextChangeDetail } from "./interfaces";
6
+ import type { ActiveTarget, Cell, EdgeCell, InitialCell, NodeBrickConf, NodeCell, NodeId, DecoratorCell, DecoratorType, CellContextMenuDetail, ConnectNodesDetail, EdgeLineConf, DecoratorTextChangeDetail, LayoutType, LayoutOptions } from "./interfaces";
7
7
  import type { MoveCellPayload, ResizeCellPayload } from "./reducers/interfaces";
8
8
  export interface EoDrawCanvasProps {
9
9
  cells: InitialCell[] | undefined;
10
+ layout: LayoutType;
11
+ layoutOptions?: LayoutOptions;
10
12
  defaultNodeSize: SizeTuple;
11
13
  defaultNodeBricks?: NodeBrickConf[];
12
14
  defaultEdgeLines?: EdgeLineConf[];
@@ -59,6 +61,8 @@ export declare class EoDrawCanvas extends ReactNextElement implements EoDrawCanv
59
61
  * 仅当初始化时使用,渲染后重新设置 `cells` 将无效。
60
62
  */
61
63
  accessor cells: InitialCell[] | undefined;
64
+ accessor layout: LayoutType;
65
+ accessor layoutOptions: LayoutOptions | undefined;
62
66
  accessor defaultNodeSize: SizeTuple;
63
67
  accessor defaultNodeBricks: NodeBrickConf[] | undefined;
64
68
  /**
@@ -1,7 +1,8 @@
1
1
  import type { UseSingleBrickConf } from "@next-core/react-runtime";
2
+ import type { SimulationLinkDatum, SimulationNodeDatum } from "d3-force";
2
3
  import type { ResizeCellPayload } from "./reducers/interfaces";
3
- import type { PositionTuple, TransformLiteral } from "../diagram/interfaces";
4
- import { SYMBOL_FOR_SIZE_INITIALIZED } from "./constants";
4
+ import type { PartialRectTuple, PositionTuple, TransformLiteral } from "../diagram/interfaces";
5
+ import { SYMBOL_FOR_SIZE_INITIALIZED, type SYMBOL_FOR_LAYOUT_INITIALIZED } from "./constants";
5
6
  export type Cell = NodeCell | EdgeCell | DecoratorCell;
6
7
  export type BrickCell = NodeBrickCell;
7
8
  export type NodeCell = NodeBrickCell;
@@ -17,6 +18,7 @@ export interface BaseNodeCell extends BaseCell {
17
18
  id: NodeId;
18
19
  view: NodeView;
19
20
  [SYMBOL_FOR_SIZE_INITIALIZED]?: boolean;
21
+ [SYMBOL_FOR_LAYOUT_INITIALIZED]?: boolean;
20
22
  }
21
23
  export interface BaseEdgeCell extends BaseCell {
22
24
  type: "edge";
@@ -58,6 +60,19 @@ export interface NodeBrickConf {
58
60
  export interface EdgeLineConf {
59
61
  if?: string | boolean | null;
60
62
  dashed?: boolean;
63
+ strokeWidth?: number;
64
+ strokeColor?: string;
65
+ interactStrokeWidth?: number;
66
+ }
67
+ export interface ComputedEdgeLineConf {
68
+ dashed: boolean;
69
+ strokeWidth: number;
70
+ strokeColor: string;
71
+ interactStrokeWidth: number;
72
+ markerEnd: string;
73
+ }
74
+ export interface LineMarker {
75
+ strokeColor: string;
61
76
  }
62
77
  export type ActiveTarget = ActiveTargetOfNode | ActiveTargetOfEdge | ActiveTargetOfDecorator;
63
78
  export interface ActiveTargetOfNode {
@@ -108,3 +123,29 @@ export interface DecoratorTextChangeDetail {
108
123
  id: string;
109
124
  view: DecoratorView;
110
125
  }
126
+ export type LayoutType = "manual" | "force" | "dagre" | undefined;
127
+ export type LayoutOptions = LayoutOptionsDagre | LayoutOptionsForce;
128
+ export interface LayoutOptionsDagre extends BaseLayoutOptions {
129
+ rankdir?: "TB" | "BT" | "LR" | "RL";
130
+ ranksep?: number;
131
+ edgesep?: number;
132
+ nodesep?: number;
133
+ align?: "UL" | "UR" | "DL" | "DR";
134
+ }
135
+ export interface LayoutOptionsForce extends BaseLayoutOptions {
136
+ collide?: boolean | ForceCollideOptions;
137
+ }
138
+ export interface ForceCollideOptions {
139
+ radiusDiff?: number;
140
+ strength?: number;
141
+ iterations?: number;
142
+ }
143
+ export interface BaseLayoutOptions {
144
+ nodePadding?: PartialRectTuple;
145
+ }
146
+ export interface ForceNode extends SimulationNodeDatum {
147
+ id: NodeId;
148
+ width: number;
149
+ height: number;
150
+ }
151
+ export type ForceLink = SimulationLinkDatum<ForceNode>;
@@ -3,3 +3,4 @@ export declare function isNodeCell(cell: Cell): cell is NodeCell;
3
3
  export declare function isDecoratorCell(cell: Cell): cell is DecoratorCell;
4
4
  export declare function isInitialNodeCell(cell: InitialCell): cell is InitialNodeCell;
5
5
  export declare function isEdgeCell(cell: Cell): cell is EdgeCell;
6
+ export declare function isNodeOrEdgeCell(cell: Cell): cell is NodeCell | EdgeCell;
@@ -1,9 +1,10 @@
1
- import type { ActiveTarget, Cell } from "../interfaces";
1
+ import type { ActiveTarget, Cell, LayoutType } from "../interfaces";
2
2
  import type { MoveCellPayload, ResizeCellPayload } from "../reducers/interfaces";
3
- export declare function handleMouseDown(event: MouseEvent, { action, cell, scale, onCellMoving, onCellMoved, onCellResizing, onCellResized, onSwitchActiveTarget, }: {
3
+ export declare function handleMouseDown(event: MouseEvent, { action, cell, scale, layout, onCellMoving, onCellMoved, onCellResizing, onCellResized, onSwitchActiveTarget, }: {
4
4
  action: "move" | "resize";
5
5
  cell: Cell;
6
6
  scale: number;
7
+ layout?: LayoutType;
7
8
  onCellMoving?(info: MoveCellPayload): void;
8
9
  onCellMoved?(info: MoveCellPayload): void;
9
10
  onCellResizing?(info: ResizeCellPayload): void;
@@ -1,7 +1,8 @@
1
1
  import type { RangeTuple, SizeTuple, TransformLiteral } from "../../diagram/interfaces";
2
- import type { Cell, InitialCell, NodeId } from "../interfaces";
3
- export declare function updateCells({ cells, previousCells, defaultNodeSize, canvasWidth, canvasHeight, scaleRange, transform, reason, parent, }: {
2
+ import type { Cell, InitialCell, LayoutType, NodeId } from "../interfaces";
3
+ export declare function updateCells({ cells, layout, previousCells, defaultNodeSize, canvasWidth, canvasHeight, scaleRange, transform, reason, parent, }: {
4
4
  cells: InitialCell[];
5
+ layout?: LayoutType;
5
6
  previousCells: Cell[];
6
7
  defaultNodeSize: SizeTuple;
7
8
  canvasWidth: number;
@@ -5,6 +5,7 @@ import type { Cell } from "../../draw-canvas/interfaces";
5
5
  export interface UseAutoCenterOptions {
6
6
  rootRef: React.RefObject<SVGSVGElement>;
7
7
  cells: Cell[];
8
+ layoutInitialized: boolean;
8
9
  zoomable?: boolean;
9
10
  zoomer: ZoomBehavior<SVGSVGElement, unknown>;
10
11
  scaleRange: RangeTuple;
@@ -13,4 +14,4 @@ export type UseAutoCenterResult = [
13
14
  centered: boolean,
14
15
  setCentered: React.Dispatch<React.SetStateAction<boolean>>
15
16
  ];
16
- export declare function useAutoCenter({ rootRef, cells, zoomable, zoomer, scaleRange, }: UseAutoCenterOptions): UseAutoCenterResult;
17
+ export declare function useAutoCenter({ rootRef, cells, layoutInitialized, zoomable, zoomer, scaleRange, }: UseAutoCenterOptions): UseAutoCenterResult;
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import type { ZoomBehavior } from "d3-zoom";
3
+ import type { Cell, LayoutOptions, LayoutType } from "../../draw-canvas/interfaces";
4
+ import type { RangeTuple } from "../../diagram/interfaces";
5
+ import type { DrawCanvasAction } from "../../draw-canvas/reducers/interfaces";
6
+ export interface UseLayoutOptions {
7
+ layout: LayoutType;
8
+ layoutOptions?: LayoutOptions;
9
+ rootRef: React.RefObject<SVGSVGElement>;
10
+ cells: Cell[];
11
+ zoomable?: boolean;
12
+ zoomer: ZoomBehavior<SVGSVGElement, unknown>;
13
+ scaleRange: RangeTuple;
14
+ dispatch: (value: DrawCanvasAction) => void;
15
+ }
16
+ export declare function useLayout({ layout, layoutOptions, rootRef, cells, zoomable, zoomer, scaleRange, dispatch, }: UseLayoutOptions): {
17
+ centered: boolean;
18
+ setCentered: React.Dispatch<React.SetStateAction<boolean>>;
19
+ };
@@ -0,0 +1,10 @@
1
+ import type { Cell, ComputedEdgeLineConf, EdgeCell, EdgeLineConf, LineMarker } from "../../draw-canvas/interfaces";
2
+ export interface UseLineMarkersOptions {
3
+ cells: Cell[];
4
+ defaultEdgeLines: EdgeLineConf[] | undefined;
5
+ markerPrefix: string;
6
+ }
7
+ export declare function useLineMarkers({ cells, defaultEdgeLines, markerPrefix, }: UseLineMarkersOptions): [
8
+ lineConfMap: WeakMap<EdgeCell, ComputedEdgeLineConf>,
9
+ markers: LineMarker[]
10
+ ];
@@ -0,0 +1,7 @@
1
+ import type { Cell, LayoutType } from "../../draw-canvas/interfaces";
2
+ export interface UseReadyOptions {
3
+ cells: Cell[];
4
+ layout: LayoutType;
5
+ centered: boolean;
6
+ }
7
+ export declare function useReady({ cells, layout, centered }: UseReadyOptions): boolean;
@@ -146,3 +146,279 @@
146
146
  ]
147
147
  %>
148
148
  ```
149
+
150
+ ### Force layout
151
+
152
+ ```yaml preview minHeight="600px"
153
+ - brick: div
154
+ properties:
155
+ style:
156
+ display: flex
157
+ height: 600px
158
+ gap: 1em
159
+ context:
160
+ - name: initialCells
161
+ value: |
162
+ <%
163
+ [
164
+ {
165
+ type: "decorator",
166
+ id: "area-1",
167
+ decorator: "area",
168
+ view: {
169
+ x: 10,
170
+ y: 20,
171
+ width: 400,
172
+ height: 300,
173
+ },
174
+ },
175
+ {
176
+ type: "edge",
177
+ source: "X",
178
+ target: "Y",
179
+ },
180
+ {
181
+ type: "edge",
182
+ source: "X",
183
+ target: "Z",
184
+ data: {
185
+ virtual: true,
186
+ }
187
+ },
188
+ ].concat(
189
+ ["X", "Y", "Z", "W"].map((id) => ({
190
+ type: "node",
191
+ id,
192
+ data: {
193
+ name: `Node ${id}`,
194
+ },
195
+ view: {
196
+ width: 60,
197
+ height: 60,
198
+ }
199
+ }))
200
+ ).concat([
201
+ {
202
+ type: "decorator",
203
+ id: "text-1",
204
+ decorator: "text",
205
+ view: {
206
+ x: 100,
207
+ y: 120,
208
+ width: 100,
209
+ height: 20,
210
+ text: "Hello!"
211
+ },
212
+ },
213
+ ])
214
+ %>
215
+ - name: activeTarget
216
+ - name: targetCell
217
+ children:
218
+ - brick: div
219
+ properties:
220
+ style:
221
+ flex: 1
222
+ minWidth: 0
223
+ children:
224
+ - brick: eo-display-canvas
225
+ properties:
226
+ style:
227
+ width: 100%
228
+ height: 100%
229
+ activeTarget: <%= CTX.activeTarget %>
230
+ fadeUnrelatedCells: true
231
+ layout: force
232
+ # Initial nodes only
233
+ defaultNodeSize: [60, 60]
234
+ defaultNodeBricks:
235
+ - useBrick:
236
+ brick: diagram.experimental-node
237
+ properties:
238
+ textContent: <% `Node ${DATA.node.id}` %>
239
+ status: |
240
+ <%=
241
+ CTX.activeTarget?.type === "node" && CTX.activeTarget.id === DATA.node.id
242
+ ? "highlighted"
243
+ // : CTX.unrelated.some(n =>
244
+ // n.type === "node" && n.id === DATA.node.id
245
+ // )
246
+ // ? "faded"
247
+ : "default"
248
+ %>
249
+ defaultEdgeLines:
250
+ - if: <% DATA.edge.data?.virtual %>
251
+ dashed: true
252
+ cells: <% CTX.initialCells %>
253
+ events:
254
+ activeTarget.change:
255
+ action: context.replace
256
+ args:
257
+ - activeTarget
258
+ - <% EVENT.detail %>
259
+ cell.contextmenu:
260
+ - target: eo-context-menu
261
+ method: open
262
+ args:
263
+ - position:
264
+ - <% EVENT.detail.clientX %>
265
+ - <% EVENT.detail.clientY %>
266
+ - action: context.replace
267
+ args:
268
+ - targetCell
269
+ - <% EVENT.detail.cell %>
270
+ scale.change:
271
+ action: context.replace
272
+ args:
273
+ - scale
274
+ - <% EVENT.detail %>
275
+ - brick: eo-context-menu
276
+ properties:
277
+ actions: |
278
+ <%=
279
+ [
280
+ {
281
+ text: `Test ${CTX.targetCell?.type}`,
282
+ event: `test-${CTX.targetCell?.type}`,
283
+ }
284
+ ]
285
+ %>
286
+ ```
287
+
288
+ ### Dagre layout
289
+
290
+ ```yaml preview minHeight="600px"
291
+ - brick: div
292
+ properties:
293
+ style:
294
+ display: flex
295
+ height: 600px
296
+ gap: 1em
297
+ context:
298
+ - name: initialCells
299
+ value: |
300
+ <%
301
+ [
302
+ {
303
+ type: "decorator",
304
+ id: "area-1",
305
+ decorator: "area",
306
+ view: {
307
+ x: 10,
308
+ y: 20,
309
+ width: 400,
310
+ height: 300,
311
+ },
312
+ },
313
+ {
314
+ type: "edge",
315
+ source: "X",
316
+ target: "Y",
317
+ },
318
+ {
319
+ type: "edge",
320
+ source: "X",
321
+ target: "Z",
322
+ data: {
323
+ virtual: true,
324
+ }
325
+ },
326
+ ].concat(
327
+ ["X", "Y", "Z", "W"].map((id) => ({
328
+ type: "node",
329
+ id,
330
+ data: {
331
+ name: `Node ${id}`,
332
+ },
333
+ view: {
334
+ width: 60,
335
+ height: 60,
336
+ }
337
+ }))
338
+ ).concat([
339
+ {
340
+ type: "decorator",
341
+ id: "text-1",
342
+ decorator: "text",
343
+ view: {
344
+ x: 100,
345
+ y: 120,
346
+ width: 100,
347
+ height: 20,
348
+ text: "Hello!"
349
+ },
350
+ },
351
+ ])
352
+ %>
353
+ - name: activeTarget
354
+ - name: targetCell
355
+ children:
356
+ - brick: div
357
+ properties:
358
+ style:
359
+ flex: 1
360
+ minWidth: 0
361
+ children:
362
+ - brick: eo-display-canvas
363
+ properties:
364
+ style:
365
+ width: 100%
366
+ height: 100%
367
+ activeTarget: <%= CTX.activeTarget %>
368
+ fadeUnrelatedCells: true
369
+ layout: dagre
370
+ # Initial nodes only
371
+ defaultNodeSize: [60, 60]
372
+ defaultNodeBricks:
373
+ - useBrick:
374
+ brick: diagram.experimental-node
375
+ properties:
376
+ textContent: <% `Node ${DATA.node.id}` %>
377
+ status: |
378
+ <%=
379
+ CTX.activeTarget?.type === "node" && CTX.activeTarget.id === DATA.node.id
380
+ ? "highlighted"
381
+ // : CTX.unrelated.some(n =>
382
+ // n.type === "node" && n.id === DATA.node.id
383
+ // )
384
+ // ? "faded"
385
+ : "default"
386
+ %>
387
+ defaultEdgeLines:
388
+ - if: <% DATA.edge.data?.virtual %>
389
+ dashed: true
390
+ cells: <% CTX.initialCells %>
391
+ events:
392
+ activeTarget.change:
393
+ action: context.replace
394
+ args:
395
+ - activeTarget
396
+ - <% EVENT.detail %>
397
+ cell.contextmenu:
398
+ - target: eo-context-menu
399
+ method: open
400
+ args:
401
+ - position:
402
+ - <% EVENT.detail.clientX %>
403
+ - <% EVENT.detail.clientY %>
404
+ - action: context.replace
405
+ args:
406
+ - targetCell
407
+ - <% EVENT.detail.cell %>
408
+ scale.change:
409
+ action: context.replace
410
+ args:
411
+ - scale
412
+ - <% EVENT.detail %>
413
+ - brick: eo-context-menu
414
+ properties:
415
+ actions: |
416
+ <%=
417
+ [
418
+ {
419
+ text: `Test ${CTX.targetCell?.type}`,
420
+ event: `test-${CTX.targetCell?.type}`,
421
+ }
422
+ ]
423
+ %>
424
+ ```