orcasvn-react-diagrams 0.2.5 → 0.2.6
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 +23 -0
- package/README.md +15 -34
- package/ai/api-contract.json +38 -1
- package/ai/manifest.json +1 -1
- package/dist/cjs/examples.js +1252 -113
- package/dist/cjs/index.js +876 -81
- package/dist/cjs/types/api/createDiagramEditor.d.ts +2 -1
- package/dist/cjs/types/api/types.d.ts +26 -1
- package/dist/cjs/types/displaybox/demos/OffsetAnchorAvoidanceDemoTab.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/ZoomToFitElementsDemoTab.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/offsetAnchorAvoidanceDemo.d.ts +4 -0
- package/dist/cjs/types/displaybox/demos/textDemo.d.ts +3 -0
- package/dist/cjs/types/displaybox/demos/zoomToFitElementsDemo.d.ts +4 -0
- package/dist/cjs/types/engine/AutoLayoutService.d.ts +44 -1
- package/dist/cjs/types/engine/DiagramEngine.d.ts +12 -0
- package/dist/cjs/types/engine/LinkRoutingService.d.ts +1 -0
- package/dist/cjs/types/models/TextModel.d.ts +1 -0
- package/dist/cjs/types/renderer/konva/KonvaInteraction.d.ts +2 -0
- package/dist/esm/examples.js +1252 -113
- package/dist/esm/examples.js.map +1 -1
- package/dist/esm/index.js +876 -81
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api/createDiagramEditor.d.ts +2 -1
- package/dist/esm/types/api/types.d.ts +26 -1
- package/dist/esm/types/displaybox/demos/OffsetAnchorAvoidanceDemoTab.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/ZoomToFitElementsDemoTab.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/offsetAnchorAvoidanceDemo.d.ts +4 -0
- package/dist/esm/types/displaybox/demos/textDemo.d.ts +3 -0
- package/dist/esm/types/displaybox/demos/zoomToFitElementsDemo.d.ts +4 -0
- package/dist/esm/types/engine/AutoLayoutService.d.ts +44 -1
- package/dist/esm/types/engine/DiagramEngine.d.ts +12 -0
- package/dist/esm/types/engine/LinkRoutingService.d.ts +1 -0
- package/dist/esm/types/models/TextModel.d.ts +1 -0
- package/dist/esm/types/renderer/konva/KonvaInteraction.d.ts +2 -0
- package/dist/examples.d.ts +27 -1
- package/dist/index.d.ts +29 -2
- package/docs/API_CONTRACT.md +38 -3
- package/docs/CAPABILITIES.md +3 -0
- package/docs/COMMANDS_EVENTS.md +8 -0
- package/docs/DOCUMENTATION_WORKFLOW.md +2 -1
- package/docs/INTEGRATION_PLAYBOOK.md +3 -0
- package/docs/STATE_INVARIANTS.md +4 -0
- package/package.json +1 -1
- package/src/displaybox/demos/AutoLayoutDemoTab.tsx +337 -316
- package/src/displaybox/demos/EngineEventsDemoTab.tsx +12 -11
- package/src/displaybox/demos/OffsetAnchorAvoidanceDemoTab.tsx +30 -0
- package/src/displaybox/demos/TextLayoutDemoTab.tsx +18 -1
- package/src/displaybox/demos/ZoomToFitElementsDemoTab.tsx +29 -0
- package/src/displaybox/demos/autoLayoutDemo.ts +74 -73
- package/src/displaybox/demos/index.tsx +80 -64
- package/src/displaybox/demos/offsetAnchorAvoidanceDemo.ts +211 -0
- package/src/displaybox/demos/textDemo.ts +6 -2
- package/src/displaybox/demos/zoomToFitElementsDemo.ts +83 -0
package/dist/esm/index.js
CHANGED
|
@@ -268,6 +268,7 @@ var TextModel = /** @class */ (function () {
|
|
|
268
268
|
this.size = data.size ? __assign({}, data.size) : undefined;
|
|
269
269
|
this.style = data.style;
|
|
270
270
|
this.ownerId = (_a = data.ownerId) !== null && _a !== void 0 ? _a : null;
|
|
271
|
+
this.interaction = data.interaction ? __assign({}, data.interaction) : undefined;
|
|
271
272
|
this.layout = data.layout ? __assign({}, data.layout) : undefined;
|
|
272
273
|
this.displayContent = (_b = data.displayContent) !== null && _b !== void 0 ? _b : data.content;
|
|
273
274
|
this.displayOffset = data.displayOffset ? __assign({}, data.displayOffset) : undefined;
|
|
@@ -304,6 +305,7 @@ var TextModel = /** @class */ (function () {
|
|
|
304
305
|
size: this.size ? __assign({}, this.size) : undefined,
|
|
305
306
|
style: this.style,
|
|
306
307
|
ownerId: this.ownerId,
|
|
308
|
+
interaction: this.interaction ? __assign({}, this.interaction) : undefined,
|
|
307
309
|
layout: this.layout ? __assign({}, this.layout) : undefined,
|
|
308
310
|
displayContent: (_a = this.displayContent) !== null && _a !== void 0 ? _a : this.content,
|
|
309
311
|
displayOffset: this.displayOffset ? __assign({}, this.displayOffset) : undefined,
|
|
@@ -318,7 +320,7 @@ var distance = function (a, b) {
|
|
|
318
320
|
var dy = a.y - b.y;
|
|
319
321
|
return Math.sqrt(dx * dx + dy * dy);
|
|
320
322
|
};
|
|
321
|
-
var clamp$
|
|
323
|
+
var clamp$2 = function (value, min, max) {
|
|
322
324
|
if (value < min)
|
|
323
325
|
return min;
|
|
324
326
|
if (value > max)
|
|
@@ -1165,7 +1167,7 @@ var pathLength = function (points) {
|
|
|
1165
1167
|
}
|
|
1166
1168
|
return total;
|
|
1167
1169
|
};
|
|
1168
|
-
var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
1170
|
+
var clamp$1 = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
1169
1171
|
var ObstacleRouter = /** @class */ (function () {
|
|
1170
1172
|
function ObstacleRouter(options) {
|
|
1171
1173
|
var _a, _b, _c;
|
|
@@ -1445,7 +1447,7 @@ var ObstacleRouter = /** @class */ (function () {
|
|
|
1445
1447
|
return null;
|
|
1446
1448
|
if (corridor.axis === 'horizontal') {
|
|
1447
1449
|
var direction_1 = source.x <= target.x ? 1 : -1;
|
|
1448
|
-
var corridorY = clamp((source.y + target.y) / 2, corridor.bounds.y + this.padding, corridor.bounds.y + corridor.bounds.height - this.padding);
|
|
1450
|
+
var corridorY = clamp$1((source.y + target.y) / 2, corridor.bounds.y + this.padding, corridor.bounds.y + corridor.bounds.height - this.padding);
|
|
1449
1451
|
var sourceExitX = direction_1 > 0
|
|
1450
1452
|
? corridor.sourceBranchRect.x + corridor.sourceBranchRect.width + this.padding
|
|
1451
1453
|
: corridor.sourceBranchRect.x - this.padding;
|
|
@@ -1462,7 +1464,7 @@ var ObstacleRouter = /** @class */ (function () {
|
|
|
1462
1464
|
]);
|
|
1463
1465
|
}
|
|
1464
1466
|
var direction = source.y <= target.y ? 1 : -1;
|
|
1465
|
-
var corridorX = clamp((source.x + target.x) / 2, corridor.bounds.x + this.padding, corridor.bounds.x + corridor.bounds.width - this.padding);
|
|
1467
|
+
var corridorX = clamp$1((source.x + target.x) / 2, corridor.bounds.x + this.padding, corridor.bounds.x + corridor.bounds.width - this.padding);
|
|
1466
1468
|
var sourceExitY = direction > 0
|
|
1467
1469
|
? corridor.sourceBranchRect.y + corridor.sourceBranchRect.height + this.padding
|
|
1468
1470
|
: corridor.sourceBranchRect.y - this.padding;
|
|
@@ -2014,6 +2016,7 @@ var TextLayoutService = /** @class */ (function () {
|
|
|
2014
2016
|
return TextLayoutService;
|
|
2015
2017
|
}());
|
|
2016
2018
|
|
|
2019
|
+
var GRID_ROW_UNITS = 12;
|
|
2017
2020
|
var AutoLayoutService = /** @class */ (function () {
|
|
2018
2021
|
function AutoLayoutService(config) {
|
|
2019
2022
|
this.model = config.model;
|
|
@@ -2028,11 +2031,24 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2028
2031
|
if (!layout || layout.mode === 'manual')
|
|
2029
2032
|
return { patches: [], movedPortIds: [] };
|
|
2030
2033
|
var preserveParentSize = Boolean(options === null || options === void 0 ? void 0 : options.preserveParentSize);
|
|
2034
|
+
var preserveParentWidth = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentWidth);
|
|
2035
|
+
var preserveParentHeight = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentHeight);
|
|
2031
2036
|
var padding = this.resolveLayoutPadding(layout);
|
|
2032
2037
|
var labelReservedTopLane = this.resolveLabelReservedTopLane(parentId, layout);
|
|
2033
2038
|
var autoResize = this.resolveAutoResizeMode(layout);
|
|
2034
2039
|
var children = this.model.getChildren(parentId);
|
|
2035
2040
|
if (children.length === 0) {
|
|
2041
|
+
if (preserveParentWidth || preserveParentHeight) {
|
|
2042
|
+
var targetWidth_1 = preserveParentWidth ? parent.size.width : Math.max(0, Math.round(padding.x * 2));
|
|
2043
|
+
var targetHeight_1 = preserveParentHeight
|
|
2044
|
+
? parent.size.height
|
|
2045
|
+
: Math.max(0, Math.round(padding.y * 2 + labelReservedTopLane));
|
|
2046
|
+
if (parent.size.width === targetWidth_1 && parent.size.height === targetHeight_1) {
|
|
2047
|
+
return { patches: [], movedPortIds: [] };
|
|
2048
|
+
}
|
|
2049
|
+
var resizePatches_1 = this.commandQueue.run(createResizeElementCommand(parentId, { width: targetWidth_1, height: targetHeight_1 }), this.model);
|
|
2050
|
+
return { patches: resizePatches_1, movedPortIds: __spreadArray([], parent.portIds, true) };
|
|
2051
|
+
}
|
|
2036
2052
|
if (preserveParentSize) {
|
|
2037
2053
|
return { patches: [], movedPortIds: [] };
|
|
2038
2054
|
}
|
|
@@ -2047,9 +2063,17 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2047
2063
|
return { patches: resizePatches, movedPortIds: __spreadArray([], parent.portIds, true) };
|
|
2048
2064
|
}
|
|
2049
2065
|
if (layout.mode === 'grid') {
|
|
2050
|
-
return this.applyGridLayoutForParent(parentId, parent, children,
|
|
2066
|
+
return this.applyGridLayoutForParent(parentId, parent, children, {
|
|
2067
|
+
preserveParentSize: preserveParentSize,
|
|
2068
|
+
preserveParentWidth: preserveParentWidth,
|
|
2069
|
+
preserveParentHeight: preserveParentHeight,
|
|
2070
|
+
});
|
|
2051
2071
|
}
|
|
2052
|
-
return this.applyAxisLayoutForParent(parentId, parent, children, layout.mode,
|
|
2072
|
+
return this.applyAxisLayoutForParent(parentId, parent, children, layout.mode, {
|
|
2073
|
+
preserveParentSize: preserveParentSize,
|
|
2074
|
+
preserveParentWidth: preserveParentWidth,
|
|
2075
|
+
preserveParentHeight: preserveParentHeight,
|
|
2076
|
+
});
|
|
2053
2077
|
};
|
|
2054
2078
|
AutoLayoutService.prototype.applyLayoutCascade = function (startParentId) {
|
|
2055
2079
|
var _a;
|
|
@@ -2092,11 +2116,102 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2092
2116
|
});
|
|
2093
2117
|
return { patches: patches, movedPortIds: Array.from(new Set(movedPortIds)) };
|
|
2094
2118
|
};
|
|
2095
|
-
AutoLayoutService.prototype.
|
|
2119
|
+
AutoLayoutService.prototype.describeGridRows = function (parentId) {
|
|
2120
|
+
var _a;
|
|
2121
|
+
var parent = this.model.getElement(parentId);
|
|
2122
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid')
|
|
2123
|
+
return [];
|
|
2124
|
+
return this.resolveAssignedGridRows(parent).map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); });
|
|
2125
|
+
};
|
|
2126
|
+
AutoLayoutService.prototype.describeGridSlotState = function (parentId) {
|
|
2127
|
+
var _this = this;
|
|
2128
|
+
var _a;
|
|
2129
|
+
var parent = this.model.getElement(parentId);
|
|
2130
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid')
|
|
2131
|
+
return null;
|
|
2132
|
+
var assignedRows = this.resolveAssignedGridRows(parent);
|
|
2133
|
+
return {
|
|
2134
|
+
orderedChildIds: assignedRows.flatMap(function (row) { return row.childIds; }),
|
|
2135
|
+
slotWeights: assignedRows.flatMap(function (row) { return row.weights.slice(0, row.childIds.length).map(function (weight) { return _this.clampGridUnits(weight); }); }),
|
|
2136
|
+
};
|
|
2137
|
+
};
|
|
2138
|
+
AutoLayoutService.prototype.resolveGridReorderedLayout = function (parentId, previousState) {
|
|
2139
|
+
var _this = this;
|
|
2140
|
+
var _a;
|
|
2141
|
+
var parent = this.model.getElement(parentId);
|
|
2142
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid' || !parent.layout)
|
|
2143
|
+
return null;
|
|
2144
|
+
var sortedChildren = this.sortGridChildrenForLayout(this.model.getChildren(parentId));
|
|
2145
|
+
var orderedChildIds = sortedChildren.map(function (child) { return child.id; });
|
|
2146
|
+
if (orderedChildIds.length === previousState.orderedChildIds.length &&
|
|
2147
|
+
orderedChildIds.every(function (childId, index) { return childId === previousState.orderedChildIds[index]; })) {
|
|
2148
|
+
return null;
|
|
2149
|
+
}
|
|
2150
|
+
var weightByChildId = new Map();
|
|
2151
|
+
previousState.orderedChildIds.forEach(function (childId, index) {
|
|
2152
|
+
var _a;
|
|
2153
|
+
weightByChildId.set(childId, _this.clampGridUnits((_a = previousState.slotWeights[index]) !== null && _a !== void 0 ? _a : GRID_ROW_UNITS));
|
|
2154
|
+
});
|
|
2155
|
+
var reorderedTemplate = orderedChildIds.map(function (childId) { var _a; return (_a = weightByChildId.get(childId)) !== null && _a !== void 0 ? _a : GRID_ROW_UNITS; });
|
|
2156
|
+
return __assign(__assign({}, parent.layout), { gridTemplate: reorderedTemplate });
|
|
2157
|
+
};
|
|
2158
|
+
AutoLayoutService.prototype.resolveGridChildResizeTopologyChange = function (parentId, childId, requestedWidth) {
|
|
2159
|
+
var _a;
|
|
2160
|
+
var parent = this.model.getElement(parentId);
|
|
2161
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid' || !parent.layout)
|
|
2162
|
+
return null;
|
|
2163
|
+
var slotState = this.resolveGridChildSlotState(parentId, childId);
|
|
2164
|
+
if (!slotState)
|
|
2165
|
+
return null;
|
|
2166
|
+
var assignedRows = slotState.assignedRows, orderedChildIds = slotState.orderedChildIds, slotWeights = slotState.slotWeights, childFlatIndex = slotState.childFlatIndex, rowIndex = slotState.rowIndex;
|
|
2167
|
+
var currentUnits = slotWeights[childFlatIndex];
|
|
2168
|
+
var requestedUnits = this.resolveRequestedGridUnits(parent, assignedRows[rowIndex], requestedWidth);
|
|
2169
|
+
if (requestedUnits === currentUnits)
|
|
2170
|
+
return null;
|
|
2171
|
+
var nextSlotWeights = __spreadArray([], slotWeights, true);
|
|
2172
|
+
nextSlotWeights[childFlatIndex] = requestedUnits;
|
|
2173
|
+
var nextRows = this.packGridRowsFromSlots(orderedChildIds, nextSlotWeights);
|
|
2174
|
+
var beforeRows = assignedRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); });
|
|
2175
|
+
var afterRows = nextRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); });
|
|
2176
|
+
var rowsChanged = !this.gridRowSnapshotsEqual(beforeRows, afterRows);
|
|
2177
|
+
var reason = requestedUnits < currentUnits && rowsChanged ? 'child-resize-split' : 'child-resize-redistribute';
|
|
2178
|
+
return {
|
|
2179
|
+
parentId: parentId,
|
|
2180
|
+
triggerChildId: childId,
|
|
2181
|
+
reason: reason,
|
|
2182
|
+
beforeRows: beforeRows,
|
|
2183
|
+
afterRows: afterRows,
|
|
2184
|
+
nextLayout: __assign(__assign({}, parent.layout), { gridTemplate: nextSlotWeights }),
|
|
2185
|
+
};
|
|
2186
|
+
};
|
|
2187
|
+
AutoLayoutService.prototype.snapGridChildRequestedWidth = function (parentId, childId, requestedWidth) {
|
|
2188
|
+
var _a, _b;
|
|
2189
|
+
var parent = this.model.getElement(parentId);
|
|
2190
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid' || !parent.layout)
|
|
2191
|
+
return requestedWidth;
|
|
2192
|
+
var slotState = this.resolveGridChildSlotState(parentId, childId);
|
|
2193
|
+
if (!slotState)
|
|
2194
|
+
return requestedWidth;
|
|
2195
|
+
var requestedUnits = this.resolveRequestedGridUnits(parent, slotState.assignedRows[slotState.rowIndex], requestedWidth);
|
|
2196
|
+
var rowUnitWidth = this.resolveGridRowUnitWidth(Math.max(0, parent.size.width - this.resolveLayoutPadding(parent.layout).x * 2), slotState.assignedRows[slotState.rowIndex].childIds.length, (_b = parent.layout.gap) !== null && _b !== void 0 ? _b : 12);
|
|
2197
|
+
return Math.max(1, Math.round(requestedUnits * rowUnitWidth));
|
|
2198
|
+
};
|
|
2199
|
+
AutoLayoutService.prototype.canGridChildGrowRightward = function (parentId, childId) {
|
|
2200
|
+
var _a;
|
|
2201
|
+
var parent = this.model.getElement(parentId);
|
|
2202
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid' || !parent.layout)
|
|
2203
|
+
return false;
|
|
2204
|
+
var orderedIds = this.resolveAssignedGridRows(parent).flatMap(function (row) { return row.childIds; });
|
|
2205
|
+
var childIndex = orderedIds.indexOf(childId);
|
|
2206
|
+
return childIndex >= 0 && childIndex < orderedIds.length - 1;
|
|
2207
|
+
};
|
|
2208
|
+
AutoLayoutService.prototype.applyAxisLayoutForParent = function (parentId, parent, children, axis, options) {
|
|
2096
2209
|
var _a, _b;
|
|
2097
2210
|
var _this = this;
|
|
2098
2211
|
var _c, _d, _e, _f;
|
|
2099
|
-
|
|
2212
|
+
var preserveParentSize = Boolean(options === null || options === void 0 ? void 0 : options.preserveParentSize);
|
|
2213
|
+
var preserveParentWidth = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentWidth);
|
|
2214
|
+
var preserveParentHeight = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentHeight);
|
|
2100
2215
|
var layout = parent.layout;
|
|
2101
2216
|
var padding = this.resolveLayoutPadding(layout);
|
|
2102
2217
|
var gap = (_c = layout === null || layout === void 0 ? void 0 : layout.gap) !== null && _c !== void 0 ? _c : 12;
|
|
@@ -2179,8 +2294,16 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2179
2294
|
}
|
|
2180
2295
|
else {
|
|
2181
2296
|
(_a = resolveParentSize(fittedSizes), newParentWidth = _a.width, newParentHeight = _a.height);
|
|
2297
|
+
if (preserveParentWidth)
|
|
2298
|
+
newParentWidth = preservedParentWidth;
|
|
2299
|
+
if (preserveParentHeight)
|
|
2300
|
+
newParentHeight = preservedParentHeight;
|
|
2182
2301
|
fittedSizes = calculateFittedSizes(newParentWidth, newParentHeight);
|
|
2183
2302
|
(_b = resolveParentSize(fittedSizes), newParentWidth = _b.width, newParentHeight = _b.height);
|
|
2303
|
+
if (preserveParentWidth)
|
|
2304
|
+
newParentWidth = preservedParentWidth;
|
|
2305
|
+
if (preserveParentHeight)
|
|
2306
|
+
newParentHeight = preservedParentHeight;
|
|
2184
2307
|
}
|
|
2185
2308
|
var availableWidth = Math.max(0, newParentWidth - padding.x * 2);
|
|
2186
2309
|
var availableHeight = Math.max(0, newParentHeight - padding.y * 2 - labelReservedTopLane);
|
|
@@ -2215,10 +2338,12 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2215
2338
|
height: newParentHeight,
|
|
2216
2339
|
});
|
|
2217
2340
|
};
|
|
2218
|
-
AutoLayoutService.prototype.applyGridLayoutForParent = function (parentId, parent, children,
|
|
2341
|
+
AutoLayoutService.prototype.applyGridLayoutForParent = function (parentId, parent, children, options) {
|
|
2219
2342
|
var _this = this;
|
|
2220
2343
|
var _a, _b;
|
|
2221
|
-
|
|
2344
|
+
var preserveParentSize = Boolean(options === null || options === void 0 ? void 0 : options.preserveParentSize);
|
|
2345
|
+
var preserveParentWidth = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentWidth);
|
|
2346
|
+
var preserveParentHeight = preserveParentSize || Boolean(options === null || options === void 0 ? void 0 : options.preserveParentHeight);
|
|
2222
2347
|
var layout = parent.layout;
|
|
2223
2348
|
var padding = this.resolveLayoutPadding(layout);
|
|
2224
2349
|
var gap = (_a = layout === null || layout === void 0 ? void 0 : layout.gap) !== null && _a !== void 0 ? _a : 12;
|
|
@@ -2226,9 +2351,7 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2226
2351
|
var labelReservedTopLane = this.resolveLabelReservedTopLane(parentId, layout);
|
|
2227
2352
|
var constraints = this.resolveChildSizeConstraints(layout);
|
|
2228
2353
|
var autoResize = this.resolveAutoResizeMode(layout);
|
|
2229
|
-
|
|
2230
|
-
// Grid slot assignment should not depend on transient child positions produced during drag.
|
|
2231
|
-
var sorted = __spreadArray([], children, true);
|
|
2354
|
+
var sorted = this.sortGridChildrenForLayout(children);
|
|
2232
2355
|
var templateRows = this.normalizeGridTemplate(layout === null || layout === void 0 ? void 0 : layout.gridTemplate);
|
|
2233
2356
|
var assignedRows = this.assignChildrenToGridRows(sorted.map(function (child) { return child.id; }), templateRows);
|
|
2234
2357
|
var rowMetrics = assignedRows.map(function (row) {
|
|
@@ -2243,20 +2366,33 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2243
2366
|
};
|
|
2244
2367
|
});
|
|
2245
2368
|
var rowHeight = clampedSizes.reduce(function (max, size) { return Math.max(max, size.height); }, 0);
|
|
2246
|
-
var
|
|
2369
|
+
var totalGap = Math.max(0, clampedSizes.length - 1) * gap;
|
|
2370
|
+
var usedUnits = effectiveWeights.reduce(function (sum, weight) { return sum + _this.clampGridUnits(weight); }, 0);
|
|
2371
|
+
var requiredUnitWidth = effectiveWeights.reduce(function (max, weight, index) {
|
|
2372
|
+
var _a, _b;
|
|
2373
|
+
var slotUnits = Math.max(1, weight !== null && weight !== void 0 ? weight : 1);
|
|
2374
|
+
var width = (_b = (_a = clampedSizes[index]) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0;
|
|
2375
|
+
return Math.max(max, width / slotUnits);
|
|
2376
|
+
}, 0);
|
|
2377
|
+
var rowWidth = usedUnits >= GRID_ROW_UNITS
|
|
2378
|
+
? autoResize === 'grow-shrink'
|
|
2379
|
+
? Math.round(requiredUnitWidth * GRID_ROW_UNITS) + totalGap
|
|
2380
|
+
: clampedSizes.reduce(function (sum, size) { return sum + size.width; }, 0) + totalGap
|
|
2381
|
+
: Math.round(requiredUnitWidth * Math.max(1, usedUnits)) + totalGap;
|
|
2247
2382
|
return {
|
|
2248
2383
|
row: row,
|
|
2249
2384
|
rowHeight: rowHeight,
|
|
2250
2385
|
rowWidth: rowWidth,
|
|
2386
|
+
usedUnits: usedUnits,
|
|
2251
2387
|
effectiveWeights: effectiveWeights,
|
|
2252
2388
|
};
|
|
2253
2389
|
});
|
|
2254
2390
|
var requiredInnerWidth = rowMetrics.reduce(function (max, metric) { return Math.max(max, metric.rowWidth); }, 0);
|
|
2255
2391
|
var requiredInnerHeight = rowMetrics.reduce(function (sum, metric) { return sum + metric.rowHeight; }, 0) + Math.max(0, rowMetrics.length - 1) * gap;
|
|
2256
|
-
var newParentWidth =
|
|
2392
|
+
var newParentWidth = preserveParentWidth
|
|
2257
2393
|
? Math.max(0, Math.round(parent.size.width))
|
|
2258
2394
|
: this.resolveAutoResizedDimension(parent.size.width, padding.x * 2 + requiredInnerWidth, autoResize);
|
|
2259
|
-
var newParentHeight =
|
|
2395
|
+
var newParentHeight = preserveParentHeight
|
|
2260
2396
|
? Math.max(0, Math.round(parent.size.height))
|
|
2261
2397
|
: this.resolveAutoResizedDimension(parent.size.height, padding.y * 2 + labelReservedTopLane + requiredInnerHeight, autoResize);
|
|
2262
2398
|
var availableWidth = Math.max(0, newParentWidth - padding.x * 2);
|
|
@@ -2275,8 +2411,11 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2275
2411
|
if (childCount <= 0)
|
|
2276
2412
|
return;
|
|
2277
2413
|
var totalGap = Math.max(0, childCount - 1) * gap;
|
|
2278
|
-
var
|
|
2279
|
-
|
|
2414
|
+
var rowOuterWidth = metric.usedUnits >= GRID_ROW_UNITS
|
|
2415
|
+
? availableWidth
|
|
2416
|
+
: Math.min(availableWidth, metric.rowWidth);
|
|
2417
|
+
var rowInnerWidth = Math.max(0, rowOuterWidth - totalGap);
|
|
2418
|
+
var cellWidths = _this.resolveGridCellWidths(rowInnerWidth, metric.effectiveWeights);
|
|
2280
2419
|
var rowHeight = metric.rowHeight;
|
|
2281
2420
|
var cursorX = padding.x;
|
|
2282
2421
|
metric.row.childIds.forEach(function (childId, index) {
|
|
@@ -2300,6 +2439,13 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2300
2439
|
height: newParentHeight,
|
|
2301
2440
|
});
|
|
2302
2441
|
};
|
|
2442
|
+
AutoLayoutService.prototype.resolveGridCellWidths = function (rowInnerWidth, weights) {
|
|
2443
|
+
var _this = this;
|
|
2444
|
+
if (weights.length === 0)
|
|
2445
|
+
return [];
|
|
2446
|
+
var safeWeights = weights.map(function (weight) { return _this.clampGridUnits(weight); });
|
|
2447
|
+
return this.distributeWeightedSizes(Math.max(0, rowInnerWidth), safeWeights);
|
|
2448
|
+
};
|
|
2303
2449
|
AutoLayoutService.prototype.applyResolvedLayout = function (parentId, parent, desiredPositions, desiredSizes, parentSize) {
|
|
2304
2450
|
var _this = this;
|
|
2305
2451
|
var _a;
|
|
@@ -2362,43 +2508,96 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2362
2508
|
: Number.POSITIVE_INFINITY;
|
|
2363
2509
|
return { minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight };
|
|
2364
2510
|
};
|
|
2511
|
+
AutoLayoutService.prototype.resolveAssignedGridRows = function (parent) {
|
|
2512
|
+
var _a;
|
|
2513
|
+
var children = this.model.getChildren(parent.id);
|
|
2514
|
+
var sorted = this.sortGridChildrenForLayout(children);
|
|
2515
|
+
var templateRows = this.normalizeGridTemplate((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.gridTemplate);
|
|
2516
|
+
return this.assignChildrenToGridRows(sorted.map(function (child) { return child.id; }), templateRows);
|
|
2517
|
+
};
|
|
2518
|
+
AutoLayoutService.prototype.repartitionAssignedGridRows = function (assignedRows, rowIndex, nextCurrentRowCount) {
|
|
2519
|
+
var _a, _b;
|
|
2520
|
+
var allChildIds = assignedRows.flatMap(function (row) { return row.childIds; });
|
|
2521
|
+
var prefixRows = assignedRows.slice(0, rowIndex).map(function (row) { return ({
|
|
2522
|
+
weights: __spreadArray([], row.weights.slice(0, row.childIds.length), true),
|
|
2523
|
+
childIds: __spreadArray([], row.childIds, true),
|
|
2524
|
+
}); });
|
|
2525
|
+
var prefixCount = prefixRows.reduce(function (sum, row) { return sum + row.childIds.length; }, 0);
|
|
2526
|
+
var nextRows = __spreadArray([], prefixRows, true);
|
|
2527
|
+
var currentChildIds = allChildIds.slice(prefixCount, prefixCount + nextCurrentRowCount);
|
|
2528
|
+
if (currentChildIds.length > 0) {
|
|
2529
|
+
nextRows.push({
|
|
2530
|
+
weights: this.fitGridRowWeights((_a = assignedRows[rowIndex]) === null || _a === void 0 ? void 0 : _a.weights, currentChildIds.length),
|
|
2531
|
+
childIds: currentChildIds,
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
var cursor = prefixCount + currentChildIds.length;
|
|
2535
|
+
var trailingRowIndex = rowIndex + 1;
|
|
2536
|
+
while (cursor < allChildIds.length) {
|
|
2537
|
+
var sourceRow = assignedRows[Math.min(trailingRowIndex, assignedRows.length - 1)];
|
|
2538
|
+
var sourceCapacity = Math.max(1, (_b = sourceRow === null || sourceRow === void 0 ? void 0 : sourceRow.childIds.length) !== null && _b !== void 0 ? _b : 1);
|
|
2539
|
+
var rowChildIds = allChildIds.slice(cursor, cursor + sourceCapacity);
|
|
2540
|
+
nextRows.push({
|
|
2541
|
+
weights: this.fitGridRowWeights(sourceRow === null || sourceRow === void 0 ? void 0 : sourceRow.weights, rowChildIds.length),
|
|
2542
|
+
childIds: rowChildIds,
|
|
2543
|
+
});
|
|
2544
|
+
cursor += rowChildIds.length;
|
|
2545
|
+
trailingRowIndex += 1;
|
|
2546
|
+
}
|
|
2547
|
+
return nextRows;
|
|
2548
|
+
};
|
|
2549
|
+
AutoLayoutService.prototype.fitGridRowWeights = function (sourceWeights, childCount) {
|
|
2550
|
+
if (childCount <= 0)
|
|
2551
|
+
return [];
|
|
2552
|
+
var base = Array.isArray(sourceWeights) && sourceWeights.length > 0 ? sourceWeights : [1];
|
|
2553
|
+
var normalizedBase = this.normalizeRowWeightsToTwelveUnits(base);
|
|
2554
|
+
if (normalizedBase.length === childCount) {
|
|
2555
|
+
return normalizedBase;
|
|
2556
|
+
}
|
|
2557
|
+
if (normalizedBase.length > childCount) {
|
|
2558
|
+
return this.normalizeRowWeightsToTwelveUnits(normalizedBase.slice(0, childCount));
|
|
2559
|
+
}
|
|
2560
|
+
return this.buildEqualGridUnits(childCount);
|
|
2561
|
+
};
|
|
2562
|
+
AutoLayoutService.prototype.gridRowSnapshotsEqual = function (a, b) {
|
|
2563
|
+
var _a, _b, _c, _d;
|
|
2564
|
+
if (a.length !== b.length)
|
|
2565
|
+
return false;
|
|
2566
|
+
for (var index = 0; index < a.length; index += 1) {
|
|
2567
|
+
var left = (_b = (_a = a[index]) === null || _a === void 0 ? void 0 : _a.childIds) !== null && _b !== void 0 ? _b : [];
|
|
2568
|
+
var right = (_d = (_c = b[index]) === null || _c === void 0 ? void 0 : _c.childIds) !== null && _d !== void 0 ? _d : [];
|
|
2569
|
+
if (left.length !== right.length)
|
|
2570
|
+
return false;
|
|
2571
|
+
for (var childIndex = 0; childIndex < left.length; childIndex += 1) {
|
|
2572
|
+
if (left[childIndex] !== right[childIndex])
|
|
2573
|
+
return false;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
return true;
|
|
2577
|
+
};
|
|
2365
2578
|
AutoLayoutService.prototype.normalizeGridTemplate = function (template) {
|
|
2579
|
+
var slots = this.normalizeGridSlotUnits(template);
|
|
2366
2580
|
var rows = [];
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
}
|
|
2375
|
-
if (!Array.isArray(entry))
|
|
2376
|
-
return;
|
|
2377
|
-
if (entry.length === 1 && Number.isFinite(entry[0]) && entry[0] > 1) {
|
|
2378
|
-
var count = Math.max(0, Math.floor(entry[0]));
|
|
2379
|
-
if (count > 0) {
|
|
2380
|
-
rows.push({ weights: Array.from({ length: count }, function () { return 1; }) });
|
|
2381
|
-
}
|
|
2382
|
-
return;
|
|
2383
|
-
}
|
|
2384
|
-
var weights = entry
|
|
2385
|
-
.map(function (value) {
|
|
2386
|
-
if (!Number.isFinite(value) || value <= 0)
|
|
2387
|
-
return 1;
|
|
2388
|
-
return value;
|
|
2389
|
-
})
|
|
2390
|
-
.filter(function (value) { return value > 0; });
|
|
2391
|
-
if (weights.length > 0) {
|
|
2392
|
-
rows.push({ weights: weights });
|
|
2581
|
+
var currentRow = [];
|
|
2582
|
+
var currentUnits = 0;
|
|
2583
|
+
slots.forEach(function (slotUnits) {
|
|
2584
|
+
if (currentRow.length > 0 && currentUnits + slotUnits > GRID_ROW_UNITS) {
|
|
2585
|
+
rows.push({ weights: __spreadArray([], currentRow, true) });
|
|
2586
|
+
currentRow = [];
|
|
2587
|
+
currentUnits = 0;
|
|
2393
2588
|
}
|
|
2589
|
+
currentRow.push(slotUnits);
|
|
2590
|
+
currentUnits += slotUnits;
|
|
2394
2591
|
});
|
|
2592
|
+
if (currentRow.length > 0) {
|
|
2593
|
+
rows.push({ weights: __spreadArray([], currentRow, true) });
|
|
2594
|
+
}
|
|
2395
2595
|
if (rows.length === 0) {
|
|
2396
|
-
rows.push({ weights: [
|
|
2596
|
+
rows.push({ weights: [GRID_ROW_UNITS] });
|
|
2397
2597
|
}
|
|
2398
2598
|
return rows;
|
|
2399
2599
|
};
|
|
2400
2600
|
AutoLayoutService.prototype.assignChildrenToGridRows = function (childIds, templateRows) {
|
|
2401
|
-
var _a;
|
|
2402
2601
|
var assigned = [];
|
|
2403
2602
|
var cursor = 0;
|
|
2404
2603
|
templateRows.forEach(function (rowTemplate) {
|
|
@@ -2414,19 +2613,348 @@ var AutoLayoutService = /** @class */ (function () {
|
|
|
2414
2613
|
cursor += rowChildren.length;
|
|
2415
2614
|
});
|
|
2416
2615
|
while (cursor < childIds.length) {
|
|
2417
|
-
var
|
|
2418
|
-
var lastRow = templateRows[templateRows.length - 1];
|
|
2419
|
-
var fallbackColumns = (_a = lastRow === null || lastRow === void 0 ? void 0 : lastRow.weights.length) !== null && _a !== void 0 ? _a : 1;
|
|
2420
|
-
var fallbackCount = Math.max(1, Math.min(remaining, fallbackColumns));
|
|
2421
|
-
var rowChildren = childIds.slice(cursor, cursor + fallbackCount);
|
|
2616
|
+
var rowChildren = childIds.slice(cursor, cursor + 1);
|
|
2422
2617
|
assigned.push({
|
|
2423
|
-
weights:
|
|
2618
|
+
weights: [GRID_ROW_UNITS],
|
|
2424
2619
|
childIds: rowChildren,
|
|
2425
2620
|
});
|
|
2426
2621
|
cursor += rowChildren.length;
|
|
2427
2622
|
}
|
|
2428
2623
|
return assigned;
|
|
2429
2624
|
};
|
|
2625
|
+
AutoLayoutService.prototype.resolveGridChildSlotState = function (parentId, childId) {
|
|
2626
|
+
var _this = this;
|
|
2627
|
+
var _a;
|
|
2628
|
+
var parent = this.model.getElement(parentId);
|
|
2629
|
+
if (!parent || ((_a = parent.layout) === null || _a === void 0 ? void 0 : _a.mode) !== 'grid')
|
|
2630
|
+
return null;
|
|
2631
|
+
var assignedRows = this.resolveAssignedGridRows(parent);
|
|
2632
|
+
if (assignedRows.length === 0)
|
|
2633
|
+
return null;
|
|
2634
|
+
var orderedChildIds = assignedRows.flatMap(function (row) { return row.childIds; });
|
|
2635
|
+
var slotWeights = assignedRows.flatMap(function (row) { return row.weights.slice(0, row.childIds.length).map(function (weight) { return _this.clampGridUnits(weight); }); });
|
|
2636
|
+
var childFlatIndex = orderedChildIds.indexOf(childId);
|
|
2637
|
+
if (childFlatIndex < 0)
|
|
2638
|
+
return null;
|
|
2639
|
+
var rowIndex = assignedRows.findIndex(function (row) { return row.childIds.includes(childId); });
|
|
2640
|
+
if (rowIndex < 0)
|
|
2641
|
+
return null;
|
|
2642
|
+
return { assignedRows: assignedRows, orderedChildIds: orderedChildIds, slotWeights: slotWeights, childFlatIndex: childFlatIndex, rowIndex: rowIndex };
|
|
2643
|
+
};
|
|
2644
|
+
AutoLayoutService.prototype.packGridRowsFromSlots = function (childIds, slotWeights) {
|
|
2645
|
+
var _this = this;
|
|
2646
|
+
var rows = [];
|
|
2647
|
+
var currentChildIds = [];
|
|
2648
|
+
var currentWeights = [];
|
|
2649
|
+
var currentUnits = 0;
|
|
2650
|
+
childIds.forEach(function (childId, index) {
|
|
2651
|
+
var _a;
|
|
2652
|
+
var slotUnits = _this.clampGridUnits((_a = slotWeights[index]) !== null && _a !== void 0 ? _a : GRID_ROW_UNITS);
|
|
2653
|
+
if (currentChildIds.length > 0 && currentUnits + slotUnits > GRID_ROW_UNITS) {
|
|
2654
|
+
rows.push({ childIds: __spreadArray([], currentChildIds, true), weights: __spreadArray([], currentWeights, true) });
|
|
2655
|
+
currentChildIds = [];
|
|
2656
|
+
currentWeights = [];
|
|
2657
|
+
currentUnits = 0;
|
|
2658
|
+
}
|
|
2659
|
+
currentChildIds.push(childId);
|
|
2660
|
+
currentWeights.push(slotUnits);
|
|
2661
|
+
currentUnits += slotUnits;
|
|
2662
|
+
});
|
|
2663
|
+
if (currentChildIds.length > 0) {
|
|
2664
|
+
rows.push({ childIds: __spreadArray([], currentChildIds, true), weights: __spreadArray([], currentWeights, true) });
|
|
2665
|
+
}
|
|
2666
|
+
return rows;
|
|
2667
|
+
};
|
|
2668
|
+
AutoLayoutService.prototype.resolveRequestedGridUnits = function (parent, currentRow, requestedWidth) {
|
|
2669
|
+
var _a;
|
|
2670
|
+
if (!parent.layout || parent.layout.mode !== 'grid' || !currentRow)
|
|
2671
|
+
return GRID_ROW_UNITS;
|
|
2672
|
+
var rowUnitWidth = this.resolveGridRowUnitWidth(Math.max(0, parent.size.width - this.resolveLayoutPadding(parent.layout).x * 2), currentRow.childIds.length, (_a = parent.layout.gap) !== null && _a !== void 0 ? _a : 12);
|
|
2673
|
+
if (rowUnitWidth <= 0)
|
|
2674
|
+
return GRID_ROW_UNITS;
|
|
2675
|
+
return this.clampGridUnits(Math.round(requestedWidth / rowUnitWidth));
|
|
2676
|
+
};
|
|
2677
|
+
AutoLayoutService.prototype.sortGridChildrenForLayout = function (children) {
|
|
2678
|
+
return __spreadArray([], children, true).sort(function (a, b) {
|
|
2679
|
+
if (a.position.y === b.position.y) {
|
|
2680
|
+
if (a.position.x === b.position.x)
|
|
2681
|
+
return a.id.localeCompare(b.id);
|
|
2682
|
+
return a.position.x - b.position.x;
|
|
2683
|
+
}
|
|
2684
|
+
return a.position.y - b.position.y;
|
|
2685
|
+
});
|
|
2686
|
+
};
|
|
2687
|
+
AutoLayoutService.prototype.resolveRightwardGridOverflowChange = function (params) {
|
|
2688
|
+
var _a, _b;
|
|
2689
|
+
var assignedRows = params.assignedRows, rowIndex = params.rowIndex, childIndex = params.childIndex, requestedWidth = params.requestedWidth, availableWidth = params.availableWidth, gap = params.gap, parentLayout = params.parentLayout, parentId = params.parentId, childId = params.childId;
|
|
2690
|
+
var currentRow = assignedRows[rowIndex];
|
|
2691
|
+
if (!currentRow || childIndex < 0 || childIndex >= currentRow.childIds.length - 1)
|
|
2692
|
+
return null;
|
|
2693
|
+
var rowUnitWidth = this.resolveGridRowUnitWidth(availableWidth, currentRow.childIds.length, gap);
|
|
2694
|
+
if (rowUnitWidth <= 0)
|
|
2695
|
+
return null;
|
|
2696
|
+
var currentUnits = (_b = (_a = currentRow.weights[childIndex]) !== null && _a !== void 0 ? _a : this.normalizeRowWeightsToTwelveUnits(currentRow.weights)[childIndex]) !== null && _b !== void 0 ? _b : 1;
|
|
2697
|
+
var requestedUnits = this.clampLayoutSize(Math.round(requestedWidth / rowUnitWidth), currentUnits + 1, GRID_ROW_UNITS - 1);
|
|
2698
|
+
var leftWeights = currentRow.weights.slice(0, childIndex);
|
|
2699
|
+
var leftSum = leftWeights.reduce(function (sum, value) { return sum + value; }, 0);
|
|
2700
|
+
var rightWeights = currentRow.weights.slice(childIndex + 1);
|
|
2701
|
+
var rightIds = currentRow.childIds.slice(childIndex + 1);
|
|
2702
|
+
var followingRows = assignedRows.slice(rowIndex + 1);
|
|
2703
|
+
for (var retainCount = rightIds.length - 1; retainCount >= 0; retainCount -= 1) {
|
|
2704
|
+
var maxTargetUnits = GRID_ROW_UNITS - leftSum - retainCount;
|
|
2705
|
+
if (requestedUnits > maxTargetUnits)
|
|
2706
|
+
continue;
|
|
2707
|
+
var retainedIds = rightIds.slice(0, retainCount);
|
|
2708
|
+
var retainedWeights = rightWeights.slice(0, retainCount);
|
|
2709
|
+
var overflowIds = __spreadArray(__spreadArray([], rightIds.slice(retainCount), true), followingRows.flatMap(function (row) { return row.childIds; }), true);
|
|
2710
|
+
var remainingUnits = GRID_ROW_UNITS - leftSum - requestedUnits;
|
|
2711
|
+
var nextCurrentWeights = __spreadArray(__spreadArray(__spreadArray([], leftWeights, true), [
|
|
2712
|
+
requestedUnits
|
|
2713
|
+
], false), this.distributeUnitsWithMinimums(remainingUnits, retainedWeights), true);
|
|
2714
|
+
var nextRows = assignedRows.slice(0, rowIndex).map(function (row) { return ({
|
|
2715
|
+
weights: __spreadArray([], row.weights, true),
|
|
2716
|
+
childIds: __spreadArray([], row.childIds, true),
|
|
2717
|
+
}); });
|
|
2718
|
+
nextRows.push({
|
|
2719
|
+
weights: nextCurrentWeights,
|
|
2720
|
+
childIds: __spreadArray(__spreadArray([], currentRow.childIds.slice(0, childIndex + 1), true), retainedIds, true),
|
|
2721
|
+
});
|
|
2722
|
+
var trailingRows = this.reflowTrailingGridRows(overflowIds, followingRows, currentRow.weights.length);
|
|
2723
|
+
var allRows = __spreadArray(__spreadArray([], nextRows, true), trailingRows, true);
|
|
2724
|
+
var beforeRows = assignedRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); });
|
|
2725
|
+
var afterRows = allRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); });
|
|
2726
|
+
if (this.gridRowSnapshotsEqual(beforeRows, afterRows) && this.gridWeightsEqual(assignedRows, allRows)) {
|
|
2727
|
+
return null;
|
|
2728
|
+
}
|
|
2729
|
+
return {
|
|
2730
|
+
parentId: parentId,
|
|
2731
|
+
triggerChildId: childId,
|
|
2732
|
+
reason: 'child-resize-redistribute',
|
|
2733
|
+
beforeRows: beforeRows,
|
|
2734
|
+
afterRows: afterRows,
|
|
2735
|
+
nextLayout: __assign(__assign({}, parentLayout), { gridTemplate: this.flattenAssignedRowsToGridTemplate(allRows) }),
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
return null;
|
|
2739
|
+
};
|
|
2740
|
+
AutoLayoutService.prototype.resolveSameRowGridUnitResizeChange = function (params) {
|
|
2741
|
+
var _this = this;
|
|
2742
|
+
var _a, _b, _c, _d;
|
|
2743
|
+
var assignedRows = params.assignedRows, rowIndex = params.rowIndex, childIndex = params.childIndex, requestedWidth = params.requestedWidth, availableWidth = params.availableWidth, gap = params.gap, parentLayout = params.parentLayout, parentId = params.parentId, childId = params.childId;
|
|
2744
|
+
var currentRow = assignedRows[rowIndex];
|
|
2745
|
+
if (!currentRow || currentRow.childIds.length <= 1)
|
|
2746
|
+
return null;
|
|
2747
|
+
var donorIndices = Array.from({ length: Math.max(0, currentRow.childIds.length - childIndex - 1) }, function (_, index) { return childIndex + 1 + index; });
|
|
2748
|
+
if (donorIndices.length === 0)
|
|
2749
|
+
return null;
|
|
2750
|
+
var rowUnitWidth = this.resolveGridRowUnitWidth(availableWidth, currentRow.childIds.length, gap);
|
|
2751
|
+
if (rowUnitWidth <= 0)
|
|
2752
|
+
return null;
|
|
2753
|
+
var currentUnits = (_b = (_a = currentRow.weights[childIndex]) !== null && _a !== void 0 ? _a : this.normalizeRowWeightsToTwelveUnits(currentRow.weights)[childIndex]) !== null && _b !== void 0 ? _b : 1;
|
|
2754
|
+
var requestedUnits = this.clampLayoutSize(Math.round(requestedWidth / rowUnitWidth), 1, GRID_ROW_UNITS - 1);
|
|
2755
|
+
if (requestedUnits === currentUnits)
|
|
2756
|
+
return null;
|
|
2757
|
+
var nextWeights = __spreadArray([], currentRow.weights, true);
|
|
2758
|
+
var delta = requestedUnits - currentUnits;
|
|
2759
|
+
if (delta > 0) {
|
|
2760
|
+
for (var _i = 0, donorIndices_1 = donorIndices; _i < donorIndices_1.length; _i++) {
|
|
2761
|
+
var donorIndex = donorIndices_1[_i];
|
|
2762
|
+
if (delta <= 0)
|
|
2763
|
+
break;
|
|
2764
|
+
var donorCapacity = Math.max(0, ((_c = nextWeights[donorIndex]) !== null && _c !== void 0 ? _c : 1) - 1);
|
|
2765
|
+
var transfer = Math.min(delta, donorCapacity);
|
|
2766
|
+
nextWeights[donorIndex] -= transfer;
|
|
2767
|
+
nextWeights[childIndex] += transfer;
|
|
2768
|
+
delta -= transfer;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
else {
|
|
2772
|
+
var release = Math.abs(delta);
|
|
2773
|
+
for (var _e = 0, donorIndices_2 = donorIndices; _e < donorIndices_2.length; _e++) {
|
|
2774
|
+
var donorIndex = donorIndices_2[_e];
|
|
2775
|
+
if (release <= 0)
|
|
2776
|
+
break;
|
|
2777
|
+
var transfer = release;
|
|
2778
|
+
nextWeights[donorIndex] += transfer;
|
|
2779
|
+
nextWeights[childIndex] -= transfer;
|
|
2780
|
+
release -= transfer;
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
if (delta > 0)
|
|
2784
|
+
return null;
|
|
2785
|
+
if (((_d = nextWeights[childIndex]) !== null && _d !== void 0 ? _d : currentUnits) === currentUnits)
|
|
2786
|
+
return null;
|
|
2787
|
+
var nextRows = assignedRows.map(function (row, index) {
|
|
2788
|
+
return index === rowIndex
|
|
2789
|
+
? {
|
|
2790
|
+
weights: _this.normalizeRowWeightsToTwelveUnits(nextWeights),
|
|
2791
|
+
childIds: __spreadArray([], row.childIds, true),
|
|
2792
|
+
}
|
|
2793
|
+
: { weights: __spreadArray([], row.weights, true), childIds: __spreadArray([], row.childIds, true) };
|
|
2794
|
+
});
|
|
2795
|
+
return {
|
|
2796
|
+
parentId: parentId,
|
|
2797
|
+
triggerChildId: childId,
|
|
2798
|
+
reason: 'child-resize-redistribute',
|
|
2799
|
+
beforeRows: assignedRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); }),
|
|
2800
|
+
afterRows: nextRows.map(function (row) { return ({ childIds: __spreadArray([], row.childIds, true) }); }),
|
|
2801
|
+
nextLayout: __assign(__assign({}, parentLayout), { gridTemplate: this.flattenAssignedRowsToGridTemplate(nextRows) }),
|
|
2802
|
+
};
|
|
2803
|
+
};
|
|
2804
|
+
AutoLayoutService.prototype.splitGridRowIntoTwelveUnits = function (assignedRows, rowIndex, childId, requestedWidth, availableWidth, gap) {
|
|
2805
|
+
var _a;
|
|
2806
|
+
var currentRow = assignedRows[rowIndex];
|
|
2807
|
+
var nextRow = assignedRows[rowIndex + 1];
|
|
2808
|
+
if (!currentRow || !nextRow || currentRow.childIds.length !== 1 || nextRow.childIds.length === 0) {
|
|
2809
|
+
return [];
|
|
2810
|
+
}
|
|
2811
|
+
var rowUnitWidth = this.resolveGridRowUnitWidth(availableWidth, 2, gap);
|
|
2812
|
+
var requestedUnits = this.clampLayoutSize(Math.round(requestedWidth / rowUnitWidth), 1, GRID_ROW_UNITS - 1);
|
|
2813
|
+
var nextRows = assignedRows.slice(0, rowIndex).map(function (row) { return ({
|
|
2814
|
+
weights: __spreadArray([], row.weights, true),
|
|
2815
|
+
childIds: __spreadArray([], row.childIds, true),
|
|
2816
|
+
}); });
|
|
2817
|
+
nextRows.push({
|
|
2818
|
+
weights: [requestedUnits, GRID_ROW_UNITS - requestedUnits],
|
|
2819
|
+
childIds: [childId, nextRow.childIds[0]],
|
|
2820
|
+
});
|
|
2821
|
+
var trailingRows = [];
|
|
2822
|
+
var remainingChildIds = __spreadArray(__spreadArray([], nextRow.childIds.slice(1), true), assignedRows.slice(rowIndex + 2).flatMap(function (row) { return row.childIds; }), true);
|
|
2823
|
+
var cursor = 0;
|
|
2824
|
+
var seedRows = assignedRows.slice(rowIndex + 1);
|
|
2825
|
+
var seedIndex = 0;
|
|
2826
|
+
while (cursor < remainingChildIds.length) {
|
|
2827
|
+
var seed = seedRows[Math.min(seedIndex, seedRows.length - 1)];
|
|
2828
|
+
var capacity = Math.max(1, (_a = seed === null || seed === void 0 ? void 0 : seed.childIds.length) !== null && _a !== void 0 ? _a : 1);
|
|
2829
|
+
var rowChildIds = remainingChildIds.slice(cursor, cursor + capacity);
|
|
2830
|
+
trailingRows.push({
|
|
2831
|
+
weights: this.fitGridRowWeights(seed === null || seed === void 0 ? void 0 : seed.weights, rowChildIds.length),
|
|
2832
|
+
childIds: rowChildIds,
|
|
2833
|
+
});
|
|
2834
|
+
cursor += rowChildIds.length;
|
|
2835
|
+
seedIndex += 1;
|
|
2836
|
+
}
|
|
2837
|
+
return __spreadArray(__spreadArray([], nextRows, true), trailingRows, true);
|
|
2838
|
+
};
|
|
2839
|
+
AutoLayoutService.prototype.reflowTrailingGridRows = function (childIds, seedRows, fallbackColumnCount) {
|
|
2840
|
+
var _a;
|
|
2841
|
+
if (childIds.length === 0)
|
|
2842
|
+
return [];
|
|
2843
|
+
var trailingRows = [];
|
|
2844
|
+
var cursor = 0;
|
|
2845
|
+
var seedIndex = 0;
|
|
2846
|
+
var normalizedSeedRows = seedRows.length > 0 ? seedRows : [{ weights: this.buildEqualGridUnits(Math.max(1, fallbackColumnCount)), childIds: [] }];
|
|
2847
|
+
while (cursor < childIds.length) {
|
|
2848
|
+
var seed = normalizedSeedRows[Math.min(seedIndex, normalizedSeedRows.length - 1)];
|
|
2849
|
+
var capacity = Math.max(1, (_a = seed === null || seed === void 0 ? void 0 : seed.weights.length) !== null && _a !== void 0 ? _a : fallbackColumnCount);
|
|
2850
|
+
var rowChildIds = childIds.slice(cursor, cursor + capacity);
|
|
2851
|
+
trailingRows.push({
|
|
2852
|
+
weights: this.fitGridRowWeights(seed === null || seed === void 0 ? void 0 : seed.weights, rowChildIds.length),
|
|
2853
|
+
childIds: rowChildIds,
|
|
2854
|
+
});
|
|
2855
|
+
cursor += rowChildIds.length;
|
|
2856
|
+
seedIndex += 1;
|
|
2857
|
+
}
|
|
2858
|
+
return trailingRows;
|
|
2859
|
+
};
|
|
2860
|
+
AutoLayoutService.prototype.flattenAssignedRowsToGridTemplate = function (rows) {
|
|
2861
|
+
var _this = this;
|
|
2862
|
+
return rows.flatMap(function (row) { return _this.normalizeRowWeightsToTwelveUnits(row.weights.slice(0, row.childIds.length)); });
|
|
2863
|
+
};
|
|
2864
|
+
AutoLayoutService.prototype.buildEqualGridUnits = function (count) {
|
|
2865
|
+
if (count <= 0)
|
|
2866
|
+
return [];
|
|
2867
|
+
var base = Math.floor(GRID_ROW_UNITS / count);
|
|
2868
|
+
var remainder = GRID_ROW_UNITS - base * count;
|
|
2869
|
+
return Array.from({ length: count }, function (_, index) { return base + (index < remainder ? 1 : 0); });
|
|
2870
|
+
};
|
|
2871
|
+
AutoLayoutService.prototype.normalizeRowWeightsToTwelveUnits = function (weights) {
|
|
2872
|
+
var safeWeights = weights.map(function (weight) { return (Number.isFinite(weight) && weight > 0 ? weight : 1); });
|
|
2873
|
+
if (safeWeights.length === 0)
|
|
2874
|
+
return [GRID_ROW_UNITS];
|
|
2875
|
+
if (safeWeights.length === 1)
|
|
2876
|
+
return [GRID_ROW_UNITS];
|
|
2877
|
+
var distributed = this.distributeWeightedSizes(GRID_ROW_UNITS, safeWeights);
|
|
2878
|
+
var normalized = distributed.map(function (value) { return Math.max(1, value); });
|
|
2879
|
+
var total = normalized.reduce(function (sum, value) { return sum + value; }, 0);
|
|
2880
|
+
if (total === GRID_ROW_UNITS)
|
|
2881
|
+
return normalized;
|
|
2882
|
+
if (total < GRID_ROW_UNITS) {
|
|
2883
|
+
var cursor_1 = 0;
|
|
2884
|
+
while (total < GRID_ROW_UNITS) {
|
|
2885
|
+
normalized[cursor_1 % normalized.length] += 1;
|
|
2886
|
+
total += 1;
|
|
2887
|
+
cursor_1 += 1;
|
|
2888
|
+
}
|
|
2889
|
+
return normalized;
|
|
2890
|
+
}
|
|
2891
|
+
var cursor = normalized.length - 1;
|
|
2892
|
+
while (total > GRID_ROW_UNITS && cursor >= 0) {
|
|
2893
|
+
if (normalized[cursor] > 1) {
|
|
2894
|
+
normalized[cursor] -= 1;
|
|
2895
|
+
total -= 1;
|
|
2896
|
+
}
|
|
2897
|
+
else {
|
|
2898
|
+
cursor -= 1;
|
|
2899
|
+
}
|
|
2900
|
+
if (cursor < 0 && total > GRID_ROW_UNITS) {
|
|
2901
|
+
cursor = normalized.length - 1;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
return normalized;
|
|
2905
|
+
};
|
|
2906
|
+
AutoLayoutService.prototype.normalizeGridSlotUnits = function (template) {
|
|
2907
|
+
var _this = this;
|
|
2908
|
+
var slots = [];
|
|
2909
|
+
(template !== null && template !== void 0 ? template : []).forEach(function (entry) {
|
|
2910
|
+
if (typeof entry === 'number') {
|
|
2911
|
+
if (Number.isFinite(entry) && entry > 0) {
|
|
2912
|
+
slots.push(_this.clampGridUnits(entry));
|
|
2913
|
+
}
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
if (!Array.isArray(entry))
|
|
2917
|
+
return;
|
|
2918
|
+
entry.forEach(function (value) {
|
|
2919
|
+
if (Number.isFinite(value) && value > 0) {
|
|
2920
|
+
slots.push(_this.clampGridUnits(value));
|
|
2921
|
+
}
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
return slots;
|
|
2925
|
+
};
|
|
2926
|
+
AutoLayoutService.prototype.clampGridUnits = function (value) {
|
|
2927
|
+
return Math.max(1, Math.min(GRID_ROW_UNITS, Math.round(value)));
|
|
2928
|
+
};
|
|
2929
|
+
AutoLayoutService.prototype.distributeUnitsWithMinimums = function (totalUnits, seedWeights) {
|
|
2930
|
+
if (seedWeights.length === 0)
|
|
2931
|
+
return [];
|
|
2932
|
+
var minimumTotal = seedWeights.length;
|
|
2933
|
+
var clampedTotal = Math.max(minimumTotal, totalUnits);
|
|
2934
|
+
var distributed = this.distributeWeightedSizes(clampedTotal - minimumTotal, seedWeights).map(function (value) { return value + 1; });
|
|
2935
|
+
return distributed;
|
|
2936
|
+
};
|
|
2937
|
+
AutoLayoutService.prototype.gridWeightsEqual = function (leftRows, rightRows) {
|
|
2938
|
+
var _a, _b, _c, _d;
|
|
2939
|
+
if (leftRows.length !== rightRows.length)
|
|
2940
|
+
return false;
|
|
2941
|
+
for (var rowIndex = 0; rowIndex < leftRows.length; rowIndex += 1) {
|
|
2942
|
+
var left = (_b = (_a = leftRows[rowIndex]) === null || _a === void 0 ? void 0 : _a.weights) !== null && _b !== void 0 ? _b : [];
|
|
2943
|
+
var right = (_d = (_c = rightRows[rowIndex]) === null || _c === void 0 ? void 0 : _c.weights) !== null && _d !== void 0 ? _d : [];
|
|
2944
|
+
if (left.length !== right.length)
|
|
2945
|
+
return false;
|
|
2946
|
+
for (var index = 0; index < left.length; index += 1) {
|
|
2947
|
+
if (left[index] !== right[index])
|
|
2948
|
+
return false;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
return true;
|
|
2952
|
+
};
|
|
2953
|
+
AutoLayoutService.prototype.resolveGridRowUnitWidth = function (availableWidth, childCount, gap) {
|
|
2954
|
+
var totalGap = Math.max(0, childCount - 1) * gap;
|
|
2955
|
+
var rowInnerWidth = Math.max(0, availableWidth - totalGap);
|
|
2956
|
+
return rowInnerWidth / GRID_ROW_UNITS;
|
|
2957
|
+
};
|
|
2430
2958
|
AutoLayoutService.prototype.resolveLabelReservedTopLane = function (parentId, layout) {
|
|
2431
2959
|
var _a, _b, _c, _d;
|
|
2432
2960
|
var policy = layout === null || layout === void 0 ? void 0 : layout.labelReservedSpace;
|
|
@@ -2961,11 +3489,18 @@ var LinkRoutingService = /** @class */ (function () {
|
|
|
2961
3489
|
var onEdge = (shape === null || shape === void 0 ? void 0 : shape.projectToBorder)
|
|
2962
3490
|
? this.isPointOnProjectedBorder(point, rect, shape.projectToBorder, EDGE_TOLERANCE)
|
|
2963
3491
|
: this.isPointOnRectEdge(point, rect, EDGE_TOLERANCE);
|
|
2964
|
-
var
|
|
3492
|
+
var projectedBorderPoint = (shape === null || shape === void 0 ? void 0 : shape.projectToBorder)
|
|
3493
|
+
? shape.projectToBorder(point, rect)
|
|
3494
|
+
: projectPointToBoundary(point, rect, 'rect');
|
|
3495
|
+
var projectedBoundaryEquivalent = !onEdge && !this.isPointInsideRect(point, rect, EDGE_TOLERANCE);
|
|
3496
|
+
var sidePoint = projectedBoundaryEquivalent ? projectedBorderPoint : point;
|
|
3497
|
+
var onEdgeSide = onEdge || projectedBoundaryEquivalent
|
|
3498
|
+
? (_b = (_a = shape === null || shape === void 0 ? void 0 : shape.resolveBorderSide) === null || _a === void 0 ? void 0 : _a.call(shape, sidePoint, rect)) !== null && _b !== void 0 ? _b : this.resolveEdgeSide(sidePoint, rect)
|
|
3499
|
+
: undefined;
|
|
2965
3500
|
if (onEdgeSide && oppositePoint) {
|
|
2966
3501
|
onEdgeSide = this.resolveCornerTieBreakSide(point, rect, oppositePoint, onEdgeSide);
|
|
2967
3502
|
}
|
|
2968
|
-
return { onEdge: onEdge, onEdgeSide: onEdgeSide };
|
|
3503
|
+
return { onEdge: onEdge || projectedBoundaryEquivalent, onEdgeSide: onEdgeSide };
|
|
2969
3504
|
};
|
|
2970
3505
|
LinkRoutingService.prototype.resolveCornerTieBreakSide = function (point, rect, oppositePoint, currentSide) {
|
|
2971
3506
|
var onLeft = Math.abs(point.x - rect.x) <= EDGE_TOLERANCE;
|
|
@@ -3127,6 +3662,12 @@ var LinkRoutingService = /** @class */ (function () {
|
|
|
3127
3662
|
var onBottom = Math.abs(point.y - (rect.y + rect.height)) <= tolerance;
|
|
3128
3663
|
return onLeft || onRight || onTop || onBottom;
|
|
3129
3664
|
};
|
|
3665
|
+
LinkRoutingService.prototype.isPointInsideRect = function (point, rect, tolerance) {
|
|
3666
|
+
return (point.x >= rect.x - tolerance &&
|
|
3667
|
+
point.x <= rect.x + rect.width + tolerance &&
|
|
3668
|
+
point.y >= rect.y - tolerance &&
|
|
3669
|
+
point.y <= rect.y + rect.height + tolerance);
|
|
3670
|
+
};
|
|
3130
3671
|
LinkRoutingService.prototype.resolveEdgeSide = function (point, rect) {
|
|
3131
3672
|
var distances = [
|
|
3132
3673
|
{ side: 'left', value: Math.abs(point.x - rect.x) },
|
|
@@ -3171,8 +3712,8 @@ var MutationPipeline = /** @class */ (function () {
|
|
|
3171
3712
|
}());
|
|
3172
3713
|
|
|
3173
3714
|
var clampToRect = function (point, rect) { return ({
|
|
3174
|
-
x: clamp$
|
|
3175
|
-
y: clamp$
|
|
3715
|
+
x: clamp$2(point.x, rect.x, rect.x + rect.width),
|
|
3716
|
+
y: clamp$2(point.y, rect.y, rect.y + rect.height),
|
|
3176
3717
|
}); };
|
|
3177
3718
|
var snapToRectBorder = function (point, rect) {
|
|
3178
3719
|
var clamped = clampToRect(point, rect);
|
|
@@ -3309,9 +3850,7 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3309
3850
|
});
|
|
3310
3851
|
this.emitChange(allPatches);
|
|
3311
3852
|
};
|
|
3312
|
-
DiagramEngine.prototype.
|
|
3313
|
-
var _this = this;
|
|
3314
|
-
var oldWorld = this.model.getElementWorldPosition(id);
|
|
3853
|
+
DiagramEngine.prototype.resolveElementMovePosition = function (id, x, y) {
|
|
3315
3854
|
var snapped = this.snapper.snap({ x: x, y: y });
|
|
3316
3855
|
var element = this.model.getElement(id);
|
|
3317
3856
|
var position = snapped;
|
|
@@ -3351,14 +3890,46 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3351
3890
|
}
|
|
3352
3891
|
}
|
|
3353
3892
|
}
|
|
3893
|
+
return { element: element === null || element === void 0 ? void 0 : element.toData(), position: position };
|
|
3894
|
+
};
|
|
3895
|
+
DiagramEngine.prototype.buildChildMutationLayoutSteps = function (parentId, options) {
|
|
3896
|
+
var _this = this;
|
|
3897
|
+
var _a;
|
|
3898
|
+
if (!parentId) {
|
|
3899
|
+
return [function () { return _this.applyLayoutCascade(null); }];
|
|
3900
|
+
}
|
|
3901
|
+
var parent = this.model.getElement(parentId);
|
|
3902
|
+
if ((options === null || options === void 0 ? void 0 : options.preserveGridParentWidth) && ((_a = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _a === void 0 ? void 0 : _a.mode) === 'grid') {
|
|
3903
|
+
return [
|
|
3904
|
+
function () { return _this.applyLayoutForParent(parentId, { preserveParentWidth: true }); },
|
|
3905
|
+
function () { var _a; return _this.applyLayoutCascade((_a = parent.parentId) !== null && _a !== void 0 ? _a : null); },
|
|
3906
|
+
];
|
|
3907
|
+
}
|
|
3908
|
+
return [function () { return _this.applyLayoutCascade(parentId); }];
|
|
3909
|
+
};
|
|
3910
|
+
DiagramEngine.prototype.moveElementTo = function (id, x, y) {
|
|
3911
|
+
var _a;
|
|
3912
|
+
var oldWorld = this.model.getElementWorldPosition(id);
|
|
3913
|
+
var _b = this.resolveElementMovePosition(id, x, y), element = _b.element, position = _b.position;
|
|
3914
|
+
var beforeGridSlotState = (element === null || element === void 0 ? void 0 : element.parentId)
|
|
3915
|
+
? this.autoLayoutService.describeGridSlotState(element.parentId)
|
|
3916
|
+
: null;
|
|
3354
3917
|
var patches = this.commandQueue.run(createMoveElementCommand(id, position), this.model);
|
|
3918
|
+
if ((element === null || element === void 0 ? void 0 : element.parentId) && beforeGridSlotState) {
|
|
3919
|
+
var reorderedLayout = this.autoLayoutService.resolveGridReorderedLayout(element.parentId, beforeGridSlotState);
|
|
3920
|
+
if (reorderedLayout) {
|
|
3921
|
+
patches.push.apply(patches, this.commandQueue.run(createSetElementLayoutCommand(element.parentId, reorderedLayout), this.model));
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3355
3924
|
var movedPortIds = [];
|
|
3356
3925
|
if (element) {
|
|
3357
3926
|
movedPortIds.push.apply(movedPortIds, this.collectElementPortIds(element.id));
|
|
3358
3927
|
}
|
|
3359
3928
|
var allPatches = this.mutationPipeline.run({
|
|
3360
3929
|
basePatches: patches,
|
|
3361
|
-
layoutSteps:
|
|
3930
|
+
layoutSteps: this.buildChildMutationLayoutSteps((_a = element === null || element === void 0 ? void 0 : element.parentId) !== null && _a !== void 0 ? _a : null, {
|
|
3931
|
+
preserveGridParentWidth: true,
|
|
3932
|
+
}),
|
|
3362
3933
|
movedPortIds: movedPortIds,
|
|
3363
3934
|
});
|
|
3364
3935
|
this.emitChange(allPatches);
|
|
@@ -3375,24 +3946,106 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3375
3946
|
}
|
|
3376
3947
|
}
|
|
3377
3948
|
};
|
|
3949
|
+
DiagramEngine.prototype.resizeElementBounds = function (id, bounds) {
|
|
3950
|
+
var _this = this;
|
|
3951
|
+
var _a, _b, _c, _d;
|
|
3952
|
+
var _e = this.resolveElementMovePosition(id, bounds.x, bounds.y), element = _e.element, position = _e.position;
|
|
3953
|
+
if (!element)
|
|
3954
|
+
return;
|
|
3955
|
+
var oldSize = __assign({}, element.size);
|
|
3956
|
+
var preserveParentSize = Boolean(element.layout && element.layout.mode !== 'manual');
|
|
3957
|
+
var gridLayoutChange = this.resolveGridChildWidthResizeTopologyChange(element, bounds.width);
|
|
3958
|
+
var patches = [];
|
|
3959
|
+
if (gridLayoutChange) {
|
|
3960
|
+
patches.push.apply(patches, this.commandQueue.run(createSetElementLayoutCommand(gridLayoutChange.parentId, gridLayoutChange.afterLayout), this.model));
|
|
3961
|
+
}
|
|
3962
|
+
var positionChanged = element.position.x !== position.x || element.position.y !== position.y;
|
|
3963
|
+
if (positionChanged) {
|
|
3964
|
+
patches.push.apply(patches, this.commandQueue.run(createMoveElementCommand(id, position), this.model));
|
|
3965
|
+
}
|
|
3966
|
+
patches.push.apply(patches, this.commandQueue.run(createResizeElementCommand(id, { width: bounds.width, height: bounds.height }), this.model));
|
|
3967
|
+
var movedPortIds = this.collectElementPortIds(element.id);
|
|
3968
|
+
var layoutSteps = [function () { return _this.applyLayoutForParent(id, { preserveParentSize: preserveParentSize }); }];
|
|
3969
|
+
if (gridLayoutChange && element.parentId) {
|
|
3970
|
+
var grandParentId_1 = (_b = (_a = this.model.getElement(element.parentId)) === null || _a === void 0 ? void 0 : _a.parentId) !== null && _b !== void 0 ? _b : null;
|
|
3971
|
+
layoutSteps.push(function () { var _a; return _this.applyLayoutForParent((_a = element.parentId) !== null && _a !== void 0 ? _a : '', { preserveParentWidth: true }); });
|
|
3972
|
+
if (grandParentId_1) {
|
|
3973
|
+
layoutSteps.push(function () { return _this.applyLayoutCascade(grandParentId_1); });
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
else {
|
|
3977
|
+
layoutSteps.push.apply(layoutSteps, this.buildChildMutationLayoutSteps((_c = element.parentId) !== null && _c !== void 0 ? _c : null, {
|
|
3978
|
+
preserveGridParentWidth: true,
|
|
3979
|
+
}));
|
|
3980
|
+
}
|
|
3981
|
+
var allPatches = this.mutationPipeline.run({
|
|
3982
|
+
basePatches: patches,
|
|
3983
|
+
layoutSteps: layoutSteps,
|
|
3984
|
+
movedPortIds: movedPortIds,
|
|
3985
|
+
});
|
|
3986
|
+
if (gridLayoutChange) {
|
|
3987
|
+
this.events.emit('gridLayoutChanged', {
|
|
3988
|
+
parentId: gridLayoutChange.parentId,
|
|
3989
|
+
triggerChildId: gridLayoutChange.triggerChildId,
|
|
3990
|
+
reason: gridLayoutChange.reason,
|
|
3991
|
+
beforeRows: gridLayoutChange.beforeRows,
|
|
3992
|
+
afterRows: gridLayoutChange.afterRows,
|
|
3993
|
+
beforeGridTemplate: gridLayoutChange.beforeGridTemplate,
|
|
3994
|
+
afterGridTemplate: gridLayoutChange.afterGridTemplate,
|
|
3995
|
+
});
|
|
3996
|
+
}
|
|
3997
|
+
this.emitChange(allPatches);
|
|
3998
|
+
var newSize = (_d = this.model.getElement(id)) === null || _d === void 0 ? void 0 : _d.size;
|
|
3999
|
+
if (newSize && (oldSize.width !== newSize.width || oldSize.height !== newSize.height)) {
|
|
4000
|
+
this.events.emit('elementResized', { elementId: id, oldSize: oldSize, newSize: __assign({}, newSize) });
|
|
4001
|
+
}
|
|
4002
|
+
};
|
|
3378
4003
|
DiagramEngine.prototype.resizeElement = function (id, width, height) {
|
|
3379
4004
|
var _this = this;
|
|
3380
|
-
var _a;
|
|
4005
|
+
var _a, _b, _c, _d;
|
|
3381
4006
|
var element = this.model.getElement(id);
|
|
3382
4007
|
var oldSize = element === null || element === void 0 ? void 0 : element.size;
|
|
3383
4008
|
var preserveParentSize = Boolean((element === null || element === void 0 ? void 0 : element.layout) && element.layout.mode !== 'manual');
|
|
3384
|
-
var
|
|
4009
|
+
var gridLayoutChange = element
|
|
4010
|
+
? this.resolveGridChildWidthResizeTopologyChange(element, width)
|
|
4011
|
+
: null;
|
|
4012
|
+
var patches = [];
|
|
4013
|
+
if (gridLayoutChange) {
|
|
4014
|
+
patches.push.apply(patches, this.commandQueue.run(createSetElementLayoutCommand(gridLayoutChange.parentId, gridLayoutChange.afterLayout), this.model));
|
|
4015
|
+
}
|
|
4016
|
+
patches.push.apply(patches, this.commandQueue.run(createResizeElementCommand(id, { width: width, height: height }), this.model));
|
|
3385
4017
|
var movedPortIds = element ? this.collectElementPortIds(element.id) : [];
|
|
4018
|
+
var layoutSteps = [function () { return _this.applyLayoutForParent(id, { preserveParentSize: preserveParentSize }); }];
|
|
4019
|
+
if (gridLayoutChange && (element === null || element === void 0 ? void 0 : element.parentId)) {
|
|
4020
|
+
var grandParentId_2 = (_b = (_a = this.model.getElement(element.parentId)) === null || _a === void 0 ? void 0 : _a.parentId) !== null && _b !== void 0 ? _b : null;
|
|
4021
|
+
layoutSteps.push(function () { var _a; return _this.applyLayoutForParent((_a = element.parentId) !== null && _a !== void 0 ? _a : '', { preserveParentWidth: true }); });
|
|
4022
|
+
if (grandParentId_2) {
|
|
4023
|
+
layoutSteps.push(function () { return _this.applyLayoutCascade(grandParentId_2); });
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
else {
|
|
4027
|
+
layoutSteps.push.apply(layoutSteps, this.buildChildMutationLayoutSteps((_c = element === null || element === void 0 ? void 0 : element.parentId) !== null && _c !== void 0 ? _c : null, {
|
|
4028
|
+
preserveGridParentWidth: true,
|
|
4029
|
+
}));
|
|
4030
|
+
}
|
|
3386
4031
|
var allPatches = this.mutationPipeline.run({
|
|
3387
4032
|
basePatches: patches,
|
|
3388
|
-
layoutSteps:
|
|
3389
|
-
function () { return _this.applyLayoutForParent(id, { preserveParentSize: preserveParentSize }); },
|
|
3390
|
-
function () { var _a; return _this.applyLayoutCascade((_a = element === null || element === void 0 ? void 0 : element.parentId) !== null && _a !== void 0 ? _a : null); },
|
|
3391
|
-
],
|
|
4033
|
+
layoutSteps: layoutSteps,
|
|
3392
4034
|
movedPortIds: movedPortIds,
|
|
3393
4035
|
});
|
|
4036
|
+
if (gridLayoutChange) {
|
|
4037
|
+
this.events.emit('gridLayoutChanged', {
|
|
4038
|
+
parentId: gridLayoutChange.parentId,
|
|
4039
|
+
triggerChildId: gridLayoutChange.triggerChildId,
|
|
4040
|
+
reason: gridLayoutChange.reason,
|
|
4041
|
+
beforeRows: gridLayoutChange.beforeRows,
|
|
4042
|
+
afterRows: gridLayoutChange.afterRows,
|
|
4043
|
+
beforeGridTemplate: gridLayoutChange.beforeGridTemplate,
|
|
4044
|
+
afterGridTemplate: gridLayoutChange.afterGridTemplate,
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
3394
4047
|
this.emitChange(allPatches);
|
|
3395
|
-
var newSize = (
|
|
4048
|
+
var newSize = (_d = this.model.getElement(id)) === null || _d === void 0 ? void 0 : _d.size;
|
|
3396
4049
|
if (oldSize && newSize && (oldSize.width !== newSize.width || oldSize.height !== newSize.height)) {
|
|
3397
4050
|
this.events.emit('elementResized', { elementId: id, oldSize: __assign({}, oldSize), newSize: __assign({}, newSize) });
|
|
3398
4051
|
}
|
|
@@ -3697,6 +4350,7 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3697
4350
|
return baseRotation + instanceRotation;
|
|
3698
4351
|
};
|
|
3699
4352
|
DiagramEngine.prototype.normalizeElementResize = function (id, proposal, handle, minSize) {
|
|
4353
|
+
var _a, _b;
|
|
3700
4354
|
if (minSize === void 0) { minSize = 20; }
|
|
3701
4355
|
var clamped = {
|
|
3702
4356
|
x: proposal.x,
|
|
@@ -3708,13 +4362,19 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3708
4362
|
if (!element)
|
|
3709
4363
|
return clamped;
|
|
3710
4364
|
var lockHorizontalResize = this.shouldLockAutoLayoutChildHorizontalResize(element);
|
|
4365
|
+
var currentWorldPosition = this.model.getElementWorldPosition(id);
|
|
4366
|
+
var anchorGridWidthToLeft = this.shouldAnchorAutoLayoutGridChildWidthToLeft(element);
|
|
4367
|
+
var freezeGridLeftEdge = anchorGridWidthToLeft || lockHorizontalResize;
|
|
4368
|
+
var snappedGridWidth = this.resolveSnappedGridChildWidth(element, clamped.width);
|
|
3711
4369
|
var shape = this.shapeRegistry.get(element.shapeId);
|
|
3712
4370
|
if (!(shape === null || shape === void 0 ? void 0 : shape.normalizeResize)) {
|
|
3713
|
-
if (!lockHorizontalResize)
|
|
4371
|
+
if (!lockHorizontalResize && !anchorGridWidthToLeft)
|
|
3714
4372
|
return clamped;
|
|
3715
|
-
var width_1 =
|
|
3716
|
-
|
|
3717
|
-
|
|
4373
|
+
var width_1 = lockHorizontalResize
|
|
4374
|
+
? Math.max(minSize, element.size.width)
|
|
4375
|
+
: Math.max(minSize, snappedGridWidth);
|
|
4376
|
+
var x_1 = freezeGridLeftEdge ? ((_a = currentWorldPosition === null || currentWorldPosition === void 0 ? void 0 : currentWorldPosition.x) !== null && _a !== void 0 ? _a : clamped.x) : clamped.x;
|
|
4377
|
+
if (!freezeGridLeftEdge && (handle === 'sw' || handle === 'nw')) {
|
|
3718
4378
|
x_1 += clamped.width - width_1;
|
|
3719
4379
|
}
|
|
3720
4380
|
return { x: x_1, y: clamped.y, width: width_1, height: clamped.height };
|
|
@@ -3725,11 +4385,15 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3725
4385
|
minSize: minSize,
|
|
3726
4386
|
proposal: { width: clamped.width, height: clamped.height },
|
|
3727
4387
|
});
|
|
3728
|
-
var width = lockHorizontalResize
|
|
4388
|
+
var width = lockHorizontalResize
|
|
4389
|
+
? Math.max(minSize, element.size.width)
|
|
4390
|
+
: anchorGridWidthToLeft
|
|
4391
|
+
? Math.max(minSize, snappedGridWidth)
|
|
4392
|
+
: Math.max(minSize, normalized.width);
|
|
3729
4393
|
var height = Math.max(minSize, normalized.height);
|
|
3730
|
-
var x = clamped.x;
|
|
4394
|
+
var x = freezeGridLeftEdge ? ((_b = currentWorldPosition === null || currentWorldPosition === void 0 ? void 0 : currentWorldPosition.x) !== null && _b !== void 0 ? _b : clamped.x) : clamped.x;
|
|
3731
4395
|
var y = clamped.y;
|
|
3732
|
-
if (handle === 'sw' || handle === 'nw') {
|
|
4396
|
+
if (!freezeGridLeftEdge && (handle === 'sw' || handle === 'nw')) {
|
|
3733
4397
|
x += clamped.width - width;
|
|
3734
4398
|
}
|
|
3735
4399
|
if (handle === 'ne' || handle === 'nw') {
|
|
@@ -3747,7 +4411,64 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
3747
4411
|
if (element.layout && element.layout.mode !== 'manual')
|
|
3748
4412
|
return false;
|
|
3749
4413
|
var parent = this.model.getElement(parentId);
|
|
3750
|
-
|
|
4414
|
+
if (((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid')
|
|
4415
|
+
return false;
|
|
4416
|
+
return !Boolean(parent.layout.gridChildWidthResizeEnabled);
|
|
4417
|
+
};
|
|
4418
|
+
DiagramEngine.prototype.shouldAnchorAutoLayoutGridChildWidthToLeft = function (element) {
|
|
4419
|
+
var _a, _b;
|
|
4420
|
+
var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
|
|
4421
|
+
if (!parentId)
|
|
4422
|
+
return false;
|
|
4423
|
+
if (this.model.getChildren(element.id).length > 0)
|
|
4424
|
+
return false;
|
|
4425
|
+
if (element.layout && element.layout.mode !== 'manual')
|
|
4426
|
+
return false;
|
|
4427
|
+
var parent = this.model.getElement(parentId);
|
|
4428
|
+
return Boolean(((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) === 'grid' && parent.layout.gridChildWidthResizeEnabled);
|
|
4429
|
+
};
|
|
4430
|
+
DiagramEngine.prototype.shouldRestrictAutoLayoutChildRightGrowth = function (element, handle, requestedWidth) {
|
|
4431
|
+
return false;
|
|
4432
|
+
};
|
|
4433
|
+
DiagramEngine.prototype.resolveSnappedGridChildWidth = function (element, requestedWidth) {
|
|
4434
|
+
var _a;
|
|
4435
|
+
var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
|
|
4436
|
+
if (!parentId)
|
|
4437
|
+
return requestedWidth;
|
|
4438
|
+
if (this.model.getChildren(element.id).length > 0)
|
|
4439
|
+
return requestedWidth;
|
|
4440
|
+
if (element.layout && element.layout.mode !== 'manual')
|
|
4441
|
+
return requestedWidth;
|
|
4442
|
+
var parent = this.model.getElement(parentId);
|
|
4443
|
+
if (!(parent === null || parent === void 0 ? void 0 : parent.layout) || parent.layout.mode !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
|
|
4444
|
+
return requestedWidth;
|
|
4445
|
+
return this.autoLayoutService.snapGridChildRequestedWidth(parentId, element.id, requestedWidth);
|
|
4446
|
+
};
|
|
4447
|
+
DiagramEngine.prototype.resolveGridChildWidthResizeTopologyChange = function (element, requestedWidth) {
|
|
4448
|
+
var _a, _b, _c;
|
|
4449
|
+
var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
|
|
4450
|
+
if (!parentId)
|
|
4451
|
+
return null;
|
|
4452
|
+
if (this.model.getChildren(element.id).length > 0)
|
|
4453
|
+
return null;
|
|
4454
|
+
if (element.layout && element.layout.mode !== 'manual')
|
|
4455
|
+
return null;
|
|
4456
|
+
var parent = this.model.getElement(parentId);
|
|
4457
|
+
if (!parent || ((_b = parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
|
|
4458
|
+
return null;
|
|
4459
|
+
var topologyChange = this.autoLayoutService.resolveGridChildResizeTopologyChange(parentId, element.id, requestedWidth);
|
|
4460
|
+
if (!topologyChange)
|
|
4461
|
+
return null;
|
|
4462
|
+
return {
|
|
4463
|
+
parentId: topologyChange.parentId,
|
|
4464
|
+
triggerChildId: topologyChange.triggerChildId,
|
|
4465
|
+
reason: topologyChange.reason,
|
|
4466
|
+
beforeRows: topologyChange.beforeRows,
|
|
4467
|
+
afterRows: topologyChange.afterRows,
|
|
4468
|
+
beforeGridTemplate: parent.layout.gridTemplate ? __spreadArray([], parent.layout.gridTemplate, true) : undefined,
|
|
4469
|
+
afterGridTemplate: __spreadArray([], ((_c = topologyChange.nextLayout.gridTemplate) !== null && _c !== void 0 ? _c : []), true),
|
|
4470
|
+
afterLayout: topologyChange.nextLayout,
|
|
4471
|
+
};
|
|
3751
4472
|
};
|
|
3752
4473
|
DiagramEngine.prototype.getPortWorldPosition = function (id) {
|
|
3753
4474
|
return this.model.getPortWorldPosition(id);
|
|
@@ -4030,8 +4751,8 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
4030
4751
|
}
|
|
4031
4752
|
if (style === null || style === void 0 ? void 0 : style.moveBounds) {
|
|
4032
4753
|
var bounds = style.moveBounds;
|
|
4033
|
-
position.x = clamp$
|
|
4034
|
-
position.y = clamp$
|
|
4754
|
+
position.x = clamp$2(position.x, bounds.x, bounds.x + bounds.width);
|
|
4755
|
+
position.y = clamp$2(position.y, bounds.y, bounds.y + bounds.height);
|
|
4035
4756
|
}
|
|
4036
4757
|
if (effectiveMoveMode === 'border') {
|
|
4037
4758
|
var resolvedBorder = this.resolveBorderPositionWithLimits(position, element, (_e = element.portMovement) === null || _e === void 0 ? void 0 : _e.positionLimits);
|
|
@@ -5952,6 +6673,10 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
5952
6673
|
return;
|
|
5953
6674
|
}
|
|
5954
6675
|
if (hit.type === 'text') {
|
|
6676
|
+
if (!_this.isTextMovable(hit.id)) {
|
|
6677
|
+
_this.setCursor('default');
|
|
6678
|
+
return;
|
|
6679
|
+
}
|
|
5955
6680
|
var base = _this.engine.getTextWorldPosition(hit.id);
|
|
5956
6681
|
if (base) {
|
|
5957
6682
|
_this.dragState = {
|
|
@@ -6341,6 +7066,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
6341
7066
|
var hit = _this.resolveHit(point);
|
|
6342
7067
|
if (!hit || hit.type !== 'text')
|
|
6343
7068
|
return;
|
|
7069
|
+
if (!_this.isTextEditable(hit.id))
|
|
7070
|
+
return;
|
|
6344
7071
|
_this.startTextEdit(hit.id);
|
|
6345
7072
|
};
|
|
6346
7073
|
this.stage.on('dblclick dbltap', doubleClick);
|
|
@@ -7493,8 +8220,12 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
7493
8220
|
y: normalized.y + normalized.height / 2,
|
|
7494
8221
|
}
|
|
7495
8222
|
: { x: normalized.x, y: normalized.y };
|
|
7496
|
-
this.engine.
|
|
7497
|
-
|
|
8223
|
+
this.engine.resizeElementBounds(state.elementId, {
|
|
8224
|
+
x: moveTarget.x,
|
|
8225
|
+
y: moveTarget.y,
|
|
8226
|
+
width: normalized.width,
|
|
8227
|
+
height: normalized.height,
|
|
8228
|
+
});
|
|
7498
8229
|
this.updateSelectionOverlays();
|
|
7499
8230
|
};
|
|
7500
8231
|
KonvaInteraction.prototype.parseResizeHandle = function (id) {
|
|
@@ -7830,6 +8561,14 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
7830
8561
|
KonvaInteraction.prototype.getTextById = function (id) {
|
|
7831
8562
|
return this.engine.getState().texts.find(function (text) { return text.id === id; });
|
|
7832
8563
|
};
|
|
8564
|
+
KonvaInteraction.prototype.isTextMovable = function (id) {
|
|
8565
|
+
var _a, _b;
|
|
8566
|
+
return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.movable) !== false;
|
|
8567
|
+
};
|
|
8568
|
+
KonvaInteraction.prototype.isTextEditable = function (id) {
|
|
8569
|
+
var _a, _b;
|
|
8570
|
+
return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.editable) !== false;
|
|
8571
|
+
};
|
|
7833
8572
|
KonvaInteraction.prototype.getLinkById = function (id) {
|
|
7834
8573
|
return this.engine.getState().links.find(function (link) { return link.id === id; });
|
|
7835
8574
|
};
|
|
@@ -8512,6 +9251,24 @@ var hasBounds = function (bounds) {
|
|
|
8512
9251
|
bounds.maxX >= bounds.minX &&
|
|
8513
9252
|
bounds.maxY >= bounds.minY;
|
|
8514
9253
|
};
|
|
9254
|
+
var DEFAULT_VIEWPORT_FIT_PADDING = 24;
|
|
9255
|
+
var DEFAULT_VIEWPORT_FIT_MIN_ZOOM = 0.2;
|
|
9256
|
+
var DEFAULT_VIEWPORT_FIT_MAX_ZOOM = 3;
|
|
9257
|
+
var resolveViewportFitOptions = function (options) {
|
|
9258
|
+
var padding = typeof (options === null || options === void 0 ? void 0 : options.padding) === 'number' && Number.isFinite(options.padding)
|
|
9259
|
+
? Math.max(0, options.padding)
|
|
9260
|
+
: DEFAULT_VIEWPORT_FIT_PADDING;
|
|
9261
|
+
var requestedMinZoom = typeof (options === null || options === void 0 ? void 0 : options.minZoom) === 'number' && Number.isFinite(options.minZoom)
|
|
9262
|
+
? Math.max(0.000001, options.minZoom)
|
|
9263
|
+
: DEFAULT_VIEWPORT_FIT_MIN_ZOOM;
|
|
9264
|
+
var requestedMaxZoom = typeof (options === null || options === void 0 ? void 0 : options.maxZoom) === 'number' && Number.isFinite(options.maxZoom)
|
|
9265
|
+
? Math.max(0.000001, options.maxZoom)
|
|
9266
|
+
: DEFAULT_VIEWPORT_FIT_MAX_ZOOM;
|
|
9267
|
+
var minZoom = Math.min(requestedMinZoom, requestedMaxZoom);
|
|
9268
|
+
var maxZoom = Math.max(requestedMinZoom, requestedMaxZoom);
|
|
9269
|
+
return { padding: padding, minZoom: minZoom, maxZoom: maxZoom };
|
|
9270
|
+
};
|
|
9271
|
+
var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
8515
9272
|
var resolveStateWorldBounds = function (state) {
|
|
8516
9273
|
var bounds = createBounds();
|
|
8517
9274
|
state.elements.forEach(function (element) {
|
|
@@ -8548,6 +9305,34 @@ var resolveStateWorldBounds = function (state) {
|
|
|
8548
9305
|
});
|
|
8549
9306
|
return hasBounds(bounds) ? bounds : null;
|
|
8550
9307
|
};
|
|
9308
|
+
var resolveElementWorldBounds = function (state) {
|
|
9309
|
+
var bounds = createBounds();
|
|
9310
|
+
state.elements.forEach(function (element) {
|
|
9311
|
+
includeRect(bounds, element.position.x, element.position.y, element.size.width, element.size.height);
|
|
9312
|
+
});
|
|
9313
|
+
return hasBounds(bounds) ? bounds : null;
|
|
9314
|
+
};
|
|
9315
|
+
var resolveViewportFitTransform = function (state, viewportSize, options) {
|
|
9316
|
+
var bounds = resolveElementWorldBounds(state);
|
|
9317
|
+
if (!bounds)
|
|
9318
|
+
return null;
|
|
9319
|
+
var safeWidth = Math.max(1, viewportSize.width);
|
|
9320
|
+
var safeHeight = Math.max(1, viewportSize.height);
|
|
9321
|
+
var _a = resolveViewportFitOptions(options), padding = _a.padding, minZoom = _a.minZoom, maxZoom = _a.maxZoom;
|
|
9322
|
+
var availableWidth = Math.max(1, safeWidth - padding * 2);
|
|
9323
|
+
var availableHeight = Math.max(1, safeHeight - padding * 2);
|
|
9324
|
+
var contentWidth = Math.max(1, bounds.maxX - bounds.minX);
|
|
9325
|
+
var contentHeight = Math.max(1, bounds.maxY - bounds.minY);
|
|
9326
|
+
var rawZoom = Math.min(availableWidth / contentWidth, availableHeight / contentHeight);
|
|
9327
|
+
var zoom = clamp(rawZoom, minZoom, maxZoom);
|
|
9328
|
+
var centerX = (bounds.minX + bounds.maxX) / 2;
|
|
9329
|
+
var centerY = (bounds.minY + bounds.maxY) / 2;
|
|
9330
|
+
var pan = {
|
|
9331
|
+
x: safeWidth / 2 - centerX * zoom,
|
|
9332
|
+
y: safeHeight / 2 - centerY * zoom,
|
|
9333
|
+
};
|
|
9334
|
+
return { pan: pan, zoom: zoom };
|
|
9335
|
+
};
|
|
8551
9336
|
var resolveFitToContentPadding = function (fitToContent) {
|
|
8552
9337
|
if (typeof fitToContent === 'object' && typeof fitToContent.padding === 'number') {
|
|
8553
9338
|
return Math.max(0, fitToContent.padding);
|
|
@@ -8623,10 +9408,12 @@ var registerSimpleShapes = function (registry, shapes, isPort) {
|
|
|
8623
9408
|
var createDiagramEditor = function (config) {
|
|
8624
9409
|
var _a, _b;
|
|
8625
9410
|
var Konva = getKonva();
|
|
9411
|
+
var stageWidth = (_a = config.width) !== null && _a !== void 0 ? _a : 900;
|
|
9412
|
+
var stageHeight = (_b = config.height) !== null && _b !== void 0 ? _b : 560;
|
|
8626
9413
|
var stage = new Konva.Stage({
|
|
8627
9414
|
container: config.container,
|
|
8628
|
-
width:
|
|
8629
|
-
height:
|
|
9415
|
+
width: stageWidth,
|
|
9416
|
+
height: stageHeight,
|
|
8630
9417
|
});
|
|
8631
9418
|
var stageContainer = typeof stage.container === 'function' ? stage.container() : stage.container;
|
|
8632
9419
|
if (stageContainer && stageContainer.tabIndex < 0) {
|
|
@@ -8773,6 +9560,12 @@ var createDiagramEditor = function (config) {
|
|
|
8773
9560
|
completeLinkToPort: function (targetPortId) { return interaction.completeLinkToPort(targetPortId); },
|
|
8774
9561
|
completeLinkToElement: function (targetElementId, pointer) { return interaction.completeLinkToElement(targetElementId, pointer); },
|
|
8775
9562
|
cancelLink: function () { return interaction.cancelLink(); },
|
|
9563
|
+
zoomToFitElements: function (options) {
|
|
9564
|
+
var transform = resolveViewportFitTransform(engine.getState(), { width: stageWidth, height: stageHeight }, options);
|
|
9565
|
+
if (!transform)
|
|
9566
|
+
return;
|
|
9567
|
+
engine.setViewport(transform.pan, transform.zoom);
|
|
9568
|
+
},
|
|
8776
9569
|
exportImage: function (options) {
|
|
8777
9570
|
engine.render();
|
|
8778
9571
|
if (typeof stage.toDataURL !== 'function') {
|
|
@@ -8799,6 +9592,8 @@ var createDiagramEditor = function (config) {
|
|
|
8799
9592
|
return stage.toDataURL(__assign(__assign({}, baseOptions), { x: cropX, y: cropY, width: cropWidth, height: cropHeight }));
|
|
8800
9593
|
},
|
|
8801
9594
|
resize: function (width, height) {
|
|
9595
|
+
stageWidth = width;
|
|
9596
|
+
stageHeight = height;
|
|
8802
9597
|
stage.width(width);
|
|
8803
9598
|
stage.height(height);
|
|
8804
9599
|
engine.render();
|