@inditextech/weave-sdk 5.1.5 → 5.2.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/types.js CHANGED
@@ -36,13 +36,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
36
  }) : target, mod));
37
37
 
38
38
  //#endregion
39
- //#region ../../node_modules/emittery/maps.js
39
+ //#region node_modules/emittery/maps.js
40
40
  const anyMap = new WeakMap();
41
41
  const eventsMap = new WeakMap();
42
42
  const producersMap = new WeakMap();
43
43
 
44
44
  //#endregion
45
- //#region ../../node_modules/emittery/index.js
45
+ //#region node_modules/emittery/index.js
46
46
  const anyProducer = Symbol("anyProducer");
47
47
  const resolvedPromise = Promise.resolve();
48
48
  const listenerAdded = Symbol("listenerAdded");
@@ -4432,23 +4432,12 @@ var TransformerController = class {
4432
4432
  if (this.tr.nodes().length === 1 && this.tr.nodes()[0].getAttrs().isContainerPrincipal) {
4433
4433
  const pos = stage.getPointerPosition();
4434
4434
  if (!pos) return;
4435
+ const back = this.tr.findOne(".back");
4436
+ if (!back) return;
4435
4437
  const shapeUnder = stage.getIntersection(pos);
4436
- if (!shapeUnder) {
4437
- this.tr.setAttrs({ listening: true });
4438
- this.tr.forceUpdate();
4439
- }
4440
- if (shapeUnder && this.tr.getChildren().includes(shapeUnder) && shapeUnder.name() === "back") {
4441
- this.tr.setAttrs({ listening: false });
4442
- this.tr.forceUpdate();
4443
- }
4444
- if (shapeUnder && this.tr.nodes()[0].getChildren().includes(shapeUnder)) {
4445
- this.tr.setAttrs({ listening: false });
4446
- this.tr.forceUpdate();
4447
- }
4448
- if (shapeUnder && !this.tr.getChildren().includes(shapeUnder) && this.tr.nodes()[0].getChildren().includes(shapeUnder)) {
4449
- this.tr.setAttrs({ listening: true });
4450
- this.tr.forceUpdate();
4451
- }
4438
+ if (shapeUnder === back) back.listening(false);
4439
+ else back.listening(true);
4440
+ this.tr.forceUpdate();
4452
4441
  }
4453
4442
  };
4454
4443
  stage.on("pointermove", (0, import_throttle.default)(handlePointerMoveInit, DEFAULT_THROTTLE_MS));
@@ -5029,7 +5018,7 @@ function handlePointerDown(ctx, e) {
5029
5018
  const stage = ctx.getWeaveInstance().getStage();
5030
5019
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
5031
5020
  const selectedGroup = getTargetedNode(ctx.getWeaveInstance());
5032
- if (selectedGroup?.getParent() instanceof Konva.Transformer) {
5021
+ if (selectedGroup?.getParent() instanceof Konva.Transformer && selectedGroup?.hasName("back")) {
5033
5022
  ctx.setAreaSelecting(false);
5034
5023
  ctx.getEdgePanning().stop();
5035
5024
  ctx.getAreaSelector().hide();
@@ -8598,6 +8587,20 @@ var WeaveGroupsManager = class {
8598
8587
  parentId
8599
8588
  };
8600
8589
  }
8590
+ selectRenderedNode(nodeId, triggerSelectionEvent = false) {
8591
+ this.instance.addOnceEventListener("onStateChange", () => {
8592
+ this.getNodesMultiSelectionFeedbackPlugin()?.cleanupSelectedHalos();
8593
+ const node = this.instance.getStage().findOne(`#${nodeId}`);
8594
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
8595
+ if (node && selectionPlugin) {
8596
+ const tr = selectionPlugin.getTransformer();
8597
+ selectionPlugin.setSelectedNodes([node]);
8598
+ tr.show();
8599
+ tr.forceUpdate();
8600
+ if (triggerSelectionEvent) selectionPlugin.triggerSelectedNodesEvent();
8601
+ }
8602
+ });
8603
+ }
8601
8604
  group(nodes) {
8602
8605
  this.instance.stateTransactional(() => {
8603
8606
  this.logger.debug({ nodes }, "Grouping nodes");
@@ -8688,17 +8691,7 @@ var WeaveGroupsManager = class {
8688
8691
  groupNode.y(0);
8689
8692
  this.instance.updateNodeNT(groupHandler.serialize(groupNode));
8690
8693
  }
8691
- setTimeout(() => {
8692
- this.getNodesMultiSelectionFeedbackPlugin()?.cleanupSelectedHalos();
8693
- const groupNode$1 = stage.findOne(`#${groupId}`);
8694
- const selectionPlugin$1 = this.instance.getPlugin("nodesSelection");
8695
- if (groupNode$1 && selectionPlugin$1) {
8696
- const tr = selectionPlugin$1.getTransformer();
8697
- selectionPlugin$1.setSelectedNodes([groupNode$1]);
8698
- tr.show();
8699
- tr.forceUpdate();
8700
- }
8701
- }, 10);
8694
+ this.selectRenderedNode(groupId);
8702
8695
  });
8703
8696
  }
8704
8697
  unGroup(group) {
@@ -8710,6 +8703,11 @@ var WeaveGroupsManager = class {
8710
8703
  this.logger.debug({ group }, "Group instance doesn't exists, cannot un-group");
8711
8704
  return;
8712
8705
  }
8706
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
8707
+ if (selectionPlugin) {
8708
+ const tr = selectionPlugin.getTransformer();
8709
+ tr.hide();
8710
+ }
8713
8711
  let nodeId = void 0;
8714
8712
  let newLayer = this.instance.getMainLayer();
8715
8713
  if (konvaGroup.getParent() && konvaGroup.getParent() instanceof Konva.Group && konvaGroup.getParent()?.getAttrs().nodeId) {
@@ -8762,6 +8760,7 @@ var WeaveGroupsManager = class {
8762
8760
  node.key = newNodeId;
8763
8761
  node.props.id = newNodeId;
8764
8762
  for (const prop of Object.keys(node.props)) if (typeof node.props[prop] === "string") node.props[prop] = node.props[prop].replace(oldId, newNodeId);
8763
+ newChildId = newNodeId;
8765
8764
  this.instance.addNodeNT(node, nodeId ?? newLayer.getAttrs().id);
8766
8765
  }
8767
8766
  child.destroy();
@@ -8771,12 +8770,7 @@ var WeaveGroupsManager = class {
8771
8770
  const groupNode = groupHandler.serialize(konvaGroup);
8772
8771
  this.instance.removeNodeNT(groupNode, { emitUserChangeEvent: false });
8773
8772
  }
8774
- setTimeout(() => {
8775
- this.getNodesMultiSelectionFeedbackPlugin()?.cleanupSelectedHalos();
8776
- const firstElement = newLayer.findOne(`#${newChildId}`);
8777
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
8778
- if (firstElement && selectionPlugin) selectionPlugin.setSelectedNodes([firstElement]);
8779
- }, 0);
8773
+ if (newChildId) this.selectRenderedNode(newChildId, true);
8780
8774
  });
8781
8775
  }
8782
8776
  extractTransformFromMatrix(m) {
@@ -9782,7 +9776,7 @@ var WeaveRegisterManager = class {
9782
9776
 
9783
9777
  //#endregion
9784
9778
  //#region package.json
9785
- var version = "5.1.5";
9779
+ var version = "5.2.1";
9786
9780
 
9787
9781
  //#endregion
9788
9782
  //#region src/managers/setup.ts
@@ -15716,7 +15710,9 @@ var WeaveImageNode = class extends WeaveNode {
15716
15710
  transformer.hide();
15717
15711
  utilityLayer?.destroyChildren();
15718
15712
  this.renderCropMode(utilityLayer, image);
15719
- utilityLayer?.show();
15713
+ utilityLayer.show();
15714
+ utilityLayer.draw();
15715
+ this.updateCropCursorForCurrentPointer();
15720
15716
  });
15721
15717
  image.on("onCmdCtrlReleased", () => {
15722
15718
  const utilityLayer = this.instance.getUtilityLayer();
@@ -15796,6 +15792,24 @@ var WeaveImageNode = class extends WeaveNode {
15796
15792
  y: 1 / stageScale
15797
15793
  });
15798
15794
  }
15795
+ getCropAnchorCursor(position) {
15796
+ if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_LEFT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_RIGHT) return "nesw-resize";
15797
+ if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_LEFT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_RIGHT) return "nwse-resize";
15798
+ if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.MIDDLE_RIGHT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.MIDDLE_LEFT) return "ew-resize";
15799
+ if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_CENTER || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_CENTER) return "ns-resize";
15800
+ return void 0;
15801
+ }
15802
+ updateCropCursorForCurrentPointer() {
15803
+ const stage = this.instance.getStage();
15804
+ const pointerPosition = stage.getPointerPosition?.();
15805
+ if (!pointerPosition) return;
15806
+ const intersection = stage.getIntersection?.(pointerPosition);
15807
+ if (!intersection) return;
15808
+ const position = intersection.getAttr("cropAnchorPosition");
15809
+ if (!position) return;
15810
+ const cursor = this.getCropAnchorCursor(position);
15811
+ if (cursor) stage.container().style.cursor = cursor;
15812
+ }
15799
15813
  renderCropAnchor(position, node, layer, onClick) {
15800
15814
  const transform = node.getAbsoluteTransform().copy();
15801
15815
  const stage = this.instance.getStage();
@@ -15847,6 +15861,7 @@ var WeaveImageNode = class extends WeaveNode {
15847
15861
  name: "cropMode",
15848
15862
  rotation: node.rotation()
15849
15863
  });
15864
+ anchor.setAttr("cropAnchorPosition", position);
15850
15865
  this.config.cropMode.selection.anchorStyleFunc(anchor, position);
15851
15866
  layer.add(anchor);
15852
15867
  anchor.scale({
@@ -15869,10 +15884,8 @@ var WeaveImageNode = class extends WeaveNode {
15869
15884
  if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.MIDDLE_LEFT) anchor.setAbsolutePosition(absoluteCorners[6]);
15870
15885
  if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_CENTER) anchor.setAbsolutePosition(absoluteCorners[7]);
15871
15886
  anchor.on("pointerover", () => {
15872
- if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_LEFT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_RIGHT) this.instance.getStage().container().style.cursor = "nesw-resize";
15873
- if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_LEFT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_RIGHT) this.instance.getStage().container().style.cursor = "nwse-resize";
15874
- if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.MIDDLE_RIGHT || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.MIDDLE_LEFT) this.instance.getStage().container().style.cursor = "ew-resize";
15875
- if (position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.TOP_CENTER || position === WEAVE_IMAGE_CROP_ANCHOR_POSITION.BOTTOM_CENTER) this.instance.getStage().container().style.cursor = "ns-resize";
15887
+ const cursor = this.getCropAnchorCursor(position);
15888
+ if (cursor) this.instance.getStage().container().style.cursor = cursor;
15876
15889
  });
15877
15890
  anchor.on("pointerdown", () => {
15878
15891
  onClick();
@@ -30942,6 +30955,7 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
30942
30955
  triggerContextMenu(eventTarget, target) {
30943
30956
  const stage = this.instance.getStage();
30944
30957
  const selectionPlugin = this.getSelectionPlugin();
30958
+ const selectedNodes = selectionPlugin?.getSelectedNodes() ?? [];
30945
30959
  let nodes = [];
30946
30960
  if (target && target !== stage) {
30947
30961
  const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
@@ -30958,6 +30972,14 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
30958
30972
  node: nodeHandler?.serialize(node)
30959
30973
  };
30960
30974
  });
30975
+ const targetIsPartOfMultiSelection = target !== void 0 && selectedNodes.length > 1 && selectedNodes.some((selectedNode) => selectedNode.getAttrs().id === target.getAttrs().id);
30976
+ if (targetIsPartOfMultiSelection) nodes = selectedNodes.map((node) => {
30977
+ const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
30978
+ return {
30979
+ instance: node,
30980
+ node: nodeHandler?.serialize(node)
30981
+ };
30982
+ });
30961
30983
  if (this.contextMenuVisible) this.closeContextMenu();
30962
30984
  let allNodesMutexUnlocked = true;
30963
30985
  let allNodesUnlocked = true;
@@ -30975,7 +30997,7 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
30975
30997
  }
30976
30998
  }
30977
30999
  if (!allNodesMutexUnlocked || !allNodesUnlocked) return;
30978
- if (selectionPlugin && !(eventTarget.getParent() instanceof Konva.Transformer && selectionPlugin.getSelectedNodes().length > 0)) {
31000
+ if (selectionPlugin && !(eventTarget.getParent() instanceof Konva.Transformer && selectedNodes.length > 0) && !targetIsPartOfMultiSelection) {
30979
31001
  selectionPlugin.setSelectedNodes([...nodes.map((node) => node.instance)]);
30980
31002
  selectionPlugin.getHoverTransformer().nodes([]);
30981
31003
  }