@inditextech/weave-sdk 3.0.0 → 3.1.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 +208 -88
- package/dist/sdk.node.js +208 -88
- package/dist/types.d.ts +42 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +208 -88
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/types.js
CHANGED
|
@@ -17879,6 +17879,8 @@ function getTopmostShadowHost(el) {
|
|
|
17879
17879
|
return current?.shadowRoot || null;
|
|
17880
17880
|
}
|
|
17881
17881
|
function getVisibleNodes({ instance, stage, nodeParent, skipNodes, referenceLayer }) {
|
|
17882
|
+
const nodesSelection = instance.getPlugin("nodesSelection");
|
|
17883
|
+
if (nodesSelection) nodesSelection.getTransformer().hide();
|
|
17882
17884
|
const nodes = getVisibleNodesInViewport(stage, referenceLayer);
|
|
17883
17885
|
const finalVisibleNodes = [];
|
|
17884
17886
|
nodes.forEach((node) => {
|
|
@@ -17891,6 +17893,7 @@ function getVisibleNodes({ instance, stage, nodeParent, skipNodes, referenceLaye
|
|
|
17891
17893
|
if (node.getParent() !== referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
|
|
17892
17894
|
finalVisibleNodes.push(node);
|
|
17893
17895
|
});
|
|
17896
|
+
if (nodesSelection) nodesSelection.getTransformer().show();
|
|
17894
17897
|
return finalVisibleNodes;
|
|
17895
17898
|
}
|
|
17896
17899
|
function memoize(fn) {
|
|
@@ -18755,8 +18758,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
18755
18758
|
tr.on("transformstart", () => {
|
|
18756
18759
|
this.transformInProcess = true;
|
|
18757
18760
|
this.triggerSelectedNodesEvent();
|
|
18758
|
-
tr.visible(false);
|
|
18759
|
-
tr.forceUpdate();
|
|
18760
18761
|
const selectedNodes$1 = tr.nodes();
|
|
18761
18762
|
for (const node of selectedNodes$1) {
|
|
18762
18763
|
node.handleMouseout();
|
|
@@ -18824,8 +18825,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
18824
18825
|
tr.on("transform", (0, import_throttle.default)(handleTransform, DEFAULT_THROTTLE_MS));
|
|
18825
18826
|
tr.on("transformend", () => {
|
|
18826
18827
|
this.transformInProcess = false;
|
|
18827
|
-
tr.visible(true);
|
|
18828
|
-
tr.forceUpdate();
|
|
18829
18828
|
if (this.getSelectedNodes().length > 1) this.instance.releaseMutexLock();
|
|
18830
18829
|
const selectedNodes$1 = tr.nodes();
|
|
18831
18830
|
for (const node of selectedNodes$1) {
|
|
@@ -18843,8 +18842,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
18843
18842
|
let selectedNodes = [];
|
|
18844
18843
|
tr.on("dragstart", (e) => {
|
|
18845
18844
|
this.dragInProcess = true;
|
|
18846
|
-
tr.visible(false);
|
|
18847
|
-
tr.forceUpdate();
|
|
18848
18845
|
const mainLayer = this.instance.getMainLayer();
|
|
18849
18846
|
if (!mainLayer) return;
|
|
18850
18847
|
initialPos = {
|
|
@@ -18919,8 +18916,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
18919
18916
|
tr.on("dragmove", (0, import_throttle.default)(handleDragMove, DEFAULT_THROTTLE_MS));
|
|
18920
18917
|
tr.on("dragend", (e) => {
|
|
18921
18918
|
this.dragInProcess = false;
|
|
18922
|
-
tr.visible(true);
|
|
18923
|
-
tr.forceUpdate();
|
|
18924
18919
|
const mainLayer = this.instance.getMainLayer();
|
|
18925
18920
|
if (!mainLayer) return;
|
|
18926
18921
|
this.instance.getSelectionLayer()?.hitGraphEnabled(true);
|
|
@@ -19225,7 +19220,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19225
19220
|
}
|
|
19226
19221
|
});
|
|
19227
19222
|
stage.container().addEventListener("keyup", (e) => {
|
|
19228
|
-
if (e.ctrlKey || e.metaKey) this.isCtrlMetaPressed = false;
|
|
19223
|
+
if (!(e.ctrlKey || e.metaKey)) this.isCtrlMetaPressed = false;
|
|
19229
19224
|
if (e.code === "Space") this.isSpaceKeyPressed = false;
|
|
19230
19225
|
});
|
|
19231
19226
|
stage.on("pointerdown", (e) => {
|
|
@@ -19402,8 +19397,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19402
19397
|
this.selecting = false;
|
|
19403
19398
|
this.stopPanLoop();
|
|
19404
19399
|
this.tr.nodes([...selectedNodes]);
|
|
19405
|
-
this.handleBehaviors();
|
|
19406
19400
|
this.handleMultipleSelectionBehavior();
|
|
19401
|
+
this.handleBehaviors();
|
|
19407
19402
|
if (this.tr.nodes().length > 0) {
|
|
19408
19403
|
stage.container().tabIndex = 1;
|
|
19409
19404
|
stage.container().focus();
|
|
@@ -19514,8 +19509,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19514
19509
|
this.tr.nodes(nodes);
|
|
19515
19510
|
areNodesSelected = true;
|
|
19516
19511
|
}
|
|
19517
|
-
this.handleBehaviors();
|
|
19518
19512
|
this.handleMultipleSelectionBehavior();
|
|
19513
|
+
this.handleBehaviors();
|
|
19519
19514
|
if (areNodesSelected) {
|
|
19520
19515
|
stage.container().tabIndex = 1;
|
|
19521
19516
|
stage.container().focus();
|
|
@@ -19551,11 +19546,12 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19551
19546
|
for (const node of nodes) anchorsArrays.push(node?.allowedAnchors() ?? []);
|
|
19552
19547
|
const enabledAnchors = intersectArrays(anchorsArrays);
|
|
19553
19548
|
transformerAttrs.enabledAnchors = enabledAnchors;
|
|
19554
|
-
this.tr.enabledAnchors(transformerAttrs.enabledAnchors);
|
|
19555
19549
|
}
|
|
19556
19550
|
if (this.tr && this.tr.nodes().length > 0) {
|
|
19551
|
+
if (transformerAttrs.enabledAnchors?.length === 0) transformerAttrs.resizeEnabled = false;
|
|
19557
19552
|
this.tr.setAttrs(transformerAttrs);
|
|
19558
19553
|
this.tr.forceUpdate();
|
|
19554
|
+
this.tr.getLayer()?.batchDraw();
|
|
19559
19555
|
}
|
|
19560
19556
|
}
|
|
19561
19557
|
setSelectedNodes(nodes) {
|
|
@@ -19872,8 +19868,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19872
19868
|
}
|
|
19873
19869
|
}
|
|
19874
19870
|
handlePaste(position, relativePosition) {
|
|
19875
|
-
|
|
19876
|
-
|
|
19871
|
+
this.instance.stateTransactional(() => {
|
|
19872
|
+
const stage = this.instance.getStage();
|
|
19873
|
+
if (!this.toPaste) return;
|
|
19877
19874
|
const nodesToSelect = [];
|
|
19878
19875
|
const newElements = this.checkIfInternalElementsAreNew(JSON.stringify(this.toPaste));
|
|
19879
19876
|
if (this.config.paddingOnPaste.enabled && newElements) {
|
|
@@ -19884,7 +19881,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19884
19881
|
for (const element of Object.keys(this.toPaste.weave)) {
|
|
19885
19882
|
const node = this.toPaste.weave[element].element;
|
|
19886
19883
|
const posRelativeToSelection = this.toPaste.weave[element].posRelativeToSelection;
|
|
19887
|
-
let containerId = this.toPaste.weave[element]
|
|
19884
|
+
let containerId = this.toPaste.weave[element]?.containerId;
|
|
19885
|
+
const nodeHandler = this.instance.getNodeHandler(node.props.nodeType ?? "");
|
|
19886
|
+
if (!nodeHandler) continue;
|
|
19888
19887
|
if (node.props.children) this.recursivelyUpdateKeys(node.props.children);
|
|
19889
19888
|
const newNodeId = v4_default();
|
|
19890
19889
|
delete node.props.containerId;
|
|
@@ -19906,24 +19905,24 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19906
19905
|
containerId = container.getAttrs().id ?? "";
|
|
19907
19906
|
localPos = container.getAbsoluteTransform().copy().invert().point(position);
|
|
19908
19907
|
}
|
|
19909
|
-
const
|
|
19910
|
-
|
|
19911
|
-
|
|
19912
|
-
|
|
19913
|
-
|
|
19914
|
-
|
|
19915
|
-
|
|
19916
|
-
|
|
19917
|
-
|
|
19918
|
-
|
|
19919
|
-
|
|
19920
|
-
|
|
19908
|
+
const realOffset = nodeHandler.realOffset(node);
|
|
19909
|
+
node.props.x = localPos.x + realOffset.x + posRelativeToSelection.x;
|
|
19910
|
+
node.props.y = localPos.y + realOffset.y + posRelativeToSelection.y;
|
|
19911
|
+
}
|
|
19912
|
+
if (!position) {
|
|
19913
|
+
node.props.x = node.props.x + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingX : 0);
|
|
19914
|
+
node.props.y = node.props.y + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingY : 0);
|
|
19915
|
+
}
|
|
19916
|
+
let containerNode = this.instance.getStage().findOne(`#${containerId}`);
|
|
19917
|
+
if (!containerNode) {
|
|
19918
|
+
containerId = this.instance.getMainLayer()?.getAttrs().id ?? "";
|
|
19919
|
+
containerNode = this.instance.getMainLayer();
|
|
19920
|
+
}
|
|
19921
|
+
if (containerId) {
|
|
19922
|
+
this.instance.addNodeNT(node, containerId);
|
|
19923
|
+
const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
|
|
19924
|
+
if (realNode) nodesToSelect.push(realNode);
|
|
19921
19925
|
}
|
|
19922
|
-
const containerNode = this.instance.getStage().findOne(`#${containerId}`);
|
|
19923
|
-
if (!containerNode) containerId = this.instance.getMainLayer()?.getAttrs().id ?? "";
|
|
19924
|
-
this.instance.addNode(node, containerId);
|
|
19925
|
-
const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
|
|
19926
|
-
if (realNode) nodesToSelect.push(realNode);
|
|
19927
19926
|
this.getStageGridPlugin()?.onRender();
|
|
19928
19927
|
}
|
|
19929
19928
|
this.instance.emitEvent("onPaste", {
|
|
@@ -19937,8 +19936,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19937
19936
|
smartZoom: true
|
|
19938
19937
|
});
|
|
19939
19938
|
this.toPaste = void 0;
|
|
19940
|
-
|
|
19941
|
-
|
|
19939
|
+
this.cancel();
|
|
19940
|
+
});
|
|
19942
19941
|
}
|
|
19943
19942
|
async finishHandleCopy() {
|
|
19944
19943
|
this.actualInternalPaddingX = 0;
|
|
@@ -19966,7 +19965,12 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19966
19965
|
y: 0
|
|
19967
19966
|
}
|
|
19968
19967
|
};
|
|
19969
|
-
|
|
19968
|
+
const selectedNodesSortedByZIndexAsc = [...selectedNodes].sort((a, b) => {
|
|
19969
|
+
const aZ = a.getZIndex() ?? 0;
|
|
19970
|
+
const bZ = b.getZIndex() ?? 0;
|
|
19971
|
+
return aZ - bZ;
|
|
19972
|
+
});
|
|
19973
|
+
for (const node of selectedNodesSortedByZIndexAsc) {
|
|
19970
19974
|
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
19971
19975
|
if (!nodeHandler) continue;
|
|
19972
19976
|
const parentNode = node.getParent();
|
|
@@ -20328,7 +20332,8 @@ var WeaveNode = class {
|
|
|
20328
20332
|
if (!selectionPlugin) return;
|
|
20329
20333
|
selectionPlugin.getHoverTransformer().nodes([]);
|
|
20330
20334
|
}
|
|
20331
|
-
setupDefaultNodeEvents(node) {
|
|
20335
|
+
setupDefaultNodeEvents(node, options = { performScaleReset: true }) {
|
|
20336
|
+
const { performScaleReset } = mergeExceptArrays({ performScaleReset: true }, options);
|
|
20332
20337
|
const handleNodesChange = () => {
|
|
20333
20338
|
if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
|
|
20334
20339
|
node.draggable(true);
|
|
@@ -20395,13 +20400,16 @@ var WeaveNode = class {
|
|
|
20395
20400
|
const nodesSnappingPlugin = this.getNodesEdgeSnappingPlugin();
|
|
20396
20401
|
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupGuidelines();
|
|
20397
20402
|
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
20398
|
-
this.scaleReset(node$1);
|
|
20403
|
+
if (performScaleReset) this.scaleReset(node$1);
|
|
20399
20404
|
if (this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
|
|
20400
20405
|
this.getNodesSelectionFeedbackPlugin()?.showSelectionHalo(node$1);
|
|
20401
20406
|
this.getNodesSelectionFeedbackPlugin()?.updateSelectionHalo(node$1);
|
|
20402
20407
|
}
|
|
20403
20408
|
const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
|
|
20404
|
-
if (nodeHandler)
|
|
20409
|
+
if (nodeHandler) {
|
|
20410
|
+
const shouldUpdateOnTransform = node$1.getAttrs().shouldUpdateOnTransform ?? true;
|
|
20411
|
+
if (shouldUpdateOnTransform) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
20412
|
+
}
|
|
20405
20413
|
this.getNodesSelectionPlugin()?.getHoverTransformer().forceUpdate();
|
|
20406
20414
|
});
|
|
20407
20415
|
const stage = this.instance.getStage();
|
|
@@ -20637,7 +20645,9 @@ var WeaveNode = class {
|
|
|
20637
20645
|
}
|
|
20638
20646
|
});
|
|
20639
20647
|
node.handleSelectNode = () => {
|
|
20640
|
-
this.
|
|
20648
|
+
const transformer = this.getNodesSelectionPlugin()?.getTransformer();
|
|
20649
|
+
if (!transformer) return;
|
|
20650
|
+
if (transformer.nodes().length > 1) this.getNodesSelectionFeedbackPlugin()?.createSelectionHalo(node);
|
|
20641
20651
|
};
|
|
20642
20652
|
node.handleDeselectNode = () => {
|
|
20643
20653
|
this.getNodesSelectionFeedbackPlugin()?.destroySelectionHalo(node);
|
|
@@ -21947,7 +21957,7 @@ var WeaveRegisterManager = class {
|
|
|
21947
21957
|
|
|
21948
21958
|
//#endregion
|
|
21949
21959
|
//#region package.json
|
|
21950
|
-
var version = "3.
|
|
21960
|
+
var version = "3.1.0";
|
|
21951
21961
|
|
|
21952
21962
|
//#endregion
|
|
21953
21963
|
//#region src/managers/setup.ts
|
|
@@ -23696,7 +23706,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
23696
23706
|
}
|
|
23697
23707
|
});
|
|
23698
23708
|
window.addEventListener("keyup", (e) => {
|
|
23699
|
-
if (!e.ctrlKey
|
|
23709
|
+
if (!(e.ctrlKey || e.metaKey)) {
|
|
23700
23710
|
this.isCmdCtrlPressed = false;
|
|
23701
23711
|
this.instance.getStage().container().style.cursor = "default";
|
|
23702
23712
|
const transformer = this.getSelectionPlugin()?.getTransformer();
|
|
@@ -24339,16 +24349,8 @@ const WEAVE_TEXT_NODE_DEFAULT_CONFIG = {
|
|
|
24339
24349
|
transform: { ...WEAVE_NODES_SELECTION_DEFAULT_CONFIG.selection },
|
|
24340
24350
|
outline: { enabled: false }
|
|
24341
24351
|
};
|
|
24342
|
-
|
|
24343
|
-
//#endregion
|
|
24344
|
-
//#region src/actions/text-tool/constants.ts
|
|
24345
|
-
const TEXT_TOOL_ACTION_NAME = "textTool";
|
|
24346
|
-
const TEXT_TOOL_STATE = {
|
|
24347
|
-
["IDLE"]: "idle",
|
|
24348
|
-
["ADDING"]: "adding",
|
|
24349
|
-
["FINISHED"]: "finished"
|
|
24350
|
-
};
|
|
24351
24352
|
const TEXT_LAYOUT = {
|
|
24353
|
+
["SMART"]: "smart",
|
|
24352
24354
|
["AUTO_ALL"]: "auto-all",
|
|
24353
24355
|
["AUTO_HEIGHT"]: "auto-height",
|
|
24354
24356
|
["FIXED"]: "fixed"
|
|
@@ -24362,6 +24364,8 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24362
24364
|
textAreaSuperContainer = null;
|
|
24363
24365
|
textAreaContainer = null;
|
|
24364
24366
|
textArea = null;
|
|
24367
|
+
eventsInitialized = false;
|
|
24368
|
+
isCtrlMetaPressed = false;
|
|
24365
24369
|
constructor(params) {
|
|
24366
24370
|
super();
|
|
24367
24371
|
const { config } = params ?? {};
|
|
@@ -24370,6 +24374,17 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24370
24374
|
this.editing = false;
|
|
24371
24375
|
this.textArea = null;
|
|
24372
24376
|
}
|
|
24377
|
+
initEvents() {
|
|
24378
|
+
if (!this.eventsInitialized && !globalThis._weave_isServerSide) {
|
|
24379
|
+
window.addEventListener("keydown", (e) => {
|
|
24380
|
+
if (e.ctrlKey || e.metaKey) this.isCtrlMetaPressed = true;
|
|
24381
|
+
});
|
|
24382
|
+
window.addEventListener("keyup", (e) => {
|
|
24383
|
+
if (!(e.ctrlKey || e.metaKey)) this.isCtrlMetaPressed = false;
|
|
24384
|
+
});
|
|
24385
|
+
this.eventsInitialized = true;
|
|
24386
|
+
}
|
|
24387
|
+
}
|
|
24373
24388
|
updateNode(nodeInstance) {
|
|
24374
24389
|
const actNode = this.instance.getStage().findOne(`#${nodeInstance.id()}`);
|
|
24375
24390
|
if (actNode) {
|
|
@@ -24398,6 +24413,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24398
24413
|
}
|
|
24399
24414
|
}
|
|
24400
24415
|
onRender(props) {
|
|
24416
|
+
this.initEvents();
|
|
24401
24417
|
const text = new Konva.Text({
|
|
24402
24418
|
...props,
|
|
24403
24419
|
name: "node",
|
|
@@ -24413,6 +24429,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24413
24429
|
const defaultTransformerProperties = this.defaultGetTransformerProperties(this.config.transform);
|
|
24414
24430
|
text.getTransformerProperties = function() {
|
|
24415
24431
|
const actualAttrs = this.getAttrs();
|
|
24432
|
+
if (actualAttrs.layout === TEXT_LAYOUT.SMART) return {
|
|
24433
|
+
...defaultTransformerProperties,
|
|
24434
|
+
resizeEnabled: true,
|
|
24435
|
+
keepRatio: false,
|
|
24436
|
+
enabledAnchors: []
|
|
24437
|
+
};
|
|
24416
24438
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return {
|
|
24417
24439
|
...defaultTransformerProperties,
|
|
24418
24440
|
resizeEnabled: false,
|
|
@@ -24427,6 +24449,14 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24427
24449
|
};
|
|
24428
24450
|
text.allowedAnchors = function() {
|
|
24429
24451
|
const actualAttrs = this.getAttrs();
|
|
24452
|
+
if (actualAttrs.layout === TEXT_LAYOUT.SMART) return [
|
|
24453
|
+
"top-left",
|
|
24454
|
+
"top-right",
|
|
24455
|
+
"middle-right",
|
|
24456
|
+
"middle-left",
|
|
24457
|
+
"bottom-left",
|
|
24458
|
+
"bottom-right"
|
|
24459
|
+
];
|
|
24430
24460
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return [];
|
|
24431
24461
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_HEIGHT) return ["middle-right", "middle-left"];
|
|
24432
24462
|
return [
|
|
@@ -24441,35 +24471,93 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24441
24471
|
];
|
|
24442
24472
|
};
|
|
24443
24473
|
text.setAttrs({ measureMultilineText: this.measureMultilineText(text) });
|
|
24444
|
-
this.setupDefaultNodeEvents(text);
|
|
24445
|
-
const handleTextTransform = (e) => {
|
|
24446
|
-
const node = e.target;
|
|
24447
|
-
if (this.isSelecting() && this.isNodeSelected(node)) e.cancelBubble = true;
|
|
24448
|
-
};
|
|
24449
|
-
text.on("transformstart", (e) => {
|
|
24450
|
-
this.instance.emitEvent("onTransform", e.target);
|
|
24451
|
-
});
|
|
24452
|
-
text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
|
|
24453
|
-
text.on("transformend", () => {
|
|
24454
|
-
this.instance.emitEvent("onTransform", null);
|
|
24455
|
-
});
|
|
24474
|
+
this.setupDefaultNodeEvents(text, { performScaleReset: false });
|
|
24456
24475
|
text.dblClick = () => {
|
|
24457
24476
|
if (this.editing) return;
|
|
24458
24477
|
if (!(this.isSelecting() && this.isNodeSelected(text))) return;
|
|
24459
24478
|
this.triggerEditMode(text);
|
|
24460
24479
|
};
|
|
24461
|
-
text.
|
|
24462
|
-
|
|
24463
|
-
|
|
24464
|
-
|
|
24465
|
-
|
|
24466
|
-
|
|
24480
|
+
text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
|
|
24481
|
+
let actualAnchor = void 0;
|
|
24482
|
+
text.on("transformstart", (e) => {
|
|
24483
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
24484
|
+
actualAnchor = this.getNodesSelectionPlugin()?.getTransformer()?.getActiveAnchor();
|
|
24485
|
+
if (text.getAttrs().layout === TEXT_LAYOUT.SMART && [
|
|
24486
|
+
"top-left",
|
|
24487
|
+
"top-right",
|
|
24488
|
+
"bottom-left",
|
|
24489
|
+
"bottom-right"
|
|
24490
|
+
].includes(actualAnchor ?? "") || text.getAttrs().layout === TEXT_LAYOUT.FIXED && this.isCtrlMetaPressed) this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(true);
|
|
24491
|
+
else this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(false);
|
|
24492
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
|
|
24493
|
+
text.wrap("word");
|
|
24494
|
+
text.height(void 0);
|
|
24495
|
+
}
|
|
24496
|
+
e.cancelBubble = true;
|
|
24497
|
+
});
|
|
24498
|
+
const handleTextTransform = () => {
|
|
24499
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
|
|
24500
|
+
text.width(text.width() * text.scaleX());
|
|
24501
|
+
text.scaleX(1);
|
|
24502
|
+
text.scaleY(1);
|
|
24503
|
+
text.height(void 0);
|
|
24504
|
+
text.getLayer()?.batchDraw();
|
|
24505
|
+
}
|
|
24506
|
+
if (this.isSelecting() && this.isNodeSelected(text) && ![TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) || this.isSelecting() && this.isNodeSelected(text) && [TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ![
|
|
24507
|
+
"top-left",
|
|
24508
|
+
"top-right",
|
|
24509
|
+
"bottom-left",
|
|
24510
|
+
"bottom-right"
|
|
24511
|
+
].includes(actualAnchor ?? "")) {
|
|
24512
|
+
text.width(text.width() * text.scaleX());
|
|
24467
24513
|
resetScale(text);
|
|
24468
24514
|
text.fontSize(text.fontSize() * text.scaleY());
|
|
24469
|
-
e.cancelBubble = true;
|
|
24470
24515
|
}
|
|
24516
|
+
text.setAttr("shouldUpdateOnTransform", false);
|
|
24517
|
+
text.getLayer()?.batchDraw();
|
|
24518
|
+
};
|
|
24519
|
+
text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
|
|
24520
|
+
const handleTransformEnd = () => {
|
|
24521
|
+
this.instance.emitEvent("onTransform", null);
|
|
24522
|
+
let definedSmartWidth = false;
|
|
24523
|
+
let smartFixedWidth = text.getAttr("smartFixedWidth") ?? false;
|
|
24524
|
+
if (![TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ![
|
|
24525
|
+
"top-left",
|
|
24526
|
+
"top-right",
|
|
24527
|
+
"bottom-left",
|
|
24528
|
+
"bottom-right"
|
|
24529
|
+
].includes(actualAnchor ?? "")) this.scaleReset(text);
|
|
24530
|
+
if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && [
|
|
24531
|
+
"top-left",
|
|
24532
|
+
"top-right",
|
|
24533
|
+
"bottom-left",
|
|
24534
|
+
"bottom-right"
|
|
24535
|
+
].includes(actualAnchor ?? "")) text.setAttrs({
|
|
24536
|
+
width: Math.ceil(text.width() * text.scaleX()),
|
|
24537
|
+
height: Math.ceil(text.height() * text.scaleY()),
|
|
24538
|
+
fontSize: text.fontSize() * text.scaleY(),
|
|
24539
|
+
scaleX: 1,
|
|
24540
|
+
scaleY: 1
|
|
24541
|
+
});
|
|
24542
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && !smartFixedWidth && !definedSmartWidth) {
|
|
24543
|
+
text.setAttr("smartFixedWidth", true);
|
|
24544
|
+
smartFixedWidth = true;
|
|
24545
|
+
definedSmartWidth = true;
|
|
24546
|
+
text.width(Math.ceil(text.width() * text.scaleX()));
|
|
24547
|
+
text.scaleX(1);
|
|
24548
|
+
text.height(void 0);
|
|
24549
|
+
text.getLayer()?.batchDraw();
|
|
24550
|
+
text.height(Math.ceil(text.height()));
|
|
24551
|
+
}
|
|
24552
|
+
if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && smartFixedWidth && !definedSmartWidth) {
|
|
24553
|
+
text.width(Math.ceil(text.width() * text.scaleX()));
|
|
24554
|
+
text.scaleX(1);
|
|
24555
|
+
}
|
|
24556
|
+
this.instance.updateNode(this.serialize(text));
|
|
24557
|
+
};
|
|
24558
|
+
text.on("transformend", () => {
|
|
24559
|
+
handleTransformEnd();
|
|
24471
24560
|
});
|
|
24472
|
-
text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
|
|
24473
24561
|
this.instance.addEventListener("onNodeRenderedAdded", (node) => {
|
|
24474
24562
|
if (node.id() === text.id() && node.getParent() !== text.getParent()) text.getAttr("cancelEditMode")?.();
|
|
24475
24563
|
});
|
|
@@ -24505,10 +24593,13 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24505
24593
|
width = textAreaWidth;
|
|
24506
24594
|
height = textAreaHeight;
|
|
24507
24595
|
}
|
|
24508
|
-
if (nextProps.layout === TEXT_LAYOUT.
|
|
24509
|
-
const {
|
|
24510
|
-
|
|
24596
|
+
if (nextProps.layout === TEXT_LAYOUT.SMART && !nextProps.smartFixedWidth) {
|
|
24597
|
+
const { width: textAreaWidth } = this.textRenderedSize(nextProps.text, nodeInstance);
|
|
24598
|
+
width = textAreaWidth;
|
|
24599
|
+
height = void 0;
|
|
24511
24600
|
}
|
|
24601
|
+
if (nextProps.layout === TEXT_LAYOUT.SMART && nextProps.smartFixedWidth) height = void 0;
|
|
24602
|
+
if (nextProps.layout === TEXT_LAYOUT.AUTO_HEIGHT) height = void 0;
|
|
24512
24603
|
if (nextProps.layout === TEXT_LAYOUT.FIXED) updateNeeded = false;
|
|
24513
24604
|
nodeInstance.setAttrs({
|
|
24514
24605
|
width,
|
|
@@ -24534,6 +24625,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24534
24625
|
delete cleanedAttrs.cancelEditMode;
|
|
24535
24626
|
delete cleanedAttrs.measureMultilineText;
|
|
24536
24627
|
delete cleanedAttrs.overridesMouseControl;
|
|
24628
|
+
delete cleanedAttrs.shouldUpdateOnTransform;
|
|
24537
24629
|
delete cleanedAttrs.dragBoundFunc;
|
|
24538
24630
|
return {
|
|
24539
24631
|
key: attrs.id ?? "",
|
|
@@ -24558,12 +24650,11 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24558
24650
|
};
|
|
24559
24651
|
textAreaDomResize(textNode) {
|
|
24560
24652
|
if (!this.textArea || !this.textAreaContainer) return;
|
|
24561
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24653
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24562
24654
|
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
24563
|
-
this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x +
|
|
24655
|
+
this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 1 + "px";
|
|
24564
24656
|
}
|
|
24565
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.
|
|
24566
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
24657
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) {
|
|
24567
24658
|
this.textAreaContainer.style.height = "auto";
|
|
24568
24659
|
this.textAreaContainer.style.height = this.textArea.scrollHeight + textNode.getAbsoluteScale().y + "px";
|
|
24569
24660
|
}
|
|
@@ -24649,15 +24740,21 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24649
24740
|
this.textAreaContainer.style.position = "absolute";
|
|
24650
24741
|
this.textAreaContainer.style.top = position.y * upscaleScale + "px";
|
|
24651
24742
|
this.textAreaContainer.style.left = position.x * upscaleScale + "px";
|
|
24743
|
+
if (textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24744
|
+
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24745
|
+
this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
|
|
24746
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24747
|
+
}
|
|
24652
24748
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24653
24749
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24654
|
-
this.textAreaContainer.style.width = (rect.width +
|
|
24655
|
-
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
24750
|
+
this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
|
|
24751
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24656
24752
|
}
|
|
24657
|
-
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
24753
|
+
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && textNode.getAttrs().smartFixedWidth) {
|
|
24658
24754
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24659
|
-
this.textAreaContainer.style.width = (rect.width +
|
|
24660
|
-
this.textAreaContainer.style.
|
|
24755
|
+
this.textAreaContainer.style.width = (rect.width + 10) * stage.scaleX() + "px";
|
|
24756
|
+
if (textNode.getAttrs().smartFixedWidth) this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24757
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24661
24758
|
}
|
|
24662
24759
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
|
|
24663
24760
|
this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
@@ -24742,11 +24839,11 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24742
24839
|
}
|
|
24743
24840
|
const updateTextNodeSize = () => {
|
|
24744
24841
|
if (!this.textArea) return;
|
|
24745
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24842
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24746
24843
|
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
24747
24844
|
textNode.width(textAreaWidth);
|
|
24748
24845
|
}
|
|
24749
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) textNode.height(this.textArea.scrollHeight * (1 / textNode.getAbsoluteScale().x));
|
|
24846
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) textNode.height(this.textArea.scrollHeight * (1 / textNode.getAbsoluteScale().x));
|
|
24750
24847
|
};
|
|
24751
24848
|
const handleKeyDown = (e) => {
|
|
24752
24849
|
if (this.textArea && textNode && e.code === "Escape") {
|
|
@@ -24817,13 +24914,15 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24817
24914
|
}
|
|
24818
24915
|
updateTextAreaDOM(textNode) {
|
|
24819
24916
|
if (!this.textAreaContainer || !this.textArea) return;
|
|
24820
|
-
const
|
|
24917
|
+
const stage = this.instance.getStage();
|
|
24918
|
+
const upscaleScale = stage.getAttr("upscaleScale");
|
|
24919
|
+
const textPosition = textNode.absolutePosition();
|
|
24821
24920
|
const position = {
|
|
24822
24921
|
x: textPosition.x,
|
|
24823
24922
|
y: textPosition.y
|
|
24824
24923
|
};
|
|
24825
|
-
this.textAreaContainer.style.top = position.y + "px";
|
|
24826
|
-
this.textAreaContainer.style.left = position.x + "px";
|
|
24924
|
+
this.textAreaContainer.style.top = position.y * upscaleScale + "px";
|
|
24925
|
+
this.textAreaContainer.style.left = position.x * upscaleScale + "px";
|
|
24827
24926
|
if (textNode.getAttrs().verticalAlign === "top") this.textAreaContainer.style.alignItems = "start";
|
|
24828
24927
|
if (textNode.getAttrs().verticalAlign === "middle") this.textAreaContainer.style.alignItems = "center";
|
|
24829
24928
|
if (textNode.getAttrs().verticalAlign === "bottom") this.textAreaContainer.style.alignItems = "end";
|
|
@@ -24892,6 +24991,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24892
24991
|
this.keyPressHandler = void 0;
|
|
24893
24992
|
}
|
|
24894
24993
|
}
|
|
24994
|
+
resetSmartLayout(textNode) {
|
|
24995
|
+
textNode.setAttr("smartFixedWidth", void 0);
|
|
24996
|
+
const { width: textAreaWidth } = this.textRenderedSize(textNode.text(), textNode);
|
|
24997
|
+
textNode.width(textAreaWidth);
|
|
24998
|
+
this.instance.updateNode(this.serialize(textNode));
|
|
24999
|
+
}
|
|
24895
25000
|
};
|
|
24896
25001
|
|
|
24897
25002
|
//#endregion
|
|
@@ -33124,6 +33229,15 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
33124
33229
|
}
|
|
33125
33230
|
};
|
|
33126
33231
|
|
|
33232
|
+
//#endregion
|
|
33233
|
+
//#region src/actions/text-tool/constants.ts
|
|
33234
|
+
const TEXT_TOOL_ACTION_NAME = "textTool";
|
|
33235
|
+
const TEXT_TOOL_STATE = {
|
|
33236
|
+
["IDLE"]: "idle",
|
|
33237
|
+
["ADDING"]: "adding",
|
|
33238
|
+
["FINISHED"]: "finished"
|
|
33239
|
+
};
|
|
33240
|
+
|
|
33127
33241
|
//#endregion
|
|
33128
33242
|
//#region src/actions/text-tool/text-tool.ts
|
|
33129
33243
|
var WeaveTextToolAction = class extends WeaveAction {
|
|
@@ -33146,7 +33260,7 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
33146
33260
|
initProps() {
|
|
33147
33261
|
return {
|
|
33148
33262
|
text: "",
|
|
33149
|
-
layout: TEXT_LAYOUT.
|
|
33263
|
+
layout: TEXT_LAYOUT.SMART,
|
|
33150
33264
|
fontSize: 20,
|
|
33151
33265
|
fontFamily: "Arial, sans-serif",
|
|
33152
33266
|
fill: "#000000",
|
|
@@ -36166,6 +36280,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36166
36280
|
gridDotMaxDotsPerAxis: WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS,
|
|
36167
36281
|
...config
|
|
36168
36282
|
};
|
|
36283
|
+
this.forceStageChange = false;
|
|
36169
36284
|
}
|
|
36170
36285
|
getName() {
|
|
36171
36286
|
return WEAVE_STAGE_GRID_PLUGIN_KEY;
|
|
@@ -36373,6 +36488,10 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36373
36488
|
gridLayer.add(originShape);
|
|
36374
36489
|
}
|
|
36375
36490
|
hasStageChanged() {
|
|
36491
|
+
if (this.forceStageChange) {
|
|
36492
|
+
this.forceStageChange = false;
|
|
36493
|
+
return true;
|
|
36494
|
+
}
|
|
36376
36495
|
const stage = this.instance.getStage();
|
|
36377
36496
|
const actualScaleX = stage.scaleX();
|
|
36378
36497
|
const actualScaleY = stage.scaleY();
|
|
@@ -36415,6 +36534,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36415
36534
|
}
|
|
36416
36535
|
setType(type) {
|
|
36417
36536
|
this.config.type = type;
|
|
36537
|
+
this.forceStageChange = true;
|
|
36418
36538
|
this.onRender();
|
|
36419
36539
|
}
|
|
36420
36540
|
};
|