@flowgram.ai/free-layout-core 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
@@ -191,6 +191,7 @@ var PORT_SIZE = 24;
191
191
  var WorkflowPortEntity = class extends import_core4.Entity {
192
192
  // relativePosition
193
193
  constructor(opts) {
194
+ var _a;
194
195
  super(opts);
195
196
  this.portID = "";
196
197
  this._disabled = false;
@@ -199,7 +200,7 @@ var WorkflowPortEntity = class extends import_core4.Entity {
199
200
  this.onErrorChanged = this._onErrorChangedEmitter.event;
200
201
  this.portID = opts.portID || "";
201
202
  this.portType = opts.type;
202
- this._disabled = opts.disabled ?? false;
203
+ this._disabled = (_a = opts.disabled) != null ? _a : false;
203
204
  this.node = opts.node;
204
205
  this.updateTargetElement(opts.targetElement);
205
206
  this.toDispose.push(this.node.getData(import_core4.TransformData).onDataChange(() => this.fireChange()));
@@ -329,6 +330,7 @@ WorkflowPortEntity.type = "WorkflowPortEntity";
329
330
  // src/entity-datas/workflow-node-ports-data.ts
330
331
  var WorkflowNodePortsData = class extends import_core5.EntityData {
331
332
  constructor(entity) {
333
+ var _a;
332
334
  super(entity);
333
335
  /** 静态的 ports 数据 */
334
336
  this._staticPorts = [];
@@ -337,7 +339,7 @@ var WorkflowNodePortsData = class extends import_core5.EntityData {
337
339
  this.entity = entity;
338
340
  const meta = entity.getNodeMeta();
339
341
  const defaultPorts = meta.useDynamicPort ? [] : [{ type: "input" }, { type: "output" }];
340
- this._staticPorts = meta.defaultPorts?.slice() || defaultPorts;
342
+ this._staticPorts = ((_a = meta.defaultPorts) == null ? void 0 : _a.slice()) || defaultPorts;
341
343
  this.updatePorts(this._staticPorts);
342
344
  if (meta.useDynamicPort) {
343
345
  this.toDispose.push(
@@ -404,8 +406,9 @@ var WorkflowNodePortsData = class extends import_core5.EntityData {
404
406
  if (!(0, import_lodash_es.isEqual)(this._prePorts, ports)) {
405
407
  const portKeys = ports.map((port) => this.getPortId(port.type, port.portID));
406
408
  this._portIDSet.forEach((portId) => {
409
+ var _a;
407
410
  if (!portKeys.includes(portId)) {
408
- this.getPortEntity(portId)?.dispose();
411
+ (_a = this.getPortEntity(portId)) == null ? void 0 : _a.dispose();
409
412
  }
410
413
  });
411
414
  ports.forEach((port) => this.updatePortEntity(port));
@@ -499,8 +502,9 @@ var WorkflowNodePortsData = class extends import_core5.EntityData {
499
502
  * 获取或创建 port 实体
500
503
  */
501
504
  getOrCreatePortEntity(portInfo) {
505
+ var _a;
502
506
  const id = this.getPortId(portInfo.type, portInfo.portID);
503
- return this.getPortEntity(id) ?? this.createPortEntity(portInfo);
507
+ return (_a = this.getPortEntity(id)) != null ? _a : this.createPortEntity(portInfo);
504
508
  }
505
509
  /**
506
510
  * 更新 port 实体
@@ -568,7 +572,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends import_core6.E
568
572
  return;
569
573
  }
570
574
  inputNodes.forEach((inputNode) => {
571
- if (inputNode?.parent === node || node?.parent === inputNode) {
575
+ if ((inputNode == null ? void 0 : inputNode.parent) === node || (node == null ? void 0 : node.parent) === inputNode) {
572
576
  return;
573
577
  }
574
578
  handleNode(inputNode);
@@ -599,7 +603,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends import_core6.E
599
603
  return;
600
604
  }
601
605
  outputNodes.forEach((outputNode) => {
602
- if (outputNode?.parent === node || node?.parent === outputNode) {
606
+ if ((outputNode == null ? void 0 : outputNode.parent) === node || (node == null ? void 0 : node.parent) === outputNode) {
603
607
  return;
604
608
  }
605
609
  handleNode(outputNode);
@@ -659,19 +663,23 @@ var WorkflowLineRenderData = class extends import_core7.EntityData {
659
663
  return this.data.position;
660
664
  }
661
665
  get path() {
662
- return this.currentLine?.path ?? "";
666
+ var _a, _b;
667
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.path) != null ? _b : "";
663
668
  }
664
669
  calcDistance(pos) {
665
- return this.currentLine?.calcDistance(pos) ?? Number.MAX_SAFE_INTEGER;
670
+ var _a, _b;
671
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.calcDistance(pos)) != null ? _b : Number.MAX_SAFE_INTEGER;
666
672
  }
667
673
  get bounds() {
668
- return this.currentLine?.bounds ?? new import_utils7.Rectangle();
674
+ var _a, _b;
675
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.bounds) != null ? _b : new import_utils7.Rectangle();
669
676
  }
670
677
  /**
671
678
  * 更新数据
672
679
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
673
680
  */
674
681
  update() {
682
+ var _a;
675
683
  this.syncContributions();
676
684
  const oldVersion = this.data.version;
677
685
  this.updatePosition();
@@ -680,21 +688,23 @@ var WorkflowLineRenderData = class extends import_core7.EntityData {
680
688
  return;
681
689
  }
682
690
  this.data.version = newVersion;
683
- this.currentLine?.update({
691
+ (_a = this.currentLine) == null ? void 0 : _a.update({
684
692
  fromPos: this.data.position.from,
685
693
  toPos: this.data.position.to
686
694
  });
687
695
  }
688
696
  get lineType() {
689
- return this.entity.renderType ?? this.entity.linesManager.lineType;
697
+ var _a;
698
+ return (_a = this.entity.renderType) != null ? _a : this.entity.linesManager.lineType;
690
699
  }
691
700
  /**
692
701
  * 更新版本
693
702
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
694
703
  */
695
704
  updatePosition() {
705
+ var _a, _b, _c, _d;
696
706
  this.data.position.from = this.entity.from.getData(WorkflowNodePortsData).getOutputPoint(this.entity.info.fromPort);
697
- this.data.position.to = this.entity.info.drawingTo ?? this.entity.to?.getData(WorkflowNodePortsData)?.getInputPoint(this.entity.info.toPort) ?? {
707
+ this.data.position.to = (_d = (_c = this.entity.info.drawingTo) != null ? _c : (_b = (_a = this.entity.to) == null ? void 0 : _a.getData(WorkflowNodePortsData)) == null ? void 0 : _b.getInputPoint(this.entity.info.toPort)) != null ? _d : {
698
708
  x: this.data.position.from.x,
699
709
  y: this.data.position.from.y
700
710
  };
@@ -778,7 +788,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
778
788
  return this.highlightColor === this.linesManager.lineColor.hidden;
779
789
  }
780
790
  get inContainer() {
781
- const nodeInContainer = (node) => !!node?.parent && node.parent.flowNodeType !== "root";
791
+ const nodeInContainer = (node) => !!(node == null ? void 0 : node.parent) && node.parent.flowNodeType !== "root";
782
792
  return nodeInContainer(this.from) || nodeInContainer(this.to);
783
793
  }
784
794
  /**
@@ -919,7 +929,8 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
919
929
  }
920
930
  /** 获取线条样式 */
921
931
  get className() {
922
- return this.linesManager.setLineClassName(this) ?? "";
932
+ var _a;
933
+ return (_a = this.linesManager.setLineClassName(this)) != null ? _a : "";
923
934
  }
924
935
  get color() {
925
936
  return this.linesManager.getLineColor(this);
@@ -940,8 +951,8 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
940
951
  validate() {
941
952
  const { fromPort, toPort } = this;
942
953
  this.validateSelf();
943
- fromPort?.validate();
944
- toPort?.validate();
954
+ fromPort == null ? void 0 : fromPort.validate();
955
+ toPort == null ? void 0 : toPort.validate();
945
956
  }
946
957
  validateSelf() {
947
958
  const { fromPort, toPort } = this;
@@ -959,14 +970,15 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
959
970
  return this.linesManager.canRemove(this, newLineInfo);
960
971
  }
961
972
  get node() {
973
+ var _a, _b, _c, _d, _e, _f;
962
974
  if (this._node) return this._node;
963
975
  this._node = import_utils8.domUtils.createDivWithClass("gedit-flow-activity-line");
964
976
  this._node.dataset.testid = "sdk.workflow.canvas.line";
965
977
  this._node.dataset.lineId = this.id;
966
978
  this._node.dataset.fromNodeId = this.from.id;
967
- this._node.dataset.fromPortId = this.fromPort?.id ?? "";
968
- this._node.dataset.toNodeId = this.to?.id ?? "";
969
- this._node.dataset.toPortId = this.toPort?.id ?? "";
979
+ this._node.dataset.fromPortId = (_b = (_a = this.fromPort) == null ? void 0 : _a.id) != null ? _b : "";
980
+ this._node.dataset.toNodeId = (_d = (_c = this.to) == null ? void 0 : _c.id) != null ? _d : "";
981
+ this._node.dataset.toPortId = (_f = (_e = this.toPort) == null ? void 0 : _e.id) != null ? _f : "";
970
982
  this._node.dataset.hasError = this.hasError ? "true" : "false";
971
983
  return this._node;
972
984
  }
@@ -1018,7 +1030,8 @@ var WorkflowSelectService = class {
1018
1030
  return this.selectionService.selection.some((s) => s.id === id);
1019
1031
  }
1020
1032
  isActivated(id) {
1021
- return this.activatedNode?.id === id;
1033
+ var _a;
1034
+ return ((_a = this.activatedNode) == null ? void 0 : _a.id) === id;
1022
1035
  }
1023
1036
  /**
1024
1037
  * 选中的节点
@@ -1089,8 +1102,8 @@ WorkflowSelectService = __decorateClass([
1089
1102
 
1090
1103
  // src/service/workflow-hover-service.ts
1091
1104
  var import_inversify2 = require("inversify");
1092
- var import_core10 = require("@flowgram.ai/core");
1093
1105
  var import_utils11 = require("@flowgram.ai/utils");
1106
+ var import_core10 = require("@flowgram.ai/core");
1094
1107
  var WorkflowHoverService = class {
1095
1108
  constructor() {
1096
1109
  this.onHoveredChangeEmitter = new import_utils11.Emitter();
@@ -1210,19 +1223,23 @@ function toFormJSON(node) {
1210
1223
  if (!formData || !node.getNodeRegistry().formMeta) return void 0;
1211
1224
  return formData.toJSON();
1212
1225
  }
1213
- function initFormDataFromJSON(node, json) {
1226
+ function initFormDataFromJSON(node, json, isFirstCreate) {
1214
1227
  const formData = node.getData(import_form_core.FlowNodeFormData);
1215
1228
  const registry = node.getNodeRegistry();
1216
1229
  const { formMeta } = registry;
1217
1230
  if (formData && formMeta) {
1218
- formData.createForm(formMeta, json.data);
1219
- formData.onDataChange(() => {
1220
- node.document.fireContentChange({
1221
- type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
1222
- toJSON: () => formData.toJSON(),
1223
- entity: node
1231
+ if (isFirstCreate) {
1232
+ formData.createForm(formMeta, json.data);
1233
+ formData.onDataChange(() => {
1234
+ node.document.fireContentChange({
1235
+ type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
1236
+ toJSON: () => formData.toJSON(),
1237
+ entity: node
1238
+ });
1224
1239
  });
1225
- });
1240
+ } else {
1241
+ formData.updateFormValues(json.data);
1242
+ }
1226
1243
  }
1227
1244
  }
1228
1245
 
@@ -1233,12 +1250,13 @@ var WorkflowDocumentOptionsDefault = {
1233
1250
  grab: 'url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMCAyMSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMC40ODczIDIuNjIzNzhDOS45MDczMSAyLjYyMzc4IDkuNDM3MTMgMy4wOTM5NiA5LjQzNzEzIDMuNjczOTZWNS4xNDM3NkM5LjM5NDI4IDQuNDAyNzQgOC43Nzk3OCAzLjgxNTA0IDguMDI4MDIgMy44MTUwNEM3LjI0ODQ4IDMuODE1MDQgNi42MTY1MyA0LjQ0Njk5IDYuNjE2NTMgNS4yMjY1M1YxMS44Mjg5TDUuNjc0MTggMTEuMDA0OUM1LjE1NDg3IDEwLjU1MDkgNC40MDk1IDEwLjQ2MzYgMy43OTkzOCAxMC43ODU1TDMuNjk2OTQgMTAuODM5NkMzLjA2MjE3IDExLjE3NDUgMi45MjI2IDEyLjAyMjggMy40MTY2MiAxMi41NDM0TDcuMzM5NTkgMTYuNjc3NVYxNy4zMjU5QzcuMzM5NTkgMTcuNzg2MiA3LjcxMjY5IDE4LjE1OTMgOC4xNzI5MiAxOC4xNTkzSDEzLjgwODRDMTQuMjY4NyAxOC4xNTkzIDE0LjY0MTcgMTc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yVjE2Ljc5MzhDMTUuNzM4MSAxNS43MTkgMTYuMzg1IDE0LjI3MjggMTYuNDYwMyAxMi43NDdDMTYuNDY0NiAxMi42NiAxNi40NjcgMTIuNTcyOCAxNi40Njc2IDEyLjQ4NTRMMTYuNDY3NyAxMi40NDY3TDE2LjQ2NzYgOC4wMTk4M0MxNi40Njc2IDcuMzQ1MDQgMTUuOTI1MiA2Ljc5NjkzIDE1LjI1MjUgNi43ODc3MUwxNS4yMzUzIDYuNzg3NTlDMTUuMTI1IDYuNzg3NTkgMTUuMDE4IDYuODAyMSAxNC45MTYyIDYuODI5MzFWOS42MDEzNkMxNC45MTYyIDkuODUzNDIgMTQuNzExOSAxMC4wNTc3IDE0LjQ1OTggMTAuMDU3N0MxNC4yMDc4IDEwLjA1NzcgMTQuMDAzNCA5Ljg1MzQxIDE0LjAwMzQgOS42MDEzNlY3Ljk4OTg1QzE0LjAwMzIgNy45OTk4MiAxNC4wMDMxIDguMDA5ODEgMTQuMDAzMSA4LjAxOTgzTDE0LjAwMzQgOS42MDEzNkwxNC4wMDI1IDYuNzExNUMxNC4wMDI1IDYuNDQ5NzQgMTMuOTIwOSA2LjIwNzA1IDEzLjc4MTggNi4wMDc0OEMxMy41NjIgNS42OTI0MiAxMy4xOTg5IDUuNDg0ODMgMTIuNzg3IDUuNDc5MzdMMTIuNzcwMyA1LjQ3OTI2QzEyLjY1ODggNS40NzkyNiAxMi41NTA3IDUuNDk0MDggMTIuNDQ3OSA1LjUyMTg2WiIgZmlsbD0iIzFEMUMyMyIvPgo8L3N2Zz4="), auto'
1235
1252
  },
1236
- fromNodeJSON(node, json) {
1237
- initFormDataFromJSON(node, json);
1253
+ fromNodeJSON(node, json, isFirstCreate) {
1254
+ initFormDataFromJSON(node, json, isFirstCreate);
1238
1255
  return;
1239
1256
  },
1240
1257
  toNodeJSON(node) {
1241
- const nodeError = node.getData(import_form_core2.FlowNodeErrorData)?.getError();
1258
+ var _a, _b;
1259
+ const nodeError = (_a = node.getData(import_form_core2.FlowNodeErrorData)) == null ? void 0 : _a.getError();
1242
1260
  if (nodeError) {
1243
1261
  throw nodeError;
1244
1262
  }
@@ -1246,8 +1264,8 @@ var WorkflowDocumentOptionsDefault = {
1246
1264
  let formJSON = toFormJSON(node);
1247
1265
  const metaData = {};
1248
1266
  const nodeMeta = node.getNodeMeta();
1249
- const subCanvas = nodeMeta.subCanvas?.(node);
1250
- if (subCanvas?.isCanvas === false) {
1267
+ const subCanvas = (_b = nodeMeta.subCanvas) == null ? void 0 : _b.call(nodeMeta, node);
1268
+ if ((subCanvas == null ? void 0 : subCanvas.isCanvas) === false) {
1251
1269
  const canvasNodeTransform = subCanvas.canvasNode.getData(import_document4.FlowNodeTransformData);
1252
1270
  const { x, y } = canvasNodeTransform.transform.position;
1253
1271
  metaData.canvasPosition = { x, y };
@@ -1350,6 +1368,7 @@ var WorkflowLinesManager = class {
1350
1368
  return this.createLine(newPortInfo);
1351
1369
  }
1352
1370
  createLine(options) {
1371
+ var _a;
1353
1372
  const { from, to, drawingTo, fromPort, toPort } = options;
1354
1373
  const available = Boolean(from && to);
1355
1374
  const key = options.key || WorkflowLineEntity.portInfoToLineId(options);
@@ -1359,7 +1378,7 @@ var WorkflowLinesManager = class {
1359
1378
  line.validate();
1360
1379
  return line;
1361
1380
  }
1362
- const fromNode = this.entityManager.getEntityById(from)?.getData(WorkflowNodeLinesData);
1381
+ const fromNode = (_a = this.entityManager.getEntityById(from)) == null ? void 0 : _a.getData(WorkflowNodeLinesData);
1363
1382
  const toNode = to ? this.entityManager.getEntityById(to).getData(WorkflowNodeLinesData) : void 0;
1364
1383
  if (!fromNode) {
1365
1384
  return;
@@ -1377,26 +1396,24 @@ var WorkflowLinesManager = class {
1377
1396
  });
1378
1397
  this.registerData(line);
1379
1398
  fromNode.addLine(line);
1380
- toNode?.addLine(line);
1399
+ toNode == null ? void 0 : toNode.addLine(line);
1381
1400
  line.onDispose(() => {
1382
1401
  if (drawingTo) {
1383
1402
  this.isDrawing = false;
1384
1403
  }
1385
1404
  fromNode.removeLine(line);
1386
- toNode?.removeLine(line);
1405
+ toNode == null ? void 0 : toNode.removeLine(line);
1387
1406
  line.validate();
1388
1407
  });
1389
- line.toDispose.push(
1390
- import_utils12.Disposable.create(() => {
1391
- if (available) {
1392
- this.onAvailableLinesChangeEmitter.fire({
1393
- type: "DELETE_LINE" /* DELETE_LINE */,
1394
- toJSON: () => line.toJSON(),
1395
- entity: line
1396
- });
1397
- }
1398
- })
1399
- );
1408
+ line.onDispose(() => {
1409
+ if (available) {
1410
+ this.onAvailableLinesChangeEmitter.fire({
1411
+ type: "DELETE_LINE" /* DELETE_LINE */,
1412
+ toJSON: () => line.toJSON(),
1413
+ entity: line
1414
+ });
1415
+ }
1416
+ });
1400
1417
  if (available) {
1401
1418
  this.onAvailableLinesChangeEmitter.fire({
1402
1419
  type: "ADD_LINE" /* ADD_LINE */,
@@ -1534,7 +1551,10 @@ var WorkflowLinesManager = class {
1534
1551
  const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
1535
1552
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1536
1553
  if (targetPort) {
1537
- const targetNode = this.document.getAllNodes().slice().reverse().filter((node) => targetPort.node?.parent?.id !== node.id).find((node) => node.getData(import_core12.TransformData).contains(pos.x, pos.y));
1554
+ const targetNode = this.document.getAllNodes().slice().reverse().filter((node) => {
1555
+ var _a, _b;
1556
+ return ((_b = (_a = targetPort.node) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) !== node.id;
1557
+ }).find((node) => node.getData(import_core12.TransformData).contains(pos.x, pos.y));
1538
1558
  if (targetNode && targetNode !== targetPort.node) {
1539
1559
  return;
1540
1560
  }
@@ -1546,21 +1566,22 @@ var WorkflowLinesManager = class {
1546
1566
  * @param pos - 鼠标位置
1547
1567
  */
1548
1568
  getNodeFromMousePos(pos) {
1569
+ var _a, _b;
1549
1570
  const allNodes = this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1550
1571
  const containNodes = [];
1551
1572
  const { selection } = this.selectService;
1552
- const zoom = this.entityManager.getEntity(import_core12.PlaygroundConfigEntity)?.config?.zoom || 1;
1573
+ const zoom = ((_b = (_a = this.entityManager.getEntity(import_core12.PlaygroundConfigEntity)) == null ? void 0 : _a.config) == null ? void 0 : _b.zoom) || 1;
1553
1574
  allNodes.forEach((node) => {
1554
1575
  const { bounds } = node.getData(import_document5.FlowNodeTransformData);
1555
1576
  if (bounds.clone().pad(4 / zoom).contains(pos.x, pos.y)) {
1556
1577
  containNodes.push(node);
1557
1578
  }
1558
1579
  });
1559
- if (selection?.length) {
1580
+ if (selection == null ? void 0 : selection.length) {
1560
1581
  const filteredNodes = containNodes.filter(
1561
1582
  (node) => selection.some((_node) => node.id === _node.id)
1562
1583
  );
1563
- if (filteredNodes?.length) {
1584
+ if (filteredNodes == null ? void 0 : filteredNodes.length) {
1564
1585
  return (0, import_lodash_es3.last)(filteredNodes);
1565
1586
  }
1566
1587
  }
@@ -1604,9 +1625,9 @@ var import_core14 = require("@flowgram.ai/core");
1604
1625
 
1605
1626
  // src/layout/free-layout.ts
1606
1627
  var import_inversify4 = require("inversify");
1628
+ var import_utils13 = require("@flowgram.ai/utils");
1607
1629
  var import_document6 = require("@flowgram.ai/document");
1608
1630
  var import_core13 = require("@flowgram.ai/core");
1609
- var import_utils13 = require("@flowgram.ai/utils");
1610
1631
  var FREE_LAYOUT_KEY = "free-layout";
1611
1632
  var FreeLayout = class {
1612
1633
  constructor() {
@@ -1619,7 +1640,8 @@ var FreeLayout = class {
1619
1640
  * 更新布局
1620
1641
  */
1621
1642
  update() {
1622
- if (this.document.root.getData(import_document6.FlowNodeTransformData)?.localDirty) {
1643
+ var _a;
1644
+ if ((_a = this.document.root.getData(import_document6.FlowNodeTransformData)) == null ? void 0 : _a.localDirty) {
1623
1645
  this.document.root.clearMemoGlobal();
1624
1646
  }
1625
1647
  }
@@ -1641,6 +1663,21 @@ var FreeLayout = class {
1641
1663
  const parentTransform = node.parent.getData(import_document6.FlowNodeTransformData);
1642
1664
  parentTransform.transform.fireChange();
1643
1665
  }
1666
+ /**
1667
+ * 更新所有受影响的上下游节点
1668
+ */
1669
+ updateAffectedTransform(node) {
1670
+ const transformData = node.transform;
1671
+ if (!transformData.localDirty) {
1672
+ return;
1673
+ }
1674
+ const allParents = this.getAllParents(node);
1675
+ const allBlocks = this.getAllBlocks(node).reverse();
1676
+ const affectedNodes = [...allBlocks, ...allParents];
1677
+ affectedNodes.forEach((node2) => {
1678
+ this.fireChange(node2);
1679
+ });
1680
+ }
1644
1681
  /**
1645
1682
  * 获取节点的 padding 数据
1646
1683
  * @param node
@@ -1686,6 +1723,30 @@ var FreeLayout = class {
1686
1723
  getDefaultNodeOrigin() {
1687
1724
  return { x: 0.5, y: 0 };
1688
1725
  }
1726
+ getAllParents(node) {
1727
+ const parents = [];
1728
+ let current = node.parent;
1729
+ while (current) {
1730
+ parents.push(current);
1731
+ current = current.parent;
1732
+ }
1733
+ return parents;
1734
+ }
1735
+ getAllBlocks(node) {
1736
+ return node.blocks.reduce(
1737
+ (acc, child) => [...acc, ...this.getAllBlocks(child)],
1738
+ [node]
1739
+ );
1740
+ }
1741
+ fireChange(node) {
1742
+ const transformData = node == null ? void 0 : node.transform;
1743
+ if (!node || !(transformData == null ? void 0 : transformData.localDirty)) {
1744
+ return;
1745
+ }
1746
+ node.clearMemoGlobal();
1747
+ node.clearMemoLocal();
1748
+ transformData.transform.fireChange();
1749
+ }
1689
1750
  };
1690
1751
  __decorateClass([
1691
1752
  (0, import_inversify4.inject)(import_core13.PlaygroundConfigEntity)
@@ -1708,7 +1769,6 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1708
1769
  this.onContentChange = this._onContentChangeEmitter.event;
1709
1770
  this._onReloadEmitter = new import_utils14.Emitter();
1710
1771
  this.onReload = this._onReloadEmitter.event;
1711
- this.disposed = false;
1712
1772
  /**
1713
1773
  * 数据加载完成
1714
1774
  */
@@ -1737,12 +1797,14 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1737
1797
  });
1738
1798
  }
1739
1799
  async load() {
1800
+ if (this.disposed) return;
1740
1801
  this._loading = true;
1741
1802
  await super.load();
1742
1803
  this._loading = false;
1743
1804
  this.onLoadedEmitter.fire();
1744
1805
  }
1745
1806
  async reload(json, delayTime = 0) {
1807
+ if (this.disposed) return;
1746
1808
  this._loading = true;
1747
1809
  this.clear();
1748
1810
  this.fromJSON(json);
@@ -1755,9 +1817,11 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1755
1817
  * @param json
1756
1818
  */
1757
1819
  fromJSON(json, fireRender = true) {
1820
+ var _a, _b;
1821
+ if (this.disposed) return;
1758
1822
  const workflowJSON = {
1759
- nodes: json.nodes ?? [],
1760
- edges: json.edges ?? []
1823
+ nodes: (_a = json.nodes) != null ? _a : [],
1824
+ edges: (_b = json.edges) != null ? _b : []
1761
1825
  };
1762
1826
  this.entityManager.changeEntityLocked = true;
1763
1827
  this.renderJSON(workflowJSON);
@@ -1781,14 +1845,16 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1781
1845
  * @param json
1782
1846
  */
1783
1847
  createWorkflowNode(json, isClone = false, parentId) {
1848
+ var _a, _b, _c;
1784
1849
  const isExistedNode = this.getNode(json.id);
1785
- const parent = this.getNode(parentId ?? this.root.id) ?? this.root;
1850
+ const parent = (_a = this.getNode(parentId != null ? parentId : this.root.id)) != null ? _a : this.root;
1786
1851
  const node = this.addNode(
1787
1852
  {
1788
1853
  ...json,
1789
1854
  parent
1790
1855
  },
1791
1856
  void 0,
1857
+ true,
1792
1858
  true
1793
1859
  );
1794
1860
  const registry = node.getNodeRegistry();
@@ -1797,9 +1863,11 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1797
1863
  const formData = getFlowNodeFormData(node);
1798
1864
  const transform = node.getData(import_document7.FlowNodeTransformData);
1799
1865
  const freeLayout = this.layout;
1800
- transform.onDataChange(() => {
1801
- freeLayout.syncTransform(node);
1802
- });
1866
+ if (!isExistedNode) {
1867
+ transform.onDataChange(() => {
1868
+ freeLayout.syncTransform(node);
1869
+ });
1870
+ }
1803
1871
  let { position } = meta;
1804
1872
  if (!position) {
1805
1873
  position = this.getNodeDefaultPosition(json.type);
@@ -1818,44 +1886,44 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1818
1886
  });
1819
1887
  }
1820
1888
  const positionData = node.getData(import_core14.PositionData);
1821
- positionData.onDataChange(() => {
1822
- this.fireContentChange({
1823
- type: "MOVE_NODE" /* MOVE_NODE */,
1824
- toJSON: () => positionData.toJSON(),
1825
- entity: node
1889
+ if (!isExistedNode) {
1890
+ positionData.onDataChange(() => {
1891
+ this.fireContentChange({
1892
+ type: "MOVE_NODE" /* MOVE_NODE */,
1893
+ toJSON: () => positionData.toJSON(),
1894
+ entity: node
1895
+ });
1826
1896
  });
1827
- });
1897
+ }
1828
1898
  const subCanvas = this.getNodeSubCanvas(node);
1829
- if (!isExistedNode && !subCanvas?.isCanvas) {
1899
+ if (!isExistedNode && !(subCanvas == null ? void 0 : subCanvas.isCanvas)) {
1830
1900
  this.fireContentChange({
1831
1901
  type: "ADD_NODE" /* ADD_NODE */,
1832
1902
  entity: node,
1833
1903
  toJSON: () => this.toNodeJSON(node)
1834
1904
  });
1835
- node.toDispose.push(
1836
- import_utils14.Disposable.create(() => {
1837
- this.fireContentChange({
1838
- type: "DELETE_NODE" /* DELETE_NODE */,
1839
- entity: node,
1840
- toJSON: () => this.toNodeJSON(node)
1841
- });
1842
- })
1843
- );
1844
- node.toDispose.push(
1845
- import_utils14.Disposable.create(() => {
1846
- if (!node.parent || node.parent.flowNodeType === import_document7.FlowNodeBaseType.ROOT) {
1847
- return;
1848
- }
1849
- const parentTransform = node.parent.getData(import_document7.FlowNodeTransformData);
1850
- setTimeout(() => {
1851
- parentTransform.fireChange();
1852
- }, 0);
1853
- })
1854
- );
1905
+ node.onDispose(() => {
1906
+ if (!node.parent || node.parent.flowNodeType === import_document7.FlowNodeBaseType.ROOT) {
1907
+ return;
1908
+ }
1909
+ const parentTransform = node.parent.getData(import_document7.FlowNodeTransformData);
1910
+ parentTransform.fireChange();
1911
+ });
1912
+ let lastDeleteNodeData;
1913
+ node.preDispose.onDispose(() => {
1914
+ lastDeleteNodeData = this.toNodeJSON(node);
1915
+ });
1916
+ node.onDispose(() => {
1917
+ this.fireContentChange({
1918
+ type: "DELETE_NODE" /* DELETE_NODE */,
1919
+ entity: node,
1920
+ toJSON: () => lastDeleteNodeData
1921
+ });
1922
+ });
1855
1923
  }
1856
1924
  if (json.blocks) {
1857
1925
  this.renderJSON(
1858
- { nodes: json.blocks, edges: json.edges ?? [] },
1926
+ { nodes: json.blocks, edges: (_b = json.edges) != null ? _b : [] },
1859
1927
  {
1860
1928
  parent: node,
1861
1929
  isClone
@@ -1865,21 +1933,39 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1865
1933
  if (subCanvas) {
1866
1934
  const canvasTransform = subCanvas.canvasNode.getData(import_core14.TransformData);
1867
1935
  canvasTransform.update({
1868
- position: subCanvas.parentNode.getNodeMeta()?.canvasPosition
1936
+ position: (_c = subCanvas.parentNode.getNodeMeta()) == null ? void 0 : _c.canvasPosition
1869
1937
  });
1870
- subCanvas.parentNode.onDispose(() => {
1871
- subCanvas.canvasNode.dispose();
1938
+ if (!isExistedNode) {
1939
+ subCanvas.parentNode.onDispose(() => {
1940
+ subCanvas.canvasNode.dispose();
1941
+ });
1942
+ subCanvas.canvasNode.onDispose(() => {
1943
+ subCanvas.parentNode.dispose();
1944
+ });
1945
+ }
1946
+ }
1947
+ if (!isExistedNode) {
1948
+ this.onNodeCreateEmitter.fire({
1949
+ node,
1950
+ data: json,
1951
+ json
1872
1952
  });
1873
- subCanvas.canvasNode.onDispose(() => {
1874
- subCanvas.parentNode.dispose();
1953
+ } else {
1954
+ this.onNodeUpdateEmitter.fire({
1955
+ node,
1956
+ data: json,
1957
+ json
1875
1958
  });
1876
1959
  }
1877
- this.onNodeCreateEmitter.fire({
1878
- node,
1879
- data: json
1880
- });
1881
1960
  return node;
1882
1961
  }
1962
+ get layout() {
1963
+ const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
1964
+ if (!layout) {
1965
+ throw new Error(`Unknown flow layout: ${this.currentLayoutKey}`);
1966
+ }
1967
+ return layout;
1968
+ }
1883
1969
  /**
1884
1970
  * 获取默认的 x y 坐标, 默认为当前画布可视区域中心
1885
1971
  * @param type
@@ -1916,11 +2002,11 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1916
2002
  ...json,
1917
2003
  id,
1918
2004
  type,
1919
- meta: { position, ...json?.meta },
2005
+ meta: { position, ...json == null ? void 0 : json.meta },
1920
2006
  // TODO title 和 meta 要从注册数据去拿
1921
- data: json?.data,
1922
- blocks: json?.blocks,
1923
- edges: json?.edges
2007
+ data: json == null ? void 0 : json.data,
2008
+ blocks: json == null ? void 0 : json.blocks,
2009
+ edges: json == null ? void 0 : json.edges
1924
2010
  },
1925
2011
  false,
1926
2012
  parentID
@@ -1947,7 +2033,10 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1947
2033
  }));
1948
2034
  const startNodeId = allNode.find((node) => node.isStart).id;
1949
2035
  const endNodeId = allNode.find((node) => node.isNodeEnd).id;
1950
- const nodeInContainer = allNode.filter((node) => node.parent?.getNodeMeta().isContainer).map((node) => node.id);
2036
+ const nodeInContainer = allNode.filter((node) => {
2037
+ var _a;
2038
+ return (_a = node.parent) == null ? void 0 : _a.getNodeMeta().isContainer;
2039
+ }).map((node) => node.id);
1951
2040
  const associatedCache = /* @__PURE__ */ new Set([endNodeId, ...nodeInContainer]);
1952
2041
  const bfs = (nodeId) => {
1953
2042
  if (associatedCache.has(nodeId)) {
@@ -1982,7 +2071,7 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1982
2071
  }
1983
2072
  toNodeJSON(node) {
1984
2073
  const subCanvas = this.getNodeSubCanvas(node);
1985
- if (subCanvas?.isCanvas === true) {
2074
+ if ((subCanvas == null ? void 0 : subCanvas.isCanvas) === true) {
1986
2075
  return this.toNodeJSON(subCanvas.parentNode);
1987
2076
  }
1988
2077
  const json = this.toNodeJSONFromOptions(node);
@@ -2016,6 +2105,7 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2016
2105
  return WorkflowDocumentOptionsDefault.toNodeJSON(node);
2017
2106
  }
2018
2107
  copyNode(node, newNodeId, format, position) {
2108
+ var _a;
2019
2109
  let json = this.toNodeJSON(node);
2020
2110
  if (format) {
2021
2111
  json = format(json);
@@ -2037,7 +2127,7 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2037
2127
  edges: json.edges
2038
2128
  },
2039
2129
  true,
2040
- node.parent?.id
2130
+ (_a = node.parent) == null ? void 0 : _a.id
2041
2131
  );
2042
2132
  }
2043
2133
  copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position, parentId) {
@@ -2084,26 +2174,24 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2084
2174
  * 导出数据
2085
2175
  */
2086
2176
  toJSON() {
2177
+ var _a, _b;
2087
2178
  const rootJSON = this.toNodeJSON(this.root);
2088
2179
  return {
2089
- nodes: rootJSON.blocks ?? [],
2090
- edges: rootJSON.edges ?? []
2180
+ nodes: (_a = rootJSON.blocks) != null ? _a : [],
2181
+ edges: (_b = rootJSON.edges) != null ? _b : []
2091
2182
  };
2092
2183
  }
2093
2184
  dispose() {
2094
- if (this.disposed) {
2095
- return;
2096
- }
2097
2185
  super.dispose();
2098
- this.disposed = true;
2099
2186
  this._onReloadEmitter.dispose();
2100
2187
  }
2101
2188
  /**
2102
2189
  * 逐层创建节点和线条
2103
2190
  */
2104
2191
  renderJSON(json, options) {
2105
- const { parent = this.root, isClone = false } = options ?? {};
2106
- const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2192
+ var _a, _b;
2193
+ const { parent = this.root, isClone = false } = options != null ? options : {};
2194
+ const containerID = (_b = (_a = this.getNodeSubCanvas(parent)) == null ? void 0 : _a.canvasNode.id) != null ? _b : parent.id;
2107
2195
  const nodes = json.nodes.map(
2108
2196
  (nodeJSON) => this.createWorkflowNode(nodeJSON, isClone, containerID)
2109
2197
  );
@@ -2111,9 +2199,10 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2111
2199
  return { nodes, edges };
2112
2200
  }
2113
2201
  getNodeSubCanvas(node) {
2202
+ var _a;
2114
2203
  if (!node) return;
2115
2204
  const nodeMeta = node.getNodeMeta();
2116
- const subCanvas = nodeMeta.subCanvas?.(node);
2205
+ const subCanvas = (_a = nodeMeta.subCanvas) == null ? void 0 : _a.call(nodeMeta, node);
2117
2206
  return subCanvas;
2118
2207
  }
2119
2208
  getNodeChildren(node) {
@@ -2121,8 +2210,9 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2121
2210
  const subCanvas = this.getNodeSubCanvas(node);
2122
2211
  const childrenWithCanvas = subCanvas ? subCanvas.canvasNode.collapsedChildren : node.collapsedChildren;
2123
2212
  const children = childrenWithCanvas.filter((child) => {
2213
+ var _a, _b;
2124
2214
  const childMeta = child.getNodeMeta();
2125
- return !childMeta.subCanvas?.(node)?.isCanvas;
2215
+ return !((_b = (_a = childMeta.subCanvas) == null ? void 0 : _a.call(childMeta, node)) == null ? void 0 : _b.isCanvas);
2126
2216
  }).filter(Boolean);
2127
2217
  return children;
2128
2218
  }
@@ -2249,6 +2339,7 @@ var WorkflowDragService = class {
2249
2339
  * @param triggerEvent
2250
2340
  */
2251
2341
  async startDragSelectedNodes(triggerEvent) {
2342
+ var _a;
2252
2343
  let { selectedNodes } = this.selectService;
2253
2344
  if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
2254
2345
  return Promise.resolve(false);
@@ -2293,15 +2384,10 @@ var WorkflowDragService = class {
2293
2384
  x: nodeStartPosition.x + offset.x,
2294
2385
  y: nodeStartPosition.y + offset.y
2295
2386
  };
2296
- if (node.collapsedChildren?.length > 0) {
2297
- node.collapsedChildren.forEach((childNode) => {
2298
- const childNodeTransformData = childNode.getData(import_document8.FlowNodeTransformData);
2299
- childNodeTransformData.fireChange();
2300
- });
2301
- }
2302
2387
  transform.update({
2303
2388
  position: newPosition
2304
2389
  });
2390
+ this.document.layout.updateAffectedTransform(node);
2305
2391
  positions.push(newPosition);
2306
2392
  });
2307
2393
  this._nodesDragEmitter.fire({
@@ -2326,7 +2412,7 @@ var WorkflowDragService = class {
2326
2412
  });
2327
2413
  }
2328
2414
  });
2329
- return dragger.start(triggerEvent.clientX, triggerEvent.clientY, this.playgroundConfig)?.then(() => dragSuccess);
2415
+ return (_a = dragger.start(triggerEvent.clientX, triggerEvent.clientY, this.playgroundConfig)) == null ? void 0 : _a.then(() => dragSuccess);
2330
2416
  }
2331
2417
  /**
2332
2418
  * 通过拖入卡片添加
@@ -2344,7 +2430,7 @@ var WorkflowDragService = class {
2344
2430
  type,
2345
2431
  position,
2346
2432
  data,
2347
- parent?.id
2433
+ parent == null ? void 0 : parent.id
2348
2434
  );
2349
2435
  return node;
2350
2436
  }
@@ -2394,7 +2480,7 @@ var WorkflowDragService = class {
2394
2480
  );
2395
2481
  return import_utils16.Rectangle.intersects(draggingRect, transformRect);
2396
2482
  });
2397
- this.updateDropNode(collisionTransform?.entity);
2483
+ this.updateDropNode(collisionTransform == null ? void 0 : collisionTransform.entity);
2398
2484
  },
2399
2485
  onDragEnd: async (e) => {
2400
2486
  const dropNode = this._dropNode;
@@ -2511,7 +2597,8 @@ var WorkflowDragService = class {
2511
2597
  }
2512
2598
  /** 是否容器节点 */
2513
2599
  isContainer(node) {
2514
- return node?.getNodeMeta().isContainer ?? false;
2600
+ var _a;
2601
+ return (_a = node == null ? void 0 : node.getNodeMeta().isContainer) != null ? _a : false;
2515
2602
  }
2516
2603
  /**
2517
2604
  * 获取节点整体位置
@@ -2536,7 +2623,7 @@ var WorkflowDragService = class {
2536
2623
  }
2537
2624
  updateDropNode(node) {
2538
2625
  if (this._dropNode) {
2539
- if (this._dropNode.id === node?.id) {
2626
+ if (this._dropNode.id === (node == null ? void 0 : node.id)) {
2540
2627
  return;
2541
2628
  }
2542
2629
  this.selectService.clear();
@@ -2558,7 +2645,7 @@ var WorkflowDragService = class {
2558
2645
  this.hoverService.clearHovered();
2559
2646
  }
2560
2647
  handleDragOnNode(toNode, fromPort, line, toPort, originLine) {
2561
- if (toPort && (originLine?.toPort === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
2648
+ if (toPort && ((originLine == null ? void 0 : originLine.toPort) === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
2562
2649
  this.hoverService.updateHoveredKey(toPort.id);
2563
2650
  line.setToPort(toPort);
2564
2651
  this._onDragLineEventEmitter.fire({
@@ -2580,14 +2667,15 @@ var WorkflowDragService = class {
2580
2667
  }
2581
2668
  }
2582
2669
  childrenOfContainer(nodes) {
2670
+ var _a;
2583
2671
  if (nodes.length === 0) {
2584
2672
  return;
2585
2673
  }
2586
- const sourceContainer = nodes[0]?.parent;
2674
+ const sourceContainer = (_a = nodes[0]) == null ? void 0 : _a.parent;
2587
2675
  if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
2588
2676
  return;
2589
2677
  }
2590
- const valid = nodes.every((node) => node?.parent === sourceContainer);
2678
+ const valid = nodes.every((node) => (node == null ? void 0 : node.parent) === sourceContainer);
2591
2679
  if (!valid) {
2592
2680
  return;
2593
2681
  }
@@ -2600,7 +2688,7 @@ var WorkflowDragService = class {
2600
2688
  */
2601
2689
  async startDrawingLine(fromPort, event, originLine) {
2602
2690
  const isFromInActivePort = !originLine && fromPort.isErrorPort() && fromPort.disabled;
2603
- if (originLine?.disabled || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
2691
+ if ((originLine == null ? void 0 : originLine.disabled) || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
2604
2692
  return { dragSuccess: false, newLine: void 0 };
2605
2693
  }
2606
2694
  this.selectService.clear();
@@ -2663,7 +2751,7 @@ var WorkflowDragService = class {
2663
2751
  } else {
2664
2752
  line.drawingTo = { x: dragPos.x, y: dragPos.y };
2665
2753
  }
2666
- originLine?.validate();
2754
+ originLine == null ? void 0 : originLine.validate();
2667
2755
  line.validate();
2668
2756
  },
2669
2757
  // eslint-disable-next-line complexity
@@ -2683,7 +2771,7 @@ var WorkflowDragService = class {
2683
2771
  })
2684
2772
  )
2685
2773
  );
2686
- line?.dispose();
2774
+ line == null ? void 0 : line.dispose();
2687
2775
  this._onDragLineEventEmitter.fire({
2688
2776
  type: "onDragEnd"
2689
2777
  });
@@ -2691,7 +2779,7 @@ var WorkflowDragService = class {
2691
2779
  originLine.highlightColor = "";
2692
2780
  }
2693
2781
  const end = () => {
2694
- originLine?.validate();
2782
+ originLine == null ? void 0 : originLine.validate();
2695
2783
  deferred.resolve({ dragSuccess });
2696
2784
  };
2697
2785
  if (dragSuccess) {
@@ -2718,7 +2806,7 @@ var WorkflowDragService = class {
2718
2806
  if (originLine && (!this.linesManager.canRemove(originLine, newLineInfo, false) || lineErrorReset)) {
2719
2807
  return end();
2720
2808
  } else {
2721
- originLine?.dispose();
2809
+ originLine == null ? void 0 : originLine.dispose();
2722
2810
  }
2723
2811
  if (!toPort || !this.linesManager.canAddLine(fromPort, toPort, false)) {
2724
2812
  return end();
@@ -2822,18 +2910,14 @@ var layoutToPositions = async (nodes, nodePositionMap) => {
2822
2910
  const transform = node.getData(import_core16.TransformData);
2823
2911
  const deltaX = (nodePositionMap[node.id].x - transform.position.x) * v.d / 100;
2824
2912
  const deltaY = (nodePositionMap[node.id].y - transform.bounds.height / 2 - transform.position.y) * v.d / 100;
2825
- if (node.collapsedChildren?.length > 0) {
2826
- node.collapsedChildren.forEach((childNode) => {
2827
- const childNodeTransformData = childNode.getData(import_document10.FlowNodeTransformData);
2828
- childNodeTransformData.fireChange();
2829
- });
2830
- }
2831
2913
  transform.update({
2832
2914
  position: {
2833
2915
  x: transform.position.x + deltaX,
2834
2916
  y: transform.position.y + deltaY
2835
2917
  }
2836
2918
  });
2919
+ const document2 = node.document;
2920
+ document2.layout.updateAffectedTransform(node);
2837
2921
  });
2838
2922
  },
2839
2923
  onComplete: () => {
@@ -2949,7 +3033,7 @@ function usePlaygroundReadonlyState(listenChange) {
2949
3033
  if (listenChange) {
2950
3034
  dispose = playground.config.onReadonlyOrDisabledChange(() => refresh());
2951
3035
  }
2952
- return () => dispose?.dispose();
3036
+ return () => dispose == null ? void 0 : dispose.dispose();
2953
3037
  }, [listenChange]);
2954
3038
  return playground.config.readonly;
2955
3039
  }
@@ -2959,6 +3043,7 @@ function checkTargetDraggable(el) {
2959
3043
  return el && el.tagName !== "INPUT" && el.tagName !== "TEXTAREA" && !el.closest(".flow-canvas-not-draggable");
2960
3044
  }
2961
3045
  function useNodeRender(nodeFromProps) {
3046
+ var _a, _b;
2962
3047
  const node = nodeFromProps || (0, import_react2.useContext)(import_core21.PlaygroundEntityContext);
2963
3048
  const renderData = node.getData(import_document12.FlowNodeRenderData);
2964
3049
  const portsData = node.getData(WorkflowNodePortsData);
@@ -2982,6 +3067,7 @@ function useNodeRender(nodeFromProps) {
2982
3067
  }, []);
2983
3068
  const startDrag = (0, import_react2.useCallback)(
2984
3069
  (e) => {
3070
+ var _a2;
2985
3071
  e.preventDefault();
2986
3072
  if (!selectionService.isSelected(node.id)) {
2987
3073
  selectNode(e);
@@ -2990,7 +3076,7 @@ function useNodeRender(nodeFromProps) {
2990
3076
  return;
2991
3077
  }
2992
3078
  isDragging.current = true;
2993
- dragService.startDragSelectedNodes(e)?.finally(
3079
+ (_a2 = dragService.startDragSelectedNodes(e)) == null ? void 0 : _a2.finally(
2994
3080
  () => setTimeout(() => {
2995
3081
  isDragging.current = false;
2996
3082
  })
@@ -3016,15 +3102,17 @@ function useNodeRender(nodeFromProps) {
3016
3102
  );
3017
3103
  const deleteNode = (0, import_react2.useCallback)(() => node.dispose(), [node]);
3018
3104
  (0, import_core21.useListenEvents)(portsData.onDataChange);
3019
- const isFirefox = navigator?.userAgent?.includes?.("Firefox");
3105
+ const isFirefox = (_b = (_a = navigator == null ? void 0 : navigator.userAgent) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, "Firefox");
3020
3106
  const onFocus = (0, import_react2.useCallback)(() => {
3107
+ var _a2;
3021
3108
  if (isFirefox) {
3022
- nodeRef.current?.setAttribute("draggable", "false");
3109
+ (_a2 = nodeRef.current) == null ? void 0 : _a2.setAttribute("draggable", "false");
3023
3110
  }
3024
3111
  }, []);
3025
3112
  const onBlur = (0, import_react2.useCallback)(() => {
3113
+ var _a2;
3026
3114
  if (isFirefox) {
3027
- nodeRef.current?.setAttribute("draggable", "true");
3115
+ (_a2 = nodeRef.current) == null ? void 0 : _a2.setAttribute("draggable", "true");
3028
3116
  }
3029
3117
  }, []);
3030
3118
  const getExtInfo = (0, import_react2.useCallback)(() => node.getExtInfo(), [node]);
@@ -3035,7 +3123,7 @@ function useNodeRender(nodeFromProps) {
3035
3123
  [node]
3036
3124
  );
3037
3125
  const form = (0, import_react2.useMemo)(() => (0, import_node.getNodeForm)(node), [node]);
3038
- const formState = (0, import_reactive.useObserve)(form?.state);
3126
+ const formState = (0, import_reactive.useObserve)(form == null ? void 0 : form.state);
3039
3127
  const toggleExpand = (0, import_react2.useCallback)(() => {
3040
3128
  renderData.toggleExpand();
3041
3129
  }, [renderData]);
@@ -3168,7 +3256,8 @@ var WorkflowSimpleLineContribution = class {
3168
3256
  this.entity = entity;
3169
3257
  }
3170
3258
  get path() {
3171
- return this.data?.path ?? "";
3259
+ var _a, _b;
3260
+ return (_b = (_a = this.data) == null ? void 0 : _a.path) != null ? _b : "";
3172
3261
  }
3173
3262
  calcDistance(pos) {
3174
3263
  if (!this.data) {