@inditextech/weave-sdk 0.19.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.cjs CHANGED
@@ -15802,43 +15802,70 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15802
15802
  constructor(params) {
15803
15803
  super();
15804
15804
  const { config } = params ?? {};
15805
- this.config = { transformer: {
15806
- rotationSnaps: [
15807
- 0,
15808
- 45,
15809
- 90,
15810
- 135,
15811
- 180,
15812
- 225,
15813
- 270,
15814
- 315,
15815
- 360
15816
- ],
15817
- rotationSnapTolerance: 3,
15818
- ignoreStroke: true,
15819
- flipEnabled: false,
15820
- keepRatio: false,
15821
- useSingleNodeRotation: true,
15822
- shouldOverdrawWholeArea: true,
15823
- anchorStyleFunc: (anchor) => {
15824
- anchor.stroke("#27272aff");
15825
- anchor.cornerRadius(12);
15826
- if (anchor.hasName("top-center") || anchor.hasName("bottom-center")) {
15827
- anchor.height(8);
15828
- anchor.offsetY(4);
15829
- anchor.width(32);
15830
- anchor.offsetX(16);
15831
- }
15832
- if (anchor.hasName("middle-left") || anchor.hasName("middle-right")) {
15833
- anchor.height(32);
15834
- anchor.offsetY(16);
15835
- anchor.width(8);
15836
- anchor.offsetX(4);
15837
- }
15805
+ this.config = {
15806
+ transformer: {
15807
+ rotationSnaps: [
15808
+ 0,
15809
+ 45,
15810
+ 90,
15811
+ 135,
15812
+ 180,
15813
+ 225,
15814
+ 270,
15815
+ 315,
15816
+ 360
15817
+ ],
15818
+ rotationSnapTolerance: 3,
15819
+ ignoreStroke: true,
15820
+ flipEnabled: false,
15821
+ keepRatio: false,
15822
+ useSingleNodeRotation: true,
15823
+ shouldOverdrawWholeArea: true,
15824
+ enabledAnchors: [
15825
+ "top-left",
15826
+ "top-center",
15827
+ "top-right",
15828
+ "middle-right",
15829
+ "middle-left",
15830
+ "bottom-left",
15831
+ "bottom-center",
15832
+ "bottom-right"
15833
+ ],
15834
+ anchorStyleFunc: (anchor) => {
15835
+ anchor.stroke("#27272aff");
15836
+ anchor.cornerRadius(12);
15837
+ if (anchor.hasName("top-center") || anchor.hasName("bottom-center")) {
15838
+ anchor.height(8);
15839
+ anchor.offsetY(4);
15840
+ anchor.width(32);
15841
+ anchor.offsetX(16);
15842
+ }
15843
+ if (anchor.hasName("middle-left") || anchor.hasName("middle-right")) {
15844
+ anchor.height(32);
15845
+ anchor.offsetY(16);
15846
+ anchor.width(8);
15847
+ anchor.offsetX(4);
15848
+ }
15849
+ },
15850
+ borderStroke: "#0074ffcc",
15851
+ ...config?.transformer
15838
15852
  },
15839
- borderStroke: "#1e40afff",
15840
- ...config?.transformer
15841
- } };
15853
+ transformations: {
15854
+ singleSelection: { enabled: true },
15855
+ multipleSelection: { enabled: false },
15856
+ ...config?.transformations
15857
+ }
15858
+ };
15859
+ this.defaultEnabledAnchors = this.config.transformer?.enabledAnchors ?? [
15860
+ "top-left",
15861
+ "top-center",
15862
+ "top-right",
15863
+ "middle-right",
15864
+ "middle-left",
15865
+ "bottom-left",
15866
+ "bottom-center",
15867
+ "bottom-right"
15868
+ ];
15842
15869
  this.active = false;
15843
15870
  this.cameFromSelectingMultiple = false;
15844
15871
  this.selecting = false;
@@ -15901,21 +15928,47 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15901
15928
  e.cancelBubble = true;
15902
15929
  }
15903
15930
  });
15931
+ tr.on("transformstart", () => {
15932
+ this.triggerSelectedNodesEvent();
15933
+ });
15934
+ tr.on("transform", () => {
15935
+ this.triggerSelectedNodesEvent();
15936
+ });
15937
+ tr.on("transformend", () => {
15938
+ this.triggerSelectedNodesEvent();
15939
+ });
15940
+ tr.on("dragstart", (e) => {
15941
+ for (const node of tr.nodes()) node.updatePosition(e.target.getAbsolutePosition());
15942
+ tr.forceUpdate();
15943
+ e.cancelBubble = true;
15944
+ });
15904
15945
  tr.on("dragmove", (e) => {
15946
+ for (const node of tr.nodes()) node.updatePosition(e.target.getAbsolutePosition());
15947
+ e.cancelBubble = true;
15905
15948
  if (this.isSelecting() && tr.nodes().length > 1) {
15906
15949
  clearContainerTargets(this.instance);
15907
15950
  const layerToMove = checkIfOverContainer(this.instance, e.target);
15908
15951
  if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
15952
+ for (const node of tr.nodes()) {
15953
+ const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
15954
+ this.instance.updateNode(nodeHandler.serialize(node));
15955
+ }
15909
15956
  }
15957
+ tr.forceUpdate();
15910
15958
  });
15911
- tr.on("dragend", () => {
15959
+ tr.on("dragend", (e) => {
15960
+ for (const node of tr.nodes()) node.updatePosition(e.target.getAbsolutePosition());
15961
+ e.cancelBubble = true;
15912
15962
  if (this.isSelecting() && tr.nodes().length > 1) {
15913
15963
  clearContainerTargets(this.instance);
15914
15964
  for (const node of tr.nodes()) {
15915
15965
  const layerToMove = moveNodeToContainer(this.instance, node);
15916
15966
  if (layerToMove) continue;
15967
+ const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
15968
+ this.instance.updateNode(nodeHandler.serialize(node));
15917
15969
  }
15918
15970
  }
15971
+ tr.forceUpdate();
15919
15972
  });
15920
15973
  this.tr = tr;
15921
15974
  this.selectionRectangle = selectionRectangle;
@@ -16040,7 +16093,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16040
16093
  });
16041
16094
  const box = this.selectionRectangle.getClientRect();
16042
16095
  const selected = shapes.filter((shape) => {
16043
- const parent = this.instance.getInstanceRecursive(shape.getParent());
16096
+ let parent = this.instance.getInstanceRecursive(shape.getParent());
16097
+ if (parent.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
16044
16098
  if (shape.getAttrs().nodeType && shape.getAttrs().nodeType === "frame") {
16045
16099
  const frameBox = shape.getClientRect();
16046
16100
  const isContained = frameBox.x >= box.x && frameBox.y >= box.y && frameBox.x + frameBox.width <= box.x + box.width && frameBox.y + frameBox.height <= box.y + box.height;
@@ -16089,36 +16143,45 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16089
16143
  if (contextMenuPlugin && !contextMenuPlugin.isTapHold()) this.instance.emitEvent("onStageSelection");
16090
16144
  return;
16091
16145
  }
16092
- const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
16093
- const isSelected = this.tr.nodes().indexOf(e.target) >= 0;
16094
16146
  let areNodesSelected = false;
16095
- let nodeToAdd = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
16096
- if (nodeToAdd.getParent() instanceof konva.default.Transformer) {
16147
+ let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
16148
+ if (nodeTargeted.getParent() instanceof konva.default.Transformer) {
16097
16149
  const intersections = stage.getAllIntersections(mousePos);
16098
16150
  const nodesIntersected = intersections.filter((ele) => ele.getAttrs().nodeType);
16099
16151
  let targetNode = null;
16100
16152
  if (nodesIntersected.length > 0) targetNode = this.instance.getInstanceRecursive(nodesIntersected[nodesIntersected.length - 1]);
16101
- if (targetNode && targetNode.getAttrs().nodeType) {
16102
- this.tr.nodes([]);
16103
- this.triggerSelectedNodesEvent();
16104
- nodeToAdd = targetNode;
16105
- }
16153
+ if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
16106
16154
  }
16107
- if (!nodeToAdd.getAttrs().nodeType) return;
16108
- if (!metaPressed && !isSelected) {
16109
- this.tr.nodes([nodeToAdd]);
16155
+ if (!nodeTargeted.getAttrs().nodeType) return;
16156
+ let nodesSelected = 0;
16157
+ const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
16158
+ const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
16159
+ return node.getAttrs().id === nodeTargeted.getAttrs().id;
16160
+ });
16161
+ const isSelected = nodeSelectedIndex !== -1;
16162
+ if (!metaPressed) {
16163
+ this.tr.nodes([nodeTargeted]);
16164
+ nodesSelected = this.tr.nodes().length;
16110
16165
  this.tr.show();
16111
16166
  areNodesSelected = true;
16112
16167
  } else if (metaPressed && isSelected) {
16113
16168
  const nodes = this.tr.nodes().slice();
16114
- nodes.splice(nodes.indexOf(nodeToAdd), 1);
16169
+ nodes.splice(nodes.indexOf(nodeTargeted), 1);
16115
16170
  this.tr.nodes(nodes);
16171
+ nodesSelected = this.tr.nodes().length;
16116
16172
  areNodesSelected = true;
16117
16173
  } else if (metaPressed && !isSelected) {
16118
- const nodes = this.tr.nodes().concat([nodeToAdd]);
16174
+ const nodes = this.tr.nodes().concat([nodeTargeted]);
16119
16175
  this.tr.nodes(nodes);
16176
+ nodesSelected = this.tr.nodes().length;
16120
16177
  areNodesSelected = true;
16121
16178
  }
16179
+ if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
16180
+ if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16181
+ if (nodesSelected === 1) {
16182
+ this.tr.setAttrs({ ...nodeTargeted.getTransformerProperties() });
16183
+ this.tr.forceUpdate();
16184
+ }
16122
16185
  if (areNodesSelected) {
16123
16186
  stage.container().tabIndex = 1;
16124
16187
  stage.container().focus();
@@ -16132,6 +16195,13 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16132
16195
  }
16133
16196
  setSelectedNodes(nodes) {
16134
16197
  this.tr.setNodes(nodes);
16198
+ const nodesSelected = nodes.length;
16199
+ if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
16200
+ if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
16201
+ if (nodesSelected === 1) {
16202
+ this.tr.setAttrs({ ...nodes[0].getTransformerProperties() });
16203
+ this.tr.forceUpdate();
16204
+ }
16135
16205
  this.triggerSelectedNodesEvent();
16136
16206
  }
16137
16207
  getSelectedNodes() {
@@ -16383,6 +16453,16 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16383
16453
 
16384
16454
  //#endregion
16385
16455
  //#region src/nodes/node.ts
16456
+ const setNodesDefaultConfiguration = (config) => {
16457
+ const { transform } = config ?? {};
16458
+ konva.default.Node.prototype.getTransformerProperties = function() {
16459
+ return {
16460
+ WEAVE_DEFAULT_TRANSFORM_PROPERTIES: __inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
16461
+ ...transform
16462
+ };
16463
+ };
16464
+ konva.default.Node.prototype.updatePosition = function() {};
16465
+ };
16386
16466
  var WeaveNode = class {
16387
16467
  register(instance) {
16388
16468
  this.instance = instance;
@@ -17002,11 +17082,11 @@ var WeaveGroupsManager = class {
17002
17082
  }, 0);
17003
17083
  }
17004
17084
  unGroup(group) {
17005
- this.logger.warn({ group }, "Un-grouping group");
17085
+ this.logger.debug({ group }, "Un-grouping group");
17006
17086
  const stage = this.instance.getStage();
17007
17087
  const konvaGroup = stage.findOne(`#${group.props.id}`);
17008
17088
  if (!konvaGroup) {
17009
- this.logger.warn({ group }, "Group instance doesn't exists, cannot un-group");
17089
+ this.logger.debug({ group }, "Group instance doesn't exists, cannot un-group");
17010
17090
  return;
17011
17091
  }
17012
17092
  let nodeId = void 0;
@@ -17018,7 +17098,7 @@ var WeaveGroupsManager = class {
17018
17098
  if (konvaGroup.getParent() && konvaGroup.getParent() instanceof konva.default.Group && !konvaGroup.getParent()?.getAttrs().nodeId) newLayer = konvaGroup.getParent();
17019
17099
  if (konvaGroup.getParent() && konvaGroup.getParent() instanceof konva.default.Layer) newLayer = konvaGroup.getParent();
17020
17100
  if (!newLayer) {
17021
- this.logger.warn({ group }, "Group target container doesn't exists, cannot un-group");
17101
+ this.logger.debug({ group }, "Group target container doesn't exists, cannot un-group");
17022
17102
  return;
17023
17103
  }
17024
17104
  const newLayerChildrenAmount = newLayer?.getChildren().length ?? 0;
@@ -17304,9 +17384,10 @@ var WeaveCloningManager = class {
17304
17384
  const serializedNodes = [];
17305
17385
  newGroup.getChildren().forEach((node) => {
17306
17386
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
17307
- if (node.x() < minPoint.x || node.y() < minPoint.y) {
17308
- minPoint.x = node.x();
17309
- minPoint.y = node.y();
17387
+ const nodePos = node.getClientRect();
17388
+ if (nodePos.x < minPoint.x || nodePos.y < minPoint.y) {
17389
+ minPoint.x = nodePos.x;
17390
+ minPoint.y = nodePos.y;
17310
17391
  }
17311
17392
  const serialized = nodeHandler.serialize(node);
17312
17393
  serializedNodes.push(serialized);
@@ -17943,7 +18024,7 @@ var WeaveRegisterManager = class {
17943
18024
 
17944
18025
  //#endregion
17945
18026
  //#region package.json
17946
- var version = "0.19.0";
18027
+ var version = "0.20.1";
17947
18028
 
17948
18029
  //#endregion
17949
18030
  //#region src/managers/setup.ts
@@ -18354,6 +18435,7 @@ var Weave = class extends Emittery {
18354
18435
  this.status = __inditextech_weave_types.WEAVE_INSTANCE_STATUS.STARTING;
18355
18436
  this.emitEvent("onInstanceStatus", this.status);
18356
18437
  this.registerManager.registerNodesHandlers();
18438
+ this.setNodesDefaultConfiguration();
18357
18439
  this.registerManager.registerPlugins();
18358
18440
  this.registerManager.registerActionsHandlers();
18359
18441
  this.storeManager.registerStore(this.config.store);
@@ -18383,6 +18465,9 @@ var Weave = class extends Emittery {
18383
18465
  getConfiguration() {
18384
18466
  return this.config;
18385
18467
  }
18468
+ setNodesDefaultConfiguration(config) {
18469
+ setNodesDefaultConfiguration(config);
18470
+ }
18386
18471
  emitEvent(event, payload) {
18387
18472
  this.moduleLogger.debug({ payload }, `Emitted event [${event}]`);
18388
18473
  this.emit(event, payload);
@@ -18654,11 +18739,22 @@ const WEAVE_GROUP_NODE_TYPE = "group";
18654
18739
  //#region src/nodes/group/group.ts
18655
18740
  var WeaveGroupNode = class extends WeaveNode {
18656
18741
  nodeType = WEAVE_GROUP_NODE_TYPE;
18742
+ constructor(params) {
18743
+ super();
18744
+ const { config } = params ?? {};
18745
+ this.config = { transform: {
18746
+ ...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
18747
+ ...config?.transform
18748
+ } };
18749
+ }
18657
18750
  onRender(props) {
18658
18751
  const group = new konva.default.Group({
18659
18752
  ...props,
18660
18753
  name: "node"
18661
18754
  });
18755
+ group.getTransformerProperties = () => {
18756
+ return this.config.transform;
18757
+ };
18662
18758
  this.setupDefaultNodeEvents(group);
18663
18759
  return group;
18664
18760
  }
@@ -18694,11 +18790,22 @@ const WEAVE_RECTANGLE_NODE_TYPE = "rectangle";
18694
18790
  //#region src/nodes/rectangle/rectangle.ts
18695
18791
  var WeaveRectangleNode = class extends WeaveNode {
18696
18792
  nodeType = WEAVE_RECTANGLE_NODE_TYPE;
18793
+ constructor(params) {
18794
+ super();
18795
+ const { config } = params ?? {};
18796
+ this.config = { transform: {
18797
+ ...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
18798
+ ...config?.transform
18799
+ } };
18800
+ }
18697
18801
  onRender(props) {
18698
18802
  const rectangle = new konva.default.Rect({
18699
18803
  ...props,
18700
18804
  name: "node"
18701
18805
  });
18806
+ rectangle.getTransformerProperties = () => {
18807
+ return this.config.transform;
18808
+ };
18702
18809
  this.setupDefaultNodeEvents(rectangle);
18703
18810
  return rectangle;
18704
18811
  }
@@ -18715,11 +18822,22 @@ const WEAVE_LINE_NODE_TYPE = "line";
18715
18822
  //#region src/nodes/line/line.ts
18716
18823
  var WeaveLineNode = class extends WeaveNode {
18717
18824
  nodeType = WEAVE_LINE_NODE_TYPE;
18825
+ constructor(params) {
18826
+ super();
18827
+ const { config } = params ?? {};
18828
+ this.config = { transform: {
18829
+ ...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
18830
+ ...config?.transform
18831
+ } };
18832
+ }
18718
18833
  onRender(props) {
18719
18834
  const line = new konva.default.Line({
18720
18835
  ...props,
18721
18836
  name: "node"
18722
18837
  });
18838
+ line.getTransformerProperties = () => {
18839
+ return this.config.transform;
18840
+ };
18723
18841
  this.setupDefaultNodeEvents(line);
18724
18842
  return line;
18725
18843
  }
@@ -18759,8 +18877,13 @@ const TEXT_LAYOUT = {
18759
18877
  var WeaveTextNode = class extends WeaveNode {
18760
18878
  nodeType = WEAVE_TEXT_NODE_TYPE;
18761
18879
  editing = false;
18762
- constructor() {
18880
+ constructor(params) {
18763
18881
  super();
18882
+ const { config } = params ?? {};
18883
+ this.config = { transform: {
18884
+ ...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
18885
+ ...config?.transform
18886
+ } };
18764
18887
  this.editing = false;
18765
18888
  }
18766
18889
  updateNode(nodeInstance) {
@@ -18774,6 +18897,9 @@ var WeaveTextNode = class extends WeaveNode {
18774
18897
  ...props,
18775
18898
  name: "node"
18776
18899
  });
18900
+ text.getTransformerProperties = () => {
18901
+ return this.config.transform;
18902
+ };
18777
18903
  text.setAttrs({ measureMultilineText: this.measureMultilineText(text) });
18778
18904
  this.setupDefaultNodeEvents(text);
18779
18905
  text.on("transform", (e) => {
@@ -18855,6 +18981,7 @@ var WeaveTextNode = class extends WeaveNode {
18855
18981
  const cleanedAttrs = { ...attrs };
18856
18982
  delete cleanedAttrs.draggable;
18857
18983
  delete cleanedAttrs.triggerEditMode;
18984
+ delete cleanedAttrs.measureMultilineText;
18858
18985
  return {
18859
18986
  key: attrs.id ?? "",
18860
18987
  type: attrs.nodeType,
@@ -19559,8 +19686,13 @@ const WEAVE_IMAGE_NODE_TYPE = "image";
19559
19686
  //#region src/nodes/image/image.ts
19560
19687
  var WeaveImageNode = class extends WeaveNode {
19561
19688
  nodeType = WEAVE_IMAGE_NODE_TYPE;
19562
- constructor() {
19689
+ constructor(params) {
19563
19690
  super();
19691
+ const { config } = params ?? {};
19692
+ this.config = { transform: {
19693
+ ...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
19694
+ ...config?.transform
19695
+ } };
19564
19696
  this.imageLoaded = false;
19565
19697
  this.cropping = false;
19566
19698
  }
@@ -19581,6 +19713,9 @@ var WeaveImageNode = class extends WeaveNode {
19581
19713
  id,
19582
19714
  name: "node"
19583
19715
  });
19716
+ image.getTransformerProperties = () => {
19717
+ return this.config.transform;
19718
+ };
19584
19719
  const imagePlaceholder = new konva.default.Rect({
19585
19720
  ...groupImageProps,
19586
19721
  id: `${id}-placeholder`,
@@ -19823,10 +19958,10 @@ const WEAVE_FRAME_NODE_SIZES = {
19823
19958
  };
19824
19959
  const WEAVE_FRAME_NODE_DEFAULT_CONFIG = {
19825
19960
  fontFamily: "Arial",
19826
- fontStyle: "normal",
19961
+ fontStyle: "bold",
19827
19962
  titleHeight: 30,
19828
19963
  borderColor: "#000000ff",
19829
- borderWidth: 2,
19964
+ borderWidth: 1,
19830
19965
  onTargetLeave: {
19831
19966
  borderColor: "#000000ff",
19832
19967
  fill: "#ffffffff"
@@ -19834,6 +19969,13 @@ const WEAVE_FRAME_NODE_DEFAULT_CONFIG = {
19834
19969
  onTargetEnter: {
19835
19970
  borderColor: "#ff6863ff",
19836
19971
  fill: "#ffffffff"
19972
+ },
19973
+ transform: {
19974
+ rotateEnabled: false,
19975
+ resizeEnabled: false,
19976
+ enabledAnchors: [],
19977
+ borderStrokeWidth: 3,
19978
+ padding: 0
19837
19979
  }
19838
19980
  };
19839
19981
  const WEAVE_FRAME_NODE_DEFAULT_PROPS = {
@@ -19886,34 +20028,42 @@ var WeaveFrameNode = class extends WeaveNode {
19886
20028
  containerOffsetX: 0,
19887
20029
  containerOffsetY: titleHeight,
19888
20030
  width: props.frameWidth,
19889
- height: props.frameHeight + titleHeight,
19890
- fill: "#ffffffff",
19891
- clipX: 0,
19892
- clipY: 0,
19893
- clipWidth: props.frameWidth,
19894
- clipHeight: props.frameHeight + titleHeight,
19895
- name: "node"
20031
+ height: props.frameHeight,
20032
+ fill: "transparent",
20033
+ draggable: false
20034
+ });
20035
+ const frameInternalGroup = new konva.default.Group({
20036
+ id: `${id}-selector`,
20037
+ x: 0,
20038
+ y: 0,
20039
+ width: props.frameWidth,
20040
+ height: props.frameHeight,
20041
+ strokeScaleEnabled: false,
20042
+ draggable: false
19896
20043
  });
20044
+ frame.add(frameInternalGroup);
19897
20045
  const background = new konva.default.Rect({
19898
20046
  id: `${id}-bg`,
19899
20047
  nodeId: id,
19900
20048
  x: 0,
19901
- y: titleHeight,
20049
+ y: 0,
19902
20050
  width: props.frameWidth,
19903
20051
  stroke: borderColor,
19904
20052
  strokeWidth: borderWidth,
19905
20053
  strokeScaleEnabled: false,
20054
+ shadowForStrokeEnabled: false,
19906
20055
  height: props.frameHeight,
19907
20056
  fill: "#ffffffff",
20057
+ listening: false,
19908
20058
  draggable: false
19909
20059
  });
19910
- frame.add(background);
20060
+ frameInternalGroup.add(background);
19911
20061
  const text = new konva.default.Text({
19912
20062
  id: `${id}-title`,
19913
20063
  x: 0,
19914
- y: 0,
20064
+ y: -titleHeight,
19915
20065
  width: props.frameWidth,
19916
- height: titleHeight - 10,
20066
+ height: titleHeight,
19917
20067
  fontSize: 20,
19918
20068
  fontFamily,
19919
20069
  fontStyle,
@@ -19925,7 +20075,89 @@ var WeaveFrameNode = class extends WeaveNode {
19925
20075
  listening: false,
19926
20076
  draggable: false
19927
20077
  });
19928
- frame.add(text);
20078
+ frameInternalGroup.add(text);
20079
+ const selectorArea = new konva.default.Rect({
20080
+ ...frameParams,
20081
+ id: `${id}-selector-area`,
20082
+ name: "node",
20083
+ nodeId: id,
20084
+ containerId: `${id}-group-internal`,
20085
+ x: 0,
20086
+ y: 0,
20087
+ strokeWidth: 0,
20088
+ strokeScaleEnabled: false,
20089
+ width: props.frameWidth,
20090
+ height: props.frameHeight,
20091
+ fill: "transparent",
20092
+ draggable: false
20093
+ });
20094
+ selectorArea.getTransformerProperties = () => {
20095
+ return this.config.transform;
20096
+ };
20097
+ selectorArea.updatePosition = (position) => {
20098
+ frame.setAbsolutePosition(position);
20099
+ selectorArea.setAttrs({
20100
+ x: 0,
20101
+ y: 0
20102
+ });
20103
+ this.instance.updateNode(this.serialize(selectorArea));
20104
+ };
20105
+ const updateFrame = (e) => {
20106
+ const selectorArea$1 = e.target;
20107
+ const stage = selectorArea$1.getStage();
20108
+ if (!stage) return;
20109
+ const absPos = selectorArea$1.getAbsolutePosition();
20110
+ const absRot = selectorArea$1.getAbsoluteRotation();
20111
+ const scaleX = selectorArea$1.scaleX();
20112
+ const scaleY = selectorArea$1.scaleY();
20113
+ selectorArea$1.x(0);
20114
+ selectorArea$1.y(0);
20115
+ frame.setAbsolutePosition(absPos);
20116
+ frame.rotation(absRot);
20117
+ frame.width(selectorArea$1.width());
20118
+ frame.height(selectorArea$1.height());
20119
+ frameInternalGroup.width(Math.max(5, selectorArea$1.width() * scaleX));
20120
+ frameInternalGroup.height(Math.max(5, selectorArea$1.height() * scaleY));
20121
+ background.width(Math.max(5, selectorArea$1.width() * scaleX));
20122
+ background.height(Math.max(5, selectorArea$1.height() * scaleY));
20123
+ text.width(Math.max(5, selectorArea$1.width() * scaleX));
20124
+ text.height(titleHeight * scaleY);
20125
+ frameInternal.width(Math.max(5, selectorArea$1.width() * scaleX));
20126
+ frameInternal.height(Math.max(5, selectorArea$1.height() * scaleY));
20127
+ };
20128
+ selectorArea.on("transform", (e) => {
20129
+ updateFrame(e);
20130
+ const node = e.target;
20131
+ const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
20132
+ if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.evaluateGuidelines(e);
20133
+ const clonedSA = selectorArea.clone();
20134
+ const scaleX = clonedSA.scaleX();
20135
+ const scaleY = clonedSA.scaleY();
20136
+ clonedSA.x(0);
20137
+ clonedSA.y(0);
20138
+ clonedSA.width(Math.max(5, clonedSA.width() * scaleX));
20139
+ clonedSA.height(Math.max(5, clonedSA.height() * scaleY));
20140
+ clonedSA.scaleX(1);
20141
+ clonedSA.scaleY(1);
20142
+ this.instance.updateNode(this.serialize(clonedSA));
20143
+ e.cancelBubble = true;
20144
+ });
20145
+ selectorArea.on("transformend", (e) => {
20146
+ const node = e.target;
20147
+ const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
20148
+ if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.cleanupEvaluateGuidelines();
20149
+ const scaleX = selectorArea.scaleX();
20150
+ const scaleY = selectorArea.scaleY();
20151
+ selectorArea.x(0);
20152
+ selectorArea.y(0);
20153
+ selectorArea.width(Math.max(5, selectorArea.width() * scaleX));
20154
+ selectorArea.height(Math.max(5, selectorArea.height() * scaleY));
20155
+ selectorArea.scaleX(1);
20156
+ selectorArea.scaleY(1);
20157
+ updateFrame(e);
20158
+ this.instance.updateNode(this.serialize(selectorArea));
20159
+ });
20160
+ frameInternalGroup.add(selectorArea);
19929
20161
  const frameInternal = new konva.default.Group({
19930
20162
  id: `${id}-group-internal`,
19931
20163
  nodeId: id,
@@ -19933,17 +20165,18 @@ var WeaveFrameNode = class extends WeaveNode {
19933
20165
  y: titleHeight,
19934
20166
  width: props.frameWidth,
19935
20167
  height: props.frameHeight,
19936
- draggable: false,
19937
- stroke: "transparent",
19938
20168
  strokeScaleEnabled: false,
19939
- borderWidth: 0,
19940
- clipX: 0,
19941
- clipY: 0,
19942
- clipWidth: props.frameWidth,
19943
- clipHeight: props.frameHeight
20169
+ draggable: false
19944
20170
  });
19945
- frame.add(frameInternal);
20171
+ frameInternal.clipFunc((ctx) => {
20172
+ const width = frameInternal.width() * frameInternal.scaleX();
20173
+ const height = frameInternal.height() * frameInternal.scaleY();
20174
+ ctx.rect(0, -titleHeight, width, height);
20175
+ });
20176
+ frameInternalGroup.add(frameInternal);
19946
20177
  this.setupDefaultNodeEvents(frame);
20178
+ frame.on("dragmove", () => {});
20179
+ frame.on("dragend", () => {});
19947
20180
  frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
19948
20181
  background.setAttrs({
19949
20182
  stroke: onTargetLeaveBorderColor,
@@ -19964,13 +20197,51 @@ var WeaveFrameNode = class extends WeaveNode {
19964
20197
  const { id } = nextProps;
19965
20198
  const frameNode = nodeInstance;
19966
20199
  const newProps = { ...nextProps };
20200
+ const { titleHeight } = this.config;
19967
20201
  nodeInstance.setAttrs({ ...newProps });
19968
- const frameTitle = frameNode.findOne(`#${id}-title`);
19969
- if (frameTitle) frameTitle.setAttrs({ text: nextProps.title });
20202
+ const selectorArea = frameNode.findOne(`#${id}-selector-area`);
20203
+ if (selectorArea) {
20204
+ selectorArea.setAttrs({
20205
+ x: 0,
20206
+ y: 0,
20207
+ width: nextProps.width,
20208
+ height: nextProps.height
20209
+ });
20210
+ const frameInternalGroup = frameNode.findOne(`#${id}-selector`);
20211
+ if (frameInternalGroup) frameInternalGroup.setAttrs({
20212
+ x: 0,
20213
+ y: 0,
20214
+ width: nextProps.width * selectorArea.scaleX(),
20215
+ height: nextProps.height * selectorArea.scaleY()
20216
+ });
20217
+ const background = frameNode.findOne(`#${id}-bg`);
20218
+ if (background) background.setAttrs({
20219
+ x: 0,
20220
+ y: 0,
20221
+ width: nextProps.width * selectorArea.scaleX(),
20222
+ height: nextProps.height * selectorArea.scaleY()
20223
+ });
20224
+ const text = frameNode.findOne(`#${id}-title`);
20225
+ if (text) text.setAttrs({
20226
+ x: 0,
20227
+ y: -titleHeight,
20228
+ text: nextProps.title,
20229
+ width: nextProps.width * selectorArea.scaleX()
20230
+ });
20231
+ const frameInternal = frameNode.findOne(`#${id}-group-internal`);
20232
+ if (frameInternal) frameInternal.setAttrs({
20233
+ x: 0,
20234
+ y: titleHeight,
20235
+ width: nextProps.width * selectorArea.scaleX(),
20236
+ height: nextProps.height * selectorArea.scaleY()
20237
+ });
20238
+ }
19970
20239
  }
19971
20240
  serialize(instance) {
20241
+ const stage = this.instance.getStage();
19972
20242
  const attrs = instance.getAttrs();
19973
- const frameInternal = instance.findOne(`#${attrs.containerId}`);
20243
+ const mainNode = stage?.findOne(`#${attrs.nodeId}`);
20244
+ const frameInternal = mainNode?.findOne(`#${attrs.containerId}`);
19974
20245
  const childrenMapped = [];
19975
20246
  if (frameInternal) {
19976
20247
  const children = [...frameInternal.getChildren()];
@@ -19979,15 +20250,16 @@ var WeaveFrameNode = class extends WeaveNode {
19979
20250
  childrenMapped.push(handler.serialize(node));
19980
20251
  }
19981
20252
  }
19982
- const cleanedAttrs = { ...attrs };
20253
+ const realAttrs = mainNode?.getAttrs();
20254
+ const cleanedAttrs = { ...realAttrs };
19983
20255
  delete cleanedAttrs.draggable;
19984
20256
  return {
19985
- key: attrs.id ?? "",
19986
- type: attrs.nodeType,
20257
+ key: realAttrs?.id ?? "",
20258
+ type: realAttrs?.nodeType,
19987
20259
  props: {
19988
20260
  ...cleanedAttrs,
19989
- id: attrs.id ?? "",
19990
- nodeType: attrs.nodeType,
20261
+ id: realAttrs?.id ?? "",
20262
+ nodeType: realAttrs?.nodeType,
19991
20263
  children: childrenMapped
19992
20264
  }
19993
20265
  };
@@ -19997,28 +20269,44 @@ var WeaveFrameNode = class extends WeaveNode {
19997
20269
  //#endregion
19998
20270
  //#region src/plugins/stage-zoom/constants.ts
19999
20271
  const WEAVE_STAGE_ZOOM_KEY = "stageZoom";
20272
+ const WEAVE_STAGE_ZOOM_DEFAULT_CONFIG = {
20273
+ zoomSteps: [
20274
+ .1,
20275
+ .2,
20276
+ .3,
20277
+ .4,
20278
+ .5,
20279
+ .6,
20280
+ .7,
20281
+ .8,
20282
+ .9,
20283
+ 1,
20284
+ 1.25,
20285
+ 1.5,
20286
+ 1.75,
20287
+ 2,
20288
+ 3,
20289
+ 4,
20290
+ 6,
20291
+ 8,
20292
+ 10
20293
+ ],
20294
+ defaultZoom: 1,
20295
+ fitToScreen: { padding: 40 },
20296
+ fitToSelection: { padding: 40 }
20297
+ };
20000
20298
 
20001
20299
  //#endregion
20002
20300
  //#region src/plugins/stage-zoom/stage-zoom.ts
20003
20301
  var WeaveStageZoomPlugin = class extends WeavePlugin {
20004
20302
  getLayerName = void 0;
20005
20303
  initLayer = void 0;
20006
- padding = 175;
20007
20304
  defaultStep = 3;
20008
20305
  constructor(params) {
20009
20306
  super();
20010
20307
  const { config } = params ?? {};
20011
20308
  this.config = {
20012
- zoomSteps: [
20013
- .1,
20014
- .25,
20015
- .5,
20016
- 1,
20017
- 2,
20018
- 4,
20019
- 8
20020
- ],
20021
- defaultZoom: 1,
20309
+ ...WEAVE_STAGE_ZOOM_DEFAULT_CONFIG,
20022
20310
  ...config
20023
20311
  };
20024
20312
  if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
@@ -20078,13 +20366,13 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
20078
20366
  canZoomOut() {
20079
20367
  if (!this.enabled) return false;
20080
20368
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
20081
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
20369
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomOut");
20082
20370
  return this.actualStep - 1 > 0;
20083
20371
  }
20084
20372
  canZoomIn() {
20085
20373
  if (!this.enabled) return false;
20086
20374
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
20087
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
20375
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomIn");
20088
20376
  return this.actualStep + 1 < this.config.zoomSteps.length;
20089
20377
  }
20090
20378
  zoomToStep(step) {
@@ -20093,20 +20381,15 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
20093
20381
  this.actualStep = step;
20094
20382
  this.setZoom(this.config.zoomSteps[step]);
20095
20383
  }
20096
- findClosestStepIndex() {
20097
- let closestStepIndex = 0;
20098
- let actualDiff = Infinity;
20099
- for (let i = 0; i < this.config.zoomSteps.length; i++) if (Math.abs(this.config.zoomSteps[i] - this.actualScale) < actualDiff) {
20100
- closestStepIndex = i;
20101
- actualDiff = Math.abs(this.config.zoomSteps[i] - this.actualScale);
20102
- }
20103
- return closestStepIndex;
20384
+ findClosestStepIndex(direction) {
20385
+ const nextValue = this.config.zoomSteps.filter((scale) => direction === "zoomIn" ? scale >= this.actualScale : scale <= this.actualScale).sort((a, b) => direction === "zoomIn" ? a - b : b - a)[0];
20386
+ return this.config.zoomSteps.findIndex((scale) => scale === nextValue);
20104
20387
  }
20105
20388
  zoomIn() {
20106
20389
  if (!this.enabled) return;
20107
20390
  if (!this.canZoomIn()) return;
20108
20391
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
20109
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
20392
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomIn");
20110
20393
  else this.actualStep += 1;
20111
20394
  this.setZoom(this.config.zoomSteps[this.actualStep]);
20112
20395
  }
@@ -20114,7 +20397,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
20114
20397
  if (!this.enabled) return;
20115
20398
  if (!this.canZoomOut()) return;
20116
20399
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
20117
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
20400
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomOut");
20118
20401
  else this.actualStep -= 1;
20119
20402
  this.setZoom(this.config.zoomSteps[this.actualStep]);
20120
20403
  }
@@ -20127,11 +20410,32 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
20127
20410
  }
20128
20411
  const stage = this.instance.getStage();
20129
20412
  if (mainLayer) {
20130
- const box = mainLayer.getClientRect({ relativeTo: stage });
20131
- const scale = Math.min(stage.width() / (box.width + this.padding * 2), stage.height() / (box.height + this.padding * 2));
20132
- stage.setAttrs({
20133
- x: -box.x * scale + (stage.width() - box.width * scale) / 2,
20134
- y: -box.y * scale + (stage.height() - box.height * scale) / 2
20413
+ const box = mainLayer.getClientRect({
20414
+ relativeTo: stage,
20415
+ skipStroke: true
20416
+ });
20417
+ const stageBox = {
20418
+ width: stage.width(),
20419
+ height: stage.height()
20420
+ };
20421
+ const availableScreenWidth = stageBox.width - 2 * this.config.fitToScreen.padding;
20422
+ const availableScreenHeight = stageBox.height - 2 * this.config.fitToScreen.padding;
20423
+ const scaleX = availableScreenWidth / box.width;
20424
+ const scaleY = availableScreenHeight / box.height;
20425
+ const scale = Math.min(scaleX, scaleY);
20426
+ stage.scale({
20427
+ x: scale,
20428
+ y: scale
20429
+ });
20430
+ const selectionCenterX = box.x + box.width / 2;
20431
+ const selectionCenterY = box.y + box.height / 2;
20432
+ const canvasCenterX = stage.width() / (2 * scale);
20433
+ const canvasCenterY = stage.height() / (2 * scale);
20434
+ const stageX = (canvasCenterX - selectionCenterX) * scale;
20435
+ const stageY = (canvasCenterY - selectionCenterY) * scale;
20436
+ stage.position({
20437
+ x: stageX,
20438
+ y: stageY
20135
20439
  });
20136
20440
  this.setZoom(scale, false);
20137
20441
  }
@@ -20166,10 +20470,28 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
20166
20470
  zoomTransformer.setNodes(selectionPlugin.getTransformer().getNodes());
20167
20471
  zoomTransformer.forceUpdate();
20168
20472
  const box = zoomTransformer.__getNodeRect();
20169
- const scale = Math.min(stage.width() / (zoomTransformer.width() + this.padding * 2), stage.height() / (zoomTransformer.height() + this.padding * 2));
20170
- stage.setAttrs({
20171
- x: -box.x * scale + (stage.width() - zoomTransformer.width() * scale) / 2,
20172
- y: -box.y * scale + (stage.height() - zoomTransformer.height() * scale) / 2
20473
+ const stageBox = {
20474
+ width: stage.width(),
20475
+ height: stage.height()
20476
+ };
20477
+ const availableScreenWidth = stageBox.width - 2 * this.config.fitToSelection.padding;
20478
+ const availableScreenHeight = stageBox.height - 2 * this.config.fitToSelection.padding;
20479
+ const scaleX = availableScreenWidth / box.width;
20480
+ const scaleY = availableScreenHeight / box.height;
20481
+ const scale = Math.min(scaleX, scaleY);
20482
+ stage.scale({
20483
+ x: scale,
20484
+ y: scale
20485
+ });
20486
+ const selectionCenterX = box.x + box.width / 2;
20487
+ const selectionCenterY = box.y + box.height / 2;
20488
+ const canvasCenterX = stage.width() / (2 * scale);
20489
+ const canvasCenterY = stage.height() / (2 * scale);
20490
+ const stageX = (canvasCenterX - selectionCenterX) * scale;
20491
+ const stageY = (canvasCenterY - selectionCenterY) * scale;
20492
+ stage.position({
20493
+ x: stageX,
20494
+ y: stageY
20173
20495
  });
20174
20496
  this.setZoom(scale, false);
20175
20497
  zoomTransformer.destroy();
@@ -21288,7 +21610,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
21288
21610
  stage.container().style.cursor = "default";
21289
21611
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
21290
21612
  if (selectionPlugin) {
21291
- const node = stage.findOne(`#${this.frameId}`);
21613
+ const node = stage.findOne(`#${this.frameId}-selector-area`);
21292
21614
  if (node) selectionPlugin.setSelectedNodes([node]);
21293
21615
  this.instance.triggerAction("selectionTool");
21294
21616
  }
@@ -22330,6 +22652,10 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
22330
22652
  nodes
22331
22653
  };
22332
22654
  }
22655
+ deleteGuides() {
22656
+ const utilityLayer = this.instance.getUtilityLayer();
22657
+ if (utilityLayer) utilityLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
22658
+ }
22333
22659
  evaluateGuidelines(e) {
22334
22660
  const utilityLayer = this.instance.getUtilityLayer();
22335
22661
  if (!this.enabled) return;
@@ -22337,14 +22663,13 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
22337
22663
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
22338
22664
  let skipNodes = [];
22339
22665
  let node = void 0;
22340
- if (e.type === "dragmove" && nodesSelectionPlugin && e.target instanceof konva.default.Transformer && e.target.getNodes().length === 1) {
22341
- const actualTarget = e.target;
22342
- node = actualTarget.getNodes()[0];
22666
+ if (e.type === "dragmove" && nodesSelectionPlugin && nodesSelectionPlugin.getTransformer().nodes().length === 1) {
22667
+ node = nodesSelectionPlugin.getTransformer().nodes()[0];
22343
22668
  skipNodes.push(node.getAttrs().id ?? "");
22344
22669
  }
22345
- if (e.type === "dragmove" && nodesSelectionPlugin && e.target instanceof konva.default.Transformer && e.target.getNodes().length > 1) {
22346
- const { nodes } = this.getSelectedNodesMetadata(e.target);
22347
- node = e.target;
22670
+ if (e.type === "dragmove" && nodesSelectionPlugin && nodesSelectionPlugin.getTransformer().nodes().length > 1) {
22671
+ const { nodes } = this.getSelectedNodesMetadata(nodesSelectionPlugin.getTransformer());
22672
+ node = nodesSelectionPlugin.getTransformer();
22348
22673
  skipNodes = [...nodes];
22349
22674
  }
22350
22675
  if (e.type === "transform") node = e.target;