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