@flowgram.ai/free-layout-core 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -183,6 +183,27 @@ import {
183
183
  PlaygroundConfigEntity,
184
184
  TransformData as TransformData3
185
185
  } from "@flowgram.ai/core";
186
+
187
+ // src/utils/location-config-to-point.ts
188
+ function locationConfigToPoint(bounds, config, _offset = { x: 0, y: 0 }) {
189
+ const offset = { ..._offset };
190
+ if (config.left !== void 0) {
191
+ offset.x += typeof config.left === "string" ? parseFloat(config.left) * 0.01 * bounds.width : config.left;
192
+ } else if (config.right !== void 0) {
193
+ offset.x += bounds.width - (typeof config.right === "string" ? parseFloat(config.right) * 0.01 * bounds.width : config.right);
194
+ }
195
+ if (config.top !== void 0) {
196
+ offset.y += typeof config.top === "string" ? parseFloat(config.top) * 0.01 * bounds.height : config.top;
197
+ } else if (config.bottom !== void 0) {
198
+ offset.y += bounds.height - (typeof config.bottom === "string" ? parseFloat(config.bottom) * 0.01 * bounds.height : config.bottom);
199
+ }
200
+ return {
201
+ x: bounds.x + offset.x,
202
+ y: bounds.y + offset.y
203
+ };
204
+ }
205
+
206
+ // src/entities/workflow-port-entity.ts
186
207
  var PORT_SIZE = 24;
187
208
  var WorkflowPortEntity = class extends Entity {
188
209
  constructor(opts) {
@@ -195,6 +216,7 @@ var WorkflowPortEntity = class extends Entity {
195
216
  this.portType = opts.type;
196
217
  this._disabled = opts.disabled;
197
218
  this._offset = opts.offset;
219
+ this._locationConfig = opts.locationConfig;
198
220
  this._location = opts.location;
199
221
  this._size = opts.size;
200
222
  this.node = opts.node;
@@ -242,7 +264,7 @@ var WorkflowPortEntity = class extends Entity {
242
264
  return "right";
243
265
  }
244
266
  get point() {
245
- const { targetElement } = this;
267
+ const { targetElement, _locationConfig } = this;
246
268
  const { bounds } = this.node.getData(FlowNodeTransformData);
247
269
  const location2 = this.location;
248
270
  if (targetElement) {
@@ -257,8 +279,14 @@ var WorkflowPortEntity = class extends Entity {
257
279
  location: location2
258
280
  };
259
281
  }
260
- let point = { x: 0, y: 0 };
282
+ if (_locationConfig) {
283
+ return {
284
+ ...locationConfigToPoint(bounds, _locationConfig, this._offset),
285
+ location: location2
286
+ };
287
+ }
261
288
  const offset = this._offset || { x: 0, y: 0 };
289
+ let point = { x: 0, y: 0 };
262
290
  switch (location2) {
263
291
  case "left":
264
292
  point = bounds.leftCenter;
@@ -371,6 +399,10 @@ var WorkflowPortEntity = class extends Entity {
371
399
  this._offset = data.offset;
372
400
  changed = true;
373
401
  }
402
+ if (Compare.isChanged(data.locationConfig, this._locationConfig)) {
403
+ this._locationConfig = data.locationConfig;
404
+ changed = true;
405
+ }
374
406
  if (Compare.isChanged(data.size, this._size)) {
375
407
  this._size = data.size;
376
408
  changed = true;
@@ -2536,12 +2568,14 @@ var WorkflowDocument = class extends FlowDocument {
2536
2568
  * 批量添加节点
2537
2569
  */
2538
2570
  batchAddFromJSON(json, options) {
2539
- const { parent = this.root } = options ?? {};
2571
+ const { parent = this.root, onNodeCreated, onEdgeCreated } = options ?? {};
2540
2572
  const parentID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2541
2573
  const processedJSON = buildGroupJSON(json);
2542
2574
  const nodes = processedJSON.nodes.map(
2543
2575
  (nodeJSON) => this._createWorkflowNode(nodeJSON, {
2544
- parentID
2576
+ parentID,
2577
+ onNodeCreated,
2578
+ onEdgeCreated
2545
2579
  })
2546
2580
  );
2547
2581
  const edges = processedJSON.edges.map((edge) => this.createWorkflowLine(edge, parentID)).filter(Boolean);
@@ -3563,6 +3597,7 @@ var WorkflowOperationBaseServiceImpl = class extends FlowOperationBaseServiceImp
3563
3597
  edges: json.edges ?? []
3564
3598
  };
3565
3599
  const oldNodes = this.document.getAllNodes();
3600
+ const oldEdges = this.linesManager.getAllLines();
3566
3601
  const oldPositionMap = new Map(
3567
3602
  oldNodes.map((node) => [
3568
3603
  node.id,
@@ -3574,11 +3609,17 @@ var WorkflowOperationBaseServiceImpl = class extends FlowOperationBaseServiceImp
3574
3609
  );
3575
3610
  const newNodes = [];
3576
3611
  const newEdges = [];
3577
- this.linesManager.getAllLines().map((line) => line.dispose());
3578
3612
  this.document.batchAddFromJSON(workflowJSON, {
3579
3613
  onNodeCreated: (node) => newNodes.push(node),
3580
3614
  onEdgeCreated: (edge) => newEdges.push(edge)
3581
3615
  });
3616
+ const newEdgeIDSet = new Set(newEdges.map((edge) => edge.id));
3617
+ oldEdges.forEach((edge) => {
3618
+ if (!newEdgeIDSet.has(edge.id)) {
3619
+ edge.dispose();
3620
+ return;
3621
+ }
3622
+ });
3582
3623
  const newNodeIDSet = new Set(newNodes.map((node) => node.id));
3583
3624
  oldNodes.forEach((node) => {
3584
3625
  if (!newNodeIDSet.has(node.id)) {