@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/sdk.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();
@@ -9115,6 +9120,32 @@ var WeaveFontsManager = class {
9115
9120
  this.logger = this.instance.getChildLogger("fonts-manager");
9116
9121
  this.logger.debug("Fonts manager created");
9117
9122
  }
9123
+ async loadFontFamily(fontFamily) {
9124
+ const fontsPromises = [];
9125
+ for (const fontFace of fontFamily.fontFaces) {
9126
+ const { source,...fontFaceDescriptors } = fontFace;
9127
+ const fontVariant = new FontFace(fontFamily.family, source, fontFaceDescriptors);
9128
+ fontsPromises.push(fontVariant.load().then(() => document.fonts.add(fontVariant)));
9129
+ }
9130
+ await Promise.all(fontsPromises);
9131
+ return {
9132
+ id: fontFamily.family,
9133
+ name: `${fontFamily.family}, sans-serif`,
9134
+ offsetY: fontFamily.offset.y,
9135
+ supportedStyles: fontFamily.supportedStyles
9136
+ };
9137
+ }
9138
+ async loadFontsFamilies(fontFamilies) {
9139
+ const familiesPromises = [];
9140
+ for (const fontFamily of fontFamilies) familiesPromises.push(this.loadFontFamily(fontFamily));
9141
+ try {
9142
+ const fonts = await Promise.all(familiesPromises);
9143
+ return fonts;
9144
+ } catch (ex) {
9145
+ console.error("Error loading fonts families", ex);
9146
+ return [];
9147
+ }
9148
+ }
9118
9149
  async loadFonts() {
9119
9150
  this.logger.info("Loading fonts");
9120
9151
  const fontsConfig = this.instance.getConfiguration().fonts;
@@ -9123,7 +9154,7 @@ var WeaveFontsManager = class {
9123
9154
  return;
9124
9155
  }
9125
9156
  let fontsToLoad = [];
9126
- if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig();
9157
+ if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig(this.loadFontsFamilies.bind(this));
9127
9158
  if (fontsConfig && fontsConfig instanceof Array) fontsToLoad = fontsConfig;
9128
9159
  for (const font of fontsToLoad) this.loadedFonts.push(font);
9129
9160
  this.logger.info("Fonts loaded");
@@ -9662,7 +9693,7 @@ var WeaveRegisterManager = class {
9662
9693
 
9663
9694
  //#endregion
9664
9695
  //#region package.json
9665
- var version = "5.0.0-SNAPSHOT.409.1";
9696
+ var version = "5.0.0";
9666
9697
 
9667
9698
  //#endregion
9668
9699
  //#region src/managers/setup.ts
@@ -10104,7 +10135,8 @@ var WeaveExportManager = class {
10104
10135
  fill: backgroundColor
10105
10136
  });
10106
10137
  const exportGroup = new Konva.Group();
10107
- if (!exportArea) {
10138
+ if (exportArea) mainLayer.add(background);
10139
+ else {
10108
10140
  exportGroup.add(background);
10109
10141
  for (const node of nodes) {
10110
10142
  const clonedNode = node.clone({ id: v4_default() });
@@ -10116,7 +10148,7 @@ var WeaveExportManager = class {
10116
10148
  exportGroup.add(clonedNode);
10117
10149
  }
10118
10150
  mainLayer.add(exportGroup);
10119
- } else mainLayer.add(background);
10151
+ }
10120
10152
  const backgroundRect = background.getClientRect();
10121
10153
  stage.batchDraw();
10122
10154
  const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
@@ -15193,8 +15225,8 @@ var WeaveImageNode = class extends WeaveNode {
15193
15225
  if (this.config.imageFallback.enabled) {
15194
15226
  const imageFallbackId = this.config.imageFallback.getId(params);
15195
15227
  let finalDataURL = "";
15196
- if (!dataURL) finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15197
- else finalDataURL = dataURL;
15228
+ if (dataURL) finalDataURL = dataURL;
15229
+ else finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15198
15230
  this.imageFallbackURL[imageFallbackId] = finalDataURL;
15199
15231
  }
15200
15232
  }
@@ -15215,7 +15247,7 @@ var WeaveImageNode = class extends WeaveNode {
15215
15247
  this.setupNotUsedImagesCleanup();
15216
15248
  };
15217
15249
  const bindedCleanupHandler = cleanupHandler.bind(this);
15218
- if (!this.notUsedImagesCleanup) this.notUsedImagesCleanup = setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15250
+ this.notUsedImagesCleanup ??= setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15219
15251
  }
15220
15252
  preloadCursors() {
15221
15253
  return new Promise((resolve) => {
@@ -16047,6 +16079,18 @@ var WeaveImageNode = class extends WeaveNode {
16047
16079
  }
16048
16080
  if (node) this.loadImage(node.getAttrs(), node, false, false);
16049
16081
  }
16082
+ forceLoadFallbackImage(nodeInstance, dataURL) {
16083
+ const nodeId = nodeInstance.getAttrs().id ?? "";
16084
+ const node = this.instance.getStage().findOne(`#${nodeId}`);
16085
+ if (this.imageTryoutIds[nodeId]) {
16086
+ clearTimeout(this.imageTryoutIds[nodeId]);
16087
+ delete this.imageTryoutIds[nodeId];
16088
+ }
16089
+ if (node) {
16090
+ this.cacheImageFallbackURL(node.getAttrs(), dataURL);
16091
+ this.loadImage(node.getAttrs(), node, true);
16092
+ }
16093
+ }
16050
16094
  onDestroy(nodeInstance) {
16051
16095
  const nodeId = nodeInstance.getAttrs().id ?? "";
16052
16096
  const utilityLayer = this.instance.getUtilityLayer();
@@ -24789,6 +24833,7 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
24789
24833
  //#endregion
24790
24834
  //#region src/actions/image-tool/image-tool.ts
24791
24835
  var WeaveImageToolAction = class extends WeaveAction {
24836
+ initInitialized = false;
24792
24837
  initialized = false;
24793
24838
  initialCursor = null;
24794
24839
  imageAction = {};
@@ -24821,7 +24866,8 @@ var WeaveImageToolAction = class extends WeaveAction {
24821
24866
  };
24822
24867
  }
24823
24868
  onInit() {
24824
- this.instance.addEventListener("onStageDrop", (e) => {
24869
+ if (this.initInitialized) return;
24870
+ const handleImageOnStageDrop = (e) => {
24825
24871
  const dragId = this.instance.getDragStartedId();
24826
24872
  const dragProperties = this.instance.getDragProperties();
24827
24873
  if (dragProperties && dragId === WEAVE_IMAGE_TOOL_ACTION_NAME) {
@@ -24837,7 +24883,9 @@ var WeaveImageToolAction = class extends WeaveAction {
24837
24883
  position: mousePoint
24838
24884
  });
24839
24885
  }
24840
- });
24886
+ };
24887
+ this.instance.addEventListener("onStageDrop", handleImageOnStageDrop);
24888
+ this.initInitialized = true;
24841
24889
  }
24842
24890
  setupEvents() {
24843
24891
  const stage = this.instance.getStage();
@@ -25243,6 +25291,7 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
25243
25291
  //#endregion
25244
25292
  //#region src/actions/images-tool/images-tool.ts
25245
25293
  var WeaveImagesToolAction = class extends WeaveAction {
25294
+ initInitialized = false;
25246
25295
  initialized = false;
25247
25296
  initialCursor = null;
25248
25297
  nodesIds = [];
@@ -25285,7 +25334,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
25285
25334
  };
25286
25335
  }
25287
25336
  onInit() {
25288
- this.instance.addEventListener("onStageDrop", (e) => {
25337
+ if (this.initInitialized) return;
25338
+ const handleImagesOnStageDrop = (e) => {
25289
25339
  const dragId = this.instance.getDragStartedId();
25290
25340
  const dragProperties = this.instance.getDragProperties();
25291
25341
  if (dragProperties && dragId === WEAVE_IMAGES_TOOL_ACTION_NAME) {
@@ -25300,7 +25350,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
25300
25350
  ...dragProperties.forceMainContainer && { forceMainContainer: dragProperties.forceMainContainer }
25301
25351
  });
25302
25352
  }
25303
- });
25353
+ };
25354
+ this.instance.addEventListener("onStageDrop", handleImagesOnStageDrop);
25355
+ this.initInitialized = true;
25304
25356
  }
25305
25357
  setupEvents() {
25306
25358
  const stage = this.instance.getStage();
@@ -27490,6 +27542,7 @@ const VIDEO_TOOL_STATE = {
27490
27542
  //#endregion
27491
27543
  //#region src/actions/video-tool/video-tool.ts
27492
27544
  var WeaveVideoToolAction = class extends WeaveAction {
27545
+ initInitialized = false;
27493
27546
  initialized = false;
27494
27547
  initialCursor = null;
27495
27548
  cursorPadding = 5;
@@ -27526,7 +27579,8 @@ var WeaveVideoToolAction = class extends WeaveAction {
27526
27579
  };
27527
27580
  }
27528
27581
  onInit() {
27529
- this.instance.addEventListener("onStageDrop", (e) => {
27582
+ if (this.initInitialized) return;
27583
+ const handleVideoOnStageDrop = (e) => {
27530
27584
  const dragId = this.instance.getDragStartedId();
27531
27585
  const dragProperties = this.instance.getDragProperties();
27532
27586
  if (dragProperties && dragId === VIDEO_TOOL_ACTION_NAME) {
@@ -27540,7 +27594,9 @@ var WeaveVideoToolAction = class extends WeaveAction {
27540
27594
  position: mousePoint
27541
27595
  });
27542
27596
  }
27543
- });
27597
+ };
27598
+ this.instance.addEventListener("onStageDrop", handleVideoOnStageDrop);
27599
+ this.initInitialized = true;
27544
27600
  }
27545
27601
  setupEvents() {
27546
27602
  const stage = this.instance.getStage();
package/dist/sdk.node.js CHANGED
@@ -6607,7 +6607,12 @@ var WeaveNode = class {
6607
6607
  this.instance.emitEvent("onDrag", null);
6608
6608
  const realNodeTarget = this.getRealSelectedNode(nodeTarget);
6609
6609
  const isInGroupContext = (this.getSelectionPlugin()?.getActiveGroupContext() ?? null) !== null;
6610
- if (!isInGroupContext && this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && (realNodeTarget.getAttrs().lockToContainer === void 0 || !realNodeTarget.getAttrs().lockToContainer)) this.instance.stateTransactional(() => {
6610
+ const shouldUpdateMove = this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && (realNodeTarget.getAttrs().lockToContainer === void 0 || !realNodeTarget.getAttrs().lockToContainer);
6611
+ if (isInGroupContext && shouldUpdateMove) {
6612
+ if (realNodeTarget.getAttrs().isCloned) this.instance.getCloningManager().removeClone(realNodeTarget);
6613
+ this.instance.updateNodeNT(this.serialize(realNodeTarget));
6614
+ }
6615
+ if (!isInGroupContext && shouldUpdateMove) this.instance.stateTransactional(() => {
6611
6616
  clearContainerTargets(this.instance);
6612
6617
  const layerToMove = containerOverCursor(this.instance, [realNodeTarget]);
6613
6618
  let containerToMove = this.instance.getMainLayer();
@@ -9114,6 +9119,32 @@ var WeaveFontsManager = class {
9114
9119
  this.logger = this.instance.getChildLogger("fonts-manager");
9115
9120
  this.logger.debug("Fonts manager created");
9116
9121
  }
9122
+ async loadFontFamily(fontFamily) {
9123
+ const fontsPromises = [];
9124
+ for (const fontFace of fontFamily.fontFaces) {
9125
+ const { source,...fontFaceDescriptors } = fontFace;
9126
+ const fontVariant = new FontFace(fontFamily.family, source, fontFaceDescriptors);
9127
+ fontsPromises.push(fontVariant.load().then(() => document.fonts.add(fontVariant)));
9128
+ }
9129
+ await Promise.all(fontsPromises);
9130
+ return {
9131
+ id: fontFamily.family,
9132
+ name: `${fontFamily.family}, sans-serif`,
9133
+ offsetY: fontFamily.offset.y,
9134
+ supportedStyles: fontFamily.supportedStyles
9135
+ };
9136
+ }
9137
+ async loadFontsFamilies(fontFamilies) {
9138
+ const familiesPromises = [];
9139
+ for (const fontFamily of fontFamilies) familiesPromises.push(this.loadFontFamily(fontFamily));
9140
+ try {
9141
+ const fonts = await Promise.all(familiesPromises);
9142
+ return fonts;
9143
+ } catch (ex) {
9144
+ console.error("Error loading fonts families", ex);
9145
+ return [];
9146
+ }
9147
+ }
9117
9148
  async loadFonts() {
9118
9149
  this.logger.info("Loading fonts");
9119
9150
  const fontsConfig = this.instance.getConfiguration().fonts;
@@ -9122,7 +9153,7 @@ var WeaveFontsManager = class {
9122
9153
  return;
9123
9154
  }
9124
9155
  let fontsToLoad = [];
9125
- if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig();
9156
+ if (fontsConfig && fontsConfig instanceof Function) fontsToLoad = await fontsConfig(this.loadFontsFamilies.bind(this));
9126
9157
  if (fontsConfig && fontsConfig instanceof Array) fontsToLoad = fontsConfig;
9127
9158
  for (const font of fontsToLoad) this.loadedFonts.push(font);
9128
9159
  this.logger.info("Fonts loaded");
@@ -9661,7 +9692,7 @@ var WeaveRegisterManager = class {
9661
9692
 
9662
9693
  //#endregion
9663
9694
  //#region package.json
9664
- var version = "5.0.0-SNAPSHOT.409.1";
9695
+ var version = "5.0.0";
9665
9696
 
9666
9697
  //#endregion
9667
9698
  //#region src/managers/setup.ts
@@ -10103,7 +10134,8 @@ var WeaveExportManager = class {
10103
10134
  fill: backgroundColor
10104
10135
  });
10105
10136
  const exportGroup = new Konva.Group();
10106
- if (!exportArea) {
10137
+ if (exportArea) mainLayer.add(background);
10138
+ else {
10107
10139
  exportGroup.add(background);
10108
10140
  for (const node of nodes) {
10109
10141
  const clonedNode = node.clone({ id: v4_default() });
@@ -10115,7 +10147,7 @@ var WeaveExportManager = class {
10115
10147
  exportGroup.add(clonedNode);
10116
10148
  }
10117
10149
  mainLayer.add(exportGroup);
10118
- } else mainLayer.add(background);
10150
+ }
10119
10151
  const backgroundRect = background.getClientRect();
10120
10152
  stage.batchDraw();
10121
10153
  const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
@@ -15192,8 +15224,8 @@ var WeaveImageNode = class extends WeaveNode {
15192
15224
  if (this.config.imageFallback.enabled) {
15193
15225
  const imageFallbackId = this.config.imageFallback.getId(params);
15194
15226
  let finalDataURL = "";
15195
- if (!dataURL) finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15196
- else finalDataURL = dataURL;
15227
+ if (dataURL) finalDataURL = dataURL;
15228
+ else finalDataURL = this.config.imageFallback.getDataURL(imageFallbackId);
15197
15229
  this.imageFallbackURL[imageFallbackId] = finalDataURL;
15198
15230
  }
15199
15231
  }
@@ -15214,7 +15246,7 @@ var WeaveImageNode = class extends WeaveNode {
15214
15246
  this.setupNotUsedImagesCleanup();
15215
15247
  };
15216
15248
  const bindedCleanupHandler = cleanupHandler.bind(this);
15217
- if (!this.notUsedImagesCleanup) this.notUsedImagesCleanup = setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15249
+ this.notUsedImagesCleanup ??= setTimeout(bindedCleanupHandler, this.config.cleanup.intervalMs);
15218
15250
  }
15219
15251
  preloadCursors() {
15220
15252
  return new Promise((resolve) => {
@@ -16046,6 +16078,18 @@ var WeaveImageNode = class extends WeaveNode {
16046
16078
  }
16047
16079
  if (node) this.loadImage(node.getAttrs(), node, false, false);
16048
16080
  }
16081
+ forceLoadFallbackImage(nodeInstance, dataURL) {
16082
+ const nodeId = nodeInstance.getAttrs().id ?? "";
16083
+ const node = this.instance.getStage().findOne(`#${nodeId}`);
16084
+ if (this.imageTryoutIds[nodeId]) {
16085
+ clearTimeout(this.imageTryoutIds[nodeId]);
16086
+ delete this.imageTryoutIds[nodeId];
16087
+ }
16088
+ if (node) {
16089
+ this.cacheImageFallbackURL(node.getAttrs(), dataURL);
16090
+ this.loadImage(node.getAttrs(), node, true);
16091
+ }
16092
+ }
16049
16093
  onDestroy(nodeInstance) {
16050
16094
  const nodeId = nodeInstance.getAttrs().id ?? "";
16051
16095
  const utilityLayer = this.instance.getUtilityLayer();
@@ -24788,6 +24832,7 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
24788
24832
  //#endregion
24789
24833
  //#region src/actions/image-tool/image-tool.ts
24790
24834
  var WeaveImageToolAction = class extends WeaveAction {
24835
+ initInitialized = false;
24791
24836
  initialized = false;
24792
24837
  initialCursor = null;
24793
24838
  imageAction = {};
@@ -24820,7 +24865,8 @@ var WeaveImageToolAction = class extends WeaveAction {
24820
24865
  };
24821
24866
  }
24822
24867
  onInit() {
24823
- this.instance.addEventListener("onStageDrop", (e) => {
24868
+ if (this.initInitialized) return;
24869
+ const handleImageOnStageDrop = (e) => {
24824
24870
  const dragId = this.instance.getDragStartedId();
24825
24871
  const dragProperties = this.instance.getDragProperties();
24826
24872
  if (dragProperties && dragId === WEAVE_IMAGE_TOOL_ACTION_NAME) {
@@ -24836,7 +24882,9 @@ var WeaveImageToolAction = class extends WeaveAction {
24836
24882
  position: mousePoint
24837
24883
  });
24838
24884
  }
24839
- });
24885
+ };
24886
+ this.instance.addEventListener("onStageDrop", handleImageOnStageDrop);
24887
+ this.initInitialized = true;
24840
24888
  }
24841
24889
  setupEvents() {
24842
24890
  const stage = this.instance.getStage();
@@ -25242,6 +25290,7 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
25242
25290
  //#endregion
25243
25291
  //#region src/actions/images-tool/images-tool.ts
25244
25292
  var WeaveImagesToolAction = class extends WeaveAction {
25293
+ initInitialized = false;
25245
25294
  initialized = false;
25246
25295
  initialCursor = null;
25247
25296
  nodesIds = [];
@@ -25284,7 +25333,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
25284
25333
  };
25285
25334
  }
25286
25335
  onInit() {
25287
- this.instance.addEventListener("onStageDrop", (e) => {
25336
+ if (this.initInitialized) return;
25337
+ const handleImagesOnStageDrop = (e) => {
25288
25338
  const dragId = this.instance.getDragStartedId();
25289
25339
  const dragProperties = this.instance.getDragProperties();
25290
25340
  if (dragProperties && dragId === WEAVE_IMAGES_TOOL_ACTION_NAME) {
@@ -25299,7 +25349,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
25299
25349
  ...dragProperties.forceMainContainer && { forceMainContainer: dragProperties.forceMainContainer }
25300
25350
  });
25301
25351
  }
25302
- });
25352
+ };
25353
+ this.instance.addEventListener("onStageDrop", handleImagesOnStageDrop);
25354
+ this.initInitialized = true;
25303
25355
  }
25304
25356
  setupEvents() {
25305
25357
  const stage = this.instance.getStage();
@@ -27489,6 +27541,7 @@ const VIDEO_TOOL_STATE = {
27489
27541
  //#endregion
27490
27542
  //#region src/actions/video-tool/video-tool.ts
27491
27543
  var WeaveVideoToolAction = class extends WeaveAction {
27544
+ initInitialized = false;
27492
27545
  initialized = false;
27493
27546
  initialCursor = null;
27494
27547
  cursorPadding = 5;
@@ -27525,7 +27578,8 @@ var WeaveVideoToolAction = class extends WeaveAction {
27525
27578
  };
27526
27579
  }
27527
27580
  onInit() {
27528
- this.instance.addEventListener("onStageDrop", (e) => {
27581
+ if (this.initInitialized) return;
27582
+ const handleVideoOnStageDrop = (e) => {
27529
27583
  const dragId = this.instance.getDragStartedId();
27530
27584
  const dragProperties = this.instance.getDragProperties();
27531
27585
  if (dragProperties && dragId === VIDEO_TOOL_ACTION_NAME) {
@@ -27539,7 +27593,9 @@ var WeaveVideoToolAction = class extends WeaveAction {
27539
27593
  position: mousePoint
27540
27594
  });
27541
27595
  }
27542
- });
27596
+ };
27597
+ this.instance.addEventListener("onStageDrop", handleVideoOnStageDrop);
27598
+ this.initInitialized = true;
27543
27599
  }
27544
27600
  setupEvents() {
27545
27601
  const stage = this.instance.getStage();