orcasvn-react-diagrams 0.2.8 → 0.2.10
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 +22 -0
- package/README.md +8 -6
- package/ai/api-contract.json +18 -0
- package/ai/invariants.json +8 -0
- package/ai/manifest.json +1 -1
- package/dist/cjs/examples.js +468 -24
- package/dist/cjs/index.js +305 -24
- package/dist/cjs/types/api/types.d.ts +2 -0
- package/dist/cjs/types/displaybox/demos/elementVisibilitySelectionDemo.d.ts +4 -0
- package/dist/cjs/types/engine/DiagramEngine.d.ts +8 -0
- package/dist/cjs/types/models/DiagramModel.d.ts +5 -0
- package/dist/cjs/types/models/ElementModel.d.ts +2 -0
- package/dist/esm/examples.js +468 -24
- package/dist/esm/examples.js.map +1 -1
- package/dist/esm/index.js +305 -24
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api/types.d.ts +2 -0
- package/dist/esm/types/displaybox/demos/elementVisibilitySelectionDemo.d.ts +4 -0
- package/dist/esm/types/engine/DiagramEngine.d.ts +8 -0
- package/dist/esm/types/models/DiagramModel.d.ts +5 -0
- package/dist/esm/types/models/ElementModel.d.ts +2 -0
- package/dist/examples.d.ts +2 -0
- package/dist/index.d.ts +9 -0
- package/docs/API_CONTRACT.md +19 -1
- package/docs/CAPABILITIES.md +1 -0
- package/docs/COMMANDS_EVENTS.md +3 -1
- package/docs/DOCUMENTATION_WORKFLOW.md +3 -1
- package/docs/INTEGRATION_PLAYBOOK.md +1 -0
- package/docs/PORTING_CHECKLIST.md +1 -0
- package/docs/STATE_INVARIANTS.md +9 -1
- package/package.json +1 -1
- package/src/displaybox/demos/elementVisibilitySelectionDemo.ts +163 -0
- package/src/displaybox/demos/index.tsx +14 -7
package/dist/cjs/index.js
CHANGED
|
@@ -87,6 +87,8 @@ var ElementModel = /** @class */ (function () {
|
|
|
87
87
|
this.style = data.style;
|
|
88
88
|
this.portIds = data.portIds ? __spreadArray([], data.portIds, true) : [];
|
|
89
89
|
this.textIds = data.textIds ? __spreadArray([], data.textIds, true) : [];
|
|
90
|
+
this.visible = data.visible;
|
|
91
|
+
this.selectable = data.selectable;
|
|
90
92
|
this.parentId = (_a = data.parentId) !== null && _a !== void 0 ? _a : null;
|
|
91
93
|
this.moveMode = data.moveMode;
|
|
92
94
|
this.anchorCenter = data.anchorCenter;
|
|
@@ -125,6 +127,8 @@ var ElementModel = /** @class */ (function () {
|
|
|
125
127
|
style: this.style,
|
|
126
128
|
portIds: __spreadArray([], this.portIds, true),
|
|
127
129
|
textIds: __spreadArray([], this.textIds, true),
|
|
130
|
+
visible: this.visible,
|
|
131
|
+
selectable: this.selectable,
|
|
128
132
|
parentId: this.parentId,
|
|
129
133
|
moveMode: this.moveMode,
|
|
130
134
|
anchorCenter: this.anchorCenter,
|
|
@@ -528,6 +532,18 @@ var DiagramModel = /** @class */ (function () {
|
|
|
528
532
|
DiagramModel.prototype.getElement = function (id) {
|
|
529
533
|
return this.elements.get(id);
|
|
530
534
|
};
|
|
535
|
+
DiagramModel.prototype.isElementVisible = function (id) {
|
|
536
|
+
var element = this.elements.get(id);
|
|
537
|
+
if (!element)
|
|
538
|
+
return false;
|
|
539
|
+
return element.visible !== false;
|
|
540
|
+
};
|
|
541
|
+
DiagramModel.prototype.isElementSelectable = function (id) {
|
|
542
|
+
var element = this.elements.get(id);
|
|
543
|
+
if (!element)
|
|
544
|
+
return false;
|
|
545
|
+
return this.isElementVisible(id) && element.selectable !== false;
|
|
546
|
+
};
|
|
531
547
|
DiagramModel.prototype.setElementLayout = function (id, layout) {
|
|
532
548
|
var element = this.elements.get(id);
|
|
533
549
|
if (!element)
|
|
@@ -546,6 +562,12 @@ var DiagramModel = /** @class */ (function () {
|
|
|
546
562
|
DiagramModel.prototype.getPort = function (id) {
|
|
547
563
|
return this.ports.get(id);
|
|
548
564
|
};
|
|
565
|
+
DiagramModel.prototype.isPortVisible = function (id) {
|
|
566
|
+
var port = this.ports.get(id);
|
|
567
|
+
if (!port)
|
|
568
|
+
return false;
|
|
569
|
+
return this.isElementVisible(port.elementId);
|
|
570
|
+
};
|
|
549
571
|
DiagramModel.prototype.getPortWorldPosition = function (id) {
|
|
550
572
|
var port = this.ports.get(id);
|
|
551
573
|
if (!port)
|
|
@@ -561,6 +583,16 @@ var DiagramModel = /** @class */ (function () {
|
|
|
561
583
|
DiagramModel.prototype.getLink = function (id) {
|
|
562
584
|
return this.links.get(id);
|
|
563
585
|
};
|
|
586
|
+
DiagramModel.prototype.isLinkVisible = function (id) {
|
|
587
|
+
var link = this.links.get(id);
|
|
588
|
+
if (!link)
|
|
589
|
+
return false;
|
|
590
|
+
var sourcePort = this.ports.get(link.sourcePortId);
|
|
591
|
+
var targetPort = this.ports.get(link.targetPortId);
|
|
592
|
+
var sourceVisible = sourcePort ? this.isPortVisible(sourcePort.id) : true;
|
|
593
|
+
var targetVisible = targetPort ? this.isPortVisible(targetPort.id) : true;
|
|
594
|
+
return sourceVisible && targetVisible;
|
|
595
|
+
};
|
|
564
596
|
DiagramModel.prototype.getLinkMidpoint = function (id) {
|
|
565
597
|
var link = this.links.get(id);
|
|
566
598
|
if (!link)
|
|
@@ -570,6 +602,23 @@ var DiagramModel = /** @class */ (function () {
|
|
|
570
602
|
DiagramModel.prototype.getText = function (id) {
|
|
571
603
|
return this.texts.get(id);
|
|
572
604
|
};
|
|
605
|
+
DiagramModel.prototype.isTextVisible = function (id) {
|
|
606
|
+
var text = this.texts.get(id);
|
|
607
|
+
if (!text)
|
|
608
|
+
return false;
|
|
609
|
+
if (!text.ownerId)
|
|
610
|
+
return true;
|
|
611
|
+
if (this.elements.has(text.ownerId)) {
|
|
612
|
+
return this.isElementVisible(text.ownerId);
|
|
613
|
+
}
|
|
614
|
+
if (this.ports.has(text.ownerId)) {
|
|
615
|
+
return this.isPortVisible(text.ownerId);
|
|
616
|
+
}
|
|
617
|
+
if (this.links.has(text.ownerId)) {
|
|
618
|
+
return this.isLinkVisible(text.ownerId);
|
|
619
|
+
}
|
|
620
|
+
return true;
|
|
621
|
+
};
|
|
573
622
|
DiagramModel.prototype.getTextWorldPosition = function (id) {
|
|
574
623
|
var text = this.texts.get(id);
|
|
575
624
|
if (!text)
|
|
@@ -4332,16 +4381,38 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
4332
4381
|
this.emitEntityDeletionEvents(removal.removed);
|
|
4333
4382
|
};
|
|
4334
4383
|
DiagramEngine.prototype.setSelection = function (ids) {
|
|
4335
|
-
this.selection.set(ids);
|
|
4384
|
+
this.selection.set(this.normalizeSelectionIds(ids));
|
|
4336
4385
|
this.emitSelection();
|
|
4337
4386
|
};
|
|
4338
4387
|
DiagramEngine.prototype.toggleSelection = function (id) {
|
|
4339
|
-
this.selection.
|
|
4388
|
+
var current = new Set(this.selection.get());
|
|
4389
|
+
if (current.has(id)) {
|
|
4390
|
+
current.delete(id);
|
|
4391
|
+
}
|
|
4392
|
+
else if (this.isSelectableId(id)) {
|
|
4393
|
+
current.add(id);
|
|
4394
|
+
}
|
|
4395
|
+
this.selection.set(Array.from(current));
|
|
4340
4396
|
this.emitSelection();
|
|
4341
4397
|
};
|
|
4342
4398
|
DiagramEngine.prototype.getSelection = function () {
|
|
4343
4399
|
return this.selection.get();
|
|
4344
4400
|
};
|
|
4401
|
+
DiagramEngine.prototype.isElementVisible = function (id) {
|
|
4402
|
+
return this.model.isElementVisible(id);
|
|
4403
|
+
};
|
|
4404
|
+
DiagramEngine.prototype.isElementSelectable = function (id) {
|
|
4405
|
+
return this.model.isElementSelectable(id);
|
|
4406
|
+
};
|
|
4407
|
+
DiagramEngine.prototype.isPortVisible = function (id) {
|
|
4408
|
+
return this.model.isPortVisible(id);
|
|
4409
|
+
};
|
|
4410
|
+
DiagramEngine.prototype.isLinkVisible = function (id) {
|
|
4411
|
+
return this.model.isLinkVisible(id);
|
|
4412
|
+
};
|
|
4413
|
+
DiagramEngine.prototype.isTextVisible = function (id) {
|
|
4414
|
+
return this.model.isTextVisible(id);
|
|
4415
|
+
};
|
|
4345
4416
|
DiagramEngine.prototype.getElementWorldPosition = function (id) {
|
|
4346
4417
|
return this.model.getElementWorldPosition(id);
|
|
4347
4418
|
};
|
|
@@ -4603,11 +4674,15 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
4603
4674
|
var _this = this;
|
|
4604
4675
|
var _a;
|
|
4605
4676
|
var allPatches = this.appendTextLayoutPatches(patches, (_a = options === null || options === void 0 ? void 0 : options.emitTextUpdated) !== null && _a !== void 0 ? _a : true);
|
|
4677
|
+
var selectionChanged = this.syncSelectionToPolicies();
|
|
4606
4678
|
var state = this.model.toState();
|
|
4607
4679
|
this.events.emit('change', { patches: allPatches, state: state });
|
|
4608
|
-
if ((options === null || options === void 0 ? void 0 : options.render)
|
|
4609
|
-
return;
|
|
4610
|
-
|
|
4680
|
+
if ((options === null || options === void 0 ? void 0 : options.render) !== false) {
|
|
4681
|
+
this.scheduler.requestRender(function () { return _this.renderer.render(_this.model); });
|
|
4682
|
+
}
|
|
4683
|
+
if (selectionChanged) {
|
|
4684
|
+
this.emitSelection();
|
|
4685
|
+
}
|
|
4611
4686
|
};
|
|
4612
4687
|
DiagramEngine.prototype.appendTextLayoutPatches = function (patches, emitTextUpdated) {
|
|
4613
4688
|
var _this = this;
|
|
@@ -5053,6 +5128,31 @@ var DiagramEngine = /** @class */ (function () {
|
|
|
5053
5128
|
});
|
|
5054
5129
|
this.renderer.renderSelection(selectedIds);
|
|
5055
5130
|
};
|
|
5131
|
+
DiagramEngine.prototype.normalizeSelectionIds = function (ids) {
|
|
5132
|
+
var _this = this;
|
|
5133
|
+
return ids.filter(function (id, index) { return ids.indexOf(id) === index && _this.isSelectableId(id); });
|
|
5134
|
+
};
|
|
5135
|
+
DiagramEngine.prototype.isSelectableId = function (id) {
|
|
5136
|
+
if (this.model.getElement(id))
|
|
5137
|
+
return this.model.isElementSelectable(id);
|
|
5138
|
+
if (this.model.getPort(id))
|
|
5139
|
+
return this.model.isPortVisible(id);
|
|
5140
|
+
if (this.model.getLink(id))
|
|
5141
|
+
return this.model.isLinkVisible(id);
|
|
5142
|
+
if (this.model.getText(id))
|
|
5143
|
+
return this.model.isTextVisible(id);
|
|
5144
|
+
return false;
|
|
5145
|
+
};
|
|
5146
|
+
DiagramEngine.prototype.syncSelectionToPolicies = function () {
|
|
5147
|
+
var current = this.selection.get();
|
|
5148
|
+
var normalized = this.normalizeSelectionIds(current);
|
|
5149
|
+
if (current.length === normalized.length &&
|
|
5150
|
+
current.every(function (id, index) { return id === normalized[index]; })) {
|
|
5151
|
+
return false;
|
|
5152
|
+
}
|
|
5153
|
+
this.selection.set(normalized);
|
|
5154
|
+
return true;
|
|
5155
|
+
};
|
|
5056
5156
|
DiagramEngine.prototype.applyLayoutForParent = function (parentId, options) {
|
|
5057
5157
|
return this.autoLayoutService.applyLayoutForParent(parentId, options);
|
|
5058
5158
|
};
|
|
@@ -6005,7 +6105,9 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6005
6105
|
};
|
|
6006
6106
|
KonvaRenderer.prototype.syncElements = function (model) {
|
|
6007
6107
|
var _this = this;
|
|
6008
|
-
var elements = Array.from(model.elements.values())
|
|
6108
|
+
var elements = Array.from(model.elements.values())
|
|
6109
|
+
.filter(function (element) { return model.isElementVisible(element.id); })
|
|
6110
|
+
.map(function (element, index) { return ({
|
|
6009
6111
|
element: element,
|
|
6010
6112
|
depth: _this.getElementDepth(model, element),
|
|
6011
6113
|
order: index,
|
|
@@ -6038,6 +6140,10 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6038
6140
|
node.setAttrs({ __depth: depth });
|
|
6039
6141
|
}
|
|
6040
6142
|
});
|
|
6143
|
+
var visibleElementIds = new Set(elements.map(function (_a) {
|
|
6144
|
+
var element = _a.element;
|
|
6145
|
+
return element.id;
|
|
6146
|
+
}));
|
|
6041
6147
|
elements.forEach(function (_a) {
|
|
6042
6148
|
var _b;
|
|
6043
6149
|
var element = _a.element;
|
|
@@ -6046,7 +6152,7 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6046
6152
|
});
|
|
6047
6153
|
Array.from(this.elementNodes.keys()).forEach(function (id) {
|
|
6048
6154
|
var _a;
|
|
6049
|
-
if (!
|
|
6155
|
+
if (!visibleElementIds.has(id)) {
|
|
6050
6156
|
var node = _this.elementNodes.get(id);
|
|
6051
6157
|
(_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
|
|
6052
6158
|
_this.elementNodes.delete(id);
|
|
@@ -6069,7 +6175,7 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6069
6175
|
};
|
|
6070
6176
|
KonvaRenderer.prototype.syncPorts = function (model) {
|
|
6071
6177
|
var _this = this;
|
|
6072
|
-
var ports = Array.from(model.ports.values());
|
|
6178
|
+
var ports = Array.from(model.ports.values()).filter(function (port) { return model.isPortVisible(port.id); });
|
|
6073
6179
|
ports.forEach(function (port) {
|
|
6074
6180
|
var _a, _b, _c, _d, _e;
|
|
6075
6181
|
var data = port.toData();
|
|
@@ -6087,9 +6193,10 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6087
6193
|
_this.updatePosition(node, position);
|
|
6088
6194
|
_this.applyPortOrientation(node, data, position, model);
|
|
6089
6195
|
});
|
|
6196
|
+
var visiblePortIds = new Set(ports.map(function (port) { return port.id; }));
|
|
6090
6197
|
Array.from(this.portNodes.keys()).forEach(function (id) {
|
|
6091
6198
|
var _a;
|
|
6092
|
-
if (!
|
|
6199
|
+
if (!visiblePortIds.has(id)) {
|
|
6093
6200
|
var node = _this.portNodes.get(id);
|
|
6094
6201
|
(_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
|
|
6095
6202
|
_this.portNodes.delete(id);
|
|
@@ -6100,7 +6207,7 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6100
6207
|
};
|
|
6101
6208
|
KonvaRenderer.prototype.syncLinks = function (model) {
|
|
6102
6209
|
var _this = this;
|
|
6103
|
-
var links = Array.from(model.links.values());
|
|
6210
|
+
var links = Array.from(model.links.values()).filter(function (link) { return model.isLinkVisible(link.id); });
|
|
6104
6211
|
links.forEach(function (link) {
|
|
6105
6212
|
var _a, _b;
|
|
6106
6213
|
var node = _this.linkNodes.get(link.id);
|
|
@@ -6111,9 +6218,10 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6111
6218
|
}
|
|
6112
6219
|
_this.updateLine(node, link.toData());
|
|
6113
6220
|
});
|
|
6221
|
+
var visibleLinkIds = new Set(links.map(function (link) { return link.id; }));
|
|
6114
6222
|
Array.from(this.linkNodes.keys()).forEach(function (id) {
|
|
6115
6223
|
var _a;
|
|
6116
|
-
if (!
|
|
6224
|
+
if (!visibleLinkIds.has(id)) {
|
|
6117
6225
|
var node = _this.linkNodes.get(id);
|
|
6118
6226
|
(_a = node === null || node === void 0 ? void 0 : node.destroy) === null || _a === void 0 ? void 0 : _a.call(node);
|
|
6119
6227
|
_this.linkNodes.delete(id);
|
|
@@ -6124,7 +6232,7 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6124
6232
|
};
|
|
6125
6233
|
KonvaRenderer.prototype.syncTexts = function (model) {
|
|
6126
6234
|
var _this = this;
|
|
6127
|
-
var texts = Array.from(model.texts.values());
|
|
6235
|
+
var texts = Array.from(model.texts.values()).filter(function (text) { return model.isTextVisible(text.id); });
|
|
6128
6236
|
texts.forEach(function (text) {
|
|
6129
6237
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
6130
6238
|
var node = _this.textNodes.get(text.id);
|
|
@@ -6213,9 +6321,10 @@ var KonvaRenderer = /** @class */ (function () {
|
|
|
6213
6321
|
_this.textBackgroundNodes.delete(text.id);
|
|
6214
6322
|
}
|
|
6215
6323
|
});
|
|
6324
|
+
var visibleTextIds = new Set(texts.map(function (text) { return text.id; }));
|
|
6216
6325
|
Array.from(this.textNodes.keys()).forEach(function (id) {
|
|
6217
6326
|
var _a, _b;
|
|
6218
|
-
if (!
|
|
6327
|
+
if (!visibleTextIds.has(id)) {
|
|
6219
6328
|
var backgroundNode = _this.textBackgroundNodes.get(id);
|
|
6220
6329
|
(_a = backgroundNode === null || backgroundNode === void 0 ? void 0 : backgroundNode.destroy) === null || _a === void 0 ? void 0 : _a.call(backgroundNode);
|
|
6221
6330
|
_this.textBackgroundNodes.delete(id);
|
|
@@ -7218,15 +7327,21 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
7218
7327
|
KonvaInteraction.prototype.normalizeHit = function (hit) {
|
|
7219
7328
|
if (!hit || hit.type === 'none')
|
|
7220
7329
|
return null;
|
|
7221
|
-
if (hit.type === 'port'
|
|
7222
|
-
hit.
|
|
7223
|
-
|
|
7224
|
-
|
|
7330
|
+
if (hit.type === 'port') {
|
|
7331
|
+
return this.engine.isPortVisible(hit.id) ? hit : null;
|
|
7332
|
+
}
|
|
7333
|
+
if (hit.type === 'link') {
|
|
7334
|
+
return this.engine.isLinkVisible(hit.id) ? hit : null;
|
|
7335
|
+
}
|
|
7336
|
+
if (hit.type === 'text') {
|
|
7337
|
+
return this.engine.isTextVisible(hit.id) ? hit : null;
|
|
7338
|
+
}
|
|
7339
|
+
if (hit.type === 'resize-handle' ||
|
|
7225
7340
|
hit.type === 'link-handle' ||
|
|
7226
7341
|
hit.type === 'shape-hover-control') {
|
|
7227
7342
|
return hit;
|
|
7228
7343
|
}
|
|
7229
|
-
return __assign(__assign({}, hit), { type: 'element' });
|
|
7344
|
+
return this.engine.isElementSelectable(hit.id) ? __assign(__assign({}, hit), { type: 'element' }) : null;
|
|
7230
7345
|
};
|
|
7231
7346
|
KonvaInteraction.prototype.resolveHit = function (point) {
|
|
7232
7347
|
var _this = this;
|
|
@@ -7292,6 +7407,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
7292
7407
|
var best = null;
|
|
7293
7408
|
state.elements.forEach(function (element) {
|
|
7294
7409
|
var _a, _b, _c;
|
|
7410
|
+
if (!_this.engine.isElementSelectable(element.id))
|
|
7411
|
+
return;
|
|
7295
7412
|
var world = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
|
|
7296
7413
|
var rotation = _this.engine.getElementRotation(element.id);
|
|
7297
7414
|
if (!pointInRotatedRect(point, world, element.size, rotation, (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false))
|
|
@@ -7321,6 +7438,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
7321
7438
|
var bestDistance = Number.POSITIVE_INFINITY;
|
|
7322
7439
|
links.forEach(function (link) {
|
|
7323
7440
|
var _a, _b;
|
|
7441
|
+
if (!_this.engine.isLinkVisible(link.id))
|
|
7442
|
+
return;
|
|
7324
7443
|
if (link.points.length < 2)
|
|
7325
7444
|
return;
|
|
7326
7445
|
var tolerance = ((_b = (_a = link.style) === null || _a === void 0 ? void 0 : _a.hitStrokeWidth) !== null && _b !== void 0 ? _b : 15) / 2;
|
|
@@ -8335,6 +8454,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
8335
8454
|
};
|
|
8336
8455
|
state.elements.forEach(function (element) {
|
|
8337
8456
|
var _a, _b;
|
|
8457
|
+
if (!_this.engine.isElementSelectable(element.id))
|
|
8458
|
+
return;
|
|
8338
8459
|
var position = (_a = _this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
|
|
8339
8460
|
var rotation = _this.engine.getElementRotation(element.id);
|
|
8340
8461
|
var anchorCenter = (_b = element.anchorCenter) !== null && _b !== void 0 ? _b : false;
|
|
@@ -8352,6 +8473,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
8352
8473
|
});
|
|
8353
8474
|
state.ports.forEach(function (port) {
|
|
8354
8475
|
var _a;
|
|
8476
|
+
if (!_this.engine.isPortVisible(port.id))
|
|
8477
|
+
return;
|
|
8355
8478
|
var position = (_a = _this.engine.getPortWorldPosition(port.id)) !== null && _a !== void 0 ? _a : port.position;
|
|
8356
8479
|
if (containsPoint(position)) {
|
|
8357
8480
|
selected.add(port.id);
|
|
@@ -8359,6 +8482,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
8359
8482
|
});
|
|
8360
8483
|
state.texts.forEach(function (text) {
|
|
8361
8484
|
var _a, _b, _c, _d, _e;
|
|
8485
|
+
if (!_this.engine.isTextVisible(text.id))
|
|
8486
|
+
return;
|
|
8362
8487
|
var position = (_a = _this.engine.getTextWorldPosition(text.id)) !== null && _a !== void 0 ? _a : text.position;
|
|
8363
8488
|
var width = (_c = (_b = text.size) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
8364
8489
|
var height = (_e = (_d = text.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : 0;
|
|
@@ -8368,6 +8493,8 @@ var KonvaInteraction = /** @class */ (function () {
|
|
|
8368
8493
|
}
|
|
8369
8494
|
});
|
|
8370
8495
|
state.links.forEach(function (link) {
|
|
8496
|
+
if (!_this.engine.isLinkVisible(link.id))
|
|
8497
|
+
return;
|
|
8371
8498
|
if (link.points.length === 0)
|
|
8372
8499
|
return;
|
|
8373
8500
|
var xs = link.points.map(function (point) { return point.x; });
|
|
@@ -9299,32 +9426,180 @@ var resolveViewportFitOptions = function (options) {
|
|
|
9299
9426
|
return { padding: padding, minZoom: minZoom, maxZoom: maxZoom };
|
|
9300
9427
|
};
|
|
9301
9428
|
var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
9429
|
+
var isElementVisibleInState = function (elementId, elementsById) {
|
|
9430
|
+
var element = elementsById.get(elementId);
|
|
9431
|
+
if (!element)
|
|
9432
|
+
return false;
|
|
9433
|
+
return element.visible !== false;
|
|
9434
|
+
};
|
|
9435
|
+
var isPortVisibleInState = function (portId, portsById, elementsById) {
|
|
9436
|
+
var port = portsById.get(portId);
|
|
9437
|
+
if (!port)
|
|
9438
|
+
return false;
|
|
9439
|
+
return isElementVisibleInState(port.elementId, elementsById);
|
|
9440
|
+
};
|
|
9441
|
+
var isLinkVisibleInState = function (linkId, linksById, portsById, elementsById) {
|
|
9442
|
+
var link = linksById.get(linkId);
|
|
9443
|
+
if (!link)
|
|
9444
|
+
return false;
|
|
9445
|
+
var sourcePort = portsById.get(link.sourcePortId);
|
|
9446
|
+
var targetPort = portsById.get(link.targetPortId);
|
|
9447
|
+
var sourceVisible = sourcePort ? isPortVisibleInState(sourcePort.id, portsById, elementsById) : true;
|
|
9448
|
+
var targetVisible = targetPort ? isPortVisibleInState(targetPort.id, portsById, elementsById) : true;
|
|
9449
|
+
return sourceVisible && targetVisible;
|
|
9450
|
+
};
|
|
9451
|
+
var isTextVisibleInState = function (text, elementsById, portsById, linksById) {
|
|
9452
|
+
if (!text.ownerId)
|
|
9453
|
+
return true;
|
|
9454
|
+
if (elementsById.has(text.ownerId))
|
|
9455
|
+
return isElementVisibleInState(text.ownerId, elementsById);
|
|
9456
|
+
if (portsById.has(text.ownerId))
|
|
9457
|
+
return isPortVisibleInState(text.ownerId, portsById, elementsById);
|
|
9458
|
+
if (linksById.has(text.ownerId))
|
|
9459
|
+
return isLinkVisibleInState(text.ownerId, linksById, portsById, elementsById);
|
|
9460
|
+
return true;
|
|
9461
|
+
};
|
|
9462
|
+
var resolveElementWorldPositionInState = function (elementId, elementsById) {
|
|
9463
|
+
var element = elementsById.get(elementId);
|
|
9464
|
+
if (!element)
|
|
9465
|
+
return null;
|
|
9466
|
+
var x = element.position.x;
|
|
9467
|
+
var y = element.position.y;
|
|
9468
|
+
if (element.anchorCenter) {
|
|
9469
|
+
x -= element.size.width / 2;
|
|
9470
|
+
y -= element.size.height / 2;
|
|
9471
|
+
}
|
|
9472
|
+
var current = element;
|
|
9473
|
+
while (current.parentId) {
|
|
9474
|
+
var parent_1 = elementsById.get(current.parentId);
|
|
9475
|
+
if (!parent_1)
|
|
9476
|
+
break;
|
|
9477
|
+
var parentX = parent_1.position.x;
|
|
9478
|
+
var parentY = parent_1.position.y;
|
|
9479
|
+
if (parent_1.anchorCenter) {
|
|
9480
|
+
parentX -= parent_1.size.width / 2;
|
|
9481
|
+
parentY -= parent_1.size.height / 2;
|
|
9482
|
+
}
|
|
9483
|
+
x += parentX;
|
|
9484
|
+
y += parentY;
|
|
9485
|
+
current = parent_1;
|
|
9486
|
+
}
|
|
9487
|
+
return { x: x, y: y };
|
|
9488
|
+
};
|
|
9489
|
+
var resolvePortWorldPositionInState = function (portId, portsById, elementsById) {
|
|
9490
|
+
var port = portsById.get(portId);
|
|
9491
|
+
if (!port)
|
|
9492
|
+
return null;
|
|
9493
|
+
var elementPosition = resolveElementWorldPositionInState(port.elementId, elementsById);
|
|
9494
|
+
if (!elementPosition)
|
|
9495
|
+
return __assign({}, port.position);
|
|
9496
|
+
return {
|
|
9497
|
+
x: elementPosition.x + port.position.x,
|
|
9498
|
+
y: elementPosition.y + port.position.y,
|
|
9499
|
+
};
|
|
9500
|
+
};
|
|
9501
|
+
var resolveLinkMidpointInState = function (link) {
|
|
9502
|
+
var points = link.points;
|
|
9503
|
+
if (points.length === 0)
|
|
9504
|
+
return { x: 0, y: 0 };
|
|
9505
|
+
if (points.length === 1)
|
|
9506
|
+
return __assign({}, points[0]);
|
|
9507
|
+
var total = 0;
|
|
9508
|
+
for (var i = 1; i < points.length; i += 1) {
|
|
9509
|
+
total += distance(points[i - 1], points[i]);
|
|
9510
|
+
}
|
|
9511
|
+
var halfway = total / 2;
|
|
9512
|
+
var traveled = 0;
|
|
9513
|
+
for (var i = 1; i < points.length; i += 1) {
|
|
9514
|
+
var segment = distance(points[i - 1], points[i]);
|
|
9515
|
+
if (traveled + segment >= halfway) {
|
|
9516
|
+
var ratio = segment === 0 ? 0 : (halfway - traveled) / segment;
|
|
9517
|
+
return {
|
|
9518
|
+
x: points[i - 1].x + (points[i].x - points[i - 1].x) * ratio,
|
|
9519
|
+
y: points[i - 1].y + (points[i].y - points[i - 1].y) * ratio,
|
|
9520
|
+
};
|
|
9521
|
+
}
|
|
9522
|
+
traveled += segment;
|
|
9523
|
+
}
|
|
9524
|
+
return __assign({}, points[points.length - 1]);
|
|
9525
|
+
};
|
|
9526
|
+
var resolveTextWorldPositionInState = function (text, elementsById, portsById, linksById) {
|
|
9527
|
+
if (!text.ownerId)
|
|
9528
|
+
return __assign({}, text.position);
|
|
9529
|
+
if (elementsById.has(text.ownerId)) {
|
|
9530
|
+
var elementPosition = resolveElementWorldPositionInState(text.ownerId, elementsById);
|
|
9531
|
+
if (!elementPosition)
|
|
9532
|
+
return __assign({}, text.position);
|
|
9533
|
+
return {
|
|
9534
|
+
x: elementPosition.x + text.position.x,
|
|
9535
|
+
y: elementPosition.y + text.position.y,
|
|
9536
|
+
};
|
|
9537
|
+
}
|
|
9538
|
+
if (portsById.has(text.ownerId)) {
|
|
9539
|
+
var portPosition = resolvePortWorldPositionInState(text.ownerId, portsById, elementsById);
|
|
9540
|
+
if (!portPosition)
|
|
9541
|
+
return __assign({}, text.position);
|
|
9542
|
+
return {
|
|
9543
|
+
x: portPosition.x + text.position.x,
|
|
9544
|
+
y: portPosition.y + text.position.y,
|
|
9545
|
+
};
|
|
9546
|
+
}
|
|
9547
|
+
if (linksById.has(text.ownerId)) {
|
|
9548
|
+
var link = linksById.get(text.ownerId);
|
|
9549
|
+
if (!link)
|
|
9550
|
+
return __assign({}, text.position);
|
|
9551
|
+
var midpoint = resolveLinkMidpointInState(link);
|
|
9552
|
+
return {
|
|
9553
|
+
x: midpoint.x + text.position.x,
|
|
9554
|
+
y: midpoint.y + text.position.y,
|
|
9555
|
+
};
|
|
9556
|
+
}
|
|
9557
|
+
return __assign({}, text.position);
|
|
9558
|
+
};
|
|
9302
9559
|
var resolveStateWorldBounds = function (state) {
|
|
9303
9560
|
var bounds = createBounds();
|
|
9561
|
+
var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
|
|
9562
|
+
var portsById = new Map(state.ports.map(function (port) { return [port.id, port]; }));
|
|
9563
|
+
var linksById = new Map(state.links.map(function (link) { return [link.id, link]; }));
|
|
9304
9564
|
state.elements.forEach(function (element) {
|
|
9305
|
-
|
|
9565
|
+
if (!isElementVisibleInState(element.id, elementsById))
|
|
9566
|
+
return;
|
|
9567
|
+
var position = resolveElementWorldPositionInState(element.id, elementsById);
|
|
9568
|
+
if (!position)
|
|
9569
|
+
return;
|
|
9570
|
+
includeRect(bounds, position.x, position.y, element.size.width, element.size.height);
|
|
9306
9571
|
});
|
|
9307
9572
|
state.ports.forEach(function (port) {
|
|
9308
9573
|
var _a;
|
|
9574
|
+
if (!isPortVisibleInState(port.id, portsById, elementsById))
|
|
9575
|
+
return;
|
|
9576
|
+
var position = resolvePortWorldPositionInState(port.id, portsById, elementsById);
|
|
9577
|
+
if (!position)
|
|
9578
|
+
return;
|
|
9309
9579
|
var size = port.size;
|
|
9310
9580
|
if (!size) {
|
|
9311
|
-
expandBounds(bounds,
|
|
9581
|
+
expandBounds(bounds, position.x, position.y);
|
|
9312
9582
|
return;
|
|
9313
9583
|
}
|
|
9314
9584
|
var anchorCenter = (_a = port.anchorCenter) !== null && _a !== void 0 ? _a : true;
|
|
9315
|
-
var x = anchorCenter ?
|
|
9316
|
-
var y = anchorCenter ?
|
|
9585
|
+
var x = anchorCenter ? position.x - size.width / 2 : position.x;
|
|
9586
|
+
var y = anchorCenter ? position.y - size.height / 2 : position.y;
|
|
9317
9587
|
includeRect(bounds, x, y, size.width, size.height);
|
|
9318
9588
|
});
|
|
9319
9589
|
state.links.forEach(function (link) {
|
|
9590
|
+
if (!isLinkVisibleInState(link.id, linksById, portsById, elementsById))
|
|
9591
|
+
return;
|
|
9320
9592
|
link.points.forEach(function (point) {
|
|
9321
9593
|
expandBounds(bounds, point.x, point.y);
|
|
9322
9594
|
});
|
|
9323
9595
|
});
|
|
9324
9596
|
state.texts.forEach(function (text) {
|
|
9325
9597
|
var _a;
|
|
9598
|
+
if (!isTextVisibleInState(text, elementsById, portsById, linksById))
|
|
9599
|
+
return;
|
|
9326
9600
|
var offset = (_a = text.displayOffset) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
|
|
9327
|
-
var
|
|
9601
|
+
var worldPosition = resolveTextWorldPositionInState(text, elementsById, portsById, linksById);
|
|
9602
|
+
var position = { x: worldPosition.x + offset.x, y: worldPosition.y + offset.y };
|
|
9328
9603
|
var clipSize = text.displayClipSize;
|
|
9329
9604
|
var size = clipSize !== null && clipSize !== void 0 ? clipSize : text.size;
|
|
9330
9605
|
if (size) {
|
|
@@ -9337,8 +9612,14 @@ var resolveStateWorldBounds = function (state) {
|
|
|
9337
9612
|
};
|
|
9338
9613
|
var resolveElementWorldBounds = function (state) {
|
|
9339
9614
|
var bounds = createBounds();
|
|
9615
|
+
var elementsById = new Map(state.elements.map(function (element) { return [element.id, element]; }));
|
|
9340
9616
|
state.elements.forEach(function (element) {
|
|
9341
|
-
|
|
9617
|
+
if (!isElementVisibleInState(element.id, elementsById))
|
|
9618
|
+
return;
|
|
9619
|
+
var position = resolveElementWorldPositionInState(element.id, elementsById);
|
|
9620
|
+
if (!position)
|
|
9621
|
+
return;
|
|
9622
|
+
includeRect(bounds, position.x, position.y, element.size.width, element.size.height);
|
|
9342
9623
|
});
|
|
9343
9624
|
return hasBounds(bounds) ? bounds : null;
|
|
9344
9625
|
};
|
|
@@ -76,6 +76,11 @@ export default class DiagramEngine {
|
|
|
76
76
|
setSelection(ids: string[]): void;
|
|
77
77
|
toggleSelection(id: string): void;
|
|
78
78
|
getSelection(): string[];
|
|
79
|
+
isElementVisible(id: string): boolean;
|
|
80
|
+
isElementSelectable(id: string): boolean;
|
|
81
|
+
isPortVisible(id: string): boolean;
|
|
82
|
+
isLinkVisible(id: string): boolean;
|
|
83
|
+
isTextVisible(id: string): boolean;
|
|
79
84
|
getElementWorldPosition(id: string): Point | null;
|
|
80
85
|
getElementRotation(id: string): number;
|
|
81
86
|
normalizeElementResize(id: string, proposal: {
|
|
@@ -146,6 +151,9 @@ export default class DiagramEngine {
|
|
|
146
151
|
private resolveTextPresentation;
|
|
147
152
|
private resolveAllTextPresentationPatches;
|
|
148
153
|
private emitSelection;
|
|
154
|
+
private normalizeSelectionIds;
|
|
155
|
+
private isSelectableId;
|
|
156
|
+
private syncSelectionToPolicies;
|
|
149
157
|
private applyLayoutForParent;
|
|
150
158
|
private applyLayoutCascade;
|
|
151
159
|
private applyAllLayouts;
|
|
@@ -13,14 +13,19 @@ export default class DiagramModel {
|
|
|
13
13
|
load(state: DiagramState): void;
|
|
14
14
|
toState(): DiagramState;
|
|
15
15
|
getElement(id: string): ElementModel | undefined;
|
|
16
|
+
isElementVisible(id: string): boolean;
|
|
17
|
+
isElementSelectable(id: string): boolean;
|
|
16
18
|
setElementLayout(id: string, layout: ElementData['layout']): void;
|
|
17
19
|
getChildren(parentId: string): ElementModel[];
|
|
18
20
|
getElementWorldPosition(id: string): Point | null;
|
|
19
21
|
getPort(id: string): PortModel | undefined;
|
|
22
|
+
isPortVisible(id: string): boolean;
|
|
20
23
|
getPortWorldPosition(id: string): Point | null;
|
|
21
24
|
getLink(id: string): LinkModel | undefined;
|
|
25
|
+
isLinkVisible(id: string): boolean;
|
|
22
26
|
getLinkMidpoint(id: string): Point | null;
|
|
23
27
|
getText(id: string): TextModel | undefined;
|
|
28
|
+
isTextVisible(id: string): boolean;
|
|
24
29
|
getTextWorldPosition(id: string): Point | null;
|
|
25
30
|
addElement(data: ElementData): ElementModel;
|
|
26
31
|
moveElement(id: string, position: Point): void;
|