@inditextech/weave-sdk 2.18.1 → 2.20.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.js CHANGED
@@ -20080,7 +20080,8 @@ var WeaveNode = class {
20080
20080
  register(instance) {
20081
20081
  this.instance = instance;
20082
20082
  this.logger = this.instance.getChildLogger(this.getNodeType());
20083
- this.instance.getChildLogger("node").debug(`Node with type [${this.getNodeType()}] registered`);
20083
+ this.onRegister();
20084
+ this.instance.getChildLogger(`node-${this.getNodeType()}`).debug(`Node with type [${this.getNodeType()}] registered`);
20084
20085
  return this;
20085
20086
  }
20086
20087
  getNodeType() {
@@ -20568,6 +20569,7 @@ var WeaveNode = class {
20568
20569
  }
20569
20570
  };
20570
20571
  }
20572
+ onRegister() {}
20571
20573
  onAdd(nodeInstance) {}
20572
20574
  onDestroy(nodeInstance) {
20573
20575
  nodeInstance.destroy();
@@ -22076,7 +22078,7 @@ var WeaveRegisterManager = class {
22076
22078
 
22077
22079
  //#endregion
22078
22080
  //#region package.json
22079
- var version = "2.18.1";
22081
+ var version = "2.20.0";
22080
22082
 
22081
22083
  //#endregion
22082
22084
  //#region src/managers/setup.ts
@@ -22769,6 +22771,7 @@ function watchMap(onChange, map = new Map()) {
22769
22771
  //#endregion
22770
22772
  //#region src/managers/async/async.ts
22771
22773
  var WeaveAsyncManager = class {
22774
+ asyncElementsLoadedEventEmitted = false;
22772
22775
  constructor(instance) {
22773
22776
  this.instance = instance;
22774
22777
  this.logger = this.instance.getChildLogger("async-manager");
@@ -22780,6 +22783,12 @@ var WeaveAsyncManager = class {
22780
22783
  asyncElementsLoaded() {
22781
22784
  return [...this.asyncElements.values()].every((el) => el.status === WEAVE_ASYNC_STATUS.LOADED);
22782
22785
  }
22786
+ getAmountAsyncElements() {
22787
+ return [...this.asyncElements.values()].length;
22788
+ }
22789
+ getAmountAsyncElementsLoaded() {
22790
+ return [...this.asyncElements.values()].filter((el) => el.status === WEAVE_ASYNC_STATUS.LOADED).length;
22791
+ }
22783
22792
  loadAsyncElement(nodeId, type) {
22784
22793
  let element = this.asyncElements.get(nodeId);
22785
22794
  if (element) element.status = WEAVE_ASYNC_STATUS.LOADING;
@@ -22788,6 +22797,10 @@ var WeaveAsyncManager = class {
22788
22797
  status: WEAVE_ASYNC_STATUS.LOADING
22789
22798
  };
22790
22799
  this.asyncElements.set(nodeId, element);
22800
+ this.instance.emitEvent("onAsyncElementsLoading", {
22801
+ loaded: this.getAmountAsyncElementsLoaded(),
22802
+ total: this.getAmountAsyncElements()
22803
+ });
22791
22804
  }
22792
22805
  resolveAsyncElement(nodeId, type) {
22793
22806
  let element = this.asyncElements.get(nodeId);
@@ -22797,6 +22810,17 @@ var WeaveAsyncManager = class {
22797
22810
  status: WEAVE_ASYNC_STATUS.LOADED
22798
22811
  };
22799
22812
  this.asyncElements.set(nodeId, element);
22813
+ this.instance.emitEvent("onAsyncElementsLoading", {
22814
+ loaded: this.getAmountAsyncElementsLoaded(),
22815
+ total: this.getAmountAsyncElements()
22816
+ });
22817
+ if (!this.asyncElementsLoadedEventEmitted) {
22818
+ const allLoaded = this.asyncElementsLoaded();
22819
+ if (allLoaded) {
22820
+ this.instance.emitEvent("onAsyncElementsLoaded");
22821
+ this.asyncElementsLoadedEventEmitted = true;
22822
+ }
22823
+ }
22800
22824
  }
22801
22825
  };
22802
22826
 
@@ -24455,6 +24479,10 @@ var WeaveTextNode = class extends WeaveNode {
24455
24479
  this.instance.addEventListener("onNodeRenderedAdded", (node) => {
24456
24480
  if (node.id() === text.id() && node.getParent() !== text.getParent()) text.getAttr("cancelEditMode")?.();
24457
24481
  });
24482
+ if (!this.instance.isServerSide() && !this.keyPressHandler) {
24483
+ this.keyPressHandler = this.handleKeyPress.bind(this);
24484
+ window.addEventListener("keypress", this.keyPressHandler);
24485
+ }
24458
24486
  return text;
24459
24487
  }
24460
24488
  onUpdate(nodeInstance, nextProps) {
@@ -24880,6 +24908,7 @@ var WeaveImageCrop = class WeaveImageCrop {
24880
24908
  if (nodeDistanceSnappingPlugin) nodeDistanceSnappingPlugin.disable();
24881
24909
  const nodesSelectionPlugin = this.getNodesSelectionPlugin();
24882
24910
  if (nodesSelectionPlugin) nodesSelectionPlugin.disable();
24911
+ this.node.clearCache(this.image);
24883
24912
  this.image.setAttrs({ cropping: true });
24884
24913
  const imageAttrs = this.image.getAttrs();
24885
24914
  this.internalImage.hide();
@@ -25058,6 +25087,7 @@ var WeaveImageCrop = class WeaveImageCrop {
25058
25087
  if (nodesSelectionPlugin) nodesSelectionPlugin.enable();
25059
25088
  stage.mode(WEAVE_STAGE_DEFAULT_MODE);
25060
25089
  this.instance.releaseMutexLock();
25090
+ this.node.cacheNode(this.image);
25061
25091
  this.instance.emitEvent("onImageCropEnd", { instance: this.image });
25062
25092
  }
25063
25093
  drawGridLines(x, y, width, height) {
@@ -25119,6 +25149,7 @@ var WeaveImageCrop = class WeaveImageCrop {
25119
25149
  this.image.setAbsolutePosition(cropImageStage);
25120
25150
  this.image.attrs.cropInfo = void 0;
25121
25151
  this.instance.updateNode(this.node.serialize(this.image));
25152
+ this.node.cacheNode(this.image);
25122
25153
  }
25123
25154
  handleClipEnd() {
25124
25155
  const clipRect = this.cropRect.getClientRect({ relativeTo: this.cropGroup });
@@ -25215,11 +25246,15 @@ const WEAVE_IMAGE_CROP_END_TYPE = {
25215
25246
  ["ACCEPT"]: "accept",
25216
25247
  ["CANCEL"]: "cancel"
25217
25248
  };
25218
- const WEAVE_IMAGE_DEFAULT_CONFIG = { crossOrigin: "anonymous" };
25249
+ const WEAVE_IMAGE_DEFAULT_CONFIG = {
25250
+ performance: { cache: { enabled: false } },
25251
+ crossOrigin: "anonymous"
25252
+ };
25219
25253
 
25220
25254
  //#endregion
25221
25255
  //#region src/nodes/image/image.ts
25222
25256
  var WeaveImageNode = class extends WeaveNode {
25257
+ imageBitmapCache = {};
25223
25258
  imageSource = {};
25224
25259
  imageState = {};
25225
25260
  nodeType = WEAVE_IMAGE_NODE_TYPE;
@@ -25235,6 +25270,9 @@ var WeaveImageNode = class extends WeaveNode {
25235
25270
  this.config = mergeExceptArrays(WEAVE_IMAGE_DEFAULT_CONFIG, config);
25236
25271
  this.imageCrop = null;
25237
25272
  }
25273
+ onRegister() {
25274
+ this.logger.info(`image caching enabled: ${this.config.performance.cache.enabled}`);
25275
+ }
25238
25276
  triggerCrop(imageNode) {
25239
25277
  const stage = this.instance.getStage();
25240
25278
  if (imageNode.getAttrs().cropping ?? false) return;
@@ -25384,8 +25422,9 @@ var WeaveImageNode = class extends WeaveNode {
25384
25422
  };
25385
25423
  if (this.imageSource[id]) {
25386
25424
  imagePlaceholder.destroy();
25425
+ const imageSource = this.imageSource[id];
25387
25426
  internalImage.setAttrs({
25388
- image: this.imageSource[id],
25427
+ image: imageSource,
25389
25428
  visible: true
25390
25429
  });
25391
25430
  image.setAttr("imageInfo", {
@@ -25409,14 +25448,27 @@ var WeaveImageNode = class extends WeaveNode {
25409
25448
  this.updatePlaceholderSize(image, imagePlaceholder);
25410
25449
  this.loadImage(imageProps, image);
25411
25450
  }
25451
+ if (this.config.performance.cache.enabled) image.on("transformend", () => {
25452
+ this.cacheNode(image);
25453
+ });
25412
25454
  image.setAttr("imageURL", imageProps.imageURL);
25413
25455
  this.instance.addEventListener("onNodeRenderedAdded", (node) => {
25414
25456
  if (node.id() === image.id() && node.getParent() !== image.getParent()) {
25415
25457
  if (this.imageCrop) this.closeCrop(image, WEAVE_IMAGE_CROP_END_TYPE.CANCEL);
25416
25458
  }
25417
25459
  });
25460
+ this.cacheNode(image);
25418
25461
  return image;
25419
25462
  }
25463
+ clearCache(nodeInstance) {
25464
+ if (this.config.performance.cache.enabled) nodeInstance.clearCache();
25465
+ }
25466
+ cacheNode(nodeInstance) {
25467
+ if (this.config.performance.cache.enabled) {
25468
+ nodeInstance.clearCache();
25469
+ nodeInstance.cache({ pixelRatio: this.config.performance.cache.pixelRatio });
25470
+ }
25471
+ }
25420
25472
  onUpdate(nodeInstance, nextProps) {
25421
25473
  const id = nodeInstance.getAttrs().id;
25422
25474
  const node = nodeInstance;
@@ -25516,6 +25568,7 @@ var WeaveImageNode = class extends WeaveNode {
25516
25568
  });
25517
25569
  this.updateImageCrop(nodeInstance);
25518
25570
  }
25571
+ this.cacheNode(nodeInstance);
25519
25572
  }
25520
25573
  preloadImage(imageId, imageURL, { onLoad, onError }) {
25521
25574
  const realImageURL = this.config.urlTransformer?.(imageURL ?? "") ?? imageURL;
@@ -25530,7 +25583,7 @@ var WeaveImageNode = class extends WeaveNode {
25530
25583
  delete this.imageState[imageId];
25531
25584
  onError(error);
25532
25585
  };
25533
- this.imageSource[imageId].onload = () => {
25586
+ this.imageSource[imageId].onload = async () => {
25534
25587
  this.imageState[imageId] = {
25535
25588
  loaded: true,
25536
25589
  error: false
@@ -25562,10 +25615,11 @@ var WeaveImageNode = class extends WeaveNode {
25562
25615
  height: imageProps.height ? imageProps.height : this.imageSource[id].height
25563
25616
  });
25564
25617
  imagePlaceholder.destroy();
25618
+ const imageSource = this.imageSource[id];
25565
25619
  internalImage.setAttrs({
25566
25620
  width: imageProps.width ? imageProps.width : this.imageSource[id].width,
25567
25621
  height: imageProps.height ? imageProps.height : this.imageSource[id].height,
25568
- image: this.imageSource[id],
25622
+ image: imageSource,
25569
25623
  visible: true
25570
25624
  });
25571
25625
  internalImage.setAttr("imageInfo", {
@@ -25588,6 +25642,7 @@ var WeaveImageNode = class extends WeaveNode {
25588
25642
  };
25589
25643
  this.updateImageCrop(image);
25590
25644
  this.resolveAsyncElement(id);
25645
+ this.cacheNode(image);
25591
25646
  }
25592
25647
  },
25593
25648
  onError: (error) => {
@@ -25612,6 +25667,7 @@ var WeaveImageNode = class extends WeaveNode {
25612
25667
  console.error("Error loading image", realImageURL, error);
25613
25668
  imagePlaceholder?.setAttrs({ visible: true });
25614
25669
  internalImage?.setAttrs({ visible: false });
25670
+ this.cacheNode(image);
25615
25671
  }
25616
25672
  });
25617
25673
  }
@@ -31609,13 +31665,14 @@ var WeaveBrushToolAction = class extends WeaveAction {
31609
31665
  this.cancelAction();
31610
31666
  return;
31611
31667
  }
31612
- if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.isSpacePressed = true;
31613
- if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
31614
- this.cancelAction();
31668
+ if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
31669
+ this.isSpacePressed = true;
31615
31670
  return;
31616
31671
  }
31672
+ if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.cancelAction();
31617
31673
  });
31618
31674
  const handlePointerDown = (e) => {
31675
+ if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
31619
31676
  if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
31620
31677
  if (this.getZoomPlugin()?.isPinching()) return;
31621
31678
  if (this.isSpacePressed) return;