@inditextech/weave-sdk 0.18.0 → 0.19.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.cjs CHANGED
@@ -15769,12 +15769,12 @@ function checkIfOverContainer(instance, node) {
15769
15769
  return layerToMove;
15770
15770
  }
15771
15771
  function moveNodeToContainer(instance, node) {
15772
- const nodesIntersected = instance.pointIntersectsContainerElement();
15772
+ const nodeIntersected = instance.pointIntersectsContainerElement();
15773
15773
  let nodeActualContainer = node.getParent();
15774
15774
  if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
15775
15775
  let layerToMove = void 0;
15776
- if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
15777
- if (!nodesIntersected && nodeActualContainer?.getAttrs().id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
15776
+ if (!node.getAttrs().containerId && nodeIntersected && nodeActualContainer?.getAttrs().id !== nodeIntersected.getAttrs().id) layerToMove = nodeIntersected;
15777
+ if (!nodeIntersected && nodeActualContainer?.getAttrs().id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
15778
15778
  if (layerToMove) {
15779
15779
  const nodePos = node.getAbsolutePosition();
15780
15780
  const nodeRotation = node.getAbsoluteRotation();
@@ -17138,6 +17138,28 @@ var WeaveTargetingManager = class {
17138
17138
  this.logger = this.instance.getChildLogger("targeting-manager");
17139
17139
  this.logger.debug("Targeting manager created");
17140
17140
  }
17141
+ resolveNode(node) {
17142
+ const stage = this.instance.getStage();
17143
+ const nodeAttrs = node.getAttrs();
17144
+ if (nodeAttrs.nodeId) {
17145
+ const parentNode = stage.findOne(`#${nodeAttrs.nodeId}`);
17146
+ if (!parentNode) return void 0;
17147
+ return this.resolveNode(parentNode);
17148
+ }
17149
+ if (nodeAttrs.nodeType && nodeAttrs.nodeType !== "layer") return node;
17150
+ return void 0;
17151
+ }
17152
+ pointIntersectsElement(point) {
17153
+ const stage = this.instance.getStage();
17154
+ const relativeMousePointer = point ? point : stage.getPointerPosition() ?? {
17155
+ x: 0,
17156
+ y: 0
17157
+ };
17158
+ const mainLayer = this.instance.getMainLayer();
17159
+ if (!mainLayer) return null;
17160
+ const intersectedNode = mainLayer.getIntersection(relativeMousePointer);
17161
+ return intersectedNode;
17162
+ }
17141
17163
  pointIntersectsContainerElement(actualLayer, point) {
17142
17164
  const stage = this.instance.getStage();
17143
17165
  const relativeMousePointer = point ? point : stage.getPointerPosition() ?? {
@@ -17149,7 +17171,9 @@ var WeaveTargetingManager = class {
17149
17171
  if (intersections) for (const node of intersections) {
17150
17172
  if (node.getAttrs().nodeId) {
17151
17173
  const parent = stage.findOne(`#${node.getAttrs().nodeId}`);
17152
- intersectedNode = parent;
17174
+ if (!parent) continue;
17175
+ const resolvedNode = this.resolveNode(parent);
17176
+ if (resolvedNode && resolvedNode.getAttrs().containerId && resolvedNode.getAttrs().id !== actualLayer?.getAttrs().id) intersectedNode = parent;
17153
17177
  continue;
17154
17178
  }
17155
17179
  if (node.getAttrs().containerId && node.getAttrs().id !== actualLayer?.getAttrs().id) {
@@ -17919,7 +17943,7 @@ var WeaveRegisterManager = class {
17919
17943
 
17920
17944
  //#endregion
17921
17945
  //#region package.json
17922
- var version = "0.18.0";
17946
+ var version = "0.19.0";
17923
17947
 
17924
17948
  //#endregion
17925
17949
  //#region src/managers/setup.ts
@@ -18525,6 +18549,14 @@ var Weave = class extends Emittery {
18525
18549
  unGroup(group) {
18526
18550
  this.groupsManager.unGroup(group);
18527
18551
  }
18552
+ resolveNode(node) {
18553
+ const resolvedNode = this.targetingManager.resolveNode(node);
18554
+ if (resolvedNode) return resolvedNode;
18555
+ return void 0;
18556
+ }
18557
+ pointIntersectsElement(point) {
18558
+ return this.targetingManager.pointIntersectsElement(point);
18559
+ }
18528
18560
  pointIntersectsContainerElement(actualLayer, point) {
18529
18561
  return this.targetingManager.pointIntersectsContainerElement(actualLayer, point);
18530
18562
  }
@@ -18708,6 +18740,20 @@ const SELECTION_TOOL_STATE = {
18708
18740
  ["SELECTING"]: "selection"
18709
18741
  };
18710
18742
 
18743
+ //#endregion
18744
+ //#region src/actions/text-tool/constants.ts
18745
+ const TEXT_TOOL_ACTION_NAME = "textTool";
18746
+ const TEXT_TOOL_STATE = {
18747
+ ["IDLE"]: "idle",
18748
+ ["ADDING"]: "adding",
18749
+ ["FINISHED"]: "finished"
18750
+ };
18751
+ const TEXT_LAYOUT = {
18752
+ ["AUTO_ALL"]: "auto-all",
18753
+ ["AUTO_HEIGHT"]: "auto-height",
18754
+ ["FIXED"]: "fixed"
18755
+ };
18756
+
18711
18757
  //#endregion
18712
18758
  //#region src/nodes/text/text.ts
18713
18759
  var WeaveTextNode = class extends WeaveNode {
@@ -18728,7 +18774,23 @@ var WeaveTextNode = class extends WeaveNode {
18728
18774
  ...props,
18729
18775
  name: "node"
18730
18776
  });
18777
+ text.setAttrs({ measureMultilineText: this.measureMultilineText(text) });
18731
18778
  this.setupDefaultNodeEvents(text);
18779
+ text.on("transform", (e) => {
18780
+ const node = e.target;
18781
+ if (this.isSelecting() && this.isNodeSelected(node)) {
18782
+ const nodeHandler = this.instance.getNodeHandler(WEAVE_TEXT_NODE_TYPE);
18783
+ const serializedNode = nodeHandler.serialize(node);
18784
+ this.instance.updateNode({
18785
+ ...serializedNode,
18786
+ props: {
18787
+ ...serializedNode.props,
18788
+ layout: TEXT_LAYOUT.FIXED
18789
+ }
18790
+ });
18791
+ e.cancelBubble = true;
18792
+ }
18793
+ });
18732
18794
  window.addEventListener("keypress", (e) => {
18733
18795
  if (e.key === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing) {
18734
18796
  e.preventDefault();
@@ -18770,6 +18832,23 @@ var WeaveTextNode = class extends WeaveNode {
18770
18832
  }
18771
18833
  onUpdate(nodeInstance, nextProps) {
18772
18834
  nodeInstance.setAttrs({ ...nextProps });
18835
+ let width = nextProps.width;
18836
+ let height = nextProps.height;
18837
+ if (nextProps.layout === TEXT_LAYOUT.AUTO_ALL) {
18838
+ const { width: textAreaWidth, height: textAreaHeight } = this.textRenderedSize(nextProps.text, nodeInstance);
18839
+ width = textAreaWidth + 3.2;
18840
+ height = textAreaHeight + 3.2;
18841
+ }
18842
+ if (nextProps.layout === TEXT_LAYOUT.AUTO_HEIGHT) {
18843
+ const { height: textAreaHeight } = this.textRenderedSize(nextProps.text, nodeInstance);
18844
+ height = textAreaHeight + 3.2;
18845
+ }
18846
+ nodeInstance.setAttrs({
18847
+ width,
18848
+ height
18849
+ });
18850
+ if (nextProps.width !== nodeInstance.getAttrs().width || nextProps.height !== nodeInstance.getAttrs().height) this.updateNode(nodeInstance);
18851
+ if (this.editing) this.updateTextAreaDOM(nodeInstance);
18773
18852
  }
18774
18853
  serialize(instance) {
18775
18854
  const attrs = instance.getAttrs();
@@ -18787,73 +18866,119 @@ var WeaveTextNode = class extends WeaveNode {
18787
18866
  }
18788
18867
  };
18789
18868
  }
18790
- resizeTextAreaDOM(textNode) {
18791
- const textArea = document.getElementById(textNode.id());
18792
- if (!textArea) return;
18793
- const stage = this.instance.getStage();
18794
- const textPosition = textNode.absolutePosition();
18795
- const position = {
18796
- x: stage.container().offsetLeft + textPosition.x,
18797
- y: stage.container().offsetTop + textPosition.y
18798
- };
18799
- textArea.style.top = position.y + "px";
18800
- textArea.style.left = position.x + "px";
18801
- textArea.style.width = textNode.getWidth() * textNode.getAbsoluteScale().x + "px";
18802
- textArea.style.height = textNode.getHeight() * textNode.getAbsoluteScale().x + "px";
18803
- textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
18804
- }
18805
18869
  onZoomChangeHandler = (textNode) => () => {
18806
18870
  if (!this.editing) return;
18807
- this.resizeTextAreaDOM(textNode);
18871
+ this.updateTextAreaDOM(textNode);
18808
18872
  };
18809
18873
  onStageMoveHandler = (textNode) => () => {
18810
18874
  if (!this.editing) return;
18811
- this.resizeTextAreaDOM(textNode);
18875
+ this.updateTextAreaDOM(textNode);
18812
18876
  };
18877
+ textAreaDomResize(textAreaContainer, textArea, textNode) {
18878
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
18879
+ const { width: textAreaWidth } = this.textRenderedSize(textArea.value, textNode);
18880
+ textAreaContainer.style.width = (textAreaWidth + 5) * textNode.getAbsoluteScale().x + "px";
18881
+ }
18882
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) textAreaContainer.style.height = "auto";
18883
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
18884
+ textAreaContainer.style.height = "auto";
18885
+ textAreaContainer.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().y + "px";
18886
+ }
18887
+ textArea.style.height = "auto";
18888
+ textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18889
+ textArea.rows = textArea.value.split("\n").length;
18890
+ }
18891
+ measureMultilineText(textNode) {
18892
+ return () => {
18893
+ return this.textRenderedSize(textNode.text(), textNode);
18894
+ };
18895
+ }
18896
+ textRenderedSize(text, textNode) {
18897
+ let width = 0;
18898
+ let height = 0;
18899
+ const lines = text.split("\n");
18900
+ for (const line of lines) {
18901
+ const textSize = textNode.measureSize(line);
18902
+ if (textSize.width > width) width = textSize.width;
18903
+ height = height + textSize.height * (textNode.lineHeight() ?? 1);
18904
+ }
18905
+ return {
18906
+ width,
18907
+ height
18908
+ };
18909
+ }
18813
18910
  createTextAreaDOM(textNode, position) {
18814
18911
  const stage = this.instance.getStage();
18912
+ const textAreaSuperContainer = document.createElement("div");
18913
+ textAreaSuperContainer.id = `${textNode.id()}_supercontainer`;
18914
+ textAreaSuperContainer.style.position = "absolute";
18915
+ textAreaSuperContainer.style.top = "0px";
18916
+ textAreaSuperContainer.style.left = "0px";
18917
+ textAreaSuperContainer.style.bottom = "0px";
18918
+ textAreaSuperContainer.style.right = "0px";
18919
+ textAreaSuperContainer.style.overflow = "hidden";
18920
+ const textAreaContainer = document.createElement("div");
18921
+ textAreaContainer.id = `${textNode.id()}_container`;
18815
18922
  const textArea = document.createElement("textarea");
18816
18923
  textArea.id = textNode.id();
18817
- stage.container().appendChild(textArea);
18924
+ textAreaContainer.appendChild(textArea);
18925
+ textAreaSuperContainer.appendChild(textAreaContainer);
18926
+ stage.container().appendChild(textAreaSuperContainer);
18927
+ const containerRect = stage.container().getBoundingClientRect();
18818
18928
  this.instance.addEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
18819
18929
  this.instance.addEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
18820
18930
  window.weaveTextEditing[textNode.id()] = "editing";
18821
18931
  textArea.value = textNode.text();
18822
18932
  textArea.id = textNode.id();
18823
- textArea.style.position = "fixed";
18824
- textArea.style.top = position.y + "px";
18825
- textArea.style.left = position.x + "px";
18826
- textArea.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
18827
- textArea.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
18933
+ textAreaContainer.style.overflow = "hidden";
18934
+ textAreaContainer.style.display = "flex";
18935
+ textAreaContainer.style.justifyContent = "start";
18936
+ if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
18937
+ if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
18938
+ if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
18939
+ textAreaContainer.style.position = "absolute";
18940
+ textAreaContainer.style.top = -containerRect.y + position.y + "px";
18941
+ textAreaContainer.style.left = -containerRect.x + position.x + "px";
18942
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
18943
+ textAreaContainer.style.width = textArea.scrollWidth + "px";
18944
+ textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
18945
+ }
18946
+ if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
18947
+ textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
18948
+ textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
18949
+ }
18950
+ if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
18951
+ textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
18952
+ textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
18953
+ }
18828
18954
  textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
18829
- textArea.style.border = "solid 1px #1e40af";
18955
+ textArea.rows = textNode.text().split("\n").length;
18956
+ textAreaContainer.style.border = "solid 1px #1e40af";
18957
+ textArea.style.caretColor = "black";
18958
+ textArea.style.width = "100%";
18830
18959
  textArea.style.minHeight = "auto";
18831
18960
  textArea.style.margin = "0px";
18832
18961
  textArea.style.overflow = "hidden";
18833
18962
  textArea.style.background = "transparent";
18963
+ textArea.style.border = "none";
18834
18964
  textArea.style.outline = "none";
18835
18965
  textArea.style.resize = "none";
18836
18966
  textArea.style.lineHeight = `${textNode.lineHeight()}`;
18837
18967
  textArea.style.fontFamily = textNode.fontFamily();
18838
- textArea.style.transformOrigin = "left top";
18968
+ textAreaContainer.style.transformOrigin = "left top";
18839
18969
  textArea.style.textAlign = textNode.align();
18840
18970
  textArea.style.color = `${textNode.fill()}`;
18841
18971
  textArea.onfocus = () => {
18842
- textArea.style.height = "auto";
18843
- textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18844
- textArea.setSelectionRange(textArea.value.length, textArea.value.length);
18972
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
18845
18973
  };
18846
18974
  textArea.onkeydown = () => {
18847
- textArea.style.height = "auto";
18848
- textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18975
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
18849
18976
  };
18850
18977
  textArea.onkeyup = () => {
18851
- textArea.style.height = "auto";
18852
- textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18978
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
18853
18979
  };
18854
18980
  textArea.oninput = () => {
18855
- textArea.style.height = "auto";
18856
- textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
18981
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
18857
18982
  };
18858
18983
  const rotation = textNode.rotation();
18859
18984
  let transform = "";
@@ -18866,10 +18991,12 @@ var WeaveTextNode = class extends WeaveNode {
18866
18991
  const handleKeyDown = (e) => {
18867
18992
  e.stopPropagation();
18868
18993
  if (textArea && textNode && e.key === "Escape") {
18869
- textNode.width(parseFloat(textArea.style.width) * (1 / textNode.getAbsoluteScale().x));
18870
- textNode.height((textArea.scrollHeight + 1.6) * (1 / textNode.getAbsoluteScale().x));
18994
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
18995
+ const { width: textAreaWidth } = this.textRenderedSize(textArea.value, textNode);
18996
+ textNode.width(textAreaWidth + 3.2);
18997
+ }
18998
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) textNode.height((textArea.scrollHeight + 1.6) * (1 / textNode.getAbsoluteScale().x));
18871
18999
  textNode.text(textArea.value);
18872
- this.updateNode(textNode);
18873
19000
  this.removeTextAreaDOM(textNode);
18874
19001
  this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
18875
19002
  this.instance.removeEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
@@ -18880,9 +19007,11 @@ var WeaveTextNode = class extends WeaveNode {
18880
19007
  const handleKeyUp = () => {
18881
19008
  textNode.text(textArea.value);
18882
19009
  if (textArea && textNode) {
18883
- textArea.style.width = textNode.width() * textNode.getAbsoluteScale().x + "px";
18884
- textArea.style.height = "auto";
18885
- textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
19010
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
19011
+ textAreaContainer.style.height = "auto";
19012
+ textAreaContainer.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
19013
+ }
19014
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
18886
19015
  }
18887
19016
  };
18888
19017
  textArea.addEventListener("keydown", handleKeyDown);
@@ -18890,22 +19019,16 @@ var WeaveTextNode = class extends WeaveNode {
18890
19019
  textArea.tabIndex = 1;
18891
19020
  textArea.focus();
18892
19021
  const handleOutsideClick = (e) => {
18893
- if (!e && textArea.value === "") {
18894
- this.updateNode(textNode);
18895
- this.removeTextAreaDOM(textNode);
18896
- textArea.removeEventListener("keydown", handleKeyDown);
18897
- textArea.removeEventListener("keyup", handleKeyUp);
18898
- window.removeEventListener("click", handleOutsideClick);
18899
- window.removeEventListener("touchstart", handleOutsideClick);
18900
- }
18901
- if (e && e.target !== textArea && textArea.value !== "") {
19022
+ let clickedOnCanvas = false;
19023
+ if (e.target?.id === `${textNode.id()}_supercontainer`) clickedOnCanvas = true;
19024
+ if (clickedOnCanvas) {
18902
19025
  textNode.text(textArea.value);
18903
- this.updateNode(textNode);
18904
19026
  this.removeTextAreaDOM(textNode);
18905
19027
  textArea.removeEventListener("keydown", handleKeyDown);
18906
19028
  textArea.removeEventListener("keyup", handleKeyUp);
18907
19029
  window.removeEventListener("click", handleOutsideClick);
18908
19030
  window.removeEventListener("touchstart", handleOutsideClick);
19031
+ return;
18909
19032
  }
18910
19033
  };
18911
19034
  setTimeout(() => {
@@ -18913,12 +19036,58 @@ var WeaveTextNode = class extends WeaveNode {
18913
19036
  window.addEventListener("touchstart", handleOutsideClick);
18914
19037
  });
18915
19038
  }
19039
+ updateTextAreaDOM(textNode) {
19040
+ const textAreaContainer = document.getElementById(`${textNode.id()}_container`);
19041
+ const textArea = document.getElementById(textNode.id());
19042
+ if (!textAreaContainer || !textArea) return;
19043
+ const stage = this.instance.getStage();
19044
+ const containerRect = stage.container().getBoundingClientRect();
19045
+ const textPosition = textNode.getClientRect();
19046
+ const position = {
19047
+ x: textPosition.x,
19048
+ y: textPosition.y
19049
+ };
19050
+ textAreaContainer.style.top = -containerRect.y + position.y + "px";
19051
+ textAreaContainer.style.left = -containerRect.x + position.x + "px";
19052
+ if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
19053
+ if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
19054
+ if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
19055
+ textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
19056
+ textArea.rows = textNode.text().split("\n").length;
19057
+ textArea.style.lineHeight = `${textNode.lineHeight()}`;
19058
+ textArea.style.fontFamily = textNode.fontFamily();
19059
+ textArea.style.textAlign = textNode.align();
19060
+ textArea.style.color = `${textNode.fill()}`;
19061
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
19062
+ this.textAreaDomResize(textAreaContainer, textArea, textNode);
19063
+ const rotation = textNode.rotation();
19064
+ let transform = "";
19065
+ if (rotation) transform += "rotateZ(" + rotation + "deg)";
19066
+ const px = 0;
19067
+ const py = -3 * stage.scaleY();
19068
+ transform += "translateX(" + px + "px)";
19069
+ transform += "translateY(" + py + "px)";
19070
+ textArea.style.transform = transform;
19071
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
19072
+ if (selectionPlugin) {
19073
+ const tr = selectionPlugin.getTransformer();
19074
+ this.instance.disablePlugin("nodesSelection");
19075
+ tr.hide();
19076
+ }
19077
+ if (this.editing) textNode.visible(false);
19078
+ else textNode.visible(true);
19079
+ }
18916
19080
  removeTextAreaDOM(textNode) {
18917
19081
  const stage = this.instance.getStage();
18918
19082
  delete window.weaveTextEditing[textNode.id()];
19083
+ const textAreaSuperContainer = document.getElementById(`${textNode.id()}_supercontainer`);
19084
+ if (textAreaSuperContainer) textAreaSuperContainer.remove();
19085
+ const textAreaContainer = document.getElementById(`${textNode.id()}_container`);
19086
+ if (textAreaContainer) textAreaContainer.remove();
18919
19087
  const textArea = document.getElementById(textNode.id());
18920
19088
  if (textArea) textArea.remove();
18921
19089
  textNode.visible(true);
19090
+ this.updateNode(textNode);
18922
19091
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
18923
19092
  if (selectionPlugin) {
18924
19093
  this.instance.enablePlugin("nodesSelection");
@@ -18926,7 +19095,6 @@ var WeaveTextNode = class extends WeaveNode {
18926
19095
  if (tr) {
18927
19096
  tr.nodes([textNode]);
18928
19097
  tr.show();
18929
- tr.forceUpdate();
18930
19098
  }
18931
19099
  this.instance.triggerAction("selectionTool");
18932
19100
  }
@@ -19401,6 +19569,7 @@ var WeaveImageNode = class extends WeaveNode {
19401
19569
  const imageProps = props;
19402
19570
  const { id } = imageProps;
19403
19571
  const groupImageProps = { ...imageProps };
19572
+ delete groupImageProps.children;
19404
19573
  delete groupImageProps.imageProperties;
19405
19574
  delete groupImageProps.zIndex;
19406
19575
  const internalImageProps = { ...props };
@@ -19415,6 +19584,7 @@ var WeaveImageNode = class extends WeaveNode {
19415
19584
  const imagePlaceholder = new konva.default.Rect({
19416
19585
  ...groupImageProps,
19417
19586
  id: `${id}-placeholder`,
19587
+ nodeId: id,
19418
19588
  x: 0,
19419
19589
  y: 0,
19420
19590
  scaleX: 1,
@@ -19432,6 +19602,7 @@ var WeaveImageNode = class extends WeaveNode {
19432
19602
  ...internalImageProps,
19433
19603
  ...imageProperties,
19434
19604
  id: `${id}-image`,
19605
+ nodeId: id,
19435
19606
  x: 0,
19436
19607
  y: 0,
19437
19608
  scaleX: 1,
@@ -19503,6 +19674,7 @@ var WeaveImageNode = class extends WeaveNode {
19503
19674
  ...nodeAttrs.imageProperties ?? {},
19504
19675
  name: void 0,
19505
19676
  id: `${id}-placeholder`,
19677
+ nodeId: id,
19506
19678
  x: 0,
19507
19679
  y: 0,
19508
19680
  scaleX: 1,
@@ -19519,6 +19691,7 @@ var WeaveImageNode = class extends WeaveNode {
19519
19691
  ...nodeAttrs.imageProperties ?? {},
19520
19692
  name: void 0,
19521
19693
  id: `${id}-image`,
19694
+ nodeId: id,
19522
19695
  x: 0,
19523
19696
  y: 0,
19524
19697
  scaleX: 1,
@@ -19534,6 +19707,7 @@ var WeaveImageNode = class extends WeaveNode {
19534
19707
  ...nodeAttrs.imageProperties ?? {},
19535
19708
  name: void 0,
19536
19709
  id: `${id}-image`,
19710
+ nodeId: id,
19537
19711
  x: 0,
19538
19712
  y: 0,
19539
19713
  scaleX: 1,
@@ -20179,6 +20353,13 @@ var WeaveMoveToolAction = class extends WeaveAction {
20179
20353
  return MOVE_TOOL_ACTION_NAME;
20180
20354
  }
20181
20355
  setupEvents() {
20356
+ const stage = this.instance.getStage();
20357
+ stage.container().addEventListener("keydown", (e) => {
20358
+ if (e.key === "Escape" && this.instance.getActiveAction() === MOVE_TOOL_ACTION_NAME) {
20359
+ this.cancelAction();
20360
+ return;
20361
+ }
20362
+ });
20182
20363
  this.initialized = true;
20183
20364
  }
20184
20365
  setState(state) {
@@ -20203,11 +20384,7 @@ var WeaveMoveToolAction = class extends WeaveAction {
20203
20384
  const stage = this.instance.getStage();
20204
20385
  stage.container().style.cursor = "default";
20205
20386
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
20206
- if (selectionPlugin) {
20207
- const tr = selectionPlugin.getTransformer();
20208
- this.instance.disablePlugin("nodesSelection");
20209
- tr.hide();
20210
- }
20387
+ if (selectionPlugin) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
20211
20388
  this.setState(MOVE_TOOL_STATE.IDLE);
20212
20389
  }
20213
20390
  };
@@ -20266,6 +20443,82 @@ var WeaveSelectionToolAction = class extends WeaveAction {
20266
20443
  }
20267
20444
  };
20268
20445
 
20446
+ //#endregion
20447
+ //#region src/actions/eraser-tool/constants.ts
20448
+ const ERASER_TOOL_ACTION_NAME = "eraserTool";
20449
+ const ERASER_TOOL_STATE = {
20450
+ ["IDLE"]: "idle",
20451
+ ["ERASING"]: "erasing"
20452
+ };
20453
+
20454
+ //#endregion
20455
+ //#region src/actions/eraser-tool/eraser-tool.ts
20456
+ var WeaveEraserToolAction = class extends WeaveAction {
20457
+ initialized = false;
20458
+ erasing = false;
20459
+ onPropsChange = void 0;
20460
+ onInit = void 0;
20461
+ constructor() {
20462
+ super();
20463
+ this.initialized = false;
20464
+ this.erasing = false;
20465
+ this.state = ERASER_TOOL_STATE.IDLE;
20466
+ }
20467
+ getName() {
20468
+ return ERASER_TOOL_ACTION_NAME;
20469
+ }
20470
+ setupEvents() {
20471
+ const stage = this.instance.getStage();
20472
+ stage.on("click touch", (e) => {
20473
+ e.evt.preventDefault();
20474
+ if (!this.erasing) return;
20475
+ const nodeIntersected = this.instance.pointIntersectsElement();
20476
+ if (nodeIntersected) {
20477
+ const realNode = this.instance.resolveNode(nodeIntersected);
20478
+ if (!realNode) return;
20479
+ const nodeType = realNode.getAttrs().nodeType;
20480
+ const nodeHandler = this.instance.getNodeHandler(nodeType);
20481
+ const nodeSerialized = nodeHandler.serialize(realNode);
20482
+ this.instance.removeNode(nodeSerialized);
20483
+ }
20484
+ });
20485
+ stage.container().addEventListener("keydown", (e) => {
20486
+ if (e.key === "Escape" && this.instance.getActiveAction() === ERASER_TOOL_ACTION_NAME) {
20487
+ this.cancelAction();
20488
+ return;
20489
+ }
20490
+ });
20491
+ this.initialized = true;
20492
+ }
20493
+ setState(state) {
20494
+ this.state = state;
20495
+ }
20496
+ setEraser() {
20497
+ const stage = this.instance.getStage();
20498
+ stage.container().style.cursor = "crosshair";
20499
+ stage.container().focus();
20500
+ this.erasing = true;
20501
+ this.setState(ERASER_TOOL_STATE.ERASING);
20502
+ }
20503
+ trigger(cancelAction) {
20504
+ if (!this.instance) throw new Error("Instance not defined");
20505
+ if (!this.initialized) this.setupEvents();
20506
+ const stage = this.instance.getStage();
20507
+ stage.container().tabIndex = 1;
20508
+ stage.container().focus();
20509
+ this.cancelAction = cancelAction;
20510
+ this.setEraser();
20511
+ }
20512
+ cleanup() {
20513
+ const stage = this.instance.getStage();
20514
+ stage.container().style.cursor = "default";
20515
+ this.erasing = false;
20516
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
20517
+ if (selectionPlugin) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
20518
+ this.setState(ERASER_TOOL_STATE.IDLE);
20519
+ }
20520
+ };
20521
+
20269
20522
  //#endregion
20270
20523
  //#region src/actions/rectangle-tool/constants.ts
20271
20524
  const RECTANGLE_TOOL_ACTION_NAME = "rectangleTool";
@@ -20830,15 +21083,6 @@ var WeaveBrushToolAction = class extends WeaveAction {
20830
21083
  }
20831
21084
  };
20832
21085
 
20833
- //#endregion
20834
- //#region src/actions/text-tool/constants.ts
20835
- const TEXT_TOOL_ACTION_NAME = "textTool";
20836
- const TEXT_TOOL_STATE = {
20837
- ["IDLE"]: "idle",
20838
- ["ADDING"]: "adding",
20839
- ["FINISHED"]: "finished"
20840
- };
20841
-
20842
21086
  //#endregion
20843
21087
  //#region src/actions/text-tool/text-tool.ts
20844
21088
  var WeaveTextToolAction = class extends WeaveAction {
@@ -20901,8 +21145,9 @@ var WeaveTextToolAction = class extends WeaveAction {
20901
21145
  const node = nodeHandler.create(this.textId, {
20902
21146
  x: this.clickPoint?.x ?? 0,
20903
21147
  y: this.clickPoint?.y ?? 0,
20904
- text: "Your text here...",
20905
- width: 300,
21148
+ text: "",
21149
+ layout: TEXT_LAYOUT.AUTO_ALL,
21150
+ width: 10,
20906
21151
  fontSize: 20,
20907
21152
  fontFamily: "Arial, sans-serif",
20908
21153
  fill: "#000000ff",
@@ -21438,10 +21683,10 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
21438
21683
  this.disableMove();
21439
21684
  }
21440
21685
  });
21441
- stage.on("mouseenter", () => {
21686
+ stage.container().addEventListener("mouseenter", () => {
21442
21687
  this.overStage = true;
21443
21688
  });
21444
- stage.on("mouseleave", () => {
21689
+ stage.container().addEventListener("mouseleave", () => {
21445
21690
  this.overStage = false;
21446
21691
  });
21447
21692
  stage.on("mousedown", (e) => {
@@ -21516,7 +21761,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
21516
21761
  if (!this.enabled || !this.overStage || this.isCtrlOrMetaPressed || this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed) return;
21517
21762
  stage.x(stage.x() - e.deltaX);
21518
21763
  stage.y(stage.y() - e.deltaY);
21519
- this.instance.emit("stageMove", void 0);
21764
+ this.instance.emit("onStageMove", void 0);
21520
21765
  });
21521
21766
  }
21522
21767
  enable() {
@@ -22376,6 +22621,8 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
22376
22621
  exports.BRUSH_TOOL_ACTION_NAME = BRUSH_TOOL_ACTION_NAME
22377
22622
  exports.BRUSH_TOOL_STATE = BRUSH_TOOL_STATE
22378
22623
  exports.COPY_PASTE_NODES_PLUGIN_STATE = COPY_PASTE_NODES_PLUGIN_STATE
22624
+ exports.ERASER_TOOL_ACTION_NAME = ERASER_TOOL_ACTION_NAME
22625
+ exports.ERASER_TOOL_STATE = ERASER_TOOL_STATE
22379
22626
  exports.FRAME_TOOL_ACTION_NAME = FRAME_TOOL_ACTION_NAME
22380
22627
  exports.FRAME_TOOL_STATE = FRAME_TOOL_STATE
22381
22628
  exports.GUIDE_LINE_DEFAULT_CONFIG = GUIDE_LINE_DEFAULT_CONFIG
@@ -22394,6 +22641,7 @@ exports.RECTANGLE_TOOL_ACTION_NAME = RECTANGLE_TOOL_ACTION_NAME
22394
22641
  exports.RECTANGLE_TOOL_STATE = RECTANGLE_TOOL_STATE
22395
22642
  exports.SELECTION_TOOL_ACTION_NAME = SELECTION_TOOL_ACTION_NAME
22396
22643
  exports.SELECTION_TOOL_STATE = SELECTION_TOOL_STATE
22644
+ exports.TEXT_LAYOUT = TEXT_LAYOUT
22397
22645
  exports.TEXT_TOOL_ACTION_NAME = TEXT_TOOL_ACTION_NAME
22398
22646
  exports.TEXT_TOOL_STATE = TEXT_TOOL_STATE
22399
22647
  exports.WEAVE_COPY_PASTE_NODES_KEY = WEAVE_COPY_PASTE_NODES_KEY
@@ -22426,6 +22674,7 @@ exports.WeaveBrushToolAction = WeaveBrushToolAction
22426
22674
  exports.WeaveConnectedUsersPlugin = WeaveConnectedUsersPlugin
22427
22675
  exports.WeaveContextMenuPlugin = WeaveContextMenuPlugin
22428
22676
  exports.WeaveCopyPasteNodesPlugin = WeaveCopyPasteNodesPlugin
22677
+ exports.WeaveEraserToolAction = WeaveEraserToolAction
22429
22678
  exports.WeaveExportNodeToolAction = WeaveExportNodeToolAction
22430
22679
  exports.WeaveExportStageToolAction = WeaveExportStageToolAction
22431
22680
  exports.WeaveFitToScreenToolAction = WeaveFitToScreenToolAction