@inditextech/weave-sdk 5.0.0-SNAPSHOT.409.1 → 5.0.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/types.js CHANGED
@@ -6608,7 +6608,12 @@ var WeaveNode = class {
6608
6608
  this.instance.emitEvent("onDrag", null);
6609
6609
  const realNodeTarget = this.getRealSelectedNode(nodeTarget);
6610
6610
  const isInGroupContext = (this.getSelectionPlugin()?.getActiveGroupContext() ?? null) !== null;
6611
- if (!isInGroupContext && this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && (realNodeTarget.getAttrs().lockToContainer === void 0 || !realNodeTarget.getAttrs().lockToContainer)) this.instance.stateTransactional(() => {
6611
+ const shouldUpdateMove = this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && (realNodeTarget.getAttrs().lockToContainer === void 0 || !realNodeTarget.getAttrs().lockToContainer);
6612
+ if (isInGroupContext && shouldUpdateMove) {
6613
+ if (realNodeTarget.getAttrs().isCloned) this.instance.getCloningManager().removeClone(realNodeTarget);
6614
+ this.instance.updateNodeNT(this.serialize(realNodeTarget));
6615
+ }
6616
+ if (!isInGroupContext && shouldUpdateMove) this.instance.stateTransactional(() => {
6612
6617
  clearContainerTargets(this.instance);
6613
6618
  const layerToMove = containerOverCursor(this.instance, [realNodeTarget]);
6614
6619
  let containerToMove = this.instance.getMainLayer();
@@ -9126,6 +9131,32 @@ var WeaveFontsManager = class {
9126
9131
  this.logger = this.instance.getChildLogger("fonts-manager");
9127
9132
  this.logger.debug("Fonts manager created");
9128
9133
  }
9134
+ async loadFontFamily(fontFamily) {
9135
+ const fontsPromises = [];
9136
+ for (const fontFace of fontFamily.fontFaces) {
9137
+ const { source,...fontFaceDescriptors } = fontFace;
9138
+ const fontVariant = new FontFace(fontFamily.family, source, fontFaceDescriptors);
9139
+ fontsPromises.push(fontVariant.load().then(() => document.fonts.add(fontVariant)));
9140
+ }
9141
+ await Promise.all(fontsPromises);
9142
+ return {
9143
+ id: fontFamily.family,
9144
+ name: `${fontFamily.family}, sans-serif`,
9145
+ offsetY: fontFamily.offset.y,
9146
+ supportedStyles: fontFamily.supportedStyles
9147
+ };
9148
+ }
9149
+ async loadFontsFamilies(fontFamilies) {
9150
+ const familiesPromises = [];
9151
+ for (const fontFamily of fontFamilies) familiesPromises.push(this.loadFontFamily(fontFamily));
9152
+ try {
9153
+ const fonts = await Promise.all(familiesPromises);
9154
+ return fonts;
9155
+ } catch (ex) {
9156
+ console.error("Error loading fonts families", ex);
9157
+ return [];
9158
+ }
9159
+ }
9129
9160
  async loadFonts() {
9130
9161
  this.logger.info("Loading fonts");
9131
9162
  const fontsConfig = this.instance.getConfiguration().fonts;
@@ -9134,7 +9165,7 @@ var WeaveFontsManager = class {
9134
9165
  return;
9135
9166
  }
9136
9167
  let fontsToLoad = [];
9137
- if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig();
9168
+ if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig(this.loadFontsFamilies.bind(this));
9138
9169
  if (fontsConfig && fontsConfig instanceof Array) fontsToLoad = fontsConfig;
9139
9170
  for (const font of fontsToLoad) this.loadedFonts.push(font);
9140
9171
  this.logger.info("Fonts loaded");
@@ -9673,7 +9704,7 @@ var WeaveRegisterManager = class {
9673
9704
 
9674
9705
  //#endregion
9675
9706
  //#region package.json
9676
- var version = "5.0.0-SNAPSHOT.409.1";
9707
+ var version = "5.0.0";
9677
9708
 
9678
9709
  //#endregion
9679
9710
  //#region src/managers/setup.ts
@@ -10115,7 +10146,8 @@ var WeaveExportManager = class {
10115
10146
  fill: backgroundColor
10116
10147
  });
10117
10148
  const exportGroup = new Konva.Group();
10118
- if (!exportArea) {
10149
+ if (exportArea) mainLayer.add(background);
10150
+ else {
10119
10151
  exportGroup.add(background);
10120
10152
  for (const node of nodes) {
10121
10153
  const clonedNode = node.clone({ id: v4_default() });
@@ -10127,7 +10159,7 @@ var WeaveExportManager = class {
10127
10159
  exportGroup.add(clonedNode);
10128
10160
  }
10129
10161
  mainLayer.add(exportGroup);
10130
- } else mainLayer.add(background);
10162
+ }
10131
10163
  const backgroundRect = background.getClientRect();
10132
10164
  stage.batchDraw();
10133
10165
  const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
@@ -15250,8 +15282,8 @@ var WeaveImageNode = class extends WeaveNode {
15250
15282
  if (this.config.imageFallback.enabled) {
15251
15283
  const imageFallbackId = this.config.imageFallback.getId(params);
15252
15284
  let finalDataURL = "";
15253
- if (!dataURL) finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15254
- else finalDataURL = dataURL;
15285
+ if (dataURL) finalDataURL = dataURL;
15286
+ else finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15255
15287
  this.imageFallbackURL[imageFallbackId] = finalDataURL;
15256
15288
  }
15257
15289
  }
@@ -15272,7 +15304,7 @@ var WeaveImageNode = class extends WeaveNode {
15272
15304
  this.setupNotUsedImagesCleanup();
15273
15305
  };
15274
15306
  const bindedCleanupHandler = cleanupHandler.bind(this);
15275
- if (!this.notUsedImagesCleanup) this.notUsedImagesCleanup = setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15307
+ this.notUsedImagesCleanup ??= setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15276
15308
  }
15277
15309
  preloadCursors() {
15278
15310
  return new Promise((resolve) => {
@@ -16104,6 +16136,18 @@ var WeaveImageNode = class extends WeaveNode {
16104
16136
  }
16105
16137
  if (node) this.loadImage(node.getAttrs(), node, false, false);
16106
16138
  }
16139
+ forceLoadFallbackImage(nodeInstance, dataURL) {
16140
+ const nodeId = nodeInstance.getAttrs().id ?? "";
16141
+ const node = this.instance.getStage().findOne(`#${nodeId}`);
16142
+ if (this.imageTryoutIds[nodeId]) {
16143
+ clearTimeout(this.imageTryoutIds[nodeId]);
16144
+ delete this.imageTryoutIds[nodeId];
16145
+ }
16146
+ if (node) {
16147
+ this.cacheImageFallbackURL(node.getAttrs(), dataURL);
16148
+ this.loadImage(node.getAttrs(), node, true);
16149
+ }
16150
+ }
16107
16151
  onDestroy(nodeInstance) {
16108
16152
  const nodeId = nodeInstance.getAttrs().id ?? "";
16109
16153
  const utilityLayer = this.instance.getUtilityLayer();
@@ -24846,6 +24890,7 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
24846
24890
  //#endregion
24847
24891
  //#region src/actions/image-tool/image-tool.ts
24848
24892
  var WeaveImageToolAction = class extends WeaveAction {
24893
+ initInitialized = false;
24849
24894
  initialized = false;
24850
24895
  initialCursor = null;
24851
24896
  imageAction = {};
@@ -24878,7 +24923,8 @@ var WeaveImageToolAction = class extends WeaveAction {
24878
24923
  };
24879
24924
  }
24880
24925
  onInit() {
24881
- this.instance.addEventListener("onStageDrop", (e) => {
24926
+ if (this.initInitialized) return;
24927
+ const handleImageOnStageDrop = (e) => {
24882
24928
  const dragId = this.instance.getDragStartedId();
24883
24929
  const dragProperties = this.instance.getDragProperties();
24884
24930
  if (dragProperties && dragId === WEAVE_IMAGE_TOOL_ACTION_NAME) {
@@ -24894,7 +24940,9 @@ var WeaveImageToolAction = class extends WeaveAction {
24894
24940
  position: mousePoint
24895
24941
  });
24896
24942
  }
24897
- });
24943
+ };
24944
+ this.instance.addEventListener("onStageDrop", handleImageOnStageDrop);
24945
+ this.initInitialized = true;
24898
24946
  }
24899
24947
  setupEvents() {
24900
24948
  const stage = this.instance.getStage();
@@ -25300,6 +25348,7 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
25300
25348
  //#endregion
25301
25349
  //#region src/actions/images-tool/images-tool.ts
25302
25350
  var WeaveImagesToolAction = class extends WeaveAction {
25351
+ initInitialized = false;
25303
25352
  initialized = false;
25304
25353
  initialCursor = null;
25305
25354
  nodesIds = [];
@@ -25342,7 +25391,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
25342
25391
  };
25343
25392
  }
25344
25393
  onInit() {
25345
- this.instance.addEventListener("onStageDrop", (e) => {
25394
+ if (this.initInitialized) return;
25395
+ const handleImagesOnStageDrop = (e) => {
25346
25396
  const dragId = this.instance.getDragStartedId();
25347
25397
  const dragProperties = this.instance.getDragProperties();
25348
25398
  if (dragProperties && dragId === WEAVE_IMAGES_TOOL_ACTION_NAME) {
@@ -25357,7 +25407,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
25357
25407
  ...dragProperties.forceMainContainer && { forceMainContainer: dragProperties.forceMainContainer }
25358
25408
  });
25359
25409
  }
25360
- });
25410
+ };
25411
+ this.instance.addEventListener("onStageDrop", handleImagesOnStageDrop);
25412
+ this.initInitialized = true;
25361
25413
  }
25362
25414
  setupEvents() {
25363
25415
  const stage = this.instance.getStage();
@@ -27547,6 +27599,7 @@ const VIDEO_TOOL_STATE = {
27547
27599
  //#endregion
27548
27600
  //#region src/actions/video-tool/video-tool.ts
27549
27601
  var WeaveVideoToolAction = class extends WeaveAction {
27602
+ initInitialized = false;
27550
27603
  initialized = false;
27551
27604
  initialCursor = null;
27552
27605
  cursorPadding = 5;
@@ -27583,7 +27636,8 @@ var WeaveVideoToolAction = class extends WeaveAction {
27583
27636
  };
27584
27637
  }
27585
27638
  onInit() {
27586
- this.instance.addEventListener("onStageDrop", (e) => {
27639
+ if (this.initInitialized) return;
27640
+ const handleVideoOnStageDrop = (e) => {
27587
27641
  const dragId = this.instance.getDragStartedId();
27588
27642
  const dragProperties = this.instance.getDragProperties();
27589
27643
  if (dragProperties && dragId === VIDEO_TOOL_ACTION_NAME) {
@@ -27597,7 +27651,9 @@ var WeaveVideoToolAction = class extends WeaveAction {
27597
27651
  position: mousePoint
27598
27652
  });
27599
27653
  }
27600
- });
27654
+ };
27655
+ this.instance.addEventListener("onStageDrop", handleVideoOnStageDrop);
27656
+ this.initInitialized = true;
27601
27657
  }
27602
27658
  setupEvents() {
27603
27659
  const stage = this.instance.getStage();