@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/esm/index.js CHANGED
@@ -145,6 +145,7 @@ var PORT_SIZE = 24;
145
145
  var WorkflowPortEntity = class extends Entity {
146
146
  // relativePosition
147
147
  constructor(opts) {
148
+ var _a;
148
149
  super(opts);
149
150
  this.portID = "";
150
151
  this._disabled = false;
@@ -153,7 +154,7 @@ var WorkflowPortEntity = class extends Entity {
153
154
  this.onErrorChanged = this._onErrorChangedEmitter.event;
154
155
  this.portID = opts.portID || "";
155
156
  this.portType = opts.type;
156
- this._disabled = opts.disabled ?? false;
157
+ this._disabled = (_a = opts.disabled) != null ? _a : false;
157
158
  this.node = opts.node;
158
159
  this.updateTargetElement(opts.targetElement);
159
160
  this.toDispose.push(this.node.getData(TransformData3).onDataChange(() => this.fireChange()));
@@ -283,6 +284,7 @@ WorkflowPortEntity.type = "WorkflowPortEntity";
283
284
  // src/entity-datas/workflow-node-ports-data.ts
284
285
  var WorkflowNodePortsData = class extends EntityData {
285
286
  constructor(entity) {
287
+ var _a;
286
288
  super(entity);
287
289
  /** 静态的 ports 数据 */
288
290
  this._staticPorts = [];
@@ -291,7 +293,7 @@ var WorkflowNodePortsData = class extends EntityData {
291
293
  this.entity = entity;
292
294
  const meta = entity.getNodeMeta();
293
295
  const defaultPorts = meta.useDynamicPort ? [] : [{ type: "input" }, { type: "output" }];
294
- this._staticPorts = meta.defaultPorts?.slice() || defaultPorts;
296
+ this._staticPorts = ((_a = meta.defaultPorts) == null ? void 0 : _a.slice()) || defaultPorts;
295
297
  this.updatePorts(this._staticPorts);
296
298
  if (meta.useDynamicPort) {
297
299
  this.toDispose.push(
@@ -358,8 +360,9 @@ var WorkflowNodePortsData = class extends EntityData {
358
360
  if (!isEqual(this._prePorts, ports)) {
359
361
  const portKeys = ports.map((port) => this.getPortId(port.type, port.portID));
360
362
  this._portIDSet.forEach((portId) => {
363
+ var _a;
361
364
  if (!portKeys.includes(portId)) {
362
- this.getPortEntity(portId)?.dispose();
365
+ (_a = this.getPortEntity(portId)) == null ? void 0 : _a.dispose();
363
366
  }
364
367
  });
365
368
  ports.forEach((port) => this.updatePortEntity(port));
@@ -453,8 +456,9 @@ var WorkflowNodePortsData = class extends EntityData {
453
456
  * 获取或创建 port 实体
454
457
  */
455
458
  getOrCreatePortEntity(portInfo) {
459
+ var _a;
456
460
  const id = this.getPortId(portInfo.type, portInfo.portID);
457
- return this.getPortEntity(id) ?? this.createPortEntity(portInfo);
461
+ return (_a = this.getPortEntity(id)) != null ? _a : this.createPortEntity(portInfo);
458
462
  }
459
463
  /**
460
464
  * 更新 port 实体
@@ -522,7 +526,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
522
526
  return;
523
527
  }
524
528
  inputNodes.forEach((inputNode) => {
525
- if (inputNode?.parent === node || node?.parent === inputNode) {
529
+ if ((inputNode == null ? void 0 : inputNode.parent) === node || (node == null ? void 0 : node.parent) === inputNode) {
526
530
  return;
527
531
  }
528
532
  handleNode(inputNode);
@@ -553,7 +557,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
553
557
  return;
554
558
  }
555
559
  outputNodes.forEach((outputNode) => {
556
- if (outputNode?.parent === node || node?.parent === outputNode) {
560
+ if ((outputNode == null ? void 0 : outputNode.parent) === node || (node == null ? void 0 : node.parent) === outputNode) {
557
561
  return;
558
562
  }
559
563
  handleNode(outputNode);
@@ -613,19 +617,23 @@ var WorkflowLineRenderData = class extends EntityData3 {
613
617
  return this.data.position;
614
618
  }
615
619
  get path() {
616
- return this.currentLine?.path ?? "";
620
+ var _a, _b;
621
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.path) != null ? _b : "";
617
622
  }
618
623
  calcDistance(pos) {
619
- return this.currentLine?.calcDistance(pos) ?? Number.MAX_SAFE_INTEGER;
624
+ var _a, _b;
625
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.calcDistance(pos)) != null ? _b : Number.MAX_SAFE_INTEGER;
620
626
  }
621
627
  get bounds() {
622
- return this.currentLine?.bounds ?? new Rectangle4();
628
+ var _a, _b;
629
+ return (_b = (_a = this.currentLine) == null ? void 0 : _a.bounds) != null ? _b : new Rectangle4();
623
630
  }
624
631
  /**
625
632
  * 更新数据
626
633
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
627
634
  */
628
635
  update() {
636
+ var _a;
629
637
  this.syncContributions();
630
638
  const oldVersion = this.data.version;
631
639
  this.updatePosition();
@@ -634,21 +642,23 @@ var WorkflowLineRenderData = class extends EntityData3 {
634
642
  return;
635
643
  }
636
644
  this.data.version = newVersion;
637
- this.currentLine?.update({
645
+ (_a = this.currentLine) == null ? void 0 : _a.update({
638
646
  fromPos: this.data.position.from,
639
647
  toPos: this.data.position.to
640
648
  });
641
649
  }
642
650
  get lineType() {
643
- return this.entity.renderType ?? this.entity.linesManager.lineType;
651
+ var _a;
652
+ return (_a = this.entity.renderType) != null ? _a : this.entity.linesManager.lineType;
644
653
  }
645
654
  /**
646
655
  * 更新版本
647
656
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
648
657
  */
649
658
  updatePosition() {
659
+ var _a, _b, _c, _d;
650
660
  this.data.position.from = this.entity.from.getData(WorkflowNodePortsData).getOutputPoint(this.entity.info.fromPort);
651
- this.data.position.to = this.entity.info.drawingTo ?? this.entity.to?.getData(WorkflowNodePortsData)?.getInputPoint(this.entity.info.toPort) ?? {
661
+ 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 : {
652
662
  x: this.data.position.from.x,
653
663
  y: this.data.position.from.y
654
664
  };
@@ -732,7 +742,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
732
742
  return this.highlightColor === this.linesManager.lineColor.hidden;
733
743
  }
734
744
  get inContainer() {
735
- const nodeInContainer = (node) => !!node?.parent && node.parent.flowNodeType !== "root";
745
+ const nodeInContainer = (node) => !!(node == null ? void 0 : node.parent) && node.parent.flowNodeType !== "root";
736
746
  return nodeInContainer(this.from) || nodeInContainer(this.to);
737
747
  }
738
748
  /**
@@ -873,7 +883,8 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
873
883
  }
874
884
  /** 获取线条样式 */
875
885
  get className() {
876
- return this.linesManager.setLineClassName(this) ?? "";
886
+ var _a;
887
+ return (_a = this.linesManager.setLineClassName(this)) != null ? _a : "";
877
888
  }
878
889
  get color() {
879
890
  return this.linesManager.getLineColor(this);
@@ -894,8 +905,8 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
894
905
  validate() {
895
906
  const { fromPort, toPort } = this;
896
907
  this.validateSelf();
897
- fromPort?.validate();
898
- toPort?.validate();
908
+ fromPort == null ? void 0 : fromPort.validate();
909
+ toPort == null ? void 0 : toPort.validate();
899
910
  }
900
911
  validateSelf() {
901
912
  const { fromPort, toPort } = this;
@@ -913,14 +924,15 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
913
924
  return this.linesManager.canRemove(this, newLineInfo);
914
925
  }
915
926
  get node() {
927
+ var _a, _b, _c, _d, _e, _f;
916
928
  if (this._node) return this._node;
917
929
  this._node = domUtils.createDivWithClass("gedit-flow-activity-line");
918
930
  this._node.dataset.testid = "sdk.workflow.canvas.line";
919
931
  this._node.dataset.lineId = this.id;
920
932
  this._node.dataset.fromNodeId = this.from.id;
921
- this._node.dataset.fromPortId = this.fromPort?.id ?? "";
922
- this._node.dataset.toNodeId = this.to?.id ?? "";
923
- this._node.dataset.toPortId = this.toPort?.id ?? "";
933
+ this._node.dataset.fromPortId = (_b = (_a = this.fromPort) == null ? void 0 : _a.id) != null ? _b : "";
934
+ this._node.dataset.toNodeId = (_d = (_c = this.to) == null ? void 0 : _c.id) != null ? _d : "";
935
+ this._node.dataset.toPortId = (_f = (_e = this.toPort) == null ? void 0 : _e.id) != null ? _f : "";
924
936
  this._node.dataset.hasError = this.hasError ? "true" : "false";
925
937
  return this._node;
926
938
  }
@@ -972,7 +984,8 @@ var WorkflowSelectService = class {
972
984
  return this.selectionService.selection.some((s) => s.id === id);
973
985
  }
974
986
  isActivated(id) {
975
- return this.activatedNode?.id === id;
987
+ var _a;
988
+ return ((_a = this.activatedNode) == null ? void 0 : _a.id) === id;
976
989
  }
977
990
  /**
978
991
  * 选中的节点
@@ -1043,8 +1056,8 @@ WorkflowSelectService = __decorateClass([
1043
1056
 
1044
1057
  // src/service/workflow-hover-service.ts
1045
1058
  import { inject as inject2, injectable as injectable2 } from "inversify";
1046
- import { EntityManager } from "@flowgram.ai/core";
1047
1059
  import { Emitter as Emitter2 } from "@flowgram.ai/utils";
1060
+ import { EntityManager } from "@flowgram.ai/core";
1048
1061
  var WorkflowHoverService = class {
1049
1062
  constructor() {
1050
1063
  this.onHoveredChangeEmitter = new Emitter2();
@@ -1125,7 +1138,7 @@ import {
1125
1138
  // src/workflow-lines-manager.ts
1126
1139
  import { last } from "lodash-es";
1127
1140
  import { inject as inject3, injectable as injectable3 } from "inversify";
1128
- import { Disposable as Disposable2, DisposableCollection, Emitter as Emitter3 } from "@flowgram.ai/utils";
1141
+ import { DisposableCollection, Emitter as Emitter3 } from "@flowgram.ai/utils";
1129
1142
  import { FlowNodeRenderData as FlowNodeRenderData2, FlowNodeTransformData as FlowNodeTransformData3 } from "@flowgram.ai/document";
1130
1143
  import { EntityManager as EntityManager2, PlaygroundConfigEntity as PlaygroundConfigEntity2, TransformData as TransformData6 } from "@flowgram.ai/core";
1131
1144
 
@@ -1144,19 +1157,23 @@ function toFormJSON(node) {
1144
1157
  if (!formData || !node.getNodeRegistry().formMeta) return void 0;
1145
1158
  return formData.toJSON();
1146
1159
  }
1147
- function initFormDataFromJSON(node, json) {
1160
+ function initFormDataFromJSON(node, json, isFirstCreate) {
1148
1161
  const formData = node.getData(FlowNodeFormData);
1149
1162
  const registry = node.getNodeRegistry();
1150
1163
  const { formMeta } = registry;
1151
1164
  if (formData && formMeta) {
1152
- formData.createForm(formMeta, json.data);
1153
- formData.onDataChange(() => {
1154
- node.document.fireContentChange({
1155
- type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
1156
- toJSON: () => formData.toJSON(),
1157
- entity: node
1165
+ if (isFirstCreate) {
1166
+ formData.createForm(formMeta, json.data);
1167
+ formData.onDataChange(() => {
1168
+ node.document.fireContentChange({
1169
+ type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
1170
+ toJSON: () => formData.toJSON(),
1171
+ entity: node
1172
+ });
1158
1173
  });
1159
- });
1174
+ } else {
1175
+ formData.updateFormValues(json.data);
1176
+ }
1160
1177
  }
1161
1178
  }
1162
1179
 
@@ -1167,12 +1184,13 @@ var WorkflowDocumentOptionsDefault = {
1167
1184
  grab: 'url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMCAyMSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMC40ODczIDIuNjIzNzhDOS45MDczMSAyLjYyMzc4IDkuNDM3MTMgMy4wOTM5NiA5LjQzNzEzIDMuNjczOTZWNS4xNDM3NkM5LjM5NDI4IDQuNDAyNzQgOC43Nzk3OCAzLjgxNTA0IDguMDI4MDIgMy44MTUwNEM3LjI0ODQ4IDMuODE1MDQgNi42MTY1MyA0LjQ0Njk5IDYuNjE2NTMgNS4yMjY1M1YxMS44Mjg5TDUuNjc0MTggMTEuMDA0OUM1LjE1NDg3IDEwLjU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UyMTg2WiIgZmlsbD0iIzFEMUMyMyIvPgo8L3N2Zz4="), auto'
1169
1186
  },
1170
- fromNodeJSON(node, json) {
1171
- initFormDataFromJSON(node, json);
1187
+ fromNodeJSON(node, json, isFirstCreate) {
1188
+ initFormDataFromJSON(node, json, isFirstCreate);
1172
1189
  return;
1173
1190
  },
1174
1191
  toNodeJSON(node) {
1175
- const nodeError = node.getData(FlowNodeErrorData)?.getError();
1192
+ var _a, _b;
1193
+ const nodeError = (_a = node.getData(FlowNodeErrorData)) == null ? void 0 : _a.getError();
1176
1194
  if (nodeError) {
1177
1195
  throw nodeError;
1178
1196
  }
@@ -1180,8 +1198,8 @@ var WorkflowDocumentOptionsDefault = {
1180
1198
  let formJSON = toFormJSON(node);
1181
1199
  const metaData = {};
1182
1200
  const nodeMeta = node.getNodeMeta();
1183
- const subCanvas = nodeMeta.subCanvas?.(node);
1184
- if (subCanvas?.isCanvas === false) {
1201
+ const subCanvas = (_b = nodeMeta.subCanvas) == null ? void 0 : _b.call(nodeMeta, node);
1202
+ if ((subCanvas == null ? void 0 : subCanvas.isCanvas) === false) {
1185
1203
  const canvasNodeTransform = subCanvas.canvasNode.getData(FlowNodeTransformData2);
1186
1204
  const { x, y } = canvasNodeTransform.transform.position;
1187
1205
  metaData.canvasPosition = { x, y };
@@ -1284,6 +1302,7 @@ var WorkflowLinesManager = class {
1284
1302
  return this.createLine(newPortInfo);
1285
1303
  }
1286
1304
  createLine(options) {
1305
+ var _a;
1287
1306
  const { from, to, drawingTo, fromPort, toPort } = options;
1288
1307
  const available = Boolean(from && to);
1289
1308
  const key = options.key || WorkflowLineEntity.portInfoToLineId(options);
@@ -1293,7 +1312,7 @@ var WorkflowLinesManager = class {
1293
1312
  line.validate();
1294
1313
  return line;
1295
1314
  }
1296
- const fromNode = this.entityManager.getEntityById(from)?.getData(WorkflowNodeLinesData);
1315
+ const fromNode = (_a = this.entityManager.getEntityById(from)) == null ? void 0 : _a.getData(WorkflowNodeLinesData);
1297
1316
  const toNode = to ? this.entityManager.getEntityById(to).getData(WorkflowNodeLinesData) : void 0;
1298
1317
  if (!fromNode) {
1299
1318
  return;
@@ -1311,26 +1330,24 @@ var WorkflowLinesManager = class {
1311
1330
  });
1312
1331
  this.registerData(line);
1313
1332
  fromNode.addLine(line);
1314
- toNode?.addLine(line);
1333
+ toNode == null ? void 0 : toNode.addLine(line);
1315
1334
  line.onDispose(() => {
1316
1335
  if (drawingTo) {
1317
1336
  this.isDrawing = false;
1318
1337
  }
1319
1338
  fromNode.removeLine(line);
1320
- toNode?.removeLine(line);
1339
+ toNode == null ? void 0 : toNode.removeLine(line);
1321
1340
  line.validate();
1322
1341
  });
1323
- line.toDispose.push(
1324
- Disposable2.create(() => {
1325
- if (available) {
1326
- this.onAvailableLinesChangeEmitter.fire({
1327
- type: "DELETE_LINE" /* DELETE_LINE */,
1328
- toJSON: () => line.toJSON(),
1329
- entity: line
1330
- });
1331
- }
1332
- })
1333
- );
1342
+ line.onDispose(() => {
1343
+ if (available) {
1344
+ this.onAvailableLinesChangeEmitter.fire({
1345
+ type: "DELETE_LINE" /* DELETE_LINE */,
1346
+ toJSON: () => line.toJSON(),
1347
+ entity: line
1348
+ });
1349
+ }
1350
+ });
1334
1351
  if (available) {
1335
1352
  this.onAvailableLinesChangeEmitter.fire({
1336
1353
  type: "ADD_LINE" /* ADD_LINE */,
@@ -1468,7 +1485,10 @@ var WorkflowLinesManager = class {
1468
1485
  const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
1469
1486
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1470
1487
  if (targetPort) {
1471
- const targetNode = this.document.getAllNodes().slice().reverse().filter((node) => targetPort.node?.parent?.id !== node.id).find((node) => node.getData(TransformData6).contains(pos.x, pos.y));
1488
+ const targetNode = this.document.getAllNodes().slice().reverse().filter((node) => {
1489
+ var _a, _b;
1490
+ return ((_b = (_a = targetPort.node) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) !== node.id;
1491
+ }).find((node) => node.getData(TransformData6).contains(pos.x, pos.y));
1472
1492
  if (targetNode && targetNode !== targetPort.node) {
1473
1493
  return;
1474
1494
  }
@@ -1480,21 +1500,22 @@ var WorkflowLinesManager = class {
1480
1500
  * @param pos - 鼠标位置
1481
1501
  */
1482
1502
  getNodeFromMousePos(pos) {
1503
+ var _a, _b;
1483
1504
  const allNodes = this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1484
1505
  const containNodes = [];
1485
1506
  const { selection } = this.selectService;
1486
- const zoom = this.entityManager.getEntity(PlaygroundConfigEntity2)?.config?.zoom || 1;
1507
+ const zoom = ((_b = (_a = this.entityManager.getEntity(PlaygroundConfigEntity2)) == null ? void 0 : _a.config) == null ? void 0 : _b.zoom) || 1;
1487
1508
  allNodes.forEach((node) => {
1488
1509
  const { bounds } = node.getData(FlowNodeTransformData3);
1489
1510
  if (bounds.clone().pad(4 / zoom).contains(pos.x, pos.y)) {
1490
1511
  containNodes.push(node);
1491
1512
  }
1492
1513
  });
1493
- if (selection?.length) {
1514
+ if (selection == null ? void 0 : selection.length) {
1494
1515
  const filteredNodes = containNodes.filter(
1495
1516
  (node) => selection.some((_node) => node.id === _node.id)
1496
1517
  );
1497
- if (filteredNodes?.length) {
1518
+ if (filteredNodes == null ? void 0 : filteredNodes.length) {
1498
1519
  return last(filteredNodes);
1499
1520
  }
1500
1521
  }
@@ -1531,7 +1552,7 @@ WorkflowLinesManager = __decorateClass([
1531
1552
  // src/workflow-document.ts
1532
1553
  import { customAlphabet } from "nanoid";
1533
1554
  import { inject as inject5, injectable as injectable5, optional, postConstruct } from "inversify";
1534
- import { Disposable as Disposable3, Emitter as Emitter4 } from "@flowgram.ai/utils";
1555
+ import { Emitter as Emitter4 } from "@flowgram.ai/utils";
1535
1556
  import { NodeEngineContext } from "@flowgram.ai/form-core";
1536
1557
  import { FlowDocument, FlowNodeBaseType, FlowNodeTransformData as FlowNodeTransformData5 } from "@flowgram.ai/document";
1537
1558
  import {
@@ -1543,16 +1564,16 @@ import {
1543
1564
 
1544
1565
  // src/layout/free-layout.ts
1545
1566
  import { inject as inject4, injectable as injectable4 } from "inversify";
1546
- import {
1547
- FlowDocumentProvider,
1548
- FlowNodeTransformData as FlowNodeTransformData4
1549
- } from "@flowgram.ai/document";
1550
- import { PlaygroundConfigEntity as PlaygroundConfigEntity3, TransformData as TransformData7 } from "@flowgram.ai/core";
1551
1567
  import {
1552
1568
  PaddingSchema,
1553
1569
  Rectangle as Rectangle7,
1554
1570
  SizeSchema as SizeSchema2
1555
1571
  } from "@flowgram.ai/utils";
1572
+ import {
1573
+ FlowDocumentProvider,
1574
+ FlowNodeTransformData as FlowNodeTransformData4
1575
+ } from "@flowgram.ai/document";
1576
+ import { PlaygroundConfigEntity as PlaygroundConfigEntity3, TransformData as TransformData7 } from "@flowgram.ai/core";
1556
1577
  var FREE_LAYOUT_KEY = "free-layout";
1557
1578
  var FreeLayout = class {
1558
1579
  constructor() {
@@ -1565,7 +1586,8 @@ var FreeLayout = class {
1565
1586
  * 更新布局
1566
1587
  */
1567
1588
  update() {
1568
- if (this.document.root.getData(FlowNodeTransformData4)?.localDirty) {
1589
+ var _a;
1590
+ if ((_a = this.document.root.getData(FlowNodeTransformData4)) == null ? void 0 : _a.localDirty) {
1569
1591
  this.document.root.clearMemoGlobal();
1570
1592
  }
1571
1593
  }
@@ -1587,6 +1609,21 @@ var FreeLayout = class {
1587
1609
  const parentTransform = node.parent.getData(FlowNodeTransformData4);
1588
1610
  parentTransform.transform.fireChange();
1589
1611
  }
1612
+ /**
1613
+ * 更新所有受影响的上下游节点
1614
+ */
1615
+ updateAffectedTransform(node) {
1616
+ const transformData = node.transform;
1617
+ if (!transformData.localDirty) {
1618
+ return;
1619
+ }
1620
+ const allParents = this.getAllParents(node);
1621
+ const allBlocks = this.getAllBlocks(node).reverse();
1622
+ const affectedNodes = [...allBlocks, ...allParents];
1623
+ affectedNodes.forEach((node2) => {
1624
+ this.fireChange(node2);
1625
+ });
1626
+ }
1590
1627
  /**
1591
1628
  * 获取节点的 padding 数据
1592
1629
  * @param node
@@ -1632,6 +1669,30 @@ var FreeLayout = class {
1632
1669
  getDefaultNodeOrigin() {
1633
1670
  return { x: 0.5, y: 0 };
1634
1671
  }
1672
+ getAllParents(node) {
1673
+ const parents = [];
1674
+ let current = node.parent;
1675
+ while (current) {
1676
+ parents.push(current);
1677
+ current = current.parent;
1678
+ }
1679
+ return parents;
1680
+ }
1681
+ getAllBlocks(node) {
1682
+ return node.blocks.reduce(
1683
+ (acc, child) => [...acc, ...this.getAllBlocks(child)],
1684
+ [node]
1685
+ );
1686
+ }
1687
+ fireChange(node) {
1688
+ const transformData = node == null ? void 0 : node.transform;
1689
+ if (!node || !(transformData == null ? void 0 : transformData.localDirty)) {
1690
+ return;
1691
+ }
1692
+ node.clearMemoGlobal();
1693
+ node.clearMemoLocal();
1694
+ transformData.transform.fireChange();
1695
+ }
1635
1696
  };
1636
1697
  __decorateClass([
1637
1698
  inject4(PlaygroundConfigEntity3)
@@ -1654,7 +1715,6 @@ var WorkflowDocument = class extends FlowDocument {
1654
1715
  this.onContentChange = this._onContentChangeEmitter.event;
1655
1716
  this._onReloadEmitter = new Emitter4();
1656
1717
  this.onReload = this._onReloadEmitter.event;
1657
- this.disposed = false;
1658
1718
  /**
1659
1719
  * 数据加载完成
1660
1720
  */
@@ -1683,12 +1743,14 @@ var WorkflowDocument = class extends FlowDocument {
1683
1743
  });
1684
1744
  }
1685
1745
  async load() {
1746
+ if (this.disposed) return;
1686
1747
  this._loading = true;
1687
1748
  await super.load();
1688
1749
  this._loading = false;
1689
1750
  this.onLoadedEmitter.fire();
1690
1751
  }
1691
1752
  async reload(json, delayTime = 0) {
1753
+ if (this.disposed) return;
1692
1754
  this._loading = true;
1693
1755
  this.clear();
1694
1756
  this.fromJSON(json);
@@ -1701,9 +1763,11 @@ var WorkflowDocument = class extends FlowDocument {
1701
1763
  * @param json
1702
1764
  */
1703
1765
  fromJSON(json, fireRender = true) {
1766
+ var _a, _b;
1767
+ if (this.disposed) return;
1704
1768
  const workflowJSON = {
1705
- nodes: json.nodes ?? [],
1706
- edges: json.edges ?? []
1769
+ nodes: (_a = json.nodes) != null ? _a : [],
1770
+ edges: (_b = json.edges) != null ? _b : []
1707
1771
  };
1708
1772
  this.entityManager.changeEntityLocked = true;
1709
1773
  this.renderJSON(workflowJSON);
@@ -1727,14 +1791,16 @@ var WorkflowDocument = class extends FlowDocument {
1727
1791
  * @param json
1728
1792
  */
1729
1793
  createWorkflowNode(json, isClone = false, parentId) {
1794
+ var _a, _b, _c;
1730
1795
  const isExistedNode = this.getNode(json.id);
1731
- const parent = this.getNode(parentId ?? this.root.id) ?? this.root;
1796
+ const parent = (_a = this.getNode(parentId != null ? parentId : this.root.id)) != null ? _a : this.root;
1732
1797
  const node = this.addNode(
1733
1798
  {
1734
1799
  ...json,
1735
1800
  parent
1736
1801
  },
1737
1802
  void 0,
1803
+ true,
1738
1804
  true
1739
1805
  );
1740
1806
  const registry = node.getNodeRegistry();
@@ -1743,9 +1809,11 @@ var WorkflowDocument = class extends FlowDocument {
1743
1809
  const formData = getFlowNodeFormData(node);
1744
1810
  const transform = node.getData(FlowNodeTransformData5);
1745
1811
  const freeLayout = this.layout;
1746
- transform.onDataChange(() => {
1747
- freeLayout.syncTransform(node);
1748
- });
1812
+ if (!isExistedNode) {
1813
+ transform.onDataChange(() => {
1814
+ freeLayout.syncTransform(node);
1815
+ });
1816
+ }
1749
1817
  let { position } = meta;
1750
1818
  if (!position) {
1751
1819
  position = this.getNodeDefaultPosition(json.type);
@@ -1764,44 +1832,44 @@ var WorkflowDocument = class extends FlowDocument {
1764
1832
  });
1765
1833
  }
1766
1834
  const positionData = node.getData(PositionData);
1767
- positionData.onDataChange(() => {
1768
- this.fireContentChange({
1769
- type: "MOVE_NODE" /* MOVE_NODE */,
1770
- toJSON: () => positionData.toJSON(),
1771
- entity: node
1835
+ if (!isExistedNode) {
1836
+ positionData.onDataChange(() => {
1837
+ this.fireContentChange({
1838
+ type: "MOVE_NODE" /* MOVE_NODE */,
1839
+ toJSON: () => positionData.toJSON(),
1840
+ entity: node
1841
+ });
1772
1842
  });
1773
- });
1843
+ }
1774
1844
  const subCanvas = this.getNodeSubCanvas(node);
1775
- if (!isExistedNode && !subCanvas?.isCanvas) {
1845
+ if (!isExistedNode && !(subCanvas == null ? void 0 : subCanvas.isCanvas)) {
1776
1846
  this.fireContentChange({
1777
1847
  type: "ADD_NODE" /* ADD_NODE */,
1778
1848
  entity: node,
1779
1849
  toJSON: () => this.toNodeJSON(node)
1780
1850
  });
1781
- node.toDispose.push(
1782
- Disposable3.create(() => {
1783
- this.fireContentChange({
1784
- type: "DELETE_NODE" /* DELETE_NODE */,
1785
- entity: node,
1786
- toJSON: () => this.toNodeJSON(node)
1787
- });
1788
- })
1789
- );
1790
- node.toDispose.push(
1791
- Disposable3.create(() => {
1792
- if (!node.parent || node.parent.flowNodeType === FlowNodeBaseType.ROOT) {
1793
- return;
1794
- }
1795
- const parentTransform = node.parent.getData(FlowNodeTransformData5);
1796
- setTimeout(() => {
1797
- parentTransform.fireChange();
1798
- }, 0);
1799
- })
1800
- );
1851
+ node.onDispose(() => {
1852
+ if (!node.parent || node.parent.flowNodeType === FlowNodeBaseType.ROOT) {
1853
+ return;
1854
+ }
1855
+ const parentTransform = node.parent.getData(FlowNodeTransformData5);
1856
+ parentTransform.fireChange();
1857
+ });
1858
+ let lastDeleteNodeData;
1859
+ node.preDispose.onDispose(() => {
1860
+ lastDeleteNodeData = this.toNodeJSON(node);
1861
+ });
1862
+ node.onDispose(() => {
1863
+ this.fireContentChange({
1864
+ type: "DELETE_NODE" /* DELETE_NODE */,
1865
+ entity: node,
1866
+ toJSON: () => lastDeleteNodeData
1867
+ });
1868
+ });
1801
1869
  }
1802
1870
  if (json.blocks) {
1803
1871
  this.renderJSON(
1804
- { nodes: json.blocks, edges: json.edges ?? [] },
1872
+ { nodes: json.blocks, edges: (_b = json.edges) != null ? _b : [] },
1805
1873
  {
1806
1874
  parent: node,
1807
1875
  isClone
@@ -1811,21 +1879,39 @@ var WorkflowDocument = class extends FlowDocument {
1811
1879
  if (subCanvas) {
1812
1880
  const canvasTransform = subCanvas.canvasNode.getData(TransformData8);
1813
1881
  canvasTransform.update({
1814
- position: subCanvas.parentNode.getNodeMeta()?.canvasPosition
1882
+ position: (_c = subCanvas.parentNode.getNodeMeta()) == null ? void 0 : _c.canvasPosition
1815
1883
  });
1816
- subCanvas.parentNode.onDispose(() => {
1817
- subCanvas.canvasNode.dispose();
1884
+ if (!isExistedNode) {
1885
+ subCanvas.parentNode.onDispose(() => {
1886
+ subCanvas.canvasNode.dispose();
1887
+ });
1888
+ subCanvas.canvasNode.onDispose(() => {
1889
+ subCanvas.parentNode.dispose();
1890
+ });
1891
+ }
1892
+ }
1893
+ if (!isExistedNode) {
1894
+ this.onNodeCreateEmitter.fire({
1895
+ node,
1896
+ data: json,
1897
+ json
1818
1898
  });
1819
- subCanvas.canvasNode.onDispose(() => {
1820
- subCanvas.parentNode.dispose();
1899
+ } else {
1900
+ this.onNodeUpdateEmitter.fire({
1901
+ node,
1902
+ data: json,
1903
+ json
1821
1904
  });
1822
1905
  }
1823
- this.onNodeCreateEmitter.fire({
1824
- node,
1825
- data: json
1826
- });
1827
1906
  return node;
1828
1907
  }
1908
+ get layout() {
1909
+ const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
1910
+ if (!layout) {
1911
+ throw new Error(`Unknown flow layout: ${this.currentLayoutKey}`);
1912
+ }
1913
+ return layout;
1914
+ }
1829
1915
  /**
1830
1916
  * 获取默认的 x y 坐标, 默认为当前画布可视区域中心
1831
1917
  * @param type
@@ -1862,11 +1948,11 @@ var WorkflowDocument = class extends FlowDocument {
1862
1948
  ...json,
1863
1949
  id,
1864
1950
  type,
1865
- meta: { position, ...json?.meta },
1951
+ meta: { position, ...json == null ? void 0 : json.meta },
1866
1952
  // TODO title 和 meta 要从注册数据去拿
1867
- data: json?.data,
1868
- blocks: json?.blocks,
1869
- edges: json?.edges
1953
+ data: json == null ? void 0 : json.data,
1954
+ blocks: json == null ? void 0 : json.blocks,
1955
+ edges: json == null ? void 0 : json.edges
1870
1956
  },
1871
1957
  false,
1872
1958
  parentID
@@ -1893,7 +1979,10 @@ var WorkflowDocument = class extends FlowDocument {
1893
1979
  }));
1894
1980
  const startNodeId = allNode.find((node) => node.isStart).id;
1895
1981
  const endNodeId = allNode.find((node) => node.isNodeEnd).id;
1896
- const nodeInContainer = allNode.filter((node) => node.parent?.getNodeMeta().isContainer).map((node) => node.id);
1982
+ const nodeInContainer = allNode.filter((node) => {
1983
+ var _a;
1984
+ return (_a = node.parent) == null ? void 0 : _a.getNodeMeta().isContainer;
1985
+ }).map((node) => node.id);
1897
1986
  const associatedCache = /* @__PURE__ */ new Set([endNodeId, ...nodeInContainer]);
1898
1987
  const bfs = (nodeId) => {
1899
1988
  if (associatedCache.has(nodeId)) {
@@ -1928,7 +2017,7 @@ var WorkflowDocument = class extends FlowDocument {
1928
2017
  }
1929
2018
  toNodeJSON(node) {
1930
2019
  const subCanvas = this.getNodeSubCanvas(node);
1931
- if (subCanvas?.isCanvas === true) {
2020
+ if ((subCanvas == null ? void 0 : subCanvas.isCanvas) === true) {
1932
2021
  return this.toNodeJSON(subCanvas.parentNode);
1933
2022
  }
1934
2023
  const json = this.toNodeJSONFromOptions(node);
@@ -1962,6 +2051,7 @@ var WorkflowDocument = class extends FlowDocument {
1962
2051
  return WorkflowDocumentOptionsDefault.toNodeJSON(node);
1963
2052
  }
1964
2053
  copyNode(node, newNodeId, format, position) {
2054
+ var _a;
1965
2055
  let json = this.toNodeJSON(node);
1966
2056
  if (format) {
1967
2057
  json = format(json);
@@ -1983,7 +2073,7 @@ var WorkflowDocument = class extends FlowDocument {
1983
2073
  edges: json.edges
1984
2074
  },
1985
2075
  true,
1986
- node.parent?.id
2076
+ (_a = node.parent) == null ? void 0 : _a.id
1987
2077
  );
1988
2078
  }
1989
2079
  copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position, parentId) {
@@ -2030,26 +2120,24 @@ var WorkflowDocument = class extends FlowDocument {
2030
2120
  * 导出数据
2031
2121
  */
2032
2122
  toJSON() {
2123
+ var _a, _b;
2033
2124
  const rootJSON = this.toNodeJSON(this.root);
2034
2125
  return {
2035
- nodes: rootJSON.blocks ?? [],
2036
- edges: rootJSON.edges ?? []
2126
+ nodes: (_a = rootJSON.blocks) != null ? _a : [],
2127
+ edges: (_b = rootJSON.edges) != null ? _b : []
2037
2128
  };
2038
2129
  }
2039
2130
  dispose() {
2040
- if (this.disposed) {
2041
- return;
2042
- }
2043
2131
  super.dispose();
2044
- this.disposed = true;
2045
2132
  this._onReloadEmitter.dispose();
2046
2133
  }
2047
2134
  /**
2048
2135
  * 逐层创建节点和线条
2049
2136
  */
2050
2137
  renderJSON(json, options) {
2051
- const { parent = this.root, isClone = false } = options ?? {};
2052
- const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2138
+ var _a, _b;
2139
+ const { parent = this.root, isClone = false } = options != null ? options : {};
2140
+ const containerID = (_b = (_a = this.getNodeSubCanvas(parent)) == null ? void 0 : _a.canvasNode.id) != null ? _b : parent.id;
2053
2141
  const nodes = json.nodes.map(
2054
2142
  (nodeJSON) => this.createWorkflowNode(nodeJSON, isClone, containerID)
2055
2143
  );
@@ -2057,9 +2145,10 @@ var WorkflowDocument = class extends FlowDocument {
2057
2145
  return { nodes, edges };
2058
2146
  }
2059
2147
  getNodeSubCanvas(node) {
2148
+ var _a;
2060
2149
  if (!node) return;
2061
2150
  const nodeMeta = node.getNodeMeta();
2062
- const subCanvas = nodeMeta.subCanvas?.(node);
2151
+ const subCanvas = (_a = nodeMeta.subCanvas) == null ? void 0 : _a.call(nodeMeta, node);
2063
2152
  return subCanvas;
2064
2153
  }
2065
2154
  getNodeChildren(node) {
@@ -2067,8 +2156,9 @@ var WorkflowDocument = class extends FlowDocument {
2067
2156
  const subCanvas = this.getNodeSubCanvas(node);
2068
2157
  const childrenWithCanvas = subCanvas ? subCanvas.canvasNode.collapsedChildren : node.collapsedChildren;
2069
2158
  const children = childrenWithCanvas.filter((child) => {
2159
+ var _a, _b;
2070
2160
  const childMeta = child.getNodeMeta();
2071
- return !childMeta.subCanvas?.(node)?.isCanvas;
2161
+ return !((_b = (_a = childMeta.subCanvas) == null ? void 0 : _a.call(childMeta, node)) == null ? void 0 : _b.isCanvas);
2072
2162
  }).filter(Boolean);
2073
2163
  return children;
2074
2164
  }
@@ -2195,6 +2285,7 @@ var WorkflowDragService = class {
2195
2285
  * @param triggerEvent
2196
2286
  */
2197
2287
  async startDragSelectedNodes(triggerEvent) {
2288
+ var _a;
2198
2289
  let { selectedNodes } = this.selectService;
2199
2290
  if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
2200
2291
  return Promise.resolve(false);
@@ -2239,15 +2330,10 @@ var WorkflowDragService = class {
2239
2330
  x: nodeStartPosition.x + offset.x,
2240
2331
  y: nodeStartPosition.y + offset.y
2241
2332
  };
2242
- if (node.collapsedChildren?.length > 0) {
2243
- node.collapsedChildren.forEach((childNode) => {
2244
- const childNodeTransformData = childNode.getData(FlowNodeTransformData6);
2245
- childNodeTransformData.fireChange();
2246
- });
2247
- }
2248
2333
  transform.update({
2249
2334
  position: newPosition
2250
2335
  });
2336
+ this.document.layout.updateAffectedTransform(node);
2251
2337
  positions.push(newPosition);
2252
2338
  });
2253
2339
  this._nodesDragEmitter.fire({
@@ -2272,7 +2358,7 @@ var WorkflowDragService = class {
2272
2358
  });
2273
2359
  }
2274
2360
  });
2275
- return dragger.start(triggerEvent.clientX, triggerEvent.clientY, this.playgroundConfig)?.then(() => dragSuccess);
2361
+ return (_a = dragger.start(triggerEvent.clientX, triggerEvent.clientY, this.playgroundConfig)) == null ? void 0 : _a.then(() => dragSuccess);
2276
2362
  }
2277
2363
  /**
2278
2364
  * 通过拖入卡片添加
@@ -2290,7 +2376,7 @@ var WorkflowDragService = class {
2290
2376
  type,
2291
2377
  position,
2292
2378
  data,
2293
- parent?.id
2379
+ parent == null ? void 0 : parent.id
2294
2380
  );
2295
2381
  return node;
2296
2382
  }
@@ -2340,7 +2426,7 @@ var WorkflowDragService = class {
2340
2426
  );
2341
2427
  return Rectangle8.intersects(draggingRect, transformRect);
2342
2428
  });
2343
- this.updateDropNode(collisionTransform?.entity);
2429
+ this.updateDropNode(collisionTransform == null ? void 0 : collisionTransform.entity);
2344
2430
  },
2345
2431
  onDragEnd: async (e) => {
2346
2432
  const dropNode = this._dropNode;
@@ -2457,7 +2543,8 @@ var WorkflowDragService = class {
2457
2543
  }
2458
2544
  /** 是否容器节点 */
2459
2545
  isContainer(node) {
2460
- return node?.getNodeMeta().isContainer ?? false;
2546
+ var _a;
2547
+ return (_a = node == null ? void 0 : node.getNodeMeta().isContainer) != null ? _a : false;
2461
2548
  }
2462
2549
  /**
2463
2550
  * 获取节点整体位置
@@ -2482,7 +2569,7 @@ var WorkflowDragService = class {
2482
2569
  }
2483
2570
  updateDropNode(node) {
2484
2571
  if (this._dropNode) {
2485
- if (this._dropNode.id === node?.id) {
2572
+ if (this._dropNode.id === (node == null ? void 0 : node.id)) {
2486
2573
  return;
2487
2574
  }
2488
2575
  this.selectService.clear();
@@ -2504,7 +2591,7 @@ var WorkflowDragService = class {
2504
2591
  this.hoverService.clearHovered();
2505
2592
  }
2506
2593
  handleDragOnNode(toNode, fromPort, line, toPort, originLine) {
2507
- if (toPort && (originLine?.toPort === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
2594
+ if (toPort && ((originLine == null ? void 0 : originLine.toPort) === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
2508
2595
  this.hoverService.updateHoveredKey(toPort.id);
2509
2596
  line.setToPort(toPort);
2510
2597
  this._onDragLineEventEmitter.fire({
@@ -2526,14 +2613,15 @@ var WorkflowDragService = class {
2526
2613
  }
2527
2614
  }
2528
2615
  childrenOfContainer(nodes) {
2616
+ var _a;
2529
2617
  if (nodes.length === 0) {
2530
2618
  return;
2531
2619
  }
2532
- const sourceContainer = nodes[0]?.parent;
2620
+ const sourceContainer = (_a = nodes[0]) == null ? void 0 : _a.parent;
2533
2621
  if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
2534
2622
  return;
2535
2623
  }
2536
- const valid = nodes.every((node) => node?.parent === sourceContainer);
2624
+ const valid = nodes.every((node) => (node == null ? void 0 : node.parent) === sourceContainer);
2537
2625
  if (!valid) {
2538
2626
  return;
2539
2627
  }
@@ -2546,7 +2634,7 @@ var WorkflowDragService = class {
2546
2634
  */
2547
2635
  async startDrawingLine(fromPort, event, originLine) {
2548
2636
  const isFromInActivePort = !originLine && fromPort.isErrorPort() && fromPort.disabled;
2549
- if (originLine?.disabled || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
2637
+ if ((originLine == null ? void 0 : originLine.disabled) || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
2550
2638
  return { dragSuccess: false, newLine: void 0 };
2551
2639
  }
2552
2640
  this.selectService.clear();
@@ -2609,7 +2697,7 @@ var WorkflowDragService = class {
2609
2697
  } else {
2610
2698
  line.drawingTo = { x: dragPos.x, y: dragPos.y };
2611
2699
  }
2612
- originLine?.validate();
2700
+ originLine == null ? void 0 : originLine.validate();
2613
2701
  line.validate();
2614
2702
  },
2615
2703
  // eslint-disable-next-line complexity
@@ -2629,7 +2717,7 @@ var WorkflowDragService = class {
2629
2717
  })
2630
2718
  )
2631
2719
  );
2632
- line?.dispose();
2720
+ line == null ? void 0 : line.dispose();
2633
2721
  this._onDragLineEventEmitter.fire({
2634
2722
  type: "onDragEnd"
2635
2723
  });
@@ -2637,7 +2725,7 @@ var WorkflowDragService = class {
2637
2725
  originLine.highlightColor = "";
2638
2726
  }
2639
2727
  const end = () => {
2640
- originLine?.validate();
2728
+ originLine == null ? void 0 : originLine.validate();
2641
2729
  deferred.resolve({ dragSuccess });
2642
2730
  };
2643
2731
  if (dragSuccess) {
@@ -2664,7 +2752,7 @@ var WorkflowDragService = class {
2664
2752
  if (originLine && (!this.linesManager.canRemove(originLine, newLineInfo, false) || lineErrorReset)) {
2665
2753
  return end();
2666
2754
  } else {
2667
- originLine?.dispose();
2755
+ originLine == null ? void 0 : originLine.dispose();
2668
2756
  }
2669
2757
  if (!toPort || !this.linesManager.canAddLine(fromPort, toPort, false)) {
2670
2758
  return end();
@@ -2768,18 +2856,14 @@ var layoutToPositions = async (nodes, nodePositionMap) => {
2768
2856
  const transform = node.getData(TransformData10);
2769
2857
  const deltaX = (nodePositionMap[node.id].x - transform.position.x) * v.d / 100;
2770
2858
  const deltaY = (nodePositionMap[node.id].y - transform.bounds.height / 2 - transform.position.y) * v.d / 100;
2771
- if (node.collapsedChildren?.length > 0) {
2772
- node.collapsedChildren.forEach((childNode) => {
2773
- const childNodeTransformData = childNode.getData(FlowNodeTransformData7);
2774
- childNodeTransformData.fireChange();
2775
- });
2776
- }
2777
2859
  transform.update({
2778
2860
  position: {
2779
2861
  x: transform.position.x + deltaX,
2780
2862
  y: transform.position.y + deltaY
2781
2863
  }
2782
2864
  });
2865
+ const document2 = node.document;
2866
+ document2.layout.updateAffectedTransform(node);
2783
2867
  });
2784
2868
  },
2785
2869
  onComplete: () => {
@@ -2895,7 +2979,7 @@ function usePlaygroundReadonlyState(listenChange) {
2895
2979
  if (listenChange) {
2896
2980
  dispose = playground.config.onReadonlyOrDisabledChange(() => refresh());
2897
2981
  }
2898
- return () => dispose?.dispose();
2982
+ return () => dispose == null ? void 0 : dispose.dispose();
2899
2983
  }, [listenChange]);
2900
2984
  return playground.config.readonly;
2901
2985
  }
@@ -2905,6 +2989,7 @@ function checkTargetDraggable(el) {
2905
2989
  return el && el.tagName !== "INPUT" && el.tagName !== "TEXTAREA" && !el.closest(".flow-canvas-not-draggable");
2906
2990
  }
2907
2991
  function useNodeRender(nodeFromProps) {
2992
+ var _a, _b;
2908
2993
  const node = nodeFromProps || useContext(PlaygroundEntityContext);
2909
2994
  const renderData = node.getData(FlowNodeRenderData3);
2910
2995
  const portsData = node.getData(WorkflowNodePortsData);
@@ -2928,6 +3013,7 @@ function useNodeRender(nodeFromProps) {
2928
3013
  }, []);
2929
3014
  const startDrag = useCallback(
2930
3015
  (e) => {
3016
+ var _a2;
2931
3017
  e.preventDefault();
2932
3018
  if (!selectionService.isSelected(node.id)) {
2933
3019
  selectNode(e);
@@ -2936,7 +3022,7 @@ function useNodeRender(nodeFromProps) {
2936
3022
  return;
2937
3023
  }
2938
3024
  isDragging.current = true;
2939
- dragService.startDragSelectedNodes(e)?.finally(
3025
+ (_a2 = dragService.startDragSelectedNodes(e)) == null ? void 0 : _a2.finally(
2940
3026
  () => setTimeout(() => {
2941
3027
  isDragging.current = false;
2942
3028
  })
@@ -2962,15 +3048,17 @@ function useNodeRender(nodeFromProps) {
2962
3048
  );
2963
3049
  const deleteNode = useCallback(() => node.dispose(), [node]);
2964
3050
  useListenEvents(portsData.onDataChange);
2965
- const isFirefox = navigator?.userAgent?.includes?.("Firefox");
3051
+ const isFirefox = (_b = (_a = navigator == null ? void 0 : navigator.userAgent) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, "Firefox");
2966
3052
  const onFocus = useCallback(() => {
3053
+ var _a2;
2967
3054
  if (isFirefox) {
2968
- nodeRef.current?.setAttribute("draggable", "false");
3055
+ (_a2 = nodeRef.current) == null ? void 0 : _a2.setAttribute("draggable", "false");
2969
3056
  }
2970
3057
  }, []);
2971
3058
  const onBlur = useCallback(() => {
3059
+ var _a2;
2972
3060
  if (isFirefox) {
2973
- nodeRef.current?.setAttribute("draggable", "true");
3061
+ (_a2 = nodeRef.current) == null ? void 0 : _a2.setAttribute("draggable", "true");
2974
3062
  }
2975
3063
  }, []);
2976
3064
  const getExtInfo = useCallback(() => node.getExtInfo(), [node]);
@@ -2981,7 +3069,7 @@ function useNodeRender(nodeFromProps) {
2981
3069
  [node]
2982
3070
  );
2983
3071
  const form = useMemo(() => getNodeForm(node), [node]);
2984
- const formState = useObserve(form?.state);
3072
+ const formState = useObserve(form == null ? void 0 : form.state);
2985
3073
  const toggleExpand = useCallback(() => {
2986
3074
  renderData.toggleExpand();
2987
3075
  }, [renderData]);
@@ -3117,7 +3205,8 @@ var WorkflowSimpleLineContribution = class {
3117
3205
  this.entity = entity;
3118
3206
  }
3119
3207
  get path() {
3120
- return this.data?.path ?? "";
3208
+ var _a, _b;
3209
+ return (_b = (_a = this.data) == null ? void 0 : _a.path) != null ? _b : "";
3121
3210
  }
3122
3211
  calcDistance(pos) {
3123
3212
  if (!this.data) {