@uigraph/sdk 1.2.3 → 1.2.5
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/dist/{__headless.BLqB7VsJ.d.mts → __headless.CnrU6aAA.d.mts} +1 -0
- package/dist/{__headless.DfSqiw4X.d.cts → __headless.D9VUj46t.d.cts} +1 -0
- package/dist/{__headless.DGmyg-me.cjs → __headless.DbTnxFi3.cjs} +1 -0
- package/dist/{__headless.DpdtlCFx.mjs → __headless.bq_YVz7q.mjs} +1 -0
- package/dist/{__index.Bvdu5Kox.d.mts → __index.BQQp_uAt.d.mts} +119 -1
- package/dist/{__index.YhKZQgFP.d.cts → __index.BVDt3Nmx.d.cts} +119 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.mts +1 -1
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.mts +1 -1
- package/dist/headless.mjs +1 -1
- package/dist/index.cjs +1162 -87
- package/dist/index.d.cts +101 -5
- package/dist/index.d.mts +101 -5
- package/dist/index.mjs +1153 -86
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as ComponentInputType } from "./__component-type.CYmD-KIu.mjs";
|
|
2
|
-
import { t as contextSchema } from "./__headless.
|
|
2
|
+
import { t as contextSchema } from "./__headless.bq_YVz7q.mjs";
|
|
3
3
|
import { arrayNonNullable, generateUUID as generateUUID$1, objectPick } from "daily-code";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { MarkerType, Position } from "@xyflow/react";
|
|
6
|
+
import markdownToDelta from "markdown-to-quill-delta";
|
|
6
7
|
import dagre from "dagre";
|
|
7
8
|
import mermaid from "mermaid";
|
|
8
|
-
import markdownToDelta from "markdown-to-quill-delta";
|
|
9
9
|
function mapDynamoTypeToAstType(dynamoType) {
|
|
10
10
|
switch (dynamoType) {
|
|
11
11
|
case "S": return "string";
|
|
@@ -1773,76 +1773,433 @@ function syncBaseData(prev, next, options) {
|
|
|
1773
1773
|
}
|
|
1774
1774
|
return updated;
|
|
1775
1775
|
}
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
SUBGRAPH_CONTENT_TOP_MARGIN: 10,
|
|
1780
|
-
NODE_SEPARATION_HORIZONTAL: 80,
|
|
1781
|
-
NODE_SEPARATION_VERTICAL: 100,
|
|
1782
|
-
CONTAINER_SEPARATION_HORIZONTAL: 120,
|
|
1783
|
-
CONTAINER_SEPARATION_VERTICAL: 160,
|
|
1784
|
-
NESTED_SUBGRAPH_SEPARATION_HORIZONTAL: 120,
|
|
1785
|
-
NESTED_SUBGRAPH_SEPARATION_VERTICAL: 140,
|
|
1786
|
-
META_GRAPH_MARGIN: 100,
|
|
1787
|
-
NESTED_CONTENT_MARGIN: 40,
|
|
1788
|
-
MIXED_CONTENT_VERTICAL_SPACING: 100,
|
|
1789
|
-
MIXED_CONTENT_HORIZONTAL_SPACING: 120
|
|
1776
|
+
const DEFAULT_C4_LAYOUT = {
|
|
1777
|
+
c4ShapeInRow: 4,
|
|
1778
|
+
c4BoundaryInRow: 2
|
|
1790
1779
|
};
|
|
1791
|
-
({
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
MESSAGE_CHAR_WIDTH: 7,
|
|
1808
|
-
MESSAGE_LINE_HEIGHT: 20,
|
|
1809
|
-
MESSAGE_HORIZONTAL_PADDING: 24,
|
|
1810
|
-
MESSAGE_VERTICAL_PADDING: 8,
|
|
1811
|
-
ROW_VERTICAL_PADDING: 16,
|
|
1812
|
-
NOTE_OFFSET: 24,
|
|
1813
|
-
BLOCK_TOP_PADDING: 36,
|
|
1814
|
-
BLOCK_BOTTOM_PADDING: 16,
|
|
1815
|
-
BLOCK_SIDE_PADDING: 44,
|
|
1816
|
-
BLOCK_SECTION_PADDING: 22,
|
|
1817
|
-
BLOCK_CONTENT_INSET: 12,
|
|
1818
|
-
BLOCK_FRAME_GAP: 12,
|
|
1819
|
-
BOX_TOP_INSET: 26,
|
|
1820
|
-
BOX_BOTTOM_PADDING: 24
|
|
1780
|
+
function buildStereotype(keyword) {
|
|
1781
|
+
const suffix = keyword.shape === "db" ? "_db" : keyword.shape === "queue" ? "_queue" : "";
|
|
1782
|
+
return `${keyword.isExternal ? "external_" : ""}${keyword.kind}${suffix}`;
|
|
1783
|
+
}
|
|
1784
|
+
const C4_DIAGRAM_TYPES = [
|
|
1785
|
+
"C4Context",
|
|
1786
|
+
"C4Container",
|
|
1787
|
+
"C4Component",
|
|
1788
|
+
"C4Dynamic",
|
|
1789
|
+
"C4Deployment"
|
|
1790
|
+
];
|
|
1791
|
+
const ELEMENT_KINDS = {
|
|
1792
|
+
Person: "person",
|
|
1793
|
+
System: "system",
|
|
1794
|
+
Container: "container",
|
|
1795
|
+
Component: "component"
|
|
1821
1796
|
};
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1797
|
+
const BOUNDARY_KEYWORDS = {
|
|
1798
|
+
Boundary: { kind: "generic" },
|
|
1799
|
+
Enterprise_Boundary: {
|
|
1800
|
+
kind: "enterprise",
|
|
1801
|
+
fixedType: "ENTERPRISE"
|
|
1802
|
+
},
|
|
1803
|
+
System_Boundary: {
|
|
1804
|
+
kind: "system",
|
|
1805
|
+
fixedType: "SYSTEM"
|
|
1806
|
+
},
|
|
1807
|
+
Container_Boundary: {
|
|
1808
|
+
kind: "container",
|
|
1809
|
+
fixedType: "CONTAINER"
|
|
1810
|
+
},
|
|
1811
|
+
Deployment_Node: {
|
|
1812
|
+
kind: "node",
|
|
1813
|
+
nodeType: "node"
|
|
1814
|
+
},
|
|
1815
|
+
Node: {
|
|
1816
|
+
kind: "node",
|
|
1817
|
+
nodeType: "node"
|
|
1818
|
+
},
|
|
1819
|
+
Node_L: {
|
|
1820
|
+
kind: "node",
|
|
1821
|
+
nodeType: "nodeL"
|
|
1822
|
+
},
|
|
1823
|
+
Node_R: {
|
|
1824
|
+
kind: "node",
|
|
1825
|
+
nodeType: "nodeR"
|
|
1841
1826
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1827
|
+
};
|
|
1828
|
+
const REL_DIRECTIONS = {
|
|
1829
|
+
Rel: "default",
|
|
1830
|
+
RelIndex: "default",
|
|
1831
|
+
BiRel: "bi",
|
|
1832
|
+
Rel_Back: "back",
|
|
1833
|
+
Rel_U: "up",
|
|
1834
|
+
Rel_Up: "up",
|
|
1835
|
+
Rel_D: "down",
|
|
1836
|
+
Rel_Down: "down",
|
|
1837
|
+
Rel_L: "left",
|
|
1838
|
+
Rel_Left: "left",
|
|
1839
|
+
Rel_R: "right",
|
|
1840
|
+
Rel_Right: "right",
|
|
1841
|
+
Rel_Neighbor: "default",
|
|
1842
|
+
BiRel_Neighbor: "bi"
|
|
1843
|
+
};
|
|
1844
|
+
const DIRECTIONS = [
|
|
1845
|
+
"TB",
|
|
1846
|
+
"BT",
|
|
1847
|
+
"LR",
|
|
1848
|
+
"RL"
|
|
1849
|
+
];
|
|
1850
|
+
function parseElementKeyword(keyword) {
|
|
1851
|
+
let rest = keyword;
|
|
1852
|
+
let isExternal = false;
|
|
1853
|
+
if (rest.endsWith("_Ext")) {
|
|
1854
|
+
isExternal = true;
|
|
1855
|
+
rest = rest.slice(0, -4);
|
|
1856
|
+
}
|
|
1857
|
+
let shape = "default";
|
|
1858
|
+
if (rest.endsWith("Db")) {
|
|
1859
|
+
shape = "db";
|
|
1860
|
+
rest = rest.slice(0, -2);
|
|
1861
|
+
} else if (rest.endsWith("Queue")) {
|
|
1862
|
+
shape = "queue";
|
|
1863
|
+
rest = rest.slice(0, -5);
|
|
1864
|
+
}
|
|
1865
|
+
const kind = ELEMENT_KINDS[rest];
|
|
1866
|
+
if (!kind) return null;
|
|
1867
|
+
return {
|
|
1868
|
+
kind,
|
|
1869
|
+
shape,
|
|
1870
|
+
isExternal
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
function splitArguments(raw) {
|
|
1874
|
+
if (!raw.trim()) return [];
|
|
1875
|
+
const args = [];
|
|
1876
|
+
let current = "";
|
|
1877
|
+
let inQuotes = false;
|
|
1878
|
+
let depth = 0;
|
|
1879
|
+
for (let i = 0; i < raw.length; i++) {
|
|
1880
|
+
const char = raw[i];
|
|
1881
|
+
if (char === "\"" && raw[i - 1] !== "\\") {
|
|
1882
|
+
inQuotes = !inQuotes;
|
|
1883
|
+
current += char;
|
|
1884
|
+
continue;
|
|
1885
|
+
}
|
|
1886
|
+
if (!inQuotes && (char === "(" || char === "[")) depth++;
|
|
1887
|
+
if (!inQuotes && (char === ")" || char === "]")) depth--;
|
|
1888
|
+
if (char === "," && !inQuotes && depth === 0) {
|
|
1889
|
+
args.push(current.trim());
|
|
1890
|
+
current = "";
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
current += char;
|
|
1894
|
+
}
|
|
1895
|
+
args.push(current.trim());
|
|
1896
|
+
return args;
|
|
1897
|
+
}
|
|
1898
|
+
function unquote(value) {
|
|
1899
|
+
const trimmed = value.trim();
|
|
1900
|
+
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") && trimmed.length >= 2) return trimmed.slice(1, -1).replace(/\\"/g, "\"").replace(/<br\s*\/?>/gi, "\n").trim();
|
|
1901
|
+
return trimmed.replace(/<br\s*\/?>/gi, "\n");
|
|
1902
|
+
}
|
|
1903
|
+
function partitionArguments(args) {
|
|
1904
|
+
const positional = [];
|
|
1905
|
+
const named = {};
|
|
1906
|
+
for (const arg of args) {
|
|
1907
|
+
const match = arg.match(/^\$([A-Za-z0-9_]+)\s*=\s*([\s\S]*)$/);
|
|
1908
|
+
if (match) {
|
|
1909
|
+
named[match[1]] = unquote(match[2]);
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
positional.push(unquote(arg));
|
|
1913
|
+
}
|
|
1914
|
+
return {
|
|
1915
|
+
positional,
|
|
1916
|
+
named
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
function slot(positional, index) {
|
|
1920
|
+
const value = positional[index];
|
|
1921
|
+
if (value === void 0) return void 0;
|
|
1922
|
+
if (value === "") return void 0;
|
|
1923
|
+
return value;
|
|
1924
|
+
}
|
|
1925
|
+
function isC4Diagram(code) {
|
|
1926
|
+
for (const line of code.split("\n")) {
|
|
1927
|
+
const trimmed = line.trim();
|
|
1928
|
+
if (!trimmed || trimmed.startsWith("%%")) continue;
|
|
1929
|
+
return C4_DIAGRAM_TYPES.some((type) => trimmed.toLowerCase().startsWith(type.toLowerCase()));
|
|
1930
|
+
}
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
function toStatements(code) {
|
|
1934
|
+
const statements = [];
|
|
1935
|
+
let buffer = "";
|
|
1936
|
+
let depth = 0;
|
|
1937
|
+
for (const rawLine of code.split("\n")) {
|
|
1938
|
+
const line = rawLine.replace(/%%.*$/, "").trim();
|
|
1939
|
+
if (!line) continue;
|
|
1940
|
+
buffer = buffer ? `${buffer} ${line}` : line;
|
|
1941
|
+
let inQuotes = false;
|
|
1942
|
+
for (let i = 0; i < line.length; i++) {
|
|
1943
|
+
const char = line[i];
|
|
1944
|
+
if (char === "\"" && line[i - 1] !== "\\") inQuotes = !inQuotes;
|
|
1945
|
+
if (inQuotes) continue;
|
|
1946
|
+
if (char === "(") depth++;
|
|
1947
|
+
if (char === ")") depth--;
|
|
1948
|
+
}
|
|
1949
|
+
if (depth > 0) continue;
|
|
1950
|
+
depth = 0;
|
|
1951
|
+
statements.push(...splitOnBraces(buffer));
|
|
1952
|
+
buffer = "";
|
|
1953
|
+
}
|
|
1954
|
+
if (buffer) statements.push(...splitOnBraces(buffer));
|
|
1955
|
+
return statements;
|
|
1956
|
+
}
|
|
1957
|
+
function splitOnBraces(buffer) {
|
|
1958
|
+
const statements = [];
|
|
1959
|
+
let current = "";
|
|
1960
|
+
let inQuotes = false;
|
|
1961
|
+
let depth = 0;
|
|
1962
|
+
function flush() {
|
|
1963
|
+
if (current.trim()) statements.push(current.trim());
|
|
1964
|
+
current = "";
|
|
1965
|
+
}
|
|
1966
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
1967
|
+
const char = buffer[i];
|
|
1968
|
+
if (char === "\"" && buffer[i - 1] !== "\\") inQuotes = !inQuotes;
|
|
1969
|
+
if (!inQuotes && char === "(") depth++;
|
|
1970
|
+
if (!inQuotes && char === ")") depth--;
|
|
1971
|
+
if (!inQuotes && depth === 0 && char === "{") {
|
|
1972
|
+
current += char;
|
|
1973
|
+
flush();
|
|
1974
|
+
continue;
|
|
1975
|
+
}
|
|
1976
|
+
if (!inQuotes && depth === 0 && char === "}") {
|
|
1977
|
+
flush();
|
|
1978
|
+
statements.push("}");
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
current += char;
|
|
1982
|
+
}
|
|
1983
|
+
flush();
|
|
1984
|
+
return statements;
|
|
1985
|
+
}
|
|
1986
|
+
function parseC4Diagram(code) {
|
|
1987
|
+
const elements = [];
|
|
1988
|
+
const boundaries = [];
|
|
1989
|
+
const relationships = [];
|
|
1990
|
+
const elementStyles = {};
|
|
1991
|
+
const boundaryStyles = {};
|
|
1992
|
+
const relStyles = {};
|
|
1993
|
+
const layout = _objectSpread2({}, DEFAULT_C4_LAYOUT);
|
|
1994
|
+
let type = "C4Context";
|
|
1995
|
+
let title;
|
|
1996
|
+
let accTitle;
|
|
1997
|
+
let accDescription;
|
|
1998
|
+
let direction;
|
|
1999
|
+
const boundaryStack = [];
|
|
2000
|
+
let anonymousBoundaryCount = 0;
|
|
2001
|
+
let accDescrLines;
|
|
2002
|
+
function currentParentId() {
|
|
2003
|
+
return boundaryStack[boundaryStack.length - 1];
|
|
2004
|
+
}
|
|
2005
|
+
function registerChild(childId) {
|
|
2006
|
+
const parentId = currentParentId();
|
|
2007
|
+
if (!parentId) return;
|
|
2008
|
+
const parent = boundaries.find((boundary) => boundary.id === parentId);
|
|
2009
|
+
if (!parent) return;
|
|
2010
|
+
if (parent.childIds.includes(childId)) return;
|
|
2011
|
+
parent.childIds.push(childId);
|
|
2012
|
+
}
|
|
2013
|
+
for (const statement of toStatements(code)) {
|
|
2014
|
+
if (accDescrLines) {
|
|
2015
|
+
if (statement === "}") {
|
|
2016
|
+
accDescription = accDescrLines.join("\n").trim();
|
|
2017
|
+
accDescrLines = void 0;
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
accDescrLines.push(statement);
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
const detectedType = C4_DIAGRAM_TYPES.find((candidate) => statement.toLowerCase().startsWith(candidate.toLowerCase()));
|
|
2024
|
+
if (detectedType) {
|
|
2025
|
+
type = detectedType;
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
if (statement === "}") {
|
|
2029
|
+
boundaryStack.pop();
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
const directionMatch = statement.match(/^direction\s+(TB|BT|LR|RL)$/i);
|
|
2033
|
+
if (directionMatch) {
|
|
2034
|
+
direction = DIRECTIONS.find((candidate) => candidate === directionMatch[1].toUpperCase());
|
|
2035
|
+
continue;
|
|
2036
|
+
}
|
|
2037
|
+
const accTitleMatch = statement.match(/^accTitle\s*:\s*(.*)$/i);
|
|
2038
|
+
if (accTitleMatch) {
|
|
2039
|
+
accTitle = unquote(accTitleMatch[1]);
|
|
2040
|
+
continue;
|
|
2041
|
+
}
|
|
2042
|
+
if (/^accDescr\s*\{$/i.test(statement)) {
|
|
2043
|
+
accDescrLines = [];
|
|
2044
|
+
continue;
|
|
2045
|
+
}
|
|
2046
|
+
const accDescrMatch = statement.match(/^accDescr\s*:\s*(.*)$/i);
|
|
2047
|
+
if (accDescrMatch) {
|
|
2048
|
+
accDescription = unquote(accDescrMatch[1]);
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
const titleMatch = statement.match(/^title\s+(.*)$/i);
|
|
2052
|
+
if (titleMatch) {
|
|
2053
|
+
title = unquote(titleMatch[1]);
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
const callMatch = statement.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)\s*(\{)?\s*$/);
|
|
2057
|
+
if (!callMatch) continue;
|
|
2058
|
+
const [, keyword, rawArgs, openBrace] = callMatch;
|
|
2059
|
+
const { positional, named } = partitionArguments(splitArguments(rawArgs));
|
|
2060
|
+
if (keyword === "UpdateLayoutConfig") {
|
|
2061
|
+
var _named$c4ShapeInRow, _named$c4BoundaryInRo;
|
|
2062
|
+
const inRow = (_named$c4ShapeInRow = named.c4ShapeInRow) !== null && _named$c4ShapeInRow !== void 0 ? _named$c4ShapeInRow : slot(positional, 0);
|
|
2063
|
+
const boundaryInRow = (_named$c4BoundaryInRo = named.c4BoundaryInRow) !== null && _named$c4BoundaryInRo !== void 0 ? _named$c4BoundaryInRo : slot(positional, 1);
|
|
2064
|
+
if (inRow) layout.c4ShapeInRow = Number(inRow) || layout.c4ShapeInRow;
|
|
2065
|
+
if (boundaryInRow) layout.c4BoundaryInRow = Number(boundaryInRow) || layout.c4BoundaryInRow;
|
|
2066
|
+
continue;
|
|
2067
|
+
}
|
|
2068
|
+
if (keyword === "UpdateElementStyle" || keyword === "UpdateBoundaryStyle") {
|
|
2069
|
+
var _named$shadowing, _named$bgColor, _named$fontColor, _named$borderColor, _named$shape, _named$sprite, _named$techn, _named$legendText, _named$legendSprite;
|
|
2070
|
+
const target = slot(positional, 0);
|
|
2071
|
+
if (!target) continue;
|
|
2072
|
+
const shadowing = (_named$shadowing = named.shadowing) !== null && _named$shadowing !== void 0 ? _named$shadowing : slot(positional, 4);
|
|
2073
|
+
const style = {
|
|
2074
|
+
bgColor: (_named$bgColor = named.bgColor) !== null && _named$bgColor !== void 0 ? _named$bgColor : slot(positional, 1),
|
|
2075
|
+
fontColor: (_named$fontColor = named.fontColor) !== null && _named$fontColor !== void 0 ? _named$fontColor : slot(positional, 2),
|
|
2076
|
+
borderColor: (_named$borderColor = named.borderColor) !== null && _named$borderColor !== void 0 ? _named$borderColor : slot(positional, 3),
|
|
2077
|
+
shadowing: shadowing === void 0 ? void 0 : shadowing === "true",
|
|
2078
|
+
shape: (_named$shape = named.shape) !== null && _named$shape !== void 0 ? _named$shape : slot(positional, 5),
|
|
2079
|
+
sprite: (_named$sprite = named.sprite) !== null && _named$sprite !== void 0 ? _named$sprite : slot(positional, 6),
|
|
2080
|
+
techn: (_named$techn = named.techn) !== null && _named$techn !== void 0 ? _named$techn : slot(positional, 7),
|
|
2081
|
+
legendText: (_named$legendText = named.legendText) !== null && _named$legendText !== void 0 ? _named$legendText : slot(positional, 8),
|
|
2082
|
+
legendSprite: (_named$legendSprite = named.legendSprite) !== null && _named$legendSprite !== void 0 ? _named$legendSprite : slot(positional, 9)
|
|
2083
|
+
};
|
|
2084
|
+
if (keyword === "UpdateBoundaryStyle") boundaryStyles[target] = style;
|
|
2085
|
+
else elementStyles[target] = style;
|
|
2086
|
+
continue;
|
|
2087
|
+
}
|
|
2088
|
+
if (keyword === "UpdateRelStyle") {
|
|
2089
|
+
var _named$offsetX, _named$offsetY, _named$textColor, _named$lineColor;
|
|
2090
|
+
const from = slot(positional, 0);
|
|
2091
|
+
const to = slot(positional, 1);
|
|
2092
|
+
if (!from || !to) continue;
|
|
2093
|
+
const offsetX = (_named$offsetX = named.offsetX) !== null && _named$offsetX !== void 0 ? _named$offsetX : slot(positional, 4);
|
|
2094
|
+
const offsetY = (_named$offsetY = named.offsetY) !== null && _named$offsetY !== void 0 ? _named$offsetY : slot(positional, 5);
|
|
2095
|
+
const lineWidth = named.lineWidth;
|
|
2096
|
+
relStyles[`${from}->${to}`] = {
|
|
2097
|
+
textColor: (_named$textColor = named.textColor) !== null && _named$textColor !== void 0 ? _named$textColor : slot(positional, 2),
|
|
2098
|
+
lineColor: (_named$lineColor = named.lineColor) !== null && _named$lineColor !== void 0 ? _named$lineColor : slot(positional, 3),
|
|
2099
|
+
offsetX: offsetX === void 0 ? void 0 : Number(offsetX),
|
|
2100
|
+
offsetY: offsetY === void 0 ? void 0 : Number(offsetY),
|
|
2101
|
+
lineWidth: lineWidth === void 0 ? void 0 : Number(lineWidth),
|
|
2102
|
+
lineStyle: named.lineStyle
|
|
2103
|
+
};
|
|
2104
|
+
continue;
|
|
2105
|
+
}
|
|
2106
|
+
if (/^(SHOW_|HIDE_)/.test(keyword)) continue;
|
|
2107
|
+
const boundaryKeyword = BOUNDARY_KEYWORDS[keyword];
|
|
2108
|
+
if (boundaryKeyword) {
|
|
2109
|
+
var _slot, _ref, _ref2, _boundaryKeyword$fixe, _slot2, _named$descr, _named$sprite2, _named$tags;
|
|
2110
|
+
const id = (_slot = slot(positional, 0)) !== null && _slot !== void 0 ? _slot : `boundary-${++anonymousBoundaryCount}`;
|
|
2111
|
+
const isNode = boundaryKeyword.nodeType !== void 0;
|
|
2112
|
+
const defaultType = isNode ? "node" : "system";
|
|
2113
|
+
const boundaryType = (_ref = (_ref2 = (_boundaryKeyword$fixe = boundaryKeyword.fixedType) !== null && _boundaryKeyword$fixe !== void 0 ? _boundaryKeyword$fixe : named.type) !== null && _ref2 !== void 0 ? _ref2 : slot(positional, 2)) !== null && _ref !== void 0 ? _ref : defaultType;
|
|
2114
|
+
const tagsIndex = boundaryKeyword.fixedType ? 2 : isNode ? 5 : 3;
|
|
2115
|
+
const boundary = {
|
|
2116
|
+
id,
|
|
2117
|
+
label: (_slot2 = slot(positional, 1)) !== null && _slot2 !== void 0 ? _slot2 : id,
|
|
2118
|
+
kind: boundaryKeyword.kind,
|
|
2119
|
+
type: boundaryType,
|
|
2120
|
+
description: isNode ? (_named$descr = named.descr) !== null && _named$descr !== void 0 ? _named$descr : slot(positional, 3) : named.descr,
|
|
2121
|
+
nodeType: boundaryKeyword.nodeType,
|
|
2122
|
+
parentId: currentParentId(),
|
|
2123
|
+
childIds: [],
|
|
2124
|
+
sprite: (_named$sprite2 = named.sprite) !== null && _named$sprite2 !== void 0 ? _named$sprite2 : isNode ? slot(positional, 4) : void 0,
|
|
2125
|
+
tags: (_named$tags = named.tags) !== null && _named$tags !== void 0 ? _named$tags : slot(positional, tagsIndex),
|
|
2126
|
+
link: named.link
|
|
2127
|
+
};
|
|
2128
|
+
registerChild(id);
|
|
2129
|
+
const existing = boundaries.findIndex((entry) => entry.id === id);
|
|
2130
|
+
if (existing === -1) boundaries.push(boundary);
|
|
2131
|
+
else boundaries[existing] = _objectSpread2(_objectSpread2({}, boundary), {}, { childIds: boundaries[existing].childIds });
|
|
2132
|
+
if (openBrace) boundaryStack.push(id);
|
|
2133
|
+
continue;
|
|
2134
|
+
}
|
|
2135
|
+
const relDirection = REL_DIRECTIONS[keyword];
|
|
2136
|
+
if (relDirection) {
|
|
2137
|
+
var _slot3, _named$techn2, _named$descr2, _named$sprite3, _named$tags2;
|
|
2138
|
+
const args = keyword === "RelIndex" ? positional.slice(1) : positional;
|
|
2139
|
+
const from = slot(args, 0);
|
|
2140
|
+
const to = slot(args, 1);
|
|
2141
|
+
if (!from || !to) continue;
|
|
2142
|
+
const relationship = {
|
|
2143
|
+
from,
|
|
2144
|
+
to,
|
|
2145
|
+
label: (_slot3 = slot(args, 2)) !== null && _slot3 !== void 0 ? _slot3 : "",
|
|
2146
|
+
technology: (_named$techn2 = named.techn) !== null && _named$techn2 !== void 0 ? _named$techn2 : slot(args, 3),
|
|
2147
|
+
description: (_named$descr2 = named.descr) !== null && _named$descr2 !== void 0 ? _named$descr2 : slot(args, 4),
|
|
2148
|
+
direction: relDirection,
|
|
2149
|
+
index: relationships.length,
|
|
2150
|
+
sprite: (_named$sprite3 = named.sprite) !== null && _named$sprite3 !== void 0 ? _named$sprite3 : slot(args, 5),
|
|
2151
|
+
tags: (_named$tags2 = named.tags) !== null && _named$tags2 !== void 0 ? _named$tags2 : slot(args, 6),
|
|
2152
|
+
link: named.link
|
|
2153
|
+
};
|
|
2154
|
+
const existing = relationships.findIndex((entry) => entry.from === from && entry.to === to);
|
|
2155
|
+
if (existing === -1) relationships.push(relationship);
|
|
2156
|
+
else relationships[existing] = _objectSpread2(_objectSpread2({}, relationship), {}, { index: relationships[existing].index });
|
|
2157
|
+
continue;
|
|
2158
|
+
}
|
|
2159
|
+
const elementKeyword = parseElementKeyword(keyword);
|
|
2160
|
+
if (elementKeyword) {
|
|
2161
|
+
var _slot4, _named$techn3, _named$descr3, _named$sprite4, _named$tags3;
|
|
2162
|
+
const id = slot(positional, 0);
|
|
2163
|
+
if (!id) continue;
|
|
2164
|
+
const hasTechnologySlot = elementKeyword.kind === "container" || elementKeyword.kind === "component";
|
|
2165
|
+
const descrIndex = hasTechnologySlot ? 3 : 2;
|
|
2166
|
+
const link = named.link;
|
|
2167
|
+
const element = {
|
|
2168
|
+
id,
|
|
2169
|
+
label: (_slot4 = slot(positional, 1)) !== null && _slot4 !== void 0 ? _slot4 : id,
|
|
2170
|
+
technology: (_named$techn3 = named.techn) !== null && _named$techn3 !== void 0 ? _named$techn3 : hasTechnologySlot ? slot(positional, 2) : void 0,
|
|
2171
|
+
description: (_named$descr3 = named.descr) !== null && _named$descr3 !== void 0 ? _named$descr3 : slot(positional, descrIndex),
|
|
2172
|
+
kind: elementKeyword.kind,
|
|
2173
|
+
shape: elementKeyword.shape,
|
|
2174
|
+
isExternal: elementKeyword.isExternal,
|
|
2175
|
+
stereotype: buildStereotype(elementKeyword),
|
|
2176
|
+
parentId: currentParentId(),
|
|
2177
|
+
sprite: (_named$sprite4 = named.sprite) !== null && _named$sprite4 !== void 0 ? _named$sprite4 : slot(positional, descrIndex + 1),
|
|
2178
|
+
tags: (_named$tags3 = named.tags) !== null && _named$tags3 !== void 0 ? _named$tags3 : slot(positional, descrIndex + 2),
|
|
2179
|
+
link,
|
|
2180
|
+
subDiagramId: (link === null || link === void 0 ? void 0 : link.startsWith("uig:")) ? link.slice(4) : void 0
|
|
2181
|
+
};
|
|
2182
|
+
registerChild(id);
|
|
2183
|
+
const existing = elements.findIndex((entry) => entry.id === id);
|
|
2184
|
+
if (existing === -1) elements.push(element);
|
|
2185
|
+
else elements[existing] = element;
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return {
|
|
2190
|
+
type,
|
|
2191
|
+
title,
|
|
2192
|
+
accTitle,
|
|
2193
|
+
accDescription,
|
|
2194
|
+
direction,
|
|
2195
|
+
elements,
|
|
2196
|
+
boundaries,
|
|
2197
|
+
relationships,
|
|
2198
|
+
elementStyles,
|
|
2199
|
+
boundaryStyles,
|
|
2200
|
+
relStyles,
|
|
2201
|
+
layout
|
|
2202
|
+
};
|
|
1846
2203
|
}
|
|
1847
2204
|
function flattenMetaData(fields, fieldsValues) {
|
|
1848
2205
|
const output = {};
|
|
@@ -1980,6 +2337,422 @@ function getComponentFieldByLabel(fields, label) {
|
|
|
1980
2337
|
return ((_field$label = field.label) === null || _field$label === void 0 ? void 0 : _field$label.toLowerCase()) === label.toLowerCase();
|
|
1981
2338
|
});
|
|
1982
2339
|
}
|
|
2340
|
+
const C4_LAYOUT = {
|
|
2341
|
+
WIDTH: 240,
|
|
2342
|
+
MIN_HEIGHT: 80,
|
|
2343
|
+
SHAPE_MARGIN: 90,
|
|
2344
|
+
ROW_MARGIN: 80,
|
|
2345
|
+
SHAPE_PADDING: 24,
|
|
2346
|
+
BOUNDARY_HEADER: 72,
|
|
2347
|
+
BOUNDARY_PADDING: 48,
|
|
2348
|
+
BOUNDARY_MARGIN: 60,
|
|
2349
|
+
DIAGRAM_MARGIN_X: 60,
|
|
2350
|
+
DIAGRAM_MARGIN_Y: 40
|
|
2351
|
+
};
|
|
2352
|
+
const C4_COLORS = {
|
|
2353
|
+
person: {
|
|
2354
|
+
fill: "#08427B",
|
|
2355
|
+
stroke: "#052E56"
|
|
2356
|
+
},
|
|
2357
|
+
personExternal: {
|
|
2358
|
+
fill: "#686868",
|
|
2359
|
+
stroke: "#4D4D4D"
|
|
2360
|
+
},
|
|
2361
|
+
system: {
|
|
2362
|
+
fill: "#1168BD",
|
|
2363
|
+
stroke: "#0B4884"
|
|
2364
|
+
},
|
|
2365
|
+
systemExternal: {
|
|
2366
|
+
fill: "#999999",
|
|
2367
|
+
stroke: "#6B6B6B"
|
|
2368
|
+
},
|
|
2369
|
+
container: {
|
|
2370
|
+
fill: "#438DD5",
|
|
2371
|
+
stroke: "#2E6295"
|
|
2372
|
+
},
|
|
2373
|
+
containerExternal: {
|
|
2374
|
+
fill: "#B3B3B3",
|
|
2375
|
+
stroke: "#8A8A8A"
|
|
2376
|
+
},
|
|
2377
|
+
component: {
|
|
2378
|
+
fill: "#85BBF0",
|
|
2379
|
+
stroke: "#5D82A8"
|
|
2380
|
+
},
|
|
2381
|
+
componentExternal: {
|
|
2382
|
+
fill: "#CCCCCC",
|
|
2383
|
+
stroke: "#A6A6A6"
|
|
2384
|
+
},
|
|
2385
|
+
node: {
|
|
2386
|
+
fill: "#1F2937",
|
|
2387
|
+
stroke: "#4B5563"
|
|
2388
|
+
},
|
|
2389
|
+
nodeExternal: {
|
|
2390
|
+
fill: "#374151",
|
|
2391
|
+
stroke: "#6B7280"
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
const BOUNDARY_BORDER = "#828DA3";
|
|
2395
|
+
function getC4ElementColors(element) {
|
|
2396
|
+
var _C4_COLORS$key;
|
|
2397
|
+
return (_C4_COLORS$key = C4_COLORS[element.isExternal ? `${element.kind}External` : element.kind]) !== null && _C4_COLORS$key !== void 0 ? _C4_COLORS$key : C4_COLORS.system;
|
|
2398
|
+
}
|
|
2399
|
+
const NAME_LINE_HEIGHT = 22;
|
|
2400
|
+
const SMALL_LINE_HEIGHT = 18;
|
|
2401
|
+
const PERSON_GLYPH = 30;
|
|
2402
|
+
const CYLINDER_LIPS = 34;
|
|
2403
|
+
const QUEUE_CAPS = 68;
|
|
2404
|
+
function wrappedLines(text, usableWidth, charWidth) {
|
|
2405
|
+
if (!text) return 0;
|
|
2406
|
+
const charsPerLine = Math.max(6, Math.floor(usableWidth / charWidth));
|
|
2407
|
+
return text.split("\n").reduce((total, line) => total + Math.max(1, Math.ceil(line.length / charsPerLine)), 0);
|
|
2408
|
+
}
|
|
2409
|
+
function measureElement(element) {
|
|
2410
|
+
let usableWidth = C4_LAYOUT.WIDTH - C4_LAYOUT.SHAPE_PADDING * 2;
|
|
2411
|
+
if (element.shape === "queue") usableWidth -= QUEUE_CAPS;
|
|
2412
|
+
let height = C4_LAYOUT.SHAPE_PADDING * 2;
|
|
2413
|
+
height += SMALL_LINE_HEIGHT;
|
|
2414
|
+
if (element.kind === "person") height += PERSON_GLYPH;
|
|
2415
|
+
height += wrappedLines(element.label, usableWidth, 8.6) * NAME_LINE_HEIGHT;
|
|
2416
|
+
if (element.technology) height += SMALL_LINE_HEIGHT;
|
|
2417
|
+
height += wrappedLines(element.description, usableWidth, 5.9) * SMALL_LINE_HEIGHT;
|
|
2418
|
+
if (element.shape === "db") height += CYLINDER_LIPS;
|
|
2419
|
+
return {
|
|
2420
|
+
width: C4_LAYOUT.WIDTH,
|
|
2421
|
+
height: Math.max(C4_LAYOUT.MIN_HEIGHT, height)
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
function layoutContainer(containerId, data, childrenOf, elementById, placements) {
|
|
2425
|
+
var _childrenOf$get;
|
|
2426
|
+
const childIds = (_childrenOf$get = childrenOf.get(containerId)) !== null && _childrenOf$get !== void 0 ? _childrenOf$get : [];
|
|
2427
|
+
const shapeIds = childIds.filter((id) => elementById.has(id));
|
|
2428
|
+
const boundaryIds = childIds.filter((id) => !elementById.has(id));
|
|
2429
|
+
const originX = containerId ? C4_LAYOUT.BOUNDARY_PADDING : C4_LAYOUT.DIAGRAM_MARGIN_X;
|
|
2430
|
+
const originY = containerId ? C4_LAYOUT.BOUNDARY_HEADER : C4_LAYOUT.DIAGRAM_MARGIN_Y;
|
|
2431
|
+
let cursorY = originY;
|
|
2432
|
+
let maxX = originX;
|
|
2433
|
+
let lastMargin = 0;
|
|
2434
|
+
const perRow = Math.max(1, data.layout.c4ShapeInRow);
|
|
2435
|
+
for (let index = 0; index < shapeIds.length; index += perRow) {
|
|
2436
|
+
const row = shapeIds.slice(index, index + perRow);
|
|
2437
|
+
let rowHeight = 0;
|
|
2438
|
+
row.forEach((id, column) => {
|
|
2439
|
+
const size = measureElement(elementById.get(id));
|
|
2440
|
+
const x = originX + column * (C4_LAYOUT.WIDTH + C4_LAYOUT.SHAPE_MARGIN);
|
|
2441
|
+
placements.set(id, {
|
|
2442
|
+
x,
|
|
2443
|
+
y: cursorY,
|
|
2444
|
+
width: size.width,
|
|
2445
|
+
height: size.height
|
|
2446
|
+
});
|
|
2447
|
+
rowHeight = Math.max(rowHeight, size.height);
|
|
2448
|
+
maxX = Math.max(maxX, x + size.width);
|
|
2449
|
+
});
|
|
2450
|
+
cursorY += rowHeight + C4_LAYOUT.ROW_MARGIN;
|
|
2451
|
+
lastMargin = C4_LAYOUT.ROW_MARGIN;
|
|
2452
|
+
}
|
|
2453
|
+
const boundarySizes = /* @__PURE__ */ new Map();
|
|
2454
|
+
for (const id of boundaryIds) boundarySizes.set(id, layoutContainer(id, data, childrenOf, elementById, placements));
|
|
2455
|
+
const boundariesPerRow = Math.max(1, data.layout.c4BoundaryInRow);
|
|
2456
|
+
for (let index = 0; index < boundaryIds.length; index += boundariesPerRow) {
|
|
2457
|
+
const row = boundaryIds.slice(index, index + boundariesPerRow);
|
|
2458
|
+
let rowHeight = 0;
|
|
2459
|
+
let cursorX = originX;
|
|
2460
|
+
for (const id of row) {
|
|
2461
|
+
const size = boundarySizes.get(id);
|
|
2462
|
+
placements.set(id, {
|
|
2463
|
+
x: cursorX,
|
|
2464
|
+
y: cursorY,
|
|
2465
|
+
width: size.width,
|
|
2466
|
+
height: size.height
|
|
2467
|
+
});
|
|
2468
|
+
cursorX += size.width + C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2469
|
+
rowHeight = Math.max(rowHeight, size.height);
|
|
2470
|
+
maxX = Math.max(maxX, cursorX - C4_LAYOUT.BOUNDARY_MARGIN);
|
|
2471
|
+
}
|
|
2472
|
+
cursorY += rowHeight + C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2473
|
+
lastMargin = C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2474
|
+
}
|
|
2475
|
+
const hasChildren = shapeIds.length > 0 || boundaryIds.length > 0;
|
|
2476
|
+
const trailing = containerId ? C4_LAYOUT.BOUNDARY_PADDING : C4_LAYOUT.DIAGRAM_MARGIN_Y;
|
|
2477
|
+
if (!hasChildren) return {
|
|
2478
|
+
width: C4_LAYOUT.WIDTH + originX + trailing,
|
|
2479
|
+
height: C4_LAYOUT.MIN_HEIGHT + originY + trailing
|
|
2480
|
+
};
|
|
2481
|
+
return {
|
|
2482
|
+
width: maxX + originX,
|
|
2483
|
+
height: cursorY - lastMargin + trailing
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
function resolveSide(direction, from, to) {
|
|
2487
|
+
if (direction === "up") return {
|
|
2488
|
+
source: "top",
|
|
2489
|
+
target: "bottom"
|
|
2490
|
+
};
|
|
2491
|
+
if (direction === "down") return {
|
|
2492
|
+
source: "bottom",
|
|
2493
|
+
target: "top"
|
|
2494
|
+
};
|
|
2495
|
+
if (direction === "left") return {
|
|
2496
|
+
source: "left",
|
|
2497
|
+
target: "right"
|
|
2498
|
+
};
|
|
2499
|
+
if (direction === "right") return {
|
|
2500
|
+
source: "right",
|
|
2501
|
+
target: "left"
|
|
2502
|
+
};
|
|
2503
|
+
const dx = to.x - from.x;
|
|
2504
|
+
const dy = to.y - from.y;
|
|
2505
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
2506
|
+
if (dx >= 0) return {
|
|
2507
|
+
source: "right",
|
|
2508
|
+
target: "left"
|
|
2509
|
+
};
|
|
2510
|
+
return {
|
|
2511
|
+
source: "left",
|
|
2512
|
+
target: "right"
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
if (dy >= 0) return {
|
|
2516
|
+
source: "bottom",
|
|
2517
|
+
target: "top"
|
|
2518
|
+
};
|
|
2519
|
+
return {
|
|
2520
|
+
source: "top",
|
|
2521
|
+
target: "bottom"
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
function applyElementStyle(base, style) {
|
|
2525
|
+
var _style$bgColor, _style$borderColor;
|
|
2526
|
+
return {
|
|
2527
|
+
fill: (_style$bgColor = style === null || style === void 0 ? void 0 : style.bgColor) !== null && _style$bgColor !== void 0 ? _style$bgColor : base.fill,
|
|
2528
|
+
stroke: (_style$borderColor = style === null || style === void 0 ? void 0 : style.borderColor) !== null && _style$borderColor !== void 0 ? _style$borderColor : base.stroke,
|
|
2529
|
+
fontColor: style === null || style === void 0 ? void 0 : style.fontColor
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
function convertC4ToReactFlow(data) {
|
|
2533
|
+
const elementById = new Map(data.elements.map((el) => [el.id, el]));
|
|
2534
|
+
const boundaryById = new Map(data.boundaries.map((b) => [b.id, b]));
|
|
2535
|
+
const childrenOf = /* @__PURE__ */ new Map();
|
|
2536
|
+
function attach(id, parentId) {
|
|
2537
|
+
var _childrenOf$get2;
|
|
2538
|
+
const siblings = (_childrenOf$get2 = childrenOf.get(parentId)) !== null && _childrenOf$get2 !== void 0 ? _childrenOf$get2 : [];
|
|
2539
|
+
siblings.push(id);
|
|
2540
|
+
childrenOf.set(parentId, siblings);
|
|
2541
|
+
}
|
|
2542
|
+
for (const boundary of data.boundaries) attach(boundary.id, boundary.parentId);
|
|
2543
|
+
for (const element of data.elements) attach(element.id, element.parentId);
|
|
2544
|
+
const placements = /* @__PURE__ */ new Map();
|
|
2545
|
+
layoutContainer(void 0, data, childrenOf, elementById, placements);
|
|
2546
|
+
const nodes = [];
|
|
2547
|
+
for (const boundary of data.boundaries) {
|
|
2548
|
+
var _data$boundaryStyles$, _style$bgColor2, _style$borderColor2;
|
|
2549
|
+
const placement = placements.get(boundary.id);
|
|
2550
|
+
if (!placement) continue;
|
|
2551
|
+
const style = (_data$boundaryStyles$ = data.boundaryStyles[boundary.id]) !== null && _data$boundaryStyles$ !== void 0 ? _data$boundaryStyles$ : data.elementStyles[boundary.id];
|
|
2552
|
+
nodes.push({
|
|
2553
|
+
id: boundary.id,
|
|
2554
|
+
type: "c4Boundary",
|
|
2555
|
+
position: {
|
|
2556
|
+
x: placement.x,
|
|
2557
|
+
y: placement.y
|
|
2558
|
+
},
|
|
2559
|
+
data: {
|
|
2560
|
+
source: "mermaid",
|
|
2561
|
+
c4BoundaryKind: boundary.kind,
|
|
2562
|
+
boundaryType: boundary.type,
|
|
2563
|
+
description: boundary.description,
|
|
2564
|
+
c4NodeType: boundary.nodeType,
|
|
2565
|
+
link: boundary.link,
|
|
2566
|
+
backgroundColor: (_style$bgColor2 = style === null || style === void 0 ? void 0 : style.bgColor) !== null && _style$bgColor2 !== void 0 ? _style$bgColor2 : "transparent",
|
|
2567
|
+
borderColor: (_style$borderColor2 = style === null || style === void 0 ? void 0 : style.borderColor) !== null && _style$borderColor2 !== void 0 ? _style$borderColor2 : BOUNDARY_BORDER,
|
|
2568
|
+
fontColor: style === null || style === void 0 ? void 0 : style.fontColor,
|
|
2569
|
+
componentFields: [generateComponentFieldNameInput(boundary.label)]
|
|
2570
|
+
},
|
|
2571
|
+
style: {
|
|
2572
|
+
width: placement.width,
|
|
2573
|
+
height: placement.height
|
|
2574
|
+
},
|
|
2575
|
+
width: placement.width,
|
|
2576
|
+
height: placement.height,
|
|
2577
|
+
parentId: boundary.parentId,
|
|
2578
|
+
extent: boundary.parentId ? "parent" : void 0,
|
|
2579
|
+
selectable: true,
|
|
2580
|
+
draggable: true
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
for (const element of data.elements) {
|
|
2584
|
+
const placement = placements.get(element.id);
|
|
2585
|
+
if (!placement) continue;
|
|
2586
|
+
const colors = applyElementStyle(getC4ElementColors(element), data.elementStyles[element.id]);
|
|
2587
|
+
nodes.push({
|
|
2588
|
+
id: element.id,
|
|
2589
|
+
type: element.subDiagramId ? "subDiagram" : "c4",
|
|
2590
|
+
position: {
|
|
2591
|
+
x: placement.x,
|
|
2592
|
+
y: placement.y
|
|
2593
|
+
},
|
|
2594
|
+
width: placement.width,
|
|
2595
|
+
height: placement.height,
|
|
2596
|
+
data: {
|
|
2597
|
+
source: "mermaid",
|
|
2598
|
+
diagramId: element.subDiagramId,
|
|
2599
|
+
diagramName: element.label,
|
|
2600
|
+
c4Kind: element.kind,
|
|
2601
|
+
c4Shape: element.shape,
|
|
2602
|
+
isExternal: element.isExternal,
|
|
2603
|
+
technology: element.technology,
|
|
2604
|
+
description: element.description,
|
|
2605
|
+
link: element.link,
|
|
2606
|
+
fill: colors.fill,
|
|
2607
|
+
stroke: colors.stroke,
|
|
2608
|
+
fontColor: colors.fontColor,
|
|
2609
|
+
componentFields: [generateComponentFieldNameInput(element.label)]
|
|
2610
|
+
},
|
|
2611
|
+
style: {
|
|
2612
|
+
width: placement.width,
|
|
2613
|
+
height: placement.height
|
|
2614
|
+
},
|
|
2615
|
+
parentId: element.parentId,
|
|
2616
|
+
extent: element.parentId ? "parent" : void 0
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
2620
|
+
for (const boundary of data.boundaries) parentOf.set(boundary.id, boundary.parentId);
|
|
2621
|
+
for (const element of data.elements) parentOf.set(element.id, element.parentId);
|
|
2622
|
+
function absoluteCenter(id) {
|
|
2623
|
+
const placement = placements.get(id);
|
|
2624
|
+
let x = placement.x + placement.width / 2;
|
|
2625
|
+
let y = placement.y + placement.height / 2;
|
|
2626
|
+
let parentId = parentOf.get(id);
|
|
2627
|
+
while (parentId) {
|
|
2628
|
+
const parent = placements.get(parentId);
|
|
2629
|
+
x += parent.x;
|
|
2630
|
+
y += parent.y;
|
|
2631
|
+
parentId = parentOf.get(parentId);
|
|
2632
|
+
}
|
|
2633
|
+
return {
|
|
2634
|
+
x,
|
|
2635
|
+
y
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
return {
|
|
2639
|
+
nodes,
|
|
2640
|
+
edges: data.relationships.filter((rel) => (elementById.has(rel.from) || boundaryById.has(rel.from)) && (elementById.has(rel.to) || boundaryById.has(rel.to))).map((rel) => {
|
|
2641
|
+
var _style$lineColor, _style$lineWidth;
|
|
2642
|
+
const isBack = rel.direction === "back";
|
|
2643
|
+
const source = isBack ? rel.to : rel.from;
|
|
2644
|
+
const target = isBack ? rel.from : rel.to;
|
|
2645
|
+
const style = data.relStyles[`${rel.from}->${rel.to}`];
|
|
2646
|
+
const lineColor = (_style$lineColor = style === null || style === void 0 ? void 0 : style.lineColor) !== null && _style$lineColor !== void 0 ? _style$lineColor : BOUNDARY_BORDER;
|
|
2647
|
+
const label = [rel.label, rel.technology ? `[${rel.technology}]` : ""].filter(Boolean).join(" ");
|
|
2648
|
+
const side = resolveSide(rel.direction, absoluteCenter(source), absoluteCenter(target));
|
|
2649
|
+
return {
|
|
2650
|
+
id: `c4-rel-${rel.from}-${rel.to}-${rel.index}`,
|
|
2651
|
+
source,
|
|
2652
|
+
target,
|
|
2653
|
+
sourceHandle: `source-${side.source}`,
|
|
2654
|
+
targetHandle: `target-${side.target}`,
|
|
2655
|
+
label,
|
|
2656
|
+
type: "simplebezier",
|
|
2657
|
+
style: {
|
|
2658
|
+
stroke: lineColor,
|
|
2659
|
+
strokeWidth: (_style$lineWidth = style === null || style === void 0 ? void 0 : style.lineWidth) !== null && _style$lineWidth !== void 0 ? _style$lineWidth : 1.5
|
|
2660
|
+
},
|
|
2661
|
+
data: {
|
|
2662
|
+
source: "mermaid",
|
|
2663
|
+
labelColor: style === null || style === void 0 ? void 0 : style.textColor,
|
|
2664
|
+
labelOffsetX: style === null || style === void 0 ? void 0 : style.offsetX,
|
|
2665
|
+
labelOffsetY: style === null || style === void 0 ? void 0 : style.offsetY
|
|
2666
|
+
},
|
|
2667
|
+
markerEnd: {
|
|
2668
|
+
type: MarkerType.ArrowClosed,
|
|
2669
|
+
width: 14,
|
|
2670
|
+
height: 14,
|
|
2671
|
+
color: lineColor
|
|
2672
|
+
},
|
|
2673
|
+
markerStart: rel.direction === "bi" ? {
|
|
2674
|
+
type: MarkerType.ArrowClosed,
|
|
2675
|
+
width: 14,
|
|
2676
|
+
height: 14,
|
|
2677
|
+
color: lineColor
|
|
2678
|
+
} : void 0
|
|
2679
|
+
};
|
|
2680
|
+
})
|
|
2681
|
+
};
|
|
2682
|
+
}
|
|
2683
|
+
function convertC4MermaidToReactFlow(code) {
|
|
2684
|
+
return convertC4ToReactFlow(parseC4Diagram(code));
|
|
2685
|
+
}
|
|
2686
|
+
const LAYOUT_SPACING = {
|
|
2687
|
+
SUBGRAPH_HEADER_HEIGHT: 35,
|
|
2688
|
+
SUBGRAPH_PADDING: 8,
|
|
2689
|
+
SUBGRAPH_CONTENT_TOP_MARGIN: 10,
|
|
2690
|
+
NODE_SEPARATION_HORIZONTAL: 80,
|
|
2691
|
+
NODE_SEPARATION_VERTICAL: 100,
|
|
2692
|
+
CONTAINER_SEPARATION_HORIZONTAL: 120,
|
|
2693
|
+
CONTAINER_SEPARATION_VERTICAL: 160,
|
|
2694
|
+
NESTED_SUBGRAPH_SEPARATION_HORIZONTAL: 120,
|
|
2695
|
+
NESTED_SUBGRAPH_SEPARATION_VERTICAL: 140,
|
|
2696
|
+
META_GRAPH_MARGIN: 100,
|
|
2697
|
+
NESTED_CONTENT_MARGIN: 40,
|
|
2698
|
+
MIXED_CONTENT_VERTICAL_SPACING: 100,
|
|
2699
|
+
MIXED_CONTENT_HORIZONTAL_SPACING: 120
|
|
2700
|
+
};
|
|
2701
|
+
({
|
|
2702
|
+
NETWORK_SIMPLEX: "network-simplex",
|
|
2703
|
+
TIGHT_TREE: "tight-tree",
|
|
2704
|
+
LONGEST_PATH: "longest-path"
|
|
2705
|
+
}).TIGHT_TREE;
|
|
2706
|
+
const SEQUENCE_LAYOUT = {
|
|
2707
|
+
COLUMN_WIDTH: 360,
|
|
2708
|
+
ROW_HEIGHT: 60,
|
|
2709
|
+
HEADER_HEIGHT: 40,
|
|
2710
|
+
MESSAGE_NODE_WIDTH: 140,
|
|
2711
|
+
MESSAGE_NODE_HEIGHT: 32,
|
|
2712
|
+
SELF_LOOP_OFFSET: 48,
|
|
2713
|
+
PARTICIPANT_NODE_WIDTH: 10,
|
|
2714
|
+
MESSAGE_MAX_WIDTH: 240,
|
|
2715
|
+
MESSAGE_TARGET_WRAP_LINES: 2,
|
|
2716
|
+
MESSAGE_CHAR_WIDTH: 7,
|
|
2717
|
+
MESSAGE_LINE_HEIGHT: 20,
|
|
2718
|
+
MESSAGE_HORIZONTAL_PADDING: 24,
|
|
2719
|
+
MESSAGE_VERTICAL_PADDING: 8,
|
|
2720
|
+
ROW_VERTICAL_PADDING: 16,
|
|
2721
|
+
NOTE_OFFSET: 24,
|
|
2722
|
+
BLOCK_TOP_PADDING: 36,
|
|
2723
|
+
BLOCK_BOTTOM_PADDING: 16,
|
|
2724
|
+
BLOCK_SIDE_PADDING: 44,
|
|
2725
|
+
BLOCK_SECTION_PADDING: 22,
|
|
2726
|
+
BLOCK_CONTENT_INSET: 12,
|
|
2727
|
+
BLOCK_FRAME_GAP: 12,
|
|
2728
|
+
BOX_TOP_INSET: 26,
|
|
2729
|
+
BOX_BOTTOM_PADDING: 24
|
|
2730
|
+
};
|
|
2731
|
+
function sanitizeMermaidLabels(src) {
|
|
2732
|
+
if (!src) return src;
|
|
2733
|
+
const subgraphFixed = src.replace(/([A-Za-z0-9_]+)\[((?:(?![\"']).)*?)\]/g, (m, id, label) => {
|
|
2734
|
+
if (/^[\"']/.test(label)) return m;
|
|
2735
|
+
if (/[()\"\[\],:;]/.test(label)) return `${id}[\"${String(label).replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"]`;
|
|
2736
|
+
return m;
|
|
2737
|
+
}).replace(/^([ \t]*subgraph\s+)([^\n\r]+)(\|[^\n\r]*)?$/gim, (m, pre, title, rest) => {
|
|
2738
|
+
const t = String(title).trim();
|
|
2739
|
+
if (/^[\"']/.test(t)) return m;
|
|
2740
|
+
if (/[()\"\[\],:;]/.test(t)) return `${pre}\"${t.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"${rest || ""}`;
|
|
2741
|
+
return m;
|
|
2742
|
+
});
|
|
2743
|
+
const diagRegex = /\b(graph|flowchart|sequenceDiagram|stateDiagram|classDiagram|gantt|journey|erDiagram|gitGraph|pie|timeline|infoDiagram)\b/i;
|
|
2744
|
+
const allStarts = [];
|
|
2745
|
+
let mm;
|
|
2746
|
+
const globalRegex = new RegExp(diagRegex.source, "gim");
|
|
2747
|
+
while ((mm = globalRegex.exec(subgraphFixed)) !== null) {
|
|
2748
|
+
allStarts.push(mm.index);
|
|
2749
|
+
if (globalRegex.lastIndex === mm.index) globalRegex.lastIndex++;
|
|
2750
|
+
}
|
|
2751
|
+
if (allStarts.length <= 1) return subgraphFixed;
|
|
2752
|
+
const first = allStarts[0];
|
|
2753
|
+
const second = allStarts[1];
|
|
2754
|
+
return subgraphFixed.slice(first, second).trim();
|
|
2755
|
+
}
|
|
1983
2756
|
const LABEL_TYPE_PREFIX = /^\s*type:(\w+)\s*[:|-]\s*/i;
|
|
1984
2757
|
const TAG_TO_NODE_TYPE = {
|
|
1985
2758
|
builder: "builder",
|
|
@@ -2193,6 +2966,14 @@ const ARROW_TOKENS = [
|
|
|
2193
2966
|
arrowType: "none"
|
|
2194
2967
|
}
|
|
2195
2968
|
];
|
|
2969
|
+
function findArrowTokenFor(options) {
|
|
2970
|
+
const exact = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType && candidate.half === options.half && Boolean(candidate.reversed) === Boolean(options.reversed));
|
|
2971
|
+
if (exact) return exact.token;
|
|
2972
|
+
const byHead = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType);
|
|
2973
|
+
if (byHead) return byHead.token;
|
|
2974
|
+
if (options.lineStyle === "dashed") return "-->>";
|
|
2975
|
+
return "->>";
|
|
2976
|
+
}
|
|
2196
2977
|
const BLOCK_OPENERS = [
|
|
2197
2978
|
"loop",
|
|
2198
2979
|
"alt",
|
|
@@ -2982,12 +3763,7 @@ function convertSequenceDiagramToReactFlow(mermaidCode) {
|
|
|
2982
3763
|
lifelineHeight: grid.contentHeight,
|
|
2983
3764
|
activations,
|
|
2984
3765
|
links: participant.links
|
|
2985
|
-
}, participant.createdAtRow === void 0 ? {} : { lifelineStartRow: grid.toLayoutRow(participant.createdAtRow) }), participant.destroyedAtRow === void 0 ? {} : { lifelineEndRow: grid.toLastLayoutRow(participant.destroyedAtRow) }), {}, { componentFields: [generateComponentFieldNameInput(participant.name)
|
|
2986
|
-
componentFieldId: "color",
|
|
2987
|
-
label: "Color",
|
|
2988
|
-
data: SEQUENCE_PARTICIPANT_COLOR,
|
|
2989
|
-
type: ComponentInputType.ColorPicker
|
|
2990
|
-
})] })
|
|
3766
|
+
}, participant.createdAtRow === void 0 ? {} : { lifelineStartRow: grid.toLayoutRow(participant.createdAtRow) }), participant.destroyedAtRow === void 0 ? {} : { lifelineEndRow: grid.toLastLayoutRow(participant.destroyedAtRow) }), {}, { componentFields: [generateComponentFieldNameInput(participant.name)] })
|
|
2991
3767
|
});
|
|
2992
3768
|
}
|
|
2993
3769
|
for (const note of data.notes) {
|
|
@@ -3119,6 +3895,7 @@ function detectDiagramType(code) {
|
|
|
3119
3895
|
for (const line of lines) {
|
|
3120
3896
|
const trimmed = line.trim().toLowerCase();
|
|
3121
3897
|
if (trimmed.startsWith("sequencediagram")) return "sequence";
|
|
3898
|
+
if (trimmed.startsWith("c4")) return "c4";
|
|
3122
3899
|
if (trimmed.startsWith("flowchart") || trimmed.startsWith("graph")) return "flowchart";
|
|
3123
3900
|
}
|
|
3124
3901
|
return "flowchart";
|
|
@@ -4346,7 +5123,6 @@ function createReactFlowElements(nodes, edges, subgraphs, subgraphLayouts, subgr
|
|
|
4346
5123
|
edges: edges.map((edge, index) => {
|
|
4347
5124
|
const edgeStyle = { strokeWidth: 2.5 };
|
|
4348
5125
|
const edgeType = "default";
|
|
4349
|
-
const animated = true;
|
|
4350
5126
|
switch (edge.type) {
|
|
4351
5127
|
case "-->":
|
|
4352
5128
|
case "->": break;
|
|
@@ -4369,7 +5145,6 @@ function createReactFlowElements(nodes, edges, subgraphs, subgraphLayouts, subgr
|
|
|
4369
5145
|
target: targetId,
|
|
4370
5146
|
label: edge.label,
|
|
4371
5147
|
type: edgeType,
|
|
4372
|
-
animated,
|
|
4373
5148
|
style: edgeStyle,
|
|
4374
5149
|
labelStyle: {
|
|
4375
5150
|
fontSize: "12px",
|
|
@@ -4428,7 +5203,9 @@ function convertMermaidToReactFlow(_x3) {
|
|
|
4428
5203
|
function _convertMermaidToReactFlow() {
|
|
4429
5204
|
_convertMermaidToReactFlow = _asyncToGenerator(function* (mermaidCode) {
|
|
4430
5205
|
try {
|
|
4431
|
-
|
|
5206
|
+
const diagramType = detectDiagramType(mermaidCode);
|
|
5207
|
+
if (diagramType === "sequence") return convertSequenceDiagramToReactFlow(mermaidCode);
|
|
5208
|
+
if (diagramType === "c4") return convertC4MermaidToReactFlow(mermaidCode);
|
|
4432
5209
|
return convertFlowchartToReactFlow(mermaidCode);
|
|
4433
5210
|
} catch (error) {
|
|
4434
5211
|
console.error("Error converting Mermaid to React Flow:", error);
|
|
@@ -4440,6 +5217,295 @@ function _convertMermaidToReactFlow() {
|
|
|
4440
5217
|
});
|
|
4441
5218
|
return _convertMermaidToReactFlow.apply(this, arguments);
|
|
4442
5219
|
}
|
|
5220
|
+
function isSequenceDiagram(nodes) {
|
|
5221
|
+
return nodes.some((node) => node.type === "sequenceParticipant");
|
|
5222
|
+
}
|
|
5223
|
+
function fieldValue(node, componentFieldId) {
|
|
5224
|
+
var _node$data, _field$data;
|
|
5225
|
+
const fields = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.componentFields;
|
|
5226
|
+
if (!Array.isArray(fields)) return void 0;
|
|
5227
|
+
const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === componentFieldId);
|
|
5228
|
+
const value = field === null || field === void 0 || (_field$data = field.data) === null || _field$data === void 0 || (_field$data = _field$data[0]) === null || _field$data === void 0 ? void 0 : _field$data.value;
|
|
5229
|
+
if (typeof value !== "string") return void 0;
|
|
5230
|
+
if (!value.trim()) return void 0;
|
|
5231
|
+
return value;
|
|
5232
|
+
}
|
|
5233
|
+
function nodeLabel(node) {
|
|
5234
|
+
var _node$data2;
|
|
5235
|
+
const fromField = fieldValue(node, "name");
|
|
5236
|
+
if (fromField !== void 0) return fromField;
|
|
5237
|
+
const label = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.label;
|
|
5238
|
+
if (typeof label === "string") return label;
|
|
5239
|
+
return "";
|
|
5240
|
+
}
|
|
5241
|
+
function encodeLabel(text) {
|
|
5242
|
+
return text.replace(/#/g, "#").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim();
|
|
5243
|
+
}
|
|
5244
|
+
function toMermaidId(name, index, used) {
|
|
5245
|
+
const base = name.replace(/[^A-Za-z0-9_]/g, "") || `P${index}`;
|
|
5246
|
+
let candidate = base;
|
|
5247
|
+
let suffix = 2;
|
|
5248
|
+
while (used.has(candidate)) {
|
|
5249
|
+
candidate = `${base}_${suffix}`;
|
|
5250
|
+
suffix++;
|
|
5251
|
+
}
|
|
5252
|
+
used.add(candidate);
|
|
5253
|
+
return candidate;
|
|
5254
|
+
}
|
|
5255
|
+
function collectParticipants(nodes) {
|
|
5256
|
+
const used = /* @__PURE__ */ new Set();
|
|
5257
|
+
return nodes.filter((node) => node.type === "sequenceParticipant").sort((a, b) => a.position.x - b.position.x).map((node, index) => {
|
|
5258
|
+
var _node$data3, _node$data4, _node$data5, _node$data6, _node$data7;
|
|
5259
|
+
const name = nodeLabel(node) || `Participant ${index + 1}`;
|
|
5260
|
+
const rawType = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.participantType;
|
|
5261
|
+
const activations = (_node$data4 = node.data) === null || _node$data4 === void 0 ? void 0 : _node$data4.activations;
|
|
5262
|
+
const links = (_node$data5 = node.data) === null || _node$data5 === void 0 ? void 0 : _node$data5.links;
|
|
5263
|
+
const createdRow = (_node$data6 = node.data) === null || _node$data6 === void 0 ? void 0 : _node$data6.lifelineStartRow;
|
|
5264
|
+
const destroyedRow = (_node$data7 = node.data) === null || _node$data7 === void 0 ? void 0 : _node$data7.lifelineEndRow;
|
|
5265
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({
|
|
5266
|
+
nodeId: node.id,
|
|
5267
|
+
mermaidId: toMermaidId(name, index, used),
|
|
5268
|
+
name,
|
|
5269
|
+
type: typeof rawType === "string" ? rawType : "participant",
|
|
5270
|
+
links: Array.isArray(links) ? links : [],
|
|
5271
|
+
activations: Array.isArray(activations) ? activations : []
|
|
5272
|
+
}, typeof createdRow === "number" ? { createdRow } : {}), typeof destroyedRow === "number" ? { destroyedRow } : {}), {}, { x: node.position.x });
|
|
5273
|
+
});
|
|
5274
|
+
}
|
|
5275
|
+
function buildMessageLinks(edges, participantNodeIds) {
|
|
5276
|
+
const links = /* @__PURE__ */ new Map();
|
|
5277
|
+
for (const edge of edges) {
|
|
5278
|
+
if (participantNodeIds.has(edge.source)) links.set(edge.target, _objectSpread2(_objectSpread2({}, links.get(edge.target)), {}, { from: edge.source }));
|
|
5279
|
+
if (participantNodeIds.has(edge.target)) links.set(edge.source, _objectSpread2(_objectSpread2({}, links.get(edge.source)), {}, { to: edge.target }));
|
|
5280
|
+
}
|
|
5281
|
+
return links;
|
|
5282
|
+
}
|
|
5283
|
+
function arrowTokenOf(edgeFrom, edgeTo) {
|
|
5284
|
+
var _edgeTo$data$arrowTyp, _edgeTo$data, _edgeFrom$data, _edgeTo$data$half, _edgeTo$data2, _edgeFrom$data2, _edgeFrom$data3, _ref, _ref2;
|
|
5285
|
+
const arrowType = (_edgeTo$data$arrowTyp = edgeTo === null || edgeTo === void 0 || (_edgeTo$data = edgeTo.data) === null || _edgeTo$data === void 0 ? void 0 : _edgeTo$data.arrowType) !== null && _edgeTo$data$arrowTyp !== void 0 ? _edgeTo$data$arrowTyp : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data = edgeFrom.data) === null || _edgeFrom$data === void 0 ? void 0 : _edgeFrom$data.arrowType;
|
|
5286
|
+
const half = (_edgeTo$data$half = edgeTo === null || edgeTo === void 0 || (_edgeTo$data2 = edgeTo.data) === null || _edgeTo$data2 === void 0 ? void 0 : _edgeTo$data2.half) !== null && _edgeTo$data$half !== void 0 ? _edgeTo$data$half : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data2 = edgeFrom.data) === null || _edgeFrom$data2 === void 0 ? void 0 : _edgeFrom$data2.half;
|
|
5287
|
+
const reversed = (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data3 = edgeFrom.data) === null || _edgeFrom$data3 === void 0 ? void 0 : _edgeFrom$data3.reversed) === true;
|
|
5288
|
+
return findArrowTokenFor(_objectSpread2(_objectSpread2({
|
|
5289
|
+
lineStyle: (edgeTo === null || edgeTo === void 0 || (_ref = edgeTo.style) === null || _ref === void 0 ? void 0 : _ref.strokeDasharray) !== void 0 || (edgeFrom === null || edgeFrom === void 0 || (_ref2 = edgeFrom.style) === null || _ref2 === void 0 ? void 0 : _ref2.strokeDasharray) !== void 0 ? "dashed" : "solid",
|
|
5290
|
+
arrowType: arrowType !== null && arrowType !== void 0 ? arrowType : "filled"
|
|
5291
|
+
}, half ? { half } : {}), {}, { reversed }));
|
|
5292
|
+
}
|
|
5293
|
+
function noteParticipantNodeIds(note, participants, noteNode$1) {
|
|
5294
|
+
const byImportedId = (Array.isArray(note.participants) ? note.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
|
|
5295
|
+
if (byImportedId.length > 0) return byImportedId.map((participant) => participant.nodeId);
|
|
5296
|
+
if (participants.length === 0) return [];
|
|
5297
|
+
const noteCenter = noteNode$1.position.x + (Number(noteNode$1.width) || 0) / 2;
|
|
5298
|
+
return [[...participants].sort((a, b) => Math.abs(a.x - noteCenter) - Math.abs(b.x - noteCenter))[0].nodeId];
|
|
5299
|
+
}
|
|
5300
|
+
function collectRowItems(nodes, edges, participants) {
|
|
5301
|
+
const participantNodeIds = new Set(participants.map((p) => p.nodeId));
|
|
5302
|
+
const links = buildMessageLinks(edges, participantNodeIds);
|
|
5303
|
+
const items = [];
|
|
5304
|
+
for (const node of nodes) {
|
|
5305
|
+
var _node$data8, _node$data9, _edgeFrom$data4, _edgeTo$data3;
|
|
5306
|
+
if (participantNodeIds.has(node.id)) continue;
|
|
5307
|
+
const note = (_node$data8 = node.data) === null || _node$data8 === void 0 ? void 0 : _node$data8.sequenceNote;
|
|
5308
|
+
if (note) {
|
|
5309
|
+
var _note$placement;
|
|
5310
|
+
items.push({
|
|
5311
|
+
item: {
|
|
5312
|
+
kind: "note",
|
|
5313
|
+
nodeId: node.id,
|
|
5314
|
+
text: nodeLabel(node),
|
|
5315
|
+
placement: (_note$placement = note.placement) !== null && _note$placement !== void 0 ? _note$placement : "over",
|
|
5316
|
+
participantNodeIds: noteParticipantNodeIds(note, participants, node)
|
|
5317
|
+
},
|
|
5318
|
+
y: node.position.y
|
|
5319
|
+
});
|
|
5320
|
+
continue;
|
|
5321
|
+
}
|
|
5322
|
+
const link = links.get(node.id);
|
|
5323
|
+
if (!(link === null || link === void 0 ? void 0 : link.from) || !link.to) continue;
|
|
5324
|
+
const edgeFrom = edges.find((edge) => edge.target === node.id && edge.source === link.from);
|
|
5325
|
+
const edgeTo = edges.find((edge) => edge.source === node.id && edge.target === link.to);
|
|
5326
|
+
const sequenceNumber = (_node$data9 = node.data) === null || _node$data9 === void 0 ? void 0 : _node$data9.sequenceNumber;
|
|
5327
|
+
items.push({
|
|
5328
|
+
item: _objectSpread2({
|
|
5329
|
+
kind: "message",
|
|
5330
|
+
nodeId: node.id,
|
|
5331
|
+
fromNodeId: link.from,
|
|
5332
|
+
toNodeId: link.to,
|
|
5333
|
+
label: nodeLabel(node),
|
|
5334
|
+
token: arrowTokenOf(edgeFrom, edgeTo),
|
|
5335
|
+
centralSource: (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data4 = edgeFrom.data) === null || _edgeFrom$data4 === void 0 ? void 0 : _edgeFrom$data4.centralSource) === true,
|
|
5336
|
+
centralTarget: (edgeTo === null || edgeTo === void 0 || (_edgeTo$data3 = edgeTo.data) === null || _edgeTo$data3 === void 0 ? void 0 : _edgeTo$data3.centralTarget) === true
|
|
5337
|
+
}, typeof sequenceNumber === "number" ? { sequenceNumber } : {}),
|
|
5338
|
+
y: node.position.y
|
|
5339
|
+
});
|
|
5340
|
+
}
|
|
5341
|
+
return items.sort((a, b) => a.y - b.y).map((entry) => entry.item);
|
|
5342
|
+
}
|
|
5343
|
+
function collectBlocks(nodes) {
|
|
5344
|
+
const blocks = [];
|
|
5345
|
+
for (const node of nodes) {
|
|
5346
|
+
var _node$data10, _block$type, _block$label, _block$depth, _block$sections;
|
|
5347
|
+
const block = (_node$data10 = node.data) === null || _node$data10 === void 0 ? void 0 : _node$data10.sequenceBlock;
|
|
5348
|
+
if (!block) continue;
|
|
5349
|
+
if (typeof block.startRow !== "number") continue;
|
|
5350
|
+
if (typeof block.endRow !== "number") continue;
|
|
5351
|
+
blocks.push(_objectSpread2(_objectSpread2({
|
|
5352
|
+
type: (_block$type = block.type) !== null && _block$type !== void 0 ? _block$type : "rect",
|
|
5353
|
+
label: (_block$label = block.label) !== null && _block$label !== void 0 ? _block$label : ""
|
|
5354
|
+
}, block.color ? { color: block.color } : {}), {}, {
|
|
5355
|
+
depth: (_block$depth = block.depth) !== null && _block$depth !== void 0 ? _block$depth : 0,
|
|
5356
|
+
startRow: block.startRow,
|
|
5357
|
+
endRow: block.endRow,
|
|
5358
|
+
sections: ((_block$sections = block.sections) !== null && _block$sections !== void 0 ? _block$sections : []).filter((section) => typeof section.startRow === "number" && typeof section.endRow === "number").map((section) => {
|
|
5359
|
+
var _section$label;
|
|
5360
|
+
return {
|
|
5361
|
+
label: (_section$label = section.label) !== null && _section$label !== void 0 ? _section$label : "",
|
|
5362
|
+
startRow: section.startRow,
|
|
5363
|
+
endRow: section.endRow
|
|
5364
|
+
};
|
|
5365
|
+
})
|
|
5366
|
+
}));
|
|
5367
|
+
}
|
|
5368
|
+
return blocks;
|
|
5369
|
+
}
|
|
5370
|
+
function collectBoxes(nodes, participants) {
|
|
5371
|
+
const boxes = [];
|
|
5372
|
+
for (const node of nodes) {
|
|
5373
|
+
var _node$data11, _node$data12, _box$label;
|
|
5374
|
+
const box = (_node$data11 = node.data) === null || _node$data11 === void 0 ? void 0 : _node$data11.sequenceBox;
|
|
5375
|
+
if (!box) continue;
|
|
5376
|
+
const byImportedId = (Array.isArray(box.participants) ? box.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
|
|
5377
|
+
const left = node.position.x;
|
|
5378
|
+
const right = node.position.x + (Number(node.width) || 0);
|
|
5379
|
+
const contained = byImportedId.length > 0 ? byImportedId : participants.filter((participant) => participant.x >= left && participant.x <= right);
|
|
5380
|
+
if (contained.length === 0) continue;
|
|
5381
|
+
const backgroundColor = (_node$data12 = node.data) === null || _node$data12 === void 0 ? void 0 : _node$data12.backgroundColor;
|
|
5382
|
+
boxes.push(_objectSpread2(_objectSpread2({ label: (_box$label = box.label) !== null && _box$label !== void 0 ? _box$label : "" }, typeof backgroundColor === "string" ? { color: backgroundColor } : {}), {}, { participantNodeIds: contained.map((participant) => participant.nodeId) }));
|
|
5383
|
+
}
|
|
5384
|
+
return boxes;
|
|
5385
|
+
}
|
|
5386
|
+
function participantDeclaration(participant, keyword) {
|
|
5387
|
+
const stereotype = participant.type === "participant" || participant.type === "actor" ? "" : `@{ "type": "${participant.type}" }`;
|
|
5388
|
+
const alias = participant.mermaidId === participant.name ? "" : ` as ${encodeLabel(participant.name)}`;
|
|
5389
|
+
return `${keyword} ${participant.mermaidId}${stereotype}${alias}`;
|
|
5390
|
+
}
|
|
5391
|
+
function convertReactFlowToSequenceMermaid(nodes, edges) {
|
|
5392
|
+
const participants = collectParticipants(nodes);
|
|
5393
|
+
const items = collectRowItems(nodes, edges, participants);
|
|
5394
|
+
const blocks = collectBlocks(nodes);
|
|
5395
|
+
const boxes = collectBoxes(nodes, participants);
|
|
5396
|
+
const participantByNodeId = new Map(participants.map((participant) => [participant.nodeId, participant]));
|
|
5397
|
+
const rowByItemId = /* @__PURE__ */ new Map();
|
|
5398
|
+
const lastRowByItemId = /* @__PURE__ */ new Map();
|
|
5399
|
+
let row = 0;
|
|
5400
|
+
for (const item of items) {
|
|
5401
|
+
rowByItemId.set(item.nodeId, row);
|
|
5402
|
+
const isSelf = item.kind === "message" && item.fromNodeId === item.toNodeId;
|
|
5403
|
+
lastRowByItemId.set(item.nodeId, isSelf ? row + 1 : row);
|
|
5404
|
+
row += isSelf ? 2 : 1;
|
|
5405
|
+
}
|
|
5406
|
+
const rowCount = row;
|
|
5407
|
+
const lines = ["sequenceDiagram"];
|
|
5408
|
+
const titleNode = nodes.find((node) => node.id === "sequence-title");
|
|
5409
|
+
if (titleNode) {
|
|
5410
|
+
var _fieldValue;
|
|
5411
|
+
const text = (_fieldValue = fieldValue(titleNode, "text")) !== null && _fieldValue !== void 0 ? _fieldValue : nodeLabel(titleNode);
|
|
5412
|
+
if (text) lines.push(` title ${encodeLabel(text)}`);
|
|
5413
|
+
}
|
|
5414
|
+
const boxByFirstParticipant = /* @__PURE__ */ new Map();
|
|
5415
|
+
const boxEndByParticipant = /* @__PURE__ */ new Map();
|
|
5416
|
+
for (const box of boxes) {
|
|
5417
|
+
var _boxEndByParticipant$;
|
|
5418
|
+
const ordered = participants.filter((participant) => box.participantNodeIds.includes(participant.nodeId));
|
|
5419
|
+
if (ordered.length === 0) continue;
|
|
5420
|
+
boxByFirstParticipant.set(ordered[0].nodeId, box);
|
|
5421
|
+
boxEndByParticipant.set(ordered[ordered.length - 1].nodeId, ((_boxEndByParticipant$ = boxEndByParticipant.get(ordered[ordered.length - 1].nodeId)) !== null && _boxEndByParticipant$ !== void 0 ? _boxEndByParticipant$ : 0) + 1);
|
|
5422
|
+
}
|
|
5423
|
+
for (const participant of participants) {
|
|
5424
|
+
var _boxEndByParticipant$2;
|
|
5425
|
+
const box = boxByFirstParticipant.get(participant.nodeId);
|
|
5426
|
+
if (box) {
|
|
5427
|
+
const color = box.color ? `${box.color} ` : "";
|
|
5428
|
+
lines.push(` box ${color}${encodeLabel(box.label)}`.trimEnd());
|
|
5429
|
+
}
|
|
5430
|
+
if (participant.createdRow === void 0) {
|
|
5431
|
+
const keyword = participant.type === "actor" ? "actor" : "participant";
|
|
5432
|
+
lines.push(` ${participantDeclaration(participant, keyword)}`);
|
|
5433
|
+
}
|
|
5434
|
+
const boxEnds = (_boxEndByParticipant$2 = boxEndByParticipant.get(participant.nodeId)) !== null && _boxEndByParticipant$2 !== void 0 ? _boxEndByParticipant$2 : 0;
|
|
5435
|
+
for (let index = 0; index < boxEnds; index++) lines.push(" end");
|
|
5436
|
+
}
|
|
5437
|
+
for (const participant of participants) for (const link of participant.links) lines.push(` link ${participant.mermaidId}: ${link.label} @ ${link.url}`);
|
|
5438
|
+
const numbered = items.filter((item) => item.kind === "message" && item.sequenceNumber !== void 0);
|
|
5439
|
+
if (numbered.length > 0) {
|
|
5440
|
+
const start = numbered[0].sequenceNumber;
|
|
5441
|
+
const step = numbered.length > 1 ? numbered[1].sequenceNumber - numbered[0].sequenceNumber : 1;
|
|
5442
|
+
lines.push(` autonumber ${start} ${step}`);
|
|
5443
|
+
}
|
|
5444
|
+
const openBlocks = [];
|
|
5445
|
+
function indent() {
|
|
5446
|
+
return " ".repeat(openBlocks.length + 1);
|
|
5447
|
+
}
|
|
5448
|
+
for (let currentRow = 0; currentRow < rowCount; currentRow++) {
|
|
5449
|
+
const opening = blocks.filter((block) => block.startRow === currentRow).sort((a, b) => a.depth - b.depth);
|
|
5450
|
+
for (const block of opening) {
|
|
5451
|
+
const label = encodeLabel(block.label);
|
|
5452
|
+
const color = block.type === "rect" && block.color ? `${block.color} ` : "";
|
|
5453
|
+
lines.push(`${indent()}${block.type} ${color}${label}`.trimEnd());
|
|
5454
|
+
openBlocks.push(block);
|
|
5455
|
+
}
|
|
5456
|
+
for (const [depth, block] of openBlocks.entries()) for (const section of block.sections.slice(1)) {
|
|
5457
|
+
if (section.startRow !== currentRow) continue;
|
|
5458
|
+
const keyword = block.type === "par" ? "and" : block.type === "critical" ? "option" : "else";
|
|
5459
|
+
lines.push(`${" ".repeat(depth + 1)}${keyword} ${encodeLabel(section.label)}`.trimEnd());
|
|
5460
|
+
}
|
|
5461
|
+
const item = items.find((entry) => rowByItemId.get(entry.nodeId) === currentRow);
|
|
5462
|
+
if (item) {
|
|
5463
|
+
for (const participant of participants) {
|
|
5464
|
+
if (participant.createdRow !== currentRow) continue;
|
|
5465
|
+
const keyword = participant.type === "actor" ? "actor" : "participant";
|
|
5466
|
+
lines.push(`${indent()}create ${participantDeclaration(participant, keyword)}`);
|
|
5467
|
+
}
|
|
5468
|
+
for (const participant of participants) {
|
|
5469
|
+
if (participant.destroyedRow !== currentRow) continue;
|
|
5470
|
+
lines.push(`${indent()}destroy ${participant.mermaidId}`);
|
|
5471
|
+
}
|
|
5472
|
+
for (const participant of participants) for (const activation of participant.activations) {
|
|
5473
|
+
if (activation.startRow !== currentRow) continue;
|
|
5474
|
+
lines.push(`${indent()}activate ${participant.mermaidId}`);
|
|
5475
|
+
}
|
|
5476
|
+
if (item.kind === "message") {
|
|
5477
|
+
const from = participantByNodeId.get(item.fromNodeId);
|
|
5478
|
+
const to = participantByNodeId.get(item.toNodeId);
|
|
5479
|
+
if (from && to) {
|
|
5480
|
+
const source = item.centralSource ? `${from.mermaidId}()` : from.mermaidId;
|
|
5481
|
+
const target = item.centralTarget ? `()${to.mermaidId}` : to.mermaidId;
|
|
5482
|
+
lines.push(`${indent()}${source}${item.token}${target}: ${encodeLabel(item.label)}`);
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
5485
|
+
if (item.kind === "note") {
|
|
5486
|
+
const names = item.participantNodeIds.map((nodeId) => {
|
|
5487
|
+
var _participantByNodeId$;
|
|
5488
|
+
return (_participantByNodeId$ = participantByNodeId.get(nodeId)) === null || _participantByNodeId$ === void 0 ? void 0 : _participantByNodeId$.mermaidId;
|
|
5489
|
+
}).filter((id) => id !== void 0);
|
|
5490
|
+
if (names.length > 0) lines.push(`${indent()}Note ${item.placement} ${names.join(",")}: ${encodeLabel(item.text)}`);
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
const rowEnd = item ? lastRowByItemId.get(item.nodeId) : currentRow;
|
|
5494
|
+
for (const participant of participants) for (const activation of participant.activations) {
|
|
5495
|
+
if (activation.endRow !== rowEnd) continue;
|
|
5496
|
+
lines.push(`${indent()}deactivate ${participant.mermaidId}`);
|
|
5497
|
+
}
|
|
5498
|
+
while (openBlocks.length > 0 && openBlocks[openBlocks.length - 1].endRow <= rowEnd) {
|
|
5499
|
+
openBlocks.pop();
|
|
5500
|
+
lines.push(`${indent()}end`);
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
while (openBlocks.length > 0) {
|
|
5504
|
+
openBlocks.pop();
|
|
5505
|
+
lines.push(`${indent()}end`);
|
|
5506
|
+
}
|
|
5507
|
+
return lines.join("\n");
|
|
5508
|
+
}
|
|
4443
5509
|
const BOUND_PADDING = 20;
|
|
4444
5510
|
function createGroupNode(options) {
|
|
4445
5511
|
var _options$id, _options$name;
|
|
@@ -4762,6 +5828,7 @@ function _convertMermaidToReactFlowWithContext() {
|
|
|
4762
5828
|
if ((_ctx$style = ctx.style) === null || _ctx$style === void 0 ? void 0 : _ctx$style.height) clonedNode.height = ctx.style.height;
|
|
4763
5829
|
if ((_ctx$style2 = ctx.style) === null || _ctx$style2 === void 0 ? void 0 : _ctx$style2.width) clonedNode.width = ctx.style.width;
|
|
4764
5830
|
clonedNode.data = _objectSpread2(_objectSpread2(_objectSpread2({}, clonedNode.data), objectPick((_ctx$style3 = ctx.style) !== null && _ctx$style3 !== void 0 ? _ctx$style3 : {}, [
|
|
5831
|
+
"color",
|
|
4765
5832
|
"fill",
|
|
4766
5833
|
"stroke",
|
|
4767
5834
|
"strokeWidth",
|
|
@@ -4818,6 +5885,10 @@ function _convertMermaidToReactFlowWithContext() {
|
|
|
4818
5885
|
if (nodeParent) return _objectSpread2(_objectSpread2({}, node), {}, { parentId: nodeParent.id });
|
|
4819
5886
|
return node;
|
|
4820
5887
|
})];
|
|
5888
|
+
if (isSequenceDiagram(combinedNodes)) return {
|
|
5889
|
+
edges: resolvedEdges,
|
|
5890
|
+
nodes: combinedNodes
|
|
5891
|
+
};
|
|
4821
5892
|
return {
|
|
4822
5893
|
edges: resolvedEdges,
|
|
4823
5894
|
nodes: (options === null || options === void 0 ? void 0 : options.repositionNodes) ? resizeNodesLayouts(combinedNodes) : combinedNodes
|
|
@@ -5431,20 +6502,16 @@ function resolveMermaidDetailedNodeLabel(node) {
|
|
|
5431
6502
|
]);
|
|
5432
6503
|
}
|
|
5433
6504
|
if (nodeType === "sequenceParticipant") {
|
|
5434
|
-
var _getFieldString4
|
|
6505
|
+
var _getFieldString4;
|
|
5435
6506
|
const label = (_getFieldString4 = getFieldString(componentFields, "Label")) !== null && _getFieldString4 !== void 0 ? _getFieldString4 : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.label);
|
|
5436
6507
|
const participantName = name !== null && name !== void 0 ? name : label;
|
|
5437
6508
|
const rowCount = typeof (nodeData === null || nodeData === void 0 ? void 0 : nodeData.rowCount) === "number" ? nodeData.rowCount : void 0;
|
|
5438
|
-
const color =
|
|
6509
|
+
const color = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.color);
|
|
5439
6510
|
return buildDetailedLabel([
|
|
5440
6511
|
participantName ? `SequenceParticipant: ${participantName}` : "SequenceParticipant",
|
|
5441
6512
|
...typeof rowCount === "number" ? [`rows: ${rowCount}`] : [],
|
|
5442
6513
|
...color ? [`color: ${color}`] : [],
|
|
5443
|
-
...buildFieldLines(componentFields, new Set([
|
|
5444
|
-
"name",
|
|
5445
|
-
"label",
|
|
5446
|
-
"color"
|
|
5447
|
-
]))
|
|
6514
|
+
...buildFieldLines(componentFields, new Set(["name", "label"]))
|
|
5448
6515
|
]);
|
|
5449
6516
|
}
|
|
5450
6517
|
if (nodeType === "comment") return buildDetailedLabel([`Comment: ${(typeof (nodeData === null || nodeData === void 0 ? void 0 : nodeData.isResolved) === "boolean" ? nodeData.isResolved : void 0) ? "Resolved" : "Open"}`, ...buildFieldLines(componentFields, new Set(["name"]))]);
|
|
@@ -5524,4 +6591,4 @@ function convertUiGraphToMermaid(input, options) {
|
|
|
5524
6591
|
context
|
|
5525
6592
|
};
|
|
5526
6593
|
}
|
|
5527
|
-
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT,
|
|
6594
|
+
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, C4_COLORS, C4_LAYOUT, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT, SqlToAstParser, buildMetaData, contextSchema, convertC4MermaidToReactFlow, convertC4ToReactFlow, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertReactFlowToSequenceMermaid, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, getC4ElementColors, isC4Diagram, isSequenceDiagram, parseC4Diagram, sanitizeMermaidLabels, syncBaseData };
|