@metadev/daga 2.0.2 → 3.0.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.cjs.js CHANGED
@@ -209,6 +209,8 @@ exports.Events = void 0;
209
209
  Events["KeyDown"] = "keydown";
210
210
  Events["KeyUp"] = "keyup";
211
211
  Events["MouseDown"] = "mousedown";
212
+ Events["MouseEnter"] = "mouseenter";
213
+ Events["MouseLeave"] = "mouseleave";
212
214
  Events["MouseMove"] = "mousemove";
213
215
  Events["MouseOut"] = "mouseout";
214
216
  Events["MouseOver"] = "mouseover";
@@ -1945,6 +1947,293 @@ class DiagramConnectionSet extends DiagramElementSet {
1945
1947
  }
1946
1948
  }
1947
1949
 
1950
+ /**
1951
+ * Default values of the parameters of a diagram field.
1952
+ * @private
1953
+ * @see DiagramField
1954
+ */
1955
+ const DIAGRAM_FIELD_DEFAULTS = {
1956
+ editable: true,
1957
+ fontSize: 0,
1958
+ margin: 0,
1959
+ padding: 0,
1960
+ fontFamily: "'Wonder Unit Sans', sans-serif",
1961
+ color: '#000000',
1962
+ selectedColor: '#000000',
1963
+ horizontalAlign: exports.HorizontalAlign.Center,
1964
+ verticalAlign: exports.VerticalAlign.Center,
1965
+ fit: false
1966
+ };
1967
+ /**
1968
+ * A field which displays text and is part of a diagram element.
1969
+ * @public
1970
+ * @see DiagramNode
1971
+ * @see DiagramPort
1972
+ * @see DiagramSection
1973
+ */
1974
+ class DiagramField extends DiagramElement {
1975
+ /**
1976
+ * Text contents of this field.
1977
+ * @public
1978
+ */
1979
+ get text() {
1980
+ return this._text;
1981
+ }
1982
+ set text(value) {
1983
+ var _a;
1984
+ if (value.trim() === '') {
1985
+ value = this.defaultText;
1986
+ }
1987
+ this._text = value;
1988
+ this.updateInView();
1989
+ if (this.fit) {
1990
+ (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
1991
+ }
1992
+ }
1993
+ constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit) {
1994
+ const id = `${rootElement === null || rootElement === void 0 ? void 0 : rootElement.id}_field`;
1995
+ if (model.fields.get(id) !== undefined) {
1996
+ throw new Error('DiagramField for rootElement already exists');
1997
+ }
1998
+ super(model, id);
1999
+ /**
2000
+ * Collaborative timestamp for text.
2001
+ * @public
2002
+ */
2003
+ this.textTimestamp = null;
2004
+ this.rootElement = rootElement;
2005
+ this.coords = coords;
2006
+ this.width = width;
2007
+ this.height = height;
2008
+ this.fontSize = fontSize;
2009
+ this.fontFamily = fontFamily;
2010
+ this.color = color;
2011
+ this.selectedColor = selectedColor;
2012
+ this.horizontalAlign = horizontalAlign;
2013
+ this.verticalAlign = verticalAlign;
2014
+ this.defaultText = text;
2015
+ this._text = text;
2016
+ this.editable = editable;
2017
+ this.fit = fit;
2018
+ }
2019
+ select() {
2020
+ var _a, _b;
2021
+ 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}`);
2022
+ }
2023
+ get removed() {
2024
+ return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
2025
+ }
2026
+ updateInView() {
2027
+ var _a;
2028
+ (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateFieldsInView(this.id);
2029
+ }
2030
+ /**
2031
+ * Change the coordinates of this field to the given coordinates.
2032
+ * @public
2033
+ * @param coords A point in the diagram.
2034
+ */
2035
+ move(coords) {
2036
+ this.coords = coords;
2037
+ this.updateInView();
2038
+ }
2039
+ getPriority() {
2040
+ var _a;
2041
+ return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
2042
+ }
2043
+ }
2044
+ class DiagramFieldSet extends DiagramElementSet {
2045
+ /**
2046
+ * Instance a set of fields for the given model. This method is used internally.
2047
+ * @private
2048
+ */
2049
+ constructor(model) {
2050
+ super();
2051
+ this.model = model;
2052
+ }
2053
+ /**
2054
+ * Instance a new field and add it to this set. This method is normally called when instancing an element with a field and it is rarely called by itself.
2055
+ * @private
2056
+ */
2057
+ new(rootElement, coords, fontSize, fontFamily, color, selectedColor, width, height, horizontalAlign, verticalAlign, text, editable, fit) {
2058
+ const field = new DiagramField(this.model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit);
2059
+ super.add(field);
2060
+ field.updateInView();
2061
+ // add this field to its root element
2062
+ if (rootElement !== undefined) {
2063
+ rootElement.label = field;
2064
+ }
2065
+ return field;
2066
+ }
2067
+ remove(id) {
2068
+ var _a;
2069
+ const field = this.get(id, true);
2070
+ if (field) {
2071
+ // remove from root element
2072
+ if (((_a = field.rootElement) === null || _a === void 0 ? void 0 : _a.label) !== undefined) {
2073
+ if (field.rootElement.label === field) {
2074
+ field.rootElement.label = undefined;
2075
+ }
2076
+ }
2077
+ // remove from set of fields
2078
+ super.remove(id);
2079
+ // remove from canvas
2080
+ field.updateInView();
2081
+ }
2082
+ }
2083
+ }
2084
+ const getBottomMargin = config => {
2085
+ if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2086
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2087
+ } else if (typeof config.margin === 'number') {
2088
+ return config.margin;
2089
+ } else {
2090
+ if (config.margin.length === 0) {
2091
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2092
+ } else if (config.margin.length === 1) {
2093
+ return config.margin[0];
2094
+ } else if (config.margin.length === 2) {
2095
+ return config.margin[0];
2096
+ } else if (config.margin.length === 3) {
2097
+ return config.margin[2];
2098
+ } else {
2099
+ return config.margin[2];
2100
+ }
2101
+ }
2102
+ };
2103
+ const getLeftMargin = config => {
2104
+ if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2105
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2106
+ } else if (typeof config.margin === 'number') {
2107
+ return config.margin;
2108
+ } else {
2109
+ if (config.margin.length === 0) {
2110
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2111
+ } else if (config.margin.length === 1) {
2112
+ return config.margin[0];
2113
+ } else if (config.margin.length === 2) {
2114
+ return config.margin[1];
2115
+ } else if (config.margin.length === 3) {
2116
+ return config.margin[1];
2117
+ } else {
2118
+ return config.margin[3];
2119
+ }
2120
+ }
2121
+ };
2122
+ const getRightMargin = config => {
2123
+ if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2124
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2125
+ } else if (typeof config.margin === 'number') {
2126
+ return config.margin;
2127
+ } else {
2128
+ if (config.margin.length === 0) {
2129
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2130
+ } else if (config.margin.length === 1) {
2131
+ return config.margin[0];
2132
+ } else if (config.margin.length === 2) {
2133
+ return config.margin[1];
2134
+ } else if (config.margin.length === 3) {
2135
+ return config.margin[1];
2136
+ } else {
2137
+ return config.margin[1];
2138
+ }
2139
+ }
2140
+ };
2141
+ const getTopMargin = config => {
2142
+ if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
2143
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2144
+ } else if (typeof config.margin === 'number') {
2145
+ return config.margin;
2146
+ } else {
2147
+ if (config.margin.length === 0) {
2148
+ return DIAGRAM_FIELD_DEFAULTS.margin;
2149
+ } else if (config.margin.length === 1) {
2150
+ return config.margin[0];
2151
+ } else if (config.margin.length === 2) {
2152
+ return config.margin[0];
2153
+ } else if (config.margin.length === 3) {
2154
+ return config.margin[0];
2155
+ } else {
2156
+ return config.margin[0];
2157
+ }
2158
+ }
2159
+ };
2160
+ const getBottomPadding = config => {
2161
+ if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2162
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2163
+ } else if (typeof config.padding === 'number') {
2164
+ return config.padding;
2165
+ } else {
2166
+ if (config.padding.length === 0) {
2167
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2168
+ } else if (config.padding.length === 1) {
2169
+ return config.padding[0];
2170
+ } else if (config.padding.length === 2) {
2171
+ return config.padding[0];
2172
+ } else if (config.padding.length === 3) {
2173
+ return config.padding[2];
2174
+ } else {
2175
+ return config.padding[2];
2176
+ }
2177
+ }
2178
+ };
2179
+ const getLeftPadding = config => {
2180
+ if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2181
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2182
+ } else if (typeof config.padding === 'number') {
2183
+ return config.padding;
2184
+ } else {
2185
+ if (config.padding.length === 0) {
2186
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2187
+ } else if (config.padding.length === 1) {
2188
+ return config.padding[0];
2189
+ } else if (config.padding.length === 2) {
2190
+ return config.padding[1];
2191
+ } else if (config.padding.length === 3) {
2192
+ return config.padding[1];
2193
+ } else {
2194
+ return config.padding[3];
2195
+ }
2196
+ }
2197
+ };
2198
+ const getRightPadding = config => {
2199
+ if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2200
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2201
+ } else if (typeof config.padding === 'number') {
2202
+ return config.padding;
2203
+ } else {
2204
+ if (config.padding.length === 0) {
2205
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2206
+ } else if (config.padding.length === 1) {
2207
+ return config.padding[0];
2208
+ } else if (config.padding.length === 2) {
2209
+ return config.padding[1];
2210
+ } else if (config.padding.length === 3) {
2211
+ return config.padding[1];
2212
+ } else {
2213
+ return config.padding[1];
2214
+ }
2215
+ }
2216
+ };
2217
+ const getTopPadding = config => {
2218
+ if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
2219
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2220
+ } else if (typeof config.padding === 'number') {
2221
+ return config.padding;
2222
+ } else {
2223
+ if (config.padding.length === 0) {
2224
+ return DIAGRAM_FIELD_DEFAULTS.padding;
2225
+ } else if (config.padding.length === 1) {
2226
+ return config.padding[0];
2227
+ } else if (config.padding.length === 2) {
2228
+ return config.padding[0];
2229
+ } else if (config.padding.length === 3) {
2230
+ return config.padding[0];
2231
+ } else {
2232
+ return config.padding[0];
2233
+ }
2234
+ }
2235
+ };
2236
+
1948
2237
  /**
1949
2238
  * Default values of the look of a diagram section.
1950
2239
  * @private
@@ -2895,220 +3184,77 @@ class DiagramPort extends DiagramElement {
2895
3184
  * Connections that end at this port.
2896
3185
  * @public
2897
3186
  */
2898
- this.incomingConnections = [];
2899
- this.rootElement = rootElement;
2900
- this.coords = coords;
2901
- this.direction = direction;
2902
- }
2903
- get removed() {
2904
- return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
2905
- }
2906
- updateInView() {
2907
- var _a;
2908
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
2909
- }
2910
- /**
2911
- * Add a connection to this port's list of outgoing connections.
2912
- * @public
2913
- * @param connection A connection.
2914
- */
2915
- startConnection(connection) {
2916
- this.outgoingConnections.push(connection);
2917
- }
2918
- /**
2919
- * Add a connection to this port's list of incoming connections.
2920
- * @public
2921
- * @param connection A connection.
2922
- */
2923
- finishConnection(connection) {
2924
- this.incomingConnections.push(connection);
2925
- }
2926
- /**
2927
- * Get the root node of this port, which is either its rootElement if it's a node or it's rootElement's node if it's a section.
2928
- * @public
2929
- * @returns A node if it could be found, `undefined` otherwise.
2930
- */
2931
- getNode() {
2932
- if (this.rootElement instanceof DiagramNode) {
2933
- return this.rootElement;
2934
- } else if (this.rootElement instanceof DiagramSection) {
2935
- return this.rootElement.node;
2936
- }
2937
- return undefined;
2938
- }
2939
- getPriority() {
2940
- var _a;
2941
- return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
2942
- }
2943
- /**
2944
- * Change the coordinates of this port to the given coordinates and move its labels correspondingly.
2945
- * @public
2946
- * @param coords A point in the diagram.
2947
- */
2948
- move(coords) {
2949
- const coordDifferences = [coords[0] - this.coords[0], coords[1] - this.coords[1]];
2950
- this.coords = coords;
2951
- for (const connection of this.outgoingConnections) {
2952
- connection.setStart(this);
2953
- }
2954
- for (const connection of this.incomingConnections) {
2955
- connection.setEnd(this);
2956
- }
2957
- if (this.label) {
2958
- this.label.move([this.label.coords[0] + coordDifferences[0], this.label.coords[1] + coordDifferences[1]]);
2959
- }
2960
- this.updateInView();
2961
- }
2962
- distanceTo(coords) {
2963
- return distanceBetweenPoints(this.coords, coords);
2964
- }
2965
- }
2966
- class DiagramPortSet extends DiagramElementSet {
2967
- /**
2968
- * Instance a set of ports for the given model. This method is used internally.
2969
- * @private
2970
- */
2971
- constructor(model) {
2972
- super();
2973
- this.model = model;
2974
- }
2975
- /**
2976
- * Instance a new port and add it to this set. This method is normally called when instancing an element with a port and it is rarely called by itself.
2977
- * @private
2978
- */
2979
- new(rootElement, coords, direction, id) {
2980
- const port = new DiagramPort(this.model, rootElement, coords, direction, id);
2981
- super.add(port);
2982
- port.updateInView();
2983
- // add this port to its root element
2984
- if (rootElement !== undefined) {
2985
- rootElement.ports.push(port);
2986
- }
2987
- return port;
2988
- }
2989
- remove(id) {
2990
- const port = this.get(id, true);
2991
- if (port) {
2992
- // remove all connections
2993
- while (port.outgoingConnections.length > 0) {
2994
- this.model.connections.remove(port.outgoingConnections[0].id);
2995
- }
2996
- while (port.incomingConnections.length > 0) {
2997
- this.model.connections.remove(port.incomingConnections[0].id);
2998
- }
2999
- // remove label
3000
- if (port.label) {
3001
- this.model.fields.remove(port.label.id);
3002
- }
3003
- // remove from root element
3004
- if (port.rootElement instanceof DiagramNode || port.rootElement instanceof DiagramSection) {
3005
- removeIfExists(port.rootElement.ports, port);
3006
- }
3007
- // remove from set of ports
3008
- super.remove(id);
3009
- // remove from canvas
3010
- port.updateInView();
3011
- }
3012
- }
3013
- }
3014
-
3015
- /**
3016
- * Default values of the parameters of a diagram field.
3017
- * @private
3018
- * @see DiagramField
3019
- */
3020
- const DIAGRAM_FIELD_DEFAULTS = {
3021
- editable: true,
3022
- fontSize: 0,
3023
- margin: 0,
3024
- padding: 0,
3025
- fontFamily: "'Wonder Unit Sans', sans-serif",
3026
- color: '#000000',
3027
- selectedColor: '#000000',
3028
- horizontalAlign: exports.HorizontalAlign.Center,
3029
- verticalAlign: exports.VerticalAlign.Center,
3030
- fit: false
3031
- };
3032
- /**
3033
- * A field which displays text and is part of a diagram element.
3034
- * @public
3035
- * @see DiagramNode
3036
- * @see DiagramPort
3037
- * @see DiagramSection
3038
- */
3039
- class DiagramField extends DiagramElement {
3040
- /**
3041
- * Text contents of this field.
3042
- * @public
3043
- */
3044
- get text() {
3045
- return this._text;
3046
- }
3047
- set text(value) {
3048
- var _a;
3049
- if (value.trim() === '') {
3050
- value = this.defaultText;
3051
- }
3052
- this._text = value;
3053
- this.updateInView();
3054
- if (this.fit) {
3055
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
3056
- }
3057
- }
3058
- constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit) {
3059
- const id = `${rootElement === null || rootElement === void 0 ? void 0 : rootElement.id}_field`;
3060
- if (model.fields.get(id) !== undefined) {
3061
- throw new Error('DiagramField for rootElement already exists');
3062
- }
3063
- super(model, id);
3064
- /**
3065
- * Collaborative timestamp for text.
3066
- * @public
3067
- */
3068
- this.textTimestamp = null;
3069
- this.rootElement = rootElement;
3070
- this.coords = coords;
3071
- this.width = width;
3072
- this.height = height;
3073
- this.fontSize = fontSize;
3074
- this.fontFamily = fontFamily;
3075
- this.color = color;
3076
- this.selectedColor = selectedColor;
3077
- this.horizontalAlign = horizontalAlign;
3078
- this.verticalAlign = verticalAlign;
3079
- this.defaultText = text;
3080
- this._text = text;
3081
- this.editable = editable;
3082
- this.fit = fit;
3083
- }
3084
- select() {
3085
- var _a, _b;
3086
- 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}`);
3187
+ this.incomingConnections = [];
3188
+ this.rootElement = rootElement;
3189
+ this.coords = coords;
3190
+ this.direction = direction;
3087
3191
  }
3088
3192
  get removed() {
3089
3193
  return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
3090
3194
  }
3091
3195
  updateInView() {
3092
3196
  var _a;
3093
- (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateFieldsInView(this.id);
3197
+ (_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
3094
3198
  }
3095
3199
  /**
3096
- * Change the coordinates of this field to the given coordinates.
3200
+ * Add a connection to this port's list of outgoing connections.
3201
+ * @public
3202
+ * @param connection A connection.
3203
+ */
3204
+ startConnection(connection) {
3205
+ this.outgoingConnections.push(connection);
3206
+ }
3207
+ /**
3208
+ * Add a connection to this port's list of incoming connections.
3209
+ * @public
3210
+ * @param connection A connection.
3211
+ */
3212
+ finishConnection(connection) {
3213
+ this.incomingConnections.push(connection);
3214
+ }
3215
+ /**
3216
+ * Get the root node of this port, which is either its rootElement if it's a node or it's rootElement's node if it's a section.
3217
+ * @public
3218
+ * @returns A node if it could be found, `undefined` otherwise.
3219
+ */
3220
+ getNode() {
3221
+ if (this.rootElement instanceof DiagramNode) {
3222
+ return this.rootElement;
3223
+ } else if (this.rootElement instanceof DiagramSection) {
3224
+ return this.rootElement.node;
3225
+ }
3226
+ return undefined;
3227
+ }
3228
+ getPriority() {
3229
+ var _a;
3230
+ return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
3231
+ }
3232
+ /**
3233
+ * Change the coordinates of this port to the given coordinates and move its labels correspondingly.
3097
3234
  * @public
3098
3235
  * @param coords A point in the diagram.
3099
3236
  */
3100
3237
  move(coords) {
3238
+ const coordDifferences = [coords[0] - this.coords[0], coords[1] - this.coords[1]];
3101
3239
  this.coords = coords;
3240
+ for (const connection of this.outgoingConnections) {
3241
+ connection.setStart(this);
3242
+ }
3243
+ for (const connection of this.incomingConnections) {
3244
+ connection.setEnd(this);
3245
+ }
3246
+ if (this.label) {
3247
+ this.label.move([this.label.coords[0] + coordDifferences[0], this.label.coords[1] + coordDifferences[1]]);
3248
+ }
3102
3249
  this.updateInView();
3103
3250
  }
3104
- getPriority() {
3105
- var _a;
3106
- return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
3251
+ distanceTo(coords) {
3252
+ return distanceBetweenPoints(this.coords, coords);
3107
3253
  }
3108
3254
  }
3109
- class DiagramFieldSet extends DiagramElementSet {
3255
+ class DiagramPortSet extends DiagramElementSet {
3110
3256
  /**
3111
- * Instance a set of fields for the given model. This method is used internally.
3257
+ * Instance a set of ports for the given model. This method is used internally.
3112
3258
  * @private
3113
3259
  */
3114
3260
  constructor(model) {
@@ -3116,187 +3262,44 @@ class DiagramFieldSet extends DiagramElementSet {
3116
3262
  this.model = model;
3117
3263
  }
3118
3264
  /**
3119
- * Instance a new field and add it to this set. This method is normally called when instancing an element with a field and it is rarely called by itself.
3265
+ * Instance a new port and add it to this set. This method is normally called when instancing an element with a port and it is rarely called by itself.
3120
3266
  * @private
3121
3267
  */
3122
- new(rootElement, coords, fontSize, fontFamily, color, selectedColor, width, height, horizontalAlign, verticalAlign, text, editable, fit) {
3123
- const field = new DiagramField(this.model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit);
3124
- super.add(field);
3125
- field.updateInView();
3126
- // add this field to its root element
3268
+ new(rootElement, coords, direction, id) {
3269
+ const port = new DiagramPort(this.model, rootElement, coords, direction, id);
3270
+ super.add(port);
3271
+ port.updateInView();
3272
+ // add this port to its root element
3127
3273
  if (rootElement !== undefined) {
3128
- rootElement.label = field;
3274
+ rootElement.ports.push(port);
3129
3275
  }
3130
- return field;
3276
+ return port;
3131
3277
  }
3132
3278
  remove(id) {
3133
- const field = this.get(id, true);
3134
- if (field) {
3279
+ const port = this.get(id, true);
3280
+ if (port) {
3281
+ // remove all connections
3282
+ while (port.outgoingConnections.length > 0) {
3283
+ this.model.connections.remove(port.outgoingConnections[0].id);
3284
+ }
3285
+ while (port.incomingConnections.length > 0) {
3286
+ this.model.connections.remove(port.incomingConnections[0].id);
3287
+ }
3288
+ // remove label
3289
+ if (port.label) {
3290
+ this.model.fields.remove(port.label.id);
3291
+ }
3135
3292
  // remove from root element
3136
- if (field.rootElement instanceof DiagramNode || field.rootElement instanceof DiagramSection || field.rootElement instanceof DiagramPort) {
3137
- if (field.rootElement.label === field) {
3138
- field.rootElement.label = undefined;
3139
- }
3293
+ if (port.rootElement instanceof DiagramNode || port.rootElement instanceof DiagramSection) {
3294
+ removeIfExists(port.rootElement.ports, port);
3140
3295
  }
3141
- // remove from set of fields
3296
+ // remove from set of ports
3142
3297
  super.remove(id);
3143
3298
  // remove from canvas
3144
- field.updateInView();
3299
+ port.updateInView();
3145
3300
  }
3146
3301
  }
3147
3302
  }
3148
- const getBottomMargin = config => {
3149
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
3150
- return DIAGRAM_FIELD_DEFAULTS.margin;
3151
- } else if (typeof config.margin === 'number') {
3152
- return config.margin;
3153
- } else {
3154
- if (config.margin.length === 0) {
3155
- return DIAGRAM_FIELD_DEFAULTS.margin;
3156
- } else if (config.margin.length === 1) {
3157
- return config.margin[0];
3158
- } else if (config.margin.length === 2) {
3159
- return config.margin[0];
3160
- } else if (config.margin.length === 3) {
3161
- return config.margin[2];
3162
- } else {
3163
- return config.margin[2];
3164
- }
3165
- }
3166
- };
3167
- const getLeftMargin = config => {
3168
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
3169
- return DIAGRAM_FIELD_DEFAULTS.margin;
3170
- } else if (typeof config.margin === 'number') {
3171
- return config.margin;
3172
- } else {
3173
- if (config.margin.length === 0) {
3174
- return DIAGRAM_FIELD_DEFAULTS.margin;
3175
- } else if (config.margin.length === 1) {
3176
- return config.margin[0];
3177
- } else if (config.margin.length === 2) {
3178
- return config.margin[1];
3179
- } else if (config.margin.length === 3) {
3180
- return config.margin[1];
3181
- } else {
3182
- return config.margin[3];
3183
- }
3184
- }
3185
- };
3186
- const getRightMargin = config => {
3187
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
3188
- return DIAGRAM_FIELD_DEFAULTS.margin;
3189
- } else if (typeof config.margin === 'number') {
3190
- return config.margin;
3191
- } else {
3192
- if (config.margin.length === 0) {
3193
- return DIAGRAM_FIELD_DEFAULTS.margin;
3194
- } else if (config.margin.length === 1) {
3195
- return config.margin[0];
3196
- } else if (config.margin.length === 2) {
3197
- return config.margin[1];
3198
- } else if (config.margin.length === 3) {
3199
- return config.margin[1];
3200
- } else {
3201
- return config.margin[1];
3202
- }
3203
- }
3204
- };
3205
- const getTopMargin = config => {
3206
- if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
3207
- return DIAGRAM_FIELD_DEFAULTS.margin;
3208
- } else if (typeof config.margin === 'number') {
3209
- return config.margin;
3210
- } else {
3211
- if (config.margin.length === 0) {
3212
- return DIAGRAM_FIELD_DEFAULTS.margin;
3213
- } else if (config.margin.length === 1) {
3214
- return config.margin[0];
3215
- } else if (config.margin.length === 2) {
3216
- return config.margin[0];
3217
- } else if (config.margin.length === 3) {
3218
- return config.margin[0];
3219
- } else {
3220
- return config.margin[0];
3221
- }
3222
- }
3223
- };
3224
- const getBottomPadding = config => {
3225
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
3226
- return DIAGRAM_FIELD_DEFAULTS.padding;
3227
- } else if (typeof config.padding === 'number') {
3228
- return config.padding;
3229
- } else {
3230
- if (config.padding.length === 0) {
3231
- return DIAGRAM_FIELD_DEFAULTS.padding;
3232
- } else if (config.padding.length === 1) {
3233
- return config.padding[0];
3234
- } else if (config.padding.length === 2) {
3235
- return config.padding[0];
3236
- } else if (config.padding.length === 3) {
3237
- return config.padding[2];
3238
- } else {
3239
- return config.padding[2];
3240
- }
3241
- }
3242
- };
3243
- const getLeftPadding = config => {
3244
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
3245
- return DIAGRAM_FIELD_DEFAULTS.padding;
3246
- } else if (typeof config.padding === 'number') {
3247
- return config.padding;
3248
- } else {
3249
- if (config.padding.length === 0) {
3250
- return DIAGRAM_FIELD_DEFAULTS.padding;
3251
- } else if (config.padding.length === 1) {
3252
- return config.padding[0];
3253
- } else if (config.padding.length === 2) {
3254
- return config.padding[1];
3255
- } else if (config.padding.length === 3) {
3256
- return config.padding[1];
3257
- } else {
3258
- return config.padding[3];
3259
- }
3260
- }
3261
- };
3262
- const getRightPadding = config => {
3263
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
3264
- return DIAGRAM_FIELD_DEFAULTS.padding;
3265
- } else if (typeof config.padding === 'number') {
3266
- return config.padding;
3267
- } else {
3268
- if (config.padding.length === 0) {
3269
- return DIAGRAM_FIELD_DEFAULTS.padding;
3270
- } else if (config.padding.length === 1) {
3271
- return config.padding[0];
3272
- } else if (config.padding.length === 2) {
3273
- return config.padding[1];
3274
- } else if (config.padding.length === 3) {
3275
- return config.padding[1];
3276
- } else {
3277
- return config.padding[1];
3278
- }
3279
- }
3280
- };
3281
- const getTopPadding = config => {
3282
- if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
3283
- return DIAGRAM_FIELD_DEFAULTS.padding;
3284
- } else if (typeof config.padding === 'number') {
3285
- return config.padding;
3286
- } else {
3287
- if (config.padding.length === 0) {
3288
- return DIAGRAM_FIELD_DEFAULTS.padding;
3289
- } else if (config.padding.length === 1) {
3290
- return config.padding[0];
3291
- } else if (config.padding.length === 2) {
3292
- return config.padding[0];
3293
- } else if (config.padding.length === 3) {
3294
- return config.padding[0];
3295
- } else {
3296
- return config.padding[0];
3297
- }
3298
- }
3299
- };
3300
3303
 
3301
3304
  /**
3302
3305
  * Importer which imports a diagram from its daga model representation.
@@ -5301,6 +5304,15 @@ const ACTION_STACK_SIZE = 25;
5301
5304
  const UNFINISHED_CONNECTION_ID = 'diagram-connection-unfinished';
5302
5305
  const MAX_DISTANCE_TO_PORT = 100;
5303
5306
  class DiagramCanvas {
5307
+ get connectionType() {
5308
+ return this._connectionType;
5309
+ }
5310
+ set connectionType(value) {
5311
+ var _a, _b;
5312
+ this._connectionType = value;
5313
+ // refresh the palette every time connectionType is set so that the palette keeps track of updates to the connectionType
5314
+ (_b = (_a = this.parentComponent) === null || _a === void 0 ? void 0 : _a.palette) === null || _b === void 0 ? void 0 : _b.refreshPalette();
5315
+ }
5304
5316
  /**
5305
5317
  * Constructs a canvas object.
5306
5318
  * @public
@@ -5357,7 +5369,7 @@ class DiagramCanvas {
5357
5369
  const connectionType = new DiagramConnectionType(Object.assign(Object.assign({}, config.connectionTypeDefaults), connectionTypeConfig));
5358
5370
  this.model.connections.types.add(connectionType);
5359
5371
  }
5360
- this.connectionType = config.defaultConnection !== undefined ? this.model.connections.types.get(config.defaultConnection) : undefined;
5372
+ this._connectionType = config.defaultConnection !== undefined ? this.model.connections.types.get(config.defaultConnection) : undefined;
5361
5373
  }
5362
5374
  }
5363
5375
  addValidator(validator) {
@@ -6390,6 +6402,8 @@ class DiagramCanvas {
6390
6402
  const userHighlight = this.userHighlight.getFocus();
6391
6403
  if (userHighlight instanceof DiagramPort) {
6392
6404
  this.finishConnection(userHighlight);
6405
+ } else if (userHighlight instanceof DiagramField && userHighlight.rootElement instanceof DiagramPort) {
6406
+ this.finishConnection(userHighlight.rootElement);
6393
6407
  } else if (userHighlight instanceof DiagramNode || userHighlight instanceof DiagramSection || userHighlight instanceof DiagramField) {
6394
6408
  let targetRootElement;
6395
6409
  if (userHighlight instanceof DiagramNode || userHighlight instanceof DiagramSection) {
@@ -7134,7 +7148,7 @@ const getRelatedNodeOrItself = element => {
7134
7148
  if (element instanceof DiagramSection) {
7135
7149
  return element.node || element;
7136
7150
  }
7137
- return element.rootElement !== undefined ? getRelatedNodeOrItself(element.rootElement) : element;
7151
+ return element.rootElement instanceof DiagramNode || element.rootElement instanceof DiagramSection || element.rootElement instanceof DiagramPort ? getRelatedNodeOrItself(element.rootElement) : element;
7138
7152
  };
7139
7153
 
7140
7154
  const VERSION = '0.0.1';