@inditextech/weave-sdk 0.33.0 → 0.34.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.cjs +442 -105
- package/dist/sdk.d.cts +82 -4
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +82 -4
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +453 -121
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -15683,9 +15683,8 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15683
15683
|
const mousePos = stage.getPointerPosition();
|
|
15684
15684
|
if (mousePos && mousePos.x >= box.x && mousePos.x <= box.x + box.width && mousePos.y >= box.y && mousePos.y <= box.y + box.height) clickOnTransformer = true;
|
|
15685
15685
|
}
|
|
15686
|
-
if (target !== stage && !clickOnTransformer) return;
|
|
15687
15686
|
let nodes = [];
|
|
15688
|
-
if (clickOnTransformer && selectionPlugin) {
|
|
15687
|
+
if (target !== stage && clickOnTransformer && selectionPlugin) {
|
|
15689
15688
|
const transformer = selectionPlugin.getTransformer();
|
|
15690
15689
|
nodes = transformer.getNodes().map((node) => {
|
|
15691
15690
|
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
@@ -15695,6 +15694,13 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15695
15694
|
};
|
|
15696
15695
|
}).filter((node) => typeof node !== "undefined");
|
|
15697
15696
|
}
|
|
15697
|
+
if (target !== stage && !clickOnTransformer) {
|
|
15698
|
+
const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
|
|
15699
|
+
nodes = [{
|
|
15700
|
+
instance: target,
|
|
15701
|
+
node: nodeHandler?.serialize(target)
|
|
15702
|
+
}];
|
|
15703
|
+
}
|
|
15698
15704
|
const containerRect = stage.container().getBoundingClientRect();
|
|
15699
15705
|
const pointerPos = stage.getPointerPosition();
|
|
15700
15706
|
if (containerRect && pointerPos) {
|
|
@@ -15803,6 +15809,8 @@ function checkIfOverContainer(instance, node) {
|
|
|
15803
15809
|
}
|
|
15804
15810
|
function moveNodeToContainer(instance, node) {
|
|
15805
15811
|
const nodeIntersected = instance.pointIntersectsContainerElement();
|
|
15812
|
+
const isLocked = instance.allNodesLocked([node]);
|
|
15813
|
+
if (isLocked) return;
|
|
15806
15814
|
let nodeActualContainer = node.getParent();
|
|
15807
15815
|
if (!nodeActualContainer) return void 0;
|
|
15808
15816
|
const actualContainerAttrs = nodeActualContainer.getAttrs();
|
|
@@ -16242,16 +16250,24 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16242
16250
|
return false;
|
|
16243
16251
|
});
|
|
16244
16252
|
const selectedNodes = new Set();
|
|
16245
|
-
const framesNodes = selected.
|
|
16246
|
-
|
|
16253
|
+
const framesNodes = selected.map((shape) => {
|
|
16254
|
+
if (shape.getAttrs().nodeType === "frame" && shape.getAttrs().nodeId) return stage.findOne(`#${shape.getAttrs().nodeId}`);
|
|
16255
|
+
return shape;
|
|
16256
|
+
}).filter((shape) => {
|
|
16257
|
+
return shape.getAttrs().nodeType === "frame";
|
|
16258
|
+
});
|
|
16259
|
+
const framesNodesIds = framesNodes.map((shape) => {
|
|
16260
|
+
return shape.getAttrs().id;
|
|
16261
|
+
});
|
|
16247
16262
|
const otherNodes = selected.filter((shape) => shape.getAttrs().nodeType !== "frame");
|
|
16248
16263
|
otherNodes.forEach((node) => {
|
|
16249
|
-
|
|
16250
|
-
if (
|
|
16264
|
+
let parent = this.instance.getInstanceRecursive(node.getParent());
|
|
16265
|
+
if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
16266
|
+
if (parent && !framesNodesIds.includes(parent?.getAttrs().id) && !node.getAttrs().locked) selectedNodes.add(node);
|
|
16251
16267
|
});
|
|
16252
16268
|
framesNodes.forEach((node) => {
|
|
16253
16269
|
const frameNode = node;
|
|
16254
|
-
selectedNodes.add(frameNode);
|
|
16270
|
+
if (!frameNode.getAttrs().locked) selectedNodes.add(frameNode);
|
|
16255
16271
|
});
|
|
16256
16272
|
this.tr.nodes([...selectedNodes]);
|
|
16257
16273
|
this.triggerSelectedNodesEvent();
|
|
@@ -16302,6 +16318,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16302
16318
|
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
16303
16319
|
});
|
|
16304
16320
|
const isSelected = nodeSelectedIndex !== -1;
|
|
16321
|
+
if (nodeTargeted.getAttrs().locked) return;
|
|
16305
16322
|
if (!metaPressed) {
|
|
16306
16323
|
this.tr.nodes([nodeTargeted]);
|
|
16307
16324
|
nodesSelected = this.tr.nodes().length;
|
|
@@ -16665,106 +16682,100 @@ var WeaveNode = class {
|
|
|
16665
16682
|
node.scaleY(1);
|
|
16666
16683
|
}
|
|
16667
16684
|
setupDefaultNodeEvents(node) {
|
|
16668
|
-
this.previousPointer = null;
|
|
16669
16685
|
this.instance.addEventListener("onNodesChange", () => {
|
|
16670
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16686
|
+
if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
|
|
16671
16687
|
node.draggable(true);
|
|
16672
16688
|
return;
|
|
16673
16689
|
}
|
|
16674
16690
|
node.draggable(false);
|
|
16675
16691
|
});
|
|
16676
|
-
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
|
|
16680
|
-
|
|
16681
|
-
|
|
16682
|
-
|
|
16683
|
-
|
|
16684
|
-
|
|
16685
|
-
|
|
16686
|
-
|
|
16687
|
-
|
|
16688
|
-
|
|
16689
|
-
|
|
16690
|
-
}
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
|
|
16694
|
-
|
|
16695
|
-
|
|
16696
|
-
|
|
16697
|
-
|
|
16698
|
-
|
|
16699
|
-
|
|
16700
|
-
|
|
16701
|
-
|
|
16702
|
-
|
|
16703
|
-
|
|
16704
|
-
|
|
16705
|
-
|
|
16706
|
-
|
|
16707
|
-
|
|
16708
|
-
return;
|
|
16709
|
-
}
|
|
16710
|
-
});
|
|
16711
|
-
const handleDragMove = (e) => {
|
|
16712
|
-
const stage = this.instance.getStage();
|
|
16713
|
-
if (stage.isMouseWheelPressed()) {
|
|
16714
|
-
e.cancelBubble = true;
|
|
16715
|
-
node.stopDrag();
|
|
16716
|
-
return;
|
|
16717
|
-
}
|
|
16718
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16719
|
-
clearContainerTargets(this.instance);
|
|
16720
|
-
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16721
|
-
if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
16722
|
-
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
16723
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
|
|
16724
|
-
}
|
|
16725
|
-
};
|
|
16726
|
-
node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
|
|
16727
|
-
node.on("dragend", (e) => {
|
|
16728
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16729
|
-
clearContainerTargets(this.instance);
|
|
16692
|
+
const isLocked = node.getAttrs().locked ?? false;
|
|
16693
|
+
if (isLocked) {
|
|
16694
|
+
node.off("transformstart");
|
|
16695
|
+
node.off("transform");
|
|
16696
|
+
node.off("transformend");
|
|
16697
|
+
node.off("dragstart");
|
|
16698
|
+
node.off("dragmove");
|
|
16699
|
+
node.off("dragend");
|
|
16700
|
+
node.off("pointerenter");
|
|
16701
|
+
node.off("pointerleave");
|
|
16702
|
+
} else {
|
|
16703
|
+
let transforming = false;
|
|
16704
|
+
node.on("transformstart", () => {
|
|
16705
|
+
transforming = true;
|
|
16706
|
+
});
|
|
16707
|
+
const handleTransform = (e) => {
|
|
16708
|
+
const node$1 = e.target;
|
|
16709
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16710
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16711
|
+
if (nodesSelectionPlugin && this.isSelecting() && this.isNodeSelected(node$1)) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
16712
|
+
if (nodesSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesSnappingPlugin.evaluateGuidelines(e);
|
|
16713
|
+
if (this.isSelecting() && this.isNodeSelected(node$1)) {
|
|
16714
|
+
this.scaleReset(node$1);
|
|
16715
|
+
const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
|
|
16716
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
16717
|
+
}
|
|
16718
|
+
};
|
|
16719
|
+
node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
|
|
16720
|
+
node.on("transformend", (e) => {
|
|
16721
|
+
const node$1 = e.target;
|
|
16722
|
+
transforming = false;
|
|
16723
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16730
16724
|
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16731
16725
|
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
this.instance.updateNode(
|
|
16735
|
-
}
|
|
16736
|
-
|
|
16737
|
-
this.previousPointer = null;
|
|
16738
|
-
node.on("pointerenter", () => {
|
|
16739
|
-
const realNode = this.instance.getInstanceRecursive(node);
|
|
16740
|
-
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
|
|
16741
|
-
const stage = this.instance.getStage();
|
|
16742
|
-
this.previousPointer = stage.container().style.cursor;
|
|
16743
|
-
stage.container().style.cursor = "pointer";
|
|
16744
|
-
return;
|
|
16745
|
-
}
|
|
16746
|
-
if (this.isPasting()) {
|
|
16747
|
-
const stage = this.instance.getStage();
|
|
16748
|
-
this.previousPointer = stage.container().style.cursor;
|
|
16749
|
-
stage.container().style.cursor = "crosshair";
|
|
16750
|
-
return;
|
|
16751
|
-
}
|
|
16752
|
-
});
|
|
16753
|
-
node.on("pointerleave", () => {
|
|
16754
|
-
const realNode = this.instance.getInstanceRecursive(node);
|
|
16755
|
-
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
|
|
16726
|
+
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
16727
|
+
const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
|
|
16728
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
16729
|
+
});
|
|
16730
|
+
node.on("dragstart", (e) => {
|
|
16756
16731
|
const stage = this.instance.getStage();
|
|
16757
|
-
stage.
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
|
|
16761
|
-
|
|
16732
|
+
if (stage.isMouseWheelPressed()) {
|
|
16733
|
+
e.cancelBubble = true;
|
|
16734
|
+
e.target.stopDrag();
|
|
16735
|
+
}
|
|
16736
|
+
});
|
|
16737
|
+
const handleDragMove = (e) => {
|
|
16762
16738
|
const stage = this.instance.getStage();
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
16766
|
-
|
|
16767
|
-
|
|
16739
|
+
if (stage.isMouseWheelPressed()) {
|
|
16740
|
+
e.cancelBubble = true;
|
|
16741
|
+
e.target.stopDrag();
|
|
16742
|
+
return;
|
|
16743
|
+
}
|
|
16744
|
+
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16745
|
+
clearContainerTargets(this.instance);
|
|
16746
|
+
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16747
|
+
if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
16748
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
16749
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
|
|
16750
|
+
}
|
|
16751
|
+
};
|
|
16752
|
+
node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
|
|
16753
|
+
node.on("dragend", (e) => {
|
|
16754
|
+
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16755
|
+
clearContainerTargets(this.instance);
|
|
16756
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16757
|
+
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
16758
|
+
const containerToMove = moveNodeToContainer(this.instance, e.target);
|
|
16759
|
+
if (containerToMove) return;
|
|
16760
|
+
this.instance.updateNode(this.serialize(node));
|
|
16761
|
+
}
|
|
16762
|
+
});
|
|
16763
|
+
node.on("pointerenter", (e) => {
|
|
16764
|
+
const realNode = this.instance.getInstanceRecursive(node);
|
|
16765
|
+
const isLocked$1 = realNode.getAttrs().locked ?? false;
|
|
16766
|
+
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
|
|
16767
|
+
const stage = this.instance.getStage();
|
|
16768
|
+
stage.container().style.cursor = !isLocked$1 ? "pointer" : "default";
|
|
16769
|
+
e.cancelBubble = true;
|
|
16770
|
+
return;
|
|
16771
|
+
}
|
|
16772
|
+
if (this.isPasting()) {
|
|
16773
|
+
const stage = this.instance.getStage();
|
|
16774
|
+
stage.container().style.cursor = "crosshair";
|
|
16775
|
+
e.cancelBubble = true;
|
|
16776
|
+
}
|
|
16777
|
+
});
|
|
16778
|
+
}
|
|
16768
16779
|
}
|
|
16769
16780
|
create(key, props) {
|
|
16770
16781
|
return {
|
|
@@ -16796,6 +16807,32 @@ var WeaveNode = class {
|
|
|
16796
16807
|
}
|
|
16797
16808
|
};
|
|
16798
16809
|
}
|
|
16810
|
+
lock(instance) {
|
|
16811
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16812
|
+
instance.setAttrs({ locked: true });
|
|
16813
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16814
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16815
|
+
if (selectionPlugin) {
|
|
16816
|
+
const selectedNodes = selectionPlugin.getSelectedNodes();
|
|
16817
|
+
const newSelectedNodes = selectedNodes.filter((node) => node.getAttrs().id !== instance.getAttrs().id);
|
|
16818
|
+
selectionPlugin.setSelectedNodes(newSelectedNodes);
|
|
16819
|
+
selectionPlugin.getTransformer().forceUpdate();
|
|
16820
|
+
}
|
|
16821
|
+
this.setupDefaultNodeEvents(instance);
|
|
16822
|
+
const stage = this.instance.getStage();
|
|
16823
|
+
stage.container().style.cursor = "default";
|
|
16824
|
+
}
|
|
16825
|
+
unlock(instance) {
|
|
16826
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16827
|
+
instance.setAttrs({ locked: false });
|
|
16828
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16829
|
+
this.setupDefaultNodeEvents(instance);
|
|
16830
|
+
const stage = this.instance.getStage();
|
|
16831
|
+
stage.container().style.cursor = "default";
|
|
16832
|
+
}
|
|
16833
|
+
isLocked(instance) {
|
|
16834
|
+
return instance.getAttrs().locked ?? false;
|
|
16835
|
+
}
|
|
16799
16836
|
};
|
|
16800
16837
|
|
|
16801
16838
|
//#endregion
|
|
@@ -18230,7 +18267,7 @@ var WeaveRegisterManager = class {
|
|
|
18230
18267
|
|
|
18231
18268
|
//#endregion
|
|
18232
18269
|
//#region package.json
|
|
18233
|
-
var version = "0.
|
|
18270
|
+
var version = "0.34.0";
|
|
18234
18271
|
|
|
18235
18272
|
//#endregion
|
|
18236
18273
|
//#region src/managers/setup.ts
|
|
@@ -18801,6 +18838,9 @@ var Weave = class {
|
|
|
18801
18838
|
getElementsTree() {
|
|
18802
18839
|
return this.stateManager.getElementsTree();
|
|
18803
18840
|
}
|
|
18841
|
+
isEmpty() {
|
|
18842
|
+
return this.getElementsTree().length === 0;
|
|
18843
|
+
}
|
|
18804
18844
|
moveUp(node) {
|
|
18805
18845
|
this.zIndexManager.moveUp(node);
|
|
18806
18846
|
}
|
|
@@ -18841,7 +18881,8 @@ var Weave = class {
|
|
|
18841
18881
|
if (selectionPlugin) {
|
|
18842
18882
|
const stage = this.getStage();
|
|
18843
18883
|
const instanceNodes = nodesIds.map((nodeId) => {
|
|
18844
|
-
|
|
18884
|
+
let nodeInstance = stage.findOne(`#${nodeId}`);
|
|
18885
|
+
if (nodeInstance && nodeInstance.getAttrs().nodeType === "frame") nodeInstance = stage.findOne(`#${nodeId}-selector-area`);
|
|
18845
18886
|
return nodeInstance;
|
|
18846
18887
|
});
|
|
18847
18888
|
selectionPlugin.setSelectedNodes(instanceNodes);
|
|
@@ -18862,6 +18903,48 @@ var Weave = class {
|
|
|
18862
18903
|
async exportNodes(nodes, boundingNodes, options) {
|
|
18863
18904
|
return await this.exportManager.exportNodes(nodes, boundingNodes, options);
|
|
18864
18905
|
}
|
|
18906
|
+
allNodesLocked(nodes) {
|
|
18907
|
+
let allNodesLocked = true;
|
|
18908
|
+
for (const node of nodes) {
|
|
18909
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18910
|
+
if (!nodeHandler) continue;
|
|
18911
|
+
allNodesLocked = allNodesLocked && nodeHandler.isLocked(node);
|
|
18912
|
+
}
|
|
18913
|
+
return allNodesLocked;
|
|
18914
|
+
}
|
|
18915
|
+
allNodesUnlocked(nodes) {
|
|
18916
|
+
let allNodesUnlocked = true;
|
|
18917
|
+
for (const node of nodes) {
|
|
18918
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18919
|
+
if (!nodeHandler) continue;
|
|
18920
|
+
allNodesUnlocked = allNodesUnlocked && !nodeHandler.isLocked(node);
|
|
18921
|
+
}
|
|
18922
|
+
return allNodesUnlocked;
|
|
18923
|
+
}
|
|
18924
|
+
lockNode(node) {
|
|
18925
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18926
|
+
if (!nodeHandler) return;
|
|
18927
|
+
nodeHandler.lock(node);
|
|
18928
|
+
}
|
|
18929
|
+
lockNodes(nodes) {
|
|
18930
|
+
for (const node of nodes) {
|
|
18931
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18932
|
+
if (!nodeHandler) continue;
|
|
18933
|
+
nodeHandler.lock(node);
|
|
18934
|
+
}
|
|
18935
|
+
}
|
|
18936
|
+
unlockNode(node) {
|
|
18937
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18938
|
+
if (!nodeHandler) return;
|
|
18939
|
+
nodeHandler.unlock(node);
|
|
18940
|
+
}
|
|
18941
|
+
unlockNodes(nodes) {
|
|
18942
|
+
for (const node of nodes) {
|
|
18943
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18944
|
+
if (!nodeHandler) continue;
|
|
18945
|
+
nodeHandler.unlock(node);
|
|
18946
|
+
}
|
|
18947
|
+
}
|
|
18865
18948
|
};
|
|
18866
18949
|
|
|
18867
18950
|
//#endregion
|
|
@@ -18887,6 +18970,12 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
18887
18970
|
stage.container().addEventListener("blur", () => {
|
|
18888
18971
|
this.stageFocused = false;
|
|
18889
18972
|
});
|
|
18973
|
+
stage.on("pointermove", (e) => {
|
|
18974
|
+
if (e.target === stage) {
|
|
18975
|
+
const stage$1 = this.instance.getStage();
|
|
18976
|
+
stage$1.container().style.cursor = "default";
|
|
18977
|
+
}
|
|
18978
|
+
});
|
|
18890
18979
|
stage.on("pointerdown", (e) => {
|
|
18891
18980
|
if (e.evt.button === 1) this.wheelMousePressed = true;
|
|
18892
18981
|
});
|
|
@@ -23310,7 +23399,8 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
23310
23399
|
if (!realNode) return;
|
|
23311
23400
|
const nodeType = realNode.getAttrs().nodeType;
|
|
23312
23401
|
const nodeHandler = this.instance.getNodeHandler(nodeType);
|
|
23313
|
-
|
|
23402
|
+
const isLocked = this.instance.allNodesLocked([realNode]);
|
|
23403
|
+
if (nodeHandler && !isLocked) {
|
|
23314
23404
|
const nodeSerialized = nodeHandler.serialize(realNode);
|
|
23315
23405
|
this.instance.removeNode(nodeSerialized);
|
|
23316
23406
|
}
|
|
@@ -23769,9 +23859,6 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
23769
23859
|
return;
|
|
23770
23860
|
}
|
|
23771
23861
|
});
|
|
23772
|
-
stage.on("pointerdblclick", () => {
|
|
23773
|
-
this.cancelAction();
|
|
23774
|
-
});
|
|
23775
23862
|
stage.on("pointerclick", () => {
|
|
23776
23863
|
if (this.state === PEN_TOOL_STATE.IDLE) return;
|
|
23777
23864
|
if (this.state === PEN_TOOL_STATE.ADDING) {
|
|
@@ -25045,6 +25132,252 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
|
|
|
25045
25132
|
}
|
|
25046
25133
|
};
|
|
25047
25134
|
|
|
25135
|
+
//#endregion
|
|
25136
|
+
//#region src/actions/align-nodes-tool/constants.ts
|
|
25137
|
+
const ALIGN_NODES_TOOL_ACTION_NAME = "alignNodesTool";
|
|
25138
|
+
const ALIGN_NODES_ALIGN_TO = {
|
|
25139
|
+
["LEFT_HORIZONTAL"]: "left-horizontal",
|
|
25140
|
+
["CENTER_HORIZONTAL"]: "center-horizontal",
|
|
25141
|
+
["RIGHT_HORIZONTAL"]: "right-horizontal",
|
|
25142
|
+
["TOP_VERTICAL"]: "top-vertical",
|
|
25143
|
+
["CENTER_VERTICAL"]: "center-vertical",
|
|
25144
|
+
["BOTTOM_VERTICAL"]: "bottom-vertical"
|
|
25145
|
+
};
|
|
25146
|
+
const ALIGN_NODES_TOOL_STATE = { ["IDLE"]: "idle" };
|
|
25147
|
+
|
|
25148
|
+
//#endregion
|
|
25149
|
+
//#region src/actions/align-nodes-tool/align-nodes-tool.ts
|
|
25150
|
+
var WeaveAlignNodesToolAction = class extends WeaveAction {
|
|
25151
|
+
initialized = false;
|
|
25152
|
+
onPropsChange = void 0;
|
|
25153
|
+
onInit = void 0;
|
|
25154
|
+
constructor() {
|
|
25155
|
+
super();
|
|
25156
|
+
this.initialized = false;
|
|
25157
|
+
this.state = ALIGN_NODES_TOOL_STATE.IDLE;
|
|
25158
|
+
}
|
|
25159
|
+
getName() {
|
|
25160
|
+
return ALIGN_NODES_TOOL_ACTION_NAME;
|
|
25161
|
+
}
|
|
25162
|
+
setupEvents() {
|
|
25163
|
+
this.initialized = true;
|
|
25164
|
+
}
|
|
25165
|
+
setState(state) {
|
|
25166
|
+
this.state = state;
|
|
25167
|
+
}
|
|
25168
|
+
updateNode(node) {
|
|
25169
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
25170
|
+
if (nodeHandler) {
|
|
25171
|
+
const actualNode = nodeHandler.serialize(node);
|
|
25172
|
+
this.instance.updateNode(actualNode);
|
|
25173
|
+
}
|
|
25174
|
+
}
|
|
25175
|
+
getParents(nodes) {
|
|
25176
|
+
if (nodes.length === 0) return [];
|
|
25177
|
+
const counts = {};
|
|
25178
|
+
for (const node of nodes) {
|
|
25179
|
+
let realNode = node;
|
|
25180
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25181
|
+
if (!realNode) continue;
|
|
25182
|
+
const parentId = realNode.getParent()?.getAttrs().id ?? "";
|
|
25183
|
+
const entry = counts[parentId];
|
|
25184
|
+
if (entry) entry.count++;
|
|
25185
|
+
else counts[parentId] = {
|
|
25186
|
+
count: 1,
|
|
25187
|
+
id: realNode.getParent()?.getAttrs().id ?? "",
|
|
25188
|
+
value: realNode.getParent()
|
|
25189
|
+
};
|
|
25190
|
+
}
|
|
25191
|
+
return Object.keys(counts).map((key) => counts[key].id);
|
|
25192
|
+
}
|
|
25193
|
+
alignToLeftHorizontal(nodes) {
|
|
25194
|
+
let targetX = Infinity;
|
|
25195
|
+
for (const node of nodes) {
|
|
25196
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25197
|
+
const realX = box.x;
|
|
25198
|
+
if (realX < targetX) targetX = realX;
|
|
25199
|
+
}
|
|
25200
|
+
for (const node of nodes) {
|
|
25201
|
+
let realNode = node;
|
|
25202
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25203
|
+
if (!realNode) continue;
|
|
25204
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25205
|
+
const deltaX = targetX - box.x;
|
|
25206
|
+
realNode.x(realNode.x() + deltaX);
|
|
25207
|
+
this.updateNode(realNode);
|
|
25208
|
+
}
|
|
25209
|
+
}
|
|
25210
|
+
alignToCenterHorizontal(nodes) {
|
|
25211
|
+
let minX = Infinity;
|
|
25212
|
+
let maxX = -Infinity;
|
|
25213
|
+
for (const node of nodes) {
|
|
25214
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25215
|
+
const realX = box.x;
|
|
25216
|
+
const realXWidth = box.x + box.width;
|
|
25217
|
+
if (realX < minX) minX = realX;
|
|
25218
|
+
if (realXWidth > maxX) maxX = realXWidth;
|
|
25219
|
+
}
|
|
25220
|
+
const targetX = minX + (maxX - minX) / 2;
|
|
25221
|
+
for (const node of nodes) {
|
|
25222
|
+
let realNode = node;
|
|
25223
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25224
|
+
if (!realNode) continue;
|
|
25225
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25226
|
+
const deltaX = targetX - (box.x + box.width / 2);
|
|
25227
|
+
realNode.x(realNode.x() + deltaX);
|
|
25228
|
+
this.updateNode(realNode);
|
|
25229
|
+
}
|
|
25230
|
+
}
|
|
25231
|
+
alignToRightHorizontal(nodes) {
|
|
25232
|
+
let targetX = -Infinity;
|
|
25233
|
+
for (const node of nodes) {
|
|
25234
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25235
|
+
const realX = box.x + box.width;
|
|
25236
|
+
if (realX > targetX) targetX = realX;
|
|
25237
|
+
}
|
|
25238
|
+
for (const node of nodes) {
|
|
25239
|
+
let realNode = node;
|
|
25240
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25241
|
+
if (!realNode) continue;
|
|
25242
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25243
|
+
const deltaX = targetX - (box.x + box.width);
|
|
25244
|
+
realNode.x(realNode.x() + deltaX);
|
|
25245
|
+
this.updateNode(realNode);
|
|
25246
|
+
}
|
|
25247
|
+
}
|
|
25248
|
+
alignToTopVertical(nodes) {
|
|
25249
|
+
let targetY = Infinity;
|
|
25250
|
+
for (const node of nodes) {
|
|
25251
|
+
let realNode = node;
|
|
25252
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25253
|
+
if (!realNode) continue;
|
|
25254
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25255
|
+
const realY = box.y;
|
|
25256
|
+
if (realY < targetY) targetY = realY;
|
|
25257
|
+
}
|
|
25258
|
+
for (const node of nodes) {
|
|
25259
|
+
let realNode = node;
|
|
25260
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25261
|
+
if (!realNode) continue;
|
|
25262
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25263
|
+
const deltaY = targetY - box.y;
|
|
25264
|
+
realNode.y(realNode.y() + deltaY);
|
|
25265
|
+
this.updateNode(realNode);
|
|
25266
|
+
}
|
|
25267
|
+
}
|
|
25268
|
+
alignToCenterVertical(nodes) {
|
|
25269
|
+
let minY = Infinity;
|
|
25270
|
+
let maxY = -Infinity;
|
|
25271
|
+
for (const node of nodes) {
|
|
25272
|
+
let realNode = node;
|
|
25273
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25274
|
+
if (!realNode) continue;
|
|
25275
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25276
|
+
const realY = box.y;
|
|
25277
|
+
const realYWidth = box.y + box.height;
|
|
25278
|
+
if (realY < minY) minY = realY;
|
|
25279
|
+
if (realYWidth > maxY) maxY = realYWidth;
|
|
25280
|
+
}
|
|
25281
|
+
const targetY = minY + (maxY - minY) / 2;
|
|
25282
|
+
for (const node of nodes) {
|
|
25283
|
+
let realNode = node;
|
|
25284
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25285
|
+
if (!realNode) continue;
|
|
25286
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25287
|
+
const deltaY = targetY - (box.y + box.height / 2);
|
|
25288
|
+
realNode.y(realNode.y() + deltaY);
|
|
25289
|
+
this.updateNode(realNode);
|
|
25290
|
+
}
|
|
25291
|
+
}
|
|
25292
|
+
alignToBottomVertical(nodes) {
|
|
25293
|
+
let targetY = -Infinity;
|
|
25294
|
+
for (const node of nodes) {
|
|
25295
|
+
let realNode = node;
|
|
25296
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25297
|
+
if (!realNode) continue;
|
|
25298
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25299
|
+
const realY = box.y + box.height;
|
|
25300
|
+
if (realY > targetY) targetY = realY;
|
|
25301
|
+
}
|
|
25302
|
+
for (const node of nodes) {
|
|
25303
|
+
let realNode = node;
|
|
25304
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25305
|
+
if (!realNode) continue;
|
|
25306
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25307
|
+
const deltaY = targetY - (box.y + box.height);
|
|
25308
|
+
realNode.y(realNode.y() + deltaY);
|
|
25309
|
+
this.updateNode(realNode);
|
|
25310
|
+
}
|
|
25311
|
+
}
|
|
25312
|
+
alignNodes(alignTo) {
|
|
25313
|
+
let selectedNodes = [];
|
|
25314
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
25315
|
+
if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
|
|
25316
|
+
const parentsIds = this.getParents(selectedNodes);
|
|
25317
|
+
let parent = this.instance.getMainLayer();
|
|
25318
|
+
if (parentsIds.length === 1) parent = this.instance.getStage().findOne(`#${parentsIds[0]}`);
|
|
25319
|
+
if (parentsIds.length > 1 && !parentsIds.includes("mainLayer")) {
|
|
25320
|
+
this.cancelAction();
|
|
25321
|
+
return;
|
|
25322
|
+
}
|
|
25323
|
+
selectedNodes = [...selectedNodes.filter((node) => {
|
|
25324
|
+
let realNode = node;
|
|
25325
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25326
|
+
return realNode?.getParent()?.getAttrs().id === parent?.getAttrs().id;
|
|
25327
|
+
})];
|
|
25328
|
+
switch (alignTo) {
|
|
25329
|
+
case ALIGN_NODES_ALIGN_TO.LEFT_HORIZONTAL: {
|
|
25330
|
+
this.alignToLeftHorizontal(selectedNodes);
|
|
25331
|
+
break;
|
|
25332
|
+
}
|
|
25333
|
+
case ALIGN_NODES_ALIGN_TO.CENTER_HORIZONTAL: {
|
|
25334
|
+
this.alignToCenterHorizontal(selectedNodes);
|
|
25335
|
+
break;
|
|
25336
|
+
}
|
|
25337
|
+
case ALIGN_NODES_ALIGN_TO.RIGHT_HORIZONTAL: {
|
|
25338
|
+
this.alignToRightHorizontal(selectedNodes);
|
|
25339
|
+
break;
|
|
25340
|
+
}
|
|
25341
|
+
case ALIGN_NODES_ALIGN_TO.TOP_VERTICAL: {
|
|
25342
|
+
this.alignToTopVertical(selectedNodes);
|
|
25343
|
+
break;
|
|
25344
|
+
}
|
|
25345
|
+
case ALIGN_NODES_ALIGN_TO.CENTER_VERTICAL: {
|
|
25346
|
+
this.alignToCenterVertical(selectedNodes);
|
|
25347
|
+
break;
|
|
25348
|
+
}
|
|
25349
|
+
case ALIGN_NODES_ALIGN_TO.BOTTOM_VERTICAL: {
|
|
25350
|
+
this.alignToBottomVertical(selectedNodes);
|
|
25351
|
+
break;
|
|
25352
|
+
}
|
|
25353
|
+
default: break;
|
|
25354
|
+
}
|
|
25355
|
+
this.cancelAction();
|
|
25356
|
+
}
|
|
25357
|
+
canAlignSelectedNodes() {
|
|
25358
|
+
let selectedNodes = [];
|
|
25359
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
25360
|
+
if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
|
|
25361
|
+
const parentsIds = this.getParents(selectedNodes);
|
|
25362
|
+
if (parentsIds.length > 1) return false;
|
|
25363
|
+
return true;
|
|
25364
|
+
}
|
|
25365
|
+
trigger(cancelAction, { alignTo, triggerSelectionTool = true }) {
|
|
25366
|
+
if (!this.instance) throw new Error("Instance not defined");
|
|
25367
|
+
if (!this.initialized) this.setupEvents();
|
|
25368
|
+
const stage = this.instance.getStage();
|
|
25369
|
+
stage.container().tabIndex = 1;
|
|
25370
|
+
stage.container().focus();
|
|
25371
|
+
this.triggerSelectionTool = triggerSelectionTool;
|
|
25372
|
+
this.cancelAction = cancelAction;
|
|
25373
|
+
this.alignNodes(alignTo);
|
|
25374
|
+
}
|
|
25375
|
+
cleanup() {
|
|
25376
|
+
if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
|
|
25377
|
+
this.setState(ALIGN_NODES_TOOL_STATE.IDLE);
|
|
25378
|
+
}
|
|
25379
|
+
};
|
|
25380
|
+
|
|
25048
25381
|
//#endregion
|
|
25049
25382
|
//#region src/plugins/stage-grid/constants.ts
|
|
25050
25383
|
const WEAVE_STAGE_GRID_KEY = "stageGrid";
|
|
@@ -25054,8 +25387,8 @@ const WEAVE_GRID_TYPES = {
|
|
|
25054
25387
|
};
|
|
25055
25388
|
const WEAVE_GRID_DEFAULT_SIZE = 50;
|
|
25056
25389
|
const WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_TYPES.LINES;
|
|
25057
|
-
const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.
|
|
25058
|
-
const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.
|
|
25390
|
+
const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.1)";
|
|
25391
|
+
const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.1)";
|
|
25059
25392
|
const WEAVE_GRID_DEFAULT_STROKE = .5;
|
|
25060
25393
|
const WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = 4;
|
|
25061
25394
|
const WEAVE_GRID_DEFAULT_RADIUS = 1;
|
|
@@ -26269,6 +26602,9 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26269
26602
|
};
|
|
26270
26603
|
|
|
26271
26604
|
//#endregion
|
|
26605
|
+
exports.ALIGN_NODES_ALIGN_TO = ALIGN_NODES_ALIGN_TO
|
|
26606
|
+
exports.ALIGN_NODES_TOOL_ACTION_NAME = ALIGN_NODES_TOOL_ACTION_NAME
|
|
26607
|
+
exports.ALIGN_NODES_TOOL_STATE = ALIGN_NODES_TOOL_STATE
|
|
26272
26608
|
exports.ARROW_TOOL_ACTION_NAME = ARROW_TOOL_ACTION_NAME
|
|
26273
26609
|
exports.ARROW_TOOL_STATE = ARROW_TOOL_STATE
|
|
26274
26610
|
exports.BRUSH_TOOL_ACTION_NAME = BRUSH_TOOL_ACTION_NAME
|
|
@@ -26342,6 +26678,7 @@ exports.WEAVE_USER_POINTER_KEY = WEAVE_USER_POINTER_KEY
|
|
|
26342
26678
|
exports.WEAVE_USER_SELECTION_KEY = WEAVE_USER_SELECTION_KEY
|
|
26343
26679
|
exports.Weave = Weave
|
|
26344
26680
|
exports.WeaveAction = WeaveAction
|
|
26681
|
+
exports.WeaveAlignNodesToolAction = WeaveAlignNodesToolAction
|
|
26345
26682
|
exports.WeaveArrowNode = WeaveArrowNode
|
|
26346
26683
|
exports.WeaveArrowToolAction = WeaveArrowToolAction
|
|
26347
26684
|
exports.WeaveBrushToolAction = WeaveBrushToolAction
|