@inditextech/weave-sdk 3.0.0 → 3.1.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.node.js CHANGED
@@ -17878,6 +17878,8 @@ function getTopmostShadowHost(el) {
17878
17878
  return current?.shadowRoot || null;
17879
17879
  }
17880
17880
  function getVisibleNodes({ instance, stage, nodeParent, skipNodes, referenceLayer }) {
17881
+ const nodesSelection = instance.getPlugin("nodesSelection");
17882
+ if (nodesSelection) nodesSelection.getTransformer().hide();
17881
17883
  const nodes = getVisibleNodesInViewport(stage, referenceLayer);
17882
17884
  const finalVisibleNodes = [];
17883
17885
  nodes.forEach((node) => {
@@ -17890,6 +17892,7 @@ function getVisibleNodes({ instance, stage, nodeParent, skipNodes, referenceLaye
17890
17892
  if (node.getParent() !== referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
17891
17893
  finalVisibleNodes.push(node);
17892
17894
  });
17895
+ if (nodesSelection) nodesSelection.getTransformer().show();
17893
17896
  return finalVisibleNodes;
17894
17897
  }
17895
17898
  function memoize(fn) {
@@ -18754,8 +18757,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18754
18757
  tr.on("transformstart", () => {
18755
18758
  this.transformInProcess = true;
18756
18759
  this.triggerSelectedNodesEvent();
18757
- tr.visible(false);
18758
- tr.forceUpdate();
18759
18760
  const selectedNodes$1 = tr.nodes();
18760
18761
  for (const node of selectedNodes$1) {
18761
18762
  node.handleMouseout();
@@ -18823,8 +18824,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18823
18824
  tr.on("transform", (0, import_throttle.default)(handleTransform, DEFAULT_THROTTLE_MS));
18824
18825
  tr.on("transformend", () => {
18825
18826
  this.transformInProcess = false;
18826
- tr.visible(true);
18827
- tr.forceUpdate();
18828
18827
  if (this.getSelectedNodes().length > 1) this.instance.releaseMutexLock();
18829
18828
  const selectedNodes$1 = tr.nodes();
18830
18829
  for (const node of selectedNodes$1) {
@@ -18842,8 +18841,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18842
18841
  let selectedNodes = [];
18843
18842
  tr.on("dragstart", (e) => {
18844
18843
  this.dragInProcess = true;
18845
- tr.visible(false);
18846
- tr.forceUpdate();
18847
18844
  const mainLayer = this.instance.getMainLayer();
18848
18845
  if (!mainLayer) return;
18849
18846
  initialPos = {
@@ -18918,8 +18915,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18918
18915
  tr.on("dragmove", (0, import_throttle.default)(handleDragMove, DEFAULT_THROTTLE_MS));
18919
18916
  tr.on("dragend", (e) => {
18920
18917
  this.dragInProcess = false;
18921
- tr.visible(true);
18922
- tr.forceUpdate();
18923
18918
  const mainLayer = this.instance.getMainLayer();
18924
18919
  if (!mainLayer) return;
18925
18920
  this.instance.getSelectionLayer()?.hitGraphEnabled(true);
@@ -19224,7 +19219,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19224
19219
  }
19225
19220
  });
19226
19221
  stage.container().addEventListener("keyup", (e) => {
19227
- if (e.ctrlKey || e.metaKey) this.isCtrlMetaPressed = false;
19222
+ if (!(e.ctrlKey || e.metaKey)) this.isCtrlMetaPressed = false;
19228
19223
  if (e.code === "Space") this.isSpaceKeyPressed = false;
19229
19224
  });
19230
19225
  stage.on("pointerdown", (e) => {
@@ -19401,8 +19396,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19401
19396
  this.selecting = false;
19402
19397
  this.stopPanLoop();
19403
19398
  this.tr.nodes([...selectedNodes]);
19404
- this.handleBehaviors();
19405
19399
  this.handleMultipleSelectionBehavior();
19400
+ this.handleBehaviors();
19406
19401
  if (this.tr.nodes().length > 0) {
19407
19402
  stage.container().tabIndex = 1;
19408
19403
  stage.container().focus();
@@ -19513,8 +19508,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19513
19508
  this.tr.nodes(nodes);
19514
19509
  areNodesSelected = true;
19515
19510
  }
19516
- this.handleBehaviors();
19517
19511
  this.handleMultipleSelectionBehavior();
19512
+ this.handleBehaviors();
19518
19513
  if (areNodesSelected) {
19519
19514
  stage.container().tabIndex = 1;
19520
19515
  stage.container().focus();
@@ -19550,11 +19545,12 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19550
19545
  for (const node of nodes) anchorsArrays.push(node?.allowedAnchors() ?? []);
19551
19546
  const enabledAnchors = intersectArrays(anchorsArrays);
19552
19547
  transformerAttrs.enabledAnchors = enabledAnchors;
19553
- this.tr.enabledAnchors(transformerAttrs.enabledAnchors);
19554
19548
  }
19555
19549
  if (this.tr && this.tr.nodes().length > 0) {
19550
+ if (transformerAttrs.enabledAnchors?.length === 0) transformerAttrs.resizeEnabled = false;
19556
19551
  this.tr.setAttrs(transformerAttrs);
19557
19552
  this.tr.forceUpdate();
19553
+ this.tr.getLayer()?.batchDraw();
19558
19554
  }
19559
19555
  }
19560
19556
  setSelectedNodes(nodes) {
@@ -19871,8 +19867,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
19871
19867
  }
19872
19868
  }
19873
19869
  handlePaste(position, relativePosition) {
19874
- const stage = this.instance.getStage();
19875
- if (this.toPaste) {
19870
+ this.instance.stateTransactional(() => {
19871
+ const stage = this.instance.getStage();
19872
+ if (!this.toPaste) return;
19876
19873
  const nodesToSelect = [];
19877
19874
  const newElements = this.checkIfInternalElementsAreNew(JSON.stringify(this.toPaste));
19878
19875
  if (this.config.paddingOnPaste.enabled && newElements) {
@@ -19883,7 +19880,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
19883
19880
  for (const element of Object.keys(this.toPaste.weave)) {
19884
19881
  const node = this.toPaste.weave[element].element;
19885
19882
  const posRelativeToSelection = this.toPaste.weave[element].posRelativeToSelection;
19886
- let containerId = this.toPaste.weave[element].containerId;
19883
+ let containerId = this.toPaste.weave[element]?.containerId;
19884
+ const nodeHandler = this.instance.getNodeHandler(node.props.nodeType ?? "");
19885
+ if (!nodeHandler) continue;
19887
19886
  if (node.props.children) this.recursivelyUpdateKeys(node.props.children);
19888
19887
  const newNodeId = v4_default();
19889
19888
  delete node.props.containerId;
@@ -19905,24 +19904,24 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
19905
19904
  containerId = container.getAttrs().id ?? "";
19906
19905
  localPos = container.getAbsoluteTransform().copy().invert().point(position);
19907
19906
  }
19908
- const nodeHandler = this.instance.getNodeHandler(node.props.nodeType ?? "");
19909
- if (nodeHandler) {
19910
- const realOffset = nodeHandler.realOffset(node);
19911
- node.props.x = localPos.x + realOffset.x + posRelativeToSelection.x;
19912
- node.props.y = localPos.y + realOffset.y + posRelativeToSelection.y;
19913
- }
19914
- } else {
19915
- const nodeHandler = this.instance.getNodeHandler(node.props.nodeType ?? "");
19916
- if (nodeHandler) {
19917
- node.props.x = node.props.x + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingX : 0);
19918
- node.props.y = node.props.y + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingY : 0);
19919
- }
19907
+ const realOffset = nodeHandler.realOffset(node);
19908
+ node.props.x = localPos.x + realOffset.x + posRelativeToSelection.x;
19909
+ node.props.y = localPos.y + realOffset.y + posRelativeToSelection.y;
19910
+ }
19911
+ if (!position) {
19912
+ node.props.x = node.props.x + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingX : 0);
19913
+ node.props.y = node.props.y + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingY : 0);
19914
+ }
19915
+ let containerNode = this.instance.getStage().findOne(`#${containerId}`);
19916
+ if (!containerNode) {
19917
+ containerId = this.instance.getMainLayer()?.getAttrs().id ?? "";
19918
+ containerNode = this.instance.getMainLayer();
19919
+ }
19920
+ if (containerId) {
19921
+ this.instance.addNodeNT(node, containerId);
19922
+ const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
19923
+ if (realNode) nodesToSelect.push(realNode);
19920
19924
  }
19921
- const containerNode = this.instance.getStage().findOne(`#${containerId}`);
19922
- if (!containerNode) containerId = this.instance.getMainLayer()?.getAttrs().id ?? "";
19923
- this.instance.addNode(node, containerId);
19924
- const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
19925
- if (realNode) nodesToSelect.push(realNode);
19926
19925
  this.getStageGridPlugin()?.onRender();
19927
19926
  }
19928
19927
  this.instance.emitEvent("onPaste", {
@@ -19936,8 +19935,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
19936
19935
  smartZoom: true
19937
19936
  });
19938
19937
  this.toPaste = void 0;
19939
- }
19940
- this.cancel();
19938
+ this.cancel();
19939
+ });
19941
19940
  }
19942
19941
  async finishHandleCopy() {
19943
19942
  this.actualInternalPaddingX = 0;
@@ -19965,7 +19964,12 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
19965
19964
  y: 0
19966
19965
  }
19967
19966
  };
19968
- for (const node of selectedNodes) {
19967
+ const selectedNodesSortedByZIndexAsc = [...selectedNodes].sort((a, b) => {
19968
+ const aZ = a.getZIndex() ?? 0;
19969
+ const bZ = b.getZIndex() ?? 0;
19970
+ return aZ - bZ;
19971
+ });
19972
+ for (const node of selectedNodesSortedByZIndexAsc) {
19969
19973
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
19970
19974
  if (!nodeHandler) continue;
19971
19975
  const parentNode = node.getParent();
@@ -20327,7 +20331,8 @@ var WeaveNode = class {
20327
20331
  if (!selectionPlugin) return;
20328
20332
  selectionPlugin.getHoverTransformer().nodes([]);
20329
20333
  }
20330
- setupDefaultNodeEvents(node) {
20334
+ setupDefaultNodeEvents(node, options = { performScaleReset: true }) {
20335
+ const { performScaleReset } = mergeExceptArrays({ performScaleReset: true }, options);
20331
20336
  const handleNodesChange = () => {
20332
20337
  if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
20333
20338
  node.draggable(true);
@@ -20394,13 +20399,16 @@ var WeaveNode = class {
20394
20399
  const nodesSnappingPlugin = this.getNodesEdgeSnappingPlugin();
20395
20400
  if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupGuidelines();
20396
20401
  if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
20397
- this.scaleReset(node$1);
20402
+ if (performScaleReset) this.scaleReset(node$1);
20398
20403
  if (this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
20399
20404
  this.getNodesSelectionFeedbackPlugin()?.showSelectionHalo(node$1);
20400
20405
  this.getNodesSelectionFeedbackPlugin()?.updateSelectionHalo(node$1);
20401
20406
  }
20402
20407
  const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
20403
- if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
20408
+ if (nodeHandler) {
20409
+ const shouldUpdateOnTransform = node$1.getAttrs().shouldUpdateOnTransform ?? true;
20410
+ if (shouldUpdateOnTransform) this.instance.updateNode(nodeHandler.serialize(node$1));
20411
+ }
20404
20412
  this.getNodesSelectionPlugin()?.getHoverTransformer().forceUpdate();
20405
20413
  });
20406
20414
  const stage = this.instance.getStage();
@@ -20636,7 +20644,9 @@ var WeaveNode = class {
20636
20644
  }
20637
20645
  });
20638
20646
  node.handleSelectNode = () => {
20639
- this.getNodesSelectionFeedbackPlugin()?.createSelectionHalo(node);
20647
+ const transformer = this.getNodesSelectionPlugin()?.getTransformer();
20648
+ if (!transformer) return;
20649
+ if (transformer.nodes().length > 1) this.getNodesSelectionFeedbackPlugin()?.createSelectionHalo(node);
20640
20650
  };
20641
20651
  node.handleDeselectNode = () => {
20642
20652
  this.getNodesSelectionFeedbackPlugin()?.destroySelectionHalo(node);
@@ -21935,7 +21945,7 @@ var WeaveRegisterManager = class {
21935
21945
 
21936
21946
  //#endregion
21937
21947
  //#region package.json
21938
- var version = "3.0.0";
21948
+ var version = "3.1.0";
21939
21949
 
21940
21950
  //#endregion
21941
21951
  //#region src/managers/setup.ts
@@ -23684,7 +23694,7 @@ var WeaveStageNode = class extends WeaveNode {
23684
23694
  }
23685
23695
  });
23686
23696
  window.addEventListener("keyup", (e) => {
23687
- if (!e.ctrlKey && !e.metaKey) {
23697
+ if (!(e.ctrlKey || e.metaKey)) {
23688
23698
  this.isCmdCtrlPressed = false;
23689
23699
  this.instance.getStage().container().style.cursor = "default";
23690
23700
  const transformer = this.getSelectionPlugin()?.getTransformer();
@@ -24327,16 +24337,8 @@ const WEAVE_TEXT_NODE_DEFAULT_CONFIG = {
24327
24337
  transform: { ...WEAVE_NODES_SELECTION_DEFAULT_CONFIG.selection },
24328
24338
  outline: { enabled: false }
24329
24339
  };
24330
-
24331
- //#endregion
24332
- //#region src/actions/text-tool/constants.ts
24333
- const TEXT_TOOL_ACTION_NAME = "textTool";
24334
- const TEXT_TOOL_STATE = {
24335
- ["IDLE"]: "idle",
24336
- ["ADDING"]: "adding",
24337
- ["FINISHED"]: "finished"
24338
- };
24339
24340
  const TEXT_LAYOUT = {
24341
+ ["SMART"]: "smart",
24340
24342
  ["AUTO_ALL"]: "auto-all",
24341
24343
  ["AUTO_HEIGHT"]: "auto-height",
24342
24344
  ["FIXED"]: "fixed"
@@ -24350,6 +24352,8 @@ var WeaveTextNode = class extends WeaveNode {
24350
24352
  textAreaSuperContainer = null;
24351
24353
  textAreaContainer = null;
24352
24354
  textArea = null;
24355
+ eventsInitialized = false;
24356
+ isCtrlMetaPressed = false;
24353
24357
  constructor(params) {
24354
24358
  super();
24355
24359
  const { config } = params ?? {};
@@ -24358,6 +24362,17 @@ var WeaveTextNode = class extends WeaveNode {
24358
24362
  this.editing = false;
24359
24363
  this.textArea = null;
24360
24364
  }
24365
+ initEvents() {
24366
+ if (!this.eventsInitialized && !globalThis._weave_isServerSide) {
24367
+ window.addEventListener("keydown", (e) => {
24368
+ if (e.ctrlKey || e.metaKey) this.isCtrlMetaPressed = true;
24369
+ });
24370
+ window.addEventListener("keyup", (e) => {
24371
+ if (!(e.ctrlKey || e.metaKey)) this.isCtrlMetaPressed = false;
24372
+ });
24373
+ this.eventsInitialized = true;
24374
+ }
24375
+ }
24361
24376
  updateNode(nodeInstance) {
24362
24377
  const actNode = this.instance.getStage().findOne(`#${nodeInstance.id()}`);
24363
24378
  if (actNode) {
@@ -24386,6 +24401,7 @@ var WeaveTextNode = class extends WeaveNode {
24386
24401
  }
24387
24402
  }
24388
24403
  onRender(props) {
24404
+ this.initEvents();
24389
24405
  const text = new Konva.Text({
24390
24406
  ...props,
24391
24407
  name: "node",
@@ -24401,6 +24417,12 @@ var WeaveTextNode = class extends WeaveNode {
24401
24417
  const defaultTransformerProperties = this.defaultGetTransformerProperties(this.config.transform);
24402
24418
  text.getTransformerProperties = function() {
24403
24419
  const actualAttrs = this.getAttrs();
24420
+ if (actualAttrs.layout === TEXT_LAYOUT.SMART) return {
24421
+ ...defaultTransformerProperties,
24422
+ resizeEnabled: true,
24423
+ keepRatio: false,
24424
+ enabledAnchors: []
24425
+ };
24404
24426
  if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return {
24405
24427
  ...defaultTransformerProperties,
24406
24428
  resizeEnabled: false,
@@ -24415,6 +24437,14 @@ var WeaveTextNode = class extends WeaveNode {
24415
24437
  };
24416
24438
  text.allowedAnchors = function() {
24417
24439
  const actualAttrs = this.getAttrs();
24440
+ if (actualAttrs.layout === TEXT_LAYOUT.SMART) return [
24441
+ "top-left",
24442
+ "top-right",
24443
+ "middle-right",
24444
+ "middle-left",
24445
+ "bottom-left",
24446
+ "bottom-right"
24447
+ ];
24418
24448
  if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return [];
24419
24449
  if (actualAttrs.layout === TEXT_LAYOUT.AUTO_HEIGHT) return ["middle-right", "middle-left"];
24420
24450
  return [
@@ -24429,35 +24459,93 @@ var WeaveTextNode = class extends WeaveNode {
24429
24459
  ];
24430
24460
  };
24431
24461
  text.setAttrs({ measureMultilineText: this.measureMultilineText(text) });
24432
- this.setupDefaultNodeEvents(text);
24433
- const handleTextTransform = (e) => {
24434
- const node = e.target;
24435
- if (this.isSelecting() && this.isNodeSelected(node)) e.cancelBubble = true;
24436
- };
24437
- text.on("transformstart", (e) => {
24438
- this.instance.emitEvent("onTransform", e.target);
24439
- });
24440
- text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
24441
- text.on("transformend", () => {
24442
- this.instance.emitEvent("onTransform", null);
24443
- });
24462
+ this.setupDefaultNodeEvents(text, { performScaleReset: false });
24444
24463
  text.dblClick = () => {
24445
24464
  if (this.editing) return;
24446
24465
  if (!(this.isSelecting() && this.isNodeSelected(text))) return;
24447
24466
  this.triggerEditMode(text);
24448
24467
  };
24449
- text.on("transform", (e) => {
24450
- if (this.isSelecting() && this.isNodeSelected(text)) {
24451
- text.setAttrs({
24452
- width: text.width() * text.scaleX(),
24453
- scaleX: 1
24454
- });
24468
+ text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
24469
+ let actualAnchor = void 0;
24470
+ text.on("transformstart", (e) => {
24471
+ this.instance.emitEvent("onTransform", e.target);
24472
+ actualAnchor = this.getNodesSelectionPlugin()?.getTransformer()?.getActiveAnchor();
24473
+ if (text.getAttrs().layout === TEXT_LAYOUT.SMART && [
24474
+ "top-left",
24475
+ "top-right",
24476
+ "bottom-left",
24477
+ "bottom-right"
24478
+ ].includes(actualAnchor ?? "") || text.getAttrs().layout === TEXT_LAYOUT.FIXED && this.isCtrlMetaPressed) this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(true);
24479
+ else this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(false);
24480
+ if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
24481
+ text.wrap("word");
24482
+ text.height(void 0);
24483
+ }
24484
+ e.cancelBubble = true;
24485
+ });
24486
+ const handleTextTransform = () => {
24487
+ if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
24488
+ text.width(text.width() * text.scaleX());
24489
+ text.scaleX(1);
24490
+ text.scaleY(1);
24491
+ text.height(void 0);
24492
+ text.getLayer()?.batchDraw();
24493
+ }
24494
+ if (this.isSelecting() && this.isNodeSelected(text) && ![TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) || this.isSelecting() && this.isNodeSelected(text) && [TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ![
24495
+ "top-left",
24496
+ "top-right",
24497
+ "bottom-left",
24498
+ "bottom-right"
24499
+ ].includes(actualAnchor ?? "")) {
24500
+ text.width(text.width() * text.scaleX());
24455
24501
  resetScale(text);
24456
24502
  text.fontSize(text.fontSize() * text.scaleY());
24457
- e.cancelBubble = true;
24458
24503
  }
24504
+ text.setAttr("shouldUpdateOnTransform", false);
24505
+ text.getLayer()?.batchDraw();
24506
+ };
24507
+ text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
24508
+ const handleTransformEnd = () => {
24509
+ this.instance.emitEvent("onTransform", null);
24510
+ let definedSmartWidth = false;
24511
+ let smartFixedWidth = text.getAttr("smartFixedWidth") ?? false;
24512
+ if (![TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ![
24513
+ "top-left",
24514
+ "top-right",
24515
+ "bottom-left",
24516
+ "bottom-right"
24517
+ ].includes(actualAnchor ?? "")) this.scaleReset(text);
24518
+ if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && [
24519
+ "top-left",
24520
+ "top-right",
24521
+ "bottom-left",
24522
+ "bottom-right"
24523
+ ].includes(actualAnchor ?? "")) text.setAttrs({
24524
+ width: Math.ceil(text.width() * text.scaleX()),
24525
+ height: Math.ceil(text.height() * text.scaleY()),
24526
+ fontSize: text.fontSize() * text.scaleY(),
24527
+ scaleX: 1,
24528
+ scaleY: 1
24529
+ });
24530
+ if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && !smartFixedWidth && !definedSmartWidth) {
24531
+ text.setAttr("smartFixedWidth", true);
24532
+ smartFixedWidth = true;
24533
+ definedSmartWidth = true;
24534
+ text.width(Math.ceil(text.width() * text.scaleX()));
24535
+ text.scaleX(1);
24536
+ text.height(void 0);
24537
+ text.getLayer()?.batchDraw();
24538
+ text.height(Math.ceil(text.height()));
24539
+ }
24540
+ if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && smartFixedWidth && !definedSmartWidth) {
24541
+ text.width(Math.ceil(text.width() * text.scaleX()));
24542
+ text.scaleX(1);
24543
+ }
24544
+ this.instance.updateNode(this.serialize(text));
24545
+ };
24546
+ text.on("transformend", () => {
24547
+ handleTransformEnd();
24459
24548
  });
24460
- text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
24461
24549
  this.instance.addEventListener("onNodeRenderedAdded", (node) => {
24462
24550
  if (node.id() === text.id() && node.getParent() !== text.getParent()) text.getAttr("cancelEditMode")?.();
24463
24551
  });
@@ -24493,10 +24581,13 @@ var WeaveTextNode = class extends WeaveNode {
24493
24581
  width = textAreaWidth;
24494
24582
  height = textAreaHeight;
24495
24583
  }
24496
- if (nextProps.layout === TEXT_LAYOUT.AUTO_HEIGHT) {
24497
- const { height: textAreaHeight } = this.textRenderedSize(nextProps.text, nodeInstance);
24498
- height = textAreaHeight;
24584
+ if (nextProps.layout === TEXT_LAYOUT.SMART && !nextProps.smartFixedWidth) {
24585
+ const { width: textAreaWidth } = this.textRenderedSize(nextProps.text, nodeInstance);
24586
+ width = textAreaWidth;
24587
+ height = void 0;
24499
24588
  }
24589
+ if (nextProps.layout === TEXT_LAYOUT.SMART && nextProps.smartFixedWidth) height = void 0;
24590
+ if (nextProps.layout === TEXT_LAYOUT.AUTO_HEIGHT) height = void 0;
24500
24591
  if (nextProps.layout === TEXT_LAYOUT.FIXED) updateNeeded = false;
24501
24592
  nodeInstance.setAttrs({
24502
24593
  width,
@@ -24522,6 +24613,7 @@ var WeaveTextNode = class extends WeaveNode {
24522
24613
  delete cleanedAttrs.cancelEditMode;
24523
24614
  delete cleanedAttrs.measureMultilineText;
24524
24615
  delete cleanedAttrs.overridesMouseControl;
24616
+ delete cleanedAttrs.shouldUpdateOnTransform;
24525
24617
  delete cleanedAttrs.dragBoundFunc;
24526
24618
  return {
24527
24619
  key: attrs.id ?? "",
@@ -24546,12 +24638,11 @@ var WeaveTextNode = class extends WeaveNode {
24546
24638
  };
24547
24639
  textAreaDomResize(textNode) {
24548
24640
  if (!this.textArea || !this.textAreaContainer) return;
24549
- if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
24641
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
24550
24642
  const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
24551
- this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 2 + "px";
24643
+ this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 1 + "px";
24552
24644
  }
24553
- if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) this.textAreaContainer.style.height = "auto";
24554
- if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
24645
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) {
24555
24646
  this.textAreaContainer.style.height = "auto";
24556
24647
  this.textAreaContainer.style.height = this.textArea.scrollHeight + textNode.getAbsoluteScale().y + "px";
24557
24648
  }
@@ -24637,15 +24728,21 @@ var WeaveTextNode = class extends WeaveNode {
24637
24728
  this.textAreaContainer.style.position = "absolute";
24638
24729
  this.textAreaContainer.style.top = position.y * upscaleScale + "px";
24639
24730
  this.textAreaContainer.style.left = position.x * upscaleScale + "px";
24731
+ if (textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
24732
+ const rect = textNode.getClientRect({ relativeTo: stage });
24733
+ this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
24734
+ this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
24735
+ }
24640
24736
  if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
24641
24737
  const rect = textNode.getClientRect({ relativeTo: stage });
24642
- this.textAreaContainer.style.width = (rect.width + 1) * stage.scaleX() + "px";
24643
- this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
24738
+ this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
24739
+ this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
24644
24740
  }
24645
- if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
24741
+ if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && textNode.getAttrs().smartFixedWidth) {
24646
24742
  const rect = textNode.getClientRect({ relativeTo: stage });
24647
- this.textAreaContainer.style.width = (rect.width + 1) * stage.scaleX() + "px";
24648
- this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
24743
+ this.textAreaContainer.style.width = (rect.width + 10) * stage.scaleX() + "px";
24744
+ if (textNode.getAttrs().smartFixedWidth) this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
24745
+ this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
24649
24746
  }
24650
24747
  if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
24651
24748
  this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
@@ -24730,11 +24827,11 @@ var WeaveTextNode = class extends WeaveNode {
24730
24827
  }
24731
24828
  const updateTextNodeSize = () => {
24732
24829
  if (!this.textArea) return;
24733
- if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
24830
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
24734
24831
  const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
24735
24832
  textNode.width(textAreaWidth);
24736
24833
  }
24737
- if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) textNode.height(this.textArea.scrollHeight * (1 / textNode.getAbsoluteScale().x));
24834
+ if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) textNode.height(this.textArea.scrollHeight * (1 / textNode.getAbsoluteScale().x));
24738
24835
  };
24739
24836
  const handleKeyDown = (e) => {
24740
24837
  if (this.textArea && textNode && e.code === "Escape") {
@@ -24805,13 +24902,15 @@ var WeaveTextNode = class extends WeaveNode {
24805
24902
  }
24806
24903
  updateTextAreaDOM(textNode) {
24807
24904
  if (!this.textAreaContainer || !this.textArea) return;
24808
- const textPosition = textNode.getClientRect();
24905
+ const stage = this.instance.getStage();
24906
+ const upscaleScale = stage.getAttr("upscaleScale");
24907
+ const textPosition = textNode.absolutePosition();
24809
24908
  const position = {
24810
24909
  x: textPosition.x,
24811
24910
  y: textPosition.y
24812
24911
  };
24813
- this.textAreaContainer.style.top = position.y + "px";
24814
- this.textAreaContainer.style.left = position.x + "px";
24912
+ this.textAreaContainer.style.top = position.y * upscaleScale + "px";
24913
+ this.textAreaContainer.style.left = position.x * upscaleScale + "px";
24815
24914
  if (textNode.getAttrs().verticalAlign === "top") this.textAreaContainer.style.alignItems = "start";
24816
24915
  if (textNode.getAttrs().verticalAlign === "middle") this.textAreaContainer.style.alignItems = "center";
24817
24916
  if (textNode.getAttrs().verticalAlign === "bottom") this.textAreaContainer.style.alignItems = "end";
@@ -24880,6 +24979,12 @@ var WeaveTextNode = class extends WeaveNode {
24880
24979
  this.keyPressHandler = void 0;
24881
24980
  }
24882
24981
  }
24982
+ resetSmartLayout(textNode) {
24983
+ textNode.setAttr("smartFixedWidth", void 0);
24984
+ const { width: textAreaWidth } = this.textRenderedSize(textNode.text(), textNode);
24985
+ textNode.width(textAreaWidth);
24986
+ this.instance.updateNode(this.serialize(textNode));
24987
+ }
24883
24988
  };
24884
24989
 
24885
24990
  //#endregion
@@ -33112,6 +33217,15 @@ var WeaveBrushToolAction = class extends WeaveAction {
33112
33217
  }
33113
33218
  };
33114
33219
 
33220
+ //#endregion
33221
+ //#region src/actions/text-tool/constants.ts
33222
+ const TEXT_TOOL_ACTION_NAME = "textTool";
33223
+ const TEXT_TOOL_STATE = {
33224
+ ["IDLE"]: "idle",
33225
+ ["ADDING"]: "adding",
33226
+ ["FINISHED"]: "finished"
33227
+ };
33228
+
33115
33229
  //#endregion
33116
33230
  //#region src/actions/text-tool/text-tool.ts
33117
33231
  var WeaveTextToolAction = class extends WeaveAction {
@@ -33134,7 +33248,7 @@ var WeaveTextToolAction = class extends WeaveAction {
33134
33248
  initProps() {
33135
33249
  return {
33136
33250
  text: "",
33137
- layout: TEXT_LAYOUT.AUTO_ALL,
33251
+ layout: TEXT_LAYOUT.SMART,
33138
33252
  fontSize: 20,
33139
33253
  fontFamily: "Arial, sans-serif",
33140
33254
  fill: "#000000",
@@ -36108,6 +36222,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
36108
36222
  gridDotMaxDotsPerAxis: WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS,
36109
36223
  ...config
36110
36224
  };
36225
+ this.forceStageChange = false;
36111
36226
  }
36112
36227
  getName() {
36113
36228
  return WEAVE_STAGE_GRID_PLUGIN_KEY;
@@ -36315,6 +36430,10 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
36315
36430
  gridLayer.add(originShape);
36316
36431
  }
36317
36432
  hasStageChanged() {
36433
+ if (this.forceStageChange) {
36434
+ this.forceStageChange = false;
36435
+ return true;
36436
+ }
36318
36437
  const stage = this.instance.getStage();
36319
36438
  const actualScaleX = stage.scaleX();
36320
36439
  const actualScaleY = stage.scaleY();
@@ -36357,6 +36476,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
36357
36476
  }
36358
36477
  setType(type) {
36359
36478
  this.config.type = type;
36479
+ this.forceStageChange = true;
36360
36480
  this.onRender();
36361
36481
  }
36362
36482
  };