@metadev/daga 3.0.0 → 3.1.0

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
@@ -303,6 +303,9 @@ const MINIMUM_DISTANCE_BEFORE_TURN = 20;
303
303
  * @private
304
304
  */
305
305
  const linePath = (shape, points, startDirection, endDirection, minimumDistanceBeforeTurn) => {
306
+ if (typeof shape === 'function') {
307
+ return shape(points, startDirection, endDirection, minimumDistanceBeforeTurn);
308
+ }
306
309
  if (points.length === 0) {
307
310
  return '';
308
311
  } else if (points.length === 1) {
@@ -665,6 +668,9 @@ var ClosedShape;
665
668
  * @private
666
669
  */
667
670
  const generalClosedPath = (shape, x, y, width, height) => {
671
+ if (typeof shape === 'function') {
672
+ return shape(x, y, width, height);
673
+ }
668
674
  switch (shape) {
669
675
  case ClosedShape.Ellipse:
670
676
  return ellipsePath(x, y, width, height);
@@ -798,7 +804,7 @@ const numberOfColumns = s => {
798
804
  };
799
805
  const numberOfRows = s => {
800
806
  var _a;
801
- return ((_a = s.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) || 0;
807
+ return ((_a = s.match(/\n/g)) === null || _a === undefined ? undefined : _a.length) || 0;
802
808
  };
803
809
 
804
810
  /**
@@ -958,14 +964,14 @@ class DiagramElement {
958
964
  */
959
965
  get highlighted() {
960
966
  var _a, _b;
961
- return ((_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userHighlight) === null || _b === void 0 ? void 0 : _b.contains(this.id)) || false;
967
+ return ((_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.userHighlight) === null || _b === undefined ? undefined : _b.contains(this.id)) || false;
962
968
  }
963
969
  /**
964
970
  * Whether this diagram element is currently in the user selection.
965
971
  */
966
972
  get selected() {
967
973
  var _a, _b;
968
- return ((_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.userSelection) === null || _b === void 0 ? void 0 : _b.contains(this.id)) || false;
974
+ return ((_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.userSelection) === null || _b === undefined ? undefined : _b.contains(this.id)) || false;
969
975
  }
970
976
  constructor(model, id) {
971
977
  /**
@@ -994,7 +1000,7 @@ class DiagramElement {
994
1000
  */
995
1001
  select() {
996
1002
  var _a, _b;
997
- return (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.selectCanvasView()) === null || _b === void 0 ? void 0 : _b.select(`g#${this.id}`);
1003
+ return (_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.selectCanvasView()) === null || _b === undefined ? undefined : _b.select(`g#${this.id}`);
998
1004
  }
999
1005
  }
1000
1006
  class DiagramElementSet extends DiagramEntitySet {
@@ -1217,6 +1223,7 @@ class ValueSet {
1217
1223
  constructor(propertySet, rootElement) {
1218
1224
  this.displayedProperties = [];
1219
1225
  this.hiddenProperties = [];
1226
+ // TODO JC: make this private after reviewing how it's used from React
1220
1227
  this.values = {};
1221
1228
  this.valueSets = {};
1222
1229
  /**
@@ -1295,7 +1302,7 @@ class ValueSet {
1295
1302
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1296
1303
  getValue(key) {
1297
1304
  var _a;
1298
- const rootAttribute = (_a = this.propertySet.getProperty(key)) === null || _a === void 0 ? void 0 : _a.rootAttribute;
1305
+ const rootAttribute = (_a = this.propertySet.getProperty(key)) === null || _a === undefined ? undefined : _a.rootAttribute;
1299
1306
  if (rootAttribute !== undefined && rootAttribute !== null) {
1300
1307
  this.values[key] = this.getRootElementValue(rootAttribute);
1301
1308
  }
@@ -1380,7 +1387,7 @@ class ValueSet {
1380
1387
  if (property && property.type === Type.Object) {
1381
1388
  return this.getSubValueSet(key).hasAnySetValue();
1382
1389
  }
1383
- return !empty(value) && !equals(value, property === null || property === void 0 ? void 0 : property.defaultValue);
1390
+ return !empty(value) && !equals(value, property === null || property === undefined ? undefined : property.defaultValue);
1384
1391
  }
1385
1392
  /**
1386
1393
  * Checks if any of the values in the set are not empty or the default value.
@@ -1739,7 +1746,11 @@ class DiagramConnection extends DiagramElement {
1739
1746
  }
1740
1747
  updateInView() {
1741
1748
  var _a;
1742
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateConnectionsInView(this.id);
1749
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateConnectionsInView(this.id);
1750
+ }
1751
+ raise() {
1752
+ var _a;
1753
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
1743
1754
  }
1744
1755
  /**
1745
1756
  * Set the start of this connection to the given port or reset this connection's starting port if `undefined`.
@@ -1755,12 +1766,12 @@ class DiagramConnection extends DiagramElement {
1755
1766
  this.start = start;
1756
1767
  if (start !== undefined) {
1757
1768
  start.outgoingConnections.push(this);
1758
- this.startDirection = start === null || start === void 0 ? void 0 : start.direction;
1759
- this.startCoords = (start === null || start === void 0 ? void 0 : start.coords) || [0, 0];
1769
+ this.startDirection = start === null || start === undefined ? undefined : start.direction;
1770
+ this.startCoords = (start === null || start === undefined ? undefined : start.coords) || [0, 0];
1760
1771
  }
1761
1772
  } else {
1762
- this.startDirection = start === null || start === void 0 ? void 0 : start.direction;
1763
- this.startCoords = (start === null || start === void 0 ? void 0 : start.coords) || [0, 0];
1773
+ this.startDirection = start === null || start === undefined ? undefined : start.direction;
1774
+ this.startCoords = (start === null || start === undefined ? undefined : start.coords) || [0, 0];
1764
1775
  }
1765
1776
  this.updateInView();
1766
1777
  }
@@ -1778,12 +1789,12 @@ class DiagramConnection extends DiagramElement {
1778
1789
  this.end = end;
1779
1790
  if (end !== undefined) {
1780
1791
  end.incomingConnections.push(this);
1781
- this.endDirection = end === null || end === void 0 ? void 0 : end.direction;
1782
- this.endCoords = (end === null || end === void 0 ? void 0 : end.coords) || [0, 0];
1792
+ this.endDirection = end === null || end === undefined ? undefined : end.direction;
1793
+ this.endCoords = (end === null || end === undefined ? undefined : end.coords) || [0, 0];
1783
1794
  }
1784
1795
  } else {
1785
- this.endDirection = end === null || end === void 0 ? void 0 : end.direction;
1786
- this.endCoords = (end === null || end === void 0 ? void 0 : end.coords) || [0, 0];
1796
+ this.endDirection = end === null || end === undefined ? undefined : end.direction;
1797
+ this.endCoords = (end === null || end === undefined ? undefined : end.coords) || [0, 0];
1787
1798
  }
1788
1799
  this.updateInView();
1789
1800
  }
@@ -1794,7 +1805,7 @@ class DiagramConnection extends DiagramElement {
1794
1805
  */
1795
1806
  tighten() {
1796
1807
  var _a, _b;
1797
- if (((_a = this.start) === null || _a === void 0 ? void 0 : _a.rootElement) && this.end) {
1808
+ if (((_a = this.start) === null || _a === undefined ? undefined : _a.rootElement) && this.end) {
1798
1809
  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]);
1799
1810
  checkAlternativeStartPorts: for (const alternativeStartPort of alternativeStartPortsSortedByDistanceAscending) {
1800
1811
  if (alternativeStartPort === this.end) {
@@ -1824,7 +1835,7 @@ class DiagramConnection extends DiagramElement {
1824
1835
  }
1825
1836
  }
1826
1837
  }
1827
- if (((_b = this.end) === null || _b === void 0 ? void 0 : _b.rootElement) && this.start) {
1838
+ if (((_b = this.end) === null || _b === undefined ? undefined : _b.rootElement) && this.start) {
1828
1839
  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]);
1829
1840
  checkAlternativeEndPorts: for (const alternativeEndPort of alternativeEndPortsSortedByDistanceAscending) {
1830
1841
  if (alternativeEndPort === this.start) {
@@ -1916,8 +1927,8 @@ class DiagramConnectionSet extends DiagramElementSet {
1916
1927
  const connection = this.get(id, true);
1917
1928
  if (connection) {
1918
1929
  // remove from ports
1919
- removeIfExists(((_a = connection.start) === null || _a === void 0 ? void 0 : _a.outgoingConnections) || [], connection);
1920
- removeIfExists(((_b = connection.end) === null || _b === void 0 ? void 0 : _b.incomingConnections) || [], connection);
1930
+ removeIfExists(((_a = connection.start) === null || _a === undefined ? undefined : _a.outgoingConnections) || [], connection);
1931
+ removeIfExists(((_b = connection.end) === null || _b === undefined ? undefined : _b.incomingConnections) || [], connection);
1921
1932
  // remove from set of connections
1922
1933
  super.remove(id);
1923
1934
  // remove from canvas
@@ -1966,11 +1977,11 @@ class DiagramField extends DiagramElement {
1966
1977
  this._text = value;
1967
1978
  this.updateInView();
1968
1979
  if (this.fit) {
1969
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
1980
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.fitFieldRootInView(this.id);
1970
1981
  }
1971
1982
  }
1972
1983
  constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit) {
1973
- const id = `${rootElement === null || rootElement === void 0 ? void 0 : rootElement.id}_field`;
1984
+ const id = `${rootElement === null || rootElement === undefined ? undefined : rootElement.id}_field`;
1974
1985
  if (model.fields.get(id) !== undefined) {
1975
1986
  throw new Error('DiagramField for rootElement already exists');
1976
1987
  }
@@ -1997,14 +2008,18 @@ class DiagramField extends DiagramElement {
1997
2008
  }
1998
2009
  select() {
1999
2010
  var _a, _b;
2000
- return (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.selectCanvasView()) === null || _b === void 0 ? void 0 : _b.select(`foreignObject#${this.id}`);
2011
+ return (_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.selectCanvasView()) === null || _b === undefined ? undefined : _b.select(`foreignObject#${this.id}`);
2001
2012
  }
2002
2013
  get removed() {
2003
2014
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
2004
2015
  }
2005
2016
  updateInView() {
2006
2017
  var _a;
2007
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateFieldsInView(this.id);
2018
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateFieldsInView(this.id);
2019
+ }
2020
+ raise() {
2021
+ var _a;
2022
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
2008
2023
  }
2009
2024
  /**
2010
2025
  * Change the coordinates of this field to the given coordinates.
@@ -2017,7 +2032,7 @@ class DiagramField extends DiagramElement {
2017
2032
  }
2018
2033
  getPriority() {
2019
2034
  var _a;
2020
- return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
2035
+ return ((_a = this.rootElement) === null || _a === undefined ? undefined : _a.getPriority()) || DEFAULT_PRIORITY;
2021
2036
  }
2022
2037
  }
2023
2038
  class DiagramFieldSet extends DiagramElementSet {
@@ -2048,7 +2063,7 @@ class DiagramFieldSet extends DiagramElementSet {
2048
2063
  const field = this.get(id, true);
2049
2064
  if (field) {
2050
2065
  // remove from root element
2051
- if (((_a = field.rootElement) === null || _a === void 0 ? void 0 : _a.label) !== undefined) {
2066
+ if (((_a = field.rootElement) === null || _a === undefined ? undefined : _a.label) !== undefined) {
2052
2067
  if (field.rootElement.label === field) {
2053
2068
  field.rootElement.label = undefined;
2054
2069
  }
@@ -2061,7 +2076,7 @@ class DiagramFieldSet extends DiagramElementSet {
2061
2076
  }
2062
2077
  }
2063
2078
  const getBottomMargin = config => {
2064
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2079
+ if ((config === null || config === undefined ? undefined : config.margin) === null || (config === null || config === undefined ? undefined : config.margin) === undefined) {
2065
2080
  return DIAGRAM_FIELD_DEFAULTS.margin;
2066
2081
  } else if (typeof config.margin === 'number') {
2067
2082
  return config.margin;
@@ -2080,7 +2095,7 @@ const getBottomMargin = config => {
2080
2095
  }
2081
2096
  };
2082
2097
  const getLeftMargin = config => {
2083
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2098
+ if ((config === null || config === undefined ? undefined : config.margin) === null || (config === null || config === undefined ? undefined : config.margin) === undefined) {
2084
2099
  return DIAGRAM_FIELD_DEFAULTS.margin;
2085
2100
  } else if (typeof config.margin === 'number') {
2086
2101
  return config.margin;
@@ -2099,7 +2114,7 @@ const getLeftMargin = config => {
2099
2114
  }
2100
2115
  };
2101
2116
  const getRightMargin = config => {
2102
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2117
+ if ((config === null || config === undefined ? undefined : config.margin) === null || (config === null || config === undefined ? undefined : config.margin) === undefined) {
2103
2118
  return DIAGRAM_FIELD_DEFAULTS.margin;
2104
2119
  } else if (typeof config.margin === 'number') {
2105
2120
  return config.margin;
@@ -2118,7 +2133,7 @@ const getRightMargin = config => {
2118
2133
  }
2119
2134
  };
2120
2135
  const getTopMargin = config => {
2121
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2136
+ if ((config === null || config === undefined ? undefined : config.margin) === null || (config === null || config === undefined ? undefined : config.margin) === undefined) {
2122
2137
  return DIAGRAM_FIELD_DEFAULTS.margin;
2123
2138
  } else if (typeof config.margin === 'number') {
2124
2139
  return config.margin;
@@ -2136,8 +2151,8 @@ const getTopMargin = config => {
2136
2151
  }
2137
2152
  }
2138
2153
  };
2139
- const getBottomPadding = config => {
2140
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2154
+ const getBottomPadding$1 = config => {
2155
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
2141
2156
  return DIAGRAM_FIELD_DEFAULTS.padding;
2142
2157
  } else if (typeof config.padding === 'number') {
2143
2158
  return config.padding;
@@ -2155,8 +2170,8 @@ const getBottomPadding = config => {
2155
2170
  }
2156
2171
  }
2157
2172
  };
2158
- const getLeftPadding = config => {
2159
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2173
+ const getLeftPadding$1 = config => {
2174
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
2160
2175
  return DIAGRAM_FIELD_DEFAULTS.padding;
2161
2176
  } else if (typeof config.padding === 'number') {
2162
2177
  return config.padding;
@@ -2174,8 +2189,8 @@ const getLeftPadding = config => {
2174
2189
  }
2175
2190
  }
2176
2191
  };
2177
- const getRightPadding = config => {
2178
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2192
+ const getRightPadding$1 = config => {
2193
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
2179
2194
  return DIAGRAM_FIELD_DEFAULTS.padding;
2180
2195
  } else if (typeof config.padding === 'number') {
2181
2196
  return config.padding;
@@ -2193,8 +2208,8 @@ const getRightPadding = config => {
2193
2208
  }
2194
2209
  }
2195
2210
  };
2196
- const getTopPadding = config => {
2197
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2211
+ const getTopPadding$1 = config => {
2212
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
2198
2213
  return DIAGRAM_FIELD_DEFAULTS.padding;
2199
2214
  } else if (typeof config.padding === 'number') {
2200
2215
  return config.padding;
@@ -2275,7 +2290,7 @@ class DiagramSection extends DiagramElement {
2275
2290
  */
2276
2291
  get name() {
2277
2292
  var _a;
2278
- return ((_a = this.label) === null || _a === void 0 ? void 0 : _a.text) || '';
2293
+ return ((_a = this.label) === null || _a === undefined ? undefined : _a.text) || '';
2279
2294
  }
2280
2295
  set name(name) {
2281
2296
  if (this.label) {
@@ -2309,23 +2324,36 @@ class DiagramSection extends DiagramElement {
2309
2324
  }
2310
2325
  updateInView() {
2311
2326
  var _a;
2312
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateSectionsInView(this.id);
2327
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateSectionsInView(this.id);
2328
+ }
2329
+ raise() {
2330
+ var _a;
2331
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
2332
+ if (this.label) {
2333
+ this.label.raise();
2334
+ }
2335
+ for (const port of this.ports) {
2336
+ port.raise();
2337
+ }
2338
+ for (const decorator of this.decorators) {
2339
+ decorator.raise();
2340
+ }
2313
2341
  }
2314
2342
  getConfig() {
2315
2343
  var _a, _b, _c, _d, _e;
2316
- return (_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];
2344
+ return (_e = (_d = (_c = (_b = (_a = this.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.sectionGrid) === null || _c === undefined ? undefined : _c.sections) === null || _d === undefined ? undefined : _d[this.indexYInNode]) === null || _e === undefined ? undefined : _e[this.indexXInNode];
2317
2345
  }
2318
2346
  getMinWidth() {
2319
2347
  var _a, _b, _c, _d;
2320
- return ((_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.minWidths) === null || _d === void 0 ? void 0 : _d[this.indexXInNode]) || DIAGRAM_SECTION_MIN_WIDTH;
2348
+ return ((_d = (_c = (_b = (_a = this.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.sectionGrid) === null || _c === undefined ? undefined : _c.minWidths) === null || _d === undefined ? undefined : _d[this.indexXInNode]) || DIAGRAM_SECTION_MIN_WIDTH;
2321
2349
  }
2322
2350
  getMinHeight() {
2323
2351
  var _a, _b, _c, _d;
2324
- return ((_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.minHeights) === null || _d === void 0 ? void 0 : _d[this.indexYInNode]) || DIAGRAM_SECTION_MIN_HEIGHT;
2352
+ return ((_d = (_c = (_b = (_a = this.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.sectionGrid) === null || _c === undefined ? undefined : _c.minHeights) === null || _d === undefined ? undefined : _d[this.indexYInNode]) || DIAGRAM_SECTION_MIN_HEIGHT;
2325
2353
  }
2326
2354
  getPriority() {
2327
2355
  var _a, _b, _c, _d, _e, _f;
2328
- 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) || DIAGRAM_SECTION_DEFAULTS.priority;
2356
+ return ((_f = (_e = (_d = (_c = (_b = (_a = this.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.sectionGrid) === null || _c === undefined ? undefined : _c.sections) === null || _d === undefined ? undefined : _d[this.indexYInNode]) === null || _e === undefined ? undefined : _e[this.indexXInNode]) === null || _f === undefined ? undefined : _f.priority) || DIAGRAM_SECTION_DEFAULTS.priority;
2329
2357
  }
2330
2358
  /**
2331
2359
  * Get the port of this section which is closest to the given coordinates.
@@ -2490,9 +2518,9 @@ class DiagramSection extends DiagramElement {
2490
2518
  }
2491
2519
  // Set label's dimensions as a function of ours.
2492
2520
  if (this.label) {
2493
- this.label.coords = [this.coords[0] + getLeftMargin((_a = this.getConfig()) === null || _a === void 0 ? void 0 : _a.label), this.coords[1] + getTopMargin((_b = this.getConfig()) === null || _b === void 0 ? void 0 : _b.label)];
2494
- this.label.width = this.width - getLeftMargin((_c = this.getConfig()) === null || _c === void 0 ? void 0 : _c.label) - getRightMargin((_d = this.getConfig()) === null || _d === void 0 ? void 0 : _d.label);
2495
- this.label.height = this.height - getTopMargin((_e = this.getConfig()) === null || _e === void 0 ? void 0 : _e.label) - getBottomMargin((_f = this.getConfig()) === null || _f === void 0 ? void 0 : _f.label);
2521
+ this.label.coords = [this.coords[0] + getLeftMargin((_a = this.getConfig()) === null || _a === undefined ? undefined : _a.label), this.coords[1] + getTopMargin((_b = this.getConfig()) === null || _b === undefined ? undefined : _b.label)];
2522
+ this.label.width = this.width - getLeftMargin((_c = this.getConfig()) === null || _c === undefined ? undefined : _c.label) - getRightMargin((_d = this.getConfig()) === null || _d === undefined ? undefined : _d.label);
2523
+ this.label.height = this.height - getTopMargin((_e = this.getConfig()) === null || _e === undefined ? undefined : _e.label) - getBottomMargin((_f = this.getConfig()) === null || _f === undefined ? undefined : _f.label);
2496
2524
  this.label.updateInView();
2497
2525
  }
2498
2526
  // Move decorators to match the new coords.
@@ -2526,11 +2554,11 @@ class DiagramSectionSet extends DiagramElementSet {
2526
2554
  node.sections.push(section);
2527
2555
  node.updateInView();
2528
2556
  // add section ports
2529
- const sectionPorts = (_d = (_c = (_b = (_a = node.type.sectionGrid) === null || _a === void 0 ? void 0 : _a.sections) === null || _b === void 0 ? void 0 : _b[indexYInNode]) === null || _c === void 0 ? void 0 : _c[indexXInNode]) === null || _d === void 0 ? void 0 : _d.ports;
2557
+ const sectionPorts = (_d = (_c = (_b = (_a = node.type.sectionGrid) === null || _a === undefined ? undefined : _a.sections) === null || _b === undefined ? undefined : _b[indexYInNode]) === null || _c === undefined ? undefined : _c[indexXInNode]) === null || _d === undefined ? undefined : _d.ports;
2530
2558
  if (sectionPorts && sectionPorts.length > 0) {
2531
2559
  for (let i = 0; i < sectionPorts.length; ++i) {
2532
2560
  const portConfig = sectionPorts[i];
2533
- const port = this.model.ports.new(section, [section.coords[0] + (((_e = portConfig === null || portConfig === void 0 ? void 0 : portConfig.coords) === null || _e === void 0 ? void 0 : _e[0]) || 0), section.coords[1] + (((_f = portConfig === null || portConfig === void 0 ? void 0 : portConfig.coords) === null || _f === void 0 ? void 0 : _f[1]) || 0)], portConfig === null || portConfig === void 0 ? void 0 : portConfig.direction, `${section.id}_${i}`);
2561
+ const port = this.model.ports.new(section, [section.coords[0] + (((_e = portConfig === null || portConfig === undefined ? undefined : portConfig.coords) === null || _e === undefined ? undefined : _e[0]) || 0), section.coords[1] + (((_f = portConfig === null || portConfig === undefined ? undefined : portConfig.coords) === null || _f === undefined ? undefined : _f[1]) || 0)], portConfig === null || portConfig === undefined ? undefined : portConfig.direction, `${section.id}_${i}`);
2534
2562
  if (portConfig.label) {
2535
2563
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), portConfig.label);
2536
2564
  let labelCoords;
@@ -2553,7 +2581,7 @@ class DiagramSectionSet extends DiagramElementSet {
2553
2581
  }
2554
2582
  }
2555
2583
  // add section label
2556
- 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;
2584
+ const sectionLabel = (_k = (_j = (_h = (_g = node.type.sectionGrid) === null || _g === undefined ? undefined : _g.sections) === null || _h === undefined ? undefined : _h[indexYInNode]) === null || _j === undefined ? undefined : _j[indexXInNode]) === null || _k === undefined ? undefined : _k.label;
2557
2585
  if (sectionLabel) {
2558
2586
  const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), sectionLabel);
2559
2587
  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.editable, labelConfiguration.fit);
@@ -2609,11 +2637,14 @@ const DIAGRAM_NODE_TYPE_DEFAULTS = {
2609
2637
  minHeight: 1,
2610
2638
  resizableX: false,
2611
2639
  resizableY: false,
2640
+ padding: 0,
2612
2641
  label: null,
2613
2642
  ports: [],
2614
2643
  sectionGrid: null,
2615
2644
  look: DIAGRAM_NODE_LOOK_DEFAULTS,
2616
2645
  isUnique: false,
2646
+ canBeParentless: true,
2647
+ childrenTypes: [],
2617
2648
  priority: DEFAULT_PRIORITY,
2618
2649
  properties: []
2619
2650
  };
@@ -2633,13 +2664,19 @@ class DiagramNodeType {
2633
2664
  this.minHeight = values.minHeight;
2634
2665
  this.resizableX = values.resizableX;
2635
2666
  this.resizableY = values.resizableY;
2667
+ this.bottomPadding = getBottomPadding(values);
2668
+ this.leftPadding = getLeftPadding(values);
2669
+ this.rightPadding = getRightPadding(values);
2670
+ this.topPadding = getTopPadding(values);
2636
2671
  this.label = values.label;
2637
2672
  this.ports = values.ports;
2638
2673
  this.sectionGrid = values.sectionGrid;
2639
2674
  this.look = values.look;
2640
2675
  this.isUnique = values.isUnique;
2676
+ this.canBeParentless = values.canBeParentless;
2677
+ this.childrenTypes = values.childrenTypes;
2641
2678
  this.priority = values.priority;
2642
- this.propertySet = new PropertySet((options === null || options === void 0 ? void 0 : options.properties) || []);
2679
+ this.propertySet = new PropertySet((options === null || options === undefined ? undefined : options.properties) || []);
2643
2680
  }
2644
2681
  }
2645
2682
  /**
@@ -2656,7 +2693,7 @@ class DiagramNode extends DiagramElement {
2656
2693
  */
2657
2694
  get name() {
2658
2695
  var _a;
2659
- return ((_a = this.label) === null || _a === void 0 ? void 0 : _a.text) || '';
2696
+ return ((_a = this.label) === null || _a === undefined ? undefined : _a.text) || '';
2660
2697
  }
2661
2698
  set name(name) {
2662
2699
  if (this.label) {
@@ -2668,6 +2705,11 @@ class DiagramNode extends DiagramElement {
2668
2705
  throw new Error(`DiagramNode with id "${id}" already exists`);
2669
2706
  }
2670
2707
  super(model, id);
2708
+ /**
2709
+ * Nodes contained within this node.
2710
+ * @public
2711
+ */
2712
+ this.children = [];
2671
2713
  /**
2672
2714
  * Sections of this node.
2673
2715
  * @public
@@ -2684,7 +2726,7 @@ class DiagramNode extends DiagramElement {
2684
2726
  */
2685
2727
  this.decorators = [];
2686
2728
  /**
2687
- * Collaborative timestamp for SetGeometryCollabActions.
2729
+ * Collaborative timestamp for MoveCollabAction, SetGeometryCollabAction and SetParentCollabAction.
2688
2730
  * @public
2689
2731
  */
2690
2732
  this.geometryTimestamp = null;
@@ -2700,7 +2742,26 @@ class DiagramNode extends DiagramElement {
2700
2742
  }
2701
2743
  updateInView() {
2702
2744
  var _a;
2703
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateNodesInView(this.id);
2745
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateNodesInView(this.id);
2746
+ }
2747
+ raise() {
2748
+ var _a;
2749
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
2750
+ if (this.label) {
2751
+ this.label.raise();
2752
+ }
2753
+ for (const port of this.ports) {
2754
+ port.raise();
2755
+ }
2756
+ for (const section of this.sections) {
2757
+ section.raise();
2758
+ }
2759
+ for (const decorator of this.decorators) {
2760
+ decorator.raise();
2761
+ }
2762
+ for (const child of this.children) {
2763
+ child.raise();
2764
+ }
2704
2765
  }
2705
2766
  getPriority() {
2706
2767
  return this.type.priority;
@@ -2792,7 +2853,7 @@ class DiagramNode extends DiagramElement {
2792
2853
  if (!includeRemoved && incomingConnection.removed) {
2793
2854
  continue;
2794
2855
  }
2795
- const otherNode = (_a = incomingConnection.start) === null || _a === void 0 ? void 0 : _a.getNode();
2856
+ const otherNode = (_a = incomingConnection.start) === null || _a === undefined ? undefined : _a.getNode();
2796
2857
  if (otherNode) {
2797
2858
  if (!includeRemoved && otherNode.removed) {
2798
2859
  continue;
@@ -2804,7 +2865,7 @@ class DiagramNode extends DiagramElement {
2804
2865
  if (!includeRemoved && outgoingConnection.removed) {
2805
2866
  continue;
2806
2867
  }
2807
- const otherNode = (_b = outgoingConnection.end) === null || _b === void 0 ? void 0 : _b.getNode();
2868
+ const otherNode = (_b = outgoingConnection.end) === null || _b === undefined ? undefined : _b.getNode();
2808
2869
  if (otherNode) {
2809
2870
  if (!includeRemoved && otherNode.removed) {
2810
2871
  continue;
@@ -2815,6 +2876,94 @@ class DiagramNode extends DiagramElement {
2815
2876
  }
2816
2877
  return result;
2817
2878
  }
2879
+ /**
2880
+ * Return the ancestor of this node which has no ancestors. If this node has no ancestors, returns itself.
2881
+ * @returns The ancestor of this node which has no ancestors.
2882
+ */
2883
+ getLastAncestor() {
2884
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2885
+ let node = this;
2886
+ while (node.parent !== undefined) {
2887
+ node = node === null || node === undefined ? undefined : node.parent;
2888
+ }
2889
+ return node;
2890
+ }
2891
+ /**
2892
+ * Return true if this node is among the ancestors of the given node.
2893
+ * @param child A node.
2894
+ * @returns `true` if this node is among the ancestors of the given node, `false` otherwise.
2895
+ */
2896
+ isAncestorOf(child) {
2897
+ let node = child;
2898
+ while (node !== undefined) {
2899
+ if (this.id === node.id) {
2900
+ return true;
2901
+ }
2902
+ node = node.parent;
2903
+ }
2904
+ return false;
2905
+ }
2906
+ /**
2907
+ * Return true if the given node is among the ancestors of this node.
2908
+ * @param child A node.
2909
+ * @returns `true` if the given node is among the ancestors of this node, `false` otherwise.
2910
+ */
2911
+ isDescendantOf(child) {
2912
+ return child.isAncestorOf(this);
2913
+ }
2914
+ addChild(child) {
2915
+ if (child.id === this.id) {
2916
+ // do nothing; a node can't be its own child
2917
+ return;
2918
+ }
2919
+ let node = this.parent;
2920
+ let isChildParentOfThis = false;
2921
+ while (node !== undefined) {
2922
+ if (node.id === child.id) {
2923
+ isChildParentOfThis = true;
2924
+ break;
2925
+ }
2926
+ node = node.parent;
2927
+ }
2928
+ if (isChildParentOfThis) {
2929
+ // do nothing; a node can't be its own ancestor
2930
+ return;
2931
+ }
2932
+ if (this.children.indexOf(child) >= 0) {
2933
+ // do nothing, child is already among the node's children
2934
+ return;
2935
+ }
2936
+ this.fitToChild(child);
2937
+ this.children.push(child);
2938
+ child.parent = this;
2939
+ child.raise();
2940
+ }
2941
+ removeChild(child) {
2942
+ removeIfExists(this.children, child);
2943
+ child.parent = undefined;
2944
+ }
2945
+ fitToChild(child) {
2946
+ const excessLeft = this.coords[0] - child.coords[0] + this.type.leftPadding;
2947
+ if (excessLeft >= 0) {
2948
+ this.stretch(Side.Left, excessLeft);
2949
+ }
2950
+ const excessTop = this.coords[1] - child.coords[1] + this.type.topPadding;
2951
+ if (excessTop >= 0) {
2952
+ this.stretch(Side.Top, excessTop);
2953
+ }
2954
+ const excessRight = child.coords[0] + child.width - (this.coords[0] + this.width) + this.type.rightPadding;
2955
+ if (excessRight >= 0) {
2956
+ this.stretch(Side.Right, excessRight);
2957
+ }
2958
+ const excessBottom = child.coords[1] + child.height - (this.coords[1] + this.height) + this.type.bottomPadding;
2959
+ if (excessBottom >= 0) {
2960
+ this.stretch(Side.Bottom, excessBottom);
2961
+ }
2962
+ if (this.parent) {
2963
+ // ensure this node also fits inside its parent after stretching
2964
+ this.parent.fitToChild(this);
2965
+ }
2966
+ }
2818
2967
  /**
2819
2968
  * Change the coordinates of this node to the given coordinates and move its sections, ports and labels correspondingly.
2820
2969
  * @public
@@ -2822,6 +2971,9 @@ class DiagramNode extends DiagramElement {
2822
2971
  */
2823
2972
  move(coords) {
2824
2973
  const coordDifferences = [coords[0] - this.coords[0], coords[1] - this.coords[1]];
2974
+ for (const child of this.children) {
2975
+ child.move([child.coords[0] + coordDifferences[0], child.coords[1] + coordDifferences[1]]);
2976
+ }
2825
2977
  for (const section of this.sections) {
2826
2978
  section.move([section.coords[0] + coordDifferences[0], section.coords[1] + coordDifferences[1]]);
2827
2979
  }
@@ -2830,7 +2982,9 @@ class DiagramNode extends DiagramElement {
2830
2982
  width: this.width,
2831
2983
  height: this.height,
2832
2984
  // We already moved the sections above - skip changing them in setDimensions.
2833
- sections: {}
2985
+ sections: {},
2986
+ // We don't change the children when stretching
2987
+ children: {}
2834
2988
  });
2835
2989
  }
2836
2990
  /**
@@ -2879,7 +3033,9 @@ class DiagramNode extends DiagramElement {
2879
3033
  width: newCoordsX[1] - newCoordsX[0],
2880
3034
  height: newCoordsY[1] - newCoordsY[0],
2881
3035
  // we ignore this.sections, the stretching of a node with sections is handled in the stretchSections method
2882
- sections: {}
3036
+ sections: {},
3037
+ // we ignore this.children
3038
+ children: {}
2883
3039
  });
2884
3040
  }
2885
3041
  /**
@@ -2968,16 +3124,23 @@ class DiagramNode extends DiagramElement {
2968
3124
  * Returns the current values of all geometric properties (coordinates and dimensions) of this node and its sections.
2969
3125
  * @public
2970
3126
  */
2971
- getGeometry() {
3127
+ getGeometry(excludeId) {
2972
3128
  const sections = {};
2973
3129
  for (const section of this.sections) {
2974
3130
  sections[section.id] = section.getGeometry();
2975
3131
  }
3132
+ const children = {};
3133
+ for (const child of this.children) {
3134
+ if (child.id !== excludeId) {
3135
+ children[child.id] = child.getGeometry(excludeId);
3136
+ }
3137
+ }
2976
3138
  return {
2977
3139
  coords: [...this.coords],
2978
3140
  width: this.width,
2979
3141
  height: this.height,
2980
- sections
3142
+ sections,
3143
+ children
2981
3144
  };
2982
3145
  }
2983
3146
  /**
@@ -2985,6 +3148,7 @@ class DiagramNode extends DiagramElement {
2985
3148
  * @public
2986
3149
  */
2987
3150
  setGeometry(geometry) {
3151
+ this.raise();
2988
3152
  const oldCoordsX = [this.coords[0], this.coords[0] + this.width];
2989
3153
  const oldCoordsY = [this.coords[1], this.coords[1] + this.height];
2990
3154
  this.coords = [...geometry.coords];
@@ -2992,6 +3156,13 @@ class DiagramNode extends DiagramElement {
2992
3156
  this.height = geometry.height;
2993
3157
  const newCoordsX = [this.coords[0], this.coords[0] + this.width];
2994
3158
  const newCoordsY = [this.coords[1], this.coords[1] + this.height];
3159
+ // Update children, if supplied.
3160
+ for (const child of this.children) {
3161
+ const childGeometry = geometry.children[child.id];
3162
+ if (childGeometry) {
3163
+ child.setGeometry(childGeometry);
3164
+ }
3165
+ }
2995
3166
  // Update sections, if supplied.
2996
3167
  for (const section of this.sections) {
2997
3168
  const sectionGeometry = geometry.sections[section.id];
@@ -3063,10 +3234,10 @@ class DiagramNodeSet extends DiagramElementSet {
3063
3234
  for (let j = 0; j < nodeType.sectionGrid.sections.length; ++j) {
3064
3235
  let widthAccumulator = node.coords[0] + (nodeType.sectionGrid.margin || 0);
3065
3236
  for (let i = 0; i < nodeType.sectionGrid.sections[j].length; ++i) {
3066
- this.model.sections.new(node, i, j, [widthAccumulator, heightAccumulator], ((_a = nodeType.sectionGrid.defaultWidths) === null || _a === void 0 ? void 0 : _a[i]) || DIAGRAM_SECTION_DEFAULT_WIDTH, ((_b = nodeType.sectionGrid.defaultHeights) === null || _b === void 0 ? void 0 : _b[j]) || DIAGRAM_SECTION_DEFAULT_HEIGHT, `${node.id}_${j}_${i}`);
3067
- widthAccumulator += (((_c = nodeType.sectionGrid.defaultWidths) === null || _c === void 0 ? void 0 : _c[i]) || DIAGRAM_SECTION_DEFAULT_WIDTH) + (nodeType.sectionGrid.margin || 0);
3237
+ this.model.sections.new(node, i, j, [widthAccumulator, heightAccumulator], ((_a = nodeType.sectionGrid.defaultWidths) === null || _a === undefined ? undefined : _a[i]) || DIAGRAM_SECTION_DEFAULT_WIDTH, ((_b = nodeType.sectionGrid.defaultHeights) === null || _b === undefined ? undefined : _b[j]) || DIAGRAM_SECTION_DEFAULT_HEIGHT, `${node.id}_${j}_${i}`);
3238
+ widthAccumulator += (((_c = nodeType.sectionGrid.defaultWidths) === null || _c === undefined ? undefined : _c[i]) || DIAGRAM_SECTION_DEFAULT_WIDTH) + (nodeType.sectionGrid.margin || 0);
3068
3239
  }
3069
- heightAccumulator += (((_d = nodeType.sectionGrid.defaultHeights) === null || _d === void 0 ? void 0 : _d[j]) || DIAGRAM_SECTION_DEFAULT_HEIGHT) + (nodeType.sectionGrid.margin || 0);
3240
+ heightAccumulator += (((_d = nodeType.sectionGrid.defaultHeights) === null || _d === undefined ? undefined : _d[j]) || DIAGRAM_SECTION_DEFAULT_HEIGHT) + (nodeType.sectionGrid.margin || 0);
3070
3241
  }
3071
3242
  }
3072
3243
  // add node ports
@@ -3101,12 +3272,20 @@ class DiagramNodeSet extends DiagramElementSet {
3101
3272
  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.editable, labelConfiguration.fit);
3102
3273
  }
3103
3274
  node.valueSet.resetValues();
3104
- (_e = node.model.canvas) === null || _e === void 0 ? void 0 : _e.fitNodeInView(node.id);
3275
+ (_e = node.model.canvas) === null || _e === undefined ? undefined : _e.fitNodeInView(node.id);
3105
3276
  return node;
3106
3277
  }
3107
3278
  remove(id) {
3108
3279
  const node = this.get(id, true);
3109
3280
  if (node) {
3281
+ // remove from parent
3282
+ if (node.parent) {
3283
+ removeIfExists(node.parent.children, node);
3284
+ }
3285
+ // remove all children
3286
+ while (node.children.length > 0) {
3287
+ this.model.nodes.remove(node.children[0].id);
3288
+ }
3110
3289
  // remove all sections
3111
3290
  while (node.sections.length > 0) {
3112
3291
  this.model.sections.remove(node.sections[0].id);
@@ -3129,7 +3308,137 @@ class DiagramNodeSet extends DiagramElementSet {
3129
3308
  node.updateInView();
3130
3309
  }
3131
3310
  }
3311
+ /**
3312
+ * Gets all the nodes that overlap with the given coordinates.
3313
+ * @public
3314
+ * @param x A coordinate along the x axis.
3315
+ * @param y A coordinate along the y axis.
3316
+ * @returns All the nodes that overlap with the given coordinates.
3317
+ */
3318
+ getAtCoordinates(x, y) {
3319
+ const nodesAtLocation = [];
3320
+ for (const node of this) {
3321
+ if (node.coords[0] < x && x < node.coords[0] + node.width && node.coords[1] < y && y < node.coords[1] + node.height) {
3322
+ nodesAtLocation.push(node);
3323
+ }
3324
+ }
3325
+ return nodesAtLocation;
3326
+ }
3132
3327
  }
3328
+ /**
3329
+ * Removes any nodes from the given list which are a descendant of another node in the list.
3330
+ * @param nodes A list of nodes.
3331
+ * @returns The given list of nodes minus any node that is a descendant of another node in the list.
3332
+ */
3333
+ const filterByOnlyAncestors = nodes => {
3334
+ for (let i = 0; i < nodes.length; ++i) {
3335
+ for (let j = 0; j < nodes.length; ++j) {
3336
+ if (j !== i && nodes[j].isDescendantOf(nodes[i])) {
3337
+ nodes.splice(j, 1);
3338
+ --j;
3339
+ if (i > j) {
3340
+ --i;
3341
+ }
3342
+ }
3343
+ }
3344
+ }
3345
+ return nodes;
3346
+ };
3347
+ /**
3348
+ * Removes any nodes from the given list which are an ancestor of another node in the list.
3349
+ * @param nodes A list of nodes.
3350
+ * @returns The given list of nodes minus any node that is an ancestor of another node in the list.
3351
+ */
3352
+ const filterByOnlyDescendants = nodes => {
3353
+ for (let i = 0; i < nodes.length; ++i) {
3354
+ for (let j = 0; j < nodes.length; ++j) {
3355
+ if (j !== i && nodes[j].isAncestorOf(nodes[i])) {
3356
+ nodes.splice(j, 1);
3357
+ --j;
3358
+ if (i > j) {
3359
+ --i;
3360
+ }
3361
+ }
3362
+ }
3363
+ }
3364
+ return nodes;
3365
+ };
3366
+ const getBottomPadding = config => {
3367
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
3368
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3369
+ } else if (typeof config.padding === 'number') {
3370
+ return config.padding;
3371
+ } else {
3372
+ if (config.padding.length === 0) {
3373
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3374
+ } else if (config.padding.length === 1) {
3375
+ return config.padding[0];
3376
+ } else if (config.padding.length === 2) {
3377
+ return config.padding[0];
3378
+ } else if (config.padding.length === 3) {
3379
+ return config.padding[2];
3380
+ } else {
3381
+ return config.padding[2];
3382
+ }
3383
+ }
3384
+ };
3385
+ const getLeftPadding = config => {
3386
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
3387
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3388
+ } else if (typeof config.padding === 'number') {
3389
+ return config.padding;
3390
+ } else {
3391
+ if (config.padding.length === 0) {
3392
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3393
+ } else if (config.padding.length === 1) {
3394
+ return config.padding[0];
3395
+ } else if (config.padding.length === 2) {
3396
+ return config.padding[1];
3397
+ } else if (config.padding.length === 3) {
3398
+ return config.padding[1];
3399
+ } else {
3400
+ return config.padding[3];
3401
+ }
3402
+ }
3403
+ };
3404
+ const getRightPadding = config => {
3405
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
3406
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3407
+ } else if (typeof config.padding === 'number') {
3408
+ return config.padding;
3409
+ } else {
3410
+ if (config.padding.length === 0) {
3411
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3412
+ } else if (config.padding.length === 1) {
3413
+ return config.padding[0];
3414
+ } else if (config.padding.length === 2) {
3415
+ return config.padding[1];
3416
+ } else if (config.padding.length === 3) {
3417
+ return config.padding[1];
3418
+ } else {
3419
+ return config.padding[1];
3420
+ }
3421
+ }
3422
+ };
3423
+ const getTopPadding = config => {
3424
+ if ((config === null || config === undefined ? undefined : config.padding) === null || (config === null || config === undefined ? undefined : config.padding) === undefined) {
3425
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3426
+ } else if (typeof config.padding === 'number') {
3427
+ return config.padding;
3428
+ } else {
3429
+ if (config.padding.length === 0) {
3430
+ return DIAGRAM_NODE_TYPE_DEFAULTS.padding;
3431
+ } else if (config.padding.length === 1) {
3432
+ return config.padding[0];
3433
+ } else if (config.padding.length === 2) {
3434
+ return config.padding[0];
3435
+ } else if (config.padding.length === 3) {
3436
+ return config.padding[0];
3437
+ } else {
3438
+ return config.padding[0];
3439
+ }
3440
+ }
3441
+ };
3133
3442
 
3134
3443
  /**
3135
3444
  * Default values of the parameters of a diagram port.
@@ -3173,7 +3482,17 @@ class DiagramPort extends DiagramElement {
3173
3482
  }
3174
3483
  updateInView() {
3175
3484
  var _a;
3176
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
3485
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updatePortsInView(this.id);
3486
+ }
3487
+ raise() {
3488
+ var _a;
3489
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
3490
+ for (const connection of this.incomingConnections) {
3491
+ connection.raise();
3492
+ }
3493
+ for (const connection of this.outgoingConnections) {
3494
+ connection.raise();
3495
+ }
3177
3496
  }
3178
3497
  /**
3179
3498
  * Add a connection to this port's list of outgoing connections.
@@ -3206,7 +3525,7 @@ class DiagramPort extends DiagramElement {
3206
3525
  }
3207
3526
  getPriority() {
3208
3527
  var _a;
3209
- return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
3528
+ return ((_a = this.rootElement) === null || _a === undefined ? undefined : _a.getPriority()) || DEFAULT_PRIORITY;
3210
3529
  }
3211
3530
  /**
3212
3531
  * Change the coordinates of this port to the given coordinates and move its labels correspondingly.
@@ -3312,7 +3631,7 @@ class DagaImporter {
3312
3631
  return model;
3313
3632
  }
3314
3633
  importNode(model, node) {
3315
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
3634
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
3316
3635
  const newNodeType = model.nodes.types.get(node.type);
3317
3636
  if (newNodeType) {
3318
3637
  const newNode = new DiagramNode(model, newNodeType, node.coords, node.id);
@@ -3330,14 +3649,21 @@ class DagaImporter {
3330
3649
  newField.updateInView();
3331
3650
  }
3332
3651
  }
3652
+ for (const child of node.children || []) {
3653
+ const newChild = this.importNode(model, child);
3654
+ if (newChild !== undefined) {
3655
+ (_a = newNode.children) === null || _a === undefined ? undefined : _a.push(newChild);
3656
+ newChild.parent = newNode;
3657
+ }
3658
+ }
3333
3659
  for (const section of node.sections || []) {
3334
3660
  const newSection = new DiagramSection(model, newNode, section.indexXInNode, section.indexYInNode, section.coords, section.width, section.height, section.id);
3335
- (_a = newNode.sections) === null || _a === void 0 ? void 0 : _a.push(newSection);
3661
+ (_b = newNode.sections) === null || _b === undefined ? undefined : _b.push(newSection);
3336
3662
  model.sections.add(newSection);
3337
3663
  if (section.label) {
3338
3664
  // add section label
3339
- if ((_e = (_d = (_c = (_b = newNodeType.sectionGrid) === null || _b === void 0 ? void 0 : _b.sections) === null || _c === void 0 ? void 0 : _c[section.indexYInNode]) === null || _d === void 0 ? void 0 : _d[section.indexXInNode]) === null || _e === void 0 ? void 0 : _e.label) {
3340
- const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_j = (_h = (_g = (_f = newNodeType.sectionGrid) === null || _f === void 0 ? void 0 : _f.sections) === null || _g === void 0 ? void 0 : _g[section.indexYInNode]) === null || _h === void 0 ? void 0 : _h[section.indexXInNode]) === null || _j === void 0 ? void 0 : _j.label);
3665
+ if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === undefined ? undefined : _c.sections) === null || _d === undefined ? undefined : _d[section.indexYInNode]) === null || _e === undefined ? undefined : _e[section.indexXInNode]) === null || _f === undefined ? undefined : _f.label) {
3666
+ const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === undefined ? undefined : _g.sections) === null || _h === undefined ? undefined : _h[section.indexYInNode]) === null || _j === undefined ? undefined : _j[section.indexXInNode]) === null || _k === undefined ? undefined : _k.label);
3341
3667
  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.editable, labelConfiguration.fit);
3342
3668
  newField.text = section.label;
3343
3669
  newSection.label = newField;
@@ -3482,16 +3808,21 @@ class DagaImporter {
3482
3808
  * @see AddNodeAction
3483
3809
  */
3484
3810
  class AddNodeCollabAction {
3485
- constructor(canvas, id, typeId, coords, label, values) {
3811
+ constructor(canvas, id, typeId, coords, parentId, label, values) {
3486
3812
  this.canvas = canvas;
3487
3813
  this.id = id;
3488
3814
  this.typeId = typeId;
3489
3815
  this.coords = coords;
3816
+ this.parentId = parentId;
3490
3817
  this.label = label;
3491
3818
  this.values = values;
3492
3819
  }
3493
3820
  do() {
3821
+ var _a;
3494
3822
  const node = this.canvas.model.nodes.new(this.typeId, this.coords, this.id);
3823
+ if (this.parentId !== undefined) {
3824
+ (_a = this.canvas.model.nodes.get(this.parentId)) === null || _a === undefined ? undefined : _a.addChild(node);
3825
+ }
3495
3826
  if (this.values !== undefined) {
3496
3827
  node.valueSet.setValues(structuredClone(Object.assign(Object.assign({}, node.valueSet.getValues()), this.values)));
3497
3828
  }
@@ -3505,12 +3836,45 @@ class AddNodeCollabAction {
3505
3836
  id: this.id,
3506
3837
  typeId: this.typeId,
3507
3838
  coords: this.coords,
3839
+ parentId: this.parentId,
3508
3840
  label: this.label,
3509
3841
  values: this.values
3510
3842
  };
3511
3843
  }
3512
3844
  static deserialize(canvas, serialized) {
3513
- return new AddNodeCollabAction(canvas, serialized.id, serialized.typeId, serialized.coords, serialized.label, serialized.values);
3845
+ return new AddNodeCollabAction(canvas, serialized.id, serialized.typeId, serialized.coords, serialized.parentId, serialized.label, serialized.values);
3846
+ }
3847
+ }
3848
+ /**
3849
+ * Collaborative which consists of applying a layout to the diagram which can change the location of several nodes.
3850
+ * @private
3851
+ * @see ApplyLayoutAction
3852
+ */
3853
+ class ApplyLayoutCollabAction {
3854
+ constructor(canvas, to, timestamp) {
3855
+ this.canvas = canvas;
3856
+ this.to = to;
3857
+ this.timestamp = timestamp;
3858
+ }
3859
+ do() {
3860
+ for (const nodeId in this.to) {
3861
+ const node = this.canvas.model.nodes.get(nodeId, true);
3862
+ if (node && timestampWins(this.timestamp, node.geometryTimestamp)) {
3863
+ const point = this.to[nodeId];
3864
+ node.move([point[0], point[1]]);
3865
+ node.geometryTimestamp = this.timestamp;
3866
+ }
3867
+ }
3868
+ }
3869
+ serialize() {
3870
+ return {
3871
+ type: 'applyLayout',
3872
+ to: this.to,
3873
+ timestamp: this.timestamp
3874
+ };
3875
+ }
3876
+ static deserialize(canvas, serialized) {
3877
+ return new ApplyLayoutCollabAction(canvas, serialized.to, serialized.timestamp);
3514
3878
  }
3515
3879
  }
3516
3880
  /**
@@ -3526,10 +3890,12 @@ class MoveCollabAction {
3526
3890
  this.timestamp = timestamp;
3527
3891
  }
3528
3892
  do() {
3893
+ var _a;
3529
3894
  for (const nodeId of this.nodeIds) {
3530
3895
  const node = this.canvas.model.nodes.get(nodeId, true);
3531
3896
  if (node && timestampWins(this.timestamp, node.geometryTimestamp)) {
3532
3897
  node.move([node.coords[0] + this.delta[0], node.coords[1] + this.delta[1]]);
3898
+ (_a = node.parent) === null || _a === undefined ? undefined : _a.fitToChild(node);
3533
3899
  node.geometryTimestamp = this.timestamp;
3534
3900
  }
3535
3901
  }
@@ -3559,19 +3925,20 @@ class SetGeometryCollabAction {
3559
3925
  this.timestamp = timestamp;
3560
3926
  }
3561
3927
  do() {
3562
- var _a, _b;
3928
+ var _a, _b, _c;
3563
3929
  const node = this.canvas.model.nodes.get(this.nodeId, true);
3564
3930
  if (node && timestampWins(this.timestamp, node.geometryTimestamp)) {
3565
3931
  node.setGeometry(this.to);
3566
3932
  // Re-fit the labels, in case their text has changed since `this.to` was measured.
3567
- if ((_a = node.label) === null || _a === void 0 ? void 0 : _a.fit) {
3933
+ if ((_a = node.label) === null || _a === undefined ? undefined : _a.fit) {
3568
3934
  this.canvas.fitFieldRootInView(node.label.id);
3569
3935
  }
3570
3936
  for (const section of node.sections) {
3571
- if ((_b = section.label) === null || _b === void 0 ? void 0 : _b.fit) {
3937
+ if ((_b = section.label) === null || _b === undefined ? undefined : _b.fit) {
3572
3938
  this.canvas.fitFieldRootInView(section.label.id);
3573
3939
  }
3574
3940
  }
3941
+ (_c = node.parent) === null || _c === undefined ? undefined : _c.fitToChild(node);
3575
3942
  node.geometryTimestamp = this.timestamp;
3576
3943
  }
3577
3944
  }
@@ -3587,6 +3954,42 @@ class SetGeometryCollabAction {
3587
3954
  return new SetGeometryCollabAction(canvas, serialized.nodeId, serialized.to, serialized.timestamp);
3588
3955
  }
3589
3956
  }
3957
+ /**
3958
+ * Collaborative action which consists of setting a node's parent.
3959
+ * @private
3960
+ * @see SetParentAction
3961
+ */
3962
+ class SetParentCollabAction {
3963
+ constructor(canvas, childId, parentId, childGeometry, timestamp) {
3964
+ this.canvas = canvas;
3965
+ this.childId = childId;
3966
+ this.parentId = parentId;
3967
+ this.childGeometry = childGeometry;
3968
+ this.timestamp = timestamp;
3969
+ }
3970
+ do() {
3971
+ var _a;
3972
+ const childNode = this.canvas.model.nodes.get(this.childId, true);
3973
+ const parentNode = this.parentId !== undefined ? this.canvas.model.nodes.get(this.parentId, true) : undefined;
3974
+ if (childNode && (this.parentId !== undefined ? parentNode : true) && timestampWins(this.timestamp, childNode.geometryTimestamp)) {
3975
+ (_a = childNode.parent) === null || _a === undefined ? undefined : _a.removeChild(childNode);
3976
+ childNode.setGeometry(this.childGeometry);
3977
+ parentNode === null || parentNode === undefined ? undefined : parentNode.addChild(childNode);
3978
+ }
3979
+ }
3980
+ serialize() {
3981
+ return {
3982
+ type: 'setParent',
3983
+ childId: this.childId,
3984
+ parentId: this.parentId,
3985
+ childGeometry: this.childGeometry,
3986
+ timestamp: this.timestamp
3987
+ };
3988
+ }
3989
+ static deserialize(canvas, serialized) {
3990
+ return new SetParentCollabAction(canvas, serialized.childId, serialized.parentId, serialized.childGeometry, serialized.timestamp);
3991
+ }
3992
+ }
3590
3993
  /**
3591
3994
  * Collaborative action which consists of adding a connection.
3592
3995
  * @private
@@ -3668,12 +4071,12 @@ class UpdateValuesCollabAction {
3668
4071
  if (this.id === undefined) {
3669
4072
  return this.canvas.model.valueSet;
3670
4073
  } else {
3671
- return (_a = this.canvas.model.nodes.get(this.id, true) || this.canvas.model.connections.get(this.id, true)) === null || _a === void 0 ? void 0 : _a.valueSet;
4074
+ return (_a = this.canvas.model.nodes.get(this.id, true) || this.canvas.model.connections.get(this.id, true)) === null || _a === undefined ? undefined : _a.valueSet;
3672
4075
  }
3673
4076
  }
3674
4077
  do() {
3675
4078
  var _a;
3676
- (_a = this.getValueSet()) === null || _a === void 0 ? void 0 : _a.overwriteValuesLww(this.to, this.timestamp);
4079
+ (_a = this.getValueSet()) === null || _a === undefined ? undefined : _a.overwriteValuesLww(this.to, this.timestamp);
3677
4080
  }
3678
4081
  serialize() {
3679
4082
  return {
@@ -3858,6 +4261,12 @@ class CollabEngine {
3858
4261
  action.do();
3859
4262
  break;
3860
4263
  }
4264
+ case 'applyLayout':
4265
+ {
4266
+ const action = ApplyLayoutCollabAction.deserialize(this.canvas, message);
4267
+ action.do();
4268
+ break;
4269
+ }
3861
4270
  case 'move':
3862
4271
  {
3863
4272
  const action = MoveCollabAction.deserialize(this.canvas, message);
@@ -3870,6 +4279,12 @@ class CollabEngine {
3870
4279
  action.do();
3871
4280
  break;
3872
4281
  }
4282
+ case 'setParent':
4283
+ {
4284
+ const action = SetParentCollabAction.deserialize(this.canvas, message);
4285
+ action.do();
4286
+ break;
4287
+ }
3873
4288
  case 'addConnection':
3874
4289
  {
3875
4290
  const action = AddConnectionCollabAction.deserialize(this.canvas, message);
@@ -3910,7 +4325,7 @@ class CollabEngine {
3910
4325
  }
3911
4326
 
3912
4327
  /**
3913
- * A stack of recent actions taken by the user that can be undone and redone.
4328
+ * A stack of recent actions taken by the user.
3914
4329
  * @private
3915
4330
  */
3916
4331
  class ActionStack {
@@ -3935,37 +4350,60 @@ class ActionStack {
3935
4350
  this.history.push(action);
3936
4351
  ++this.index;
3937
4352
  }
3938
- this.canvas.diagramChange$.next();
4353
+ this.canvas.diagramChange$.next({
4354
+ action,
4355
+ method: DiagramActionMethod.Do
4356
+ });
3939
4357
  }
3940
4358
  /**
3941
4359
  * Undoes the last action in the history, not counting undone actions.
3942
4360
  * @private
3943
4361
  */
3944
4362
  undo() {
4363
+ let action;
3945
4364
  if (this.index > 0) {
3946
4365
  let hasEffect;
3947
4366
  do {
3948
4367
  --this.index;
3949
- hasEffect = this.history[this.index].undo();
4368
+ action = this.history[this.index];
4369
+ hasEffect = action.undo();
3950
4370
  } while (!hasEffect && this.index > 0);
3951
4371
  }
3952
- this.canvas.diagramChange$.next();
4372
+ this.canvas.diagramChange$.next({
4373
+ action,
4374
+ method: DiagramActionMethod.Undo
4375
+ });
3953
4376
  }
3954
4377
  /**
3955
4378
  * Redoes the last undone action in the history.
3956
4379
  * @private
3957
4380
  */
3958
4381
  redo() {
4382
+ let action;
3959
4383
  if (this.index < this.history.length) {
3960
4384
  let hasEffect;
3961
4385
  do {
3962
- hasEffect = this.history[this.index].redo();
4386
+ action = this.history[this.index];
4387
+ hasEffect = action.redo();
3963
4388
  ++this.index;
3964
4389
  } while (!hasEffect && this.index < this.history.length);
3965
4390
  }
3966
- this.canvas.diagramChange$.next();
4391
+ this.canvas.diagramChange$.next({
4392
+ action,
4393
+ method: DiagramActionMethod.Redo
4394
+ });
3967
4395
  }
3968
4396
  }
4397
+ /**
4398
+ * The different methods of an action.
4399
+ * @private
4400
+ */
4401
+ var DiagramActionMethod;
4402
+ (function (DiagramActionMethod) {
4403
+ DiagramActionMethod[DiagramActionMethod["Do"] = 0] = "Do";
4404
+ DiagramActionMethod[DiagramActionMethod["Undo"] = 1] = "Undo";
4405
+ DiagramActionMethod[DiagramActionMethod["Redo"] = 2] = "Redo";
4406
+ })(DiagramActionMethod || (DiagramActionMethod = {}));
3969
4407
  /**
3970
4408
  * Enum listing the actions that can be taken by the user.
3971
4409
  * The actions can correspond to a DiagramAction that can be recorded in the action stack of a diagram or they may not correspond to any DiagramAction implementations.
@@ -3985,6 +4423,12 @@ var DiagramActions;
3985
4423
  * @see AddNodeAction
3986
4424
  */
3987
4425
  DiagramActions["AddNode"] = "add-node";
4426
+ /**
4427
+ * Action that corresponds to applying a layout which changes the location of several nodes.
4428
+ * @public
4429
+ * @see ApplyLayoutAction
4430
+ */
4431
+ DiagramActions["ApplyLayout"] = "apply-layout";
3988
4432
  /**
3989
4433
  * Action that corresponds to copying diagram elements to the clipboard.
3990
4434
  * @public
@@ -4050,17 +4494,25 @@ var DiagramActions;
4050
4494
  * @see DiagramNode
4051
4495
  */
4052
4496
  class AddNodeAction {
4053
- constructor(canvas, type, coords, label, values) {
4497
+ constructor(canvas, type, coords, parentId, ancestorId, fromAncestorGeometry, toAncestorGeometry, label, values) {
4054
4498
  this.canvas = canvas;
4055
4499
  this.type = type;
4056
4500
  this.coords = coords;
4501
+ this.parentId = parentId;
4502
+ this.ancestorId = ancestorId;
4503
+ this.fromAncestorGeometry = fromAncestorGeometry;
4504
+ this.toAncestorGeometry = toAncestorGeometry;
4057
4505
  this.label = label;
4058
4506
  this.values = values;
4059
4507
  this.id = this.canvas.collabEngine.freshId();
4060
4508
  }
4061
4509
  do() {
4062
- const collabAction = new AddNodeCollabAction(this.canvas, this.id, this.type.id, this.coords, this.label, this.values);
4510
+ const collabAction = new AddNodeCollabAction(this.canvas, this.id, this.type.id, this.coords, this.parentId, this.label, this.values);
4063
4511
  this.canvas.collabEngine.doCollaboratively(collabAction);
4512
+ if (this.ancestorId !== undefined && this.toAncestorGeometry !== undefined) {
4513
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.toAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4514
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4515
+ }
4064
4516
  // creating a node always has an effect
4065
4517
  return true;
4066
4518
  }
@@ -4068,6 +4520,10 @@ class AddNodeAction {
4068
4520
  const node = this.canvas.model.nodes.get(this.id);
4069
4521
  const collabAction = new SetSelfRemovedCollabAction(this.canvas, [this.id], [], [], [], [], true, this.canvas.collabEngine.freshTimestamp());
4070
4522
  this.canvas.collabEngine.doCollaboratively(collabAction);
4523
+ if (this.ancestorId !== undefined && this.fromAncestorGeometry !== undefined) {
4524
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.fromAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4525
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4526
+ }
4071
4527
  // undoing creating a node has an effect if the node was not already removed
4072
4528
  return node !== undefined;
4073
4529
  }
@@ -4075,10 +4531,38 @@ class AddNodeAction {
4075
4531
  const node = this.canvas.model.nodes.get(this.id);
4076
4532
  const collabAction = new SetSelfRemovedCollabAction(this.canvas, [this.id], [], [], [], [], false, this.canvas.collabEngine.freshTimestamp());
4077
4533
  this.canvas.collabEngine.doCollaboratively(collabAction);
4534
+ if (this.ancestorId !== undefined && this.toAncestorGeometry !== undefined) {
4535
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.toAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4536
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4537
+ }
4078
4538
  // redoing creating a node has an effect if the node was removed
4079
4539
  return node === undefined;
4080
4540
  }
4081
4541
  }
4542
+ /**
4543
+ * Action which consists of applying a layout to the diagram which can change the location of several nodes.
4544
+ * @private
4545
+ */
4546
+ class ApplyLayoutAction {
4547
+ constructor(canvas, from, to) {
4548
+ this.canvas = canvas;
4549
+ this.from = from;
4550
+ this.to = to;
4551
+ }
4552
+ do() {
4553
+ const collabAction = new ApplyLayoutCollabAction(this.canvas, this.to, this.canvas.collabEngine.freshTimestamp());
4554
+ this.canvas.collabEngine.doCollaboratively(collabAction);
4555
+ return true;
4556
+ }
4557
+ undo() {
4558
+ const collabAction = new ApplyLayoutCollabAction(this.canvas, this.from, this.canvas.collabEngine.freshTimestamp());
4559
+ this.canvas.collabEngine.doCollaboratively(collabAction);
4560
+ return true;
4561
+ }
4562
+ redo() {
4563
+ return this.do();
4564
+ }
4565
+ }
4082
4566
  /**
4083
4567
  * Action which consists of changing the coordinates of diagram elements by a fixed amount.
4084
4568
  * @private
@@ -4109,17 +4593,26 @@ class MoveAction {
4109
4593
  * @see DiagramNode
4110
4594
  */
4111
4595
  class SetGeometryAction {
4112
- constructor(canvas, intent, nodeId, from, to) {
4596
+ constructor(canvas, intent, nodeId, from, to, ancestorId, fromAncestorGeometry, toAncestorGeometry) {
4113
4597
  this.canvas = canvas;
4114
4598
  this.intent = intent;
4115
4599
  this.nodeId = nodeId;
4116
4600
  this.from = from;
4117
4601
  this.to = to;
4602
+ this.ancestorId = ancestorId;
4603
+ this.fromAncestorGeometry = fromAncestorGeometry;
4604
+ this.toAncestorGeometry = toAncestorGeometry;
4118
4605
  }
4119
4606
  do() {
4120
4607
  const node = this.canvas.model.nodes.get(this.nodeId);
4121
- const collabAction = new SetGeometryCollabAction(this.canvas, this.nodeId, this.to, this.canvas.collabEngine.freshTimestamp());
4122
- this.canvas.collabEngine.doCollaboratively(collabAction);
4608
+ if (node) {
4609
+ const collabAction = new SetGeometryCollabAction(this.canvas, this.nodeId, this.to, this.canvas.collabEngine.freshTimestamp());
4610
+ this.canvas.collabEngine.doCollaboratively(collabAction);
4611
+ if (this.ancestorId !== undefined && this.toAncestorGeometry !== undefined) {
4612
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.toAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4613
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4614
+ }
4615
+ }
4123
4616
  return node !== undefined;
4124
4617
  }
4125
4618
  undo() {
@@ -4128,6 +4621,10 @@ class SetGeometryAction {
4128
4621
  this.to = node.getGeometry();
4129
4622
  const collabAction = new SetGeometryCollabAction(this.canvas, this.nodeId, this.from, this.canvas.collabEngine.freshTimestamp());
4130
4623
  this.canvas.collabEngine.doCollaboratively(collabAction);
4624
+ if (this.ancestorId !== undefined && this.fromAncestorGeometry !== undefined) {
4625
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.fromAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4626
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4627
+ }
4131
4628
  }
4132
4629
  return node !== undefined;
4133
4630
  }
@@ -4141,6 +4638,46 @@ class SetGeometryAction {
4141
4638
  return node !== undefined;
4142
4639
  }
4143
4640
  }
4641
+ /**
4642
+ * Action which consists of setting a node's parent.
4643
+ * @private
4644
+ */
4645
+ class SetParentAction {
4646
+ constructor(canvas, childId, fromParentId, toParentId, fromChildGeometry, toChildGeometry, ancestorId, fromAncestorGeometry, toAncestorGeometry) {
4647
+ this.canvas = canvas;
4648
+ this.childId = childId;
4649
+ this.fromParentId = fromParentId;
4650
+ this.toParentId = toParentId;
4651
+ this.fromChildGeometry = fromChildGeometry;
4652
+ this.toChildGeometry = toChildGeometry;
4653
+ this.ancestorId = ancestorId;
4654
+ this.fromAncestorGeometry = fromAncestorGeometry;
4655
+ this.toAncestorGeometry = toAncestorGeometry;
4656
+ }
4657
+ do() {
4658
+ const childNode = this.canvas.model.nodes.get(this.childId);
4659
+ const collabAction1 = new SetParentCollabAction(this.canvas, this.childId, this.toParentId, this.toChildGeometry, this.canvas.collabEngine.freshTimestamp());
4660
+ this.canvas.collabEngine.doCollaboratively(collabAction1);
4661
+ if (this.ancestorId !== undefined && this.toAncestorGeometry !== undefined) {
4662
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.toAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4663
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4664
+ }
4665
+ return childNode !== undefined;
4666
+ }
4667
+ undo() {
4668
+ const childNode = this.canvas.model.nodes.get(this.childId);
4669
+ const collabAction1 = new SetParentCollabAction(this.canvas, this.childId, this.fromParentId, this.fromChildGeometry, this.canvas.collabEngine.freshTimestamp());
4670
+ this.canvas.collabEngine.doCollaboratively(collabAction1);
4671
+ if (this.ancestorId !== undefined && this.fromAncestorGeometry !== undefined) {
4672
+ const collabAction2 = new SetGeometryCollabAction(this.canvas, this.ancestorId, this.fromAncestorGeometry, this.canvas.collabEngine.freshTimestamp());
4673
+ this.canvas.collabEngine.doCollaboratively(collabAction2);
4674
+ }
4675
+ return childNode !== undefined;
4676
+ }
4677
+ redo() {
4678
+ return this.do();
4679
+ }
4680
+ }
4144
4681
  /**
4145
4682
  * Action which consists of adding a connection.
4146
4683
  * @private
@@ -4405,21 +4942,97 @@ class PasteAction {
4405
4942
  }
4406
4943
 
4407
4944
  /**
4408
- * Represents an action taken by the user on the diagram.
4945
+ * Represents an action taken by the user on the diagram which doesn't have an impact on the diagram's model.
4946
+ * Contrast with {@link DiagramAction} which does have an impact on the diagram's model.
4409
4947
  * @public
4410
4948
  */
4411
4949
  class DiagramEvent {
4412
- constructor(cause, type, target, coords) {
4413
- this.cause = cause;
4950
+ constructor(type) {
4414
4951
  this.type = type;
4415
- this.target = target;
4416
- this.coords = coords;
4417
4952
  this.defaultPrevented = false;
4418
4953
  }
4419
4954
  preventDefault() {
4420
4955
  this.defaultPrevented = true;
4421
4956
  }
4422
4957
  }
4958
+ /**
4959
+ * Diagram user events.
4960
+ * @public
4961
+ */
4962
+ var DiagramEvents;
4963
+ (function (DiagramEvents) {
4964
+ DiagramEvents[DiagramEvents["DoubleClick"] = 0] = "DoubleClick";
4965
+ DiagramEvents[DiagramEvents["SecondaryClick"] = 1] = "SecondaryClick";
4966
+ DiagramEvents[DiagramEvents["Selection"] = 2] = "Selection";
4967
+ DiagramEvents[DiagramEvents["Highlight"] = 3] = "Highlight";
4968
+ })(DiagramEvents || (DiagramEvents = {}));
4969
+ /**
4970
+ * Diagram event which consists of the user performing a double click on the diagram.
4971
+ */
4972
+ class DiagramDoubleClickEvent extends DiagramEvent {
4973
+ /**
4974
+ * Create a diagram double click event.
4975
+ *
4976
+ * @param cause Mouse event which triggered this event.
4977
+ * @param target Diagram element which is targeted by the event, or null if no element was targeted (the diagram background was targeted).
4978
+ * @param coords Optionally, coordinates of the point of the diagram where the event happened.
4979
+ */
4980
+ constructor(cause, target, coords) {
4981
+ super(DiagramEvents.DoubleClick);
4982
+ this.cause = cause;
4983
+ this.target = target;
4984
+ this.coords = coords;
4985
+ }
4986
+ }
4987
+ /**
4988
+ * Diagram event which consists of the user performing a secondary click on the diagram.
4989
+ */
4990
+ class DiagramSecondaryClickEvent extends DiagramEvent {
4991
+ /**
4992
+ * Create a diagram secondary click event.
4993
+ *
4994
+ * @param cause Mouse event which triggered this event.
4995
+ * @param target Diagram element which is targeted by the event, or null if no element was targeted (the diagram background was targeted).
4996
+ * @param coords Optionally, coordinates of the point of the diagram where the event happened.
4997
+ */
4998
+ constructor(cause, target, coords) {
4999
+ super(DiagramEvents.SecondaryClick);
5000
+ this.cause = cause;
5001
+ this.target = target;
5002
+ this.coords = coords;
5003
+ }
5004
+ }
5005
+ /**
5006
+ * Diagram event which consists of the user either adding or removing one or several diagram elements from the user selection.
5007
+ */
5008
+ class DiagramSelectionEvent extends DiagramEvent {
5009
+ /**
5010
+ * Create a diagram selection event.
5011
+ *
5012
+ * @param targets Diagram elements which are targeted by the event.
5013
+ * @param selected `true` if the targets were selected, `false` if the targets were deselected.
5014
+ */
5015
+ constructor(targets, selected) {
5016
+ super(DiagramEvents.Selection);
5017
+ this.targets = targets;
5018
+ this.selected = selected;
5019
+ }
5020
+ }
5021
+ /**
5022
+ * Diagram event which consists of the user highlighting a diagram element.
5023
+ * If the target is `null`, that means that the previously highlighted element was unhighlighted.
5024
+ */
5025
+ class DiagramHighlightedEvent extends DiagramEvent {
5026
+ /**
5027
+ * Create a diagram highlight event.
5028
+ *
5029
+ * @param target Diagram element which is targeted by the event.
5030
+ */
5031
+ constructor(target) {
5032
+ super(DiagramEvents.Highlight);
5033
+ this.target = target;
5034
+ }
5035
+ }
4423
5036
 
4424
5037
  /**
4425
5038
  * A foreign object which is inserted with arbitrary html into a diagram.
@@ -4445,14 +5058,18 @@ class DiagramDecorator extends DiagramElement {
4445
5058
  }
4446
5059
  select() {
4447
5060
  var _a, _b;
4448
- return (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.selectCanvasView()) === null || _b === void 0 ? void 0 : _b.select(`foreignObject#${this.id}`);
5061
+ return (_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.selectCanvasView()) === null || _b === undefined ? undefined : _b.select(`foreignObject#${this.id}`);
4449
5062
  }
4450
5063
  get removed() {
4451
5064
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
4452
5065
  }
4453
5066
  updateInView() {
4454
5067
  var _a;
4455
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateDecoratorsInView(this.id);
5068
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateDecoratorsInView(this.id);
5069
+ }
5070
+ raise() {
5071
+ var _a;
5072
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
4456
5073
  }
4457
5074
  /**
4458
5075
  * Change the coordinates of this decorator to the given coordinates.
@@ -4524,14 +5141,18 @@ class DiagramObject extends DiagramElement {
4524
5141
  }
4525
5142
  select() {
4526
5143
  var _a, _b;
4527
- return (_b = (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.selectCanvasView()) === null || _b === void 0 ? void 0 : _b.select(`foreignObject#${this.id}`);
5144
+ return (_b = (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.selectCanvasView()) === null || _b === undefined ? undefined : _b.select(`foreignObject#${this.id}`);
4528
5145
  }
4529
5146
  get removed() {
4530
5147
  return this.selfRemoved;
4531
5148
  }
4532
5149
  updateInView() {
4533
5150
  var _a;
4534
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateObjectsInView(this.id);
5151
+ (_a = this.model.canvas) === null || _a === undefined ? undefined : _a.updateObjectsInView(this.id);
5152
+ }
5153
+ raise() {
5154
+ var _a;
5155
+ (_a = this.select()) === null || _a === undefined ? undefined : _a.raise();
4535
5156
  }
4536
5157
  /**
4537
5158
  * Change the coordinates of this object to the given coordinates.
@@ -4641,7 +5262,7 @@ class DiagramModel {
4641
5262
  */
4642
5263
  clear() {
4643
5264
  var _a, _b;
4644
- (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.cancelAllUserActions();
5265
+ (_a = this.canvas) === null || _a === undefined ? undefined : _a.cancelAllUserActions();
4645
5266
  this.id = undefined;
4646
5267
  this.name = '';
4647
5268
  this.description = undefined;
@@ -4656,7 +5277,7 @@ class DiagramModel {
4656
5277
  this.objects.clear();
4657
5278
  this.decorators.clear();
4658
5279
  this.valueSet.resetValues();
4659
- (_b = this.canvas) === null || _b === void 0 ? void 0 : _b.updateModelInView();
5280
+ (_b = this.canvas) === null || _b === undefined ? undefined : _b.updateModelInView();
4660
5281
  }
4661
5282
  }
4662
5283
 
@@ -4785,7 +5406,7 @@ class DiagramContextMenu {
4785
5406
  */
4786
5407
  close() {
4787
5408
  var _a;
4788
- (_a = this.contextMenuContainer) === null || _a === void 0 ? void 0 : _a.remove();
5409
+ (_a = this.contextMenuContainer) === null || _a === undefined ? undefined : _a.remove();
4789
5410
  this.contextMenuContainer = undefined;
4790
5411
  }
4791
5412
  }
@@ -4900,6 +5521,7 @@ class DagaExporter {
4900
5521
  }
4901
5522
  for (const node of model.nodes.all(true)) {
4902
5523
  if (!includeCollabMeta && node.removed) continue;
5524
+ if (node.parent !== undefined) continue;
4903
5525
  result.nodes.push(this.exportNode(node, includeCollabMeta));
4904
5526
  }
4905
5527
  for (const connection of model.connections.all(true)) {
@@ -4910,6 +5532,10 @@ class DagaExporter {
4910
5532
  }
4911
5533
  exportNode(node, includeCollabMeta = false) {
4912
5534
  var _a, _b, _c, _d;
5535
+ const children = [];
5536
+ for (const child of node.children) {
5537
+ children.push(this.exportNode(child, includeCollabMeta));
5538
+ }
4913
5539
  const sections = [];
4914
5540
  for (const section of node.sections) {
4915
5541
  const ports = [];
@@ -4918,7 +5544,7 @@ class DagaExporter {
4918
5544
  id: port.id,
4919
5545
  coords: roundPoint(port.coords),
4920
5546
  direction: port.direction,
4921
- label: ((_a = port.label) === null || _a === void 0 ? void 0 : _a.text) || ''
5547
+ label: ((_a = port.label) === null || _a === undefined ? undefined : _a.text) || ''
4922
5548
  }, includeCollabMeta ? {
4923
5549
  collabMeta: Object.assign({
4924
5550
  removed: port.removed,
@@ -4930,7 +5556,7 @@ class DagaExporter {
4930
5556
  sections.push(Object.assign({
4931
5557
  id: section.id,
4932
5558
  ports,
4933
- label: ((_b = section.label) === null || _b === void 0 ? void 0 : _b.text) || '',
5559
+ label: ((_b = section.label) === null || _b === undefined ? undefined : _b.text) || '',
4934
5560
  indexXInNode: section.indexXInNode,
4935
5561
  indexYInNode: section.indexYInNode,
4936
5562
  coords: roundPoint(section.coords),
@@ -4950,7 +5576,7 @@ class DagaExporter {
4950
5576
  id: port.id,
4951
5577
  coords: roundPoint(port.coords),
4952
5578
  direction: port.direction,
4953
- label: ((_c = port.label) === null || _c === void 0 ? void 0 : _c.text) || ''
5579
+ label: ((_c = port.label) === null || _c === undefined ? undefined : _c.text) || ''
4954
5580
  }, includeCollabMeta ? {
4955
5581
  collabMeta: Object.assign({
4956
5582
  removed: port.removed,
@@ -4962,9 +5588,10 @@ class DagaExporter {
4962
5588
  return Object.assign({
4963
5589
  id: node.id,
4964
5590
  type: node.type.id,
5591
+ children,
4965
5592
  sections,
4966
5593
  ports,
4967
- label: ((_d = node.label) === null || _d === void 0 ? void 0 : _d.text) || '',
5594
+ label: ((_d = node.label) === null || _d === undefined ? undefined : _d.text) || '',
4968
5595
  coords: roundPoint(node.coords),
4969
5596
  width: node.width,
4970
5597
  height: node.height,
@@ -4984,8 +5611,8 @@ class DagaExporter {
4984
5611
  return Object.assign({
4985
5612
  id: connection.id,
4986
5613
  type: connection.type.id,
4987
- start: ((_a = connection.start) === null || _a === void 0 ? void 0 : _a.id) || '',
4988
- end: ((_b = connection.end) === null || _b === void 0 ? void 0 : _b.id) || '',
5614
+ start: ((_a = connection.start) === null || _a === undefined ? undefined : _a.id) || '',
5615
+ end: ((_b = connection.end) === null || _b === undefined ? undefined : _b.id) || '',
4989
5616
  startLabel: connection.startLabel,
4990
5617
  middleLabel: connection.middleLabel,
4991
5618
  endLabel: connection.endLabel,
@@ -5205,11 +5832,11 @@ class DiagramUserSelection extends DiagramElementSet {
5205
5832
  openInPropertyEditor(selection) {
5206
5833
  var _a;
5207
5834
  this.makeUpdateValuesAction();
5208
- const propertyEditor = (_a = this.canvas.parentComponent) === null || _a === void 0 ? void 0 : _a.propertyEditor;
5835
+ const propertyEditor = (_a = this.canvas.parentComponent) === null || _a === undefined ? undefined : _a.propertyEditor;
5209
5836
  if (propertyEditor === undefined) {
5210
5837
  return;
5211
5838
  }
5212
- const selectedValueSet = selection === null || selection === void 0 ? void 0 : selection.valueSet;
5839
+ const selectedValueSet = selection === null || selection === undefined ? undefined : selection.valueSet;
5213
5840
  if (selectedValueSet) {
5214
5841
  this.propertyEditorSelection = selection;
5215
5842
  this.propertyEditorValues = structuredClone(selectedValueSet.getValues());
@@ -5251,11 +5878,11 @@ class DiagramUserSelection extends DiagramElementSet {
5251
5878
  const previousSelectionId = this.propertyEditorSelection instanceof DiagramModel ? undefined : this.propertyEditorSelection.id;
5252
5879
  // check if there have been changes in the previously selected ValueSet,
5253
5880
  // and create an UpdateValuesAction if there have
5254
- if (equals(this.propertyEditorValues, (_a = this.propertyEditorSelection) === null || _a === void 0 ? void 0 : _a.valueSet.getValues())) {
5881
+ if (equals(this.propertyEditorValues, (_a = this.propertyEditorSelection) === null || _a === undefined ? undefined : _a.valueSet.getValues())) {
5255
5882
  return;
5256
5883
  }
5257
5884
  const from = this.propertyEditorValues;
5258
- const to = structuredClone((_b = this.propertyEditorSelection) === null || _b === void 0 ? void 0 : _b.valueSet.getValues());
5885
+ const to = structuredClone((_b = this.propertyEditorSelection) === null || _b === undefined ? undefined : _b.valueSet.getValues());
5259
5886
  const [fromDiff, toDiff] = diff(from, to);
5260
5887
  const currentAction = new UpdateValuesAction(this.canvas, previousSelectionId, fromDiff, toDiff);
5261
5888
  currentAction.do();
@@ -5290,7 +5917,7 @@ class DiagramCanvas {
5290
5917
  var _a, _b;
5291
5918
  this._connectionType = value;
5292
5919
  // refresh the palette every time connectionType is set so that the palette keeps track of updates to the connectionType
5293
- (_b = (_a = this.parentComponent) === null || _a === void 0 ? void 0 : _a.palette) === null || _b === void 0 ? void 0 : _b.refreshPalette();
5920
+ (_b = (_a = this.parentComponent) === null || _a === undefined ? undefined : _a.palette) === null || _b === undefined ? undefined : _b.refreshPalette();
5294
5921
  }
5295
5922
  /**
5296
5923
  * Constructs a canvas object.
@@ -5311,24 +5938,23 @@ class DiagramCanvas {
5311
5938
  this.viewInitialized$ = new Subject();
5312
5939
  this.validatorChange$ = new Subject();
5313
5940
  this.diagramChange$ = new Subject();
5314
- this.diagramImportantChange$ = new Subject();
5315
- this.propertyEditorChanges$ = new Subject();
5316
5941
  this.diagramEvent$ = new Subject();
5942
+ this.propertyEditorChanges$ = new Subject();
5317
5943
  this.parentComponent = parentComponent;
5318
5944
  this.model = new DiagramModel(this, undefined, config.name || 'unnamed', '', config.type || '', config.properties || []);
5319
5945
  this.userSelection = new DiagramUserSelection(this);
5320
5946
  this.userHighlight = new DiagramUserHighlight(this);
5321
5947
  this.contextMenu = new DiagramContextMenu(this);
5322
- this.backgroundColor = ((_a = config.canvas) === null || _a === void 0 ? void 0 : _a.backgroundColor) || '#FFFFFF';
5323
- this.gridSize = ((_c = (_b = config.canvas) === null || _b === void 0 ? void 0 : _b.grid) === null || _c === void 0 ? void 0 : _c.enabled) === false || ((_d = config.canvas) === null || _d === void 0 ? void 0 : _d.grid) === undefined ? 0 : Math.abs(((_f = (_e = config.canvas) === null || _e === void 0 ? void 0 : _e.grid) === null || _f === void 0 ? void 0 : _f.spacing) || 10);
5324
- this.gridThickness = Math.abs(((_h = (_g = config.canvas) === null || _g === void 0 ? void 0 : _g.grid) === null || _h === void 0 ? void 0 : _h.thickness) || 0.05);
5325
- this.gridColor = ((_k = (_j = config.canvas) === null || _j === void 0 ? void 0 : _j.grid) === null || _k === void 0 ? void 0 : _k.color) || 'rgba(0, 0, 0, 0.1)';
5326
- this.snapToGrid = ((_m = (_l = config.canvas) === null || _l === void 0 ? void 0 : _l.grid) === null || _m === void 0 ? void 0 : _m.enabled) === false || ((_o = config.canvas) === null || _o === void 0 ? void 0 : _o.grid) === undefined ? false : ((_q = (_p = config.canvas) === null || _p === void 0 ? void 0 : _p.grid) === null || _q === void 0 ? void 0 : _q.snap) || false;
5327
- this.zoomFactor = ((_r = config.canvas) === null || _r === void 0 ? void 0 : _r.zoomFactor) || 2;
5328
- this.panRate = ((_s = config.canvas) === null || _s === void 0 ? void 0 : _s.panRate) || 100;
5948
+ this.backgroundColor = ((_a = config.canvas) === null || _a === undefined ? undefined : _a.backgroundColor) || '#FFFFFF';
5949
+ this.gridSize = ((_c = (_b = config.canvas) === null || _b === undefined ? undefined : _b.grid) === null || _c === undefined ? undefined : _c.enabled) === false || ((_d = config.canvas) === null || _d === undefined ? undefined : _d.grid) === undefined ? 0 : Math.abs(((_f = (_e = config.canvas) === null || _e === undefined ? undefined : _e.grid) === null || _f === undefined ? undefined : _f.spacing) || 10);
5950
+ this.gridThickness = Math.abs(((_h = (_g = config.canvas) === null || _g === undefined ? undefined : _g.grid) === null || _h === undefined ? undefined : _h.thickness) || 0.05);
5951
+ this.gridColor = ((_k = (_j = config.canvas) === null || _j === undefined ? undefined : _j.grid) === null || _k === undefined ? undefined : _k.color) || 'rgba(0, 0, 0, 0.1)';
5952
+ this.snapToGrid = ((_m = (_l = config.canvas) === null || _l === undefined ? undefined : _l.grid) === null || _m === undefined ? undefined : _m.enabled) === false || ((_o = config.canvas) === null || _o === undefined ? undefined : _o.grid) === undefined ? false : ((_q = (_p = config.canvas) === null || _p === undefined ? undefined : _p.grid) === null || _q === undefined ? undefined : _q.snap) || false;
5953
+ this.zoomFactor = ((_r = config.canvas) === null || _r === undefined ? undefined : _r.zoomFactor) || 2;
5954
+ this.panRate = ((_s = config.canvas) === null || _s === undefined ? undefined : _s.panRate) || 100;
5329
5955
  this.inferConnectionType = config.inferConnectionType || false;
5330
5956
  this.multipleSelectionOn = false;
5331
- this.priorityThresholds = ((_t = config.canvas) === null || _t === void 0 ? void 0 : _t.priorityThresholds) || [];
5957
+ this.priorityThresholds = ((_t = config.canvas) === null || _t === undefined ? undefined : _t.priorityThresholds) || [];
5332
5958
  this.priorityThreshold = this.priorityThresholds ? this.priorityThresholds[0] : undefined;
5333
5959
  this.layoutFormat = config.layoutFormat;
5334
5960
  this.userActions = config.userActions || {};
@@ -5372,7 +5998,7 @@ class DiagramCanvas {
5372
5998
  for (const node of this.model.nodes) {
5373
5999
  this.fitNodeInView(node.id);
5374
6000
  }
5375
- (_b = (_a = this.parentComponent) === null || _a === void 0 ? void 0 : _a.palette) === null || _b === void 0 ? void 0 : _b.refreshPalette();
6001
+ (_b = (_a = this.parentComponent) === null || _a === undefined ? undefined : _a.palette) === null || _b === undefined ? undefined : _b.refreshPalette();
5376
6002
  }
5377
6003
  // View methods
5378
6004
  initView(appendTo) {
@@ -5383,7 +6009,7 @@ class DiagramCanvas {
5383
6009
  var _a;
5384
6010
  // focus on the diagram when clicking so that we can focus on the diagram
5385
6011
  // keyboard events only work if we're focusing on the diagram
5386
- (_a = d3.select(this.diagramRoot).node()) === null || _a === void 0 ? void 0 : _a.focus();
6012
+ (_a = d3.select(this.diagramRoot).node()) === null || _a === undefined ? undefined : _a.focus();
5387
6013
  }).on(Events.ContextMenu, event => {
5388
6014
  if (this.dragging) {
5389
6015
  event.preventDefault();
@@ -5391,14 +6017,14 @@ class DiagramCanvas {
5391
6017
  this.dragging = false;
5392
6018
  return;
5393
6019
  }
5394
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, undefined);
6020
+ const diagramEvent = new DiagramSecondaryClickEvent(event, null);
5395
6021
  this.diagramEvent$.next(diagramEvent);
5396
6022
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
5397
6023
  event.preventDefault();
5398
6024
  this.contextMenu.open(event);
5399
6025
  }
5400
6026
  }).on(Events.DoubleClick, event => {
5401
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, undefined);
6027
+ const diagramEvent = new DiagramDoubleClickEvent(event, null);
5402
6028
  this.diagramEvent$.next(diagramEvent);
5403
6029
  }).on(Events.KeyDown, event => {
5404
6030
  if (!event.ctrlKey && (event.key === Keys.Delete || event.key === Keys.Backspace) && this.canUserPerformAction(DiagramActions.Remove)) {
@@ -5414,15 +6040,34 @@ class DiagramCanvas {
5414
6040
  for (const connection of this.model.connections) {
5415
6041
  this.userSelection.add(connection);
5416
6042
  }
6043
+ this.diagramEvent$.next(new DiagramSelectionEvent(this.userSelection.all(), true));
5417
6044
  }
5418
6045
  if (event.ctrlKey && event.key === 'i') {
5419
6046
  event.preventDefault();
5420
6047
  // invert selection
6048
+ const selectedElements = [];
6049
+ const deselectedElements = [];
5421
6050
  for (const node of this.model.nodes) {
5422
6051
  this.userSelection.toggle(node);
6052
+ if (node.selected) {
6053
+ selectedElements.push(node);
6054
+ } else {
6055
+ deselectedElements.push(node);
6056
+ }
5423
6057
  }
5424
6058
  for (const connection of this.model.connections) {
5425
6059
  this.userSelection.toggle(connection);
6060
+ if (connection.selected) {
6061
+ selectedElements.push(connection);
6062
+ } else {
6063
+ deselectedElements.push(connection);
6064
+ }
6065
+ }
6066
+ if (selectedElements.length > 0) {
6067
+ this.diagramEvent$.next(new DiagramSelectionEvent(selectedElements, true));
6068
+ }
6069
+ if (deselectedElements.length > 0) {
6070
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
5426
6071
  }
5427
6072
  }
5428
6073
  if (event.ctrlKey && event.key === 'c') {
@@ -5467,12 +6112,12 @@ class DiagramCanvas {
5467
6112
  if (event.key === Keys.ArrowLeft) {
5468
6113
  event.preventDefault();
5469
6114
  // move left, faster if we're zoomed out and slower if we're zoomed in
5470
- this.translateBy(-this.panRate / this.zoomTransform.k, 0);
6115
+ this.translateBy(this.panRate / this.zoomTransform.k, 0);
5471
6116
  }
5472
6117
  if (event.key === Keys.ArrowRight) {
5473
6118
  event.preventDefault();
5474
6119
  // move right, faster if we're zoomed out and slower if we're zoomed in
5475
- this.translateBy(this.panRate / this.zoomTransform.k, 0);
6120
+ this.translateBy(-this.panRate / this.zoomTransform.k, 0);
5476
6121
  }
5477
6122
  if (event.key === Keys.ArrowDown) {
5478
6123
  event.preventDefault();
@@ -5492,12 +6137,22 @@ class DiagramCanvas {
5492
6137
  this.unfinishedConnection.endCoords = pointerCoords;
5493
6138
  }
5494
6139
  }).on(Events.MouseOver, () => {
5495
- this.userHighlight.clear();
6140
+ if (this.userHighlight.size() > 0) {
6141
+ this.userHighlight.clear();
6142
+ this.diagramEvent$.next(new DiagramHighlightedEvent(null));
6143
+ }
5496
6144
  }).on(Events.Click, () => {
5497
- this.userHighlight.clear();
6145
+ if (this.userHighlight.size() > 0) {
6146
+ this.userHighlight.clear();
6147
+ this.diagramEvent$.next(new DiagramHighlightedEvent(null));
6148
+ }
5498
6149
  this.contextMenu.close();
5499
- this.userSelection.clear();
5500
- this.userSelection.openInPropertyEditor(this.model);
6150
+ if (this.userSelection.size() > 0) {
6151
+ const deselectedElements = this.userSelection.all();
6152
+ this.userSelection.clear();
6153
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
6154
+ this.userSelection.openInPropertyEditor(this.model);
6155
+ }
5501
6156
  }).call(d3.drag().filter(event => {
5502
6157
  return this.multipleSelectionOn || isSecondaryButton(event);
5503
6158
  }).on(DragEvents.Start, event => {
@@ -5539,14 +6194,7 @@ class DiagramCanvas {
5539
6194
  canvasBackgroundPattern.append('circle').attr('cx', this.gridSize / 2).attr('cy', this.gridSize / 2).attr('r', this.gridSize * this.gridThickness).attr('fill', this.gridColor);
5540
6195
  canvasBackground.attr('fill', `url(#${this.backgroundPatternId})`);
5541
6196
  }
5542
- const canvasElements = canvasView.append('g').attr('class', 'daga-canvas-elements');
5543
- canvasElements.append('g').attr('class', 'daga-canvas-nodes');
5544
- canvasElements.append('g').attr('class', 'daga-canvas-sections');
5545
- canvasElements.append('g').attr('class', 'daga-canvas-ports');
5546
- canvasElements.append('g').attr('class', 'daga-canvas-connections');
5547
- canvasElements.append('g').attr('class', 'daga-canvas-fields');
5548
- canvasElements.append('g').attr('class', 'daga-canvas-objects');
5549
- canvasElements.append('g').attr('class', 'daga-canvas-decorators');
6197
+ canvasView.append('g').attr('class', 'daga-canvas-elements');
5550
6198
  this.viewInitialized$.next();
5551
6199
  }
5552
6200
  zoomBy(factor) {
@@ -5604,8 +6252,8 @@ class DiagramCanvas {
5604
6252
  }
5605
6253
  getCoordinatesOnScreen() {
5606
6254
  var _a;
5607
- const rootBoundingClientRect = (_a = this.selectRoot().node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
5608
- const rootDimensions = [(rootBoundingClientRect === null || rootBoundingClientRect === void 0 ? void 0 : rootBoundingClientRect.width) || 0, (rootBoundingClientRect === null || rootBoundingClientRect === void 0 ? void 0 : rootBoundingClientRect.height) || 0];
6255
+ const rootBoundingClientRect = (_a = this.selectRoot().node()) === null || _a === undefined ? undefined : _a.getBoundingClientRect();
6256
+ const rootDimensions = [(rootBoundingClientRect === null || rootBoundingClientRect === undefined ? undefined : rootBoundingClientRect.width) || 0, (rootBoundingClientRect === null || rootBoundingClientRect === undefined ? undefined : rootBoundingClientRect.height) || 0];
5609
6257
  return [[-this.zoomTransform.x / this.zoomTransform.k, -this.zoomTransform.y / this.zoomTransform.k], [(rootDimensions[0] - this.zoomTransform.x) / this.zoomTransform.k, (rootDimensions[1] - this.zoomTransform.y) / this.zoomTransform.k]];
5610
6258
  }
5611
6259
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -5647,7 +6295,7 @@ class DiagramCanvas {
5647
6295
  this.updateDecoratorsInView();
5648
6296
  }
5649
6297
  updateNodesInView(...ids) {
5650
- let updateSelection = this.selectCanvasNodes().selectAll('g.diagram-node').data(this.model.nodes.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6298
+ let updateSelection = this.selectCanvasElements().selectAll('g.diagram-node').data(this.model.nodes.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
5651
6299
  const exitSelection = updateSelection.exit();
5652
6300
  const enterSelection = updateSelection.enter().append('g').attr('id', d => d.id).attr('class', d => `diagram-node${d.type.resizableX ? ' resizable-x' : ''}${d.type.resizableY ? ' resizable-y' : ''} ${d.type.look.lookType}`);
5653
6301
  if (ids && ids.length > 0) {
@@ -5658,12 +6306,16 @@ class DiagramCanvas {
5658
6306
  enterSelection.on(Events.MouseOver, (_event, d) => {
5659
6307
  if (!this.dragging) {
5660
6308
  this.userHighlight.focusOn(d);
6309
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
5661
6310
  }
5662
6311
  }).on(Events.Click, (event, d) => {
5663
6312
  if (!event.ctrlKey && !event.shiftKey) {
6313
+ const deselectedElements = this.userSelection.all();
5664
6314
  this.userSelection.clear();
6315
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
5665
6316
  }
5666
6317
  this.userSelection.toggle(d);
6318
+ this.diagramEvent$.next(new DiagramSelectionEvent([d], d.selected));
5667
6319
  }).on(Events.ContextMenu, (event, d) => {
5668
6320
  if (this.dragging) {
5669
6321
  event.preventDefault();
@@ -5671,16 +6323,18 @@ class DiagramCanvas {
5671
6323
  this.dragging = false;
5672
6324
  return;
5673
6325
  }
5674
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, d);
6326
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
5675
6327
  this.diagramEvent$.next(diagramEvent);
5676
6328
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
5677
6329
  event.preventDefault();
5678
6330
  this.userHighlight.focusOn(d);
6331
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
5679
6332
  this.userSelection.add(d);
6333
+ this.diagramEvent$.next(new DiagramSelectionEvent([d], true));
5680
6334
  this.contextMenu.open(event);
5681
6335
  }
5682
6336
  }).on(Events.DoubleClick, (event, d) => {
5683
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
6337
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
5684
6338
  this.diagramEvent$.next(diagramEvent);
5685
6339
  }).call(d3.drag().filter(event => {
5686
6340
  this.secondaryButton = isSecondaryButton(event);
@@ -5870,11 +6524,11 @@ class DiagramCanvas {
5870
6524
  mergeSelection.filter('.resizable-y').select('line.bottom-resizer').attr('x1', 0).attr('x2', d => d.width).attr('y1', d => d.height - RESIZER_THICKNESS / 2).attr('y2', d => d.height - RESIZER_THICKNESS / 2);
5871
6525
  }
5872
6526
  updateSectionsInView(...ids) {
5873
- let updateSelection = this.selectCanvasSections().selectAll('g.diagram-section').data(this.model.sections.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6527
+ 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);
5874
6528
  const exitSelection = updateSelection.exit();
5875
6529
  const enterSelection = updateSelection.enter().append('g').attr('id', d => d.id).attr('class', d => {
5876
6530
  var _a, _b, _c, _d, _e, _f;
5877
- 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' : ''} ${(_f = (_e = d.getConfig()) === null || _e === void 0 ? void 0 : _e.look) === null || _f === void 0 ? void 0 : _f.lookType}`;
6531
+ return `diagram-section${((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) ? ' resizable-x' : ''}${((_d = (_c = d.node) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.resizableY) ? ' resizable-y' : ''} ${(_f = (_e = d.getConfig()) === null || _e === undefined ? undefined : _e.look) === null || _f === undefined ? undefined : _f.lookType}`;
5878
6532
  });
5879
6533
  if (ids && ids.length > 0) {
5880
6534
  updateSelection = updateSelection.filter(d => ids.includes(d.id));
@@ -5884,12 +6538,17 @@ class DiagramCanvas {
5884
6538
  enterSelection.on(Events.MouseOver, (_event, d) => {
5885
6539
  if (!this.dragging) {
5886
6540
  this.userHighlight.focusOn(d);
6541
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
5887
6542
  }
5888
6543
  }).on(Events.Click, (event, d) => {
5889
6544
  if (!event.ctrlKey && !event.shiftKey) {
6545
+ const deselectedElements = this.userSelection.all();
5890
6546
  this.userSelection.clear();
6547
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
5891
6548
  }
5892
- this.userSelection.toggle(getRelatedNodeOrItself(d));
6549
+ const elementToBeToggled = getRelatedNodeOrItself(d);
6550
+ this.userSelection.toggle(elementToBeToggled);
6551
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToBeToggled], elementToBeToggled.selected));
5893
6552
  }).on(Events.ContextMenu, (event, d) => {
5894
6553
  if (this.dragging) {
5895
6554
  event.preventDefault();
@@ -5897,17 +6556,19 @@ class DiagramCanvas {
5897
6556
  this.dragging = false;
5898
6557
  return;
5899
6558
  }
5900
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, d);
6559
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
5901
6560
  this.diagramEvent$.next(diagramEvent);
5902
6561
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
5903
6562
  event.preventDefault();
5904
6563
  const elementToSelect = getRelatedNodeOrItself(d);
5905
6564
  this.userHighlight.focusOn(elementToSelect);
6565
+ this.diagramEvent$.next(new DiagramHighlightedEvent(elementToSelect));
5906
6566
  this.userSelection.add(elementToSelect);
6567
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToSelect], true));
5907
6568
  this.contextMenu.open(event);
5908
6569
  }
5909
6570
  }).on(Events.DoubleClick, (event, d) => {
5910
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
6571
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
5911
6572
  this.diagramEvent$.next(diagramEvent);
5912
6573
  }).call(d3.drag().filter(event => {
5913
6574
  this.secondaryButton = isSecondaryButton(event);
@@ -5916,7 +6577,7 @@ class DiagramCanvas {
5916
6577
  if (this.multipleSelectionOn || this.secondaryButton) {
5917
6578
  this.startMultipleSelection(event);
5918
6579
  } else {
5919
- const node = d === null || d === void 0 ? void 0 : d.node;
6580
+ const node = d === null || d === undefined ? undefined : d.node;
5920
6581
  if (node) {
5921
6582
  this.startMovingNode(event, node);
5922
6583
  } else {
@@ -5927,7 +6588,7 @@ class DiagramCanvas {
5927
6588
  if (this.multipleSelectionOn || this.secondaryButton) {
5928
6589
  this.continueMultipleSelection(event);
5929
6590
  } else {
5930
- const node = d === null || d === void 0 ? void 0 : d.node;
6591
+ const node = d === null || d === undefined ? undefined : d.node;
5931
6592
  if (node) {
5932
6593
  this.continueMovingNode(event, node);
5933
6594
  } else {
@@ -5938,7 +6599,7 @@ class DiagramCanvas {
5938
6599
  if (this.multipleSelectionOn || this.secondaryButton) {
5939
6600
  this.finishMultipleSelection(event);
5940
6601
  } else {
5941
- const node = d === null || d === void 0 ? void 0 : d.node;
6602
+ const node = d === null || d === undefined ? undefined : d.node;
5942
6603
  if (node) {
5943
6604
  this.finishMovingNode(event, node);
5944
6605
  } else {
@@ -5960,17 +6621,17 @@ class DiagramCanvas {
5960
6621
  enterSelection.filter('.stretchable-image-look').append('image').attr('class', 'bottom-right-image').attr('preserveAspectRatio', 'none');
5961
6622
  enterSelection.filter('.resizable-x').append('line').attr('class', 'left-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
5962
6623
  var _a, _b;
5963
- 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) {
6624
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
5964
6625
  setCursorStyle(CursorStyle.EWResize);
5965
6626
  }
5966
6627
  }).on(Events.MouseOut, (_event, d) => {
5967
6628
  var _a, _b;
5968
- 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) {
6629
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
5969
6630
  setCursorStyle();
5970
6631
  }
5971
6632
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
5972
6633
  var _a, _b;
5973
- 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) {
6634
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
5974
6635
  setCursorStyle(CursorStyle.EWResize);
5975
6636
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
5976
6637
  } else {
@@ -5978,13 +6639,13 @@ class DiagramCanvas {
5978
6639
  }
5979
6640
  }).on(DragEvents.Drag, (event, d) => {
5980
6641
  var _a, _b;
5981
- 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) {
6642
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
5982
6643
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
5983
6644
  d.node.stretchSections(Side.Left, d.coords[0] - pointerCoords[0], d.indexXInNode, d.indexYInNode);
5984
6645
  }
5985
6646
  }).on(DragEvents.End, (event, d) => {
5986
6647
  var _a, _b;
5987
- 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) {
6648
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
5988
6649
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
5989
6650
  if (this.snapToGrid) {
5990
6651
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -5999,17 +6660,17 @@ class DiagramCanvas {
5999
6660
  }));
6000
6661
  enterSelection.filter('.resizable-y').append('line').attr('class', 'top-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
6001
6662
  var _a, _b;
6002
- 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) {
6663
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6003
6664
  setCursorStyle(CursorStyle.NSResize);
6004
6665
  }
6005
6666
  }).on(Events.MouseOut, (_event, d) => {
6006
6667
  var _a, _b;
6007
- 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) {
6668
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6008
6669
  setCursorStyle();
6009
6670
  }
6010
6671
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
6011
6672
  var _a, _b;
6012
- 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) {
6673
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6013
6674
  setCursorStyle(CursorStyle.NSResize);
6014
6675
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
6015
6676
  } else {
@@ -6017,13 +6678,13 @@ class DiagramCanvas {
6017
6678
  }
6018
6679
  }).on(DragEvents.Drag, (event, d) => {
6019
6680
  var _a, _b;
6020
- 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) {
6681
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6021
6682
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6022
6683
  d.node.stretchSections(Side.Top, d.coords[1] - pointerCoords[1], d.indexXInNode, d.indexYInNode);
6023
6684
  }
6024
6685
  }).on(DragEvents.End, (event, d) => {
6025
6686
  var _a, _b;
6026
- 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) {
6687
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
6027
6688
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6028
6689
  if (this.snapToGrid) {
6029
6690
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -6038,17 +6699,17 @@ class DiagramCanvas {
6038
6699
  }));
6039
6700
  enterSelection.filter('.resizable-x').append('line').attr('class', 'right-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
6040
6701
  var _a, _b;
6041
- 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) {
6702
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
6042
6703
  setCursorStyle(CursorStyle.EWResize);
6043
6704
  }
6044
6705
  }).on(Events.MouseOut, (_event, d) => {
6045
6706
  var _a, _b;
6046
- 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) {
6707
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
6047
6708
  setCursorStyle();
6048
6709
  }
6049
6710
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
6050
6711
  var _a, _b;
6051
- 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) {
6712
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
6052
6713
  setCursorStyle(CursorStyle.EWResize);
6053
6714
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
6054
6715
  } else {
@@ -6056,13 +6717,13 @@ class DiagramCanvas {
6056
6717
  }
6057
6718
  }).on(DragEvents.Drag, (event, d) => {
6058
6719
  var _a, _b;
6059
- 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) {
6720
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed) {
6060
6721
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6061
6722
  d.node.stretchSections(Side.Right, pointerCoords[0] - (d.coords[0] + d.width), d.indexXInNode, d.indexYInNode);
6062
6723
  }
6063
6724
  }).on(DragEvents.End, (event, d) => {
6064
6725
  var _a, _b;
6065
- 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) {
6726
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableX) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
6066
6727
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6067
6728
  if (this.snapToGrid) {
6068
6729
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -6077,17 +6738,17 @@ class DiagramCanvas {
6077
6738
  }));
6078
6739
  enterSelection.filter('.resizable-y').append('line').attr('class', 'bottom-resizer').attr('stroke', 'transparent').attr('stroke-width', `${RESIZER_THICKNESS}px`).on(Events.MouseOver, (_event, d) => {
6079
6740
  var _a, _b;
6080
- 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) {
6741
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6081
6742
  setCursorStyle(CursorStyle.NSResize);
6082
6743
  }
6083
6744
  }).on(Events.MouseOut, (_event, d) => {
6084
6745
  var _a, _b;
6085
- 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) {
6746
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6086
6747
  setCursorStyle();
6087
6748
  }
6088
6749
  }).call(d3.drag().on(DragEvents.Start, (_event, d) => {
6089
6750
  var _a, _b;
6090
- 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) {
6751
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6091
6752
  setCursorStyle(CursorStyle.NSResize);
6092
6753
  this.currentAction = new SetGeometryAction(this, DiagramActions.StretchSection, d.node.id, d.node.getGeometry(), d.node.getGeometry());
6093
6754
  } else {
@@ -6095,13 +6756,13 @@ class DiagramCanvas {
6095
6756
  }
6096
6757
  }).on(DragEvents.Drag, (event, d) => {
6097
6758
  var _a, _b;
6098
- 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) {
6759
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed) {
6099
6760
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6100
6761
  d.node.stretchSections(Side.Bottom, pointerCoords[1] - (d.coords[1] + d.height), d.indexXInNode, d.indexYInNode);
6101
6762
  }
6102
6763
  }).on(DragEvents.End, (event, d) => {
6103
6764
  var _a, _b;
6104
- 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) {
6765
+ if (this.canUserPerformAction(DiagramActions.StretchSection) && ((_b = (_a = d.node) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.resizableY) && !d.removed && this.currentAction instanceof SetGeometryAction && this.currentAction.intent === DiagramActions.StretchSection) {
6105
6766
  let pointerCoords = this.getPointerLocationRelativeToCanvas(event);
6106
6767
  if (this.snapToGrid) {
6107
6768
  pointerCoords = this.getClosestGridPoint(pointerCoords);
@@ -6117,143 +6778,143 @@ class DiagramCanvas {
6117
6778
  mergeSelection.attr('transform', d => `translate(${d.coords[0]},${d.coords[1]})`).attr('opacity', d => d.removed ? 0.5 : 1);
6118
6779
  mergeSelection.filter('.shaped-look').select('path').attr('d', d => {
6119
6780
  var _a;
6120
- return generalClosedPath(((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).shape, 0, 0, d.width, d.height);
6781
+ return generalClosedPath(((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).shape, 0, 0, d.width, d.height);
6121
6782
  }).attr('fill', d => {
6122
6783
  var _a, _b;
6123
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedFillColor : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).fillColor;
6784
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedFillColor : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).fillColor;
6124
6785
  }).attr('stroke', d => {
6125
6786
  var _a, _b;
6126
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBorderColor : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).borderColor;
6787
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBorderColor : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).borderColor;
6127
6788
  }).attr('stroke-width', d => `${d.highlighted ? 3 : 1}px`);
6128
6789
  mergeSelection.filter('.image-look').select('image').attr('x', 0).attr('y', 0).attr('width', d => d.width).attr('height', d => d.height).attr('href', d => {
6129
6790
  var _a, _b;
6130
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImage : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImage;
6791
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImage : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImage;
6131
6792
  });
6132
6793
  mergeSelection.filter('.stretchable-image-look').select('image.top-left-image').attr('x', 0).attr('y', 0).attr('width', d => {
6133
6794
  var _a;
6134
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6795
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6135
6796
  }).attr('height', d => {
6136
6797
  var _a;
6137
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6798
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6138
6799
  }).attr('href', d => {
6139
6800
  var _a, _b;
6140
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageTopLeft : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageTopLeft;
6801
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageTopLeft : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageTopLeft;
6141
6802
  });
6142
6803
  mergeSelection.filter('.stretchable-image-look').select('image.top-image').attr('x', d => {
6143
6804
  var _a;
6144
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6805
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6145
6806
  }).attr('y', 0).attr('width', d => {
6146
6807
  var _a, _b;
6147
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).leftMargin;
6808
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).leftMargin;
6148
6809
  }).attr('height', d => {
6149
6810
  var _a;
6150
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6811
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6151
6812
  }).attr('href', d => {
6152
6813
  var _a, _b;
6153
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageTop : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageTop;
6814
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageTop : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageTop;
6154
6815
  });
6155
6816
  mergeSelection.filter('.stretchable-image-look').select('image.top-right-image').attr('x', d => {
6156
6817
  var _a;
6157
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6818
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6158
6819
  }).attr('y', 0).attr('width', d => {
6159
6820
  var _a;
6160
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6821
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6161
6822
  }).attr('height', d => {
6162
6823
  var _a;
6163
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6824
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6164
6825
  }).attr('href', d => {
6165
6826
  var _a, _b;
6166
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageTopRight : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageTopRight;
6827
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageTopRight : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageTopRight;
6167
6828
  });
6168
6829
  mergeSelection.filter('.stretchable-image-look').select('image.left-image').attr('x', 0).attr('y', d => {
6169
6830
  var _a;
6170
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6831
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6171
6832
  }).attr('width', d => {
6172
6833
  var _a;
6173
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6834
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6174
6835
  }).attr('height', d => {
6175
6836
  var _a, _b;
6176
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).topMargin;
6837
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).topMargin;
6177
6838
  }).attr('href', d => {
6178
6839
  var _a, _b;
6179
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageLeft : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageLeft;
6840
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageLeft : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageLeft;
6180
6841
  });
6181
6842
  mergeSelection.filter('.stretchable-image-look').select('image.center-image').attr('x', d => {
6182
6843
  var _a;
6183
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6844
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6184
6845
  }).attr('y', d => {
6185
6846
  var _a;
6186
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6847
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6187
6848
  }).attr('width', d => {
6188
6849
  var _a, _b;
6189
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).leftMargin;
6850
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).leftMargin;
6190
6851
  }).attr('height', d => {
6191
6852
  var _a, _b;
6192
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).topMargin;
6853
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).topMargin;
6193
6854
  }).attr('href', d => {
6194
6855
  var _a, _b;
6195
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageCenter : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageCenter;
6856
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageCenter : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageCenter;
6196
6857
  });
6197
6858
  mergeSelection.filter('.stretchable-image-look').select('image.right-image').attr('x', d => {
6198
6859
  var _a;
6199
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6860
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6200
6861
  }).attr('y', d => {
6201
6862
  var _a;
6202
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).topMargin;
6863
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).topMargin;
6203
6864
  }).attr('width', d => {
6204
6865
  var _a;
6205
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6866
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6206
6867
  }).attr('height', d => {
6207
6868
  var _a, _b;
6208
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).topMargin;
6869
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).topMargin;
6209
6870
  }).attr('href', d => {
6210
6871
  var _a, _b;
6211
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageRight : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageRight;
6872
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageRight : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageRight;
6212
6873
  });
6213
6874
  mergeSelection.filter('.stretchable-image-look').select('image.bottom-left-image').attr('x', 0).attr('y', d => {
6214
6875
  var _a;
6215
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6876
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6216
6877
  }).attr('width', d => {
6217
6878
  var _a;
6218
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6879
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6219
6880
  }).attr('height', d => {
6220
6881
  var _a;
6221
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6882
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6222
6883
  }).attr('href', d => {
6223
6884
  var _a, _b;
6224
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageBottomLeft : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageBottomLeft;
6885
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageBottomLeft : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageBottomLeft;
6225
6886
  });
6226
6887
  mergeSelection.filter('.stretchable-image-look').select('image.bottom-image').attr('x', d => {
6227
6888
  var _a;
6228
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).leftMargin;
6889
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).leftMargin;
6229
6890
  }).attr('y', d => {
6230
6891
  var _a;
6231
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6892
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6232
6893
  }).attr('width', d => {
6233
6894
  var _a, _b;
6234
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).leftMargin;
6895
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin - ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).leftMargin;
6235
6896
  }).attr('height', d => {
6236
6897
  var _a;
6237
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6898
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6238
6899
  }).attr('href', d => {
6239
6900
  var _a, _b;
6240
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageBottom : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageBottom;
6901
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageBottom : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageBottom;
6241
6902
  });
6242
6903
  mergeSelection.filter('.stretchable-image-look').select('image.bottom-right-image').attr('x', d => {
6243
6904
  var _a;
6244
- return d.width - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6905
+ return d.width - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6245
6906
  }).attr('y', d => {
6246
6907
  var _a;
6247
- return d.height - ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6908
+ return d.height - ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6248
6909
  }).attr('width', d => {
6249
6910
  var _a;
6250
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).rightMargin;
6911
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).rightMargin;
6251
6912
  }).attr('height', d => {
6252
6913
  var _a;
6253
- return ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).bottomMargin;
6914
+ return ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).bottomMargin;
6254
6915
  }).attr('href', d => {
6255
6916
  var _a, _b;
6256
- return d.selected ? ((_a = d.getConfig()) === null || _a === void 0 ? void 0 : _a.look).selectedBackgroundImageBottomRight : ((_b = d.getConfig()) === null || _b === void 0 ? void 0 : _b.look).backgroundImageBottomRight;
6917
+ return d.selected ? ((_a = d.getConfig()) === null || _a === undefined ? undefined : _a.look).selectedBackgroundImageBottomRight : ((_b = d.getConfig()) === null || _b === undefined ? undefined : _b.look).backgroundImageBottomRight;
6257
6918
  });
6258
6919
  mergeSelection.filter('.resizable-x').select('line.left-resizer').attr('x1', RESIZER_THICKNESS / 2).attr('x2', RESIZER_THICKNESS / 2).attr('y1', 0).attr('y2', d => d.height);
6259
6920
  mergeSelection.filter('.resizable-y').select('line.top-resizer').attr('x1', 0).attr('x2', d => d.width).attr('y1', RESIZER_THICKNESS / 2).attr('y2', RESIZER_THICKNESS / 2);
@@ -6261,7 +6922,7 @@ class DiagramCanvas {
6261
6922
  mergeSelection.filter('.resizable-y').select('line.bottom-resizer').attr('x1', 0).attr('x2', d => d.width).attr('y1', d => d.height - RESIZER_THICKNESS / 2).attr('y2', d => d.height - RESIZER_THICKNESS / 2);
6262
6923
  }
6263
6924
  updatePortsInView(...ids) {
6264
- let updateSelection = this.selectCanvasPorts().selectAll('g.diagram-port').data(this.model.ports.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6925
+ let updateSelection = this.selectCanvasElements().selectAll('g.diagram-port').data(this.model.ports.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6265
6926
  const exitSelection = updateSelection.exit();
6266
6927
  const enterSelection = updateSelection.enter().append('g').attr('id', d => d.id).attr('class', 'diagram-port');
6267
6928
  if (ids && ids.length > 0) {
@@ -6274,9 +6935,10 @@ class DiagramCanvas {
6274
6935
  if (!this.unfinishedConnection && !this.dragging) {
6275
6936
  // if there is an unfinished connection, the port will be highlighted automatically if the pointer is close
6276
6937
  this.userHighlight.focusOn(d);
6938
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
6277
6939
  }
6278
6940
  if (this.unfinishedConnection) {
6279
- const canConnectionFinishAtThisPort = this.unfinishedConnection.type.canStartFromType(((_c = (_b = (_a = this.unfinishedConnection.start) === null || _a === void 0 ? void 0 : _a.getNode()) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_e = (_d = d.getNode()) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.id) || '') || this.unfinishedConnection.type.canStartFromType(((_g = (_f = d.getNode()) === null || _f === void 0 ? void 0 : _f.type) === null || _g === void 0 ? void 0 : _g.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_k = (_j = (_h = this.unfinishedConnection.start) === null || _h === void 0 ? void 0 : _h.getNode()) === null || _j === void 0 ? void 0 : _j.type) === null || _k === void 0 ? void 0 : _k.id) || '');
6941
+ const canConnectionFinishAtThisPort = this.unfinishedConnection.type.canStartFromType(((_c = (_b = (_a = this.unfinishedConnection.start) === null || _a === undefined ? undefined : _a.getNode()) === null || _b === undefined ? undefined : _b.type) === null || _c === undefined ? undefined : _c.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_e = (_d = d.getNode()) === null || _d === undefined ? undefined : _d.type) === null || _e === undefined ? undefined : _e.id) || '') || this.unfinishedConnection.type.canStartFromType(((_g = (_f = d.getNode()) === null || _f === undefined ? undefined : _f.type) === null || _g === undefined ? undefined : _g.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_k = (_j = (_h = this.unfinishedConnection.start) === null || _h === undefined ? undefined : _h.getNode()) === null || _j === undefined ? undefined : _j.type) === null || _k === undefined ? undefined : _k.id) || '');
6280
6942
  if (!canConnectionFinishAtThisPort) {
6281
6943
  setCursorStyle(CursorStyle.NoDrop);
6282
6944
  }
@@ -6287,9 +6949,13 @@ class DiagramCanvas {
6287
6949
  }
6288
6950
  }).on(Events.Click, (event, d) => {
6289
6951
  if (!event.ctrlKey && !event.shiftKey) {
6952
+ const deselectedElements = this.userSelection.all();
6290
6953
  this.userSelection.clear();
6954
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
6291
6955
  }
6292
- this.userSelection.toggle(getRelatedNodeOrItself(d));
6956
+ const elementToBeToggled = getRelatedNodeOrItself(d);
6957
+ this.userSelection.toggle(elementToBeToggled);
6958
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToBeToggled], elementToBeToggled.selected));
6293
6959
  }).on(Events.ContextMenu, (event, d) => {
6294
6960
  if (this.dragging) {
6295
6961
  event.preventDefault();
@@ -6297,17 +6963,19 @@ class DiagramCanvas {
6297
6963
  this.dragging = false;
6298
6964
  return;
6299
6965
  }
6300
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, d);
6966
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
6301
6967
  this.diagramEvent$.next(diagramEvent);
6302
6968
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
6303
6969
  event.preventDefault();
6304
6970
  const elementToSelect = getRelatedNodeOrItself(d);
6305
6971
  this.userHighlight.focusOn(elementToSelect);
6972
+ this.diagramEvent$.next(new DiagramHighlightedEvent(elementToSelect));
6306
6973
  this.userSelection.add(elementToSelect);
6974
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToSelect], true));
6307
6975
  this.contextMenu.open(event);
6308
6976
  }
6309
6977
  }).on(Events.DoubleClick, (event, d) => {
6310
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
6978
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
6311
6979
  this.diagramEvent$.next(diagramEvent);
6312
6980
  }).call(d3.drag().filter(event => {
6313
6981
  this.secondaryButton = isSecondaryButton(event);
@@ -6335,8 +7003,8 @@ class DiagramCanvas {
6335
7003
  if (this.canUserPerformAction(DiagramActions.AddConnection) && !d.removed) {
6336
7004
  if (this.unfinishedConnection !== undefined) {
6337
7005
  const endCoords = [event.x, event.y];
6338
- (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.attr('d', getConnectionPath(this.unfinishedConnection.type.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.type.width, (_b = this.unfinishedConnection.startMarkerLook) === null || _b === void 0 ? void 0 : _b.markerWidth, (_c = this.unfinishedConnection.endMarkerLook) === null || _c === void 0 ? void 0 : _c.markerWidth));
6339
- const unfinishedConnectionGhostNode = (_d = this.unfinishedConnectionTracer) === null || _d === void 0 ? void 0 : _d.node();
7006
+ (_a = this.unfinishedConnectionTracer) === null || _a === undefined ? undefined : _a.attr('d', getConnectionPath(this.unfinishedConnection.type.shape, this.unfinishedConnection.startCoords, endCoords, this.unfinishedConnection.startDirection, this.unfinishedConnection.endDirection, this.unfinishedConnection.type.width, (_b = this.unfinishedConnection.startMarkerLook) === null || _b === undefined ? undefined : _b.markerWidth, (_c = this.unfinishedConnection.endMarkerLook) === null || _c === undefined ? undefined : _c.markerWidth));
7007
+ const unfinishedConnectionGhostNode = (_d = this.unfinishedConnectionTracer) === null || _d === undefined ? undefined : _d.node();
6340
7008
  if (unfinishedConnectionGhostNode) {
6341
7009
  let margin = 2;
6342
7010
  const unfinishedConnectionTotalLength = unfinishedConnectionGhostNode.getTotalLength();
@@ -6377,7 +7045,7 @@ class DiagramCanvas {
6377
7045
  this.finishMultipleSelection(event);
6378
7046
  } else {
6379
7047
  if (this.canUserPerformAction(DiagramActions.AddConnection) && !d.removed) {
6380
- (_a = this.unfinishedConnectionTracer) === null || _a === void 0 ? void 0 : _a.remove();
7048
+ (_a = this.unfinishedConnectionTracer) === null || _a === undefined ? undefined : _a.remove();
6381
7049
  const userHighlight = this.userHighlight.getFocus();
6382
7050
  if (userHighlight instanceof DiagramPort) {
6383
7051
  this.finishConnection(userHighlight);
@@ -6415,7 +7083,7 @@ class DiagramCanvas {
6415
7083
  if (this.unfinishedConnection) {
6416
7084
  connectionList.push(this.unfinishedConnection);
6417
7085
  }
6418
- let updateSelection = this.selectCanvasConnections().selectAll('g.diagram-connection').data(connectionList, d => d.id);
7086
+ let updateSelection = this.selectCanvasElements().selectAll('g.diagram-connection').data(connectionList, d => d.id);
6419
7087
  const exitSelection = updateSelection.exit();
6420
7088
  const enterSelection = updateSelection.enter().append('g').attr('id', d => d.id).attr('class', 'diagram-connection');
6421
7089
  if (ids && ids.length > 0) {
@@ -6426,12 +7094,16 @@ class DiagramCanvas {
6426
7094
  enterSelection.on(Events.MouseOver, (_event, d) => {
6427
7095
  if (d.end !== undefined && !this.dragging) {
6428
7096
  this.userHighlight.focusOn(d);
7097
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
6429
7098
  }
6430
7099
  }).on(Events.Click, (event, d) => {
6431
7100
  if (!event.ctrlKey && !event.shiftKey) {
7101
+ const deselectedElements = this.userSelection.all();
6432
7102
  this.userSelection.clear();
7103
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
6433
7104
  }
6434
7105
  this.userSelection.toggle(d);
7106
+ this.diagramEvent$.next(new DiagramSelectionEvent([d], d.selected));
6435
7107
  }).on(Events.ContextMenu, (event, d) => {
6436
7108
  if (this.dragging) {
6437
7109
  event.preventDefault();
@@ -6439,16 +7111,18 @@ class DiagramCanvas {
6439
7111
  this.dragging = false;
6440
7112
  return;
6441
7113
  }
6442
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, d);
7114
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
6443
7115
  this.diagramEvent$.next(diagramEvent);
6444
7116
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
6445
7117
  event.preventDefault();
6446
7118
  this.userHighlight.focusOn(d);
7119
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
6447
7120
  this.userSelection.add(d);
7121
+ this.diagramEvent$.next(new DiagramSelectionEvent([d], true));
6448
7122
  this.contextMenu.open(event);
6449
7123
  }
6450
7124
  }).on(Events.DoubleClick, (event, d) => {
6451
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
7125
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
6452
7126
  this.diagramEvent$.next(diagramEvent);
6453
7127
  }).call(d3.drag().filter(event => {
6454
7128
  this.secondaryButton = isSecondaryButton(event);
@@ -6475,11 +7149,11 @@ class DiagramCanvas {
6475
7149
  enterSelection.select('g.diagram-connection-end-label').append('text').style('user-select', 'none');
6476
7150
  mergeSelection.attr('opacity', d => d.removed ? 0.5 : 1).select('path.diagram-connection-path').attr('d', d => {
6477
7151
  var _a, _b;
6478
- return getConnectionPath(d.type.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.width, (_a = d.startMarkerLook) === null || _a === void 0 ? void 0 : _a.markerWidth, (_b = d.endMarkerLook) === null || _b === void 0 ? void 0 : _b.markerWidth);
7152
+ return getConnectionPath(d.type.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.width, (_a = d.startMarkerLook) === null || _a === undefined ? undefined : _a.markerWidth, (_b = d.endMarkerLook) === null || _b === undefined ? undefined : _b.markerWidth);
6479
7153
  }).attr('marker-start', d => `url(#${d.id}-start-marker)`).attr('marker-end', d => `url(#${d.id}-end-marker)`).attr('stroke', d => d.selected ? d.type.selectedColor : d.type.color).attr('stroke-width', d => `${d.highlighted ? d.type.width + 1 : d.type.width}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.type.style, d.type.width)).attr('fill', 'none');
6480
7154
  mergeSelection.select('path.diagram-connection-path-box').attr('d', d => {
6481
7155
  var _a, _b;
6482
- return getConnectionPath(d.type.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.width, (_a = d.startMarkerLook) === null || _a === void 0 ? void 0 : _a.markerWidth, (_b = d.endMarkerLook) === null || _b === void 0 ? void 0 : _b.markerWidth);
7156
+ return getConnectionPath(d.type.shape, d.startCoords, d.endCoords, d.startDirection, d.endDirection, d.type.width, (_a = d.startMarkerLook) === null || _a === undefined ? undefined : _a.markerWidth, (_b = d.endMarkerLook) === null || _b === undefined ? undefined : _b.markerWidth);
6483
7157
  }).attr('stroke', 'transparent')
6484
7158
  // allow generating pointer events even when it is transparent
6485
7159
  .attr('pointer-events', 'stroke').attr('stroke-width', d => `${d.type.width + CONNECTION_PATH_BOX_THICKNESS}px`).attr('stroke-dasharray', d => lineStyleDasharray(d.type.style, d.type.width)).attr('fill', 'none');
@@ -6489,7 +7163,7 @@ class DiagramCanvas {
6489
7163
  });
6490
7164
  }
6491
7165
  updateFieldsInView(...ids) {
6492
- let updateSelection = this.selectCanvasFields().selectAll('foreignObject.diagram-field').data(this.model.fields.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
7166
+ let updateSelection = this.selectCanvasElements().selectAll('foreignObject.diagram-field').data(this.model.fields.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6493
7167
  const exitSelection = updateSelection.exit();
6494
7168
  const enterSelection = updateSelection.enter().append('foreignObject').attr('id', d => d.id).attr('class', 'diagram-field');
6495
7169
  if (ids && ids.length > 0) {
@@ -6500,12 +7174,17 @@ class DiagramCanvas {
6500
7174
  enterSelection.style('box-sizing', 'border-box').on(Events.MouseOver, (_event, d) => {
6501
7175
  if (!this.dragging) {
6502
7176
  this.userHighlight.focusOn(d);
7177
+ this.diagramEvent$.next(new DiagramHighlightedEvent(d));
6503
7178
  }
6504
7179
  }).on(Events.Click, (event, d) => {
6505
7180
  if (!event.ctrlKey && !event.shiftKey) {
7181
+ const deselectedElements = this.userSelection.all();
6506
7182
  this.userSelection.clear();
7183
+ this.diagramEvent$.next(new DiagramSelectionEvent(deselectedElements, false));
6507
7184
  }
6508
- this.userSelection.toggle(getRelatedNodeOrItself(d));
7185
+ const elementToBeToggled = getRelatedNodeOrItself(d);
7186
+ this.userSelection.toggle(elementToBeToggled);
7187
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToBeToggled], elementToBeToggled.selected));
6509
7188
  }).on(Events.ContextMenu, (event, d) => {
6510
7189
  if (this.dragging) {
6511
7190
  event.preventDefault();
@@ -6513,17 +7192,19 @@ class DiagramCanvas {
6513
7192
  this.dragging = false;
6514
7193
  return;
6515
7194
  }
6516
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, d);
7195
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
6517
7196
  this.diagramEvent$.next(diagramEvent);
6518
7197
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
6519
7198
  event.preventDefault();
6520
7199
  const elementToSelect = getRelatedNodeOrItself(d);
6521
7200
  this.userHighlight.focusOn(elementToSelect);
7201
+ this.diagramEvent$.next(new DiagramHighlightedEvent(elementToSelect));
6522
7202
  this.userSelection.add(elementToSelect);
7203
+ this.diagramEvent$.next(new DiagramSelectionEvent([elementToSelect], true));
6523
7204
  this.contextMenu.open(event);
6524
7205
  }
6525
7206
  }).on(Events.DoubleClick, (event, d) => {
6526
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
7207
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
6527
7208
  this.diagramEvent$.next(diagramEvent);
6528
7209
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.EditField) && d.editable && !d.removed) {
6529
7210
  this.currentAction = new EditFieldAction(this, d.id, d.text, '');
@@ -6595,7 +7276,7 @@ class DiagramCanvas {
6595
7276
  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('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/>'));
6596
7277
  }
6597
7278
  updateObjectsInView(...ids) {
6598
- let updateSelection = this.selectCanvasObjects().selectAll('foreignObject.diagram-object').data(this.model.objects.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
7279
+ 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);
6599
7280
  const exitSelection = updateSelection.exit();
6600
7281
  const enterSelection = updateSelection.enter().append('foreignObject').attr('id', d => d.id).attr('class', 'diagram-object');
6601
7282
  if (ids && ids.length > 0) {
@@ -6604,21 +7285,21 @@ class DiagramCanvas {
6604
7285
  const mergeSelection = enterSelection.merge(updateSelection);
6605
7286
  mergeSelection.attr('width', d => `${d.width}px`).attr('height', d => `${d.height}px`).attr('transform', d => `translate(${d.coords[0]},${d.coords[1]})`).html(d => d.html);
6606
7287
  exitSelection.remove();
6607
- enterSelection.on(Events.ContextMenu, event => {
7288
+ enterSelection.on(Events.ContextMenu, (event, d) => {
6608
7289
  if (this.dragging) {
6609
7290
  event.preventDefault();
6610
7291
  event.stopPropagation();
6611
7292
  this.dragging = false;
6612
7293
  return;
6613
7294
  }
6614
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, undefined);
7295
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
6615
7296
  this.diagramEvent$.next(diagramEvent);
6616
7297
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
6617
7298
  event.preventDefault();
6618
7299
  this.contextMenu.open(event);
6619
7300
  }
6620
7301
  }).on(Events.DoubleClick, (event, d) => {
6621
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
7302
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
6622
7303
  this.diagramEvent$.next(diagramEvent);
6623
7304
  }).call(d3.drag().filter(event => {
6624
7305
  this.secondaryButton = isSecondaryButton(event);
@@ -6632,7 +7313,7 @@ class DiagramCanvas {
6632
7313
  }));
6633
7314
  }
6634
7315
  updateDecoratorsInView(...ids) {
6635
- let updateSelection = this.selectCanvasDecorators().selectAll('foreignObject.diagram-decorator').data(this.model.decorators.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
7316
+ let updateSelection = this.selectCanvasElements().selectAll('foreignObject.diagram-decorator').data(this.model.decorators.filter(e => this.priorityThreshold !== undefined ? e.getPriority() >= this.priorityThreshold : true), d => d.id);
6636
7317
  const exitSelection = updateSelection.exit();
6637
7318
  const enterSelection = updateSelection.enter().append('foreignObject').attr('id', d => d.id).attr('class', 'diagram-decorator');
6638
7319
  if (ids && ids.length > 0) {
@@ -6641,21 +7322,21 @@ class DiagramCanvas {
6641
7322
  const mergeSelection = enterSelection.merge(updateSelection);
6642
7323
  mergeSelection.attr('width', d => `${d.width}px`).attr('height', d => `${d.height}px`).attr('transform', d => `translate(${d.coords[0]},${d.coords[1]})`).html(d => d.html);
6643
7324
  exitSelection.remove();
6644
- enterSelection.on(Events.ContextMenu, event => {
7325
+ enterSelection.on(Events.ContextMenu, (event, d) => {
6645
7326
  if (this.dragging) {
6646
7327
  event.preventDefault();
6647
7328
  event.stopPropagation();
6648
7329
  this.dragging = false;
6649
7330
  return;
6650
7331
  }
6651
- const diagramEvent = new DiagramEvent(event, Events.ContextMenu, undefined);
7332
+ const diagramEvent = new DiagramSecondaryClickEvent(event, d);
6652
7333
  this.diagramEvent$.next(diagramEvent);
6653
7334
  if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.ContextMenu)) {
6654
7335
  event.preventDefault();
6655
7336
  this.contextMenu.open(event);
6656
7337
  }
6657
7338
  }).on(Events.DoubleClick, (event, d) => {
6658
- const diagramEvent = new DiagramEvent(event, Events.DoubleClick, d);
7339
+ const diagramEvent = new DiagramDoubleClickEvent(event, d);
6659
7340
  this.diagramEvent$.next(diagramEvent);
6660
7341
  }).call(d3.drag().filter(event => {
6661
7342
  this.secondaryButton = isSecondaryButton(event);
@@ -6678,33 +7359,33 @@ class DiagramCanvas {
6678
7359
  const pathLength = pathNode.getTotalLength();
6679
7360
  // bind start labels
6680
7361
  connectionSelection.select('g.diagram-connection-start-label text').attr('x', 0).attr('y', labelConfiguration.fontSize / 3).attr('text-anchor', 'middle').attr('font-family', labelConfiguration.fontFamily).attr('font-size', labelConfiguration.fontSize).attr('fill', connection.selected ? labelConfiguration.selectedColor : labelConfiguration.color).style('font-kerning', 'none').text(connection.startLabel);
6681
- const startLabelBoundingRect = (_a = connectionSelection.select('g.diagram-connection-start-label text').node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
7362
+ const startLabelBoundingRect = (_a = connectionSelection.select('g.diagram-connection-start-label text').node()) === null || _a === undefined ? undefined : _a.getBoundingClientRect();
6682
7363
  if (startLabelBoundingRect) {
6683
7364
  // don't create space for the label if the label is empty
6684
- const boundingWidth = !connection.startLabel ? 0 : startLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding(labelConfiguration) + getRightPadding(labelConfiguration);
6685
- const boundingHeight = !connection.startLabel ? 0 : startLabelBoundingRect.height / this.zoomTransform.k + getTopPadding(labelConfiguration) + getBottomPadding(labelConfiguration);
7365
+ const boundingWidth = !connection.startLabel ? 0 : startLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding$1(labelConfiguration) + getRightPadding$1(labelConfiguration);
7366
+ const boundingHeight = !connection.startLabel ? 0 : startLabelBoundingRect.height / this.zoomTransform.k + getTopPadding$1(labelConfiguration) + getBottomPadding$1(labelConfiguration);
6686
7367
  const pathStartLabelPoint = pathNode.getPointAtLength(Math.max(getLeftMargin(labelConfiguration) + boundingWidth / 2, getRightMargin(labelConfiguration) + boundingWidth / 2, getTopMargin(labelConfiguration) + boundingHeight / 2, getBottomMargin(labelConfiguration) + boundingHeight / 2));
6687
7368
  connectionSelection.select('g.diagram-connection-start-label path').attr('d', pillPath(-boundingWidth / 2, -boundingHeight / 2, boundingWidth, boundingHeight)).attr('fill', connection.selected ? connection.type.selectedColor : connection.type.color).attr('stroke', 'none');
6688
7369
  connectionSelection.select('g.diagram-connection-start-label').attr('transform', `translate(${pathStartLabelPoint.x},${pathStartLabelPoint.y})`);
6689
7370
  }
6690
7371
  // bind middle labels
6691
7372
  connectionSelection.select('g.diagram-connection-middle-label text').attr('x', 0).attr('y', labelConfiguration.fontSize / 3).attr('text-anchor', 'middle').attr('font-family', labelConfiguration.fontFamily).attr('font-size', labelConfiguration.fontSize).attr('fill', connection.selected ? labelConfiguration.selectedColor : labelConfiguration.color).style('font-kerning', 'none').text(connection.middleLabel);
6692
- const middleLabelBoundingRect = (_b = connectionSelection.select('g.diagram-connection-middle-label text').node()) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
7373
+ const middleLabelBoundingRect = (_b = connectionSelection.select('g.diagram-connection-middle-label text').node()) === null || _b === undefined ? undefined : _b.getBoundingClientRect();
6693
7374
  if (middleLabelBoundingRect) {
6694
7375
  // don't create space for the label if the label is empty
6695
- const boundingWidth = !connection.middleLabel ? 0 : middleLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding(labelConfiguration) + getRightPadding(labelConfiguration);
6696
- const boundingHeight = !connection.middleLabel ? 0 : middleLabelBoundingRect.height / this.zoomTransform.k + getTopPadding(labelConfiguration) + getBottomPadding(labelConfiguration);
7376
+ const boundingWidth = !connection.middleLabel ? 0 : middleLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding$1(labelConfiguration) + getRightPadding$1(labelConfiguration);
7377
+ const boundingHeight = !connection.middleLabel ? 0 : middleLabelBoundingRect.height / this.zoomTransform.k + getTopPadding$1(labelConfiguration) + getBottomPadding$1(labelConfiguration);
6697
7378
  const pathMiddleLabelPoint = pathNode.getPointAtLength(pathLength / 2);
6698
7379
  connectionSelection.select('g.diagram-connection-middle-label path').attr('d', pillPath(-boundingWidth / 2, -boundingHeight / 2, boundingWidth, boundingHeight)).attr('fill', connection.selected ? connection.type.selectedColor : connection.type.color).attr('stroke', 'none');
6699
7380
  connectionSelection.select('g.diagram-connection-middle-label').attr('transform', `translate(${pathMiddleLabelPoint.x},${pathMiddleLabelPoint.y})`);
6700
7381
  }
6701
7382
  // bind end labels
6702
7383
  connectionSelection.select('g.diagram-connection-end-label text').attr('x', 0).attr('y', labelConfiguration.fontSize / 3).attr('text-anchor', 'middle').attr('font-family', labelConfiguration.fontFamily).attr('font-size', labelConfiguration.fontSize).attr('fill', connection.selected ? labelConfiguration.selectedColor : labelConfiguration.color).style('font-kerning', 'none').text(connection.endLabel);
6703
- const endLabelBoundingRect = (_c = connectionSelection.select('g.diagram-connection-end-label text').node()) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect();
7384
+ const endLabelBoundingRect = (_c = connectionSelection.select('g.diagram-connection-end-label text').node()) === null || _c === undefined ? undefined : _c.getBoundingClientRect();
6704
7385
  if (endLabelBoundingRect) {
6705
7386
  // don't create space for the label if the label is empty
6706
- const boundingWidth = !connection.endLabel ? 0 : endLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding(labelConfiguration) + getRightPadding(labelConfiguration);
6707
- const boundingHeight = !connection.endLabel ? 0 : endLabelBoundingRect.height / this.zoomTransform.k + getTopPadding(labelConfiguration) + getBottomPadding(labelConfiguration);
7387
+ const boundingWidth = !connection.endLabel ? 0 : endLabelBoundingRect.width / this.zoomTransform.k + getLeftPadding$1(labelConfiguration) + getRightPadding$1(labelConfiguration);
7388
+ const boundingHeight = !connection.endLabel ? 0 : endLabelBoundingRect.height / this.zoomTransform.k + getTopPadding$1(labelConfiguration) + getBottomPadding$1(labelConfiguration);
6708
7389
  const pathEndLabelPoint = pathNode.getPointAtLength(pathLength - Math.max(getLeftMargin(labelConfiguration) + boundingWidth / 2, getRightMargin(labelConfiguration) + boundingWidth / 2, getTopMargin(labelConfiguration) + boundingHeight / 2, getBottomMargin(labelConfiguration) + boundingHeight / 2));
6709
7390
  connectionSelection.select('g.diagram-connection-end-label path').attr('d', pillPath(-boundingWidth / 2, -boundingHeight / 2, boundingWidth, boundingHeight)).attr('fill', connection.selected ? connection.type.selectedColor : connection.type.color).attr('stroke', 'none');
6710
7391
  connectionSelection.select('g.diagram-connection-end-label').attr('transform', `translate(${pathEndLabelPoint.x},${pathEndLabelPoint.y})`);
@@ -6754,7 +7435,7 @@ class DiagramCanvas {
6754
7435
  const fieldDimensions = this.minimumSizeOfField(field);
6755
7436
  let minimumFieldWidth = fieldDimensions[0];
6756
7437
  let minimumFieldHeight = fieldDimensions[1];
6757
- for (const section of ((_a = field.rootElement.node) === null || _a === void 0 ? void 0 : _a.sections) || []) {
7438
+ for (const section of ((_a = field.rootElement.node) === null || _a === undefined ? undefined : _a.sections) || []) {
6758
7439
  if (section.label) {
6759
7440
  if (section.indexXInNode === field.rootElement.indexXInNode && section.indexYInNode !== field.rootElement.indexYInNode) {
6760
7441
  minimumFieldWidth = Math.max(minimumFieldWidth, this.minimumSizeOfField(section.label)[0]);
@@ -6769,8 +7450,8 @@ class DiagramCanvas {
6769
7450
  if (fieldDimensions[1] < minimumFieldHeight) {
6770
7451
  fieldDimensions[1] = minimumFieldHeight;
6771
7452
  }
6772
- let stretchX = fieldDimensions[0] + getLeftMargin((_c = (_b = field.rootElement) === null || _b === void 0 ? void 0 : _b.getConfig()) === null || _c === void 0 ? void 0 : _c.label) + getRightMargin((_e = (_d = field.rootElement) === null || _d === void 0 ? void 0 : _d.getConfig()) === null || _e === void 0 ? void 0 : _e.label) - field.rootElement.width;
6773
- let stretchY = fieldDimensions[1] + getTopMargin((_g = (_f = field.rootElement) === null || _f === void 0 ? void 0 : _f.getConfig()) === null || _g === void 0 ? void 0 : _g.label) + getBottomMargin((_j = (_h = field.rootElement) === null || _h === void 0 ? void 0 : _h.getConfig()) === null || _j === void 0 ? void 0 : _j.label) - field.rootElement.height;
7453
+ let stretchX = fieldDimensions[0] + getLeftMargin((_c = (_b = field.rootElement) === null || _b === undefined ? undefined : _b.getConfig()) === null || _c === undefined ? undefined : _c.label) + getRightMargin((_e = (_d = field.rootElement) === null || _d === undefined ? undefined : _d.getConfig()) === null || _e === undefined ? undefined : _e.label) - field.rootElement.width;
7454
+ let stretchY = fieldDimensions[1] + getTopMargin((_g = (_f = field.rootElement) === null || _f === undefined ? undefined : _f.getConfig()) === null || _g === undefined ? undefined : _g.label) + getBottomMargin((_j = (_h = field.rootElement) === null || _h === undefined ? undefined : _h.getConfig()) === null || _j === undefined ? undefined : _j.label) - field.rootElement.height;
6774
7455
  if (this.snapToGrid) {
6775
7456
  stretchX = Math.ceil(stretchX / this.gridSize) * this.gridSize;
6776
7457
  stretchY = Math.ceil(stretchY / this.gridSize) * this.gridSize;
@@ -6782,8 +7463,8 @@ class DiagramCanvas {
6782
7463
  if (field.rootElement.height + stretchY < (field.rootElement.getMinHeight() || 0)) {
6783
7464
  stretchY = (field.rootElement.getMinHeight() || 0) - field.rootElement.height;
6784
7465
  }
6785
- (_k = field.rootElement.node) === null || _k === void 0 ? void 0 : _k.stretchSections(Side.Right, stretchX, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
6786
- (_l = field.rootElement.node) === null || _l === void 0 ? void 0 : _l.stretchSections(Side.Bottom, stretchY, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
7466
+ (_k = field.rootElement.node) === null || _k === undefined ? undefined : _k.stretchSections(Side.Right, stretchX, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
7467
+ (_l = field.rootElement.node) === null || _l === undefined ? undefined : _l.stretchSections(Side.Bottom, stretchY, field.rootElement.indexXInNode, field.rootElement.indexYInNode);
6787
7468
  }
6788
7469
  }
6789
7470
  fitNodeInView(id) {
@@ -6805,8 +7486,8 @@ class DiagramCanvas {
6805
7486
  }
6806
7487
  }
6807
7488
  // add the margin that goes between the rightmost and bottommost points of the sections and the edge of the node
6808
- newNodeWidth += ((_a = node.type.sectionGrid) === null || _a === void 0 ? void 0 : _a.margin) || 0;
6809
- newNodeHeight += ((_b = node.type.sectionGrid) === null || _b === void 0 ? void 0 : _b.margin) || 0;
7489
+ newNodeWidth += ((_a = node.type.sectionGrid) === null || _a === undefined ? undefined : _a.margin) || 0;
7490
+ newNodeHeight += ((_b = node.type.sectionGrid) === null || _b === undefined ? undefined : _b.margin) || 0;
6810
7491
  node.stretch(Side.Right, newNodeWidth - node.width);
6811
7492
  node.stretch(Side.Bottom, newNodeHeight - node.height);
6812
7493
  }
@@ -6820,42 +7501,21 @@ class DiagramCanvas {
6820
7501
  selectCanvasElements() {
6821
7502
  return this.selectRoot().select(`.daga-canvas-elements`);
6822
7503
  }
6823
- selectCanvasNodes() {
6824
- return this.selectRoot().select(`.daga-canvas-nodes`);
6825
- }
6826
- selectCanvasSections() {
6827
- return this.selectRoot().select(`.daga-canvas-sections`);
6828
- }
6829
- selectCanvasPorts() {
6830
- return this.selectRoot().select(`.daga-canvas-ports`);
6831
- }
6832
- selectCanvasConnections() {
6833
- return this.selectRoot().select(`.daga-canvas-connections`);
6834
- }
6835
- selectCanvasFields() {
6836
- return this.selectRoot().select(`.daga-canvas-fields`);
6837
- }
6838
- selectCanvasObjects() {
6839
- return this.selectRoot().select(`.daga-canvas-objects`);
6840
- }
6841
- selectCanvasDecorators() {
6842
- return this.selectRoot().select(`.daga-canvas-decorators`);
6843
- }
6844
7504
  // User actions
6845
7505
  startConnection(port) {
6846
7506
  var _a, _b, _c, _d;
6847
- 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) || '') || this.connectionType.canFinishOnType(((_d = (_c = port.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || ''))) {
7507
+ if (this.connectionType && (this.connectionType.canStartFromType(((_b = (_a = port.getNode()) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.id) || '') || this.connectionType.canFinishOnType(((_d = (_c = port.getNode()) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.id) || ''))) {
6848
7508
  this.unfinishedConnection = new DiagramConnection(this.model, this.connectionType, port, undefined, UNFINISHED_CONNECTION_ID);
6849
7509
  } else {
6850
7510
  if (this.inferConnectionType) {
6851
7511
  let differentConnectionType = this.model.connections.types.all().find(t => {
6852
7512
  var _a, _b;
6853
- return t.canStartFromType(((_b = (_a = port.getNode()) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.id) || '');
7513
+ return t.canStartFromType(((_b = (_a = port.getNode()) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.id) || '');
6854
7514
  });
6855
7515
  if (differentConnectionType === undefined) {
6856
7516
  differentConnectionType = this.model.connections.types.all().find(t => {
6857
7517
  var _a, _b;
6858
- return t.canFinishOnType(((_b = (_a = port.getNode()) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.id) || '');
7518
+ return t.canFinishOnType(((_b = (_a = port.getNode()) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.id) || '');
6859
7519
  });
6860
7520
  }
6861
7521
  if (differentConnectionType !== undefined) {
@@ -6869,14 +7529,14 @@ class DiagramCanvas {
6869
7529
  this.userHighlight.clear();
6870
7530
  if (this.unfinishedConnection !== undefined) {
6871
7531
  if (this.unfinishedConnection.start !== port) {
6872
- if (this.unfinishedConnection.type.canStartFromType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_f = (_e = port.getNode()) === null || _e === void 0 ? void 0 : _e.type) === null || _f === void 0 ? void 0 : _f.id) || '')) {
6873
- const addConnectionAction = new AddConnectionAction(this, this.unfinishedConnection.type, (_g = this.unfinishedConnection.start) === null || _g === void 0 ? void 0 : _g.id, port.id);
7532
+ if (this.unfinishedConnection.type.canStartFromType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === undefined ? undefined : _a.start) === null || _b === undefined ? undefined : _b.getNode()) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.id) || '') && this.unfinishedConnection.type.canFinishOnType(((_f = (_e = port.getNode()) === null || _e === undefined ? undefined : _e.type) === null || _f === undefined ? undefined : _f.id) || '')) {
7533
+ const addConnectionAction = new AddConnectionAction(this, this.unfinishedConnection.type, (_g = this.unfinishedConnection.start) === null || _g === undefined ? undefined : _g.id, port.id);
6874
7534
  // clean up the previous unfinished connection
6875
7535
  this.dropConnection();
6876
7536
  addConnectionAction.do();
6877
7537
  this.actionStack.add(addConnectionAction);
6878
- } else if (this.unfinishedConnection.type.canFinishOnType(((_l = (_k = (_j = (_h = this.unfinishedConnection) === null || _h === void 0 ? void 0 : _h.start) === null || _j === void 0 ? void 0 : _j.getNode()) === null || _k === void 0 ? void 0 : _k.type) === null || _l === void 0 ? void 0 : _l.id) || '') && this.unfinishedConnection.type.canStartFromType(((_o = (_m = port.getNode()) === null || _m === void 0 ? void 0 : _m.type) === null || _o === void 0 ? void 0 : _o.id) || '')) {
6879
- const addConnectionAction = new AddConnectionAction(this, this.unfinishedConnection.type, port.id, (_p = this.unfinishedConnection.start) === null || _p === void 0 ? void 0 : _p.id);
7538
+ } else if (this.unfinishedConnection.type.canFinishOnType(((_l = (_k = (_j = (_h = this.unfinishedConnection) === null || _h === undefined ? undefined : _h.start) === null || _j === undefined ? undefined : _j.getNode()) === null || _k === undefined ? undefined : _k.type) === null || _l === undefined ? undefined : _l.id) || '') && this.unfinishedConnection.type.canStartFromType(((_o = (_m = port.getNode()) === null || _m === undefined ? undefined : _m.type) === null || _o === undefined ? undefined : _o.id) || '')) {
7539
+ const addConnectionAction = new AddConnectionAction(this, this.unfinishedConnection.type, port.id, (_p = this.unfinishedConnection.start) === null || _p === undefined ? undefined : _p.id);
6880
7540
  // clean up the previous unfinished connection
6881
7541
  this.dropConnection();
6882
7542
  addConnectionAction.do();
@@ -6885,18 +7545,18 @@ class DiagramCanvas {
6885
7545
  if (this.inferConnectionType) {
6886
7546
  let differentConnectionType = this.model.connections.types.all().find(t => {
6887
7547
  var _a, _b, _c, _d, _e, _f;
6888
- return t.canStartFromType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || '') && t.canFinishOnType(((_f = (_e = port.getNode()) === null || _e === void 0 ? void 0 : _e.type) === null || _f === void 0 ? void 0 : _f.id) || '');
7548
+ return t.canStartFromType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === undefined ? undefined : _a.start) === null || _b === undefined ? undefined : _b.getNode()) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.id) || '') && t.canFinishOnType(((_f = (_e = port.getNode()) === null || _e === undefined ? undefined : _e.type) === null || _f === undefined ? undefined : _f.id) || '');
6889
7549
  });
6890
7550
  let invertConnection = false;
6891
7551
  if (differentConnectionType === undefined) {
6892
7552
  differentConnectionType = this.model.connections.types.all().find(t => {
6893
7553
  var _a, _b, _c, _d, _e, _f;
6894
- return t.canFinishOnType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.getNode()) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.id) || '') && t.canStartFromType(((_f = (_e = port.getNode()) === null || _e === void 0 ? void 0 : _e.type) === null || _f === void 0 ? void 0 : _f.id) || '');
7554
+ return t.canFinishOnType(((_d = (_c = (_b = (_a = this.unfinishedConnection) === null || _a === undefined ? undefined : _a.start) === null || _b === undefined ? undefined : _b.getNode()) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.id) || '') && t.canStartFromType(((_f = (_e = port.getNode()) === null || _e === undefined ? undefined : _e.type) === null || _f === undefined ? undefined : _f.id) || '');
6895
7555
  });
6896
7556
  invertConnection = true;
6897
7557
  }
6898
7558
  if (differentConnectionType !== undefined) {
6899
- const addConnectionAction = new AddConnectionAction(this, differentConnectionType, invertConnection ? port.id : (_q = this.unfinishedConnection.start) === null || _q === void 0 ? void 0 : _q.id, invertConnection ? (_r = this.unfinishedConnection.start) === null || _r === void 0 ? void 0 : _r.id : port.id);
7559
+ const addConnectionAction = new AddConnectionAction(this, differentConnectionType, invertConnection ? port.id : (_q = this.unfinishedConnection.start) === null || _q === undefined ? undefined : _q.id, invertConnection ? (_r = this.unfinishedConnection.start) === null || _r === undefined ? undefined : _r.id : port.id);
6900
7560
  // clean up the previous unfinished connection
6901
7561
  this.dropConnection();
6902
7562
  addConnectionAction.do();
@@ -6918,9 +7578,9 @@ class DiagramCanvas {
6918
7578
  }
6919
7579
  dropConnection() {
6920
7580
  var _a, _b, _c, _d;
6921
- (_a = this.unfinishedConnection) === null || _a === void 0 ? void 0 : _a.setStart(undefined);
6922
- (_b = this.unfinishedConnection) === null || _b === void 0 ? void 0 : _b.setEnd(undefined);
6923
- (_d = (_c = this.unfinishedConnection) === null || _c === void 0 ? void 0 : _c.select()) === null || _d === void 0 ? void 0 : _d.remove();
7581
+ (_a = this.unfinishedConnection) === null || _a === undefined ? undefined : _a.setStart(undefined);
7582
+ (_b = this.unfinishedConnection) === null || _b === undefined ? undefined : _b.setEnd(undefined);
7583
+ (_d = (_c = this.unfinishedConnection) === null || _c === undefined ? undefined : _c.select()) === null || _d === undefined ? undefined : _d.remove();
6924
7584
  this.unfinishedConnection = undefined;
6925
7585
  }
6926
7586
  cancelAllUserActions() {
@@ -6965,9 +7625,9 @@ class DiagramCanvas {
6965
7625
  // keep the field from shrinking below its original size
6966
7626
  const newWidth = Math.max(inputFieldWidth, width);
6967
7627
  const newHeight = Math.max(inputFieldHeight, height);
6968
- inputFieldContainer === null || inputFieldContainer === void 0 ? void 0 : inputFieldContainer.attr('width', `${newWidth}px`);
7628
+ inputFieldContainer === null || inputFieldContainer === undefined ? undefined : inputFieldContainer.attr('width', `${newWidth}px`);
6969
7629
  inputField.style('width', `${newWidth}px`);
6970
- inputFieldContainer === null || inputFieldContainer === void 0 ? void 0 : inputFieldContainer.attr('height', `${newHeight}px`);
7630
+ inputFieldContainer === null || inputFieldContainer === undefined ? undefined : inputFieldContainer.attr('height', `${newHeight}px`);
6971
7631
  inputField.style('height', `${newHeight}px`);
6972
7632
  if (changeCallback) {
6973
7633
  changeCallback(value);
@@ -6989,13 +7649,13 @@ class DiagramCanvas {
6989
7649
  var _a, _b, _c;
6990
7650
  // when removing an element, a blur event is emitted
6991
7651
  // we remove the listener for blur so that it doesn't shoot again on element removal
6992
- (_b = (_a = this.inputFieldContainer) === null || _a === void 0 ? void 0 : _a.select('input')) === null || _b === void 0 ? void 0 : _b.on(Events.Blur, null);
6993
- (_c = this.inputFieldContainer) === null || _c === void 0 ? void 0 : _c.remove();
7652
+ (_b = (_a = this.inputFieldContainer) === null || _a === undefined ? undefined : _a.select('input')) === null || _b === undefined ? undefined : _b.on(Events.Blur, null);
7653
+ (_c = this.inputFieldContainer) === null || _c === undefined ? undefined : _c.remove();
6994
7654
  this.inputFieldContainer = undefined;
6995
7655
  }
6996
7656
  minimumSizeOfField(field) {
6997
7657
  var _a, _b;
6998
- const pNode = (_b = (_a = field.select()) === null || _a === void 0 ? void 0 : _a.select('p')) === null || _b === void 0 ? void 0 : _b.node();
7658
+ const pNode = (_b = (_a = field.select()) === null || _a === undefined ? undefined : _a.select('p')) === null || _b === undefined ? undefined : _b.node();
6999
7659
  if (!pNode) {
7000
7660
  // happens when a field has been created but not updated in view yet
7001
7661
  return [0, 0];
@@ -7010,10 +7670,11 @@ class DiagramCanvas {
7010
7670
  if (this.canUserPerformAction(DiagramActions.MoveNode) && !d.removed) {
7011
7671
  setCursorStyle(CursorStyle.Grabbing);
7012
7672
  this.draggingFrom = [event.x, event.y];
7013
- if (d.selected) {
7673
+ if (d.selected && this.userSelection.count(e => e instanceof DiagramNode) > 1) {
7014
7674
  this.currentAction = new MoveAction(this, this.userSelection.filter(e => e instanceof DiagramNode).map(n => n.id), d.coords);
7015
7675
  } else {
7016
- this.currentAction = new MoveAction(this, [d.id], d.coords);
7676
+ const ancestorOfNode = d.getLastAncestor();
7677
+ this.currentAction = new SetGeometryAction(this, DiagramActions.MoveNode, d.id, d.getGeometry(), d.getGeometry(), ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.id, ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.getGeometry(d.id), ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.getGeometry(d.id));
7017
7678
  }
7018
7679
  } else {
7019
7680
  setCursorStyle(CursorStyle.NotAllowed);
@@ -7023,7 +7684,7 @@ class DiagramCanvas {
7023
7684
  * Method to call to continue the moving of a node triggered by a user drag event.
7024
7685
  */
7025
7686
  continueMovingNode(event, d) {
7026
- if (this.canUserPerformAction(DiagramActions.MoveNode) && this.currentAction instanceof MoveAction && !d.removed) {
7687
+ if (this.canUserPerformAction(DiagramActions.MoveNode) && (this.currentAction instanceof MoveAction || this.currentAction instanceof SetGeometryAction) && !d.removed) {
7027
7688
  const newNodeCoords = [event.x - d.width / 2, event.y - d.height / 2];
7028
7689
  if (d.selected) {
7029
7690
  this.userSelection.move([newNodeCoords[0] - d.coords[0], newNodeCoords[1] - d.coords[1]]);
@@ -7038,24 +7699,58 @@ class DiagramCanvas {
7038
7699
  * Method to call to finish the moving of a node triggered by a user drag event.
7039
7700
  */
7040
7701
  finishMovingNode(event, d) {
7702
+ var _a, _b, _c;
7041
7703
  if (this.canUserPerformAction(DiagramActions.MoveNode) && !d.removed) {
7042
7704
  // prevent drag behavior if mouse hasn't moved
7043
- if ((this.draggingFrom[0] !== event.x || this.draggingFrom[1] !== event.y) && this.currentAction instanceof MoveAction) {
7705
+ if (this.draggingFrom[0] !== event.x || this.draggingFrom[1] !== event.y) {
7044
7706
  let newNodeCoords = [event.x - d.width / 2, event.y - d.height / 2];
7045
7707
  if (this.snapToGrid) {
7046
7708
  newNodeCoords = this.getClosestGridPoint(newNodeCoords);
7047
7709
  }
7048
- const movingFrom = this.currentAction.delta;
7049
- this.currentAction.delta = [newNodeCoords[0] - movingFrom[0], newNodeCoords[1] - movingFrom[1]];
7050
- // reset position of node prior to moving it again
7051
- if (d.selected) {
7052
- this.userSelection.move([movingFrom[0] - d.coords[0], movingFrom[1] - d.coords[1]]);
7053
- } else {
7054
- d.move(movingFrom);
7710
+ if (this.currentAction instanceof MoveAction) {
7711
+ const movingFrom = this.currentAction.delta;
7712
+ this.currentAction.delta = [newNodeCoords[0] - movingFrom[0], newNodeCoords[1] - movingFrom[1]];
7713
+ // reset position of node prior to moving it again
7714
+ if (d.selected) {
7715
+ this.userSelection.move([movingFrom[0] - d.coords[0], movingFrom[1] - d.coords[1]]);
7716
+ } else {
7717
+ d.move(movingFrom);
7718
+ }
7719
+ } else if (this.currentAction instanceof SetGeometryAction) {
7720
+ d.move(newNodeCoords);
7721
+ // if moving a single node, we can change the node's parent,
7722
+ // so we check whether we dropped this node on a potential parent
7723
+ const nodesAtLocation = this.model.nodes.getAtCoordinates(event.x, event.y).filter(n => n.id !== d.id && !n.isDescendantOf(d));
7724
+ // filter by which nodes can have this node as a child
7725
+ const nodesAtLocationWhichCanHaveNodeAsAChild = nodesAtLocation.filter(n => n.type.childrenTypes.includes(d.type.id));
7726
+ // filter by which nodes don't have descendants in this collection
7727
+ const filteredNodesAtLocation = filterByOnlyDescendants(nodesAtLocationWhichCanHaveNodeAsAChild);
7728
+ const droppedOn = filteredNodesAtLocation[filteredNodesAtLocation.length - 1];
7729
+ if (droppedOn !== d.parent && (d.type.canBeParentless || droppedOn !== undefined)) {
7730
+ const ancestorOfDroppedOn = droppedOn === null || droppedOn === undefined ? undefined : droppedOn.getLastAncestor();
7731
+ const fromChildGeometry = this.currentAction.from;
7732
+ const setParentAction = new SetParentAction(this, d.id, (_a = d.parent) === null || _a === undefined ? undefined : _a.id, droppedOn === null || droppedOn === undefined ? undefined : droppedOn.id, fromChildGeometry, d.getGeometry(), ancestorOfDroppedOn === null || ancestorOfDroppedOn === undefined ? undefined : ancestorOfDroppedOn.id, ancestorOfDroppedOn === null || ancestorOfDroppedOn === undefined ? undefined : ancestorOfDroppedOn.getGeometry(d.id), ancestorOfDroppedOn === null || ancestorOfDroppedOn === undefined ? undefined : ancestorOfDroppedOn.getGeometry(d.id));
7733
+ (_b = d.parent) === null || _b === undefined ? undefined : _b.removeChild(d);
7734
+ if (droppedOn !== undefined) {
7735
+ droppedOn.addChild(d);
7736
+ }
7737
+ setParentAction.toChildGeometry = d.getGeometry(d.id);
7738
+ setParentAction.toAncestorGeometry = ancestorOfDroppedOn === null || ancestorOfDroppedOn === undefined ? undefined : ancestorOfDroppedOn.getGeometry(d.id);
7739
+ this.currentAction = setParentAction;
7740
+ } else {
7741
+ const ancestorOfNode = d === null || d === undefined ? undefined : d.getLastAncestor();
7742
+ this.currentAction.ancestorId = ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.id;
7743
+ this.currentAction.fromAncestorGeometry = ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.getGeometry(d.id);
7744
+ (_c = d.parent) === null || _c === undefined ? undefined : _c.fitToChild(d);
7745
+ this.currentAction.to = d.getGeometry(d.id);
7746
+ this.currentAction.toAncestorGeometry = ancestorOfNode === null || ancestorOfNode === undefined ? undefined : ancestorOfNode.getGeometry(d.id);
7747
+ }
7748
+ }
7749
+ if (this.currentAction !== undefined) {
7750
+ this.currentAction.do();
7751
+ this.actionStack.add(this.currentAction);
7752
+ this.currentAction = undefined;
7055
7753
  }
7056
- this.currentAction.do();
7057
- this.actionStack.add(this.currentAction);
7058
- this.currentAction = undefined;
7059
7754
  }
7060
7755
  }
7061
7756
  setCursorStyle();
@@ -7074,14 +7769,14 @@ class DiagramCanvas {
7074
7769
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7075
7770
  if (this.draggingFrom[0] !== pointerCoords[0] || this.draggingFrom[1] !== pointerCoords[1]) {
7076
7771
  setCursorStyle(CursorStyle.Crosshair);
7077
- (_d = (_c = (_b = (_a = this.multipleSelectionContainer) === null || _a === void 0 ? void 0 : _a.attr('x', Math.min(this.draggingFrom[0], pointerCoords[0]))) === null || _b === void 0 ? void 0 : _b.attr('y', Math.min(this.draggingFrom[1], pointerCoords[1]))) === null || _c === void 0 ? void 0 : _c.attr('width', Math.abs(this.draggingFrom[0] - pointerCoords[0]))) === null || _d === void 0 ? void 0 : _d.attr('height', Math.abs(this.draggingFrom[1] - pointerCoords[1]));
7772
+ (_d = (_c = (_b = (_a = this.multipleSelectionContainer) === null || _a === undefined ? undefined : _a.attr('x', Math.min(this.draggingFrom[0], pointerCoords[0]))) === null || _b === undefined ? undefined : _b.attr('y', Math.min(this.draggingFrom[1], pointerCoords[1]))) === null || _c === undefined ? undefined : _c.attr('width', Math.abs(this.draggingFrom[0] - pointerCoords[0]))) === null || _d === undefined ? undefined : _d.attr('height', Math.abs(this.draggingFrom[1] - pointerCoords[1]));
7078
7773
  this.dragging = true;
7079
7774
  }
7080
7775
  }
7081
7776
  finishMultipleSelection(event) {
7082
7777
  var _a;
7083
7778
  const pointerCoords = this.getPointerLocationRelativeToCanvas(event);
7084
- (_a = this.multipleSelectionContainer) === null || _a === void 0 ? void 0 : _a.remove();
7779
+ (_a = this.multipleSelectionContainer) === null || _a === undefined ? undefined : _a.remove();
7085
7780
  this.multipleSelectionContainer = undefined;
7086
7781
  this.userSelection.clear();
7087
7782
  for (const node of this.model.nodes) {
@@ -7090,6 +7785,7 @@ class DiagramCanvas {
7090
7785
  }
7091
7786
  }
7092
7787
  this.multipleSelectionOn = false;
7788
+ this.diagramEvent$.next(new DiagramSelectionEvent(this.userSelection.all(), true));
7093
7789
  setCursorStyle();
7094
7790
  }
7095
7791
  }
@@ -7209,7 +7905,7 @@ class CollabClient {
7209
7905
  const initialModel = message.initialModel;
7210
7906
  new DagaImporter().import(session.canvas.model, initialModel);
7211
7907
  this.startSyncing(session);
7212
- (_a = session.joinRoomResolve) === null || _a === void 0 ? void 0 : _a.call(session);
7908
+ (_a = session.joinRoomResolve) === null || _a === undefined ? undefined : _a.call(session);
7213
7909
  session.joinRoomResolve = undefined;
7214
7910
  break;
7215
7911
  }
@@ -7232,7 +7928,7 @@ class CollabClient {
7232
7928
  session.locator = message.locator;
7233
7929
  this.pendingSessions.delete(message.refId);
7234
7930
  this.sessions.set(session.locator, session);
7235
- (_b = session.createRoomResolve) === null || _b === void 0 ? void 0 : _b.call(session, session.locator);
7931
+ (_b = session.createRoomResolve) === null || _b === undefined ? undefined : _b.call(session, session.locator);
7236
7932
  session.createRoomResolve = undefined;
7237
7933
  // Deliver queued AddMessages now that we have a locator.
7238
7934
  for (const message of session.addQueue) {
@@ -7488,21 +8184,21 @@ class Grid {
7488
8184
  */
7489
8185
  class AdjacencyLayout {
7490
8186
  apply(model) {
7491
- var _a, _b;
8187
+ var _a;
7492
8188
  if (model.nodes.length === 0) {
7493
8189
  // nothing to arrange...
7494
8190
  return model;
7495
8191
  }
7496
8192
  // arrange nodes
7497
8193
  const nodeArrangement = new Grid();
7498
- const nodesToBeArranged = model.nodes.all();
8194
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent);
7499
8195
  while (nodesToBeArranged.length > 0) {
7500
8196
  arrangeNode(nodesToBeArranged[0], nodeArrangement, [0, 0], nodesToBeArranged);
7501
8197
  }
7502
8198
  // place nodes according to arrangement
7503
8199
  const maximumWidth = Math.max(...model.nodes.map(n => n.width));
7504
8200
  const maximumHeight = Math.max(...model.nodes.map(n => n.height));
7505
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
8201
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
7506
8202
  for (let y = nodeArrangement.minY(); y <= nodeArrangement.maxY(); ++y) {
7507
8203
  for (let x = nodeArrangement.minX(); x <= nodeArrangement.maxX(); ++x) {
7508
8204
  const node = nodeArrangement.get([x, y]);
@@ -7511,7 +8207,6 @@ class AdjacencyLayout {
7511
8207
  }
7512
8208
  }
7513
8209
  }
7514
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7515
8210
  return model;
7516
8211
  }
7517
8212
  }
@@ -7532,14 +8227,14 @@ const arrangeNode = (node, nodeArrangement, coords, nodesToBeArranged) => {
7532
8227
  */
7533
8228
  class BreadthAdjacencyLayout {
7534
8229
  apply(model) {
7535
- var _a, _b;
8230
+ var _a;
7536
8231
  if (model.nodes.length === 0) {
7537
8232
  // nothing to arrange...
7538
8233
  return model;
7539
8234
  }
7540
8235
  // arrange nodes
7541
8236
  const nodeArrangement = new Grid();
7542
- const nodesToBeArranged = model.nodes.all();
8237
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent);
7543
8238
  const nodeGridIndices = {};
7544
8239
  const firstNode = nodesToBeArranged[0];
7545
8240
  let currentNodeLevel = [firstNode];
@@ -7568,7 +8263,7 @@ class BreadthAdjacencyLayout {
7568
8263
  // place nodes according to arrangement
7569
8264
  const maximumWidth = Math.max(...model.nodes.map(n => n.width));
7570
8265
  const maximumHeight = Math.max(...model.nodes.map(n => n.height));
7571
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
8266
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
7572
8267
  for (let y = nodeArrangement.minY(); y <= nodeArrangement.maxY(); ++y) {
7573
8268
  for (let x = nodeArrangement.minX(); x <= nodeArrangement.maxX(); ++x) {
7574
8269
  const node = nodeArrangement.get([x, y]);
@@ -7577,7 +8272,6 @@ class BreadthAdjacencyLayout {
7577
8272
  }
7578
8273
  }
7579
8274
  }
7580
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7581
8275
  return model;
7582
8276
  }
7583
8277
  }
@@ -7588,13 +8282,13 @@ class BreadthAdjacencyLayout {
7588
8282
  */
7589
8283
  class BreadthLayout {
7590
8284
  apply(model) {
7591
- var _a, _b;
8285
+ var _a;
7592
8286
  if (model.nodes.length === 0) {
7593
8287
  // nothing to arrange...
7594
8288
  return model;
7595
8289
  }
7596
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
7597
- let nodesToBeArranged = model.nodes.all();
8290
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
8291
+ let nodesToBeArranged = model.nodes.filter(n => !n.parent);
7598
8292
  // Arrange nodes by a breadth first search
7599
8293
  const firstNode = nodesToBeArranged[0];
7600
8294
  removeIfExists(nodesToBeArranged, firstNode);
@@ -7640,7 +8334,6 @@ class BreadthLayout {
7640
8334
  for (const connection of model.connections) {
7641
8335
  connection.tighten();
7642
8336
  }
7643
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7644
8337
  return model;
7645
8338
  }
7646
8339
  }
@@ -7651,14 +8344,14 @@ class BreadthLayout {
7651
8344
  */
7652
8345
  class ForceLayout {
7653
8346
  apply(model) {
7654
- var _a, _b;
8347
+ var _a;
7655
8348
  if (model.nodes.length === 0) {
7656
8349
  // nothing to arrange...
7657
8350
  return model;
7658
8351
  }
7659
8352
  // as a starting point, we apply a simple layout
7660
8353
  new BreadthLayout().apply(model);
7661
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
8354
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
7662
8355
  const coolingFactor = 0.99;
7663
8356
  const minimumTemperature = 1;
7664
8357
  const attractionFactor = 0.1;
@@ -7736,7 +8429,6 @@ class ForceLayout {
7736
8429
  for (const connection of model.connections) {
7737
8430
  connection.tighten();
7738
8431
  }
7739
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7740
8432
  return model;
7741
8433
  }
7742
8434
  }
@@ -7747,20 +8439,19 @@ class ForceLayout {
7747
8439
  */
7748
8440
  class HorizontalLayout {
7749
8441
  apply(model) {
7750
- var _a, _b;
8442
+ var _a;
7751
8443
  if (model.nodes.length === 0) {
7752
8444
  // nothing to arrange...
7753
8445
  return model;
7754
8446
  }
7755
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
7756
- const nodesToBeArranged = model.nodes.all();
8447
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
8448
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent);
7757
8449
  nodesToBeArranged.sort((a, b) => b.type.priority - a.type.priority);
7758
8450
  let widthAccumulator = 0;
7759
8451
  for (const node of nodesToBeArranged) {
7760
8452
  node.move([widthAccumulator, 0]);
7761
8453
  widthAccumulator += node.width + gapSize;
7762
8454
  }
7763
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7764
8455
  return model;
7765
8456
  }
7766
8457
  }
@@ -7771,7 +8462,7 @@ class HorizontalLayout {
7771
8462
  */
7772
8463
  class PriorityLayout {
7773
8464
  apply(model) {
7774
- var _a, _b;
8465
+ var _a;
7775
8466
  if (model.nodes.length === 0) {
7776
8467
  // nothing to arrange...
7777
8468
  return model;
@@ -7783,10 +8474,10 @@ class PriorityLayout {
7783
8474
  new BreadthLayout().apply(model);
7784
8475
  return model;
7785
8476
  }
7786
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
7787
- const nodesToBeArranged = model.nodes.all();
8477
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
8478
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent);
7788
8479
  const nodeArrangement = [];
7789
- const nodesWithMaximumPriorityToBeArranged = model.nodes.filter(n => n.getPriority() >= maximumPriority);
8480
+ const nodesWithMaximumPriorityToBeArranged = model.nodes.filter(n => !n.parent).filter(n => n.getPriority() >= maximumPriority);
7790
8481
  const nodesWithMaximumPriority = [];
7791
8482
  if (nodesWithMaximumPriorityToBeArranged.length > 1) {
7792
8483
  // use bfs to sort nodes by distance to the first node
@@ -7868,7 +8559,6 @@ class PriorityLayout {
7868
8559
  for (const connection of model.connections) {
7869
8560
  connection.tighten();
7870
8561
  }
7871
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7872
8562
  return model;
7873
8563
  }
7874
8564
  }
@@ -7879,7 +8569,7 @@ class PriorityLayout {
7879
8569
  */
7880
8570
  class TreeLayout {
7881
8571
  apply(model) {
7882
- var _a, _b;
8572
+ var _a;
7883
8573
  if (model.nodes.length === 0) {
7884
8574
  // nothing to arrange...
7885
8575
  return model;
@@ -7891,8 +8581,8 @@ class TreeLayout {
7891
8581
  new BreadthLayout().apply(model);
7892
8582
  return model;
7893
8583
  }
7894
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
7895
- const nodesToBeArranged = [...model.nodes].sort((n1, n2) => n2.getPriority() - n1.getPriority());
8584
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
8585
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent).sort((n1, n2) => n2.getPriority() - n1.getPriority());
7896
8586
  const branches = [];
7897
8587
  while (nodesToBeArranged.length > 0) {
7898
8588
  const nodeToBeArranged = nodesToBeArranged[0];
@@ -7921,7 +8611,6 @@ class TreeLayout {
7921
8611
  for (const connection of model.connections) {
7922
8612
  connection.tighten();
7923
8613
  }
7924
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7925
8614
  return model;
7926
8615
  }
7927
8616
  }
@@ -7978,20 +8667,19 @@ class Branch {
7978
8667
  */
7979
8668
  class VerticalLayout {
7980
8669
  apply(model) {
7981
- var _a, _b;
8670
+ var _a;
7982
8671
  if (model.nodes.length === 0) {
7983
8672
  // nothing to arrange...
7984
8673
  return model;
7985
8674
  }
7986
- const gapSize = (((_a = model.canvas) === null || _a === void 0 ? void 0 : _a.gridSize) || 0) * 2;
7987
- const nodesToBeArranged = model.nodes.all();
8675
+ const gapSize = (((_a = model.canvas) === null || _a === undefined ? undefined : _a.gridSize) || 0) * 2;
8676
+ const nodesToBeArranged = model.nodes.filter(n => !n.parent);
7988
8677
  nodesToBeArranged.sort((a, b) => b.type.priority - a.type.priority);
7989
8678
  let heightAccumulator = 0;
7990
8679
  for (const node of nodesToBeArranged) {
7991
8680
  node.move([0, heightAccumulator]);
7992
8681
  heightAccumulator += node.height + gapSize;
7993
8682
  }
7994
- (_b = model.canvas) === null || _b === void 0 ? void 0 : _b.diagramChange$.next();
7995
8683
  return model;
7996
8684
  }
7997
8685
  }
@@ -8009,5 +8697,12 @@ const layouts = {
8009
8697
  tree: new TreeLayout(),
8010
8698
  vertical: new VerticalLayout()
8011
8699
  };
8700
+ const getLocationsOfNodes = model => {
8701
+ const locations = {};
8702
+ for (const node of model.nodes) {
8703
+ locations[node.id] = node.coords;
8704
+ }
8705
+ return locations;
8706
+ };
8012
8707
 
8013
- export { ACTION_STACK_SIZE, ActionStack, AddConnectionAction, AddNodeAction, AdjacencyLayout, BreadthAdjacencyLayout, BreadthLayout, ClosedShape, CollabClient, Corner, CursorStyle, DIAGRAM_FIELD_DEFAULTS, DagaExporter, DagaImporter, DiagramActions, DiagramCanvas, DiagramConnection, DiagramConnectionSet, DiagramConnectionType, DiagramContextMenu, DiagramDecorator, DiagramDecoratorSet, DiagramElement, DiagramElementSet, DiagramEntitySet, DiagramEvent, DiagramField, DiagramFieldSet, DiagramModel, DiagramNode, DiagramNodeSet, DiagramNodeType, DiagramObject, DiagramObjectSet, DiagramPort, DiagramPortSet, DiagramSection, DiagramSectionSet, DiagramUserHighlight, DiagramUserSelection, DragEvents, EditFieldAction, Events, ForceLayout, HorizontalAlign, HorizontalLayout, Keys, LineShape, LineStyle, PriorityLayout, Property, PropertySet, RemoveAction, SetGeometryAction, Side, TreeLayout, Type, UpdateValuesAction, ValueSet, VerticalAlign, VerticalLayout, ZoomEvents, addIfNotExists, diff, equals, generalClosedPath, getBottomMargin, getBottomPadding, getLeftMargin, getLeftPadding, getRightMargin, getRightPadding, getTopMargin, getTopPadding, isObject, layouts, linePath, lineStyleDasharray, removeIfExists, setCursorStyle };
8708
+ export { ACTION_STACK_SIZE, ActionStack, AddConnectionAction, AddNodeAction, AdjacencyLayout, ApplyLayoutAction, BreadthAdjacencyLayout, BreadthLayout, ClosedShape, CollabClient, Corner, CursorStyle, DIAGRAM_FIELD_DEFAULTS, DagaExporter, DagaImporter, DiagramActionMethod, DiagramActions, DiagramCanvas, DiagramConnection, DiagramConnectionSet, DiagramConnectionType, DiagramContextMenu, DiagramDecorator, DiagramDecoratorSet, DiagramDoubleClickEvent, DiagramElement, DiagramElementSet, DiagramEntitySet, DiagramEvent, DiagramEvents, DiagramField, DiagramFieldSet, DiagramModel, DiagramNode, DiagramNodeSet, DiagramNodeType, DiagramObject, DiagramObjectSet, DiagramPort, DiagramPortSet, DiagramSecondaryClickEvent, DiagramSection, DiagramSectionSet, DiagramUserHighlight, DiagramUserSelection, DragEvents, EditFieldAction, Events, ForceLayout, HorizontalAlign, HorizontalLayout, Keys, LineShape, LineStyle, MoveAction, PasteAction, PriorityLayout, Property, PropertySet, RemoveAction, SetGeometryAction, SetParentAction, Side, TreeLayout, Type, UpdateValuesAction, ValueSet, VerticalAlign, VerticalLayout, ZoomEvents, addIfNotExists, diff, equals, filterByOnlyAncestors, filterByOnlyDescendants, generalClosedPath, getBottomMargin, getBottomPadding$1 as getBottomPadding, getLeftMargin, getLeftPadding$1 as getLeftPadding, getLocationsOfNodes, getRightMargin, getRightPadding$1 as getRightPadding, getTopMargin, getTopPadding$1 as getTopPadding, isObject, layouts, linePath, lineStyleDasharray, removeIfExists, setCursorStyle };