@inditextech/weave-sdk 3.0.0-SNAPSHOT.58.1 → 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 +48 -40
- 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/sdk.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);
|
|
@@ -21936,7 +21946,7 @@ var WeaveRegisterManager = class {
|
|
|
21936
21946
|
|
|
21937
21947
|
//#endregion
|
|
21938
21948
|
//#region package.json
|
|
21939
|
-
var version = "3.
|
|
21949
|
+
var version = "3.1.0";
|
|
21940
21950
|
|
|
21941
21951
|
//#endregion
|
|
21942
21952
|
//#region src/managers/setup.ts
|
|
@@ -23685,7 +23695,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
23685
23695
|
}
|
|
23686
23696
|
});
|
|
23687
23697
|
window.addEventListener("keyup", (e) => {
|
|
23688
|
-
if (!e.ctrlKey
|
|
23698
|
+
if (!(e.ctrlKey || e.metaKey)) {
|
|
23689
23699
|
this.isCmdCtrlPressed = false;
|
|
23690
23700
|
this.instance.getStage().container().style.cursor = "default";
|
|
23691
23701
|
const transformer = this.getSelectionPlugin()?.getTransformer();
|
|
@@ -24328,16 +24338,8 @@ const WEAVE_TEXT_NODE_DEFAULT_CONFIG = {
|
|
|
24328
24338
|
transform: { ...WEAVE_NODES_SELECTION_DEFAULT_CONFIG.selection },
|
|
24329
24339
|
outline: { enabled: false }
|
|
24330
24340
|
};
|
|
24331
|
-
|
|
24332
|
-
//#endregion
|
|
24333
|
-
//#region src/actions/text-tool/constants.ts
|
|
24334
|
-
const TEXT_TOOL_ACTION_NAME = "textTool";
|
|
24335
|
-
const TEXT_TOOL_STATE = {
|
|
24336
|
-
["IDLE"]: "idle",
|
|
24337
|
-
["ADDING"]: "adding",
|
|
24338
|
-
["FINISHED"]: "finished"
|
|
24339
|
-
};
|
|
24340
24341
|
const TEXT_LAYOUT = {
|
|
24342
|
+
["SMART"]: "smart",
|
|
24341
24343
|
["AUTO_ALL"]: "auto-all",
|
|
24342
24344
|
["AUTO_HEIGHT"]: "auto-height",
|
|
24343
24345
|
["FIXED"]: "fixed"
|
|
@@ -24351,6 +24353,8 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24351
24353
|
textAreaSuperContainer = null;
|
|
24352
24354
|
textAreaContainer = null;
|
|
24353
24355
|
textArea = null;
|
|
24356
|
+
eventsInitialized = false;
|
|
24357
|
+
isCtrlMetaPressed = false;
|
|
24354
24358
|
constructor(params) {
|
|
24355
24359
|
super();
|
|
24356
24360
|
const { config } = params ?? {};
|
|
@@ -24359,6 +24363,17 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24359
24363
|
this.editing = false;
|
|
24360
24364
|
this.textArea = null;
|
|
24361
24365
|
}
|
|
24366
|
+
initEvents() {
|
|
24367
|
+
if (!this.eventsInitialized && !globalThis._weave_isServerSide) {
|
|
24368
|
+
window.addEventListener("keydown", (e) => {
|
|
24369
|
+
if (e.ctrlKey || e.metaKey) this.isCtrlMetaPressed = true;
|
|
24370
|
+
});
|
|
24371
|
+
window.addEventListener("keyup", (e) => {
|
|
24372
|
+
if (!(e.ctrlKey || e.metaKey)) this.isCtrlMetaPressed = false;
|
|
24373
|
+
});
|
|
24374
|
+
this.eventsInitialized = true;
|
|
24375
|
+
}
|
|
24376
|
+
}
|
|
24362
24377
|
updateNode(nodeInstance) {
|
|
24363
24378
|
const actNode = this.instance.getStage().findOne(`#${nodeInstance.id()}`);
|
|
24364
24379
|
if (actNode) {
|
|
@@ -24387,6 +24402,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24387
24402
|
}
|
|
24388
24403
|
}
|
|
24389
24404
|
onRender(props) {
|
|
24405
|
+
this.initEvents();
|
|
24390
24406
|
const text = new Konva.Text({
|
|
24391
24407
|
...props,
|
|
24392
24408
|
name: "node",
|
|
@@ -24402,6 +24418,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24402
24418
|
const defaultTransformerProperties = this.defaultGetTransformerProperties(this.config.transform);
|
|
24403
24419
|
text.getTransformerProperties = function() {
|
|
24404
24420
|
const actualAttrs = this.getAttrs();
|
|
24421
|
+
if (actualAttrs.layout === TEXT_LAYOUT.SMART) return {
|
|
24422
|
+
...defaultTransformerProperties,
|
|
24423
|
+
resizeEnabled: true,
|
|
24424
|
+
keepRatio: false,
|
|
24425
|
+
enabledAnchors: []
|
|
24426
|
+
};
|
|
24405
24427
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return {
|
|
24406
24428
|
...defaultTransformerProperties,
|
|
24407
24429
|
resizeEnabled: false,
|
|
@@ -24416,6 +24438,14 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24416
24438
|
};
|
|
24417
24439
|
text.allowedAnchors = function() {
|
|
24418
24440
|
const actualAttrs = this.getAttrs();
|
|
24441
|
+
if (actualAttrs.layout === TEXT_LAYOUT.SMART) return [
|
|
24442
|
+
"top-left",
|
|
24443
|
+
"top-right",
|
|
24444
|
+
"middle-right",
|
|
24445
|
+
"middle-left",
|
|
24446
|
+
"bottom-left",
|
|
24447
|
+
"bottom-right"
|
|
24448
|
+
];
|
|
24419
24449
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_ALL) return [];
|
|
24420
24450
|
if (actualAttrs.layout === TEXT_LAYOUT.AUTO_HEIGHT) return ["middle-right", "middle-left"];
|
|
24421
24451
|
return [
|
|
@@ -24430,35 +24460,93 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24430
24460
|
];
|
|
24431
24461
|
};
|
|
24432
24462
|
text.setAttrs({ measureMultilineText: this.measureMultilineText(text) });
|
|
24433
|
-
this.setupDefaultNodeEvents(text);
|
|
24434
|
-
const handleTextTransform = (e) => {
|
|
24435
|
-
const node = e.target;
|
|
24436
|
-
if (this.isSelecting() && this.isNodeSelected(node)) e.cancelBubble = true;
|
|
24437
|
-
};
|
|
24438
|
-
text.on("transformstart", (e) => {
|
|
24439
|
-
this.instance.emitEvent("onTransform", e.target);
|
|
24440
|
-
});
|
|
24441
|
-
text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
|
|
24442
|
-
text.on("transformend", () => {
|
|
24443
|
-
this.instance.emitEvent("onTransform", null);
|
|
24444
|
-
});
|
|
24463
|
+
this.setupDefaultNodeEvents(text, { performScaleReset: false });
|
|
24445
24464
|
text.dblClick = () => {
|
|
24446
24465
|
if (this.editing) return;
|
|
24447
24466
|
if (!(this.isSelecting() && this.isNodeSelected(text))) return;
|
|
24448
24467
|
this.triggerEditMode(text);
|
|
24449
24468
|
};
|
|
24450
|
-
text.
|
|
24451
|
-
|
|
24452
|
-
|
|
24453
|
-
|
|
24454
|
-
|
|
24455
|
-
|
|
24469
|
+
text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
|
|
24470
|
+
let actualAnchor = void 0;
|
|
24471
|
+
text.on("transformstart", (e) => {
|
|
24472
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
24473
|
+
actualAnchor = this.getNodesSelectionPlugin()?.getTransformer()?.getActiveAnchor();
|
|
24474
|
+
if (text.getAttrs().layout === TEXT_LAYOUT.SMART && [
|
|
24475
|
+
"top-left",
|
|
24476
|
+
"top-right",
|
|
24477
|
+
"bottom-left",
|
|
24478
|
+
"bottom-right"
|
|
24479
|
+
].includes(actualAnchor ?? "") || text.getAttrs().layout === TEXT_LAYOUT.FIXED && this.isCtrlMetaPressed) this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(true);
|
|
24480
|
+
else this.getNodesSelectionPlugin()?.getTransformer()?.keepRatio(false);
|
|
24481
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
|
|
24482
|
+
text.wrap("word");
|
|
24483
|
+
text.height(void 0);
|
|
24484
|
+
}
|
|
24485
|
+
e.cancelBubble = true;
|
|
24486
|
+
});
|
|
24487
|
+
const handleTextTransform = () => {
|
|
24488
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "")) {
|
|
24489
|
+
text.width(text.width() * text.scaleX());
|
|
24490
|
+
text.scaleX(1);
|
|
24491
|
+
text.scaleY(1);
|
|
24492
|
+
text.height(void 0);
|
|
24493
|
+
text.getLayer()?.batchDraw();
|
|
24494
|
+
}
|
|
24495
|
+
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) && ![
|
|
24496
|
+
"top-left",
|
|
24497
|
+
"top-right",
|
|
24498
|
+
"bottom-left",
|
|
24499
|
+
"bottom-right"
|
|
24500
|
+
].includes(actualAnchor ?? "")) {
|
|
24501
|
+
text.width(text.width() * text.scaleX());
|
|
24456
24502
|
resetScale(text);
|
|
24457
24503
|
text.fontSize(text.fontSize() * text.scaleY());
|
|
24458
|
-
e.cancelBubble = true;
|
|
24459
24504
|
}
|
|
24505
|
+
text.setAttr("shouldUpdateOnTransform", false);
|
|
24506
|
+
text.getLayer()?.batchDraw();
|
|
24507
|
+
};
|
|
24508
|
+
text.on("transform", (0, import_lodash.throttle)(handleTextTransform, DEFAULT_THROTTLE_MS));
|
|
24509
|
+
const handleTransformEnd = () => {
|
|
24510
|
+
this.instance.emitEvent("onTransform", null);
|
|
24511
|
+
let definedSmartWidth = false;
|
|
24512
|
+
let smartFixedWidth = text.getAttr("smartFixedWidth") ?? false;
|
|
24513
|
+
if (![TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ![
|
|
24514
|
+
"top-left",
|
|
24515
|
+
"top-right",
|
|
24516
|
+
"bottom-left",
|
|
24517
|
+
"bottom-right"
|
|
24518
|
+
].includes(actualAnchor ?? "")) this.scaleReset(text);
|
|
24519
|
+
if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && [
|
|
24520
|
+
"top-left",
|
|
24521
|
+
"top-right",
|
|
24522
|
+
"bottom-left",
|
|
24523
|
+
"bottom-right"
|
|
24524
|
+
].includes(actualAnchor ?? "")) text.setAttrs({
|
|
24525
|
+
width: Math.ceil(text.width() * text.scaleX()),
|
|
24526
|
+
height: Math.ceil(text.height() * text.scaleY()),
|
|
24527
|
+
fontSize: text.fontSize() * text.scaleY(),
|
|
24528
|
+
scaleX: 1,
|
|
24529
|
+
scaleY: 1
|
|
24530
|
+
});
|
|
24531
|
+
if ([TEXT_LAYOUT.AUTO_HEIGHT, TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && !smartFixedWidth && !definedSmartWidth) {
|
|
24532
|
+
text.setAttr("smartFixedWidth", true);
|
|
24533
|
+
smartFixedWidth = true;
|
|
24534
|
+
definedSmartWidth = true;
|
|
24535
|
+
text.width(Math.ceil(text.width() * text.scaleX()));
|
|
24536
|
+
text.scaleX(1);
|
|
24537
|
+
text.height(void 0);
|
|
24538
|
+
text.getLayer()?.batchDraw();
|
|
24539
|
+
text.height(Math.ceil(text.height()));
|
|
24540
|
+
}
|
|
24541
|
+
if ([TEXT_LAYOUT.SMART].includes(text.getAttrs().layout) && ["middle-right", "middle-left"].includes(actualAnchor ?? "") && smartFixedWidth && !definedSmartWidth) {
|
|
24542
|
+
text.width(Math.ceil(text.width() * text.scaleX()));
|
|
24543
|
+
text.scaleX(1);
|
|
24544
|
+
}
|
|
24545
|
+
this.instance.updateNode(this.serialize(text));
|
|
24546
|
+
};
|
|
24547
|
+
text.on("transformend", () => {
|
|
24548
|
+
handleTransformEnd();
|
|
24460
24549
|
});
|
|
24461
|
-
text.setAttr("triggerEditMode", this.triggerEditMode.bind(this));
|
|
24462
24550
|
this.instance.addEventListener("onNodeRenderedAdded", (node) => {
|
|
24463
24551
|
if (node.id() === text.id() && node.getParent() !== text.getParent()) text.getAttr("cancelEditMode")?.();
|
|
24464
24552
|
});
|
|
@@ -24494,10 +24582,13 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24494
24582
|
width = textAreaWidth;
|
|
24495
24583
|
height = textAreaHeight;
|
|
24496
24584
|
}
|
|
24497
|
-
if (nextProps.layout === TEXT_LAYOUT.
|
|
24498
|
-
const {
|
|
24499
|
-
|
|
24585
|
+
if (nextProps.layout === TEXT_LAYOUT.SMART && !nextProps.smartFixedWidth) {
|
|
24586
|
+
const { width: textAreaWidth } = this.textRenderedSize(nextProps.text, nodeInstance);
|
|
24587
|
+
width = textAreaWidth;
|
|
24588
|
+
height = void 0;
|
|
24500
24589
|
}
|
|
24590
|
+
if (nextProps.layout === TEXT_LAYOUT.SMART && nextProps.smartFixedWidth) height = void 0;
|
|
24591
|
+
if (nextProps.layout === TEXT_LAYOUT.AUTO_HEIGHT) height = void 0;
|
|
24501
24592
|
if (nextProps.layout === TEXT_LAYOUT.FIXED) updateNeeded = false;
|
|
24502
24593
|
nodeInstance.setAttrs({
|
|
24503
24594
|
width,
|
|
@@ -24523,6 +24614,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24523
24614
|
delete cleanedAttrs.cancelEditMode;
|
|
24524
24615
|
delete cleanedAttrs.measureMultilineText;
|
|
24525
24616
|
delete cleanedAttrs.overridesMouseControl;
|
|
24617
|
+
delete cleanedAttrs.shouldUpdateOnTransform;
|
|
24526
24618
|
delete cleanedAttrs.dragBoundFunc;
|
|
24527
24619
|
return {
|
|
24528
24620
|
key: attrs.id ?? "",
|
|
@@ -24547,12 +24639,11 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24547
24639
|
};
|
|
24548
24640
|
textAreaDomResize(textNode) {
|
|
24549
24641
|
if (!this.textArea || !this.textAreaContainer) return;
|
|
24550
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24642
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24551
24643
|
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
24552
|
-
this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x +
|
|
24644
|
+
this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 1 + "px";
|
|
24553
24645
|
}
|
|
24554
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.
|
|
24555
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
24646
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) {
|
|
24556
24647
|
this.textAreaContainer.style.height = "auto";
|
|
24557
24648
|
this.textAreaContainer.style.height = this.textArea.scrollHeight + textNode.getAbsoluteScale().y + "px";
|
|
24558
24649
|
}
|
|
@@ -24638,15 +24729,21 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24638
24729
|
this.textAreaContainer.style.position = "absolute";
|
|
24639
24730
|
this.textAreaContainer.style.top = position.y * upscaleScale + "px";
|
|
24640
24731
|
this.textAreaContainer.style.left = position.x * upscaleScale + "px";
|
|
24732
|
+
if (textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24733
|
+
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24734
|
+
this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
|
|
24735
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24736
|
+
}
|
|
24641
24737
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24642
24738
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24643
|
-
this.textAreaContainer.style.width = (rect.width +
|
|
24644
|
-
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
24739
|
+
this.textAreaContainer.style.width = (rect.width + 2) * stage.scaleX() + "px";
|
|
24740
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24645
24741
|
}
|
|
24646
|
-
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
24742
|
+
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && textNode.getAttrs().smartFixedWidth) {
|
|
24647
24743
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
24648
|
-
this.textAreaContainer.style.width = (rect.width +
|
|
24649
|
-
this.textAreaContainer.style.
|
|
24744
|
+
this.textAreaContainer.style.width = (rect.width + 10) * stage.scaleX() + "px";
|
|
24745
|
+
if (textNode.getAttrs().smartFixedWidth) this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24746
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2 + 1) * textNode.getAbsoluteScale().x + "px";
|
|
24650
24747
|
}
|
|
24651
24748
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
|
|
24652
24749
|
this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
@@ -24731,11 +24828,11 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24731
24828
|
}
|
|
24732
24829
|
const updateTextNodeSize = () => {
|
|
24733
24830
|
if (!this.textArea) return;
|
|
24734
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
24831
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
24735
24832
|
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
24736
24833
|
textNode.width(textAreaWidth);
|
|
24737
24834
|
}
|
|
24738
|
-
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));
|
|
24835
|
+
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));
|
|
24739
24836
|
};
|
|
24740
24837
|
const handleKeyDown = (e) => {
|
|
24741
24838
|
if (this.textArea && textNode && e.code === "Escape") {
|
|
@@ -24806,13 +24903,15 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24806
24903
|
}
|
|
24807
24904
|
updateTextAreaDOM(textNode) {
|
|
24808
24905
|
if (!this.textAreaContainer || !this.textArea) return;
|
|
24809
|
-
const
|
|
24906
|
+
const stage = this.instance.getStage();
|
|
24907
|
+
const upscaleScale = stage.getAttr("upscaleScale");
|
|
24908
|
+
const textPosition = textNode.absolutePosition();
|
|
24810
24909
|
const position = {
|
|
24811
24910
|
x: textPosition.x,
|
|
24812
24911
|
y: textPosition.y
|
|
24813
24912
|
};
|
|
24814
|
-
this.textAreaContainer.style.top = position.y + "px";
|
|
24815
|
-
this.textAreaContainer.style.left = position.x + "px";
|
|
24913
|
+
this.textAreaContainer.style.top = position.y * upscaleScale + "px";
|
|
24914
|
+
this.textAreaContainer.style.left = position.x * upscaleScale + "px";
|
|
24816
24915
|
if (textNode.getAttrs().verticalAlign === "top") this.textAreaContainer.style.alignItems = "start";
|
|
24817
24916
|
if (textNode.getAttrs().verticalAlign === "middle") this.textAreaContainer.style.alignItems = "center";
|
|
24818
24917
|
if (textNode.getAttrs().verticalAlign === "bottom") this.textAreaContainer.style.alignItems = "end";
|
|
@@ -24881,6 +24980,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
24881
24980
|
this.keyPressHandler = void 0;
|
|
24882
24981
|
}
|
|
24883
24982
|
}
|
|
24983
|
+
resetSmartLayout(textNode) {
|
|
24984
|
+
textNode.setAttr("smartFixedWidth", void 0);
|
|
24985
|
+
const { width: textAreaWidth } = this.textRenderedSize(textNode.text(), textNode);
|
|
24986
|
+
textNode.width(textAreaWidth);
|
|
24987
|
+
this.instance.updateNode(this.serialize(textNode));
|
|
24988
|
+
}
|
|
24884
24989
|
};
|
|
24885
24990
|
|
|
24886
24991
|
//#endregion
|
|
@@ -33113,6 +33218,15 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
33113
33218
|
}
|
|
33114
33219
|
};
|
|
33115
33220
|
|
|
33221
|
+
//#endregion
|
|
33222
|
+
//#region src/actions/text-tool/constants.ts
|
|
33223
|
+
const TEXT_TOOL_ACTION_NAME = "textTool";
|
|
33224
|
+
const TEXT_TOOL_STATE = {
|
|
33225
|
+
["IDLE"]: "idle",
|
|
33226
|
+
["ADDING"]: "adding",
|
|
33227
|
+
["FINISHED"]: "finished"
|
|
33228
|
+
};
|
|
33229
|
+
|
|
33116
33230
|
//#endregion
|
|
33117
33231
|
//#region src/actions/text-tool/text-tool.ts
|
|
33118
33232
|
var WeaveTextToolAction = class extends WeaveAction {
|
|
@@ -33135,7 +33249,7 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
33135
33249
|
initProps() {
|
|
33136
33250
|
return {
|
|
33137
33251
|
text: "",
|
|
33138
|
-
layout: TEXT_LAYOUT.
|
|
33252
|
+
layout: TEXT_LAYOUT.SMART,
|
|
33139
33253
|
fontSize: 20,
|
|
33140
33254
|
fontFamily: "Arial, sans-serif",
|
|
33141
33255
|
fill: "#000000",
|
|
@@ -36109,6 +36223,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36109
36223
|
gridDotMaxDotsPerAxis: WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS,
|
|
36110
36224
|
...config
|
|
36111
36225
|
};
|
|
36226
|
+
this.forceStageChange = false;
|
|
36112
36227
|
}
|
|
36113
36228
|
getName() {
|
|
36114
36229
|
return WEAVE_STAGE_GRID_PLUGIN_KEY;
|
|
@@ -36316,6 +36431,10 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36316
36431
|
gridLayer.add(originShape);
|
|
36317
36432
|
}
|
|
36318
36433
|
hasStageChanged() {
|
|
36434
|
+
if (this.forceStageChange) {
|
|
36435
|
+
this.forceStageChange = false;
|
|
36436
|
+
return true;
|
|
36437
|
+
}
|
|
36319
36438
|
const stage = this.instance.getStage();
|
|
36320
36439
|
const actualScaleX = stage.scaleX();
|
|
36321
36440
|
const actualScaleY = stage.scaleY();
|
|
@@ -36358,6 +36477,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
36358
36477
|
}
|
|
36359
36478
|
setType(type) {
|
|
36360
36479
|
this.config.type = type;
|
|
36480
|
+
this.forceStageChange = true;
|
|
36361
36481
|
this.onRender();
|
|
36362
36482
|
}
|
|
36363
36483
|
};
|