@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/Changelog.md +10 -0
- package/index.cjs.js +380 -366
- package/index.esm.js +380 -366
- package/package.json +1 -1
- package/src/lib/diagram/canvas/diagram-canvas.d.ts +3 -1
- package/src/lib/diagram/diagram-config.d.ts +9 -0
- package/src/lib/diagram/model/diagram-field.d.ts +6 -6
- package/src/lib/diagram/model/diagram-node.d.ts +2 -2
- package/src/lib/diagram/model/diagram-port.d.ts +2 -2
- package/src/lib/diagram/model/diagram-section.d.ts +2 -2
- package/src/lib/util/events.d.ts +2 -0
package/index.esm.js
CHANGED
|
@@ -188,6 +188,8 @@ var Events;
|
|
|
188
188
|
Events["KeyDown"] = "keydown";
|
|
189
189
|
Events["KeyUp"] = "keyup";
|
|
190
190
|
Events["MouseDown"] = "mousedown";
|
|
191
|
+
Events["MouseEnter"] = "mouseenter";
|
|
192
|
+
Events["MouseLeave"] = "mouseleave";
|
|
191
193
|
Events["MouseMove"] = "mousemove";
|
|
192
194
|
Events["MouseOut"] = "mouseout";
|
|
193
195
|
Events["MouseOver"] = "mouseover";
|
|
@@ -1924,6 +1926,293 @@ class DiagramConnectionSet extends DiagramElementSet {
|
|
|
1924
1926
|
}
|
|
1925
1927
|
}
|
|
1926
1928
|
|
|
1929
|
+
/**
|
|
1930
|
+
* Default values of the parameters of a diagram field.
|
|
1931
|
+
* @private
|
|
1932
|
+
* @see DiagramField
|
|
1933
|
+
*/
|
|
1934
|
+
const DIAGRAM_FIELD_DEFAULTS = {
|
|
1935
|
+
editable: true,
|
|
1936
|
+
fontSize: 0,
|
|
1937
|
+
margin: 0,
|
|
1938
|
+
padding: 0,
|
|
1939
|
+
fontFamily: "'Wonder Unit Sans', sans-serif",
|
|
1940
|
+
color: '#000000',
|
|
1941
|
+
selectedColor: '#000000',
|
|
1942
|
+
horizontalAlign: HorizontalAlign.Center,
|
|
1943
|
+
verticalAlign: VerticalAlign.Center,
|
|
1944
|
+
fit: false
|
|
1945
|
+
};
|
|
1946
|
+
/**
|
|
1947
|
+
* A field which displays text and is part of a diagram element.
|
|
1948
|
+
* @public
|
|
1949
|
+
* @see DiagramNode
|
|
1950
|
+
* @see DiagramPort
|
|
1951
|
+
* @see DiagramSection
|
|
1952
|
+
*/
|
|
1953
|
+
class DiagramField extends DiagramElement {
|
|
1954
|
+
/**
|
|
1955
|
+
* Text contents of this field.
|
|
1956
|
+
* @public
|
|
1957
|
+
*/
|
|
1958
|
+
get text() {
|
|
1959
|
+
return this._text;
|
|
1960
|
+
}
|
|
1961
|
+
set text(value) {
|
|
1962
|
+
var _a;
|
|
1963
|
+
if (value.trim() === '') {
|
|
1964
|
+
value = this.defaultText;
|
|
1965
|
+
}
|
|
1966
|
+
this._text = value;
|
|
1967
|
+
this.updateInView();
|
|
1968
|
+
if (this.fit) {
|
|
1969
|
+
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
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`;
|
|
1974
|
+
if (model.fields.get(id) !== undefined) {
|
|
1975
|
+
throw new Error('DiagramField for rootElement already exists');
|
|
1976
|
+
}
|
|
1977
|
+
super(model, id);
|
|
1978
|
+
/**
|
|
1979
|
+
* Collaborative timestamp for text.
|
|
1980
|
+
* @public
|
|
1981
|
+
*/
|
|
1982
|
+
this.textTimestamp = null;
|
|
1983
|
+
this.rootElement = rootElement;
|
|
1984
|
+
this.coords = coords;
|
|
1985
|
+
this.width = width;
|
|
1986
|
+
this.height = height;
|
|
1987
|
+
this.fontSize = fontSize;
|
|
1988
|
+
this.fontFamily = fontFamily;
|
|
1989
|
+
this.color = color;
|
|
1990
|
+
this.selectedColor = selectedColor;
|
|
1991
|
+
this.horizontalAlign = horizontalAlign;
|
|
1992
|
+
this.verticalAlign = verticalAlign;
|
|
1993
|
+
this.defaultText = text;
|
|
1994
|
+
this._text = text;
|
|
1995
|
+
this.editable = editable;
|
|
1996
|
+
this.fit = fit;
|
|
1997
|
+
}
|
|
1998
|
+
select() {
|
|
1999
|
+
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}`);
|
|
2001
|
+
}
|
|
2002
|
+
get removed() {
|
|
2003
|
+
return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
|
|
2004
|
+
}
|
|
2005
|
+
updateInView() {
|
|
2006
|
+
var _a;
|
|
2007
|
+
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updateFieldsInView(this.id);
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Change the coordinates of this field to the given coordinates.
|
|
2011
|
+
* @public
|
|
2012
|
+
* @param coords A point in the diagram.
|
|
2013
|
+
*/
|
|
2014
|
+
move(coords) {
|
|
2015
|
+
this.coords = coords;
|
|
2016
|
+
this.updateInView();
|
|
2017
|
+
}
|
|
2018
|
+
getPriority() {
|
|
2019
|
+
var _a;
|
|
2020
|
+
return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
class DiagramFieldSet extends DiagramElementSet {
|
|
2024
|
+
/**
|
|
2025
|
+
* Instance a set of fields for the given model. This method is used internally.
|
|
2026
|
+
* @private
|
|
2027
|
+
*/
|
|
2028
|
+
constructor(model) {
|
|
2029
|
+
super();
|
|
2030
|
+
this.model = model;
|
|
2031
|
+
}
|
|
2032
|
+
/**
|
|
2033
|
+
* 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.
|
|
2034
|
+
* @private
|
|
2035
|
+
*/
|
|
2036
|
+
new(rootElement, coords, fontSize, fontFamily, color, selectedColor, width, height, horizontalAlign, verticalAlign, text, editable, fit) {
|
|
2037
|
+
const field = new DiagramField(this.model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit);
|
|
2038
|
+
super.add(field);
|
|
2039
|
+
field.updateInView();
|
|
2040
|
+
// add this field to its root element
|
|
2041
|
+
if (rootElement !== undefined) {
|
|
2042
|
+
rootElement.label = field;
|
|
2043
|
+
}
|
|
2044
|
+
return field;
|
|
2045
|
+
}
|
|
2046
|
+
remove(id) {
|
|
2047
|
+
var _a;
|
|
2048
|
+
const field = this.get(id, true);
|
|
2049
|
+
if (field) {
|
|
2050
|
+
// remove from root element
|
|
2051
|
+
if (((_a = field.rootElement) === null || _a === void 0 ? void 0 : _a.label) !== undefined) {
|
|
2052
|
+
if (field.rootElement.label === field) {
|
|
2053
|
+
field.rootElement.label = undefined;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
// remove from set of fields
|
|
2057
|
+
super.remove(id);
|
|
2058
|
+
// remove from canvas
|
|
2059
|
+
field.updateInView();
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
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) {
|
|
2065
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2066
|
+
} else if (typeof config.margin === 'number') {
|
|
2067
|
+
return config.margin;
|
|
2068
|
+
} else {
|
|
2069
|
+
if (config.margin.length === 0) {
|
|
2070
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2071
|
+
} else if (config.margin.length === 1) {
|
|
2072
|
+
return config.margin[0];
|
|
2073
|
+
} else if (config.margin.length === 2) {
|
|
2074
|
+
return config.margin[0];
|
|
2075
|
+
} else if (config.margin.length === 3) {
|
|
2076
|
+
return config.margin[2];
|
|
2077
|
+
} else {
|
|
2078
|
+
return config.margin[2];
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
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) {
|
|
2084
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2085
|
+
} else if (typeof config.margin === 'number') {
|
|
2086
|
+
return config.margin;
|
|
2087
|
+
} else {
|
|
2088
|
+
if (config.margin.length === 0) {
|
|
2089
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2090
|
+
} else if (config.margin.length === 1) {
|
|
2091
|
+
return config.margin[0];
|
|
2092
|
+
} else if (config.margin.length === 2) {
|
|
2093
|
+
return config.margin[1];
|
|
2094
|
+
} else if (config.margin.length === 3) {
|
|
2095
|
+
return config.margin[1];
|
|
2096
|
+
} else {
|
|
2097
|
+
return config.margin[3];
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
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) {
|
|
2103
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2104
|
+
} else if (typeof config.margin === 'number') {
|
|
2105
|
+
return config.margin;
|
|
2106
|
+
} else {
|
|
2107
|
+
if (config.margin.length === 0) {
|
|
2108
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2109
|
+
} else if (config.margin.length === 1) {
|
|
2110
|
+
return config.margin[0];
|
|
2111
|
+
} else if (config.margin.length === 2) {
|
|
2112
|
+
return config.margin[1];
|
|
2113
|
+
} else if (config.margin.length === 3) {
|
|
2114
|
+
return config.margin[1];
|
|
2115
|
+
} else {
|
|
2116
|
+
return config.margin[1];
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
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) {
|
|
2122
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2123
|
+
} else if (typeof config.margin === 'number') {
|
|
2124
|
+
return config.margin;
|
|
2125
|
+
} else {
|
|
2126
|
+
if (config.margin.length === 0) {
|
|
2127
|
+
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
2128
|
+
} else if (config.margin.length === 1) {
|
|
2129
|
+
return config.margin[0];
|
|
2130
|
+
} else if (config.margin.length === 2) {
|
|
2131
|
+
return config.margin[0];
|
|
2132
|
+
} else if (config.margin.length === 3) {
|
|
2133
|
+
return config.margin[0];
|
|
2134
|
+
} else {
|
|
2135
|
+
return config.margin[0];
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
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) {
|
|
2141
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2142
|
+
} else if (typeof config.padding === 'number') {
|
|
2143
|
+
return config.padding;
|
|
2144
|
+
} else {
|
|
2145
|
+
if (config.padding.length === 0) {
|
|
2146
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2147
|
+
} else if (config.padding.length === 1) {
|
|
2148
|
+
return config.padding[0];
|
|
2149
|
+
} else if (config.padding.length === 2) {
|
|
2150
|
+
return config.padding[0];
|
|
2151
|
+
} else if (config.padding.length === 3) {
|
|
2152
|
+
return config.padding[2];
|
|
2153
|
+
} else {
|
|
2154
|
+
return config.padding[2];
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
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) {
|
|
2160
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2161
|
+
} else if (typeof config.padding === 'number') {
|
|
2162
|
+
return config.padding;
|
|
2163
|
+
} else {
|
|
2164
|
+
if (config.padding.length === 0) {
|
|
2165
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2166
|
+
} else if (config.padding.length === 1) {
|
|
2167
|
+
return config.padding[0];
|
|
2168
|
+
} else if (config.padding.length === 2) {
|
|
2169
|
+
return config.padding[1];
|
|
2170
|
+
} else if (config.padding.length === 3) {
|
|
2171
|
+
return config.padding[1];
|
|
2172
|
+
} else {
|
|
2173
|
+
return config.padding[3];
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
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) {
|
|
2179
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2180
|
+
} else if (typeof config.padding === 'number') {
|
|
2181
|
+
return config.padding;
|
|
2182
|
+
} else {
|
|
2183
|
+
if (config.padding.length === 0) {
|
|
2184
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2185
|
+
} else if (config.padding.length === 1) {
|
|
2186
|
+
return config.padding[0];
|
|
2187
|
+
} else if (config.padding.length === 2) {
|
|
2188
|
+
return config.padding[1];
|
|
2189
|
+
} else if (config.padding.length === 3) {
|
|
2190
|
+
return config.padding[1];
|
|
2191
|
+
} else {
|
|
2192
|
+
return config.padding[1];
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
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) {
|
|
2198
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2199
|
+
} else if (typeof config.padding === 'number') {
|
|
2200
|
+
return config.padding;
|
|
2201
|
+
} else {
|
|
2202
|
+
if (config.padding.length === 0) {
|
|
2203
|
+
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
2204
|
+
} else if (config.padding.length === 1) {
|
|
2205
|
+
return config.padding[0];
|
|
2206
|
+
} else if (config.padding.length === 2) {
|
|
2207
|
+
return config.padding[0];
|
|
2208
|
+
} else if (config.padding.length === 3) {
|
|
2209
|
+
return config.padding[0];
|
|
2210
|
+
} else {
|
|
2211
|
+
return config.padding[0];
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
|
|
1927
2216
|
/**
|
|
1928
2217
|
* Default values of the look of a diagram section.
|
|
1929
2218
|
* @private
|
|
@@ -2874,220 +3163,77 @@ class DiagramPort extends DiagramElement {
|
|
|
2874
3163
|
* Connections that end at this port.
|
|
2875
3164
|
* @public
|
|
2876
3165
|
*/
|
|
2877
|
-
this.incomingConnections = [];
|
|
2878
|
-
this.rootElement = rootElement;
|
|
2879
|
-
this.coords = coords;
|
|
2880
|
-
this.direction = direction;
|
|
2881
|
-
}
|
|
2882
|
-
get removed() {
|
|
2883
|
-
return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
|
|
2884
|
-
}
|
|
2885
|
-
updateInView() {
|
|
2886
|
-
var _a;
|
|
2887
|
-
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
|
|
2888
|
-
}
|
|
2889
|
-
/**
|
|
2890
|
-
* Add a connection to this port's list of outgoing connections.
|
|
2891
|
-
* @public
|
|
2892
|
-
* @param connection A connection.
|
|
2893
|
-
*/
|
|
2894
|
-
startConnection(connection) {
|
|
2895
|
-
this.outgoingConnections.push(connection);
|
|
2896
|
-
}
|
|
2897
|
-
/**
|
|
2898
|
-
* Add a connection to this port's list of incoming connections.
|
|
2899
|
-
* @public
|
|
2900
|
-
* @param connection A connection.
|
|
2901
|
-
*/
|
|
2902
|
-
finishConnection(connection) {
|
|
2903
|
-
this.incomingConnections.push(connection);
|
|
2904
|
-
}
|
|
2905
|
-
/**
|
|
2906
|
-
* 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.
|
|
2907
|
-
* @public
|
|
2908
|
-
* @returns A node if it could be found, `undefined` otherwise.
|
|
2909
|
-
*/
|
|
2910
|
-
getNode() {
|
|
2911
|
-
if (this.rootElement instanceof DiagramNode) {
|
|
2912
|
-
return this.rootElement;
|
|
2913
|
-
} else if (this.rootElement instanceof DiagramSection) {
|
|
2914
|
-
return this.rootElement.node;
|
|
2915
|
-
}
|
|
2916
|
-
return undefined;
|
|
2917
|
-
}
|
|
2918
|
-
getPriority() {
|
|
2919
|
-
var _a;
|
|
2920
|
-
return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
|
|
2921
|
-
}
|
|
2922
|
-
/**
|
|
2923
|
-
* Change the coordinates of this port to the given coordinates and move its labels correspondingly.
|
|
2924
|
-
* @public
|
|
2925
|
-
* @param coords A point in the diagram.
|
|
2926
|
-
*/
|
|
2927
|
-
move(coords) {
|
|
2928
|
-
const coordDifferences = [coords[0] - this.coords[0], coords[1] - this.coords[1]];
|
|
2929
|
-
this.coords = coords;
|
|
2930
|
-
for (const connection of this.outgoingConnections) {
|
|
2931
|
-
connection.setStart(this);
|
|
2932
|
-
}
|
|
2933
|
-
for (const connection of this.incomingConnections) {
|
|
2934
|
-
connection.setEnd(this);
|
|
2935
|
-
}
|
|
2936
|
-
if (this.label) {
|
|
2937
|
-
this.label.move([this.label.coords[0] + coordDifferences[0], this.label.coords[1] + coordDifferences[1]]);
|
|
2938
|
-
}
|
|
2939
|
-
this.updateInView();
|
|
2940
|
-
}
|
|
2941
|
-
distanceTo(coords) {
|
|
2942
|
-
return distanceBetweenPoints(this.coords, coords);
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
class DiagramPortSet extends DiagramElementSet {
|
|
2946
|
-
/**
|
|
2947
|
-
* Instance a set of ports for the given model. This method is used internally.
|
|
2948
|
-
* @private
|
|
2949
|
-
*/
|
|
2950
|
-
constructor(model) {
|
|
2951
|
-
super();
|
|
2952
|
-
this.model = model;
|
|
2953
|
-
}
|
|
2954
|
-
/**
|
|
2955
|
-
* 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.
|
|
2956
|
-
* @private
|
|
2957
|
-
*/
|
|
2958
|
-
new(rootElement, coords, direction, id) {
|
|
2959
|
-
const port = new DiagramPort(this.model, rootElement, coords, direction, id);
|
|
2960
|
-
super.add(port);
|
|
2961
|
-
port.updateInView();
|
|
2962
|
-
// add this port to its root element
|
|
2963
|
-
if (rootElement !== undefined) {
|
|
2964
|
-
rootElement.ports.push(port);
|
|
2965
|
-
}
|
|
2966
|
-
return port;
|
|
2967
|
-
}
|
|
2968
|
-
remove(id) {
|
|
2969
|
-
const port = this.get(id, true);
|
|
2970
|
-
if (port) {
|
|
2971
|
-
// remove all connections
|
|
2972
|
-
while (port.outgoingConnections.length > 0) {
|
|
2973
|
-
this.model.connections.remove(port.outgoingConnections[0].id);
|
|
2974
|
-
}
|
|
2975
|
-
while (port.incomingConnections.length > 0) {
|
|
2976
|
-
this.model.connections.remove(port.incomingConnections[0].id);
|
|
2977
|
-
}
|
|
2978
|
-
// remove label
|
|
2979
|
-
if (port.label) {
|
|
2980
|
-
this.model.fields.remove(port.label.id);
|
|
2981
|
-
}
|
|
2982
|
-
// remove from root element
|
|
2983
|
-
if (port.rootElement instanceof DiagramNode || port.rootElement instanceof DiagramSection) {
|
|
2984
|
-
removeIfExists(port.rootElement.ports, port);
|
|
2985
|
-
}
|
|
2986
|
-
// remove from set of ports
|
|
2987
|
-
super.remove(id);
|
|
2988
|
-
// remove from canvas
|
|
2989
|
-
port.updateInView();
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
/**
|
|
2995
|
-
* Default values of the parameters of a diagram field.
|
|
2996
|
-
* @private
|
|
2997
|
-
* @see DiagramField
|
|
2998
|
-
*/
|
|
2999
|
-
const DIAGRAM_FIELD_DEFAULTS = {
|
|
3000
|
-
editable: true,
|
|
3001
|
-
fontSize: 0,
|
|
3002
|
-
margin: 0,
|
|
3003
|
-
padding: 0,
|
|
3004
|
-
fontFamily: "'Wonder Unit Sans', sans-serif",
|
|
3005
|
-
color: '#000000',
|
|
3006
|
-
selectedColor: '#000000',
|
|
3007
|
-
horizontalAlign: HorizontalAlign.Center,
|
|
3008
|
-
verticalAlign: VerticalAlign.Center,
|
|
3009
|
-
fit: false
|
|
3010
|
-
};
|
|
3011
|
-
/**
|
|
3012
|
-
* A field which displays text and is part of a diagram element.
|
|
3013
|
-
* @public
|
|
3014
|
-
* @see DiagramNode
|
|
3015
|
-
* @see DiagramPort
|
|
3016
|
-
* @see DiagramSection
|
|
3017
|
-
*/
|
|
3018
|
-
class DiagramField extends DiagramElement {
|
|
3019
|
-
/**
|
|
3020
|
-
* Text contents of this field.
|
|
3021
|
-
* @public
|
|
3022
|
-
*/
|
|
3023
|
-
get text() {
|
|
3024
|
-
return this._text;
|
|
3025
|
-
}
|
|
3026
|
-
set text(value) {
|
|
3027
|
-
var _a;
|
|
3028
|
-
if (value.trim() === '') {
|
|
3029
|
-
value = this.defaultText;
|
|
3030
|
-
}
|
|
3031
|
-
this._text = value;
|
|
3032
|
-
this.updateInView();
|
|
3033
|
-
if (this.fit) {
|
|
3034
|
-
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.fitFieldRootInView(this.id);
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
constructor(model, rootElement, coords, width, height, fontSize, fontFamily, color, selectedColor, horizontalAlign, verticalAlign, text, editable, fit) {
|
|
3038
|
-
const id = `${rootElement === null || rootElement === void 0 ? void 0 : rootElement.id}_field`;
|
|
3039
|
-
if (model.fields.get(id) !== undefined) {
|
|
3040
|
-
throw new Error('DiagramField for rootElement already exists');
|
|
3041
|
-
}
|
|
3042
|
-
super(model, id);
|
|
3043
|
-
/**
|
|
3044
|
-
* Collaborative timestamp for text.
|
|
3045
|
-
* @public
|
|
3046
|
-
*/
|
|
3047
|
-
this.textTimestamp = null;
|
|
3048
|
-
this.rootElement = rootElement;
|
|
3049
|
-
this.coords = coords;
|
|
3050
|
-
this.width = width;
|
|
3051
|
-
this.height = height;
|
|
3052
|
-
this.fontSize = fontSize;
|
|
3053
|
-
this.fontFamily = fontFamily;
|
|
3054
|
-
this.color = color;
|
|
3055
|
-
this.selectedColor = selectedColor;
|
|
3056
|
-
this.horizontalAlign = horizontalAlign;
|
|
3057
|
-
this.verticalAlign = verticalAlign;
|
|
3058
|
-
this.defaultText = text;
|
|
3059
|
-
this._text = text;
|
|
3060
|
-
this.editable = editable;
|
|
3061
|
-
this.fit = fit;
|
|
3062
|
-
}
|
|
3063
|
-
select() {
|
|
3064
|
-
var _a, _b;
|
|
3065
|
-
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}`);
|
|
3166
|
+
this.incomingConnections = [];
|
|
3167
|
+
this.rootElement = rootElement;
|
|
3168
|
+
this.coords = coords;
|
|
3169
|
+
this.direction = direction;
|
|
3066
3170
|
}
|
|
3067
3171
|
get removed() {
|
|
3068
3172
|
return this.selfRemoved || this.rootElement !== undefined && this.rootElement.removed;
|
|
3069
3173
|
}
|
|
3070
3174
|
updateInView() {
|
|
3071
3175
|
var _a;
|
|
3072
|
-
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.
|
|
3176
|
+
(_a = this.model.canvas) === null || _a === void 0 ? void 0 : _a.updatePortsInView(this.id);
|
|
3073
3177
|
}
|
|
3074
3178
|
/**
|
|
3075
|
-
*
|
|
3179
|
+
* Add a connection to this port's list of outgoing connections.
|
|
3180
|
+
* @public
|
|
3181
|
+
* @param connection A connection.
|
|
3182
|
+
*/
|
|
3183
|
+
startConnection(connection) {
|
|
3184
|
+
this.outgoingConnections.push(connection);
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
* Add a connection to this port's list of incoming connections.
|
|
3188
|
+
* @public
|
|
3189
|
+
* @param connection A connection.
|
|
3190
|
+
*/
|
|
3191
|
+
finishConnection(connection) {
|
|
3192
|
+
this.incomingConnections.push(connection);
|
|
3193
|
+
}
|
|
3194
|
+
/**
|
|
3195
|
+
* 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.
|
|
3196
|
+
* @public
|
|
3197
|
+
* @returns A node if it could be found, `undefined` otherwise.
|
|
3198
|
+
*/
|
|
3199
|
+
getNode() {
|
|
3200
|
+
if (this.rootElement instanceof DiagramNode) {
|
|
3201
|
+
return this.rootElement;
|
|
3202
|
+
} else if (this.rootElement instanceof DiagramSection) {
|
|
3203
|
+
return this.rootElement.node;
|
|
3204
|
+
}
|
|
3205
|
+
return undefined;
|
|
3206
|
+
}
|
|
3207
|
+
getPriority() {
|
|
3208
|
+
var _a;
|
|
3209
|
+
return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
|
|
3210
|
+
}
|
|
3211
|
+
/**
|
|
3212
|
+
* Change the coordinates of this port to the given coordinates and move its labels correspondingly.
|
|
3076
3213
|
* @public
|
|
3077
3214
|
* @param coords A point in the diagram.
|
|
3078
3215
|
*/
|
|
3079
3216
|
move(coords) {
|
|
3217
|
+
const coordDifferences = [coords[0] - this.coords[0], coords[1] - this.coords[1]];
|
|
3080
3218
|
this.coords = coords;
|
|
3219
|
+
for (const connection of this.outgoingConnections) {
|
|
3220
|
+
connection.setStart(this);
|
|
3221
|
+
}
|
|
3222
|
+
for (const connection of this.incomingConnections) {
|
|
3223
|
+
connection.setEnd(this);
|
|
3224
|
+
}
|
|
3225
|
+
if (this.label) {
|
|
3226
|
+
this.label.move([this.label.coords[0] + coordDifferences[0], this.label.coords[1] + coordDifferences[1]]);
|
|
3227
|
+
}
|
|
3081
3228
|
this.updateInView();
|
|
3082
3229
|
}
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
return ((_a = this.rootElement) === null || _a === void 0 ? void 0 : _a.getPriority()) || DEFAULT_PRIORITY;
|
|
3230
|
+
distanceTo(coords) {
|
|
3231
|
+
return distanceBetweenPoints(this.coords, coords);
|
|
3086
3232
|
}
|
|
3087
3233
|
}
|
|
3088
|
-
class
|
|
3234
|
+
class DiagramPortSet extends DiagramElementSet {
|
|
3089
3235
|
/**
|
|
3090
|
-
* Instance a set of
|
|
3236
|
+
* Instance a set of ports for the given model. This method is used internally.
|
|
3091
3237
|
* @private
|
|
3092
3238
|
*/
|
|
3093
3239
|
constructor(model) {
|
|
@@ -3095,187 +3241,44 @@ class DiagramFieldSet extends DiagramElementSet {
|
|
|
3095
3241
|
this.model = model;
|
|
3096
3242
|
}
|
|
3097
3243
|
/**
|
|
3098
|
-
* Instance a new
|
|
3244
|
+
* 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.
|
|
3099
3245
|
* @private
|
|
3100
3246
|
*/
|
|
3101
|
-
new(rootElement, coords,
|
|
3102
|
-
const
|
|
3103
|
-
super.add(
|
|
3104
|
-
|
|
3105
|
-
// add this
|
|
3247
|
+
new(rootElement, coords, direction, id) {
|
|
3248
|
+
const port = new DiagramPort(this.model, rootElement, coords, direction, id);
|
|
3249
|
+
super.add(port);
|
|
3250
|
+
port.updateInView();
|
|
3251
|
+
// add this port to its root element
|
|
3106
3252
|
if (rootElement !== undefined) {
|
|
3107
|
-
rootElement.
|
|
3253
|
+
rootElement.ports.push(port);
|
|
3108
3254
|
}
|
|
3109
|
-
return
|
|
3255
|
+
return port;
|
|
3110
3256
|
}
|
|
3111
3257
|
remove(id) {
|
|
3112
|
-
const
|
|
3113
|
-
if (
|
|
3258
|
+
const port = this.get(id, true);
|
|
3259
|
+
if (port) {
|
|
3260
|
+
// remove all connections
|
|
3261
|
+
while (port.outgoingConnections.length > 0) {
|
|
3262
|
+
this.model.connections.remove(port.outgoingConnections[0].id);
|
|
3263
|
+
}
|
|
3264
|
+
while (port.incomingConnections.length > 0) {
|
|
3265
|
+
this.model.connections.remove(port.incomingConnections[0].id);
|
|
3266
|
+
}
|
|
3267
|
+
// remove label
|
|
3268
|
+
if (port.label) {
|
|
3269
|
+
this.model.fields.remove(port.label.id);
|
|
3270
|
+
}
|
|
3114
3271
|
// remove from root element
|
|
3115
|
-
if (
|
|
3116
|
-
|
|
3117
|
-
field.rootElement.label = undefined;
|
|
3118
|
-
}
|
|
3272
|
+
if (port.rootElement instanceof DiagramNode || port.rootElement instanceof DiagramSection) {
|
|
3273
|
+
removeIfExists(port.rootElement.ports, port);
|
|
3119
3274
|
}
|
|
3120
|
-
// remove from set of
|
|
3275
|
+
// remove from set of ports
|
|
3121
3276
|
super.remove(id);
|
|
3122
3277
|
// remove from canvas
|
|
3123
|
-
|
|
3278
|
+
port.updateInView();
|
|
3124
3279
|
}
|
|
3125
3280
|
}
|
|
3126
3281
|
}
|
|
3127
|
-
const getBottomMargin = config => {
|
|
3128
|
-
if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
|
|
3129
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3130
|
-
} else if (typeof config.margin === 'number') {
|
|
3131
|
-
return config.margin;
|
|
3132
|
-
} else {
|
|
3133
|
-
if (config.margin.length === 0) {
|
|
3134
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3135
|
-
} else if (config.margin.length === 1) {
|
|
3136
|
-
return config.margin[0];
|
|
3137
|
-
} else if (config.margin.length === 2) {
|
|
3138
|
-
return config.margin[0];
|
|
3139
|
-
} else if (config.margin.length === 3) {
|
|
3140
|
-
return config.margin[2];
|
|
3141
|
-
} else {
|
|
3142
|
-
return config.margin[2];
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
};
|
|
3146
|
-
const getLeftMargin = config => {
|
|
3147
|
-
if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
|
|
3148
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3149
|
-
} else if (typeof config.margin === 'number') {
|
|
3150
|
-
return config.margin;
|
|
3151
|
-
} else {
|
|
3152
|
-
if (config.margin.length === 0) {
|
|
3153
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3154
|
-
} else if (config.margin.length === 1) {
|
|
3155
|
-
return config.margin[0];
|
|
3156
|
-
} else if (config.margin.length === 2) {
|
|
3157
|
-
return config.margin[1];
|
|
3158
|
-
} else if (config.margin.length === 3) {
|
|
3159
|
-
return config.margin[1];
|
|
3160
|
-
} else {
|
|
3161
|
-
return config.margin[3];
|
|
3162
|
-
}
|
|
3163
|
-
}
|
|
3164
|
-
};
|
|
3165
|
-
const getRightMargin = config => {
|
|
3166
|
-
if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
|
|
3167
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3168
|
-
} else if (typeof config.margin === 'number') {
|
|
3169
|
-
return config.margin;
|
|
3170
|
-
} else {
|
|
3171
|
-
if (config.margin.length === 0) {
|
|
3172
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3173
|
-
} else if (config.margin.length === 1) {
|
|
3174
|
-
return config.margin[0];
|
|
3175
|
-
} else if (config.margin.length === 2) {
|
|
3176
|
-
return config.margin[1];
|
|
3177
|
-
} else if (config.margin.length === 3) {
|
|
3178
|
-
return config.margin[1];
|
|
3179
|
-
} else {
|
|
3180
|
-
return config.margin[1];
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
};
|
|
3184
|
-
const getTopMargin = config => {
|
|
3185
|
-
if ((config === null || config === void 0 ? void 0 : config.margin) === null || (config === null || config === void 0 ? void 0 : config.margin) === undefined) {
|
|
3186
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3187
|
-
} else if (typeof config.margin === 'number') {
|
|
3188
|
-
return config.margin;
|
|
3189
|
-
} else {
|
|
3190
|
-
if (config.margin.length === 0) {
|
|
3191
|
-
return DIAGRAM_FIELD_DEFAULTS.margin;
|
|
3192
|
-
} else if (config.margin.length === 1) {
|
|
3193
|
-
return config.margin[0];
|
|
3194
|
-
} else if (config.margin.length === 2) {
|
|
3195
|
-
return config.margin[0];
|
|
3196
|
-
} else if (config.margin.length === 3) {
|
|
3197
|
-
return config.margin[0];
|
|
3198
|
-
} else {
|
|
3199
|
-
return config.margin[0];
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
};
|
|
3203
|
-
const getBottomPadding = config => {
|
|
3204
|
-
if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
|
|
3205
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3206
|
-
} else if (typeof config.padding === 'number') {
|
|
3207
|
-
return config.padding;
|
|
3208
|
-
} else {
|
|
3209
|
-
if (config.padding.length === 0) {
|
|
3210
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3211
|
-
} else if (config.padding.length === 1) {
|
|
3212
|
-
return config.padding[0];
|
|
3213
|
-
} else if (config.padding.length === 2) {
|
|
3214
|
-
return config.padding[0];
|
|
3215
|
-
} else if (config.padding.length === 3) {
|
|
3216
|
-
return config.padding[2];
|
|
3217
|
-
} else {
|
|
3218
|
-
return config.padding[2];
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
};
|
|
3222
|
-
const getLeftPadding = config => {
|
|
3223
|
-
if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
|
|
3224
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3225
|
-
} else if (typeof config.padding === 'number') {
|
|
3226
|
-
return config.padding;
|
|
3227
|
-
} else {
|
|
3228
|
-
if (config.padding.length === 0) {
|
|
3229
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3230
|
-
} else if (config.padding.length === 1) {
|
|
3231
|
-
return config.padding[0];
|
|
3232
|
-
} else if (config.padding.length === 2) {
|
|
3233
|
-
return config.padding[1];
|
|
3234
|
-
} else if (config.padding.length === 3) {
|
|
3235
|
-
return config.padding[1];
|
|
3236
|
-
} else {
|
|
3237
|
-
return config.padding[3];
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
};
|
|
3241
|
-
const getRightPadding = config => {
|
|
3242
|
-
if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
|
|
3243
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3244
|
-
} else if (typeof config.padding === 'number') {
|
|
3245
|
-
return config.padding;
|
|
3246
|
-
} else {
|
|
3247
|
-
if (config.padding.length === 0) {
|
|
3248
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3249
|
-
} else if (config.padding.length === 1) {
|
|
3250
|
-
return config.padding[0];
|
|
3251
|
-
} else if (config.padding.length === 2) {
|
|
3252
|
-
return config.padding[1];
|
|
3253
|
-
} else if (config.padding.length === 3) {
|
|
3254
|
-
return config.padding[1];
|
|
3255
|
-
} else {
|
|
3256
|
-
return config.padding[1];
|
|
3257
|
-
}
|
|
3258
|
-
}
|
|
3259
|
-
};
|
|
3260
|
-
const getTopPadding = config => {
|
|
3261
|
-
if ((config === null || config === void 0 ? void 0 : config.padding) === null || (config === null || config === void 0 ? void 0 : config.padding) === undefined) {
|
|
3262
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3263
|
-
} else if (typeof config.padding === 'number') {
|
|
3264
|
-
return config.padding;
|
|
3265
|
-
} else {
|
|
3266
|
-
if (config.padding.length === 0) {
|
|
3267
|
-
return DIAGRAM_FIELD_DEFAULTS.padding;
|
|
3268
|
-
} else if (config.padding.length === 1) {
|
|
3269
|
-
return config.padding[0];
|
|
3270
|
-
} else if (config.padding.length === 2) {
|
|
3271
|
-
return config.padding[0];
|
|
3272
|
-
} else if (config.padding.length === 3) {
|
|
3273
|
-
return config.padding[0];
|
|
3274
|
-
} else {
|
|
3275
|
-
return config.padding[0];
|
|
3276
|
-
}
|
|
3277
|
-
}
|
|
3278
|
-
};
|
|
3279
3282
|
|
|
3280
3283
|
/**
|
|
3281
3284
|
* Importer which imports a diagram from its daga model representation.
|
|
@@ -5280,6 +5283,15 @@ const ACTION_STACK_SIZE = 25;
|
|
|
5280
5283
|
const UNFINISHED_CONNECTION_ID = 'diagram-connection-unfinished';
|
|
5281
5284
|
const MAX_DISTANCE_TO_PORT = 100;
|
|
5282
5285
|
class DiagramCanvas {
|
|
5286
|
+
get connectionType() {
|
|
5287
|
+
return this._connectionType;
|
|
5288
|
+
}
|
|
5289
|
+
set connectionType(value) {
|
|
5290
|
+
var _a, _b;
|
|
5291
|
+
this._connectionType = value;
|
|
5292
|
+
// 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();
|
|
5294
|
+
}
|
|
5283
5295
|
/**
|
|
5284
5296
|
* Constructs a canvas object.
|
|
5285
5297
|
* @public
|
|
@@ -5336,7 +5348,7 @@ class DiagramCanvas {
|
|
|
5336
5348
|
const connectionType = new DiagramConnectionType(Object.assign(Object.assign({}, config.connectionTypeDefaults), connectionTypeConfig));
|
|
5337
5349
|
this.model.connections.types.add(connectionType);
|
|
5338
5350
|
}
|
|
5339
|
-
this.
|
|
5351
|
+
this._connectionType = config.defaultConnection !== undefined ? this.model.connections.types.get(config.defaultConnection) : undefined;
|
|
5340
5352
|
}
|
|
5341
5353
|
}
|
|
5342
5354
|
addValidator(validator) {
|
|
@@ -6369,6 +6381,8 @@ class DiagramCanvas {
|
|
|
6369
6381
|
const userHighlight = this.userHighlight.getFocus();
|
|
6370
6382
|
if (userHighlight instanceof DiagramPort) {
|
|
6371
6383
|
this.finishConnection(userHighlight);
|
|
6384
|
+
} else if (userHighlight instanceof DiagramField && userHighlight.rootElement instanceof DiagramPort) {
|
|
6385
|
+
this.finishConnection(userHighlight.rootElement);
|
|
6372
6386
|
} else if (userHighlight instanceof DiagramNode || userHighlight instanceof DiagramSection || userHighlight instanceof DiagramField) {
|
|
6373
6387
|
let targetRootElement;
|
|
6374
6388
|
if (userHighlight instanceof DiagramNode || userHighlight instanceof DiagramSection) {
|
|
@@ -7113,7 +7127,7 @@ const getRelatedNodeOrItself = element => {
|
|
|
7113
7127
|
if (element instanceof DiagramSection) {
|
|
7114
7128
|
return element.node || element;
|
|
7115
7129
|
}
|
|
7116
|
-
return element.rootElement
|
|
7130
|
+
return element.rootElement instanceof DiagramNode || element.rootElement instanceof DiagramSection || element.rootElement instanceof DiagramPort ? getRelatedNodeOrItself(element.rootElement) : element;
|
|
7117
7131
|
};
|
|
7118
7132
|
|
|
7119
7133
|
const VERSION = '0.0.1';
|