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