@inditextech/weave-sdk 2.20.0 → 2.20.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.js CHANGED
@@ -20366,22 +20366,27 @@ var WeaveNode = class {
20366
20366
  }
20367
20367
  const realNodeTarget = this.getRealSelectedNode(nodeTarget);
20368
20368
  if (realNodeTarget.getAttrs().isCloned) return;
20369
- originalNode = realNodeTarget.clone();
20370
- originalContainer = realNodeTarget.getParent();
20371
- if (originalContainer?.getAttrs().nodeId) originalContainer = stage.findOne(`#${originalContainer.getAttrs().nodeId}`);
20372
20369
  if (this.getNodesSelectionPlugin()?.getSelectedNodes().length === 1 && realNodeTarget.getAttr("dragStartOpacity") === void 0) {
20373
20370
  realNodeTarget.setAttr("dragStartOpacity", realNodeTarget.opacity());
20374
20371
  realNodeTarget.opacity(this.getNodesSelectionPlugin()?.getDragOpacity());
20375
20372
  }
20373
+ originalNode = realNodeTarget.clone();
20374
+ originalContainer = realNodeTarget.getParent();
20375
+ if (originalContainer?.getAttrs().nodeId) originalContainer = stage.findOne(`#${originalContainer.getAttrs().nodeId}`);
20376
20376
  if (e.evt?.altKey) {
20377
20377
  nodeTarget.setAttrs({ isCloneOrigin: true });
20378
20378
  nodeTarget.setAttrs({ isCloned: false });
20379
20379
  nodeTarget.stopDrag(e.evt);
20380
20380
  e.cancelBubble = true;
20381
20381
  const clone = this.instance.getCloningManager().cloneNode(realNodeTarget);
20382
+ const originalNodeOpacity = realNodeTarget.getAttr("dragStartOpacity") ?? 1;
20383
+ realNodeTarget.setAttrs({ opacity: originalNodeOpacity });
20384
+ realNodeTarget.setAttr("dragStartOpacity", void 0);
20382
20385
  if (clone && !this.instance.getCloningManager().isClone(clone)) {
20383
- clone.setAttrs({ isCloneOrigin: false });
20384
- clone.setAttrs({ isCloned: true });
20386
+ clone.setAttrs({
20387
+ isCloneOrigin: false,
20388
+ isCloned: true
20389
+ });
20385
20390
  this.instance.getCloningManager().addClone(clone);
20386
20391
  }
20387
20392
  stage.setPointersPositions(e.evt);
@@ -20704,6 +20709,9 @@ var WeaveNode = class {
20704
20709
  const usersPresencePlugin = this.instance.getPlugin(WEAVE_USERS_PRESENCE_PLUGIN_KEY);
20705
20710
  return usersPresencePlugin;
20706
20711
  }
20712
+ getIsAsync() {
20713
+ return false;
20714
+ }
20707
20715
  };
20708
20716
 
20709
20717
  //#endregion
@@ -22078,7 +22086,7 @@ var WeaveRegisterManager = class {
22078
22086
 
22079
22087
  //#endregion
22080
22088
  //#region package.json
22081
- var version = "2.20.0";
22089
+ var version = "2.20.2";
22082
22090
 
22083
22091
  //#endregion
22084
22092
  //#region src/managers/setup.ts
@@ -22779,6 +22787,34 @@ var WeaveAsyncManager = class {
22779
22787
  this.asyncElements = watchMap(() => {
22780
22788
  this.instance.emitEvent("onAsyncElementChange");
22781
22789
  }, new Map());
22790
+ this.instance.addEventListener("onRoomLoaded", (isRoomLoaded) => {
22791
+ if (!isRoomLoaded) return;
22792
+ const roomHasResourcesToLoad = this.roomHasResourcesToLoad();
22793
+ if (!roomHasResourcesToLoad && !this.asyncElementsLoadedEventEmitted) {
22794
+ this.instance.emitEvent("onAsyncElementsLoaded");
22795
+ this.asyncElementsLoadedEventEmitted = true;
22796
+ }
22797
+ });
22798
+ }
22799
+ extractAsyncElements(state) {
22800
+ const asyncElements = [];
22801
+ const traverse = (element) => {
22802
+ const nodeHandler = this.instance.getNodeHandler(element.type);
22803
+ if (nodeHandler?.getIsAsync()) asyncElements.push(element);
22804
+ const children = element.props?.children;
22805
+ if (Array.isArray(children)) for (const child of children) traverse(child);
22806
+ };
22807
+ if ("key" in state.weave && state.weave.key === "stage") {
22808
+ const children = state.weave.props.children ?? [];
22809
+ for (const child of children) traverse(child);
22810
+ } else for (const element of Object.values(state.weave)) traverse(element);
22811
+ return asyncElements;
22812
+ }
22813
+ roomHasResourcesToLoad() {
22814
+ const roomData = this.instance.getStore().getState();
22815
+ const jsonRoomData = JSON.parse(JSON.stringify(roomData));
22816
+ const asyncElements = this.extractAsyncElements(jsonRoomData);
22817
+ return asyncElements.length > 0;
22782
22818
  }
22783
22819
  asyncElementsLoaded() {
22784
22820
  return [...this.asyncElements.values()].every((el) => el.status === WEAVE_ASYNC_STATUS.LOADED);
@@ -25457,7 +25493,6 @@ var WeaveImageNode = class extends WeaveNode {
25457
25493
  if (this.imageCrop) this.closeCrop(image, WEAVE_IMAGE_CROP_END_TYPE.CANCEL);
25458
25494
  }
25459
25495
  });
25460
- this.cacheNode(image);
25461
25496
  return image;
25462
25497
  }
25463
25498
  clearCache(nodeInstance) {
@@ -25765,6 +25800,9 @@ var WeaveImageNode = class extends WeaveNode {
25765
25800
  y: 1
25766
25801
  });
25767
25802
  }
25803
+ getIsAsync() {
25804
+ return true;
25805
+ }
25768
25806
  };
25769
25807
 
25770
25808
  //#endregion
@@ -27774,6 +27812,9 @@ var WeaveVideoNode = class extends WeaveNode {
27774
27812
  y: 1
27775
27813
  });
27776
27814
  }
27815
+ getIsAsync() {
27816
+ return true;
27817
+ }
27777
27818
  };
27778
27819
 
27779
27820
  //#endregion
@@ -29793,6 +29834,9 @@ var WeaveConnectorNode = class extends WeaveNode {
29793
29834
  }
29794
29835
  return result;
29795
29836
  };
29837
+ getIsAsync() {
29838
+ return true;
29839
+ }
29796
29840
  };
29797
29841
 
29798
29842
  //#endregion
@@ -29895,6 +29939,8 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
29895
29939
  actScale.y = scale;
29896
29940
  stage.scale(actScale);
29897
29941
  this.actualScale = scale;
29942
+ this.actualStep = this.findClosestStepIndex(oldScale < scale ? "zoomOut" : "zoomIn");
29943
+ this.actualScale = scale;
29898
29944
  if (centered) {
29899
29945
  const stageCenter = {
29900
29946
  x: stage.width() / 2,
@@ -29940,13 +29986,13 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
29940
29986
  canZoomOut() {
29941
29987
  if (!this.enabled) return false;
29942
29988
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
29943
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomOut");
29989
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomIn");
29944
29990
  return this.actualStep - 1 >= 0;
29945
29991
  }
29946
29992
  canZoomIn() {
29947
29993
  if (!this.enabled) return false;
29948
29994
  const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
29949
- if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomIn");
29995
+ if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex("zoomOut");
29950
29996
  return this.actualStep + 1 < this.config.zoomSteps.length;
29951
29997
  }
29952
29998
  zoomToStep(step) {
@@ -29996,7 +30042,8 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
29996
30042
  const scale = Math.min(scaleX, scaleY);
29997
30043
  return scale;
29998
30044
  }
29999
- fitToScreen() {
30045
+ fitToScreen(options) {
30046
+ const finalOptions = mergeExceptArrays({ overrideZoom: true }, options);
30000
30047
  if (!this.enabled) return;
30001
30048
  const stage = this.instance.getStage();
30002
30049
  const mainLayer = this.instance.getMainLayer();
@@ -30033,8 +30080,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30033
30080
  const upscaleScale = stage.getAttr("upscaleScale");
30034
30081
  const stageWidth = stage.width();
30035
30082
  const stageHeight = stage.height();
30036
- const scaleX = (stageWidth - this.config.fitToScreen.padding * 2 / upscaleScale) / bounds.width;
30037
- const scaleY = (stageHeight - this.config.fitToScreen.padding * 2 / upscaleScale) / bounds.height;
30083
+ let scaleX = (stageWidth - this.config.fitToScreen.padding * 2 / upscaleScale) / bounds.width;
30084
+ let scaleY = (stageHeight - this.config.fitToScreen.padding * 2 / upscaleScale) / bounds.height;
30085
+ if (!finalOptions.overrideZoom) {
30086
+ scaleX = this.clamp(scaleX, this.config.zoomSteps[0], this.config.zoomSteps[this.config.zoomSteps.length - 1]);
30087
+ scaleY = this.clamp(scaleY, this.config.zoomSteps[0], this.config.zoomSteps[this.config.zoomSteps.length - 1]);
30088
+ }
30038
30089
  const scale = Math.min(scaleX, scaleY);
30039
30090
  const offsetX = bounds.x + bounds.width / 2;
30040
30091
  const offsetY = bounds.y + bounds.height / 2;
@@ -30048,7 +30099,11 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30048
30099
  });
30049
30100
  this.setZoom(scale, false);
30050
30101
  }
30051
- fitToElements(box, smartZoom = false) {
30102
+ fitToElements(box, options) {
30103
+ const finalOptions = mergeExceptArrays({
30104
+ smartZoom: false,
30105
+ overrideZoom: true
30106
+ }, options);
30052
30107
  const stage = this.instance.getStage();
30053
30108
  const container = stage.container();
30054
30109
  const scale = stage.scale();
@@ -30061,7 +30116,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30061
30116
  x: box.x + box.width / 2,
30062
30117
  y: box.y + box.height / 2
30063
30118
  };
30064
- if (smartZoom && fitsInView) {
30119
+ if (finalOptions.smartZoom && fitsInView) {
30065
30120
  const newPosition = {
30066
30121
  x: containerWidth / 2 - selectionCenter.x * scale.x,
30067
30122
  y: containerHeight / 2 - selectionCenter.y * scale.y
@@ -30081,8 +30136,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30081
30136
  };
30082
30137
  const availableScreenWidth = stageBox.width - 2 * this.config.fitToSelection.padding / upscaleScale;
30083
30138
  const availableScreenHeight = stageBox.height - 2 * this.config.fitToSelection.padding / upscaleScale;
30084
- const scaleX = availableScreenWidth / box.width;
30085
- const scaleY = availableScreenHeight / box.height;
30139
+ let scaleX = availableScreenWidth / box.width;
30140
+ let scaleY = availableScreenHeight / box.height;
30141
+ if (!finalOptions.overrideZoom) {
30142
+ scaleX = this.clamp(scaleX, this.config.zoomSteps[0], this.config.zoomSteps[this.config.zoomSteps.length - 1]);
30143
+ scaleY = this.clamp(scaleY, this.config.zoomSteps[0], this.config.zoomSteps[this.config.zoomSteps.length - 1]);
30144
+ }
30086
30145
  const finalScale = Math.min(scaleX, scaleY);
30087
30146
  stage.scale({
30088
30147
  x: finalScale,
@@ -30100,16 +30159,24 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30100
30159
  });
30101
30160
  this.setZoom(finalScale, false);
30102
30161
  }
30103
- fitToNodes(nodes, smartZoom = false) {
30162
+ fitToNodes(nodes, options) {
30163
+ const finalOptions = mergeExceptArrays({
30164
+ smartZoom: false,
30165
+ overrideZoom: true
30166
+ }, options);
30104
30167
  if (!this.enabled) return;
30105
30168
  const stage = this.instance.getStage();
30106
30169
  if (nodes.length === 0) return;
30107
30170
  const nodesInstances = nodes.map((nodeId) => this.instance.getStage().findOne(`#${nodeId}`)).filter((node) => node !== null);
30108
30171
  const box = getBoundingBox(nodesInstances, { relativeTo: stage });
30109
30172
  if (box.width === 0 || box.height === 0) return;
30110
- this.fitToElements(box, smartZoom);
30173
+ this.fitToElements(box, finalOptions);
30111
30174
  }
30112
- fitToSelection(smartZoom = false) {
30175
+ fitToSelection(options) {
30176
+ const finalOptions = mergeExceptArrays({
30177
+ smartZoom: false,
30178
+ overrideZoom: true
30179
+ }, options);
30113
30180
  if (!this.enabled) return;
30114
30181
  const stage = this.instance.getStage();
30115
30182
  const selectionPlugin = this.getNodesSelectionPlugin();
@@ -30118,7 +30185,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30118
30185
  if (nodes.length === 0) return;
30119
30186
  const box = getBoundingBox(selectionPlugin.getTransformer().getNodes(), { relativeTo: stage });
30120
30187
  if (box.width === 0 || box.height === 0) return;
30121
- this.fitToElements(box, smartZoom);
30188
+ this.fitToElements(box, finalOptions);
30122
30189
  }
30123
30190
  enable() {
30124
30191
  this.enabled = true;
@@ -30284,6 +30351,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
30284
30351
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
30285
30352
  return contextMenuPlugin;
30286
30353
  }
30354
+ getZoomSteps() {
30355
+ return this.config.zoomSteps;
30356
+ }
30357
+ clamp(value, min, max) {
30358
+ return Math.min(Math.max(value, min), max);
30359
+ }
30287
30360
  };
30288
30361
 
30289
30362
  //#endregion
@@ -30375,7 +30448,7 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
30375
30448
  }
30376
30449
  trigger(cancelAction, params) {
30377
30450
  const stageZoomPlugin = this.getStageZoomPlugin();
30378
- if (stageZoomPlugin) stageZoomPlugin.fitToScreen();
30451
+ if (stageZoomPlugin) stageZoomPlugin.fitToScreen({ overrideZoom: params?.overrideZoom ?? true });
30379
30452
  this.previousAction = params.previousAction;
30380
30453
  this.cancelAction = cancelAction;
30381
30454
  this.cancelAction();
@@ -30414,7 +30487,10 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
30414
30487
  }
30415
30488
  trigger(cancelAction, params) {
30416
30489
  const stageZoomPlugin = this.getStageZoomPlugin();
30417
- stageZoomPlugin.fitToSelection(params?.smartZoom ?? false);
30490
+ stageZoomPlugin.fitToSelection({
30491
+ smartZoom: params?.smartZoom ?? false,
30492
+ overrideZoom: params?.overrideZoom ?? true
30493
+ });
30418
30494
  this.previousAction = params.previousAction;
30419
30495
  this.cancelAction = cancelAction;
30420
30496
  this.cancelAction();