orcasvn-react-diagrams 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -91,6 +91,7 @@ var ElementModel = /** @class */ (function () {
91
91
  this.moveMode = data.moveMode;
92
92
  this.anchorCenter = data.anchorCenter;
93
93
  this.layout = data.layout;
94
+ this.childElementInteraction = data.childElementInteraction;
94
95
  this.portMovement = data.portMovement;
95
96
  }
96
97
  ElementModel.prototype.setPosition = function (position) {
@@ -128,6 +129,7 @@ var ElementModel = /** @class */ (function () {
128
129
  moveMode: this.moveMode,
129
130
  anchorCenter: this.anchorCenter,
130
131
  layout: this.layout,
132
+ childElementInteraction: this.childElementInteraction,
131
133
  portMovement: this.portMovement,
132
134
  };
133
135
  };
@@ -4408,9 +4410,7 @@ var DiagramEngine = /** @class */ (function () {
4408
4410
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4409
4411
  if (!parentId)
4410
4412
  return false;
4411
- if (this.model.getChildren(element.id).length > 0)
4412
- return false;
4413
- if (element.layout && element.layout.mode !== 'manual')
4413
+ if (!this.isLeafGridChildResizeCandidate(element))
4414
4414
  return false;
4415
4415
  var parent = this.model.getElement(parentId);
4416
4416
  if (((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid')
@@ -4418,16 +4418,7 @@ var DiagramEngine = /** @class */ (function () {
4418
4418
  return !Boolean(parent.layout.gridChildWidthResizeEnabled);
4419
4419
  };
4420
4420
  DiagramEngine.prototype.shouldAnchorAutoLayoutGridChildWidthToLeft = function (element) {
4421
- var _a, _b;
4422
- var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4423
- if (!parentId)
4424
- return false;
4425
- if (this.model.getChildren(element.id).length > 0)
4426
- return false;
4427
- if (element.layout && element.layout.mode !== 'manual')
4428
- return false;
4429
- var parent = this.model.getElement(parentId);
4430
- return Boolean(((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) === 'grid' && parent.layout.gridChildWidthResizeEnabled);
4421
+ return this.isEnabledGridChildWidthResizeCandidate(element);
4431
4422
  };
4432
4423
  DiagramEngine.prototype.shouldRestrictAutoLayoutChildRightGrowth = function (element, handle, requestedWidth) {
4433
4424
  return false;
@@ -4437,41 +4428,55 @@ var DiagramEngine = /** @class */ (function () {
4437
4428
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4438
4429
  if (!parentId)
4439
4430
  return requestedWidth;
4440
- if (this.model.getChildren(element.id).length > 0)
4441
- return requestedWidth;
4442
- if (element.layout && element.layout.mode !== 'manual')
4443
- return requestedWidth;
4444
- var parent = this.model.getElement(parentId);
4445
- if (!(parent === null || parent === void 0 ? void 0 : parent.layout) || parent.layout.mode !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
4431
+ if (!this.isEnabledGridChildWidthResizeCandidate(element))
4446
4432
  return requestedWidth;
4447
4433
  return this.autoLayoutService.snapGridChildRequestedWidth(parentId, element.id, requestedWidth);
4448
4434
  };
4449
4435
  DiagramEngine.prototype.resolveGridChildWidthResizeTopologyChange = function (element, requestedWidth) {
4450
- var _a, _b, _c;
4436
+ var _a, _b;
4451
4437
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4452
4438
  if (!parentId)
4453
4439
  return null;
4454
- if (this.model.getChildren(element.id).length > 0)
4455
- return null;
4456
- if (element.layout && element.layout.mode !== 'manual')
4440
+ if (!this.isEnabledGridChildWidthResizeCandidate(element))
4457
4441
  return null;
4458
4442
  var parent = this.model.getElement(parentId);
4459
- if (!parent || ((_b = parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
4443
+ if (!parent)
4460
4444
  return null;
4461
4445
  var topologyChange = this.autoLayoutService.resolveGridChildResizeTopologyChange(parentId, element.id, requestedWidth);
4462
4446
  if (!topologyChange)
4463
4447
  return null;
4448
+ var parentLayout = parent.layout;
4449
+ if (!parentLayout)
4450
+ return null;
4464
4451
  return {
4465
4452
  parentId: topologyChange.parentId,
4466
4453
  triggerChildId: topologyChange.triggerChildId,
4467
4454
  reason: topologyChange.reason,
4468
4455
  beforeRows: topologyChange.beforeRows,
4469
4456
  afterRows: topologyChange.afterRows,
4470
- beforeGridTemplate: parent.layout.gridTemplate ? __spreadArray([], parent.layout.gridTemplate, true) : undefined,
4471
- afterGridTemplate: __spreadArray([], ((_c = topologyChange.nextLayout.gridTemplate) !== null && _c !== void 0 ? _c : []), true),
4457
+ beforeGridTemplate: parentLayout.gridTemplate ? __spreadArray([], parentLayout.gridTemplate, true) : undefined,
4458
+ afterGridTemplate: __spreadArray([], ((_b = topologyChange.nextLayout.gridTemplate) !== null && _b !== void 0 ? _b : []), true),
4472
4459
  afterLayout: topologyChange.nextLayout,
4473
4460
  };
4474
4461
  };
4462
+ DiagramEngine.prototype.isLeafGridChildResizeCandidate = function (element) {
4463
+ if (this.model.getChildren(element.id).length > 0)
4464
+ return false;
4465
+ if (element.layout && element.layout.mode !== 'manual')
4466
+ return false;
4467
+ return true;
4468
+ };
4469
+ DiagramEngine.prototype.isEnabledGridChildWidthResizeCandidate = function (element) {
4470
+ var _a;
4471
+ var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4472
+ if (!parentId)
4473
+ return false;
4474
+ var parent = this.model.getElement(parentId);
4475
+ var layout = parent === null || parent === void 0 ? void 0 : parent.layout;
4476
+ if (!layout || layout.mode !== 'grid')
4477
+ return false;
4478
+ return Boolean(layout.gridChildWidthResizeEnabled);
4479
+ };
4475
4480
  DiagramEngine.prototype.getPortWorldPosition = function (id) {
4476
4481
  return this.model.getPortWorldPosition(id);
4477
4482
  };
@@ -6378,7 +6383,7 @@ var ellipseMidPointToIndex = function (value) {
6378
6383
  var KonvaInteraction = /** @class */ (function () {
6379
6384
  function KonvaInteraction(engine, config) {
6380
6385
  if (config === void 0) { config = {}; }
6381
- var _a, _b;
6386
+ var _a;
6382
6387
  this.linkDragContext = null;
6383
6388
  this.programmaticLinkSession = null;
6384
6389
  this.bound = false;
@@ -6402,7 +6407,6 @@ var KonvaInteraction = /** @class */ (function () {
6402
6407
  this.stage = config.stage;
6403
6408
  this.hitTester = (_a = config.hitTester) !== null && _a !== void 0 ? _a : new KonvaHitTester();
6404
6409
  this.renderer = config.renderer;
6405
- this.panKey = (_b = config.panKey) !== null && _b !== void 0 ? _b : 'Control';
6406
6410
  this.shapeRegistry = config.shapeRegistry;
6407
6411
  this.shapeHoverControls = this.normalizeShapeHoverControls(config.shapeHoverControls);
6408
6412
  this.onShapeHoverControlInteracted = config.onShapeHoverControlInteracted;
@@ -6570,7 +6574,10 @@ var KonvaInteraction = /** @class */ (function () {
6570
6574
  var hit = _this.resolveHit(point);
6571
6575
  var nativeEvent = event === null || event === void 0 ? void 0 : event.evt;
6572
6576
  var isMulti = Boolean(nativeEvent && (nativeEvent.ctrlKey || nativeEvent.metaKey || nativeEvent.shiftKey));
6573
- var isPanGesture = Boolean(nativeEvent && _this.isPanKeyPressed(nativeEvent) && nativeEvent.button === 0);
6577
+ var isPrimaryButton = !nativeEvent || nativeEvent.button === 0;
6578
+ var isEmptyPaper = !hit || hit.type === 'none';
6579
+ var isMarqueeGesture = Boolean(isPrimaryButton && isEmptyPaper && (nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.shiftKey));
6580
+ var isPanGesture = Boolean(isPrimaryButton && isEmptyPaper && !(nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.shiftKey));
6574
6581
  var pointerInfo = _this.buildPointerInfo(point, nativeEvent);
6575
6582
  if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'shape-hover-control') {
6576
6583
  var resolvedControl = _this.resolveShapeHoverControlFromHit(hit.id, point);
@@ -6628,11 +6635,14 @@ var KonvaInteraction = /** @class */ (function () {
6628
6635
  }
6629
6636
  return;
6630
6637
  }
6631
- if (!hit || hit.type === 'none') {
6638
+ if (isMarqueeGesture) {
6632
6639
  _this.dragState = { mode: 'marquee', start: point, isMulti: isMulti, hasMoved: false };
6633
6640
  (_d = _this.renderer) === null || _d === void 0 ? void 0 : _d.renderMarquee({ x: point.x, y: point.y, width: 0, height: 0 });
6634
6641
  return;
6635
6642
  }
6643
+ if (isEmptyPaper) {
6644
+ return;
6645
+ }
6636
6646
  if (hit.type === 'port') {
6637
6647
  var elementId = _this.engine.getPortElementId(hit.id);
6638
6648
  if (!elementId)
@@ -6697,6 +6707,7 @@ var KonvaInteraction = /** @class */ (function () {
6697
6707
  var element = _this.getElementById(hit.id);
6698
6708
  if (!element)
6699
6709
  return;
6710
+ var movable = _this.isElementMovable(hit.id);
6700
6711
  var anchor = element.anchorCenter ? 'center' : 'top-left';
6701
6712
  var base = element.anchorCenter
6702
6713
  ? {
@@ -6711,12 +6722,13 @@ var KonvaInteraction = /** @class */ (function () {
6711
6722
  offset: { x: point.x - base.x, y: point.y - base.y },
6712
6723
  start: __assign({}, base),
6713
6724
  anchor: anchor,
6725
+ movable: movable,
6714
6726
  startParentId: (_e = element.parentId) !== null && _e !== void 0 ? _e : null,
6715
6727
  selectionIds: _this.engine.getSelection(),
6716
6728
  isMulti: isMulti,
6717
6729
  hasMoved: false,
6718
6730
  };
6719
- _this.setCursor('grabbing');
6731
+ _this.setCursor(movable ? 'grabbing' : 'pointer');
6720
6732
  }
6721
6733
  }
6722
6734
  };
@@ -6774,6 +6786,9 @@ var KonvaInteraction = /** @class */ (function () {
6774
6786
  var dy = target.y - _this.dragState.start.y;
6775
6787
  var moved = Math.hypot(dx, dy) >= _this.dragThreshold;
6776
6788
  _this.dragState.hasMoved = _this.dragState.hasMoved || moved;
6789
+ if (!_this.dragState.movable) {
6790
+ return;
6791
+ }
6777
6792
  _this.engine.moveElementTo(_this.dragState.id, target.x, target.y);
6778
6793
  if (_this.renderer && _this.engine.getSelection().includes(_this.dragState.id)) {
6779
6794
  var element = _this.getElementById(_this.dragState.id);
@@ -6899,15 +6914,15 @@ var KonvaInteraction = /** @class */ (function () {
6899
6914
  var dx = point.x - _this.dragState.start.x;
6900
6915
  var dy = point.y - _this.dragState.start.y;
6901
6916
  _this.pan = {
6902
- x: _this.dragState.origin.x - dx * _this.panSpeed,
6903
- y: _this.dragState.origin.y - dy * _this.panSpeed,
6917
+ x: _this.dragState.origin.x + dx * _this.panSpeed,
6918
+ y: _this.dragState.origin.y + dy * _this.panSpeed,
6904
6919
  };
6905
6920
  _this.applyStageTransform();
6906
6921
  _this.engine.setViewport(_this.pan, _this.zoom);
6907
6922
  }
6908
6923
  };
6909
6924
  var pointerUp = function () {
6910
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6925
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6911
6926
  var args = [];
6912
6927
  for (var _i = 0; _i < arguments.length; _i++) {
6913
6928
  args[_i] = arguments[_i];
@@ -7001,10 +7016,21 @@ var KonvaInteraction = /** @class */ (function () {
7001
7016
  _this.engine.emitPaperClick(pointerInfo);
7002
7017
  }
7003
7018
  }
7004
- if (((_h = _this.dragState) === null || _h === void 0 ? void 0 : _h.mode) === 'move' && _this.dragState.type === 'element') {
7019
+ if (((_h = _this.dragState) === null || _h === void 0 ? void 0 : _h.mode) === 'pan') {
7020
+ var point = pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.dragState.start;
7021
+ var dx = point.x - _this.dragState.start.x;
7022
+ var dy = point.y - _this.dragState.start.y;
7023
+ var moved = Math.hypot(dx, dy) >= _this.dragThreshold;
7024
+ if (!moved) {
7025
+ _this.engine.setSelection([]);
7026
+ var pointerInfo = _this.buildPointerInfo(point, nativeEvent);
7027
+ _this.engine.emitPaperClick(pointerInfo);
7028
+ }
7029
+ }
7030
+ if (((_j = _this.dragState) === null || _j === void 0 ? void 0 : _j.mode) === 'move' && _this.dragState.type === 'element') {
7005
7031
  var element = _this.getElementById(_this.dragState.id);
7006
7032
  if (element) {
7007
- var endTopLeft = (_j = _this.engine.getElementWorldPosition(_this.dragState.id)) !== null && _j !== void 0 ? _j : element.position;
7033
+ var endTopLeft = (_k = _this.engine.getElementWorldPosition(_this.dragState.id)) !== null && _k !== void 0 ? _k : element.position;
7008
7034
  var endWorld = _this.dragState.anchor === 'center'
7009
7035
  ? {
7010
7036
  x: endTopLeft.x + element.size.width / 2,
@@ -7015,7 +7041,8 @@ var KonvaInteraction = /** @class */ (function () {
7015
7041
  x: endWorld.x - _this.dragState.start.x,
7016
7042
  y: endWorld.y - _this.dragState.start.y,
7017
7043
  };
7018
- var moved = _this.dragState.hasMoved || Math.hypot(delta.x, delta.y) > 0;
7044
+ var moved = _this.dragState.movable &&
7045
+ (_this.dragState.hasMoved || Math.hypot(delta.x, delta.y) > 0);
7019
7046
  if (moved) {
7020
7047
  _this.engine.emitElementDrop({
7021
7048
  elementId: _this.dragState.id,
@@ -7027,16 +7054,16 @@ var KonvaInteraction = /** @class */ (function () {
7027
7054
  anchor: _this.dragState.anchor,
7028
7055
  });
7029
7056
  }
7030
- else {
7057
+ else if (!_this.dragState.hasMoved) {
7031
7058
  var pointerInfo = _this.buildPointerInfo(pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.dragState.start, nativeEvent);
7032
7059
  _this.engine.emitElementClick(_this.dragState.id, pointerInfo, _this.dragState.isMulti);
7033
7060
  }
7034
7061
  }
7035
7062
  }
7036
- if (((_k = _this.dragState) === null || _k === void 0 ? void 0 : _k.mode) === 'move' && _this.dragState.type === 'port') {
7063
+ if (((_l = _this.dragState) === null || _l === void 0 ? void 0 : _l.mode) === 'move' && _this.dragState.type === 'port') {
7037
7064
  var elementId = _this.engine.getPortElementId(_this.dragState.id);
7038
7065
  if (elementId) {
7039
- var pointerInfo = _this.buildPointerInfo((_l = pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.engine.getPortWorldPosition(_this.dragState.id)) !== null && _l !== void 0 ? _l : { x: 0, y: 0 }, nativeEvent);
7066
+ var pointerInfo = _this.buildPointerInfo((_m = pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.engine.getPortWorldPosition(_this.dragState.id)) !== null && _m !== void 0 ? _m : { x: 0, y: 0 }, nativeEvent);
7040
7067
  _this.engine.emitPortMouseUp({ portId: _this.dragState.id, elementId: elementId, pointer: pointerInfo });
7041
7068
  }
7042
7069
  }
@@ -7342,6 +7369,10 @@ var KonvaInteraction = /** @class */ (function () {
7342
7369
  this.setCursor('pointer');
7343
7370
  return;
7344
7371
  }
7372
+ if (hit.type === 'element' && !this.isElementMovable(hit.id)) {
7373
+ this.setCursor('pointer');
7374
+ return;
7375
+ }
7345
7376
  this.setCursor('grab');
7346
7377
  };
7347
7378
  KonvaInteraction.prototype.normalizeShapeHoverControls = function (controls) {
@@ -8567,6 +8598,14 @@ var KonvaInteraction = /** @class */ (function () {
8567
8598
  var _a, _b;
8568
8599
  return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.movable) !== false;
8569
8600
  };
8601
+ KonvaInteraction.prototype.isElementMovable = function (id) {
8602
+ var _a;
8603
+ var element = this.getElementById(id);
8604
+ if (!(element === null || element === void 0 ? void 0 : element.parentId))
8605
+ return true;
8606
+ var parent = this.getElementById(element.parentId);
8607
+ return ((_a = parent === null || parent === void 0 ? void 0 : parent.childElementInteraction) === null || _a === void 0 ? void 0 : _a.movable) !== false;
8608
+ };
8570
8609
  KonvaInteraction.prototype.isTextEditable = function (id) {
8571
8610
  var _a, _b;
8572
8611
  return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.editable) !== false;
@@ -8685,19 +8724,6 @@ var KonvaInteraction = /** @class */ (function () {
8685
8724
  var tag = target.tagName.toLowerCase();
8686
8725
  return tag === 'input' || tag === 'textarea' || tag === 'select';
8687
8726
  };
8688
- KonvaInteraction.prototype.isPanKeyPressed = function (event) {
8689
- switch (this.panKey) {
8690
- case 'Shift':
8691
- return event.shiftKey;
8692
- case 'Alt':
8693
- return event.altKey;
8694
- case 'Meta':
8695
- return event.metaKey;
8696
- case 'Control':
8697
- default:
8698
- return event.ctrlKey;
8699
- }
8700
- };
8701
8727
  return KonvaInteraction;
8702
8728
  }());
8703
8729
 
@@ -29,6 +29,9 @@ export type TextInteractionPolicy = {
29
29
  movable?: boolean;
30
30
  editable?: boolean;
31
31
  };
32
+ export type ElementChildInteractionPolicy = {
33
+ movable?: boolean;
34
+ };
32
35
  export type BorderSide = 'left' | 'right' | 'top' | 'bottom';
33
36
  export type HostAnchorPreset = 'vertices' | 'cardinal';
34
37
  export type PortLinkAttachMode = 'external' | 'internal';
@@ -270,6 +273,7 @@ export type ElementData = {
270
273
  moveMode?: MoveConstraint;
271
274
  anchorCenter?: boolean;
272
275
  layout?: ElementLayout;
276
+ childElementInteraction?: ElementChildInteractionPolicy;
273
277
  portMovement?: ElementPortMovementPolicy;
274
278
  };
275
279
  export type PortData = {
@@ -1,2 +1,4 @@
1
+ import type { DiagramState } from '../../api';
1
2
  import type { DemoConfig } from '../types';
3
+ export declare const createAutoLayoutState: (lockComparisonChildren?: boolean) => DiagramState;
2
4
  export declare const autoLayoutDemoConfig: DemoConfig;
@@ -94,6 +94,8 @@ export default class DiagramEngine {
94
94
  private shouldRestrictAutoLayoutChildRightGrowth;
95
95
  private resolveSnappedGridChildWidth;
96
96
  private resolveGridChildWidthResizeTopologyChange;
97
+ private isLeafGridChildResizeCandidate;
98
+ private isEnabledGridChildWidthResizeCandidate;
97
99
  getPortWorldPosition(id: string): Point | null;
98
100
  getPortLinkWorldPosition(id: string, options?: {
99
101
  oppositePortId?: string;
@@ -11,6 +11,7 @@ export default class ElementModel {
11
11
  moveMode?: MoveConstraint;
12
12
  anchorCenter?: boolean;
13
13
  layout?: ElementData['layout'];
14
+ childElementInteraction?: ElementData['childElementInteraction'];
14
15
  portMovement?: ElementData['portMovement'];
15
16
  constructor(data: ElementData);
16
17
  setPosition(position: Point): void;
@@ -74,7 +74,6 @@ export default class KonvaInteraction {
74
74
  private readonly occupiedVertexTolerance;
75
75
  private readonly nestedHoverElementPadding;
76
76
  private emittingElementLinkEnded;
77
- private panKey;
78
77
  constructor(engine: DiagramEngine, config?: InteractionConfig);
79
78
  setShapeHoverControls(controls?: ElementShapeHoverControls): void;
80
79
  startLinkFromPort(sourcePortId: string, pointer?: Point): void;
@@ -147,6 +146,7 @@ export default class KonvaInteraction {
147
146
  private getPortById;
148
147
  private getTextById;
149
148
  private isTextMovable;
149
+ private isElementMovable;
150
150
  private isTextEditable;
151
151
  private getLinkById;
152
152
  private resolveTextScreenPosition;
@@ -154,5 +154,4 @@ export default class KonvaInteraction {
154
154
  private applyStageTransform;
155
155
  private cancelLinkDrag;
156
156
  private isEditableTarget;
157
- private isPanKeyPressed;
158
157
  }