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