@inditextech/weave-sdk 0.33.0 → 0.35.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
@@ -15493,7 +15493,6 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
15493
15493
  } else root._ = _;
15494
15494
  }).call(exports);
15495
15495
  } });
15496
- var import_lodash$1 = __toESM(require_lodash());
15497
15496
  var import_lodash = __toESM(require_lodash(), 1);
15498
15497
 
15499
15498
  //#endregion
@@ -15587,12 +15586,12 @@ var WeaveStore = class {
15587
15586
  node: JSON.parse(JSON.stringify(nodeInfo.node))
15588
15587
  });
15589
15588
  }
15590
- if (!this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) {
15589
+ if (!this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) {
15591
15590
  this.instance.setupRenderer();
15592
15591
  this.isRoomLoaded = true;
15593
15592
  this.instance.emitEvent("onRoomLoaded", this.isRoomLoaded);
15594
15593
  }
15595
- if (this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) this.instance.render();
15594
+ if (this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) this.instance.render();
15596
15595
  });
15597
15596
  }
15598
15597
  canUndoStateStep() {
@@ -15684,9 +15683,8 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15684
15683
  const mousePos = stage.getPointerPosition();
15685
15684
  if (mousePos && mousePos.x >= box.x && mousePos.x <= box.x + box.width && mousePos.y >= box.y && mousePos.y <= box.y + box.height) clickOnTransformer = true;
15686
15685
  }
15687
- if (target !== stage && !clickOnTransformer) return;
15688
15686
  let nodes = [];
15689
- if (clickOnTransformer && selectionPlugin) {
15687
+ if (target !== stage && clickOnTransformer && selectionPlugin) {
15690
15688
  const transformer = selectionPlugin.getTransformer();
15691
15689
  nodes = transformer.getNodes().map((node) => {
15692
15690
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
@@ -15696,6 +15694,13 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15696
15694
  };
15697
15695
  }).filter((node) => typeof node !== "undefined");
15698
15696
  }
15697
+ if (target !== stage && !clickOnTransformer) {
15698
+ const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
15699
+ nodes = [{
15700
+ instance: target,
15701
+ node: nodeHandler?.serialize(target)
15702
+ }];
15703
+ }
15699
15704
  const containerRect = stage.container().getBoundingClientRect();
15700
15705
  const pointerPos = stage.getPointerPosition();
15701
15706
  if (containerRect && pointerPos) {
@@ -15724,19 +15729,34 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15724
15729
  }
15725
15730
  initEvents() {
15726
15731
  const stage = this.instance.getStage();
15732
+ this.instance.addEventListener("onDrag", (node) => {
15733
+ if (node) this.dragging = true;
15734
+ else this.dragging = false;
15735
+ });
15736
+ this.instance.addEventListener("onTransform", (node) => {
15737
+ if (node) this.transforming = true;
15738
+ else this.transforming = false;
15739
+ });
15727
15740
  stage.on("pointerdown", (e) => {
15728
15741
  this.pointers[e.evt.pointerId] = e.evt;
15742
+ if (e.evt.pointerType === "mouse") return;
15729
15743
  if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
15730
15744
  this.touchTimer = setTimeout(() => {
15731
15745
  this.tapHold = true;
15746
+ if (this.touchTimer && (this.dragging || this.transforming)) {
15747
+ clearTimeout(this.touchTimer);
15748
+ return;
15749
+ }
15732
15750
  this.triggerContextMenu(e.target);
15733
15751
  }, this.tapHoldTimeout);
15734
15752
  });
15735
- stage.on("pointermove", () => {
15753
+ stage.on("pointermove", (e) => {
15754
+ if (e.evt.pointerType === "mouse") return;
15736
15755
  if (this.touchTimer) clearTimeout(this.touchTimer);
15737
15756
  });
15738
15757
  stage.on("pointerup", (e) => {
15739
15758
  delete this.pointers[e.evt.pointerId];
15759
+ if (e.evt.pointerType === "mouse") return;
15740
15760
  if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
15741
15761
  if (this.touchTimer) {
15742
15762
  clearTimeout(this.touchTimer);
@@ -15804,6 +15824,8 @@ function checkIfOverContainer(instance, node) {
15804
15824
  }
15805
15825
  function moveNodeToContainer(instance, node) {
15806
15826
  const nodeIntersected = instance.pointIntersectsContainerElement();
15827
+ const isLocked = instance.allNodesLocked([node]);
15828
+ if (isLocked) return;
15807
15829
  let nodeActualContainer = node.getParent();
15808
15830
  if (!nodeActualContainer) return void 0;
15809
15831
  const actualContainerAttrs = nodeActualContainer.getAttrs();
@@ -16016,7 +16038,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16016
16038
  const handleTransform = () => {
16017
16039
  this.triggerSelectedNodesEvent();
16018
16040
  };
16019
- tr.on("transform", (0, import_lodash$1.throttle)(handleTransform, 50));
16041
+ tr.on("transform", (0, import_lodash.throttle)(handleTransform, 50));
16020
16042
  tr.on("transformend", () => {
16021
16043
  this.triggerSelectedNodesEvent();
16022
16044
  });
@@ -16056,7 +16078,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16056
16078
  }
16057
16079
  tr.forceUpdate();
16058
16080
  };
16059
- tr.on("dragmove", (0, import_lodash$1.throttle)(handleDragMove, 50));
16081
+ tr.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 50));
16060
16082
  tr.on("dragend", (e) => {
16061
16083
  this.dragging = false;
16062
16084
  e.cancelBubble = true;
@@ -16206,7 +16228,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16206
16228
  height: Math.abs(y2 - y1)
16207
16229
  });
16208
16230
  };
16209
- stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
16231
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
16210
16232
  stage.on("pointerup", (e) => {
16211
16233
  delete this.pointers[e.evt.pointerId];
16212
16234
  if (!this.initialized) return;
@@ -16243,16 +16265,26 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16243
16265
  return false;
16244
16266
  });
16245
16267
  const selectedNodes = new Set();
16246
- const framesNodes = selected.filter((shape) => shape.getAttrs().nodeType === "frame");
16247
- const framesNodesIds = selected.map((shape) => shape.getAttrs().id);
16268
+ const framesNodes = selected.filter((shape) => {
16269
+ return shape.getAttrs().nodeType === "frame";
16270
+ });
16271
+ const framesNodesIds = framesNodes.map((shape) => {
16272
+ if (shape.getAttrs().nodeType === "frame" && shape.getAttrs().nodeId) return stage.findOne(`#${shape.getAttrs().nodeId}`);
16273
+ return shape;
16274
+ }).filter((shape) => {
16275
+ return shape.getAttrs().nodeType === "frame";
16276
+ }).map((shape) => {
16277
+ return shape.getAttrs().id;
16278
+ });
16248
16279
  const otherNodes = selected.filter((shape) => shape.getAttrs().nodeType !== "frame");
16249
16280
  otherNodes.forEach((node) => {
16250
- const parent = this.instance.getInstanceRecursive(node.getParent());
16251
- if (!framesNodesIds.includes(parent?.getAttrs().id)) selectedNodes.add(node);
16281
+ let parent = this.instance.getInstanceRecursive(node.getParent());
16282
+ if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
16283
+ if (parent && !framesNodesIds.includes(parent?.getAttrs().id) && !node.getAttrs().locked) selectedNodes.add(node);
16252
16284
  });
16253
16285
  framesNodes.forEach((node) => {
16254
16286
  const frameNode = node;
16255
- selectedNodes.add(frameNode);
16287
+ if (!frameNode.getAttrs().locked) selectedNodes.add(frameNode);
16256
16288
  });
16257
16289
  this.tr.nodes([...selectedNodes]);
16258
16290
  this.triggerSelectedNodesEvent();
@@ -16303,6 +16335,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16303
16335
  return node.getAttrs().id === nodeTargeted.getAttrs().id;
16304
16336
  });
16305
16337
  const isSelected = nodeSelectedIndex !== -1;
16338
+ if (nodeTargeted.getAttrs().locked) return;
16306
16339
  if (!metaPressed) {
16307
16340
  this.tr.nodes([nodeTargeted]);
16308
16341
  nodesSelected = this.tr.nodes().length;
@@ -16666,106 +16699,104 @@ var WeaveNode = class {
16666
16699
  node.scaleY(1);
16667
16700
  }
16668
16701
  setupDefaultNodeEvents(node) {
16669
- this.previousPointer = null;
16670
16702
  this.instance.addEventListener("onNodesChange", () => {
16671
- if (this.isSelecting() && this.isNodeSelected(node)) {
16703
+ if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
16672
16704
  node.draggable(true);
16673
16705
  return;
16674
16706
  }
16675
16707
  node.draggable(false);
16676
16708
  });
16677
- let transforming = false;
16678
- node.on("transformstart", () => {
16679
- transforming = true;
16680
- });
16681
- const handleTransform = (e) => {
16682
- const node$1 = e.target;
16683
- const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
16684
- const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
16685
- if (nodesSelectionPlugin && this.isSelecting() && this.isNodeSelected(node$1)) nodesSelectionPlugin.getTransformer().forceUpdate();
16686
- if (nodesSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesSnappingPlugin.evaluateGuidelines(e);
16687
- if (this.isSelecting() && this.isNodeSelected(node$1)) {
16688
- this.scaleReset(node$1);
16689
- const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16690
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16691
- }
16692
- };
16693
- node.on("transform", (0, import_lodash$1.throttle)(handleTransform, 100));
16694
- node.on("transformend", (e) => {
16695
- const node$1 = e.target;
16696
- transforming = false;
16697
- const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
16698
- const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
16699
- if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
16700
- if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
16701
- const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16702
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16703
- });
16704
- node.on("dragstart", (e) => {
16705
- const stage = this.instance.getStage();
16706
- if (stage.isMouseWheelPressed()) {
16707
- e.cancelBubble = true;
16708
- node.stopDrag();
16709
- return;
16710
- }
16711
- });
16712
- const handleDragMove = (e) => {
16713
- const stage = this.instance.getStage();
16714
- if (stage.isMouseWheelPressed()) {
16715
- e.cancelBubble = true;
16716
- node.stopDrag();
16717
- return;
16718
- }
16719
- if (this.isSelecting() && this.isNodeSelected(node)) {
16720
- clearContainerTargets(this.instance);
16721
- const layerToMove = checkIfOverContainer(this.instance, e.target);
16722
- if (layerToMove) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
16723
- const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16724
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
16725
- }
16726
- };
16727
- node.on("dragmove", (0, import_lodash$1.throttle)(handleDragMove, 100));
16728
- node.on("dragend", (e) => {
16729
- if (this.isSelecting() && this.isNodeSelected(node)) {
16730
- clearContainerTargets(this.instance);
16709
+ const isLocked = node.getAttrs().locked ?? false;
16710
+ if (isLocked) {
16711
+ node.off("transformstart");
16712
+ node.off("transform");
16713
+ node.off("transformend");
16714
+ node.off("dragstart");
16715
+ node.off("dragmove");
16716
+ node.off("dragend");
16717
+ node.off("pointerenter");
16718
+ node.off("pointerleave");
16719
+ } else {
16720
+ let transforming = false;
16721
+ node.on("transformstart", (e) => {
16722
+ transforming = true;
16723
+ this.instance.emitEvent("onTransform", e.target);
16724
+ });
16725
+ const handleTransform = (e) => {
16726
+ const node$1 = e.target;
16727
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
16728
+ const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
16729
+ if (nodesSelectionPlugin && this.isSelecting() && this.isNodeSelected(node$1)) nodesSelectionPlugin.getTransformer().forceUpdate();
16730
+ if (nodesSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesSnappingPlugin.evaluateGuidelines(e);
16731
+ if (this.isSelecting() && this.isNodeSelected(node$1)) {
16732
+ this.scaleReset(node$1);
16733
+ const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16734
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16735
+ }
16736
+ };
16737
+ node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
16738
+ node.on("transformend", (e) => {
16739
+ const node$1 = e.target;
16740
+ this.instance.emitEvent("onTransform", null);
16741
+ transforming = false;
16742
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
16731
16743
  const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
16732
16744
  if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
16733
- const containerToMove = moveNodeToContainer(this.instance, e.target);
16734
- if (containerToMove) return;
16735
- this.instance.updateNode(this.serialize(node));
16736
- }
16737
- });
16738
- this.previousPointer = null;
16739
- node.on("pointerenter", () => {
16740
- const realNode = this.instance.getInstanceRecursive(node);
16741
- if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
16742
- const stage = this.instance.getStage();
16743
- this.previousPointer = stage.container().style.cursor;
16744
- stage.container().style.cursor = "pointer";
16745
- return;
16746
- }
16747
- if (this.isPasting()) {
16748
- const stage = this.instance.getStage();
16749
- this.previousPointer = stage.container().style.cursor;
16750
- stage.container().style.cursor = "crosshair";
16751
- return;
16752
- }
16753
- });
16754
- node.on("pointerleave", () => {
16755
- const realNode = this.instance.getInstanceRecursive(node);
16756
- if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
16745
+ if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
16746
+ const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16747
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16748
+ });
16749
+ node.on("dragstart", (e) => {
16757
16750
  const stage = this.instance.getStage();
16758
- stage.container().style.cursor = this.previousPointer ?? "default";
16759
- this.previousPointer = null;
16760
- return;
16761
- }
16762
- if (this.isPasting()) {
16751
+ this.instance.emitEvent("onDrag", e.target);
16752
+ if (stage.isMouseWheelPressed()) {
16753
+ e.cancelBubble = true;
16754
+ e.target.stopDrag();
16755
+ }
16756
+ });
16757
+ const handleDragMove = (e) => {
16763
16758
  const stage = this.instance.getStage();
16764
- this.previousPointer = stage.container().style.cursor;
16765
- stage.container().style.cursor = "crosshair";
16766
- return;
16767
- }
16768
- });
16759
+ if (stage.isMouseWheelPressed()) {
16760
+ e.cancelBubble = true;
16761
+ e.target.stopDrag();
16762
+ return;
16763
+ }
16764
+ if (this.isSelecting() && this.isNodeSelected(node)) {
16765
+ clearContainerTargets(this.instance);
16766
+ const layerToMove = checkIfOverContainer(this.instance, e.target);
16767
+ if (layerToMove) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
16768
+ const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16769
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
16770
+ }
16771
+ };
16772
+ node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
16773
+ node.on("dragend", (e) => {
16774
+ this.instance.emitEvent("onDrag", null);
16775
+ if (this.isSelecting() && this.isNodeSelected(node)) {
16776
+ clearContainerTargets(this.instance);
16777
+ const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
16778
+ if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
16779
+ const containerToMove = moveNodeToContainer(this.instance, e.target);
16780
+ if (containerToMove) return;
16781
+ this.instance.updateNode(this.serialize(node));
16782
+ }
16783
+ });
16784
+ node.on("pointerenter", (e) => {
16785
+ const realNode = this.instance.getInstanceRecursive(node);
16786
+ const isLocked$1 = realNode.getAttrs().locked ?? false;
16787
+ if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
16788
+ const stage = this.instance.getStage();
16789
+ stage.container().style.cursor = !isLocked$1 ? "pointer" : "default";
16790
+ e.cancelBubble = true;
16791
+ return;
16792
+ }
16793
+ if (this.isPasting()) {
16794
+ const stage = this.instance.getStage();
16795
+ stage.container().style.cursor = "crosshair";
16796
+ e.cancelBubble = true;
16797
+ }
16798
+ });
16799
+ }
16769
16800
  }
16770
16801
  create(key, props) {
16771
16802
  return {
@@ -16797,6 +16828,61 @@ var WeaveNode = class {
16797
16828
  }
16798
16829
  };
16799
16830
  }
16831
+ show(instance) {
16832
+ if (instance.getAttrs().nodeType !== this.getNodeType()) return;
16833
+ instance.setAttrs({ visible: true });
16834
+ this.instance.updateNode(this.serialize(instance));
16835
+ this.setupDefaultNodeEvents(instance);
16836
+ const stage = this.instance.getStage();
16837
+ stage.container().style.cursor = "default";
16838
+ }
16839
+ hide(instance) {
16840
+ if (instance.getAttrs().nodeType !== this.getNodeType()) return;
16841
+ instance.setAttrs({ visible: false });
16842
+ const selectionPlugin = this.getSelectionPlugin();
16843
+ if (selectionPlugin) {
16844
+ const ids = [instance.getAttrs().id];
16845
+ if (instance.getAttrs().nodeType === "frame") ids.push(`${instance.getAttrs().id}-selector-area`);
16846
+ const selectedNodes = selectionPlugin.getSelectedNodes();
16847
+ const newSelectedNodes = selectedNodes.filter((node) => !ids.includes(node.getAttrs().id));
16848
+ selectionPlugin.setSelectedNodes(newSelectedNodes);
16849
+ selectionPlugin.getTransformer().forceUpdate();
16850
+ }
16851
+ this.instance.updateNode(this.serialize(instance));
16852
+ this.setupDefaultNodeEvents(instance);
16853
+ const stage = this.instance.getStage();
16854
+ stage.container().style.cursor = "default";
16855
+ }
16856
+ isVisible(instance) {
16857
+ if (typeof instance.getAttrs().visible === "undefined") return true;
16858
+ return instance.getAttrs().visible ?? false;
16859
+ }
16860
+ lock(instance) {
16861
+ if (instance.getAttrs().nodeType !== this.getNodeType()) return;
16862
+ instance.setAttrs({ locked: true });
16863
+ this.instance.updateNode(this.serialize(instance));
16864
+ const selectionPlugin = this.getSelectionPlugin();
16865
+ if (selectionPlugin) {
16866
+ const selectedNodes = selectionPlugin.getSelectedNodes();
16867
+ const newSelectedNodes = selectedNodes.filter((node) => node.getAttrs().id !== instance.getAttrs().id);
16868
+ selectionPlugin.setSelectedNodes(newSelectedNodes);
16869
+ selectionPlugin.getTransformer().forceUpdate();
16870
+ }
16871
+ this.setupDefaultNodeEvents(instance);
16872
+ const stage = this.instance.getStage();
16873
+ stage.container().style.cursor = "default";
16874
+ }
16875
+ unlock(instance) {
16876
+ if (instance.getAttrs().nodeType !== this.getNodeType()) return;
16877
+ instance.setAttrs({ locked: false });
16878
+ this.instance.updateNode(this.serialize(instance));
16879
+ this.setupDefaultNodeEvents(instance);
16880
+ const stage = this.instance.getStage();
16881
+ stage.container().style.cursor = "default";
16882
+ }
16883
+ isLocked(instance) {
16884
+ return instance.getAttrs().locked ?? false;
16885
+ }
16800
16886
  };
16801
16887
 
16802
16888
  //#endregion
@@ -18231,7 +18317,7 @@ var WeaveRegisterManager = class {
18231
18317
 
18232
18318
  //#endregion
18233
18319
  //#region package.json
18234
- var version = "0.33.0";
18320
+ var version = "0.35.0";
18235
18321
 
18236
18322
  //#endregion
18237
18323
  //#region src/managers/setup.ts
@@ -18802,6 +18888,9 @@ var Weave = class {
18802
18888
  getElementsTree() {
18803
18889
  return this.stateManager.getElementsTree();
18804
18890
  }
18891
+ isEmpty() {
18892
+ return this.getElementsTree().length === 0;
18893
+ }
18805
18894
  moveUp(node) {
18806
18895
  this.zIndexManager.moveUp(node);
18807
18896
  }
@@ -18842,7 +18931,8 @@ var Weave = class {
18842
18931
  if (selectionPlugin) {
18843
18932
  const stage = this.getStage();
18844
18933
  const instanceNodes = nodesIds.map((nodeId) => {
18845
- const nodeInstance = stage.findOne(`#${nodeId}`);
18934
+ let nodeInstance = stage.findOne(`#${nodeId}`);
18935
+ if (nodeInstance && nodeInstance.getAttrs().nodeType === "frame") nodeInstance = stage.findOne(`#${nodeId}-selector-area`);
18846
18936
  return nodeInstance;
18847
18937
  });
18848
18938
  selectionPlugin.setSelectedNodes(instanceNodes);
@@ -18863,6 +18953,90 @@ var Weave = class {
18863
18953
  async exportNodes(nodes, boundingNodes, options) {
18864
18954
  return await this.exportManager.exportNodes(nodes, boundingNodes, options);
18865
18955
  }
18956
+ allNodesLocked(nodes) {
18957
+ let allNodesLocked = true;
18958
+ for (const node of nodes) {
18959
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18960
+ if (!nodeHandler) continue;
18961
+ allNodesLocked = allNodesLocked && nodeHandler.isLocked(node);
18962
+ }
18963
+ return allNodesLocked;
18964
+ }
18965
+ allNodesUnlocked(nodes) {
18966
+ let allNodesUnlocked = true;
18967
+ for (const node of nodes) {
18968
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18969
+ if (!nodeHandler) continue;
18970
+ allNodesUnlocked = allNodesUnlocked && !nodeHandler.isLocked(node);
18971
+ }
18972
+ return allNodesUnlocked;
18973
+ }
18974
+ lockNode(node) {
18975
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18976
+ if (!nodeHandler) return;
18977
+ nodeHandler.lock(node);
18978
+ }
18979
+ lockNodes(nodes) {
18980
+ for (const node of nodes) {
18981
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18982
+ if (!nodeHandler) continue;
18983
+ nodeHandler.lock(node);
18984
+ }
18985
+ }
18986
+ unlockNode(node) {
18987
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18988
+ if (!nodeHandler) return;
18989
+ nodeHandler.unlock(node);
18990
+ }
18991
+ unlockNodes(nodes) {
18992
+ for (const node of nodes) {
18993
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
18994
+ if (!nodeHandler) continue;
18995
+ nodeHandler.unlock(node);
18996
+ }
18997
+ }
18998
+ allNodesVisible(nodes) {
18999
+ let allNodesVisible = true;
19000
+ for (const node of nodes) {
19001
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19002
+ if (!nodeHandler) continue;
19003
+ allNodesVisible = allNodesVisible && nodeHandler.isVisible(node);
19004
+ }
19005
+ return allNodesVisible;
19006
+ }
19007
+ allNodesHidden(nodes) {
19008
+ let allNodesHidden = true;
19009
+ for (const node of nodes) {
19010
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19011
+ if (!nodeHandler) continue;
19012
+ allNodesHidden = allNodesHidden && !nodeHandler.isVisible(node);
19013
+ }
19014
+ return allNodesHidden;
19015
+ }
19016
+ hideNode(node) {
19017
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19018
+ if (!nodeHandler) return;
19019
+ nodeHandler.hide(node);
19020
+ }
19021
+ hideNodes(nodes) {
19022
+ for (const node of nodes) {
19023
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19024
+ if (!nodeHandler) continue;
19025
+ nodeHandler.hide(node);
19026
+ }
19027
+ }
19028
+ showNode(node) {
19029
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19030
+ if (!nodeHandler) return;
19031
+ nodeHandler.show(node);
19032
+ }
19033
+ showNodes(nodes) {
19034
+ for (const node of nodes) {
19035
+ const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
19036
+ if (!nodeHandler) continue;
19037
+ nodeHandler.show(node);
19038
+ }
19039
+ }
18866
19040
  };
18867
19041
 
18868
19042
  //#endregion
@@ -18888,6 +19062,28 @@ var WeaveStageNode = class extends WeaveNode {
18888
19062
  stage.container().addEventListener("blur", () => {
18889
19063
  this.stageFocused = false;
18890
19064
  });
19065
+ Konva.Stage.prototype.allowActions = function(actions) {
19066
+ if (typeof actions !== "undefined") this._allowActions = actions;
19067
+ return this._allowActions;
19068
+ };
19069
+ Konva.Stage.prototype.allowSelectNodes = function(nodeTypes) {
19070
+ if (typeof nodeTypes !== "undefined") this._allowSelectNodeTypes = nodeTypes;
19071
+ return this._allowSelectNodeTypes;
19072
+ };
19073
+ Konva.Stage.prototype.allowSelection = function(allowSelection) {
19074
+ if (typeof allowSelection !== "undefined") this._allowSelection = allowSelection;
19075
+ return this._allowSelection;
19076
+ };
19077
+ stage.on("pointermove", (e) => {
19078
+ if (stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
19079
+ const stage$1 = this.instance.getStage();
19080
+ stage$1.container().style.cursor = "default";
19081
+ }
19082
+ if (e.target === stage && this.instance.getActiveAction() === "selectionTool") {
19083
+ const stage$1 = this.instance.getStage();
19084
+ stage$1.container().style.cursor = "default";
19085
+ }
19086
+ });
18891
19087
  stage.on("pointerdown", (e) => {
18892
19088
  if (e.evt.button === 1) this.wheelMousePressed = true;
18893
19089
  });
@@ -19217,7 +19413,13 @@ var WeaveTextNode = class extends WeaveNode {
19217
19413
  const node = e.target;
19218
19414
  if (this.isSelecting() && this.isNodeSelected(node)) e.cancelBubble = true;
19219
19415
  };
19220
- text.on("transform", (0, import_lodash$1.throttle)(handleTextTransform, 50));
19416
+ text.on("transformstart", (e) => {
19417
+ this.instance.emitEvent("onTransform", e.target);
19418
+ });
19419
+ text.on("transform", (0, import_lodash.throttle)(handleTextTransform, 50));
19420
+ text.on("transformend", () => {
19421
+ this.instance.emitEvent("onTransform", null);
19422
+ });
19221
19423
  window.addEventListener("keypress", (e) => {
19222
19424
  if (e.key === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing && e.target !== this.textArea) {
19223
19425
  e.preventDefault();
@@ -19956,19 +20158,26 @@ var WeaveImageCrop = class WeaveImageCrop {
19956
20158
  skipStroke: true
19957
20159
  });
19958
20160
  this.drawGridLines(0, 0, cropRect.width, cropRect.height);
19959
- this.cropRect.on("dragmove", () => {
20161
+ const handleGridLines = () => {
19960
20162
  const cropRect$1 = this.cropRect.getClientRect({
19961
20163
  relativeTo: this.cropGroup,
19962
20164
  skipStroke: true
19963
20165
  });
19964
20166
  this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
20167
+ };
20168
+ this.cropRect.on("dragstart", (e) => {
20169
+ this.instance.emitEvent("onDrag", e.target);
19965
20170
  });
19966
- this.cropRect.on("transform", () => {
19967
- const cropRect$1 = this.cropRect.getClientRect({
19968
- relativeTo: this.cropGroup,
19969
- skipStroke: true
19970
- });
19971
- this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
20171
+ this.cropRect.on("dragmove", handleGridLines);
20172
+ this.cropRect.on("dragend", () => {
20173
+ this.instance.emitEvent("onDrag", null);
20174
+ });
20175
+ this.cropRect.on("transformstart", (e) => {
20176
+ this.instance.emitEvent("onTransform", e.target);
20177
+ });
20178
+ this.cropRect.on("transform", handleGridLines);
20179
+ this.cropRect.on("transformend", () => {
20180
+ this.instance.emitEvent("onTransform", null);
19972
20181
  });
19973
20182
  this.transformer.nodes([this.cropRect]);
19974
20183
  this.cropGroup.add(this.cropImage);
@@ -20450,7 +20659,7 @@ var WeaveImageNode = class extends WeaveNode {
20450
20659
  const stage = this.instance.getStage();
20451
20660
  const image = stage.findOne(`#${imageAttrs.id}`);
20452
20661
  const internalImage = image?.findOne(`#${imageAttrs.id}-image`);
20453
- if (image && internalImage && !imageAttrs.adding && imageAttrs.cropInfo && !(0, import_lodash$1.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
20662
+ if (image && internalImage && !imageAttrs.adding && imageAttrs.cropInfo && !(0, import_lodash.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
20454
20663
  const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
20455
20664
  internalImage.width(imageAttrs.uncroppedImage.width);
20456
20665
  internalImage.height(imageAttrs.uncroppedImage.height);
@@ -20467,7 +20676,7 @@ var WeaveImageNode = class extends WeaveNode {
20467
20676
  internalImage.height(imageAttrs.cropSize.height);
20468
20677
  this.cachedCropInfo[imageAttrs.id ?? ""] = imageAttrs.cropInfo;
20469
20678
  }
20470
- if (image && internalImage && !imageAttrs.adding && !imageAttrs.cropInfo && !(0, import_lodash$1.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
20679
+ if (image && internalImage && !imageAttrs.adding && !imageAttrs.cropInfo && !(0, import_lodash.isEqual)(imageAttrs.cropInfo, this.cachedCropInfo[imageAttrs.id ?? ""])) {
20471
20680
  internalImage.width(imageAttrs.uncroppedImage.width);
20472
20681
  internalImage.height(imageAttrs.uncroppedImage.height);
20473
20682
  internalImage.rotation(0);
@@ -20882,8 +21091,12 @@ var WeaveFrameNode = class extends WeaveNode {
20882
21091
  clonedSA.scaleY(1);
20883
21092
  e.cancelBubble = true;
20884
21093
  };
20885
- selectorArea.on("transform", (0, import_lodash$1.throttle)(handleSelectorAreaTransform, 50));
20886
21094
  selectorArea.on("transformend", (e) => {
21095
+ this.instance.emitEvent("onTransform", e.target);
21096
+ });
21097
+ selectorArea.on("transform", (0, import_lodash.throttle)(handleSelectorAreaTransform, 50));
21098
+ selectorArea.on("transformend", (e) => {
21099
+ this.instance.emitEvent("onTransform", null);
20887
21100
  const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
20888
21101
  if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
20889
21102
  const scaleX = selectorArea.scaleX();
@@ -22724,7 +22937,7 @@ var require_hammer = __commonJS({ "../../node_modules/hammerjs/hammer.js"(export
22724
22937
  else window$1[exportName] = Hammer;
22725
22938
  })(window, document, "Hammer");
22726
22939
  } });
22727
- var import_hammer = __toESM(require_hammer());
22940
+ var import_hammer = __toESM(require_hammer(), 1);
22728
22941
 
22729
22942
  //#endregion
22730
22943
  //#region src/plugins/stage-zoom/stage-zoom.ts
@@ -22764,7 +22977,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22764
22977
  this.config.zoomSteps = [minimumZoom, ...this.config.zoomSteps];
22765
22978
  }
22766
22979
  };
22767
- mainLayer?.on("draw", (0, import_lodash$1.throttle)(handleDraw, 50));
22980
+ mainLayer?.on("draw", (0, import_lodash.throttle)(handleDraw, 50));
22768
22981
  this.setZoom(this.config.zoomSteps[this.actualStep]);
22769
22982
  }
22770
22983
  setZoom(scale, centered = true, pointer) {
@@ -22895,7 +23108,9 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22895
23108
  x: 0,
22896
23109
  y: 0
22897
23110
  });
22898
- const bounds = getBoundingBox(stage, mainLayer.getChildren());
23111
+ let realNodes = mainLayer.getChildren();
23112
+ realNodes = realNodes.filter((node) => typeof node.getAttrs().visible === "undefined" || node.getAttrs().visible);
23113
+ const bounds = getBoundingBox(stage, realNodes);
22899
23114
  const stageWidth = stage.width();
22900
23115
  const stageHeight = stage.height();
22901
23116
  const scaleX = (stageWidth - this.config.fitToScreen.padding * 2) / bounds.width;
@@ -23205,12 +23420,14 @@ var WeaveMoveToolAction = class extends WeaveAction {
23205
23420
  stage.container().focus();
23206
23421
  this.setState(MOVE_TOOL_STATE.MOVING);
23207
23422
  }
23208
- trigger(cancelAction) {
23423
+ trigger(cancelAction, params) {
23209
23424
  if (!this.instance) throw new Error("Instance not defined");
23210
23425
  if (!this.initialized) this.setupEvents();
23211
23426
  const stage = this.instance.getStage();
23212
23427
  stage.container().tabIndex = 1;
23213
23428
  stage.container().focus();
23429
+ const { triggerSelectionTool = true } = params ?? {};
23430
+ this.triggerSelectionTool = triggerSelectionTool;
23214
23431
  this.cancelAction = cancelAction;
23215
23432
  this.setMoving();
23216
23433
  }
@@ -23218,7 +23435,7 @@ var WeaveMoveToolAction = class extends WeaveAction {
23218
23435
  const stage = this.instance.getStage();
23219
23436
  stage.container().style.cursor = "default";
23220
23437
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
23221
- if (selectionPlugin) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
23438
+ if (selectionPlugin && this.triggerSelectionTool) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
23222
23439
  this.setState(MOVE_TOOL_STATE.IDLE);
23223
23440
  }
23224
23441
  };
@@ -23311,7 +23528,8 @@ var WeaveEraserToolAction = class extends WeaveAction {
23311
23528
  if (!realNode) return;
23312
23529
  const nodeType = realNode.getAttrs().nodeType;
23313
23530
  const nodeHandler = this.instance.getNodeHandler(nodeType);
23314
- if (nodeHandler) {
23531
+ const isLocked = this.instance.allNodesLocked([realNode]);
23532
+ if (nodeHandler && !isLocked) {
23315
23533
  const nodeSerialized = nodeHandler.serialize(realNode);
23316
23534
  this.instance.removeNode(nodeSerialized);
23317
23535
  }
@@ -23770,9 +23988,6 @@ var WeavePenToolAction = class extends WeaveAction {
23770
23988
  return;
23771
23989
  }
23772
23990
  });
23773
- stage.on("pointerdblclick", () => {
23774
- this.cancelAction();
23775
- });
23776
23991
  stage.on("pointerclick", () => {
23777
23992
  if (this.state === PEN_TOOL_STATE.IDLE) return;
23778
23993
  if (this.state === PEN_TOOL_STATE.ADDING) {
@@ -25046,6 +25261,252 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
25046
25261
  }
25047
25262
  };
25048
25263
 
25264
+ //#endregion
25265
+ //#region src/actions/align-nodes-tool/constants.ts
25266
+ const ALIGN_NODES_TOOL_ACTION_NAME = "alignNodesTool";
25267
+ const ALIGN_NODES_ALIGN_TO = {
25268
+ ["LEFT_HORIZONTAL"]: "left-horizontal",
25269
+ ["CENTER_HORIZONTAL"]: "center-horizontal",
25270
+ ["RIGHT_HORIZONTAL"]: "right-horizontal",
25271
+ ["TOP_VERTICAL"]: "top-vertical",
25272
+ ["CENTER_VERTICAL"]: "center-vertical",
25273
+ ["BOTTOM_VERTICAL"]: "bottom-vertical"
25274
+ };
25275
+ const ALIGN_NODES_TOOL_STATE = { ["IDLE"]: "idle" };
25276
+
25277
+ //#endregion
25278
+ //#region src/actions/align-nodes-tool/align-nodes-tool.ts
25279
+ var WeaveAlignNodesToolAction = class extends WeaveAction {
25280
+ initialized = false;
25281
+ onPropsChange = void 0;
25282
+ onInit = void 0;
25283
+ constructor() {
25284
+ super();
25285
+ this.initialized = false;
25286
+ this.state = ALIGN_NODES_TOOL_STATE.IDLE;
25287
+ }
25288
+ getName() {
25289
+ return ALIGN_NODES_TOOL_ACTION_NAME;
25290
+ }
25291
+ setupEvents() {
25292
+ this.initialized = true;
25293
+ }
25294
+ setState(state) {
25295
+ this.state = state;
25296
+ }
25297
+ updateNode(node) {
25298
+ const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
25299
+ if (nodeHandler) {
25300
+ const actualNode = nodeHandler.serialize(node);
25301
+ this.instance.updateNode(actualNode);
25302
+ }
25303
+ }
25304
+ getParents(nodes) {
25305
+ if (nodes.length === 0) return [];
25306
+ const counts = {};
25307
+ for (const node of nodes) {
25308
+ let realNode = node;
25309
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25310
+ if (!realNode) continue;
25311
+ const parentId = realNode.getParent()?.getAttrs().id ?? "";
25312
+ const entry = counts[parentId];
25313
+ if (entry) entry.count++;
25314
+ else counts[parentId] = {
25315
+ count: 1,
25316
+ id: realNode.getParent()?.getAttrs().id ?? "",
25317
+ value: realNode.getParent()
25318
+ };
25319
+ }
25320
+ return Object.keys(counts).map((key) => counts[key].id);
25321
+ }
25322
+ alignToLeftHorizontal(nodes) {
25323
+ let targetX = Infinity;
25324
+ for (const node of nodes) {
25325
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25326
+ const realX = box.x;
25327
+ if (realX < targetX) targetX = realX;
25328
+ }
25329
+ for (const node of nodes) {
25330
+ let realNode = node;
25331
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25332
+ if (!realNode) continue;
25333
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25334
+ const deltaX = targetX - box.x;
25335
+ realNode.x(realNode.x() + deltaX);
25336
+ this.updateNode(realNode);
25337
+ }
25338
+ }
25339
+ alignToCenterHorizontal(nodes) {
25340
+ let minX = Infinity;
25341
+ let maxX = -Infinity;
25342
+ for (const node of nodes) {
25343
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25344
+ const realX = box.x;
25345
+ const realXWidth = box.x + box.width;
25346
+ if (realX < minX) minX = realX;
25347
+ if (realXWidth > maxX) maxX = realXWidth;
25348
+ }
25349
+ const targetX = minX + (maxX - minX) / 2;
25350
+ for (const node of nodes) {
25351
+ let realNode = node;
25352
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25353
+ if (!realNode) continue;
25354
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25355
+ const deltaX = targetX - (box.x + box.width / 2);
25356
+ realNode.x(realNode.x() + deltaX);
25357
+ this.updateNode(realNode);
25358
+ }
25359
+ }
25360
+ alignToRightHorizontal(nodes) {
25361
+ let targetX = -Infinity;
25362
+ for (const node of nodes) {
25363
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25364
+ const realX = box.x + box.width;
25365
+ if (realX > targetX) targetX = realX;
25366
+ }
25367
+ for (const node of nodes) {
25368
+ let realNode = node;
25369
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25370
+ if (!realNode) continue;
25371
+ const box = node.getClientRect({ relativeTo: this.instance.getStage() });
25372
+ const deltaX = targetX - (box.x + box.width);
25373
+ realNode.x(realNode.x() + deltaX);
25374
+ this.updateNode(realNode);
25375
+ }
25376
+ }
25377
+ alignToTopVertical(nodes) {
25378
+ let targetY = Infinity;
25379
+ for (const node of nodes) {
25380
+ let realNode = node;
25381
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25382
+ if (!realNode) continue;
25383
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25384
+ const realY = box.y;
25385
+ if (realY < targetY) targetY = realY;
25386
+ }
25387
+ for (const node of nodes) {
25388
+ let realNode = node;
25389
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25390
+ if (!realNode) continue;
25391
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25392
+ const deltaY = targetY - box.y;
25393
+ realNode.y(realNode.y() + deltaY);
25394
+ this.updateNode(realNode);
25395
+ }
25396
+ }
25397
+ alignToCenterVertical(nodes) {
25398
+ let minY = Infinity;
25399
+ let maxY = -Infinity;
25400
+ for (const node of nodes) {
25401
+ let realNode = node;
25402
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25403
+ if (!realNode) continue;
25404
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25405
+ const realY = box.y;
25406
+ const realYWidth = box.y + box.height;
25407
+ if (realY < minY) minY = realY;
25408
+ if (realYWidth > maxY) maxY = realYWidth;
25409
+ }
25410
+ const targetY = minY + (maxY - minY) / 2;
25411
+ for (const node of nodes) {
25412
+ let realNode = node;
25413
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25414
+ if (!realNode) continue;
25415
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25416
+ const deltaY = targetY - (box.y + box.height / 2);
25417
+ realNode.y(realNode.y() + deltaY);
25418
+ this.updateNode(realNode);
25419
+ }
25420
+ }
25421
+ alignToBottomVertical(nodes) {
25422
+ let targetY = -Infinity;
25423
+ for (const node of nodes) {
25424
+ let realNode = node;
25425
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25426
+ if (!realNode) continue;
25427
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25428
+ const realY = box.y + box.height;
25429
+ if (realY > targetY) targetY = realY;
25430
+ }
25431
+ for (const node of nodes) {
25432
+ let realNode = node;
25433
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25434
+ if (!realNode) continue;
25435
+ const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
25436
+ const deltaY = targetY - (box.y + box.height);
25437
+ realNode.y(realNode.y() + deltaY);
25438
+ this.updateNode(realNode);
25439
+ }
25440
+ }
25441
+ alignNodes(alignTo) {
25442
+ let selectedNodes = [];
25443
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
25444
+ if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
25445
+ const parentsIds = this.getParents(selectedNodes);
25446
+ let parent = this.instance.getMainLayer();
25447
+ if (parentsIds.length === 1) parent = this.instance.getStage().findOne(`#${parentsIds[0]}`);
25448
+ if (parentsIds.length > 1 && !parentsIds.includes("mainLayer")) {
25449
+ this.cancelAction();
25450
+ return;
25451
+ }
25452
+ selectedNodes = [...selectedNodes.filter((node) => {
25453
+ let realNode = node;
25454
+ if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
25455
+ return realNode?.getParent()?.getAttrs().id === parent?.getAttrs().id;
25456
+ })];
25457
+ switch (alignTo) {
25458
+ case ALIGN_NODES_ALIGN_TO.LEFT_HORIZONTAL: {
25459
+ this.alignToLeftHorizontal(selectedNodes);
25460
+ break;
25461
+ }
25462
+ case ALIGN_NODES_ALIGN_TO.CENTER_HORIZONTAL: {
25463
+ this.alignToCenterHorizontal(selectedNodes);
25464
+ break;
25465
+ }
25466
+ case ALIGN_NODES_ALIGN_TO.RIGHT_HORIZONTAL: {
25467
+ this.alignToRightHorizontal(selectedNodes);
25468
+ break;
25469
+ }
25470
+ case ALIGN_NODES_ALIGN_TO.TOP_VERTICAL: {
25471
+ this.alignToTopVertical(selectedNodes);
25472
+ break;
25473
+ }
25474
+ case ALIGN_NODES_ALIGN_TO.CENTER_VERTICAL: {
25475
+ this.alignToCenterVertical(selectedNodes);
25476
+ break;
25477
+ }
25478
+ case ALIGN_NODES_ALIGN_TO.BOTTOM_VERTICAL: {
25479
+ this.alignToBottomVertical(selectedNodes);
25480
+ break;
25481
+ }
25482
+ default: break;
25483
+ }
25484
+ this.cancelAction();
25485
+ }
25486
+ canAlignSelectedNodes() {
25487
+ let selectedNodes = [];
25488
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
25489
+ if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
25490
+ const parentsIds = this.getParents(selectedNodes);
25491
+ if (parentsIds.length > 1) return false;
25492
+ return true;
25493
+ }
25494
+ trigger(cancelAction, { alignTo, triggerSelectionTool = true }) {
25495
+ if (!this.instance) throw new Error("Instance not defined");
25496
+ if (!this.initialized) this.setupEvents();
25497
+ const stage = this.instance.getStage();
25498
+ stage.container().tabIndex = 1;
25499
+ stage.container().focus();
25500
+ this.triggerSelectionTool = triggerSelectionTool;
25501
+ this.cancelAction = cancelAction;
25502
+ this.alignNodes(alignTo);
25503
+ }
25504
+ cleanup() {
25505
+ if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
25506
+ this.setState(ALIGN_NODES_TOOL_STATE.IDLE);
25507
+ }
25508
+ };
25509
+
25049
25510
  //#endregion
25050
25511
  //#region src/plugins/stage-grid/constants.ts
25051
25512
  const WEAVE_STAGE_GRID_KEY = "stageGrid";
@@ -25055,8 +25516,8 @@ const WEAVE_GRID_TYPES = {
25055
25516
  };
25056
25517
  const WEAVE_GRID_DEFAULT_SIZE = 50;
25057
25518
  const WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_TYPES.LINES;
25058
- const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.2)";
25059
- const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.2)";
25519
+ const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.1)";
25520
+ const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.1)";
25060
25521
  const WEAVE_GRID_DEFAULT_STROKE = .5;
25061
25522
  const WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = 4;
25062
25523
  const WEAVE_GRID_DEFAULT_RADIUS = 1;
@@ -25121,7 +25582,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
25121
25582
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
25122
25583
  this.onRender();
25123
25584
  };
25124
- stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
25585
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
25125
25586
  stage.on("pointermove", () => {
25126
25587
  if (!this.enabled) return;
25127
25588
  this.onRender();
@@ -25416,7 +25877,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25416
25877
  stage.y(stage.y() - deltaY);
25417
25878
  this.instance.emitEvent("onStageMove");
25418
25879
  };
25419
- stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
25880
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
25420
25881
  stage.on("pointerdown", () => {
25421
25882
  const mousePos = stage.getPointerPosition();
25422
25883
  previousMouseX = mousePos?.x ?? 0;
@@ -25532,7 +25993,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
25532
25993
  newConnectedUsers[userInformation.name] = userInformation;
25533
25994
  }
25534
25995
  }
25535
- if (!(0, import_lodash$1.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
25996
+ if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
25536
25997
  this.connectedUsers = newConnectedUsers;
25537
25998
  });
25538
25999
  }
@@ -26270,5 +26731,5 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
26270
26731
  };
26271
26732
 
26272
26733
  //#endregion
26273
- export { ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_NODES_SNAPPING_KEY, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_GRID_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTERS_DEFAULT_PROPS, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, Weave, WeaveAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveZoomInToolAction, WeaveZoomOutToolAction, checkIfOverContainer, clearContainerTargets, getBoundingBox, getContrastTextColor, moveNodeToContainer, resetScale, stringToColor };
26734
+ export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_NODES_SNAPPING_KEY, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_GRID_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTERS_DEFAULT_PROPS, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveZoomInToolAction, WeaveZoomOutToolAction, checkIfOverContainer, clearContainerTargets, getBoundingBox, getContrastTextColor, moveNodeToContainer, resetScale, stringToColor };
26274
26735
  //# sourceMappingURL=sdk.js.map