@flowgram.ai/document 0.1.0-alpha.7 → 0.1.0-alpha.8

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.js CHANGED
@@ -85,11 +85,17 @@ var FlowNodeBaseType = /* @__PURE__ */ ((FlowNodeBaseType2) => {
85
85
  FlowNodeBaseType2["BLOCK_ORDER_ICON"] = "blockOrderIcon";
86
86
  FlowNodeBaseType2["GROUP"] = "group";
87
87
  FlowNodeBaseType2["END"] = "end";
88
+ FlowNodeBaseType2["BREAK"] = "break";
88
89
  FlowNodeBaseType2["CONDITION"] = "condition";
89
90
  FlowNodeBaseType2["SUB_CANVAS"] = "subCanvas";
91
+ FlowNodeBaseType2["MULTI_INPUTS"] = "multiInputs";
92
+ FlowNodeBaseType2["MULTI_OUTPUTS"] = "multiOutputs";
93
+ FlowNodeBaseType2["INPUT"] = "input";
94
+ FlowNodeBaseType2["OUTPUT"] = "output";
90
95
  return FlowNodeBaseType2;
91
96
  })(FlowNodeBaseType || {});
92
97
  var FlowNodeSplitType = /* @__PURE__ */ ((FlowNodeSplitType2) => {
98
+ FlowNodeSplitType2["SIMPLE_SPLIT"] = "simpleSplit";
93
99
  FlowNodeSplitType2["DYNAMIC_SPLIT"] = "dynamicSplit";
94
100
  FlowNodeSplitType2["STATIC_SPLIT"] = "staticSplit";
95
101
  return FlowNodeSplitType2;
@@ -233,13 +239,37 @@ var DEFAULT_FLOW_NODE_META = (nodeType, document) => {
233
239
  };
234
240
  var FlowNodeRegistry;
235
241
  ((FlowNodeRegistry4) => {
242
+ function mergeChildRegistries(r1 = [], r2 = []) {
243
+ if (r1.length === 0 || r2.length === 0) {
244
+ return [...r1, ...r2];
245
+ }
246
+ const r1Filter = r1.map((r1Current) => {
247
+ const r2Current = r2.find((n) => n.type === r1Current.type);
248
+ if (r2Current) {
249
+ return merge(r1Current, r2Current, r1Current.type);
250
+ }
251
+ return r1Current;
252
+ });
253
+ const r2Filter = r2.filter((n) => !r1.some((r) => r.type === n.type));
254
+ return [...r1Filter, ...r2Filter];
255
+ }
256
+ FlowNodeRegistry4.mergeChildRegistries = mergeChildRegistries;
236
257
  function merge(registry1, registry2, finalType) {
258
+ const extendKeys = registry1.__extends__ ? registry1.__extends__.slice() : [];
259
+ if (registry1.type !== registry2.type) {
260
+ extendKeys.unshift(registry1.type);
261
+ }
237
262
  return {
238
263
  ...registry1,
239
264
  ...registry2,
265
+ extendChildRegistries: mergeChildRegistries(
266
+ registry1.extendChildRegistries,
267
+ registry2.extendChildRegistries
268
+ ),
240
269
  meta: { ...registry1.meta, ...registry2.meta },
241
270
  extend: void 0,
242
- type: finalType
271
+ type: finalType,
272
+ __extends__: extendKeys
243
273
  };
244
274
  }
245
275
  FlowNodeRegistry4.merge = merge;
@@ -346,6 +376,7 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
346
376
  this.expanded = !this.expanded;
347
377
  }
348
378
  toggleMouseEnter(silent = false) {
379
+ var _a;
349
380
  this.entity.document.renderState.setNodeHovered(this.entity);
350
381
  if (silent) return;
351
382
  const transform = this.entity.getData(FlowNodeTransformData);
@@ -357,7 +388,7 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
357
388
  this.mouseLeaveTimeout = void 0;
358
389
  }
359
390
  transform.renderState.hovered = true;
360
- if (this.entity.isFirst && this.entity.parent?.id !== "root") {
391
+ if (this.entity.isFirst && ((_a = this.entity.parent) == null ? void 0 : _a.id) !== "root") {
361
392
  transform.parent.renderState.activated = true;
362
393
  } else {
363
394
  transform.renderState.activated = true;
@@ -368,8 +399,9 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
368
399
  if (silent) return;
369
400
  const transform = this.entity.getData(FlowNodeTransformData);
370
401
  this.mouseLeaveTimeout = setTimeout(() => {
402
+ var _a;
371
403
  transform.renderState.hovered = false;
372
- if (this.entity.isFirst && this.entity.parent?.id !== "root") {
404
+ if (this.entity.isFirst && ((_a = this.entity.parent) == null ? void 0 : _a.id) !== "root") {
373
405
  transform.parent.renderState.activated = false;
374
406
  }
375
407
  transform.renderState.activated = false;
@@ -418,10 +450,11 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
418
450
  this.data.stackIndex = index;
419
451
  }
420
452
  get lineActivated() {
453
+ var _a, _b, _c;
421
454
  const { activated } = this;
422
455
  if (!activated) return false;
423
456
  return Boolean(
424
- this.entity.parent?.getData(_FlowNodeRenderData)?.activated || this.entity.isInlineBlock || this.entity.next?.getData(_FlowNodeRenderData).activated
457
+ ((_b = (_a = this.entity.parent) == null ? void 0 : _a.getData(_FlowNodeRenderData)) == null ? void 0 : _b.activated) || this.entity.isInlineBlock || ((_c = this.entity.next) == null ? void 0 : _c.getData(_FlowNodeRenderData).activated)
425
458
  );
426
459
  }
427
460
  get node() {
@@ -625,10 +658,10 @@ var _FlowNodeTransformData = class _FlowNodeTransformData extends import_core2.E
625
658
  return this.entity.document.layout.getPadding(this.entity);
626
659
  }
627
660
  setParentTransform(transform) {
628
- if (this.transform.parent !== transform?.transform) {
661
+ if (this.transform.parent !== (transform == null ? void 0 : transform.transform)) {
629
662
  this.localDirty = true;
630
663
  }
631
- this.transform.setParent(transform?.transform);
664
+ this.transform.setParent(transform == null ? void 0 : transform.transform);
632
665
  }
633
666
  get spacing() {
634
667
  const { spacing } = this.entity.getNodeMeta();
@@ -655,10 +688,12 @@ var _FlowNodeTransformData = class _FlowNodeTransformData extends import_core2.E
655
688
  * 上一个节点的 transform 数据
656
689
  */
657
690
  get pre() {
658
- return this.entity.pre?.getData(_FlowNodeTransformData);
691
+ var _a;
692
+ return (_a = this.entity.pre) == null ? void 0 : _a.getData(_FlowNodeTransformData);
659
693
  }
660
694
  get originParent() {
661
- return this.entity.originParent?.getData(_FlowNodeTransformData);
695
+ var _a;
696
+ return (_a = this.entity.originParent) == null ? void 0 : _a.getData(_FlowNodeTransformData);
662
697
  }
663
698
  get isFirst() {
664
699
  return this.entity.isFirst;
@@ -667,22 +702,26 @@ var _FlowNodeTransformData = class _FlowNodeTransformData extends import_core2.E
667
702
  return this.entity.isLast;
668
703
  }
669
704
  get lastChild() {
670
- return this.entity.lastChild?.getData(_FlowNodeTransformData);
705
+ var _a;
706
+ return (_a = this.entity.lastChild) == null ? void 0 : _a.getData(_FlowNodeTransformData);
671
707
  }
672
708
  get firstChild() {
673
- return this.entity.firstChild?.getData(_FlowNodeTransformData);
709
+ var _a;
710
+ return (_a = this.entity.firstChild) == null ? void 0 : _a.getData(_FlowNodeTransformData);
674
711
  }
675
712
  /**
676
713
  * 下一个节点的 transform 数据
677
714
  */
678
715
  get next() {
679
- return this.entity.next?.getData(_FlowNodeTransformData);
716
+ var _a;
717
+ return (_a = this.entity.next) == null ? void 0 : _a.getData(_FlowNodeTransformData);
680
718
  }
681
719
  /**
682
720
  * parent 节点的 transform 数据
683
721
  */
684
722
  get parent() {
685
- return this.entity.parent?.getData(_FlowNodeTransformData);
723
+ var _a;
724
+ return (_a = this.entity.parent) == null ? void 0 : _a.getData(_FlowNodeTransformData);
686
725
  }
687
726
  };
688
727
  _FlowNodeTransformData.type = "FlowNodeTransformData";
@@ -706,9 +745,10 @@ var drawLineToNext = (transition) => {
706
745
  return [];
707
746
  };
708
747
  var drawLineToBottom = (transition) => {
748
+ var _a;
709
749
  const { transform } = transition;
710
750
  const currentOutput = transform.outputPoint;
711
- const parentOutput = transform.parent?.outputPoint;
751
+ const parentOutput = (_a = transform.parent) == null ? void 0 : _a.outputPoint;
712
752
  if (!transform.next && parentOutput && !new import_utils3.Point().copyFrom(currentOutput).equals(parentOutput) && !transition.isNodeEnd) {
713
753
  return [
714
754
  {
@@ -725,20 +765,23 @@ var FlowNodeTransitionData = class extends import_core3.EntityData {
725
765
  return {};
726
766
  }
727
767
  formatLines(lines) {
728
- if (this.entity.document.options?.formatNodeLines) {
729
- return this.entity.document.options?.formatNodeLines?.(this.entity, lines);
768
+ var _a, _b, _c;
769
+ if ((_a = this.entity.document.options) == null ? void 0 : _a.formatNodeLines) {
770
+ return (_c = (_b = this.entity.document.options) == null ? void 0 : _b.formatNodeLines) == null ? void 0 : _c.call(_b, this.entity, lines);
730
771
  }
731
772
  return lines;
732
773
  }
733
774
  formatLabels(labels) {
775
+ var _a, _b;
734
776
  if (this.entity.document.options.formatNodeLabels) {
735
- return this.entity.document.options?.formatNodeLabels?.(this.entity, labels);
777
+ return (_b = (_a = this.entity.document.options) == null ? void 0 : _a.formatNodeLabels) == null ? void 0 : _b.call(_a, this.entity, labels);
736
778
  }
737
779
  return labels;
738
780
  }
739
781
  get lines() {
740
782
  return this.entity.memoGlobal("lines", () => {
741
- const { getChildLines } = this.entity.parent?.getNodeRegistry() || {};
783
+ var _a;
784
+ const { getChildLines } = ((_a = this.entity.parent) == null ? void 0 : _a.getNodeRegistry()) || {};
742
785
  if (getChildLines) {
743
786
  return this.formatLines(getChildLines(this, this.entity.document.layout));
744
787
  }
@@ -754,7 +797,8 @@ var FlowNodeTransitionData = class extends import_core3.EntityData {
754
797
  }
755
798
  get labels() {
756
799
  return this.entity.memoGlobal("labels", () => {
757
- const { getChildLabels } = this.entity.parent?.getNodeRegistry() || {};
800
+ var _a, _b;
801
+ const { getChildLabels } = ((_a = this.entity.parent) == null ? void 0 : _a.getNodeRegistry()) || {};
758
802
  if (getChildLabels) {
759
803
  return this.formatLabels(getChildLabels(this, this.entity.document.layout));
760
804
  }
@@ -774,7 +818,7 @@ var FlowNodeTransitionData = class extends import_core3.EntityData {
774
818
  }
775
819
  ]);
776
820
  }
777
- const parentOutput = this.transform.parent?.outputPoint;
821
+ const parentOutput = (_b = this.transform.parent) == null ? void 0 : _b.outputPoint;
778
822
  if (parentOutput && !new import_utils3.Point().copyFrom(currentOutput).equals(parentOutput) && !this.isNodeEnd) {
779
823
  return this.formatLabels([
780
824
  {
@@ -1021,8 +1065,9 @@ var FlowNodeEntity = class extends import_core4.Entity {
1021
1065
  return this.children.length;
1022
1066
  }
1023
1067
  get collapsed() {
1068
+ var _a;
1024
1069
  if (this.document.renderTree.isCollapsed(this)) return true;
1025
- return !!this.parent?.collapsed;
1070
+ return !!((_a = this.parent) == null ? void 0 : _a.collapsed);
1026
1071
  }
1027
1072
  set collapsed(collapsed) {
1028
1073
  this.document.renderTree.setCollapsed(this, collapsed);
@@ -1223,7 +1268,7 @@ var FlowRendererStateEntity = class extends import_core6.ConfigEntity {
1223
1268
  }
1224
1269
  setNodeHovered(node) {
1225
1270
  this.updateConfig({
1226
- nodeHoveredId: node?.id
1271
+ nodeHoveredId: node == null ? void 0 : node.id
1227
1272
  });
1228
1273
  }
1229
1274
  getDragLabelSide() {
@@ -1248,7 +1293,7 @@ var FlowRendererStateEntity = class extends import_core6.ConfigEntity {
1248
1293
  }
1249
1294
  setDragStartEntity(node) {
1250
1295
  this.updateConfig({
1251
- nodeDragStartId: node?.id
1296
+ nodeDragStartId: node == null ? void 0 : node.id
1252
1297
  });
1253
1298
  }
1254
1299
  // 拖拽多个节点时
@@ -1350,7 +1395,7 @@ var FlowVirtualTree = class _FlowVirtualTree {
1350
1395
  moveChilds(parent, childs, index) {
1351
1396
  const parentInfo = this.getInfo(parent);
1352
1397
  const len = parentInfo.children.length;
1353
- let childIndex = index ?? len;
1398
+ let childIndex = index != null ? index : len;
1354
1399
  childs.forEach((child) => {
1355
1400
  const childInfo = this.getInfo(child);
1356
1401
  if (childInfo.parent) {
@@ -1448,13 +1493,15 @@ var FlowVirtualTree = class _FlowVirtualTree {
1448
1493
  get size() {
1449
1494
  return this.map.size;
1450
1495
  }
1451
- toString() {
1496
+ toString(showType) {
1452
1497
  const ret = [];
1453
1498
  this.traverse((node, depth) => {
1454
1499
  if (depth === 0) {
1455
1500
  ret.push(node.id);
1456
1501
  } else {
1457
- ret.push(`|${new Array(depth).fill("--").join("")} ${node.id}`);
1502
+ ret.push(
1503
+ `|${new Array(depth).fill("--").join("")} ${showType ? `${node.flowNodeType}(${node.id})` : node.id}`
1504
+ );
1458
1505
  }
1459
1506
  });
1460
1507
  return `${ret.join("\n")}`;
@@ -1498,7 +1545,8 @@ var FlowRenderTree = class extends FlowVirtualTree {
1498
1545
  *
1499
1546
  */
1500
1547
  openNodeInsideCollapsed(node) {
1501
- let curr = this.originTree.getInfo(node)?.parent;
1548
+ var _a;
1549
+ let curr = (_a = this.originTree.getInfo(node)) == null ? void 0 : _a.parent;
1502
1550
  while (curr) {
1503
1551
  if (this.nodesCollapsed.has(curr)) {
1504
1552
  this.nodesCollapsed.delete(curr);
@@ -1570,7 +1618,7 @@ var FlowRenderTree = class extends FlowVirtualTree {
1570
1618
  if (shouldDragAllNextNodes && next) {
1571
1619
  this.dragNextNodesToBlock(passBlocks[0], next);
1572
1620
  }
1573
- children?.forEach((child) => {
1621
+ children == null ? void 0 : children.forEach((child) => {
1574
1622
  this.refineBranch(child);
1575
1623
  });
1576
1624
  if (shouldDragAllNextNodes) {
@@ -1720,11 +1768,22 @@ var FlowDocument = class {
1720
1768
  this.onNodeCreate = this.onNodeCreateEmitter.event;
1721
1769
  this.onNodeDispose = this.onNodeDisposeEmitter.event;
1722
1770
  this.onLayoutChange = this.onLayoutChangeEmitter.event;
1771
+ this._disposed = false;
1772
+ }
1773
+ /**
1774
+ *
1775
+ */
1776
+ get disposed() {
1777
+ return this._disposed;
1723
1778
  }
1724
1779
  init() {
1780
+ var _a, _b;
1725
1781
  if (!this.options) this.options = FlowDocumentOptionsDefault;
1726
1782
  this.currentLayoutKey = this.options.defaultLayout || "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
1727
- this.contributions.forEach((contrib) => contrib.registerDocument?.(this));
1783
+ this.contributions.forEach((contrib) => {
1784
+ var _a2;
1785
+ return (_a2 = contrib.registerDocument) == null ? void 0 : _a2.call(contrib, this);
1786
+ });
1728
1787
  this.root = this.addNode({ id: "root", type: "root" /* ROOT */ });
1729
1788
  this.originTree = new FlowVirtualTree(this.root);
1730
1789
  this.transformer = this.entityManager.createEntity(
@@ -1733,7 +1792,7 @@ var FlowDocument = class {
1733
1792
  );
1734
1793
  this.renderState = this.entityManager.createEntity(FlowRendererStateEntity);
1735
1794
  this.renderTree = new FlowRenderTree(this.root, this.originTree, this);
1736
- this.layout.reload?.();
1795
+ (_b = (_a = this.layout).reload) == null ? void 0 : _b.call(_a);
1737
1796
  }
1738
1797
  /**
1739
1798
  * 从数据初始化 O(n)
@@ -1745,6 +1804,7 @@ var FlowDocument = class {
1745
1804
  * @param fireRender 是否要触发渲染,默认 true
1746
1805
  */
1747
1806
  fromJSON(json, fireRender = true) {
1807
+ if (this._disposed) return;
1748
1808
  this.originTree.clear();
1749
1809
  this.renderTree.clear();
1750
1810
  this.entityManager.changeEntityLocked = true;
@@ -1768,7 +1828,10 @@ var FlowDocument = class {
1768
1828
  return layout;
1769
1829
  }
1770
1830
  async load() {
1771
- await Promise.all(this.contributions.map((c) => c.loadDocument?.(this)));
1831
+ await Promise.all(this.contributions.map((c) => {
1832
+ var _a;
1833
+ return (_a = c.loadDocument) == null ? void 0 : _a.call(c, this);
1834
+ }));
1772
1835
  }
1773
1836
  get loading() {
1774
1837
  return this.transformer.loading;
@@ -1802,8 +1865,9 @@ var FlowDocument = class {
1802
1865
  return result;
1803
1866
  }
1804
1867
  removeNode(node) {
1868
+ var _a;
1805
1869
  if (typeof node === "string") {
1806
- this.getNode(node)?.dispose();
1870
+ (_a = this.getNode(node)) == null ? void 0 : _a.dispose();
1807
1871
  } else {
1808
1872
  node.dispose();
1809
1873
  }
@@ -1813,7 +1877,8 @@ var FlowDocument = class {
1813
1877
  * @param data
1814
1878
  * @param addedNodes
1815
1879
  */
1816
- addNode(data, addedNodes, ignoreCreateEvent) {
1880
+ addNode(data, addedNodes, ignoreCreateAndUpdateEvent, ignoreBlocks) {
1881
+ var _a, _b, _c, _d;
1817
1882
  const { id, type = "block", originParent, parent, meta, hidden, index } = data;
1818
1883
  let node = this.getNode(id);
1819
1884
  let isNew = false;
@@ -1834,10 +1899,10 @@ var FlowDocument = class {
1834
1899
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
1835
1900
  node.addInitializeData(datas);
1836
1901
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
1837
- if (this.options.fromNodeJSON) {
1838
- this.options.fromNodeJSON(node, data);
1839
- }
1902
+ (_b = (_a = this.options).fromNodeJSON) == null ? void 0 : _b.call(_a, node, data, true);
1840
1903
  isNew = true;
1904
+ } else {
1905
+ (_d = (_c = this.options).fromNodeJSON) == null ? void 0 : _d.call(_c, node, data, false);
1841
1906
  }
1842
1907
  node.initData({
1843
1908
  originParent,
@@ -1849,25 +1914,29 @@ var FlowDocument = class {
1849
1914
  if (node.isStart) {
1850
1915
  this.root.addChild(node);
1851
1916
  }
1852
- this.onNodeUpdateEmitter.fire({ node, data });
1853
- addedNodes?.push(node);
1917
+ addedNodes == null ? void 0 : addedNodes.push(node);
1854
1918
  if (register.onCreate) {
1855
1919
  const extendNodes = register.onCreate(node, data);
1856
1920
  if (extendNodes && addedNodes) {
1857
1921
  addedNodes.push(...extendNodes);
1858
1922
  }
1859
- } else if (data.blocks && data.blocks.length > 0) {
1923
+ } else if (data.blocks && data.blocks.length > 0 && !ignoreBlocks) {
1860
1924
  if (!data.blocks[0].type) {
1861
1925
  this.addInlineBlocks(node, data.blocks, addedNodes);
1862
1926
  } else {
1863
1927
  this.addBlocksAsChildren(node, data.blocks, addedNodes);
1864
1928
  }
1865
1929
  }
1866
- if (isNew && !ignoreCreateEvent) {
1867
- this.onNodeCreateEmitter.fire({
1868
- node,
1869
- data
1870
- });
1930
+ if (!ignoreCreateAndUpdateEvent) {
1931
+ if (isNew) {
1932
+ this.onNodeCreateEmitter.fire({
1933
+ node,
1934
+ data,
1935
+ json: data
1936
+ });
1937
+ } else {
1938
+ this.onNodeUpdateEmitter.fire({ node, data, json: data });
1939
+ }
1871
1940
  }
1872
1941
  return node;
1873
1942
  }
@@ -1903,18 +1972,16 @@ var FlowDocument = class {
1903
1972
  parent: node
1904
1973
  });
1905
1974
  addedNodes.push(blockIconNode);
1906
- if (blocks.length > 0) {
1907
- const inlineBlocksNode = this.addNode({
1908
- id: `$inlineBlocks$${node.id}`,
1909
- type: "inlineBlocks" /* INLINE_BLOCKS */,
1910
- originParent: node,
1911
- parent: node
1912
- });
1913
- addedNodes.push(inlineBlocksNode);
1914
- blocks.forEach((blockData) => {
1915
- this.addBlock(node, blockData, addedNodes);
1916
- });
1917
- }
1975
+ const inlineBlocksNode = this.addNode({
1976
+ id: `$inlineBlocks$${node.id}`,
1977
+ type: "inlineBlocks" /* INLINE_BLOCKS */,
1978
+ originParent: node,
1979
+ parent: node
1980
+ });
1981
+ addedNodes.push(inlineBlocksNode);
1982
+ blocks.forEach((blockData) => {
1983
+ this.addBlock(node, blockData, addedNodes);
1984
+ });
1918
1985
  return addedNodes;
1919
1986
  }
1920
1987
  /**
@@ -1925,6 +1992,7 @@ var FlowDocument = class {
1925
1992
  * @param parent 默认去找 $inlineBlocks$
1926
1993
  */
1927
1994
  addBlock(target, blockData, addedNodes, parent, index) {
1995
+ var _a;
1928
1996
  const node = typeof target === "string" ? this.getNode(target) : target;
1929
1997
  const { onBlockChildCreate } = node.getNodeRegistry();
1930
1998
  if (onBlockChildCreate) {
@@ -1938,7 +2006,7 @@ var FlowDocument = class {
1938
2006
  parent,
1939
2007
  index
1940
2008
  });
1941
- if (blockData.meta?.defaultCollapsed) {
2009
+ if ((_a = blockData.meta) == null ? void 0 : _a.defaultCollapsed) {
1942
2010
  block.collapsed = true;
1943
2011
  }
1944
2012
  const blockOrderIcon = this.addNode({
@@ -1949,7 +2017,7 @@ var FlowDocument = class {
1949
2017
  data: blockData.data,
1950
2018
  parent: block
1951
2019
  });
1952
- addedNodes?.push(block, blockOrderIcon);
2020
+ addedNodes == null ? void 0 : addedNodes.push(block, blockOrderIcon);
1953
2021
  if (blockData.blocks) {
1954
2022
  this.addBlocksAsChildren(block, blockData.blocks, addedNodes);
1955
2023
  }
@@ -1977,12 +2045,24 @@ var FlowDocument = class {
1977
2045
  ...preRegistry,
1978
2046
  ...newRegistry,
1979
2047
  meta: {
1980
- ...preRegistry?.meta,
1981
- ...newRegistry?.meta
1982
- }
2048
+ ...preRegistry == null ? void 0 : preRegistry.meta,
2049
+ ...newRegistry == null ? void 0 : newRegistry.meta
2050
+ },
2051
+ extendChildRegistries: FlowNodeRegistry.mergeChildRegistries(
2052
+ preRegistry == null ? void 0 : preRegistry.extendChildRegistries,
2053
+ newRegistry == null ? void 0 : newRegistry.extendChildRegistries
2054
+ )
1983
2055
  });
1984
2056
  });
1985
2057
  }
2058
+ /**
2059
+ * Check node extend
2060
+ * @param currentType
2061
+ * @param parentType
2062
+ */
2063
+ isExtend(currentType, parentType) {
2064
+ return (this.getNodeRegistry(currentType).__extends__ || []).includes(parentType);
2065
+ }
1986
2066
  /**
1987
2067
  * 导出数据,可以重载
1988
2068
  */
@@ -1999,13 +2079,15 @@ var FlowDocument = class {
1999
2079
  return this.getNodeRegistry(type, originParent);
2000
2080
  }
2001
2081
  getNodeRegistry(type, originParent) {
2002
- const typeKey = `${type}_${originParent?.flowNodeType || ""}`;
2082
+ var _a, _b, _c, _d, _e;
2083
+ const typeKey = `${type}_${(originParent == null ? void 0 : originParent.flowNodeType) || ""}`;
2003
2084
  if (this.nodeRegistryCache.has(typeKey)) {
2004
2085
  return this.nodeRegistryCache.get(typeKey);
2005
2086
  }
2006
- const customDefaultRegistry = this.options.getNodeDefaultRegistry?.(type);
2087
+ const customDefaultRegistry = (_b = (_a = this.options).getNodeDefaultRegistry) == null ? void 0 : _b.call(_a, type);
2007
2088
  let register = this.registers.get(type) || { type };
2008
2089
  const extendRegisters = [];
2090
+ const extendKey = register.extend;
2009
2091
  if (register.extend && this.registers.has(register.extend)) {
2010
2092
  register = FlowNodeRegistry.merge(
2011
2093
  this.getNodeRegistry(register.extend),
@@ -2014,9 +2096,9 @@ var FlowDocument = class {
2014
2096
  );
2015
2097
  }
2016
2098
  if (originParent) {
2017
- const extendRegister = this.getNodeRegistry(
2099
+ const extendRegister = (_c = this.getNodeRegistry(
2018
2100
  originParent.flowNodeType
2019
- ).extendChildRegistries?.find((r) => r.type === type);
2101
+ ).extendChildRegistries) == null ? void 0 : _c.find((r) => r.type === type);
2020
2102
  if (extendRegister) {
2021
2103
  if (extendRegister.extend && this.registers.has(extendRegister.extend)) {
2022
2104
  extendRegisters.push(this.registers.get(extendRegister.extend));
@@ -2026,16 +2108,19 @@ var FlowDocument = class {
2026
2108
  }
2027
2109
  register = FlowNodeRegistry.extend(register, extendRegisters);
2028
2110
  const defaultNodeMeta = DEFAULT_FLOW_NODE_META(type, this);
2029
- defaultNodeMeta.spacing = this.options?.constants?.[ConstantKeys.NODE_SPACING] || defaultNodeMeta.spacing;
2111
+ defaultNodeMeta.spacing = ((_e = (_d = this.options) == null ? void 0 : _d.constants) == null ? void 0 : _e[ConstantKeys.NODE_SPACING]) || defaultNodeMeta.spacing;
2030
2112
  const res = {
2031
2113
  ...customDefaultRegistry,
2032
2114
  ...register,
2033
2115
  meta: {
2034
2116
  ...defaultNodeMeta,
2035
- ...customDefaultRegistry?.meta,
2117
+ ...customDefaultRegistry == null ? void 0 : customDefaultRegistry.meta,
2036
2118
  ...register.meta
2037
2119
  }
2038
2120
  };
2121
+ if (extendKey) {
2122
+ res.extend = extendKey;
2123
+ }
2039
2124
  this.nodeRegistryCache.set(typeKey, res);
2040
2125
  return res;
2041
2126
  }
@@ -2086,8 +2171,8 @@ var FlowDocument = class {
2086
2171
  getAllNodes() {
2087
2172
  return this.entityManager.getEntities(FlowNodeEntity);
2088
2173
  }
2089
- toString() {
2090
- return this.originTree.toString();
2174
+ toString(showType) {
2175
+ return this.originTree.toString(showType);
2091
2176
  }
2092
2177
  /**
2093
2178
  * 返回需要渲染的数据
@@ -2164,12 +2249,13 @@ var FlowDocument = class {
2164
2249
  * @param layoutKey
2165
2250
  */
2166
2251
  setLayout(layoutKey) {
2252
+ var _a;
2167
2253
  if (this.currentLayoutKey === layoutKey) return;
2168
2254
  const layout = this.layouts.find((layout2) => layout2.name === layoutKey);
2169
2255
  if (!layout) return;
2170
2256
  this.currentLayoutKey = layoutKey;
2171
2257
  this.transformer.clear();
2172
- layout.reload?.();
2258
+ (_a = layout.reload) == null ? void 0 : _a.call(layout);
2173
2259
  this.fireRender();
2174
2260
  this.onLayoutChangeEmitter.fire(this.layout);
2175
2261
  }
@@ -2182,6 +2268,7 @@ var FlowDocument = class {
2182
2268
  );
2183
2269
  }
2184
2270
  dispose() {
2271
+ if (this._disposed) return;
2185
2272
  this.registers.clear();
2186
2273
  this.nodeRegistryCache.clear();
2187
2274
  this.originTree.dispose();
@@ -2190,6 +2277,7 @@ var FlowDocument = class {
2190
2277
  this.onNodeCreateEmitter.dispose();
2191
2278
  this.onNodeDisposeEmitter.dispose();
2192
2279
  this.onLayoutChangeEmitter.dispose();
2280
+ this._disposed = true;
2193
2281
  }
2194
2282
  };
2195
2283
  __decorateClass([
@@ -2217,137 +2305,434 @@ FlowDocument = __decorateClass([
2217
2305
  var import_inversify8 = require("inversify");
2218
2306
 
2219
2307
  // src/services/flow-drag-service.ts
2220
- var import_inversify5 = require("inversify");
2221
- var import_core10 = require("@flowgram.ai/core");
2222
- var import_utils9 = require("@flowgram.ai/utils");
2223
-
2224
- // src/services/flow-operation-base-service.ts
2225
2308
  var import_inversify3 = require("inversify");
2226
2309
  var import_utils8 = require("@flowgram.ai/utils");
2227
2310
  var import_core8 = require("@flowgram.ai/core");
2228
- var FlowOperationBaseServiceImpl = class {
2229
- constructor() {
2230
- this.onNodeAddEmitter = new import_utils8.Emitter();
2231
- this.onNodeAdd = this.onNodeAddEmitter.event;
2232
- this.toDispose = new import_utils8.DisposableCollection();
2233
- this.onNodeMoveEmitter = new import_utils8.Emitter();
2234
- this.onNodeMove = this.onNodeMoveEmitter.event;
2311
+
2312
+ // src/services/flow-group-service/flow-group-controller.ts
2313
+ var FlowGroupController = class _FlowGroupController {
2314
+ constructor(groupNode) {
2315
+ this.groupNode = groupNode;
2235
2316
  }
2236
- init() {
2237
- this.toDispose.pushAll([this.onNodeAddEmitter, this.onNodeMoveEmitter]);
2317
+ get nodes() {
2318
+ return this.groupNode.collapsedChildren || [];
2238
2319
  }
2239
- addNode(nodeJSON, config = {}) {
2240
- const { parent, index, hidden } = config;
2241
- let parentEntity;
2242
- if (parent) {
2243
- parentEntity = this.toNodeEntity(parent);
2320
+ get collapsed() {
2321
+ const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2322
+ return groupTransformData.collapsed;
2323
+ }
2324
+ collapse() {
2325
+ this.collapsed = true;
2326
+ }
2327
+ expand() {
2328
+ this.collapsed = false;
2329
+ }
2330
+ /** 获取分组外围的最大边框 */
2331
+ get bounds() {
2332
+ const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
2333
+ return groupNodeBounds;
2334
+ }
2335
+ /** 是否是开始节点 */
2336
+ isStartNode(node) {
2337
+ if (!node) {
2338
+ return false;
2244
2339
  }
2245
- let register;
2246
- if (parentEntity) {
2247
- register = parentEntity.getNodeRegistry();
2340
+ const nodes = this.nodes;
2341
+ if (!nodes[0]) {
2342
+ return false;
2248
2343
  }
2249
- const addJSON = {
2250
- ...nodeJSON,
2251
- type: nodeJSON.type || "block" /* BLOCK */
2252
- };
2253
- const addNodeData = {
2254
- ...addJSON,
2255
- parent: parentEntity,
2256
- index,
2257
- hidden
2258
- };
2259
- let added;
2260
- if (parentEntity && register?.addChild) {
2261
- added = register.addChild(parentEntity, addJSON, {
2262
- index,
2263
- hidden
2264
- });
2265
- } else {
2266
- added = this.document.addNode(addNodeData);
2344
+ return node.id === nodes[0].id;
2345
+ }
2346
+ /** 是否是结束节点 */
2347
+ isEndNode(node) {
2348
+ if (!node) {
2349
+ return false;
2267
2350
  }
2268
- this.onNodeAddEmitter.fire({
2269
- node: added,
2270
- data: addNodeData
2271
- });
2272
- return added;
2351
+ const nodes = this.nodes;
2352
+ if (!nodes[nodes.length - 1]) {
2353
+ return false;
2354
+ }
2355
+ return node.id === nodes[nodes.length - 1].id;
2273
2356
  }
2274
- addFromNode(fromNode, nodeJSON) {
2275
- return this.document.addFromNode(fromNode, nodeJSON);
2357
+ set note(note) {
2358
+ this.groupNode.getNodeMeta().note = note;
2276
2359
  }
2277
- deleteNode(node) {
2278
- this.document.removeNode(node);
2360
+ get note() {
2361
+ return this.groupNode.getNodeMeta().note || "";
2279
2362
  }
2280
- deleteNodes(nodes) {
2281
- (nodes || []).forEach((node) => {
2282
- this.deleteNode(node);
2283
- });
2363
+ set noteHeight(height) {
2364
+ this.groupNode.getNodeMeta().noteHeight = height;
2284
2365
  }
2285
- addBlock(target, blockJSON, config = {}) {
2286
- const { parent, index } = config;
2287
- return this.document.addBlock(target, blockJSON, void 0, parent, index);
2366
+ get noteHeight() {
2367
+ return this.groupNode.getNodeMeta().noteHeight || 0;
2288
2368
  }
2289
- moveNode(node, config = {}) {
2290
- const { parent: newParent, index } = config;
2291
- const entity = this.toNodeEntity(node);
2292
- const parent = entity?.parent;
2293
- if (!parent) {
2294
- return;
2369
+ get positionConfig() {
2370
+ return this.groupNode.getNodeMeta().positionConfig;
2371
+ }
2372
+ set collapsed(collapsed) {
2373
+ var _a;
2374
+ const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2375
+ groupTransformData.collapsed = collapsed;
2376
+ groupTransformData.localDirty = true;
2377
+ if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
2378
+ if ((_a = groupTransformData.parent) == null ? void 0 : _a.firstChild)
2379
+ groupTransformData.parent.firstChild.localDirty = true;
2380
+ }
2381
+ set hovered(hovered) {
2382
+ const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2383
+ if (hovered) {
2384
+ groupRenderData.toggleMouseEnter();
2385
+ } else {
2386
+ groupRenderData.toggleMouseLeave();
2295
2387
  }
2296
- const newParentEntity = newParent ? this.toNodeEntity(newParent) : parent;
2297
- if (!newParentEntity) {
2298
- console.warn("no new parent found", newParent);
2388
+ if (groupRenderData.hovered === hovered) {
2299
2389
  return;
2300
2390
  }
2301
- let toIndex = typeof index === "undefined" ? newParentEntity.collapsedChildren.length : index;
2302
- return this.doMoveNode(entity, newParentEntity, toIndex);
2391
+ groupRenderData.hovered = hovered;
2303
2392
  }
2304
- /**
2305
- * 拖拽节点
2306
- * @param param0
2307
- * @returns
2308
- */
2309
- dragNodes({ dropNode, nodes }) {
2310
- if (nodes.length === 0) {
2393
+ get hovered() {
2394
+ const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2395
+ return groupRenderData.hovered;
2396
+ }
2397
+ static create(groupNode) {
2398
+ if (!groupNode) {
2311
2399
  return;
2312
2400
  }
2313
- const startNode = nodes[0];
2314
- const fromParent = startNode.parent;
2315
- const toParent = dropNode.parent;
2316
- if (!fromParent || !toParent) {
2401
+ if (!FlowGroupUtils.isGroupNode(groupNode)) {
2317
2402
  return;
2318
2403
  }
2319
- const fromIndex = fromParent.children.findIndex((child) => child === startNode);
2320
- const dropIndex = toParent.children.findIndex((child) => child === dropNode);
2321
- let toIndex = dropIndex + 1;
2322
- if (fromParent === toParent && fromIndex < dropIndex) {
2323
- toIndex = toIndex - nodes.length;
2404
+ return new _FlowGroupController(groupNode);
2405
+ }
2406
+ };
2407
+
2408
+ // src/services/flow-group-service/flow-group-utils.ts
2409
+ var FlowGroupUtils;
2410
+ ((FlowGroupUtils2) => {
2411
+ const findNodeParents = (node) => {
2412
+ const parents = [];
2413
+ let parent = node.parent;
2414
+ while (parent) {
2415
+ parents.push(parent);
2416
+ parent = parent.parent;
2324
2417
  }
2325
- const value = {
2326
- nodeIds: nodes.map((node) => node.id),
2327
- fromParentId: fromParent.id,
2328
- toParentId: toParent.id,
2329
- fromIndex,
2330
- toIndex
2331
- };
2332
- return this.apply({
2333
- type: "moveChildNodes" /* moveChildNodes */,
2334
- value
2418
+ return parents;
2419
+ };
2420
+ const isNodeInGroup = (node) => {
2421
+ var _a;
2422
+ if (((_a = node == null ? void 0 : node.parent) == null ? void 0 : _a.flowNodeType) === "group" /* GROUP */) {
2423
+ return true;
2424
+ }
2425
+ return false;
2426
+ };
2427
+ FlowGroupUtils2.validate = (nodes) => {
2428
+ if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
2429
+ return false;
2430
+ }
2431
+ const isGroupRelatedNode = nodes.some((node) => (0, FlowGroupUtils2.isGroupNode)(node));
2432
+ if (isGroupRelatedNode) return false;
2433
+ const hasGroup = nodes.some((node) => node && isNodeInGroup(node));
2434
+ if (hasGroup) return false;
2435
+ const parent = nodes[0].parent;
2436
+ const isSameParent = nodes.every((node) => node.parent === parent);
2437
+ if (!isSameParent) return false;
2438
+ const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
2439
+ const isIndexContinuous = indexes.every((index, i, arr) => {
2440
+ if (i === 0) {
2441
+ return true;
2442
+ }
2443
+ return index === arr[i - 1] + 1;
2335
2444
  });
2445
+ if (!isIndexContinuous) return false;
2446
+ const parents = findNodeParents(nodes[0]);
2447
+ const parentsInGroup = parents.some((parent2) => isNodeInGroup(parent2));
2448
+ if (parentsInGroup) return false;
2449
+ return true;
2450
+ };
2451
+ FlowGroupUtils2.getNodeGroupController = (node) => {
2452
+ if (!node) {
2453
+ return;
2454
+ }
2455
+ if (!isNodeInGroup(node)) {
2456
+ return;
2457
+ }
2458
+ const groupNode = node == null ? void 0 : node.parent;
2459
+ return FlowGroupController.create(groupNode);
2460
+ };
2461
+ FlowGroupUtils2.getNodeRecursionGroupController = (node) => {
2462
+ if (!node) {
2463
+ return;
2464
+ }
2465
+ const group = (0, FlowGroupUtils2.getNodeGroupController)(node);
2466
+ if (group) {
2467
+ return group;
2468
+ }
2469
+ if (node.parent) {
2470
+ return (0, FlowGroupUtils2.getNodeRecursionGroupController)(node.parent);
2471
+ }
2472
+ return;
2473
+ };
2474
+ FlowGroupUtils2.isGroupNode = (group) => group.flowNodeType === "group" /* GROUP */;
2475
+ })(FlowGroupUtils || (FlowGroupUtils = {}));
2476
+
2477
+ // src/services/flow-drag-service.ts
2478
+ var FlowDragService = class {
2479
+ constructor() {
2480
+ this.onDropEmitter = new import_utils8.Emitter();
2481
+ this.onDrop = this.onDropEmitter.event;
2336
2482
  }
2337
- /**
2338
- * 执行操作
2339
- * @param operation 可序列化的操作
2340
- * @returns 操作返回
2341
- */
2342
- apply(operation) {
2343
- const document = this.document;
2344
- switch (operation.type) {
2345
- case "addFromNode" /* addFromNode */:
2346
- return document.addFromNode(operation.value.fromId, operation.value.data);
2347
- case "deleteFromNode" /* deleteFromNode */:
2348
- return document.getNode(operation.value?.data?.id)?.dispose();
2349
- case "addBlock" /* addBlock */: {
2350
- let parent;
2483
+ get renderState() {
2484
+ return this.document.renderState;
2485
+ }
2486
+ // 拖拽所有节点中的首个节点
2487
+ get dragStartNode() {
2488
+ return this.renderState.getDragStartEntity();
2489
+ }
2490
+ // 拖拽的所有节点
2491
+ get dragNodes() {
2492
+ return this.renderState.getDragEntities();
2493
+ }
2494
+ // 放置的区域
2495
+ get dropNodeId() {
2496
+ return this.renderState.getNodeDroppingId();
2497
+ }
2498
+ // 是否在拖拽分支
2499
+ get isDragBranch() {
2500
+ var _a;
2501
+ return (_a = this.dragStartNode) == null ? void 0 : _a.isInlineBlock;
2502
+ }
2503
+ // 拖拽的所有节点及其自节点
2504
+ get nodeDragIdsWithChildren() {
2505
+ return this.renderState.config.nodeDragIdsWithChildren || [];
2506
+ }
2507
+ get dragging() {
2508
+ var _a;
2509
+ const renderData = (_a = this.dragStartNode) == null ? void 0 : _a.getData(FlowNodeRenderData);
2510
+ return !!(renderData == null ? void 0 : renderData.dragging);
2511
+ }
2512
+ get labelSide() {
2513
+ return this.renderState.config.dragLabelSide;
2514
+ }
2515
+ /**
2516
+ * 放置到目标分支
2517
+ */
2518
+ dropBranch() {
2519
+ this.dropNode();
2520
+ }
2521
+ /**
2522
+ * 移动到目标节点
2523
+ */
2524
+ dropNode() {
2525
+ const dropEntity = this.document.getNode(this.dropNodeId);
2526
+ if (!dropEntity) {
2527
+ return;
2528
+ }
2529
+ const sortNodes = [];
2530
+ let curr = this.dragStartNode;
2531
+ while (curr && this.dragNodes.includes(curr)) {
2532
+ sortNodes.push(curr);
2533
+ curr = curr.next;
2534
+ }
2535
+ this.operationService.dragNodes({
2536
+ dropNode: dropEntity,
2537
+ nodes: sortNodes
2538
+ });
2539
+ if (sortNodes.length > 0) {
2540
+ this.onDropEmitter.fire({
2541
+ dropNode: dropEntity,
2542
+ dragNodes: sortNodes
2543
+ });
2544
+ }
2545
+ }
2546
+ /**
2547
+ * 拖拽是否可以释放在该节点后面
2548
+ */
2549
+ isDroppableNode(node) {
2550
+ if (!this.dragging || this.isDragBranch) {
2551
+ return false;
2552
+ }
2553
+ if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
2554
+ return false;
2555
+ }
2556
+ if (node.isInlineBlocks || node.isInlineBlock) {
2557
+ return false;
2558
+ }
2559
+ const hasGroupNode = this.dragNodes.some(
2560
+ (node2) => node2.flowNodeType === "group" /* GROUP */
2561
+ );
2562
+ if (hasGroupNode) {
2563
+ const group = FlowGroupUtils.getNodeRecursionGroupController(node);
2564
+ if (group) {
2565
+ return false;
2566
+ }
2567
+ }
2568
+ return true;
2569
+ }
2570
+ /**
2571
+ * 拖拽分支是否可以释放在该分支
2572
+ * @param node 拖拽的分支节点
2573
+ * @param side 分支的前面还是后面
2574
+ */
2575
+ isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
2576
+ if (this.isDragBranch) {
2577
+ if (
2578
+ // 拖拽到分支
2579
+ !node.isInlineBlock || // 只能在同一分支条件下
2580
+ node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
2581
+ node === this.dragStartNode
2582
+ ) {
2583
+ return false;
2584
+ }
2585
+ if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
2586
+ return true;
2587
+ }
2588
+ if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
2589
+ return true;
2590
+ }
2591
+ }
2592
+ return false;
2593
+ }
2594
+ };
2595
+ __decorateClass([
2596
+ (0, import_inversify3.inject)(FlowDocument)
2597
+ ], FlowDragService.prototype, "document", 2);
2598
+ __decorateClass([
2599
+ (0, import_inversify3.inject)(FlowOperationBaseService)
2600
+ ], FlowDragService.prototype, "operationService", 2);
2601
+ __decorateClass([
2602
+ (0, import_inversify3.inject)(import_core8.EntityManager)
2603
+ ], FlowDragService.prototype, "entityManager", 2);
2604
+ FlowDragService = __decorateClass([
2605
+ (0, import_inversify3.injectable)()
2606
+ ], FlowDragService);
2607
+
2608
+ // src/services/flow-operation-base-service.ts
2609
+ var import_inversify4 = require("inversify");
2610
+ var import_utils9 = require("@flowgram.ai/utils");
2611
+ var import_core9 = require("@flowgram.ai/core");
2612
+ var FlowOperationBaseServiceImpl = class {
2613
+ constructor() {
2614
+ this.onNodeAddEmitter = new import_utils9.Emitter();
2615
+ this.onNodeAdd = this.onNodeAddEmitter.event;
2616
+ this.toDispose = new import_utils9.DisposableCollection();
2617
+ this.onNodeMoveEmitter = new import_utils9.Emitter();
2618
+ this.onNodeMove = this.onNodeMoveEmitter.event;
2619
+ }
2620
+ init() {
2621
+ this.toDispose.pushAll([this.onNodeAddEmitter, this.onNodeMoveEmitter]);
2622
+ }
2623
+ addNode(nodeJSON, config = {}) {
2624
+ const { parent, index, hidden } = config;
2625
+ let parentEntity;
2626
+ if (parent) {
2627
+ parentEntity = this.toNodeEntity(parent);
2628
+ }
2629
+ let register;
2630
+ if (parentEntity) {
2631
+ register = parentEntity.getNodeRegistry();
2632
+ }
2633
+ const addJSON = {
2634
+ ...nodeJSON,
2635
+ type: nodeJSON.type || "block" /* BLOCK */
2636
+ };
2637
+ const addNodeData = {
2638
+ ...addJSON,
2639
+ parent: parentEntity,
2640
+ index,
2641
+ hidden
2642
+ };
2643
+ let added;
2644
+ if (parentEntity && (register == null ? void 0 : register.addChild)) {
2645
+ added = register.addChild(parentEntity, addJSON, {
2646
+ index,
2647
+ hidden
2648
+ });
2649
+ } else {
2650
+ added = this.document.addNode(addNodeData);
2651
+ }
2652
+ this.onNodeAddEmitter.fire({
2653
+ node: added,
2654
+ data: addNodeData
2655
+ });
2656
+ return added;
2657
+ }
2658
+ addFromNode(fromNode, nodeJSON) {
2659
+ return this.document.addFromNode(fromNode, nodeJSON);
2660
+ }
2661
+ deleteNode(node) {
2662
+ this.document.removeNode(node);
2663
+ }
2664
+ deleteNodes(nodes) {
2665
+ (nodes || []).forEach((node) => {
2666
+ this.deleteNode(node);
2667
+ });
2668
+ }
2669
+ addBlock(target, blockJSON, config = {}) {
2670
+ const { parent, index } = config;
2671
+ return this.document.addBlock(target, blockJSON, void 0, parent, index);
2672
+ }
2673
+ moveNode(node, config = {}) {
2674
+ const { parent: newParent, index } = config;
2675
+ const entity = this.toNodeEntity(node);
2676
+ const parent = entity == null ? void 0 : entity.parent;
2677
+ if (!parent) {
2678
+ return;
2679
+ }
2680
+ const newParentEntity = newParent ? this.toNodeEntity(newParent) : parent;
2681
+ if (!newParentEntity) {
2682
+ console.warn("no new parent found", newParent);
2683
+ return;
2684
+ }
2685
+ let toIndex = typeof index === "undefined" ? newParentEntity.collapsedChildren.length : index;
2686
+ return this.doMoveNode(entity, newParentEntity, toIndex);
2687
+ }
2688
+ /**
2689
+ * 拖拽节点
2690
+ * @param param0
2691
+ * @returns
2692
+ */
2693
+ dragNodes({ dropNode, nodes }) {
2694
+ if (nodes.length === 0) {
2695
+ return;
2696
+ }
2697
+ const startNode = nodes[0];
2698
+ const fromParent = startNode.parent;
2699
+ const toParent = dropNode.parent;
2700
+ if (!fromParent || !toParent) {
2701
+ return;
2702
+ }
2703
+ const fromIndex = fromParent.children.findIndex((child) => child === startNode);
2704
+ const dropIndex = toParent.children.findIndex((child) => child === dropNode);
2705
+ let toIndex = dropIndex + 1;
2706
+ if (fromParent === toParent && fromIndex < dropIndex) {
2707
+ toIndex = toIndex - nodes.length;
2708
+ }
2709
+ const value = {
2710
+ nodeIds: nodes.map((node) => node.id),
2711
+ fromParentId: fromParent.id,
2712
+ toParentId: toParent.id,
2713
+ fromIndex,
2714
+ toIndex
2715
+ };
2716
+ return this.apply({
2717
+ type: "moveChildNodes" /* moveChildNodes */,
2718
+ value
2719
+ });
2720
+ }
2721
+ /**
2722
+ * 执行操作
2723
+ * @param operation 可序列化的操作
2724
+ * @returns 操作返回
2725
+ */
2726
+ apply(operation) {
2727
+ var _a, _b, _c, _d, _e, _f;
2728
+ const document = this.document;
2729
+ switch (operation.type) {
2730
+ case "addFromNode" /* addFromNode */:
2731
+ return document.addFromNode(operation.value.fromId, operation.value.data);
2732
+ case "deleteFromNode" /* deleteFromNode */:
2733
+ return (_c = document.getNode((_b = (_a = operation.value) == null ? void 0 : _a.data) == null ? void 0 : _b.id)) == null ? void 0 : _c.dispose();
2734
+ case "addBlock" /* addBlock */: {
2735
+ let parent;
2351
2736
  if (operation.value.parentId) {
2352
2737
  parent = document.getNode(operation.value.parentId);
2353
2738
  }
@@ -2360,8 +2745,8 @@ var FlowOperationBaseServiceImpl = class {
2360
2745
  );
2361
2746
  }
2362
2747
  case "deleteBlock" /* deleteBlock */: {
2363
- const entity = document.getNode(operation.value?.blockData.id);
2364
- return entity?.dispose();
2748
+ const entity = document.getNode((_d = operation.value) == null ? void 0 : _d.blockData.id);
2749
+ return entity == null ? void 0 : entity.dispose();
2365
2750
  }
2366
2751
  case "createGroup" /* createGroup */: {
2367
2752
  const groupNode = document.addFromNode(operation.value.targetId, {
@@ -2380,7 +2765,7 @@ var FlowOperationBaseServiceImpl = class {
2380
2765
  dropNodeId: operation.value.groupId,
2381
2766
  sortNodeIds: operation.value.nodeIds
2382
2767
  });
2383
- return document.getNode(operation.value.groupId)?.dispose();
2768
+ return (_e = document.getNode(operation.value.groupId)) == null ? void 0 : _e.dispose();
2384
2769
  }
2385
2770
  case "moveNodes" /* moveNodes */: {
2386
2771
  return document.moveNodes({
@@ -2405,7 +2790,7 @@ var FlowOperationBaseServiceImpl = class {
2405
2790
  case "deleteNodes" /* deleteNodes */: {
2406
2791
  (operation.value.nodes || []).forEach((node) => {
2407
2792
  const entity = document.getNode(node.id);
2408
- entity?.dispose();
2793
+ entity == null ? void 0 : entity.dispose();
2409
2794
  });
2410
2795
  break;
2411
2796
  }
@@ -2419,7 +2804,7 @@ var FlowOperationBaseServiceImpl = class {
2419
2804
  });
2420
2805
  }
2421
2806
  case "deleteChildNode" /* deleteChildNode */:
2422
- return document.getNode(operation.value.data.id)?.dispose();
2807
+ return (_f = document.getNode(operation.value.data.id)) == null ? void 0 : _f.dispose();
2423
2808
  case "moveChildNodes" /* moveChildNodes */:
2424
2809
  return document.moveChildNodes(operation.value);
2425
2810
  default:
@@ -2444,7 +2829,7 @@ var FlowOperationBaseServiceImpl = class {
2444
2829
  }
2445
2830
  getNodeIndex(node) {
2446
2831
  const entity = this.toNodeEntity(node);
2447
- const parent = entity?.parent;
2832
+ const parent = entity == null ? void 0 : entity.parent;
2448
2833
  if (!parent) {
2449
2834
  return -1;
2450
2835
  }
@@ -2470,29 +2855,29 @@ var FlowOperationBaseServiceImpl = class {
2470
2855
  }
2471
2856
  };
2472
2857
  __decorateClass([
2473
- (0, import_inversify3.inject)(import_core8.EntityManager)
2858
+ (0, import_inversify4.inject)(import_core9.EntityManager)
2474
2859
  ], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
2475
2860
  __decorateClass([
2476
- (0, import_inversify3.inject)(FlowDocument)
2861
+ (0, import_inversify4.inject)(FlowDocument)
2477
2862
  ], FlowOperationBaseServiceImpl.prototype, "document", 2);
2478
2863
  __decorateClass([
2479
- (0, import_inversify3.postConstruct)()
2864
+ (0, import_inversify4.postConstruct)()
2480
2865
  ], FlowOperationBaseServiceImpl.prototype, "init", 1);
2481
2866
  FlowOperationBaseServiceImpl = __decorateClass([
2482
- (0, import_inversify3.injectable)()
2867
+ (0, import_inversify4.injectable)()
2483
2868
  ], FlowOperationBaseServiceImpl);
2484
2869
 
2485
- // src/services/flow-group-service.ts
2870
+ // src/services/flow-group-service/flow-group-service.ts
2486
2871
  var import_nanoid = require("nanoid");
2487
- var import_inversify4 = require("inversify");
2488
- var import_core9 = require("@flowgram.ai/core");
2872
+ var import_inversify5 = require("inversify");
2873
+ var import_core10 = require("@flowgram.ai/core");
2489
2874
  var FlowGroupService = class {
2490
2875
  /** 创建分组节点 */
2491
2876
  createGroup(nodes) {
2492
2877
  if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
2493
2878
  return;
2494
2879
  }
2495
- if (!FlowGroupController.validate(nodes)) {
2880
+ if (!FlowGroupUtils.validate(nodes)) {
2496
2881
  return;
2497
2882
  }
2498
2883
  const sortedNodes = nodes.sort((a, b) => a.index - b.index);
@@ -2562,309 +2947,18 @@ var FlowGroupService = class {
2562
2947
  return FlowGroupController.create(group);
2563
2948
  }
2564
2949
  static validate(nodes) {
2565
- return FlowGroupController.validate(nodes);
2950
+ return FlowGroupUtils.validate(nodes);
2566
2951
  }
2567
2952
  };
2568
2953
  __decorateClass([
2569
- (0, import_inversify4.inject)(import_core9.EntityManager)
2954
+ (0, import_inversify5.inject)(import_core10.EntityManager)
2570
2955
  ], FlowGroupService.prototype, "entityManager", 2);
2571
2956
  __decorateClass([
2572
- (0, import_inversify4.inject)(FlowOperationBaseService)
2957
+ (0, import_inversify5.inject)(FlowOperationBaseService)
2573
2958
  ], FlowGroupService.prototype, "operationService", 2);
2574
2959
  FlowGroupService = __decorateClass([
2575
- (0, import_inversify4.injectable)()
2576
- ], FlowGroupService);
2577
- var FlowGroupController = class _FlowGroupController {
2578
- constructor(groupNode) {
2579
- this.groupNode = groupNode;
2580
- }
2581
- get nodes() {
2582
- return this.groupNode.collapsedChildren || [];
2583
- }
2584
- get collapsed() {
2585
- const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2586
- return groupTransformData.collapsed;
2587
- }
2588
- collapse() {
2589
- this.collapsed = true;
2590
- }
2591
- expand() {
2592
- this.collapsed = false;
2593
- }
2594
- /** 获取分组外围的最大边框 */
2595
- get bounds() {
2596
- const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
2597
- return groupNodeBounds;
2598
- }
2599
- /** 是否是开始节点 */
2600
- isStartNode(node) {
2601
- if (!node) {
2602
- return false;
2603
- }
2604
- const nodes = this.nodes;
2605
- if (!nodes[0]) {
2606
- return false;
2607
- }
2608
- return node.id === nodes[0].id;
2609
- }
2610
- /** 是否是结束节点 */
2611
- isEndNode(node) {
2612
- if (!node) {
2613
- return false;
2614
- }
2615
- const nodes = this.nodes;
2616
- if (!nodes[nodes.length - 1]) {
2617
- return false;
2618
- }
2619
- return node.id === nodes[nodes.length - 1].id;
2620
- }
2621
- set note(note) {
2622
- this.groupNode.getNodeMeta().note = note;
2623
- }
2624
- get note() {
2625
- return this.groupNode.getNodeMeta().note || "";
2626
- }
2627
- set noteHeight(height) {
2628
- this.groupNode.getNodeMeta().noteHeight = height;
2629
- }
2630
- get noteHeight() {
2631
- return this.groupNode.getNodeMeta().noteHeight || 0;
2632
- }
2633
- get positionConfig() {
2634
- return this.groupNode.getNodeMeta().positionConfig;
2635
- }
2636
- set collapsed(collapsed) {
2637
- const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2638
- groupTransformData.collapsed = collapsed;
2639
- groupTransformData.localDirty = true;
2640
- if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
2641
- if (groupTransformData.parent?.firstChild)
2642
- groupTransformData.parent.firstChild.localDirty = true;
2643
- }
2644
- set hovered(hovered) {
2645
- const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2646
- if (hovered) {
2647
- groupRenderData.toggleMouseEnter();
2648
- } else {
2649
- groupRenderData.toggleMouseLeave();
2650
- }
2651
- if (groupRenderData.hovered === hovered) {
2652
- return;
2653
- }
2654
- groupRenderData.hovered = hovered;
2655
- }
2656
- get hovered() {
2657
- const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2658
- return groupRenderData.hovered;
2659
- }
2660
- static create(groupNode) {
2661
- if (!groupNode) {
2662
- return;
2663
- }
2664
- if (!_FlowGroupController.isGroupNode(groupNode)) {
2665
- return;
2666
- }
2667
- return new _FlowGroupController(groupNode);
2668
- }
2669
- /** 判断节点能否组成分组 */
2670
- static validate(nodes) {
2671
- if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
2672
- return false;
2673
- }
2674
- const isGroupRelatedNode = nodes.some((node) => _FlowGroupController.isGroupNode(node));
2675
- if (isGroupRelatedNode) return false;
2676
- const hasGroup = nodes.some((node) => node && this.isNodeInGroup(node));
2677
- if (hasGroup) return false;
2678
- const parent = nodes[0].parent;
2679
- const isSameParent = nodes.every((node) => node.parent === parent);
2680
- if (!isSameParent) return false;
2681
- const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
2682
- const isIndexContinuous = indexes.every((index, i, arr) => {
2683
- if (i === 0) {
2684
- return true;
2685
- }
2686
- return index === arr[i - 1] + 1;
2687
- });
2688
- if (!isIndexContinuous) return false;
2689
- const parents = this.findNodeParents(nodes[0]);
2690
- const parentsInGroup = parents.some((parent2) => this.isNodeInGroup(parent2));
2691
- if (parentsInGroup) return false;
2692
- return true;
2693
- }
2694
- /** 获取节点分组控制 */
2695
- static getNodeGroupController(node) {
2696
- if (!node) {
2697
- return;
2698
- }
2699
- if (!this.isNodeInGroup(node)) {
2700
- return;
2701
- }
2702
- const groupNode = node?.parent;
2703
- return _FlowGroupController.create(groupNode);
2704
- }
2705
- /** 向上递归查找分组递归控制 */
2706
- static getNodeRecursionGroupController(node) {
2707
- if (!node) {
2708
- return;
2709
- }
2710
- const group = this.getNodeGroupController(node);
2711
- if (group) {
2712
- return group;
2713
- }
2714
- if (node.parent) {
2715
- return this.getNodeRecursionGroupController(node.parent);
2716
- }
2717
- return;
2718
- }
2719
- /** 是否分组节点 */
2720
- static isGroupNode(group) {
2721
- return group.flowNodeType === "group" /* GROUP */;
2722
- }
2723
- /** 找到节点所有上级 */
2724
- static findNodeParents(node) {
2725
- const parents = [];
2726
- let parent = node.parent;
2727
- while (parent) {
2728
- parents.push(parent);
2729
- parent = parent.parent;
2730
- }
2731
- return parents;
2732
- }
2733
- /** 节点是否处于分组中 */
2734
- static isNodeInGroup(node) {
2735
- if (node?.parent?.flowNodeType === "group" /* GROUP */) {
2736
- return true;
2737
- }
2738
- return false;
2739
- }
2740
- };
2741
-
2742
- // src/services/flow-drag-service.ts
2743
- var FlowDragService = class {
2744
- constructor() {
2745
- this.onDropEmitter = new import_utils9.Emitter();
2746
- this.onDrop = this.onDropEmitter.event;
2747
- }
2748
- get renderState() {
2749
- return this.document.renderState;
2750
- }
2751
- // 拖拽所有节点中的首个节点
2752
- get dragStartNode() {
2753
- return this.renderState.getDragStartEntity();
2754
- }
2755
- // 拖拽的所有节点
2756
- get dragNodes() {
2757
- return this.renderState.getDragEntities();
2758
- }
2759
- // 放置的区域
2760
- get dropNodeId() {
2761
- return this.renderState.getNodeDroppingId();
2762
- }
2763
- // 是否在拖拽分支
2764
- get isDragBranch() {
2765
- return this.dragStartNode?.isInlineBlock;
2766
- }
2767
- // 拖拽的所有节点及其自节点
2768
- get nodeDragIdsWithChildren() {
2769
- return this.renderState.config.nodeDragIdsWithChildren || [];
2770
- }
2771
- get dragging() {
2772
- const renderData = this.dragStartNode?.getData(FlowNodeRenderData);
2773
- return !!renderData?.dragging;
2774
- }
2775
- get labelSide() {
2776
- return this.renderState.config.dragLabelSide;
2777
- }
2778
- /**
2779
- * 放置到目标分支
2780
- */
2781
- dropBranch() {
2782
- this.dropNode();
2783
- }
2784
- /**
2785
- * 移动到目标节点
2786
- */
2787
- dropNode() {
2788
- const dropEntity = this.document.getNode(this.dropNodeId);
2789
- if (!dropEntity) {
2790
- return;
2791
- }
2792
- const sortNodes = [];
2793
- let curr = this.dragStartNode;
2794
- while (curr && this.dragNodes.includes(curr)) {
2795
- sortNodes.push(curr);
2796
- curr = curr.next;
2797
- }
2798
- this.operationService.dragNodes({
2799
- dropNode: dropEntity,
2800
- nodes: sortNodes
2801
- });
2802
- if (sortNodes.length > 0) {
2803
- this.onDropEmitter.fire({
2804
- dropNode: dropEntity,
2805
- dragNodes: sortNodes
2806
- });
2807
- }
2808
- }
2809
- /**
2810
- * 拖拽是否可以释放在该节点后面
2811
- */
2812
- isDroppableNode(node) {
2813
- if (!this.dragging || this.isDragBranch) {
2814
- return false;
2815
- }
2816
- if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
2817
- return false;
2818
- }
2819
- if (node.isInlineBlocks || node.isInlineBlock) {
2820
- return false;
2821
- }
2822
- const hasGroupNode = this.dragNodes.some((node2) => node2.flowNodeType === "group" /* GROUP */);
2823
- if (hasGroupNode) {
2824
- const group = FlowGroupController.getNodeRecursionGroupController(node);
2825
- if (group) {
2826
- return false;
2827
- }
2828
- }
2829
- return true;
2830
- }
2831
- /**
2832
- * 拖拽分支是否可以释放在该分支
2833
- * @param node 拖拽的分支节点
2834
- * @param side 分支的前面还是后面
2835
- */
2836
- isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
2837
- if (this.isDragBranch) {
2838
- if (
2839
- // 拖拽到分支
2840
- !node.isInlineBlock || // 只能在同一分支条件下
2841
- node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
2842
- node === this.dragStartNode
2843
- ) {
2844
- return false;
2845
- }
2846
- if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
2847
- return true;
2848
- }
2849
- if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
2850
- return true;
2851
- }
2852
- }
2853
- return false;
2854
- }
2855
- };
2856
- __decorateClass([
2857
- (0, import_inversify5.inject)(FlowDocument)
2858
- ], FlowDragService.prototype, "document", 2);
2859
- __decorateClass([
2860
- (0, import_inversify5.inject)(FlowOperationBaseService)
2861
- ], FlowDragService.prototype, "operationService", 2);
2862
- __decorateClass([
2863
- (0, import_inversify5.inject)(import_core10.EntityManager)
2864
- ], FlowDragService.prototype, "entityManager", 2);
2865
- FlowDragService = __decorateClass([
2866
2960
  (0, import_inversify5.injectable)()
2867
- ], FlowDragService);
2961
+ ], FlowGroupService);
2868
2962
 
2869
2963
  // src/layout/vertical-fixed-layout.ts
2870
2964
  var import_inversify6 = require("inversify");
@@ -2895,6 +2989,7 @@ var VerticalFixedLayout = class {
2895
2989
  * @param forceChange
2896
2990
  */
2897
2991
  updateLocalTransform(node, forceChange = false) {
2992
+ var _a, _b, _c, _d;
2898
2993
  const { children, parent, isInlineBlock } = node;
2899
2994
  const transform = node.getData(FlowNodeTransformData);
2900
2995
  const { getDelta, getOrigin } = node.getNodeRegistry();
@@ -2928,9 +3023,9 @@ var VerticalFixedLayout = class {
2928
3023
  origin: getOrigin ? getOrigin(transform, this) : this.getDefaultNodeOrigin()
2929
3024
  });
2930
3025
  const preTransform = transform.pre;
2931
- const delta = getDelta?.(transform, this) || { x: 0, y: 0 };
2932
- const inlineSpacingPre = isInlineBlock && transform.parent?.inlineSpacingPre ? transform.parent?.inlineSpacingPre : 0;
2933
- const fromParentDelta = parent?.getNodeRegistry().getChildDelta?.(transform, this) || {
3026
+ const delta = (getDelta == null ? void 0 : getDelta(transform, this)) || { x: 0, y: 0 };
3027
+ const inlineSpacingPre = isInlineBlock && ((_a = transform.parent) == null ? void 0 : _a.inlineSpacingPre) ? (_b = transform.parent) == null ? void 0 : _b.inlineSpacingPre : 0;
3028
+ const fromParentDelta = ((_d = parent == null ? void 0 : (_c = parent.getNodeRegistry()).getChildDelta) == null ? void 0 : _d.call(_c, transform, this)) || {
2934
3029
  x: 0,
2935
3030
  y: 0
2936
3031
  };
@@ -2940,8 +3035,8 @@ var VerticalFixedLayout = class {
2940
3035
  if (isInlineBlock) {
2941
3036
  position.y += inlineSpacingPre;
2942
3037
  } else {
2943
- position.y += preTransform?.localBounds.bottom || 0;
2944
- position.y += preTransform?.spacing || 0;
3038
+ position.y += (preTransform == null ? void 0 : preTransform.localBounds.bottom) || 0;
3039
+ position.y += (preTransform == null ? void 0 : preTransform.spacing) || 0;
2945
3040
  }
2946
3041
  transform.transform.update({
2947
3042
  size: transform.data.size,
@@ -2952,10 +3047,12 @@ var VerticalFixedLayout = class {
2952
3047
  return true;
2953
3048
  }
2954
3049
  onAfterUpdateLocalTransform(transform) {
3050
+ var _a;
2955
3051
  const { onAfterUpdateLocalTransform } = transform.entity.getNodeRegistry();
2956
- onAfterUpdateLocalTransform?.(transform, this);
2957
- this.contribs?.forEach((_contrib) => {
2958
- _contrib?.onAfterUpdateLocalTransform?.(transform, this);
3052
+ onAfterUpdateLocalTransform == null ? void 0 : onAfterUpdateLocalTransform(transform, this);
3053
+ (_a = this.contribs) == null ? void 0 : _a.forEach((_contrib) => {
3054
+ var _a2;
3055
+ (_a2 = _contrib == null ? void 0 : _contrib.onAfterUpdateLocalTransform) == null ? void 0 : _a2.call(_contrib, transform, this);
2959
3056
  });
2960
3057
  }
2961
3058
  getNodeTransform(node) {
@@ -3032,6 +3129,7 @@ var HorizontalFixedLayout = class {
3032
3129
  * @param forceChange
3033
3130
  */
3034
3131
  updateLocalTransform(node, forceChange = false) {
3132
+ var _a, _b, _c, _d;
3035
3133
  const { children, parent, isInlineBlock } = node;
3036
3134
  const transform = node.getData(FlowNodeTransformData);
3037
3135
  const { getDelta, getOrigin } = node.getNodeRegistry();
@@ -3065,9 +3163,9 @@ var HorizontalFixedLayout = class {
3065
3163
  origin: getOrigin ? getOrigin(transform, this) : this.getDefaultNodeOrigin()
3066
3164
  });
3067
3165
  const preTransform = transform.pre;
3068
- const delta = getDelta?.(transform, this) || { x: 0, y: 0 };
3069
- const inlineSpacingPre = isInlineBlock && transform.parent?.inlineSpacingPre ? transform.parent?.inlineSpacingPre : 0;
3070
- const fromParentDelta = parent?.getNodeRegistry().getChildDelta?.(transform, this) || {
3166
+ const delta = (getDelta == null ? void 0 : getDelta(transform, this)) || { x: 0, y: 0 };
3167
+ const inlineSpacingPre = isInlineBlock && ((_a = transform.parent) == null ? void 0 : _a.inlineSpacingPre) ? (_b = transform.parent) == null ? void 0 : _b.inlineSpacingPre : 0;
3168
+ const fromParentDelta = ((_d = parent == null ? void 0 : (_c = parent.getNodeRegistry()).getChildDelta) == null ? void 0 : _d.call(_c, transform, this)) || {
3071
3169
  x: 0,
3072
3170
  y: 0
3073
3171
  };
@@ -3077,8 +3175,8 @@ var HorizontalFixedLayout = class {
3077
3175
  if (isInlineBlock) {
3078
3176
  position.x += inlineSpacingPre;
3079
3177
  } else {
3080
- position.x += preTransform?.localBounds.right || 0;
3081
- position.x += preTransform?.spacing || 0;
3178
+ position.x += (preTransform == null ? void 0 : preTransform.localBounds.right) || 0;
3179
+ position.x += (preTransform == null ? void 0 : preTransform.spacing) || 0;
3082
3180
  }
3083
3181
  transform.transform.update({
3084
3182
  size: transform.data.size,
@@ -3089,10 +3187,12 @@ var HorizontalFixedLayout = class {
3089
3187
  return true;
3090
3188
  }
3091
3189
  onAfterUpdateLocalTransform(transform) {
3190
+ var _a;
3092
3191
  const { onAfterUpdateLocalTransform } = transform.entity.getNodeRegistry();
3093
- onAfterUpdateLocalTransform?.(transform, this);
3094
- this.contribs?.forEach((_contrib) => {
3095
- _contrib?.onAfterUpdateLocalTransform?.(transform, this);
3192
+ onAfterUpdateLocalTransform == null ? void 0 : onAfterUpdateLocalTransform(transform, this);
3193
+ (_a = this.contribs) == null ? void 0 : _a.forEach((_contrib) => {
3194
+ var _a2;
3195
+ (_a2 = _contrib == null ? void 0 : _contrib.onAfterUpdateLocalTransform) == null ? void 0 : _a2.call(_contrib, transform, this);
3096
3196
  });
3097
3197
  }
3098
3198
  getNodeTransform(node) {
@@ -3160,8 +3260,9 @@ var FlowDocumentContainerModule = new import_inversify8.ContainerModule((bind) =
3160
3260
 
3161
3261
  // src/utils/get-default-spacing.ts
3162
3262
  var getDefaultSpacing = (node, key, defaultSpacing) => {
3263
+ var _a;
3163
3264
  const flowDocumentOptions = node.getService(FlowDocumentOptions);
3164
- const spacing = flowDocumentOptions?.constants?.[key] || defaultSpacing || DEFAULT_SPACING[key];
3265
+ const spacing = ((_a = flowDocumentOptions == null ? void 0 : flowDocumentOptions.constants) == null ? void 0 : _a[key]) || defaultSpacing || DEFAULT_SPACING[key];
3165
3266
  return spacing;
3166
3267
  };
3167
3268
  // Annotate the CommonJS export names for ESM import in node: