orcasvn-react-diagrams 0.2.11 → 0.2.12

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +11 -7
  3. package/ai/api-contract.json +43 -1
  4. package/ai/manifest.json +1 -1
  5. package/dist/cjs/examples.js +492 -286
  6. package/dist/cjs/index.js +180 -61
  7. package/dist/cjs/types/api/createDiagramEditor.d.ts +2 -1
  8. package/dist/cjs/types/api/types.d.ts +14 -0
  9. package/dist/cjs/types/displaybox/demos/LinkPortCreationDemoTab.d.ts +3 -0
  10. package/dist/cjs/types/displaybox/demos/linkLabelsDemo.d.ts +4 -0
  11. package/dist/cjs/types/displaybox/types.d.ts +3 -0
  12. package/dist/cjs/types/displaybox/useDemoEditor.d.ts +3 -2
  13. package/dist/cjs/types/engine/DiagramEngine.d.ts +2 -1
  14. package/dist/cjs/types/engine/TextLayoutService.d.ts +1 -0
  15. package/dist/cjs/types/examples/index.d.ts +1 -1
  16. package/dist/cjs/types/renderer/konva/KonvaInteraction.d.ts +10 -1
  17. package/dist/esm/examples.js +492 -286
  18. package/dist/esm/examples.js.map +1 -1
  19. package/dist/esm/index.js +180 -61
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/types/api/createDiagramEditor.d.ts +2 -1
  22. package/dist/esm/types/api/types.d.ts +14 -0
  23. package/dist/esm/types/displaybox/demos/LinkPortCreationDemoTab.d.ts +3 -0
  24. package/dist/esm/types/displaybox/demos/linkLabelsDemo.d.ts +4 -0
  25. package/dist/esm/types/displaybox/types.d.ts +3 -0
  26. package/dist/esm/types/displaybox/useDemoEditor.d.ts +3 -2
  27. package/dist/esm/types/engine/DiagramEngine.d.ts +2 -1
  28. package/dist/esm/types/engine/TextLayoutService.d.ts +1 -0
  29. package/dist/esm/types/examples/index.d.ts +1 -1
  30. package/dist/esm/types/renderer/konva/KonvaInteraction.d.ts +10 -1
  31. package/dist/examples.d.ts +4 -1
  32. package/dist/index.d.ts +16 -1
  33. package/docs/API_CONTRACT.md +40 -0
  34. package/docs/CAPABILITIES.md +2 -0
  35. package/docs/COMMANDS_EVENTS.md +1 -0
  36. package/docs/DOCUMENTATION_WORKFLOW.md +3 -1
  37. package/docs/INTEGRATION_PLAYBOOK.md +4 -0
  38. package/docs/STATE_INVARIANTS.md +3 -0
  39. package/package.json +1 -1
  40. package/src/displaybox/demos/LinkPortCreationDemoTab.tsx +98 -0
  41. package/src/displaybox/demos/index.tsx +122 -221
  42. package/src/displaybox/demos/linkLabelsDemo.ts +164 -0
  43. package/src/displaybox/demos/linkPortCreationDemo.ts +7 -7
  44. package/src/displaybox/types.ts +21 -11
  45. package/src/examples/index.ts +1 -0
@@ -2,17 +2,6 @@
2
2
 
3
3
  var React = require('react');
4
4
 
5
- var fallbackId = function () {
6
- return "id-".concat(Math.random().toString(36).slice(2, 10), "-").concat(Date.now().toString(36));
7
- };
8
- var createId = function () {
9
- var cryptoApi = globalThis.crypto;
10
- if (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.randomUUID) {
11
- return cryptoApi.randomUUID();
12
- }
13
- return fallbackId();
14
- };
15
-
16
5
  /******************************************************************************
17
6
  Copyright (c) Microsoft Corporation.
18
7
 
@@ -82,6 +71,17 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
82
71
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
83
72
  };
84
73
 
74
+ var fallbackId = function () {
75
+ return "id-".concat(Math.random().toString(36).slice(2, 10), "-").concat(Date.now().toString(36));
76
+ };
77
+ var createId = function () {
78
+ var cryptoApi = globalThis.crypto;
79
+ if (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.randomUUID) {
80
+ return cryptoApi.randomUUID();
81
+ }
82
+ return fallbackId();
83
+ };
84
+
85
85
  var DEFAULT_PADDING = 12;
86
86
  var DEFAULT_TOLERANCE = 0.5;
87
87
  var DEFAULT_STUB_LENGTH = 12;
@@ -848,7 +848,7 @@ var createLinkPortCreationState = function () { return ({
848
848
  var linkPortCreationDemoConfig = ({
849
849
  id: 'link-port-creation',
850
850
  title: 'Link Creates Port',
851
- description: 'Drag from a port to an element to auto-create a target port.',
851
+ description: 'Drag from a port to an element to auto-create a target port, then compare default and host-customized target-port creation.',
852
852
  createState: createLinkPortCreationState,
853
853
  elementShapes: baseElementShapes,
854
854
  portShapes: basePortShapes,
@@ -3634,6 +3634,163 @@ var linkColorPoolDemoConfig = {
3634
3634
  ],
3635
3635
  };
3636
3636
 
3637
+ var linkLabelDemoSourceId = 'link-label-source';
3638
+ var linkLabelDemoTargetId = 'link-label-target';
3639
+ var linkLabelDemoLinkId = 'link-label-link';
3640
+ var linkLabelDemoTextId = 'link-label-text';
3641
+ var resolveLinkMidpoint = function (points) {
3642
+ if (points.length === 0)
3643
+ return { x: 0, y: 0 };
3644
+ if (points.length === 1)
3645
+ return __assign({}, points[0]);
3646
+ var total = 0;
3647
+ for (var index = 1; index < points.length; index += 1) {
3648
+ total += Math.hypot(points[index].x - points[index - 1].x, points[index].y - points[index - 1].y);
3649
+ }
3650
+ var halfway = total / 2;
3651
+ var travelled = 0;
3652
+ for (var index = 1; index < points.length; index += 1) {
3653
+ var segment = Math.hypot(points[index].x - points[index - 1].x, points[index].y - points[index - 1].y);
3654
+ if (travelled + segment >= halfway) {
3655
+ var ratio = segment === 0 ? 0 : (halfway - travelled) / segment;
3656
+ return {
3657
+ x: points[index - 1].x + (points[index].x - points[index - 1].x) * ratio,
3658
+ y: points[index - 1].y + (points[index].y - points[index - 1].y) * ratio,
3659
+ };
3660
+ }
3661
+ travelled += segment;
3662
+ }
3663
+ return __assign({}, points[points.length - 1]);
3664
+ };
3665
+ var nudgeLinkLabel = function (editor, state) {
3666
+ var link = state.links.find(function (item) { return item.id === linkLabelDemoLinkId; });
3667
+ var label = state.texts.find(function (item) { return item.id === linkLabelDemoTextId; });
3668
+ if (!link || !label)
3669
+ return;
3670
+ var midpoint = resolveLinkMidpoint(link.points);
3671
+ editor.moveTextTo(linkLabelDemoTextId, midpoint.x + 72, midpoint.y - 24);
3672
+ };
3673
+ var createLinkLabelsState = function () { return ({
3674
+ elements: [
3675
+ {
3676
+ id: linkLabelDemoSourceId,
3677
+ position: { x: 120, y: 180 },
3678
+ size: { width: 220, height: 120 },
3679
+ shapeId: 'default',
3680
+ },
3681
+ {
3682
+ id: linkLabelDemoTargetId,
3683
+ position: { x: 500, y: 220 },
3684
+ size: { width: 220, height: 140 },
3685
+ shapeId: 'panel',
3686
+ },
3687
+ ],
3688
+ ports: [
3689
+ {
3690
+ id: 'link-label-source-port',
3691
+ elementId: linkLabelDemoSourceId,
3692
+ position: { x: 220, y: 60 },
3693
+ shapeId: 'port-circle',
3694
+ moveMode: 'border',
3695
+ anchorCenter: true,
3696
+ },
3697
+ {
3698
+ id: 'link-label-target-port',
3699
+ elementId: linkLabelDemoTargetId,
3700
+ position: { x: 0, y: 70 },
3701
+ shapeId: 'port-circle',
3702
+ moveMode: 'border',
3703
+ anchorCenter: true,
3704
+ },
3705
+ ],
3706
+ links: [
3707
+ {
3708
+ id: linkLabelDemoLinkId,
3709
+ sourcePortId: 'link-label-source-port',
3710
+ targetPortId: 'link-label-target-port',
3711
+ points: [],
3712
+ },
3713
+ ],
3714
+ texts: [
3715
+ {
3716
+ id: "".concat(linkLabelDemoSourceId, "-label"),
3717
+ content: 'Source node',
3718
+ position: { x: 12, y: -14 },
3719
+ ownerId: linkLabelDemoSourceId,
3720
+ },
3721
+ {
3722
+ id: "".concat(linkLabelDemoTargetId, "-label"),
3723
+ content: 'Move me, reroute me',
3724
+ position: { x: 12, y: -14 },
3725
+ ownerId: linkLabelDemoTargetId,
3726
+ },
3727
+ {
3728
+ id: linkLabelDemoTextId,
3729
+ content: 'I am just owned text',
3730
+ position: { x: 0, y: -24 },
3731
+ ownerId: linkLabelDemoLinkId,
3732
+ layout: {
3733
+ boundsMode: 'fixed',
3734
+ fixedSize: { width: 160, height: 24 },
3735
+ wrap: 'none',
3736
+ overflow: 'ellipsis-end',
3737
+ },
3738
+ style: {
3739
+ fill: '#1f2937',
3740
+ backgroundFill: '#fef3c7',
3741
+ padding: 4,
3742
+ },
3743
+ },
3744
+ {
3745
+ id: 'link-label-tip',
3746
+ content: 'This label is TextData owned by the link. Drag or edit it, reroute the link, then delete the link to confirm the label follows and cascades away.',
3747
+ position: { x: 120, y: 110 },
3748
+ layout: {
3749
+ boundsMode: 'fixed',
3750
+ fixedSize: { width: 620, height: 44 },
3751
+ wrap: 'word',
3752
+ overflow: 'clip',
3753
+ padding: 0,
3754
+ },
3755
+ style: {
3756
+ fill: '#475569',
3757
+ },
3758
+ },
3759
+ ],
3760
+ }); };
3761
+ var linkLabelsDemoConfig = {
3762
+ id: 'link-labels',
3763
+ title: 'Link Labels',
3764
+ description: 'Link-owned text stays anchored to the route midpoint. Drag or edit the label, reroute the link, then delete the link to watch the owned text disappear with it.',
3765
+ createState: createLinkLabelsState,
3766
+ elementShapes: baseElementShapes,
3767
+ portShapes: basePortShapes,
3768
+ defaultElementShapeId: 'default',
3769
+ defaultPortShapeId: 'port-circle',
3770
+ actions: [
3771
+ {
3772
+ id: 'link-label-offset',
3773
+ label: 'Offset label via API',
3774
+ run: function (editor, state) { return nudgeLinkLabel(editor, state); },
3775
+ },
3776
+ {
3777
+ id: 'link-label-reroute',
3778
+ label: 'Move target + reroute',
3779
+ run: function (editor) {
3780
+ editor.moveElementTo(linkLabelDemoTargetId, 660, 320);
3781
+ editor.rerouteAllLinks();
3782
+ },
3783
+ },
3784
+ {
3785
+ id: 'link-label-delete',
3786
+ label: 'Delete labeled link',
3787
+ run: function (editor) {
3788
+ editor.removeLink(linkLabelDemoLinkId);
3789
+ },
3790
+ },
3791
+ ],
3792
+ };
3793
+
3637
3794
  var createGridOverlayState = function () { return ({
3638
3795
  elements: [
3639
3796
  {
@@ -6150,21 +6307,20 @@ var TextLayoutService = /** @class */ (function () {
6150
6307
  return ids;
6151
6308
  };
6152
6309
  TextLayoutService.prototype.shouldTrackOwnerBoundLayout = function (text) {
6153
- var _a;
6154
6310
  if (!text.layout)
6155
6311
  return false;
6156
- var boundsMode = (_a = text.layout.boundsMode) !== null && _a !== void 0 ? _a : (text.ownerId ? 'owner-width' : undefined);
6312
+ var boundsMode = this.resolveDefaultBoundsMode(text);
6157
6313
  return boundsMode === 'owner-width' || boundsMode === 'owner-box';
6158
6314
  };
6159
6315
  TextLayoutService.prototype.resolveTextLayoutBounds = function (text, padding) {
6160
- var _a, _b, _c;
6316
+ var _a, _b;
6161
6317
  var layout = text.layout;
6162
6318
  if (!layout)
6163
6319
  return {};
6164
- var boundsMode = (_a = layout.boundsMode) !== null && _a !== void 0 ? _a : (text.ownerId ? 'owner-width' : undefined);
6320
+ var boundsMode = this.resolveDefaultBoundsMode(text);
6165
6321
  if (boundsMode === 'fixed') {
6166
- var width = (_b = layout.fixedSize) === null || _b === void 0 ? void 0 : _b.width;
6167
- var height = (_c = layout.fixedSize) === null || _c === void 0 ? void 0 : _c.height;
6322
+ var width = (_a = layout.fixedSize) === null || _a === void 0 ? void 0 : _a.width;
6323
+ var height = (_b = layout.fixedSize) === null || _b === void 0 ? void 0 : _b.height;
6168
6324
  return {
6169
6325
  width: typeof width === 'number' ? Math.max(0, width - padding * 2) : undefined,
6170
6326
  height: typeof height === 'number' ? Math.max(0, height - padding * 2) : undefined,
@@ -6184,6 +6340,14 @@ var TextLayoutService = /** @class */ (function () {
6184
6340
  }
6185
6341
  return {};
6186
6342
  };
6343
+ TextLayoutService.prototype.resolveDefaultBoundsMode = function (text) {
6344
+ var _a;
6345
+ if ((_a = text.layout) === null || _a === void 0 ? void 0 : _a.boundsMode)
6346
+ return text.layout.boundsMode;
6347
+ if (!text.ownerId)
6348
+ return undefined;
6349
+ return this.model.getElement(text.ownerId) ? 'owner-width' : undefined;
6350
+ };
6187
6351
  TextLayoutService.prototype.wrapText = function (content, maxWidth, mode, text) {
6188
6352
  var _this = this;
6189
6353
  if (maxWidth === undefined || !Number.isFinite(maxWidth)) {
@@ -8425,6 +8589,24 @@ var DiagramEngine = /** @class */ (function () {
8425
8589
  var patches = this.commandQueue.run(createAddPortCommand(nextPort), this.model);
8426
8590
  this.emitChange(patches);
8427
8591
  };
8592
+ DiagramEngine.prototype.normalizePortDraftForElement = function (elementId, draft) {
8593
+ var _a;
8594
+ var element = this.model.getElement(elementId);
8595
+ if (!element)
8596
+ return null;
8597
+ var nextDraft = __assign(__assign({}, draft), { position: __assign({}, draft.position), size: draft.size ? __assign({}, draft.size) : undefined, style: draft.style ? __assign({}, draft.style) : undefined, textIds: draft.textIds ? __spreadArray([], draft.textIds, true) : undefined, placementPoint: draft.placementPoint ? __assign({}, draft.placementPoint) : undefined, linkAttachPoint: draft.linkAttachPoint ? __assign({}, draft.linkAttachPoint) : undefined, externalLinkAttachPoint: draft.externalLinkAttachPoint ? __assign({}, draft.externalLinkAttachPoint) : undefined, internalLinkAttachPoint: draft.internalLinkAttachPoint ? __assign({}, draft.internalLinkAttachPoint) : undefined, rotationPivot: draft.rotationPivot ? __assign({}, draft.rotationPivot) : undefined });
8598
+ var constrained = this.resolveConstrainedPortRelativePosition({
8599
+ position: nextDraft.position,
8600
+ size: nextDraft.size,
8601
+ style: nextDraft.style,
8602
+ moveMode: nextDraft.moveMode,
8603
+ anchorCenter: nextDraft.anchorCenter,
8604
+ currentAnchorId: nextDraft.currentAnchorId,
8605
+ }, element, nextDraft.position);
8606
+ nextDraft.position = constrained.position;
8607
+ nextDraft.currentAnchorId = (_a = constrained.currentAnchorId) !== null && _a !== void 0 ? _a : undefined;
8608
+ return nextDraft;
8609
+ };
8428
8610
  DiagramEngine.prototype.movePortTo = function (id, x, y) {
8429
8611
  var snapped = this.snapper.snap({ x: x, y: y });
8430
8612
  var port = this.model.getPort(id);
@@ -10774,6 +10956,7 @@ var KonvaInteraction = /** @class */ (function () {
10774
10956
  this.shapeHoverControls = this.normalizeShapeHoverControls(config.shapeHoverControls);
10775
10957
  this.onShapeHoverControlInteracted = config.onShapeHoverControlInteracted;
10776
10958
  this.onShapeHoverControlActivated = config.onShapeHoverControlActivated;
10959
+ this.onCreateLinkTargetPort = config.onCreateLinkTargetPort;
10777
10960
  }
10778
10961
  KonvaInteraction.prototype.setShapeHoverControls = function (controls) {
10779
10962
  this.shapeHoverControls = this.normalizeShapeHoverControls(controls);
@@ -10790,6 +10973,9 @@ var KonvaInteraction = /** @class */ (function () {
10790
10973
  var sourceElementId = this.engine.getPortElementId(sourcePortId);
10791
10974
  if (!sourceElementId)
10792
10975
  return;
10976
+ var sourcePort = this.getPortById(sourcePortId);
10977
+ if (!sourcePort)
10978
+ return;
10793
10979
  var sourcePoint = (_a = this.engine.getPortLinkWorldPosition(sourcePortId)) !== null && _a !== void 0 ? _a : this.engine.getPortWorldPosition(sourcePortId);
10794
10980
  if (!sourcePoint)
10795
10981
  return;
@@ -10806,6 +10992,7 @@ var KonvaInteraction = /** @class */ (function () {
10806
10992
  this.programmaticLinkSession = {
10807
10993
  sourcePortId: sourcePortId,
10808
10994
  sourceElementId: sourceElementId,
10995
+ sourcePort: this.clonePortData(sourcePort),
10809
10996
  start: start,
10810
10997
  current: start,
10811
10998
  };
@@ -10815,6 +11002,7 @@ var KonvaInteraction = /** @class */ (function () {
10815
11002
  mode: 'link-drag',
10816
11003
  sourcePortId: sourcePortId,
10817
11004
  sourceElementId: sourceElementId,
11005
+ sourcePort: this.clonePortData(sourcePort),
10818
11006
  start: start,
10819
11007
  current: start,
10820
11008
  isMulti: false,
@@ -10830,7 +11018,7 @@ var KonvaInteraction = /** @class */ (function () {
10830
11018
  }
10831
11019
  };
10832
11020
  KonvaInteraction.prototype.updateLinkPreview = function (pointer) {
10833
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
11021
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
10834
11022
  if (this.programmaticLinkSession) {
10835
11023
  this.programmaticLinkSession.current = __assign({}, pointer);
10836
11024
  }
@@ -10842,28 +11030,29 @@ var KonvaInteraction = /** @class */ (function () {
10842
11030
  return;
10843
11031
  }
10844
11032
  var sourcePortId = (_c = (_b = this.programmaticLinkSession) === null || _b === void 0 ? void 0 : _b.sourcePortId) !== null && _c !== void 0 ? _c : (((_d = this.dragState) === null || _d === void 0 ? void 0 : _d.mode) === 'link-drag' ? this.dragState.sourcePortId : null);
11033
+ var sourceElementId = (_f = (_e = this.programmaticLinkSession) === null || _e === void 0 ? void 0 : _e.sourceElementId) !== null && _f !== void 0 ? _f : (((_g = this.dragState) === null || _g === void 0 ? void 0 : _g.mode) === 'link-drag' ? this.dragState.sourceElementId : null);
10845
11034
  if (!sourcePortId)
10846
11035
  return;
10847
11036
  var source = this.resolveLinkPreviewSource(sourcePortId, pointer);
10848
11037
  if (source) {
10849
- (_e = this.renderer) === null || _e === void 0 ? void 0 : _e.renderTempLink([source, pointer]);
11038
+ (_h = this.renderer) === null || _h === void 0 ? void 0 : _h.renderTempLink([source, pointer]);
10850
11039
  }
10851
11040
  var hit = this.resolveHit(pointer);
10852
- if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'element') {
10853
- var placeholder = this.createPlaceholderPort(hit.id, pointer, sourcePortId);
11041
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'element' && sourceElementId) {
11042
+ var placeholder = this.createPlaceholderPort(hit.id, pointer, sourcePortId, sourceElementId);
10854
11043
  if (placeholder) {
10855
11044
  var hostElement = this.getElementById(hit.id);
10856
11045
  if (hostElement) {
10857
- var hostWorld = (_f = this.engine.getElementWorldPosition(hit.id)) !== null && _f !== void 0 ? _f : hostElement.position;
10858
- (_h = (_g = this.renderer) === null || _g === void 0 ? void 0 : _g.renderPortPlaceholder) === null || _h === void 0 ? void 0 : _h.call(_g, placeholder, { id: hostElement.id, position: hostWorld, size: hostElement.size, shapeId: hostElement.shapeId });
11046
+ var hostWorld = (_j = this.engine.getElementWorldPosition(hit.id)) !== null && _j !== void 0 ? _j : hostElement.position;
11047
+ (_l = (_k = this.renderer) === null || _k === void 0 ? void 0 : _k.renderPortPlaceholder) === null || _l === void 0 ? void 0 : _l.call(_k, placeholder, { id: hostElement.id, position: hostWorld, size: hostElement.size, shapeId: hostElement.shapeId });
10859
11048
  }
10860
11049
  else {
10861
- (_k = (_j = this.renderer) === null || _j === void 0 ? void 0 : _j.renderPortPlaceholder) === null || _k === void 0 ? void 0 : _k.call(_j, placeholder);
11050
+ (_o = (_m = this.renderer) === null || _m === void 0 ? void 0 : _m.renderPortPlaceholder) === null || _o === void 0 ? void 0 : _o.call(_m, placeholder);
10862
11051
  }
10863
11052
  }
10864
11053
  return;
10865
11054
  }
10866
- (_m = (_l = this.renderer) === null || _l === void 0 ? void 0 : _l.clearPortPlaceholder) === null || _m === void 0 ? void 0 : _m.call(_l);
11055
+ (_q = (_p = this.renderer) === null || _p === void 0 ? void 0 : _p.clearPortPlaceholder) === null || _q === void 0 ? void 0 : _q.call(_p);
10867
11056
  };
10868
11057
  KonvaInteraction.prototype.completeLinkToPort = function (targetPortId) {
10869
11058
  var _a, _b;
@@ -11025,10 +11214,14 @@ var KonvaInteraction = /** @class */ (function () {
11025
11214
  }
11026
11215
  }
11027
11216
  else {
11217
+ var sourcePort = _this.getPortById(hit.id);
11218
+ if (!sourcePort)
11219
+ return;
11028
11220
  _this.dragState = {
11029
11221
  mode: 'link-drag',
11030
11222
  sourcePortId: hit.id,
11031
11223
  sourceElementId: elementId,
11224
+ sourcePort: _this.clonePortData(sourcePort),
11032
11225
  start: point,
11033
11226
  current: point,
11034
11227
  isMulti: isMulti,
@@ -11210,7 +11403,7 @@ var KonvaInteraction = /** @class */ (function () {
11210
11403
  }
11211
11404
  }
11212
11405
  else if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'element') {
11213
- var placeholder = _this.createPlaceholderPort(hit.id, point, _this.dragState.sourcePortId);
11406
+ var placeholder = _this.createPlaceholderPort(hit.id, point, _this.dragState.sourcePortId, _this.dragState.sourceElementId);
11214
11407
  if (placeholder) {
11215
11408
  var hostElement = _this.getElementById(hit.id);
11216
11409
  if (hostElement) {
@@ -12885,7 +13078,8 @@ var KonvaInteraction = /** @class */ (function () {
12885
13078
  return { createdLinkId: createdLinkId, targetPortId: targetPortId, targetElementId: targetElementId };
12886
13079
  };
12887
13080
  KonvaInteraction.prototype.tryCreateLinkToElement = function (sourcePortId, sourceElementId, targetElementId, worldPoint) {
12888
- var targetPort = this.createPortForLink(targetElementId, worldPoint, sourcePortId);
13081
+ var _a, _b;
13082
+ var targetPort = this.createPortForLink(targetElementId, worldPoint, sourcePortId, sourceElementId);
12889
13083
  if (!targetPort) {
12890
13084
  return { createdLinkId: null, targetPortId: null, targetElementId: null };
12891
13085
  }
@@ -12901,7 +13095,10 @@ var KonvaInteraction = /** @class */ (function () {
12901
13095
  return { createdLinkId: null, targetPortId: targetPort.id, targetElementId: targetElementId };
12902
13096
  }
12903
13097
  this.engine.addPortToElement(targetElementId, targetPort);
12904
- this.engine.movePortTo(targetPort.id, worldPoint.x, worldPoint.y);
13098
+ var targetElementWorld = (_a = this.engine.getElementWorldPosition(targetElementId)) !== null && _a !== void 0 ? _a : (_b = this.getElementById(targetElementId)) === null || _b === void 0 ? void 0 : _b.position;
13099
+ if (targetElementWorld) {
13100
+ this.engine.movePortTo(targetPort.id, targetElementWorld.x + targetPort.position.x, targetElementWorld.y + targetPort.position.y);
13101
+ }
12905
13102
  var createdLinkId = createId();
12906
13103
  this.engine.addLink({
12907
13104
  id: createdLinkId,
@@ -12911,61 +13108,139 @@ var KonvaInteraction = /** @class */ (function () {
12911
13108
  });
12912
13109
  return { createdLinkId: createdLinkId, targetPortId: targetPort.id, targetElementId: targetElementId };
12913
13110
  };
12914
- KonvaInteraction.prototype.createPortForLink = function (elementId, worldPoint, sourcePortId) {
12915
- var _a, _b, _c, _d;
12916
- var element = this.getElementById(elementId);
12917
- if (!element)
13111
+ KonvaInteraction.prototype.createPortForLink = function (elementId, worldPoint, sourcePortId, sourceElementId) {
13112
+ var resolved = this.resolveLinkTargetPortDraft(elementId, worldPoint, sourcePortId, sourceElementId, 'commit');
13113
+ if (!resolved)
12918
13114
  return null;
12919
- var elementPosition = (_a = this.engine.getElementWorldPosition(elementId)) !== null && _a !== void 0 ? _a : element.position;
12920
- var relative = {
12921
- x: worldPoint.x - elementPosition.x,
12922
- y: worldPoint.y - elementPosition.y,
12923
- };
12924
- var sourcePort = this.getPortById(sourcePortId);
12925
- var destinationMoveMode = ((_b = element.portMovement) === null || _b === void 0 ? void 0 : _b.moveMode) && element.portMovement.moveMode !== 'anchors'
12926
- ? element.portMovement.moveMode
12927
- : undefined;
12928
13115
  return {
12929
13116
  id: createId(),
12930
13117
  elementId: elementId,
12931
- position: relative,
12932
- shapeId: sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.shapeId,
12933
- size: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.size) ? __assign({}, sourcePort.size) : undefined,
12934
- style: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.style) ? __assign({}, sourcePort.style) : undefined,
12935
- moveMode: destinationMoveMode !== null && destinationMoveMode !== void 0 ? destinationMoveMode : sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.moveMode,
12936
- anchorCenter: (_c = sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.anchorCenter) !== null && _c !== void 0 ? _c : true,
12937
- orientToHostBorder: (_d = sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.orientToHostBorder) !== null && _d !== void 0 ? _d : true,
12938
- placementPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.placementPoint) ? __assign({}, sourcePort.placementPoint) : undefined,
12939
- linkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.linkAttachPoint) ? __assign({}, sourcePort.linkAttachPoint) : undefined,
12940
- externalLinkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.externalLinkAttachPoint) ? __assign({}, sourcePort.externalLinkAttachPoint) : undefined,
12941
- internalLinkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.internalLinkAttachPoint) ? __assign({}, sourcePort.internalLinkAttachPoint) : undefined,
12942
- rotationPivot: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.rotationPivot) ? __assign({}, sourcePort.rotationPivot) : undefined,
13118
+ position: __assign({}, resolved.draft.position),
13119
+ shapeId: resolved.draft.shapeId,
13120
+ size: resolved.draft.size ? __assign({}, resolved.draft.size) : undefined,
13121
+ style: resolved.draft.style ? __assign({}, resolved.draft.style) : undefined,
13122
+ textIds: resolved.draft.textIds ? __spreadArray([], resolved.draft.textIds, true) : undefined,
13123
+ moveMode: resolved.draft.moveMode,
13124
+ anchorCenter: resolved.draft.anchorCenter,
13125
+ orientToHostBorder: resolved.draft.orientToHostBorder,
13126
+ placementPoint: resolved.draft.placementPoint ? __assign({}, resolved.draft.placementPoint) : undefined,
13127
+ linkAttachPoint: resolved.draft.linkAttachPoint ? __assign({}, resolved.draft.linkAttachPoint) : undefined,
13128
+ externalLinkAttachPoint: resolved.draft.externalLinkAttachPoint ? __assign({}, resolved.draft.externalLinkAttachPoint) : undefined,
13129
+ internalLinkAttachPoint: resolved.draft.internalLinkAttachPoint ? __assign({}, resolved.draft.internalLinkAttachPoint) : undefined,
13130
+ rotationPivot: resolved.draft.rotationPivot ? __assign({}, resolved.draft.rotationPivot) : undefined,
13131
+ currentAnchorId: resolved.draft.currentAnchorId,
12943
13132
  };
12944
13133
  };
12945
- KonvaInteraction.prototype.createPlaceholderPort = function (elementId, worldPoint, sourcePortId) {
12946
- var _a, _b, _c;
12947
- var element = this.getElementById(elementId);
12948
- var sourcePort = this.getPortById(sourcePortId);
12949
- var destinationMoveMode = ((_a = element === null || element === void 0 ? void 0 : element.portMovement) === null || _a === void 0 ? void 0 : _a.moveMode) && element.portMovement.moveMode !== 'anchors'
12950
- ? element.portMovement.moveMode
12951
- : undefined;
13134
+ KonvaInteraction.prototype.createPlaceholderPort = function (elementId, worldPoint, sourcePortId, sourceElementId) {
13135
+ var _a;
13136
+ var resolved = this.resolveLinkTargetPortDraft(elementId, worldPoint, sourcePortId, sourceElementId, 'preview');
13137
+ if (!resolved)
13138
+ return null;
13139
+ var hostWorld = (_a = this.engine.getElementWorldPosition(elementId)) !== null && _a !== void 0 ? _a : resolved.targetElement.position;
12952
13140
  return {
12953
13141
  id: "port-placeholder:".concat(sourcePortId),
12954
13142
  elementId: elementId,
12955
- position: { x: worldPoint.x, y: worldPoint.y },
12956
- shapeId: sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.shapeId,
12957
- size: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.size) ? __assign({}, sourcePort.size) : undefined,
12958
- style: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.style) ? __assign({}, sourcePort.style) : undefined,
12959
- moveMode: destinationMoveMode !== null && destinationMoveMode !== void 0 ? destinationMoveMode : sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.moveMode,
12960
- anchorCenter: (_b = sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.anchorCenter) !== null && _b !== void 0 ? _b : true,
12961
- orientToHostBorder: (_c = sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.orientToHostBorder) !== null && _c !== void 0 ? _c : true,
12962
- placementPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.placementPoint) ? __assign({}, sourcePort.placementPoint) : undefined,
12963
- linkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.linkAttachPoint) ? __assign({}, sourcePort.linkAttachPoint) : undefined,
12964
- externalLinkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.externalLinkAttachPoint) ? __assign({}, sourcePort.externalLinkAttachPoint) : undefined,
12965
- internalLinkAttachPoint: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.internalLinkAttachPoint) ? __assign({}, sourcePort.internalLinkAttachPoint) : undefined,
12966
- rotationPivot: (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.rotationPivot) ? __assign({}, sourcePort.rotationPivot) : undefined,
13143
+ position: {
13144
+ x: hostWorld.x + resolved.draft.position.x,
13145
+ y: hostWorld.y + resolved.draft.position.y,
13146
+ },
13147
+ shapeId: resolved.draft.shapeId,
13148
+ size: resolved.draft.size ? __assign({}, resolved.draft.size) : undefined,
13149
+ style: resolved.draft.style ? __assign({}, resolved.draft.style) : undefined,
13150
+ textIds: resolved.draft.textIds ? __spreadArray([], resolved.draft.textIds, true) : undefined,
13151
+ moveMode: resolved.draft.moveMode,
13152
+ anchorCenter: resolved.draft.anchorCenter,
13153
+ orientToHostBorder: resolved.draft.orientToHostBorder,
13154
+ placementPoint: resolved.draft.placementPoint ? __assign({}, resolved.draft.placementPoint) : undefined,
13155
+ linkAttachPoint: resolved.draft.linkAttachPoint ? __assign({}, resolved.draft.linkAttachPoint) : undefined,
13156
+ externalLinkAttachPoint: resolved.draft.externalLinkAttachPoint ? __assign({}, resolved.draft.externalLinkAttachPoint) : undefined,
13157
+ internalLinkAttachPoint: resolved.draft.internalLinkAttachPoint ? __assign({}, resolved.draft.internalLinkAttachPoint) : undefined,
13158
+ rotationPivot: resolved.draft.rotationPivot ? __assign({}, resolved.draft.rotationPivot) : undefined,
13159
+ currentAnchorId: resolved.draft.currentAnchorId,
13160
+ };
13161
+ };
13162
+ KonvaInteraction.prototype.resolveLinkTargetPortDraft = function (elementId, worldPoint, sourcePortId, sourceElementId, phase) {
13163
+ var _a;
13164
+ var targetElement = this.getElementById(elementId);
13165
+ var sourcePort = this.resolveLinkSourcePort(sourcePortId);
13166
+ if (!targetElement || !sourcePort)
13167
+ return null;
13168
+ var defaultDraft = this.buildDefaultLinkTargetPortDraft(targetElement, worldPoint, sourcePort);
13169
+ var override = (_a = this.onCreateLinkTargetPort) === null || _a === void 0 ? void 0 : _a.call(this, {
13170
+ phase: phase,
13171
+ pointer: __assign({}, worldPoint),
13172
+ sourcePortId: sourcePortId,
13173
+ sourceElementId: sourceElementId,
13174
+ targetElementId: elementId,
13175
+ sourcePort: this.clonePortData(sourcePort),
13176
+ targetElement: this.cloneElementData(targetElement),
13177
+ defaultPort: this.cloneLinkTargetPortDraft(defaultDraft),
13178
+ });
13179
+ var mergedDraft = this.mergeLinkTargetPortDraft(defaultDraft, override);
13180
+ var normalizedDraft = this.engine.normalizePortDraftForElement(elementId, mergedDraft);
13181
+ if (!normalizedDraft)
13182
+ return null;
13183
+ return {
13184
+ draft: normalizedDraft,
13185
+ targetElement: this.cloneElementData(targetElement),
13186
+ };
13187
+ };
13188
+ KonvaInteraction.prototype.buildDefaultLinkTargetPortDraft = function (element, worldPoint, sourcePort) {
13189
+ var _a, _b, _c, _d;
13190
+ var elementPosition = (_a = this.engine.getElementWorldPosition(element.id)) !== null && _a !== void 0 ? _a : element.position;
13191
+ var destinationMoveMode = ((_b = element.portMovement) === null || _b === void 0 ? void 0 : _b.moveMode) && element.portMovement.moveMode !== 'anchors'
13192
+ ? element.portMovement.moveMode
13193
+ : undefined;
13194
+ return {
13195
+ position: {
13196
+ x: worldPoint.x - elementPosition.x,
13197
+ y: worldPoint.y - elementPosition.y,
13198
+ },
13199
+ shapeId: sourcePort.shapeId,
13200
+ size: sourcePort.size ? __assign({}, sourcePort.size) : undefined,
13201
+ style: sourcePort.style ? __assign({}, sourcePort.style) : undefined,
13202
+ moveMode: destinationMoveMode !== null && destinationMoveMode !== void 0 ? destinationMoveMode : sourcePort.moveMode,
13203
+ anchorCenter: (_c = sourcePort.anchorCenter) !== null && _c !== void 0 ? _c : true,
13204
+ orientToHostBorder: (_d = sourcePort.orientToHostBorder) !== null && _d !== void 0 ? _d : true,
13205
+ placementPoint: sourcePort.placementPoint ? __assign({}, sourcePort.placementPoint) : undefined,
13206
+ linkAttachPoint: sourcePort.linkAttachPoint ? __assign({}, sourcePort.linkAttachPoint) : undefined,
13207
+ externalLinkAttachPoint: sourcePort.externalLinkAttachPoint ? __assign({}, sourcePort.externalLinkAttachPoint) : undefined,
13208
+ internalLinkAttachPoint: sourcePort.internalLinkAttachPoint ? __assign({}, sourcePort.internalLinkAttachPoint) : undefined,
13209
+ rotationPivot: sourcePort.rotationPivot ? __assign({}, sourcePort.rotationPivot) : undefined,
12967
13210
  };
12968
13211
  };
13212
+ KonvaInteraction.prototype.mergeLinkTargetPortDraft = function (defaultDraft, override) {
13213
+ return this.cloneLinkTargetPortDraft(__assign(__assign({}, defaultDraft), (override !== null && override !== void 0 ? override : {})));
13214
+ };
13215
+ KonvaInteraction.prototype.resolveLinkSourcePort = function (sourcePortId) {
13216
+ var _a, _b;
13217
+ if (((_a = this.programmaticLinkSession) === null || _a === void 0 ? void 0 : _a.sourcePortId) === sourcePortId) {
13218
+ return this.clonePortData(this.programmaticLinkSession.sourcePort);
13219
+ }
13220
+ if (((_b = this.dragState) === null || _b === void 0 ? void 0 : _b.mode) === 'link-drag' && this.dragState.sourcePortId === sourcePortId) {
13221
+ return this.clonePortData(this.dragState.sourcePort);
13222
+ }
13223
+ var sourcePort = this.getPortById(sourcePortId);
13224
+ return sourcePort ? this.clonePortData(sourcePort) : null;
13225
+ };
13226
+ KonvaInteraction.prototype.clonePortData = function (port) {
13227
+ return __assign(__assign({}, port), { position: __assign({}, port.position), size: port.size ? __assign({}, port.size) : undefined, style: port.style ? __assign({}, port.style) : undefined, textIds: port.textIds ? __spreadArray([], port.textIds, true) : undefined, placementPoint: port.placementPoint ? __assign({}, port.placementPoint) : undefined, linkAttachPoint: port.linkAttachPoint ? __assign({}, port.linkAttachPoint) : undefined, externalLinkAttachPoint: port.externalLinkAttachPoint ? __assign({}, port.externalLinkAttachPoint) : undefined, internalLinkAttachPoint: port.internalLinkAttachPoint ? __assign({}, port.internalLinkAttachPoint) : undefined, rotationPivot: port.rotationPivot ? __assign({}, port.rotationPivot) : undefined });
13228
+ };
13229
+ KonvaInteraction.prototype.cloneLinkTargetPortDraft = function (draft) {
13230
+ return __assign(__assign({}, draft), { position: __assign({}, draft.position), size: draft.size ? __assign({}, draft.size) : undefined, style: draft.style ? __assign({}, draft.style) : undefined, textIds: draft.textIds ? __spreadArray([], draft.textIds, true) : undefined, placementPoint: draft.placementPoint ? __assign({}, draft.placementPoint) : undefined, linkAttachPoint: draft.linkAttachPoint ? __assign({}, draft.linkAttachPoint) : undefined, externalLinkAttachPoint: draft.externalLinkAttachPoint ? __assign({}, draft.externalLinkAttachPoint) : undefined, internalLinkAttachPoint: draft.internalLinkAttachPoint ? __assign({}, draft.internalLinkAttachPoint) : undefined, rotationPivot: draft.rotationPivot ? __assign({}, draft.rotationPivot) : undefined });
13231
+ };
13232
+ KonvaInteraction.prototype.cloneElementData = function (element) {
13233
+ return __assign(__assign({}, element), { position: __assign({}, element.position), size: __assign({}, element.size), style: element.style ? __assign({}, element.style) : undefined, portIds: element.portIds ? __spreadArray([], element.portIds, true) : undefined, textIds: element.textIds ? __spreadArray([], element.textIds, true) : undefined, layout: element.layout ? __assign({}, element.layout) : undefined, childElementInteraction: element.childElementInteraction ? __assign({}, element.childElementInteraction) : undefined, portMovement: element.portMovement
13234
+ ? __assign(__assign({}, element.portMovement), { anchorConstraint: element.portMovement.anchorConstraint
13235
+ ? __assign({}, element.portMovement.anchorConstraint) : undefined, positionLimits: element.portMovement.positionLimits
13236
+ ? {
13237
+ x: element.portMovement.positionLimits.x
13238
+ ? __assign({}, element.portMovement.positionLimits.x) : undefined,
13239
+ y: element.portMovement.positionLimits.y
13240
+ ? __assign({}, element.portMovement.positionLimits.y) : undefined,
13241
+ }
13242
+ : undefined }) : undefined });
13243
+ };
12969
13244
  KonvaInteraction.prototype.getElementById = function (id) {
12970
13245
  return this.engine.getState().elements.find(function (element) { return element.id === id; });
12971
13246
  };
@@ -14082,6 +14357,7 @@ var createDiagramEditor = function (config) {
14082
14357
  shapeHoverControls: config.elementShapeHoverControls,
14083
14358
  onShapeHoverControlInteracted: config.onElementShapeHoverControlInteraction,
14084
14359
  onShapeHoverControlActivated: config.onElementShapeHoverControlActivated,
14360
+ onCreateLinkTargetPort: config.onCreateLinkTargetPort,
14085
14361
  });
14086
14362
  interaction.bind();
14087
14363
  if (config.initialState) {
@@ -14181,7 +14457,7 @@ var useDisplayBoxMetricsUpdater = function () {
14181
14457
  };
14182
14458
 
14183
14459
  var useDemoEditor = function (_a) {
14184
- var createState = _a.createState, elementShapes = _a.elementShapes, portShapes = _a.portShapes, router = _a.router, snapDefault = _a.snapDefault, linkRouteRefreshPolicy = _a.linkRouteRefreshPolicy, linkColorPoolPolicy = _a.linkColorPoolPolicy, elementShapeHoverControls = _a.elementShapeHoverControls, onElementShapeHoverControlInteraction = _a.onElementShapeHoverControlInteraction, onElementShapeHoverControlActivated = _a.onElementShapeHoverControlActivated;
14460
+ var createState = _a.createState, elementShapes = _a.elementShapes, portShapes = _a.portShapes, router = _a.router, snapDefault = _a.snapDefault, linkRouteRefreshPolicy = _a.linkRouteRefreshPolicy, linkColorPoolPolicy = _a.linkColorPoolPolicy, elementShapeHoverControls = _a.elementShapeHoverControls, onElementShapeHoverControlInteraction = _a.onElementShapeHoverControlInteraction, onElementShapeHoverControlActivated = _a.onElementShapeHoverControlActivated, onCreateLinkTargetPort = _a.onCreateLinkTargetPort;
14185
14461
  var containerRef = React.useRef(null);
14186
14462
  var editorRef = React.useRef(null);
14187
14463
  var _b = React.useState(null), diagramState = _b[0], setDiagramState = _b[1];
@@ -14228,6 +14504,7 @@ var useDemoEditor = function (_a) {
14228
14504
  elementShapeHoverControls: elementShapeHoverControls,
14229
14505
  onElementShapeHoverControlInteraction: onElementShapeHoverControlInteraction,
14230
14506
  onElementShapeHoverControlActivated: onElementShapeHoverControlActivated,
14507
+ onCreateLinkTargetPort: onCreateLinkTargetPort,
14231
14508
  onChange: function (event) {
14232
14509
  setDiagramState(event.state);
14233
14510
  var viewportPatch = event.patches.find(function (patch) { return patch.entity === 'viewport'; });
@@ -14275,6 +14552,7 @@ var useDemoEditor = function (_a) {
14275
14552
  elementShapeHoverControls,
14276
14553
  onElementShapeHoverControlInteraction,
14277
14554
  onElementShapeHoverControlActivated,
14555
+ onCreateLinkTargetPort,
14278
14556
  ]);
14279
14557
  return {
14280
14558
  containerRef: containerRef,
@@ -14622,6 +14900,66 @@ var LinkCancelDemo = function () {
14622
14900
  React.createElement(DisplayBoxStage, { containerRef: containerRef })));
14623
14901
  };
14624
14902
 
14903
+ var LinkPortCreationDemo = function () {
14904
+ var _a = React.useState(false), useHostTargetPort = _a[0], setUseHostTargetPort = _a[1];
14905
+ var onCreateLinkTargetPort = React.useMemo(function () {
14906
+ if (!useHostTargetPort)
14907
+ return undefined;
14908
+ return function (_a) {
14909
+ var defaultPort = _a.defaultPort;
14910
+ return ({
14911
+ shapeId: 'port-dark',
14912
+ size: { width: 16, height: 16 },
14913
+ style: {
14914
+ fill: '#f97316',
14915
+ stroke: '#9a3412',
14916
+ strokeWidth: 2,
14917
+ name: 'port',
14918
+ },
14919
+ position: {
14920
+ x: defaultPort.position.x,
14921
+ y: 24,
14922
+ },
14923
+ orientToHostBorder: false,
14924
+ });
14925
+ };
14926
+ }, [useHostTargetPort]);
14927
+ var _b = useDemoEditor({
14928
+ createState: linkPortCreationDemoConfig.createState,
14929
+ elementShapes: linkPortCreationDemoConfig.elementShapes,
14930
+ portShapes: linkPortCreationDemoConfig.portShapes,
14931
+ router: linkPortCreationDemoConfig.router,
14932
+ snapDefault: linkPortCreationDemoConfig.snapDefault,
14933
+ linkRouteRefreshPolicy: linkPortCreationDemoConfig.linkRouteRefreshPolicy,
14934
+ linkColorPoolPolicy: linkPortCreationDemoConfig.linkColorPoolPolicy,
14935
+ onCreateLinkTargetPort: onCreateLinkTargetPort,
14936
+ }), containerRef = _b.containerRef, editorRef = _b.editorRef, diagramState = _b.diagramState, selection = _b.selection, snapEnabled = _b.snapEnabled, setSnapEnabled = _b.setSnapEnabled;
14937
+ var nextOffset = useOffsetSequence();
14938
+ var actionHelpers = React.useMemo(function () { return ({ nextOffset: nextOffset }); }, [nextOffset]);
14939
+ var controls = useDemoControls({
14940
+ demo: linkPortCreationDemoConfig,
14941
+ editorRef: editorRef,
14942
+ diagramState: diagramState,
14943
+ selection: selection,
14944
+ snapEnabled: snapEnabled,
14945
+ setSnapEnabled: setSnapEnabled,
14946
+ actionHelpers: actionHelpers,
14947
+ });
14948
+ return (React.createElement("section", null,
14949
+ React.createElement("div", { style: { marginBottom: 12 } },
14950
+ React.createElement("h2", { style: { marginTop: 0, marginBottom: 4 } }, linkPortCreationDemoConfig.title),
14951
+ React.createElement("p", { style: { marginTop: 0, marginBottom: 8 } }, linkPortCreationDemoConfig.description),
14952
+ React.createElement("label", { style: { display: 'inline-flex', alignItems: 'center', gap: 8, fontWeight: 600 } },
14953
+ React.createElement("input", { type: "checkbox", checked: useHostTargetPort, onChange: function (event) { return setUseHostTargetPort(event.target.checked); } }),
14954
+ "Customize target port via onCreateLinkTargetPort"),
14955
+ React.createElement("p", { style: { marginTop: 8, marginBottom: 0, color: '#5c4a2c' } },
14956
+ "Default mode clones the source port. Custom mode reshapes the target-port preview and commit together; host cancellation still belongs to ",
14957
+ React.createElement("code", null, "elementLinkConnecting"),
14958
+ ".")),
14959
+ React.createElement(DisplayBoxControls, { actions: linkPortCreationDemoConfig.actions, snapEnabled: controls.snapEnabled, selectedLinkRouting: controls.selectedLinkRouting, canToggleLinkRouting: controls.canToggleLinkRouting, onReload: controls.handleReload, onZoomIn: controls.handleZoomIn, onZoomOut: controls.handleZoomOut, onResetViewport: controls.handleResetViewport, onToggleSnap: controls.handleToggleSnap, onManualRender: controls.handleManualRender, onToggleLinkRouting: controls.handleToggleLinkRouting, onAction: controls.handleAction, onExportImage: controls.handleExportImage, onClearExportPreview: controls.handleClearExportPreview, exportPreviewDataUrl: controls.exportPreviewDataUrl, exportError: controls.exportError }),
14960
+ React.createElement(DisplayBoxStage, { containerRef: containerRef, stageStyle: linkPortCreationDemoConfig.stageStyle })));
14961
+ };
14962
+
14625
14963
  var parentOptions = [
14626
14964
  { id: 'layout-row', label: 'Horizontal layout' },
14627
14965
  { id: 'layout-column', label: 'Vertical layout' },
@@ -16987,218 +17325,86 @@ var VertexControlLinkSessionDemo = function () {
16987
17325
  };
16988
17326
 
16989
17327
  var wrapSimpleDemo = function (demo) { return function () { return React.createElement(SimpleDemo, { demo: demo }); }; };
16990
- var demoTabs = [
16991
- {
16992
- id: basicDemoConfig.id,
16993
- title: basicDemoConfig.title,
16994
- description: basicDemoConfig.description,
16995
- Component: wrapSimpleDemo(basicDemoConfig),
16996
- },
16997
- {
16998
- id: linkPortCreationDemoConfig.id,
16999
- title: linkPortCreationDemoConfig.title,
17000
- description: linkPortCreationDemoConfig.description,
17001
- Component: wrapSimpleDemo(linkPortCreationDemoConfig),
17002
- },
17003
- {
17004
- id: nestedDemoConfig.id,
17005
- title: nestedDemoConfig.title,
17006
- description: nestedDemoConfig.description,
17007
- Component: wrapSimpleDemo(nestedDemoConfig),
17008
- },
17009
- {
17010
- id: customDemoConfig.id,
17011
- title: customDemoConfig.title,
17012
- description: customDemoConfig.description,
17013
- Component: wrapSimpleDemo(customDemoConfig),
17014
- },
17015
- {
17016
- id: textDemoConfig.id,
17017
- title: textDemoConfig.title,
17018
- description: textDemoConfig.description,
17019
- Component: TextLayoutDemo,
17020
- },
17021
- {
17022
- id: selectionDemoConfig.id,
17023
- title: selectionDemoConfig.title,
17024
- description: selectionDemoConfig.description,
17025
- Component: wrapSimpleDemo(selectionDemoConfig),
17026
- },
17027
- {
17028
- id: elementVisibilitySelectionDemoConfig.id,
17029
- title: elementVisibilitySelectionDemoConfig.title,
17030
- description: elementVisibilitySelectionDemoConfig.description,
17031
- Component: wrapSimpleDemo(elementVisibilitySelectionDemoConfig),
17032
- },
17033
- {
17034
- id: eventHandlersDemoConfig.id,
17035
- title: eventHandlersDemoConfig.title,
17036
- description: eventHandlersDemoConfig.description,
17037
- Component: EventHandlersDemo,
17038
- },
17039
- {
17040
- id: engineEventsDemoConfig.id,
17041
- title: engineEventsDemoConfig.title,
17042
- description: engineEventsDemoConfig.description,
17043
- Component: EngineEventsDemo,
17044
- },
17045
- {
17046
- id: deletionEventsDemoConfig.id,
17047
- title: deletionEventsDemoConfig.title,
17048
- description: deletionEventsDemoConfig.description,
17049
- Component: DeletionEventsDemo,
17050
- },
17051
- {
17052
- id: autoLayoutDemoConfig.id,
17053
- title: autoLayoutDemoConfig.title,
17054
- description: autoLayoutDemoConfig.description,
17055
- Component: AutoLayoutDemo,
17056
- },
17057
- {
17058
- id: linkCancelDemoConfig.id,
17059
- title: linkCancelDemoConfig.title,
17060
- description: linkCancelDemoConfig.description,
17061
- Component: LinkCancelDemo,
17062
- },
17063
- {
17064
- id: externalDragDropDemoConfig.id,
17065
- title: externalDragDropDemoConfig.title,
17066
- description: externalDragDropDemoConfig.description,
17067
- Component: ExternalDragDropDemo,
17068
- },
17069
- {
17070
- id: shapeGalleryDemoConfig.id,
17071
- title: shapeGalleryDemoConfig.title,
17072
- description: shapeGalleryDemoConfig.description,
17073
- Component: wrapSimpleDemo(shapeGalleryDemoConfig),
17074
- },
17075
- {
17076
- id: roundedRectRadiusDemoConfig.id,
17077
- title: roundedRectRadiusDemoConfig.title,
17078
- description: roundedRectRadiusDemoConfig.description,
17079
- Component: wrapSimpleDemo(roundedRectRadiusDemoConfig),
17080
- },
17081
- {
17082
- id: rotatedCreationDemoConfig.id,
17083
- title: rotatedCreationDemoConfig.title,
17084
- description: rotatedCreationDemoConfig.description,
17085
- Component: wrapSimpleDemo(rotatedCreationDemoConfig),
17086
- },
17087
- {
17088
- id: svgPathDemoConfig.id,
17089
- title: svgPathDemoConfig.title,
17090
- description: svgPathDemoConfig.description,
17091
- Component: SvgPathDemo,
17092
- },
17093
- {
17094
- id: asymmetricPortMultiAnchorDemoConfig.id,
17095
- title: asymmetricPortMultiAnchorDemoConfig.title,
17096
- description: asymmetricPortMultiAnchorDemoConfig.description,
17097
- Component: AsymmetricPortMultiAnchorDemo,
17098
- },
17099
- {
17100
- id: multiLevelTreeDemoConfig.id,
17101
- title: multiLevelTreeDemoConfig.title,
17102
- description: multiLevelTreeDemoConfig.description,
17103
- Component: wrapSimpleDemo(multiLevelTreeDemoConfig),
17104
- },
17105
- {
17106
- id: multipleElementsDemoConfig.id,
17107
- title: multipleElementsDemoConfig.title,
17108
- description: multipleElementsDemoConfig.description,
17109
- Component: wrapSimpleDemo(multipleElementsDemoConfig),
17110
- },
17111
- {
17112
- id: portConstraintsDemoConfig.id,
17113
- title: portConstraintsDemoConfig.title,
17114
- description: portConstraintsDemoConfig.description,
17115
- Component: wrapSimpleDemo(portConstraintsDemoConfig),
17116
- },
17117
- {
17118
- id: portPositionLimitsDemoConfig.id,
17119
- title: portPositionLimitsDemoConfig.title,
17120
- description: portPositionLimitsDemoConfig.description,
17121
- Component: wrapSimpleDemo(portPositionLimitsDemoConfig),
17122
- },
17123
- {
17124
- id: labelStyleDemoConfig.id,
17125
- title: labelStyleDemoConfig.title,
17126
- description: labelStyleDemoConfig.description,
17127
- Component: wrapSimpleDemo(labelStyleDemoConfig),
17128
- },
17129
- {
17130
- id: linkColorPoolDemoConfig.id,
17131
- title: linkColorPoolDemoConfig.title,
17132
- description: linkColorPoolDemoConfig.description,
17133
- Component: LinkColorPoolDemo,
17134
- },
17135
- {
17136
- id: portBorderDemoConfig.id,
17137
- title: portBorderDemoConfig.title,
17138
- description: portBorderDemoConfig.description,
17139
- Component: wrapSimpleDemo(portBorderDemoConfig),
17140
- },
17141
- {
17142
- id: shapeBorderMovementDemoConfig.id,
17143
- title: shapeBorderMovementDemoConfig.title,
17144
- description: shapeBorderMovementDemoConfig.description,
17145
- Component: wrapSimpleDemo(shapeBorderMovementDemoConfig),
17146
- },
17147
- {
17148
- id: shapeHoverControlsDemoConfig.id,
17149
- title: shapeHoverControlsDemoConfig.title,
17150
- description: shapeHoverControlsDemoConfig.description,
17151
- Component: ShapeHoverControlsDemo,
17152
- },
17153
- {
17154
- id: vertexControlLinkSessionDemoConfig.id,
17155
- title: vertexControlLinkSessionDemoConfig.title,
17156
- description: vertexControlLinkSessionDemoConfig.description,
17157
- Component: VertexControlLinkSessionDemo,
17158
- },
17159
- {
17160
- id: childConstraintsDemoConfig.id,
17161
- title: childConstraintsDemoConfig.title,
17162
- description: childConstraintsDemoConfig.description,
17163
- Component: wrapSimpleDemo(childConstraintsDemoConfig),
17164
- },
17165
- {
17166
- id: gridOverlayDemoConfig.id,
17167
- title: gridOverlayDemoConfig.title,
17168
- description: gridOverlayDemoConfig.description,
17169
- Component: wrapSimpleDemo(gridOverlayDemoConfig),
17170
- },
17171
- {
17172
- id: routingDemoConfig.id,
17173
- title: routingDemoConfig.title,
17174
- description: routingDemoConfig.description,
17175
- Component: wrapSimpleDemo(routingDemoConfig),
17176
- },
17177
- {
17178
- id: obstacleRoutingDemoConfig.id,
17179
- title: obstacleRoutingDemoConfig.title,
17180
- description: obstacleRoutingDemoConfig.description,
17181
- Component: ObstacleRoutingDemo,
17182
- },
17183
- {
17184
- id: offsetAnchorAvoidanceDemoConfig.id,
17185
- title: offsetAnchorAvoidanceDemoConfig.title,
17186
- description: offsetAnchorAvoidanceDemoConfig.description,
17187
- Component: OffsetAnchorAvoidanceDemo,
17188
- },
17189
- {
17190
- id: zoomToFitElementsDemoConfig.id,
17191
- title: zoomToFitElementsDemoConfig.title,
17192
- description: zoomToFitElementsDemoConfig.description,
17193
- Component: ZoomToFitElementsDemo,
17194
- },
17195
- {
17196
- id: linkBendHandlesDemoConfig.id,
17197
- title: linkBendHandlesDemoConfig.title,
17198
- description: linkBendHandlesDemoConfig.description,
17199
- Component: wrapSimpleDemo(linkBendHandlesDemoConfig),
17200
- },
17201
- ];
17328
+ var menuGroupOrder = {
17329
+ basics: 1,
17330
+ layoutText: 2,
17331
+ shapes: 3,
17332
+ portsAnchors: 4,
17333
+ linksRouting: 5,
17334
+ eventsIntegration: 6,
17335
+ };
17336
+ var registerDemo = function (demo, Component, menuGroup, menuOrder) { return ({
17337
+ demo: demo,
17338
+ Component: Component,
17339
+ menuGroup: menuGroup,
17340
+ menuOrder: menuOrder,
17341
+ }); };
17342
+ var toDemoDefinition = function (_a) {
17343
+ var demo = _a.demo, Component = _a.Component, menuGroup = _a.menuGroup, menuOrder = _a.menuOrder;
17344
+ return ({
17345
+ id: demo.id,
17346
+ title: demo.title,
17347
+ description: demo.description,
17348
+ Component: Component,
17349
+ menuGroup: menuGroup,
17350
+ menuOrder: menuOrder,
17351
+ });
17352
+ };
17353
+ var compareDemoDefinitions = function (left, right) {
17354
+ return menuGroupOrder[left.menuGroup] - menuGroupOrder[right.menuGroup]
17355
+ || left.menuOrder - right.menuOrder
17356
+ || left.title.localeCompare(right.title);
17357
+ };
17358
+ var basics = [
17359
+ registerDemo(basicDemoConfig, wrapSimpleDemo(basicDemoConfig), 'basics', 1),
17360
+ registerDemo(multipleElementsDemoConfig, wrapSimpleDemo(multipleElementsDemoConfig), 'basics', 2),
17361
+ registerDemo(nestedDemoConfig, wrapSimpleDemo(nestedDemoConfig), 'basics', 3),
17362
+ registerDemo(selectionDemoConfig, wrapSimpleDemo(selectionDemoConfig), 'basics', 4),
17363
+ registerDemo(elementVisibilitySelectionDemoConfig, wrapSimpleDemo(elementVisibilitySelectionDemoConfig), 'basics', 5),
17364
+ registerDemo(zoomToFitElementsDemoConfig, ZoomToFitElementsDemo, 'basics', 6),
17365
+ ];
17366
+ var layoutAndText = [
17367
+ registerDemo(textDemoConfig, TextLayoutDemo, 'layoutText', 1),
17368
+ registerDemo(labelStyleDemoConfig, wrapSimpleDemo(labelStyleDemoConfig), 'layoutText', 2),
17369
+ registerDemo(autoLayoutDemoConfig, AutoLayoutDemo, 'layoutText', 3),
17370
+ registerDemo(multiLevelTreeDemoConfig, wrapSimpleDemo(multiLevelTreeDemoConfig), 'layoutText', 4),
17371
+ registerDemo(childConstraintsDemoConfig, wrapSimpleDemo(childConstraintsDemoConfig), 'layoutText', 5),
17372
+ registerDemo(gridOverlayDemoConfig, wrapSimpleDemo(gridOverlayDemoConfig), 'layoutText', 6),
17373
+ ];
17374
+ var shapes = [
17375
+ registerDemo(customDemoConfig, wrapSimpleDemo(customDemoConfig), 'shapes', 1),
17376
+ registerDemo(shapeGalleryDemoConfig, wrapSimpleDemo(shapeGalleryDemoConfig), 'shapes', 2),
17377
+ registerDemo(roundedRectRadiusDemoConfig, wrapSimpleDemo(roundedRectRadiusDemoConfig), 'shapes', 3),
17378
+ registerDemo(rotatedCreationDemoConfig, wrapSimpleDemo(rotatedCreationDemoConfig), 'shapes', 4),
17379
+ registerDemo(svgPathDemoConfig, SvgPathDemo, 'shapes', 5),
17380
+ registerDemo(shapeBorderMovementDemoConfig, wrapSimpleDemo(shapeBorderMovementDemoConfig), 'shapes', 6),
17381
+ registerDemo(shapeHoverControlsDemoConfig, ShapeHoverControlsDemo, 'shapes', 7),
17382
+ ];
17383
+ var portsAndAnchors = [
17384
+ registerDemo(linkPortCreationDemoConfig, LinkPortCreationDemo, 'portsAnchors', 1),
17385
+ registerDemo(portConstraintsDemoConfig, wrapSimpleDemo(portConstraintsDemoConfig), 'portsAnchors', 2),
17386
+ registerDemo(portPositionLimitsDemoConfig, wrapSimpleDemo(portPositionLimitsDemoConfig), 'portsAnchors', 3),
17387
+ registerDemo(portBorderDemoConfig, wrapSimpleDemo(portBorderDemoConfig), 'portsAnchors', 4),
17388
+ registerDemo(asymmetricPortMultiAnchorDemoConfig, AsymmetricPortMultiAnchorDemo, 'portsAnchors', 5),
17389
+ ];
17390
+ var linksAndRouting = [
17391
+ registerDemo(linkCancelDemoConfig, LinkCancelDemo, 'linksRouting', 1),
17392
+ registerDemo(linkBendHandlesDemoConfig, wrapSimpleDemo(linkBendHandlesDemoConfig), 'linksRouting', 2),
17393
+ registerDemo(linkLabelsDemoConfig, wrapSimpleDemo(linkLabelsDemoConfig), 'linksRouting', 3),
17394
+ registerDemo(linkColorPoolDemoConfig, LinkColorPoolDemo, 'linksRouting', 4),
17395
+ registerDemo(routingDemoConfig, wrapSimpleDemo(routingDemoConfig), 'linksRouting', 5),
17396
+ registerDemo(obstacleRoutingDemoConfig, ObstacleRoutingDemo, 'linksRouting', 6),
17397
+ registerDemo(offsetAnchorAvoidanceDemoConfig, OffsetAnchorAvoidanceDemo, 'linksRouting', 7),
17398
+ registerDemo(vertexControlLinkSessionDemoConfig, VertexControlLinkSessionDemo, 'linksRouting', 8),
17399
+ ];
17400
+ var eventsAndIntegration = [
17401
+ registerDemo(eventHandlersDemoConfig, EventHandlersDemo, 'eventsIntegration', 1),
17402
+ registerDemo(engineEventsDemoConfig, EngineEventsDemo, 'eventsIntegration', 2),
17403
+ registerDemo(deletionEventsDemoConfig, DeletionEventsDemo, 'eventsIntegration', 3),
17404
+ registerDemo(externalDragDropDemoConfig, ExternalDragDropDemo, 'eventsIntegration', 4),
17405
+ ];
17406
+ var demoTabs = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], basics, true), layoutAndText, true), shapes, true), portsAndAnchors, true), linksAndRouting, true), eventsAndIntegration, true).map(toDemoDefinition)
17407
+ .sort(compareDemoDefinitions);
17202
17408
 
17203
17409
  exports.baseElementShapes = baseElementShapes;
17204
17410
  exports.basePortShapes = basePortShapes;