@inditextech/weave-sdk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.cjs CHANGED
@@ -15754,6 +15754,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15754
15754
  rotationSnapTolerance: 3,
15755
15755
  ignoreStroke: true,
15756
15756
  flipEnabled: false,
15757
+ keepRatio: false,
15757
15758
  useSingleNodeRotation: true,
15758
15759
  shouldOverdrawWholeArea: true,
15759
15760
  anchorStyleFunc: (anchor) => {
@@ -17806,7 +17807,7 @@ var WeaveRegisterManager = class {
17806
17807
 
17807
17808
  //#endregion
17808
17809
  //#region package.json
17809
- var version = "0.7.0";
17810
+ var version = "0.8.0";
17810
17811
 
17811
17812
  //#endregion
17812
17813
  //#region src/managers/setup.ts
@@ -21348,7 +21349,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
21348
21349
  const userInfo = this.config.getUser();
21349
21350
  store.setAwarenessInfo(WEAVE_CONNECTED_USER_INFO_KEY, userInfo);
21350
21351
  this.callbacks?.onConnectedUsersChanged?.({ [userInfo.name]: userInfo });
21351
- store.onAwarenessChange((changes) => {
21352
+ this.instance.addEventListener("onAwarenessChange", (changes) => {
21352
21353
  if (!this.enabled) {
21353
21354
  this.connectedUsers = {};
21354
21355
  this.callbacks?.onConnectedUsersChanged?.({});
@@ -21416,7 +21417,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
21416
21417
  onInit() {
21417
21418
  const store = this.instance.getStore();
21418
21419
  const stage = this.instance.getStage();
21419
- store.onAwarenessChange((changes) => {
21420
+ this.instance.addEventListener("onAwarenessChange", (changes) => {
21420
21421
  const selfUser = this.config.getUser();
21421
21422
  for (const change of changes) {
21422
21423
  if (!change[WEAVE_USER_POINTER_KEY]) continue;
@@ -21681,9 +21682,9 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21681
21682
  this.enabled = enabled;
21682
21683
  }
21683
21684
  evaluateGuidelines(e) {
21684
- const mainLayer = this.instance.getMainLayer();
21685
+ const utilityLayer = this.instance.getUtilityLayer();
21685
21686
  if (!this.enabled) return;
21686
- if (!mainLayer) return;
21687
+ if (!utilityLayer) return;
21687
21688
  let node = void 0;
21688
21689
  if (e.type === "dragmove" && e.target instanceof konva.default.Transformer) {
21689
21690
  const actualTarget = e.target;
@@ -21691,11 +21692,11 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21691
21692
  }
21692
21693
  if (e.type === "transform") node = e.target;
21693
21694
  if (typeof node === "undefined") return;
21694
- mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21695
21695
  const lineGuideStops = this.getLineGuideStops(node);
21696
21696
  const itemBounds = this.getObjectSnappingEdges(node);
21697
21697
  const guides = this.getGuides(lineGuideStops, itemBounds, e.type);
21698
21698
  if (!guides.length) return;
21699
+ utilityLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21699
21700
  this.drawGuides(guides);
21700
21701
  if (e.type === "dragmove") {
21701
21702
  const absPos = node.absolutePosition();
@@ -21719,41 +21720,41 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21719
21720
  const transformer = nodesSelectionPlugin.getTransformer();
21720
21721
  transformer.anchorDragBoundFunc((_, newAbsPos) => {
21721
21722
  const finalPos = { ...newAbsPos };
21722
- guides.forEach((lg) => {
21723
- switch (lg.orientation) {
21724
- case GUIDE_ORIENTATION.VERTICAL: {
21725
- const distX = Math.sqrt(Math.pow(newAbsPos.x - lg.lineGuide, 2));
21726
- if (distX < this.transformSnappingThreshold) finalPos.x = lg.lineGuide;
21727
- break;
21728
- }
21729
- case GUIDE_ORIENTATION.HORIZONTAL: {
21730
- const distY = Math.sqrt(Math.pow(newAbsPos.y - lg.lineGuide, 2));
21731
- if (distY < this.transformSnappingThreshold) finalPos.y = lg.lineGuide;
21732
- break;
21733
- }
21723
+ for (const lg of guides) switch (lg.orientation) {
21724
+ case GUIDE_ORIENTATION.VERTICAL: {
21725
+ const distX = Math.sqrt(Math.pow(newAbsPos.x - lg.lineGuide, 2));
21726
+ if (distX < this.transformSnappingThreshold) finalPos.x = lg.lineGuide;
21727
+ break;
21734
21728
  }
21735
- });
21729
+ case GUIDE_ORIENTATION.HORIZONTAL: {
21730
+ const distY = Math.sqrt(Math.pow(newAbsPos.y - lg.lineGuide, 2));
21731
+ if (distY < this.transformSnappingThreshold) finalPos.y = lg.lineGuide;
21732
+ break;
21733
+ }
21734
+ }
21736
21735
  return finalPos;
21737
21736
  });
21738
21737
  }
21739
21738
  }
21740
21739
  }
21741
21740
  cleanupEvaluateGuidelines() {
21742
- const mainLayer = this.instance.getMainLayer();
21741
+ const utilityLayer = this.instance.getUtilityLayer();
21743
21742
  if (!this.enabled) return;
21744
- if (!mainLayer) return;
21745
- mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21743
+ if (!utilityLayer) return;
21744
+ utilityLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21746
21745
  }
21747
21746
  initEvents() {
21748
21747
  const stage = this.instance.getStage();
21749
- const mainLayer = this.instance.getMainLayer();
21750
- if (mainLayer) {
21748
+ const utilityLayer = this.instance.getUtilityLayer();
21749
+ if (utilityLayer) {
21751
21750
  stage.on("dragmove", this.evaluateGuidelines.bind(this));
21752
21751
  stage.on("dragend", this.cleanupEvaluateGuidelines.bind(this));
21753
21752
  }
21754
21753
  }
21755
21754
  getLineGuideStops(skipShape) {
21756
21755
  const stage = this.instance.getStage();
21756
+ const nodesSelection = this.instance.getPlugin("nodesSelection");
21757
+ if (nodesSelection) nodesSelection.getTransformer().hide();
21757
21758
  const vertical = [
21758
21759
  0,
21759
21760
  stage.width() / 2,
@@ -21766,7 +21767,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21766
21767
  ];
21767
21768
  stage.find(".node").forEach((guideItem) => {
21768
21769
  if (guideItem === skipShape) return;
21769
- const box = guideItem.getClientRect();
21770
+ const box = guideItem.getClientRect({ skipStroke: true });
21770
21771
  vertical.push([
21771
21772
  box.x,
21772
21773
  box.x + box.width,
@@ -21778,28 +21779,29 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21778
21779
  box.y + box.height / 2
21779
21780
  ]);
21780
21781
  });
21782
+ if (nodesSelection) nodesSelection.getTransformer().show();
21781
21783
  return {
21782
21784
  vertical: vertical.flat(),
21783
21785
  horizontal: horizontal.flat()
21784
21786
  };
21785
21787
  }
21786
21788
  getObjectSnappingEdges(node) {
21787
- const box = node.getClientRect();
21789
+ const box = node.getClientRect({ skipStroke: true });
21788
21790
  const absPos = node.absolutePosition();
21789
21791
  const snappingEdges = {
21790
21792
  vertical: [
21791
21793
  {
21792
- guide: Math.round(box.x),
21794
+ guide: box.x,
21793
21795
  offset: Math.round(absPos.x - box.x),
21794
21796
  snap: NODE_SNAP.START
21795
21797
  },
21796
21798
  {
21797
- guide: Math.round(box.x + box.width / 2),
21799
+ guide: box.x + box.width / 2,
21798
21800
  offset: Math.round(absPos.x - box.x - box.width / 2),
21799
21801
  snap: NODE_SNAP.CENTER
21800
21802
  },
21801
21803
  {
21802
- guide: Math.round(box.x + box.width),
21804
+ guide: box.x + box.width,
21803
21805
  offset: Math.round(absPos.x - box.x - box.width),
21804
21806
  snap: NODE_SNAP.END
21805
21807
  }
@@ -21888,8 +21890,8 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21888
21890
  }
21889
21891
  drawGuides(guides) {
21890
21892
  const stage = this.instance.getStage();
21891
- const mainLayer = this.instance.getMainLayer();
21892
- if (mainLayer) guides.forEach((lg) => {
21893
+ const utilityLayer = this.instance.getUtilityLayer();
21894
+ if (utilityLayer) guides.forEach((lg) => {
21893
21895
  if (lg.orientation === GUIDE_ORIENTATION.HORIZONTAL) {
21894
21896
  const line = new konva.default.Line({
21895
21897
  ...this.guideLineConfig,
@@ -21903,7 +21905,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21903
21905
  ],
21904
21906
  name: GUIDE_LINE_NAME
21905
21907
  });
21906
- mainLayer.add(line);
21908
+ utilityLayer.add(line);
21907
21909
  line.absolutePosition({
21908
21910
  x: 0,
21909
21911
  y: lg.lineGuide
@@ -21922,7 +21924,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21922
21924
  ],
21923
21925
  name: GUIDE_LINE_NAME
21924
21926
  });
21925
- mainLayer.add(line);
21927
+ utilityLayer.add(line);
21926
21928
  line.absolutePosition({
21927
21929
  x: lg.lineGuide,
21928
21930
  y: 0
package/dist/sdk.d.cts CHANGED
@@ -52,7 +52,6 @@ type WeaveStoreOptions = {
52
52
  interface WeaveStoreBase {
53
53
  connect(): void;
54
54
  disconnect(): void;
55
- onAwarenessChange<K extends string, T>(callback: (changes: WeaveAwarenessChange<K, T>[]) => void): void;
56
55
  setAwarenessInfo(field: string, value: unknown): void;
57
56
  }
58
57
 
@@ -115,7 +114,6 @@ type WeaveNodeFound = {
115
114
  parent: WeaveStateElement | null;
116
115
  index: number;
117
116
  };
118
- type WeaveAwarenessChange<K extends string, T> = { [key in K]: T };
119
117
  type WeaveElementInstance = Konva.Layer | Konva.Group | Konva.Shape;
120
118
  type WeaveLoggerConfig = {
121
119
  disabled?: boolean;
@@ -203,7 +201,6 @@ declare abstract class WeaveStore implements WeaveStoreBase {
203
201
  redoStateStep(): void;
204
202
  abstract connect(): void;
205
203
  abstract disconnect(): void;
206
- abstract onAwarenessChange<K extends string, T>(callback: (changes: WeaveAwarenessChange<K, T>[]) => void): void;
207
204
  abstract setAwarenessInfo(field: string, value: unknown): void;
208
205
  }
209
206
 
package/dist/sdk.d.ts CHANGED
@@ -52,7 +52,6 @@ type WeaveStoreOptions = {
52
52
  interface WeaveStoreBase {
53
53
  connect(): void;
54
54
  disconnect(): void;
55
- onAwarenessChange<K extends string, T>(callback: (changes: WeaveAwarenessChange<K, T>[]) => void): void;
56
55
  setAwarenessInfo(field: string, value: unknown): void;
57
56
  }
58
57
 
@@ -115,7 +114,6 @@ type WeaveNodeFound = {
115
114
  parent: WeaveStateElement | null;
116
115
  index: number;
117
116
  };
118
- type WeaveAwarenessChange<K extends string, T> = { [key in K]: T };
119
117
  type WeaveElementInstance = Konva.Layer | Konva.Group | Konva.Shape;
120
118
  type WeaveLoggerConfig = {
121
119
  disabled?: boolean;
@@ -203,7 +201,6 @@ declare abstract class WeaveStore implements WeaveStoreBase {
203
201
  redoStateStep(): void;
204
202
  abstract connect(): void;
205
203
  abstract disconnect(): void;
206
- abstract onAwarenessChange<K extends string, T>(callback: (changes: WeaveAwarenessChange<K, T>[]) => void): void;
207
204
  abstract setAwarenessInfo(field: string, value: unknown): void;
208
205
  }
209
206
 
package/dist/sdk.js CHANGED
@@ -15754,6 +15754,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15754
15754
  rotationSnapTolerance: 3,
15755
15755
  ignoreStroke: true,
15756
15756
  flipEnabled: false,
15757
+ keepRatio: false,
15757
15758
  useSingleNodeRotation: true,
15758
15759
  shouldOverdrawWholeArea: true,
15759
15760
  anchorStyleFunc: (anchor) => {
@@ -17806,7 +17807,7 @@ var WeaveRegisterManager = class {
17806
17807
 
17807
17808
  //#endregion
17808
17809
  //#region package.json
17809
- var version = "0.7.0";
17810
+ var version = "0.8.0";
17810
17811
 
17811
17812
  //#endregion
17812
17813
  //#region src/managers/setup.ts
@@ -21348,7 +21349,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
21348
21349
  const userInfo = this.config.getUser();
21349
21350
  store.setAwarenessInfo(WEAVE_CONNECTED_USER_INFO_KEY, userInfo);
21350
21351
  this.callbacks?.onConnectedUsersChanged?.({ [userInfo.name]: userInfo });
21351
- store.onAwarenessChange((changes) => {
21352
+ this.instance.addEventListener("onAwarenessChange", (changes) => {
21352
21353
  if (!this.enabled) {
21353
21354
  this.connectedUsers = {};
21354
21355
  this.callbacks?.onConnectedUsersChanged?.({});
@@ -21416,7 +21417,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
21416
21417
  onInit() {
21417
21418
  const store = this.instance.getStore();
21418
21419
  const stage = this.instance.getStage();
21419
- store.onAwarenessChange((changes) => {
21420
+ this.instance.addEventListener("onAwarenessChange", (changes) => {
21420
21421
  const selfUser = this.config.getUser();
21421
21422
  for (const change of changes) {
21422
21423
  if (!change[WEAVE_USER_POINTER_KEY]) continue;
@@ -21681,9 +21682,9 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21681
21682
  this.enabled = enabled;
21682
21683
  }
21683
21684
  evaluateGuidelines(e) {
21684
- const mainLayer = this.instance.getMainLayer();
21685
+ const utilityLayer = this.instance.getUtilityLayer();
21685
21686
  if (!this.enabled) return;
21686
- if (!mainLayer) return;
21687
+ if (!utilityLayer) return;
21687
21688
  let node = void 0;
21688
21689
  if (e.type === "dragmove" && e.target instanceof Konva.Transformer) {
21689
21690
  const actualTarget = e.target;
@@ -21691,11 +21692,11 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21691
21692
  }
21692
21693
  if (e.type === "transform") node = e.target;
21693
21694
  if (typeof node === "undefined") return;
21694
- mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21695
21695
  const lineGuideStops = this.getLineGuideStops(node);
21696
21696
  const itemBounds = this.getObjectSnappingEdges(node);
21697
21697
  const guides = this.getGuides(lineGuideStops, itemBounds, e.type);
21698
21698
  if (!guides.length) return;
21699
+ utilityLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21699
21700
  this.drawGuides(guides);
21700
21701
  if (e.type === "dragmove") {
21701
21702
  const absPos = node.absolutePosition();
@@ -21719,41 +21720,41 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21719
21720
  const transformer = nodesSelectionPlugin.getTransformer();
21720
21721
  transformer.anchorDragBoundFunc((_, newAbsPos) => {
21721
21722
  const finalPos = { ...newAbsPos };
21722
- guides.forEach((lg) => {
21723
- switch (lg.orientation) {
21724
- case GUIDE_ORIENTATION.VERTICAL: {
21725
- const distX = Math.sqrt(Math.pow(newAbsPos.x - lg.lineGuide, 2));
21726
- if (distX < this.transformSnappingThreshold) finalPos.x = lg.lineGuide;
21727
- break;
21728
- }
21729
- case GUIDE_ORIENTATION.HORIZONTAL: {
21730
- const distY = Math.sqrt(Math.pow(newAbsPos.y - lg.lineGuide, 2));
21731
- if (distY < this.transformSnappingThreshold) finalPos.y = lg.lineGuide;
21732
- break;
21733
- }
21723
+ for (const lg of guides) switch (lg.orientation) {
21724
+ case GUIDE_ORIENTATION.VERTICAL: {
21725
+ const distX = Math.sqrt(Math.pow(newAbsPos.x - lg.lineGuide, 2));
21726
+ if (distX < this.transformSnappingThreshold) finalPos.x = lg.lineGuide;
21727
+ break;
21734
21728
  }
21735
- });
21729
+ case GUIDE_ORIENTATION.HORIZONTAL: {
21730
+ const distY = Math.sqrt(Math.pow(newAbsPos.y - lg.lineGuide, 2));
21731
+ if (distY < this.transformSnappingThreshold) finalPos.y = lg.lineGuide;
21732
+ break;
21733
+ }
21734
+ }
21736
21735
  return finalPos;
21737
21736
  });
21738
21737
  }
21739
21738
  }
21740
21739
  }
21741
21740
  cleanupEvaluateGuidelines() {
21742
- const mainLayer = this.instance.getMainLayer();
21741
+ const utilityLayer = this.instance.getUtilityLayer();
21743
21742
  if (!this.enabled) return;
21744
- if (!mainLayer) return;
21745
- mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21743
+ if (!utilityLayer) return;
21744
+ utilityLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
21746
21745
  }
21747
21746
  initEvents() {
21748
21747
  const stage = this.instance.getStage();
21749
- const mainLayer = this.instance.getMainLayer();
21750
- if (mainLayer) {
21748
+ const utilityLayer = this.instance.getUtilityLayer();
21749
+ if (utilityLayer) {
21751
21750
  stage.on("dragmove", this.evaluateGuidelines.bind(this));
21752
21751
  stage.on("dragend", this.cleanupEvaluateGuidelines.bind(this));
21753
21752
  }
21754
21753
  }
21755
21754
  getLineGuideStops(skipShape) {
21756
21755
  const stage = this.instance.getStage();
21756
+ const nodesSelection = this.instance.getPlugin("nodesSelection");
21757
+ if (nodesSelection) nodesSelection.getTransformer().hide();
21757
21758
  const vertical = [
21758
21759
  0,
21759
21760
  stage.width() / 2,
@@ -21766,7 +21767,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21766
21767
  ];
21767
21768
  stage.find(".node").forEach((guideItem) => {
21768
21769
  if (guideItem === skipShape) return;
21769
- const box = guideItem.getClientRect();
21770
+ const box = guideItem.getClientRect({ skipStroke: true });
21770
21771
  vertical.push([
21771
21772
  box.x,
21772
21773
  box.x + box.width,
@@ -21778,28 +21779,29 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21778
21779
  box.y + box.height / 2
21779
21780
  ]);
21780
21781
  });
21782
+ if (nodesSelection) nodesSelection.getTransformer().show();
21781
21783
  return {
21782
21784
  vertical: vertical.flat(),
21783
21785
  horizontal: horizontal.flat()
21784
21786
  };
21785
21787
  }
21786
21788
  getObjectSnappingEdges(node) {
21787
- const box = node.getClientRect();
21789
+ const box = node.getClientRect({ skipStroke: true });
21788
21790
  const absPos = node.absolutePosition();
21789
21791
  const snappingEdges = {
21790
21792
  vertical: [
21791
21793
  {
21792
- guide: Math.round(box.x),
21794
+ guide: box.x,
21793
21795
  offset: Math.round(absPos.x - box.x),
21794
21796
  snap: NODE_SNAP.START
21795
21797
  },
21796
21798
  {
21797
- guide: Math.round(box.x + box.width / 2),
21799
+ guide: box.x + box.width / 2,
21798
21800
  offset: Math.round(absPos.x - box.x - box.width / 2),
21799
21801
  snap: NODE_SNAP.CENTER
21800
21802
  },
21801
21803
  {
21802
- guide: Math.round(box.x + box.width),
21804
+ guide: box.x + box.width,
21803
21805
  offset: Math.round(absPos.x - box.x - box.width),
21804
21806
  snap: NODE_SNAP.END
21805
21807
  }
@@ -21888,8 +21890,8 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21888
21890
  }
21889
21891
  drawGuides(guides) {
21890
21892
  const stage = this.instance.getStage();
21891
- const mainLayer = this.instance.getMainLayer();
21892
- if (mainLayer) guides.forEach((lg) => {
21893
+ const utilityLayer = this.instance.getUtilityLayer();
21894
+ if (utilityLayer) guides.forEach((lg) => {
21893
21895
  if (lg.orientation === GUIDE_ORIENTATION.HORIZONTAL) {
21894
21896
  const line = new Konva.Line({
21895
21897
  ...this.guideLineConfig,
@@ -21903,7 +21905,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21903
21905
  ],
21904
21906
  name: GUIDE_LINE_NAME
21905
21907
  });
21906
- mainLayer.add(line);
21908
+ utilityLayer.add(line);
21907
21909
  line.absolutePosition({
21908
21910
  x: 0,
21909
21911
  y: lg.lineGuide
@@ -21922,7 +21924,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
21922
21924
  ],
21923
21925
  name: GUIDE_LINE_NAME
21924
21926
  });
21925
- mainLayer.add(line);
21927
+ utilityLayer.add(line);
21926
21928
  line.absolutePosition({
21927
21929
  x: lg.lineGuide,
21928
21930
  y: 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -43,7 +43,7 @@
43
43
  "version:release": "npm version $RELEASE_VERSION -m \"[npm-scripts] prepare release $RELEASE_VERSION\" --tag-version-prefix \"\""
44
44
  },
45
45
  "dependencies": {
46
- "@inditextech/weave-types": "0.7.0",
46
+ "@inditextech/weave-types": "0.8.0",
47
47
  "@syncedstore/core": "0.6.0",
48
48
  "canvas": "3.1.0",
49
49
  "konva": "9.3.20",