@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
|
@@ -7,14 +7,11 @@ export * from "./widgets/mermaid-requirement-node.js";
|
|
|
7
7
|
export * from "./widgets/mermaid-requirement-relationship.js";
|
|
8
8
|
export * from "./widgets/mermaid-subgraph.js";
|
|
9
9
|
export * from "./widgets/mermaid-flowchart-directive.js";
|
|
10
|
-
|
|
11
10
|
export * from "./monaco/MermaidLanguage.js";
|
|
12
|
-
|
|
13
11
|
export * from "./services/MermaidLayoutCopyPasteService.js";
|
|
14
12
|
export * from "./services/MermaidLayoutPlacementService.js";
|
|
15
13
|
export * from "./services/MermaidParserService.js";
|
|
16
14
|
export * from "./services/MermaidConnectionRouting.js";
|
|
17
15
|
export * from "./services/MermaidElementsService.js";
|
|
18
16
|
export * from "./toolbar/ConnectMermaidNodesTool.js";
|
|
19
|
-
|
|
20
17
|
export * from "./setupMermaidServiceContainer.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./widgets/mermaid-node.js";
|
|
2
|
+
export * from "./widgets/mermaid-edge.js";
|
|
3
|
+
export * from "./widgets/mermaid-sequence-message.js";
|
|
4
|
+
export * from "./widgets/mermaid-sequence-participant.js";
|
|
5
|
+
export * from "./widgets/mermaid-mindmap-node.js";
|
|
6
|
+
export * from "./widgets/mermaid-requirement-node.js";
|
|
7
|
+
export * from "./widgets/mermaid-requirement-relationship.js";
|
|
8
|
+
export * from "./widgets/mermaid-subgraph.js";
|
|
9
|
+
export * from "./widgets/mermaid-flowchart-directive.js";
|
|
10
|
+
export * from "./monaco/MermaidLanguage.js";
|
|
11
|
+
export * from "./services/MermaidLayoutCopyPasteService.js";
|
|
12
|
+
export * from "./services/MermaidLayoutPlacementService.js";
|
|
13
|
+
export * from "./services/MermaidParserService.js";
|
|
14
|
+
export * from "./services/MermaidConnectionRouting.js";
|
|
15
|
+
export * from "./services/MermaidElementsService.js";
|
|
16
|
+
export * from "./toolbar/ConnectMermaidNodesTool.js";
|
|
17
|
+
export * from "./setupMermaidServiceContainer.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addMermaidLanguageToMonaco(monaco?: any): void;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export function addMermaidLanguageToMonaco(monaco
|
|
1
|
+
export function addMermaidLanguageToMonaco(monaco) {
|
|
2
2
|
if (!monaco)
|
|
3
3
|
//@ts-ignore
|
|
4
4
|
monaco = window.monaco;
|
|
5
|
-
|
|
6
5
|
monaco.languages.register({ id: "mermaidLanguage" });
|
|
7
|
-
|
|
8
6
|
monaco.languages.setMonarchTokensProvider("mermaidLanguage", {
|
|
9
7
|
tokenizer: {
|
|
10
8
|
root: [
|
|
@@ -16,7 +14,6 @@ export function addMermaidLanguageToMonaco(monaco?: any) {
|
|
|
16
14
|
],
|
|
17
15
|
},
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
monaco.editor.defineTheme("mermaidTheme", {
|
|
21
18
|
base: "vs",
|
|
22
19
|
inherit: false,
|
package/{src/services/MermaidConnectionRouting.ts → dist/services/MermaidConnectionRouting.js}
RENAMED
|
@@ -1,90 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function isEdgeItem(designItem: IDesignItem) {
|
|
1
|
+
import { encodeWaypoints, routeBetweenBounds } from "./mermaidGeometry.js";
|
|
2
|
+
function isEdgeItem(designItem) {
|
|
5
3
|
return designItem.element.localName === "mermaid-edge" || designItem.element.localName === "mermaid-requirement-relationship";
|
|
6
4
|
}
|
|
7
|
-
|
|
8
|
-
function isNodeItem(designItem: IDesignItem) {
|
|
5
|
+
function isNodeItem(designItem) {
|
|
9
6
|
return designItem.element.localName === "mermaid-node" || designItem.element.localName === "mermaid-requirement-node";
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
function getNodeId(designItem: IDesignItem) {
|
|
8
|
+
function getNodeId(designItem) {
|
|
13
9
|
if (designItem.element.localName === "mermaid-requirement-node")
|
|
14
10
|
return designItem.element.getAttribute("label");
|
|
15
11
|
return designItem.element.getAttribute("node-id");
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const allItems: IDesignItem[] = [];
|
|
13
|
+
function collectCanvasDesignItems(rootDesignItem) {
|
|
14
|
+
const allItems = [];
|
|
20
15
|
const stack = Array.from(rootDesignItem.children());
|
|
21
|
-
|
|
22
16
|
while (stack.length) {
|
|
23
|
-
const item = stack.pop()
|
|
17
|
+
const item = stack.pop();
|
|
24
18
|
allItems.push(item);
|
|
25
19
|
stack.push(...item.children());
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
return allItems;
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.map(item => [getNodeId(item), item] as const)
|
|
36
|
-
.filter((entry): entry is [string, IDesignItem] => !!entry[0])
|
|
37
|
-
);
|
|
23
|
+
function createNodeItemsById(rootItems) {
|
|
24
|
+
return new Map(rootItems
|
|
25
|
+
.filter(isNodeItem)
|
|
26
|
+
.map(item => [getNodeId(item), item])
|
|
27
|
+
.filter((entry) => !!entry[0]));
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.map(getNodeId)
|
|
45
|
-
.filter((id): id is string => !!id)
|
|
46
|
-
);
|
|
47
|
-
|
|
29
|
+
export function rerouteConnectedMermaidEdges(instanceServiceContainer, changedItems, operationFinished) {
|
|
30
|
+
const changedNodeIds = new Set(changedItems
|
|
31
|
+
.filter(isNodeItem)
|
|
32
|
+
.map(getNodeId)
|
|
33
|
+
.filter((id) => !!id));
|
|
48
34
|
if (!changedNodeIds.size)
|
|
49
35
|
return;
|
|
50
|
-
|
|
51
36
|
const designerCanvas = instanceServiceContainer.designerCanvas;
|
|
52
37
|
const rootItems = collectCanvasDesignItems(designerCanvas.rootDesignItem);
|
|
53
38
|
const nodeItemsById = createNodeItemsById(rootItems);
|
|
54
39
|
const affectedEdges = rootItems.filter(item => {
|
|
55
40
|
if (!isEdgeItem(item))
|
|
56
41
|
return false;
|
|
57
|
-
|
|
58
42
|
const from = item.element.getAttribute("from");
|
|
59
43
|
const to = item.element.getAttribute("to");
|
|
60
44
|
return !!from && !!to && (changedNodeIds.has(from) || changedNodeIds.has(to));
|
|
61
45
|
});
|
|
62
|
-
|
|
63
46
|
for (const edgeItem of affectedEdges) {
|
|
64
47
|
const sourceItem = nodeItemsById.get(edgeItem.element.getAttribute("from"));
|
|
65
48
|
const targetItem = nodeItemsById.get(edgeItem.element.getAttribute("to"));
|
|
66
49
|
if (!sourceItem || !targetItem)
|
|
67
50
|
continue;
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
designerCanvas.getNormalizedElementCoordinates(sourceItem.element),
|
|
71
|
-
designerCanvas.getNormalizedElementCoordinates(targetItem.element),
|
|
72
|
-
getDiagramDirection(edgeItem)
|
|
73
|
-
));
|
|
74
|
-
const edgeElement = edgeItem.element as HTMLElement & { setPreviewWaypoints?: (waypoints: string | null) => void };
|
|
75
|
-
|
|
51
|
+
const waypoints = encodeWaypoints(routeBetweenBounds(designerCanvas.getNormalizedElementCoordinates(sourceItem.element), designerCanvas.getNormalizedElementCoordinates(targetItem.element), getDiagramDirection(edgeItem)));
|
|
52
|
+
const edgeElement = edgeItem.element;
|
|
76
53
|
if (operationFinished) {
|
|
77
54
|
edgeElement.setPreviewWaypoints?.(waypoints);
|
|
78
55
|
if (edgeItem.getAttribute("waypoints") !== waypoints)
|
|
79
56
|
edgeItem.setAttribute("waypoints", waypoints);
|
|
80
57
|
queueMicrotask(() => edgeElement.setPreviewWaypoints?.(null));
|
|
81
|
-
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
82
60
|
edgeElement.setPreviewWaypoints?.(waypoints);
|
|
83
61
|
}
|
|
84
62
|
}
|
|
85
63
|
}
|
|
86
|
-
|
|
87
|
-
function getDiagramDirection(designItem: IDesignItem): FlowchartDirection {
|
|
64
|
+
function getDiagramDirection(designItem) {
|
|
88
65
|
const direction = designItem.element.getAttribute("diagram-direction");
|
|
89
66
|
if (direction === "TB" || direction === "TD" || direction === "BT" || direction === "RL" || direction === "LR")
|
|
90
67
|
return direction;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractPropertiesService, BindingTarget, IDesignItem, IProperty, RefreshMode, ValueType } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare const mermaidDiagramTypeAttribute = "data-mermaid-diagram-type";
|
|
3
|
+
export declare const mermaidFlowchartDirectionAttribute = "data-mermaid-flowchart-direction";
|
|
4
|
+
export declare const mermaidTitleAttribute = "data-mermaid-title";
|
|
5
|
+
export declare const mermaidFrontmatterAttribute = "data-mermaid-frontmatter";
|
|
6
|
+
export type MermaidDocumentDiagramType = "flowchart" | "sequenceDiagram" | "mindmap" | "requirementDiagram";
|
|
7
|
+
export declare class MermaidDocumentPropertiesService extends AbstractPropertiesService {
|
|
8
|
+
private readonly _diagramTypeProperty;
|
|
9
|
+
private readonly _flowchartDirectionProperty;
|
|
10
|
+
private readonly _requirementDirectionProperty;
|
|
11
|
+
private readonly _titleProperty;
|
|
12
|
+
getRefreshMode(): RefreshMode;
|
|
13
|
+
isHandledElement(designItem: IDesignItem): boolean;
|
|
14
|
+
getProperties(designItem: IDesignItem): Promise<IProperty[]>;
|
|
15
|
+
getProperty(designItem: IDesignItem, name: string): Promise<IProperty>;
|
|
16
|
+
setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void>;
|
|
17
|
+
getPropertyTarget(): BindingTarget;
|
|
18
|
+
getValue(designItems: IDesignItem[], property: IProperty): any;
|
|
19
|
+
isSet(designItems: IDesignItem[], property: IProperty): ValueType;
|
|
20
|
+
}
|
|
21
|
+
export declare function getMermaidDocumentDiagramType(rootDesignItem: IDesignItem): MermaidDocumentDiagramType;
|
|
22
|
+
export declare function getMermaidDocumentFlowchartDirection(rootDesignItem: IDesignItem): string;
|
|
23
|
+
export declare function getMermaidDocumentTitle(rootDesignItem: IDesignItem): string;
|
|
24
|
+
export declare function getMermaidDocumentFrontmatter(rootDesignItem: IDesignItem): string;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { AbstractPropertiesService, BindingTarget,
|
|
1
|
+
import { AbstractPropertiesService, BindingTarget, PropertyType, RefreshMode, ValueType } from "@node-projects/web-component-designer";
|
|
2
2
|
import { rerouteConnectedMermaidEdges } from "./MermaidConnectionRouting.js";
|
|
3
|
-
import { FlowchartDirection } from "./mermaidGeometry.js";
|
|
4
|
-
|
|
5
3
|
export const mermaidDiagramTypeAttribute = "data-mermaid-diagram-type";
|
|
6
4
|
export const mermaidFlowchartDirectionAttribute = "data-mermaid-flowchart-direction";
|
|
7
5
|
export const mermaidTitleAttribute = "data-mermaid-title";
|
|
8
6
|
export const mermaidFrontmatterAttribute = "data-mermaid-frontmatter";
|
|
9
|
-
|
|
10
|
-
export type MermaidDocumentDiagramType = "flowchart" | "sequenceDiagram" | "mindmap" | "requirementDiagram";
|
|
11
|
-
|
|
12
7
|
export class MermaidDocumentPropertiesService extends AbstractPropertiesService {
|
|
13
|
-
|
|
8
|
+
_diagramTypeProperty = {
|
|
14
9
|
name: "diagramType",
|
|
15
10
|
displayName: "diagram type",
|
|
16
11
|
type: "list",
|
|
@@ -19,8 +14,7 @@ export class MermaidDocumentPropertiesService extends AbstractPropertiesService
|
|
|
19
14
|
service: this,
|
|
20
15
|
propertyType: PropertyType.attribute,
|
|
21
16
|
};
|
|
22
|
-
|
|
23
|
-
private readonly _flowchartDirectionProperty: IProperty = {
|
|
17
|
+
_flowchartDirectionProperty = {
|
|
24
18
|
name: "flowchartDirection",
|
|
25
19
|
displayName: "flowchart direction",
|
|
26
20
|
type: "list",
|
|
@@ -29,8 +23,7 @@ export class MermaidDocumentPropertiesService extends AbstractPropertiesService
|
|
|
29
23
|
service: this,
|
|
30
24
|
propertyType: PropertyType.attribute,
|
|
31
25
|
};
|
|
32
|
-
|
|
33
|
-
private readonly _requirementDirectionProperty: IProperty = {
|
|
26
|
+
_requirementDirectionProperty = {
|
|
34
27
|
name: "requirementDirection",
|
|
35
28
|
displayName: "direction",
|
|
36
29
|
type: "list",
|
|
@@ -39,8 +32,7 @@ export class MermaidDocumentPropertiesService extends AbstractPropertiesService
|
|
|
39
32
|
service: this,
|
|
40
33
|
propertyType: PropertyType.attribute,
|
|
41
34
|
};
|
|
42
|
-
|
|
43
|
-
private readonly _titleProperty: IProperty = {
|
|
35
|
+
_titleProperty = {
|
|
44
36
|
name: "title",
|
|
45
37
|
displayName: "title",
|
|
46
38
|
type: "string",
|
|
@@ -48,26 +40,21 @@ export class MermaidDocumentPropertiesService extends AbstractPropertiesService
|
|
|
48
40
|
service: this,
|
|
49
41
|
propertyType: PropertyType.attribute,
|
|
50
42
|
};
|
|
51
|
-
|
|
52
|
-
override getRefreshMode() {
|
|
43
|
+
getRefreshMode() {
|
|
53
44
|
return RefreshMode.fullOnValueChange;
|
|
54
45
|
}
|
|
55
|
-
|
|
56
|
-
override isHandledElement(designItem: IDesignItem): boolean {
|
|
46
|
+
isHandledElement(designItem) {
|
|
57
47
|
return designItem.isRootItem;
|
|
58
48
|
}
|
|
59
|
-
|
|
60
|
-
override async getProperties(designItem: IDesignItem): Promise<IProperty[]> {
|
|
49
|
+
async getProperties(designItem) {
|
|
61
50
|
const diagramType = getMermaidDocumentDiagramType(designItem);
|
|
62
51
|
if (diagramType === "requirementDiagram")
|
|
63
52
|
return [this._diagramTypeProperty, this._requirementDirectionProperty, this._titleProperty];
|
|
64
53
|
if (diagramType === "sequenceDiagram" || diagramType === "mindmap")
|
|
65
54
|
return [this._diagramTypeProperty, this._titleProperty];
|
|
66
|
-
|
|
67
55
|
return [this._diagramTypeProperty, this._flowchartDirectionProperty, this._titleProperty];
|
|
68
56
|
}
|
|
69
|
-
|
|
70
|
-
override async getProperty(designItem: IDesignItem, name: string): Promise<IProperty> {
|
|
57
|
+
async getProperty(designItem, name) {
|
|
71
58
|
if (name === this._diagramTypeProperty.name)
|
|
72
59
|
return this._diagramTypeProperty;
|
|
73
60
|
if (name === this._flowchartDirectionProperty.name)
|
|
@@ -78,102 +65,86 @@ export class MermaidDocumentPropertiesService extends AbstractPropertiesService
|
|
|
78
65
|
return this._titleProperty;
|
|
79
66
|
return null;
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
override async setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void> {
|
|
68
|
+
async setValue(designItems, property, value) {
|
|
83
69
|
const rootDesignItems = designItems.filter(designItem => this.isHandledElement(designItem));
|
|
84
70
|
if (!rootDesignItems.length)
|
|
85
71
|
return;
|
|
86
|
-
|
|
87
72
|
const changeGroup = rootDesignItems[0].openGroup("mermaid document property changed: " + property.name + " to " + value);
|
|
88
73
|
try {
|
|
89
74
|
for (const designItem of rootDesignItems)
|
|
90
75
|
setAttribute(designItem, property.attributeName, value);
|
|
91
|
-
|
|
92
76
|
if (property.name === this._diagramTypeProperty.name && (value === "flowchart" || value === "requirementDiagram")) {
|
|
93
77
|
for (const designItem of rootDesignItems) {
|
|
94
78
|
if (!designItem.hasAttribute(mermaidFlowchartDirectionAttribute))
|
|
95
79
|
setAttribute(designItem, mermaidFlowchartDirectionAttribute, value === "requirementDiagram" ? "TB" : "TD");
|
|
96
80
|
}
|
|
97
81
|
}
|
|
98
|
-
|
|
99
82
|
if (property.name === this._flowchartDirectionProperty.name && isFlowchartDirection(value)) {
|
|
100
83
|
for (const designItem of rootDesignItems)
|
|
101
84
|
updateFlowchartDirection(designItem, value);
|
|
102
85
|
}
|
|
103
86
|
changeGroup.commit();
|
|
104
|
-
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
105
89
|
changeGroup.abort();
|
|
106
90
|
throw error;
|
|
107
91
|
}
|
|
108
92
|
}
|
|
109
|
-
|
|
110
|
-
override getPropertyTarget(): BindingTarget {
|
|
93
|
+
getPropertyTarget() {
|
|
111
94
|
return BindingTarget.attribute;
|
|
112
95
|
}
|
|
113
|
-
|
|
114
|
-
override getValue(designItems: IDesignItem[], property: IProperty): any {
|
|
96
|
+
getValue(designItems, property) {
|
|
115
97
|
const designItem = designItems?.[0];
|
|
116
98
|
if (!designItem)
|
|
117
99
|
return null;
|
|
118
|
-
|
|
119
100
|
if (property.name === this._diagramTypeProperty.name)
|
|
120
101
|
return getMermaidDocumentDiagramType(designItem);
|
|
121
|
-
|
|
122
102
|
if (property.name === this._flowchartDirectionProperty.name)
|
|
123
103
|
return getMermaidDocumentFlowchartDirection(designItem);
|
|
124
104
|
if (property.name === this._requirementDirectionProperty.name)
|
|
125
105
|
return getMermaidDocumentFlowchartDirection(designItem);
|
|
126
|
-
|
|
127
106
|
if (property.name === this._titleProperty.name)
|
|
128
107
|
return getMermaidDocumentTitle(designItem);
|
|
129
|
-
|
|
130
108
|
return super.getValue(designItems, property);
|
|
131
109
|
}
|
|
132
|
-
|
|
133
|
-
override isSet(designItems: IDesignItem[], property: IProperty): ValueType {
|
|
110
|
+
isSet(designItems, property) {
|
|
134
111
|
return this.getValue(designItems, property) != null ? ValueType.all : ValueType.none;
|
|
135
112
|
}
|
|
136
113
|
}
|
|
137
|
-
|
|
138
|
-
export function getMermaidDocumentDiagramType(rootDesignItem: IDesignItem): MermaidDocumentDiagramType {
|
|
114
|
+
export function getMermaidDocumentDiagramType(rootDesignItem) {
|
|
139
115
|
const value = rootDesignItem?.getAttribute(mermaidDiagramTypeAttribute);
|
|
140
116
|
if (value === "sequenceDiagram" || value === "mindmap" || value === "requirementDiagram")
|
|
141
117
|
return value;
|
|
142
118
|
return "flowchart";
|
|
143
119
|
}
|
|
144
|
-
|
|
145
|
-
export function getMermaidDocumentFlowchartDirection(rootDesignItem: IDesignItem) {
|
|
120
|
+
export function getMermaidDocumentFlowchartDirection(rootDesignItem) {
|
|
146
121
|
return rootDesignItem?.getAttribute(mermaidFlowchartDirectionAttribute) ?? "TD";
|
|
147
122
|
}
|
|
148
|
-
|
|
149
|
-
export function getMermaidDocumentTitle(rootDesignItem: IDesignItem) {
|
|
123
|
+
export function getMermaidDocumentTitle(rootDesignItem) {
|
|
150
124
|
return rootDesignItem?.getAttribute(mermaidTitleAttribute) ?? "";
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
export function getMermaidDocumentFrontmatter(rootDesignItem: IDesignItem) {
|
|
126
|
+
export function getMermaidDocumentFrontmatter(rootDesignItem) {
|
|
154
127
|
return rootDesignItem?.getAttribute(mermaidFrontmatterAttribute) ?? "";
|
|
155
128
|
}
|
|
156
|
-
|
|
157
|
-
function setAttribute(designItem: IDesignItem, attributeName: string, value: any) {
|
|
129
|
+
function setAttribute(designItem, attributeName, value) {
|
|
158
130
|
if (value == null || value === "")
|
|
159
131
|
designItem.removeAttribute(attributeName);
|
|
160
132
|
else
|
|
161
133
|
designItem.setAttribute(attributeName, value.toString());
|
|
162
134
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const flowchartNodes: IDesignItem[] = [];
|
|
135
|
+
function updateFlowchartDirection(rootDesignItem, direction) {
|
|
136
|
+
const flowchartNodes = [];
|
|
166
137
|
for (const child of rootDesignItem.children(true)) {
|
|
167
138
|
if (child.element.localName === "mermaid-node") {
|
|
168
139
|
child.setAttribute("diagram-direction", direction);
|
|
169
140
|
flowchartNodes.push(child);
|
|
170
|
-
}
|
|
141
|
+
}
|
|
142
|
+
else if (child.element.localName === "mermaid-edge") {
|
|
171
143
|
child.setAttribute("diagram-direction", direction);
|
|
172
144
|
}
|
|
173
145
|
}
|
|
174
146
|
rerouteConnectedMermaidEdges(rootDesignItem.instanceServiceContainer, flowchartNodes, true);
|
|
175
147
|
}
|
|
176
|
-
|
|
177
|
-
function isFlowchartDirection(value: string): value is FlowchartDirection {
|
|
148
|
+
function isFlowchartDirection(value) {
|
|
178
149
|
return value === "TB" || value === "TD" || value === "BT" || value === "RL" || value === "LR";
|
|
179
150
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IElementDefinition, IElementsService, InstanceServiceContainer } from "@node-projects/web-component-designer";
|
|
2
|
+
import { TypedEvent } from "@node-projects/base-custom-webcomponent";
|
|
3
|
+
export declare class MermaidElementsService implements IElementsService {
|
|
4
|
+
private readonly _name;
|
|
5
|
+
readonly onElementsChanged: TypedEvent<void>;
|
|
6
|
+
private _allElements;
|
|
7
|
+
private _instanceServiceContainer;
|
|
8
|
+
private _currentDiagramType;
|
|
9
|
+
private _resolveStored;
|
|
10
|
+
private _rejectStored;
|
|
11
|
+
constructor(_name: string, file: string | URL);
|
|
12
|
+
get name(): string;
|
|
13
|
+
setInstanceServiceContainer(instanceServiceContainer: InstanceServiceContainer): void;
|
|
14
|
+
getElements(): Promise<IElementDefinition[]>;
|
|
15
|
+
private _filterElements;
|
|
16
|
+
private _refreshCurrentDiagramType;
|
|
17
|
+
private _resolveWaiting;
|
|
18
|
+
private _rejectWaiting;
|
|
19
|
+
}
|
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
import { IElementDefinition, IElementsService, InstanceServiceContainer } from "@node-projects/web-component-designer";
|
|
2
1
|
import { LazyLoader, TypedEvent } from "@node-projects/base-custom-webcomponent";
|
|
3
|
-
import { getMermaidDocumentDiagramType
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly onElementsChanged = new TypedEvent<void>();
|
|
15
|
-
|
|
16
|
-
private _allElements: MermaidElementDefinition[];
|
|
17
|
-
private _instanceServiceContainer: InstanceServiceContainer;
|
|
18
|
-
private _currentDiagramType: MermaidDocumentDiagramType = "flowchart";
|
|
19
|
-
private _resolveStored: ((value: IElementDefinition[]) => void)[];
|
|
20
|
-
private _rejectStored: ((errorCode: number) => void)[];
|
|
21
|
-
|
|
22
|
-
constructor(private readonly _name: string, file: string | URL) {
|
|
2
|
+
import { getMermaidDocumentDiagramType } from "./MermaidDocumentPropertiesService.js";
|
|
3
|
+
export class MermaidElementsService {
|
|
4
|
+
_name;
|
|
5
|
+
onElementsChanged = new TypedEvent();
|
|
6
|
+
_allElements;
|
|
7
|
+
_instanceServiceContainer;
|
|
8
|
+
_currentDiagramType = "flowchart";
|
|
9
|
+
_resolveStored;
|
|
10
|
+
_rejectStored;
|
|
11
|
+
constructor(_name, file) {
|
|
12
|
+
this._name = _name;
|
|
23
13
|
LazyLoader.LoadText(file.toString()).then(data => {
|
|
24
|
-
const parsed = JSON.parse(data)
|
|
14
|
+
const parsed = JSON.parse(data);
|
|
25
15
|
this._allElements = parsed.elements.map(element => typeof element === "string" ? { tag: element } : element);
|
|
26
16
|
this._resolveWaiting();
|
|
27
17
|
}).catch(error => this._rejectWaiting(error));
|
|
28
18
|
}
|
|
29
|
-
|
|
30
19
|
get name() {
|
|
31
20
|
return this._name;
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
setInstanceServiceContainer(instanceServiceContainer: InstanceServiceContainer) {
|
|
22
|
+
setInstanceServiceContainer(instanceServiceContainer) {
|
|
35
23
|
this._instanceServiceContainer = instanceServiceContainer;
|
|
36
24
|
this._refreshCurrentDiagramType();
|
|
37
25
|
instanceServiceContainer.onContentChanged.on(() => this._refreshCurrentDiagramType());
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
getElements(): Promise<IElementDefinition[]> {
|
|
27
|
+
getElements() {
|
|
41
28
|
if (this._allElements)
|
|
42
29
|
return Promise.resolve(this._filterElements());
|
|
43
30
|
if (!this._resolveStored) {
|
|
@@ -49,20 +36,17 @@ export class MermaidElementsService implements IElementsService {
|
|
|
49
36
|
this._rejectStored.push(reject);
|
|
50
37
|
});
|
|
51
38
|
}
|
|
52
|
-
|
|
53
|
-
private _filterElements() {
|
|
39
|
+
_filterElements() {
|
|
54
40
|
return this._allElements.filter(element => !element.diagramTypes || element.diagramTypes.includes(this._currentDiagramType));
|
|
55
41
|
}
|
|
56
|
-
|
|
57
|
-
private _refreshCurrentDiagramType() {
|
|
42
|
+
_refreshCurrentDiagramType() {
|
|
58
43
|
const nextDiagramType = getMermaidDocumentDiagramType(this._instanceServiceContainer?.rootDesignItem);
|
|
59
44
|
if (nextDiagramType === this._currentDiagramType)
|
|
60
45
|
return;
|
|
61
46
|
this._currentDiagramType = nextDiagramType;
|
|
62
47
|
this.onElementsChanged.emit();
|
|
63
48
|
}
|
|
64
|
-
|
|
65
|
-
private _resolveWaiting() {
|
|
49
|
+
_resolveWaiting() {
|
|
66
50
|
if (!this._resolveStored)
|
|
67
51
|
return;
|
|
68
52
|
const elements = this._filterElements();
|
|
@@ -70,8 +54,7 @@ export class MermaidElementsService implements IElementsService {
|
|
|
70
54
|
this._resolveStored = null;
|
|
71
55
|
this._rejectStored = null;
|
|
72
56
|
}
|
|
73
|
-
|
|
74
|
-
private _rejectWaiting(error: number) {
|
|
57
|
+
_rejectWaiting(error) {
|
|
75
58
|
if (!this._rejectStored)
|
|
76
59
|
return;
|
|
77
60
|
this._rejectStored.forEach(reject => reject(error));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ICopyPasteService, IDesignItem, IRect, InstanceServiceContainer, ServiceContainer } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class MermaidLayoutCopyPasteService implements ICopyPasteService {
|
|
3
|
+
copyItems(designItems: IDesignItem[]): Promise<void>;
|
|
4
|
+
getPasteItems(serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<[designItems: IDesignItem[], positions?: IRect[]]>;
|
|
5
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { copyTextToClipboard, DefaultHtmlParserService, getTextFromClipboard
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
async copyItems(designItems: IDesignItem[]): Promise<void> {
|
|
1
|
+
import { copyTextToClipboard, DefaultHtmlParserService, getTextFromClipboard } from "@node-projects/web-component-designer";
|
|
2
|
+
export class MermaidLayoutCopyPasteService {
|
|
3
|
+
async copyItems(designItems) {
|
|
5
4
|
let savedata = "";
|
|
6
5
|
for (const designItem of designItems) {
|
|
7
6
|
savedata += designItem.element.outerHTML;
|
|
8
7
|
}
|
|
9
8
|
await copyTextToClipboard(savedata);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
async getPasteItems(serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<[designItems: IDesignItem[], positions?: IRect[]]> {
|
|
10
|
+
async getPasteItems(serviceContainer, instanceServiceContainer) {
|
|
13
11
|
const text = await getTextFromClipboard();
|
|
14
12
|
const htmlParser = new DefaultHtmlParserService();
|
|
15
13
|
const result = await htmlParser.parse(text, serviceContainer, instanceServiceContainer, true);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DefaultPlacementService, IDesignItem, IDesignerCanvas, IPoint } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class MermaidLayoutPlacementService extends DefaultPlacementService {
|
|
3
|
+
serviceForContainer(container: IDesignItem): boolean;
|
|
4
|
+
canEnter(container: IDesignItem, items: IDesignItem[]): boolean;
|
|
5
|
+
enterContainer(container: IDesignItem, items: IDesignItem[]): void;
|
|
6
|
+
leaveContainer(container: IDesignItem, items: IDesignItem[]): void;
|
|
7
|
+
finishPlace(event: MouseEvent, designerCanvas: IDesignerCanvas, container: IDesignItem, startPoint: IPoint, offsetInControl: IPoint, newPoint: IPoint, items: IDesignItem[]): void;
|
|
8
|
+
}
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
import { DefaultPlacementService,
|
|
2
|
-
|
|
1
|
+
import { DefaultPlacementService, filterChildPlaceItems } from "@node-projects/web-component-designer";
|
|
3
2
|
export class MermaidLayoutPlacementService extends DefaultPlacementService {
|
|
4
|
-
|
|
3
|
+
serviceForContainer(container) {
|
|
5
4
|
return container.element.localName === "mermaid-mindmap-node" || container.element.localName === "mermaid-subgraph";
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
override canEnter(container: IDesignItem, items: IDesignItem[]) {
|
|
6
|
+
canEnter(container, items) {
|
|
9
7
|
if (container.element.localName === "mermaid-mindmap-node")
|
|
10
8
|
return items.every(item => item.element.localName === "mermaid-mindmap-node" && !item.element.contains(container.element) && item !== container);
|
|
11
9
|
if (container.element.localName === "mermaid-subgraph")
|
|
12
10
|
return items.every(item => (item.element.localName === "mermaid-node" || item.element.localName === "mermaid-subgraph") && !item.element.contains(container.element) && item !== container);
|
|
13
11
|
return false;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
override enterContainer(container: IDesignItem, items: IDesignItem[]) {
|
|
13
|
+
enterContainer(container, items) {
|
|
17
14
|
const filteredItems = filterChildPlaceItems(items);
|
|
18
15
|
for (const item of filteredItems) {
|
|
19
16
|
if (item.element.localName === "mermaid-mindmap-node" || item.element.localName === "mermaid-node" || item.element.localName === "mermaid-subgraph")
|
|
20
17
|
container.insertChild(item);
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
override leaveContainer(container: IDesignItem, items: IDesignItem[]) {
|
|
20
|
+
leaveContainer(container, items) {
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
override finishPlace(event: MouseEvent, designerCanvas: IDesignerCanvas, container: IDesignItem, startPoint: IPoint, offsetInControl: IPoint, newPoint: IPoint, items: IDesignItem[]) {
|
|
22
|
+
finishPlace(event, designerCanvas, container, startPoint, offsetInControl, newPoint, items) {
|
|
28
23
|
super.finishPlace(event, designerCanvas, container, startPoint, offsetInControl, newPoint, items);
|
|
29
24
|
}
|
|
30
25
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IDesignItem, IHtmlParserService, IHtmlWriterOptions, IHtmlWriterService, InstanceServiceContainer, ITextWriter, ServiceContainer } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class MermaidParserService implements IHtmlParserService, IHtmlWriterService {
|
|
3
|
+
options: IHtmlWriterOptions;
|
|
4
|
+
supportsRootItemWrite: boolean;
|
|
5
|
+
parse(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, parseSnippet: boolean): Promise<IDesignItem[]>;
|
|
6
|
+
write(textWriter: ITextWriter, designItems: IDesignItem[], rootContainerKeepInline: boolean, updatePositions?: boolean): void;
|
|
7
|
+
}
|