@inditextech/weave-sdk 0.11.0 → 0.12.1

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.cjs CHANGED
@@ -15571,6 +15571,15 @@ var WeaveStore = class {
15571
15571
  const newState = JSON.parse(JSON.stringify(this.getState()));
15572
15572
  config.callbacks?.onStateChange?.(newState);
15573
15573
  this.instance.emitEvent("onStateChange", newState);
15574
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
15575
+ if (this.isRoomLoaded && nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1) {
15576
+ const selectedNode = nodesSelectionPlugin.getSelectedNodes()[0];
15577
+ const nodeInfo = this.instance.getNode(selectedNode.getAttrs().id ?? "");
15578
+ if (nodeInfo && nodeInfo.node) this.instance.emitEvent("onNodeChange", {
15579
+ instance: selectedNode,
15580
+ node: JSON.parse(JSON.stringify(nodeInfo.node))
15581
+ });
15582
+ }
15574
15583
  if (!this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) {
15575
15584
  this.instance.setupRenderer();
15576
15585
  this.isRoomLoaded = true;
@@ -15740,6 +15749,52 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15740
15749
  }
15741
15750
  };
15742
15751
 
15752
+ //#endregion
15753
+ //#region src/utils.ts
15754
+ function resetScale(node) {
15755
+ node.width(Math.round((Math.max(1, node.width() * node.scaleX()) + Number.EPSILON) * 100) / 100);
15756
+ node.height(Math.round((Math.max(1, node.height() * node.scaleY()) + Number.EPSILON) * 100) / 100);
15757
+ node.scaleX(1);
15758
+ node.scaleY(1);
15759
+ node.x(Math.round((node.x() + Number.EPSILON) * 100) / 100);
15760
+ node.y(Math.round((node.y() + Number.EPSILON) * 100) / 100);
15761
+ node.rotation(Math.round((node.rotation() + Number.EPSILON) * 100) / 100);
15762
+ }
15763
+ function clearContainerTargets(instance) {
15764
+ const getContainers = instance.getContainerNodes();
15765
+ for (const container of getContainers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
15766
+ }
15767
+ function checkIfOverContainer(instance, node) {
15768
+ const nodesIntersected = instance.pointIntersectsContainerElement();
15769
+ let nodeActualContainer = node.getParent();
15770
+ if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
15771
+ let layerToMove = void 0;
15772
+ if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
15773
+ return layerToMove;
15774
+ }
15775
+ function moveNodeToContainer(instance, node) {
15776
+ const nodesIntersected = instance.pointIntersectsContainerElement();
15777
+ let nodeActualContainer = node.getParent();
15778
+ if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
15779
+ let layerToMove = void 0;
15780
+ if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
15781
+ if (!nodesIntersected && nodeActualContainer?.getAttrs().id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
15782
+ if (layerToMove) {
15783
+ const nodePos = node.getAbsolutePosition();
15784
+ const nodeRotation = node.getAbsoluteRotation();
15785
+ node.moveTo(layerToMove);
15786
+ node.setAbsolutePosition(nodePos);
15787
+ node.rotation(nodeRotation);
15788
+ node.x(node.x() - (layerToMove.getAttrs().containerOffsetX ?? 0));
15789
+ node.y(node.y() - (layerToMove.getAttrs().containerOffsetY ?? 0));
15790
+ const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
15791
+ const actualNode = nodeHandler.serialize(node);
15792
+ instance.removeNode(actualNode);
15793
+ instance.addNode(actualNode, layerToMove?.getAttrs().id);
15794
+ }
15795
+ return layerToMove;
15796
+ }
15797
+
15743
15798
  //#endregion
15744
15799
  //#region src/plugins/nodes-selection/nodes-selection.ts
15745
15800
  var WeaveNodesSelectionPlugin = class extends WeavePlugin {
@@ -15860,6 +15915,22 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15860
15915
  e.cancelBubble = true;
15861
15916
  }
15862
15917
  });
15918
+ tr.on("dragmove", (e) => {
15919
+ if (this.isSelecting() && tr.nodes().length > 1) {
15920
+ clearContainerTargets(this.instance);
15921
+ const layerToMove = checkIfOverContainer(this.instance, e.target);
15922
+ if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
15923
+ }
15924
+ });
15925
+ tr.on("dragend", () => {
15926
+ if (this.isSelecting() && tr.nodes().length > 1) {
15927
+ clearContainerTargets(this.instance);
15928
+ for (const node of tr.nodes()) {
15929
+ const layerToMove = moveNodeToContainer(this.instance, node);
15930
+ if (layerToMove) continue;
15931
+ }
15932
+ }
15933
+ });
15863
15934
  this.tr = tr;
15864
15935
  this.selectionRectangle = selectionRectangle;
15865
15936
  this.tr.on("dblclick dbltap", (evt) => {
@@ -15920,7 +15991,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15920
15991
  this.selecting = false;
15921
15992
  const stage = this.instance.getStage();
15922
15993
  stage.container().addEventListener("keydown", (e) => {
15923
- if (e.key === "Backspace" || e.key === "Delete") {
15994
+ if ((e.key === "Backspace" || e.key === "Delete") && Object.keys(window.weaveTextEditing).length === 0) {
15924
15995
  this.removeSelectedNodes();
15925
15996
  return;
15926
15997
  }
@@ -15942,6 +16013,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15942
16013
  this.selectionRectangle.width(0);
15943
16014
  this.selectionRectangle.height(0);
15944
16015
  this.selecting = true;
16016
+ this.instance.emitEvent("onSelectionState", true);
15945
16017
  if (!(e.target instanceof konva.default.Stage)) this.cameFromSelectingMultiple = true;
15946
16018
  });
15947
16019
  stage.on("mousemove touchmove", (e) => {
@@ -15967,6 +16039,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15967
16039
  if (!this.initialized) return;
15968
16040
  if (!this.active) return;
15969
16041
  this.selecting = false;
16042
+ this.instance.emitEvent("onSelectionState", false);
15970
16043
  if (!this.selectionRectangle.visible()) {
15971
16044
  this.cameFromSelectingMultiple = false;
15972
16045
  return;
@@ -16342,40 +16415,6 @@ var WeaveNode = class {
16342
16415
  if (selectionPlugin.getSelectedNodes().length === 1 && selectionPlugin.getSelectedNodes()[0].getAttrs().id === ele.getAttrs().id) selected = true;
16343
16416
  return selected;
16344
16417
  }
16345
- clearContainerTargets() {
16346
- const getContainers = this.instance.getContainerNodes();
16347
- for (const container of getContainers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
16348
- }
16349
- checkIfOverContainer(node) {
16350
- const nodesIntersected = this.instance.pointIntersectsContainerElement();
16351
- let nodeActualContainer = node.getParent();
16352
- if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = this.instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
16353
- let layerToMove = void 0;
16354
- if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
16355
- return layerToMove;
16356
- }
16357
- moveNodeToContainer(node) {
16358
- const nodesIntersected = this.instance.pointIntersectsContainerElement();
16359
- let nodeActualContainer = node.getParent();
16360
- if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = this.instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
16361
- let layerToMove = void 0;
16362
- if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
16363
- if (!nodesIntersected && nodeActualContainer?.getAttrs().id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = this.instance.getMainLayer();
16364
- if (layerToMove) {
16365
- const nodePos = node.getAbsolutePosition();
16366
- const nodeRotation = node.getAbsoluteRotation();
16367
- node.moveTo(layerToMove);
16368
- node.setAbsolutePosition(nodePos);
16369
- node.rotation(nodeRotation);
16370
- node.x(node.x() - (layerToMove.getAttrs().containerOffsetX ?? 0));
16371
- node.y(node.y() - (layerToMove.getAttrs().containerOffsetY ?? 0));
16372
- const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16373
- const actualNode = nodeHandler.serialize(node);
16374
- this.instance.removeNode(actualNode);
16375
- this.instance.addNode(actualNode, layerToMove?.getAttrs().id);
16376
- }
16377
- return layerToMove;
16378
- }
16379
16418
  setupDefaultNodeEvents(node) {
16380
16419
  this.previousPointer = null;
16381
16420
  this.instance.addEventListener("onNodesChange", () => {
@@ -16387,16 +16426,16 @@ var WeaveNode = class {
16387
16426
  });
16388
16427
  node.on("dragmove", (e) => {
16389
16428
  if (this.isSelecting() && this.isNodeSelected(node)) {
16390
- this.clearContainerTargets();
16391
- const layerToMove = this.checkIfOverContainer(e.target);
16429
+ clearContainerTargets(this.instance);
16430
+ const layerToMove = checkIfOverContainer(this.instance, e.target);
16392
16431
  if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
16393
16432
  this.instance.updateNode(this.serialize(node));
16394
16433
  }
16395
16434
  });
16396
16435
  node.on("dragend", (e) => {
16397
16436
  if (this.isSelecting() && this.isNodeSelected(node)) {
16398
- this.clearContainerTargets();
16399
- const layerToMove = this.moveNodeToContainer(e.target);
16437
+ clearContainerTargets(this.instance);
16438
+ const layerToMove = moveNodeToContainer(this.instance, e.target);
16400
16439
  if (layerToMove) return;
16401
16440
  this.instance.updateNode(this.serialize(node));
16402
16441
  }
@@ -17750,7 +17789,7 @@ var WeaveStateManager = class {
17750
17789
  getElementsTree() {
17751
17790
  const state = this.instance.getStore().getState().weave;
17752
17791
  const jsonState = JSON.parse(JSON.stringify(state, null, 2));
17753
- const mainLayer = jsonState.props.children.find((node) => node.key === "mainLayer");
17792
+ const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
17754
17793
  if (!mainLayer) return [];
17755
17794
  return mainLayer.props.children;
17756
17795
  }
@@ -17844,7 +17883,7 @@ var WeaveRegisterManager = class {
17844
17883
 
17845
17884
  //#endregion
17846
17885
  //#region package.json
17847
- var version = "0.11.0";
17886
+ var version = "0.12.1";
17848
17887
 
17849
17888
  //#endregion
17850
17889
  //#region src/managers/setup.ts
@@ -18230,6 +18269,8 @@ var Weave = class extends Emittery {
18230
18269
  this.actionsManager = new WeaveActionsManager(this);
18231
18270
  this.pluginsManager = new WeavePluginsManager(this);
18232
18271
  if (!window.weave) window.weave = this;
18272
+ window.weaveTextEditing = {};
18273
+ window.weaveDragImageURL = void 0;
18233
18274
  this.setupManager.welcomeLog();
18234
18275
  }
18235
18276
  setupRenderer() {
@@ -18482,18 +18523,6 @@ var Weave = class extends Emittery {
18482
18523
  }
18483
18524
  };
18484
18525
 
18485
- //#endregion
18486
- //#region src/utils.ts
18487
- function resetScale(node) {
18488
- node.width(Math.round((Math.max(1, node.width() * node.scaleX()) + Number.EPSILON) * 100) / 100);
18489
- node.height(Math.round((Math.max(1, node.height() * node.scaleY()) + Number.EPSILON) * 100) / 100);
18490
- node.scaleX(1);
18491
- node.scaleY(1);
18492
- node.x(Math.round((node.x() + Number.EPSILON) * 100) / 100);
18493
- node.y(Math.round((node.y() + Number.EPSILON) * 100) / 100);
18494
- node.rotation(Math.round((node.rotation() + Number.EPSILON) * 100) / 100);
18495
- }
18496
-
18497
18526
  //#endregion
18498
18527
  //#region src/nodes/stage/constants.ts
18499
18528
  const WEAVE_STAGE_NODE_TYPE = "stage";
@@ -18653,8 +18682,19 @@ var WeaveTextNode = class extends WeaveNode {
18653
18682
  name: "node"
18654
18683
  });
18655
18684
  this.setupDefaultNodeEvents(text);
18656
- text.on("dblclick dbltap", (evt) => {
18657
- evt.cancelBubble = true;
18685
+ window.addEventListener("keypress", (e) => {
18686
+ if (this.editing) return;
18687
+ if (e.key !== "Enter" && !e.shiftKey) return;
18688
+ if (this.isSelecting() && this.isNodeSelected(text)) {
18689
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
18690
+ if (nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1 && nodesSelectionPlugin.getSelectedNodes()[0].getAttrs().nodeType === WEAVE_TEXT_NODE_TYPE && !window.weaveTextEditing[nodesSelectionPlugin.getSelectedNodes()[0].id()]) {
18691
+ e.preventDefault();
18692
+ this.triggerEditMode(nodesSelectionPlugin.getSelectedNodes()[0]);
18693
+ }
18694
+ }
18695
+ });
18696
+ text.on("dblclick dbltap", (e) => {
18697
+ e.cancelBubble = true;
18658
18698
  if (this.editing) return;
18659
18699
  if (!(this.isSelecting() && this.isNodeSelected(text))) return;
18660
18700
  const stage = this.instance.getStage();
@@ -18699,24 +18739,50 @@ var WeaveTextNode = class extends WeaveNode {
18699
18739
  }
18700
18740
  };
18701
18741
  }
18742
+ resizeTextAreaDOM(textNode) {
18743
+ const textArea = document.getElementById(textNode.id());
18744
+ if (!textArea) return;
18745
+ const stage = this.instance.getStage();
18746
+ const textPosition = textNode.absolutePosition();
18747
+ const position = {
18748
+ x: stage.container().offsetLeft + textPosition.x,
18749
+ y: stage.container().offsetTop + textPosition.y
18750
+ };
18751
+ textArea.style.top = position.y + "px";
18752
+ textArea.style.left = position.x + "px";
18753
+ textArea.style.width = textNode.getWidth() * textNode.getAbsoluteScale().x + "px";
18754
+ textArea.style.height = textNode.getHeight() * textNode.getAbsoluteScale().x + "px";
18755
+ textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
18756
+ }
18757
+ onZoomChangeHandler = (textNode) => () => {
18758
+ if (!this.editing) return;
18759
+ this.resizeTextAreaDOM(textNode);
18760
+ };
18761
+ onStageMoveHandler = (textNode) => () => {
18762
+ if (!this.editing) return;
18763
+ this.resizeTextAreaDOM(textNode);
18764
+ };
18702
18765
  createTextAreaDOM(textNode, position) {
18703
18766
  const stage = this.instance.getStage();
18704
18767
  const textArea = document.createElement("textarea");
18768
+ textArea.id = textNode.id();
18705
18769
  stage.container().appendChild(textArea);
18706
- window.weaveTextEditing = true;
18770
+ this.instance.addEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
18771
+ this.instance.addEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
18772
+ window.weaveTextEditing[textNode.id()] = "editing";
18707
18773
  textArea.value = textNode.text();
18708
18774
  textArea.id = textNode.id();
18709
18775
  textArea.style.position = "fixed";
18710
18776
  textArea.style.top = position.y + "px";
18711
18777
  textArea.style.left = position.x + "px";
18712
18778
  textArea.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
18713
- textArea.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
18779
+ textArea.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
18714
18780
  textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
18715
- textArea.style.border = "solid 1px rgba(0,0,255,0.5)";
18716
- textArea.style.padding = "0px";
18781
+ textArea.style.border = "solid 1px #1e40af";
18782
+ textArea.style.minHeight = "auto";
18717
18783
  textArea.style.margin = "0px";
18718
18784
  textArea.style.overflow = "hidden";
18719
- textArea.style.background = "rgba(255,255,255,0.5)";
18785
+ textArea.style.background = "transparent";
18720
18786
  textArea.style.outline = "none";
18721
18787
  textArea.style.resize = "none";
18722
18788
  textArea.style.lineHeight = `${textNode.lineHeight()}`;
@@ -18724,29 +18790,42 @@ var WeaveTextNode = class extends WeaveNode {
18724
18790
  textArea.style.transformOrigin = "left top";
18725
18791
  textArea.style.textAlign = textNode.align();
18726
18792
  textArea.style.color = `${textNode.fill()}`;
18793
+ textArea.onfocus = () => {
18794
+ textArea.style.height = "auto";
18795
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18796
+ textArea.setSelectionRange(textArea.value.length, textArea.value.length);
18797
+ };
18798
+ textArea.onkeydown = () => {
18799
+ textArea.style.height = "auto";
18800
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18801
+ };
18802
+ textArea.onkeyup = () => {
18803
+ textArea.style.height = "auto";
18804
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18805
+ };
18806
+ textArea.onwheel = (e) => {
18807
+ e.preventDefault();
18808
+ };
18809
+ textArea.oninput = () => {
18810
+ textArea.style.height = "auto";
18811
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18812
+ };
18727
18813
  const rotation = textNode.rotation();
18728
18814
  let transform = "";
18729
18815
  if (rotation) transform += "rotateZ(" + rotation + "deg)";
18730
- const px = 1;
18731
- const py = 2;
18732
- transform += "translateX(-" + px + "px)";
18733
- transform += "translateY(-" + py + "px)";
18816
+ const px = 0;
18817
+ const py = -3 * textNode.getAbsoluteScale().x;
18818
+ transform += "translateX(" + px + "px)";
18819
+ transform += "translateY(" + py + "px)";
18734
18820
  textArea.style.transform = transform;
18735
18821
  const handleKeyDown = (e) => {
18736
18822
  if (textArea && textNode) {
18737
- if (e.key === "Enter" && !e.shiftKey) {
18738
- textNode.text(textArea.value);
18739
- this.updateNode(textNode);
18740
- this.removeTextAreaDOM(textNode);
18741
- window.removeEventListener("click", handleOutsideClick);
18742
- return;
18743
- }
18744
- if (e.key === "Enter" && e.shiftKey) {
18823
+ if (e.key === "Enter") {
18745
18824
  if (textArea && textNode) try {
18746
18825
  textNode.text(textArea.value);
18747
18826
  textArea.style.width = textNode.width() * textNode.getAbsoluteScale().x + "px";
18748
18827
  textArea.style.height = "auto";
18749
- textArea.style.height = textArea.scrollHeight + textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
18828
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18750
18829
  textArea.tabIndex = 1;
18751
18830
  textArea.focus();
18752
18831
  } catch (ex) {
@@ -18755,20 +18834,24 @@ var WeaveTextNode = class extends WeaveNode {
18755
18834
  return;
18756
18835
  }
18757
18836
  if (e.key === "Escape") {
18837
+ textNode.width(parseFloat(textArea.style.width) * (1 / textNode.getAbsoluteScale().x));
18838
+ textNode.height((textArea.scrollHeight + 1.6) * (1 / textNode.getAbsoluteScale().x));
18839
+ textNode.text(textArea.value);
18840
+ this.updateNode(textNode);
18758
18841
  this.removeTextAreaDOM(textNode);
18842
+ this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
18843
+ this.instance.removeEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
18759
18844
  window.removeEventListener("click", handleOutsideClick);
18760
18845
  return;
18761
18846
  }
18762
18847
  }
18763
18848
  };
18764
- const handleKeyUp = (e) => {
18849
+ const handleKeyUp = () => {
18765
18850
  textNode.text(textArea.value);
18766
18851
  if (textArea && textNode) {
18767
18852
  textArea.style.width = textNode.width() * textNode.getAbsoluteScale().x + "px";
18768
- if (!(e.key === "Enter" && e.shiftKey)) {
18769
- textArea.style.height = "auto";
18770
- textArea.style.height = textArea.scrollHeight + "px";
18771
- }
18853
+ textArea.style.height = "auto";
18854
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18772
18855
  }
18773
18856
  };
18774
18857
  textArea.addEventListener("keydown", handleKeyDown);
@@ -18801,7 +18884,7 @@ var WeaveTextNode = class extends WeaveNode {
18801
18884
  }
18802
18885
  removeTextAreaDOM(textNode) {
18803
18886
  const stage = this.instance.getStage();
18804
- window.weaveTextEditing = false;
18887
+ delete window.weaveTextEditing[textNode.id()];
18805
18888
  const textArea = document.getElementById(textNode.id());
18806
18889
  if (textArea) textArea.remove();
18807
18890
  textNode.visible(true);
@@ -18854,6 +18937,7 @@ const IMAGE_TOOL_STATE = {
18854
18937
  var WeaveImageToolAction = class extends WeaveAction {
18855
18938
  initialized = false;
18856
18939
  initialCursor = null;
18940
+ onPropsChange = void 0;
18857
18941
  update = void 0;
18858
18942
  constructor() {
18859
18943
  super();
@@ -18909,13 +18993,8 @@ var WeaveImageToolAction = class extends WeaveAction {
18909
18993
  if (this.state === IMAGE_TOOL_STATE.ADDING && tempImage) {
18910
18994
  const mousePos = stage.getRelativePointerPosition();
18911
18995
  tempImage.setAttrs({
18912
- ...this.props,
18913
- name: void 0,
18914
18996
  x: (mousePos?.x ?? 0) + 2,
18915
- y: (mousePos?.y ?? 0) + 2,
18916
- fill: "#ccccccff",
18917
- stroke: "#000000ff",
18918
- strokeWidth: 1
18997
+ y: (mousePos?.y ?? 0) + 2
18919
18998
  });
18920
18999
  const nodeHandler = this.instance.getNodeHandler("rectangle");
18921
19000
  this.instance.updateNode(nodeHandler.serialize(tempImage));
@@ -18940,6 +19019,7 @@ var WeaveImageToolAction = class extends WeaveAction {
18940
19019
  this.instance.emitEvent("onImageLoadEnd", void 0);
18941
19020
  if (this.imageId) this.props = {
18942
19021
  ...this.props,
19022
+ imageURL: this.imageURL,
18943
19023
  width: this.preloadImgs[this.imageId].width,
18944
19024
  height: this.preloadImgs[this.imageId].height
18945
19025
  };
@@ -18958,17 +19038,20 @@ var WeaveImageToolAction = class extends WeaveAction {
18958
19038
  stage.container().focus();
18959
19039
  if (this.imageId) {
18960
19040
  const mousePos = stage.getRelativePointerPosition();
18961
- const nodeHandler = this.instance.getNodeHandler("rectangle");
19041
+ const nodeHandler = this.instance.getNodeHandler("image");
18962
19042
  this.tempImageId = v4_default();
19043
+ const aspectRatio = this.preloadImgs[this.imageId].width / this.preloadImgs[this.imageId].height;
18963
19044
  const node = nodeHandler.create(this.tempImageId, {
18964
- ...this.props,
18965
19045
  x: (mousePos?.x ?? 0) + 5,
18966
19046
  y: (mousePos?.y ?? 0) + 5,
18967
- width: this.preloadImgs[this.imageId].width,
18968
- height: this.preloadImgs[this.imageId].height,
18969
- fill: "#ccccccff",
19047
+ width: 100 * aspectRatio,
19048
+ height: 100,
19049
+ opacity: 1,
19050
+ imageURL: this.imageURL,
18970
19051
  stroke: "#000000ff",
18971
- strokeWidth: 1
19052
+ strokeWidth: 0,
19053
+ strokeScaleEnabled: false,
19054
+ listening: false
18972
19055
  });
18973
19056
  this.instance.addNode(node, this.container?.getAttrs().id);
18974
19057
  }
@@ -19010,6 +19093,8 @@ var WeaveImageToolAction = class extends WeaveAction {
19010
19093
  if (!this.instance) throw new Error("Instance not defined");
19011
19094
  if (!this.initialized) this.setupEvents();
19012
19095
  this.cancelAction = cancelAction;
19096
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
19097
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
19013
19098
  if (params?.imageURL) {
19014
19099
  this.loadImage(params.imageURL);
19015
19100
  return;
@@ -19018,23 +19103,6 @@ var WeaveImageToolAction = class extends WeaveAction {
19018
19103
  this.addImage();
19019
19104
  return { finishUploadCallback: this.loadImage.bind(this) };
19020
19105
  }
19021
- onPropsChange() {
19022
- const stage = this.instance?.getStage();
19023
- if (stage) {
19024
- const tempImage = this.instance.getStage().findOne(`#${this.tempImageId}`);
19025
- if (tempImage) {
19026
- tempImage.setAttrs({
19027
- ...this.props,
19028
- name: void 0,
19029
- fill: "#ccccccff",
19030
- stroke: "#000000ff",
19031
- strokeWidth: 1
19032
- });
19033
- const nodeHandler = this.instance.getNodeHandler("rectangle");
19034
- this.instance.updateNode(nodeHandler.serialize(tempImage));
19035
- }
19036
- }
19037
- }
19038
19106
  cleanup() {
19039
19107
  const stage = this.instance.getStage();
19040
19108
  if (this.imageId) delete this.preloadImgs[this.imageId];
@@ -19651,8 +19719,8 @@ var WeaveFrameNode = class extends WeaveNode {
19651
19719
  const frameInternal = new konva.default.Group({
19652
19720
  id: `${id}-group-internal`,
19653
19721
  nodeId: id,
19654
- x: borderWidth,
19655
- y: titleHeight + borderWidth,
19722
+ x: borderWidth * 2,
19723
+ y: titleHeight + borderWidth * 2,
19656
19724
  width: props.frameWidth,
19657
19725
  height: props.frameHeight,
19658
19726
  draggable: false,
@@ -19661,8 +19729,8 @@ var WeaveFrameNode = class extends WeaveNode {
19661
19729
  borderWidth,
19662
19730
  clipX: 0,
19663
19731
  clipY: 0,
19664
- clipWidth: props.frameWidth,
19665
- clipHeight: props.frameHeight
19732
+ clipWidth: props.frameWidth - borderWidth * 2,
19733
+ clipHeight: props.frameHeight - borderWidth * 2
19666
19734
  });
19667
19735
  frame.add(frameInternal);
19668
19736
  this.setupDefaultNodeEvents(frame);
@@ -19725,7 +19793,7 @@ const WEAVE_STAGE_ZOOM_KEY = "stageZoom";
19725
19793
  var WeaveStageZoomPlugin = class extends WeavePlugin {
19726
19794
  getLayerName = void 0;
19727
19795
  initLayer = void 0;
19728
- padding = 100;
19796
+ padding = 175;
19729
19797
  defaultStep = 3;
19730
19798
  constructor(params) {
19731
19799
  super();
@@ -19903,18 +19971,16 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
19903
19971
  this.enabled = false;
19904
19972
  }
19905
19973
  initEvents() {
19906
- const stage = this.instance.getStage();
19907
- stage.container().addEventListener("keydown", (e) => {
19974
+ window.addEventListener("keydown", (e) => {
19908
19975
  if (e.ctrlKey || e.metaKey) this.isCtrlOrMetaPressed = true;
19909
19976
  });
19910
- stage.container().addEventListener("keyup", (e) => {
19977
+ window.addEventListener("keyup", (e) => {
19911
19978
  if (!(e.ctrlKey || e.metaKey)) this.isCtrlOrMetaPressed = false;
19912
19979
  });
19913
- stage.on("wheel", (e) => {
19914
- e.evt.preventDefault();
19980
+ window.addEventListener("wheel", (e) => {
19915
19981
  if (!this.enabled || !this.isCtrlOrMetaPressed) return;
19916
- if (e.evt.deltaY > 0) this.zoomOut();
19917
- if (e.evt.deltaY < 0) this.zoomIn();
19982
+ if (e.deltaY > 0) this.zoomOut();
19983
+ if (e.deltaY < 0) this.zoomIn();
19918
19984
  });
19919
19985
  }
19920
19986
  };
@@ -20262,15 +20328,25 @@ var WeaveRectangleToolAction = class extends WeaveAction {
20262
20328
  const rectangle = this.instance.getStage().findOne(`#${this.rectId}`);
20263
20329
  if (this.rectId && this.clickPoint && this.container && rectangle) {
20264
20330
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.container);
20265
- const deltaX = mousePoint.x - this.clickPoint?.x;
20266
- const deltaY = mousePoint.y - this.clickPoint?.y;
20267
20331
  const nodeHandler = this.instance.getNodeHandler("rectangle");
20332
+ const rectPos = {
20333
+ x: this.clickPoint.x,
20334
+ y: this.clickPoint.y
20335
+ };
20336
+ let rectWidth = this.props.width;
20337
+ let rectHeight = this.props.height;
20338
+ if (this.moved) {
20339
+ rectPos.x = Math.min(this.clickPoint.x, mousePoint.x);
20340
+ rectPos.y = Math.min(this.clickPoint.y, mousePoint.y);
20341
+ rectWidth = Math.abs(this.clickPoint.x - mousePoint.x);
20342
+ rectHeight = Math.abs(this.clickPoint.y - mousePoint.y);
20343
+ }
20268
20344
  rectangle.setAttrs({
20269
20345
  ...this.props,
20270
- x: this.moved ? rectangle.getAttrs().x : this.clickPoint.x,
20271
- y: this.moved ? rectangle.getAttrs().y : this.clickPoint.y,
20272
- width: this.moved ? Math.abs(deltaX) : this.props.width,
20273
- height: this.moved ? Math.abs(deltaY) : this.props.height
20346
+ x: rectPos.x,
20347
+ y: rectPos.y,
20348
+ width: rectWidth,
20349
+ height: rectHeight
20274
20350
  });
20275
20351
  this.instance.updateNode(nodeHandler.serialize(rectangle));
20276
20352
  }
@@ -20298,6 +20374,8 @@ var WeaveRectangleToolAction = class extends WeaveAction {
20298
20374
  stage.container().tabIndex = 1;
20299
20375
  stage.container().focus();
20300
20376
  this.cancelAction = cancelAction;
20377
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20378
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
20301
20379
  this.props = this.initProps();
20302
20380
  this.addRectangle();
20303
20381
  }
@@ -20510,6 +20588,8 @@ var WeavePenToolAction = class extends WeaveAction {
20510
20588
  stage.container().tabIndex = 1;
20511
20589
  stage.container().focus();
20512
20590
  this.cancelAction = cancelAction;
20591
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20592
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
20513
20593
  this.props = this.initProps();
20514
20594
  this.addLine();
20515
20595
  }
@@ -20684,6 +20764,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
20684
20764
  stage.container().tabIndex = 1;
20685
20765
  stage.container().focus();
20686
20766
  this.cancelAction = cancel;
20767
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
20687
20768
  this.props = this.initProps();
20688
20769
  this.setState(BRUSH_TOOL_STATE.IDLE);
20689
20770
  stage.container().style.cursor = "crosshair";
@@ -20775,7 +20856,7 @@ var WeaveTextToolAction = class extends WeaveAction {
20775
20856
  text: "Your text here...",
20776
20857
  width: 300,
20777
20858
  fontSize: 20,
20778
- fontFamily: "NotoSansMono, monospace",
20859
+ fontFamily: "Arial, sans-serif",
20779
20860
  fill: "#000000ff",
20780
20861
  strokeEnabled: false,
20781
20862
  stroke: "#000000ff",
@@ -20794,11 +20875,19 @@ var WeaveTextToolAction = class extends WeaveAction {
20794
20875
  if (!this.instance) throw new Error("Instance not defined");
20795
20876
  if (!this.initialized) this.setupEvents();
20796
20877
  this.cancelAction = cancelAction;
20878
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20879
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
20797
20880
  this.addText();
20798
20881
  }
20799
20882
  cleanup() {
20800
20883
  const stage = this.instance.getStage();
20801
20884
  stage.container().style.cursor = "default";
20885
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20886
+ if (selectionPlugin) {
20887
+ const node$1 = stage.findOne(`#${this.textId}`);
20888
+ if (node$1) selectionPlugin.setSelectedNodes([node$1]);
20889
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
20890
+ }
20802
20891
  const node = stage.findOne(`#${this.textId}`);
20803
20892
  if (node) node.getAttr("triggerEditMode")(node);
20804
20893
  this.initialCursor = null;
@@ -20896,6 +20985,8 @@ var WeaveFrameToolAction = class extends WeaveAction {
20896
20985
  stage.container().tabIndex = 1;
20897
20986
  stage.container().focus();
20898
20987
  this.cancelAction = cancelAction;
20988
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20989
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
20899
20990
  this.props = this.initProps(params);
20900
20991
  this.addFrame();
20901
20992
  }
@@ -21130,15 +21221,21 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
21130
21221
  if (!layer) return;
21131
21222
  const stage = this.instance.getStage();
21132
21223
  const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
21133
- const overflowX = 10 * this.config.gridSize;
21134
- const overflowY = 10 * this.config.gridSize;
21224
+ const overflowX = this.round(10 * this.config.gridSize, this.config.gridSize);
21225
+ const overflowY = this.round(10 * this.config.gridSize, this.config.gridSize);
21135
21226
  const pointsX = [];
21136
- for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push(i / stage.scaleX());
21227
+ for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push({
21228
+ real: i / stage.scaleX(),
21229
+ ref: i
21230
+ });
21137
21231
  const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
21138
21232
  const pointsY = [];
21139
- for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push(i / stage.scaleY());
21233
+ for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push({
21234
+ real: i / stage.scaleY(),
21235
+ ref: i
21236
+ });
21140
21237
  for (let index = 0; index < pointsX.length; index++) {
21141
- const point = pointsX[index];
21238
+ const { real: point, ref } = pointsX[index];
21142
21239
  let color = this.config.gridColor;
21143
21240
  if (point === 0) color = this.config.gridOriginColor;
21144
21241
  layer.add(new konva_lib_shapes_Line.Line({
@@ -21149,12 +21246,12 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
21149
21246
  (-stage.y() + stage.height() + overflowY) / stage.scaleY()
21150
21247
  ],
21151
21248
  stroke: color,
21152
- strokeWidth: (isZeroOrClose(point % (10 * (this.config.gridSize / stage.scaleX()))) ? 2.5 : .5) / stage.scaleX(),
21249
+ strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
21153
21250
  listening: false
21154
21251
  }));
21155
21252
  }
21156
21253
  for (let index = 0; index < pointsY.length; index++) {
21157
- const point = pointsY[index];
21254
+ const { real: point, ref } = pointsY[index];
21158
21255
  let color = this.config.gridColor;
21159
21256
  if (point === 0) color = this.config.gridOriginColor;
21160
21257
  layer.add(new konva_lib_shapes_Line.Line({
@@ -21165,7 +21262,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
21165
21262
  point
21166
21263
  ],
21167
21264
  stroke: color,
21168
- strokeWidth: (isZeroOrClose(point % (10 * (this.config.gridSize / stage.scaleY()))) ? 2.5 : .5) / stage.scaleX(),
21265
+ strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
21169
21266
  listening: false
21170
21267
  }));
21171
21268
  }
@@ -21174,20 +21271,26 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
21174
21271
  const layer = this.getLayer();
21175
21272
  if (!layer) return;
21176
21273
  const stage = this.instance.getStage();
21177
- const overflowX = Math.max(stage.width() * .2, 10 * this.config.gridSize);
21178
- const overflowY = Math.max(stage.height() * .2, 10 * this.config.gridSize);
21274
+ const overflowX = 10 * this.config.gridSize;
21275
+ const overflowY = 10 * this.config.gridSize;
21179
21276
  const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
21180
21277
  const pointsX = [];
21181
- for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push(i / stage.scaleX());
21278
+ for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push({
21279
+ real: i / stage.scaleX(),
21280
+ ref: i
21281
+ });
21182
21282
  const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
21183
21283
  const pointsY = [];
21184
- for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push(i / stage.scaleY());
21284
+ for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push({
21285
+ real: i / stage.scaleY(),
21286
+ ref: i
21287
+ });
21185
21288
  for (let indexX = 0; indexX < pointsX.length; indexX++) {
21186
- const pointX = pointsX[indexX];
21289
+ const { real: pointX, ref: refX } = pointsX[indexX];
21187
21290
  for (let indexY = 0; indexY < pointsY.length; indexY++) {
21188
- const pointY = pointsY[indexY];
21291
+ const { real: pointY, ref: refY } = pointsY[indexY];
21189
21292
  let color = this.config.gridColor;
21190
- if (pointX === 0 || pointY === 0) color = this.config.gridOriginColor;
21293
+ if (refX === 0 || refY === 0) color = this.config.gridOriginColor;
21191
21294
  layer.add(new konva_lib_shapes_Circle.Circle({
21192
21295
  x: pointX,
21193
21296
  y: pointY,
@@ -21322,6 +21425,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
21322
21425
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
21323
21426
  stage.x(stage.x() - deltaX);
21324
21427
  stage.y(stage.y() - deltaY);
21428
+ this.instance.emit("onStageMove", void 0);
21325
21429
  });
21326
21430
  stage.on("touchstart", (e) => {
21327
21431
  e.evt.preventDefault();
@@ -21343,12 +21447,13 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
21343
21447
  if (!this.enabled) return;
21344
21448
  stage.x(stage.x() - deltaX);
21345
21449
  stage.y(stage.y() - deltaY);
21450
+ this.instance.emit("onStageMove", void 0);
21346
21451
  });
21347
- stage.on("wheel", (e) => {
21348
- e.evt.preventDefault();
21452
+ window.addEventListener("wheel", (e) => {
21349
21453
  if (!this.enabled || this.isCtrlOrMetaPressed || this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed) return;
21350
- stage.x(stage.x() - e.evt.deltaX);
21351
- stage.y(stage.y() - e.evt.deltaY);
21454
+ stage.x(stage.x() - e.deltaX);
21455
+ stage.y(stage.y() - e.deltaY);
21456
+ this.instance.emit("stageMove", void 0);
21352
21457
  });
21353
21458
  }
21354
21459
  enable() {
@@ -22086,4 +22191,7 @@ exports.WeaveTextToolAction = WeaveTextToolAction
22086
22191
  exports.WeaveUsersPointersPlugin = WeaveUsersPointersPlugin
22087
22192
  exports.WeaveZoomInToolAction = WeaveZoomInToolAction
22088
22193
  exports.WeaveZoomOutToolAction = WeaveZoomOutToolAction
22194
+ exports.checkIfOverContainer = checkIfOverContainer
22195
+ exports.clearContainerTargets = clearContainerTargets
22196
+ exports.moveNodeToContainer = moveNodeToContainer
22089
22197
  exports.resetScale = resetScale