@metadev/daga 4.2.14 → 4.2.16

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/Changelog.md CHANGED
@@ -6,6 +6,19 @@ List of releases and changes.
6
6
 
7
7
  ## Next release Joyeuse
8
8
 
9
+ ## v. 4.2.16
10
+
11
+ - Fix bug where the `DagaImporter` fails to create a node's label if it's blank [#373](https://github.com/metadevpro/daga/pull/373)
12
+ - Add `openTextInput` method to `Canvas` to enable opening a text box editor for a text via API [#374](https://github.com/metadevpro/daga/pull/374)
13
+
14
+ ## v. 4.2.15
15
+
16
+ - Configure center animation duration in buttons component [#368](https://github.com/metadevpro/daga/pull/368)
17
+ - Handle interruptions in zoom and pan animations [#369](https://github.com/metadevpro/daga/pull/369)
18
+ - Render ports on top of connections in diagram [#370](https://github.com/metadevpro/daga/pull/370)
19
+ - Enable making a connection pass through extra points if configured as such [#371](https://github.com/metadevpro/daga/pull/371)
20
+ - Allow configuring the tightening of connections across ports of different types [#372](https://github.com/metadevpro/daga/pull/372)
21
+
9
22
  ## v. 4.2.14
10
23
 
11
24
  - Fix `getViewCoordinates()` canvas method to return coordinates such that using those coordinates for the `translateTo()` method results in no changes [#364](https://github.com/metadevpro/daga/pull/364)
package/index.cjs.js CHANGED
@@ -1194,13 +1194,17 @@ const clone = o => {
1194
1194
  if (typeof o !== 'object') {
1195
1195
  return o;
1196
1196
  }
1197
+ if (Array.isArray(o)) {
1198
+ return o.map(clone);
1199
+ }
1197
1200
  const res = {};
1198
1201
  for (const e of Object.entries(o)) {
1199
- if (typeof e[1] === 'object') {
1200
- res[e[0]] = clone(e[1]);
1201
- } else {
1202
- res[e[0]] = e[1];
1203
- }
1202
+ res[e[0]] = clone(e[1]);
1203
+ // if (typeof e[1] === 'object') {
1204
+ // res[e[0]] = clone(e[1]);
1205
+ // } else {
1206
+ // res[e[0]] = e[1];
1207
+ // }
1204
1208
  }
1205
1209
  return res;
1206
1210
  };
@@ -2441,7 +2445,7 @@ class DiagramConnection extends DiagramElement {
2441
2445
  */
2442
2446
  this.endLabel = '';
2443
2447
  /**
2444
- * Points that this connection passes through.
2448
+ * Points that this connection must pass through in its route from its start point to its end point, in order.
2445
2449
  * @public
2446
2450
  */
2447
2451
  this.points = [];
@@ -2459,8 +2463,10 @@ class DiagramConnection extends DiagramElement {
2459
2463
  (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateConnectionsInView(this.id);
2460
2464
  }
2461
2465
  raise() {
2462
- var _a;
2466
+ var _a, _b, _c;
2463
2467
  (_a = this.select()) === null || _a === void 0 ? void 0 : _a.raise();
2468
+ (_b = this.start) === null || _b === void 0 ? void 0 : _b.raise(false);
2469
+ (_c = this.end) === null || _c === void 0 ? void 0 : _c.raise(false);
2464
2470
  }
2465
2471
  /**
2466
2472
  * Set the start of this connection to the given port or reset this connection's starting port if `undefined`.
@@ -2514,11 +2520,12 @@ class DiagramConnection extends DiagramElement {
2514
2520
  * @public
2515
2521
  */
2516
2522
  tighten() {
2517
- var _a, _b, _c, _d, _e;
2523
+ var _a, _b, _c, _d, _e, _f;
2518
2524
  const allowConnectionLoops = ((_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.allowConnectionLoops) || false;
2519
2525
  const allowSharingPorts = ((_b = this.model.canvas) === null || _b === void 0 ? void 0 : _b.allowSharingPorts) !== false;
2520
2526
  const allowSharingBothPorts = ((_c = this.model.canvas) === null || _c === void 0 ? void 0 : _c.allowSharingBothPorts) || false;
2521
- if (((_d = this.start) === null || _d === void 0 ? void 0 : _d.rootElement) && this.end) {
2527
+ const tightenConnectionsAcrossPortTypes = ((_d = this.model.canvas) === null || _d === void 0 ? void 0 : _d.tightenConnectionsAcrossPortTypes) || false;
2528
+ if (((_e = this.start) === null || _e === void 0 ? void 0 : _e.rootElement) && this.end) {
2522
2529
  const alternativeStartPortsSortedByDistanceAscending = this.start.rootElement.ports.map(p => [p, p.distanceTo(this.end.coords)]).sort((a, b) => a[1] - b[1]).map(a => a[0]);
2523
2530
  checkAlternativeStartPorts: for (const alternativeStartPort of alternativeStartPortsSortedByDistanceAscending) {
2524
2531
  if (!allowConnectionLoops && alternativeStartPort === this.end) {
@@ -2529,6 +2536,10 @@ class DiagramConnection extends DiagramElement {
2529
2536
  // alternative start port not valid, it doesn't allow outgoing connections
2530
2537
  continue checkAlternativeStartPorts;
2531
2538
  }
2539
+ if (!tightenConnectionsAcrossPortTypes && alternativeStartPort.type !== this.start.type) {
2540
+ // alternative start port not valid, the port type is different
2541
+ continue checkAlternativeStartPorts;
2542
+ }
2532
2543
  if (!allowSharingPorts && (alternativeStartPort.incomingConnections.filter(c => !c.removed && c !== this).length > 0 || alternativeStartPort.outgoingConnections.filter(c => !c.removed && c !== this).length > 0)) {
2533
2544
  // alternative start port not valid, it already has other connections
2534
2545
  continue checkAlternativeStartPorts;
@@ -2556,7 +2567,7 @@ class DiagramConnection extends DiagramElement {
2556
2567
  }
2557
2568
  }
2558
2569
  }
2559
- if (((_e = this.end) === null || _e === void 0 ? void 0 : _e.rootElement) && this.start) {
2570
+ if (((_f = this.end) === null || _f === void 0 ? void 0 : _f.rootElement) && this.start) {
2560
2571
  const alternativeEndPortsSortedByDistanceAscending = this.end.rootElement.ports.map(p => [p, p.distanceTo(this.start.coords)]).sort((a, b) => a[1] - b[1]).map(a => a[0]);
2561
2572
  checkAlternativeEndPorts: for (const alternativeEndPort of alternativeEndPortsSortedByDistanceAscending) {
2562
2573
  if (!allowConnectionLoops && alternativeEndPort === this.start) {
@@ -2567,6 +2578,10 @@ class DiagramConnection extends DiagramElement {
2567
2578
  // alternative end port not valid, it doesn't allow incoming connections
2568
2579
  continue checkAlternativeEndPorts;
2569
2580
  }
2581
+ if (!tightenConnectionsAcrossPortTypes && alternativeEndPort.type !== this.end.type) {
2582
+ // alternative end port not valid, the port type is different
2583
+ continue checkAlternativeEndPorts;
2584
+ }
2570
2585
  if (!allowSharingPorts && (alternativeEndPort.incomingConnections.filter(c => !c.removed && c !== this).length > 0 || alternativeEndPort.outgoingConnections.filter(c => !c.removed && c !== this).length > 0)) {
2571
2586
  // alternative end port not valid, it already has other connections
2572
2587
  continue checkAlternativeEndPorts;
@@ -2635,6 +2650,7 @@ class DiagramConnectionSet extends DiagramElementSet {
2635
2650
  * @returns The instanced connection.
2636
2651
  */
2637
2652
  new(type, start, end, id) {
2653
+ var _a, _b;
2638
2654
  let connectionType;
2639
2655
  if (type instanceof DiagramConnectionType) {
2640
2656
  connectionType = type;
@@ -2649,6 +2665,8 @@ class DiagramConnectionSet extends DiagramElementSet {
2649
2665
  super.add(connection);
2650
2666
  connection.updateInView();
2651
2667
  connection.valueSet.resetValues();
2668
+ (_a = connection.start) === null || _a === void 0 ? void 0 : _a.raise(false);
2669
+ (_b = connection.end) === null || _b === void 0 ? void 0 : _b.raise(false);
2652
2670
  return connection;
2653
2671
  }
2654
2672
  remove(id) {
@@ -4766,17 +4784,19 @@ class DiagramPort extends DiagramElement {
4766
4784
  var _a;
4767
4785
  (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
4768
4786
  }
4769
- raise() {
4787
+ raise(raiseConnections = true) {
4770
4788
  var _a;
4771
4789
  (_a = this.select()) === null || _a === void 0 ? void 0 : _a.raise();
4772
4790
  if (this.label) {
4773
4791
  this.label.raise();
4774
4792
  }
4775
- for (const connection of this.incomingConnections) {
4776
- connection.raise();
4777
- }
4778
- for (const connection of this.outgoingConnections) {
4779
- connection.raise();
4793
+ if (raiseConnections) {
4794
+ for (const connection of this.incomingConnections) {
4795
+ connection.raise();
4796
+ }
4797
+ for (const connection of this.outgoingConnections) {
4798
+ connection.raise();
4799
+ }
4780
4800
  }
4781
4801
  }
4782
4802
  /**
@@ -4930,23 +4950,21 @@ class DagaImporter {
4930
4950
  model.nodes.add(newNode);
4931
4951
  newNode.width = node.width;
4932
4952
  newNode.height = node.height;
4933
- if (node.label) {
4934
- // add node decorators
4935
- if (newNodeType.decorators) {
4936
- for (let i = 0; i < newNodeType.decorators.length; ++i) {
4937
- const decoratorConfig = newNodeType.decorators[i];
4938
- model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
4939
- }
4940
- }
4941
- // add node label
4942
- if (newNodeType.label) {
4943
- const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
4944
- const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4945
- newField.text = node.label;
4946
- newNode.label = newField;
4947
- model.fields.add(newField);
4948
- newField.updateInView();
4949
- }
4953
+ // add node decorators
4954
+ if (newNodeType.decorators) {
4955
+ for (let i = 0; i < newNodeType.decorators.length; ++i) {
4956
+ const decoratorConfig = newNodeType.decorators[i];
4957
+ model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
4958
+ }
4959
+ }
4960
+ // add node label
4961
+ if (newNodeType.label) {
4962
+ const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
4963
+ const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4964
+ newField.text = node.label;
4965
+ newNode.label = newField;
4966
+ model.fields.add(newField);
4967
+ newField.updateInView();
4950
4968
  }
4951
4969
  for (const child of node.children || []) {
4952
4970
  const newChild = this.importNode(model, child);
@@ -4959,16 +4977,14 @@ class DagaImporter {
4959
4977
  const newSection = new DiagramSection(model, newNode, section.indexXInNode, section.indexYInNode, section.coords, section.width, section.height, section.id);
4960
4978
  (_b = newNode.sections) === null || _b === void 0 ? void 0 : _b.push(newSection);
4961
4979
  model.sections.add(newSection);
4962
- if (section.label) {
4963
- // add section label
4964
- if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
4965
- const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
4966
- const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4967
- newField.text = section.label;
4968
- newSection.label = newField;
4969
- model.fields.add(newField);
4970
- newField.updateInView();
4971
- }
4980
+ // add section label
4981
+ if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
4982
+ const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
4983
+ const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4984
+ newField.text = section.label;
4985
+ newSection.label = newField;
4986
+ model.fields.add(newField);
4987
+ newField.updateInView();
4972
4988
  }
4973
4989
  let portCounter = 0;
4974
4990
  for (const port of section.ports || []) {
@@ -6698,8 +6714,8 @@ const isSecondaryButton = event => {
6698
6714
  * @private
6699
6715
  * @see linePath
6700
6716
  */
6701
- const getConnectionPath = (shape, startCoords, endCoords, startDirection, endDirection, width, startMarkerWidth, endMarkerWidth) => {
6702
- return linePath(shape, [startCoords, endCoords], startDirection, endDirection, Math.max(
6717
+ const getConnectionPath = (shape, startCoords, endCoords, startDirection, endDirection, points, width, startMarkerWidth, endMarkerWidth) => {
6718
+ return linePath(shape, [startCoords, ...points, endCoords], startDirection, endDirection, Math.max(
6703
6719
  // reasonable value for the minimumDistanceBeforeTurn relative to the line width
6704
6720
  10, startMarkerWidth || 0, endMarkerWidth || 0) * width);
6705
6721
  };
@@ -7512,7 +7528,7 @@ class DiagramCanvas {
7512
7528
  * @param config The configuration object used to set the parameters of this canvas.
7513
7529
  */
7514
7530
  constructor(parentComponent, config) {
7515
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
7531
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
7516
7532
  this.backgroundPatternId = `daga-background-pattern-id-${DiagramCanvas.canvasCount++}`;
7517
7533
  this.zoomTransform = d3__namespace.zoomIdentity;
7518
7534
  // used to distinguish drags from clicks when dragging elements and during multiple selection
@@ -7540,12 +7556,13 @@ class DiagramCanvas {
7540
7556
  this.panRate = ((_z = config.canvas) === null || _z === void 0 ? void 0 : _z.panRate) || 100;
7541
7557
  this.inferConnectionType = ((_0 = config.connectionSettings) === null || _0 === void 0 ? void 0 : _0.inferConnectionType) || false;
7542
7558
  this.autoTightenConnections = ((_1 = config.connectionSettings) === null || _1 === void 0 ? void 0 : _1.autoTighten) !== false;
7543
- this.allowConnectionLoops = ((_2 = config.connectionSettings) === null || _2 === void 0 ? void 0 : _2.allowLoops) || false;
7544
- this.allowSharingPorts = ((_3 = config.connectionSettings) === null || _3 === void 0 ? void 0 : _3.sharePorts) !== false;
7545
- this.allowSharingBothPorts = ((_4 = config.connectionSettings) === null || _4 === void 0 ? void 0 : _4.shareBothPorts) || false;
7546
- this.portHighlightRadius = ((_5 = config.connectionSettings) === null || _5 === void 0 ? void 0 : _5.portHighlightRadius) || 100;
7559
+ this.tightenConnectionsAcrossPortTypes = ((_2 = config.connectionSettings) === null || _2 === void 0 ? void 0 : _2.tightenAcrossPortTypes) || false;
7560
+ this.allowConnectionLoops = ((_3 = config.connectionSettings) === null || _3 === void 0 ? void 0 : _3.allowLoops) || false;
7561
+ this.allowSharingPorts = ((_4 = config.connectionSettings) === null || _4 === void 0 ? void 0 : _4.sharePorts) !== false;
7562
+ this.allowSharingBothPorts = ((_5 = config.connectionSettings) === null || _5 === void 0 ? void 0 : _5.shareBothPorts) || false;
7563
+ this.portHighlightRadius = ((_6 = config.connectionSettings) === null || _6 === void 0 ? void 0 : _6.portHighlightRadius) || 100;
7547
7564
  this.multipleSelectionOn = false;
7548
- this.priorityThresholds = ((_6 = config.canvas) === null || _6 === void 0 ? void 0 : _6.priorityThresholds) || [];
7565
+ this.priorityThresholds = ((_7 = config.canvas) === null || _7 === void 0 ? void 0 : _7.priorityThresholds) || [];
7549
7566
  this.priorityThreshold = this.priorityThresholds ? this.priorityThresholds[0] : undefined;
7550
7567
  this.layoutFormat = config.layoutFormat;
7551
7568
  this.userActions = config.userActions || {};
@@ -7572,7 +7589,7 @@ class DiagramCanvas {
7572
7589
  const connectionType = new DiagramConnectionType(Object.assign(Object.assign({}, config.connectionTypeDefaults), connectionTypeConfig));
7573
7590
  this.model.connections.types.add(connectionType);
7574
7591
  }
7575
- this._connectionType = ((_7 = config === null || config === void 0 ? void 0 : config.connectionSettings) === null || _7 === void 0 ? void 0 : _7.defaultConnection) !== undefined ? this.model.connections.types.get(config.connectionSettings.defaultConnection) : undefined;
7592
+ this._connectionType = ((_8 = config === null || config === void 0 ? void 0 : config.connectionSettings) === null || _8 === void 0 ? void 0 : _8.defaultConnection) !== undefined ? this.model.connections.types.get(config.connectionSettings.defaultConnection) : undefined;
7576
7593
  }
7577
7594
  }
7578
7595
  addValidator(validator) {
@@ -7864,12 +7881,20 @@ class DiagramCanvas {
7864
7881
  targetY = y,
7865
7882
  targetZoom = z;
7866
7883
  this.selectCanvasElements().transition().duration(duration).ease(d3__namespace.easeCubicInOut).tween('progress', () => {
7884
+ let animationInterrupted = false;
7867
7885
  return value => {
7868
- const currentX = value * (targetX - startingX) + startingX;
7869
- const currentY = value * (targetY - startingY) + startingY;
7870
- const currentZoom = value * (targetZoom - startingZoom) + startingZoom;
7871
- this.zoomBehavior.scaleTo(this.selectCanvasView(), currentZoom);
7872
- this.zoomBehavior.translateTo(this.selectCanvasView(), currentX, currentY);
7886
+ try {
7887
+ if (!animationInterrupted) {
7888
+ const currentX = value * (targetX - startingX) + startingX;
7889
+ const currentY = value * (targetY - startingY) + startingY;
7890
+ const currentZoom = value * (targetZoom - startingZoom) + startingZoom;
7891
+ this.zoomBehavior.scaleTo(this.selectCanvasView(), currentZoom);
7892
+ this.zoomBehavior.translateTo(this.selectCanvasView(), currentX, currentY);
7893
+ }
7894
+ } catch (e) {
7895
+ console.warn('Animation has been interrupted');
7896
+ animationInterrupted = true;
7897
+ }
7873
7898
  };
7874
7899
  });
7875
7900
  }
@@ -8482,14 +8507,14 @@ class DiagramCanvas {
8482
8507
  }
8483
8508
  }
8484
8509
  }).on(exports.DragEvents.Drag, (event, d) => {
8485
- var _a, _b, _c, _d;
8510
+ var _a, _b, _c, _d, _e;
8486
8511
  if (this.multipleSelectionOn || this.secondaryButton) {
8487
8512
  this.continueMultipleSelection(event);
8488
8513
  } else {
8489
8514
  if (this.canUserPerformAction(exports.DiagramActions.AddConnection) && !d.removed) {
8490
8515
  if (this.unfinishedConnection !== undefined) {
8491
8516
  const endCoords = [event.x, event.y];
8492
- (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.attr('d', getConnectionPath(this.unfinishedConnection.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_b = this.unfinishedConnection.type.defaultStartMarkerLook) === null || _b === void 0 ? void 0 : _b.width, (_c = this.unfinishedConnection.type.defaultEndMarkerLook) === null || _c === void 0 ? void 0 : _c.width));
8517
+ (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.attr('d', getConnectionPath(this.unfinishedConnection.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.points, this.unfinishedConnection.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_b = this.unfinishedConnection.type.defaultStartMarkerLook) === null || _b === void 0 ? void 0 : _b.width, (_c = this.unfinishedConnection.type.defaultEndMarkerLook) === null || _c === void 0 ? void 0 : _c.width));
8493
8518
  const unfinishedConnectionGhostNode = (_d = this.unfinishedConnectionTracer) === null || _d === void 0 ? void 0 : _d.node();
8494
8519
  if (unfinishedConnectionGhostNode) {
8495
8520
  let margin = 2;
@@ -8504,6 +8529,7 @@ class DiagramCanvas {
8504
8529
  this.unfinishedConnection.endCoords = endCoords;
8505
8530
  }
8506
8531
  this.updateConnectionsInView(UNFINISHED_CONNECTION_ID);
8532
+ (_e = this.unfinishedConnectionPort) === null || _e === void 0 ? void 0 : _e.raise(false);
8507
8533
  // highlight closest target port
8508
8534
  if (this.model.ports.length > 0) {
8509
8535
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
@@ -8637,11 +8663,11 @@ class DiagramCanvas {
8637
8663
  enterSelection.select('g.diagram-connection-end-label').append('text').style('user-select', 'none');
8638
8664
  mergeSelection.attr('opacity', d => d.removed ? 0.5 : 1).select('path.diagram-connection-path').attr('d', d => {
8639
8665
  var _a, _b;
8640
- return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8666
+ return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.points, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8641
8667
  }).attr('marker-start', d => `url(#${d.id}-start-marker)`).attr('marker-end', d => `url(#${d.id}-end-marker)`).attr('stroke', d => d.look.color || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.color).attr('stroke-width', d => `${d.look.thickness}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.look.style || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.style, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness)).attr('fill', 'none');
8642
8668
  mergeSelection.select('path.diagram-connection-path-box').attr('d', d => {
8643
8669
  var _a, _b;
8644
- return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8670
+ return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.points, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8645
8671
  }).attr('stroke', 'transparent')
8646
8672
  // allow generating pointer events even when it is transparent
8647
8673
  .attr('pointer-events', 'stroke').attr('stroke-width', d => `${(d.look.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness) + CONNECTION_PATH_BOX_THICKNESS}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.look.style || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.style, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness)).attr('fill', 'none');
@@ -8696,21 +8722,7 @@ class DiagramCanvas {
8696
8722
  this.diagramEvent$.next(diagramEvent);
8697
8723
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(exports.DiagramActions.EditField) && d.editable && !d.removed) {
8698
8724
  this.currentAction = new EditFieldAction(this, d.id, d.text, '');
8699
- this.createInputField(d.text, d.coords, d.width, d.height, d.fontSize, d.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, d.orientation, _text => {
8700
- /*
8701
- Empty for now
8702
- We should create a better function to stretch the root element as the text expands
8703
- Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
8704
- */
8705
- }, text => {
8706
- d.text = text;
8707
- if (this.currentAction instanceof EditFieldAction) {
8708
- this.currentAction.to = text;
8709
- this.currentAction.do();
8710
- this.actionStack.add(this.currentAction);
8711
- this.currentAction = undefined;
8712
- }
8713
- });
8725
+ this.openTextInput(d.id);
8714
8726
  }
8715
8727
  }).call(d3__namespace.drag().filter(event => {
8716
8728
  this.secondaryButton = isSecondaryButton(event);
@@ -9197,6 +9209,7 @@ class DiagramCanvas {
9197
9209
  if (port.allowsOutgoing || port.allowsIncoming) {
9198
9210
  if (this.connectionType && (this.connectionType.canStartFromType(((_b = (_a = port.getNode()) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.id) || '') && port.allowsOutgoing || this.connectionType.canFinishOnType(((_d = (_c = port.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || '') && port.allowsIncoming)) {
9199
9211
  this.unfinishedConnection = new DiagramConnection(this.model, this.connectionType, port, undefined, UNFINISHED_CONNECTION_ID);
9212
+ this.unfinishedConnectionPort = port;
9200
9213
  } else {
9201
9214
  if (this.inferConnectionType) {
9202
9215
  let differentConnectionType = this.model.connections.types.all().find(t => {
@@ -9211,6 +9224,7 @@ class DiagramCanvas {
9211
9224
  }
9212
9225
  if (differentConnectionType !== undefined) {
9213
9226
  this.unfinishedConnection = new DiagramConnection(this.model, differentConnectionType, port, undefined, UNFINISHED_CONNECTION_ID);
9227
+ this.unfinishedConnectionPort = port;
9214
9228
  }
9215
9229
  }
9216
9230
  }
@@ -9284,6 +9298,7 @@ class DiagramCanvas {
9284
9298
  (_b = this.unfinishedConnection) === null || _b === void 0 ? void 0 : _b.setEnd(undefined);
9285
9299
  (_d = (_c = this.unfinishedConnection) === null || _c === void 0 ? void 0 : _c.select()) === null || _d === void 0 ? void 0 : _d.remove();
9286
9300
  this.unfinishedConnection = undefined;
9301
+ this.unfinishedConnectionPort = undefined;
9287
9302
  }
9288
9303
  cancelAllUserActions() {
9289
9304
  this.currentAction = undefined;
@@ -9295,6 +9310,27 @@ class DiagramCanvas {
9295
9310
  canUserPerformAction(action) {
9296
9311
  return this.userActions[action] !== false;
9297
9312
  }
9313
+ openTextInput(id) {
9314
+ const field = this.model.fields.get(id);
9315
+ if (field) {
9316
+ this.createInputField(field.text, field.coords, field.width, field.height, field.fontSize, field.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, field.orientation, () => {
9317
+ // (_text)
9318
+ /*
9319
+ Empty for now
9320
+ We should create a better function to stretch the root element as the text expands
9321
+ Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
9322
+ */
9323
+ }, text => {
9324
+ field.text = text;
9325
+ if (this.currentAction instanceof EditFieldAction) {
9326
+ this.currentAction.to = text;
9327
+ this.currentAction.do();
9328
+ this.actionStack.add(this.currentAction);
9329
+ this.currentAction = undefined;
9330
+ }
9331
+ });
9332
+ }
9333
+ }
9298
9334
  createInputField(text, coords, width, height, fontSize, fontFamily, orientation, changeCallback, finishCallback) {
9299
9335
  // if we have a text input open, close it before creating a new one
9300
9336
  this.removeInputField();
package/index.esm.js CHANGED
@@ -1173,13 +1173,17 @@ const clone = o => {
1173
1173
  if (typeof o !== 'object') {
1174
1174
  return o;
1175
1175
  }
1176
+ if (Array.isArray(o)) {
1177
+ return o.map(clone);
1178
+ }
1176
1179
  const res = {};
1177
1180
  for (const e of Object.entries(o)) {
1178
- if (typeof e[1] === 'object') {
1179
- res[e[0]] = clone(e[1]);
1180
- } else {
1181
- res[e[0]] = e[1];
1182
- }
1181
+ res[e[0]] = clone(e[1]);
1182
+ // if (typeof e[1] === 'object') {
1183
+ // res[e[0]] = clone(e[1]);
1184
+ // } else {
1185
+ // res[e[0]] = e[1];
1186
+ // }
1183
1187
  }
1184
1188
  return res;
1185
1189
  };
@@ -2420,7 +2424,7 @@ class DiagramConnection extends DiagramElement {
2420
2424
  */
2421
2425
  this.endLabel = '';
2422
2426
  /**
2423
- * Points that this connection passes through.
2427
+ * Points that this connection must pass through in its route from its start point to its end point, in order.
2424
2428
  * @public
2425
2429
  */
2426
2430
  this.points = [];
@@ -2438,8 +2442,10 @@ class DiagramConnection extends DiagramElement {
2438
2442
  (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateConnectionsInView(this.id);
2439
2443
  }
2440
2444
  raise() {
2441
- var _a;
2445
+ var _a, _b, _c;
2442
2446
  (_a = this.select()) === null || _a === void 0 ? void 0 : _a.raise();
2447
+ (_b = this.start) === null || _b === void 0 ? void 0 : _b.raise(false);
2448
+ (_c = this.end) === null || _c === void 0 ? void 0 : _c.raise(false);
2443
2449
  }
2444
2450
  /**
2445
2451
  * Set the start of this connection to the given port or reset this connection's starting port if `undefined`.
@@ -2493,11 +2499,12 @@ class DiagramConnection extends DiagramElement {
2493
2499
  * @public
2494
2500
  */
2495
2501
  tighten() {
2496
- var _a, _b, _c, _d, _e;
2502
+ var _a, _b, _c, _d, _e, _f;
2497
2503
  const allowConnectionLoops = ((_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.allowConnectionLoops) || false;
2498
2504
  const allowSharingPorts = ((_b = this.model.canvas) === null || _b === void 0 ? void 0 : _b.allowSharingPorts) !== false;
2499
2505
  const allowSharingBothPorts = ((_c = this.model.canvas) === null || _c === void 0 ? void 0 : _c.allowSharingBothPorts) || false;
2500
- if (((_d = this.start) === null || _d === void 0 ? void 0 : _d.rootElement) && this.end) {
2506
+ const tightenConnectionsAcrossPortTypes = ((_d = this.model.canvas) === null || _d === void 0 ? void 0 : _d.tightenConnectionsAcrossPortTypes) || false;
2507
+ if (((_e = this.start) === null || _e === void 0 ? void 0 : _e.rootElement) && this.end) {
2501
2508
  const alternativeStartPortsSortedByDistanceAscending = this.start.rootElement.ports.map(p => [p, p.distanceTo(this.end.coords)]).sort((a, b) => a[1] - b[1]).map(a => a[0]);
2502
2509
  checkAlternativeStartPorts: for (const alternativeStartPort of alternativeStartPortsSortedByDistanceAscending) {
2503
2510
  if (!allowConnectionLoops && alternativeStartPort === this.end) {
@@ -2508,6 +2515,10 @@ class DiagramConnection extends DiagramElement {
2508
2515
  // alternative start port not valid, it doesn't allow outgoing connections
2509
2516
  continue checkAlternativeStartPorts;
2510
2517
  }
2518
+ if (!tightenConnectionsAcrossPortTypes && alternativeStartPort.type !== this.start.type) {
2519
+ // alternative start port not valid, the port type is different
2520
+ continue checkAlternativeStartPorts;
2521
+ }
2511
2522
  if (!allowSharingPorts && (alternativeStartPort.incomingConnections.filter(c => !c.removed && c !== this).length > 0 || alternativeStartPort.outgoingConnections.filter(c => !c.removed && c !== this).length > 0)) {
2512
2523
  // alternative start port not valid, it already has other connections
2513
2524
  continue checkAlternativeStartPorts;
@@ -2535,7 +2546,7 @@ class DiagramConnection extends DiagramElement {
2535
2546
  }
2536
2547
  }
2537
2548
  }
2538
- if (((_e = this.end) === null || _e === void 0 ? void 0 : _e.rootElement) && this.start) {
2549
+ if (((_f = this.end) === null || _f === void 0 ? void 0 : _f.rootElement) && this.start) {
2539
2550
  const alternativeEndPortsSortedByDistanceAscending = this.end.rootElement.ports.map(p => [p, p.distanceTo(this.start.coords)]).sort((a, b) => a[1] - b[1]).map(a => a[0]);
2540
2551
  checkAlternativeEndPorts: for (const alternativeEndPort of alternativeEndPortsSortedByDistanceAscending) {
2541
2552
  if (!allowConnectionLoops && alternativeEndPort === this.start) {
@@ -2546,6 +2557,10 @@ class DiagramConnection extends DiagramElement {
2546
2557
  // alternative end port not valid, it doesn't allow incoming connections
2547
2558
  continue checkAlternativeEndPorts;
2548
2559
  }
2560
+ if (!tightenConnectionsAcrossPortTypes && alternativeEndPort.type !== this.end.type) {
2561
+ // alternative end port not valid, the port type is different
2562
+ continue checkAlternativeEndPorts;
2563
+ }
2549
2564
  if (!allowSharingPorts && (alternativeEndPort.incomingConnections.filter(c => !c.removed && c !== this).length > 0 || alternativeEndPort.outgoingConnections.filter(c => !c.removed && c !== this).length > 0)) {
2550
2565
  // alternative end port not valid, it already has other connections
2551
2566
  continue checkAlternativeEndPorts;
@@ -2614,6 +2629,7 @@ class DiagramConnectionSet extends DiagramElementSet {
2614
2629
  * @returns The instanced connection.
2615
2630
  */
2616
2631
  new(type, start, end, id) {
2632
+ var _a, _b;
2617
2633
  let connectionType;
2618
2634
  if (type instanceof DiagramConnectionType) {
2619
2635
  connectionType = type;
@@ -2628,6 +2644,8 @@ class DiagramConnectionSet extends DiagramElementSet {
2628
2644
  super.add(connection);
2629
2645
  connection.updateInView();
2630
2646
  connection.valueSet.resetValues();
2647
+ (_a = connection.start) === null || _a === void 0 ? void 0 : _a.raise(false);
2648
+ (_b = connection.end) === null || _b === void 0 ? void 0 : _b.raise(false);
2631
2649
  return connection;
2632
2650
  }
2633
2651
  remove(id) {
@@ -4745,17 +4763,19 @@ class DiagramPort extends DiagramElement {
4745
4763
  var _a;
4746
4764
  (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
4747
4765
  }
4748
- raise() {
4766
+ raise(raiseConnections = true) {
4749
4767
  var _a;
4750
4768
  (_a = this.select()) === null || _a === void 0 ? void 0 : _a.raise();
4751
4769
  if (this.label) {
4752
4770
  this.label.raise();
4753
4771
  }
4754
- for (const connection of this.incomingConnections) {
4755
- connection.raise();
4756
- }
4757
- for (const connection of this.outgoingConnections) {
4758
- connection.raise();
4772
+ if (raiseConnections) {
4773
+ for (const connection of this.incomingConnections) {
4774
+ connection.raise();
4775
+ }
4776
+ for (const connection of this.outgoingConnections) {
4777
+ connection.raise();
4778
+ }
4759
4779
  }
4760
4780
  }
4761
4781
  /**
@@ -4909,23 +4929,21 @@ class DagaImporter {
4909
4929
  model.nodes.add(newNode);
4910
4930
  newNode.width = node.width;
4911
4931
  newNode.height = node.height;
4912
- if (node.label) {
4913
- // add node decorators
4914
- if (newNodeType.decorators) {
4915
- for (let i = 0; i < newNodeType.decorators.length; ++i) {
4916
- const decoratorConfig = newNodeType.decorators[i];
4917
- model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
4918
- }
4919
- }
4920
- // add node label
4921
- if (newNodeType.label) {
4922
- const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
4923
- const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4924
- newField.text = node.label;
4925
- newNode.label = newField;
4926
- model.fields.add(newField);
4927
- newField.updateInView();
4928
- }
4932
+ // add node decorators
4933
+ if (newNodeType.decorators) {
4934
+ for (let i = 0; i < newNodeType.decorators.length; ++i) {
4935
+ const decoratorConfig = newNodeType.decorators[i];
4936
+ model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
4937
+ }
4938
+ }
4939
+ // add node label
4940
+ if (newNodeType.label) {
4941
+ const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
4942
+ const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4943
+ newField.text = node.label;
4944
+ newNode.label = newField;
4945
+ model.fields.add(newField);
4946
+ newField.updateInView();
4929
4947
  }
4930
4948
  for (const child of node.children || []) {
4931
4949
  const newChild = this.importNode(model, child);
@@ -4938,16 +4956,14 @@ class DagaImporter {
4938
4956
  const newSection = new DiagramSection(model, newNode, section.indexXInNode, section.indexYInNode, section.coords, section.width, section.height, section.id);
4939
4957
  (_b = newNode.sections) === null || _b === void 0 ? void 0 : _b.push(newSection);
4940
4958
  model.sections.add(newSection);
4941
- if (section.label) {
4942
- // add section label
4943
- if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
4944
- const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
4945
- const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4946
- newField.text = section.label;
4947
- newSection.label = newField;
4948
- model.fields.add(newField);
4949
- newField.updateInView();
4950
- }
4959
+ // add section label
4960
+ if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
4961
+ const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
4962
+ const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4963
+ newField.text = section.label;
4964
+ newSection.label = newField;
4965
+ model.fields.add(newField);
4966
+ newField.updateInView();
4951
4967
  }
4952
4968
  let portCounter = 0;
4953
4969
  for (const port of section.ports || []) {
@@ -6677,8 +6693,8 @@ const isSecondaryButton = event => {
6677
6693
  * @private
6678
6694
  * @see linePath
6679
6695
  */
6680
- const getConnectionPath = (shape, startCoords, endCoords, startDirection, endDirection, width, startMarkerWidth, endMarkerWidth) => {
6681
- return linePath(shape, [startCoords, endCoords], startDirection, endDirection, Math.max(
6696
+ const getConnectionPath = (shape, startCoords, endCoords, startDirection, endDirection, points, width, startMarkerWidth, endMarkerWidth) => {
6697
+ return linePath(shape, [startCoords, ...points, endCoords], startDirection, endDirection, Math.max(
6682
6698
  // reasonable value for the minimumDistanceBeforeTurn relative to the line width
6683
6699
  10, startMarkerWidth || 0, endMarkerWidth || 0) * width);
6684
6700
  };
@@ -7491,7 +7507,7 @@ class DiagramCanvas {
7491
7507
  * @param config The configuration object used to set the parameters of this canvas.
7492
7508
  */
7493
7509
  constructor(parentComponent, config) {
7494
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
7510
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
7495
7511
  this.backgroundPatternId = `daga-background-pattern-id-${DiagramCanvas.canvasCount++}`;
7496
7512
  this.zoomTransform = d3.zoomIdentity;
7497
7513
  // used to distinguish drags from clicks when dragging elements and during multiple selection
@@ -7519,12 +7535,13 @@ class DiagramCanvas {
7519
7535
  this.panRate = ((_z = config.canvas) === null || _z === void 0 ? void 0 : _z.panRate) || 100;
7520
7536
  this.inferConnectionType = ((_0 = config.connectionSettings) === null || _0 === void 0 ? void 0 : _0.inferConnectionType) || false;
7521
7537
  this.autoTightenConnections = ((_1 = config.connectionSettings) === null || _1 === void 0 ? void 0 : _1.autoTighten) !== false;
7522
- this.allowConnectionLoops = ((_2 = config.connectionSettings) === null || _2 === void 0 ? void 0 : _2.allowLoops) || false;
7523
- this.allowSharingPorts = ((_3 = config.connectionSettings) === null || _3 === void 0 ? void 0 : _3.sharePorts) !== false;
7524
- this.allowSharingBothPorts = ((_4 = config.connectionSettings) === null || _4 === void 0 ? void 0 : _4.shareBothPorts) || false;
7525
- this.portHighlightRadius = ((_5 = config.connectionSettings) === null || _5 === void 0 ? void 0 : _5.portHighlightRadius) || 100;
7538
+ this.tightenConnectionsAcrossPortTypes = ((_2 = config.connectionSettings) === null || _2 === void 0 ? void 0 : _2.tightenAcrossPortTypes) || false;
7539
+ this.allowConnectionLoops = ((_3 = config.connectionSettings) === null || _3 === void 0 ? void 0 : _3.allowLoops) || false;
7540
+ this.allowSharingPorts = ((_4 = config.connectionSettings) === null || _4 === void 0 ? void 0 : _4.sharePorts) !== false;
7541
+ this.allowSharingBothPorts = ((_5 = config.connectionSettings) === null || _5 === void 0 ? void 0 : _5.shareBothPorts) || false;
7542
+ this.portHighlightRadius = ((_6 = config.connectionSettings) === null || _6 === void 0 ? void 0 : _6.portHighlightRadius) || 100;
7526
7543
  this.multipleSelectionOn = false;
7527
- this.priorityThresholds = ((_6 = config.canvas) === null || _6 === void 0 ? void 0 : _6.priorityThresholds) || [];
7544
+ this.priorityThresholds = ((_7 = config.canvas) === null || _7 === void 0 ? void 0 : _7.priorityThresholds) || [];
7528
7545
  this.priorityThreshold = this.priorityThresholds ? this.priorityThresholds[0] : undefined;
7529
7546
  this.layoutFormat = config.layoutFormat;
7530
7547
  this.userActions = config.userActions || {};
@@ -7551,7 +7568,7 @@ class DiagramCanvas {
7551
7568
  const connectionType = new DiagramConnectionType(Object.assign(Object.assign({}, config.connectionTypeDefaults), connectionTypeConfig));
7552
7569
  this.model.connections.types.add(connectionType);
7553
7570
  }
7554
- this._connectionType = ((_7 = config === null || config === void 0 ? void 0 : config.connectionSettings) === null || _7 === void 0 ? void 0 : _7.defaultConnection) !== undefined ? this.model.connections.types.get(config.connectionSettings.defaultConnection) : undefined;
7571
+ this._connectionType = ((_8 = config === null || config === void 0 ? void 0 : config.connectionSettings) === null || _8 === void 0 ? void 0 : _8.defaultConnection) !== undefined ? this.model.connections.types.get(config.connectionSettings.defaultConnection) : undefined;
7555
7572
  }
7556
7573
  }
7557
7574
  addValidator(validator) {
@@ -7843,12 +7860,20 @@ class DiagramCanvas {
7843
7860
  targetY = y,
7844
7861
  targetZoom = z;
7845
7862
  this.selectCanvasElements().transition().duration(duration).ease(d3.easeCubicInOut).tween('progress', () => {
7863
+ let animationInterrupted = false;
7846
7864
  return value => {
7847
- const currentX = value * (targetX - startingX) + startingX;
7848
- const currentY = value * (targetY - startingY) + startingY;
7849
- const currentZoom = value * (targetZoom - startingZoom) + startingZoom;
7850
- this.zoomBehavior.scaleTo(this.selectCanvasView(), currentZoom);
7851
- this.zoomBehavior.translateTo(this.selectCanvasView(), currentX, currentY);
7865
+ try {
7866
+ if (!animationInterrupted) {
7867
+ const currentX = value * (targetX - startingX) + startingX;
7868
+ const currentY = value * (targetY - startingY) + startingY;
7869
+ const currentZoom = value * (targetZoom - startingZoom) + startingZoom;
7870
+ this.zoomBehavior.scaleTo(this.selectCanvasView(), currentZoom);
7871
+ this.zoomBehavior.translateTo(this.selectCanvasView(), currentX, currentY);
7872
+ }
7873
+ } catch (e) {
7874
+ console.warn('Animation has been interrupted');
7875
+ animationInterrupted = true;
7876
+ }
7852
7877
  };
7853
7878
  });
7854
7879
  }
@@ -8461,14 +8486,14 @@ class DiagramCanvas {
8461
8486
  }
8462
8487
  }
8463
8488
  }).on(DragEvents.Drag, (event, d) => {
8464
- var _a, _b, _c, _d;
8489
+ var _a, _b, _c, _d, _e;
8465
8490
  if (this.multipleSelectionOn || this.secondaryButton) {
8466
8491
  this.continueMultipleSelection(event);
8467
8492
  } else {
8468
8493
  if (this.canUserPerformAction(DiagramActions.AddConnection) && !d.removed) {
8469
8494
  if (this.unfinishedConnection !== undefined) {
8470
8495
  const endCoords = [event.x, event.y];
8471
- (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.attr('d', getConnectionPath(this.unfinishedConnection.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_b = this.unfinishedConnection.type.defaultStartMarkerLook) === null || _b === void 0 ? void 0 : _b.width, (_c = this.unfinishedConnection.type.defaultEndMarkerLook) === null || _c === void 0 ? void 0 : _c.width));
8496
+ (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.attr('d', getConnectionPath(this.unfinishedConnection.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.points, this.unfinishedConnection.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_b = this.unfinishedConnection.type.defaultStartMarkerLook) === null || _b === void 0 ? void 0 : _b.width, (_c = this.unfinishedConnection.type.defaultEndMarkerLook) === null || _c === void 0 ? void 0 : _c.width));
8472
8497
  const unfinishedConnectionGhostNode = (_d = this.unfinishedConnectionTracer) === null || _d === void 0 ? void 0 : _d.node();
8473
8498
  if (unfinishedConnectionGhostNode) {
8474
8499
  let margin = 2;
@@ -8483,6 +8508,7 @@ class DiagramCanvas {
8483
8508
  this.unfinishedConnection.endCoords = endCoords;
8484
8509
  }
8485
8510
  this.updateConnectionsInView(UNFINISHED_CONNECTION_ID);
8511
+ (_e = this.unfinishedConnectionPort) === null || _e === void 0 ? void 0 : _e.raise(false);
8486
8512
  // highlight closest target port
8487
8513
  if (this.model.ports.length > 0) {
8488
8514
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
@@ -8616,11 +8642,11 @@ class DiagramCanvas {
8616
8642
  enterSelection.select('g.diagram-connection-end-label').append('text').style('user-select', 'none');
8617
8643
  mergeSelection.attr('opacity', d => d.removed ? 0.5 : 1).select('path.diagram-connection-path').attr('d', d => {
8618
8644
  var _a, _b;
8619
- return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8645
+ return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.points, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8620
8646
  }).attr('marker-start', d => `url(#${d.id}-start-marker)`).attr('marker-end', d => `url(#${d.id}-end-marker)`).attr('stroke', d => d.look.color || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.color).attr('stroke-width', d => `${d.look.thickness}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.look.style || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.style, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness)).attr('fill', 'none');
8621
8647
  mergeSelection.select('path.diagram-connection-path-box').attr('d', d => {
8622
8648
  var _a, _b;
8623
- return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8649
+ return getConnectionPath(d.look.shape || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.points, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness, (_a = d.type.defaultStartMarkerLook) === null || _a === void 0 ? void 0 : _a.width, (_b = d.type.defaultEndMarkerLook) === null || _b === void 0 ? void 0 : _b.width);
8624
8650
  }).attr('stroke', 'transparent')
8625
8651
  // allow generating pointer events even when it is transparent
8626
8652
  .attr('pointer-events', 'stroke').attr('stroke-width', d => `${(d.look.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness) + CONNECTION_PATH_BOX_THICKNESS}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.look.style || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.style, d.type.defaultLook.thickness || DIAGRAM_CONNECTION_TYPE_DEFAULTS.look.thickness)).attr('fill', 'none');
@@ -8675,21 +8701,7 @@ class DiagramCanvas {
8675
8701
  this.diagramEvent$.next(diagramEvent);
8676
8702
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.EditField) && d.editable && !d.removed) {
8677
8703
  this.currentAction = new EditFieldAction(this, d.id, d.text, '');
8678
- this.createInputField(d.text, d.coords, d.width, d.height, d.fontSize, d.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, d.orientation, _text => {
8679
- /*
8680
- Empty for now
8681
- We should create a better function to stretch the root element as the text expands
8682
- Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
8683
- */
8684
- }, text => {
8685
- d.text = text;
8686
- if (this.currentAction instanceof EditFieldAction) {
8687
- this.currentAction.to = text;
8688
- this.currentAction.do();
8689
- this.actionStack.add(this.currentAction);
8690
- this.currentAction = undefined;
8691
- }
8692
- });
8704
+ this.openTextInput(d.id);
8693
8705
  }
8694
8706
  }).call(d3.drag().filter(event => {
8695
8707
  this.secondaryButton = isSecondaryButton(event);
@@ -9176,6 +9188,7 @@ class DiagramCanvas {
9176
9188
  if (port.allowsOutgoing || port.allowsIncoming) {
9177
9189
  if (this.connectionType && (this.connectionType.canStartFromType(((_b = (_a = port.getNode()) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.id) || '') && port.allowsOutgoing || this.connectionType.canFinishOnType(((_d = (_c = port.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || '') && port.allowsIncoming)) {
9178
9190
  this.unfinishedConnection = new DiagramConnection(this.model, this.connectionType, port, undefined, UNFINISHED_CONNECTION_ID);
9191
+ this.unfinishedConnectionPort = port;
9179
9192
  } else {
9180
9193
  if (this.inferConnectionType) {
9181
9194
  let differentConnectionType = this.model.connections.types.all().find(t => {
@@ -9190,6 +9203,7 @@ class DiagramCanvas {
9190
9203
  }
9191
9204
  if (differentConnectionType !== undefined) {
9192
9205
  this.unfinishedConnection = new DiagramConnection(this.model, differentConnectionType, port, undefined, UNFINISHED_CONNECTION_ID);
9206
+ this.unfinishedConnectionPort = port;
9193
9207
  }
9194
9208
  }
9195
9209
  }
@@ -9263,6 +9277,7 @@ class DiagramCanvas {
9263
9277
  (_b = this.unfinishedConnection) === null || _b === void 0 ? void 0 : _b.setEnd(undefined);
9264
9278
  (_d = (_c = this.unfinishedConnection) === null || _c === void 0 ? void 0 : _c.select()) === null || _d === void 0 ? void 0 : _d.remove();
9265
9279
  this.unfinishedConnection = undefined;
9280
+ this.unfinishedConnectionPort = undefined;
9266
9281
  }
9267
9282
  cancelAllUserActions() {
9268
9283
  this.currentAction = undefined;
@@ -9274,6 +9289,27 @@ class DiagramCanvas {
9274
9289
  canUserPerformAction(action) {
9275
9290
  return this.userActions[action] !== false;
9276
9291
  }
9292
+ openTextInput(id) {
9293
+ const field = this.model.fields.get(id);
9294
+ if (field) {
9295
+ this.createInputField(field.text, field.coords, field.width, field.height, field.fontSize, field.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, field.orientation, () => {
9296
+ // (_text)
9297
+ /*
9298
+ Empty for now
9299
+ We should create a better function to stretch the root element as the text expands
9300
+ Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
9301
+ */
9302
+ }, text => {
9303
+ field.text = text;
9304
+ if (this.currentAction instanceof EditFieldAction) {
9305
+ this.currentAction.to = text;
9306
+ this.currentAction.do();
9307
+ this.actionStack.add(this.currentAction);
9308
+ this.currentAction = undefined;
9309
+ }
9310
+ });
9311
+ }
9312
+ }
9277
9313
  createInputField(text, coords, width, height, fontSize, fontFamily, orientation, changeCallback, finishCallback) {
9278
9314
  // if we have a text input open, close it before creating a new one
9279
9315
  this.removeInputField();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metadev/daga",
3
- "version": "4.2.14",
3
+ "version": "4.2.16",
4
4
  "dependencies": {},
5
5
  "peerDependencies": {
6
6
  "d3": "^7.9.0",
@@ -20,7 +20,7 @@ export declare const isSecondaryButton: (event: MouseEvent) => boolean;
20
20
  * @private
21
21
  * @see linePath
22
22
  */
23
- export declare const getConnectionPath: (shape: LineShape | LineFunction, startCoords: Point, endCoords: Point, startDirection: Side | undefined, endDirection: Side | undefined, width: number, startMarkerWidth: number | undefined, endMarkerWidth: number | undefined) => string;
23
+ export declare const getConnectionPath: (shape: LineShape | LineFunction, startCoords: Point, endCoords: Point, startDirection: Side | undefined, endDirection: Side | undefined, points: Point[], width: number, startMarkerWidth: number | undefined, endMarkerWidth: number | undefined) => string;
24
24
  export declare const setCursorStyle: (style?: CursorStyle) => void;
25
25
  export declare const getRelatedNodeOrItself: (element: DiagramNode | DiagramSection | DiagramPort | DiagramField) => DiagramNode | DiagramSection | DiagramPort | DiagramField;
26
26
  export declare const needsResizerX: (element: DiagramNode | DiagramSection) => boolean;
@@ -53,6 +53,7 @@ export declare class DiagramCanvas implements Canvas {
53
53
  get connectionType(): DiagramConnectionType | undefined;
54
54
  set connectionType(value: DiagramConnectionType | undefined);
55
55
  autoTightenConnections: boolean;
56
+ tightenConnectionsAcrossPortTypes: boolean;
56
57
  allowConnectionLoops: boolean;
57
58
  allowSharingPorts: boolean;
58
59
  allowSharingBothPorts: boolean;
@@ -73,6 +74,7 @@ export declare class DiagramCanvas implements Canvas {
73
74
  * Invisible path followed by an unfinished connection. Used for making unfinished connections stop before the cursor rather than stopping right at the cursor.
74
75
  */
75
76
  private unfinishedConnectionTracer?;
77
+ private unfinishedConnectionPort?;
76
78
  private inputFieldContainer?;
77
79
  private multipleSelectionContainer?;
78
80
  private draggingFrom;
@@ -136,6 +138,7 @@ export declare class DiagramCanvas implements Canvas {
136
138
  private dropConnection;
137
139
  cancelAllUserActions(): void;
138
140
  canUserPerformAction(action: DiagramActions): boolean;
141
+ openTextInput(id: string): void;
139
142
  private createInputField;
140
143
  private removeInputField;
141
144
  private minimumSizeOfField;
@@ -52,6 +52,11 @@ export interface ButtonsComponentConfig {
52
52
  * @default 'top'
53
53
  */
54
54
  direction?: Side;
55
+ /**
56
+ * Duration of the center animation when pressing the center button. May be set to `0` or `undefined` to make it instant without animation.
57
+ * @default undefined
58
+ */
59
+ centerAnimationDuration?: number;
55
60
  /**
56
61
  * Whether to enable the user action (undo, redo) buttons in this component.
57
62
  * @default true
@@ -103,6 +103,11 @@ export interface ConnectionSettingsConfig {
103
103
  * @default true
104
104
  */
105
105
  autoTighten?: boolean;
106
+ /**
107
+ * When tightening a connection allow changing the start and end ports to ports of a different type.
108
+ * @default false
109
+ */
110
+ tightenAcrossPortTypes?: boolean;
106
111
  /**
107
112
  * Whether a connection can use the same port as start and end.
108
113
  * @default false
@@ -138,7 +138,7 @@ export declare class DiagramConnection extends DiagramElement {
138
138
  */
139
139
  endLabel: string;
140
140
  /**
141
- * Points that this connection passes through.
141
+ * Points that this connection must pass through in its route from its start point to its end point, in order.
142
142
  * @public
143
143
  */
144
144
  points: Point[];
@@ -173,7 +173,7 @@ export declare class DiagramPort extends DiagramElement implements LabeledElemen
173
173
  constructor(model: DiagramModel, type: DiagramPortType | undefined, rootElement: DiagramNode | DiagramSection | undefined, coords: Point, connectionPoint: Point | undefined, direction: Side, id: string, anchorPointX?: AnchorPoint, anchorPointY?: AnchorPoint);
174
174
  get removed(): boolean;
175
175
  updateInView(): void;
176
- raise(): void;
176
+ raise(raiseConnections?: boolean): void;
177
177
  /**
178
178
  * Add a connection to this port's list of outgoing connections.
179
179
  * @public
@@ -108,6 +108,11 @@ export interface Canvas {
108
108
  * @public
109
109
  */
110
110
  autoTightenConnections: boolean;
111
+ /**
112
+ * Whether a connection can be tightened to use ports of a different type.
113
+ * @public
114
+ */
115
+ tightenConnectionsAcrossPortTypes: boolean;
111
116
  /**
112
117
  * Whether a connection can use the same port as start and end.
113
118
  * @public
@@ -351,6 +356,11 @@ export interface Canvas {
351
356
  * @param shrink Whether the node should shrink if there is excess space; `true` by default
352
357
  */
353
358
  fitNodeInView(id: string, shrink?: boolean): void;
359
+ /**
360
+ * Open a text input for a field.
361
+ * @param id The id of a field.
362
+ */
363
+ openTextInput(id: string): void;
354
364
  /**
355
365
  * Get the d3 Selection containing the root html div element of the canvas.
356
366
  * @private