@inditextech/weave-sdk 0.33.0 → 0.35.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 +582 -116
- package/dist/sdk.d.cts +98 -5
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +98 -5
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +593 -132
- 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) {
|
|
@@ -15723,19 +15729,34 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15723
15729
|
}
|
|
15724
15730
|
initEvents() {
|
|
15725
15731
|
const stage = this.instance.getStage();
|
|
15732
|
+
this.instance.addEventListener("onDrag", (node) => {
|
|
15733
|
+
if (node) this.dragging = true;
|
|
15734
|
+
else this.dragging = false;
|
|
15735
|
+
});
|
|
15736
|
+
this.instance.addEventListener("onTransform", (node) => {
|
|
15737
|
+
if (node) this.transforming = true;
|
|
15738
|
+
else this.transforming = false;
|
|
15739
|
+
});
|
|
15726
15740
|
stage.on("pointerdown", (e) => {
|
|
15727
15741
|
this.pointers[e.evt.pointerId] = e.evt;
|
|
15742
|
+
if (e.evt.pointerType === "mouse") return;
|
|
15728
15743
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
15729
15744
|
this.touchTimer = setTimeout(() => {
|
|
15730
15745
|
this.tapHold = true;
|
|
15746
|
+
if (this.touchTimer && (this.dragging || this.transforming)) {
|
|
15747
|
+
clearTimeout(this.touchTimer);
|
|
15748
|
+
return;
|
|
15749
|
+
}
|
|
15731
15750
|
this.triggerContextMenu(e.target);
|
|
15732
15751
|
}, this.tapHoldTimeout);
|
|
15733
15752
|
});
|
|
15734
|
-
stage.on("pointermove", () => {
|
|
15753
|
+
stage.on("pointermove", (e) => {
|
|
15754
|
+
if (e.evt.pointerType === "mouse") return;
|
|
15735
15755
|
if (this.touchTimer) clearTimeout(this.touchTimer);
|
|
15736
15756
|
});
|
|
15737
15757
|
stage.on("pointerup", (e) => {
|
|
15738
15758
|
delete this.pointers[e.evt.pointerId];
|
|
15759
|
+
if (e.evt.pointerType === "mouse") return;
|
|
15739
15760
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
15740
15761
|
if (this.touchTimer) {
|
|
15741
15762
|
clearTimeout(this.touchTimer);
|
|
@@ -15803,6 +15824,8 @@ function checkIfOverContainer(instance, node) {
|
|
|
15803
15824
|
}
|
|
15804
15825
|
function moveNodeToContainer(instance, node) {
|
|
15805
15826
|
const nodeIntersected = instance.pointIntersectsContainerElement();
|
|
15827
|
+
const isLocked = instance.allNodesLocked([node]);
|
|
15828
|
+
if (isLocked) return;
|
|
15806
15829
|
let nodeActualContainer = node.getParent();
|
|
15807
15830
|
if (!nodeActualContainer) return void 0;
|
|
15808
15831
|
const actualContainerAttrs = nodeActualContainer.getAttrs();
|
|
@@ -16242,16 +16265,26 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16242
16265
|
return false;
|
|
16243
16266
|
});
|
|
16244
16267
|
const selectedNodes = new Set();
|
|
16245
|
-
const framesNodes = selected.filter((shape) =>
|
|
16246
|
-
|
|
16268
|
+
const framesNodes = selected.filter((shape) => {
|
|
16269
|
+
return shape.getAttrs().nodeType === "frame";
|
|
16270
|
+
});
|
|
16271
|
+
const framesNodesIds = framesNodes.map((shape) => {
|
|
16272
|
+
if (shape.getAttrs().nodeType === "frame" && shape.getAttrs().nodeId) return stage.findOne(`#${shape.getAttrs().nodeId}`);
|
|
16273
|
+
return shape;
|
|
16274
|
+
}).filter((shape) => {
|
|
16275
|
+
return shape.getAttrs().nodeType === "frame";
|
|
16276
|
+
}).map((shape) => {
|
|
16277
|
+
return shape.getAttrs().id;
|
|
16278
|
+
});
|
|
16247
16279
|
const otherNodes = selected.filter((shape) => shape.getAttrs().nodeType !== "frame");
|
|
16248
16280
|
otherNodes.forEach((node) => {
|
|
16249
|
-
|
|
16250
|
-
if (
|
|
16281
|
+
let parent = this.instance.getInstanceRecursive(node.getParent());
|
|
16282
|
+
if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
16283
|
+
if (parent && !framesNodesIds.includes(parent?.getAttrs().id) && !node.getAttrs().locked) selectedNodes.add(node);
|
|
16251
16284
|
});
|
|
16252
16285
|
framesNodes.forEach((node) => {
|
|
16253
16286
|
const frameNode = node;
|
|
16254
|
-
selectedNodes.add(frameNode);
|
|
16287
|
+
if (!frameNode.getAttrs().locked) selectedNodes.add(frameNode);
|
|
16255
16288
|
});
|
|
16256
16289
|
this.tr.nodes([...selectedNodes]);
|
|
16257
16290
|
this.triggerSelectedNodesEvent();
|
|
@@ -16302,6 +16335,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16302
16335
|
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
16303
16336
|
});
|
|
16304
16337
|
const isSelected = nodeSelectedIndex !== -1;
|
|
16338
|
+
if (nodeTargeted.getAttrs().locked) return;
|
|
16305
16339
|
if (!metaPressed) {
|
|
16306
16340
|
this.tr.nodes([nodeTargeted]);
|
|
16307
16341
|
nodesSelected = this.tr.nodes().length;
|
|
@@ -16665,106 +16699,104 @@ var WeaveNode = class {
|
|
|
16665
16699
|
node.scaleY(1);
|
|
16666
16700
|
}
|
|
16667
16701
|
setupDefaultNodeEvents(node) {
|
|
16668
|
-
this.previousPointer = null;
|
|
16669
16702
|
this.instance.addEventListener("onNodesChange", () => {
|
|
16670
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16703
|
+
if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
|
|
16671
16704
|
node.draggable(true);
|
|
16672
16705
|
return;
|
|
16673
16706
|
}
|
|
16674
16707
|
node.draggable(false);
|
|
16675
16708
|
});
|
|
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
|
-
|
|
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);
|
|
16709
|
+
const isLocked = node.getAttrs().locked ?? false;
|
|
16710
|
+
if (isLocked) {
|
|
16711
|
+
node.off("transformstart");
|
|
16712
|
+
node.off("transform");
|
|
16713
|
+
node.off("transformend");
|
|
16714
|
+
node.off("dragstart");
|
|
16715
|
+
node.off("dragmove");
|
|
16716
|
+
node.off("dragend");
|
|
16717
|
+
node.off("pointerenter");
|
|
16718
|
+
node.off("pointerleave");
|
|
16719
|
+
} else {
|
|
16720
|
+
let transforming = false;
|
|
16721
|
+
node.on("transformstart", (e) => {
|
|
16722
|
+
transforming = true;
|
|
16723
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
16724
|
+
});
|
|
16725
|
+
const handleTransform = (e) => {
|
|
16726
|
+
const node$1 = e.target;
|
|
16727
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16728
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16729
|
+
if (nodesSelectionPlugin && this.isSelecting() && this.isNodeSelected(node$1)) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
16730
|
+
if (nodesSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesSnappingPlugin.evaluateGuidelines(e);
|
|
16731
|
+
if (this.isSelecting() && this.isNodeSelected(node$1)) {
|
|
16732
|
+
this.scaleReset(node$1);
|
|
16733
|
+
const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
|
|
16734
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
16735
|
+
}
|
|
16736
|
+
};
|
|
16737
|
+
node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
|
|
16738
|
+
node.on("transformend", (e) => {
|
|
16739
|
+
const node$1 = e.target;
|
|
16740
|
+
this.instance.emitEvent("onTransform", null);
|
|
16741
|
+
transforming = false;
|
|
16742
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16730
16743
|
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16731
16744
|
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()) {
|
|
16745
|
+
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
16746
|
+
const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
|
|
16747
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
16748
|
+
});
|
|
16749
|
+
node.on("dragstart", (e) => {
|
|
16756
16750
|
const stage = this.instance.getStage();
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
|
|
16761
|
-
|
|
16751
|
+
this.instance.emitEvent("onDrag", e.target);
|
|
16752
|
+
if (stage.isMouseWheelPressed()) {
|
|
16753
|
+
e.cancelBubble = true;
|
|
16754
|
+
e.target.stopDrag();
|
|
16755
|
+
}
|
|
16756
|
+
});
|
|
16757
|
+
const handleDragMove = (e) => {
|
|
16762
16758
|
const stage = this.instance.getStage();
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
16766
|
-
|
|
16767
|
-
|
|
16759
|
+
if (stage.isMouseWheelPressed()) {
|
|
16760
|
+
e.cancelBubble = true;
|
|
16761
|
+
e.target.stopDrag();
|
|
16762
|
+
return;
|
|
16763
|
+
}
|
|
16764
|
+
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16765
|
+
clearContainerTargets(this.instance);
|
|
16766
|
+
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16767
|
+
if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
16768
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
16769
|
+
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
|
|
16770
|
+
}
|
|
16771
|
+
};
|
|
16772
|
+
node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
|
|
16773
|
+
node.on("dragend", (e) => {
|
|
16774
|
+
this.instance.emitEvent("onDrag", null);
|
|
16775
|
+
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16776
|
+
clearContainerTargets(this.instance);
|
|
16777
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16778
|
+
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
16779
|
+
const containerToMove = moveNodeToContainer(this.instance, e.target);
|
|
16780
|
+
if (containerToMove) return;
|
|
16781
|
+
this.instance.updateNode(this.serialize(node));
|
|
16782
|
+
}
|
|
16783
|
+
});
|
|
16784
|
+
node.on("pointerenter", (e) => {
|
|
16785
|
+
const realNode = this.instance.getInstanceRecursive(node);
|
|
16786
|
+
const isLocked$1 = realNode.getAttrs().locked ?? false;
|
|
16787
|
+
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
|
|
16788
|
+
const stage = this.instance.getStage();
|
|
16789
|
+
stage.container().style.cursor = !isLocked$1 ? "pointer" : "default";
|
|
16790
|
+
e.cancelBubble = true;
|
|
16791
|
+
return;
|
|
16792
|
+
}
|
|
16793
|
+
if (this.isPasting()) {
|
|
16794
|
+
const stage = this.instance.getStage();
|
|
16795
|
+
stage.container().style.cursor = "crosshair";
|
|
16796
|
+
e.cancelBubble = true;
|
|
16797
|
+
}
|
|
16798
|
+
});
|
|
16799
|
+
}
|
|
16768
16800
|
}
|
|
16769
16801
|
create(key, props) {
|
|
16770
16802
|
return {
|
|
@@ -16796,6 +16828,61 @@ var WeaveNode = class {
|
|
|
16796
16828
|
}
|
|
16797
16829
|
};
|
|
16798
16830
|
}
|
|
16831
|
+
show(instance) {
|
|
16832
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16833
|
+
instance.setAttrs({ visible: true });
|
|
16834
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16835
|
+
this.setupDefaultNodeEvents(instance);
|
|
16836
|
+
const stage = this.instance.getStage();
|
|
16837
|
+
stage.container().style.cursor = "default";
|
|
16838
|
+
}
|
|
16839
|
+
hide(instance) {
|
|
16840
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16841
|
+
instance.setAttrs({ visible: false });
|
|
16842
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16843
|
+
if (selectionPlugin) {
|
|
16844
|
+
const ids = [instance.getAttrs().id];
|
|
16845
|
+
if (instance.getAttrs().nodeType === "frame") ids.push(`${instance.getAttrs().id}-selector-area`);
|
|
16846
|
+
const selectedNodes = selectionPlugin.getSelectedNodes();
|
|
16847
|
+
const newSelectedNodes = selectedNodes.filter((node) => !ids.includes(node.getAttrs().id));
|
|
16848
|
+
selectionPlugin.setSelectedNodes(newSelectedNodes);
|
|
16849
|
+
selectionPlugin.getTransformer().forceUpdate();
|
|
16850
|
+
}
|
|
16851
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16852
|
+
this.setupDefaultNodeEvents(instance);
|
|
16853
|
+
const stage = this.instance.getStage();
|
|
16854
|
+
stage.container().style.cursor = "default";
|
|
16855
|
+
}
|
|
16856
|
+
isVisible(instance) {
|
|
16857
|
+
if (typeof instance.getAttrs().visible === "undefined") return true;
|
|
16858
|
+
return instance.getAttrs().visible ?? false;
|
|
16859
|
+
}
|
|
16860
|
+
lock(instance) {
|
|
16861
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16862
|
+
instance.setAttrs({ locked: true });
|
|
16863
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16864
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16865
|
+
if (selectionPlugin) {
|
|
16866
|
+
const selectedNodes = selectionPlugin.getSelectedNodes();
|
|
16867
|
+
const newSelectedNodes = selectedNodes.filter((node) => node.getAttrs().id !== instance.getAttrs().id);
|
|
16868
|
+
selectionPlugin.setSelectedNodes(newSelectedNodes);
|
|
16869
|
+
selectionPlugin.getTransformer().forceUpdate();
|
|
16870
|
+
}
|
|
16871
|
+
this.setupDefaultNodeEvents(instance);
|
|
16872
|
+
const stage = this.instance.getStage();
|
|
16873
|
+
stage.container().style.cursor = "default";
|
|
16874
|
+
}
|
|
16875
|
+
unlock(instance) {
|
|
16876
|
+
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16877
|
+
instance.setAttrs({ locked: false });
|
|
16878
|
+
this.instance.updateNode(this.serialize(instance));
|
|
16879
|
+
this.setupDefaultNodeEvents(instance);
|
|
16880
|
+
const stage = this.instance.getStage();
|
|
16881
|
+
stage.container().style.cursor = "default";
|
|
16882
|
+
}
|
|
16883
|
+
isLocked(instance) {
|
|
16884
|
+
return instance.getAttrs().locked ?? false;
|
|
16885
|
+
}
|
|
16799
16886
|
};
|
|
16800
16887
|
|
|
16801
16888
|
//#endregion
|
|
@@ -18230,7 +18317,7 @@ var WeaveRegisterManager = class {
|
|
|
18230
18317
|
|
|
18231
18318
|
//#endregion
|
|
18232
18319
|
//#region package.json
|
|
18233
|
-
var version = "0.
|
|
18320
|
+
var version = "0.35.0";
|
|
18234
18321
|
|
|
18235
18322
|
//#endregion
|
|
18236
18323
|
//#region src/managers/setup.ts
|
|
@@ -18801,6 +18888,9 @@ var Weave = class {
|
|
|
18801
18888
|
getElementsTree() {
|
|
18802
18889
|
return this.stateManager.getElementsTree();
|
|
18803
18890
|
}
|
|
18891
|
+
isEmpty() {
|
|
18892
|
+
return this.getElementsTree().length === 0;
|
|
18893
|
+
}
|
|
18804
18894
|
moveUp(node) {
|
|
18805
18895
|
this.zIndexManager.moveUp(node);
|
|
18806
18896
|
}
|
|
@@ -18841,7 +18931,8 @@ var Weave = class {
|
|
|
18841
18931
|
if (selectionPlugin) {
|
|
18842
18932
|
const stage = this.getStage();
|
|
18843
18933
|
const instanceNodes = nodesIds.map((nodeId) => {
|
|
18844
|
-
|
|
18934
|
+
let nodeInstance = stage.findOne(`#${nodeId}`);
|
|
18935
|
+
if (nodeInstance && nodeInstance.getAttrs().nodeType === "frame") nodeInstance = stage.findOne(`#${nodeId}-selector-area`);
|
|
18845
18936
|
return nodeInstance;
|
|
18846
18937
|
});
|
|
18847
18938
|
selectionPlugin.setSelectedNodes(instanceNodes);
|
|
@@ -18862,6 +18953,90 @@ var Weave = class {
|
|
|
18862
18953
|
async exportNodes(nodes, boundingNodes, options) {
|
|
18863
18954
|
return await this.exportManager.exportNodes(nodes, boundingNodes, options);
|
|
18864
18955
|
}
|
|
18956
|
+
allNodesLocked(nodes) {
|
|
18957
|
+
let allNodesLocked = true;
|
|
18958
|
+
for (const node of nodes) {
|
|
18959
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18960
|
+
if (!nodeHandler) continue;
|
|
18961
|
+
allNodesLocked = allNodesLocked && nodeHandler.isLocked(node);
|
|
18962
|
+
}
|
|
18963
|
+
return allNodesLocked;
|
|
18964
|
+
}
|
|
18965
|
+
allNodesUnlocked(nodes) {
|
|
18966
|
+
let allNodesUnlocked = true;
|
|
18967
|
+
for (const node of nodes) {
|
|
18968
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18969
|
+
if (!nodeHandler) continue;
|
|
18970
|
+
allNodesUnlocked = allNodesUnlocked && !nodeHandler.isLocked(node);
|
|
18971
|
+
}
|
|
18972
|
+
return allNodesUnlocked;
|
|
18973
|
+
}
|
|
18974
|
+
lockNode(node) {
|
|
18975
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18976
|
+
if (!nodeHandler) return;
|
|
18977
|
+
nodeHandler.lock(node);
|
|
18978
|
+
}
|
|
18979
|
+
lockNodes(nodes) {
|
|
18980
|
+
for (const node of nodes) {
|
|
18981
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18982
|
+
if (!nodeHandler) continue;
|
|
18983
|
+
nodeHandler.lock(node);
|
|
18984
|
+
}
|
|
18985
|
+
}
|
|
18986
|
+
unlockNode(node) {
|
|
18987
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18988
|
+
if (!nodeHandler) return;
|
|
18989
|
+
nodeHandler.unlock(node);
|
|
18990
|
+
}
|
|
18991
|
+
unlockNodes(nodes) {
|
|
18992
|
+
for (const node of nodes) {
|
|
18993
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
18994
|
+
if (!nodeHandler) continue;
|
|
18995
|
+
nodeHandler.unlock(node);
|
|
18996
|
+
}
|
|
18997
|
+
}
|
|
18998
|
+
allNodesVisible(nodes) {
|
|
18999
|
+
let allNodesVisible = true;
|
|
19000
|
+
for (const node of nodes) {
|
|
19001
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19002
|
+
if (!nodeHandler) continue;
|
|
19003
|
+
allNodesVisible = allNodesVisible && nodeHandler.isVisible(node);
|
|
19004
|
+
}
|
|
19005
|
+
return allNodesVisible;
|
|
19006
|
+
}
|
|
19007
|
+
allNodesHidden(nodes) {
|
|
19008
|
+
let allNodesHidden = true;
|
|
19009
|
+
for (const node of nodes) {
|
|
19010
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19011
|
+
if (!nodeHandler) continue;
|
|
19012
|
+
allNodesHidden = allNodesHidden && !nodeHandler.isVisible(node);
|
|
19013
|
+
}
|
|
19014
|
+
return allNodesHidden;
|
|
19015
|
+
}
|
|
19016
|
+
hideNode(node) {
|
|
19017
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19018
|
+
if (!nodeHandler) return;
|
|
19019
|
+
nodeHandler.hide(node);
|
|
19020
|
+
}
|
|
19021
|
+
hideNodes(nodes) {
|
|
19022
|
+
for (const node of nodes) {
|
|
19023
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19024
|
+
if (!nodeHandler) continue;
|
|
19025
|
+
nodeHandler.hide(node);
|
|
19026
|
+
}
|
|
19027
|
+
}
|
|
19028
|
+
showNode(node) {
|
|
19029
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19030
|
+
if (!nodeHandler) return;
|
|
19031
|
+
nodeHandler.show(node);
|
|
19032
|
+
}
|
|
19033
|
+
showNodes(nodes) {
|
|
19034
|
+
for (const node of nodes) {
|
|
19035
|
+
const nodeHandler = this.getNodeHandler(node.getAttrs().nodeType);
|
|
19036
|
+
if (!nodeHandler) continue;
|
|
19037
|
+
nodeHandler.show(node);
|
|
19038
|
+
}
|
|
19039
|
+
}
|
|
18865
19040
|
};
|
|
18866
19041
|
|
|
18867
19042
|
//#endregion
|
|
@@ -18887,6 +19062,28 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
18887
19062
|
stage.container().addEventListener("blur", () => {
|
|
18888
19063
|
this.stageFocused = false;
|
|
18889
19064
|
});
|
|
19065
|
+
konva.default.Stage.prototype.allowActions = function(actions) {
|
|
19066
|
+
if (typeof actions !== "undefined") this._allowActions = actions;
|
|
19067
|
+
return this._allowActions;
|
|
19068
|
+
};
|
|
19069
|
+
konva.default.Stage.prototype.allowSelectNodes = function(nodeTypes) {
|
|
19070
|
+
if (typeof nodeTypes !== "undefined") this._allowSelectNodeTypes = nodeTypes;
|
|
19071
|
+
return this._allowSelectNodeTypes;
|
|
19072
|
+
};
|
|
19073
|
+
konva.default.Stage.prototype.allowSelection = function(allowSelection) {
|
|
19074
|
+
if (typeof allowSelection !== "undefined") this._allowSelection = allowSelection;
|
|
19075
|
+
return this._allowSelection;
|
|
19076
|
+
};
|
|
19077
|
+
stage.on("pointermove", (e) => {
|
|
19078
|
+
if (stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
|
|
19079
|
+
const stage$1 = this.instance.getStage();
|
|
19080
|
+
stage$1.container().style.cursor = "default";
|
|
19081
|
+
}
|
|
19082
|
+
if (e.target === stage && this.instance.getActiveAction() === "selectionTool") {
|
|
19083
|
+
const stage$1 = this.instance.getStage();
|
|
19084
|
+
stage$1.container().style.cursor = "default";
|
|
19085
|
+
}
|
|
19086
|
+
});
|
|
18890
19087
|
stage.on("pointerdown", (e) => {
|
|
18891
19088
|
if (e.evt.button === 1) this.wheelMousePressed = true;
|
|
18892
19089
|
});
|
|
@@ -19216,7 +19413,13 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19216
19413
|
const node = e.target;
|
|
19217
19414
|
if (this.isSelecting() && this.isNodeSelected(node)) e.cancelBubble = true;
|
|
19218
19415
|
};
|
|
19416
|
+
text.on("transformstart", (e) => {
|
|
19417
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
19418
|
+
});
|
|
19219
19419
|
text.on("transform", (0, import_lodash.throttle)(handleTextTransform, 50));
|
|
19420
|
+
text.on("transformend", () => {
|
|
19421
|
+
this.instance.emitEvent("onTransform", null);
|
|
19422
|
+
});
|
|
19220
19423
|
window.addEventListener("keypress", (e) => {
|
|
19221
19424
|
if (e.key === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing && e.target !== this.textArea) {
|
|
19222
19425
|
e.preventDefault();
|
|
@@ -19955,19 +20158,26 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
19955
20158
|
skipStroke: true
|
|
19956
20159
|
});
|
|
19957
20160
|
this.drawGridLines(0, 0, cropRect.width, cropRect.height);
|
|
19958
|
-
|
|
20161
|
+
const handleGridLines = () => {
|
|
19959
20162
|
const cropRect$1 = this.cropRect.getClientRect({
|
|
19960
20163
|
relativeTo: this.cropGroup,
|
|
19961
20164
|
skipStroke: true
|
|
19962
20165
|
});
|
|
19963
20166
|
this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
|
|
20167
|
+
};
|
|
20168
|
+
this.cropRect.on("dragstart", (e) => {
|
|
20169
|
+
this.instance.emitEvent("onDrag", e.target);
|
|
19964
20170
|
});
|
|
19965
|
-
this.cropRect.on("
|
|
19966
|
-
|
|
19967
|
-
|
|
19968
|
-
|
|
19969
|
-
|
|
19970
|
-
this.
|
|
20171
|
+
this.cropRect.on("dragmove", handleGridLines);
|
|
20172
|
+
this.cropRect.on("dragend", () => {
|
|
20173
|
+
this.instance.emitEvent("onDrag", null);
|
|
20174
|
+
});
|
|
20175
|
+
this.cropRect.on("transformstart", (e) => {
|
|
20176
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
20177
|
+
});
|
|
20178
|
+
this.cropRect.on("transform", handleGridLines);
|
|
20179
|
+
this.cropRect.on("transformend", () => {
|
|
20180
|
+
this.instance.emitEvent("onTransform", null);
|
|
19971
20181
|
});
|
|
19972
20182
|
this.transformer.nodes([this.cropRect]);
|
|
19973
20183
|
this.cropGroup.add(this.cropImage);
|
|
@@ -20881,8 +21091,12 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
20881
21091
|
clonedSA.scaleY(1);
|
|
20882
21092
|
e.cancelBubble = true;
|
|
20883
21093
|
};
|
|
21094
|
+
selectorArea.on("transformend", (e) => {
|
|
21095
|
+
this.instance.emitEvent("onTransform", e.target);
|
|
21096
|
+
});
|
|
20884
21097
|
selectorArea.on("transform", (0, import_lodash.throttle)(handleSelectorAreaTransform, 50));
|
|
20885
21098
|
selectorArea.on("transformend", (e) => {
|
|
21099
|
+
this.instance.emitEvent("onTransform", null);
|
|
20886
21100
|
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
20887
21101
|
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
20888
21102
|
const scaleX = selectorArea.scaleX();
|
|
@@ -22894,7 +23108,9 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
22894
23108
|
x: 0,
|
|
22895
23109
|
y: 0
|
|
22896
23110
|
});
|
|
22897
|
-
|
|
23111
|
+
let realNodes = mainLayer.getChildren();
|
|
23112
|
+
realNodes = realNodes.filter((node) => typeof node.getAttrs().visible === "undefined" || node.getAttrs().visible);
|
|
23113
|
+
const bounds = getBoundingBox(stage, realNodes);
|
|
22898
23114
|
const stageWidth = stage.width();
|
|
22899
23115
|
const stageHeight = stage.height();
|
|
22900
23116
|
const scaleX = (stageWidth - this.config.fitToScreen.padding * 2) / bounds.width;
|
|
@@ -23204,12 +23420,14 @@ var WeaveMoveToolAction = class extends WeaveAction {
|
|
|
23204
23420
|
stage.container().focus();
|
|
23205
23421
|
this.setState(MOVE_TOOL_STATE.MOVING);
|
|
23206
23422
|
}
|
|
23207
|
-
trigger(cancelAction) {
|
|
23423
|
+
trigger(cancelAction, params) {
|
|
23208
23424
|
if (!this.instance) throw new Error("Instance not defined");
|
|
23209
23425
|
if (!this.initialized) this.setupEvents();
|
|
23210
23426
|
const stage = this.instance.getStage();
|
|
23211
23427
|
stage.container().tabIndex = 1;
|
|
23212
23428
|
stage.container().focus();
|
|
23429
|
+
const { triggerSelectionTool = true } = params ?? {};
|
|
23430
|
+
this.triggerSelectionTool = triggerSelectionTool;
|
|
23213
23431
|
this.cancelAction = cancelAction;
|
|
23214
23432
|
this.setMoving();
|
|
23215
23433
|
}
|
|
@@ -23217,7 +23435,7 @@ var WeaveMoveToolAction = class extends WeaveAction {
|
|
|
23217
23435
|
const stage = this.instance.getStage();
|
|
23218
23436
|
stage.container().style.cursor = "default";
|
|
23219
23437
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23220
|
-
if (selectionPlugin) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
23438
|
+
if (selectionPlugin && this.triggerSelectionTool) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
23221
23439
|
this.setState(MOVE_TOOL_STATE.IDLE);
|
|
23222
23440
|
}
|
|
23223
23441
|
};
|
|
@@ -23310,7 +23528,8 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
23310
23528
|
if (!realNode) return;
|
|
23311
23529
|
const nodeType = realNode.getAttrs().nodeType;
|
|
23312
23530
|
const nodeHandler = this.instance.getNodeHandler(nodeType);
|
|
23313
|
-
|
|
23531
|
+
const isLocked = this.instance.allNodesLocked([realNode]);
|
|
23532
|
+
if (nodeHandler && !isLocked) {
|
|
23314
23533
|
const nodeSerialized = nodeHandler.serialize(realNode);
|
|
23315
23534
|
this.instance.removeNode(nodeSerialized);
|
|
23316
23535
|
}
|
|
@@ -23769,9 +23988,6 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
23769
23988
|
return;
|
|
23770
23989
|
}
|
|
23771
23990
|
});
|
|
23772
|
-
stage.on("pointerdblclick", () => {
|
|
23773
|
-
this.cancelAction();
|
|
23774
|
-
});
|
|
23775
23991
|
stage.on("pointerclick", () => {
|
|
23776
23992
|
if (this.state === PEN_TOOL_STATE.IDLE) return;
|
|
23777
23993
|
if (this.state === PEN_TOOL_STATE.ADDING) {
|
|
@@ -25045,6 +25261,252 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
|
|
|
25045
25261
|
}
|
|
25046
25262
|
};
|
|
25047
25263
|
|
|
25264
|
+
//#endregion
|
|
25265
|
+
//#region src/actions/align-nodes-tool/constants.ts
|
|
25266
|
+
const ALIGN_NODES_TOOL_ACTION_NAME = "alignNodesTool";
|
|
25267
|
+
const ALIGN_NODES_ALIGN_TO = {
|
|
25268
|
+
["LEFT_HORIZONTAL"]: "left-horizontal",
|
|
25269
|
+
["CENTER_HORIZONTAL"]: "center-horizontal",
|
|
25270
|
+
["RIGHT_HORIZONTAL"]: "right-horizontal",
|
|
25271
|
+
["TOP_VERTICAL"]: "top-vertical",
|
|
25272
|
+
["CENTER_VERTICAL"]: "center-vertical",
|
|
25273
|
+
["BOTTOM_VERTICAL"]: "bottom-vertical"
|
|
25274
|
+
};
|
|
25275
|
+
const ALIGN_NODES_TOOL_STATE = { ["IDLE"]: "idle" };
|
|
25276
|
+
|
|
25277
|
+
//#endregion
|
|
25278
|
+
//#region src/actions/align-nodes-tool/align-nodes-tool.ts
|
|
25279
|
+
var WeaveAlignNodesToolAction = class extends WeaveAction {
|
|
25280
|
+
initialized = false;
|
|
25281
|
+
onPropsChange = void 0;
|
|
25282
|
+
onInit = void 0;
|
|
25283
|
+
constructor() {
|
|
25284
|
+
super();
|
|
25285
|
+
this.initialized = false;
|
|
25286
|
+
this.state = ALIGN_NODES_TOOL_STATE.IDLE;
|
|
25287
|
+
}
|
|
25288
|
+
getName() {
|
|
25289
|
+
return ALIGN_NODES_TOOL_ACTION_NAME;
|
|
25290
|
+
}
|
|
25291
|
+
setupEvents() {
|
|
25292
|
+
this.initialized = true;
|
|
25293
|
+
}
|
|
25294
|
+
setState(state) {
|
|
25295
|
+
this.state = state;
|
|
25296
|
+
}
|
|
25297
|
+
updateNode(node) {
|
|
25298
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
25299
|
+
if (nodeHandler) {
|
|
25300
|
+
const actualNode = nodeHandler.serialize(node);
|
|
25301
|
+
this.instance.updateNode(actualNode);
|
|
25302
|
+
}
|
|
25303
|
+
}
|
|
25304
|
+
getParents(nodes) {
|
|
25305
|
+
if (nodes.length === 0) return [];
|
|
25306
|
+
const counts = {};
|
|
25307
|
+
for (const node of nodes) {
|
|
25308
|
+
let realNode = node;
|
|
25309
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25310
|
+
if (!realNode) continue;
|
|
25311
|
+
const parentId = realNode.getParent()?.getAttrs().id ?? "";
|
|
25312
|
+
const entry = counts[parentId];
|
|
25313
|
+
if (entry) entry.count++;
|
|
25314
|
+
else counts[parentId] = {
|
|
25315
|
+
count: 1,
|
|
25316
|
+
id: realNode.getParent()?.getAttrs().id ?? "",
|
|
25317
|
+
value: realNode.getParent()
|
|
25318
|
+
};
|
|
25319
|
+
}
|
|
25320
|
+
return Object.keys(counts).map((key) => counts[key].id);
|
|
25321
|
+
}
|
|
25322
|
+
alignToLeftHorizontal(nodes) {
|
|
25323
|
+
let targetX = Infinity;
|
|
25324
|
+
for (const node of nodes) {
|
|
25325
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25326
|
+
const realX = box.x;
|
|
25327
|
+
if (realX < targetX) targetX = realX;
|
|
25328
|
+
}
|
|
25329
|
+
for (const node of nodes) {
|
|
25330
|
+
let realNode = node;
|
|
25331
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25332
|
+
if (!realNode) continue;
|
|
25333
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25334
|
+
const deltaX = targetX - box.x;
|
|
25335
|
+
realNode.x(realNode.x() + deltaX);
|
|
25336
|
+
this.updateNode(realNode);
|
|
25337
|
+
}
|
|
25338
|
+
}
|
|
25339
|
+
alignToCenterHorizontal(nodes) {
|
|
25340
|
+
let minX = Infinity;
|
|
25341
|
+
let maxX = -Infinity;
|
|
25342
|
+
for (const node of nodes) {
|
|
25343
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25344
|
+
const realX = box.x;
|
|
25345
|
+
const realXWidth = box.x + box.width;
|
|
25346
|
+
if (realX < minX) minX = realX;
|
|
25347
|
+
if (realXWidth > maxX) maxX = realXWidth;
|
|
25348
|
+
}
|
|
25349
|
+
const targetX = minX + (maxX - minX) / 2;
|
|
25350
|
+
for (const node of nodes) {
|
|
25351
|
+
let realNode = node;
|
|
25352
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25353
|
+
if (!realNode) continue;
|
|
25354
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25355
|
+
const deltaX = targetX - (box.x + box.width / 2);
|
|
25356
|
+
realNode.x(realNode.x() + deltaX);
|
|
25357
|
+
this.updateNode(realNode);
|
|
25358
|
+
}
|
|
25359
|
+
}
|
|
25360
|
+
alignToRightHorizontal(nodes) {
|
|
25361
|
+
let targetX = -Infinity;
|
|
25362
|
+
for (const node of nodes) {
|
|
25363
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25364
|
+
const realX = box.x + box.width;
|
|
25365
|
+
if (realX > targetX) targetX = realX;
|
|
25366
|
+
}
|
|
25367
|
+
for (const node of nodes) {
|
|
25368
|
+
let realNode = node;
|
|
25369
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25370
|
+
if (!realNode) continue;
|
|
25371
|
+
const box = node.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25372
|
+
const deltaX = targetX - (box.x + box.width);
|
|
25373
|
+
realNode.x(realNode.x() + deltaX);
|
|
25374
|
+
this.updateNode(realNode);
|
|
25375
|
+
}
|
|
25376
|
+
}
|
|
25377
|
+
alignToTopVertical(nodes) {
|
|
25378
|
+
let targetY = Infinity;
|
|
25379
|
+
for (const node of nodes) {
|
|
25380
|
+
let realNode = node;
|
|
25381
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25382
|
+
if (!realNode) continue;
|
|
25383
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25384
|
+
const realY = box.y;
|
|
25385
|
+
if (realY < targetY) targetY = realY;
|
|
25386
|
+
}
|
|
25387
|
+
for (const node of nodes) {
|
|
25388
|
+
let realNode = node;
|
|
25389
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25390
|
+
if (!realNode) continue;
|
|
25391
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25392
|
+
const deltaY = targetY - box.y;
|
|
25393
|
+
realNode.y(realNode.y() + deltaY);
|
|
25394
|
+
this.updateNode(realNode);
|
|
25395
|
+
}
|
|
25396
|
+
}
|
|
25397
|
+
alignToCenterVertical(nodes) {
|
|
25398
|
+
let minY = Infinity;
|
|
25399
|
+
let maxY = -Infinity;
|
|
25400
|
+
for (const node of nodes) {
|
|
25401
|
+
let realNode = node;
|
|
25402
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25403
|
+
if (!realNode) continue;
|
|
25404
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25405
|
+
const realY = box.y;
|
|
25406
|
+
const realYWidth = box.y + box.height;
|
|
25407
|
+
if (realY < minY) minY = realY;
|
|
25408
|
+
if (realYWidth > maxY) maxY = realYWidth;
|
|
25409
|
+
}
|
|
25410
|
+
const targetY = minY + (maxY - minY) / 2;
|
|
25411
|
+
for (const node of nodes) {
|
|
25412
|
+
let realNode = node;
|
|
25413
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25414
|
+
if (!realNode) continue;
|
|
25415
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25416
|
+
const deltaY = targetY - (box.y + box.height / 2);
|
|
25417
|
+
realNode.y(realNode.y() + deltaY);
|
|
25418
|
+
this.updateNode(realNode);
|
|
25419
|
+
}
|
|
25420
|
+
}
|
|
25421
|
+
alignToBottomVertical(nodes) {
|
|
25422
|
+
let targetY = -Infinity;
|
|
25423
|
+
for (const node of nodes) {
|
|
25424
|
+
let realNode = node;
|
|
25425
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25426
|
+
if (!realNode) continue;
|
|
25427
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25428
|
+
const realY = box.y + box.height;
|
|
25429
|
+
if (realY > targetY) targetY = realY;
|
|
25430
|
+
}
|
|
25431
|
+
for (const node of nodes) {
|
|
25432
|
+
let realNode = node;
|
|
25433
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25434
|
+
if (!realNode) continue;
|
|
25435
|
+
const box = realNode.getClientRect({ relativeTo: this.instance.getStage() });
|
|
25436
|
+
const deltaY = targetY - (box.y + box.height);
|
|
25437
|
+
realNode.y(realNode.y() + deltaY);
|
|
25438
|
+
this.updateNode(realNode);
|
|
25439
|
+
}
|
|
25440
|
+
}
|
|
25441
|
+
alignNodes(alignTo) {
|
|
25442
|
+
let selectedNodes = [];
|
|
25443
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
25444
|
+
if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
|
|
25445
|
+
const parentsIds = this.getParents(selectedNodes);
|
|
25446
|
+
let parent = this.instance.getMainLayer();
|
|
25447
|
+
if (parentsIds.length === 1) parent = this.instance.getStage().findOne(`#${parentsIds[0]}`);
|
|
25448
|
+
if (parentsIds.length > 1 && !parentsIds.includes("mainLayer")) {
|
|
25449
|
+
this.cancelAction();
|
|
25450
|
+
return;
|
|
25451
|
+
}
|
|
25452
|
+
selectedNodes = [...selectedNodes.filter((node) => {
|
|
25453
|
+
let realNode = node;
|
|
25454
|
+
if (node.getAttrs().nodeId) realNode = this.instance.getStage().findOne(`#${node.getAttrs().nodeId}`);
|
|
25455
|
+
return realNode?.getParent()?.getAttrs().id === parent?.getAttrs().id;
|
|
25456
|
+
})];
|
|
25457
|
+
switch (alignTo) {
|
|
25458
|
+
case ALIGN_NODES_ALIGN_TO.LEFT_HORIZONTAL: {
|
|
25459
|
+
this.alignToLeftHorizontal(selectedNodes);
|
|
25460
|
+
break;
|
|
25461
|
+
}
|
|
25462
|
+
case ALIGN_NODES_ALIGN_TO.CENTER_HORIZONTAL: {
|
|
25463
|
+
this.alignToCenterHorizontal(selectedNodes);
|
|
25464
|
+
break;
|
|
25465
|
+
}
|
|
25466
|
+
case ALIGN_NODES_ALIGN_TO.RIGHT_HORIZONTAL: {
|
|
25467
|
+
this.alignToRightHorizontal(selectedNodes);
|
|
25468
|
+
break;
|
|
25469
|
+
}
|
|
25470
|
+
case ALIGN_NODES_ALIGN_TO.TOP_VERTICAL: {
|
|
25471
|
+
this.alignToTopVertical(selectedNodes);
|
|
25472
|
+
break;
|
|
25473
|
+
}
|
|
25474
|
+
case ALIGN_NODES_ALIGN_TO.CENTER_VERTICAL: {
|
|
25475
|
+
this.alignToCenterVertical(selectedNodes);
|
|
25476
|
+
break;
|
|
25477
|
+
}
|
|
25478
|
+
case ALIGN_NODES_ALIGN_TO.BOTTOM_VERTICAL: {
|
|
25479
|
+
this.alignToBottomVertical(selectedNodes);
|
|
25480
|
+
break;
|
|
25481
|
+
}
|
|
25482
|
+
default: break;
|
|
25483
|
+
}
|
|
25484
|
+
this.cancelAction();
|
|
25485
|
+
}
|
|
25486
|
+
canAlignSelectedNodes() {
|
|
25487
|
+
let selectedNodes = [];
|
|
25488
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
25489
|
+
if (selectionPlugin) selectedNodes = selectionPlugin.getSelectedNodes();
|
|
25490
|
+
const parentsIds = this.getParents(selectedNodes);
|
|
25491
|
+
if (parentsIds.length > 1) return false;
|
|
25492
|
+
return true;
|
|
25493
|
+
}
|
|
25494
|
+
trigger(cancelAction, { alignTo, triggerSelectionTool = true }) {
|
|
25495
|
+
if (!this.instance) throw new Error("Instance not defined");
|
|
25496
|
+
if (!this.initialized) this.setupEvents();
|
|
25497
|
+
const stage = this.instance.getStage();
|
|
25498
|
+
stage.container().tabIndex = 1;
|
|
25499
|
+
stage.container().focus();
|
|
25500
|
+
this.triggerSelectionTool = triggerSelectionTool;
|
|
25501
|
+
this.cancelAction = cancelAction;
|
|
25502
|
+
this.alignNodes(alignTo);
|
|
25503
|
+
}
|
|
25504
|
+
cleanup() {
|
|
25505
|
+
if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
|
|
25506
|
+
this.setState(ALIGN_NODES_TOOL_STATE.IDLE);
|
|
25507
|
+
}
|
|
25508
|
+
};
|
|
25509
|
+
|
|
25048
25510
|
//#endregion
|
|
25049
25511
|
//#region src/plugins/stage-grid/constants.ts
|
|
25050
25512
|
const WEAVE_STAGE_GRID_KEY = "stageGrid";
|
|
@@ -25054,8 +25516,8 @@ const WEAVE_GRID_TYPES = {
|
|
|
25054
25516
|
};
|
|
25055
25517
|
const WEAVE_GRID_DEFAULT_SIZE = 50;
|
|
25056
25518
|
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.
|
|
25519
|
+
const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.1)";
|
|
25520
|
+
const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.1)";
|
|
25059
25521
|
const WEAVE_GRID_DEFAULT_STROKE = .5;
|
|
25060
25522
|
const WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = 4;
|
|
25061
25523
|
const WEAVE_GRID_DEFAULT_RADIUS = 1;
|
|
@@ -26269,6 +26731,9 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26269
26731
|
};
|
|
26270
26732
|
|
|
26271
26733
|
//#endregion
|
|
26734
|
+
exports.ALIGN_NODES_ALIGN_TO = ALIGN_NODES_ALIGN_TO
|
|
26735
|
+
exports.ALIGN_NODES_TOOL_ACTION_NAME = ALIGN_NODES_TOOL_ACTION_NAME
|
|
26736
|
+
exports.ALIGN_NODES_TOOL_STATE = ALIGN_NODES_TOOL_STATE
|
|
26272
26737
|
exports.ARROW_TOOL_ACTION_NAME = ARROW_TOOL_ACTION_NAME
|
|
26273
26738
|
exports.ARROW_TOOL_STATE = ARROW_TOOL_STATE
|
|
26274
26739
|
exports.BRUSH_TOOL_ACTION_NAME = BRUSH_TOOL_ACTION_NAME
|
|
@@ -26342,6 +26807,7 @@ exports.WEAVE_USER_POINTER_KEY = WEAVE_USER_POINTER_KEY
|
|
|
26342
26807
|
exports.WEAVE_USER_SELECTION_KEY = WEAVE_USER_SELECTION_KEY
|
|
26343
26808
|
exports.Weave = Weave
|
|
26344
26809
|
exports.WeaveAction = WeaveAction
|
|
26810
|
+
exports.WeaveAlignNodesToolAction = WeaveAlignNodesToolAction
|
|
26345
26811
|
exports.WeaveArrowNode = WeaveArrowNode
|
|
26346
26812
|
exports.WeaveArrowToolAction = WeaveArrowToolAction
|
|
26347
26813
|
exports.WeaveBrushToolAction = WeaveBrushToolAction
|