@uigraph/sdk 1.2.2 → 1.2.4

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/index.cjs CHANGED
@@ -2200,6 +2200,14 @@ const ARROW_TOKENS = [
2200
2200
  arrowType: "none"
2201
2201
  }
2202
2202
  ];
2203
+ function findArrowTokenFor(options) {
2204
+ const exact = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType && candidate.half === options.half && Boolean(candidate.reversed) === Boolean(options.reversed));
2205
+ if (exact) return exact.token;
2206
+ const byHead = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType);
2207
+ if (byHead) return byHead.token;
2208
+ if (options.lineStyle === "dashed") return "-->>";
2209
+ return "->>";
2210
+ }
2203
2211
  const BLOCK_OPENERS = [
2204
2212
  "loop",
2205
2213
  "alt",
@@ -3075,7 +3083,13 @@ function convertSequenceDiagramToReactFlow(mermaidCode) {
3075
3083
  },
3076
3084
  data: {
3077
3085
  source: "mermaid",
3078
- componentFields: [generateComponentFieldNameInput(data.title)]
3086
+ componentFields: [generateComponentFieldInput({
3087
+ componentFieldId: "text",
3088
+ label: "Text",
3089
+ type: require_component_type.ComponentInputType.TextBox,
3090
+ data: data.title,
3091
+ isReadonly: true
3092
+ })]
3079
3093
  }
3080
3094
  });
3081
3095
  return {
@@ -4441,6 +4455,295 @@ function _convertMermaidToReactFlow() {
4441
4455
  });
4442
4456
  return _convertMermaidToReactFlow.apply(this, arguments);
4443
4457
  }
4458
+ function isSequenceDiagram(nodes) {
4459
+ return nodes.some((node) => node.type === "sequenceParticipant");
4460
+ }
4461
+ function fieldValue(node, componentFieldId) {
4462
+ var _node$data, _field$data;
4463
+ const fields = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.componentFields;
4464
+ if (!Array.isArray(fields)) return void 0;
4465
+ const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === componentFieldId);
4466
+ 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;
4467
+ if (typeof value !== "string") return void 0;
4468
+ if (!value.trim()) return void 0;
4469
+ return value;
4470
+ }
4471
+ function nodeLabel(node) {
4472
+ var _node$data2;
4473
+ const fromField = fieldValue(node, "name");
4474
+ if (fromField !== void 0) return fromField;
4475
+ const label = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.label;
4476
+ if (typeof label === "string") return label;
4477
+ return "";
4478
+ }
4479
+ function encodeLabel(text) {
4480
+ return text.replace(/#/g, "&#35;").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim();
4481
+ }
4482
+ function toMermaidId(name, index, used) {
4483
+ const base = name.replace(/[^A-Za-z0-9_]/g, "") || `P${index}`;
4484
+ let candidate = base;
4485
+ let suffix = 2;
4486
+ while (used.has(candidate)) {
4487
+ candidate = `${base}_${suffix}`;
4488
+ suffix++;
4489
+ }
4490
+ used.add(candidate);
4491
+ return candidate;
4492
+ }
4493
+ function collectParticipants(nodes) {
4494
+ const used = /* @__PURE__ */ new Set();
4495
+ return nodes.filter((node) => node.type === "sequenceParticipant").sort((a, b) => a.position.x - b.position.x).map((node, index) => {
4496
+ var _node$data3, _node$data4, _node$data5, _node$data6, _node$data7;
4497
+ const name = nodeLabel(node) || `Participant ${index + 1}`;
4498
+ const rawType = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.participantType;
4499
+ const activations = (_node$data4 = node.data) === null || _node$data4 === void 0 ? void 0 : _node$data4.activations;
4500
+ const links = (_node$data5 = node.data) === null || _node$data5 === void 0 ? void 0 : _node$data5.links;
4501
+ const createdRow = (_node$data6 = node.data) === null || _node$data6 === void 0 ? void 0 : _node$data6.lifelineStartRow;
4502
+ const destroyedRow = (_node$data7 = node.data) === null || _node$data7 === void 0 ? void 0 : _node$data7.lifelineEndRow;
4503
+ return _objectSpread2(_objectSpread2(_objectSpread2({
4504
+ nodeId: node.id,
4505
+ mermaidId: toMermaidId(name, index, used),
4506
+ name,
4507
+ type: typeof rawType === "string" ? rawType : "participant",
4508
+ links: Array.isArray(links) ? links : [],
4509
+ activations: Array.isArray(activations) ? activations : []
4510
+ }, typeof createdRow === "number" ? { createdRow } : {}), typeof destroyedRow === "number" ? { destroyedRow } : {}), {}, { x: node.position.x });
4511
+ });
4512
+ }
4513
+ function buildMessageLinks(edges, participantNodeIds) {
4514
+ const links = /* @__PURE__ */ new Map();
4515
+ for (const edge of edges) {
4516
+ if (participantNodeIds.has(edge.source)) links.set(edge.target, _objectSpread2(_objectSpread2({}, links.get(edge.target)), {}, { from: edge.source }));
4517
+ if (participantNodeIds.has(edge.target)) links.set(edge.source, _objectSpread2(_objectSpread2({}, links.get(edge.source)), {}, { to: edge.target }));
4518
+ }
4519
+ return links;
4520
+ }
4521
+ function arrowTokenOf(edgeFrom, edgeTo) {
4522
+ var _edgeTo$data$arrowTyp, _edgeTo$data, _edgeFrom$data, _edgeTo$data$half, _edgeTo$data2, _edgeFrom$data2, _edgeFrom$data3, _ref, _ref2;
4523
+ 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;
4524
+ 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;
4525
+ const reversed = (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data3 = edgeFrom.data) === null || _edgeFrom$data3 === void 0 ? void 0 : _edgeFrom$data3.reversed) === true;
4526
+ return findArrowTokenFor(_objectSpread2(_objectSpread2({
4527
+ 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",
4528
+ arrowType: arrowType !== null && arrowType !== void 0 ? arrowType : "filled"
4529
+ }, half ? { half } : {}), {}, { reversed }));
4530
+ }
4531
+ function noteParticipantNodeIds(note, participants, noteNode$1) {
4532
+ 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));
4533
+ if (byImportedId.length > 0) return byImportedId.map((participant) => participant.nodeId);
4534
+ if (participants.length === 0) return [];
4535
+ const noteCenter = noteNode$1.position.x + (Number(noteNode$1.width) || 0) / 2;
4536
+ return [[...participants].sort((a, b) => Math.abs(a.x - noteCenter) - Math.abs(b.x - noteCenter))[0].nodeId];
4537
+ }
4538
+ function collectRowItems(nodes, edges, participants) {
4539
+ const participantNodeIds = new Set(participants.map((p) => p.nodeId));
4540
+ const links = buildMessageLinks(edges, participantNodeIds);
4541
+ const items = [];
4542
+ for (const node of nodes) {
4543
+ var _node$data8, _node$data9, _edgeFrom$data4, _edgeTo$data3;
4544
+ if (participantNodeIds.has(node.id)) continue;
4545
+ const note = (_node$data8 = node.data) === null || _node$data8 === void 0 ? void 0 : _node$data8.sequenceNote;
4546
+ if (note) {
4547
+ var _note$placement;
4548
+ items.push({
4549
+ item: {
4550
+ kind: "note",
4551
+ nodeId: node.id,
4552
+ text: nodeLabel(node),
4553
+ placement: (_note$placement = note.placement) !== null && _note$placement !== void 0 ? _note$placement : "over",
4554
+ participantNodeIds: noteParticipantNodeIds(note, participants, node)
4555
+ },
4556
+ y: node.position.y
4557
+ });
4558
+ continue;
4559
+ }
4560
+ const link = links.get(node.id);
4561
+ if (!(link === null || link === void 0 ? void 0 : link.from) || !link.to) continue;
4562
+ const edgeFrom = edges.find((edge) => edge.target === node.id && edge.source === link.from);
4563
+ const edgeTo = edges.find((edge) => edge.source === node.id && edge.target === link.to);
4564
+ const sequenceNumber = (_node$data9 = node.data) === null || _node$data9 === void 0 ? void 0 : _node$data9.sequenceNumber;
4565
+ items.push({
4566
+ item: _objectSpread2({
4567
+ kind: "message",
4568
+ nodeId: node.id,
4569
+ fromNodeId: link.from,
4570
+ toNodeId: link.to,
4571
+ label: nodeLabel(node),
4572
+ token: arrowTokenOf(edgeFrom, edgeTo),
4573
+ centralSource: (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data4 = edgeFrom.data) === null || _edgeFrom$data4 === void 0 ? void 0 : _edgeFrom$data4.centralSource) === true,
4574
+ centralTarget: (edgeTo === null || edgeTo === void 0 || (_edgeTo$data3 = edgeTo.data) === null || _edgeTo$data3 === void 0 ? void 0 : _edgeTo$data3.centralTarget) === true
4575
+ }, typeof sequenceNumber === "number" ? { sequenceNumber } : {}),
4576
+ y: node.position.y
4577
+ });
4578
+ }
4579
+ return items.sort((a, b) => a.y - b.y).map((entry) => entry.item);
4580
+ }
4581
+ function collectBlocks(nodes) {
4582
+ const blocks = [];
4583
+ for (const node of nodes) {
4584
+ var _node$data10, _block$type, _block$label, _block$depth, _block$sections;
4585
+ const block = (_node$data10 = node.data) === null || _node$data10 === void 0 ? void 0 : _node$data10.sequenceBlock;
4586
+ if (!block) continue;
4587
+ if (typeof block.startRow !== "number") continue;
4588
+ if (typeof block.endRow !== "number") continue;
4589
+ blocks.push(_objectSpread2(_objectSpread2({
4590
+ type: (_block$type = block.type) !== null && _block$type !== void 0 ? _block$type : "rect",
4591
+ label: (_block$label = block.label) !== null && _block$label !== void 0 ? _block$label : ""
4592
+ }, block.color ? { color: block.color } : {}), {}, {
4593
+ depth: (_block$depth = block.depth) !== null && _block$depth !== void 0 ? _block$depth : 0,
4594
+ startRow: block.startRow,
4595
+ endRow: block.endRow,
4596
+ sections: ((_block$sections = block.sections) !== null && _block$sections !== void 0 ? _block$sections : []).filter((section) => typeof section.startRow === "number" && typeof section.endRow === "number").map((section) => {
4597
+ var _section$label;
4598
+ return {
4599
+ label: (_section$label = section.label) !== null && _section$label !== void 0 ? _section$label : "",
4600
+ startRow: section.startRow,
4601
+ endRow: section.endRow
4602
+ };
4603
+ })
4604
+ }));
4605
+ }
4606
+ return blocks;
4607
+ }
4608
+ function collectBoxes(nodes, participants) {
4609
+ const boxes = [];
4610
+ for (const node of nodes) {
4611
+ var _node$data11, _node$data12, _box$label;
4612
+ const box = (_node$data11 = node.data) === null || _node$data11 === void 0 ? void 0 : _node$data11.sequenceBox;
4613
+ if (!box) continue;
4614
+ 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));
4615
+ const left = node.position.x;
4616
+ const right = node.position.x + (Number(node.width) || 0);
4617
+ const contained = byImportedId.length > 0 ? byImportedId : participants.filter((participant) => participant.x >= left && participant.x <= right);
4618
+ if (contained.length === 0) continue;
4619
+ const backgroundColor = (_node$data12 = node.data) === null || _node$data12 === void 0 ? void 0 : _node$data12.backgroundColor;
4620
+ 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) }));
4621
+ }
4622
+ return boxes;
4623
+ }
4624
+ function participantDeclaration(participant, keyword) {
4625
+ const stereotype = participant.type === "participant" || participant.type === "actor" ? "" : `@{ "type": "${participant.type}" }`;
4626
+ const alias = participant.mermaidId === participant.name ? "" : ` as ${encodeLabel(participant.name)}`;
4627
+ return `${keyword} ${participant.mermaidId}${stereotype}${alias}`;
4628
+ }
4629
+ function convertReactFlowToSequenceMermaid(nodes, edges) {
4630
+ const participants = collectParticipants(nodes);
4631
+ const items = collectRowItems(nodes, edges, participants);
4632
+ const blocks = collectBlocks(nodes);
4633
+ const boxes = collectBoxes(nodes, participants);
4634
+ const participantByNodeId = new Map(participants.map((participant) => [participant.nodeId, participant]));
4635
+ const rowByItemId = /* @__PURE__ */ new Map();
4636
+ const lastRowByItemId = /* @__PURE__ */ new Map();
4637
+ let row = 0;
4638
+ for (const item of items) {
4639
+ rowByItemId.set(item.nodeId, row);
4640
+ const isSelf = item.kind === "message" && item.fromNodeId === item.toNodeId;
4641
+ lastRowByItemId.set(item.nodeId, isSelf ? row + 1 : row);
4642
+ row += isSelf ? 2 : 1;
4643
+ }
4644
+ const rowCount = row;
4645
+ const lines = ["sequenceDiagram"];
4646
+ const titleNode = nodes.find((node) => node.id === "sequence-title");
4647
+ if (titleNode) {
4648
+ var _fieldValue;
4649
+ const text = (_fieldValue = fieldValue(titleNode, "text")) !== null && _fieldValue !== void 0 ? _fieldValue : nodeLabel(titleNode);
4650
+ if (text) lines.push(` title ${encodeLabel(text)}`);
4651
+ }
4652
+ const boxByFirstParticipant = /* @__PURE__ */ new Map();
4653
+ const boxEndByParticipant = /* @__PURE__ */ new Map();
4654
+ for (const box of boxes) {
4655
+ var _boxEndByParticipant$;
4656
+ const ordered = participants.filter((participant) => box.participantNodeIds.includes(participant.nodeId));
4657
+ if (ordered.length === 0) continue;
4658
+ boxByFirstParticipant.set(ordered[0].nodeId, box);
4659
+ boxEndByParticipant.set(ordered[ordered.length - 1].nodeId, ((_boxEndByParticipant$ = boxEndByParticipant.get(ordered[ordered.length - 1].nodeId)) !== null && _boxEndByParticipant$ !== void 0 ? _boxEndByParticipant$ : 0) + 1);
4660
+ }
4661
+ for (const participant of participants) {
4662
+ var _boxEndByParticipant$2;
4663
+ const box = boxByFirstParticipant.get(participant.nodeId);
4664
+ if (box) {
4665
+ const color = box.color ? `${box.color} ` : "";
4666
+ lines.push(` box ${color}${encodeLabel(box.label)}`.trimEnd());
4667
+ }
4668
+ if (participant.createdRow === void 0) {
4669
+ const keyword = participant.type === "actor" ? "actor" : "participant";
4670
+ lines.push(` ${participantDeclaration(participant, keyword)}`);
4671
+ }
4672
+ const boxEnds = (_boxEndByParticipant$2 = boxEndByParticipant.get(participant.nodeId)) !== null && _boxEndByParticipant$2 !== void 0 ? _boxEndByParticipant$2 : 0;
4673
+ for (let index = 0; index < boxEnds; index++) lines.push(" end");
4674
+ }
4675
+ for (const participant of participants) for (const link of participant.links) lines.push(` link ${participant.mermaidId}: ${link.label} @ ${link.url}`);
4676
+ const numbered = items.filter((item) => item.kind === "message" && item.sequenceNumber !== void 0);
4677
+ if (numbered.length > 0) {
4678
+ const start = numbered[0].sequenceNumber;
4679
+ const step = numbered.length > 1 ? numbered[1].sequenceNumber - numbered[0].sequenceNumber : 1;
4680
+ lines.push(` autonumber ${start} ${step}`);
4681
+ }
4682
+ const openBlocks = [];
4683
+ function indent() {
4684
+ return " ".repeat(openBlocks.length + 1);
4685
+ }
4686
+ for (let currentRow = 0; currentRow < rowCount; currentRow++) {
4687
+ const opening = blocks.filter((block) => block.startRow === currentRow).sort((a, b) => a.depth - b.depth);
4688
+ for (const block of opening) {
4689
+ const label = encodeLabel(block.label);
4690
+ const color = block.type === "rect" && block.color ? `${block.color} ` : "";
4691
+ lines.push(`${indent()}${block.type} ${color}${label}`.trimEnd());
4692
+ openBlocks.push(block);
4693
+ }
4694
+ for (const [depth, block] of openBlocks.entries()) for (const section of block.sections.slice(1)) {
4695
+ if (section.startRow !== currentRow) continue;
4696
+ const keyword = block.type === "par" ? "and" : block.type === "critical" ? "option" : "else";
4697
+ lines.push(`${" ".repeat(depth + 1)}${keyword} ${encodeLabel(section.label)}`.trimEnd());
4698
+ }
4699
+ const item = items.find((entry) => rowByItemId.get(entry.nodeId) === currentRow);
4700
+ if (item) {
4701
+ for (const participant of participants) {
4702
+ if (participant.createdRow !== currentRow) continue;
4703
+ const keyword = participant.type === "actor" ? "actor" : "participant";
4704
+ lines.push(`${indent()}create ${participantDeclaration(participant, keyword)}`);
4705
+ }
4706
+ for (const participant of participants) {
4707
+ if (participant.destroyedRow !== currentRow) continue;
4708
+ lines.push(`${indent()}destroy ${participant.mermaidId}`);
4709
+ }
4710
+ for (const participant of participants) for (const activation of participant.activations) {
4711
+ if (activation.startRow !== currentRow) continue;
4712
+ lines.push(`${indent()}activate ${participant.mermaidId}`);
4713
+ }
4714
+ if (item.kind === "message") {
4715
+ const from = participantByNodeId.get(item.fromNodeId);
4716
+ const to = participantByNodeId.get(item.toNodeId);
4717
+ if (from && to) {
4718
+ const source = item.centralSource ? `${from.mermaidId}()` : from.mermaidId;
4719
+ const target = item.centralTarget ? `()${to.mermaidId}` : to.mermaidId;
4720
+ lines.push(`${indent()}${source}${item.token}${target}: ${encodeLabel(item.label)}`);
4721
+ }
4722
+ }
4723
+ if (item.kind === "note") {
4724
+ const names = item.participantNodeIds.map((nodeId) => {
4725
+ var _participantByNodeId$;
4726
+ return (_participantByNodeId$ = participantByNodeId.get(nodeId)) === null || _participantByNodeId$ === void 0 ? void 0 : _participantByNodeId$.mermaidId;
4727
+ }).filter((id) => id !== void 0);
4728
+ if (names.length > 0) lines.push(`${indent()}Note ${item.placement} ${names.join(",")}: ${encodeLabel(item.text)}`);
4729
+ }
4730
+ }
4731
+ const rowEnd = item ? lastRowByItemId.get(item.nodeId) : currentRow;
4732
+ for (const participant of participants) for (const activation of participant.activations) {
4733
+ if (activation.endRow !== rowEnd) continue;
4734
+ lines.push(`${indent()}deactivate ${participant.mermaidId}`);
4735
+ }
4736
+ while (openBlocks.length > 0 && openBlocks[openBlocks.length - 1].endRow <= rowEnd) {
4737
+ openBlocks.pop();
4738
+ lines.push(`${indent()}end`);
4739
+ }
4740
+ }
4741
+ while (openBlocks.length > 0) {
4742
+ openBlocks.pop();
4743
+ lines.push(`${indent()}end`);
4744
+ }
4745
+ return lines.join("\n");
4746
+ }
4444
4747
  const BOUND_PADDING = 20;
4445
4748
  function createGroupNode(options) {
4446
4749
  var _options$id, _options$name;
@@ -5555,10 +5858,12 @@ exports.convertMermaidToReactFlow = convertMermaidToReactFlow;
5555
5858
  exports.convertMermaidToReactFlowWithContext = convertMermaidToReactFlowWithContext;
5556
5859
  exports.convertMongoSchemaToAst = convertMongoSchemaToAst;
5557
5860
  exports.convertNoSQLToAst = convertNoSQLToAst;
5861
+ exports.convertReactFlowToSequenceMermaid = convertReactFlowToSequenceMermaid;
5558
5862
  exports.convertUiGraphToMermaid = convertUiGraphToMermaid;
5559
5863
  exports.estimateSequenceMessageBoxSize = estimateSequenceMessageBoxSize;
5560
5864
  exports.flattenMetaData = flattenMetaData;
5561
5865
  exports.generateTableNodeId = generateTableNodeId;
5562
5866
  exports.generateUUID = generateUUID;
5867
+ exports.isSequenceDiagram = isSequenceDiagram;
5563
5868
  exports.sanitizeMermaidLabels = sanitizeMermaidLabels;
5564
5869
  exports.syncBaseData = syncBaseData;
package/dist/index.d.cts CHANGED
@@ -767,6 +767,10 @@ declare function sanitizeMermaidLabels(src: string): string;
767
767
  //#region src/mermaid-converter/mermaid-to-react-flow.d.ts
768
768
  declare function convertMermaidToReactFlow(mermaidCode: string): Promise<ReactFlowData>;
769
769
  //#endregion
770
+ //#region src/mermaid-converter/react-flow-to-sequence.d.ts
771
+ declare function isSequenceDiagram(nodes: Node[]): boolean;
772
+ declare function convertReactFlowToSequenceMermaid(nodes: Node[], edges: Edge[]): string;
773
+ //#endregion
770
774
  //#region src/mermaid-converter/sequence-layout.d.ts
771
775
  /**
772
776
  * Sizes a sequence message box from its own label text, targeting a ~2-line
@@ -806,4 +810,4 @@ type UigOutput = {
806
810
  //#region src/uig-converter/index.d.ts
807
811
  declare function convertUiGraphToMermaid(input: UiGraphInput, options?: UiGraphOptions): UigOutput;
808
812
  //#endregion
809
- export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceActivation, SequenceArrowHead, SequenceAutonumber, SequenceBlock, SequenceBlockSection, SequenceBlockType, SequenceBox, SequenceDiagramData, SequenceMessage, SequenceNote, SequenceParticipant, SequenceParticipantLink, SequenceParticipantType, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
813
+ export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceActivation, SequenceArrowHead, SequenceAutonumber, SequenceBlock, SequenceBlockSection, SequenceBlockType, SequenceBox, SequenceDiagramData, SequenceMessage, SequenceNote, SequenceParticipant, SequenceParticipantLink, SequenceParticipantType, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertReactFlowToSequenceMermaid, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, isSequenceDiagram, sanitizeMermaidLabels, syncBaseData };
package/dist/index.d.mts CHANGED
@@ -767,6 +767,10 @@ declare function sanitizeMermaidLabels(src: string): string;
767
767
  //#region src/mermaid-converter/mermaid-to-react-flow.d.ts
768
768
  declare function convertMermaidToReactFlow(mermaidCode: string): Promise<ReactFlowData>;
769
769
  //#endregion
770
+ //#region src/mermaid-converter/react-flow-to-sequence.d.ts
771
+ declare function isSequenceDiagram(nodes: Node[]): boolean;
772
+ declare function convertReactFlowToSequenceMermaid(nodes: Node[], edges: Edge[]): string;
773
+ //#endregion
770
774
  //#region src/mermaid-converter/sequence-layout.d.ts
771
775
  /**
772
776
  * Sizes a sequence message box from its own label text, targeting a ~2-line
@@ -806,4 +810,4 @@ type UigOutput = {
806
810
  //#region src/uig-converter/index.d.ts
807
811
  declare function convertUiGraphToMermaid(input: UiGraphInput, options?: UiGraphOptions): UigOutput;
808
812
  //#endregion
809
- export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceActivation, SequenceArrowHead, SequenceAutonumber, SequenceBlock, SequenceBlockSection, SequenceBlockType, SequenceBox, SequenceDiagramData, SequenceMessage, SequenceNote, SequenceParticipant, SequenceParticipantLink, SequenceParticipantType, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
813
+ export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceActivation, SequenceArrowHead, SequenceAutonumber, SequenceBlock, SequenceBlockSection, SequenceBlockType, SequenceBox, SequenceDiagramData, SequenceMessage, SequenceNote, SequenceParticipant, SequenceParticipantLink, SequenceParticipantType, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertReactFlowToSequenceMermaid, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, isSequenceDiagram, sanitizeMermaidLabels, syncBaseData };
package/dist/index.mjs CHANGED
@@ -2193,6 +2193,14 @@ const ARROW_TOKENS = [
2193
2193
  arrowType: "none"
2194
2194
  }
2195
2195
  ];
2196
+ function findArrowTokenFor(options) {
2197
+ const exact = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType && candidate.half === options.half && Boolean(candidate.reversed) === Boolean(options.reversed));
2198
+ if (exact) return exact.token;
2199
+ const byHead = ARROW_TOKENS.find((candidate) => candidate.lineStyle === options.lineStyle && candidate.arrowType === options.arrowType);
2200
+ if (byHead) return byHead.token;
2201
+ if (options.lineStyle === "dashed") return "-->>";
2202
+ return "->>";
2203
+ }
2196
2204
  const BLOCK_OPENERS = [
2197
2205
  "loop",
2198
2206
  "alt",
@@ -3068,7 +3076,13 @@ function convertSequenceDiagramToReactFlow(mermaidCode) {
3068
3076
  },
3069
3077
  data: {
3070
3078
  source: "mermaid",
3071
- componentFields: [generateComponentFieldNameInput(data.title)]
3079
+ componentFields: [generateComponentFieldInput({
3080
+ componentFieldId: "text",
3081
+ label: "Text",
3082
+ type: ComponentInputType.TextBox,
3083
+ data: data.title,
3084
+ isReadonly: true
3085
+ })]
3072
3086
  }
3073
3087
  });
3074
3088
  return {
@@ -4434,6 +4448,295 @@ function _convertMermaidToReactFlow() {
4434
4448
  });
4435
4449
  return _convertMermaidToReactFlow.apply(this, arguments);
4436
4450
  }
4451
+ function isSequenceDiagram(nodes) {
4452
+ return nodes.some((node) => node.type === "sequenceParticipant");
4453
+ }
4454
+ function fieldValue(node, componentFieldId) {
4455
+ var _node$data, _field$data;
4456
+ const fields = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.componentFields;
4457
+ if (!Array.isArray(fields)) return void 0;
4458
+ const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === componentFieldId);
4459
+ 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;
4460
+ if (typeof value !== "string") return void 0;
4461
+ if (!value.trim()) return void 0;
4462
+ return value;
4463
+ }
4464
+ function nodeLabel(node) {
4465
+ var _node$data2;
4466
+ const fromField = fieldValue(node, "name");
4467
+ if (fromField !== void 0) return fromField;
4468
+ const label = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.label;
4469
+ if (typeof label === "string") return label;
4470
+ return "";
4471
+ }
4472
+ function encodeLabel(text) {
4473
+ return text.replace(/#/g, "&#35;").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim();
4474
+ }
4475
+ function toMermaidId(name, index, used) {
4476
+ const base = name.replace(/[^A-Za-z0-9_]/g, "") || `P${index}`;
4477
+ let candidate = base;
4478
+ let suffix = 2;
4479
+ while (used.has(candidate)) {
4480
+ candidate = `${base}_${suffix}`;
4481
+ suffix++;
4482
+ }
4483
+ used.add(candidate);
4484
+ return candidate;
4485
+ }
4486
+ function collectParticipants(nodes) {
4487
+ const used = /* @__PURE__ */ new Set();
4488
+ return nodes.filter((node) => node.type === "sequenceParticipant").sort((a, b) => a.position.x - b.position.x).map((node, index) => {
4489
+ var _node$data3, _node$data4, _node$data5, _node$data6, _node$data7;
4490
+ const name = nodeLabel(node) || `Participant ${index + 1}`;
4491
+ const rawType = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.participantType;
4492
+ const activations = (_node$data4 = node.data) === null || _node$data4 === void 0 ? void 0 : _node$data4.activations;
4493
+ const links = (_node$data5 = node.data) === null || _node$data5 === void 0 ? void 0 : _node$data5.links;
4494
+ const createdRow = (_node$data6 = node.data) === null || _node$data6 === void 0 ? void 0 : _node$data6.lifelineStartRow;
4495
+ const destroyedRow = (_node$data7 = node.data) === null || _node$data7 === void 0 ? void 0 : _node$data7.lifelineEndRow;
4496
+ return _objectSpread2(_objectSpread2(_objectSpread2({
4497
+ nodeId: node.id,
4498
+ mermaidId: toMermaidId(name, index, used),
4499
+ name,
4500
+ type: typeof rawType === "string" ? rawType : "participant",
4501
+ links: Array.isArray(links) ? links : [],
4502
+ activations: Array.isArray(activations) ? activations : []
4503
+ }, typeof createdRow === "number" ? { createdRow } : {}), typeof destroyedRow === "number" ? { destroyedRow } : {}), {}, { x: node.position.x });
4504
+ });
4505
+ }
4506
+ function buildMessageLinks(edges, participantNodeIds) {
4507
+ const links = /* @__PURE__ */ new Map();
4508
+ for (const edge of edges) {
4509
+ if (participantNodeIds.has(edge.source)) links.set(edge.target, _objectSpread2(_objectSpread2({}, links.get(edge.target)), {}, { from: edge.source }));
4510
+ if (participantNodeIds.has(edge.target)) links.set(edge.source, _objectSpread2(_objectSpread2({}, links.get(edge.source)), {}, { to: edge.target }));
4511
+ }
4512
+ return links;
4513
+ }
4514
+ function arrowTokenOf(edgeFrom, edgeTo) {
4515
+ var _edgeTo$data$arrowTyp, _edgeTo$data, _edgeFrom$data, _edgeTo$data$half, _edgeTo$data2, _edgeFrom$data2, _edgeFrom$data3, _ref, _ref2;
4516
+ 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;
4517
+ 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;
4518
+ const reversed = (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data3 = edgeFrom.data) === null || _edgeFrom$data3 === void 0 ? void 0 : _edgeFrom$data3.reversed) === true;
4519
+ return findArrowTokenFor(_objectSpread2(_objectSpread2({
4520
+ 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",
4521
+ arrowType: arrowType !== null && arrowType !== void 0 ? arrowType : "filled"
4522
+ }, half ? { half } : {}), {}, { reversed }));
4523
+ }
4524
+ function noteParticipantNodeIds(note, participants, noteNode$1) {
4525
+ 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));
4526
+ if (byImportedId.length > 0) return byImportedId.map((participant) => participant.nodeId);
4527
+ if (participants.length === 0) return [];
4528
+ const noteCenter = noteNode$1.position.x + (Number(noteNode$1.width) || 0) / 2;
4529
+ return [[...participants].sort((a, b) => Math.abs(a.x - noteCenter) - Math.abs(b.x - noteCenter))[0].nodeId];
4530
+ }
4531
+ function collectRowItems(nodes, edges, participants) {
4532
+ const participantNodeIds = new Set(participants.map((p) => p.nodeId));
4533
+ const links = buildMessageLinks(edges, participantNodeIds);
4534
+ const items = [];
4535
+ for (const node of nodes) {
4536
+ var _node$data8, _node$data9, _edgeFrom$data4, _edgeTo$data3;
4537
+ if (participantNodeIds.has(node.id)) continue;
4538
+ const note = (_node$data8 = node.data) === null || _node$data8 === void 0 ? void 0 : _node$data8.sequenceNote;
4539
+ if (note) {
4540
+ var _note$placement;
4541
+ items.push({
4542
+ item: {
4543
+ kind: "note",
4544
+ nodeId: node.id,
4545
+ text: nodeLabel(node),
4546
+ placement: (_note$placement = note.placement) !== null && _note$placement !== void 0 ? _note$placement : "over",
4547
+ participantNodeIds: noteParticipantNodeIds(note, participants, node)
4548
+ },
4549
+ y: node.position.y
4550
+ });
4551
+ continue;
4552
+ }
4553
+ const link = links.get(node.id);
4554
+ if (!(link === null || link === void 0 ? void 0 : link.from) || !link.to) continue;
4555
+ const edgeFrom = edges.find((edge) => edge.target === node.id && edge.source === link.from);
4556
+ const edgeTo = edges.find((edge) => edge.source === node.id && edge.target === link.to);
4557
+ const sequenceNumber = (_node$data9 = node.data) === null || _node$data9 === void 0 ? void 0 : _node$data9.sequenceNumber;
4558
+ items.push({
4559
+ item: _objectSpread2({
4560
+ kind: "message",
4561
+ nodeId: node.id,
4562
+ fromNodeId: link.from,
4563
+ toNodeId: link.to,
4564
+ label: nodeLabel(node),
4565
+ token: arrowTokenOf(edgeFrom, edgeTo),
4566
+ centralSource: (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data4 = edgeFrom.data) === null || _edgeFrom$data4 === void 0 ? void 0 : _edgeFrom$data4.centralSource) === true,
4567
+ centralTarget: (edgeTo === null || edgeTo === void 0 || (_edgeTo$data3 = edgeTo.data) === null || _edgeTo$data3 === void 0 ? void 0 : _edgeTo$data3.centralTarget) === true
4568
+ }, typeof sequenceNumber === "number" ? { sequenceNumber } : {}),
4569
+ y: node.position.y
4570
+ });
4571
+ }
4572
+ return items.sort((a, b) => a.y - b.y).map((entry) => entry.item);
4573
+ }
4574
+ function collectBlocks(nodes) {
4575
+ const blocks = [];
4576
+ for (const node of nodes) {
4577
+ var _node$data10, _block$type, _block$label, _block$depth, _block$sections;
4578
+ const block = (_node$data10 = node.data) === null || _node$data10 === void 0 ? void 0 : _node$data10.sequenceBlock;
4579
+ if (!block) continue;
4580
+ if (typeof block.startRow !== "number") continue;
4581
+ if (typeof block.endRow !== "number") continue;
4582
+ blocks.push(_objectSpread2(_objectSpread2({
4583
+ type: (_block$type = block.type) !== null && _block$type !== void 0 ? _block$type : "rect",
4584
+ label: (_block$label = block.label) !== null && _block$label !== void 0 ? _block$label : ""
4585
+ }, block.color ? { color: block.color } : {}), {}, {
4586
+ depth: (_block$depth = block.depth) !== null && _block$depth !== void 0 ? _block$depth : 0,
4587
+ startRow: block.startRow,
4588
+ endRow: block.endRow,
4589
+ sections: ((_block$sections = block.sections) !== null && _block$sections !== void 0 ? _block$sections : []).filter((section) => typeof section.startRow === "number" && typeof section.endRow === "number").map((section) => {
4590
+ var _section$label;
4591
+ return {
4592
+ label: (_section$label = section.label) !== null && _section$label !== void 0 ? _section$label : "",
4593
+ startRow: section.startRow,
4594
+ endRow: section.endRow
4595
+ };
4596
+ })
4597
+ }));
4598
+ }
4599
+ return blocks;
4600
+ }
4601
+ function collectBoxes(nodes, participants) {
4602
+ const boxes = [];
4603
+ for (const node of nodes) {
4604
+ var _node$data11, _node$data12, _box$label;
4605
+ const box = (_node$data11 = node.data) === null || _node$data11 === void 0 ? void 0 : _node$data11.sequenceBox;
4606
+ if (!box) continue;
4607
+ 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));
4608
+ const left = node.position.x;
4609
+ const right = node.position.x + (Number(node.width) || 0);
4610
+ const contained = byImportedId.length > 0 ? byImportedId : participants.filter((participant) => participant.x >= left && participant.x <= right);
4611
+ if (contained.length === 0) continue;
4612
+ const backgroundColor = (_node$data12 = node.data) === null || _node$data12 === void 0 ? void 0 : _node$data12.backgroundColor;
4613
+ 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) }));
4614
+ }
4615
+ return boxes;
4616
+ }
4617
+ function participantDeclaration(participant, keyword) {
4618
+ const stereotype = participant.type === "participant" || participant.type === "actor" ? "" : `@{ "type": "${participant.type}" }`;
4619
+ const alias = participant.mermaidId === participant.name ? "" : ` as ${encodeLabel(participant.name)}`;
4620
+ return `${keyword} ${participant.mermaidId}${stereotype}${alias}`;
4621
+ }
4622
+ function convertReactFlowToSequenceMermaid(nodes, edges) {
4623
+ const participants = collectParticipants(nodes);
4624
+ const items = collectRowItems(nodes, edges, participants);
4625
+ const blocks = collectBlocks(nodes);
4626
+ const boxes = collectBoxes(nodes, participants);
4627
+ const participantByNodeId = new Map(participants.map((participant) => [participant.nodeId, participant]));
4628
+ const rowByItemId = /* @__PURE__ */ new Map();
4629
+ const lastRowByItemId = /* @__PURE__ */ new Map();
4630
+ let row = 0;
4631
+ for (const item of items) {
4632
+ rowByItemId.set(item.nodeId, row);
4633
+ const isSelf = item.kind === "message" && item.fromNodeId === item.toNodeId;
4634
+ lastRowByItemId.set(item.nodeId, isSelf ? row + 1 : row);
4635
+ row += isSelf ? 2 : 1;
4636
+ }
4637
+ const rowCount = row;
4638
+ const lines = ["sequenceDiagram"];
4639
+ const titleNode = nodes.find((node) => node.id === "sequence-title");
4640
+ if (titleNode) {
4641
+ var _fieldValue;
4642
+ const text = (_fieldValue = fieldValue(titleNode, "text")) !== null && _fieldValue !== void 0 ? _fieldValue : nodeLabel(titleNode);
4643
+ if (text) lines.push(` title ${encodeLabel(text)}`);
4644
+ }
4645
+ const boxByFirstParticipant = /* @__PURE__ */ new Map();
4646
+ const boxEndByParticipant = /* @__PURE__ */ new Map();
4647
+ for (const box of boxes) {
4648
+ var _boxEndByParticipant$;
4649
+ const ordered = participants.filter((participant) => box.participantNodeIds.includes(participant.nodeId));
4650
+ if (ordered.length === 0) continue;
4651
+ boxByFirstParticipant.set(ordered[0].nodeId, box);
4652
+ boxEndByParticipant.set(ordered[ordered.length - 1].nodeId, ((_boxEndByParticipant$ = boxEndByParticipant.get(ordered[ordered.length - 1].nodeId)) !== null && _boxEndByParticipant$ !== void 0 ? _boxEndByParticipant$ : 0) + 1);
4653
+ }
4654
+ for (const participant of participants) {
4655
+ var _boxEndByParticipant$2;
4656
+ const box = boxByFirstParticipant.get(participant.nodeId);
4657
+ if (box) {
4658
+ const color = box.color ? `${box.color} ` : "";
4659
+ lines.push(` box ${color}${encodeLabel(box.label)}`.trimEnd());
4660
+ }
4661
+ if (participant.createdRow === void 0) {
4662
+ const keyword = participant.type === "actor" ? "actor" : "participant";
4663
+ lines.push(` ${participantDeclaration(participant, keyword)}`);
4664
+ }
4665
+ const boxEnds = (_boxEndByParticipant$2 = boxEndByParticipant.get(participant.nodeId)) !== null && _boxEndByParticipant$2 !== void 0 ? _boxEndByParticipant$2 : 0;
4666
+ for (let index = 0; index < boxEnds; index++) lines.push(" end");
4667
+ }
4668
+ for (const participant of participants) for (const link of participant.links) lines.push(` link ${participant.mermaidId}: ${link.label} @ ${link.url}`);
4669
+ const numbered = items.filter((item) => item.kind === "message" && item.sequenceNumber !== void 0);
4670
+ if (numbered.length > 0) {
4671
+ const start = numbered[0].sequenceNumber;
4672
+ const step = numbered.length > 1 ? numbered[1].sequenceNumber - numbered[0].sequenceNumber : 1;
4673
+ lines.push(` autonumber ${start} ${step}`);
4674
+ }
4675
+ const openBlocks = [];
4676
+ function indent() {
4677
+ return " ".repeat(openBlocks.length + 1);
4678
+ }
4679
+ for (let currentRow = 0; currentRow < rowCount; currentRow++) {
4680
+ const opening = blocks.filter((block) => block.startRow === currentRow).sort((a, b) => a.depth - b.depth);
4681
+ for (const block of opening) {
4682
+ const label = encodeLabel(block.label);
4683
+ const color = block.type === "rect" && block.color ? `${block.color} ` : "";
4684
+ lines.push(`${indent()}${block.type} ${color}${label}`.trimEnd());
4685
+ openBlocks.push(block);
4686
+ }
4687
+ for (const [depth, block] of openBlocks.entries()) for (const section of block.sections.slice(1)) {
4688
+ if (section.startRow !== currentRow) continue;
4689
+ const keyword = block.type === "par" ? "and" : block.type === "critical" ? "option" : "else";
4690
+ lines.push(`${" ".repeat(depth + 1)}${keyword} ${encodeLabel(section.label)}`.trimEnd());
4691
+ }
4692
+ const item = items.find((entry) => rowByItemId.get(entry.nodeId) === currentRow);
4693
+ if (item) {
4694
+ for (const participant of participants) {
4695
+ if (participant.createdRow !== currentRow) continue;
4696
+ const keyword = participant.type === "actor" ? "actor" : "participant";
4697
+ lines.push(`${indent()}create ${participantDeclaration(participant, keyword)}`);
4698
+ }
4699
+ for (const participant of participants) {
4700
+ if (participant.destroyedRow !== currentRow) continue;
4701
+ lines.push(`${indent()}destroy ${participant.mermaidId}`);
4702
+ }
4703
+ for (const participant of participants) for (const activation of participant.activations) {
4704
+ if (activation.startRow !== currentRow) continue;
4705
+ lines.push(`${indent()}activate ${participant.mermaidId}`);
4706
+ }
4707
+ if (item.kind === "message") {
4708
+ const from = participantByNodeId.get(item.fromNodeId);
4709
+ const to = participantByNodeId.get(item.toNodeId);
4710
+ if (from && to) {
4711
+ const source = item.centralSource ? `${from.mermaidId}()` : from.mermaidId;
4712
+ const target = item.centralTarget ? `()${to.mermaidId}` : to.mermaidId;
4713
+ lines.push(`${indent()}${source}${item.token}${target}: ${encodeLabel(item.label)}`);
4714
+ }
4715
+ }
4716
+ if (item.kind === "note") {
4717
+ const names = item.participantNodeIds.map((nodeId) => {
4718
+ var _participantByNodeId$;
4719
+ return (_participantByNodeId$ = participantByNodeId.get(nodeId)) === null || _participantByNodeId$ === void 0 ? void 0 : _participantByNodeId$.mermaidId;
4720
+ }).filter((id) => id !== void 0);
4721
+ if (names.length > 0) lines.push(`${indent()}Note ${item.placement} ${names.join(",")}: ${encodeLabel(item.text)}`);
4722
+ }
4723
+ }
4724
+ const rowEnd = item ? lastRowByItemId.get(item.nodeId) : currentRow;
4725
+ for (const participant of participants) for (const activation of participant.activations) {
4726
+ if (activation.endRow !== rowEnd) continue;
4727
+ lines.push(`${indent()}deactivate ${participant.mermaidId}`);
4728
+ }
4729
+ while (openBlocks.length > 0 && openBlocks[openBlocks.length - 1].endRow <= rowEnd) {
4730
+ openBlocks.pop();
4731
+ lines.push(`${indent()}end`);
4732
+ }
4733
+ }
4734
+ while (openBlocks.length > 0) {
4735
+ openBlocks.pop();
4736
+ lines.push(`${indent()}end`);
4737
+ }
4738
+ return lines.join("\n");
4739
+ }
4437
4740
  const BOUND_PADDING = 20;
4438
4741
  function createGroupNode(options) {
4439
4742
  var _options$id, _options$name;
@@ -5518,4 +5821,4 @@ function convertUiGraphToMermaid(input, options) {
5518
5821
  context
5519
5822
  };
5520
5823
  }
5521
- export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SqlToAstParser, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
5824
+ export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT, SEQUENCE_PARTICIPANT_COLOR, SqlToAstParser, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertReactFlowToSequenceMermaid, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, isSequenceDiagram, sanitizeMermaidLabels, syncBaseData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uigraph/sdk",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "type": "module",
5
5
  "license": "BUSL-1.1",
6
6
  "repository": {