@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 +345 -188
- package/dist/sdk.node.js +345 -188
- package/dist/types.d.ts +58 -46
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +345 -188
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/types.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();
|
|
@@ -21921,19 +21923,19 @@ var WeaveRegisterManager = class {
|
|
|
21921
21923
|
plugin.register(this.instance);
|
|
21922
21924
|
this.plugins[pluginName] = plugin;
|
|
21923
21925
|
}
|
|
21924
|
-
registerNodesHandlers() {
|
|
21926
|
+
async registerNodesHandlers() {
|
|
21925
21927
|
const config = this.instance.getConfiguration();
|
|
21926
|
-
if (config.nodes) for (const node of config.nodes) this.registerNodeHandler(node);
|
|
21928
|
+
if (config.nodes) for (const node of config.nodes) await this.registerNodeHandler(node);
|
|
21927
21929
|
this.logger.info(`Nodes handlers registered`);
|
|
21928
21930
|
}
|
|
21929
|
-
registerNodeHandler(node) {
|
|
21931
|
+
async registerNodeHandler(node) {
|
|
21930
21932
|
const nodeType = node.getNodeType();
|
|
21931
21933
|
if (this.nodesHandlers[nodeType]) {
|
|
21932
21934
|
const msg = `Node handler with type [${nodeType}] already exists`;
|
|
21933
21935
|
this.logger.error(msg);
|
|
21934
21936
|
throw new Error(msg);
|
|
21935
21937
|
}
|
|
21936
|
-
node.register(this.instance);
|
|
21938
|
+
await node.register(this.instance);
|
|
21937
21939
|
this.nodesHandlers[nodeType] = node;
|
|
21938
21940
|
}
|
|
21939
21941
|
registerActionsHandlers() {
|
|
@@ -21965,7 +21967,7 @@ var WeaveRegisterManager = class {
|
|
|
21965
21967
|
|
|
21966
21968
|
//#endregion
|
|
21967
21969
|
//#region package.json
|
|
21968
|
-
var version = "3.2.0
|
|
21970
|
+
var version = "3.2.0";
|
|
21969
21971
|
|
|
21970
21972
|
//#endregion
|
|
21971
21973
|
//#region src/managers/setup.ts
|
|
@@ -22668,14 +22670,13 @@ var WeaveAsyncManager = class {
|
|
|
22668
22670
|
this.asyncElements = watchMap(() => {
|
|
22669
22671
|
this.instance.emitEvent("onAsyncElementChange");
|
|
22670
22672
|
}, new Map());
|
|
22671
|
-
|
|
22672
|
-
|
|
22673
|
-
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
});
|
|
22673
|
+
}
|
|
22674
|
+
checkForAsyncElements(elements) {
|
|
22675
|
+
const amountAsyncResourcesExtracted = this.extractAsyncResources(elements);
|
|
22676
|
+
if (amountAsyncResourcesExtracted === 0 && !this.asyncElementsLoadedEventEmitted) {
|
|
22677
|
+
this.instance.emitEvent("onAsyncElementsLoaded");
|
|
22678
|
+
this.asyncElementsLoadedEventEmitted = true;
|
|
22679
|
+
}
|
|
22679
22680
|
}
|
|
22680
22681
|
extractAsyncElements(state) {
|
|
22681
22682
|
const asyncElements = [];
|
|
@@ -22691,11 +22692,20 @@ var WeaveAsyncManager = class {
|
|
|
22691
22692
|
} else for (const element of Object.values(state.weave)) traverse(element);
|
|
22692
22693
|
return asyncElements;
|
|
22693
22694
|
}
|
|
22694
|
-
|
|
22695
|
+
extractAsyncResources(elements) {
|
|
22695
22696
|
const roomData = this.instance.getStore().getState();
|
|
22696
|
-
|
|
22697
|
+
let jsonRoomData = JSON.parse(JSON.stringify(roomData));
|
|
22698
|
+
if (elements) jsonRoomData = elements;
|
|
22697
22699
|
const asyncElements = this.extractAsyncElements(jsonRoomData);
|
|
22698
|
-
|
|
22700
|
+
for (const element of asyncElements) {
|
|
22701
|
+
const elementId = element.props?.id;
|
|
22702
|
+
if (!elementId) continue;
|
|
22703
|
+
if (!this.asyncElements.has(elementId)) this.asyncElements.set(elementId, {
|
|
22704
|
+
type: element.type,
|
|
22705
|
+
status: WEAVE_ASYNC_STATUS.NOT_LOADED
|
|
22706
|
+
});
|
|
22707
|
+
}
|
|
22708
|
+
return asyncElements.length;
|
|
22699
22709
|
}
|
|
22700
22710
|
asyncElementsLoaded() {
|
|
22701
22711
|
return [...this.asyncElements.values()].every((el) => el.status === WEAVE_ASYNC_STATUS.LOADED);
|
|
@@ -22930,7 +22940,7 @@ var Weave = class {
|
|
|
22930
22940
|
this.emitEvent("onRoomLoaded", false);
|
|
22931
22941
|
this.status = WEAVE_INSTANCE_STATUS.STARTING;
|
|
22932
22942
|
this.emitEvent("onInstanceStatus", this.status);
|
|
22933
|
-
this.registerManager.registerNodesHandlers();
|
|
22943
|
+
await this.registerManager.registerNodesHandlers();
|
|
22934
22944
|
this.augmentKonvaStageClass();
|
|
22935
22945
|
this.augmentKonvaNodeClass();
|
|
22936
22946
|
this.registerManager.registerPlugins();
|
|
@@ -23514,6 +23524,9 @@ var Weave = class {
|
|
|
23514
23524
|
nodeHandler.show(node);
|
|
23515
23525
|
}
|
|
23516
23526
|
}
|
|
23527
|
+
checkForAsyncElements(elements) {
|
|
23528
|
+
this.asyncManager.checkForAsyncElements(elements);
|
|
23529
|
+
}
|
|
23517
23530
|
asyncElementsLoaded() {
|
|
23518
23531
|
return this.asyncManager.asyncElementsLoaded();
|
|
23519
23532
|
}
|
|
@@ -23593,7 +23606,7 @@ function loadImageSource(image, options) {
|
|
|
23593
23606
|
const imageSource = Konva.Util.createImageElement();
|
|
23594
23607
|
imageSource.crossOrigin = crossOrigin;
|
|
23595
23608
|
imageSource.onerror = () => {
|
|
23596
|
-
reject();
|
|
23609
|
+
reject(new Error("Failed to load image source"));
|
|
23597
23610
|
};
|
|
23598
23611
|
imageSource.onload = async () => {
|
|
23599
23612
|
resolve(imageSource);
|
|
@@ -25120,7 +25133,10 @@ const WEAVE_IMAGE_CROP_ANCHOR_POSITION = {
|
|
|
25120
25133
|
};
|
|
25121
25134
|
const WEAVE_IMAGE_DEFAULT_CONFIG = {
|
|
25122
25135
|
performance: { cache: { enabled: false } },
|
|
25123
|
-
style: {
|
|
25136
|
+
style: {
|
|
25137
|
+
placeholder: { fill: "#aaaaaa" },
|
|
25138
|
+
cursor: { loading: "wait" }
|
|
25139
|
+
},
|
|
25124
25140
|
imageLoading: {
|
|
25125
25141
|
maxRetryAttempts: 15,
|
|
25126
25142
|
retryDelayMs: 2e3
|
|
@@ -25691,6 +25707,57 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
25691
25707
|
}
|
|
25692
25708
|
};
|
|
25693
25709
|
|
|
25710
|
+
//#endregion
|
|
25711
|
+
//#region src/nodes/image/utils.ts
|
|
25712
|
+
const extractCursorUrl = (cursor, fallback) => {
|
|
25713
|
+
const lower = cursor.toLowerCase();
|
|
25714
|
+
const start = lower.indexOf("url(");
|
|
25715
|
+
if (start === -1) return {
|
|
25716
|
+
preload: false,
|
|
25717
|
+
cursor
|
|
25718
|
+
};
|
|
25719
|
+
let i = start + 4;
|
|
25720
|
+
const len = cursor.length;
|
|
25721
|
+
while (i < len && /\s/.test(cursor[i])) i++;
|
|
25722
|
+
let quote = null;
|
|
25723
|
+
if (cursor[i] === "\"" || cursor[i] === "'") {
|
|
25724
|
+
quote = cursor[i];
|
|
25725
|
+
i++;
|
|
25726
|
+
}
|
|
25727
|
+
let buf = "";
|
|
25728
|
+
for (; i < len; i++) {
|
|
25729
|
+
const ch = cursor[i];
|
|
25730
|
+
if (quote) {
|
|
25731
|
+
if (ch === quote) {
|
|
25732
|
+
i++;
|
|
25733
|
+
break;
|
|
25734
|
+
}
|
|
25735
|
+
buf += ch;
|
|
25736
|
+
} else {
|
|
25737
|
+
if (ch === ")") break;
|
|
25738
|
+
buf += ch;
|
|
25739
|
+
}
|
|
25740
|
+
}
|
|
25741
|
+
const url = buf.trim();
|
|
25742
|
+
if (!url) return {
|
|
25743
|
+
preload: false,
|
|
25744
|
+
cursor: fallback
|
|
25745
|
+
};
|
|
25746
|
+
if (!isAllowedUrl(url)) return {
|
|
25747
|
+
preload: false,
|
|
25748
|
+
cursor: fallback
|
|
25749
|
+
};
|
|
25750
|
+
return {
|
|
25751
|
+
preload: true,
|
|
25752
|
+
cursor: url
|
|
25753
|
+
};
|
|
25754
|
+
};
|
|
25755
|
+
const isAllowedUrl = (value) => {
|
|
25756
|
+
if (/^https?:\/\//i.test(value)) return true;
|
|
25757
|
+
if (/^(javascript|data|blob|ftp):/i.test(value)) return false;
|
|
25758
|
+
return true;
|
|
25759
|
+
};
|
|
25760
|
+
|
|
25694
25761
|
//#endregion
|
|
25695
25762
|
//#region src/nodes/image/image.ts
|
|
25696
25763
|
var WeaveImageNode = class extends WeaveNode {
|
|
@@ -25718,10 +25785,41 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
25718
25785
|
this.imageTryoutAttempts = {};
|
|
25719
25786
|
this.imageFallback = {};
|
|
25720
25787
|
}
|
|
25788
|
+
preloadCursors() {
|
|
25789
|
+
const promiseHandler = (src) => new Promise((resolveInt, rejectInt) => {
|
|
25790
|
+
const img = Konva.Util.createImageElement();
|
|
25791
|
+
img.onload = () => {
|
|
25792
|
+
resolveInt();
|
|
25793
|
+
};
|
|
25794
|
+
img.onerror = () => {
|
|
25795
|
+
rejectInt(new Error(`Failed to load cursor image: ${src}`));
|
|
25796
|
+
};
|
|
25797
|
+
img.src = src;
|
|
25798
|
+
});
|
|
25799
|
+
return new Promise((resolve) => {
|
|
25800
|
+
(async () => {
|
|
25801
|
+
const cursors = Object.keys(this.config.style.cursor);
|
|
25802
|
+
const cursorUrls = [];
|
|
25803
|
+
const cursorFallback = { loading: "wait" };
|
|
25804
|
+
for (const cursorKey of cursors) {
|
|
25805
|
+
const cursorValue = this.config.style.cursor[cursorKey];
|
|
25806
|
+
const { preload, cursor } = extractCursorUrl(cursorValue, cursorFallback[cursorKey]);
|
|
25807
|
+
if (preload) cursorUrls.push({ src: cursor });
|
|
25808
|
+
}
|
|
25809
|
+
if (cursorUrls.length > 0) {
|
|
25810
|
+
const cursorsPreloading = [];
|
|
25811
|
+
for (const { src } of cursorUrls) cursorsPreloading.push(promiseHandler(src));
|
|
25812
|
+
await Promise.allSettled(cursorsPreloading);
|
|
25813
|
+
}
|
|
25814
|
+
resolve();
|
|
25815
|
+
})();
|
|
25816
|
+
});
|
|
25817
|
+
}
|
|
25721
25818
|
getConfiguration() {
|
|
25722
25819
|
return this.config;
|
|
25723
25820
|
}
|
|
25724
|
-
onRegister() {
|
|
25821
|
+
async onRegister() {
|
|
25822
|
+
await this.preloadCursors();
|
|
25725
25823
|
this.logger.info(`image caching enabled: ${this.config.performance.cache.enabled}`);
|
|
25726
25824
|
}
|
|
25727
25825
|
triggerCrop(imageNode, options) {
|
|
@@ -25798,7 +25896,7 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
25798
25896
|
});
|
|
25799
25897
|
this.setupDefaultNodeAugmentation(image);
|
|
25800
25898
|
image.defineMousePointer = () => {
|
|
25801
|
-
if (this.imageState[id]?.status === "loading") return
|
|
25899
|
+
if (this.imageState[id]?.status === "loading") return this.config.style.cursor.loading;
|
|
25802
25900
|
const selectedNodes = this.getSelectionPlugin()?.getSelectedNodes() ?? [];
|
|
25803
25901
|
if (this.isSelecting() && selectedNodes.includes(image)) return "grab";
|
|
25804
25902
|
return "pointer";
|
|
@@ -26266,6 +26364,8 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
26266
26364
|
onError(error);
|
|
26267
26365
|
};
|
|
26268
26366
|
this.imageSource[imageId].onload = async () => {
|
|
26367
|
+
const stage = this.instance.getStage();
|
|
26368
|
+
stage.container().style.cursor = "pointer";
|
|
26269
26369
|
this.imageState[imageId] = {
|
|
26270
26370
|
status: "loaded",
|
|
26271
26371
|
loaded: true,
|
|
@@ -26307,7 +26407,7 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
26307
26407
|
this.loadImage(node.getAttrs(), node, false, true);
|
|
26308
26408
|
}
|
|
26309
26409
|
}, this.config.imageLoading.retryDelayMs);
|
|
26310
|
-
if (loadTryout && this.imageTryoutIds[id]) {
|
|
26410
|
+
if (useFallback && loadTryout && this.imageTryoutIds[id]) {
|
|
26311
26411
|
clearTimeout(this.imageTryoutIds[id]);
|
|
26312
26412
|
delete this.imageTryoutIds[id];
|
|
26313
26413
|
}
|
|
@@ -26344,15 +26444,11 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
26344
26444
|
width: imageRect.width,
|
|
26345
26445
|
height: imageRect.height
|
|
26346
26446
|
});
|
|
26347
|
-
|
|
26348
|
-
|
|
26349
|
-
|
|
26350
|
-
|
|
26351
|
-
|
|
26352
|
-
loaded: true,
|
|
26353
|
-
error: false
|
|
26354
|
-
};
|
|
26355
|
-
}
|
|
26447
|
+
if (!loadFallback) this.imageState[id] = {
|
|
26448
|
+
status: "loaded",
|
|
26449
|
+
loaded: true,
|
|
26450
|
+
error: false
|
|
26451
|
+
};
|
|
26356
26452
|
this.updateImageCrop(image);
|
|
26357
26453
|
this.resolveAsyncElement(id);
|
|
26358
26454
|
this.cacheNode(image);
|
|
@@ -26398,12 +26494,6 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
26398
26494
|
updatePlaceholderSize(image, imagePlaceholder) {
|
|
26399
26495
|
const imageAttrs = image.getAttrs();
|
|
26400
26496
|
if (!this.imageState[imageAttrs.id ?? ""]?.loaded) return;
|
|
26401
|
-
if (!imageAttrs.adding && imageAttrs.cropInfo) {
|
|
26402
|
-
const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
|
|
26403
|
-
const cropScale = imageAttrs.cropInfo ? imageAttrs.cropInfo.scaleX : actualScale;
|
|
26404
|
-
imagePlaceholder.width(imageAttrs.cropSize.width * (actualScale / cropScale));
|
|
26405
|
-
imagePlaceholder.height(imageAttrs.cropSize.height * (actualScale / cropScale));
|
|
26406
|
-
}
|
|
26407
26497
|
if (!imageAttrs.adding && !imageAttrs.cropInfo) {
|
|
26408
26498
|
imagePlaceholder.width(imageAttrs.uncroppedImage.width);
|
|
26409
26499
|
imagePlaceholder.height(imageAttrs.uncroppedImage.height);
|
|
@@ -28886,7 +28976,7 @@ var WeaveVideoNode = class extends WeaveNode {
|
|
|
28886
28976
|
videoIconGroup.x(videoWidth - videoIconGroupWidth - this.config.style.icon.external.paddingX);
|
|
28887
28977
|
videoIconGroup.y(videoHeight - videoIconGroupHeight - this.config.style.icon.external.paddingY);
|
|
28888
28978
|
const nodesSelectionPlugin = this.getNodeSelectionPlugin();
|
|
28889
|
-
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()
|
|
28979
|
+
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()?.forceUpdate();
|
|
28890
28980
|
this.resolveAsyncElement(id);
|
|
28891
28981
|
};
|
|
28892
28982
|
}
|
|
@@ -29279,7 +29369,7 @@ var WeaveVideoNode = class extends WeaveNode {
|
|
|
29279
29369
|
videoIconGroup.x(videoWidth - videoIconGroupWidth - this.config.style.icon.external.paddingX);
|
|
29280
29370
|
videoIconGroup.y(videoHeight - videoIconGroupHeight - this.config.style.icon.external.paddingY);
|
|
29281
29371
|
const nodesSelectionPlugin = this.getNodeSelectionPlugin();
|
|
29282
|
-
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()
|
|
29372
|
+
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer()?.forceUpdate();
|
|
29283
29373
|
}
|
|
29284
29374
|
getNodeSelectionPlugin() {
|
|
29285
29375
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -31896,7 +31986,7 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
|
|
|
31896
31986
|
}
|
|
31897
31987
|
cleanup() {
|
|
31898
31988
|
const stage = this.instance.getStage();
|
|
31899
|
-
this.instance.triggerAction(this.previousAction);
|
|
31989
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
31900
31990
|
stage.container().style.cursor = "default";
|
|
31901
31991
|
}
|
|
31902
31992
|
};
|
|
@@ -31930,7 +32020,7 @@ var WeaveZoomInToolAction = class extends WeaveAction {
|
|
|
31930
32020
|
}
|
|
31931
32021
|
cleanup() {
|
|
31932
32022
|
const stage = this.instance.getStage();
|
|
31933
|
-
this.instance.triggerAction(this.previousAction);
|
|
32023
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
31934
32024
|
stage.container().style.cursor = "default";
|
|
31935
32025
|
}
|
|
31936
32026
|
};
|
|
@@ -31963,7 +32053,7 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
|
|
|
31963
32053
|
}
|
|
31964
32054
|
cleanup() {
|
|
31965
32055
|
const stage = this.instance.getStage();
|
|
31966
|
-
this.instance.triggerAction(this.previousAction);
|
|
32056
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
31967
32057
|
stage.container().style.cursor = "default";
|
|
31968
32058
|
}
|
|
31969
32059
|
};
|
|
@@ -32005,7 +32095,7 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
|
|
|
32005
32095
|
}
|
|
32006
32096
|
cleanup() {
|
|
32007
32097
|
const stage = this.instance.getStage();
|
|
32008
|
-
if (this.previousAction) this.instance.triggerAction(this.previousAction);
|
|
32098
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
32009
32099
|
stage.container().style.cursor = "default";
|
|
32010
32100
|
}
|
|
32011
32101
|
};
|
|
@@ -33246,14 +33336,19 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
33246
33336
|
});
|
|
33247
33337
|
window.addEventListener("keydown", (e) => {
|
|
33248
33338
|
if (e.code === "Enter" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
|
|
33339
|
+
e.stopPropagation();
|
|
33249
33340
|
this.cancelAction();
|
|
33250
33341
|
return;
|
|
33251
33342
|
}
|
|
33252
33343
|
if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
|
|
33344
|
+
e.stopPropagation();
|
|
33253
33345
|
this.isSpacePressed = true;
|
|
33254
33346
|
return;
|
|
33255
33347
|
}
|
|
33256
|
-
if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME)
|
|
33348
|
+
if (e.code === "Escape" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
|
|
33349
|
+
e.stopPropagation();
|
|
33350
|
+
this.cancelAction();
|
|
33351
|
+
}
|
|
33257
33352
|
});
|
|
33258
33353
|
const handlePointerDown = (e) => {
|
|
33259
33354
|
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
@@ -33612,12 +33707,9 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
|
|
|
33612
33707
|
var WeaveImageToolAction = class extends WeaveAction {
|
|
33613
33708
|
initialized = false;
|
|
33614
33709
|
initialCursor = null;
|
|
33615
|
-
|
|
33616
|
-
imageURL = null;
|
|
33617
|
-
forceMainContainer = false;
|
|
33710
|
+
imageAction = {};
|
|
33618
33711
|
ignoreKeyboardEvents = false;
|
|
33619
33712
|
ignorePointerEvents = false;
|
|
33620
|
-
uploadType = null;
|
|
33621
33713
|
onPropsChange = void 0;
|
|
33622
33714
|
update = void 0;
|
|
33623
33715
|
constructor(params) {
|
|
@@ -33625,14 +33717,10 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33625
33717
|
this.config = mergeExceptArrays(WEAVE_IMAGE_TOOL_CONFIG_DEFAULT, params?.config ?? {});
|
|
33626
33718
|
this.pointers = new Map();
|
|
33627
33719
|
this.initialized = false;
|
|
33628
|
-
this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
|
|
33629
33720
|
this.imageId = null;
|
|
33721
|
+
this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
|
|
33630
33722
|
this.tempImageId = null;
|
|
33631
33723
|
this.tempImageNode = null;
|
|
33632
|
-
this.container = void 0;
|
|
33633
|
-
this.imageURL = null;
|
|
33634
|
-
this.uploadType = null;
|
|
33635
|
-
this.clickPoint = null;
|
|
33636
33724
|
}
|
|
33637
33725
|
getName() {
|
|
33638
33726
|
return WEAVE_IMAGE_TOOL_ACTION_NAME;
|
|
@@ -33704,66 +33792,54 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33704
33792
|
stage.on("pointerup", (e) => {
|
|
33705
33793
|
if (this.ignorePointerEvents) return;
|
|
33706
33794
|
this.pointers.delete(e.evt.pointerId);
|
|
33707
|
-
if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding();
|
|
33795
|
+
if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding(this.imageId ?? "");
|
|
33708
33796
|
});
|
|
33709
33797
|
this.initialized = true;
|
|
33710
33798
|
}
|
|
33711
33799
|
setState(state) {
|
|
33712
33800
|
this.state = state;
|
|
33713
33801
|
}
|
|
33714
|
-
async loadImage(params) {
|
|
33802
|
+
async loadImage(nodeId, params) {
|
|
33715
33803
|
this.setCursor();
|
|
33716
33804
|
this.setFocusStage();
|
|
33717
|
-
if (!this.imageId) {
|
|
33718
|
-
this.cancelAction();
|
|
33719
|
-
return;
|
|
33720
|
-
}
|
|
33721
33805
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
33722
33806
|
if (!imageNodeHandler) return;
|
|
33723
|
-
const actualImageId = this.imageId;
|
|
33724
33807
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33725
33808
|
const image = params.image;
|
|
33726
33809
|
const realImageSize = await getImageSizeFromFile(image.file);
|
|
33727
33810
|
const downscaledImage = await downscaleImageFile(image.file, image.downscaleRatio);
|
|
33728
|
-
|
|
33729
|
-
|
|
33730
|
-
|
|
33731
|
-
|
|
33732
|
-
|
|
33733
|
-
|
|
33734
|
-
|
|
33735
|
-
|
|
33736
|
-
|
|
33737
|
-
|
|
33738
|
-
|
|
33739
|
-
|
|
33740
|
-
|
|
33741
|
-
onError: () => {
|
|
33742
|
-
this.cancelAction();
|
|
33743
|
-
}
|
|
33744
|
-
});
|
|
33745
|
-
};
|
|
33746
|
-
reader.onerror = () => {};
|
|
33747
|
-
reader.readAsDataURL(downscaledImage);
|
|
33811
|
+
try {
|
|
33812
|
+
const dataURL = await this.getDataURL(downscaledImage);
|
|
33813
|
+
this.imageAction[nodeId].props = {
|
|
33814
|
+
...this.imageAction[nodeId].props,
|
|
33815
|
+
imageFallback: dataURL,
|
|
33816
|
+
imageURL: void 0,
|
|
33817
|
+
width: realImageSize.width,
|
|
33818
|
+
height: realImageSize.height
|
|
33819
|
+
};
|
|
33820
|
+
this.addImageNode(nodeId, params?.position);
|
|
33821
|
+
} catch {
|
|
33822
|
+
this.cancelAction();
|
|
33823
|
+
}
|
|
33748
33824
|
}
|
|
33749
33825
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL) {
|
|
33750
33826
|
const image = params.image;
|
|
33751
33827
|
setTimeout(() => {
|
|
33752
|
-
this.saveImageUrl(
|
|
33828
|
+
this.saveImageUrl(nodeId, image.url);
|
|
33753
33829
|
}, 0);
|
|
33754
|
-
this.addImageNode(params?.position);
|
|
33830
|
+
this.addImageNode(nodeId, params?.position);
|
|
33755
33831
|
}
|
|
33756
33832
|
}
|
|
33757
33833
|
isTouchDevice() {
|
|
33758
33834
|
return window.matchMedia("(pointer: coarse)").matches;
|
|
33759
33835
|
}
|
|
33760
|
-
addImageNode(position) {
|
|
33836
|
+
async addImageNode(nodeId, position) {
|
|
33761
33837
|
const stage = this.instance.getStage();
|
|
33762
33838
|
this.setCursor();
|
|
33763
33839
|
this.setFocusStage();
|
|
33764
33840
|
if (position) {
|
|
33765
33841
|
this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
33766
|
-
this.handleAdding(position);
|
|
33842
|
+
this.handleAdding(nodeId, position);
|
|
33767
33843
|
return;
|
|
33768
33844
|
}
|
|
33769
33845
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
@@ -33771,11 +33847,15 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33771
33847
|
this.cancelAction();
|
|
33772
33848
|
return;
|
|
33773
33849
|
}
|
|
33774
|
-
if (this.
|
|
33850
|
+
if (this.imageAction[nodeId]) {
|
|
33851
|
+
const { uploadType } = this.imageAction[nodeId];
|
|
33775
33852
|
const mousePos = stage.getRelativePointerPosition();
|
|
33776
33853
|
this.tempImageId = v4_default();
|
|
33777
|
-
let imageSource = imageNodeHandler.getImageSource(
|
|
33778
|
-
if (
|
|
33854
|
+
let imageSource = imageNodeHandler.getImageSource(nodeId);
|
|
33855
|
+
if (uploadType === "file") {
|
|
33856
|
+
imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
|
|
33857
|
+
imageSource ??= await this.loadImageDataURL(this.imageAction[nodeId].props.imageFallback);
|
|
33858
|
+
}
|
|
33779
33859
|
if (!imageSource) {
|
|
33780
33860
|
this.cancelAction();
|
|
33781
33861
|
return;
|
|
@@ -33809,37 +33889,41 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33809
33889
|
});
|
|
33810
33890
|
this.instance.getMainLayer()?.add(this.tempImageNode);
|
|
33811
33891
|
}
|
|
33812
|
-
this.instance.emitEvent("onAddingImage"
|
|
33892
|
+
this.instance.emitEvent("onAddingImage");
|
|
33893
|
+
this.imageAction[nodeId].clickPoint = null;
|
|
33813
33894
|
}
|
|
33814
|
-
this.clickPoint = null;
|
|
33815
33895
|
this.setState(WEAVE_IMAGE_TOOL_STATE.DEFINING_POSITION);
|
|
33816
33896
|
}
|
|
33817
|
-
handleAdding(position) {
|
|
33897
|
+
async handleAdding(nodeId, position) {
|
|
33818
33898
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
33819
33899
|
if (!imageNodeHandler) {
|
|
33820
33900
|
this.cancelAction();
|
|
33821
33901
|
return;
|
|
33822
33902
|
}
|
|
33823
|
-
if (this.
|
|
33824
|
-
|
|
33825
|
-
|
|
33903
|
+
if (this.imageAction[nodeId]) {
|
|
33904
|
+
const { uploadType, imageURL, forceMainContainer } = this.imageAction[nodeId];
|
|
33905
|
+
let imageSource = imageNodeHandler.getImageSource(nodeId);
|
|
33906
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33907
|
+
imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
|
|
33908
|
+
imageSource ??= await this.loadImageDataURL(this.imageAction[nodeId].props.imageFallback);
|
|
33909
|
+
}
|
|
33826
33910
|
if (!imageSource && !position) {
|
|
33827
33911
|
this.cancelAction();
|
|
33828
33912
|
return;
|
|
33829
33913
|
}
|
|
33830
33914
|
const { mousePoint, container } = this.instance.getMousePointer(position);
|
|
33831
|
-
this.clickPoint = mousePoint;
|
|
33832
|
-
this.container = container;
|
|
33915
|
+
this.imageAction[nodeId].clickPoint = mousePoint;
|
|
33916
|
+
this.imageAction[nodeId].container = container;
|
|
33833
33917
|
const nodeHandler = this.instance.getNodeHandler("image");
|
|
33834
|
-
const imageWidth = this.props.width ? this.props.width : imageSource?.width;
|
|
33835
|
-
const imageHeight = this.props.height ? this.props.height : imageSource?.height;
|
|
33918
|
+
const imageWidth = this.imageAction[nodeId].props.width ? this.imageAction[nodeId].props.width : imageSource?.width;
|
|
33919
|
+
const imageHeight = this.imageAction[nodeId].props.height ? this.imageAction[nodeId].props.height : imageSource?.height;
|
|
33836
33920
|
let realImageURL = void 0;
|
|
33837
|
-
if (
|
|
33921
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && imageURL) realImageURL = imageURL?.url;
|
|
33838
33922
|
if (nodeHandler) {
|
|
33839
|
-
const node = nodeHandler.create(
|
|
33840
|
-
...this.props,
|
|
33841
|
-
x: this.clickPoint
|
|
33842
|
-
y: this.clickPoint
|
|
33923
|
+
const node = nodeHandler.create(nodeId, {
|
|
33924
|
+
...this.imageAction[nodeId].props,
|
|
33925
|
+
x: this.imageAction[nodeId].clickPoint.x,
|
|
33926
|
+
y: this.imageAction[nodeId].clickPoint.y,
|
|
33843
33927
|
opacity: 1,
|
|
33844
33928
|
adding: false,
|
|
33845
33929
|
imageURL: realImageURL,
|
|
@@ -33857,23 +33941,24 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33857
33941
|
height: imageHeight
|
|
33858
33942
|
}
|
|
33859
33943
|
});
|
|
33860
|
-
this.instance.addNode(node,
|
|
33861
|
-
this.instance.emitEvent("onAddedImage", { nodeId
|
|
33862
|
-
if (
|
|
33863
|
-
const uploadImageFunctionInternal = async () => {
|
|
33864
|
-
const
|
|
33944
|
+
this.instance.addNode(node, forceMainContainer ? this.instance.getMainLayer()?.getAttrs().id : this.imageAction[nodeId].container?.getAttrs().id);
|
|
33945
|
+
this.instance.emitEvent("onAddedImage", { nodeId });
|
|
33946
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33947
|
+
const uploadImageFunctionInternal = async (imageActionData) => {
|
|
33948
|
+
const { uploadImageFunction, imageFile } = imageActionData;
|
|
33865
33949
|
try {
|
|
33866
|
-
const imageURL = await
|
|
33867
|
-
|
|
33950
|
+
const imageURL$1 = await uploadImageFunction?.(imageFile.file);
|
|
33951
|
+
if (!imageURL$1) return;
|
|
33952
|
+
this.saveImageUrl(nodeId, imageURL$1);
|
|
33868
33953
|
this.instance.emitEvent("onImageUploaded", {
|
|
33869
|
-
imageURL,
|
|
33954
|
+
imageURL: imageURL$1,
|
|
33870
33955
|
nodeId
|
|
33871
33956
|
});
|
|
33872
33957
|
} catch (error) {
|
|
33873
33958
|
this.instance.emitEvent("onImageUploadedError", { error });
|
|
33874
33959
|
}
|
|
33875
33960
|
};
|
|
33876
|
-
uploadImageFunctionInternal();
|
|
33961
|
+
uploadImageFunctionInternal(this.imageAction[nodeId]);
|
|
33877
33962
|
}
|
|
33878
33963
|
}
|
|
33879
33964
|
this.setState(WEAVE_IMAGE_TOOL_STATE.FINISHED);
|
|
@@ -33888,42 +33973,51 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33888
33973
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
33889
33974
|
this.ignorePointerEvents = false;
|
|
33890
33975
|
this.ignoreKeyboardEvents = false;
|
|
33891
|
-
|
|
33892
|
-
this.
|
|
33893
|
-
this.
|
|
33894
|
-
|
|
33895
|
-
|
|
33896
|
-
|
|
33976
|
+
const nodeId = params?.nodeId ?? v4_default();
|
|
33977
|
+
this.imageId = nodeId;
|
|
33978
|
+
this.imageAction[nodeId] = {
|
|
33979
|
+
props: this.initProps(),
|
|
33980
|
+
imageId: nodeId,
|
|
33981
|
+
clickPoint: null,
|
|
33982
|
+
container: void 0,
|
|
33983
|
+
imageFile: null,
|
|
33984
|
+
imageURL: null,
|
|
33985
|
+
forceMainContainer: params?.forceMainContainer ?? false,
|
|
33986
|
+
uploadType: null,
|
|
33987
|
+
uploadImageFunction: null
|
|
33988
|
+
};
|
|
33989
|
+
if (params?.imageId) this.imageAction[nodeId].imageId = params.imageId;
|
|
33897
33990
|
if (this.forceExecution) {
|
|
33898
33991
|
this.ignorePointerEvents = true;
|
|
33899
33992
|
this.ignoreKeyboardEvents = true;
|
|
33900
33993
|
}
|
|
33901
33994
|
if (params?.position) this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
33902
33995
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE && params.image) {
|
|
33903
|
-
this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
|
|
33904
|
-
this.imageFile = params.image;
|
|
33905
|
-
this.uploadImageFunction = params.uploadImageFunction;
|
|
33906
|
-
this.loadImage({
|
|
33996
|
+
this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
|
|
33997
|
+
this.imageAction[nodeId].imageFile = params.image;
|
|
33998
|
+
this.imageAction[nodeId].uploadImageFunction = params.uploadImageFunction;
|
|
33999
|
+
this.loadImage(nodeId, {
|
|
33907
34000
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
|
|
33908
34001
|
image: params.image,
|
|
33909
34002
|
position: params?.position
|
|
33910
34003
|
});
|
|
33911
34004
|
}
|
|
33912
34005
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && params.image) {
|
|
33913
|
-
this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
|
|
33914
|
-
this.imageURL = params.image;
|
|
33915
|
-
this.
|
|
34006
|
+
this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
|
|
34007
|
+
this.imageAction[nodeId].imageURL = params.image;
|
|
34008
|
+
this.imageAction[nodeId].props = {
|
|
34009
|
+
...this.imageAction[nodeId].props,
|
|
33916
34010
|
imageFallback: params.image.fallback,
|
|
33917
34011
|
width: params.image.width,
|
|
33918
34012
|
height: params.image.height
|
|
33919
|
-
}
|
|
33920
|
-
this.loadImage({
|
|
34013
|
+
};
|
|
34014
|
+
this.loadImage(nodeId, {
|
|
33921
34015
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
|
|
33922
34016
|
image: params.image,
|
|
33923
34017
|
position: params?.position
|
|
33924
34018
|
});
|
|
33925
34019
|
}
|
|
33926
|
-
return { nodeId
|
|
34020
|
+
return { nodeId };
|
|
33927
34021
|
}
|
|
33928
34022
|
saveImageUrl(nodeId, imageURL) {
|
|
33929
34023
|
const stage = this.instance.getStage();
|
|
@@ -33949,11 +34043,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33949
34043
|
this.instance.endDrag(WEAVE_IMAGE_TOOL_ACTION_NAME);
|
|
33950
34044
|
}
|
|
33951
34045
|
this.initialCursor = null;
|
|
33952
|
-
this.forceMainContainer = false;
|
|
33953
|
-
this.container = void 0;
|
|
33954
34046
|
this.tempImageNode = null;
|
|
33955
|
-
this.imageURL = null;
|
|
33956
|
-
this.clickPoint = null;
|
|
33957
34047
|
this.setState(WEAVE_IMAGE_TOOL_STATE.IDLE);
|
|
33958
34048
|
}
|
|
33959
34049
|
getImageNodeHandler() {
|
|
@@ -33976,6 +34066,30 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33976
34066
|
getActualState() {
|
|
33977
34067
|
return this.state;
|
|
33978
34068
|
}
|
|
34069
|
+
loadImageDataURL(imageDataURL) {
|
|
34070
|
+
return new Promise((resolve, reject) => {
|
|
34071
|
+
const imageEle = Konva.Util.createImageElement();
|
|
34072
|
+
imageEle.onerror = (error) => {
|
|
34073
|
+
reject(error);
|
|
34074
|
+
};
|
|
34075
|
+
imageEle.onload = async () => {
|
|
34076
|
+
resolve(imageEle);
|
|
34077
|
+
};
|
|
34078
|
+
imageEle.src = imageDataURL;
|
|
34079
|
+
});
|
|
34080
|
+
}
|
|
34081
|
+
getDataURL(blob) {
|
|
34082
|
+
return new Promise((resolve, reject) => {
|
|
34083
|
+
const reader = new FileReader();
|
|
34084
|
+
reader.onloadend = () => {
|
|
34085
|
+
resolve(reader.result);
|
|
34086
|
+
};
|
|
34087
|
+
reader.onerror = () => {
|
|
34088
|
+
reject(new Error("Failed to generate dataURL from file"));
|
|
34089
|
+
};
|
|
34090
|
+
reader.readAsDataURL(blob);
|
|
34091
|
+
});
|
|
34092
|
+
}
|
|
33979
34093
|
};
|
|
33980
34094
|
|
|
33981
34095
|
//#endregion
|
|
@@ -34024,18 +34138,13 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
|
|
|
34024
34138
|
layout: { columns: 4 }
|
|
34025
34139
|
};
|
|
34026
34140
|
|
|
34027
|
-
//#endregion
|
|
34028
|
-
//#region src/internal-utils/generic.ts
|
|
34029
|
-
function sleep(ms) {
|
|
34030
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34031
|
-
}
|
|
34032
|
-
|
|
34033
34141
|
//#endregion
|
|
34034
34142
|
//#region src/actions/images-tool/images-tool.ts
|
|
34035
34143
|
var WeaveImagesToolAction = class extends WeaveAction {
|
|
34036
34144
|
initialized = false;
|
|
34037
34145
|
initialCursor = null;
|
|
34038
34146
|
nodesIds = [];
|
|
34147
|
+
toAdd = 0;
|
|
34039
34148
|
imagesFile = [];
|
|
34040
34149
|
imagesURL = [];
|
|
34041
34150
|
forceMainContainer = false;
|
|
@@ -34123,7 +34232,10 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34123
34232
|
});
|
|
34124
34233
|
stage.on("pointerup", (e) => {
|
|
34125
34234
|
this.pointers.delete(e.evt.pointerId);
|
|
34126
|
-
if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION)
|
|
34235
|
+
if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION) {
|
|
34236
|
+
this.instance.emitEvent("onSelectedPositionImages");
|
|
34237
|
+
this.handleAdding();
|
|
34238
|
+
}
|
|
34127
34239
|
});
|
|
34128
34240
|
this.initialized = true;
|
|
34129
34241
|
}
|
|
@@ -34163,9 +34275,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34163
34275
|
const shadowBlur = this.config.style.cursor.imageThumbnails.shadowBlur;
|
|
34164
34276
|
const shadowOffset = this.config.style.cursor.imageThumbnails.shadowOffset;
|
|
34165
34277
|
const shadowOpacity = this.config.style.cursor.imageThumbnails.shadowOpacity;
|
|
34166
|
-
const
|
|
34167
|
-
const imageWidth =
|
|
34168
|
-
const imageHeight =
|
|
34278
|
+
const scale = Math.min(maxImageWidth / imageSource.width, maxImageHeight / imageSource.height);
|
|
34279
|
+
const imageWidth = imageSource.width * scale * (1 / stage.scaleX());
|
|
34280
|
+
const imageHeight = imageSource.height * scale * (1 / stage.scaleY());
|
|
34169
34281
|
const imageNode = new Konva.Image({
|
|
34170
34282
|
x: position$1.x,
|
|
34171
34283
|
y: position$1.y,
|
|
@@ -34183,7 +34295,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34183
34295
|
shadowOffset,
|
|
34184
34296
|
shadowOpacity
|
|
34185
34297
|
});
|
|
34186
|
-
maxWidth = position$1.x + imageWidth;
|
|
34298
|
+
maxWidth = Math.max(maxWidth, position$1.x + imageWidth);
|
|
34187
34299
|
maxHeight = Math.max(maxHeight, position$1.y + imageHeight);
|
|
34188
34300
|
position$1 = {
|
|
34189
34301
|
x: position$1.x + imageThumbnailsPadding / stage.scaleX(),
|
|
@@ -34252,6 +34364,18 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34252
34364
|
let imagePositionX = originPoint.x;
|
|
34253
34365
|
let imagePositionY = originPoint.y;
|
|
34254
34366
|
let maxHeight = 0;
|
|
34367
|
+
this.nodesIds = [];
|
|
34368
|
+
const images = [];
|
|
34369
|
+
const checkAddedImages = ({ nodeId }) => {
|
|
34370
|
+
if (this.nodesIds.includes(nodeId)) this.handleImageAdded();
|
|
34371
|
+
if (this.getImagesAdded() <= 0) {
|
|
34372
|
+
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34373
|
+
this.cancelAction();
|
|
34374
|
+
this.instance.removeEventListener("onAddedImage", checkAddedImages);
|
|
34375
|
+
this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
|
|
34376
|
+
}
|
|
34377
|
+
};
|
|
34378
|
+
this.instance.addEventListener("onAddedImage", checkAddedImages);
|
|
34255
34379
|
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE && this.imagesFile) {
|
|
34256
34380
|
const imagesToUpload = this.imagesFile.length;
|
|
34257
34381
|
let imagesUploaded = 0;
|
|
@@ -34265,23 +34389,35 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34265
34389
|
};
|
|
34266
34390
|
this.instance.addEventListener("onImageUploaded", handleUploadImage);
|
|
34267
34391
|
for (let i = 0; i < this.imagesFile.length; i++) {
|
|
34268
|
-
const
|
|
34269
|
-
const
|
|
34270
|
-
const
|
|
34271
|
-
|
|
34272
|
-
|
|
34392
|
+
const nodeId = v4_default();
|
|
34393
|
+
const image = this.imagesFile[i];
|
|
34394
|
+
const { width, height } = image;
|
|
34395
|
+
const handleImage = async (nodeId$1, imageFile, position$1) => {
|
|
34396
|
+
const { imageId } = imageFile;
|
|
34397
|
+
const uploadImageFunctionInternal = async () => {
|
|
34398
|
+
const imageURL = await this.uploadImageFunction(imageFile.file);
|
|
34399
|
+
return imageURL;
|
|
34400
|
+
};
|
|
34401
|
+
this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
|
|
34402
|
+
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
|
|
34403
|
+
image: {
|
|
34404
|
+
file: imageFile.file,
|
|
34405
|
+
downscaleRatio: imageFile.downscaleRatio
|
|
34406
|
+
},
|
|
34407
|
+
uploadImageFunction: uploadImageFunctionInternal,
|
|
34408
|
+
...imageId && { imageId },
|
|
34409
|
+
position: {
|
|
34410
|
+
x: position$1.x,
|
|
34411
|
+
y: position$1.y
|
|
34412
|
+
},
|
|
34413
|
+
forceMainContainer: this.forceMainContainer,
|
|
34414
|
+
nodeId: nodeId$1
|
|
34415
|
+
}, true);
|
|
34273
34416
|
};
|
|
34274
|
-
|
|
34275
|
-
|
|
34276
|
-
|
|
34277
|
-
|
|
34278
|
-
...imageId && { imageId },
|
|
34279
|
-
position: {
|
|
34280
|
-
x: imagePositionX,
|
|
34281
|
-
y: imagePositionY
|
|
34282
|
-
},
|
|
34283
|
-
forceMainContainer: this.forceMainContainer
|
|
34284
|
-
}, true);
|
|
34417
|
+
images.push(handleImage(nodeId, image, {
|
|
34418
|
+
x: imagePositionX,
|
|
34419
|
+
y: imagePositionY
|
|
34420
|
+
}));
|
|
34285
34421
|
this.nodesIds.push(nodeId);
|
|
34286
34422
|
maxHeight = Math.max(maxHeight, height);
|
|
34287
34423
|
imagePositionX += imagesPadding + width;
|
|
@@ -34290,40 +34426,51 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34290
34426
|
imagePositionY = imagePositionY + maxHeight + imagesPadding;
|
|
34291
34427
|
maxHeight = 0;
|
|
34292
34428
|
}
|
|
34293
|
-
while (imageToolActionHandler.getActualState() !== WEAVE_IMAGES_TOOL_STATE.IDLE) await sleep(10);
|
|
34294
34429
|
}
|
|
34295
|
-
this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
|
|
34296
34430
|
}
|
|
34297
|
-
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) {
|
|
34298
|
-
|
|
34299
|
-
|
|
34300
|
-
|
|
34301
|
-
const
|
|
34302
|
-
|
|
34431
|
+
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) for (let i = 0; i < this.imagesURL.length; i++) {
|
|
34432
|
+
const nodeId = v4_default();
|
|
34433
|
+
const image = this.imagesURL[i];
|
|
34434
|
+
const handleImage = async (nodeId$1, imageURL, position$1) => {
|
|
34435
|
+
const { imageId, options } = imageURL;
|
|
34436
|
+
this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
|
|
34303
34437
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
|
|
34304
|
-
image:
|
|
34438
|
+
image: {
|
|
34439
|
+
url: imageURL.url,
|
|
34440
|
+
fallback: imageURL.fallback,
|
|
34441
|
+
width: imageURL.width,
|
|
34442
|
+
height: imageURL.height
|
|
34443
|
+
},
|
|
34305
34444
|
...imageId && { imageId },
|
|
34306
34445
|
...options && { options },
|
|
34307
34446
|
position: {
|
|
34308
|
-
x:
|
|
34309
|
-
y:
|
|
34447
|
+
x: position$1.x,
|
|
34448
|
+
y: position$1.y
|
|
34310
34449
|
},
|
|
34311
|
-
forceMainContainer: this.forceMainContainer
|
|
34450
|
+
forceMainContainer: this.forceMainContainer,
|
|
34451
|
+
nodeId: nodeId$1
|
|
34312
34452
|
}, true);
|
|
34313
|
-
|
|
34314
|
-
|
|
34315
|
-
imagePositionX
|
|
34316
|
-
|
|
34317
|
-
|
|
34318
|
-
|
|
34319
|
-
|
|
34320
|
-
|
|
34321
|
-
|
|
34322
|
-
|
|
34323
|
-
|
|
34453
|
+
};
|
|
34454
|
+
images.push(handleImage(nodeId, image, {
|
|
34455
|
+
x: imagePositionX,
|
|
34456
|
+
y: imagePositionY
|
|
34457
|
+
}));
|
|
34458
|
+
this.nodesIds.push(nodeId);
|
|
34459
|
+
maxHeight = Math.max(maxHeight, image.height);
|
|
34460
|
+
imagePositionX += imagesPadding + image.width;
|
|
34461
|
+
if ((i + 1) % layoutColumns === 0) {
|
|
34462
|
+
imagePositionX = originPoint.x;
|
|
34463
|
+
imagePositionY = imagePositionY + maxHeight + imagesPadding;
|
|
34464
|
+
maxHeight = 0;
|
|
34465
|
+
}
|
|
34466
|
+
}
|
|
34467
|
+
if (this.nodesIds.length > 0) {
|
|
34468
|
+
this.toAdd = this.nodesIds.length;
|
|
34469
|
+
await Promise.allSettled(images);
|
|
34470
|
+
} else {
|
|
34471
|
+
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34472
|
+
this.cancelAction();
|
|
34324
34473
|
}
|
|
34325
|
-
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34326
|
-
this.cancelAction();
|
|
34327
34474
|
}
|
|
34328
34475
|
trigger(cancelAction, params) {
|
|
34329
34476
|
if (!this.instance) throw new Error("Instance not defined");
|
|
@@ -34332,6 +34479,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34332
34479
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
34333
34480
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
34334
34481
|
if (params?.position) this.setState(WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION);
|
|
34482
|
+
this.nodesIds = [];
|
|
34335
34483
|
this.forceMainContainer = params.forceMainContainer ?? false;
|
|
34336
34484
|
if (params.type === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE) {
|
|
34337
34485
|
this.uploadType = WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE;
|
|
@@ -34379,6 +34527,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34379
34527
|
selectionPlugin.setSelectedNodes(addedNodes);
|
|
34380
34528
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
34381
34529
|
}
|
|
34530
|
+
this.instance.emitEvent("onFinishedImages");
|
|
34382
34531
|
this.instance.endDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
|
|
34383
34532
|
stage.container().style.cursor = "default";
|
|
34384
34533
|
this.uploadType = null;
|
|
@@ -34386,6 +34535,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34386
34535
|
this.initialCursor = null;
|
|
34387
34536
|
this.container = void 0;
|
|
34388
34537
|
this.clickPoint = null;
|
|
34538
|
+
this.nodesIds = [];
|
|
34539
|
+
this.toAdd = 0;
|
|
34389
34540
|
this.setState(WEAVE_IMAGES_TOOL_STATE.IDLE);
|
|
34390
34541
|
}
|
|
34391
34542
|
setCursor() {
|
|
@@ -34401,6 +34552,12 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34401
34552
|
isTouchDevice() {
|
|
34402
34553
|
return window.matchMedia("(pointer: coarse)").matches;
|
|
34403
34554
|
}
|
|
34555
|
+
getImagesAdded() {
|
|
34556
|
+
return this.toAdd;
|
|
34557
|
+
}
|
|
34558
|
+
handleImageAdded() {
|
|
34559
|
+
this.toAdd = this.toAdd - 1;
|
|
34560
|
+
}
|
|
34404
34561
|
setDragAndDropProperties(properties) {
|
|
34405
34562
|
this.instance.startDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
|
|
34406
34563
|
this.instance.setDragProperties(properties);
|