@inditextech/weave-sdk 3.2.0-SNAPSHOT.112.1 → 3.2.0-SNAPSHOT.116.1
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 +254 -190
- package/dist/sdk.node.js +254 -190
- package/dist/types.d.ts +35 -33
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +254 -190
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.js
CHANGED
|
@@ -21957,7 +21957,7 @@ var WeaveRegisterManager = class {
|
|
|
21957
21957
|
|
|
21958
21958
|
//#endregion
|
|
21959
21959
|
//#region package.json
|
|
21960
|
-
var version = "3.2.0-SNAPSHOT.
|
|
21960
|
+
var version = "3.2.0-SNAPSHOT.116.1";
|
|
21961
21961
|
|
|
21962
21962
|
//#endregion
|
|
21963
21963
|
//#region src/managers/setup.ts
|
|
@@ -25697,6 +25697,57 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
25697
25697
|
}
|
|
25698
25698
|
};
|
|
25699
25699
|
|
|
25700
|
+
//#endregion
|
|
25701
|
+
//#region src/nodes/image/utils.ts
|
|
25702
|
+
const extractCursorUrl = (cursor, fallback) => {
|
|
25703
|
+
const lower = cursor.toLowerCase();
|
|
25704
|
+
const start = lower.indexOf("url(");
|
|
25705
|
+
if (start === -1) return {
|
|
25706
|
+
preload: false,
|
|
25707
|
+
cursor
|
|
25708
|
+
};
|
|
25709
|
+
let i = start + 4;
|
|
25710
|
+
const len = cursor.length;
|
|
25711
|
+
while (i < len && /\s/.test(cursor[i])) i++;
|
|
25712
|
+
let quote = null;
|
|
25713
|
+
if (cursor[i] === "\"" || cursor[i] === "'") {
|
|
25714
|
+
quote = cursor[i];
|
|
25715
|
+
i++;
|
|
25716
|
+
}
|
|
25717
|
+
let buf = "";
|
|
25718
|
+
for (; i < len; i++) {
|
|
25719
|
+
const ch = cursor[i];
|
|
25720
|
+
if (quote) {
|
|
25721
|
+
if (ch === quote) {
|
|
25722
|
+
i++;
|
|
25723
|
+
break;
|
|
25724
|
+
}
|
|
25725
|
+
buf += ch;
|
|
25726
|
+
} else {
|
|
25727
|
+
if (ch === ")") break;
|
|
25728
|
+
buf += ch;
|
|
25729
|
+
}
|
|
25730
|
+
}
|
|
25731
|
+
const url = buf.trim();
|
|
25732
|
+
if (!url) return {
|
|
25733
|
+
preload: false,
|
|
25734
|
+
cursor: fallback
|
|
25735
|
+
};
|
|
25736
|
+
if (!isAllowedUrl(url)) return {
|
|
25737
|
+
preload: false,
|
|
25738
|
+
cursor: fallback
|
|
25739
|
+
};
|
|
25740
|
+
return {
|
|
25741
|
+
preload: true,
|
|
25742
|
+
cursor: url
|
|
25743
|
+
};
|
|
25744
|
+
};
|
|
25745
|
+
const isAllowedUrl = (value) => {
|
|
25746
|
+
if (/^https?:\/\//i.test(value)) return true;
|
|
25747
|
+
if (/^(javascript|data|blob|ftp):/i.test(value)) return false;
|
|
25748
|
+
return true;
|
|
25749
|
+
};
|
|
25750
|
+
|
|
25700
25751
|
//#endregion
|
|
25701
25752
|
//#region src/nodes/image/image.ts
|
|
25702
25753
|
var WeaveImageNode = class extends WeaveNode {
|
|
@@ -25732,7 +25783,7 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
25732
25783
|
const cursorFallback = { loading: "wait" };
|
|
25733
25784
|
for (const cursorKey of cursors) {
|
|
25734
25785
|
const cursorValue = this.config.style.cursor[cursorKey];
|
|
25735
|
-
const { preload, cursor } =
|
|
25786
|
+
const { preload, cursor } = extractCursorUrl(cursorValue, cursorFallback[cursorKey]);
|
|
25736
25787
|
if (preload) cursorUrls.push({ src: cursor });
|
|
25737
25788
|
}
|
|
25738
25789
|
if (cursorUrls.length > 0) {
|
|
@@ -26552,54 +26603,6 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
26552
26603
|
delete this.imageFallback[nodeId];
|
|
26553
26604
|
nodeInstance.destroy();
|
|
26554
26605
|
}
|
|
26555
|
-
extractCursorUrl(cursor, fallback) {
|
|
26556
|
-
const lower = cursor.toLowerCase();
|
|
26557
|
-
const start = lower.indexOf("url(");
|
|
26558
|
-
if (start === -1) return {
|
|
26559
|
-
preload: false,
|
|
26560
|
-
cursor
|
|
26561
|
-
};
|
|
26562
|
-
let i = start + 4;
|
|
26563
|
-
const len = cursor.length;
|
|
26564
|
-
while (i < len && /\s/.test(cursor[i])) i++;
|
|
26565
|
-
let quote = null;
|
|
26566
|
-
if (cursor[i] === "\"" || cursor[i] === "'") {
|
|
26567
|
-
quote = cursor[i];
|
|
26568
|
-
i++;
|
|
26569
|
-
}
|
|
26570
|
-
let buf = "";
|
|
26571
|
-
for (; i < len; i++) {
|
|
26572
|
-
const ch = cursor[i];
|
|
26573
|
-
if (quote) {
|
|
26574
|
-
if (ch === quote) {
|
|
26575
|
-
i++;
|
|
26576
|
-
break;
|
|
26577
|
-
}
|
|
26578
|
-
buf += ch;
|
|
26579
|
-
} else {
|
|
26580
|
-
if (ch === ")") break;
|
|
26581
|
-
buf += ch;
|
|
26582
|
-
}
|
|
26583
|
-
}
|
|
26584
|
-
const url = buf.trim();
|
|
26585
|
-
if (!url) return {
|
|
26586
|
-
preload: false,
|
|
26587
|
-
cursor: fallback
|
|
26588
|
-
};
|
|
26589
|
-
if (!this.isAllowedUrl(url)) return {
|
|
26590
|
-
preload: false,
|
|
26591
|
-
cursor: fallback
|
|
26592
|
-
};
|
|
26593
|
-
return {
|
|
26594
|
-
preload: true,
|
|
26595
|
-
cursor: url
|
|
26596
|
-
};
|
|
26597
|
-
}
|
|
26598
|
-
isAllowedUrl(value) {
|
|
26599
|
-
if (/^https?:\/\//i.test(value)) return true;
|
|
26600
|
-
if (/^(javascript|data|blob|ftp):/i.test(value)) return false;
|
|
26601
|
-
return true;
|
|
26602
|
-
}
|
|
26603
26606
|
};
|
|
26604
26607
|
|
|
26605
26608
|
//#endregion
|
|
@@ -31973,7 +31976,7 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
|
|
|
31973
31976
|
}
|
|
31974
31977
|
cleanup() {
|
|
31975
31978
|
const stage = this.instance.getStage();
|
|
31976
|
-
this.instance.triggerAction(this.previousAction);
|
|
31979
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
31977
31980
|
stage.container().style.cursor = "default";
|
|
31978
31981
|
}
|
|
31979
31982
|
};
|
|
@@ -32007,7 +32010,7 @@ var WeaveZoomInToolAction = class extends WeaveAction {
|
|
|
32007
32010
|
}
|
|
32008
32011
|
cleanup() {
|
|
32009
32012
|
const stage = this.instance.getStage();
|
|
32010
|
-
this.instance.triggerAction(this.previousAction);
|
|
32013
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
32011
32014
|
stage.container().style.cursor = "default";
|
|
32012
32015
|
}
|
|
32013
32016
|
};
|
|
@@ -32040,7 +32043,7 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
|
|
|
32040
32043
|
}
|
|
32041
32044
|
cleanup() {
|
|
32042
32045
|
const stage = this.instance.getStage();
|
|
32043
|
-
this.instance.triggerAction(this.previousAction);
|
|
32046
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
32044
32047
|
stage.container().style.cursor = "default";
|
|
32045
32048
|
}
|
|
32046
32049
|
};
|
|
@@ -32082,7 +32085,7 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
|
|
|
32082
32085
|
}
|
|
32083
32086
|
cleanup() {
|
|
32084
32087
|
const stage = this.instance.getStage();
|
|
32085
|
-
if (this.previousAction) this.instance.triggerAction(this.previousAction);
|
|
32088
|
+
if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
|
|
32086
32089
|
stage.container().style.cursor = "default";
|
|
32087
32090
|
}
|
|
32088
32091
|
};
|
|
@@ -33694,12 +33697,9 @@ const WEAVE_IMAGE_TOOL_CONFIG_DEFAULT = { style: { cursor: {
|
|
|
33694
33697
|
var WeaveImageToolAction = class extends WeaveAction {
|
|
33695
33698
|
initialized = false;
|
|
33696
33699
|
initialCursor = null;
|
|
33697
|
-
|
|
33698
|
-
imageURL = null;
|
|
33699
|
-
forceMainContainer = false;
|
|
33700
|
+
imageAction = {};
|
|
33700
33701
|
ignoreKeyboardEvents = false;
|
|
33701
33702
|
ignorePointerEvents = false;
|
|
33702
|
-
uploadType = null;
|
|
33703
33703
|
onPropsChange = void 0;
|
|
33704
33704
|
update = void 0;
|
|
33705
33705
|
constructor(params) {
|
|
@@ -33707,14 +33707,10 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33707
33707
|
this.config = mergeExceptArrays(WEAVE_IMAGE_TOOL_CONFIG_DEFAULT, params?.config ?? {});
|
|
33708
33708
|
this.pointers = new Map();
|
|
33709
33709
|
this.initialized = false;
|
|
33710
|
-
this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
|
|
33711
33710
|
this.imageId = null;
|
|
33711
|
+
this.state = WEAVE_IMAGE_TOOL_STATE.IDLE;
|
|
33712
33712
|
this.tempImageId = null;
|
|
33713
33713
|
this.tempImageNode = null;
|
|
33714
|
-
this.container = void 0;
|
|
33715
|
-
this.imageURL = null;
|
|
33716
|
-
this.uploadType = null;
|
|
33717
|
-
this.clickPoint = null;
|
|
33718
33714
|
}
|
|
33719
33715
|
getName() {
|
|
33720
33716
|
return WEAVE_IMAGE_TOOL_ACTION_NAME;
|
|
@@ -33786,66 +33782,54 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33786
33782
|
stage.on("pointerup", (e) => {
|
|
33787
33783
|
if (this.ignorePointerEvents) return;
|
|
33788
33784
|
this.pointers.delete(e.evt.pointerId);
|
|
33789
|
-
if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding();
|
|
33785
|
+
if (this.state === WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding(this.imageId ?? "");
|
|
33790
33786
|
});
|
|
33791
33787
|
this.initialized = true;
|
|
33792
33788
|
}
|
|
33793
33789
|
setState(state) {
|
|
33794
33790
|
this.state = state;
|
|
33795
33791
|
}
|
|
33796
|
-
async loadImage(params) {
|
|
33792
|
+
async loadImage(nodeId, params) {
|
|
33797
33793
|
this.setCursor();
|
|
33798
33794
|
this.setFocusStage();
|
|
33799
|
-
if (!this.imageId) {
|
|
33800
|
-
this.cancelAction();
|
|
33801
|
-
return;
|
|
33802
|
-
}
|
|
33803
33795
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
33804
33796
|
if (!imageNodeHandler) return;
|
|
33805
|
-
const actualImageId = this.imageId;
|
|
33806
33797
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33807
33798
|
const image = params.image;
|
|
33808
33799
|
const realImageSize = await getImageSizeFromFile(image.file);
|
|
33809
33800
|
const downscaledImage = await downscaleImageFile(image.file, image.downscaleRatio);
|
|
33810
|
-
|
|
33811
|
-
|
|
33812
|
-
|
|
33813
|
-
|
|
33814
|
-
|
|
33815
|
-
|
|
33816
|
-
|
|
33817
|
-
|
|
33818
|
-
|
|
33819
|
-
|
|
33820
|
-
|
|
33821
|
-
|
|
33822
|
-
|
|
33823
|
-
onError: () => {
|
|
33824
|
-
this.cancelAction();
|
|
33825
|
-
}
|
|
33826
|
-
});
|
|
33827
|
-
};
|
|
33828
|
-
reader.onerror = () => {};
|
|
33829
|
-
reader.readAsDataURL(downscaledImage);
|
|
33801
|
+
try {
|
|
33802
|
+
const dataURL = await this.getDataURL(downscaledImage);
|
|
33803
|
+
this.imageAction[nodeId].props = {
|
|
33804
|
+
...this.imageAction[nodeId].props,
|
|
33805
|
+
imageFallback: dataURL,
|
|
33806
|
+
imageURL: void 0,
|
|
33807
|
+
width: realImageSize.width,
|
|
33808
|
+
height: realImageSize.height
|
|
33809
|
+
};
|
|
33810
|
+
this.addImageNode(nodeId, params?.position);
|
|
33811
|
+
} catch {
|
|
33812
|
+
this.cancelAction();
|
|
33813
|
+
}
|
|
33830
33814
|
}
|
|
33831
33815
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL) {
|
|
33832
33816
|
const image = params.image;
|
|
33833
33817
|
setTimeout(() => {
|
|
33834
|
-
this.saveImageUrl(
|
|
33818
|
+
this.saveImageUrl(nodeId, image.url);
|
|
33835
33819
|
}, 0);
|
|
33836
|
-
this.addImageNode(params?.position);
|
|
33820
|
+
this.addImageNode(nodeId, params?.position);
|
|
33837
33821
|
}
|
|
33838
33822
|
}
|
|
33839
33823
|
isTouchDevice() {
|
|
33840
33824
|
return window.matchMedia("(pointer: coarse)").matches;
|
|
33841
33825
|
}
|
|
33842
|
-
addImageNode(position) {
|
|
33826
|
+
async addImageNode(nodeId, position) {
|
|
33843
33827
|
const stage = this.instance.getStage();
|
|
33844
33828
|
this.setCursor();
|
|
33845
33829
|
this.setFocusStage();
|
|
33846
33830
|
if (position) {
|
|
33847
33831
|
this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
33848
|
-
this.handleAdding(position);
|
|
33832
|
+
this.handleAdding(nodeId, position);
|
|
33849
33833
|
return;
|
|
33850
33834
|
}
|
|
33851
33835
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
@@ -33853,11 +33837,15 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33853
33837
|
this.cancelAction();
|
|
33854
33838
|
return;
|
|
33855
33839
|
}
|
|
33856
|
-
if (this.
|
|
33840
|
+
if (this.imageAction[nodeId]) {
|
|
33841
|
+
const { uploadType } = this.imageAction[nodeId];
|
|
33857
33842
|
const mousePos = stage.getRelativePointerPosition();
|
|
33858
33843
|
this.tempImageId = v4_default();
|
|
33859
|
-
let imageSource = imageNodeHandler.getImageSource(
|
|
33860
|
-
if (
|
|
33844
|
+
let imageSource = imageNodeHandler.getImageSource(nodeId);
|
|
33845
|
+
if (uploadType === "file") {
|
|
33846
|
+
imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
|
|
33847
|
+
if (!imageSource) imageSource = await this.loadImageSource(this.imageAction[nodeId].props.imageFallback);
|
|
33848
|
+
}
|
|
33861
33849
|
if (!imageSource) {
|
|
33862
33850
|
this.cancelAction();
|
|
33863
33851
|
return;
|
|
@@ -33891,37 +33879,41 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33891
33879
|
});
|
|
33892
33880
|
this.instance.getMainLayer()?.add(this.tempImageNode);
|
|
33893
33881
|
}
|
|
33894
|
-
this.instance.emitEvent("onAddingImage"
|
|
33882
|
+
this.instance.emitEvent("onAddingImage");
|
|
33883
|
+
this.imageAction[nodeId].clickPoint = null;
|
|
33895
33884
|
}
|
|
33896
|
-
this.clickPoint = null;
|
|
33897
33885
|
this.setState(WEAVE_IMAGE_TOOL_STATE.DEFINING_POSITION);
|
|
33898
33886
|
}
|
|
33899
|
-
handleAdding(position) {
|
|
33887
|
+
async handleAdding(nodeId, position) {
|
|
33900
33888
|
const imageNodeHandler = this.getImageNodeHandler();
|
|
33901
33889
|
if (!imageNodeHandler) {
|
|
33902
33890
|
this.cancelAction();
|
|
33903
33891
|
return;
|
|
33904
33892
|
}
|
|
33905
|
-
if (this.
|
|
33906
|
-
|
|
33907
|
-
|
|
33893
|
+
if (this.imageAction[nodeId]) {
|
|
33894
|
+
const { uploadType, imageURL, forceMainContainer } = this.imageAction[nodeId];
|
|
33895
|
+
let imageSource = imageNodeHandler.getImageSource(nodeId);
|
|
33896
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33897
|
+
imageSource = imageNodeHandler.getFallbackImageSource(nodeId);
|
|
33898
|
+
if (!imageSource) imageSource = await this.loadImageSource(this.imageAction[nodeId].props.imageFallback);
|
|
33899
|
+
}
|
|
33908
33900
|
if (!imageSource && !position) {
|
|
33909
33901
|
this.cancelAction();
|
|
33910
33902
|
return;
|
|
33911
33903
|
}
|
|
33912
33904
|
const { mousePoint, container } = this.instance.getMousePointer(position);
|
|
33913
|
-
this.clickPoint = mousePoint;
|
|
33914
|
-
this.container = container;
|
|
33905
|
+
this.imageAction[nodeId].clickPoint = mousePoint;
|
|
33906
|
+
this.imageAction[nodeId].container = container;
|
|
33915
33907
|
const nodeHandler = this.instance.getNodeHandler("image");
|
|
33916
|
-
const imageWidth = this.props.width ? this.props.width : imageSource?.width;
|
|
33917
|
-
const imageHeight = this.props.height ? this.props.height : imageSource?.height;
|
|
33908
|
+
const imageWidth = this.imageAction[nodeId].props.width ? this.imageAction[nodeId].props.width : imageSource?.width;
|
|
33909
|
+
const imageHeight = this.imageAction[nodeId].props.height ? this.imageAction[nodeId].props.height : imageSource?.height;
|
|
33918
33910
|
let realImageURL = void 0;
|
|
33919
|
-
if (
|
|
33911
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && imageURL) realImageURL = imageURL?.url;
|
|
33920
33912
|
if (nodeHandler) {
|
|
33921
|
-
const node = nodeHandler.create(
|
|
33922
|
-
...this.props,
|
|
33923
|
-
x: this.clickPoint
|
|
33924
|
-
y: this.clickPoint
|
|
33913
|
+
const node = nodeHandler.create(nodeId, {
|
|
33914
|
+
...this.imageAction[nodeId].props,
|
|
33915
|
+
x: this.imageAction[nodeId].clickPoint.x,
|
|
33916
|
+
y: this.imageAction[nodeId].clickPoint.y,
|
|
33925
33917
|
opacity: 1,
|
|
33926
33918
|
adding: false,
|
|
33927
33919
|
imageURL: realImageURL,
|
|
@@ -33939,23 +33931,24 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33939
33931
|
height: imageHeight
|
|
33940
33932
|
}
|
|
33941
33933
|
});
|
|
33942
|
-
this.instance.addNode(node,
|
|
33943
|
-
this.instance.emitEvent("onAddedImage", { nodeId
|
|
33944
|
-
if (
|
|
33945
|
-
const uploadImageFunctionInternal = async () => {
|
|
33946
|
-
const
|
|
33934
|
+
this.instance.addNode(node, forceMainContainer ? this.instance.getMainLayer()?.getAttrs().id : this.imageAction[nodeId].container?.getAttrs().id);
|
|
33935
|
+
this.instance.emitEvent("onAddedImage", { nodeId });
|
|
33936
|
+
if (uploadType === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE) {
|
|
33937
|
+
const uploadImageFunctionInternal = async (imageActionData) => {
|
|
33938
|
+
const { uploadImageFunction, imageFile } = imageActionData;
|
|
33947
33939
|
try {
|
|
33948
|
-
const imageURL = await
|
|
33949
|
-
|
|
33940
|
+
const imageURL$1 = await uploadImageFunction?.(imageFile.file);
|
|
33941
|
+
if (!imageURL$1) return;
|
|
33942
|
+
this.saveImageUrl(nodeId, imageURL$1);
|
|
33950
33943
|
this.instance.emitEvent("onImageUploaded", {
|
|
33951
|
-
imageURL,
|
|
33944
|
+
imageURL: imageURL$1,
|
|
33952
33945
|
nodeId
|
|
33953
33946
|
});
|
|
33954
33947
|
} catch (error) {
|
|
33955
33948
|
this.instance.emitEvent("onImageUploadedError", { error });
|
|
33956
33949
|
}
|
|
33957
33950
|
};
|
|
33958
|
-
uploadImageFunctionInternal();
|
|
33951
|
+
uploadImageFunctionInternal(this.imageAction[nodeId]);
|
|
33959
33952
|
}
|
|
33960
33953
|
}
|
|
33961
33954
|
this.setState(WEAVE_IMAGE_TOOL_STATE.FINISHED);
|
|
@@ -33970,11 +33963,19 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33970
33963
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
33971
33964
|
this.ignorePointerEvents = false;
|
|
33972
33965
|
this.ignoreKeyboardEvents = false;
|
|
33973
|
-
|
|
33974
|
-
this.
|
|
33975
|
-
this.
|
|
33976
|
-
|
|
33977
|
-
|
|
33966
|
+
const nodeId = params?.nodeId ?? v4_default();
|
|
33967
|
+
this.imageId = nodeId;
|
|
33968
|
+
this.imageAction[nodeId] = {
|
|
33969
|
+
props: this.initProps(),
|
|
33970
|
+
imageId: nodeId,
|
|
33971
|
+
clickPoint: null,
|
|
33972
|
+
container: void 0,
|
|
33973
|
+
imageFile: null,
|
|
33974
|
+
imageURL: null,
|
|
33975
|
+
forceMainContainer: params?.forceMainContainer ?? false,
|
|
33976
|
+
uploadType: null,
|
|
33977
|
+
uploadImageFunction: null
|
|
33978
|
+
};
|
|
33978
33979
|
if (params?.imageId) this.updateProps({ imageId: params.imageId });
|
|
33979
33980
|
if (this.forceExecution) {
|
|
33980
33981
|
this.ignorePointerEvents = true;
|
|
@@ -33982,30 +33983,30 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
33982
33983
|
}
|
|
33983
33984
|
if (params?.position) this.setState(WEAVE_IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
33984
33985
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE && params.image) {
|
|
33985
|
-
this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
|
|
33986
|
-
this.imageFile = params.image;
|
|
33987
|
-
this.uploadImageFunction = params.uploadImageFunction;
|
|
33988
|
-
this.loadImage({
|
|
33986
|
+
this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE;
|
|
33987
|
+
this.imageAction[nodeId].imageFile = params.image;
|
|
33988
|
+
this.imageAction[nodeId].uploadImageFunction = params.uploadImageFunction;
|
|
33989
|
+
this.loadImage(nodeId, {
|
|
33989
33990
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
|
|
33990
33991
|
image: params.image,
|
|
33991
33992
|
position: params?.position
|
|
33992
33993
|
});
|
|
33993
33994
|
}
|
|
33994
33995
|
if (params.type === WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL && params.image) {
|
|
33995
|
-
this.uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
|
|
33996
|
-
this.imageURL = params.image;
|
|
33996
|
+
this.imageAction[nodeId].uploadType = WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL;
|
|
33997
|
+
this.imageAction[nodeId].imageURL = params.image;
|
|
33997
33998
|
this.updateProps({
|
|
33998
33999
|
imageFallback: params.image.fallback,
|
|
33999
34000
|
width: params.image.width,
|
|
34000
34001
|
height: params.image.height
|
|
34001
34002
|
});
|
|
34002
|
-
this.loadImage({
|
|
34003
|
+
this.loadImage(nodeId, {
|
|
34003
34004
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
|
|
34004
34005
|
image: params.image,
|
|
34005
34006
|
position: params?.position
|
|
34006
34007
|
});
|
|
34007
34008
|
}
|
|
34008
|
-
return { nodeId
|
|
34009
|
+
return { nodeId };
|
|
34009
34010
|
}
|
|
34010
34011
|
saveImageUrl(nodeId, imageURL) {
|
|
34011
34012
|
const stage = this.instance.getStage();
|
|
@@ -34031,11 +34032,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
34031
34032
|
this.instance.endDrag(WEAVE_IMAGE_TOOL_ACTION_NAME);
|
|
34032
34033
|
}
|
|
34033
34034
|
this.initialCursor = null;
|
|
34034
|
-
this.forceMainContainer = false;
|
|
34035
|
-
this.container = void 0;
|
|
34036
34035
|
this.tempImageNode = null;
|
|
34037
|
-
this.imageURL = null;
|
|
34038
|
-
this.clickPoint = null;
|
|
34039
34036
|
this.setState(WEAVE_IMAGE_TOOL_STATE.IDLE);
|
|
34040
34037
|
}
|
|
34041
34038
|
getImageNodeHandler() {
|
|
@@ -34058,6 +34055,30 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
34058
34055
|
getActualState() {
|
|
34059
34056
|
return this.state;
|
|
34060
34057
|
}
|
|
34058
|
+
loadImageSource(imageDataURL) {
|
|
34059
|
+
return new Promise((resolve, reject) => {
|
|
34060
|
+
const imageEle = Konva.Util.createImageElement();
|
|
34061
|
+
imageEle.onerror = (error) => {
|
|
34062
|
+
reject(error);
|
|
34063
|
+
};
|
|
34064
|
+
imageEle.onload = async () => {
|
|
34065
|
+
resolve(imageEle);
|
|
34066
|
+
};
|
|
34067
|
+
imageEle.src = imageDataURL;
|
|
34068
|
+
});
|
|
34069
|
+
}
|
|
34070
|
+
getDataURL(blob) {
|
|
34071
|
+
return new Promise((resolve, reject) => {
|
|
34072
|
+
const reader = new FileReader();
|
|
34073
|
+
reader.onloadend = () => {
|
|
34074
|
+
resolve(reader.result);
|
|
34075
|
+
};
|
|
34076
|
+
reader.onerror = () => {
|
|
34077
|
+
reject(new Error("Failed to generate dataURL from file"));
|
|
34078
|
+
};
|
|
34079
|
+
reader.readAsDataURL(blob);
|
|
34080
|
+
});
|
|
34081
|
+
}
|
|
34061
34082
|
};
|
|
34062
34083
|
|
|
34063
34084
|
//#endregion
|
|
@@ -34106,18 +34127,13 @@ const WEAVE_IMAGES_TOOL_DEFAULT_CONFIG = {
|
|
|
34106
34127
|
layout: { columns: 4 }
|
|
34107
34128
|
};
|
|
34108
34129
|
|
|
34109
|
-
//#endregion
|
|
34110
|
-
//#region src/internal-utils/generic.ts
|
|
34111
|
-
function sleep(ms) {
|
|
34112
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34113
|
-
}
|
|
34114
|
-
|
|
34115
34130
|
//#endregion
|
|
34116
34131
|
//#region src/actions/images-tool/images-tool.ts
|
|
34117
34132
|
var WeaveImagesToolAction = class extends WeaveAction {
|
|
34118
34133
|
initialized = false;
|
|
34119
34134
|
initialCursor = null;
|
|
34120
34135
|
nodesIds = [];
|
|
34136
|
+
toAdd = 0;
|
|
34121
34137
|
imagesFile = [];
|
|
34122
34138
|
imagesURL = [];
|
|
34123
34139
|
forceMainContainer = false;
|
|
@@ -34205,7 +34221,10 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34205
34221
|
});
|
|
34206
34222
|
stage.on("pointerup", (e) => {
|
|
34207
34223
|
this.pointers.delete(e.evt.pointerId);
|
|
34208
|
-
if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION)
|
|
34224
|
+
if (this.state === WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION) {
|
|
34225
|
+
this.instance.emitEvent("onSelectedPositionImages");
|
|
34226
|
+
this.handleAdding();
|
|
34227
|
+
}
|
|
34209
34228
|
});
|
|
34210
34229
|
this.initialized = true;
|
|
34211
34230
|
}
|
|
@@ -34245,9 +34264,9 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34245
34264
|
const shadowBlur = this.config.style.cursor.imageThumbnails.shadowBlur;
|
|
34246
34265
|
const shadowOffset = this.config.style.cursor.imageThumbnails.shadowOffset;
|
|
34247
34266
|
const shadowOpacity = this.config.style.cursor.imageThumbnails.shadowOpacity;
|
|
34248
|
-
const
|
|
34249
|
-
const imageWidth =
|
|
34250
|
-
const imageHeight =
|
|
34267
|
+
const scale = Math.min(maxImageWidth / imageSource.width, maxImageHeight / imageSource.height);
|
|
34268
|
+
const imageWidth = imageSource.width * scale * (1 / stage.scaleX());
|
|
34269
|
+
const imageHeight = imageSource.height * scale * (1 / stage.scaleY());
|
|
34251
34270
|
const imageNode = new Konva.Image({
|
|
34252
34271
|
x: position$1.x,
|
|
34253
34272
|
y: position$1.y,
|
|
@@ -34265,7 +34284,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34265
34284
|
shadowOffset,
|
|
34266
34285
|
shadowOpacity
|
|
34267
34286
|
});
|
|
34268
|
-
maxWidth = position$1.x + imageWidth;
|
|
34287
|
+
maxWidth = Math.max(maxWidth, position$1.x + imageWidth);
|
|
34269
34288
|
maxHeight = Math.max(maxHeight, position$1.y + imageHeight);
|
|
34270
34289
|
position$1 = {
|
|
34271
34290
|
x: position$1.x + imageThumbnailsPadding / stage.scaleX(),
|
|
@@ -34334,6 +34353,18 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34334
34353
|
let imagePositionX = originPoint.x;
|
|
34335
34354
|
let imagePositionY = originPoint.y;
|
|
34336
34355
|
let maxHeight = 0;
|
|
34356
|
+
this.nodesIds = [];
|
|
34357
|
+
const images = [];
|
|
34358
|
+
const checkAddedImages = ({ nodeId }) => {
|
|
34359
|
+
if (this.nodesIds.includes(nodeId)) this.handleImageAdded();
|
|
34360
|
+
if (this.getImagesAdded() <= 0) {
|
|
34361
|
+
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34362
|
+
this.cancelAction();
|
|
34363
|
+
this.instance.removeEventListener("onAddedImage", checkAddedImages);
|
|
34364
|
+
this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
|
|
34365
|
+
}
|
|
34366
|
+
};
|
|
34367
|
+
this.instance.addEventListener("onAddedImage", checkAddedImages);
|
|
34337
34368
|
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE && this.imagesFile) {
|
|
34338
34369
|
const imagesToUpload = this.imagesFile.length;
|
|
34339
34370
|
let imagesUploaded = 0;
|
|
@@ -34347,23 +34378,35 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34347
34378
|
};
|
|
34348
34379
|
this.instance.addEventListener("onImageUploaded", handleUploadImage);
|
|
34349
34380
|
for (let i = 0; i < this.imagesFile.length; i++) {
|
|
34350
|
-
const
|
|
34351
|
-
const
|
|
34352
|
-
const
|
|
34353
|
-
|
|
34354
|
-
|
|
34381
|
+
const nodeId = v4_default();
|
|
34382
|
+
const image = this.imagesFile[i];
|
|
34383
|
+
const { width, height } = image;
|
|
34384
|
+
const handleImage = async (nodeId$1, imageFile, position$1) => {
|
|
34385
|
+
const { imageId } = imageFile;
|
|
34386
|
+
const uploadImageFunctionInternal = async () => {
|
|
34387
|
+
const imageURL = await this.uploadImageFunction(imageFile.file);
|
|
34388
|
+
return imageURL;
|
|
34389
|
+
};
|
|
34390
|
+
this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
|
|
34391
|
+
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.FILE,
|
|
34392
|
+
image: {
|
|
34393
|
+
file: imageFile.file,
|
|
34394
|
+
downscaleRatio: imageFile.downscaleRatio
|
|
34395
|
+
},
|
|
34396
|
+
uploadImageFunction: uploadImageFunctionInternal,
|
|
34397
|
+
...imageId && { imageId },
|
|
34398
|
+
position: {
|
|
34399
|
+
x: position$1.x,
|
|
34400
|
+
y: position$1.y
|
|
34401
|
+
},
|
|
34402
|
+
forceMainContainer: this.forceMainContainer,
|
|
34403
|
+
nodeId: nodeId$1
|
|
34404
|
+
}, true);
|
|
34355
34405
|
};
|
|
34356
|
-
|
|
34357
|
-
|
|
34358
|
-
|
|
34359
|
-
|
|
34360
|
-
...imageId && { imageId },
|
|
34361
|
-
position: {
|
|
34362
|
-
x: imagePositionX,
|
|
34363
|
-
y: imagePositionY
|
|
34364
|
-
},
|
|
34365
|
-
forceMainContainer: this.forceMainContainer
|
|
34366
|
-
}, true);
|
|
34406
|
+
images.push(handleImage(nodeId, image, {
|
|
34407
|
+
x: imagePositionX,
|
|
34408
|
+
y: imagePositionY
|
|
34409
|
+
}));
|
|
34367
34410
|
this.nodesIds.push(nodeId);
|
|
34368
34411
|
maxHeight = Math.max(maxHeight, height);
|
|
34369
34412
|
imagePositionX += imagesPadding + width;
|
|
@@ -34372,40 +34415,51 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34372
34415
|
imagePositionY = imagePositionY + maxHeight + imagesPadding;
|
|
34373
34416
|
maxHeight = 0;
|
|
34374
34417
|
}
|
|
34375
|
-
while (imageToolActionHandler.getActualState() !== WEAVE_IMAGES_TOOL_STATE.IDLE) await sleep(10);
|
|
34376
34418
|
}
|
|
34377
|
-
this.instance.emitEvent("onAddedImages", { nodesIds: this.nodesIds });
|
|
34378
34419
|
}
|
|
34379
|
-
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) {
|
|
34380
|
-
|
|
34381
|
-
|
|
34382
|
-
|
|
34383
|
-
const
|
|
34384
|
-
|
|
34420
|
+
if (this.uploadType === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL && this.imagesURL) for (let i = 0; i < this.imagesURL.length; i++) {
|
|
34421
|
+
const nodeId = v4_default();
|
|
34422
|
+
const image = this.imagesURL[i];
|
|
34423
|
+
const handleImage = async (nodeId$1, imageURL, position$1) => {
|
|
34424
|
+
const { imageId, options } = imageURL;
|
|
34425
|
+
this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
|
|
34385
34426
|
type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
|
|
34386
|
-
image:
|
|
34427
|
+
image: {
|
|
34428
|
+
url: imageURL.url,
|
|
34429
|
+
fallback: imageURL.fallback,
|
|
34430
|
+
width: imageURL.width,
|
|
34431
|
+
height: imageURL.height
|
|
34432
|
+
},
|
|
34387
34433
|
...imageId && { imageId },
|
|
34388
34434
|
...options && { options },
|
|
34389
34435
|
position: {
|
|
34390
|
-
x:
|
|
34391
|
-
y:
|
|
34436
|
+
x: position$1.x,
|
|
34437
|
+
y: position$1.y
|
|
34392
34438
|
},
|
|
34393
|
-
forceMainContainer: this.forceMainContainer
|
|
34439
|
+
forceMainContainer: this.forceMainContainer,
|
|
34440
|
+
nodeId: nodeId$1
|
|
34394
34441
|
}, true);
|
|
34395
|
-
|
|
34396
|
-
|
|
34397
|
-
imagePositionX
|
|
34398
|
-
|
|
34399
|
-
|
|
34400
|
-
|
|
34401
|
-
|
|
34402
|
-
|
|
34403
|
-
|
|
34404
|
-
|
|
34405
|
-
|
|
34442
|
+
};
|
|
34443
|
+
images.push(handleImage(nodeId, image, {
|
|
34444
|
+
x: imagePositionX,
|
|
34445
|
+
y: imagePositionY
|
|
34446
|
+
}));
|
|
34447
|
+
this.nodesIds.push(nodeId);
|
|
34448
|
+
maxHeight = Math.max(maxHeight, image.height);
|
|
34449
|
+
imagePositionX += imagesPadding + image.width;
|
|
34450
|
+
if ((i + 1) % layoutColumns === 0) {
|
|
34451
|
+
imagePositionX = originPoint.x;
|
|
34452
|
+
imagePositionY = imagePositionY + maxHeight + imagesPadding;
|
|
34453
|
+
maxHeight = 0;
|
|
34454
|
+
}
|
|
34455
|
+
}
|
|
34456
|
+
if (this.nodesIds.length > 0) {
|
|
34457
|
+
this.toAdd = this.nodesIds.length;
|
|
34458
|
+
await Promise.allSettled(images);
|
|
34459
|
+
} else {
|
|
34460
|
+
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34461
|
+
this.cancelAction();
|
|
34406
34462
|
}
|
|
34407
|
-
this.setState(WEAVE_IMAGES_TOOL_STATE.FINISHED);
|
|
34408
|
-
this.cancelAction();
|
|
34409
34463
|
}
|
|
34410
34464
|
trigger(cancelAction, params) {
|
|
34411
34465
|
if (!this.instance) throw new Error("Instance not defined");
|
|
@@ -34414,6 +34468,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34414
34468
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
34415
34469
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
34416
34470
|
if (params?.position) this.setState(WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION);
|
|
34471
|
+
this.nodesIds = [];
|
|
34417
34472
|
this.forceMainContainer = params.forceMainContainer ?? false;
|
|
34418
34473
|
if (params.type === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE) {
|
|
34419
34474
|
this.uploadType = WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE;
|
|
@@ -34461,6 +34516,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34461
34516
|
selectionPlugin.setSelectedNodes(addedNodes);
|
|
34462
34517
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
34463
34518
|
}
|
|
34519
|
+
this.instance.emitEvent("onFinishedImages");
|
|
34464
34520
|
this.instance.endDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
|
|
34465
34521
|
stage.container().style.cursor = "default";
|
|
34466
34522
|
this.uploadType = null;
|
|
@@ -34468,6 +34524,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34468
34524
|
this.initialCursor = null;
|
|
34469
34525
|
this.container = void 0;
|
|
34470
34526
|
this.clickPoint = null;
|
|
34527
|
+
this.nodesIds = [];
|
|
34528
|
+
this.toAdd = 0;
|
|
34471
34529
|
this.setState(WEAVE_IMAGES_TOOL_STATE.IDLE);
|
|
34472
34530
|
}
|
|
34473
34531
|
setCursor() {
|
|
@@ -34483,6 +34541,12 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
34483
34541
|
isTouchDevice() {
|
|
34484
34542
|
return window.matchMedia("(pointer: coarse)").matches;
|
|
34485
34543
|
}
|
|
34544
|
+
getImagesAdded() {
|
|
34545
|
+
return this.toAdd;
|
|
34546
|
+
}
|
|
34547
|
+
handleImageAdded() {
|
|
34548
|
+
this.toAdd = this.toAdd - 1;
|
|
34549
|
+
}
|
|
34486
34550
|
setDragAndDropProperties(properties) {
|
|
34487
34551
|
this.instance.startDrag(WEAVE_IMAGES_TOOL_ACTION_NAME);
|
|
34488
34552
|
this.instance.setDragProperties(properties);
|