@inditextech/weave-sdk 0.52.1 → 0.52.2

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
@@ -16244,6 +16244,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16244
16244
  "bottom-right"
16245
16245
  ];
16246
16246
  this.taps = 0;
16247
+ this.isSpaceKeyPressed = false;
16247
16248
  this.isDoubleTap = false;
16248
16249
  this.tapStart = {
16249
16250
  x: 0,
@@ -16574,11 +16575,15 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16574
16575
  this.selecting = false;
16575
16576
  const stage = this.instance.getStage();
16576
16577
  stage.container().addEventListener("keydown", (e) => {
16578
+ if (e.code === "Space") this.isSpaceKeyPressed = true;
16577
16579
  if ((e.key === "Backspace" || e.key === "Delete") && Object.keys(window.weaveTextEditing).length === 0) {
16578
16580
  this.removeSelectedNodes();
16579
16581
  return;
16580
16582
  }
16581
16583
  });
16584
+ stage.container().addEventListener("keyup", (e) => {
16585
+ if (e.key === "Space") this.isSpaceKeyPressed = false;
16586
+ });
16582
16587
  stage.on("pointerdown", (e) => {
16583
16588
  this.setTapStart(e);
16584
16589
  this.pointers[e.evt.pointerId] = e.evt;
@@ -16631,6 +16636,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16631
16636
  this.selecting = false;
16632
16637
  return;
16633
16638
  }
16639
+ if (this.isSpaceKeyPressed) return;
16634
16640
  if (!this.selecting) return;
16635
16641
  const intStage = this.instance.getStage();
16636
16642
  x2 = intStage.getRelativePointerPosition()?.x ?? 0;
@@ -16673,7 +16679,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16673
16679
  y: 0,
16674
16680
  time: 0
16675
16681
  };
16676
- this.isDoubleTap = true;
16677
16682
  this.hideSelectorArea();
16678
16683
  this.handleClickOrTap(e);
16679
16684
  return;
@@ -16805,6 +16810,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16805
16810
  }
16806
16811
  if (typeof nodeTargeted.getAttrs().isContainerPrincipal !== "undefined" && !nodeTargeted.getAttrs().isContainerPrincipal) return;
16807
16812
  if (this.isDoubleTap && !metaPressed) {
16813
+ this.isDoubleTap = false;
16808
16814
  nodeTargeted.dblClick();
16809
16815
  return;
16810
16816
  }
@@ -16968,6 +16974,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16968
16974
  catcher.style.zIndex = "-1";
16969
16975
  catcher.style.outline = "none";
16970
16976
  catcher.style.opacity = "0";
16977
+ catcher.onpaste = () => false;
16978
+ catcher.oncontextmenu = () => false;
16971
16979
  catcher.tabIndex = 0;
16972
16980
  const stageContainer = stage.container();
16973
16981
  if (stageContainer?.parentNode) stageContainer.parentNode.appendChild(catcher);
@@ -16992,47 +17000,47 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16992
17000
  if (!this.enabled) return;
16993
17001
  }
16994
17002
  });
16995
- if (catcher) catcher.addEventListener("paste", async (e) => {
16996
- e.preventDefault();
16997
- const dataList = e.clipboardData?.items;
16998
- let items = void 0;
16999
- if (!items) {
17000
- if (this.isClipboardAPIAvailable()) items = await navigator.clipboard.read();
17001
- }
17002
- if (!items && !dataList) return;
17003
- let hasWeaveData = false;
17004
- if (this.isClipboardAPIAvailable()) {
17005
- const readText = await navigator.clipboard.readText();
17006
- const continueToPaste = this.isWeaveData(readText);
17007
- if (continueToPaste) hasWeaveData = true;
17008
- } else for (const item of dataList ?? []) if (item.type === "text/plain") {
17009
- const text = await this.getTextFromClipboard(item);
17010
- if (this.isWeaveData(text)) {
17011
- hasWeaveData = true;
17012
- this.toPaste = JSON.parse(text);
17003
+ if (catcher) {
17004
+ document.addEventListener("paste", (e) => {
17005
+ e.preventDefault();
17006
+ const dataList = e.clipboardData?.items;
17007
+ if (!dataList) return;
17008
+ if (dataList?.length > 0) {
17009
+ const container = stage.container();
17010
+ const scale = stage.scale();
17011
+ const position = stage.position();
17012
+ const width = container.clientWidth;
17013
+ const height = container.clientHeight;
17014
+ const centerX = (width / 2 - position.x) / scale.x;
17015
+ const centerY = (height / 2 - position.y) / scale.y;
17016
+ const pastePosition = {
17017
+ x: centerX,
17018
+ y: centerY
17019
+ };
17020
+ this.instance.emitEvent("onPasteExternal", {
17021
+ positionCalculated: true,
17022
+ position: pastePosition,
17023
+ dataList,
17024
+ items: void 0
17025
+ });
17013
17026
  }
17014
- }
17015
- if (hasWeaveData) {
17016
- this.handlePaste();
17017
- return;
17018
- }
17019
- const container = stage.container();
17020
- const scale = stage.scale();
17021
- const position = stage.position();
17022
- const width = container.clientWidth;
17023
- const height = container.clientHeight;
17024
- const centerX = (width / 2 - position.x) / scale.x;
17025
- const centerY = (height / 2 - position.y) / scale.y;
17026
- const pastePosition = {
17027
- x: centerX,
17028
- y: centerY
17029
- };
17030
- this.instance.emitEvent("onPasteExternal", {
17031
- position: pastePosition,
17032
- dataList,
17033
- items
17034
17027
  });
17035
- });
17028
+ catcher.addEventListener("paste", async (e) => {
17029
+ e.preventDefault();
17030
+ let items = void 0;
17031
+ let hasWeaveData = false;
17032
+ if (!items) {
17033
+ if (this.isClipboardAPIAvailable()) items = await navigator.clipboard.read();
17034
+ }
17035
+ if (!items || items.length === 0) return;
17036
+ if (this.isClipboardAPIAvailable()) {
17037
+ const readText = await navigator.clipboard.readText();
17038
+ const continueToPaste = this.isWeaveData(readText);
17039
+ if (continueToPaste) hasWeaveData = true;
17040
+ }
17041
+ if (hasWeaveData) this.handlePaste();
17042
+ });
17043
+ }
17036
17044
  }
17037
17045
  isWeaveData(text) {
17038
17046
  try {
@@ -17047,13 +17055,6 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17047
17055
  return false;
17048
17056
  }
17049
17057
  }
17050
- getTextFromClipboard(item) {
17051
- return new Promise((resolve) => {
17052
- item.getAsString((text) => {
17053
- resolve(text);
17054
- });
17055
- });
17056
- }
17057
17058
  mapToPasteNodes() {
17058
17059
  const nodesSelectionPlugin = this.getNodesSelectionPlugin();
17059
17060
  const selectedNodes = nodesSelectionPlugin?.getSelectedNodes();
@@ -17184,8 +17185,10 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17184
17185
  }
17185
17186
  try {
17186
17187
  const items = await navigator.clipboard.read();
17187
- let pastePosition = position;
17188
+ let positionCalculated = false;
17189
+ let pastePosition = relativePosition;
17188
17190
  if (typeof pastePosition === "undefined") {
17191
+ positionCalculated = true;
17189
17192
  const container = stage.container();
17190
17193
  const scale = stage.scale();
17191
17194
  const position$1 = stage.position();
@@ -17199,6 +17202,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17199
17202
  };
17200
17203
  }
17201
17204
  this.instance.emitEvent("onPasteExternal", {
17205
+ positionCalculated,
17202
17206
  position: pastePosition,
17203
17207
  items
17204
17208
  });
@@ -19165,7 +19169,7 @@ var WeaveRegisterManager = class {
19165
19169
 
19166
19170
  //#endregion
19167
19171
  //#region package.json
19168
- var version = "0.52.1";
19172
+ var version = "0.52.2";
19169
19173
 
19170
19174
  //#endregion
19171
19175
  //#region src/managers/setup.ts
@@ -19747,6 +19751,15 @@ var Weave = class {
19747
19751
  isEmpty() {
19748
19752
  return this.getElementsTree().length === 0;
19749
19753
  }
19754
+ getNodeContainerId(node) {
19755
+ const stage = this.getStage();
19756
+ let nodeContainer = node.getParent()?.getAttrs().id ?? "";
19757
+ if (typeof node.getParent()?.getAttrs().nodeId !== "undefined") {
19758
+ const realContainer = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
19759
+ if (realContainer) nodeContainer = realContainer.getAttrs().id ?? "";
19760
+ }
19761
+ return nodeContainer;
19762
+ }
19750
19763
  moveUp(node) {
19751
19764
  this.zIndexManager.moveUp(node);
19752
19765
  }
@@ -20171,7 +20184,7 @@ var WeaveEllipseNode = class extends WeaveNode {
20171
20184
  ellipse.allowedAnchors = () => {
20172
20185
  const stage = this.instance.getStage();
20173
20186
  const actualEllipse = stage.findOne(`#${ellipse.id()}`);
20174
- if (actualEllipse?.getAttrs().keepAspectRatio) return [
20187
+ if (actualEllipse?.getAttrs()?.keepAspectRatio) return [
20175
20188
  "top-left",
20176
20189
  "top-right",
20177
20190
  "bottom-left",
@@ -20978,6 +20991,7 @@ var WeaveImageToolAction = class extends WeaveAction {
20978
20991
  this.imageId = null;
20979
20992
  this.forceMainContainer = false;
20980
20993
  this.container = void 0;
20994
+ this.tempImageNode = null;
20981
20995
  this.imageURL = null;
20982
20996
  this.clickPoint = null;
20983
20997
  this.setState(IMAGE_TOOL_STATE.IDLE);
@@ -20993,19 +21007,19 @@ var WeaveImageCrop = class WeaveImageCrop {
20993
21007
  this.image = image;
20994
21008
  this.internalImage = internalImage;
20995
21009
  this.cropGroup = clipGroup;
21010
+ this.cropping = false;
20996
21011
  this.onClose = () => {};
20997
21012
  this.handleHide = this.hide.bind(this);
20998
21013
  }
20999
21014
  show(onClose) {
21000
21015
  this.onClose = onClose;
21001
- const nodeSnappingPlugin = this.instance.getPlugin("nodesSnapping");
21002
- if (nodeSnappingPlugin) this.instance.disablePlugin("nodesSnapping");
21003
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
21004
- if (selectionPlugin) {
21005
- this.instance.disablePlugin("nodesSelection");
21006
- selectionPlugin.getTransformer().nodes([]);
21007
- selectionPlugin.getTransformer().hide();
21008
- }
21016
+ this.cropping = true;
21017
+ const nodeEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
21018
+ if (nodeEdgeSnappingPlugin) nodeEdgeSnappingPlugin.disable();
21019
+ const nodeDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
21020
+ if (nodeDistanceSnappingPlugin) nodeDistanceSnappingPlugin.disable();
21021
+ const nodesSelectionPlugin = this.getNodesSelectionPlugin();
21022
+ if (nodesSelectionPlugin) nodesSelectionPlugin.disable();
21009
21023
  this.image.setAttrs({ cropping: true });
21010
21024
  const imageAttrs = this.image.getAttrs();
21011
21025
  this.internalImage.hide();
@@ -21125,6 +21139,7 @@ var WeaveImageCrop = class WeaveImageCrop {
21125
21139
  this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
21126
21140
  };
21127
21141
  this.instance.getStage().on("pointerdown", (e) => {
21142
+ if (!this.cropping) return;
21128
21143
  const isStage = e.target instanceof konva.default.Stage;
21129
21144
  const isContainerEmptyArea = typeof e.target.getAttrs().isContainerPrincipal !== "undefined" && !e.target.getAttrs().isContainerPrincipal;
21130
21145
  if (isStage || isContainerEmptyArea) this.cancel();
@@ -21164,6 +21179,7 @@ var WeaveImageCrop = class WeaveImageCrop {
21164
21179
  }
21165
21180
  hide(e) {
21166
21181
  if (!["Enter", "Escape"].includes(e.key)) return;
21182
+ this.cropping = false;
21167
21183
  this.image.setAttrs({ cropping: false });
21168
21184
  if (e.key === "Enter") this.handleClipEnd();
21169
21185
  const stage = this.instance.getStage();
@@ -21173,20 +21189,13 @@ var WeaveImageCrop = class WeaveImageCrop {
21173
21189
  this.instance.getStage().container().removeEventListener("keydown", this.handleHide);
21174
21190
  this.cropGroup.destroyChildren();
21175
21191
  this.cropGroup.hide();
21176
- const nodeSnappingPlugin = this.instance.getPlugin("nodesSnapping");
21177
- if (nodeSnappingPlugin) this.instance.enablePlugin("nodesSnapping");
21192
+ const nodesEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
21193
+ if (nodesEdgeSnappingPlugin) nodesEdgeSnappingPlugin.enable();
21194
+ const nodesDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
21195
+ if (nodesDistanceSnappingPlugin) nodesDistanceSnappingPlugin.enable();
21178
21196
  this.internalImage.show();
21179
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
21180
- if (selectionPlugin) {
21181
- this.instance.enablePlugin("nodesSelection");
21182
- const selectionTransformer = selectionPlugin.getTransformer();
21183
- selectionTransformer.nodes([this.image]);
21184
- selectionTransformer.show();
21185
- setTimeout(() => {
21186
- selectionPlugin.triggerSelectedNodesEvent();
21187
- selectionTransformer.forceUpdate();
21188
- }, 0);
21189
- }
21197
+ const nodesSelectionPlugin = this.getNodesSelectionPlugin();
21198
+ if (nodesSelectionPlugin) nodesSelectionPlugin.enable();
21190
21199
  stage.mode(WEAVE_STAGE_DEFAULT_MODE);
21191
21200
  this.instance.emitEvent("onImageCropEnd", { instance: this.image });
21192
21201
  }
@@ -21324,6 +21333,18 @@ var WeaveImageCrop = class WeaveImageCrop {
21324
21333
  y: a.y + t * ab.y
21325
21334
  };
21326
21335
  }
21336
+ getNodesEdgeSnappingPlugin() {
21337
+ const snappingEdgesPlugin = this.instance.getPlugin(WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY);
21338
+ return snappingEdgesPlugin;
21339
+ }
21340
+ getNodesDistanceSnappingPlugin() {
21341
+ const snappingDistancePlugin = this.instance.getPlugin(WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY);
21342
+ return snappingDistancePlugin;
21343
+ }
21344
+ getNodesSelectionPlugin() {
21345
+ const nodesSelectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
21346
+ return nodesSelectionPlugin;
21347
+ }
21327
21348
  };
21328
21349
 
21329
21350
  //#endregion
@@ -21587,12 +21608,6 @@ var WeaveImageNode = class extends WeaveNode {
21587
21608
  });
21588
21609
  this.updateImageCrop(nextProps);
21589
21610
  }
21590
- try {
21591
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
21592
- if (selectionPlugin) selectionPlugin.getTransformer().forceUpdate();
21593
- } catch (error) {
21594
- console.error("Error updating transformer", error);
21595
- }
21596
21611
  }
21597
21612
  loadImage(params, image) {
21598
21613
  const imageProps = params;
@@ -25580,6 +25595,10 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25580
25595
  window.addEventListener("keydown", (e) => {
25581
25596
  if (e.ctrlKey || e.metaKey) this.isCtrlOrMetaPressed = true;
25582
25597
  if (e.code === "Space") {
25598
+ this.getContextMenuPlugin()?.disable();
25599
+ this.getNodesSelectionPlugin()?.disable();
25600
+ this.getNodesEdgeSnappingPlugin()?.disable();
25601
+ this.getNodesDistanceSnappingPlugin()?.disable();
25583
25602
  this.isSpaceKeyPressed = true;
25584
25603
  this.enableMove();
25585
25604
  }
@@ -25587,6 +25606,10 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25587
25606
  window.addEventListener("keyup", (e) => {
25588
25607
  if (e.key === "Meta" || e.key === "Control") this.isCtrlOrMetaPressed = false;
25589
25608
  if (e.code === "Space") {
25609
+ this.getContextMenuPlugin()?.enable();
25610
+ this.getNodesSelectionPlugin()?.enable();
25611
+ this.getNodesEdgeSnappingPlugin()?.enable();
25612
+ this.getNodesDistanceSnappingPlugin()?.enable();
25590
25613
  this.isSpaceKeyPressed = false;
25591
25614
  this.disableMove();
25592
25615
  }
@@ -25601,14 +25624,9 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25601
25624
  if (this.pointers.size > 1) return;
25602
25625
  const activeAction = this.instance.getActiveAction();
25603
25626
  let enableMove = false;
25604
- if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === MOVE_TOOL_ACTION_NAME) {
25605
- this.moveToolActive = true;
25606
- enableMove = true;
25607
- }
25608
- if (!enableMove && e.evt.pointerType === "mouse" && e.evt.buttons === 4) {
25609
- this.isMouseMiddleButtonPressed = true;
25610
- enableMove = true;
25611
- }
25627
+ if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
25628
+ if (!enableMove && e.evt.pointerType === "mouse" && e.evt.buttons === 4) this.isMouseMiddleButtonPressed = true;
25629
+ if (this.enabled && (this.isSpaceKeyPressed || this.moveToolActive || this.isMouseMiddleButtonPressed)) enableMove = true;
25612
25630
  if (enableMove) {
25613
25631
  isDragging = true;
25614
25632
  lastPos = stage.getPointerPosition();
@@ -25625,8 +25643,8 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25625
25643
  y: e.evt.clientY
25626
25644
  });
25627
25645
  if (this.pointers.size > 1) return;
25646
+ if (this.isSpaceKeyPressed) stage.container().style.cursor = "grabbing";
25628
25647
  if (!isDragging) return;
25629
- if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
25630
25648
  this.getContextMenuPlugin()?.cancelLongPressTimer();
25631
25649
  const pos = stage.getPointerPosition();
25632
25650
  if (pos && lastPos) {
@@ -25685,9 +25703,21 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25685
25703
  return zoomPlugin;
25686
25704
  }
25687
25705
  getContextMenuPlugin() {
25688
- const contextMenuPlugin = this.instance.getPlugin("contextMenu");
25706
+ const contextMenuPlugin = this.instance.getPlugin(WEAVE_CONTEXT_MENU_PLUGIN_KEY);
25689
25707
  return contextMenuPlugin;
25690
25708
  }
25709
+ getNodesSelectionPlugin() {
25710
+ const selectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
25711
+ return selectionPlugin;
25712
+ }
25713
+ getNodesEdgeSnappingPlugin() {
25714
+ const snappingPlugin = this.instance.getPlugin(WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY);
25715
+ return snappingPlugin;
25716
+ }
25717
+ getNodesDistanceSnappingPlugin() {
25718
+ const snappingPlugin = this.instance.getPlugin(WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY);
25719
+ return snappingPlugin;
25720
+ }
25691
25721
  enable() {
25692
25722
  this.enabled = true;
25693
25723
  }
package/dist/sdk.d.cts CHANGED
@@ -517,6 +517,7 @@ declare class WeaveNodesSelectionPlugin extends WeavePlugin {
517
517
  private didMove;
518
518
  private initialized;
519
519
  private readonly selectionOriginalConfig;
520
+ private isSpaceKeyPressed;
520
521
  protected taps: number;
521
522
  protected isDoubleTap: boolean;
522
523
  protected tapStart: {
@@ -781,6 +782,7 @@ declare class Weave {
781
782
  moveNode(node: WeaveStateElement, position: WeavePosition): void;
782
783
  getElementsTree(): WeaveStateElement[];
783
784
  isEmpty(): boolean;
785
+ getNodeContainerId(node: WeaveElementInstance | Konva.Node): string;
784
786
  moveUp(node: WeaveElementInstance): void;
785
787
  moveDown(node: WeaveElementInstance): void;
786
788
  sendToBack(nodes: WeaveElementInstance | WeaveElementInstance[]): void;
@@ -2391,6 +2393,9 @@ declare class WeaveStagePanningPlugin extends WeavePlugin {
2391
2393
  } | null;
2392
2394
  getZoomPlugin(): WeaveStageZoomPlugin | undefined;
2393
2395
  getContextMenuPlugin(): WeaveContextMenuPlugin | undefined;
2396
+ getNodesSelectionPlugin(): WeaveNodesSelectionPlugin | undefined;
2397
+ getNodesEdgeSnappingPlugin(): WeaveNodesEdgeSnappingPlugin | undefined;
2398
+ getNodesDistanceSnappingPlugin(): WeaveNodesDistanceSnappingPlugin | undefined;
2394
2399
  enable(): void;
2395
2400
  disable(): void;
2396
2401
  }
@@ -2616,6 +2621,7 @@ type WeaveCopyPasteNodesPluginOnPasteEvent = Error | undefined;
2616
2621
  type WeaveCopyPasteNodesPluginOnPasteExternalEvent = {
2617
2622
  items?: ClipboardItems;
2618
2623
  dataList?: DataTransferItemList;
2624
+ positionCalculated: boolean;
2619
2625
  position: Vector2d;
2620
2626
  };
2621
2627
  type WeaveCopyPastePasteModeKeys = keyof typeof WEAVE_COPY_PASTE_PASTE_MODES;
@@ -2652,7 +2658,6 @@ declare class WeaveCopyPasteNodesPlugin extends WeavePlugin {
2652
2658
  private focusPasteCatcher;
2653
2659
  initEvents(): void;
2654
2660
  private isWeaveData;
2655
- private getTextFromClipboard;
2656
2661
  private mapToPasteNodes;
2657
2662
  private setState;
2658
2663
  private recursivelyUpdateKeys;