@inditextech/weave-sdk 0.42.2 → 0.44.0

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/sdk.js CHANGED
@@ -15494,7 +15494,6 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
15494
15494
  } else root._ = _;
15495
15495
  }).call(exports);
15496
15496
  } });
15497
- var import_lodash$1 = __toESM(require_lodash());
15498
15497
  var import_lodash = __toESM(require_lodash(), 1);
15499
15498
 
15500
15499
  //#endregion
@@ -15589,12 +15588,12 @@ var WeaveStore = class {
15589
15588
  node: JSON.parse(JSON.stringify(nodeInfo.node))
15590
15589
  });
15591
15590
  }
15592
- if (!this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) {
15591
+ if (!this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) {
15593
15592
  this.instance.setupRenderer();
15594
15593
  this.isRoomLoaded = true;
15595
15594
  this.instance.emitEvent("onRoomLoaded", this.isRoomLoaded);
15596
15595
  }
15597
- if (this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) this.instance.render();
15596
+ if (this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) this.instance.render();
15598
15597
  });
15599
15598
  }
15600
15599
  canUndoStateStep() {
@@ -15959,7 +15958,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15959
15958
  super();
15960
15959
  const { config } = params ?? {};
15961
15960
  this.config = {
15962
- transformer: {
15961
+ selection: {
15963
15962
  rotationSnaps: [
15964
15963
  0,
15965
15964
  45,
@@ -15994,16 +15993,27 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15994
15993
  }
15995
15994
  },
15996
15995
  borderStroke: "#0074ffcc",
15997
- borderStrokeWidth: 3,
15998
- ...config?.transformer
15996
+ borderStrokeWidth: 1,
15997
+ ...config?.selection
15999
15998
  },
16000
- transformations: {
15999
+ hover: {
16000
+ borderStrokeWidth: 1,
16001
+ ...config?.hover
16002
+ },
16003
+ selectionArea: {
16004
+ fill: "#93c5fd40",
16005
+ stroke: "#1e40afff",
16006
+ strokeWidth: 1,
16007
+ dash: [12, 4],
16008
+ ...config?.selectionArea
16009
+ },
16010
+ behaviors: {
16001
16011
  singleSelection: { enabled: true },
16002
16012
  multipleSelection: { enabled: false },
16003
- ...config?.transformations
16013
+ ...config?.behaviors
16004
16014
  }
16005
16015
  };
16006
- this.defaultEnabledAnchors = this.config.transformer?.enabledAnchors ?? [
16016
+ this.defaultEnabledAnchors = this.config.selection?.enabledAnchors ?? [
16007
16017
  "top-left",
16008
16018
  "top-center",
16009
16019
  "top-right",
@@ -16061,23 +16071,21 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16061
16071
  stage.container().tabIndex = 1;
16062
16072
  stage.container().focus();
16063
16073
  const selectionRectangle = new Konva.Rect({
16064
- fill: "rgba(147, 197, 253, 0.25)",
16065
- stroke: "#1e40afff",
16066
- strokeWidth: 1 * stage.scaleX(),
16067
- dash: [12 * stage.scaleX(), 4 * stage.scaleX()],
16074
+ ...this.config.selectionArea,
16075
+ ...this.config.selectionArea.strokeWidth && { strokeWidth: this.config.selectionArea.strokeWidth / stage.scaleX() },
16076
+ ...this.config.selectionArea.dash && { dash: this.config.selectionArea.dash.map((d) => d / stage.scaleX()) },
16068
16077
  visible: false,
16069
16078
  listening: false
16070
16079
  });
16071
16080
  selectionLayer?.add(selectionRectangle);
16072
16081
  const tr = new Konva.Transformer({
16073
16082
  id: "selectionTransformer",
16074
- ...this.config.transformer
16083
+ ...this.config.selection
16075
16084
  });
16076
16085
  selectionLayer?.add(tr);
16077
16086
  const trHover = new Konva.Transformer({
16078
16087
  id: "hoverTransformer",
16079
- ...this.config.transformer,
16080
- borderStrokeWidth: 3,
16088
+ ...this.config.hover,
16081
16089
  rotateEnabled: false,
16082
16090
  resizeEnabled: false,
16083
16091
  enabledAnchors: [],
@@ -16092,7 +16100,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16092
16100
  if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
16093
16101
  this.triggerSelectedNodesEvent();
16094
16102
  };
16095
- tr.on("transform", (0, import_lodash$1.throttle)(handleTransform, 50));
16103
+ tr.on("transform", (0, import_lodash.throttle)(handleTransform, 50));
16096
16104
  tr.on("transformend", () => {
16097
16105
  this.triggerSelectedNodesEvent();
16098
16106
  });
@@ -16348,8 +16356,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16348
16356
  y1 = intStage.getRelativePointerPosition()?.y ?? 0;
16349
16357
  x2 = intStage.getRelativePointerPosition()?.x ?? 0;
16350
16358
  y2 = intStage.getRelativePointerPosition()?.y ?? 0;
16351
- this.selectionRectangle.strokeWidth(1 / stage.scaleX());
16352
- this.selectionRectangle.dash([12 / stage.scaleX(), 4 / stage.scaleX()]);
16359
+ this.selectionRectangle.strokeWidth(this.config.selectionArea.strokeWidth / stage.scaleX());
16360
+ this.selectionRectangle.dash(this.config.selectionArea.dash?.map((d) => d / stage.scaleX()) ?? []);
16353
16361
  this.selectionRectangle.width(0);
16354
16362
  this.selectionRectangle.height(0);
16355
16363
  this.selecting = true;
@@ -16469,16 +16477,16 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16469
16477
  if (!frameNode.getAttrs().locked) selectedNodes.add(node);
16470
16478
  });
16471
16479
  const nodesArray = [...selectedNodes];
16472
- if (nodesArray.length > 1 && !this.config.transformations.multipleSelection.enabled || nodesArray.length === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
16473
- if (nodesArray.length > 1 && this.config.transformations.multipleSelection.enabled || nodesArray.length === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16480
+ if (nodesArray.length > 1 && !this.config.behaviors.multipleSelection.enabled || nodesArray.length === 1 && !this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors([]);
16481
+ if (nodesArray.length > 1 && this.config.behaviors.multipleSelection.enabled || nodesArray.length === 1 && this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16474
16482
  if (nodesArray.length === 1) {
16475
16483
  this.tr.setAttrs({
16476
- ...this.config.transformer,
16484
+ ...this.config.selection,
16477
16485
  ...nodesArray[0].getTransformerProperties()
16478
16486
  });
16479
16487
  this.tr.forceUpdate();
16480
16488
  } else {
16481
- this.tr.setAttrs({ ...this.config.transformer });
16489
+ this.tr.setAttrs({ ...this.config.selection });
16482
16490
  this.tr.forceUpdate();
16483
16491
  }
16484
16492
  this.selecting = false;
@@ -16522,7 +16530,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16522
16530
  if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
16523
16531
  }
16524
16532
  if (!nodeTargeted.getAttrs().nodeType) return;
16525
- let nodesSelected = 0;
16526
16533
  const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
16527
16534
  const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
16528
16535
  return node.getAttrs().id === nodeTargeted.getAttrs().id;
@@ -16540,7 +16547,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16540
16547
  }
16541
16548
  if (!metaPressed) {
16542
16549
  this.tr.nodes([nodeTargeted]);
16543
- nodesSelected = this.tr.nodes().length;
16544
16550
  this.tr.show();
16545
16551
  areNodesSelected = true;
16546
16552
  }
@@ -16548,24 +16554,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16548
16554
  const nodes = this.tr.nodes().slice();
16549
16555
  nodes.splice(nodes.indexOf(nodeTargeted), 1);
16550
16556
  this.tr.nodes(nodes);
16551
- nodesSelected = this.tr.nodes().length;
16552
16557
  areNodesSelected = true;
16553
16558
  }
16554
16559
  if (metaPressed && !isSelected) {
16555
16560
  const nodes = this.tr.nodes().concat([nodeTargeted]);
16556
16561
  this.tr.nodes(nodes);
16557
- nodesSelected = this.tr.nodes().length;
16558
16562
  areNodesSelected = true;
16559
16563
  }
16560
- if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
16561
- if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16562
- if (nodesSelected === 1) {
16563
- this.tr.setAttrs({
16564
- ...this.config.transformer,
16565
- ...nodeTargeted.getTransformerProperties()
16566
- });
16567
- this.tr.forceUpdate();
16568
- }
16564
+ this.handleBehaviors();
16569
16565
  if (areNodesSelected) {
16570
16566
  stage.container().tabIndex = 1;
16571
16567
  stage.container().focus();
@@ -16579,21 +16575,25 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16579
16575
  getHoverTransformer() {
16580
16576
  return this.trHover;
16581
16577
  }
16582
- setSelectedNodes(nodes) {
16583
- this.tr.setNodes(nodes);
16584
- const nodesSelected = nodes.length;
16585
- if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
16586
- if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16578
+ handleBehaviors() {
16579
+ const nodes = this.getSelectedNodes();
16580
+ const nodesSelected = this.getSelectedNodes().length;
16581
+ if (nodesSelected > 1 && !this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && !this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors([]);
16582
+ if (nodesSelected > 1 && this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16587
16583
  if (nodesSelected === 1) {
16588
16584
  this.tr.setAttrs({
16589
- ...this.config.transformer,
16585
+ ...this.config.selection,
16590
16586
  ...nodes[0].getTransformerProperties()
16591
16587
  });
16592
16588
  this.tr.forceUpdate();
16593
16589
  } else if (nodesSelected > 1) {
16594
- this.tr.setAttrs({ ...this.config.transformer });
16590
+ this.tr.setAttrs({ ...this.config.selection });
16595
16591
  this.tr.forceUpdate();
16596
16592
  }
16593
+ }
16594
+ setSelectedNodes(nodes) {
16595
+ this.tr.setNodes(nodes);
16596
+ this.handleBehaviors();
16597
16597
  this.triggerSelectedNodesEvent();
16598
16598
  }
16599
16599
  getSelectedNodes() {
@@ -16964,7 +16964,7 @@ var WeaveNode = class {
16964
16964
  if (nodesSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesSnappingPlugin.evaluateGuidelines(e);
16965
16965
  if (this.isSelecting() && this.isNodeSelected(node$1)) this.scaleReset(node$1);
16966
16966
  };
16967
- node.on("transform", (0, import_lodash$1.throttle)(handleTransform, 100));
16967
+ node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
16968
16968
  node.on("transformend", (e) => {
16969
16969
  const node$1 = e.target;
16970
16970
  this.instance.emitEvent("onTransform", null);
@@ -17017,7 +17017,7 @@ var WeaveNode = class {
17017
17017
  if (layerToMove) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
17018
17018
  }
17019
17019
  };
17020
- node.on("dragmove", (0, import_lodash$1.throttle)(handleDragMove, 100));
17020
+ node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
17021
17021
  node.on("dragend", (e) => {
17022
17022
  if (!this.didMove) return;
17023
17023
  const isErasing = this.instance.getActiveAction() === "eraseTool";
@@ -18451,6 +18451,7 @@ var WeaveStateManager = class {
18451
18451
  return;
18452
18452
  }
18453
18453
  const doc = getYjsDoc(state);
18454
+ const userId = this.instance.getStore().getUser().id;
18454
18455
  doc.transact(() => {
18455
18456
  if (!parent.props.children) parent.props.children = [];
18456
18457
  if (index) {
@@ -18469,7 +18470,7 @@ var WeaveStateManager = class {
18469
18470
  parent.props.children.push(nodeToAdd);
18470
18471
  }
18471
18472
  this.instance.emitEvent("onNodeAdded", node);
18472
- });
18473
+ }, userId);
18473
18474
  }
18474
18475
  deepSyncSyncedStore(target, source) {
18475
18476
  for (const key in target) if (!(key in source)) delete target[key];
@@ -18513,9 +18514,10 @@ var WeaveStateManager = class {
18513
18514
  return;
18514
18515
  }
18515
18516
  const doc = getYjsDoc(state);
18517
+ const userId = this.instance.getStore().getUser().id;
18516
18518
  doc.transact(() => {
18517
18519
  this.deepSyncSyncedStore(nodeState.props, node.props);
18518
- });
18520
+ }, userId);
18519
18521
  this.instance.emitEvent("onNodeUpdated", node);
18520
18522
  }
18521
18523
  removeNode(node) {
@@ -18537,6 +18539,7 @@ var WeaveStateManager = class {
18537
18539
  return;
18538
18540
  }
18539
18541
  const doc = getYjsDoc(state);
18542
+ const userId = this.instance.getStore().getUser().id;
18540
18543
  doc.transact(() => {
18541
18544
  if (parent.props.children) {
18542
18545
  for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
@@ -18546,7 +18549,7 @@ var WeaveStateManager = class {
18546
18549
  for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
18547
18550
  this.instance.emitEvent("onNodeRemoved", node);
18548
18551
  }
18549
- });
18552
+ }, userId);
18550
18553
  }
18551
18554
  removeNodes(nodes) {
18552
18555
  for (const node of nodes) this.removeNode(node);
@@ -18578,6 +18581,7 @@ var WeaveStateManager = class {
18578
18581
  return;
18579
18582
  }
18580
18583
  const doc = getYjsDoc(state);
18584
+ const userId = this.instance.getStore().getUser().id;
18581
18585
  doc.transact(() => {
18582
18586
  if (parent.props.children) {
18583
18587
  const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
@@ -18588,7 +18592,7 @@ var WeaveStateManager = class {
18588
18592
  if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
18589
18593
  for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
18590
18594
  }
18591
- });
18595
+ }, userId);
18592
18596
  }
18593
18597
  }
18594
18598
  getElementsTree() {
@@ -18674,7 +18678,7 @@ var WeaveRegisterManager = class {
18674
18678
 
18675
18679
  //#endregion
18676
18680
  //#region package.json
18677
- var version = "0.42.2";
18681
+ var version = "0.44.0";
18678
18682
 
18679
18683
  //#endregion
18680
18684
  //#region src/managers/setup.ts
@@ -19788,7 +19792,7 @@ var WeaveTextNode = class extends WeaveNode {
19788
19792
  text.on("transformstart", (e) => {
19789
19793
  this.instance.emitEvent("onTransform", e.target);
19790
19794
  });
19791
- text.on("transform", (0, import_lodash$1.throttle)(handleTextTransform, 50));
19795
+ text.on("transform", (0, import_lodash.throttle)(handleTextTransform, 50));
19792
19796
  text.on("transformend", () => {
19793
19797
  this.instance.emitEvent("onTransform", null);
19794
19798
  });
@@ -21076,7 +21080,7 @@ var WeaveImageNode = class extends WeaveNode {
21076
21080
  const stage = this.instance.getStage();
21077
21081
  const image = stage.findOne(`#${imageAttrs.id}`);
21078
21082
  const internalImage = image?.findOne(`#${imageAttrs.id}-image`);
21079
- if (image && internalImage && !imageAttrs.adding && imageAttrs.cropInfo && !(0, import_lodash$1.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
21083
+ if (image && internalImage && !imageAttrs.adding && imageAttrs.cropInfo && !(0, import_lodash.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
21080
21084
  const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
21081
21085
  internalImage.width(imageAttrs.uncroppedImage.width);
21082
21086
  internalImage.height(imageAttrs.uncroppedImage.height);
@@ -21093,7 +21097,7 @@ var WeaveImageNode = class extends WeaveNode {
21093
21097
  internalImage.height(imageAttrs.cropSize.height);
21094
21098
  this.cachedCropInfo[imageAttrs.id ?? ""] = imageAttrs.cropInfo;
21095
21099
  }
21096
- if (image && internalImage && !imageAttrs.adding && !imageAttrs.cropInfo && !(0, import_lodash$1.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
21100
+ if (image && internalImage && !imageAttrs.adding && !imageAttrs.cropInfo && !(0, import_lodash.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
21097
21101
  internalImage.width(imageAttrs.uncroppedImage.width);
21098
21102
  internalImage.height(imageAttrs.uncroppedImage.height);
21099
21103
  internalImage.rotation(0);
@@ -21324,7 +21328,7 @@ const WEAVE_FRAME_NODE_DEFAULT_CONFIG = {
21324
21328
  rotateEnabled: false,
21325
21329
  resizeEnabled: false,
21326
21330
  enabledAnchors: [],
21327
- borderStrokeWidth: 3,
21331
+ borderStrokeWidth: 1,
21328
21332
  padding: 0
21329
21333
  }
21330
21334
  };
@@ -21409,13 +21413,15 @@ var WeaveFrameNode = class extends WeaveNode {
21409
21413
  draggable: false
21410
21414
  });
21411
21415
  frameInternalGroup.add(background);
21416
+ const stage = this.instance.getStage();
21412
21417
  const text = new Konva.Text({
21413
21418
  id: `${id}-title`,
21414
21419
  x: 0,
21415
- width: props.frameWidth,
21416
- fontSize,
21420
+ width: props.frameWidth / stage.scaleX(),
21421
+ fontSize: fontSize / stage.scaleX(),
21417
21422
  fontFamily,
21418
21423
  fontStyle,
21424
+ verticalAlign: "middle",
21419
21425
  align: "left",
21420
21426
  text: props.title,
21421
21427
  fill: fontColor,
@@ -21425,10 +21431,8 @@ var WeaveFrameNode = class extends WeaveNode {
21425
21431
  draggable: false
21426
21432
  });
21427
21433
  const textMeasures = text.measureSize(text.getAttrs().text ?? "");
21428
- const textWidth = textMeasures.width;
21429
- const textHeight = textMeasures.height;
21430
- text.y(-textHeight - titleMargin);
21431
- text.width(textWidth);
21434
+ const textHeight = textMeasures.height + 2 * titleMargin / stage.scaleX();
21435
+ text.y(-textHeight);
21432
21436
  text.height(textHeight);
21433
21437
  frameInternalGroup.add(text);
21434
21438
  frame.getTransformerProperties = () => {
@@ -21460,7 +21464,7 @@ var WeaveFrameNode = class extends WeaveNode {
21460
21464
  height: props.frameHeight,
21461
21465
  hitFunc: function(ctx, shape) {
21462
21466
  ctx.beginPath();
21463
- ctx.rect(0, -textHeight - titleMargin, textWidth, textHeight);
21467
+ ctx.rect(0, -textHeight, props.frameWidth, textHeight);
21464
21468
  ctx.fillStrokeShape(shape);
21465
21469
  },
21466
21470
  fill: "transparent",
@@ -21500,6 +21504,20 @@ var WeaveFrameNode = class extends WeaveNode {
21500
21504
  selectionArea.off("dragmove");
21501
21505
  selectionArea.off("dragend");
21502
21506
  this.setupDefaultNodeEvents(frame);
21507
+ this.instance.addEventListener("onZoomChange", () => {
21508
+ const stage$1 = this.instance.getStage();
21509
+ text.fontSize(fontSize / stage$1.scaleX());
21510
+ text.width(props.frameWidth / stage$1.scaleX());
21511
+ const textMeasures$1 = text.measureSize(text.getAttrs().text ?? "");
21512
+ const textHeight$1 = textMeasures$1.height + 2 * titleMargin / stage$1.scaleX();
21513
+ text.y(-textHeight$1);
21514
+ text.height(textHeight$1);
21515
+ selectionArea.hitFunc(function(ctx, shape) {
21516
+ ctx.beginPath();
21517
+ ctx.rect(0, -textHeight$1, props.frameWidth, textHeight$1);
21518
+ ctx.fillStrokeShape(shape);
21519
+ });
21520
+ });
21503
21521
  frame.off("pointerover");
21504
21522
  frame.on(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
21505
21523
  background.setAttrs({
@@ -21533,14 +21551,12 @@ var WeaveFrameNode = class extends WeaveNode {
21533
21551
  if (title && selectionArea) {
21534
21552
  title.text(newProps.title);
21535
21553
  const textMeasures = title.measureSize(title.getAttrs().text ?? "");
21536
- const textWidth = textMeasures.width;
21537
- const textHeight = textMeasures.height;
21538
- title.y(-textHeight - titleMargin);
21539
- title.width(textWidth);
21554
+ const textHeight = textMeasures.height + 2 * titleMargin / stage.scaleX();
21555
+ title.y(-textHeight);
21540
21556
  title.height(textHeight);
21541
21557
  selectionArea.hitFunc(function(ctx, shape) {
21542
21558
  ctx.beginPath();
21543
- ctx.rect(0, -textHeight - titleMargin, textWidth, textHeight);
21559
+ ctx.rect(0, -textHeight, nextProps.frameWidth, textHeight);
21544
21560
  ctx.fillStrokeShape(shape);
21545
21561
  });
21546
21562
  }
@@ -23392,7 +23408,7 @@ var require_hammer = __commonJS({ "../../node_modules/hammerjs/hammer.js"(export
23392
23408
  else window$1[exportName] = Hammer;
23393
23409
  })(window, document, "Hammer");
23394
23410
  } });
23395
- var import_hammer = __toESM(require_hammer());
23411
+ var import_hammer = __toESM(require_hammer(), 1);
23396
23412
 
23397
23413
  //#endregion
23398
23414
  //#region src/plugins/stage-zoom/stage-zoom.ts
@@ -23414,7 +23430,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23414
23430
  constructor(params) {
23415
23431
  super();
23416
23432
  const { config } = params ?? {};
23417
- this.config = (0, import_lodash$1.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
23433
+ this.config = (0, import_lodash.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
23418
23434
  if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
23419
23435
  this.threshold = .2;
23420
23436
  this.pinching = false;
@@ -23443,7 +23459,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23443
23459
  this.config.zoomSteps = [minimumZoom, ...this.config.zoomSteps];
23444
23460
  }
23445
23461
  };
23446
- mainLayer?.on("draw", (0, import_lodash$1.throttle)(handleDraw, 50));
23462
+ mainLayer?.on("draw", (0, import_lodash.throttle)(handleDraw, 50));
23447
23463
  this.setZoom(this.config.zoomSteps[this.actualStep]);
23448
23464
  }
23449
23465
  setZoom(scale, centered = true, pointer) {
@@ -24138,9 +24154,10 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24138
24154
  this.initialized = false;
24139
24155
  this.state = RECTANGLE_TOOL_STATE.IDLE;
24140
24156
  this.rectId = null;
24141
- this.creating = false;
24157
+ this.tempRectNode = null;
24142
24158
  this.moved = false;
24143
24159
  this.container = void 0;
24160
+ this.measureContainer = void 0;
24144
24161
  this.clickPoint = null;
24145
24162
  this.props = this.initProps();
24146
24163
  }
@@ -24179,10 +24196,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24179
24196
  this.state = RECTANGLE_TOOL_STATE.ADDING;
24180
24197
  return;
24181
24198
  }
24182
- if (this.state === RECTANGLE_TOOL_STATE.ADDING) {
24183
- this.creating = true;
24184
- this.handleAdding();
24185
- }
24199
+ if (this.state === RECTANGLE_TOOL_STATE.ADDING) this.handleAdding();
24186
24200
  });
24187
24201
  stage.on("pointermove", (e) => {
24188
24202
  if (!this.isPressed(e)) return;
@@ -24191,19 +24205,13 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24191
24205
  this.state = RECTANGLE_TOOL_STATE.ADDING;
24192
24206
  return;
24193
24207
  }
24194
- if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
24195
- this.moved = true;
24196
- this.handleMovement();
24197
- }
24208
+ if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) this.handleMovement();
24198
24209
  });
24199
24210
  stage.on("pointerup", (e) => {
24200
24211
  this.pointers.delete(e.evt.pointerId);
24201
24212
  const isTap = this.isTap(e);
24202
24213
  if (isTap) this.moved = false;
24203
- if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
24204
- this.creating = false;
24205
- this.handleSettingSize();
24206
- }
24214
+ if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) this.handleSettingSize();
24207
24215
  });
24208
24216
  this.initialized = true;
24209
24217
  }
@@ -24219,29 +24227,28 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24219
24227
  this.setState(RECTANGLE_TOOL_STATE.ADDING);
24220
24228
  }
24221
24229
  handleAdding() {
24222
- const { mousePoint, container } = this.instance.getMousePointer();
24230
+ const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
24223
24231
  this.clickPoint = mousePoint;
24224
24232
  this.container = container;
24233
+ this.measureContainer = measureContainer;
24225
24234
  this.rectId = v4_default();
24226
- const nodeHandler = this.instance.getNodeHandler("rectangle");
24227
- if (nodeHandler) {
24228
- const node = nodeHandler.create(this.rectId, {
24235
+ if (!this.tempRectNode) {
24236
+ this.tempRectNode = new Konva.Rect({
24229
24237
  ...this.props,
24238
+ id: this.rectId,
24230
24239
  strokeScaleEnabled: true,
24231
24240
  x: this.clickPoint?.x ?? 0,
24232
24241
  y: this.clickPoint?.y ?? 0,
24233
24242
  width: 0,
24234
24243
  height: 0
24235
24244
  });
24236
- this.instance.addNode(node, this.container?.getAttrs().id);
24245
+ this.measureContainer?.add(this.tempRectNode);
24237
24246
  }
24238
24247
  this.setState(RECTANGLE_TOOL_STATE.DEFINING_SIZE);
24239
24248
  }
24240
24249
  handleSettingSize() {
24241
- const rectangle = this.instance.getStage().findOne(`#${this.rectId}`);
24242
- if (this.rectId && this.clickPoint && this.container && rectangle) {
24250
+ if (this.rectId && this.tempRectNode && this.clickPoint && this.container) {
24243
24251
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.container);
24244
- const nodeHandler = this.instance.getNodeHandler("rectangle");
24245
24252
  const rectPos = {
24246
24253
  x: this.clickPoint.x,
24247
24254
  y: this.clickPoint.y
@@ -24254,31 +24261,38 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24254
24261
  rectWidth = Math.abs(this.clickPoint.x - mousePoint.x);
24255
24262
  rectHeight = Math.abs(this.clickPoint.y - mousePoint.y);
24256
24263
  }
24257
- rectangle.setAttrs({
24264
+ this.tempRectNode.setAttrs({
24258
24265
  ...this.props,
24259
24266
  x: rectPos.x,
24260
24267
  y: rectPos.y,
24261
24268
  width: rectWidth,
24262
24269
  height: rectHeight
24263
24270
  });
24264
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
24271
+ const nodeHandler = this.instance.getNodeHandler("rectangle");
24272
+ if (nodeHandler) {
24273
+ const clonedRectNode = this.tempRectNode.clone();
24274
+ this.tempRectNode.destroy();
24275
+ const node = nodeHandler.create(this.rectId, {
24276
+ ...this.props,
24277
+ ...clonedRectNode.getAttrs()
24278
+ });
24279
+ this.instance.addNode(node, this.container?.getAttrs().id);
24280
+ }
24265
24281
  this.instance.emitEvent("onAddedRectangle");
24266
24282
  }
24267
24283
  this.cancelAction();
24268
24284
  }
24269
24285
  handleMovement() {
24270
24286
  if (this.state !== RECTANGLE_TOOL_STATE.DEFINING_SIZE) return;
24271
- const rectangle = this.instance.getStage().findOne(`#${this.rectId}`);
24272
- if (this.rectId && this.container && this.clickPoint && rectangle) {
24273
- const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.container);
24287
+ if (this.rectId && this.tempRectNode && this.measureContainer && this.clickPoint) {
24288
+ this.moved = true;
24289
+ const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
24274
24290
  const deltaX = mousePoint.x - this.clickPoint?.x;
24275
24291
  const deltaY = mousePoint.y - this.clickPoint?.y;
24276
- const nodeHandler = this.instance.getNodeHandler("rectangle");
24277
- rectangle.setAttrs({
24292
+ this.tempRectNode.setAttrs({
24278
24293
  width: deltaX,
24279
24294
  height: deltaY
24280
24295
  });
24281
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
24282
24296
  }
24283
24297
  }
24284
24298
  trigger(cancelAction) {
@@ -24303,9 +24317,10 @@ var WeaveRectangleToolAction = class extends WeaveAction {
24303
24317
  this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24304
24318
  }
24305
24319
  this.rectId = null;
24306
- this.creating = false;
24320
+ this.tempRectNode = null;
24307
24321
  this.moved = false;
24308
24322
  this.container = void 0;
24323
+ this.measureContainer = void 0;
24309
24324
  this.clickPoint = null;
24310
24325
  this.setState(RECTANGLE_TOOL_STATE.IDLE);
24311
24326
  }
@@ -24541,6 +24556,8 @@ var WeavePenToolAction = class extends WeaveAction {
24541
24556
  this.state = PEN_TOOL_STATE.IDLE;
24542
24557
  this.lineId = null;
24543
24558
  this.tempLineId = null;
24559
+ this.tempMainLineNode = null;
24560
+ this.tempLineNode = null;
24544
24561
  this.container = void 0;
24545
24562
  this.measureContainer = void 0;
24546
24563
  this.clickPoint = null;
@@ -24580,11 +24597,10 @@ var WeavePenToolAction = class extends WeaveAction {
24580
24597
  this.state = PEN_TOOL_STATE.ADDING;
24581
24598
  return;
24582
24599
  }
24583
- if (this.state === PEN_TOOL_STATE.ADDING) this.handleAdding();
24600
+ if (!this.tempMainLineNode && this.state === PEN_TOOL_STATE.ADDING) this.handleAdding();
24601
+ if (this.tempMainLineNode && this.state === PEN_TOOL_STATE.ADDING) this.state = PEN_TOOL_STATE.DEFINING_SIZE;
24584
24602
  });
24585
- stage.on("pointermove", (e) => {
24586
- if (!this.isPressed(e)) return;
24587
- if (!this.pointers.has(e.evt.pointerId)) return;
24603
+ stage.on("pointermove", () => {
24588
24604
  if (this.pointers.size === 2 && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
24589
24605
  this.state = PEN_TOOL_STATE.ADDING;
24590
24606
  return;
@@ -24603,6 +24619,8 @@ var WeavePenToolAction = class extends WeaveAction {
24603
24619
  addLine() {
24604
24620
  const stage = this.instance.getStage();
24605
24621
  stage.container().style.cursor = "crosshair";
24622
+ stage.container().focus();
24623
+ this.instance.emitEvent("onAddingPen");
24606
24624
  this.tempPoint = void 0;
24607
24625
  this.tempNextPoint = void 0;
24608
24626
  this.clickPoint = null;
@@ -24616,63 +24634,58 @@ var WeavePenToolAction = class extends WeaveAction {
24616
24634
  this.measureContainer = measureContainer;
24617
24635
  this.lineId = v4_default();
24618
24636
  this.tempLineId = v4_default();
24619
- const nodeHandler = this.instance.getNodeHandler("line");
24620
- if (nodeHandler) {
24621
- const node = nodeHandler.create(this.lineId, {
24637
+ if (!this.tempLineNode) {
24638
+ this.tempMainLineNode = new Konva.Line({
24622
24639
  ...this.props,
24640
+ id: this.lineId,
24623
24641
  strokeScaleEnabled: true,
24624
24642
  x: this.clickPoint?.x ?? 0,
24625
24643
  y: this.clickPoint?.y ?? 0,
24626
24644
  points: [0, 0]
24627
24645
  });
24628
- this.instance.addNode(node, this.container?.getAttrs().id);
24629
- }
24630
- this.tempPoint = new Konva.Circle({
24631
- x: this.clickPoint?.x ?? 0,
24632
- y: this.clickPoint?.y ?? 0,
24633
- radius: 5 / stage.scaleX(),
24634
- strokeScaleEnabled: true,
24635
- stroke: "#cccccc",
24636
- strokeWidth: 0,
24637
- fill: "#cccccc"
24638
- });
24639
- this.measureContainer?.add(this.tempPoint);
24640
- if (nodeHandler) {
24641
- const tempLine = nodeHandler.create(this.tempLineId, {
24646
+ this.measureContainer?.add(this.tempMainLineNode);
24647
+ this.tempPoint = new Konva.Circle({
24648
+ x: this.clickPoint?.x ?? 0,
24649
+ y: this.clickPoint?.y ?? 0,
24650
+ radius: 5 / stage.scaleX(),
24651
+ strokeScaleEnabled: true,
24652
+ stroke: "#cccccc",
24653
+ strokeWidth: 0,
24654
+ fill: "#cccccc"
24655
+ });
24656
+ this.measureContainer?.add(this.tempPoint);
24657
+ this.tempLineNode = new Konva.Line({
24642
24658
  ...this.props,
24659
+ id: this.tempLineId,
24643
24660
  x: this.clickPoint?.x ?? 0,
24644
24661
  y: this.clickPoint?.y ?? 0,
24645
24662
  strokeScaleEnabled: true,
24646
24663
  points: [0, 0]
24647
24664
  });
24648
- this.instance.addNode(tempLine, this.container?.getAttrs().id);
24665
+ this.measureContainer?.add(this.tempLineNode);
24666
+ this.tempNextPoint = new Konva.Circle({
24667
+ x: this.clickPoint?.x ?? 0,
24668
+ y: this.clickPoint?.y ?? 0,
24669
+ radius: 5 / stage.scaleX(),
24670
+ strokeScaleEnabled: true,
24671
+ stroke: "#cccccc",
24672
+ strokeWidth: 0,
24673
+ fill: "#cccccc"
24674
+ });
24675
+ this.measureContainer?.add(this.tempNextPoint);
24676
+ this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
24649
24677
  }
24650
- this.tempNextPoint = new Konva.Circle({
24651
- x: this.clickPoint?.x ?? 0,
24652
- y: this.clickPoint?.y ?? 0,
24653
- radius: 5 / stage.scaleX(),
24654
- strokeScaleEnabled: true,
24655
- stroke: "#cccccc",
24656
- strokeWidth: 0,
24657
- fill: "#cccccc"
24658
- });
24659
- this.measureContainer?.add(this.tempNextPoint);
24660
- this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
24661
24678
  }
24662
24679
  handleSettingSize() {
24663
- const tempLine = this.instance.getStage().findOne(`#${this.tempLineId}`);
24664
- const tempMainLine = this.instance.getStage().findOne(`#${this.lineId}`);
24665
- if (this.lineId && this.tempPoint && this.tempNextPoint && this.measureContainer && tempMainLine && tempLine) {
24680
+ if (this.lineId && this.tempLineNode && this.tempMainLineNode && this.tempPoint && this.tempNextPoint && this.measureContainer) {
24666
24681
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
24667
- const newPoints = [...tempMainLine.points()];
24668
- newPoints.push(mousePoint.x - tempMainLine.x());
24669
- newPoints.push(mousePoint.y - tempMainLine.y());
24670
- tempMainLine.setAttrs({
24682
+ const newPoints = [...this.tempMainLineNode.points()];
24683
+ newPoints.push(mousePoint.x - this.tempMainLineNode.x());
24684
+ newPoints.push(mousePoint.y - this.tempMainLineNode.y());
24685
+ this.tempMainLineNode.setAttrs({
24671
24686
  ...this.props,
24672
24687
  points: newPoints
24673
24688
  });
24674
- const nodeHandler = this.instance.getNodeHandler("line");
24675
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
24676
24689
  this.tempPoint.setAttrs({
24677
24690
  x: mousePoint.x,
24678
24691
  y: mousePoint.y
@@ -24681,32 +24694,28 @@ var WeavePenToolAction = class extends WeaveAction {
24681
24694
  x: mousePoint.x,
24682
24695
  y: mousePoint.y
24683
24696
  });
24684
- tempLine.setAttrs({
24697
+ this.tempLineNode.setAttrs({
24685
24698
  ...this.props,
24686
24699
  x: mousePoint.x,
24687
24700
  y: mousePoint.y,
24688
24701
  points: [0, 0]
24689
24702
  });
24690
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
24703
+ this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
24691
24704
  }
24692
- this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
24693
24705
  }
24694
24706
  handleMovement() {
24695
24707
  if (this.state !== PEN_TOOL_STATE.DEFINING_SIZE) return;
24696
- const tempLine = this.instance.getStage().findOne(`#${this.tempLineId}`);
24697
- if (this.lineId && this.measureContainer && this.tempNextPoint && tempLine) {
24708
+ if (this.tempLineNode && this.measureContainer && this.tempNextPoint) {
24698
24709
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
24699
- tempLine.setAttrs({
24710
+ this.tempLineNode.setAttrs({
24700
24711
  ...this.props,
24701
24712
  points: [
24702
- tempLine.points()[0],
24703
- tempLine.points()[1],
24704
- mousePoint.x - tempLine.x(),
24705
- mousePoint.y - tempLine.y()
24713
+ this.tempLineNode.points()[0],
24714
+ this.tempLineNode.points()[1],
24715
+ mousePoint.x - this.tempLineNode.x(),
24716
+ mousePoint.y - this.tempLineNode.y()
24706
24717
  ]
24707
24718
  });
24708
- const nodeHandler = this.instance.getNodeHandler("line");
24709
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
24710
24719
  this.tempNextPoint.setAttrs({
24711
24720
  x: mousePoint.x,
24712
24721
  y: mousePoint.y
@@ -24729,24 +24738,20 @@ var WeavePenToolAction = class extends WeaveAction {
24729
24738
  const stage = this.instance.getStage();
24730
24739
  this.tempPoint?.destroy();
24731
24740
  this.tempNextPoint?.destroy();
24732
- const tempLine = this.instance.getStage().findOne(`#${this.tempLineId}`);
24733
- const tempMainLine = this.instance.getStage().findOne(`#${this.lineId}`);
24734
- if (tempLine) {
24735
- const nodeHandler = this.instance.getNodeHandler("line");
24736
- if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempLine));
24737
- }
24738
- if (this.lineId && tempMainLine && tempMainLine.points().length < 4) {
24739
- const nodeHandler = this.instance.getNodeHandler("line");
24740
- if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainLine));
24741
- }
24742
- if (this.lineId && tempMainLine && tempMainLine.points().length >= 4) {
24741
+ this.tempLineNode?.destroy();
24742
+ if (this.lineId && this.tempMainLineNode && this.tempMainLineNode.points().length >= 4) {
24743
24743
  const nodeHandler = this.instance.getNodeHandler("line");
24744
- tempMainLine.setAttrs({
24745
- ...this.props,
24746
- strokeWidth: 1,
24747
- hitStrokeWidth: 16
24748
- });
24749
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
24744
+ if (nodeHandler) {
24745
+ const clonedLine = this.tempMainLineNode.clone();
24746
+ this.tempMainLineNode.destroy();
24747
+ const node = nodeHandler.create(this.lineId, {
24748
+ ...this.props,
24749
+ ...clonedLine.getAttrs(),
24750
+ hitStrokeWidth: 16
24751
+ });
24752
+ this.instance.addNode(node, this.container?.getAttrs().id);
24753
+ this.instance.emitEvent("onAddedPen");
24754
+ }
24750
24755
  }
24751
24756
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24752
24757
  if (selectionPlugin) {
@@ -24759,8 +24764,11 @@ var WeavePenToolAction = class extends WeaveAction {
24759
24764
  this.tempPoint = void 0;
24760
24765
  this.tempNextPoint = void 0;
24761
24766
  this.lineId = null;
24767
+ this.tempMainLineNode = null;
24762
24768
  this.tempLineId = null;
24769
+ this.tempLineNode = null;
24763
24770
  this.container = void 0;
24771
+ this.measureContainer = void 0;
24764
24772
  this.clickPoint = null;
24765
24773
  this.setState(PEN_TOOL_STATE.IDLE);
24766
24774
  }
@@ -24963,11 +24971,13 @@ var WeaveBrushToolAction = class extends WeaveAction {
24963
24971
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
24964
24972
  this.props = this.initProps();
24965
24973
  this.setState(BRUSH_TOOL_STATE.IDLE);
24974
+ this.instance.emitEvent("onAddingBrush");
24966
24975
  stage.container().style.cursor = "crosshair";
24967
24976
  }
24968
24977
  cleanup() {
24969
24978
  const stage = this.instance.getStage();
24970
24979
  stage.container().style.cursor = "default";
24980
+ this.instance.emitEvent("onAddedBrush");
24971
24981
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24972
24982
  if (selectionPlugin) {
24973
24983
  const node = stage.findOne(`#${this.strokeId}`);
@@ -25038,6 +25048,8 @@ var WeaveTextToolAction = class extends WeaveAction {
25038
25048
  tr.hide();
25039
25049
  }
25040
25050
  stage.container().style.cursor = "crosshair";
25051
+ stage.container().focus();
25052
+ this.instance.emitEvent("onAddingText");
25041
25053
  this.clickPoint = null;
25042
25054
  this.setState(TEXT_TOOL_STATE.ADDING);
25043
25055
  }
@@ -25055,6 +25067,7 @@ var WeaveTextToolAction = class extends WeaveAction {
25055
25067
  draggable: true
25056
25068
  });
25057
25069
  this.instance.addNode(node, this.container?.getAttrs().id);
25070
+ this.instance.emitEvent("onAddedArrow");
25058
25071
  }
25059
25072
  this.setState(TEXT_TOOL_STATE.FINISHED);
25060
25073
  this.cancelAction();
@@ -25314,10 +25327,13 @@ var WeaveArrowToolAction = class extends WeaveAction {
25314
25327
  onInit = void 0;
25315
25328
  constructor() {
25316
25329
  super();
25330
+ this.pointers = new Map();
25317
25331
  this.initialized = false;
25318
25332
  this.state = ARROW_TOOL_STATE.IDLE;
25319
25333
  this.arrowId = null;
25320
25334
  this.tempArrowId = null;
25335
+ this.tempMainArrowNode = null;
25336
+ this.tempArrowNode = null;
25321
25337
  this.container = void 0;
25322
25338
  this.measureContainer = void 0;
25323
25339
  this.clickPoint = null;
@@ -25352,22 +25368,29 @@ var WeaveArrowToolAction = class extends WeaveAction {
25352
25368
  return;
25353
25369
  }
25354
25370
  });
25355
- stage.on("pointerdblclick", () => {
25356
- this.cancelAction();
25357
- });
25358
- stage.on("pointerclick", () => {
25359
- if (this.state === ARROW_TOOL_STATE.IDLE) return;
25360
- if (this.state === ARROW_TOOL_STATE.ADDING) {
25361
- this.handleAdding();
25371
+ stage.on("pointerdown", (e) => {
25372
+ this.setTapStart(e);
25373
+ this.pointers.set(e.evt.pointerId, {
25374
+ x: e.evt.clientX,
25375
+ y: e.evt.clientY
25376
+ });
25377
+ if (this.pointers.size === 2 && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
25378
+ this.state = ARROW_TOOL_STATE.ADDING;
25362
25379
  return;
25363
25380
  }
25364
- if (this.state === ARROW_TOOL_STATE.DEFINING_SIZE) {
25365
- this.handleSettingSize();
25381
+ if (!this.tempMainArrowNode && this.state === ARROW_TOOL_STATE.ADDING) this.handleAdding();
25382
+ if (this.tempMainArrowNode && this.state === ARROW_TOOL_STATE.ADDING) this.state = ARROW_TOOL_STATE.DEFINING_SIZE;
25383
+ });
25384
+ stage.on("pointermove", () => {
25385
+ if (this.pointers.size === 2 && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
25386
+ this.state = ARROW_TOOL_STATE.ADDING;
25366
25387
  return;
25367
25388
  }
25389
+ if (this.state === ARROW_TOOL_STATE.DEFINING_SIZE) this.handleMovement();
25368
25390
  });
25369
- stage.on("pointermove", () => {
25370
- this.handleMovement();
25391
+ stage.on("pointerup", (e) => {
25392
+ this.pointers.delete(e.evt.pointerId);
25393
+ if (this.state === ARROW_TOOL_STATE.DEFINING_SIZE) this.handleSettingSize();
25371
25394
  });
25372
25395
  this.initialized = true;
25373
25396
  }
@@ -25377,6 +25400,8 @@ var WeaveArrowToolAction = class extends WeaveAction {
25377
25400
  addArrow() {
25378
25401
  const stage = this.instance.getStage();
25379
25402
  stage.container().style.cursor = "crosshair";
25403
+ stage.container().focus();
25404
+ this.instance.emitEvent("onAddingArrow");
25380
25405
  this.tempPoint = void 0;
25381
25406
  this.tempNextPoint = void 0;
25382
25407
  this.clickPoint = null;
@@ -25390,65 +25415,58 @@ var WeaveArrowToolAction = class extends WeaveAction {
25390
25415
  this.measureContainer = measureContainer;
25391
25416
  this.arrowId = v4_default();
25392
25417
  this.tempArrowId = v4_default();
25393
- const nodeHandler = this.instance.getNodeHandler("arrow");
25394
- const lineNodeHandler = this.instance.getNodeHandler("line");
25395
- if (lineNodeHandler) {
25396
- const node = lineNodeHandler.create(this.arrowId, {
25418
+ if (!this.tempMainArrowNode) {
25419
+ this.tempMainArrowNode = new Konva.Line({
25397
25420
  ...this.props,
25421
+ id: this.arrowId,
25398
25422
  strokeScaleEnabled: true,
25399
25423
  x: this.clickPoint?.x ?? 0,
25400
25424
  y: this.clickPoint?.y ?? 0,
25401
25425
  points: [0, 0]
25402
25426
  });
25403
- this.instance.addNode(node, this.container?.getAttrs().id);
25404
- }
25405
- this.tempPoint = new Konva.Circle({
25406
- x: this.clickPoint?.x ?? 0,
25407
- y: this.clickPoint?.y ?? 0,
25408
- radius: 5 / stage.scaleX(),
25409
- strokeScaleEnabled: true,
25410
- stroke: "#cccccc",
25411
- strokeWidth: 0,
25412
- fill: "#cccccc"
25413
- });
25414
- this.measureContainer?.add(this.tempPoint);
25415
- if (nodeHandler) {
25416
- const tempArrow = nodeHandler.create(this.tempArrowId, {
25417
- ...this.props,
25427
+ this.measureContainer?.add(this.tempMainArrowNode);
25428
+ this.tempPoint = new Konva.Circle({
25418
25429
  x: this.clickPoint?.x ?? 0,
25419
25430
  y: this.clickPoint?.y ?? 0,
25431
+ radius: 5 / stage.scaleX(),
25420
25432
  strokeScaleEnabled: true,
25433
+ stroke: "#cccccc",
25434
+ strokeWidth: 0,
25435
+ fill: "#cccccc"
25436
+ });
25437
+ this.measureContainer?.add(this.tempPoint);
25438
+ this.tempArrowNode = new Konva.Arrow({
25439
+ ...this.props,
25440
+ id: this.tempArrowId,
25441
+ strokeScaleEnabled: true,
25442
+ x: this.clickPoint?.x ?? 0,
25443
+ y: this.clickPoint?.y ?? 0,
25421
25444
  points: [0, 0]
25422
25445
  });
25423
- this.instance.addNode(tempArrow, this.container?.getAttrs().id);
25446
+ this.measureContainer?.add(this.tempArrowNode);
25447
+ this.tempNextPoint = new Konva.Circle({
25448
+ x: this.clickPoint?.x ?? 0,
25449
+ y: this.clickPoint?.y ?? 0,
25450
+ radius: 5 / stage.scaleX(),
25451
+ strokeScaleEnabled: true,
25452
+ stroke: "#cccccc",
25453
+ strokeWidth: 0,
25454
+ fill: "#cccccc"
25455
+ });
25456
+ this.measureContainer?.add(this.tempNextPoint);
25457
+ this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
25424
25458
  }
25425
- this.tempNextPoint = new Konva.Circle({
25426
- x: this.clickPoint?.x ?? 0,
25427
- y: this.clickPoint?.y ?? 0,
25428
- radius: 5 / stage.scaleX(),
25429
- strokeScaleEnabled: true,
25430
- stroke: "#cccccc",
25431
- strokeWidth: 0,
25432
- fill: "#cccccc"
25433
- });
25434
- this.measureContainer?.add(this.tempNextPoint);
25435
- this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
25436
25459
  }
25437
25460
  handleSettingSize() {
25438
- const tempArrow = this.instance.getStage().findOne(`#${this.tempArrowId}`);
25439
- const tempMainArrow = this.instance.getStage().findOne(`#${this.arrowId}`);
25440
- if (this.arrowId && this.tempPoint && this.tempNextPoint && this.measureContainer && tempMainArrow && tempArrow) {
25461
+ if (this.arrowId && this.tempMainArrowNode && this.tempArrowNode && this.tempPoint && this.tempNextPoint && this.measureContainer) {
25441
25462
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
25442
- const newPoints = [...tempMainArrow.points()];
25443
- newPoints.push(mousePoint.x - tempMainArrow.x());
25444
- newPoints.push(mousePoint.y - tempMainArrow.y());
25445
- tempMainArrow.setAttrs({
25463
+ const newPoints = [...this.tempMainArrowNode.points()];
25464
+ newPoints.push(mousePoint.x - this.tempMainArrowNode.x());
25465
+ newPoints.push(mousePoint.y - this.tempMainArrowNode.y());
25466
+ this.tempMainArrowNode.setAttrs({
25446
25467
  ...this.props,
25447
25468
  points: newPoints
25448
25469
  });
25449
- const nodeHandler = this.instance.getNodeHandler("arrow");
25450
- const lineNodeHandler = this.instance.getNodeHandler("line");
25451
- if (lineNodeHandler) this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
25452
25470
  this.tempPoint.setAttrs({
25453
25471
  x: mousePoint.x,
25454
25472
  y: mousePoint.y
@@ -25457,32 +25475,28 @@ var WeaveArrowToolAction = class extends WeaveAction {
25457
25475
  x: mousePoint.x,
25458
25476
  y: mousePoint.y
25459
25477
  });
25460
- tempArrow.setAttrs({
25478
+ this.tempArrowNode.setAttrs({
25461
25479
  ...this.props,
25462
25480
  x: mousePoint.x,
25463
25481
  y: mousePoint.y,
25464
25482
  points: [0, 0]
25465
25483
  });
25466
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
25484
+ this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
25467
25485
  }
25468
- this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
25469
25486
  }
25470
25487
  handleMovement() {
25471
25488
  if (this.state !== ARROW_TOOL_STATE.DEFINING_SIZE) return;
25472
- const tempArrow = this.instance.getStage().findOne(`#${this.tempArrowId}`);
25473
- if (this.arrowId && this.measureContainer && this.tempNextPoint && tempArrow) {
25489
+ if (this.arrowId && this.tempArrowNode && this.measureContainer && this.tempNextPoint) {
25474
25490
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
25475
- tempArrow.setAttrs({
25491
+ this.tempArrowNode.setAttrs({
25476
25492
  ...this.props,
25477
25493
  points: [
25478
- tempArrow.points()[0],
25479
- tempArrow.points()[1],
25480
- mousePoint.x - tempArrow.x(),
25481
- mousePoint.y - tempArrow.y()
25494
+ this.tempArrowNode.points()[0],
25495
+ this.tempArrowNode.points()[1],
25496
+ mousePoint.x - this.tempArrowNode.x(),
25497
+ mousePoint.y - this.tempArrowNode.y()
25482
25498
  ]
25483
25499
  });
25484
- const nodeHandler = this.instance.getNodeHandler("arrow");
25485
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
25486
25500
  this.tempNextPoint.setAttrs({
25487
25501
  x: mousePoint.x,
25488
25502
  y: mousePoint.y
@@ -25505,29 +25519,19 @@ var WeaveArrowToolAction = class extends WeaveAction {
25505
25519
  const stage = this.instance.getStage();
25506
25520
  this.tempPoint?.destroy();
25507
25521
  this.tempNextPoint?.destroy();
25508
- const tempArrow = this.instance.getStage().findOne(`#${this.tempArrowId}`);
25509
- const tempMainArrow = this.instance.getStage().findOne(`#${this.arrowId}`);
25510
- if (tempArrow) {
25522
+ this.tempArrowNode?.destroy();
25523
+ if (this.arrowId && this.tempMainArrowNode && this.tempMainArrowNode.points().length >= 4) {
25511
25524
  const nodeHandler = this.instance.getNodeHandler("arrow");
25512
- if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempArrow));
25513
- }
25514
- if (this.arrowId && tempMainArrow && tempMainArrow.points().length < 4) {
25515
- const nodeHandler = this.instance.getNodeHandler("line");
25516
- if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
25517
- }
25518
- if (this.arrowId && tempMainArrow && tempMainArrow.points().length >= 4) {
25519
- const nodeHandler = this.instance.getNodeHandler("arrow");
25520
- const lineNodeHandler = this.instance.getNodeHandler("line");
25521
- if (nodeHandler && lineNodeHandler) {
25525
+ if (nodeHandler) {
25526
+ const clonedLine = this.tempMainArrowNode.clone();
25527
+ this.tempMainArrowNode.destroy();
25522
25528
  const finalArrow = nodeHandler.create(this.arrowId, {
25523
- ...tempMainArrow.getAttrs(),
25524
25529
  ...this.props,
25525
- strokeScaleEnabled: true,
25526
- strokeWidth: 1,
25530
+ ...clonedLine.getAttrs(),
25527
25531
  hitStrokeWidth: 16
25528
25532
  });
25529
- this.instance.removeNode(lineNodeHandler.serialize(tempMainArrow));
25530
25533
  this.instance.addNode(finalArrow, this.container?.getAttrs().id);
25534
+ this.instance.emitEvent("onAddedArrow");
25531
25535
  }
25532
25536
  }
25533
25537
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -25542,7 +25546,10 @@ var WeaveArrowToolAction = class extends WeaveAction {
25542
25546
  this.tempNextPoint = void 0;
25543
25547
  this.arrowId = null;
25544
25548
  this.tempArrowId = null;
25549
+ this.tempMainArrowNode = null;
25550
+ this.tempArrowNode = null;
25545
25551
  this.container = void 0;
25552
+ this.measureContainer = void 0;
25546
25553
  this.clickPoint = null;
25547
25554
  this.setState(ARROW_TOOL_STATE.IDLE);
25548
25555
  }
@@ -25804,6 +25811,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
25804
25811
  const stage = this.instance.getStage();
25805
25812
  stage.container().style.cursor = "crosshair";
25806
25813
  stage.container().focus();
25814
+ this.instance.emitEvent("onAddingFrame");
25807
25815
  this.frameId = null;
25808
25816
  this.clickPoint = null;
25809
25817
  this.setState(FRAME_TOOL_STATE.ADDING);
@@ -25825,6 +25833,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
25825
25833
  y: this.clickPoint.y
25826
25834
  });
25827
25835
  this.instance.addNode(node, this.container?.getAttrs().id);
25836
+ this.instance.emitEvent("onAddedFrame");
25828
25837
  }
25829
25838
  this.cancelAction?.();
25830
25839
  }
@@ -26284,7 +26293,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
26284
26293
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
26285
26294
  this.onRender();
26286
26295
  };
26287
- stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
26296
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
26288
26297
  stage.on("pointermove", () => {
26289
26298
  if (this.enabled) this.onRender();
26290
26299
  });
@@ -26856,7 +26865,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
26856
26865
  newConnectedUsers[userInformation.id] = userInformation;
26857
26866
  }
26858
26867
  }
26859
- if (!(0, import_lodash$1.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
26868
+ if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
26860
26869
  this.connectedUsers = newConnectedUsers;
26861
26870
  });
26862
26871
  }