@inditextech/weave-sdk 0.62.4 → 0.64.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.cjs +226 -29
- package/dist/sdk.d.cts +24 -6
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +24 -6
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +228 -31
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.js
CHANGED
|
@@ -2,7 +2,7 @@ import Konva from "konva";
|
|
|
2
2
|
import "konva/lib/types";
|
|
3
3
|
import { WEAVE_AWARENESS_LAYER_ID, WEAVE_EXPORT_BACKGROUND_COLOR, WEAVE_EXPORT_FORMATS, WEAVE_INSTANCE_STATUS, WEAVE_NODE_CUSTOM_EVENTS, WEAVE_NODE_LAYER_ID, WEAVE_NODE_POSITION, WEAVE_STORE_CONNECTION_STATUS, WEAVE_UTILITY_LAYER_ID } from "@inditextech/weave-types";
|
|
4
4
|
import { getYjsDoc, getYjsValue, observeDeep, syncedStore } from "@syncedstore/core";
|
|
5
|
-
import
|
|
5
|
+
import * as Y from "yjs";
|
|
6
6
|
import { Transformer } from "konva/lib/shapes/Transformer";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import ReactReconciler from "react-reconciler";
|
|
@@ -15540,6 +15540,10 @@ var WeaveStore = class {
|
|
|
15540
15540
|
getStateJson() {
|
|
15541
15541
|
return JSON.parse(JSON.stringify(this.state, void 0, 2));
|
|
15542
15542
|
}
|
|
15543
|
+
getStateSnapshot() {
|
|
15544
|
+
const doc = this.getDocument();
|
|
15545
|
+
return Y.encodeStateAsUpdate(doc);
|
|
15546
|
+
}
|
|
15543
15547
|
setup() {
|
|
15544
15548
|
this.isRoomLoaded = false;
|
|
15545
15549
|
this.instance.emitEvent("onRoomLoaded", this.isRoomLoaded);
|
|
@@ -15549,7 +15553,7 @@ var WeaveStore = class {
|
|
|
15549
15553
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15550
15554
|
);
|
|
15551
15555
|
if (weaveStateValues) {
|
|
15552
|
-
this.undoManager = new UndoManager([weaveStateValues], {
|
|
15556
|
+
this.undoManager = new Y.UndoManager([weaveStateValues], {
|
|
15553
15557
|
captureTimeout: 250,
|
|
15554
15558
|
trackedOrigins: new Set([this.config.getUser().id]),
|
|
15555
15559
|
...this.config?.undoManagerOptions
|
|
@@ -20112,7 +20116,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
20112
20116
|
const items = await navigator.clipboard.read();
|
|
20113
20117
|
if (await canHandleExternal(items)) return WEAVE_COPY_PASTE_PASTE_MODES.EXTERNAL;
|
|
20114
20118
|
} catch (e) {
|
|
20115
|
-
this.getLogger().error("Error reading clipboard data"
|
|
20119
|
+
this.getLogger().error({ error: e }, "Error reading clipboard data");
|
|
20116
20120
|
return WEAVE_COPY_PASTE_PASTE_MODES.CLIPBOARD_API_ERROR;
|
|
20117
20121
|
}
|
|
20118
20122
|
return WEAVE_COPY_PASTE_PASTE_MODES.NOT_ALLOWED;
|
|
@@ -22049,7 +22053,7 @@ var WeaveRegisterManager = class {
|
|
|
22049
22053
|
|
|
22050
22054
|
//#endregion
|
|
22051
22055
|
//#region package.json
|
|
22052
|
-
var version = "0.
|
|
22056
|
+
var version = "0.64.1";
|
|
22053
22057
|
|
|
22054
22058
|
//#endregion
|
|
22055
22059
|
//#region src/managers/setup.ts
|
|
@@ -22307,7 +22311,7 @@ var WeaveExportManager = class {
|
|
|
22307
22311
|
outH
|
|
22308
22312
|
};
|
|
22309
22313
|
}
|
|
22310
|
-
|
|
22314
|
+
exportNodesAsImage(nodes, boundingNodes, options) {
|
|
22311
22315
|
return new Promise((resolve) => {
|
|
22312
22316
|
const { format: format$2 = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
|
|
22313
22317
|
this.getNodesSelectionPlugin()?.disable();
|
|
@@ -22384,6 +22388,108 @@ var WeaveExportManager = class {
|
|
|
22384
22388
|
}
|
|
22385
22389
|
});
|
|
22386
22390
|
}
|
|
22391
|
+
async exportNodesAsBuffer(nodes, boundingNodes, options) {
|
|
22392
|
+
const { format: format$2 = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
|
|
22393
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
22394
|
+
this.getNodesDistanceSnappingPlugin()?.disable();
|
|
22395
|
+
this.getNodesEdgeSnappingPlugin()?.disable();
|
|
22396
|
+
this.getStageGridPlugin()?.disable();
|
|
22397
|
+
const stage = this.instance.getStage();
|
|
22398
|
+
const mainLayer = this.instance.getMainLayer();
|
|
22399
|
+
const originalPosition = {
|
|
22400
|
+
x: stage.x(),
|
|
22401
|
+
y: stage.y()
|
|
22402
|
+
};
|
|
22403
|
+
const originalScale = {
|
|
22404
|
+
x: stage.scaleX(),
|
|
22405
|
+
y: stage.scaleY()
|
|
22406
|
+
};
|
|
22407
|
+
stage.scale({
|
|
22408
|
+
x: 1,
|
|
22409
|
+
y: 1
|
|
22410
|
+
});
|
|
22411
|
+
let realNodes = [...nodes];
|
|
22412
|
+
if (nodes.length === 0) realNodes = mainLayer?.getChildren().map((node) => node.getAttrs().id ?? "") ?? [];
|
|
22413
|
+
const konvaNodes = [];
|
|
22414
|
+
for (const nodeId of realNodes) {
|
|
22415
|
+
const node = stage.findOne(`#${nodeId}`);
|
|
22416
|
+
if (node) konvaNodes.push(node);
|
|
22417
|
+
}
|
|
22418
|
+
if (mainLayer) {
|
|
22419
|
+
const bounds = getExportBoundingBox(stage, boundingNodes(konvaNodes));
|
|
22420
|
+
const scaleX = stage.scaleX();
|
|
22421
|
+
const scaleY = stage.scaleY();
|
|
22422
|
+
const unscaledBounds = {
|
|
22423
|
+
x: bounds.x / scaleX,
|
|
22424
|
+
y: bounds.y / scaleY,
|
|
22425
|
+
width: bounds.width / scaleX,
|
|
22426
|
+
height: bounds.height / scaleY
|
|
22427
|
+
};
|
|
22428
|
+
const exportGroup = new Konva.Group();
|
|
22429
|
+
const background = new Konva.Rect({
|
|
22430
|
+
x: unscaledBounds.x - padding,
|
|
22431
|
+
y: unscaledBounds.y - padding,
|
|
22432
|
+
width: unscaledBounds.width + 2 * padding,
|
|
22433
|
+
height: unscaledBounds.height + 2 * padding,
|
|
22434
|
+
strokeWidth: 0,
|
|
22435
|
+
fill: backgroundColor
|
|
22436
|
+
});
|
|
22437
|
+
exportGroup.add(background);
|
|
22438
|
+
for (const node of konvaNodes) {
|
|
22439
|
+
const clonedNode = node.clone({ id: v4_default() });
|
|
22440
|
+
const absPos = node.getAbsolutePosition();
|
|
22441
|
+
clonedNode.absolutePosition({
|
|
22442
|
+
x: absPos.x / scaleX,
|
|
22443
|
+
y: absPos.y / scaleY
|
|
22444
|
+
});
|
|
22445
|
+
exportGroup.add(clonedNode);
|
|
22446
|
+
}
|
|
22447
|
+
mainLayer.add(exportGroup);
|
|
22448
|
+
const backgroundRect = background.getClientRect();
|
|
22449
|
+
stage.batchDraw();
|
|
22450
|
+
const composites = [];
|
|
22451
|
+
const imageWidth = Math.round(backgroundRect.width);
|
|
22452
|
+
const imageHeight = Math.round(backgroundRect.height);
|
|
22453
|
+
const maxRenderSize = 1920;
|
|
22454
|
+
const cols = Math.ceil(imageWidth / maxRenderSize);
|
|
22455
|
+
const rows = Math.ceil(imageHeight / maxRenderSize);
|
|
22456
|
+
const tileWidth = Math.floor(imageWidth / cols);
|
|
22457
|
+
const tileHeight = Math.floor(imageHeight / rows);
|
|
22458
|
+
for (let y = 0; y < imageHeight; y += tileHeight) for (let x = 0; x < imageWidth; x += tileWidth) {
|
|
22459
|
+
const width = Math.min(tileWidth, imageWidth - x);
|
|
22460
|
+
const height = Math.min(tileHeight, imageHeight - y);
|
|
22461
|
+
const canvas = await exportGroup.toCanvas({
|
|
22462
|
+
x: Math.round(backgroundRect.x) + x,
|
|
22463
|
+
y: Math.round(backgroundRect.y) + y,
|
|
22464
|
+
width,
|
|
22465
|
+
height,
|
|
22466
|
+
mimeType: format$2,
|
|
22467
|
+
pixelRatio,
|
|
22468
|
+
quality: options.quality ?? 1
|
|
22469
|
+
});
|
|
22470
|
+
const buffer = canvas.toBuffer();
|
|
22471
|
+
composites.push({
|
|
22472
|
+
top: y * pixelRatio,
|
|
22473
|
+
left: x * pixelRatio,
|
|
22474
|
+
input: buffer
|
|
22475
|
+
});
|
|
22476
|
+
}
|
|
22477
|
+
exportGroup.destroy();
|
|
22478
|
+
stage.position(originalPosition);
|
|
22479
|
+
stage.scale(originalScale);
|
|
22480
|
+
stage.batchDraw();
|
|
22481
|
+
this.getNodesSelectionPlugin()?.enable();
|
|
22482
|
+
this.getNodesDistanceSnappingPlugin()?.enable();
|
|
22483
|
+
this.getNodesEdgeSnappingPlugin()?.enable();
|
|
22484
|
+
this.getStageGridPlugin()?.enable();
|
|
22485
|
+
return {
|
|
22486
|
+
composites,
|
|
22487
|
+
width: imageWidth * pixelRatio,
|
|
22488
|
+
height: imageHeight * pixelRatio
|
|
22489
|
+
};
|
|
22490
|
+
}
|
|
22491
|
+
throw new Error("Failed to export nodes as data URL");
|
|
22492
|
+
}
|
|
22387
22493
|
imageToBase64(img, mimeType) {
|
|
22388
22494
|
const canvas = document.createElement("canvas");
|
|
22389
22495
|
canvas.width = img.naturalWidth;
|
|
@@ -22436,6 +22542,51 @@ var WeavePluginsManager = class {
|
|
|
22436
22542
|
}
|
|
22437
22543
|
};
|
|
22438
22544
|
|
|
22545
|
+
//#endregion
|
|
22546
|
+
//#region src/watch-map.ts
|
|
22547
|
+
function watchMap(onChange, map = new Map()) {
|
|
22548
|
+
const handler = { get(target, prop, receiver) {
|
|
22549
|
+
if (prop === "set") return (key, value$1) => {
|
|
22550
|
+
const had = target.has(key);
|
|
22551
|
+
const prev = had ? target.get(key) : void 0;
|
|
22552
|
+
target.set(key, value$1);
|
|
22553
|
+
onChange({
|
|
22554
|
+
type: had ? "update" : "add",
|
|
22555
|
+
key,
|
|
22556
|
+
value: value$1,
|
|
22557
|
+
prevValue: prev,
|
|
22558
|
+
size: target.size
|
|
22559
|
+
});
|
|
22560
|
+
return receiver;
|
|
22561
|
+
};
|
|
22562
|
+
if (prop === "delete") return (key) => {
|
|
22563
|
+
const had = target.has(key);
|
|
22564
|
+
const prev = had ? target.get(key) : void 0;
|
|
22565
|
+
const ok = target.delete(key);
|
|
22566
|
+
if (ok && had) onChange({
|
|
22567
|
+
type: "delete",
|
|
22568
|
+
key,
|
|
22569
|
+
prevValue: prev,
|
|
22570
|
+
size: target.size
|
|
22571
|
+
});
|
|
22572
|
+
return ok;
|
|
22573
|
+
};
|
|
22574
|
+
if (prop === "clear") return () => {
|
|
22575
|
+
if (target.size > 0) {
|
|
22576
|
+
target.clear();
|
|
22577
|
+
onChange({
|
|
22578
|
+
type: "clear",
|
|
22579
|
+
size: 0
|
|
22580
|
+
});
|
|
22581
|
+
}
|
|
22582
|
+
};
|
|
22583
|
+
const value = Reflect.get(target, prop, receiver);
|
|
22584
|
+
if (typeof value === "function") return value.bind(target);
|
|
22585
|
+
return value;
|
|
22586
|
+
} };
|
|
22587
|
+
return new Proxy(map, handler);
|
|
22588
|
+
}
|
|
22589
|
+
|
|
22439
22590
|
//#endregion
|
|
22440
22591
|
//#region src/weave.ts
|
|
22441
22592
|
var Weave = class {
|
|
@@ -22446,7 +22597,10 @@ var Weave = class {
|
|
|
22446
22597
|
Konva.showWarnings = false;
|
|
22447
22598
|
this.id = v4_default();
|
|
22448
22599
|
this.initialized = false;
|
|
22449
|
-
this.
|
|
22600
|
+
this.asyncElements = watchMap(() => {
|
|
22601
|
+
this.emitEvent("onAsyncElementChange");
|
|
22602
|
+
}, new Map());
|
|
22603
|
+
this.config = (0, import_lodash.merge)({ serverSide: false }, weaveConfig);
|
|
22450
22604
|
this.logger = new WeaveLogger(this.config?.logger ?? {
|
|
22451
22605
|
disabled: false,
|
|
22452
22606
|
level: "error"
|
|
@@ -22468,9 +22622,6 @@ var Weave = class {
|
|
|
22468
22622
|
this.exportManager = new WeaveExportManager(this);
|
|
22469
22623
|
this.actionsManager = new WeaveActionsManager(this);
|
|
22470
22624
|
this.pluginsManager = new WeavePluginsManager(this);
|
|
22471
|
-
if (!window.weave) window.weave = this;
|
|
22472
|
-
window.weaveTextEditing = {};
|
|
22473
|
-
window.weaveDragImageURL = void 0;
|
|
22474
22625
|
this.setupManager.welcomeLog();
|
|
22475
22626
|
}
|
|
22476
22627
|
setupRenderer() {
|
|
@@ -22506,6 +22657,19 @@ var Weave = class {
|
|
|
22506
22657
|
}
|
|
22507
22658
|
async start() {
|
|
22508
22659
|
this.moduleLogger.info("Start instance");
|
|
22660
|
+
if (!this.config.serverSide) {
|
|
22661
|
+
if (!window.weave) window.weave = this;
|
|
22662
|
+
window.weaveTextEditing = {};
|
|
22663
|
+
window.weaveDragImageURL = void 0;
|
|
22664
|
+
}
|
|
22665
|
+
if (this.config.serverSide) {
|
|
22666
|
+
const { createCanvas, Image: Image$1 } = await import("canvas");
|
|
22667
|
+
globalThis.Image = Image$1;
|
|
22668
|
+
globalThis.document = { createElement(tag) {
|
|
22669
|
+
if (tag === "canvas") return createCanvas(1, 1);
|
|
22670
|
+
throw new Error(`Unsupported element: ${tag}`);
|
|
22671
|
+
} };
|
|
22672
|
+
}
|
|
22509
22673
|
this.emitEvent("onRoomLoaded", false);
|
|
22510
22674
|
this.status = WEAVE_INSTANCE_STATUS.STARTING;
|
|
22511
22675
|
this.emitEvent("onInstanceStatus", this.status);
|
|
@@ -22800,7 +22964,10 @@ var Weave = class {
|
|
|
22800
22964
|
return this.exportManager.imageToBase64(img, mimeType);
|
|
22801
22965
|
}
|
|
22802
22966
|
async exportNodes(nodes, boundingNodes, options) {
|
|
22803
|
-
return await this.exportManager.
|
|
22967
|
+
return await this.exportManager.exportNodesAsImage(nodes, boundingNodes, options);
|
|
22968
|
+
}
|
|
22969
|
+
async exportNodesAsBuffer(nodes, boundingNodes, options) {
|
|
22970
|
+
return await this.exportManager.exportNodesAsBuffer(nodes, boundingNodes, options);
|
|
22804
22971
|
}
|
|
22805
22972
|
allNodesLocked(nodes) {
|
|
22806
22973
|
let allNodesLocked = true;
|
|
@@ -22886,6 +23053,30 @@ var Weave = class {
|
|
|
22886
23053
|
nodeHandler.show(node);
|
|
22887
23054
|
}
|
|
22888
23055
|
}
|
|
23056
|
+
asyncElementsLoaded() {
|
|
23057
|
+
return [...this.asyncElements.values()].every((el) => el.status === "loaded");
|
|
23058
|
+
}
|
|
23059
|
+
loadAsyncElement(nodeId, type) {
|
|
23060
|
+
let element = this.asyncElements.get(nodeId);
|
|
23061
|
+
if (element) element.status = "loading";
|
|
23062
|
+
else element = {
|
|
23063
|
+
type,
|
|
23064
|
+
status: "loading"
|
|
23065
|
+
};
|
|
23066
|
+
this.asyncElements.set(nodeId, element);
|
|
23067
|
+
}
|
|
23068
|
+
resolveAsyncElement(nodeId, type) {
|
|
23069
|
+
let element = this.asyncElements.get(nodeId);
|
|
23070
|
+
if (element) element.status = "loaded";
|
|
23071
|
+
else element = {
|
|
23072
|
+
type,
|
|
23073
|
+
status: "loaded"
|
|
23074
|
+
};
|
|
23075
|
+
this.asyncElements.set(nodeId, element);
|
|
23076
|
+
}
|
|
23077
|
+
isServerSide() {
|
|
23078
|
+
return this.config.serverSide ?? false;
|
|
23079
|
+
}
|
|
22889
23080
|
};
|
|
22890
23081
|
|
|
22891
23082
|
//#endregion
|
|
@@ -22903,14 +23094,16 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
22903
23094
|
x: 0,
|
|
22904
23095
|
y: 0
|
|
22905
23096
|
});
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
23097
|
+
if (!this.instance.isServerSide()) {
|
|
23098
|
+
const container = stage.container();
|
|
23099
|
+
container.setAttribute("tabindex", "0");
|
|
23100
|
+
stage.container().addEventListener("focus", () => {
|
|
23101
|
+
this.stageFocused = true;
|
|
23102
|
+
});
|
|
23103
|
+
stage.container().addEventListener("blur", () => {
|
|
23104
|
+
this.stageFocused = false;
|
|
23105
|
+
});
|
|
23106
|
+
}
|
|
22914
23107
|
Konva.Stage.prototype.mode = function(mode) {
|
|
22915
23108
|
if (typeof mode !== "undefined") this._mode = mode;
|
|
22916
23109
|
return this._mode;
|
|
@@ -22930,11 +23123,11 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
22930
23123
|
stage.mode(WEAVE_STAGE_DEFAULT_MODE);
|
|
22931
23124
|
stage.on("pointerdown", (e) => {
|
|
22932
23125
|
if (e.evt.button === 1) this.wheelMousePressed = true;
|
|
22933
|
-
if ([MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grabbing";
|
|
23126
|
+
if (!this.instance.isServerSide() && [MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grabbing";
|
|
22934
23127
|
});
|
|
22935
23128
|
stage.on("pointermove", (e) => {
|
|
22936
23129
|
const activeAction = this.instance.getActiveAction();
|
|
22937
|
-
if (![MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "") && stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
|
|
23130
|
+
if (!this.instance.isServerSide() && ![MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "") && stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
|
|
22938
23131
|
const stage$1 = this.instance.getStage();
|
|
22939
23132
|
stage$1.container().style.cursor = "default";
|
|
22940
23133
|
}
|
|
@@ -22946,7 +23139,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
22946
23139
|
stage.on("pointerup", (e) => {
|
|
22947
23140
|
const activeAction = this.instance.getActiveAction();
|
|
22948
23141
|
if (e.evt.button === 1) this.wheelMousePressed = false;
|
|
22949
|
-
if ([MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) stage.container().style.cursor = "grab";
|
|
23142
|
+
if (!this.instance.isServerSide() && [MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) stage.container().style.cursor = "grab";
|
|
22950
23143
|
});
|
|
22951
23144
|
stage.on("pointerover", (e) => {
|
|
22952
23145
|
const activeAction = this.instance.getActiveAction();
|
|
@@ -22955,7 +23148,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
22955
23148
|
const parent = e.target.getParent();
|
|
22956
23149
|
if (parent && parent instanceof Konva.Transformer) return;
|
|
22957
23150
|
this.hideHoverState();
|
|
22958
|
-
stage.container().style.cursor = "default";
|
|
23151
|
+
if (!this.instance.isServerSide()) stage.container().style.cursor = "default";
|
|
22959
23152
|
});
|
|
22960
23153
|
return stage;
|
|
22961
23154
|
}
|
|
@@ -23343,7 +23536,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
23343
23536
|
text.on("transformend", () => {
|
|
23344
23537
|
this.instance.emitEvent("onTransform", null);
|
|
23345
23538
|
});
|
|
23346
|
-
window.addEventListener("keypress", (e) => {
|
|
23539
|
+
if (!this.instance.getConfiguration().serverSide) window.addEventListener("keypress", (e) => {
|
|
23347
23540
|
if (e.key === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing && e.target !== this.textArea) {
|
|
23348
23541
|
e.preventDefault();
|
|
23349
23542
|
if (this.isSelecting() && this.isNodeSelected(text)) {
|
|
@@ -24402,6 +24595,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
24402
24595
|
imageCrop.unCrop();
|
|
24403
24596
|
this.cachedCropInfo[imageNode.getAttrs().id ?? ""] = void 0;
|
|
24404
24597
|
};
|
|
24598
|
+
loadAsyncElement(nodeId) {
|
|
24599
|
+
this.instance.loadAsyncElement(nodeId, "image");
|
|
24600
|
+
}
|
|
24601
|
+
resolveAsyncElement(nodeId) {
|
|
24602
|
+
this.instance.resolveAsyncElement(nodeId, "image");
|
|
24603
|
+
}
|
|
24405
24604
|
onRender(props) {
|
|
24406
24605
|
const imageProperties = props.imageProperties;
|
|
24407
24606
|
const imageProps = props;
|
|
@@ -24601,13 +24800,15 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
24601
24800
|
const imageProps = params;
|
|
24602
24801
|
const imagePlaceholder = image.findOne(`#${imageProps.id}-placeholder`);
|
|
24603
24802
|
const internalImage = image.findOne(`#${imageProps.id}-image`);
|
|
24803
|
+
const realImageURL = this.config.urlTransformer?.(imageProps.imageURL ?? "") ?? imageProps.imageURL;
|
|
24604
24804
|
const imageObj = new Image();
|
|
24605
24805
|
imageObj.crossOrigin = this.config.crossOrigin;
|
|
24606
24806
|
imageObj.onerror = (error) => {
|
|
24607
|
-
console.error("Error loading image",
|
|
24807
|
+
console.error("Error loading image", realImageURL, error);
|
|
24608
24808
|
imagePlaceholder?.setAttrs({ visible: true });
|
|
24609
24809
|
internalImage?.setAttrs({ visible: false });
|
|
24610
24810
|
};
|
|
24811
|
+
this.loadAsyncElement(imageProps.id);
|
|
24611
24812
|
imageObj.onload = () => {
|
|
24612
24813
|
if (image && imagePlaceholder && internalImage) {
|
|
24613
24814
|
image.setAttrs({
|
|
@@ -24646,11 +24847,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
24646
24847
|
height: imageRect.height
|
|
24647
24848
|
});
|
|
24648
24849
|
this.updateImageCrop(imageProps);
|
|
24850
|
+
this.resolveAsyncElement(imageProps.id);
|
|
24649
24851
|
const nodeHandler = this.instance.getNodeHandler(image.getAttrs().nodeType);
|
|
24650
24852
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(image));
|
|
24651
24853
|
}
|
|
24652
24854
|
};
|
|
24653
|
-
if (
|
|
24855
|
+
if (realImageURL) imageObj.src = realImageURL;
|
|
24654
24856
|
}
|
|
24655
24857
|
updateImageCrop(nextProps) {
|
|
24656
24858
|
const imageAttrs = nextProps;
|
|
@@ -28882,12 +29084,7 @@ var WeaveExportStageToolAction = class extends WeaveAction {
|
|
|
28882
29084
|
}
|
|
28883
29085
|
async exportStage(boundingNodes) {
|
|
28884
29086
|
const mainLayer = this.instance.getMainLayer();
|
|
28885
|
-
const img = await this.instance.exportNodes(
|
|
28886
|
-
// mainLayer?.find('.node') ?? [],
|
|
28887
|
-
mainLayer?.getChildren() ?? [],
|
|
28888
|
-
boundingNodes,
|
|
28889
|
-
this.options
|
|
28890
|
-
);
|
|
29087
|
+
const img = await this.instance.exportNodes(mainLayer?.getChildren() ?? [], boundingNodes, this.options);
|
|
28891
29088
|
return img;
|
|
28892
29089
|
}
|
|
28893
29090
|
async trigger(cancelAction, { boundingNodes, options }) {
|