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/esm/index.js CHANGED
@@ -89,6 +89,7 @@ var ElementModel = /** @class */ (function () {
89
89
  this.moveMode = data.moveMode;
90
90
  this.anchorCenter = data.anchorCenter;
91
91
  this.layout = data.layout;
92
+ this.childElementInteraction = data.childElementInteraction;
92
93
  this.portMovement = data.portMovement;
93
94
  }
94
95
  ElementModel.prototype.setPosition = function (position) {
@@ -126,6 +127,7 @@ var ElementModel = /** @class */ (function () {
126
127
  moveMode: this.moveMode,
127
128
  anchorCenter: this.anchorCenter,
128
129
  layout: this.layout,
130
+ childElementInteraction: this.childElementInteraction,
129
131
  portMovement: this.portMovement,
130
132
  };
131
133
  };
@@ -4406,9 +4408,7 @@ var DiagramEngine = /** @class */ (function () {
4406
4408
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4407
4409
  if (!parentId)
4408
4410
  return false;
4409
- if (this.model.getChildren(element.id).length > 0)
4410
- return false;
4411
- if (element.layout && element.layout.mode !== 'manual')
4411
+ if (!this.isLeafGridChildResizeCandidate(element))
4412
4412
  return false;
4413
4413
  var parent = this.model.getElement(parentId);
4414
4414
  if (((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid')
@@ -4416,16 +4416,7 @@ var DiagramEngine = /** @class */ (function () {
4416
4416
  return !Boolean(parent.layout.gridChildWidthResizeEnabled);
4417
4417
  };
4418
4418
  DiagramEngine.prototype.shouldAnchorAutoLayoutGridChildWidthToLeft = function (element) {
4419
- var _a, _b;
4420
- var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4421
- if (!parentId)
4422
- return false;
4423
- if (this.model.getChildren(element.id).length > 0)
4424
- return false;
4425
- if (element.layout && element.layout.mode !== 'manual')
4426
- return false;
4427
- var parent = this.model.getElement(parentId);
4428
- return Boolean(((_b = parent === null || parent === void 0 ? void 0 : parent.layout) === null || _b === void 0 ? void 0 : _b.mode) === 'grid' && parent.layout.gridChildWidthResizeEnabled);
4419
+ return this.isEnabledGridChildWidthResizeCandidate(element);
4429
4420
  };
4430
4421
  DiagramEngine.prototype.shouldRestrictAutoLayoutChildRightGrowth = function (element, handle, requestedWidth) {
4431
4422
  return false;
@@ -4435,41 +4426,55 @@ var DiagramEngine = /** @class */ (function () {
4435
4426
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4436
4427
  if (!parentId)
4437
4428
  return requestedWidth;
4438
- if (this.model.getChildren(element.id).length > 0)
4439
- return requestedWidth;
4440
- if (element.layout && element.layout.mode !== 'manual')
4441
- return requestedWidth;
4442
- var parent = this.model.getElement(parentId);
4443
- if (!(parent === null || parent === void 0 ? void 0 : parent.layout) || parent.layout.mode !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
4429
+ if (!this.isEnabledGridChildWidthResizeCandidate(element))
4444
4430
  return requestedWidth;
4445
4431
  return this.autoLayoutService.snapGridChildRequestedWidth(parentId, element.id, requestedWidth);
4446
4432
  };
4447
4433
  DiagramEngine.prototype.resolveGridChildWidthResizeTopologyChange = function (element, requestedWidth) {
4448
- var _a, _b, _c;
4434
+ var _a, _b;
4449
4435
  var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4450
4436
  if (!parentId)
4451
4437
  return null;
4452
- if (this.model.getChildren(element.id).length > 0)
4453
- return null;
4454
- if (element.layout && element.layout.mode !== 'manual')
4438
+ if (!this.isEnabledGridChildWidthResizeCandidate(element))
4455
4439
  return null;
4456
4440
  var parent = this.model.getElement(parentId);
4457
- if (!parent || ((_b = parent.layout) === null || _b === void 0 ? void 0 : _b.mode) !== 'grid' || !parent.layout.gridChildWidthResizeEnabled)
4441
+ if (!parent)
4458
4442
  return null;
4459
4443
  var topologyChange = this.autoLayoutService.resolveGridChildResizeTopologyChange(parentId, element.id, requestedWidth);
4460
4444
  if (!topologyChange)
4461
4445
  return null;
4446
+ var parentLayout = parent.layout;
4447
+ if (!parentLayout)
4448
+ return null;
4462
4449
  return {
4463
4450
  parentId: topologyChange.parentId,
4464
4451
  triggerChildId: topologyChange.triggerChildId,
4465
4452
  reason: topologyChange.reason,
4466
4453
  beforeRows: topologyChange.beforeRows,
4467
4454
  afterRows: topologyChange.afterRows,
4468
- beforeGridTemplate: parent.layout.gridTemplate ? __spreadArray([], parent.layout.gridTemplate, true) : undefined,
4469
- afterGridTemplate: __spreadArray([], ((_c = topologyChange.nextLayout.gridTemplate) !== null && _c !== void 0 ? _c : []), true),
4455
+ beforeGridTemplate: parentLayout.gridTemplate ? __spreadArray([], parentLayout.gridTemplate, true) : undefined,
4456
+ afterGridTemplate: __spreadArray([], ((_b = topologyChange.nextLayout.gridTemplate) !== null && _b !== void 0 ? _b : []), true),
4470
4457
  afterLayout: topologyChange.nextLayout,
4471
4458
  };
4472
4459
  };
4460
+ DiagramEngine.prototype.isLeafGridChildResizeCandidate = function (element) {
4461
+ if (this.model.getChildren(element.id).length > 0)
4462
+ return false;
4463
+ if (element.layout && element.layout.mode !== 'manual')
4464
+ return false;
4465
+ return true;
4466
+ };
4467
+ DiagramEngine.prototype.isEnabledGridChildWidthResizeCandidate = function (element) {
4468
+ var _a;
4469
+ var parentId = (_a = element.parentId) !== null && _a !== void 0 ? _a : null;
4470
+ if (!parentId)
4471
+ return false;
4472
+ var parent = this.model.getElement(parentId);
4473
+ var layout = parent === null || parent === void 0 ? void 0 : parent.layout;
4474
+ if (!layout || layout.mode !== 'grid')
4475
+ return false;
4476
+ return Boolean(layout.gridChildWidthResizeEnabled);
4477
+ };
4473
4478
  DiagramEngine.prototype.getPortWorldPosition = function (id) {
4474
4479
  return this.model.getPortWorldPosition(id);
4475
4480
  };
@@ -6376,7 +6381,7 @@ var ellipseMidPointToIndex = function (value) {
6376
6381
  var KonvaInteraction = /** @class */ (function () {
6377
6382
  function KonvaInteraction(engine, config) {
6378
6383
  if (config === void 0) { config = {}; }
6379
- var _a, _b;
6384
+ var _a;
6380
6385
  this.linkDragContext = null;
6381
6386
  this.programmaticLinkSession = null;
6382
6387
  this.bound = false;
@@ -6400,7 +6405,6 @@ var KonvaInteraction = /** @class */ (function () {
6400
6405
  this.stage = config.stage;
6401
6406
  this.hitTester = (_a = config.hitTester) !== null && _a !== void 0 ? _a : new KonvaHitTester();
6402
6407
  this.renderer = config.renderer;
6403
- this.panKey = (_b = config.panKey) !== null && _b !== void 0 ? _b : 'Control';
6404
6408
  this.shapeRegistry = config.shapeRegistry;
6405
6409
  this.shapeHoverControls = this.normalizeShapeHoverControls(config.shapeHoverControls);
6406
6410
  this.onShapeHoverControlInteracted = config.onShapeHoverControlInteracted;
@@ -6568,7 +6572,10 @@ var KonvaInteraction = /** @class */ (function () {
6568
6572
  var hit = _this.resolveHit(point);
6569
6573
  var nativeEvent = event === null || event === void 0 ? void 0 : event.evt;
6570
6574
  var isMulti = Boolean(nativeEvent && (nativeEvent.ctrlKey || nativeEvent.metaKey || nativeEvent.shiftKey));
6571
- var isPanGesture = Boolean(nativeEvent && _this.isPanKeyPressed(nativeEvent) && nativeEvent.button === 0);
6575
+ var isPrimaryButton = !nativeEvent || nativeEvent.button === 0;
6576
+ var isEmptyPaper = !hit || hit.type === 'none';
6577
+ var isMarqueeGesture = Boolean(isPrimaryButton && isEmptyPaper && (nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.shiftKey));
6578
+ var isPanGesture = Boolean(isPrimaryButton && isEmptyPaper && !(nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.shiftKey));
6572
6579
  var pointerInfo = _this.buildPointerInfo(point, nativeEvent);
6573
6580
  if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'shape-hover-control') {
6574
6581
  var resolvedControl = _this.resolveShapeHoverControlFromHit(hit.id, point);
@@ -6626,11 +6633,14 @@ var KonvaInteraction = /** @class */ (function () {
6626
6633
  }
6627
6634
  return;
6628
6635
  }
6629
- if (!hit || hit.type === 'none') {
6636
+ if (isMarqueeGesture) {
6630
6637
  _this.dragState = { mode: 'marquee', start: point, isMulti: isMulti, hasMoved: false };
6631
6638
  (_d = _this.renderer) === null || _d === void 0 ? void 0 : _d.renderMarquee({ x: point.x, y: point.y, width: 0, height: 0 });
6632
6639
  return;
6633
6640
  }
6641
+ if (isEmptyPaper) {
6642
+ return;
6643
+ }
6634
6644
  if (hit.type === 'port') {
6635
6645
  var elementId = _this.engine.getPortElementId(hit.id);
6636
6646
  if (!elementId)
@@ -6695,6 +6705,7 @@ var KonvaInteraction = /** @class */ (function () {
6695
6705
  var element = _this.getElementById(hit.id);
6696
6706
  if (!element)
6697
6707
  return;
6708
+ var movable = _this.isElementMovable(hit.id);
6698
6709
  var anchor = element.anchorCenter ? 'center' : 'top-left';
6699
6710
  var base = element.anchorCenter
6700
6711
  ? {
@@ -6709,12 +6720,13 @@ var KonvaInteraction = /** @class */ (function () {
6709
6720
  offset: { x: point.x - base.x, y: point.y - base.y },
6710
6721
  start: __assign({}, base),
6711
6722
  anchor: anchor,
6723
+ movable: movable,
6712
6724
  startParentId: (_e = element.parentId) !== null && _e !== void 0 ? _e : null,
6713
6725
  selectionIds: _this.engine.getSelection(),
6714
6726
  isMulti: isMulti,
6715
6727
  hasMoved: false,
6716
6728
  };
6717
- _this.setCursor('grabbing');
6729
+ _this.setCursor(movable ? 'grabbing' : 'pointer');
6718
6730
  }
6719
6731
  }
6720
6732
  };
@@ -6772,6 +6784,9 @@ var KonvaInteraction = /** @class */ (function () {
6772
6784
  var dy = target.y - _this.dragState.start.y;
6773
6785
  var moved = Math.hypot(dx, dy) >= _this.dragThreshold;
6774
6786
  _this.dragState.hasMoved = _this.dragState.hasMoved || moved;
6787
+ if (!_this.dragState.movable) {
6788
+ return;
6789
+ }
6775
6790
  _this.engine.moveElementTo(_this.dragState.id, target.x, target.y);
6776
6791
  if (_this.renderer && _this.engine.getSelection().includes(_this.dragState.id)) {
6777
6792
  var element = _this.getElementById(_this.dragState.id);
@@ -6897,15 +6912,15 @@ var KonvaInteraction = /** @class */ (function () {
6897
6912
  var dx = point.x - _this.dragState.start.x;
6898
6913
  var dy = point.y - _this.dragState.start.y;
6899
6914
  _this.pan = {
6900
- x: _this.dragState.origin.x - dx * _this.panSpeed,
6901
- y: _this.dragState.origin.y - dy * _this.panSpeed,
6915
+ x: _this.dragState.origin.x + dx * _this.panSpeed,
6916
+ y: _this.dragState.origin.y + dy * _this.panSpeed,
6902
6917
  };
6903
6918
  _this.applyStageTransform();
6904
6919
  _this.engine.setViewport(_this.pan, _this.zoom);
6905
6920
  }
6906
6921
  };
6907
6922
  var pointerUp = function () {
6908
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6923
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6909
6924
  var args = [];
6910
6925
  for (var _i = 0; _i < arguments.length; _i++) {
6911
6926
  args[_i] = arguments[_i];
@@ -6999,10 +7014,21 @@ var KonvaInteraction = /** @class */ (function () {
6999
7014
  _this.engine.emitPaperClick(pointerInfo);
7000
7015
  }
7001
7016
  }
7002
- if (((_h = _this.dragState) === null || _h === void 0 ? void 0 : _h.mode) === 'move' && _this.dragState.type === 'element') {
7017
+ if (((_h = _this.dragState) === null || _h === void 0 ? void 0 : _h.mode) === 'pan') {
7018
+ var point = pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.dragState.start;
7019
+ var dx = point.x - _this.dragState.start.x;
7020
+ var dy = point.y - _this.dragState.start.y;
7021
+ var moved = Math.hypot(dx, dy) >= _this.dragThreshold;
7022
+ if (!moved) {
7023
+ _this.engine.setSelection([]);
7024
+ var pointerInfo = _this.buildPointerInfo(point, nativeEvent);
7025
+ _this.engine.emitPaperClick(pointerInfo);
7026
+ }
7027
+ }
7028
+ if (((_j = _this.dragState) === null || _j === void 0 ? void 0 : _j.mode) === 'move' && _this.dragState.type === 'element') {
7003
7029
  var element = _this.getElementById(_this.dragState.id);
7004
7030
  if (element) {
7005
- var endTopLeft = (_j = _this.engine.getElementWorldPosition(_this.dragState.id)) !== null && _j !== void 0 ? _j : element.position;
7031
+ var endTopLeft = (_k = _this.engine.getElementWorldPosition(_this.dragState.id)) !== null && _k !== void 0 ? _k : element.position;
7006
7032
  var endWorld = _this.dragState.anchor === 'center'
7007
7033
  ? {
7008
7034
  x: endTopLeft.x + element.size.width / 2,
@@ -7013,7 +7039,8 @@ var KonvaInteraction = /** @class */ (function () {
7013
7039
  x: endWorld.x - _this.dragState.start.x,
7014
7040
  y: endWorld.y - _this.dragState.start.y,
7015
7041
  };
7016
- var moved = _this.dragState.hasMoved || Math.hypot(delta.x, delta.y) > 0;
7042
+ var moved = _this.dragState.movable &&
7043
+ (_this.dragState.hasMoved || Math.hypot(delta.x, delta.y) > 0);
7017
7044
  if (moved) {
7018
7045
  _this.engine.emitElementDrop({
7019
7046
  elementId: _this.dragState.id,
@@ -7025,16 +7052,16 @@ var KonvaInteraction = /** @class */ (function () {
7025
7052
  anchor: _this.dragState.anchor,
7026
7053
  });
7027
7054
  }
7028
- else {
7055
+ else if (!_this.dragState.hasMoved) {
7029
7056
  var pointerInfo = _this.buildPointerInfo(pointerPoint !== null && pointerPoint !== void 0 ? pointerPoint : _this.dragState.start, nativeEvent);
7030
7057
  _this.engine.emitElementClick(_this.dragState.id, pointerInfo, _this.dragState.isMulti);
7031
7058
  }
7032
7059
  }
7033
7060
  }
7034
- if (((_k = _this.dragState) === null || _k === void 0 ? void 0 : _k.mode) === 'move' && _this.dragState.type === 'port') {
7061
+ if (((_l = _this.dragState) === null || _l === void 0 ? void 0 : _l.mode) === 'move' && _this.dragState.type === 'port') {
7035
7062
  var elementId = _this.engine.getPortElementId(_this.dragState.id);
7036
7063
  if (elementId) {
7037
- 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);
7064
+ 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);
7038
7065
  _this.engine.emitPortMouseUp({ portId: _this.dragState.id, elementId: elementId, pointer: pointerInfo });
7039
7066
  }
7040
7067
  }
@@ -7340,6 +7367,10 @@ var KonvaInteraction = /** @class */ (function () {
7340
7367
  this.setCursor('pointer');
7341
7368
  return;
7342
7369
  }
7370
+ if (hit.type === 'element' && !this.isElementMovable(hit.id)) {
7371
+ this.setCursor('pointer');
7372
+ return;
7373
+ }
7343
7374
  this.setCursor('grab');
7344
7375
  };
7345
7376
  KonvaInteraction.prototype.normalizeShapeHoverControls = function (controls) {
@@ -8565,6 +8596,14 @@ var KonvaInteraction = /** @class */ (function () {
8565
8596
  var _a, _b;
8566
8597
  return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.movable) !== false;
8567
8598
  };
8599
+ KonvaInteraction.prototype.isElementMovable = function (id) {
8600
+ var _a;
8601
+ var element = this.getElementById(id);
8602
+ if (!(element === null || element === void 0 ? void 0 : element.parentId))
8603
+ return true;
8604
+ var parent = this.getElementById(element.parentId);
8605
+ return ((_a = parent === null || parent === void 0 ? void 0 : parent.childElementInteraction) === null || _a === void 0 ? void 0 : _a.movable) !== false;
8606
+ };
8568
8607
  KonvaInteraction.prototype.isTextEditable = function (id) {
8569
8608
  var _a, _b;
8570
8609
  return ((_b = (_a = this.getTextById(id)) === null || _a === void 0 ? void 0 : _a.interaction) === null || _b === void 0 ? void 0 : _b.editable) !== false;
@@ -8683,19 +8722,6 @@ var KonvaInteraction = /** @class */ (function () {
8683
8722
  var tag = target.tagName.toLowerCase();
8684
8723
  return tag === 'input' || tag === 'textarea' || tag === 'select';
8685
8724
  };
8686
- KonvaInteraction.prototype.isPanKeyPressed = function (event) {
8687
- switch (this.panKey) {
8688
- case 'Shift':
8689
- return event.shiftKey;
8690
- case 'Alt':
8691
- return event.altKey;
8692
- case 'Meta':
8693
- return event.metaKey;
8694
- case 'Control':
8695
- default:
8696
- return event.ctrlKey;
8697
- }
8698
- };
8699
8725
  return KonvaInteraction;
8700
8726
  }());
8701
8727