@node-projects/web-component-designer-mermaid 0.1.0 → 0.1.1
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/{src/index.ts → dist/index.d.ts} +0 -3
- package/dist/index.js +17 -0
- package/dist/monaco/MermaidLanguage.d.ts +1 -0
- package/{src/monaco/MermaidLanguage.ts → dist/monaco/MermaidLanguage.js} +1 -4
- package/dist/services/MermaidConnectionRouting.d.ts +2 -0
- package/{src/services/MermaidConnectionRouting.ts → dist/services/MermaidConnectionRouting.js} +22 -45
- package/dist/services/MermaidDocumentPropertiesService.d.ts +24 -0
- package/{src/services/MermaidDocumentPropertiesService.ts → dist/services/MermaidDocumentPropertiesService.js} +25 -54
- package/dist/services/MermaidElementsService.d.ts +19 -0
- package/{src/services/MermaidElementsService.ts → dist/services/MermaidElementsService.js} +18 -35
- package/dist/services/MermaidLayoutCopyPasteService.d.ts +5 -0
- package/{src/services/MermaidLayoutCopyPasteService.ts → dist/services/MermaidLayoutCopyPasteService.js} +4 -6
- package/dist/services/MermaidLayoutPlacementService.d.ts +8 -0
- package/{src/services/MermaidLayoutPlacementService.ts → dist/services/MermaidLayoutPlacementService.js} +6 -11
- package/dist/services/MermaidParserService.d.ts +7 -0
- package/{src/services/MermaidParserService.ts → dist/services/MermaidParserService.js} +410 -705
- package/dist/services/MermaidPropertyGroupsService.d.ts +8 -0
- package/{src/services/MermaidPropertyGroupsService.ts → dist/services/MermaidPropertyGroupsService.js} +2 -7
- package/dist/services/mermaidGeometry.d.ts +31 -0
- package/{src/services/mermaidGeometry.ts → dist/services/mermaidGeometry.js} +13 -43
- package/dist/setupMermaidServiceContainer.d.ts +2 -0
- package/{src/setupMermaidServiceContainer.ts → dist/setupMermaidServiceContainer.js} +8 -28
- package/dist/toolbar/ConnectMermaidNodesTool.d.ts +20 -0
- package/{src/toolbar/ConnectMermaidNodesTool.ts → dist/toolbar/ConnectMermaidNodesTool.js} +26 -58
- package/dist/widgets/mermaid-edge.d.ts +45 -0
- package/{src/widgets/mermaid-edge.ts → dist/widgets/mermaid-edge.js} +39 -60
- package/dist/widgets/mermaid-flowchart-directive.d.ts +16 -0
- package/{src/widgets/mermaid-flowchart-directive.ts → dist/widgets/mermaid-flowchart-directive.js} +11 -23
- package/dist/widgets/mermaid-mindmap-node.d.ts +37 -0
- package/{src/widgets/mermaid-mindmap-node.ts → dist/widgets/mermaid-mindmap-node.js} +36 -55
- package/dist/widgets/mermaid-node.d.ts +75 -0
- package/{src/widgets/mermaid-node.ts → dist/widgets/mermaid-node.js} +78 -105
- package/dist/widgets/mermaid-requirement-node.d.ts +37 -0
- package/{src/widgets/mermaid-requirement-node.ts → dist/widgets/mermaid-requirement-node.js} +30 -49
- package/dist/widgets/mermaid-requirement-relationship.d.ts +28 -0
- package/{src/widgets/mermaid-requirement-relationship.ts → dist/widgets/mermaid-requirement-relationship.js} +21 -38
- package/dist/widgets/mermaid-sequence-message.d.ts +34 -0
- package/{src/widgets/mermaid-sequence-message.ts → dist/widgets/mermaid-sequence-message.js} +30 -44
- package/dist/widgets/mermaid-sequence-participant.d.ts +24 -0
- package/{src/widgets/mermaid-sequence-participant.ts → dist/widgets/mermaid-sequence-participant.js} +17 -28
- package/dist/widgets/mermaid-subgraph.d.ts +20 -0
- package/{src/widgets/mermaid-subgraph.ts → dist/widgets/mermaid-subgraph.js} +13 -25
- package/dist/widgets/views/mermaid-demo-view.d.ts +11 -0
- package/{src/widgets/views/mermaid-demo-view.ts → dist/widgets/views/mermaid-demo-view.js} +8 -18
- package/package.json +6 -1
- package/tsconfig.json +0 -20
- /package/{src → dist}/widgets/elements.json +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDesignItem, IPropertiesService } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class MermaidPropertyGroupsService {
|
|
3
|
+
private readonly _documentPropertiesService;
|
|
4
|
+
getPropertygroups(designItems: IDesignItem[]): {
|
|
5
|
+
name: string;
|
|
6
|
+
propertiesService: IPropertiesService;
|
|
7
|
+
}[];
|
|
8
|
+
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { IDesignItem, IPropertiesService } from "@node-projects/web-component-designer";
|
|
2
1
|
import { MermaidDocumentPropertiesService } from "./MermaidDocumentPropertiesService.js";
|
|
3
|
-
|
|
4
2
|
export class MermaidPropertyGroupsService {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getPropertygroups(designItems: IDesignItem[]): { name: string; propertiesService: IPropertiesService; }[] {
|
|
3
|
+
_documentPropertiesService = new MermaidDocumentPropertiesService();
|
|
4
|
+
getPropertygroups(designItems) {
|
|
8
5
|
const designItem = designItems?.[0];
|
|
9
6
|
if (!designItem)
|
|
10
7
|
return [];
|
|
11
|
-
|
|
12
8
|
if (designItem.isRootItem)
|
|
13
9
|
return [{ name: "mermaid", propertiesService: this._documentPropertiesService }];
|
|
14
|
-
|
|
15
10
|
const propertiesService = designItem.serviceContainer.getLastServiceWhere("propertyService", service => service.isHandledElement(designItem));
|
|
16
11
|
return propertiesService ? [{ name: "properties", propertiesService }] : [];
|
|
17
12
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
export type Rect = Point & {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
export type FlowchartDirection = "TB" | "TD" | "BT" | "RL" | "LR";
|
|
10
|
+
export declare function encodeWaypoints(waypoints: Point[]): string;
|
|
11
|
+
export declare function decodeWaypoints(value: string): {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}[];
|
|
15
|
+
export declare function boundsFromWaypoints(waypoints: Point[]): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function pathDataFromWaypoints(waypoints: Point[]): string;
|
|
22
|
+
export declare function midpointFromWaypoints(waypoints: Point[]): Point;
|
|
23
|
+
export declare function routeBetweenBounds(source: Rect, target: Rect, direction?: FlowchartDirection): {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
}[];
|
|
27
|
+
export declare function routeBetweenPoints(source: Point, target: Point): Point[];
|
|
28
|
+
export declare function getAnchor(rect: Rect, target: Point): {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
@@ -1,30 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type Rect = Point & {
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type FlowchartDirection = "TB" | "TD" | "BT" | "RL" | "LR";
|
|
12
|
-
|
|
13
|
-
export function encodeWaypoints(waypoints: Point[]) {
|
|
1
|
+
export function encodeWaypoints(waypoints) {
|
|
14
2
|
return waypoints.map(point => `${Math.round(point.x)},${Math.round(point.y)}`).join(" ");
|
|
15
3
|
}
|
|
16
|
-
|
|
17
|
-
export function decodeWaypoints(value: string) {
|
|
4
|
+
export function decodeWaypoints(value) {
|
|
18
5
|
if (!value)
|
|
19
6
|
return [];
|
|
20
|
-
|
|
21
7
|
return value.split(/\s+/).map(part => {
|
|
22
8
|
const [x, y] = part.split(",").map(Number);
|
|
23
9
|
return { x, y };
|
|
24
10
|
}).filter(point => Number.isFinite(point.x) && Number.isFinite(point.y));
|
|
25
11
|
}
|
|
26
|
-
|
|
27
|
-
export function boundsFromWaypoints(waypoints: Point[]) {
|
|
12
|
+
export function boundsFromWaypoints(waypoints) {
|
|
28
13
|
const xs = waypoints.map(point => point.x);
|
|
29
14
|
const ys = waypoints.map(point => point.y);
|
|
30
15
|
const minX = Math.min(...xs);
|
|
@@ -33,28 +18,23 @@ export function boundsFromWaypoints(waypoints: Point[]) {
|
|
|
33
18
|
const maxY = Math.max(...ys);
|
|
34
19
|
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
export function pathDataFromWaypoints(waypoints: Point[]) {
|
|
21
|
+
export function pathDataFromWaypoints(waypoints) {
|
|
38
22
|
if (!waypoints.length)
|
|
39
23
|
return "";
|
|
40
|
-
|
|
41
24
|
return waypoints.map((point, index) => `${index === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" ");
|
|
42
25
|
}
|
|
43
|
-
|
|
44
|
-
export function midpointFromWaypoints(waypoints: Point[]) {
|
|
26
|
+
export function midpointFromWaypoints(waypoints) {
|
|
45
27
|
if (!waypoints.length)
|
|
46
28
|
return { x: 0, y: 0 };
|
|
47
29
|
if (waypoints.length === 1)
|
|
48
30
|
return waypoints[0];
|
|
49
|
-
|
|
50
|
-
const segmentLengths: number[] = [];
|
|
31
|
+
const segmentLengths = [];
|
|
51
32
|
let totalLength = 0;
|
|
52
33
|
for (let i = 1; i < waypoints.length; i++) {
|
|
53
34
|
const length = distance(waypoints[i - 1], waypoints[i]);
|
|
54
35
|
segmentLengths.push(length);
|
|
55
36
|
totalLength += length;
|
|
56
37
|
}
|
|
57
|
-
|
|
58
38
|
let remaining = totalLength / 2;
|
|
59
39
|
for (let i = 1; i < waypoints.length; i++) {
|
|
60
40
|
const segmentLength = segmentLengths[i - 1];
|
|
@@ -67,11 +47,9 @@ export function midpointFromWaypoints(waypoints: Point[]) {
|
|
|
67
47
|
}
|
|
68
48
|
remaining -= segmentLength;
|
|
69
49
|
}
|
|
70
|
-
|
|
71
50
|
return waypoints[waypoints.length - 1];
|
|
72
51
|
}
|
|
73
|
-
|
|
74
|
-
export function routeBetweenBounds(source: Rect, target: Rect, direction?: FlowchartDirection) {
|
|
52
|
+
export function routeBetweenBounds(source, target, direction) {
|
|
75
53
|
const sourceCenter = center(source);
|
|
76
54
|
const targetCenter = center(target);
|
|
77
55
|
if (direction === "LR" || direction === "RL")
|
|
@@ -80,52 +58,44 @@ export function routeBetweenBounds(source: Rect, target: Rect, direction?: Flowc
|
|
|
80
58
|
return [getVerticalAnchor(source, targetCenter), getVerticalAnchor(target, sourceCenter)];
|
|
81
59
|
return [getAnchor(source, targetCenter), getAnchor(target, sourceCenter)];
|
|
82
60
|
}
|
|
83
|
-
|
|
84
|
-
export function routeBetweenPoints(source: Point, target: Point) {
|
|
61
|
+
export function routeBetweenPoints(source, target) {
|
|
85
62
|
return [source, target];
|
|
86
63
|
}
|
|
87
|
-
|
|
88
|
-
export function getAnchor(rect: Rect, target: Point) {
|
|
64
|
+
export function getAnchor(rect, target) {
|
|
89
65
|
const c = center(rect);
|
|
90
66
|
const dx = target.x - c.x;
|
|
91
67
|
const dy = target.y - c.y;
|
|
92
|
-
|
|
93
68
|
if (Math.abs(dx / rect.width) > Math.abs(dy / rect.height)) {
|
|
94
69
|
return {
|
|
95
70
|
x: dx >= 0 ? rect.x + rect.width : rect.x,
|
|
96
71
|
y: c.y,
|
|
97
72
|
};
|
|
98
73
|
}
|
|
99
|
-
|
|
100
74
|
return {
|
|
101
75
|
x: c.x,
|
|
102
76
|
y: dy >= 0 ? rect.y + rect.height : rect.y,
|
|
103
77
|
};
|
|
104
78
|
}
|
|
105
|
-
|
|
106
|
-
function center(rect: Rect) {
|
|
79
|
+
function center(rect) {
|
|
107
80
|
return {
|
|
108
81
|
x: rect.x + rect.width / 2,
|
|
109
82
|
y: rect.y + rect.height / 2,
|
|
110
83
|
};
|
|
111
84
|
}
|
|
112
|
-
|
|
113
|
-
function getHorizontalAnchor(rect: Rect, target: Point) {
|
|
85
|
+
function getHorizontalAnchor(rect, target) {
|
|
114
86
|
const c = center(rect);
|
|
115
87
|
return {
|
|
116
88
|
x: target.x >= c.x ? rect.x + rect.width : rect.x,
|
|
117
89
|
y: c.y,
|
|
118
90
|
};
|
|
119
91
|
}
|
|
120
|
-
|
|
121
|
-
function getVerticalAnchor(rect: Rect, target: Point) {
|
|
92
|
+
function getVerticalAnchor(rect, target) {
|
|
122
93
|
const c = center(rect);
|
|
123
94
|
return {
|
|
124
95
|
x: c.x,
|
|
125
96
|
y: target.y >= c.y ? rect.y + rect.height : rect.y,
|
|
126
97
|
};
|
|
127
98
|
}
|
|
128
|
-
|
|
129
|
-
function distance(a: Point, b: Point) {
|
|
99
|
+
function distance(a, b) {
|
|
130
100
|
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
131
101
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbsolutePlacementService, AltToEnterContainerExtensionProvider, BaseCustomWebComponentPropertiesService, CopyPasteContextMenu, DefaultEditorTypeService, DefaultHtmlParserService, DefaultInstanceService, DefaultModelCommandService, DefaultPropertyEditorTypesService, DeletionService, DesignItemDocumentPositionService, DesignItemService, DragDropService, ElementAtPointService, ElementDragTitleExtensionProvider, ExtensionType, GrayOutDragOverContainerExtensionProvider, GrayOutExtensionProvider, HighlightElementExtensionProvider,
|
|
1
|
+
import { AbsolutePlacementService, AltToEnterContainerExtensionProvider, BaseCustomWebComponentPropertiesService, CopyPasteContextMenu, DefaultEditorTypeService, DefaultHtmlParserService, DefaultInstanceService, DefaultModelCommandService, DefaultPropertyEditorTypesService, DeletionService, DesignItemDocumentPositionService, DesignItemService, DragDropService, ElementAtPointService, ElementDragTitleExtensionProvider, ExtensionType, GrayOutDragOverContainerExtensionProvider, GrayOutExtensionProvider, HighlightElementExtensionProvider, ItemsBelowContextMenu, MagicWandSelectorTool, MultipleItemsSelectedContextMenu, NamedTools, PanTool, PointerTool, PointerToolButtonProvider, PositionExtensionProvider, RectangleSelectorTool, ResizeExtensionProvider, SelectionDefaultExtensionProvider, SelectionService, SelectorToolButtonProvider, SeperatorToolProvider, ServiceContainer, SimpleToolButtonProvider, SnaplinesProviderService, TransformToolButtonProvider, UndoService, ZMoveContextMenu, ZoomTool, ZoomToolButtonProvider } from "@node-projects/web-component-designer";
|
|
2
2
|
import { MermaidLayoutCopyPasteService } from "./services/MermaidLayoutCopyPasteService.js";
|
|
3
3
|
import { MermaidLayoutPlacementService } from "./services/MermaidLayoutPlacementService.js";
|
|
4
4
|
import { MermaidParserService } from "./services/MermaidParserService.js";
|
|
@@ -7,12 +7,10 @@ import { ConnectMermaidNodesTool, mermaidFlowIcon } from "./toolbar/ConnectMerma
|
|
|
7
7
|
import { MermaidDemoView } from "./widgets/views/mermaid-demo-view.js";
|
|
8
8
|
import { MermaidPropertyGroupsService } from "./services/MermaidPropertyGroupsService.js";
|
|
9
9
|
import { MermaidElementsService } from "./services/MermaidElementsService.js";
|
|
10
|
-
|
|
11
10
|
export function createMermaidDesignerServiceContainer() {
|
|
12
11
|
const serviceContainer = new ServiceContainer();
|
|
13
12
|
const parserService = new MermaidParserService();
|
|
14
13
|
const elementsService = new MermaidElementsService("mermaid", new URL("./widgets/elements.json", import.meta.url));
|
|
15
|
-
|
|
16
14
|
serviceContainer.register("instanceService", new DefaultInstanceService());
|
|
17
15
|
serviceContainer.register("containerService", new AbsolutePlacementService());
|
|
18
16
|
serviceContainer.register("containerService", new MermaidLayoutPlacementService());
|
|
@@ -30,11 +28,9 @@ export function createMermaidDesignerServiceContainer() {
|
|
|
30
28
|
serviceContainer.register("propertyService", new BaseCustomWebComponentPropertiesService(true));
|
|
31
29
|
serviceContainer.register("designItemService", new DesignItemService());
|
|
32
30
|
serviceContainer.register("deletionService", new DeletionService());
|
|
33
|
-
|
|
34
|
-
serviceContainer.register("
|
|
35
|
-
serviceContainer.register("
|
|
36
|
-
serviceContainer.register("designItemDocumentPositionService", (designerCanvas: IDesignerCanvas) => new DesignItemDocumentPositionService(designerCanvas));
|
|
37
|
-
|
|
31
|
+
serviceContainer.register("undoService", (designerCanvas) => new UndoService(designerCanvas));
|
|
32
|
+
serviceContainer.register("selectionService", (designerCanvas) => new SelectionService(designerCanvas, false));
|
|
33
|
+
serviceContainer.register("designItemDocumentPositionService", (designerCanvas) => new DesignItemDocumentPositionService(designerCanvas));
|
|
38
34
|
serviceContainer.instanceServiceContainerCreatedCallbacks.push(instanceServiceContainer => {
|
|
39
35
|
const designerCanvas = instanceServiceContainer.designerCanvas;
|
|
40
36
|
elementsService.setInstanceServiceContainer(instanceServiceContainer);
|
|
@@ -46,25 +42,24 @@ export function createMermaidDesignerServiceContainer() {
|
|
|
46
42
|
rerouteConnectedMermaidEdges(instanceServiceContainer, designItems, operationFinished);
|
|
47
43
|
};
|
|
48
44
|
});
|
|
49
|
-
|
|
50
45
|
serviceContainer.designerExtensions.set(ExtensionType.Permanent, []);
|
|
51
46
|
serviceContainer.designerExtensions.set(ExtensionType.PrimarySelection, [
|
|
52
47
|
new class extends ElementDragTitleExtensionProvider {
|
|
53
|
-
|
|
48
|
+
shouldExtend(extensionManager, designerView, designItem) {
|
|
54
49
|
if (designItem.element?.localName === "mermaid-edge")
|
|
55
50
|
return false;
|
|
56
51
|
return super.shouldExtend(extensionManager, designerView, designItem);
|
|
57
52
|
}
|
|
58
53
|
}(),
|
|
59
54
|
new class extends PositionExtensionProvider {
|
|
60
|
-
|
|
55
|
+
shouldExtend(extensionManager, designerView, designItem) {
|
|
61
56
|
if (designItem.element?.localName === "mermaid-edge")
|
|
62
57
|
return false;
|
|
63
58
|
return super.shouldExtend(extensionManager, designerView, designItem);
|
|
64
59
|
}
|
|
65
60
|
}(),
|
|
66
61
|
new class extends ResizeExtensionProvider {
|
|
67
|
-
|
|
62
|
+
shouldExtend(extensionManager, designerView, designItem) {
|
|
68
63
|
if (designItem.element?.localName === "mermaid-edge")
|
|
69
64
|
return false;
|
|
70
65
|
return super.shouldExtend(extensionManager, designerView, designItem);
|
|
@@ -88,7 +83,6 @@ export function createMermaidDesignerServiceContainer() {
|
|
|
88
83
|
serviceContainer.designerExtensions.set(ExtensionType.ContainerExternalDragOverAndCanBeEntered, [
|
|
89
84
|
new GrayOutDragOverContainerExtensionProvider(),
|
|
90
85
|
]);
|
|
91
|
-
|
|
92
86
|
serviceContainer.designerTools.set(NamedTools.Pointer, new PointerTool());
|
|
93
87
|
serviceContainer.designerTools.set(NamedTools.DrawSelection, new RectangleSelectorTool());
|
|
94
88
|
serviceContainer.designerTools.set(NamedTools.Zoom, new ZoomTool());
|
|
@@ -96,28 +90,14 @@ export function createMermaidDesignerServiceContainer() {
|
|
|
96
90
|
serviceContainer.designerTools.set(NamedTools.RectangleSelector, new RectangleSelectorTool());
|
|
97
91
|
serviceContainer.designerTools.set(NamedTools.MagicWandSelector, new MagicWandSelectorTool());
|
|
98
92
|
serviceContainer.designerTools.set("MermaidFlow", new ConnectMermaidNodesTool());
|
|
99
|
-
|
|
100
93
|
serviceContainer.designerContextMenuExtensions = [
|
|
101
94
|
new CopyPasteContextMenu(),
|
|
102
95
|
new ZMoveContextMenu(),
|
|
103
96
|
new MultipleItemsSelectedContextMenu(),
|
|
104
97
|
new ItemsBelowContextMenu()
|
|
105
98
|
];
|
|
106
|
-
|
|
107
|
-
serviceContainer.designViewToolbarButtons.push(
|
|
108
|
-
new PointerToolButtonProvider(),
|
|
109
|
-
new SeperatorToolProvider(22),
|
|
110
|
-
new SelectorToolButtonProvider(),
|
|
111
|
-
new SeperatorToolProvider(22),
|
|
112
|
-
new SimpleToolButtonProvider("MermaidFlow", mermaidFlowIcon),
|
|
113
|
-
new SeperatorToolProvider(22),
|
|
114
|
-
new ZoomToolButtonProvider(),
|
|
115
|
-
new SeperatorToolProvider(22),
|
|
116
|
-
new TransformToolButtonProvider()
|
|
117
|
-
);
|
|
118
|
-
|
|
99
|
+
serviceContainer.designViewToolbarButtons.push(new PointerToolButtonProvider(), new SeperatorToolProvider(22), new SelectorToolButtonProvider(), new SeperatorToolProvider(22), new SimpleToolButtonProvider("MermaidFlow", mermaidFlowIcon), new SeperatorToolProvider(22), new ZoomToolButtonProvider(), new SeperatorToolProvider(22), new TransformToolButtonProvider());
|
|
119
100
|
serviceContainer.config.demoViewWidget = MermaidDemoView;
|
|
120
101
|
serviceContainer.register("elementsService", elementsService);
|
|
121
|
-
|
|
122
102
|
return serviceContainer;
|
|
123
103
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDesignerCanvas, ITool, ServiceContainer } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare const mermaidFlowIcon: string;
|
|
3
|
+
export declare class ConnectMermaidNodesTool implements ITool {
|
|
4
|
+
readonly cursor = "crosshair";
|
|
5
|
+
private _captureElement?;
|
|
6
|
+
private _pointerId?;
|
|
7
|
+
private _previewPath?;
|
|
8
|
+
private _sourceElement?;
|
|
9
|
+
private _sourceBounds?;
|
|
10
|
+
activated(_serviceContainer: ServiceContainer): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
13
|
+
keyboardEventHandler(designerCanvas: IDesignerCanvas, event: KeyboardEvent): void;
|
|
14
|
+
private _begin;
|
|
15
|
+
private _update;
|
|
16
|
+
private _finish;
|
|
17
|
+
private _cleanup;
|
|
18
|
+
private _getDirection;
|
|
19
|
+
private _getRelationshipTag;
|
|
20
|
+
}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
import { DesignItem, EventNames,
|
|
2
|
-
import { encodeWaypoints,
|
|
1
|
+
import { DesignItem, EventNames, InsertAction, OverlayLayer } from "@node-projects/web-component-designer";
|
|
2
|
+
import { encodeWaypoints, getAnchor, routeBetweenBounds, routeBetweenPoints, pathDataFromWaypoints } from "../services/mermaidGeometry.js";
|
|
3
3
|
import { MermaidNode } from "../widgets/mermaid-node.js";
|
|
4
4
|
import { MermaidRequirementNode } from "../widgets/mermaid-requirement-node.js";
|
|
5
5
|
import { getMermaidDocumentDiagramType } from "../services/MermaidDocumentPropertiesService.js";
|
|
6
|
-
|
|
7
|
-
function createIcon(markup: string) {
|
|
6
|
+
function createIcon(markup) {
|
|
8
7
|
return `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${markup}</svg>`)}`;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
function findNode(event: PointerEvent, currentElement: Element | null | undefined) {
|
|
9
|
+
function findNode(event, currentElement) {
|
|
12
10
|
if (currentElement instanceof HTMLElement && isConnectableNode(currentElement))
|
|
13
11
|
return currentElement;
|
|
14
|
-
|
|
15
12
|
for (const part of event.composedPath()) {
|
|
16
13
|
if (part instanceof HTMLElement && isConnectableNode(part))
|
|
17
14
|
return part;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
return null;
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
function isConnectableNode(element: HTMLElement) {
|
|
18
|
+
function isConnectableNode(element) {
|
|
24
19
|
return element.localName === MermaidNode.is || element.localName === MermaidRequirementNode.is;
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
function getElementBounds(designerCanvas: IDesignerCanvas, element: HTMLElement): Rect {
|
|
21
|
+
function getElementBounds(designerCanvas, element) {
|
|
28
22
|
const canvasRect = designerCanvas.canvas.getBoundingClientRect();
|
|
29
23
|
const elementRect = element.getBoundingClientRect();
|
|
30
24
|
const zoom = designerCanvas.zoomFactor ?? 1;
|
|
31
|
-
|
|
32
25
|
return {
|
|
33
26
|
x: (elementRect.left - canvasRect.left) / zoom,
|
|
34
27
|
y: (elementRect.top - canvasRect.top) / zoom,
|
|
@@ -36,8 +29,7 @@ function getElementBounds(designerCanvas: IDesignerCanvas, element: HTMLElement)
|
|
|
36
29
|
height: elementRect.height / zoom,
|
|
37
30
|
};
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
function getNodeId(element: HTMLElement) {
|
|
32
|
+
function getNodeId(element) {
|
|
41
33
|
if (element.localName === MermaidRequirementNode.is) {
|
|
42
34
|
let id = element.getAttribute("label");
|
|
43
35
|
if (!id) {
|
|
@@ -46,7 +38,6 @@ function getNodeId(element: HTMLElement) {
|
|
|
46
38
|
}
|
|
47
39
|
return id;
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
let id = element.getAttribute("node-id");
|
|
51
42
|
if (!id) {
|
|
52
43
|
id = `Node_${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -54,25 +45,19 @@ function getNodeId(element: HTMLElement) {
|
|
|
54
45
|
}
|
|
55
46
|
return id;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
export const mermaidFlowIcon = createIcon('<path d="M4 12h12"/><path d="M12 8l4 4-4 4"/>');
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
private _sourceBounds?: Rect;
|
|
68
|
-
|
|
69
|
-
activated(_serviceContainer: ServiceContainer) {
|
|
49
|
+
export class ConnectMermaidNodesTool {
|
|
50
|
+
cursor = "crosshair";
|
|
51
|
+
_captureElement;
|
|
52
|
+
_pointerId;
|
|
53
|
+
_previewPath;
|
|
54
|
+
_sourceElement;
|
|
55
|
+
_sourceBounds;
|
|
56
|
+
activated(_serviceContainer) {
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
dispose() {
|
|
73
59
|
}
|
|
74
|
-
|
|
75
|
-
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element) {
|
|
60
|
+
pointerEventHandler(designerCanvas, event, currentElement) {
|
|
76
61
|
switch (event.type) {
|
|
77
62
|
case EventNames.PointerDown:
|
|
78
63
|
this._begin(designerCanvas, event, currentElement);
|
|
@@ -85,24 +70,20 @@ export class ConnectMermaidNodesTool implements ITool {
|
|
|
85
70
|
break;
|
|
86
71
|
}
|
|
87
72
|
}
|
|
88
|
-
|
|
89
|
-
keyboardEventHandler(designerCanvas: IDesignerCanvas, event: KeyboardEvent) {
|
|
73
|
+
keyboardEventHandler(designerCanvas, event) {
|
|
90
74
|
if (event.key === "Escape")
|
|
91
75
|
this._cleanup(designerCanvas, true);
|
|
92
76
|
}
|
|
93
|
-
|
|
94
|
-
private _begin(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element) {
|
|
77
|
+
_begin(designerCanvas, event, currentElement) {
|
|
95
78
|
const source = findNode(event, currentElement);
|
|
96
79
|
if (!source)
|
|
97
80
|
return;
|
|
98
|
-
|
|
99
81
|
this._sourceElement = source;
|
|
100
82
|
this._sourceBounds = getElementBounds(designerCanvas, source);
|
|
101
|
-
this._captureElement = event.target
|
|
83
|
+
this._captureElement = event.target;
|
|
102
84
|
this._pointerId = event.pointerId;
|
|
103
85
|
this._captureElement?.setPointerCapture?.(this._pointerId);
|
|
104
86
|
designerCanvas.captureActiveTool(this);
|
|
105
|
-
|
|
106
87
|
this._previewPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
107
88
|
this._previewPath.setAttribute("fill", "none");
|
|
108
89
|
this._previewPath.setAttribute("stroke", "#333");
|
|
@@ -112,27 +93,22 @@ export class ConnectMermaidNodesTool implements ITool {
|
|
|
112
93
|
event.preventDefault();
|
|
113
94
|
event.stopPropagation();
|
|
114
95
|
}
|
|
115
|
-
|
|
116
|
-
private _update(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element) {
|
|
96
|
+
_update(designerCanvas, event, currentElement) {
|
|
117
97
|
if (!this._sourceBounds || !this._previewPath)
|
|
118
98
|
return;
|
|
119
|
-
|
|
120
99
|
const pointer = designerCanvas.getNormalizedEventCoordinates(event);
|
|
121
100
|
const target = findNode(event, currentElement);
|
|
122
101
|
const direction = this._getDirection();
|
|
123
102
|
const waypoints = target && target !== this._sourceElement
|
|
124
103
|
? routeBetweenBounds(this._sourceBounds, getElementBounds(designerCanvas, target), direction)
|
|
125
104
|
: routeBetweenPoints(getAnchor(this._sourceBounds, pointer), pointer);
|
|
126
|
-
|
|
127
105
|
this._previewPath.setAttribute("d", pathDataFromWaypoints(waypoints));
|
|
128
106
|
event.preventDefault();
|
|
129
107
|
event.stopPropagation();
|
|
130
108
|
}
|
|
131
|
-
|
|
132
|
-
private _finish(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element) {
|
|
109
|
+
_finish(designerCanvas, event, currentElement) {
|
|
133
110
|
if (!this._sourceElement || !this._sourceBounds)
|
|
134
111
|
return;
|
|
135
|
-
|
|
136
112
|
const target = findNode(event, currentElement);
|
|
137
113
|
if (!target || target === this._sourceElement) {
|
|
138
114
|
this._cleanup(designerCanvas, true);
|
|
@@ -140,10 +116,9 @@ export class ConnectMermaidNodesTool implements ITool {
|
|
|
140
116
|
event.stopPropagation();
|
|
141
117
|
return;
|
|
142
118
|
}
|
|
143
|
-
|
|
144
119
|
const direction = this._getDirection(target);
|
|
145
120
|
const waypoints = routeBetweenBounds(this._sourceBounds, getElementBounds(designerCanvas, target), direction);
|
|
146
|
-
const edge = document.createElement(this._getRelationshipTag(designerCanvas))
|
|
121
|
+
const edge = document.createElement(this._getRelationshipTag(designerCanvas));
|
|
147
122
|
edge.style.position = "absolute";
|
|
148
123
|
edge.style.zIndex = "4";
|
|
149
124
|
edge.setAttribute("from", getNodeId(this._sourceElement));
|
|
@@ -155,24 +130,19 @@ export class ConnectMermaidNodesTool implements ITool {
|
|
|
155
130
|
if (direction && edge.localName === "mermaid-edge")
|
|
156
131
|
edge.setAttribute("diagram-direction", direction);
|
|
157
132
|
edge.setAttribute("waypoints", encodeWaypoints(waypoints));
|
|
158
|
-
|
|
159
133
|
const designItem = DesignItem.createDesignItemFromInstance(edge, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
|
|
160
|
-
designerCanvas.instanceServiceContainer.undoService.execute(
|
|
161
|
-
new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, designItem)
|
|
162
|
-
);
|
|
134
|
+
designerCanvas.instanceServiceContainer.undoService.execute(new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, designItem));
|
|
163
135
|
this._cleanup(designerCanvas, true);
|
|
164
136
|
event.preventDefault();
|
|
165
137
|
event.stopPropagation();
|
|
166
138
|
}
|
|
167
|
-
|
|
168
|
-
private _cleanup(designerCanvas: IDesignerCanvas, finished: boolean) {
|
|
139
|
+
_cleanup(designerCanvas, finished) {
|
|
169
140
|
if (this._previewPath) {
|
|
170
141
|
designerCanvas.overlayLayer.removeOverlay(this._previewPath);
|
|
171
142
|
this._previewPath = undefined;
|
|
172
143
|
}
|
|
173
144
|
if (this._captureElement && this._pointerId !== undefined)
|
|
174
145
|
this._captureElement.releasePointerCapture?.(this._pointerId);
|
|
175
|
-
|
|
176
146
|
this._captureElement = undefined;
|
|
177
147
|
this._pointerId = undefined;
|
|
178
148
|
this._sourceElement = undefined;
|
|
@@ -181,15 +151,13 @@ export class ConnectMermaidNodesTool implements ITool {
|
|
|
181
151
|
if (finished)
|
|
182
152
|
designerCanvas.serviceContainer.globalContext.finishedWithTool(this);
|
|
183
153
|
}
|
|
184
|
-
|
|
185
|
-
private _getDirection(target?: HTMLElement): FlowchartDirection {
|
|
154
|
+
_getDirection(target) {
|
|
186
155
|
const direction = this._sourceElement?.getAttribute("diagram-direction") ?? target?.getAttribute("diagram-direction");
|
|
187
156
|
if (direction === "TB" || direction === "TD" || direction === "BT" || direction === "RL" || direction === "LR")
|
|
188
157
|
return direction;
|
|
189
158
|
return undefined;
|
|
190
159
|
}
|
|
191
|
-
|
|
192
|
-
private _getRelationshipTag(designerCanvas: IDesignerCanvas) {
|
|
160
|
+
_getRelationshipTag(designerCanvas) {
|
|
193
161
|
return getMermaidDocumentDiagramType(designerCanvas.rootDesignItem) === "requirementDiagram"
|
|
194
162
|
? "mermaid-requirement-relationship"
|
|
195
163
|
: "mermaid-edge";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
declare enum MermaidEdgeType {
|
|
3
|
+
arrow = "arrow",
|
|
4
|
+
open = "open",
|
|
5
|
+
dotted = "dotted",
|
|
6
|
+
thick = "thick",
|
|
7
|
+
invisible = "invisible",
|
|
8
|
+
circle = "circle",
|
|
9
|
+
cross = "cross",
|
|
10
|
+
multi = "multi"
|
|
11
|
+
}
|
|
12
|
+
export declare class MermaidEdge extends BaseCustomWebComponentConstructorAppend {
|
|
13
|
+
static readonly style: CSSStyleSheet;
|
|
14
|
+
static readonly template: HTMLTemplateElement;
|
|
15
|
+
static readonly is = "mermaid-edge";
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
label: string;
|
|
19
|
+
edgeType: MermaidEdgeType;
|
|
20
|
+
connector: string;
|
|
21
|
+
edgeId: string;
|
|
22
|
+
animation: string;
|
|
23
|
+
waypoints: string;
|
|
24
|
+
private _previewWaypoints;
|
|
25
|
+
private _label;
|
|
26
|
+
private _path;
|
|
27
|
+
private _svg;
|
|
28
|
+
static readonly properties: {
|
|
29
|
+
from: StringConstructor;
|
|
30
|
+
to: StringConstructor;
|
|
31
|
+
label: StringConstructor;
|
|
32
|
+
edgeType: typeof MermaidEdgeType;
|
|
33
|
+
connector: StringConstructor;
|
|
34
|
+
edgeId: StringConstructor;
|
|
35
|
+
animation: StringConstructor;
|
|
36
|
+
waypoints: StringConstructor;
|
|
37
|
+
};
|
|
38
|
+
constructor();
|
|
39
|
+
ready(): Promise<void>;
|
|
40
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
41
|
+
setPreviewWaypoints(waypoints: string | null): void;
|
|
42
|
+
private _render;
|
|
43
|
+
createMermaid(): string;
|
|
44
|
+
}
|
|
45
|
+
export {};
|