@inditextech/weave-sdk 3.2.0-SNAPSHOT.93.1 → 3.2.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
@@ -15152,6 +15152,7 @@ var WeaveStore = class {
15152
15152
  });
15153
15153
  }
15154
15154
  if (!this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) {
15155
+ this.instance.checkForAsyncElements();
15155
15156
  this.instance.setupRenderer();
15156
15157
  this.isRoomLoaded = true;
15157
15158
  this.emitOnRoomLoadedEvent();
@@ -17833,8 +17834,7 @@ function getTargetAndSkipNodes(instance, e, forceTransformer = false) {
17833
17834
  }
17834
17835
  if (e.type === "transform" && nodesSelectionPlugin) {
17835
17836
  node = e.target;
17836
- skipNodes.push(node.getAttrs().id ?? "");
17837
- skipNodes.push(...nodesSelectionPlugin.getTransformer().nodes().map((node$1) => node$1.getAttrs().id ?? ""));
17837
+ skipNodes.push(node.getAttrs().id ?? "", ...nodesSelectionPlugin.getTransformer().nodes().map((node$1) => node$1.getAttrs().id ?? ""));
17838
17838
  }
17839
17839
  return {
17840
17840
  targetNode: forceTransformer ? nodesSelectionPlugin.getTransformer() : node,
@@ -20147,10 +20147,10 @@ const augmentKonvaNodeClass = (config) => {
20147
20147
  Konva.Node.prototype.dblClick = function() {};
20148
20148
  };
20149
20149
  var WeaveNode = class {
20150
- register(instance) {
20150
+ async register(instance) {
20151
20151
  this.instance = instance;
20152
20152
  this.logger = this.instance.getChildLogger(this.getNodeType());
20153
- this.onRegister();
20153
+ await this.onRegister();
20154
20154
  this.instance.getChildLogger(`node-${this.getNodeType()}`).debug(`Node with type [${this.getNodeType()}] registered`);
20155
20155
  return this;
20156
20156
  }
@@ -20722,7 +20722,9 @@ var WeaveNode = class {
20722
20722
  }
20723
20723
  };
20724
20724
  }
20725
- onRegister() {}
20725
+ async onRegister() {
20726
+ return;
20727
+ }
20726
20728
  onAdd(nodeInstance) {}
20727
20729
  onDestroy(nodeInstance) {
20728
20730
  nodeInstance.destroy();
@@ -21910,19 +21912,19 @@ var WeaveRegisterManager = class {
21910
21912
  plugin.register(this.instance);
21911
21913
  this.plugins[pluginName] = plugin;
21912
21914
  }
21913
- registerNodesHandlers() {
21915
+ async registerNodesHandlers() {
21914
21916
  const config = this.instance.getConfiguration();
21915
- if (config.nodes) for (const node of config.nodes) this.registerNodeHandler(node);
21917
+ if (config.nodes) for (const node of config.nodes) await this.registerNodeHandler(node);
21916
21918
  this.logger.info(`Nodes handlers registered`);
21917
21919
  }
21918
- registerNodeHandler(node) {
21920
+ async registerNodeHandler(node) {
21919
21921
  const nodeType = node.getNodeType();
21920
21922
  if (this.nodesHandlers[nodeType]) {
21921
21923
  const msg = `Node handler with type [${nodeType}] already exists`;
21922
21924
  this.logger.error(msg);
21923
21925
  throw new Error(msg);
21924
21926
  }
21925
- node.register(this.instance);
21927
+ await node.register(this.instance);
21926
21928
  this.nodesHandlers[nodeType] = node;
21927
21929
  }
21928
21930
  registerActionsHandlers() {
@@ -21954,7 +21956,7 @@ var WeaveRegisterManager = class {
21954
21956
 
21955
21957
  //#endregion
21956
21958
  //#region package.json
21957
- var version = "3.2.0-SNAPSHOT.93.1";
21959
+ var version = "3.2.0";
21958
21960
 
21959
21961
  //#endregion
21960
21962
  //#region src/managers/setup.ts
@@ -22657,14 +22659,13 @@ var WeaveAsyncManager = class {
22657
22659
  this.asyncElements = watchMap(() => {
22658
22660
  this.instance.emitEvent("onAsyncElementChange");
22659
22661
  }, new Map());
22660
- this.instance.addEventListener("onRoomLoaded", (isRoomLoaded) => {
22661
- if (!isRoomLoaded) return;
22662
- const roomHasResourcesToLoad = this.roomHasResourcesToLoad();
22663
- if (!roomHasResourcesToLoad && !this.asyncElementsLoadedEventEmitted) {
22664
- this.instance.emitEvent("onAsyncElementsLoaded");
22665
- this.asyncElementsLoadedEventEmitted = true;
22666
- }
22667
- });
22662
+ }
22663
+ checkForAsyncElements(elements) {
22664
+ const amountAsyncResourcesExtracted = this.extractAsyncResources(elements);
22665
+ if (amountAsyncResourcesExtracted === 0 && !this.asyncElementsLoadedEventEmitted) {
22666
+ this.instance.emitEvent("onAsyncElementsLoaded");
22667
+ this.asyncElementsLoadedEventEmitted = true;
22668
+ }
22668
22669
  }
22669
22670
  extractAsyncElements(state) {
22670
22671
  const asyncElements = [];
@@ -22680,11 +22681,20 @@ var WeaveAsyncManager = class {
22680
22681
  } else for (const element of Object.values(state.weave)) traverse(element);
22681
22682
  return asyncElements;
22682
22683
  }
22683
- roomHasResourcesToLoad() {
22684
+ extractAsyncResources(elements) {
22684
22685
  const roomData = this.instance.getStore().getState();
22685
- const jsonRoomData = JSON.parse(JSON.stringify(roomData));
22686
+ let jsonRoomData = JSON.parse(JSON.stringify(roomData));
22687
+ if (elements) jsonRoomData = elements;
22686
22688
  const asyncElements = this.extractAsyncElements(jsonRoomData);
22687
- return asyncElements.length > 0;
22689
+ for (const element of asyncElements) {
22690
+ const elementId = element.props?.id;
22691
+ if (!elementId) continue;
22692
+ if (!this.asyncElements.has(elementId)) this.asyncElements.set(elementId, {
22693
+ type: element.type,
22694
+ status: WEAVE_ASYNC_STATUS.NOT_LOADED
22695
+ });
22696
+ }
22697
+ return asyncElements.length;
22688
22698
  }
22689
22699
  asyncElementsLoaded() {
22690
22700
  return [...this.asyncElements.values()].every((el) => el.status === WEAVE_ASYNC_STATUS.LOADED);
@@ -22919,7 +22929,7 @@ var Weave = class {
22919
22929
  this.emitEvent("onRoomLoaded", false);
22920
22930
  this.status = WEAVE_INSTANCE_STATUS.STARTING;
22921
22931
  this.emitEvent("onInstanceStatus", this.status);
22922
- this.registerManager.registerNodesHandlers();
22932
+ await this.registerManager.registerNodesHandlers();
22923
22933
  this.augmentKonvaStageClass();
22924
22934
  this.augmentKonvaNodeClass();
22925
22935
  this.registerManager.registerPlugins();
@@ -23503,6 +23513,9 @@ var Weave = class {
23503
23513
  nodeHandler.show(node);
23504
23514
  }
23505
23515
  }
23516
+ checkForAsyncElements(elements) {
23517
+ this.asyncManager.checkForAsyncElements(elements);
23518
+ }
23506
23519
  asyncElementsLoaded() {
23507
23520
  return this.asyncManager.asyncElementsLoaded();
23508
23521
  }
@@ -23582,7 +23595,7 @@ function loadImageSource(image, options) {
23582
23595
  const imageSource = Konva.Util.createImageElement();
23583
23596
  imageSource.crossOrigin = crossOrigin;
23584
23597
  imageSource.onerror = () => {
23585
- reject();
23598
+ reject(new Error("Failed to load image source"));
23586
23599
  };
23587
23600
  imageSource.onload = async () => {
23588
23601
  resolve(imageSource);
@@ -25109,7 +25122,10 @@ const WEAVE_IMAGE_CROP_ANCHOR_POSITION = {
25109
25122
  };
25110
25123
  const WEAVE_IMAGE_DEFAULT_CONFIG = {
25111
25124
  performance: { cache: { enabled: false } },
25112
- style: { placeholder: { fill: "#aaaaaa" } },
25125
+ style: {
25126
+ placeholder: { fill: "#aaaaaa" },
25127
+ cursor: { loading: "wait" }
25128
+ },
25113
25129
  imageLoading: {
25114
25130
  maxRetryAttempts: 15,
25115
25131
  retryDelayMs: 2e3
@@ -25680,6 +25696,57 @@ var WeaveImageCrop = class WeaveImageCrop {
25680
25696
  }
25681
25697
  };
25682
25698
 
25699
+ //#endregion
25700
+ //#region src/nodes/image/utils.ts
25701
+ const extractCursorUrl = (cursor, fallback) => {
25702
+ const lower = cursor.toLowerCase();
25703
+ const start = lower.indexOf("url(");
25704
+ if (start === -1) return {
25705
+ preload: false,
25706
+ cursor
25707
+ };
25708
+ let i = start + 4;
25709
+ const len = cursor.length;
25710
+ while (i < len && /\s/.test(cursor[i])) i++;
25711
+ let quote = null;
25712
+ if (cursor[i] === "\"" || cursor[i] === "'") {
25713
+ quote = cursor[i];
25714
+ i++;
25715
+ }
25716
+ let buf = "";
25717
+ for (; i < len; i++) {
25718
+ const ch = cursor[i];
25719
+ if (quote) {
25720
+ if (ch === quote) {
25721
+ i++;
25722
+ break;
25723
+ }
25724
+ buf += ch;
25725
+ } else {
25726
+ if (ch === ")") break;
25727
+ buf += ch;
25728
+ }
25729
+ }
25730
+ const url = buf.trim();
25731
+ if (!url) return {
25732
+ preload: false,
25733
+ cursor: fallback
25734
+ };
25735
+ if (!isAllowedUrl(url)) return {
25736
+ preload: false,
25737
+ cursor: fallback
25738
+ };
25739
+ return {
25740
+ preload: true,
25741
+ cursor: url
25742
+ };
25743
+ };
25744
+ const isAllowedUrl = (value) => {
25745
+ if (/^https?:\/\//i.test(value)) return true;
25746
+ if (/^(javascript|data|blob|ftp):/i.test(value)) return false;
25747
+ return true;
25748
+ };
25749
+
25683
25750
  //#endregion
25684
25751
  //#region src/nodes/image/image.ts
25685
25752
  var WeaveImageNode = class extends WeaveNode {
@@ -25707,10 +25774,41 @@ var WeaveImageNode = class extends WeaveNode {
25707
25774
  this.imageTryoutAttempts = {};
25708
25775
  this.imageFallback = {};
25709
25776
  }
25777
+ preloadCursors() {
25778
+ const promiseHandler = (src) => new Promise((resolveInt, rejectInt) => {
25779
+ const img = Konva.Util.createImageElement();
25780
+ img.onload = () => {
25781
+ resolveInt();
25782
+ };
25783
+ img.onerror = () => {
25784
+ rejectInt(new Error(`Failed to load cursor image: ${src}`));
25785
+ };
25786
+ img.src = src;
25787
+ });
25788
+ return new Promise((resolve) => {
25789
+ (async () => {
25790
+ const cursors = Object.keys(this.config.style.cursor);
25791
+ const cursorUrls = [];
25792
+ const cursorFallback = { loading: "wait" };
25793
+ for (const cursorKey of cursors) {
25794
+ const cursorValue = this.config.style.cursor[cursorKey];
25795
+ const { preload, cursor } = extractCursorUrl(cursorValue, cursorFallback[cursorKey]);
25796
+ if (preload) cursorUrls.push({ src: cursor });
25797
+ }
25798
+ if (cursorUrls.length > 0) {
25799
+ const cursorsPreloading = [];
25800
+ for (const { src } of cursorUrls) cursorsPreloading.push(promiseHandler(src));
25801
+ await Promise.allSettled(cursorsPreloading);
25802
+ }
25803
+ resolve();
25804
+ })();
25805
+ });
25806
+ }
25710
25807
  getConfiguration() {
25711
25808
  return this.config;
25712
25809
  }
25713
- onRegister() {
25810
+ async onRegister() {
25811
+ await this.preloadCursors();
25714
25812
  this.logger.info(`image caching enabled: ${this.config.performance.cache.enabled}`);
25715
25813
  }
25716
25814
  triggerCrop(imageNode, options) {
@@ -25787,7 +25885,7 @@ var WeaveImageNode = class extends WeaveNode {
25787
25885
  });
25788
25886
  this.setupDefaultNodeAugmentation(image);
25789
25887
  image.defineMousePointer = () => {
25790
- if (this.imageState[id]?.status === "loading") return "wait";
25888
+ if (this.imageState[id]?.status === "loading") return this.config.style.cursor.loading;
25791
25889
  const selectedNodes = this.getSelectionPlugin()?.getSelectedNodes() ?? [];
25792
25890
  if (this.isSelecting() && selectedNodes.includes(image)) return "grab";
25793
25891
  return "pointer";
@@ -26255,6 +26353,8 @@ var WeaveImageNode = class extends WeaveNode {
26255
26353
  onError(error);
26256
26354
  };
26257
26355
  this.imageSource[imageId].onload = async () => {
26356
+ const stage = this.instance.getStage();
26357
+ stage.container().style.cursor = "pointer";
26258
26358
  this.imageState[imageId] = {
26259
26359
  status: "loaded",
26260
26360
  loaded: true,
@@ -26296,7 +26396,7 @@ var WeaveImageNode = class extends WeaveNode {
26296
26396
  this.loadImage(node.getAttrs(), node, false, true);
26297
26397
  }
26298
26398
  }, this.config.imageLoading.retryDelayMs);
26299
- if (loadTryout && this.imageTryoutIds[id]) {
26399
+ if (useFallback && loadTryout && this.imageTryoutIds[id]) {
26300
26400
  clearTimeout(this.imageTryoutIds[id]);
26301
26401
  delete this.imageTryoutIds[id];
26302
26402
  }
@@ -26333,15 +26433,11 @@ var WeaveImageNode = class extends WeaveNode {
26333
26433
  width: imageRect.width,
26334
26434
  height: imageRect.height
26335
26435
  });
26336
- const stage = this.instance.getStage();
26337
- if (!loadFallback) {
26338
- if (!this.instance.isServerSide() && stage.container().style.cursor === "wait") stage.container().style.cursor = "pointer";
26339
- this.imageState[id] = {
26340
- status: "loaded",
26341
- loaded: true,
26342
- error: false
26343
- };
26344
- }
26436
+ if (!loadFallback) this.imageState[id] = {
26437
+ status: "loaded",
26438
+ loaded: true,
26439
+ error: false
26440
+ };
26345
26441
  this.updateImageCrop(image);
26346
26442
  this.resolveAsyncElement(id);
26347
26443
  this.cacheNode(image);
@@ -26387,12 +26483,6 @@ var WeaveImageNode = class extends WeaveNode {
26387
26483
  updatePlaceholderSize(image, imagePlaceholder) {
26388
26484
  const imageAttrs = image.getAttrs();
26389
26485
  if (!this.imageState[imageAttrs.id ?? ""]?.loaded) return;
26390
- if (!imageAttrs.adding && imageAttrs.cropInfo) {
26391
- const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
26392
- const cropScale = imageAttrs.cropInfo ? imageAttrs.cropInfo.scaleX : actualScale;
26393
- imagePlaceholder.width(imageAttrs.cropSize.width * (actualScale / cropScale));
26394
- imagePlaceholder.height(imageAttrs.cropSize.height * (actualScale / cropScale));
26395
- }
26396
26486
  if (!imageAttrs.adding && !imageAttrs.cropInfo) {
26397
26487
  imagePlaceholder.width(imageAttrs.uncroppedImage.width);
26398
26488
  imagePlaceholder.height(imageAttrs.uncroppedImage.height);
@@ -28875,7 +28965,7 @@ var WeaveVideoNode = class extends WeaveNode {
28875
28965
  videoIconGroup.x(videoWidth - videoIconGroupWidth - this.config.style.icon.external.paddingX);
28876
28966
  videoIconGroup.y(videoHeight - videoIconGroupHeight - this.config.style.icon.external.paddingY);
28877
28967
  const nodesSelectionPlugin = this.getNodeSelectionPlugin();
28878
- if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
28968
+ if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()?.forceUpdate();
28879
28969
  this.resolveAsyncElement(id);
28880
28970
  };
28881
28971
  }
@@ -29268,7 +29358,7 @@ var WeaveVideoNode = class extends WeaveNode {
29268
29358
  videoIconGroup.x(videoWidth - videoIconGroupWidth - this.config.style.icon.external.paddingX);
29269
29359
  videoIconGroup.y(videoHeight - videoIconGroupHeight - this.config.style.icon.external.paddingY);
29270
29360
  const nodesSelectionPlugin = this.getNodeSelectionPlugin();
29271
- if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
29361
+ if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()?.forceUpdate();
29272
29362
  }
29273
29363
  getNodeSelectionPlugin() {
29274
29364
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -31885,7 +31975,7 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
31885
31975
  }
31886
31976
  cleanup() {
31887
31977
  const stage = this.instance.getStage();
31888
- this.instance.triggerAction(this.previousAction);
31978
+ if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
31889
31979
  stage.container().style.cursor = "default";
31890
31980
  }
31891
31981
  };
@@ -31919,7 +32009,7 @@ var WeaveZoomInToolAction = class extends WeaveAction {
31919
32009
  }
31920
32010
  cleanup() {
31921
32011
  const stage = this.instance.getStage();
31922
- this.instance.triggerAction(this.previousAction);
32012
+ if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
31923
32013
  stage.container().style.cursor = "default";
31924
32014
  }
31925
32015
  };
@@ -31952,7 +32042,7 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
31952
32042
  }
31953
32043
  cleanup() {
31954
32044
  const stage = this.instance.getStage();
31955
- this.instance.triggerAction(this.previousAction);
32045
+ if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
31956
32046
  stage.container().style.cursor = "default";
31957
32047
  }
31958
32048
  };
@@ -31994,7 +32084,7 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
31994
32084
  }
31995
32085
  cleanup() {
31996
32086
  const stage = this.instance.getStage();
31997
- if (this.previousAction) this.instance.triggerAction(this.previousAction);
32087
+ if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
31998
32088
  stage.container().style.cursor = "default";
31999
32089
  }
32000
32090
  };
@@ -33235,14 +33325,19 @@ var WeaveBrushToolAction = class extends WeaveAction {
33235
33325
  });
33236
33326
  window.addEventListener("keydown", (e) => {
33237
33327
  if (e.code === "Enter" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
33328
+ e.stopPropagation();
33238
33329
  this.cancelAction();
33239
33330
  return;
33240
33331
  }
33241
33332
  if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
33333
+ e.stopPropagation();
33242
33334
  this.isSpacePressed = true;
33243
33335
  return;
33244
33336
  }
33245
- if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.cancelAction();
33337
+ if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
33338
+ e.stopPropagation();
33339
+ this.cancelAction();
33340
+ }
33246
33341
  });
33247
33342
  const handlePointerDown = (e) => {
33248
33343
  if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
@@ -33601,12 +33696,9 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
33601
33696
  var WeaveImageToolAction = class extends WeaveAction {
33602
33697
  initialized = false;
33603
33698
  initialCursor = null;
33604
- imageFile = null;
33605
- imageURL = null;
33606
- forceMainContainer = false;
33699
+ imageAction = {};
33607
33700
  ignoreKeyboardEvents = false;
33608
33701
  ignorePointerEvents = false;
33609
- uploadType = null;
33610
33702
  onPropsChange = void 0;
33611
33703
  update = void 0;
33612
33704
  constructor(params) {
@@ -33614,14 +33706,10 @@ var WeaveImageToolAction = class extends WeaveAction {
33614
33706
  this.config = mergeExceptArrays(WEAVE_IMAGE_TOOL_CONFIG_DEFAULT, params?.config ?? {});
33615
33707
  this.pointers = new Map();
33616
33708
  this.initialized = false;
33617
- this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
33618
33709
  this.imageId = null;
33710
+ this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
33619
33711
  this.tempImageId = null;
33620
33712
  this.tempImageNode = null;
33621
- this.container = void 0;
33622
- this.imageURL = null;
33623
- this.uploadType = null;
33624
- this.clickPoint = null;
33625
33713
  }
33626
33714
  getName() {
33627
33715
  return WEAVE_IMAGE_TOOL_ACTION_NAME;
@@ -33693,66 +33781,54 @@ var WeaveImageToolAction = class extends WeaveAction {
33693
33781
  stage.on("pointerup", (e) => {
33694
33782
  if (this.ignorePointerEvents) return;
33695
33783
  this.pointers.delete(e.evt.pointerId);
33696
- if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding();
33784
+ if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding(this.imageId ?? "");
33697
33785
  });
33698
33786
  this.initialized = true;
33699
33787
  }
33700
33788
  setState(state) {
33701
33789
  this.state = state;
33702
33790
  }
33703
- async loadImage(params) {
33791
+ async loadImage(nodeId, params) {
33704
33792
  this.setCursor();
33705
33793
  this.setFocusStage();
33706
- if (!this.imageId) {
33707
- this.cancelAction();
33708
- return;
33709
- }
33710
33794
  const imageNodeHandler = this.getImageNodeHandler();
33711
33795
  if (!imageNodeHandler) return;
33712
- const actualImageId = this.imageId;
33713
33796
  if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
33714
33797
  const image = params.image;
33715
33798
  const realImageSize = await getImageSizeFromFile(image.file);
33716
33799
  const downscaledImage = await downscaleImageFile(image.file, image.downscaleRatio);
33717
- const reader = new FileReader();
33718
- reader.onloadend = () => {
33719
- imageNodeHandler.preloadFallbackImage(actualImageId, reader.result, {
33720
- onLoad: () => {
33721
- this.props = {
33722
- ...this.props,
33723
- imageFallback: reader.result,
33724
- imageURL: void 0,
33725
- width: realImageSize.width,
33726
- height: realImageSize.height
33727
- };
33728
- this.addImageNode(params?.position);
33729
- },
33730
- onError: () => {
33731
- this.cancelAction();
33732
- }
33733
- });
33734
- };
33735
- reader.onerror = () => {};
33736
- reader.readAsDataURL(downscaledImage);
33800
+ try {
33801
+ const dataURL = await this.getDataURL(downscaledImage);
33802
+ this.imageAction[nodeId].props = {
33803
+ ...this.imageAction[nodeId].props,
33804
+ imageFallback: dataURL,
33805
+ imageURL: void 0,
33806
+ width: realImageSize.width,
33807
+ height: realImageSize.height
33808
+ };
33809
+ this.addImageNode(nodeId, params?.position);
33810
+ } catch {
33811
+ this.cancelAction();
33812
+ }
33737
33813
  }
33738
33814
  if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL) {
33739
33815
  const image = params.image;
33740
33816
  setTimeout(() => {
33741
- this.saveImageUrl(actualImageId, image.url);
33817
+ this.saveImageUrl(nodeId, image.url);
33742
33818
  }, 0);
33743
- this.addImageNode(params?.position);
33819
+ this.addImageNode(nodeId, params?.position);
33744
33820
  }
33745
33821
  }
33746
33822
  isTouchDevice() {
33747
33823
  return window.matchMedia("(pointer: coarse)").matches;
33748
33824
  }
33749
- addImageNode(position) {
33825
+ async addImageNode(nodeId, position) {
33750
33826
  const stage = this.instance.getStage();
33751
33827
  this.setCursor();
33752
33828
  this.setFocusStage();
33753
33829
  if (position) {
33754
33830
  this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
33755
- this.handleAdding(position);
33831
+ this.handleAdding(nodeId, position);
33756
33832
  return;
33757
33833
  }
33758
33834
  const imageNodeHandler = this.getImageNodeHandler();
@@ -33760,11 +33836,15 @@ var WeaveImageToolAction = class extends WeaveAction {
33760
33836
  this.cancelAction();
33761
33837
  return;
33762
33838
  }
33763
- if (this.imageId) {
33839
+ if (this.imageAction[nodeId]) {
33840
+ const { uploadType } = this.imageAction[nodeId];
33764
33841
  const mousePos = stage.getRelativePointerPosition();
33765
33842
  this.tempImageId = v4_default();
33766
- let imageSource = imageNodeHandler.getImageSource(this.imageId);
33767
- if (this.uploadType === "file") imageSource = imageNodeHandler.getFallbackImageSource(this.imageId);
33843
+ let imageSource = imageNodeHandler.getImageSource(nodeId);
33844
+ if (uploadType === "file") {
33845
+ imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
33846
+ imageSource ??= await this.loadImageDataURL(this.imageAction[nodeId].props.imageFallback);
33847
+ }
33768
33848
  if (!imageSource) {
33769
33849
  this.cancelAction();
33770
33850
  return;
@@ -33798,37 +33878,41 @@ var WeaveImageToolAction = class extends WeaveAction {
33798
33878
  });
33799
33879
  this.instance.getMainLayer()?.add(this.tempImageNode);
33800
33880
  }
33801
- this.instance.emitEvent("onAddingImage", { imageURL: this.props.imageURL });
33881
+ this.instance.emitEvent("onAddingImage");
33882
+ this.imageAction[nodeId].clickPoint = null;
33802
33883
  }
33803
- this.clickPoint = null;
33804
33884
  this.setState(WEAVE_IMAGE_TOOL_STATE.DEFINING_POSITION);
33805
33885
  }
33806
- handleAdding(position) {
33886
+ async handleAdding(nodeId, position) {
33807
33887
  const imageNodeHandler = this.getImageNodeHandler();
33808
33888
  if (!imageNodeHandler) {
33809
33889
  this.cancelAction();
33810
33890
  return;
33811
33891
  }
33812
- if (this.imageId) {
33813
- let imageSource = imageNodeHandler.getImageSource(this.imageId);
33814
- if (this.uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) imageSource = imageNodeHandler.getFallbackImageSource(this.imageId);
33892
+ if (this.imageAction[nodeId]) {
33893
+ const { uploadType, imageURL, forceMainContainer } = this.imageAction[nodeId];
33894
+ let imageSource = imageNodeHandler.getImageSource(nodeId);
33895
+ if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
33896
+ imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
33897
+ imageSource ??= await this.loadImageDataURL(this.imageAction[nodeId].props.imageFallback);
33898
+ }
33815
33899
  if (!imageSource && !position) {
33816
33900
  this.cancelAction();
33817
33901
  return;
33818
33902
  }
33819
33903
  const { mousePoint, container } = this.instance.getMousePointer(position);
33820
- this.clickPoint = mousePoint;
33821
- this.container = container;
33904
+ this.imageAction[nodeId].clickPoint = mousePoint;
33905
+ this.imageAction[nodeId].container = container;
33822
33906
  const nodeHandler = this.instance.getNodeHandler("image");
33823
- const imageWidth = this.props.width ? this.props.width : imageSource?.width;
33824
- const imageHeight = this.props.height ? this.props.height : imageSource?.height;
33907
+ const imageWidth = this.imageAction[nodeId].props.width ? this.imageAction[nodeId].props.width : imageSource?.width;
33908
+ const imageHeight = this.imageAction[nodeId].props.height ? this.imageAction[nodeId].props.height : imageSource?.height;
33825
33909
  let realImageURL = void 0;
33826
- if (this.uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imageURL) realImageURL = this.imageURL?.url;
33910
+ if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && imageURL) realImageURL = imageURL?.url;
33827
33911
  if (nodeHandler) {
33828
- const node = nodeHandler.create(this.imageId, {
33829
- ...this.props,
33830
- x: this.clickPoint?.x ?? 0,
33831
- y: this.clickPoint?.y ?? 0,
33912
+ const node = nodeHandler.create(nodeId, {
33913
+ ...this.imageAction[nodeId].props,
33914
+ x: this.imageAction[nodeId].clickPoint.x,
33915
+ y: this.imageAction[nodeId].clickPoint.y,
33832
33916
  opacity: 1,
33833
33917
  adding: false,
33834
33918
  imageURL: realImageURL,
@@ -33846,23 +33930,24 @@ var WeaveImageToolAction = class extends WeaveAction {
33846
33930
  height: imageHeight
33847
33931
  }
33848
33932
  });
33849
- this.instance.addNode(node, this.forceMainContainer ? this.instance.getMainLayer()?.getAttrs().id : this.container?.getAttrs().id);
33850
- this.instance.emitEvent("onAddedImage", { nodeId: this.imageId });
33851
- if (this.uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
33852
- const uploadImageFunctionInternal = async () => {
33853
- const nodeId = this.imageId ?? "";
33933
+ this.instance.addNode(node, forceMainContainer ? this.instance.getMainLayer()?.getAttrs().id : this.imageAction[nodeId].container?.getAttrs().id);
33934
+ this.instance.emitEvent("onAddedImage", { nodeId });
33935
+ if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
33936
+ const uploadImageFunctionInternal = async (imageActionData) => {
33937
+ const { uploadImageFunction, imageFile } = imageActionData;
33854
33938
  try {
33855
- const imageURL = await this.uploadImageFunction(this.imageFile.file);
33856
- this.saveImageUrl(nodeId, imageURL);
33939
+ const imageURL$1 = await uploadImageFunction?.(imageFile.file);
33940
+ if (!imageURL$1) return;
33941
+ this.saveImageUrl(nodeId, imageURL$1);
33857
33942
  this.instance.emitEvent("onImageUploaded", {
33858
- imageURL,
33943
+ imageURL: imageURL$1,
33859
33944
  nodeId
33860
33945
  });
33861
33946
  } catch (error) {
33862
33947
  this.instance.emitEvent("onImageUploadedError", { error });
33863
33948
  }
33864
33949
  };
33865
- uploadImageFunctionInternal();
33950
+ uploadImageFunctionInternal(this.imageAction[nodeId]);
33866
33951
  }
33867
33952
  }
33868
33953
  this.setState(WEAVE_IMAGE_TOOL_STATE.FINISHED);
@@ -33877,42 +33962,51 @@ var WeaveImageToolAction = class extends WeaveAction {
33877
33962
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
33878
33963
  this.ignorePointerEvents = false;
33879
33964
  this.ignoreKeyboardEvents = false;
33880
- this.forceMainContainer = params?.forceMainContainer ?? false;
33881
- this.imageFile = null;
33882
- this.imageURL = null;
33883
- this.imageId = v4_default();
33884
- this.props = this.initProps();
33885
- if (params?.imageId) this.updateProps({ imageId: params.imageId });
33965
+ const nodeId = params?.nodeId ?? v4_default();
33966
+ this.imageId = nodeId;
33967
+ this.imageAction[nodeId] = {
33968
+ props: this.initProps(),
33969
+ imageId: nodeId,
33970
+ clickPoint: null,
33971
+ container: void 0,
33972
+ imageFile: null,
33973
+ imageURL: null,
33974
+ forceMainContainer: params?.forceMainContainer ?? false,
33975
+ uploadType: null,
33976
+ uploadImageFunction: null
33977
+ };
33978
+ if (params?.imageId) this.imageAction[nodeId].imageId = params.imageId;
33886
33979
  if (this.forceExecution) {
33887
33980
  this.ignorePointerEvents = true;
33888
33981
  this.ignoreKeyboardEvents = true;
33889
33982
  }
33890
33983
  if (params?.position) this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
33891
33984
  if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE && params.image) {
33892
- this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
33893
- this.imageFile = params.image;
33894
- this.uploadImageFunction = params.uploadImageFunction;
33895
- this.loadImage({
33985
+ this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
33986
+ this.imageAction[nodeId].imageFile = params.image;
33987
+ this.imageAction[nodeId].uploadImageFunction = params.uploadImageFunction;
33988
+ this.loadImage(nodeId, {
33896
33989
  type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
33897
33990
  image: params.image,
33898
33991
  position: params?.position
33899
33992
  });
33900
33993
  }
33901
33994
  if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && params.image) {
33902
- this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
33903
- this.imageURL = params.image;
33904
- this.updateProps({
33995
+ this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
33996
+ this.imageAction[nodeId].imageURL = params.image;
33997
+ this.imageAction[nodeId].props = {
33998
+ ...this.imageAction[nodeId].props,
33905
33999
  imageFallback: params.image.fallback,
33906
34000
  width: params.image.width,
33907
34001
  height: params.image.height
33908
- });
33909
- this.loadImage({
34002
+ };
34003
+ this.loadImage(nodeId, {
33910
34004
  type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
33911
34005
  image: params.image,
33912
34006
  position: params?.position
33913
34007
  });
33914
34008
  }
33915
- return { nodeId: this.imageId };
34009
+ return { nodeId };
33916
34010
  }
33917
34011
  saveImageUrl(nodeId, imageURL) {
33918
34012
  const stage = this.instance.getStage();
@@ -33938,11 +34032,7 @@ var WeaveImageToolAction = class extends WeaveAction {
33938
34032
  this.instance.endDrag(WEAVE_IMAGE_TOOL_ACTION_NAME);
33939
34033
  }
33940
34034
  this.initialCursor = null;
33941
- this.forceMainContainer = false;
33942
- this.container = void 0;
33943
34035
  this.tempImageNode = null;
33944
- this.imageURL = null;
33945
- this.clickPoint = null;
33946
34036
  this.setState(WEAVE_IMAGE_TOOL_STATE.IDLE);
33947
34037
  }
33948
34038
  getImageNodeHandler() {
@@ -33965,6 +34055,30 @@ var WeaveImageToolAction = class extends WeaveAction {
33965
34055
  getActualState() {
33966
34056
  return this.state;
33967
34057
  }
34058
+ loadImageDataURL(imageDataURL) {
34059
+ return new Promise((resolve, reject) => {
34060
+ const imageEle = Konva.Util.createImageElement();
34061
+ imageEle.onerror = (error) => {
34062
+ reject(error);
34063
+ };
34064
+ imageEle.onload = async () => {
34065
+ resolve(imageEle);
34066
+ };
34067
+ imageEle.src = imageDataURL;
34068
+ });
34069
+ }
34070
+ getDataURL(blob) {
34071
+ return new Promise((resolve, reject) => {
34072
+ const reader = new FileReader();
34073
+ reader.onloadend = () => {
34074
+ resolve(reader.result);
34075
+ };
34076
+ reader.onerror = () => {
34077
+ reject(new Error("Failed to generate dataURL from file"));
34078
+ };
34079
+ reader.readAsDataURL(blob);
34080
+ });
34081
+ }
33968
34082
  };
33969
34083
 
33970
34084
  //#endregion
@@ -34013,18 +34127,13 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
34013
34127
  layout: { columns: 4 }
34014
34128
  };
34015
34129
 
34016
- //#endregion
34017
- //#region src/internal-utils/generic.ts
34018
- function sleep(ms) {
34019
- return new Promise((resolve) => setTimeout(resolve, ms));
34020
- }
34021
-
34022
34130
  //#endregion
34023
34131
  //#region src/actions/images-tool/images-tool.ts
34024
34132
  var WeaveImagesToolAction = class extends WeaveAction {
34025
34133
  initialized = false;
34026
34134
  initialCursor = null;
34027
34135
  nodesIds = [];
34136
+ toAdd = 0;
34028
34137
  imagesFile = [];
34029
34138
  imagesURL = [];
34030
34139
  forceMainContainer = false;
@@ -34112,7 +34221,10 @@ var WeaveImagesToolAction = class extends WeaveAction {
34112
34221
  });
34113
34222
  stage.on("pointerup", (e) => {
34114
34223
  this.pointers.delete(e.evt.pointerId);
34115
- if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION) this.handleAdding();
34224
+ if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION) {
34225
+ this.instance.emitEvent("onSelectedPositionImages");
34226
+ this.handleAdding();
34227
+ }
34116
34228
  });
34117
34229
  this.initialized = true;
34118
34230
  }
@@ -34152,9 +34264,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
34152
34264
  const shadowBlur = this.config.style.cursor.imageThumbnails.shadowBlur;
34153
34265
  const shadowOffset = this.config.style.cursor.imageThumbnails.shadowOffset;
34154
34266
  const shadowOpacity = this.config.style.cursor.imageThumbnails.shadowOpacity;
34155
- const aspectRatio = imageSource.width / imageSource.height || 1;
34156
- const imageWidth = maxImageWidth * aspectRatio * (1 / stage.scaleX());
34157
- const imageHeight = maxImageHeight * (1 / stage.scaleY());
34267
+ const scale = Math.min(maxImageWidth / imageSource.width, maxImageHeight / imageSource.height);
34268
+ const imageWidth = imageSource.width * scale * (1 / stage.scaleX());
34269
+ const imageHeight = imageSource.height * scale * (1 / stage.scaleY());
34158
34270
  const imageNode = new Konva.Image({
34159
34271
  x: position$1.x,
34160
34272
  y: position$1.y,
@@ -34172,7 +34284,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
34172
34284
  shadowOffset,
34173
34285
  shadowOpacity
34174
34286
  });
34175
- maxWidth = position$1.x + imageWidth;
34287
+ maxWidth = Math.max(maxWidth, position$1.x + imageWidth);
34176
34288
  maxHeight = Math.max(maxHeight, position$1.y + imageHeight);
34177
34289
  position$1 = {
34178
34290
  x: position$1.x + imageThumbnailsPadding / stage.scaleX(),
@@ -34241,6 +34353,18 @@ var WeaveImagesToolAction = class extends WeaveAction {
34241
34353
  let imagePositionX = originPoint.x;
34242
34354
  let imagePositionY = originPoint.y;
34243
34355
  let maxHeight = 0;
34356
+ this.nodesIds = [];
34357
+ const images = [];
34358
+ const checkAddedImages = ({ nodeId }) => {
34359
+ if (this.nodesIds.includes(nodeId)) this.handleImageAdded();
34360
+ if (this.getImagesAdded() <= 0) {
34361
+ this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
34362
+ this.cancelAction();
34363
+ this.instance.removeEventListener("onAddedImage", checkAddedImages);
34364
+ this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
34365
+ }
34366
+ };
34367
+ this.instance.addEventListener("onAddedImage", checkAddedImages);
34244
34368
  if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE && this.imagesFile) {
34245
34369
  const imagesToUpload = this.imagesFile.length;
34246
34370
  let imagesUploaded = 0;
@@ -34254,23 +34378,35 @@ var WeaveImagesToolAction = class extends WeaveAction {
34254
34378
  };
34255
34379
  this.instance.addEventListener("onImageUploaded", handleUploadImage);
34256
34380
  for (let i = 0; i < this.imagesFile.length; i++) {
34257
- const imageFile = this.imagesFile[i];
34258
- const { imageId, width, height,...restImageFile } = imageFile;
34259
- const uploadImageFunctionInternal = async () => {
34260
- const imageURL = await this.uploadImageFunction(imageFile.file);
34261
- return imageURL;
34381
+ const nodeId = v4_default();
34382
+ const image = this.imagesFile[i];
34383
+ const { width, height } = image;
34384
+ const handleImage = async (nodeId$1, imageFile, position$1) => {
34385
+ const { imageId } = imageFile;
34386
+ const uploadImageFunctionInternal = async () => {
34387
+ const imageURL = await this.uploadImageFunction(imageFile.file);
34388
+ return imageURL;
34389
+ };
34390
+ this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
34391
+ type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
34392
+ image: {
34393
+ file: imageFile.file,
34394
+ downscaleRatio: imageFile.downscaleRatio
34395
+ },
34396
+ uploadImageFunction: uploadImageFunctionInternal,
34397
+ ...imageId && { imageId },
34398
+ position: {
34399
+ x: position$1.x,
34400
+ y: position$1.y
34401
+ },
34402
+ forceMainContainer: this.forceMainContainer,
34403
+ nodeId: nodeId$1
34404
+ }, true);
34262
34405
  };
34263
- const { nodeId } = this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
34264
- type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
34265
- image: restImageFile,
34266
- uploadImageFunction: uploadImageFunctionInternal,
34267
- ...imageId && { imageId },
34268
- position: {
34269
- x: imagePositionX,
34270
- y: imagePositionY
34271
- },
34272
- forceMainContainer: this.forceMainContainer
34273
- }, true);
34406
+ images.push(handleImage(nodeId, image, {
34407
+ x: imagePositionX,
34408
+ y: imagePositionY
34409
+ }));
34274
34410
  this.nodesIds.push(nodeId);
34275
34411
  maxHeight = Math.max(maxHeight, height);
34276
34412
  imagePositionX += imagesPadding + width;
@@ -34279,40 +34415,51 @@ var WeaveImagesToolAction = class extends WeaveAction {
34279
34415
  imagePositionY = imagePositionY + maxHeight + imagesPadding;
34280
34416
  maxHeight = 0;
34281
34417
  }
34282
- while (imageToolActionHandler.getActualState() !== WEAVE_IMAGES_TOOL_STATE.IDLE) await sleep(10);
34283
34418
  }
34284
- this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
34285
34419
  }
34286
- if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) {
34287
- for (let i = 0; i < this.imagesURL.length; i++) {
34288
- const imageURL = this.imagesURL[i];
34289
- const { imageId, options,...restImageURL } = imageURL;
34290
- const imageURLElement = restImageURL;
34291
- const { nodeId } = this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
34420
+ if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) for (let i = 0; i < this.imagesURL.length; i++) {
34421
+ const nodeId = v4_default();
34422
+ const image = this.imagesURL[i];
34423
+ const handleImage = async (nodeId$1, imageURL, position$1) => {
34424
+ const { imageId, options } = imageURL;
34425
+ this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
34292
34426
  type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
34293
- image: imageURLElement,
34427
+ image: {
34428
+ url: imageURL.url,
34429
+ fallback: imageURL.fallback,
34430
+ width: imageURL.width,
34431
+ height: imageURL.height
34432
+ },
34294
34433
  ...imageId && { imageId },
34295
34434
  ...options && { options },
34296
34435
  position: {
34297
- x: imagePositionX,
34298
- y: imagePositionY
34436
+ x: position$1.x,
34437
+ y: position$1.y
34299
34438
  },
34300
- forceMainContainer: this.forceMainContainer
34439
+ forceMainContainer: this.forceMainContainer,
34440
+ nodeId: nodeId$1
34301
34441
  }, true);
34302
- this.nodesIds.push(nodeId);
34303
- maxHeight = Math.max(maxHeight, imageURL.height);
34304
- imagePositionX += imagesPadding + imageURL.width;
34305
- if ((i + 1) % layoutColumns === 0) {
34306
- imagePositionX = originPoint.x;
34307
- imagePositionY = imagePositionY + maxHeight + imagesPadding;
34308
- maxHeight = 0;
34309
- }
34310
- while (imageToolActionHandler.getActualState() !== WEAVE_IMAGES_TOOL_STATE.IDLE) await sleep(10);
34311
- }
34312
- this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
34442
+ };
34443
+ images.push(handleImage(nodeId, image, {
34444
+ x: imagePositionX,
34445
+ y: imagePositionY
34446
+ }));
34447
+ this.nodesIds.push(nodeId);
34448
+ maxHeight = Math.max(maxHeight, image.height);
34449
+ imagePositionX += imagesPadding + image.width;
34450
+ if ((i + 1) % layoutColumns === 0) {
34451
+ imagePositionX = originPoint.x;
34452
+ imagePositionY = imagePositionY + maxHeight + imagesPadding;
34453
+ maxHeight = 0;
34454
+ }
34455
+ }
34456
+ if (this.nodesIds.length > 0) {
34457
+ this.toAdd = this.nodesIds.length;
34458
+ await Promise.allSettled(images);
34459
+ } else {
34460
+ this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
34461
+ this.cancelAction();
34313
34462
  }
34314
- this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
34315
- this.cancelAction();
34316
34463
  }
34317
34464
  trigger(cancelAction, params) {
34318
34465
  if (!this.instance) throw new Error("Instance not defined");
@@ -34321,6 +34468,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
34321
34468
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
34322
34469
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
34323
34470
  if (params?.position) this.setState(WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION);
34471
+ this.nodesIds = [];
34324
34472
  this.forceMainContainer = params.forceMainContainer ?? false;
34325
34473
  if (params.type === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE) {
34326
34474
  this.uploadType = WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE;
@@ -34368,6 +34516,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
34368
34516
  selectionPlugin.setSelectedNodes(addedNodes);
34369
34517
  this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
34370
34518
  }
34519
+ this.instance.emitEvent("onFinishedImages");
34371
34520
  this.instance.endDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
34372
34521
  stage.container().style.cursor = "default";
34373
34522
  this.uploadType = null;
@@ -34375,6 +34524,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
34375
34524
  this.initialCursor = null;
34376
34525
  this.container = void 0;
34377
34526
  this.clickPoint = null;
34527
+ this.nodesIds = [];
34528
+ this.toAdd = 0;
34378
34529
  this.setState(WEAVE_IMAGES_TOOL_STATE.IDLE);
34379
34530
  }
34380
34531
  setCursor() {
@@ -34390,6 +34541,12 @@ var WeaveImagesToolAction = class extends WeaveAction {
34390
34541
  isTouchDevice() {
34391
34542
  return window.matchMedia("(pointer: coarse)").matches;
34392
34543
  }
34544
+ getImagesAdded() {
34545
+ return this.toAdd;
34546
+ }
34547
+ handleImageAdded() {
34548
+ this.toAdd = this.toAdd - 1;
34549
+ }
34393
34550
  setDragAndDropProperties(properties) {
34394
34551
  this.instance.startDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
34395
34552
  this.instance.setDragProperties(properties);