@metadev/daga 4.2.0 → 4.2.2

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/index.esm.js CHANGED
@@ -137,17 +137,67 @@ const translateCoordinate = (oldCoordinate, oldCoordinates, newCoordinates) => {
137
137
  return (oldCoordinate - oldCoordinates[0]) / (oldCoordinates[1] - oldCoordinates[0]) * (newCoordinates[1] - newCoordinates[0]) + newCoordinates[0];
138
138
  };
139
139
  /**
140
- * Moves the coordinates of the given point according to the given changes in coordinates.
140
+ * Moves the coordinates of the given point according to the given changes in coordinates and anchor points.
141
141
  * @public
142
142
  * @param oldPoint A point.
143
143
  * @param oldCoordsX A range of coordinates along the x axis.
144
144
  * @param oldCoordsY A range of coordinates along the y axis.
145
145
  * @param newCoordsX A range of coordinates along the x axis.
146
146
  * @param newCoordsY A range of coordinates along the y axis.
147
+ * @param anchorPointX The horizontal anchor point behavior.
148
+ * @param anchorPointY The vertical anchor point behavior.
147
149
  * @returns A new point.
148
150
  */
149
- const translatePoint = (oldPoint, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY) => {
150
- return [translateCoordinate(oldPoint[0], oldCoordsX, newCoordsX), translateCoordinate(oldPoint[1], oldCoordsY, newCoordsY)];
151
+ const translatePointWithAnchors = (oldPoint, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY, anchorPointX, anchorPointY) => {
152
+ const newX = (() => {
153
+ switch (anchorPointX) {
154
+ case 'start':
155
+ // Always maintain the same distance from the left edge
156
+ return newCoordsX[0] + (oldPoint[0] - oldCoordsX[0]);
157
+ case 'end':
158
+ // Always maintain the same distance from the right edge
159
+ return newCoordsX[1] - (oldCoordsX[1] - oldPoint[0]);
160
+ case 'middle':
161
+ {
162
+ // Always maintain the same relative position from the center
163
+ const oldCenterX = (oldCoordsX[0] + oldCoordsX[1]) / 2;
164
+ const newCenterX = (newCoordsX[0] + newCoordsX[1]) / 2;
165
+ const oldWidth = oldCoordsX[1] - oldCoordsX[0];
166
+ const newWidth = newCoordsX[1] - newCoordsX[0];
167
+ const relativePosition = (oldPoint[0] - oldCenterX) / oldWidth;
168
+ return newCenterX + relativePosition * newWidth;
169
+ }
170
+ case 'floating':
171
+ default:
172
+ // Scale proportionally (original behavior)
173
+ return translateCoordinate(oldPoint[0], oldCoordsX, newCoordsX);
174
+ }
175
+ })();
176
+ const newY = (() => {
177
+ switch (anchorPointY) {
178
+ case 'start':
179
+ // Always maintain the same distance from the top edge
180
+ return newCoordsY[0] + (oldPoint[1] - oldCoordsY[0]);
181
+ case 'end':
182
+ // Always maintain the same distance from the bottom edge
183
+ return newCoordsY[1] - (oldCoordsY[1] - oldPoint[1]);
184
+ case 'middle':
185
+ {
186
+ // Always maintain the same relative position from the center
187
+ const oldCenterY = (oldCoordsY[0] + oldCoordsY[1]) / 2;
188
+ const newCenterY = (newCoordsY[0] + newCoordsY[1]) / 2;
189
+ const oldHeight = oldCoordsY[1] - oldCoordsY[0];
190
+ const newHeight = newCoordsY[1] - newCoordsY[0];
191
+ const relativePosition = (oldPoint[1] - oldCenterY) / oldHeight;
192
+ return newCenterY + relativePosition * newHeight;
193
+ }
194
+ case 'floating':
195
+ default:
196
+ // Scale proportionally (original behavior)
197
+ return translateCoordinate(oldPoint[1], oldCoordsY, newCoordsY);
198
+ }
199
+ })();
200
+ return [newX, newY];
151
201
  };
152
202
  /**
153
203
  * Calculates the euclidean distance between two points.
@@ -244,6 +294,10 @@ var ZoomEvents;
244
294
  ZoomEvents["End"] = "end";
245
295
  })(ZoomEvents || (ZoomEvents = {}));
246
296
 
297
+ const escapeSelector = selector => {
298
+ return selector.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g, '\\$1');
299
+ };
300
+
247
301
  /**
248
302
  * An enumeration of the possible shapes of a line.
249
303
  * @public
@@ -1001,10 +1055,6 @@ class DiagramEntitySet {
1001
1055
  }
1002
1056
  }
1003
1057
 
1004
- const escapeSelector = selector => {
1005
- return selector.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g, '\\$1');
1006
- };
1007
-
1008
1058
  /**
1009
1059
  * Default priority value for diagram elements.
1010
1060
  * @private
@@ -1816,20 +1866,24 @@ class DiagramConnection extends DiagramElement {
1816
1866
  }
1817
1867
  set type(type) {
1818
1868
  var _a, _b;
1819
- (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userSelection) === null || _b === void 0 ? void 0 : _b.openInPropertyEditor(undefined);
1820
- this._type = type;
1821
- if (this.valueSet) {
1822
- this.valueSet = new ValueSet(type.propertySet, this);
1869
+ if (type !== this._type) {
1870
+ this._type = type;
1871
+ if (this.valueSet) {
1872
+ this.valueSet = new ValueSet(type.propertySet, this);
1873
+ }
1874
+ (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userSelection) === null || _b === void 0 ? void 0 : _b.openInPropertyEditor(this, false);
1875
+ this.updateInView();
1823
1876
  }
1824
- this.updateInView();
1825
1877
  }
1826
1878
  get typeString() {
1827
1879
  return this.type.id;
1828
1880
  }
1829
1881
  set typeString(typeString) {
1830
- const type = this.model.connections.types.get(typeString);
1831
- if (type) {
1832
- this.type = type;
1882
+ if (typeString !== this.type.id) {
1883
+ const type = this.model.connections.types.get(typeString);
1884
+ if (type) {
1885
+ this.type = type;
1886
+ }
1833
1887
  }
1834
1888
  }
1835
1889
  /**
@@ -2220,7 +2274,8 @@ const DIAGRAM_FIELD_DEFAULTS = {
2220
2274
  horizontalAlign: HorizontalAlign.Center,
2221
2275
  verticalAlign: VerticalAlign.Center,
2222
2276
  orientation: Side.Top,
2223
- fit: false
2277
+ fit: false,
2278
+ shrink: true
2224
2279
  };
2225
2280
  /**
2226
2281
  * A field which displays text and is part of a diagram element.
@@ -2245,10 +2300,10 @@ class DiagramField extends DiagramElement {
2245
2300
  this._text = value;
2246
2301
  this.updateInView();
2247
2302
  if (this.fit) {
2248
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
2303
+ (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id, this.shrink);
2249
2304
  }
2250
2305
  }
2251
- constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, orientation, text, editable, fit) {
2306
+ constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, orientation, text, editable, fit, shrink) {
2252
2307
  const id = `${rootElement === null || rootElement === void 0 ? void 0 : rootElement.id}_field`;
2253
2308
  if (model.fields.get(id) !== undefined) {
2254
2309
  throw new Error('DiagramField for rootElement already exists');
@@ -2269,11 +2324,31 @@ class DiagramField extends DiagramElement {
2269
2324
  this.selectedColor = selectedColor;
2270
2325
  this.horizontalAlign = horizontalAlign;
2271
2326
  this.verticalAlign = verticalAlign;
2272
- this.orientation = orientation;
2327
+ if (!isNaN(Number(orientation))) {
2328
+ this.orientation = Number(orientation);
2329
+ } else {
2330
+ switch (orientation) {
2331
+ case Side.Top:
2332
+ this.orientation = 0;
2333
+ break;
2334
+ case Side.Right:
2335
+ this.orientation = 90;
2336
+ break;
2337
+ case Side.Bottom:
2338
+ this.orientation = 180;
2339
+ break;
2340
+ case Side.Left:
2341
+ this.orientation = 270;
2342
+ break;
2343
+ default:
2344
+ this.orientation = 0;
2345
+ }
2346
+ }
2273
2347
  this.defaultText = text;
2274
2348
  this._text = text;
2275
2349
  this.editable = editable;
2276
2350
  this.fit = fit;
2351
+ this.shrink = shrink;
2277
2352
  }
2278
2353
  get removed() {
2279
2354
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
@@ -2313,8 +2388,8 @@ class DiagramFieldSet extends DiagramElementSet {
2313
2388
  * Instance a new field and add it to this set. This method is normally called when instancing an element with a field and it is rarely called by itself.
2314
2389
  * @private
2315
2390
  */
2316
- new(rootElement, coords, fontSize, fontFamily, color, selectedColor, width, height, horizontalAlign, verticalAlign, orientation, text, editable, fit) {
2317
- const field = new DiagramField(this.model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, orientation, text, editable, fit);
2391
+ new(rootElement, coords, fontSize, fontFamily, color, selectedColor, width, height, horizontalAlign, verticalAlign, orientation, text, editable, fit, shrink) {
2392
+ const field = new DiagramField(this.model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, orientation, text, editable, fit, shrink);
2318
2393
  super.add(field);
2319
2394
  field.updateInView();
2320
2395
  // add this field to its root element
@@ -2545,6 +2620,8 @@ class DiagramSectionType {
2545
2620
  this.label = options.label || null;
2546
2621
  this.ports = options.ports || [];
2547
2622
  this.priority = options.priority || DEFAULT_PRIORITY;
2623
+ this.resizableX = options.resizableX;
2624
+ this.resizableY = options.resizableY;
2548
2625
  const looks = extractLooksFromConfig(options.look || DIAGRAM_NODE_LOOK_DEFAULTS);
2549
2626
  this.defaultLook = looks.defaultLook;
2550
2627
  this.selectedLook = looks.selectedLook;
@@ -2673,6 +2750,34 @@ class DiagramSection extends DiagramElement {
2673
2750
  var _a, _b, _c, _d, _e, _f;
2674
2751
  return ((_f = (_e = (_d = (_c = (_b = (_a = this.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[this.indexYInNode]) === null || _e === void 0 ? void 0 : _e[this.indexXInNode]) === null || _f === void 0 ? void 0 : _f.priority) || DEFAULT_PRIORITY;
2675
2752
  }
2753
+ /**
2754
+ * Returns whether this section can be resized horizontally.
2755
+ * If the section has a specific resizableX setting, it uses that.
2756
+ * Otherwise, it inherits from the parent node's resizableX setting.
2757
+ * @public
2758
+ */
2759
+ getResizableX() {
2760
+ var _a, _b;
2761
+ const sectionType = this.type;
2762
+ if ((sectionType === null || sectionType === void 0 ? void 0 : sectionType.resizableX) !== undefined) {
2763
+ return sectionType.resizableX;
2764
+ }
2765
+ return ((_b = (_a = this.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) || false;
2766
+ }
2767
+ /**
2768
+ * Returns whether this section can be resized vertically.
2769
+ * If the section has a specific resizableY setting, it uses that.
2770
+ * Otherwise, it inherits from the parent node's resizableY setting.
2771
+ * @public
2772
+ */
2773
+ getResizableY() {
2774
+ var _a, _b;
2775
+ const sectionType = this.type;
2776
+ if ((sectionType === null || sectionType === void 0 ? void 0 : sectionType.resizableY) !== undefined) {
2777
+ return sectionType.resizableY;
2778
+ }
2779
+ return ((_b = (_a = this.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) || false;
2780
+ }
2676
2781
  /**
2677
2782
  * Get the port of this section which is closest to the given coordinates.
2678
2783
  * @param coords A point in the diagram.
@@ -2831,7 +2936,7 @@ class DiagramSection extends DiagramElement {
2831
2936
  const newCoordsY = [this.coords[1], this.coords[1] + this.height];
2832
2937
  // Move ports to match the new coords.
2833
2938
  for (const port of this.ports) {
2834
- port.move(translatePoint(port.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY));
2939
+ port.move(translatePointWithAnchors(port.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY, port.anchorPointX, port.anchorPointY));
2835
2940
  }
2836
2941
  // Set label's dimensions as a function of ours.
2837
2942
  const type = this.type;
@@ -2843,7 +2948,7 @@ class DiagramSection extends DiagramElement {
2843
2948
  }
2844
2949
  // Move decorators to match the new coords.
2845
2950
  for (const decorator of this.decorators) {
2846
- decorator.move(translatePoint(decorator.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY));
2951
+ decorator.move(translatePointWithAnchors(decorator.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY, decorator.anchorPointX, decorator.anchorPointY));
2847
2952
  }
2848
2953
  // Update canvas.
2849
2954
  this.getConnections().forEach(c => c.tighten());
@@ -2876,7 +2981,7 @@ class DiagramSectionSet extends DiagramElementSet {
2876
2981
  if (sectionPorts && sectionPorts.length > 0) {
2877
2982
  for (let i = 0; i < sectionPorts.length; ++i) {
2878
2983
  const portConfig = sectionPorts[i];
2879
- const port = this.model.ports.new(portConfig.type !== undefined ? this.model.ports.types.get(portConfig.type) : undefined, section, [section.coords[0] + (portConfig.coords[0] || 0), section.coords[1] + (portConfig.coords[1] || 0)], portConfig.connectionPoint !== undefined ? [section.coords[0] + (portConfig.connectionPoint[0] || 0), section.coords[1] + (portConfig.connectionPoint[1] || 0)] : undefined, portConfig === null || portConfig === void 0 ? void 0 : portConfig.direction, `${section.id}_${i}`);
2984
+ const port = this.model.ports.new(portConfig.type !== undefined ? this.model.ports.types.get(portConfig.type) : undefined, section, [section.coords[0] + (portConfig.coords[0] || 0), section.coords[1] + (portConfig.coords[1] || 0)], portConfig.connectionPoint !== undefined ? [section.coords[0] + (portConfig.connectionPoint[0] || 0), section.coords[1] + (portConfig.connectionPoint[1] || 0)] : undefined, portConfig === null || portConfig === void 0 ? void 0 : portConfig.direction, `${section.id}_${i}`, portConfig.anchorPointX || 'floating', portConfig.anchorPointY || 'floating');
2880
2985
  if ((_e = port.type) === null || _e === void 0 ? void 0 : _e.label) {
2881
2986
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_f = port.type) === null || _f === void 0 ? void 0 : _f.label);
2882
2987
  const labelWidth = 6 * labelConfiguration.fontSize + getLeftPadding$1(labelConfiguration) + getRightPadding$1(labelConfiguration);
@@ -2894,7 +2999,7 @@ class DiagramSectionSet extends DiagramElementSet {
2894
2999
  default:
2895
3000
  labelCoords = port.coords;
2896
3001
  }
2897
- this.model.fields.new(port, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelWidth, labelHeight, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
3002
+ this.model.fields.new(port, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelWidth, labelHeight, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
2898
3003
  }
2899
3004
  }
2900
3005
  }
@@ -2902,7 +3007,7 @@ class DiagramSectionSet extends DiagramElementSet {
2902
3007
  const sectionLabel = (_k = (_j = (_h = (_g = node.type.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[indexYInNode]) === null || _j === void 0 ? void 0 : _j[indexXInNode]) === null || _k === void 0 ? void 0 : _k.label;
2903
3008
  if (sectionLabel) {
2904
3009
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), sectionLabel);
2905
- this.model.fields.new(section, [section.coords[0] + getLeftMargin(labelConfiguration), section.coords[1] + getTopMargin(labelConfiguration)], labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, section.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), section.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
3010
+ this.model.fields.new(section, [section.coords[0] + getLeftMargin(labelConfiguration), section.coords[1] + getTopMargin(labelConfiguration)], labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, section.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), section.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
2906
3011
  }
2907
3012
  return section;
2908
3013
  }
@@ -3022,20 +3127,24 @@ class DiagramNode extends DiagramElement {
3022
3127
  }
3023
3128
  set type(type) {
3024
3129
  var _a, _b;
3025
- (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userSelection) === null || _b === void 0 ? void 0 : _b.openInPropertyEditor(undefined);
3026
- this._type = type;
3027
- if (this.valueSet) {
3028
- this.valueSet = new ValueSet(type.propertySet, this);
3130
+ if (type !== this._type) {
3131
+ this._type = type;
3132
+ if (this.valueSet) {
3133
+ this.valueSet = new ValueSet(type.propertySet, this);
3134
+ }
3135
+ (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userSelection) === null || _b === void 0 ? void 0 : _b.openInPropertyEditor(this, false);
3136
+ this.updateInView();
3029
3137
  }
3030
- this.updateInView();
3031
3138
  }
3032
3139
  get typeString() {
3033
3140
  return this.type.id;
3034
3141
  }
3035
3142
  set typeString(typeString) {
3036
- const type = this.model.nodes.types.get(typeString);
3037
- if (type) {
3038
- this.type = type;
3143
+ if (typeString !== this.type.id) {
3144
+ const type = this.model.nodes.types.get(typeString);
3145
+ if (type) {
3146
+ this.type = type;
3147
+ }
3039
3148
  }
3040
3149
  }
3041
3150
  /**
@@ -3335,21 +3444,42 @@ class DiagramNode extends DiagramElement {
3335
3444
  child.parent = undefined;
3336
3445
  }
3337
3446
  fitToChild(child) {
3447
+ // if the node includes sections, we stretch the sections as well when fitting to a child node
3448
+ // we assume it is most natural to stretch the last row and column of section
3449
+ // TODO: consider being able to configure which row or column gets stretched first
3450
+ const maxSectionIndexX = Math.max(...this.sections.map(s => s.indexXInNode));
3451
+ const maxSectionIndexY = Math.max(...this.sections.map(s => s.indexYInNode));
3338
3452
  const excessLeft = this.coords[0] - child.coords[0] + this.type.leftPadding;
3339
3453
  if (excessLeft >= 0) {
3340
- this.stretch(Side.Left, excessLeft);
3454
+ if (this.sections.length > 0) {
3455
+ this.stretchSections(Side.Left, excessLeft, maxSectionIndexX, maxSectionIndexY);
3456
+ } else {
3457
+ this.stretch(Side.Left, excessLeft);
3458
+ }
3341
3459
  }
3342
3460
  const excessTop = this.coords[1] - child.coords[1] + this.type.topPadding;
3343
3461
  if (excessTop >= 0) {
3344
- this.stretch(Side.Top, excessTop);
3462
+ if (this.sections.length > 0) {
3463
+ this.stretchSections(Side.Top, excessTop, maxSectionIndexX, maxSectionIndexY);
3464
+ } else {
3465
+ this.stretch(Side.Top, excessTop);
3466
+ }
3345
3467
  }
3346
3468
  const excessRight = child.coords[0] + child.width - (this.coords[0] + this.width) + this.type.rightPadding;
3347
3469
  if (excessRight >= 0) {
3348
- this.stretch(Side.Right, excessRight);
3470
+ if (this.sections.length > 0) {
3471
+ this.stretchSections(Side.Right, excessRight, maxSectionIndexX, maxSectionIndexY);
3472
+ } else {
3473
+ this.stretch(Side.Right, excessRight);
3474
+ }
3349
3475
  }
3350
3476
  const excessBottom = child.coords[1] + child.height - (this.coords[1] + this.height) + this.type.bottomPadding;
3351
3477
  if (excessBottom >= 0) {
3352
- this.stretch(Side.Bottom, excessBottom);
3478
+ if (this.sections.length > 0) {
3479
+ this.stretchSections(Side.Bottom, excessBottom, maxSectionIndexX, maxSectionIndexY);
3480
+ } else {
3481
+ this.stretch(Side.Bottom, excessBottom);
3482
+ }
3353
3483
  }
3354
3484
  if (this.parent) {
3355
3485
  // ensure this node also fits inside its parent after stretching
@@ -3564,7 +3694,7 @@ class DiagramNode extends DiagramElement {
3564
3694
  }
3565
3695
  // Move ports to match the new coords.
3566
3696
  for (const port of this.ports) {
3567
- port.move(translatePoint(port.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY));
3697
+ port.move(translatePointWithAnchors(port.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY, port.anchorPointX, port.anchorPointY));
3568
3698
  }
3569
3699
  // Set label's dimensions as a function of ours.
3570
3700
  if (this.label) {
@@ -3575,7 +3705,7 @@ class DiagramNode extends DiagramElement {
3575
3705
  }
3576
3706
  // Move decorators to match the new coords.
3577
3707
  for (const decorator of this.decorators) {
3578
- decorator.move(translatePoint(decorator.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY));
3708
+ decorator.move(translatePointWithAnchors(decorator.coords, oldCoordsX, oldCoordsY, newCoordsX, newCoordsY, decorator.anchorPointX, decorator.anchorPointY));
3579
3709
  }
3580
3710
  // Update canvas.
3581
3711
  this.getConnections().forEach(c => c.tighten());
@@ -3737,7 +3867,7 @@ class DiagramNodeSet extends DiagramElementSet {
3737
3867
  for (let i = 0; i < nodeType.ports.length; ++i) {
3738
3868
  const portConfig = nodeType.ports[i];
3739
3869
  const portType = portConfig.type !== undefined ? this.model.ports.types.get(portConfig.type) : undefined;
3740
- const port = this.model.ports.new(portType, node, [node.coords[0] + portConfig.coords[0], node.coords[1] + portConfig.coords[1]], portConfig.connectionPoint !== undefined ? [node.coords[0] + (portConfig.connectionPoint[0] || 0), node.coords[1] + (portConfig.connectionPoint[1] || 0)] : undefined, portConfig.direction, `${node.id}_port_${i}`);
3870
+ const port = this.model.ports.new(portType, node, [node.coords[0] + portConfig.coords[0], node.coords[1] + portConfig.coords[1]], portConfig.connectionPoint !== undefined ? [node.coords[0] + (portConfig.connectionPoint[0] || 0), node.coords[1] + (portConfig.connectionPoint[1] || 0)] : undefined, portConfig.direction, `${node.id}_port_${i}`, portConfig.anchorPointX || 'floating', portConfig.anchorPointY || 'floating');
3741
3871
  if ((_e = port.type) === null || _e === void 0 ? void 0 : _e.label) {
3742
3872
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_f = port.type) === null || _f === void 0 ? void 0 : _f.label);
3743
3873
  const labelWidth = 6 * labelConfiguration.fontSize + getLeftPadding$1(labelConfiguration) + getRightPadding$1(labelConfiguration);
@@ -3755,20 +3885,20 @@ class DiagramNodeSet extends DiagramElementSet {
3755
3885
  default:
3756
3886
  labelCoords = port.coords;
3757
3887
  }
3758
- this.model.fields.new(port, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelWidth, labelHeight, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
3888
+ this.model.fields.new(port, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelWidth, labelHeight, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
3759
3889
  }
3760
3890
  }
3761
3891
  }
3762
3892
  // add node label
3763
3893
  if (nodeType.label) {
3764
3894
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), nodeType.label);
3765
- this.model.fields.new(node, [node.coords[0] + getLeftMargin(labelConfiguration), node.coords[1] + getTopMargin(labelConfiguration)], labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, node.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), node.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
3895
+ this.model.fields.new(node, [node.coords[0] + getLeftMargin(labelConfiguration), node.coords[1] + getTopMargin(labelConfiguration)], labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, node.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), node.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
3766
3896
  }
3767
3897
  // add node decorators
3768
3898
  if (nodeType.decorators.length > 0) {
3769
3899
  for (let i = 0; i < nodeType.decorators.length; ++i) {
3770
3900
  const decoratorConfig = nodeType.decorators[i];
3771
- this.model.decorators.new(node, [node.coords[0] + decoratorConfig.coords[0], node.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, node.getPriority(), decoratorConfig.html, `${node.id}_decorator_${i}`);
3901
+ this.model.decorators.new(node, [node.coords[0] + decoratorConfig.coords[0], node.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, node.getPriority(), decoratorConfig.html, `${node.id}_decorator_${i}`, decoratorConfig.anchorPointX || 'floating', decoratorConfig.anchorPointY || 'floating');
3772
3902
  }
3773
3903
  }
3774
3904
  node.valueSet.resetValues();
@@ -4005,20 +4135,25 @@ class DiagramPort extends DiagramElement {
4005
4135
  return this._type;
4006
4136
  }
4007
4137
  set type(type) {
4008
- this._type = type;
4009
- this.updateInView();
4138
+ if (type !== this._type) {
4139
+ this._type = type;
4140
+ this.updateInView();
4141
+ }
4010
4142
  }
4011
4143
  get typeString() {
4012
4144
  var _a;
4013
4145
  return (_a = this.type) === null || _a === void 0 ? void 0 : _a.id;
4014
4146
  }
4015
4147
  set typeString(typeString) {
4016
- if (typeString === undefined) {
4017
- this.type = undefined;
4018
- } else {
4019
- const type = this.model.ports.types.get(typeString);
4020
- if (type) {
4021
- this.type = type;
4148
+ var _a;
4149
+ if (typeString !== ((_a = this.type) === null || _a === void 0 ? void 0 : _a.id)) {
4150
+ if (typeString === undefined) {
4151
+ this.type = undefined;
4152
+ } else {
4153
+ const type = this.model.ports.types.get(typeString);
4154
+ if (type) {
4155
+ this.type = type;
4156
+ }
4022
4157
  }
4023
4158
  }
4024
4159
  }
@@ -4103,7 +4238,7 @@ class DiagramPort extends DiagramElement {
4103
4238
  get height() {
4104
4239
  return this.width;
4105
4240
  }
4106
- constructor(model, type, rootElement, coords, connectionPoint, direction, id) {
4241
+ constructor(model, type, rootElement, coords, connectionPoint, direction, id, anchorPointX = 'floating', anchorPointY = 'floating') {
4107
4242
  if (model.ports.get(id) !== undefined) {
4108
4243
  throw new Error(`DiagramPort with id "${id}" already exists`);
4109
4244
  }
@@ -4126,6 +4261,8 @@ class DiagramPort extends DiagramElement {
4126
4261
  this.coords = coords;
4127
4262
  this.connectionPoint = connectionPoint || coords;
4128
4263
  this.direction = direction;
4264
+ this.anchorPointX = anchorPointX;
4265
+ this.anchorPointY = anchorPointY;
4129
4266
  }
4130
4267
  get removed() {
4131
4268
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
@@ -4223,8 +4360,8 @@ class DiagramPortSet extends DiagramElementSet {
4223
4360
  * Instance a new port and add it to this set. This method is normally called when instancing an element with a port and it is rarely called by itself.
4224
4361
  * @private
4225
4362
  */
4226
- new(type, rootElement, coords, connectionPoint, direction, id) {
4227
- const port = new DiagramPort(this.model, type, rootElement, coords, connectionPoint, direction, id);
4363
+ new(type, rootElement, coords, connectionPoint, direction, id, anchorPointX = 'floating', anchorPointY = 'floating') {
4364
+ const port = new DiagramPort(this.model, type, rootElement, coords, connectionPoint, direction, id, anchorPointX, anchorPointY);
4228
4365
  super.add(port);
4229
4366
  port.updateInView();
4230
4367
  // add this port to its root element
@@ -4309,7 +4446,7 @@ class DagaImporter {
4309
4446
  // add node label
4310
4447
  if (newNodeType.label) {
4311
4448
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
4312
- 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);
4449
+ 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);
4313
4450
  newField.text = node.label;
4314
4451
  newNode.label = newField;
4315
4452
  model.fields.add(newField);
@@ -4331,7 +4468,7 @@ class DagaImporter {
4331
4468
  // add section label
4332
4469
  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) {
4333
4470
  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);
4334
- 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);
4471
+ 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);
4335
4472
  newField.text = section.label;
4336
4473
  newSection.label = newField;
4337
4474
  model.fields.add(newField);
@@ -4363,7 +4500,7 @@ class DagaImporter {
4363
4500
  default:
4364
4501
  labelCoords = newPort.coords;
4365
4502
  }
4366
- const newField = new DiagramField(model, newPort, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
4503
+ const newField = new DiagramField(model, newPort, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4367
4504
  newField.text = port.label;
4368
4505
  newPort.label = newField;
4369
4506
  model.fields.add(newField);
@@ -4410,7 +4547,7 @@ class DagaImporter {
4410
4547
  default:
4411
4548
  labelCoords = newPort.coords;
4412
4549
  }
4413
- const newField = new DiagramField(model, newPort, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit);
4550
+ const newField = new DiagramField(model, newPort, labelCoords, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
4414
4551
  newField.text = port.label;
4415
4552
  newPort.label = newField;
4416
4553
  model.fields.add(newField);
@@ -4654,11 +4791,11 @@ class SetGeometryCollabAction {
4654
4791
  node.setGeometry(this.to);
4655
4792
  // Re-fit the labels, in case their text has changed since `this.to` was measured.
4656
4793
  if ((_a = node.label) === null || _a === void 0 ? void 0 : _a.fit) {
4657
- this.canvas.fitFieldRootInView(node.label.id);
4794
+ this.canvas.fitFieldRootInView(node.label.id, node.label.shrink);
4658
4795
  }
4659
4796
  for (const section of node.sections) {
4660
4797
  if ((_b = section.label) === null || _b === void 0 ? void 0 : _b.fit) {
4661
- this.canvas.fitFieldRootInView(section.label.id);
4798
+ this.canvas.fitFieldRootInView(section.label.id, section.label.shrink);
4662
4799
  }
4663
4800
  }
4664
4801
  (_c = node.parent) === null || _c === void 0 ? void 0 : _c.fitToChild(node);
@@ -5779,7 +5916,7 @@ class DiagramHighlightedEvent extends DiagramEvent {
5779
5916
  * @see DiagramSection
5780
5917
  */
5781
5918
  class DiagramDecorator extends DiagramElement {
5782
- constructor(model, rootElement, coords, width, height, priority, html, id) {
5919
+ constructor(model, rootElement, coords, width, height, priority, html, id, anchorPointX = 'floating', anchorPointY = 'floating') {
5783
5920
  if (model.objects.get(id) !== undefined) {
5784
5921
  throw new Error(`DiagramDecorator with id "${id}" already exists`);
5785
5922
  }
@@ -5793,6 +5930,8 @@ class DiagramDecorator extends DiagramElement {
5793
5930
  this.height = height;
5794
5931
  this.priority = priority;
5795
5932
  this.html = html;
5933
+ this.anchorPointX = anchorPointX;
5934
+ this.anchorPointY = anchorPointY;
5796
5935
  }
5797
5936
  get removed() {
5798
5937
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
@@ -5838,8 +5977,8 @@ class DiagramDecoratorSet extends DiagramElementSet {
5838
5977
  * @param id The id of the decorator. Cannot be an empty string.
5839
5978
  * @returns The instanced decorator.
5840
5979
  */
5841
- new(rootElement, coords, width, height, priority, html, id) {
5842
- const decorator = new DiagramDecorator(this.model, rootElement, coords, width, height, priority, html, id);
5980
+ new(rootElement, coords, width, height, priority, html, id, anchorPointX = 'floating', anchorPointY = 'floating') {
5981
+ const decorator = new DiagramDecorator(this.model, rootElement, coords, width, height, priority, html, id, anchorPointX, anchorPointY);
5843
5982
  super.add(decorator);
5844
5983
  decorator.updateInView();
5845
5984
  // add this port to its root element
@@ -6672,11 +6811,15 @@ class DiagramUserSelection extends DiagramElementSet {
6672
6811
  * Opens the value set of a diagram model or a diagram element in the property editor.
6673
6812
  * @public
6674
6813
  * @param selection A diagram model or a diagram element with a value set.
6814
+ * @param makeUpdateValuesAction Whether the method should create an UpdateValuesAction.
6675
6815
  * @see PropertyEditor
6816
+ * @see UpdateValuesAction
6676
6817
  */
6677
- openInPropertyEditor(selection) {
6818
+ openInPropertyEditor(selection, makeUpdateValuesAction = true) {
6678
6819
  var _a;
6679
- this.makeUpdateValuesAction();
6820
+ if (makeUpdateValuesAction) {
6821
+ this.makeUpdateValuesAction();
6822
+ }
6680
6823
  const propertyEditor = (_a = this.canvas.parentComponent) === null || _a === void 0 ? void 0 : _a.propertyEditor;
6681
6824
  if (propertyEditor === undefined) {
6682
6825
  return;
@@ -6684,7 +6827,9 @@ class DiagramUserSelection extends DiagramElementSet {
6684
6827
  const selectedValueSet = selection === null || selection === void 0 ? void 0 : selection.valueSet;
6685
6828
  if (selectedValueSet) {
6686
6829
  this.propertyEditorSelection = selection;
6687
- this.propertyEditorValues = structuredClone(selectedValueSet.getValues());
6830
+ if (makeUpdateValuesAction) {
6831
+ this.propertyEditorValues = structuredClone(selectedValueSet.getValues());
6832
+ }
6688
6833
  if (propertyEditor) {
6689
6834
  if (selection instanceof DiagramNode || selection instanceof DiagramConnection) {
6690
6835
  if (selection instanceof DiagramNode) {
@@ -6736,6 +6881,26 @@ class DiagramUserSelection extends DiagramElementSet {
6736
6881
  }
6737
6882
  }
6738
6883
 
6884
+ const degreesToRadians = theta => theta * Math.PI / 180;
6885
+ /**
6886
+ * Calculates the original size of the a rectangle that has been rotated by the given number of degrees resulting in a bounding box of the given size.
6887
+ *
6888
+ * @param width The width of a bounding box.
6889
+ * @param height The height of a bounding box.
6890
+ * @param orientation A rotation in degrees.
6891
+ * @returns The size of the original rectangle.
6892
+ */
6893
+ const unrotate = (width, height, orientation) => {
6894
+ // TODO: this method fails under certain edge cases
6895
+ // like for example, when angle is 45 degrees so sin(theta) == cos(theta)
6896
+ const theta = degreesToRadians(orientation);
6897
+ const orientationSine = Math.sin(theta);
6898
+ const orientationCosine = Math.cos(theta);
6899
+ const oldWidth = (Math.abs(width * orientationCosine) - Math.abs(height * orientationSine)) / (orientationCosine * orientationCosine - orientationSine * orientationSine);
6900
+ const oldHeight = (Math.abs(width * orientationSine) - Math.abs(height * orientationCosine)) / (orientationSine * orientationSine - orientationCosine * orientationCosine);
6901
+ return [oldWidth, oldHeight];
6902
+ };
6903
+
6739
6904
  /**
6740
6905
  * Thickness of the invisible path around a connection used to make it easier to click on, in diagram units.
6741
6906
  * @private
@@ -7004,6 +7169,35 @@ class DiagramCanvas {
7004
7169
  }
7005
7170
  });
7006
7171
  const canvasView = this.selectSVGElement().append('g').attr('class', 'daga-canvas-view').attr('width', `100%`).attr('height', `100%`);
7172
+ canvasView.call(this.zoomBehavior = d3.zoom().filter(event => {
7173
+ // Disable double-click zoom by filtering out dblclick events
7174
+ return event.type !== Events.DoubleClick;
7175
+ }).on(ZoomEvents.Zoom, event => {
7176
+ if (event.sourceEvent) {
7177
+ // zoom event was triggered by user
7178
+ if (!this.canUserPerformAction(DiagramActions.Zoom)) {
7179
+ setCursorStyle(CursorStyle.NotAllowed);
7180
+ return;
7181
+ }
7182
+ if (event.sourceEvent.type === Events.Wheel && event.sourceEvent.wheelDelta !== undefined) {
7183
+ if (event.sourceEvent.wheelDelta > 0) {
7184
+ setCursorStyle(CursorStyle.ZoomIn);
7185
+ }
7186
+ if (event.sourceEvent.wheelDelta < 0) {
7187
+ setCursorStyle(CursorStyle.ZoomOut);
7188
+ }
7189
+ } else if (event.sourceEvent.type === Events.MouseMove) {
7190
+ setCursorStyle(CursorStyle.AllScroll);
7191
+ }
7192
+ }
7193
+ this.zoomTransform = event.transform;
7194
+ const transformAttribute = event.transform.toString();
7195
+ this.selectCanvasElements().attr('transform', transformAttribute);
7196
+ d3.select(`#${this.backgroundPatternId}`).attr('patternTransform', transformAttribute);
7197
+ this.contextMenu.close();
7198
+ }).on(ZoomEvents.End, () => {
7199
+ setCursorStyle();
7200
+ }));
7007
7201
  canvasView.append('rect').attr('x', 0).attr('y', 0).attr('width', `100%`).attr('height', `100%`).attr('fill', this.backgroundColor).attr('stroke-width', '0').on(Events.MouseMove, event => {
7008
7202
  if (this.unfinishedConnection !== undefined) {
7009
7203
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
@@ -7034,53 +7228,28 @@ class DiagramCanvas {
7034
7228
  this.continueMultipleSelection(event);
7035
7229
  }).on(DragEvents.End, event => {
7036
7230
  this.finishMultipleSelection(event);
7037
- })).call(this.zoomBehavior = d3.zoom().on(ZoomEvents.Zoom, event => {
7038
- if (event.sourceEvent) {
7039
- // zoom event was triggered by user
7040
- if (!this.canUserPerformAction(DiagramActions.Zoom)) {
7041
- setCursorStyle(CursorStyle.NotAllowed);
7042
- return;
7043
- }
7044
- if (event.sourceEvent.type === Events.Wheel && event.sourceEvent.wheelDelta !== undefined) {
7045
- if (event.sourceEvent.wheelDelta > 0) {
7046
- setCursorStyle(CursorStyle.ZoomIn);
7047
- }
7048
- if (event.sourceEvent.wheelDelta < 0) {
7049
- setCursorStyle(CursorStyle.ZoomOut);
7050
- }
7051
- } else if (event.sourceEvent.type === Events.MouseMove) {
7052
- setCursorStyle(CursorStyle.AllScroll);
7053
- }
7054
- }
7055
- this.zoomTransform = event.transform;
7056
- const transformAttribute = event.transform.toString();
7057
- this.selectCanvasElements().attr('transform', transformAttribute);
7058
- d3.select(`#${this.backgroundPatternId}`).attr('patternTransform', transformAttribute);
7059
- this.contextMenu.close();
7060
- }).on(ZoomEvents.End, () => {
7061
- setCursorStyle();
7062
7231
  }));
7063
7232
  initializeGrid(this, canvasView, this.backgroundPatternId);
7064
7233
  canvasView.append('g').attr('class', 'daga-canvas-elements');
7065
7234
  }
7066
7235
  zoomBy(factor) {
7067
7236
  if (!isNaN(factor)) {
7068
- this.zoomBehavior.scaleBy(this.selectCanvasView().select('rect'), factor);
7237
+ this.zoomBehavior.scaleBy(this.selectCanvasView(), factor);
7069
7238
  }
7070
7239
  }
7071
7240
  zoomTo(level) {
7072
7241
  if (!isNaN(level)) {
7073
- this.zoomBehavior.scaleTo(this.selectCanvasView().select('rect'), level);
7242
+ this.zoomBehavior.scaleTo(this.selectCanvasView(), level);
7074
7243
  }
7075
7244
  }
7076
7245
  translateBy(x, y) {
7077
7246
  if (!isNaN(x) && !isNaN(y)) {
7078
- this.zoomBehavior.translateBy(this.selectCanvasView().select('rect'), x, y);
7247
+ this.zoomBehavior.translateBy(this.selectCanvasView(), x, y);
7079
7248
  }
7080
7249
  }
7081
7250
  translateTo(x, y) {
7082
7251
  if (!isNaN(x) && !isNaN(y)) {
7083
- this.zoomBehavior.translateTo(this.selectCanvasView().select('rect'), x, y);
7252
+ this.zoomBehavior.translateTo(this.selectCanvasView(), x, y);
7084
7253
  }
7085
7254
  }
7086
7255
  center() {
@@ -7374,8 +7543,8 @@ class DiagramCanvas {
7374
7543
  let updateSelection = this.selectCanvasElements().selectAll('g.diagram-section').data(this.model.sections.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
7375
7544
  const exitSelection = updateSelection.exit();
7376
7545
  const enterSelection = updateSelection.enter().append('g').attr('id', d => d.id).attr('class', d => {
7377
- var _a, _b, _c, _d, _e;
7378
- return `diagram-section${((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) ? ' resizable-x' : ''}${((_d = (_c = d.node) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.resizableY) ? ' resizable-y' : ''} ${(_e = d.look) === null || _e === void 0 ? void 0 : _e.lookType}`;
7546
+ var _a;
7547
+ return `diagram-section${d.getResizableX() ? ' resizable-x' : ''}${d.getResizableY() ? ' resizable-y' : ''} ${(_a = d.look) === null || _a === void 0 ? void 0 : _a.lookType}`;
7379
7548
  });
7380
7549
  if (ids && ids.length > 0) {
7381
7550
  updateSelection = updateSelection.filter(d => ids.includes(d.id));
@@ -7457,32 +7626,27 @@ class DiagramCanvas {
7457
7626
  }));
7458
7627
  initializeLook(enterSelection);
7459
7628
  enterSelection.filter('.resizable-x').append('line').attr('class', 'left-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
7460
- var _a, _b;
7461
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7629
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed) {
7462
7630
  setCursorStyle(CursorStyle.EWResize);
7463
7631
  }
7464
7632
  }).on(Events.MouseOut, (_event, d) => {
7465
- var _a, _b;
7466
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7633
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed) {
7467
7634
  setCursorStyle();
7468
7635
  }
7469
7636
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
7470
- var _a, _b;
7471
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7637
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && d.node) {
7472
7638
  setCursorStyle(CursorStyle.EWResize);
7473
7639
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
7474
7640
  } else {
7475
7641
  setCursorStyle(CursorStyle.NotAllowed);
7476
7642
  }
7477
7643
  }).on(DragEvents.Drag, (event, d) => {
7478
- var _a, _b;
7479
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7644
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && d.node) {
7480
7645
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7481
7646
  d.node.stretchSections(Side.Left, d.coords[0] - pointerCoords[0], d.indexXInNode, d.indexYInNode);
7482
7647
  }
7483
7648
  }).on(DragEvents.End, (event, d) => {
7484
- var _a, _b;
7485
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
7649
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection && d.node) {
7486
7650
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7487
7651
  if (this.snapToGrid) {
7488
7652
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -7496,32 +7660,27 @@ class DiagramCanvas {
7496
7660
  setCursorStyle();
7497
7661
  }));
7498
7662
  enterSelection.filter('.resizable-y').append('line').attr('class', 'top-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
7499
- var _a, _b;
7500
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7663
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed) {
7501
7664
  setCursorStyle(CursorStyle.NSResize);
7502
7665
  }
7503
7666
  }).on(Events.MouseOut, (_event, d) => {
7504
- var _a, _b;
7505
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7667
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed) {
7506
7668
  setCursorStyle();
7507
7669
  }
7508
7670
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
7509
- var _a, _b;
7510
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7671
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && d.node) {
7511
7672
  setCursorStyle(CursorStyle.NSResize);
7512
7673
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
7513
7674
  } else {
7514
7675
  setCursorStyle(CursorStyle.NotAllowed);
7515
7676
  }
7516
7677
  }).on(DragEvents.Drag, (event, d) => {
7517
- var _a, _b;
7518
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7678
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && d.node) {
7519
7679
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7520
7680
  d.node.stretchSections(Side.Top, d.coords[1] - pointerCoords[1], d.indexXInNode, d.indexYInNode);
7521
7681
  }
7522
7682
  }).on(DragEvents.End, (event, d) => {
7523
- var _a, _b;
7524
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
7683
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection && d.node) {
7525
7684
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7526
7685
  if (this.snapToGrid) {
7527
7686
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -7535,32 +7694,27 @@ class DiagramCanvas {
7535
7694
  setCursorStyle();
7536
7695
  }));
7537
7696
  enterSelection.filter('.resizable-x').append('line').attr('class', 'right-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
7538
- var _a, _b;
7539
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7697
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed) {
7540
7698
  setCursorStyle(CursorStyle.EWResize);
7541
7699
  }
7542
7700
  }).on(Events.MouseOut, (_event, d) => {
7543
- var _a, _b;
7544
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7701
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed) {
7545
7702
  setCursorStyle();
7546
7703
  }
7547
7704
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
7548
- var _a, _b;
7549
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7705
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && d.node) {
7550
7706
  setCursorStyle(CursorStyle.EWResize);
7551
7707
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
7552
7708
  } else {
7553
7709
  setCursorStyle(CursorStyle.NotAllowed);
7554
7710
  }
7555
7711
  }).on(DragEvents.Drag, (event, d) => {
7556
- var _a, _b;
7557
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed) {
7712
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && d.node) {
7558
7713
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7559
7714
  d.node.stretchSections(Side.Right, pointerCoords[0] - (d.coords[0] + d.width), d.indexXInNode, d.indexYInNode);
7560
7715
  }
7561
7716
  }).on(DragEvents.End, (event, d) => {
7562
- var _a, _b;
7563
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableX) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
7717
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableX() && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection && d.node) {
7564
7718
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7565
7719
  if (this.snapToGrid) {
7566
7720
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -7574,32 +7728,27 @@ class DiagramCanvas {
7574
7728
  setCursorStyle();
7575
7729
  }));
7576
7730
  enterSelection.filter('.resizable-y').append('line').attr('class', 'bottom-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
7577
- var _a, _b;
7578
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7731
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed) {
7579
7732
  setCursorStyle(CursorStyle.NSResize);
7580
7733
  }
7581
7734
  }).on(Events.MouseOut, (_event, d) => {
7582
- var _a, _b;
7583
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7735
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed) {
7584
7736
  setCursorStyle();
7585
7737
  }
7586
7738
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
7587
- var _a, _b;
7588
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7739
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && d.node) {
7589
7740
  setCursorStyle(CursorStyle.NSResize);
7590
7741
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
7591
7742
  } else {
7592
7743
  setCursorStyle(CursorStyle.NotAllowed);
7593
7744
  }
7594
7745
  }).on(DragEvents.Drag, (event, d) => {
7595
- var _a, _b;
7596
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed) {
7746
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && d.node) {
7597
7747
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7598
7748
  d.node.stretchSections(Side.Bottom, pointerCoords[1] - (d.coords[1] + d.height), d.indexXInNode, d.indexYInNode);
7599
7749
  }
7600
7750
  }).on(DragEvents.End, (event, d) => {
7601
- var _a, _b;
7602
- if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.resizableY) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
7751
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && d.getResizableY() && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection && d.node) {
7603
7752
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7604
7753
  if (this.snapToGrid) {
7605
7754
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -7916,7 +8065,7 @@ class DiagramCanvas {
7916
8065
  this.diagramEvent$.next(diagramEvent);
7917
8066
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.EditField) && d.editable && !d.removed) {
7918
8067
  this.currentAction = new EditFieldAction(this, d.id, d.text, '');
7919
- this.createInputField(d.text, d.coords, d.width, d.height, d.fontSize, d.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, d.orientation, text => {
8068
+ this.createInputField(d.text, d.coords, d.width, d.height, d.fontSize, d.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, d.orientation, _text => {
7920
8069
  /*
7921
8070
  Empty for now
7922
8071
  We should create a better function to stretch the root element as the text expands
@@ -7985,24 +8134,7 @@ class DiagramCanvas {
7985
8134
  }
7986
8135
  this.secondaryButton = false;
7987
8136
  })).append('xhtml:div').style('width', '100%').style('height', '100%').style('display', 'flex').append('xhtml:p').style('box-sizing', 'border-box').style('outline', 0).style('margin', 0).style('border', 0).style('padding', 0).style('user-select', 'none').style('font-kerning', 'none').style('white-space', 'nowrap');
7988
- mergeSelection.attr('x', 0).attr('y', 0).attr('width', d => `${d.width}px`).attr('height', d => `${d.height}px`).attr('transform', d => `translate(${d.coords[0]},${d.coords[1]})`).attr('opacity', d => d.removed ? 0.5 : 1).select('div').style('justify-content', d => d.horizontalAlign === HorizontalAlign.Center ? 'center' : d.horizontalAlign === HorizontalAlign.Right ? 'flex-end' : 'flex-start').style('align-items', d => d.verticalAlign === VerticalAlign.Center ? 'center' : d.verticalAlign === VerticalAlign.Bottom ? 'end' : 'start').select('p').style('max-width', d => d.fit ? 'default' : '100%').style('max-height', d => d.fit ? 'default' : '100%').style('overflow', d => d.fit ? 'default' : 'hidden').style('text-overflow', d => d.fit ? 'default' : 'ellipsis').style('text-align', d => d.horizontalAlign === HorizontalAlign.Center ? 'center' : d.horizontalAlign === HorizontalAlign.Right ? 'end' : 'start').style('transform', d => {
7989
- if (!isNaN(Number(d.orientation))) {
7990
- return `rotate(${d.orientation}deg)`;
7991
- } else {
7992
- switch (d.orientation) {
7993
- case Side.Top:
7994
- return 'rotate(0deg)';
7995
- case Side.Right:
7996
- return 'rotate(90deg)';
7997
- case Side.Bottom:
7998
- return 'rotate(180deg)';
7999
- case Side.Left:
8000
- return 'rotate(270deg)';
8001
- default:
8002
- return 'rotate(0deg)';
8003
- }
8004
- }
8005
- }).style('font-size', d => `${d.fontSize}px`).style('font-family', d => d.fontFamily || "'Wonder Unit Sans', sans-serif").style('font-weight', d => d.highlighted ? 600 : 400).style('color', d => d.selected ? d.selectedColor || '#000000' : d.color || '#000000').html(d => d.text.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>'));
8137
+ mergeSelection.attr('x', 0).attr('y', 0).attr('width', d => `${d.width}px`).attr('height', d => `${d.height}px`).attr('transform', d => `translate(${d.coords[0]},${d.coords[1]})`).attr('opacity', d => d.removed ? 0.5 : 1).select('div').style('justify-content', d => d.horizontalAlign === HorizontalAlign.Center ? 'center' : d.horizontalAlign === HorizontalAlign.Right ? 'flex-end' : 'flex-start').style('align-items', d => d.verticalAlign === VerticalAlign.Center ? 'center' : d.verticalAlign === VerticalAlign.Bottom ? 'end' : 'start').select('p').style('max-width', d => d.fit ? 'default' : `${unrotate(d.width, d.height, d.orientation)[0]}px`).style('max-height', d => d.fit ? 'default' : `${unrotate(d.width, d.height, d.orientation)[1]}px`).style('overflow', d => d.fit ? 'default' : 'clip').style('text-overflow', d => d.fit ? 'default' : 'ellipsis').style('text-align', d => d.horizontalAlign === HorizontalAlign.Center ? 'center' : d.horizontalAlign === HorizontalAlign.Right ? 'end' : 'start').style('transform', d => `rotate(${d.orientation}deg)`).style('font-size', d => `${d.fontSize}px`).style('font-family', d => d.fontFamily || "'Wonder Unit Sans', sans-serif").style('font-weight', d => d.highlighted ? 600 : 400).style('color', d => d.selected ? d.selectedColor || '#000000' : d.color || '#000000').html(d => d.text.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>'));
8006
8138
  }
8007
8139
  updateObjectsInView(...ids) {
8008
8140
  let updateSelection = this.selectCanvasElements().selectAll('foreignObject.diagram-object').data(this.model.objects.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
@@ -8222,7 +8354,7 @@ class DiagramCanvas {
8222
8354
  }
8223
8355
  return true;
8224
8356
  }
8225
- fitFieldRootInView(id, shrink) {
8357
+ fitFieldRootInView(id, shrink = true) {
8226
8358
  var _a, _b, _c;
8227
8359
  const field = this.model.fields.get(id);
8228
8360
  if (!field) {
@@ -8283,15 +8415,15 @@ class DiagramCanvas {
8283
8415
  if (field.rootElement.height + stretchY < (field.rootElement.getMinHeight() || 0)) {
8284
8416
  stretchY = (field.rootElement.getMinHeight() || 0) - field.rootElement.height;
8285
8417
  }
8286
- if (shrink !== false || stretchX > 0) {
8418
+ if (shrink || stretchX > 0) {
8287
8419
  (_b = field.rootElement.node) === null || _b === void 0 ? void 0 : _b.stretchSections(Side.Right, stretchX, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
8288
8420
  }
8289
- if (shrink !== false || stretchY > 0) {
8421
+ if (shrink || stretchY > 0) {
8290
8422
  (_c = field.rootElement.node) === null || _c === void 0 ? void 0 : _c.stretchSections(Side.Bottom, stretchY, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
8291
8423
  }
8292
8424
  }
8293
8425
  }
8294
- fitNodeInView(id) {
8426
+ fitNodeInView(id, shrink = true) {
8295
8427
  var _a, _b;
8296
8428
  const node = this.model.nodes.get(id);
8297
8429
  if (!node) {
@@ -8312,8 +8444,12 @@ class DiagramCanvas {
8312
8444
  // add the margin that goes between the rightmost and bottommost points of the sections and the edge of the node
8313
8445
  newNodeWidth += ((_a = node.type.sectionGrid) === null || _a === void 0 ? void 0 : _a.margin) || 0;
8314
8446
  newNodeHeight += ((_b = node.type.sectionGrid) === null || _b === void 0 ? void 0 : _b.margin) || 0;
8315
- node.stretch(Side.Right, newNodeWidth - node.width);
8316
- node.stretch(Side.Bottom, newNodeHeight - node.height);
8447
+ if (shrink || newNodeWidth > node.width) {
8448
+ node.stretch(Side.Right, newNodeWidth - node.width);
8449
+ }
8450
+ if (shrink || newNodeHeight > node.height) {
8451
+ node.stretch(Side.Bottom, newNodeHeight - node.height);
8452
+ }
8317
8453
  }
8318
8454
  }
8319
8455
  selectRoot() {
@@ -9156,7 +9292,7 @@ class ForceLayout {
9156
9292
  return model;
9157
9293
  }
9158
9294
  // as a starting point, we apply a simple layout
9159
- new BreadthLayout().apply(model);
9295
+ new BreadthLayout(this.gapSize).apply(model);
9160
9296
  const gapSize = this.gapSize !== undefined ? this.gapSize : (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
9161
9297
  const coolingFactor = 0.99;
9162
9298
  const minimumTemperature = 1;
@@ -9283,7 +9419,7 @@ class PriorityLayout {
9283
9419
  const minimumPriority = Math.min(...model.nodes.map(n => n.getPriority()));
9284
9420
  if (maximumPriority === minimumPriority) {
9285
9421
  // if there's no disparity in priorities, just use breadth layout
9286
- new BreadthLayout().apply(model);
9422
+ new BreadthLayout(this.gapSize).apply(model);
9287
9423
  return model;
9288
9424
  }
9289
9425
  const gapSize = this.gapSize !== undefined ? this.gapSize : (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
@@ -9393,7 +9529,7 @@ class TreeLayout {
9393
9529
  const minimumPriority = Math.min(...model.nodes.map(n => n.getPriority()));
9394
9530
  if (maximumPriority === minimumPriority) {
9395
9531
  // if there's no disparity in priorities, just use breadth layout
9396
- new BreadthLayout().apply(model);
9532
+ new BreadthLayout(this.gapSize).apply(model);
9397
9533
  return model;
9398
9534
  }
9399
9535
  const gapSize = this.gapSize !== undefined ? this.gapSize : (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;