@inditextech/weave-sdk 0.37.0 → 0.39.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 +1332 -771
- package/dist/sdk.d.cts +282 -166
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +282 -166
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1329 -772
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -29,6 +29,7 @@ require("konva/lib/types");
|
|
|
29
29
|
const __inditextech_weave_types = __toESM(require("@inditextech/weave-types"));
|
|
30
30
|
const __syncedstore_core = __toESM(require("@syncedstore/core"));
|
|
31
31
|
const yjs = __toESM(require("yjs"));
|
|
32
|
+
const konva_lib_shapes_Transformer = __toESM(require("konva/lib/shapes/Transformer"));
|
|
32
33
|
const react = __toESM(require("react"));
|
|
33
34
|
const react_reconciler = __toESM(require("react-reconciler"));
|
|
34
35
|
|
|
@@ -15648,6 +15649,132 @@ const WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT = 4;
|
|
|
15648
15649
|
const WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT = 4;
|
|
15649
15650
|
const WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT = 500;
|
|
15650
15651
|
|
|
15652
|
+
//#endregion
|
|
15653
|
+
//#region src/utils.ts
|
|
15654
|
+
function resetScale(node) {
|
|
15655
|
+
node.width(Math.round((Math.max(1, node.width() * node.scaleX()) + Number.EPSILON) * 100) / 100);
|
|
15656
|
+
node.height(Math.round((Math.max(1, node.height() * node.scaleY()) + Number.EPSILON) * 100) / 100);
|
|
15657
|
+
node.scaleX(1);
|
|
15658
|
+
node.scaleY(1);
|
|
15659
|
+
node.x(Math.round((node.x() + Number.EPSILON) * 100) / 100);
|
|
15660
|
+
node.y(Math.round((node.y() + Number.EPSILON) * 100) / 100);
|
|
15661
|
+
node.rotation(Math.round((node.rotation() + Number.EPSILON) * 100) / 100);
|
|
15662
|
+
}
|
|
15663
|
+
function clearContainerTargets(instance) {
|
|
15664
|
+
const containers = instance.getContainerNodes();
|
|
15665
|
+
for (const container of containers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
|
|
15666
|
+
}
|
|
15667
|
+
function checkIfOverContainer(instance, node) {
|
|
15668
|
+
if (node instanceof konva.default.Transformer) {
|
|
15669
|
+
const transformerNodes = node.nodes();
|
|
15670
|
+
const containersInSelection = [];
|
|
15671
|
+
for (const actualNode of transformerNodes) if (typeof actualNode.getAttrs().isContainerPrincipal !== "undefined" && actualNode.getAttrs().isContainerPrincipal) containersInSelection.push(actualNode);
|
|
15672
|
+
const containersInSelectionSet = new Set(containersInSelection);
|
|
15673
|
+
const uniqueContainersInSelection = Array.from(containersInSelectionSet);
|
|
15674
|
+
if (uniqueContainersInSelection.length > 0) return void 0;
|
|
15675
|
+
}
|
|
15676
|
+
const intersectedNode = instance.nodeIntersectsContainerElement(node);
|
|
15677
|
+
let nodeActualContainer = node.getParent();
|
|
15678
|
+
if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
|
|
15679
|
+
let layerToMove = void 0;
|
|
15680
|
+
if (!node.getAttrs().containerId && intersectedNode && nodeActualContainer?.getAttrs().id !== intersectedNode.getAttrs().id) layerToMove = intersectedNode;
|
|
15681
|
+
return layerToMove;
|
|
15682
|
+
}
|
|
15683
|
+
function moveNodeToContainer(instance, node) {
|
|
15684
|
+
const stage = instance.getStage();
|
|
15685
|
+
const nodeIntersected = instance.nodeIntersectsContainerElement(node);
|
|
15686
|
+
const isLocked = instance.allNodesLocked([node]);
|
|
15687
|
+
if (isLocked) return;
|
|
15688
|
+
let nodeActualContainer = node.getParent();
|
|
15689
|
+
if (nodeActualContainer.getAttrs().nodeId) {
|
|
15690
|
+
const realParent = stage.findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
|
|
15691
|
+
if (realParent) nodeActualContainer = realParent;
|
|
15692
|
+
}
|
|
15693
|
+
if (!nodeActualContainer) return void 0;
|
|
15694
|
+
const actualContainerAttrs = nodeActualContainer.getAttrs();
|
|
15695
|
+
let layerToMove = void 0;
|
|
15696
|
+
if (nodeIntersected && actualContainerAttrs.id !== nodeIntersected.getAttrs().id && !node.getAttrs().isContainerPrincipal) layerToMove = nodeIntersected;
|
|
15697
|
+
if (!nodeIntersected && actualContainerAttrs.id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
|
|
15698
|
+
if (layerToMove && actualContainerAttrs.id !== layerToMove.getAttrs().id && actualContainerAttrs.id !== layerToMove.getAttrs().containerId) {
|
|
15699
|
+
const layerToMoveAttrs = layerToMove.getAttrs();
|
|
15700
|
+
const nodePos = node.getAbsolutePosition();
|
|
15701
|
+
const nodeRotation = node.getAbsoluteRotation();
|
|
15702
|
+
node.moveTo(layerToMove);
|
|
15703
|
+
node.setAbsolutePosition(nodePos);
|
|
15704
|
+
node.rotation(nodeRotation);
|
|
15705
|
+
node.x(node.x() - (layerToMoveAttrs.containerOffsetX ?? 0));
|
|
15706
|
+
node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
|
|
15707
|
+
node.movedToContainer(layerToMove);
|
|
15708
|
+
const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15709
|
+
if (nodeHandler) {
|
|
15710
|
+
const actualNode = nodeHandler.serialize(node);
|
|
15711
|
+
instance.removeNode(actualNode);
|
|
15712
|
+
instance.addNode(actualNode, layerToMoveAttrs.id);
|
|
15713
|
+
return layerToMove;
|
|
15714
|
+
}
|
|
15715
|
+
}
|
|
15716
|
+
return void 0;
|
|
15717
|
+
}
|
|
15718
|
+
function getContrastTextColor(hex) {
|
|
15719
|
+
const cleaned = hex.replace(/^#/, "");
|
|
15720
|
+
const r = parseInt(cleaned.slice(0, 2), 16);
|
|
15721
|
+
const g = parseInt(cleaned.slice(2, 4), 16);
|
|
15722
|
+
const b = parseInt(cleaned.slice(4, 6), 16);
|
|
15723
|
+
const luminance = (.299 * r + .587 * g + .114 * b) / 255;
|
|
15724
|
+
return luminance > .5 ? "black" : "white";
|
|
15725
|
+
}
|
|
15726
|
+
function stringToColor(str) {
|
|
15727
|
+
let hash = 0;
|
|
15728
|
+
str.split("").forEach((char) => {
|
|
15729
|
+
hash = char.charCodeAt(0) + ((hash << 5) - hash);
|
|
15730
|
+
});
|
|
15731
|
+
let color = "#";
|
|
15732
|
+
for (let i = 0; i < 3; i++) {
|
|
15733
|
+
const value = hash >> i * 8 & 255;
|
|
15734
|
+
color += value.toString(16).padStart(2, "0");
|
|
15735
|
+
}
|
|
15736
|
+
return color;
|
|
15737
|
+
}
|
|
15738
|
+
function getBoundingBox(stage, nodes) {
|
|
15739
|
+
if (nodes.length === 0) return {
|
|
15740
|
+
x: 0,
|
|
15741
|
+
y: 0,
|
|
15742
|
+
width: 0,
|
|
15743
|
+
height: 0
|
|
15744
|
+
};
|
|
15745
|
+
let minX = Infinity;
|
|
15746
|
+
let minY = Infinity;
|
|
15747
|
+
let maxX = -Infinity;
|
|
15748
|
+
let maxY = -Infinity;
|
|
15749
|
+
for (const node of nodes) {
|
|
15750
|
+
const box = node.getRealClientRect({ skipTransform: false });
|
|
15751
|
+
minX = Math.min(minX, box.x);
|
|
15752
|
+
minY = Math.min(minY, box.y);
|
|
15753
|
+
maxX = Math.max(maxX, box.x + box.width);
|
|
15754
|
+
maxY = Math.max(maxY, box.y + box.height);
|
|
15755
|
+
}
|
|
15756
|
+
return {
|
|
15757
|
+
x: minX,
|
|
15758
|
+
y: minY,
|
|
15759
|
+
width: maxX - minX,
|
|
15760
|
+
height: maxY - minY
|
|
15761
|
+
};
|
|
15762
|
+
}
|
|
15763
|
+
function getTargetedNode(instance) {
|
|
15764
|
+
const stage = instance.getStage();
|
|
15765
|
+
let selectedGroup = void 0;
|
|
15766
|
+
const mousePos = stage.getPointerPosition();
|
|
15767
|
+
if (mousePos) {
|
|
15768
|
+
const allInter = stage.getAllIntersections(mousePos);
|
|
15769
|
+
if (allInter.length === 1) selectedGroup = instance.getInstanceRecursive(allInter[0]);
|
|
15770
|
+
else {
|
|
15771
|
+
const allInterContainersFiltered = allInter.filter((ele) => typeof ele.getAttrs().containerElement === "undefined");
|
|
15772
|
+
if (allInterContainersFiltered.length > 0) selectedGroup = instance.getInstanceRecursive(allInterContainersFiltered[0]);
|
|
15773
|
+
}
|
|
15774
|
+
}
|
|
15775
|
+
return selectedGroup;
|
|
15776
|
+
}
|
|
15777
|
+
|
|
15651
15778
|
//#endregion
|
|
15652
15779
|
//#region src/plugins/context-menu/context-menu.ts
|
|
15653
15780
|
var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
@@ -15655,9 +15782,14 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15655
15782
|
initLayer = void 0;
|
|
15656
15783
|
constructor(params) {
|
|
15657
15784
|
super();
|
|
15658
|
-
this.
|
|
15785
|
+
this.timer = null;
|
|
15659
15786
|
this.tapHold = false;
|
|
15660
15787
|
this.contextMenuVisible = false;
|
|
15788
|
+
this.tapStart = {
|
|
15789
|
+
x: 0,
|
|
15790
|
+
y: 0,
|
|
15791
|
+
time: 0
|
|
15792
|
+
};
|
|
15661
15793
|
this.tapHoldTimeout = WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT;
|
|
15662
15794
|
const { config } = params ?? {};
|
|
15663
15795
|
this.config = {
|
|
@@ -15673,34 +15805,40 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15673
15805
|
onInit() {
|
|
15674
15806
|
this.initEvents();
|
|
15675
15807
|
}
|
|
15676
|
-
|
|
15808
|
+
isPressed(e) {
|
|
15809
|
+
return e.evt.buttons > 0;
|
|
15810
|
+
}
|
|
15811
|
+
setTapStart(e) {
|
|
15812
|
+
this.tapStart = {
|
|
15813
|
+
x: e.evt.clientX,
|
|
15814
|
+
y: e.evt.clientY,
|
|
15815
|
+
time: performance.now()
|
|
15816
|
+
};
|
|
15817
|
+
}
|
|
15818
|
+
triggerContextMenu(eventTarget, target) {
|
|
15677
15819
|
const stage = this.instance.getStage();
|
|
15678
|
-
const selectionPlugin = this.
|
|
15679
|
-
let clickOnTransformer = false;
|
|
15680
|
-
if (selectionPlugin) {
|
|
15681
|
-
const transformer = selectionPlugin.getTransformer();
|
|
15682
|
-
const box = transformer.getClientRect();
|
|
15683
|
-
const mousePos = stage.getPointerPosition();
|
|
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
|
-
}
|
|
15820
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
15686
15821
|
let nodes = [];
|
|
15687
|
-
if (target
|
|
15688
|
-
const transformer = selectionPlugin.getTransformer();
|
|
15689
|
-
nodes = transformer.getNodes().map((node) => {
|
|
15690
|
-
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15691
|
-
return {
|
|
15692
|
-
instance: node,
|
|
15693
|
-
node: nodeHandler?.serialize(node)
|
|
15694
|
-
};
|
|
15695
|
-
}).filter((node) => typeof node !== "undefined");
|
|
15696
|
-
}
|
|
15697
|
-
if (target !== stage && !clickOnTransformer) {
|
|
15822
|
+
if (target && target !== stage) {
|
|
15698
15823
|
const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
|
|
15699
15824
|
nodes = [{
|
|
15700
15825
|
instance: target,
|
|
15701
15826
|
node: nodeHandler?.serialize(target)
|
|
15702
15827
|
}];
|
|
15703
15828
|
}
|
|
15829
|
+
const eventTargetParent = eventTarget.getParent();
|
|
15830
|
+
if (eventTargetParent instanceof konva.default.Transformer) nodes = eventTargetParent.nodes().map((node) => {
|
|
15831
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15832
|
+
return {
|
|
15833
|
+
instance: node,
|
|
15834
|
+
node: nodeHandler?.serialize(node)
|
|
15835
|
+
};
|
|
15836
|
+
});
|
|
15837
|
+
if (this.contextMenuVisible) this.closeContextMenu();
|
|
15838
|
+
if (selectionPlugin && !(eventTarget.getParent() instanceof konva_lib_shapes_Transformer.Transformer && selectionPlugin.getSelectedNodes().length > 0)) {
|
|
15839
|
+
selectionPlugin.setSelectedNodes([...nodes.map((node) => node.instance)]);
|
|
15840
|
+
selectionPlugin.getHoverTransformer().nodes([]);
|
|
15841
|
+
}
|
|
15704
15842
|
const containerRect = stage.container().getBoundingClientRect();
|
|
15705
15843
|
const pointerPos = stage.getPointerPosition();
|
|
15706
15844
|
if (containerRect && pointerPos) {
|
|
@@ -15727,46 +15865,49 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15727
15865
|
visible: false
|
|
15728
15866
|
});
|
|
15729
15867
|
}
|
|
15868
|
+
getSelectionPlugin() {
|
|
15869
|
+
const selectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
|
|
15870
|
+
return selectionPlugin;
|
|
15871
|
+
}
|
|
15872
|
+
cancelLongPressTimer() {
|
|
15873
|
+
if (this.timer) {
|
|
15874
|
+
clearTimeout(this.timer);
|
|
15875
|
+
this.timer = null;
|
|
15876
|
+
}
|
|
15877
|
+
}
|
|
15730
15878
|
initEvents() {
|
|
15731
15879
|
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
|
-
});
|
|
15740
15880
|
stage.on("pointerdown", (e) => {
|
|
15881
|
+
this.setTapStart(e);
|
|
15741
15882
|
this.pointers[e.evt.pointerId] = e.evt;
|
|
15883
|
+
if (e.evt.buttons === 0) return;
|
|
15742
15884
|
if (e.evt.pointerType === "mouse") return;
|
|
15743
15885
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
15744
|
-
this.
|
|
15886
|
+
if (this.timer) return;
|
|
15887
|
+
this.timer = setTimeout(() => {
|
|
15745
15888
|
this.tapHold = true;
|
|
15746
|
-
|
|
15747
|
-
|
|
15748
|
-
|
|
15749
|
-
|
|
15750
|
-
this.triggerContextMenu(e.target);
|
|
15889
|
+
const actualActions = this.instance.getActiveAction();
|
|
15890
|
+
if (actualActions !== "selectionTool") return;
|
|
15891
|
+
delete this.pointers[e.evt.pointerId];
|
|
15892
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
15893
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
15751
15894
|
}, this.tapHoldTimeout);
|
|
15752
15895
|
});
|
|
15753
|
-
stage.on("pointermove", (e) => {
|
|
15754
|
-
if (e.evt.pointerType === "mouse") return;
|
|
15755
|
-
if (this.touchTimer) clearTimeout(this.touchTimer);
|
|
15756
|
-
});
|
|
15757
15896
|
stage.on("pointerup", (e) => {
|
|
15758
15897
|
delete this.pointers[e.evt.pointerId];
|
|
15759
15898
|
if (e.evt.pointerType === "mouse") return;
|
|
15760
15899
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
15761
|
-
if (this.
|
|
15762
|
-
clearTimeout(this.
|
|
15900
|
+
if (this.timer) {
|
|
15901
|
+
clearTimeout(this.timer);
|
|
15902
|
+
this.timer = null;
|
|
15763
15903
|
this.tapHold = false;
|
|
15764
15904
|
}
|
|
15765
15905
|
});
|
|
15766
15906
|
stage.on("contextmenu", (e) => {
|
|
15767
15907
|
e.evt.preventDefault();
|
|
15768
15908
|
if (!this.enabled) return;
|
|
15769
|
-
this.
|
|
15909
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
15910
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
15770
15911
|
});
|
|
15771
15912
|
this.instance.addEventListener("onStageSelection", () => {
|
|
15772
15913
|
if (this.tapHold) return;
|
|
@@ -15799,115 +15940,19 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15799
15940
|
}
|
|
15800
15941
|
};
|
|
15801
15942
|
|
|
15802
|
-
//#endregion
|
|
15803
|
-
//#region src/utils.ts
|
|
15804
|
-
function resetScale(node) {
|
|
15805
|
-
node.width(Math.round((Math.max(1, node.width() * node.scaleX()) + Number.EPSILON) * 100) / 100);
|
|
15806
|
-
node.height(Math.round((Math.max(1, node.height() * node.scaleY()) + Number.EPSILON) * 100) / 100);
|
|
15807
|
-
node.scaleX(1);
|
|
15808
|
-
node.scaleY(1);
|
|
15809
|
-
node.x(Math.round((node.x() + Number.EPSILON) * 100) / 100);
|
|
15810
|
-
node.y(Math.round((node.y() + Number.EPSILON) * 100) / 100);
|
|
15811
|
-
node.rotation(Math.round((node.rotation() + Number.EPSILON) * 100) / 100);
|
|
15812
|
-
}
|
|
15813
|
-
function clearContainerTargets(instance) {
|
|
15814
|
-
const getContainers = instance.getContainerNodes();
|
|
15815
|
-
for (const container of getContainers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
|
|
15816
|
-
}
|
|
15817
|
-
function checkIfOverContainer(instance, node) {
|
|
15818
|
-
const nodesIntersected = instance.pointIntersectsContainerElement(node.getParent());
|
|
15819
|
-
let nodeActualContainer = node.getParent();
|
|
15820
|
-
if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
|
|
15821
|
-
let layerToMove = void 0;
|
|
15822
|
-
if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
|
|
15823
|
-
return layerToMove;
|
|
15824
|
-
}
|
|
15825
|
-
function moveNodeToContainer(instance, node) {
|
|
15826
|
-
const nodeIntersected = instance.pointIntersectsContainerElement();
|
|
15827
|
-
const isLocked = instance.allNodesLocked([node]);
|
|
15828
|
-
if (isLocked) return;
|
|
15829
|
-
let nodeActualContainer = node.getParent();
|
|
15830
|
-
if (!nodeActualContainer) return void 0;
|
|
15831
|
-
const actualContainerAttrs = nodeActualContainer.getAttrs();
|
|
15832
|
-
const nodeAttrs = node.getAttrs();
|
|
15833
|
-
if (actualContainerAttrs.nodeId) nodeActualContainer = instance.getStage().findOne(`#${actualContainerAttrs.nodeId}`);
|
|
15834
|
-
let layerToMove = void 0;
|
|
15835
|
-
if (!nodeAttrs.containerId && nodeIntersected && actualContainerAttrs.id !== nodeIntersected.getAttrs().id) layerToMove = nodeIntersected;
|
|
15836
|
-
if (!nodeIntersected && actualContainerAttrs.id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
|
|
15837
|
-
if (layerToMove && actualContainerAttrs.id !== layerToMove.getAttrs().id && actualContainerAttrs.id !== layerToMove.getAttrs().containerId) {
|
|
15838
|
-
const layerToMoveAttrs = layerToMove.getAttrs();
|
|
15839
|
-
const nodePos = node.getAbsolutePosition();
|
|
15840
|
-
const nodeRotation = node.getAbsoluteRotation();
|
|
15841
|
-
node.moveTo(layerToMove);
|
|
15842
|
-
node.setAbsolutePosition(nodePos);
|
|
15843
|
-
node.rotation(nodeRotation);
|
|
15844
|
-
node.x(node.x() - (layerToMoveAttrs.containerOffsetX ?? 0));
|
|
15845
|
-
node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
|
|
15846
|
-
node.movedToContainer(layerToMove);
|
|
15847
|
-
const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15848
|
-
if (nodeHandler) {
|
|
15849
|
-
const actualNode = nodeHandler.serialize(node);
|
|
15850
|
-
instance.removeNode(actualNode);
|
|
15851
|
-
instance.addNode(actualNode, layerToMoveAttrs.id);
|
|
15852
|
-
return layerToMove;
|
|
15853
|
-
}
|
|
15854
|
-
}
|
|
15855
|
-
return void 0;
|
|
15856
|
-
}
|
|
15857
|
-
function getContrastTextColor(hex) {
|
|
15858
|
-
const cleaned = hex.replace(/^#/, "");
|
|
15859
|
-
const r = parseInt(cleaned.slice(0, 2), 16);
|
|
15860
|
-
const g = parseInt(cleaned.slice(2, 4), 16);
|
|
15861
|
-
const b = parseInt(cleaned.slice(4, 6), 16);
|
|
15862
|
-
const luminance = (.299 * r + .587 * g + .114 * b) / 255;
|
|
15863
|
-
return luminance > .5 ? "black" : "white";
|
|
15864
|
-
}
|
|
15865
|
-
function stringToColor(str) {
|
|
15866
|
-
let hash = 0;
|
|
15867
|
-
str.split("").forEach((char) => {
|
|
15868
|
-
hash = char.charCodeAt(0) + ((hash << 5) - hash);
|
|
15869
|
-
});
|
|
15870
|
-
let color = "#";
|
|
15871
|
-
for (let i = 0; i < 3; i++) {
|
|
15872
|
-
const value = hash >> i * 8 & 255;
|
|
15873
|
-
color += value.toString(16).padStart(2, "0");
|
|
15874
|
-
}
|
|
15875
|
-
return color;
|
|
15876
|
-
}
|
|
15877
|
-
function getBoundingBox(stage, nodes) {
|
|
15878
|
-
if (nodes.length === 0) return {
|
|
15879
|
-
x: 0,
|
|
15880
|
-
y: 0,
|
|
15881
|
-
width: 0,
|
|
15882
|
-
height: 0
|
|
15883
|
-
};
|
|
15884
|
-
let minX = Infinity;
|
|
15885
|
-
let minY = Infinity;
|
|
15886
|
-
let maxX = -Infinity;
|
|
15887
|
-
let maxY = -Infinity;
|
|
15888
|
-
for (const node of nodes) {
|
|
15889
|
-
let realNode = node;
|
|
15890
|
-
if (realNode.getAttrs().containerId) realNode = stage.findOne(`#${realNode.getAttrs().containerId}`);
|
|
15891
|
-
if (!realNode) continue;
|
|
15892
|
-
const box = node.getRealClientRect({ skipTransform: false });
|
|
15893
|
-
minX = Math.min(minX, box.x);
|
|
15894
|
-
minY = Math.min(minY, box.y);
|
|
15895
|
-
maxX = Math.max(maxX, box.x + box.width);
|
|
15896
|
-
maxY = Math.max(maxY, box.y + box.height);
|
|
15897
|
-
}
|
|
15898
|
-
return {
|
|
15899
|
-
x: minX,
|
|
15900
|
-
y: minY,
|
|
15901
|
-
width: maxX - minX,
|
|
15902
|
-
height: maxY - minY
|
|
15903
|
-
};
|
|
15904
|
-
}
|
|
15905
|
-
|
|
15906
15943
|
//#endregion
|
|
15907
15944
|
//#region src/plugins/users-selection/constants.ts
|
|
15908
15945
|
const WEAVE_USERS_SELECTION_KEY = "usersSelection";
|
|
15909
15946
|
const WEAVE_USER_SELECTION_KEY = "userSelection";
|
|
15910
15947
|
|
|
15948
|
+
//#endregion
|
|
15949
|
+
//#region src/nodes/stage/constants.ts
|
|
15950
|
+
const WEAVE_STAGE_NODE_TYPE = "stage";
|
|
15951
|
+
const WEAVE_STAGE_MODE = {
|
|
15952
|
+
["normal"]: "normal",
|
|
15953
|
+
["cropping"]: "cropping"
|
|
15954
|
+
};
|
|
15955
|
+
|
|
15911
15956
|
//#endregion
|
|
15912
15957
|
//#region src/plugins/nodes-selection/nodes-selection.ts
|
|
15913
15958
|
var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
@@ -15933,16 +15978,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15933
15978
|
keepRatio: false,
|
|
15934
15979
|
useSingleNodeRotation: true,
|
|
15935
15980
|
shouldOverdrawWholeArea: true,
|
|
15936
|
-
enabledAnchors: [
|
|
15937
|
-
"top-left",
|
|
15938
|
-
"top-center",
|
|
15939
|
-
"top-right",
|
|
15940
|
-
"middle-right",
|
|
15941
|
-
"middle-left",
|
|
15942
|
-
"bottom-left",
|
|
15943
|
-
"bottom-center",
|
|
15944
|
-
"bottom-right"
|
|
15945
|
-
],
|
|
15946
15981
|
anchorStyleFunc: (anchor) => {
|
|
15947
15982
|
anchor.stroke("#27272aff");
|
|
15948
15983
|
anchor.cornerRadius(12);
|
|
@@ -15960,6 +15995,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15960
15995
|
}
|
|
15961
15996
|
},
|
|
15962
15997
|
borderStroke: "#0074ffcc",
|
|
15998
|
+
borderStrokeWidth: 3,
|
|
15963
15999
|
...config?.transformer
|
|
15964
16000
|
},
|
|
15965
16001
|
transformations: {
|
|
@@ -15978,10 +16014,17 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15978
16014
|
"bottom-center",
|
|
15979
16015
|
"bottom-right"
|
|
15980
16016
|
];
|
|
16017
|
+
this.taps = 0;
|
|
16018
|
+
this.isDoubleTap = false;
|
|
16019
|
+
this.tapStart = {
|
|
16020
|
+
x: 0,
|
|
16021
|
+
y: 0,
|
|
16022
|
+
time: 0
|
|
16023
|
+
};
|
|
16024
|
+
this.lastTapTime = 0;
|
|
15981
16025
|
this.active = false;
|
|
15982
|
-
this.
|
|
16026
|
+
this.didMove = false;
|
|
15983
16027
|
this.selecting = false;
|
|
15984
|
-
this.dragging = false;
|
|
15985
16028
|
this.initialized = false;
|
|
15986
16029
|
this.enabled = false;
|
|
15987
16030
|
this.pointers = {};
|
|
@@ -16032,73 +16075,105 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16032
16075
|
...this.config.transformer
|
|
16033
16076
|
});
|
|
16034
16077
|
selectionLayer?.add(tr);
|
|
16078
|
+
const trHover = new konva.default.Transformer({
|
|
16079
|
+
id: "hoverTransformer",
|
|
16080
|
+
...this.config.transformer,
|
|
16081
|
+
borderStrokeWidth: 3,
|
|
16082
|
+
rotateEnabled: false,
|
|
16083
|
+
resizeEnabled: false,
|
|
16084
|
+
enabledAnchors: [],
|
|
16085
|
+
listening: false
|
|
16086
|
+
});
|
|
16087
|
+
selectionLayer?.add(trHover);
|
|
16035
16088
|
tr.on("transformstart", () => {
|
|
16036
16089
|
this.triggerSelectedNodesEvent();
|
|
16037
16090
|
});
|
|
16038
|
-
const handleTransform = () => {
|
|
16091
|
+
const handleTransform = (e) => {
|
|
16092
|
+
const moved = this.checkMoved(e);
|
|
16093
|
+
if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
16039
16094
|
this.triggerSelectedNodesEvent();
|
|
16040
16095
|
};
|
|
16041
16096
|
tr.on("transform", (0, import_lodash.throttle)(handleTransform, 50));
|
|
16042
16097
|
tr.on("transformend", () => {
|
|
16043
16098
|
this.triggerSelectedNodesEvent();
|
|
16044
16099
|
});
|
|
16100
|
+
let initialPos = null;
|
|
16045
16101
|
tr.on("dragstart", (e) => {
|
|
16046
|
-
|
|
16102
|
+
initialPos = {
|
|
16103
|
+
x: e.target.x(),
|
|
16104
|
+
y: e.target.y()
|
|
16105
|
+
};
|
|
16106
|
+
this.didMove = false;
|
|
16047
16107
|
const stage$1 = this.instance.getStage();
|
|
16048
16108
|
if (stage$1.isMouseWheelPressed()) {
|
|
16049
16109
|
e.cancelBubble = true;
|
|
16050
16110
|
e.target.stopDrag();
|
|
16051
16111
|
return;
|
|
16052
16112
|
}
|
|
16113
|
+
e.cancelBubble = true;
|
|
16053
16114
|
const selectedNodes = tr.nodes();
|
|
16054
16115
|
for (let i = 0; i < selectedNodes.length; i++) {
|
|
16055
16116
|
const node = selectedNodes[i];
|
|
16056
|
-
node.updatePosition(
|
|
16117
|
+
node.updatePosition(node.getAbsolutePosition());
|
|
16057
16118
|
}
|
|
16058
16119
|
tr.forceUpdate();
|
|
16059
|
-
e.cancelBubble = true;
|
|
16060
16120
|
});
|
|
16061
16121
|
const handleDragMove = (e) => {
|
|
16122
|
+
const actualPos = {
|
|
16123
|
+
x: e.target.x(),
|
|
16124
|
+
y: e.target.y()
|
|
16125
|
+
};
|
|
16126
|
+
if (initialPos) {
|
|
16127
|
+
const moved = this.checkMovedDrag(initialPos, actualPos);
|
|
16128
|
+
if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
16129
|
+
}
|
|
16062
16130
|
const stage$1 = this.instance.getStage();
|
|
16063
16131
|
if (stage$1.isMouseWheelPressed()) {
|
|
16064
16132
|
e.cancelBubble = true;
|
|
16065
16133
|
e.target.stopDrag();
|
|
16066
16134
|
return;
|
|
16067
16135
|
}
|
|
16136
|
+
this.didMove = true;
|
|
16137
|
+
e.cancelBubble = true;
|
|
16068
16138
|
const selectedNodes = tr.nodes();
|
|
16139
|
+
let hasFrames = false;
|
|
16069
16140
|
for (let i = 0; i < selectedNodes.length; i++) {
|
|
16070
16141
|
const node = selectedNodes[i];
|
|
16071
|
-
node.
|
|
16142
|
+
if (node.getAttrs().nodeType === "frame") hasFrames = hasFrames || true;
|
|
16143
|
+
node.updatePosition(node.getAbsolutePosition());
|
|
16072
16144
|
}
|
|
16073
|
-
e.cancelBubble = true;
|
|
16074
16145
|
if (this.isSelecting() && selectedNodes.length > 1) {
|
|
16075
16146
|
clearContainerTargets(this.instance);
|
|
16076
16147
|
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16077
|
-
if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
16148
|
+
if (layerToMove && !hasFrames) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
16078
16149
|
}
|
|
16079
16150
|
tr.forceUpdate();
|
|
16080
16151
|
};
|
|
16081
|
-
tr.on("dragmove",
|
|
16152
|
+
tr.on("dragmove", handleDragMove);
|
|
16082
16153
|
tr.on("dragend", (e) => {
|
|
16083
|
-
this.
|
|
16154
|
+
if (!this.didMove) return;
|
|
16084
16155
|
e.cancelBubble = true;
|
|
16085
16156
|
const selectedNodes = tr.nodes();
|
|
16157
|
+
let hasFrames = false;
|
|
16086
16158
|
for (let i = 0; i < selectedNodes.length; i++) {
|
|
16087
16159
|
const node = selectedNodes[i];
|
|
16088
|
-
node.
|
|
16160
|
+
if (node.getAttrs().nodeType === "frame") hasFrames = hasFrames || true;
|
|
16161
|
+
node.updatePosition(node.getAbsolutePosition());
|
|
16089
16162
|
}
|
|
16090
16163
|
if (this.isSelecting() && tr.nodes().length > 1) {
|
|
16091
16164
|
const actualCursor = stage.container().style.cursor;
|
|
16092
16165
|
stage.container().style.cursor = "wait";
|
|
16093
16166
|
clearContainerTargets(this.instance);
|
|
16167
|
+
const toSelect = [];
|
|
16094
16168
|
const toUpdate = [];
|
|
16095
16169
|
const nodeUpdatePromise = (node) => {
|
|
16096
16170
|
return new Promise((resolve) => {
|
|
16097
16171
|
setTimeout(() => {
|
|
16098
|
-
|
|
16099
|
-
if (
|
|
16172
|
+
clearContainerTargets(this.instance);
|
|
16173
|
+
if (!hasFrames) moveNodeToContainer(this.instance, node);
|
|
16100
16174
|
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
16101
16175
|
if (!nodeHandler) return resolve();
|
|
16176
|
+
toSelect.push(node.getAttrs().id ?? "");
|
|
16102
16177
|
toUpdate.push(nodeHandler.serialize(node));
|
|
16103
16178
|
resolve();
|
|
16104
16179
|
}, 0);
|
|
@@ -16110,18 +16185,21 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16110
16185
|
if (results.length > 0) this.instance.updateNodes(toUpdate);
|
|
16111
16186
|
stage.container().style.cursor = actualCursor;
|
|
16112
16187
|
});
|
|
16188
|
+
setTimeout(() => {
|
|
16189
|
+
const finalSelectedNodes = [];
|
|
16190
|
+
toSelect.forEach((nodeId) => {
|
|
16191
|
+
const actNode = this.instance.getStage().findOne(`#${nodeId}`);
|
|
16192
|
+
if (actNode) finalSelectedNodes.push(actNode);
|
|
16193
|
+
});
|
|
16194
|
+
tr.nodes(finalSelectedNodes);
|
|
16195
|
+
tr.forceUpdate();
|
|
16196
|
+
}, 0);
|
|
16113
16197
|
}
|
|
16114
16198
|
tr.forceUpdate();
|
|
16115
16199
|
});
|
|
16116
16200
|
this.tr = tr;
|
|
16201
|
+
this.trHover = trHover;
|
|
16117
16202
|
this.selectionRectangle = selectionRectangle;
|
|
16118
|
-
this.tr.on("pointerdblclick", (e) => {
|
|
16119
|
-
e.cancelBubble = true;
|
|
16120
|
-
if (this.tr.getNodes().length === 1) {
|
|
16121
|
-
const node = this.tr.getNodes()[0];
|
|
16122
|
-
node.fire("pointerdblclick");
|
|
16123
|
-
}
|
|
16124
|
-
});
|
|
16125
16203
|
this.initEvents();
|
|
16126
16204
|
this.initialized = true;
|
|
16127
16205
|
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
@@ -16173,6 +16251,63 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16173
16251
|
this.tr.nodes([]);
|
|
16174
16252
|
this.triggerSelectedNodesEvent();
|
|
16175
16253
|
}
|
|
16254
|
+
setTapStart(e) {
|
|
16255
|
+
this.tapStart = {
|
|
16256
|
+
x: e.evt.clientX,
|
|
16257
|
+
y: e.evt.clientY,
|
|
16258
|
+
time: performance.now()
|
|
16259
|
+
};
|
|
16260
|
+
}
|
|
16261
|
+
checkMovedDrag(init, actual) {
|
|
16262
|
+
if (!this.tapStart) return false;
|
|
16263
|
+
const dx = actual.x - init.x;
|
|
16264
|
+
const dy = actual.y - init.y;
|
|
16265
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
16266
|
+
const MOVED_DISTANCE = 5;
|
|
16267
|
+
if (dist <= MOVED_DISTANCE) return false;
|
|
16268
|
+
return true;
|
|
16269
|
+
}
|
|
16270
|
+
checkMoved(e) {
|
|
16271
|
+
if (!this.tapStart) return false;
|
|
16272
|
+
const dx = e.evt.clientX - this.tapStart.x;
|
|
16273
|
+
const dy = e.evt.clientY - this.tapStart.y;
|
|
16274
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
16275
|
+
const MOVED_DISTANCE = 5;
|
|
16276
|
+
if (dist <= MOVED_DISTANCE) return false;
|
|
16277
|
+
return true;
|
|
16278
|
+
}
|
|
16279
|
+
checkDoubleTap(e) {
|
|
16280
|
+
if (!this.tapStart) return;
|
|
16281
|
+
const now = performance.now();
|
|
16282
|
+
const dx = e.evt.clientX - this.tapStart.x;
|
|
16283
|
+
const dy = e.evt.clientY - this.tapStart.y;
|
|
16284
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
16285
|
+
const DOUBLE_TAP_DISTANCE = 10;
|
|
16286
|
+
const DOUBLE_TAP_TIME = 300;
|
|
16287
|
+
this.isDoubleTap = false;
|
|
16288
|
+
if (this.taps >= 1 && now - this.lastTapTime < DOUBLE_TAP_TIME && dist < DOUBLE_TAP_DISTANCE) {
|
|
16289
|
+
this.taps = 0;
|
|
16290
|
+
this.lastTapTime = 0;
|
|
16291
|
+
this.tapStart = {
|
|
16292
|
+
x: 0,
|
|
16293
|
+
y: 0,
|
|
16294
|
+
time: 0
|
|
16295
|
+
};
|
|
16296
|
+
this.isDoubleTap = true;
|
|
16297
|
+
} else {
|
|
16298
|
+
this.setTapStart(e);
|
|
16299
|
+
this.taps = this.taps + 1;
|
|
16300
|
+
this.lastTapTime = now;
|
|
16301
|
+
this.isDoubleTap = false;
|
|
16302
|
+
}
|
|
16303
|
+
}
|
|
16304
|
+
hideSelectorArea() {
|
|
16305
|
+
this.selectionRectangle.setAttrs({
|
|
16306
|
+
width: 0,
|
|
16307
|
+
height: 0,
|
|
16308
|
+
visible: false
|
|
16309
|
+
});
|
|
16310
|
+
}
|
|
16176
16311
|
initEvents() {
|
|
16177
16312
|
let x1, y1, x2, y2;
|
|
16178
16313
|
this.selecting = false;
|
|
@@ -16184,13 +16319,31 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16184
16319
|
}
|
|
16185
16320
|
});
|
|
16186
16321
|
stage.on("pointerdown", (e) => {
|
|
16322
|
+
this.setTapStart(e);
|
|
16187
16323
|
this.pointers[e.evt.pointerId] = e.evt;
|
|
16188
16324
|
if (!this.initialized) return;
|
|
16189
16325
|
if (!this.active) return;
|
|
16190
16326
|
if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
|
|
16327
|
+
if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
|
|
16191
16328
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
16192
|
-
|
|
16193
|
-
|
|
16329
|
+
if (stage.mode() !== WEAVE_STAGE_MODE.normal) return;
|
|
16330
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
16331
|
+
if (selectedGroup?.getParent() instanceof konva.default.Transformer) {
|
|
16332
|
+
this.selecting = false;
|
|
16333
|
+
this.hideSelectorArea();
|
|
16334
|
+
return;
|
|
16335
|
+
}
|
|
16336
|
+
const isStage = e.target instanceof konva.default.Stage;
|
|
16337
|
+
const isTransformer = e.target?.getParent() instanceof konva.default.Transformer;
|
|
16338
|
+
const isTargetable = e.target.getAttrs().isTargetable !== false;
|
|
16339
|
+
const isContainerEmptyArea = typeof e.target.getAttrs().isContainerPrincipal !== "undefined" && !e.target.getAttrs().isContainerPrincipal;
|
|
16340
|
+
if (isTransformer) return;
|
|
16341
|
+
if (!isStage && !isContainerEmptyArea && isTargetable) {
|
|
16342
|
+
this.selecting = false;
|
|
16343
|
+
this.hideSelectorArea();
|
|
16344
|
+
this.handleClickOrTap(e);
|
|
16345
|
+
return;
|
|
16346
|
+
}
|
|
16194
16347
|
const intStage = this.instance.getStage();
|
|
16195
16348
|
x1 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
16196
16349
|
y1 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
@@ -16201,25 +16354,27 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16201
16354
|
this.selectionRectangle.width(0);
|
|
16202
16355
|
this.selectionRectangle.height(0);
|
|
16203
16356
|
this.selecting = true;
|
|
16357
|
+
this.tr.nodes([]);
|
|
16204
16358
|
this.instance.emitEvent("onSelectionState", true);
|
|
16205
|
-
if (!(e.target instanceof konva.default.Stage)) this.cameFromSelectingMultiple = true;
|
|
16206
16359
|
});
|
|
16207
16360
|
const handleMouseMove = (e) => {
|
|
16361
|
+
const moved = this.checkMoved(e);
|
|
16362
|
+
if (e.evt.buttons === 0) return;
|
|
16208
16363
|
if (!this.initialized) return;
|
|
16209
16364
|
if (!this.active) return;
|
|
16210
16365
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
16211
|
-
const contextMenuPlugin = this.
|
|
16366
|
+
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
16367
|
+
if (moved) contextMenuPlugin?.cancelLongPressTimer();
|
|
16368
|
+
else this.hideSelectorArea();
|
|
16212
16369
|
if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
|
|
16213
16370
|
this.selecting = false;
|
|
16214
16371
|
return;
|
|
16215
16372
|
}
|
|
16216
|
-
if (!this.selecting)
|
|
16217
|
-
this.cameFromSelectingMultiple = false;
|
|
16218
|
-
return;
|
|
16219
|
-
}
|
|
16373
|
+
if (!this.selecting) return;
|
|
16220
16374
|
const intStage = this.instance.getStage();
|
|
16221
16375
|
x2 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
16222
16376
|
y2 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
16377
|
+
this.getTransformer().nodes([]);
|
|
16223
16378
|
this.selectionRectangle.setAttrs({
|
|
16224
16379
|
visible: true,
|
|
16225
16380
|
x: Math.min(x1, x2),
|
|
@@ -16228,30 +16383,61 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16228
16383
|
height: Math.abs(y2 - y1)
|
|
16229
16384
|
});
|
|
16230
16385
|
};
|
|
16231
|
-
stage.on("pointermove",
|
|
16386
|
+
stage.on("pointermove", handleMouseMove);
|
|
16232
16387
|
stage.on("pointerup", (e) => {
|
|
16388
|
+
const moved = this.checkMoved(e);
|
|
16389
|
+
this.checkDoubleTap(e);
|
|
16233
16390
|
delete this.pointers[e.evt.pointerId];
|
|
16234
|
-
|
|
16235
|
-
|
|
16236
|
-
if (!this.
|
|
16237
|
-
|
|
16238
|
-
|
|
16239
|
-
|
|
16240
|
-
|
|
16391
|
+
this.getSnappingPlugin()?.cleanupEvaluateGuidelines();
|
|
16392
|
+
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
16393
|
+
if (!this.initialized) {
|
|
16394
|
+
this.hideSelectorArea();
|
|
16395
|
+
return;
|
|
16396
|
+
}
|
|
16397
|
+
if (!this.active) {
|
|
16398
|
+
this.hideSelectorArea();
|
|
16241
16399
|
return;
|
|
16242
16400
|
}
|
|
16243
16401
|
this.selecting = false;
|
|
16244
16402
|
this.instance.emitEvent("onSelectionState", false);
|
|
16403
|
+
if (this.isDoubleTap) {
|
|
16404
|
+
this.taps = 0;
|
|
16405
|
+
this.lastTapTime = 0;
|
|
16406
|
+
this.tapStart = {
|
|
16407
|
+
x: 0,
|
|
16408
|
+
y: 0,
|
|
16409
|
+
time: 0
|
|
16410
|
+
};
|
|
16411
|
+
this.isDoubleTap = true;
|
|
16412
|
+
this.hideSelectorArea();
|
|
16413
|
+
this.handleClickOrTap(e);
|
|
16414
|
+
return;
|
|
16415
|
+
}
|
|
16416
|
+
const isStage = e.target instanceof konva.default.Stage;
|
|
16417
|
+
const isContainerEmptyArea = typeof e.target.getAttrs().isContainerPrincipal !== "undefined" && !e.target.getAttrs().isContainerPrincipal;
|
|
16418
|
+
if ((isStage || isContainerEmptyArea) && !moved) {
|
|
16419
|
+
this.selecting = false;
|
|
16420
|
+
this.hideSelectorArea();
|
|
16421
|
+
this.getSelectionPlugin()?.setSelectedNodes([]);
|
|
16422
|
+
return;
|
|
16423
|
+
}
|
|
16424
|
+
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) {
|
|
16425
|
+
this.hideSelectorArea();
|
|
16426
|
+
return;
|
|
16427
|
+
}
|
|
16428
|
+
if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
|
|
16429
|
+
this.selecting = false;
|
|
16430
|
+
return;
|
|
16431
|
+
}
|
|
16245
16432
|
if (!this.selectionRectangle.visible()) {
|
|
16246
|
-
this.
|
|
16433
|
+
this.hideSelectorArea();
|
|
16247
16434
|
return;
|
|
16248
16435
|
}
|
|
16249
|
-
this.tr.nodes([]);
|
|
16250
|
-
this.selectionRectangle.visible(false);
|
|
16251
16436
|
const shapes = stage.find((node) => {
|
|
16252
16437
|
return ["Shape", "Group"].includes(node.getType()) && typeof node.getAttrs().id !== "undefined";
|
|
16253
16438
|
});
|
|
16254
16439
|
const box = this.selectionRectangle.getClientRect();
|
|
16440
|
+
this.selectionRectangle.visible(false);
|
|
16255
16441
|
const selected = shapes.filter((shape) => {
|
|
16256
16442
|
let parent = this.instance.getInstanceRecursive(shape.getParent());
|
|
16257
16443
|
if (parent.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
@@ -16265,118 +16451,148 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16265
16451
|
return false;
|
|
16266
16452
|
});
|
|
16267
16453
|
const selectedNodes = new Set();
|
|
16268
|
-
const
|
|
16269
|
-
return
|
|
16454
|
+
const containerNodes = selected.filter((node) => {
|
|
16455
|
+
return typeof node.getAttrs().isContainerPrincipal !== "undefined" && node.getAttrs().isContainerPrincipal;
|
|
16270
16456
|
});
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
return shape;
|
|
16274
|
-
}).filter((shape) => {
|
|
16275
|
-
return shape.getAttrs().nodeType === "frame";
|
|
16276
|
-
}).map((shape) => {
|
|
16277
|
-
return shape.getAttrs().id;
|
|
16457
|
+
let containerNodesIds = containerNodes.map((node) => {
|
|
16458
|
+
return node.getAttrs().id;
|
|
16278
16459
|
});
|
|
16279
|
-
const
|
|
16460
|
+
const uniqueContainerNodesIds = new Set(containerNodesIds);
|
|
16461
|
+
containerNodesIds = Array.from(uniqueContainerNodesIds);
|
|
16462
|
+
const otherNodes = selected.filter((shape) => typeof shape.getAttrs().isContainerPrincipal === "undefined" || typeof shape.getAttrs().isContainerPrincipal !== "undefined" && !shape.getAttrs().isContainerPrincipal);
|
|
16280
16463
|
otherNodes.forEach((node) => {
|
|
16281
16464
|
let parent = this.instance.getInstanceRecursive(node.getParent());
|
|
16282
16465
|
if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
16283
|
-
if (parent && !
|
|
16466
|
+
if (parent && !containerNodesIds.includes(parent?.getAttrs().id) && !node.getAttrs().locked) selectedNodes.add(node);
|
|
16284
16467
|
});
|
|
16285
|
-
|
|
16468
|
+
containerNodes.forEach((node) => {
|
|
16286
16469
|
const frameNode = node;
|
|
16287
|
-
if (!frameNode.getAttrs().locked) selectedNodes.add(
|
|
16470
|
+
if (!frameNode.getAttrs().locked) selectedNodes.add(node);
|
|
16288
16471
|
});
|
|
16289
|
-
|
|
16472
|
+
const nodesArray = [...selectedNodes];
|
|
16473
|
+
if (nodesArray.length > 1 && !this.config.transformations.multipleSelection.enabled || nodesArray.length === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16474
|
+
if (nodesArray.length > 1 && this.config.transformations.multipleSelection.enabled || nodesArray.length === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16475
|
+
if (nodesArray.length === 1) {
|
|
16476
|
+
this.tr.setAttrs({
|
|
16477
|
+
...this.config.transformer,
|
|
16478
|
+
...nodesArray[0].getTransformerProperties()
|
|
16479
|
+
});
|
|
16480
|
+
this.tr.forceUpdate();
|
|
16481
|
+
} else {
|
|
16482
|
+
this.tr.setAttrs({ ...this.config.transformer });
|
|
16483
|
+
this.tr.forceUpdate();
|
|
16484
|
+
}
|
|
16485
|
+
this.selecting = false;
|
|
16486
|
+
this.tr.nodes(nodesArray);
|
|
16290
16487
|
this.triggerSelectedNodesEvent();
|
|
16291
16488
|
stage.container().tabIndex = 1;
|
|
16292
16489
|
stage.container().focus();
|
|
16293
16490
|
});
|
|
16294
|
-
|
|
16295
|
-
|
|
16296
|
-
|
|
16297
|
-
|
|
16298
|
-
|
|
16299
|
-
|
|
16300
|
-
|
|
16301
|
-
|
|
16302
|
-
|
|
16303
|
-
|
|
16304
|
-
|
|
16305
|
-
|
|
16306
|
-
|
|
16307
|
-
|
|
16491
|
+
}
|
|
16492
|
+
getSelectionPlugin() {
|
|
16493
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16494
|
+
return selectionPlugin;
|
|
16495
|
+
}
|
|
16496
|
+
hideHoverState() {
|
|
16497
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16498
|
+
if (!selectionPlugin) return;
|
|
16499
|
+
selectionPlugin.getHoverTransformer().nodes([]);
|
|
16500
|
+
}
|
|
16501
|
+
handleClickOrTap(e) {
|
|
16502
|
+
const stage = this.instance.getStage();
|
|
16503
|
+
e.cancelBubble = true;
|
|
16504
|
+
if (!this.enabled) return;
|
|
16505
|
+
if (this.instance.getActiveAction() !== "selectionTool") return;
|
|
16506
|
+
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
16507
|
+
if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
|
|
16508
|
+
this.selecting = false;
|
|
16509
|
+
return;
|
|
16510
|
+
}
|
|
16511
|
+
this.hideHoverState();
|
|
16512
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
16513
|
+
if (!this.initialized) return;
|
|
16514
|
+
if (e.evt.pointerType === "mouse" && e.evt.button && e.evt.button !== 0) return;
|
|
16515
|
+
let areNodesSelected = false;
|
|
16516
|
+
let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
|
|
16517
|
+
if (nodeTargeted.getParent() instanceof konva.default.Transformer) {
|
|
16308
16518
|
const mousePos = stage.getPointerPosition();
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
if (
|
|
16314
|
-
|
|
16315
|
-
|
|
16316
|
-
|
|
16317
|
-
|
|
16318
|
-
|
|
16319
|
-
|
|
16320
|
-
return;
|
|
16321
|
-
}
|
|
16322
|
-
let areNodesSelected = false;
|
|
16323
|
-
let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
|
|
16324
|
-
if (nodeTargeted.getParent() instanceof konva.default.Transformer) {
|
|
16325
|
-
const intersections = stage.getAllIntersections(mousePos);
|
|
16326
|
-
const nodesIntersected = intersections.filter((ele) => ele.getAttrs().nodeType);
|
|
16327
|
-
let targetNode = null;
|
|
16328
|
-
if (nodesIntersected.length > 0) targetNode = this.instance.getInstanceRecursive(nodesIntersected[nodesIntersected.length - 1]);
|
|
16329
|
-
if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
|
|
16330
|
-
}
|
|
16331
|
-
if (!nodeTargeted.getAttrs().nodeType) return;
|
|
16332
|
-
let nodesSelected = 0;
|
|
16333
|
-
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
16334
|
-
const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
|
|
16335
|
-
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
16336
|
-
});
|
|
16337
|
-
const isSelected = nodeSelectedIndex !== -1;
|
|
16338
|
-
if (nodeTargeted.getAttrs().locked) return;
|
|
16339
|
-
if (!metaPressed) {
|
|
16340
|
-
this.tr.nodes([nodeTargeted]);
|
|
16341
|
-
nodesSelected = this.tr.nodes().length;
|
|
16342
|
-
this.tr.show();
|
|
16343
|
-
areNodesSelected = true;
|
|
16344
|
-
} else if (metaPressed && isSelected) {
|
|
16345
|
-
const nodes = this.tr.nodes().slice();
|
|
16346
|
-
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
16347
|
-
this.tr.nodes(nodes);
|
|
16348
|
-
nodesSelected = this.tr.nodes().length;
|
|
16349
|
-
areNodesSelected = true;
|
|
16350
|
-
} else if (metaPressed && !isSelected) {
|
|
16351
|
-
const nodes = this.tr.nodes().concat([nodeTargeted]);
|
|
16352
|
-
this.tr.nodes(nodes);
|
|
16353
|
-
nodesSelected = this.tr.nodes().length;
|
|
16354
|
-
areNodesSelected = true;
|
|
16355
|
-
}
|
|
16356
|
-
if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16357
|
-
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16358
|
-
if (nodesSelected === 1) {
|
|
16359
|
-
this.tr.setAttrs({ ...nodeTargeted.getTransformerProperties() });
|
|
16360
|
-
this.tr.forceUpdate();
|
|
16361
|
-
}
|
|
16362
|
-
if (areNodesSelected) {
|
|
16363
|
-
stage.container().tabIndex = 1;
|
|
16364
|
-
stage.container().focus();
|
|
16365
|
-
stage.container().style.cursor = "grab";
|
|
16366
|
-
}
|
|
16367
|
-
this.triggerSelectedNodesEvent();
|
|
16519
|
+
const intersections = stage.getAllIntersections(mousePos);
|
|
16520
|
+
const nodesIntersected = intersections.filter((ele) => ele.getAttrs().nodeType);
|
|
16521
|
+
let targetNode = null;
|
|
16522
|
+
if (nodesIntersected.length > 0) targetNode = this.instance.getInstanceRecursive(nodesIntersected[nodesIntersected.length - 1]);
|
|
16523
|
+
if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
|
|
16524
|
+
}
|
|
16525
|
+
if (!nodeTargeted.getAttrs().nodeType) return;
|
|
16526
|
+
let nodesSelected = 0;
|
|
16527
|
+
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
16528
|
+
const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
|
|
16529
|
+
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
16368
16530
|
});
|
|
16531
|
+
const isSelected = nodeSelectedIndex !== -1;
|
|
16532
|
+
if (nodeTargeted.getAttrs().locked) return;
|
|
16533
|
+
if (nodeTargeted.getAttrs().nodeId) {
|
|
16534
|
+
const realNode = stage.findOne(`#${nodeTargeted.getAttrs().nodeId}`);
|
|
16535
|
+
if (realNode) nodeTargeted = realNode;
|
|
16536
|
+
}
|
|
16537
|
+
if (typeof nodeTargeted.getAttrs().isContainerPrincipal !== "undefined" && !nodeTargeted.getAttrs().isContainerPrincipal) return;
|
|
16538
|
+
if (this.isDoubleTap && !metaPressed) {
|
|
16539
|
+
nodeTargeted.dblClick();
|
|
16540
|
+
return;
|
|
16541
|
+
}
|
|
16542
|
+
if (!metaPressed) {
|
|
16543
|
+
this.tr.nodes([nodeTargeted]);
|
|
16544
|
+
nodesSelected = this.tr.nodes().length;
|
|
16545
|
+
this.tr.show();
|
|
16546
|
+
areNodesSelected = true;
|
|
16547
|
+
}
|
|
16548
|
+
if (metaPressed && isSelected) {
|
|
16549
|
+
const nodes = this.tr.nodes().slice();
|
|
16550
|
+
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
16551
|
+
this.tr.nodes(nodes);
|
|
16552
|
+
nodesSelected = this.tr.nodes().length;
|
|
16553
|
+
areNodesSelected = true;
|
|
16554
|
+
}
|
|
16555
|
+
if (metaPressed && !isSelected) {
|
|
16556
|
+
const nodes = this.tr.nodes().concat([nodeTargeted]);
|
|
16557
|
+
this.tr.nodes(nodes);
|
|
16558
|
+
nodesSelected = this.tr.nodes().length;
|
|
16559
|
+
areNodesSelected = true;
|
|
16560
|
+
}
|
|
16561
|
+
if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16562
|
+
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16563
|
+
if (nodesSelected === 1) {
|
|
16564
|
+
this.tr.setAttrs({
|
|
16565
|
+
...this.config.transformer,
|
|
16566
|
+
...nodeTargeted.getTransformerProperties()
|
|
16567
|
+
});
|
|
16568
|
+
this.tr.forceUpdate();
|
|
16569
|
+
}
|
|
16570
|
+
if (areNodesSelected) {
|
|
16571
|
+
stage.container().tabIndex = 1;
|
|
16572
|
+
stage.container().focus();
|
|
16573
|
+
stage.container().style.cursor = "grab";
|
|
16574
|
+
}
|
|
16575
|
+
this.triggerSelectedNodesEvent();
|
|
16369
16576
|
}
|
|
16370
16577
|
getTransformer() {
|
|
16371
16578
|
return this.tr;
|
|
16372
16579
|
}
|
|
16580
|
+
getHoverTransformer() {
|
|
16581
|
+
return this.trHover;
|
|
16582
|
+
}
|
|
16373
16583
|
setSelectedNodes(nodes) {
|
|
16374
16584
|
this.tr.setNodes(nodes);
|
|
16375
16585
|
const nodesSelected = nodes.length;
|
|
16376
16586
|
if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16377
16587
|
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16378
16588
|
if (nodesSelected === 1) {
|
|
16379
|
-
this.tr.setAttrs({
|
|
16589
|
+
this.tr.setAttrs({
|
|
16590
|
+
...this.config.transformer,
|
|
16591
|
+
...nodes[0].getTransformerProperties()
|
|
16592
|
+
});
|
|
16593
|
+
this.tr.forceUpdate();
|
|
16594
|
+
} else if (nodesSelected > 1) {
|
|
16595
|
+
this.tr.setAttrs({ ...this.config.transformer });
|
|
16380
16596
|
this.tr.forceUpdate();
|
|
16381
16597
|
}
|
|
16382
16598
|
this.triggerSelectedNodesEvent();
|
|
@@ -16413,6 +16629,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16413
16629
|
this.getLayer()?.hide();
|
|
16414
16630
|
this.enabled = false;
|
|
16415
16631
|
}
|
|
16632
|
+
getContextMenuPlugin() {
|
|
16633
|
+
const contextMenuPlugin = this.instance.getPlugin("contextMenu");
|
|
16634
|
+
return contextMenuPlugin;
|
|
16635
|
+
}
|
|
16636
|
+
getSnappingPlugin() {
|
|
16637
|
+
const snappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16638
|
+
return snappingPlugin;
|
|
16639
|
+
}
|
|
16416
16640
|
};
|
|
16417
16641
|
|
|
16418
16642
|
//#endregion
|
|
@@ -16484,11 +16708,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16484
16708
|
try {
|
|
16485
16709
|
const continueToPaste = await this.readClipboardData();
|
|
16486
16710
|
if (continueToPaste) {
|
|
16487
|
-
|
|
16488
|
-
|
|
16489
|
-
this.state = COPY_PASTE_NODES_PLUGIN_STATE.PASTING;
|
|
16490
|
-
this.handlePaste(position);
|
|
16491
|
-
}
|
|
16711
|
+
this.state = COPY_PASTE_NODES_PLUGIN_STATE.PASTING;
|
|
16712
|
+
this.handlePaste();
|
|
16492
16713
|
}
|
|
16493
16714
|
} catch (ex) {
|
|
16494
16715
|
this.instance.emitEvent("onPaste", ex);
|
|
@@ -16497,7 +16718,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16497
16718
|
const items = await navigator.clipboard.read();
|
|
16498
16719
|
if (items && items.length === 1) {
|
|
16499
16720
|
const item = items[0];
|
|
16500
|
-
const position = this.instance.getStage().
|
|
16721
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
16501
16722
|
if (position) this.instance.emitEvent("onPasteExternal", {
|
|
16502
16723
|
position,
|
|
16503
16724
|
item
|
|
@@ -16530,9 +16751,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16530
16751
|
if (child.props.children) this.recursivelyUpdateKeys(child.props.children);
|
|
16531
16752
|
}
|
|
16532
16753
|
}
|
|
16533
|
-
handlePaste(
|
|
16754
|
+
handlePaste() {
|
|
16534
16755
|
if (this.toPaste) {
|
|
16535
|
-
const { mousePoint, container } = this.instance.getMousePointer(
|
|
16756
|
+
const { mousePoint, container } = this.instance.getMousePointer();
|
|
16536
16757
|
for (const element of Object.keys(this.toPaste.weave)) {
|
|
16537
16758
|
const node = this.toPaste.weave[element];
|
|
16538
16759
|
if (node.props.children) this.recursivelyUpdateKeys(node.props.children);
|
|
@@ -16542,7 +16763,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16542
16763
|
node.props.id = newNodeId;
|
|
16543
16764
|
node.props.x = mousePoint.x + (node.props.x - this.toPaste.weaveMinPoint.x);
|
|
16544
16765
|
node.props.y = mousePoint.y + (node.props.y - this.toPaste.weaveMinPoint.y);
|
|
16545
|
-
this.instance.addNode(node, container?.
|
|
16766
|
+
this.instance.addNode(node, container?.getAttrs().id);
|
|
16546
16767
|
this.instance.emitEvent("onPaste");
|
|
16547
16768
|
this.instance.emitEvent("onPaste", void 0);
|
|
16548
16769
|
}
|
|
@@ -16582,10 +16803,10 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16582
16803
|
async copy() {
|
|
16583
16804
|
await this.performCopy();
|
|
16584
16805
|
}
|
|
16585
|
-
async paste(
|
|
16806
|
+
async paste() {
|
|
16586
16807
|
try {
|
|
16587
16808
|
const continueToPaste = await this.readClipboardData();
|
|
16588
|
-
if (continueToPaste) this.handlePaste(
|
|
16809
|
+
if (continueToPaste) this.handlePaste();
|
|
16589
16810
|
} catch (ex) {
|
|
16590
16811
|
this.instance.emitEvent("onPaste", ex);
|
|
16591
16812
|
}
|
|
@@ -16593,6 +16814,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16593
16814
|
const items = await navigator.clipboard.read();
|
|
16594
16815
|
if (items && items.length === 1) {
|
|
16595
16816
|
const item = items[0];
|
|
16817
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
16596
16818
|
if (position) this.instance.emitEvent("onPasteExternal", {
|
|
16597
16819
|
position,
|
|
16598
16820
|
item
|
|
@@ -16651,6 +16873,7 @@ const augmentKonvaNodeClass = (config) => {
|
|
|
16651
16873
|
konva.default.Node.prototype.triggerCrop = function() {};
|
|
16652
16874
|
konva.default.Node.prototype.closeCrop = function() {};
|
|
16653
16875
|
konva.default.Node.prototype.resetCrop = function() {};
|
|
16876
|
+
konva.default.Node.prototype.dblClick = function() {};
|
|
16654
16877
|
};
|
|
16655
16878
|
var WeaveNode = class {
|
|
16656
16879
|
register(instance) {
|
|
@@ -16667,7 +16890,6 @@ var WeaveNode = class {
|
|
|
16667
16890
|
}
|
|
16668
16891
|
getSelectionPlugin() {
|
|
16669
16892
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16670
|
-
if (!selectionPlugin) throw new Error("WeaveNodesSelectionPlugin plugin not found");
|
|
16671
16893
|
return selectionPlugin;
|
|
16672
16894
|
}
|
|
16673
16895
|
isSelecting() {
|
|
@@ -16688,9 +16910,8 @@ var WeaveNode = class {
|
|
|
16688
16910
|
}
|
|
16689
16911
|
isNodeSelected(ele) {
|
|
16690
16912
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
return selected;
|
|
16913
|
+
if (selectionPlugin?.getSelectedNodes().map((node) => node.getAttrs().id).includes(ele.getAttrs().id)) return true;
|
|
16914
|
+
return false;
|
|
16694
16915
|
}
|
|
16695
16916
|
scaleReset(node) {
|
|
16696
16917
|
node.width(Math.max(5, node.width() * node.scaleX()));
|
|
@@ -16698,6 +16919,20 @@ var WeaveNode = class {
|
|
|
16698
16919
|
node.scaleX(1);
|
|
16699
16920
|
node.scaleY(1);
|
|
16700
16921
|
}
|
|
16922
|
+
setHoverState(node) {
|
|
16923
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16924
|
+
if (!selectionPlugin) return;
|
|
16925
|
+
if (selectionPlugin.isAreaSelecting()) {
|
|
16926
|
+
this.hideHoverState();
|
|
16927
|
+
return;
|
|
16928
|
+
}
|
|
16929
|
+
selectionPlugin.getHoverTransformer().nodes([node]);
|
|
16930
|
+
}
|
|
16931
|
+
hideHoverState() {
|
|
16932
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
16933
|
+
if (!selectionPlugin) return;
|
|
16934
|
+
selectionPlugin.getHoverTransformer().nodes([]);
|
|
16935
|
+
}
|
|
16701
16936
|
setupDefaultNodeEvents(node) {
|
|
16702
16937
|
this.instance.addEventListener("onNodesChange", () => {
|
|
16703
16938
|
if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
|
|
@@ -16747,7 +16982,17 @@ var WeaveNode = class {
|
|
|
16747
16982
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
|
|
16748
16983
|
});
|
|
16749
16984
|
node.on("dragstart", (e) => {
|
|
16985
|
+
this.didMove = false;
|
|
16986
|
+
if (e.evt?.buttons === 0) {
|
|
16987
|
+
e.target.stopDrag();
|
|
16988
|
+
return;
|
|
16989
|
+
}
|
|
16750
16990
|
const stage = this.instance.getStage();
|
|
16991
|
+
const isErasing = this.instance.getActiveAction() === "eraseTool";
|
|
16992
|
+
if (isErasing) {
|
|
16993
|
+
e.target.stopDrag();
|
|
16994
|
+
return;
|
|
16995
|
+
}
|
|
16751
16996
|
this.instance.emitEvent("onDrag", e.target);
|
|
16752
16997
|
if (stage.isMouseWheelPressed()) {
|
|
16753
16998
|
e.cancelBubble = true;
|
|
@@ -16755,24 +17000,38 @@ var WeaveNode = class {
|
|
|
16755
17000
|
}
|
|
16756
17001
|
});
|
|
16757
17002
|
const handleDragMove = (e) => {
|
|
17003
|
+
if (e.evt?.buttons === 0) {
|
|
17004
|
+
e.target.stopDrag();
|
|
17005
|
+
return;
|
|
17006
|
+
}
|
|
17007
|
+
this.didMove = true;
|
|
16758
17008
|
const stage = this.instance.getStage();
|
|
17009
|
+
const isErasing = this.instance.getActiveAction() === "eraseTool";
|
|
17010
|
+
if (isErasing) {
|
|
17011
|
+
e.target.stopDrag();
|
|
17012
|
+
return;
|
|
17013
|
+
}
|
|
16759
17014
|
if (stage.isMouseWheelPressed()) {
|
|
16760
17015
|
e.cancelBubble = true;
|
|
16761
17016
|
e.target.stopDrag();
|
|
16762
17017
|
return;
|
|
16763
17018
|
}
|
|
16764
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
17019
|
+
if (this.isSelecting() && this.isNodeSelected(node) && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
|
|
16765
17020
|
clearContainerTargets(this.instance);
|
|
16766
17021
|
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16767
17022
|
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
17023
|
}
|
|
16771
17024
|
};
|
|
16772
17025
|
node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
|
|
16773
17026
|
node.on("dragend", (e) => {
|
|
17027
|
+
if (!this.didMove) return;
|
|
17028
|
+
const isErasing = this.instance.getActiveAction() === "eraseTool";
|
|
17029
|
+
if (isErasing) {
|
|
17030
|
+
e.target.stopDrag();
|
|
17031
|
+
return;
|
|
17032
|
+
}
|
|
16774
17033
|
this.instance.emitEvent("onDrag", null);
|
|
16775
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
17034
|
+
if (this.isSelecting() && this.isNodeSelected(node) && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
|
|
16776
17035
|
clearContainerTargets(this.instance);
|
|
16777
17036
|
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16778
17037
|
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
@@ -16781,19 +17040,25 @@ var WeaveNode = class {
|
|
|
16781
17040
|
this.instance.updateNode(this.serialize(node));
|
|
16782
17041
|
}
|
|
16783
17042
|
});
|
|
16784
|
-
node.on("
|
|
17043
|
+
node.on("pointerover", (e) => {
|
|
17044
|
+
e.cancelBubble = true;
|
|
17045
|
+
const stage = this.instance.getStage();
|
|
16785
17046
|
const realNode = this.instance.getInstanceRecursive(node);
|
|
17047
|
+
const isTargetable = e.target.getAttrs().isTargetable !== false;
|
|
16786
17048
|
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 =
|
|
16790
|
-
|
|
16791
|
-
|
|
17049
|
+
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isLocked$1) {
|
|
17050
|
+
const stage$1 = this.instance.getStage();
|
|
17051
|
+
stage$1.container().style.cursor = "default";
|
|
17052
|
+
}
|
|
17053
|
+
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !isLocked$1 && stage.mode() === WEAVE_STAGE_MODE.normal) {
|
|
17054
|
+
const stage$1 = this.instance.getStage();
|
|
17055
|
+
stage$1.container().style.cursor = "pointer";
|
|
17056
|
+
this.setHoverState(realNode);
|
|
16792
17057
|
}
|
|
17058
|
+
if (!isTargetable) this.hideHoverState();
|
|
16793
17059
|
if (this.isPasting()) {
|
|
16794
|
-
const stage = this.instance.getStage();
|
|
16795
|
-
stage.container().style.cursor = "crosshair";
|
|
16796
|
-
e.cancelBubble = true;
|
|
17060
|
+
const stage$1 = this.instance.getStage();
|
|
17061
|
+
stage$1.container().style.cursor = "crosshair";
|
|
16797
17062
|
}
|
|
16798
17063
|
});
|
|
16799
17064
|
}
|
|
@@ -16874,14 +17139,19 @@ var WeaveNode = class {
|
|
|
16874
17139
|
}
|
|
16875
17140
|
unlock(instance) {
|
|
16876
17141
|
if (instance.getAttrs().nodeType !== this.getNodeType()) return;
|
|
16877
|
-
|
|
16878
|
-
this.instance.
|
|
16879
|
-
|
|
17142
|
+
let realInstance = instance;
|
|
17143
|
+
if (instance.getAttrs().nodeId) realInstance = this.instance.getStage().findOne(`#${instance.getAttrs().nodeId}`);
|
|
17144
|
+
if (!realInstance) return;
|
|
17145
|
+
realInstance.setAttrs({ locked: false });
|
|
17146
|
+
this.instance.updateNode(this.serialize(realInstance));
|
|
17147
|
+
this.setupDefaultNodeEvents(realInstance);
|
|
16880
17148
|
const stage = this.instance.getStage();
|
|
16881
17149
|
stage.container().style.cursor = "default";
|
|
16882
17150
|
}
|
|
16883
17151
|
isLocked(instance) {
|
|
16884
|
-
|
|
17152
|
+
let realInstance = instance;
|
|
17153
|
+
if (instance.getAttrs().nodeId === false) realInstance = this.instance.getInstanceRecursive(instance);
|
|
17154
|
+
return realInstance.getAttrs().locked ?? false;
|
|
16885
17155
|
}
|
|
16886
17156
|
};
|
|
16887
17157
|
|
|
@@ -16889,6 +17159,11 @@ var WeaveNode = class {
|
|
|
16889
17159
|
//#region src/actions/action.ts
|
|
16890
17160
|
var WeaveAction = class {
|
|
16891
17161
|
constructor() {
|
|
17162
|
+
this.tapStart = {
|
|
17163
|
+
x: 0,
|
|
17164
|
+
y: 0,
|
|
17165
|
+
time: 0
|
|
17166
|
+
};
|
|
16892
17167
|
return new Proxy(this, { set: (target, key, value) => {
|
|
16893
17168
|
Reflect.set(target, key, value);
|
|
16894
17169
|
this.onPropsChange?.();
|
|
@@ -16920,6 +17195,26 @@ var WeaveAction = class {
|
|
|
16920
17195
|
getProps() {
|
|
16921
17196
|
return this.props;
|
|
16922
17197
|
}
|
|
17198
|
+
isPressed(e) {
|
|
17199
|
+
return e.evt.buttons > 0;
|
|
17200
|
+
}
|
|
17201
|
+
setTapStart(e) {
|
|
17202
|
+
this.tapStart = {
|
|
17203
|
+
x: e.evt.clientX,
|
|
17204
|
+
y: e.evt.clientY,
|
|
17205
|
+
time: performance.now()
|
|
17206
|
+
};
|
|
17207
|
+
}
|
|
17208
|
+
isTap(e) {
|
|
17209
|
+
if (!this.tapStart) return false;
|
|
17210
|
+
const dx = e.evt.clientX - this.tapStart.x;
|
|
17211
|
+
const dy = e.evt.clientY - this.tapStart.y;
|
|
17212
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
17213
|
+
const dt = performance.now() - this.tapStart.time;
|
|
17214
|
+
const TAP_DISTANCE = 10;
|
|
17215
|
+
const TAP_TIME = 300;
|
|
17216
|
+
return (e.evt.pointerType === "pen" || e.evt.pointerType === "touch") && dist < TAP_DISTANCE && dt < TAP_TIME;
|
|
17217
|
+
}
|
|
16923
17218
|
};
|
|
16924
17219
|
|
|
16925
17220
|
//#endregion
|
|
@@ -17515,24 +17810,77 @@ var WeaveTargetingManager = class {
|
|
|
17515
17810
|
const intersectedNode = mainLayer.getIntersection(relativeMousePointer);
|
|
17516
17811
|
return intersectedNode;
|
|
17517
17812
|
}
|
|
17518
|
-
|
|
17813
|
+
isBoundingBoxIntersecting(nodeA, nodeB) {
|
|
17519
17814
|
const stage = this.instance.getStage();
|
|
17520
|
-
const
|
|
17815
|
+
const a = nodeA.getClientRect({ relativeTo: stage });
|
|
17816
|
+
const b = nodeB.getClientRect({ relativeTo: stage });
|
|
17817
|
+
return !(a.x + a.width < b.x || a.x > b.x + b.width || a.y + a.height < b.y || a.y > b.y + b.height);
|
|
17818
|
+
}
|
|
17819
|
+
isNodesBoundingBoxIntersecting(nodes, nodeB) {
|
|
17820
|
+
const stage = this.instance.getStage();
|
|
17821
|
+
const a = this.getBoundingBoxOfNodes(nodes);
|
|
17822
|
+
const b = nodeB.getClientRect({ relativeTo: stage });
|
|
17823
|
+
return !(a.x + a.width < b.x || a.x > b.x + b.width || a.y + a.height < b.y || a.y > b.y + b.height);
|
|
17824
|
+
}
|
|
17825
|
+
getBoundingBoxOfNodes(nodes) {
|
|
17826
|
+
const stage = this.instance.getStage();
|
|
17827
|
+
if (!nodes || nodes.length === 0) return {
|
|
17521
17828
|
x: 0,
|
|
17522
|
-
y: 0
|
|
17829
|
+
y: 0,
|
|
17830
|
+
width: 0,
|
|
17831
|
+
height: 0
|
|
17523
17832
|
};
|
|
17524
|
-
const
|
|
17833
|
+
const rects = nodes.map((node) => node.getClientRect({ relativeTo: stage }));
|
|
17834
|
+
const minX = Math.min(...rects.map((r) => r.x));
|
|
17835
|
+
const minY = Math.min(...rects.map((r) => r.y));
|
|
17836
|
+
const maxX = Math.max(...rects.map((r) => r.x + r.width));
|
|
17837
|
+
const maxY = Math.max(...rects.map((r) => r.y + r.height));
|
|
17838
|
+
return {
|
|
17839
|
+
x: minX,
|
|
17840
|
+
y: minY,
|
|
17841
|
+
width: maxX - minX,
|
|
17842
|
+
height: maxY - minY
|
|
17843
|
+
};
|
|
17844
|
+
}
|
|
17845
|
+
nodeIntersectsContainerElement(node, actualLayer) {
|
|
17846
|
+
const stage = this.instance.getStage();
|
|
17847
|
+
const containers = stage.find(".containerCapable");
|
|
17848
|
+
const intersections = [];
|
|
17849
|
+
if (node instanceof konva.default.Transformer) {
|
|
17850
|
+
const transformerNodes = node.nodes();
|
|
17851
|
+
const containersInSelection = [];
|
|
17852
|
+
for (const actualNode of transformerNodes) if (actualNode.getParent()?.getAttrs().nodeId) {
|
|
17853
|
+
const realParent = stage.findOne(`#${actualNode.getParent()?.getAttrs().nodeId}`);
|
|
17854
|
+
if (realParent) containersInSelection.push(realParent.getAttrs().id ?? "");
|
|
17855
|
+
}
|
|
17856
|
+
const containersInSelectionSet = new Set(containersInSelection);
|
|
17857
|
+
const uniqueContainersInSelection = Array.from(containersInSelectionSet);
|
|
17858
|
+
for (const container of containers) {
|
|
17859
|
+
const intersects = this.isNodesBoundingBoxIntersecting(transformerNodes, container);
|
|
17860
|
+
if (intersects && !uniqueContainersInSelection.includes(container.getAttrs().id ?? "")) intersections.push(container);
|
|
17861
|
+
}
|
|
17862
|
+
} else {
|
|
17863
|
+
let nodeActualContainer = node.getParent();
|
|
17864
|
+
if (nodeActualContainer.getAttrs().nodeId) {
|
|
17865
|
+
const realParent = stage.findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
|
|
17866
|
+
if (realParent) nodeActualContainer = realParent;
|
|
17867
|
+
}
|
|
17868
|
+
for (const container of containers) {
|
|
17869
|
+
const intersects = this.isBoundingBoxIntersecting(node, container);
|
|
17870
|
+
if (intersects && container.getAttrs().id !== node.getAttrs().id) intersections.push(container);
|
|
17871
|
+
}
|
|
17872
|
+
}
|
|
17525
17873
|
let intersectedNode = void 0;
|
|
17526
|
-
|
|
17527
|
-
if (node.getAttrs().nodeId) {
|
|
17528
|
-
const parent = stage.findOne(`#${node.getAttrs().nodeId}`);
|
|
17874
|
+
for (const node$1 of intersections) {
|
|
17875
|
+
if (node$1.getAttrs().nodeId) {
|
|
17876
|
+
const parent = stage.findOne(`#${node$1.getAttrs().nodeId}`);
|
|
17529
17877
|
if (!parent) continue;
|
|
17530
17878
|
const resolvedNode = this.resolveNode(parent);
|
|
17531
|
-
if (resolvedNode && resolvedNode.getAttrs().
|
|
17879
|
+
if (resolvedNode && resolvedNode.getAttrs().id !== actualLayer?.getAttrs().id) intersectedNode = parent;
|
|
17532
17880
|
continue;
|
|
17533
17881
|
}
|
|
17534
|
-
if (node.getAttrs().
|
|
17535
|
-
intersectedNode = node;
|
|
17882
|
+
if (node$1.getAttrs().id !== actualLayer?.getAttrs().id) {
|
|
17883
|
+
intersectedNode = node$1;
|
|
17536
17884
|
continue;
|
|
17537
17885
|
}
|
|
17538
17886
|
}
|
|
@@ -17542,7 +17890,7 @@ var WeaveTargetingManager = class {
|
|
|
17542
17890
|
this.logger.debug({ point }, "getMousePointer");
|
|
17543
17891
|
const stage = this.instance.getStage();
|
|
17544
17892
|
const mainLayer = this.instance.getMainLayer();
|
|
17545
|
-
let relativeMousePointer = point ? point :
|
|
17893
|
+
let relativeMousePointer = point ? point : mainLayer?.getRelativePointerPosition() ?? {
|
|
17546
17894
|
x: 0,
|
|
17547
17895
|
y: 0
|
|
17548
17896
|
};
|
|
@@ -17550,18 +17898,19 @@ var WeaveTargetingManager = class {
|
|
|
17550
17898
|
let container = mainLayer;
|
|
17551
17899
|
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
17552
17900
|
if (nodesSelection) nodesSelection.disable();
|
|
17553
|
-
const
|
|
17901
|
+
const dummyRect = new konva.default.Rect({
|
|
17902
|
+
width: 10,
|
|
17903
|
+
height: 10,
|
|
17904
|
+
x: relativeMousePointer.x,
|
|
17905
|
+
y: relativeMousePointer.y
|
|
17906
|
+
});
|
|
17907
|
+
mainLayer?.add(dummyRect);
|
|
17908
|
+
const intersectedNode = this.nodeIntersectsContainerElement(dummyRect);
|
|
17554
17909
|
if (intersectedNode) {
|
|
17555
|
-
const
|
|
17556
|
-
|
|
17557
|
-
|
|
17558
|
-
|
|
17559
|
-
measureContainer = node.findOne(`#${node.getAttrs().containerId}`);
|
|
17560
|
-
container = node;
|
|
17561
|
-
}
|
|
17562
|
-
if (nodeParent && nodeParent instanceof konva.default.Group && nodeParent.getAttrs().containerId) {
|
|
17563
|
-
measureContainer = nodeParent.findOne(`#${nodeParent.getAttrs().containerId}`);
|
|
17564
|
-
container = nodeParent;
|
|
17910
|
+
const containerOfNode = stage.findOne(`#${intersectedNode.getAttrs().containerId}`);
|
|
17911
|
+
if (containerOfNode) {
|
|
17912
|
+
container = intersectedNode;
|
|
17913
|
+
measureContainer = containerOfNode;
|
|
17565
17914
|
}
|
|
17566
17915
|
}
|
|
17567
17916
|
if (container?.getAttrs().nodeType !== "layer") relativeMousePointer = measureContainer?.getRelativePointerPosition() ?? relativeMousePointer;
|
|
@@ -17570,6 +17919,7 @@ var WeaveTargetingManager = class {
|
|
|
17570
17919
|
y: 0
|
|
17571
17920
|
};
|
|
17572
17921
|
if (nodesSelection) nodesSelection.enable();
|
|
17922
|
+
dummyRect.destroy();
|
|
17573
17923
|
return {
|
|
17574
17924
|
mousePoint: relativeMousePointer,
|
|
17575
17925
|
container,
|
|
@@ -17975,23 +18325,30 @@ var WeaveZIndexManager = class {
|
|
|
17975
18325
|
this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN);
|
|
17976
18326
|
}
|
|
17977
18327
|
}
|
|
17978
|
-
sendToBack(
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
const
|
|
17982
|
-
|
|
17983
|
-
const
|
|
17984
|
-
|
|
18328
|
+
sendToBack(instances) {
|
|
18329
|
+
const nodes = Array.isArray(instances) ? instances : [instances];
|
|
18330
|
+
const nodesDescending = nodes.toSorted((a, b) => b.zIndex() - a.zIndex());
|
|
18331
|
+
for (const node of nodesDescending) {
|
|
18332
|
+
node.moveToBottom();
|
|
18333
|
+
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
18334
|
+
if (handler) {
|
|
18335
|
+
const nodeState = handler.serialize(node);
|
|
18336
|
+
this.instance.updateNode(nodeState);
|
|
18337
|
+
this.instance.moveNode(nodeState, __inditextech_weave_types.WEAVE_NODE_POSITION.BACK);
|
|
18338
|
+
}
|
|
17985
18339
|
}
|
|
17986
18340
|
}
|
|
17987
|
-
bringToFront(
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
const
|
|
17991
|
-
|
|
17992
|
-
const
|
|
17993
|
-
|
|
17994
|
-
|
|
18341
|
+
bringToFront(instances) {
|
|
18342
|
+
const nodes = Array.isArray(instances) ? instances : [instances];
|
|
18343
|
+
const nodesAscending = nodes.toSorted((a, b) => a.zIndex() - b.zIndex());
|
|
18344
|
+
for (const node of nodesAscending) {
|
|
18345
|
+
node.moveToTop();
|
|
18346
|
+
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
18347
|
+
if (handler) {
|
|
18348
|
+
const nodeState = handler.serialize(node);
|
|
18349
|
+
this.instance.updateNode(nodeState);
|
|
18350
|
+
this.instance.moveNode(nodeState, __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT);
|
|
18351
|
+
}
|
|
17995
18352
|
}
|
|
17996
18353
|
}
|
|
17997
18354
|
};
|
|
@@ -18063,7 +18420,7 @@ var WeaveStateManager = class {
|
|
|
18063
18420
|
};
|
|
18064
18421
|
return this.findNodeById(state, nodeKey);
|
|
18065
18422
|
}
|
|
18066
|
-
addNode(node, parentId = "mainLayer", index = void 0
|
|
18423
|
+
addNode(node, parentId = "mainLayer", index = void 0) {
|
|
18067
18424
|
const userName = this.instance.getStore().getUser().name;
|
|
18068
18425
|
this.instance.getStore().getDocument().transact(() => {
|
|
18069
18426
|
const state = this.instance.getStore().getState();
|
|
@@ -18071,8 +18428,7 @@ var WeaveStateManager = class {
|
|
|
18071
18428
|
const msg = `State is empty, cannot add the node`;
|
|
18072
18429
|
this.logger.warn({
|
|
18073
18430
|
node,
|
|
18074
|
-
parentId
|
|
18075
|
-
doRender
|
|
18431
|
+
parentId
|
|
18076
18432
|
}, msg);
|
|
18077
18433
|
return;
|
|
18078
18434
|
}
|
|
@@ -18081,8 +18437,7 @@ var WeaveStateManager = class {
|
|
|
18081
18437
|
const msg = `Node with key [${node.key}] already exists, cannot add it`;
|
|
18082
18438
|
this.logger.warn({
|
|
18083
18439
|
node,
|
|
18084
|
-
parentId
|
|
18085
|
-
doRender
|
|
18440
|
+
parentId
|
|
18086
18441
|
}, msg);
|
|
18087
18442
|
return;
|
|
18088
18443
|
}
|
|
@@ -18091,8 +18446,7 @@ var WeaveStateManager = class {
|
|
|
18091
18446
|
const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
|
|
18092
18447
|
this.logger.warn({
|
|
18093
18448
|
node,
|
|
18094
|
-
parentId
|
|
18095
|
-
doRender
|
|
18449
|
+
parentId
|
|
18096
18450
|
}, msg);
|
|
18097
18451
|
return;
|
|
18098
18452
|
}
|
|
@@ -18122,28 +18476,21 @@ var WeaveStateManager = class {
|
|
|
18122
18476
|
parent.props.children.push(finalNode);
|
|
18123
18477
|
}
|
|
18124
18478
|
this.instance.emitEvent("onNodeAdded", node);
|
|
18125
|
-
if (doRender) this.instance.render();
|
|
18126
18479
|
}, userName);
|
|
18127
18480
|
}
|
|
18128
|
-
updateNode(node
|
|
18481
|
+
updateNode(node) {
|
|
18129
18482
|
const userName = this.instance.getStore().getUser().name;
|
|
18130
18483
|
this.instance.getStore().getDocument().transact(() => {
|
|
18131
18484
|
const state = this.instance.getStore().getState();
|
|
18132
18485
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18133
18486
|
const msg = `State is empty, cannot update the node`;
|
|
18134
|
-
this.logger.warn({
|
|
18135
|
-
node,
|
|
18136
|
-
doRender
|
|
18137
|
-
}, msg);
|
|
18487
|
+
this.logger.warn({ node }, msg);
|
|
18138
18488
|
return;
|
|
18139
18489
|
}
|
|
18140
18490
|
const { node: nodeState } = this.findNodeById(state.weave, node.key);
|
|
18141
18491
|
if (!nodeState) {
|
|
18142
18492
|
const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
|
|
18143
|
-
this.logger.warn({
|
|
18144
|
-
node,
|
|
18145
|
-
doRender
|
|
18146
|
-
}, msg);
|
|
18493
|
+
this.logger.warn({ node }, msg);
|
|
18147
18494
|
return;
|
|
18148
18495
|
}
|
|
18149
18496
|
const nodeNew = JSON.parse(JSON.stringify({
|
|
@@ -18152,28 +18499,21 @@ var WeaveStateManager = class {
|
|
|
18152
18499
|
}));
|
|
18153
18500
|
nodeState.props = { ...nodeNew };
|
|
18154
18501
|
this.instance.emitEvent("onNodeUpdated", node);
|
|
18155
|
-
if (doRender) this.instance.render();
|
|
18156
18502
|
}, userName);
|
|
18157
18503
|
}
|
|
18158
|
-
removeNode(node
|
|
18504
|
+
removeNode(node) {
|
|
18159
18505
|
const userName = this.instance.getStore().getUser().name;
|
|
18160
18506
|
this.instance.getStore().getDocument().transact(() => {
|
|
18161
18507
|
const state = this.instance.getStore().getState();
|
|
18162
18508
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18163
18509
|
const msg = `State is empty, cannot update the node`;
|
|
18164
|
-
this.logger.warn({
|
|
18165
|
-
node,
|
|
18166
|
-
doRender
|
|
18167
|
-
}, msg);
|
|
18510
|
+
this.logger.warn({ node }, msg);
|
|
18168
18511
|
return;
|
|
18169
18512
|
}
|
|
18170
18513
|
const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
|
|
18171
18514
|
if (!nodeState) {
|
|
18172
18515
|
const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
|
|
18173
|
-
this.logger.warn({
|
|
18174
|
-
node,
|
|
18175
|
-
doRender
|
|
18176
|
-
}, msg);
|
|
18516
|
+
this.logger.warn({ node }, msg);
|
|
18177
18517
|
return;
|
|
18178
18518
|
}
|
|
18179
18519
|
if (parentState) {
|
|
@@ -18182,32 +18522,24 @@ var WeaveStateManager = class {
|
|
|
18182
18522
|
parentState.props.children = filteredChildren;
|
|
18183
18523
|
}
|
|
18184
18524
|
this.instance.emitEvent("onNodeRemoved", node);
|
|
18185
|
-
if (doRender) this.instance.render();
|
|
18186
18525
|
}, userName);
|
|
18187
18526
|
}
|
|
18188
|
-
removeNodes(nodes
|
|
18189
|
-
for (const node of nodes) this.removeNode(node
|
|
18190
|
-
if (doRender) this.instance.render();
|
|
18527
|
+
removeNodes(nodes) {
|
|
18528
|
+
for (const node of nodes) this.removeNode(node);
|
|
18191
18529
|
}
|
|
18192
|
-
moveNode(node, position
|
|
18530
|
+
moveNode(node, position) {
|
|
18193
18531
|
const userName = this.instance.getStore().getUser().name;
|
|
18194
18532
|
this.instance.getStore().getDocument().transact(() => {
|
|
18195
18533
|
const state = this.instance.getStore().getState();
|
|
18196
18534
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18197
18535
|
const msg = `State is empty, cannot update the node`;
|
|
18198
|
-
this.logger.warn({
|
|
18199
|
-
node,
|
|
18200
|
-
doRender
|
|
18201
|
-
}, msg);
|
|
18536
|
+
this.logger.warn({ node }, msg);
|
|
18202
18537
|
return;
|
|
18203
18538
|
}
|
|
18204
18539
|
const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
|
|
18205
18540
|
if (!nodeState) {
|
|
18206
18541
|
const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
|
|
18207
|
-
this.logger.warn({
|
|
18208
|
-
node,
|
|
18209
|
-
doRender
|
|
18210
|
-
}, msg);
|
|
18542
|
+
this.logger.warn({ node }, msg);
|
|
18211
18543
|
return;
|
|
18212
18544
|
}
|
|
18213
18545
|
if (nodeParent) {
|
|
@@ -18231,7 +18563,6 @@ var WeaveStateManager = class {
|
|
|
18231
18563
|
});
|
|
18232
18564
|
if (!nodeParent.props.children) nodeParent.props.children = [];
|
|
18233
18565
|
nodeParent.props.children = nodeParentNewChildren;
|
|
18234
|
-
if (doRender) this.instance.render();
|
|
18235
18566
|
}
|
|
18236
18567
|
}, userName);
|
|
18237
18568
|
}
|
|
@@ -18317,7 +18648,7 @@ var WeaveRegisterManager = class {
|
|
|
18317
18648
|
|
|
18318
18649
|
//#endregion
|
|
18319
18650
|
//#region package.json
|
|
18320
|
-
var version = "0.
|
|
18651
|
+
var version = "0.39.0";
|
|
18321
18652
|
|
|
18322
18653
|
//#endregion
|
|
18323
18654
|
//#region src/managers/setup.ts
|
|
@@ -18389,6 +18720,10 @@ var WeaveStageManager = class {
|
|
|
18389
18720
|
const stage = this.getStage();
|
|
18390
18721
|
return stage.findOne(`#${__inditextech_weave_types.WEAVE_NODE_LAYER_ID}`);
|
|
18391
18722
|
}
|
|
18723
|
+
getSelectionLayer() {
|
|
18724
|
+
const stage = this.getStage();
|
|
18725
|
+
return stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
|
|
18726
|
+
}
|
|
18392
18727
|
getUtilityLayer() {
|
|
18393
18728
|
const stage = this.getStage();
|
|
18394
18729
|
return stage.findOne(`#${__inditextech_weave_types.WEAVE_UTILITY_LAYER_ID}`);
|
|
@@ -18764,6 +19099,9 @@ var Weave = class {
|
|
|
18764
19099
|
getMainLayer() {
|
|
18765
19100
|
return this.stageManager.getMainLayer();
|
|
18766
19101
|
}
|
|
19102
|
+
getSelectionLayer() {
|
|
19103
|
+
return this.stageManager.getSelectionLayer();
|
|
19104
|
+
}
|
|
18767
19105
|
getUtilityLayer() {
|
|
18768
19106
|
return this.stageManager.getUtilityLayer();
|
|
18769
19107
|
}
|
|
@@ -18859,31 +19197,27 @@ var Weave = class {
|
|
|
18859
19197
|
getNode(nodeKey) {
|
|
18860
19198
|
return this.stateManager.getNode(nodeKey);
|
|
18861
19199
|
}
|
|
18862
|
-
addNode(node, parentId = "mainLayer", index = void 0
|
|
18863
|
-
this.stateManager.addNode(node, parentId, index
|
|
19200
|
+
addNode(node, parentId = "mainLayer", index = void 0) {
|
|
19201
|
+
this.stateManager.addNode(node, parentId, index);
|
|
18864
19202
|
}
|
|
18865
|
-
updateNode(node
|
|
18866
|
-
this.stateManager.updateNode(node
|
|
19203
|
+
updateNode(node) {
|
|
19204
|
+
this.stateManager.updateNode(node);
|
|
18867
19205
|
}
|
|
18868
|
-
updateNodes(nodes
|
|
18869
|
-
for (const node of nodes) this.updateNode(node
|
|
18870
|
-
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
18871
|
-
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
18872
|
-
if (doRender) this.render();
|
|
19206
|
+
updateNodes(nodes) {
|
|
19207
|
+
for (const node of nodes) this.updateNode(node);
|
|
18873
19208
|
}
|
|
18874
|
-
removeNode(node
|
|
18875
|
-
this.stateManager.removeNode(node
|
|
19209
|
+
removeNode(node) {
|
|
19210
|
+
this.stateManager.removeNode(node);
|
|
18876
19211
|
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
18877
19212
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
18878
19213
|
}
|
|
18879
|
-
removeNodes(nodes
|
|
18880
|
-
for (const node of nodes) this.removeNode(node
|
|
19214
|
+
removeNodes(nodes) {
|
|
19215
|
+
for (const node of nodes) this.removeNode(node);
|
|
18881
19216
|
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
18882
19217
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
18883
|
-
if (doRender) this.render();
|
|
18884
19218
|
}
|
|
18885
|
-
moveNode(node, position
|
|
18886
|
-
this.stateManager.moveNode(node, position
|
|
19219
|
+
moveNode(node, position) {
|
|
19220
|
+
this.stateManager.moveNode(node, position);
|
|
18887
19221
|
}
|
|
18888
19222
|
getElementsTree() {
|
|
18889
19223
|
return this.stateManager.getElementsTree();
|
|
@@ -18897,11 +19231,11 @@ var Weave = class {
|
|
|
18897
19231
|
moveDown(node) {
|
|
18898
19232
|
this.zIndexManager.moveDown(node);
|
|
18899
19233
|
}
|
|
18900
|
-
sendToBack(
|
|
18901
|
-
this.zIndexManager.sendToBack(
|
|
19234
|
+
sendToBack(nodes) {
|
|
19235
|
+
this.zIndexManager.sendToBack(nodes);
|
|
18902
19236
|
}
|
|
18903
|
-
bringToFront(
|
|
18904
|
-
this.zIndexManager.bringToFront(
|
|
19237
|
+
bringToFront(nodes) {
|
|
19238
|
+
this.zIndexManager.bringToFront(nodes);
|
|
18905
19239
|
}
|
|
18906
19240
|
group(nodes) {
|
|
18907
19241
|
this.groupsManager.group(nodes);
|
|
@@ -18917,8 +19251,8 @@ var Weave = class {
|
|
|
18917
19251
|
pointIntersectsElement(point) {
|
|
18918
19252
|
return this.targetingManager.pointIntersectsElement(point);
|
|
18919
19253
|
}
|
|
18920
|
-
|
|
18921
|
-
return this.targetingManager.
|
|
19254
|
+
nodeIntersectsContainerElement(node, actualLayer) {
|
|
19255
|
+
return this.targetingManager.nodeIntersectsContainerElement(node, actualLayer);
|
|
18922
19256
|
}
|
|
18923
19257
|
getMousePointer(point) {
|
|
18924
19258
|
return this.targetingManager.getMousePointer(point);
|
|
@@ -18931,8 +19265,7 @@ var Weave = class {
|
|
|
18931
19265
|
if (selectionPlugin) {
|
|
18932
19266
|
const stage = this.getStage();
|
|
18933
19267
|
const instanceNodes = nodesIds.map((nodeId) => {
|
|
18934
|
-
|
|
18935
|
-
if (nodeInstance && nodeInstance.getAttrs().nodeType === "frame") nodeInstance = stage.findOne(`#${nodeId}-selector-area`);
|
|
19268
|
+
const nodeInstance = stage.findOne(`#${nodeId}`);
|
|
18936
19269
|
return nodeInstance;
|
|
18937
19270
|
});
|
|
18938
19271
|
selectionPlugin.setSelectedNodes(instanceNodes);
|
|
@@ -19039,10 +19372,6 @@ var Weave = class {
|
|
|
19039
19372
|
}
|
|
19040
19373
|
};
|
|
19041
19374
|
|
|
19042
|
-
//#endregion
|
|
19043
|
-
//#region src/nodes/stage/constants.ts
|
|
19044
|
-
const WEAVE_STAGE_NODE_TYPE = "stage";
|
|
19045
|
-
|
|
19046
19375
|
//#endregion
|
|
19047
19376
|
//#region src/nodes/stage/stage.ts
|
|
19048
19377
|
var WeaveStageNode = class extends WeaveNode {
|
|
@@ -19062,6 +19391,10 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19062
19391
|
stage.container().addEventListener("blur", () => {
|
|
19063
19392
|
this.stageFocused = false;
|
|
19064
19393
|
});
|
|
19394
|
+
konva.default.Stage.prototype.mode = function(mode) {
|
|
19395
|
+
if (typeof mode !== "undefined") this._mode = mode;
|
|
19396
|
+
return this._mode;
|
|
19397
|
+
};
|
|
19065
19398
|
konva.default.Stage.prototype.allowActions = function(actions) {
|
|
19066
19399
|
if (typeof actions !== "undefined") this._allowActions = actions;
|
|
19067
19400
|
return this._allowActions;
|
|
@@ -19074,6 +19407,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19074
19407
|
if (typeof allowSelection !== "undefined") this._allowSelection = allowSelection;
|
|
19075
19408
|
return this._allowSelection;
|
|
19076
19409
|
};
|
|
19410
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
19077
19411
|
stage.on("pointermove", (e) => {
|
|
19078
19412
|
if (stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
|
|
19079
19413
|
const stage$1 = this.instance.getStage();
|
|
@@ -19084,6 +19418,13 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19084
19418
|
stage$1.container().style.cursor = "default";
|
|
19085
19419
|
}
|
|
19086
19420
|
});
|
|
19421
|
+
stage.on("pointerover", (e) => {
|
|
19422
|
+
if (e.target !== stage && !e.target.getAttrs().nodeId) return;
|
|
19423
|
+
const parent = e.target.getParent();
|
|
19424
|
+
if (parent && parent instanceof konva.default.Transformer) return;
|
|
19425
|
+
this.hideHoverState();
|
|
19426
|
+
stage.container().style.cursor = "default";
|
|
19427
|
+
});
|
|
19087
19428
|
stage.on("pointerdown", (e) => {
|
|
19088
19429
|
if (e.evt.button === 1) this.wheelMousePressed = true;
|
|
19089
19430
|
});
|
|
@@ -19152,6 +19493,7 @@ var WeaveGroupNode = class extends WeaveNode {
|
|
|
19152
19493
|
onRender(props) {
|
|
19153
19494
|
const group = new konva.default.Group({
|
|
19154
19495
|
...props,
|
|
19496
|
+
isContainerPrincipal: true,
|
|
19155
19497
|
name: "node"
|
|
19156
19498
|
});
|
|
19157
19499
|
this.setupDefaultNodeAugmentation(group);
|
|
@@ -19368,6 +19710,8 @@ const TEXT_LAYOUT = {
|
|
|
19368
19710
|
var WeaveTextNode = class extends WeaveNode {
|
|
19369
19711
|
nodeType = WEAVE_TEXT_NODE_TYPE;
|
|
19370
19712
|
editing = false;
|
|
19713
|
+
textAreaSuperContainer = null;
|
|
19714
|
+
textAreaContainer = null;
|
|
19371
19715
|
textArea = null;
|
|
19372
19716
|
constructor(params) {
|
|
19373
19717
|
super();
|
|
@@ -19429,8 +19773,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19429
19773
|
}
|
|
19430
19774
|
}
|
|
19431
19775
|
});
|
|
19432
|
-
text.
|
|
19433
|
-
e.cancelBubble = true;
|
|
19776
|
+
text.dblClick = () => {
|
|
19434
19777
|
if (this.editing) return;
|
|
19435
19778
|
if (!(this.isSelecting() && this.isNodeSelected(text))) return;
|
|
19436
19779
|
const stage = this.instance.getStage();
|
|
@@ -19440,7 +19783,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19440
19783
|
const onlyTextElements = elements.filter((ele) => ele.getAttrs().nodeType === WEAVE_TEXT_NODE_TYPE);
|
|
19441
19784
|
if (onlyTextElements.length > 0) this.triggerEditMode(onlyTextElements[0]);
|
|
19442
19785
|
}
|
|
19443
|
-
}
|
|
19786
|
+
};
|
|
19444
19787
|
text.on("transform", (e) => {
|
|
19445
19788
|
if (this.isSelecting() && this.isNodeSelected(text)) {
|
|
19446
19789
|
text.setAttrs({
|
|
@@ -19506,19 +19849,20 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19506
19849
|
if (!this.editing) return;
|
|
19507
19850
|
this.updateTextAreaDOM(textNode);
|
|
19508
19851
|
};
|
|
19509
|
-
textAreaDomResize(
|
|
19852
|
+
textAreaDomResize(textNode) {
|
|
19853
|
+
if (!this.textArea || !this.textAreaContainer) return;
|
|
19510
19854
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
19511
|
-
const { width: textAreaWidth } = this.textRenderedSize(textArea.value, textNode);
|
|
19512
|
-
textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19855
|
+
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
19856
|
+
this.textAreaContainer.style.width = textAreaWidth * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19513
19857
|
}
|
|
19514
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) textAreaContainer.style.height = "auto";
|
|
19858
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) this.textAreaContainer.style.height = "auto";
|
|
19515
19859
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19516
|
-
textAreaContainer.style.height = "auto";
|
|
19517
|
-
textAreaContainer.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().y + "px";
|
|
19860
|
+
this.textAreaContainer.style.height = "auto";
|
|
19861
|
+
this.textAreaContainer.style.height = this.textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().y + "px";
|
|
19518
19862
|
}
|
|
19519
|
-
textArea.style.height = "auto";
|
|
19520
|
-
textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
|
|
19521
|
-
textArea.rows = textArea.value.split("\n").length;
|
|
19863
|
+
this.textArea.style.height = "auto";
|
|
19864
|
+
this.textArea.style.height = this.textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
|
|
19865
|
+
this.textArea.rows = this.textArea.value.split("\n").length;
|
|
19522
19866
|
}
|
|
19523
19867
|
measureMultilineText(textNode) {
|
|
19524
19868
|
return () => {
|
|
@@ -19539,73 +19883,74 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19539
19883
|
height
|
|
19540
19884
|
};
|
|
19541
19885
|
}
|
|
19542
|
-
mimicTextNode(textNode
|
|
19543
|
-
|
|
19544
|
-
textArea.
|
|
19545
|
-
textArea.
|
|
19546
|
-
textArea.style.
|
|
19547
|
-
textArea.style.
|
|
19548
|
-
textArea.style.
|
|
19886
|
+
mimicTextNode(textNode) {
|
|
19887
|
+
if (!this.textArea) return;
|
|
19888
|
+
this.textArea.style.fontSize = textNode.fontSize() * textNode.getAbsoluteScale().x + "px";
|
|
19889
|
+
this.textArea.rows = textNode.text().split("\n").length;
|
|
19890
|
+
this.textArea.style.letterSpacing = `${textNode.letterSpacing()}`;
|
|
19891
|
+
this.textArea.style.opacity = `${textNode.getAttrs().opacity}`;
|
|
19892
|
+
this.textArea.style.lineHeight = `${textNode.lineHeight()}`;
|
|
19893
|
+
this.textArea.style.fontFamily = textNode.fontFamily();
|
|
19549
19894
|
let fontWeight = "normal";
|
|
19550
19895
|
let fontStyle = "normal";
|
|
19551
19896
|
if ((textNode.fontStyle() ?? "normal").indexOf("bold") !== -1) fontWeight = "bold";
|
|
19552
19897
|
if ((textNode.fontStyle() ?? "normal").indexOf("italic") !== -1) fontStyle = "italic";
|
|
19553
|
-
textArea.style.fontWeight = fontWeight;
|
|
19554
|
-
textArea.style.backgroundColor = "transparent";
|
|
19555
|
-
textArea.style.fontStyle = fontStyle;
|
|
19556
|
-
textArea.style.fontVariant = textNode.fontVariant();
|
|
19557
|
-
textArea.style.textDecoration = textNode.textDecoration();
|
|
19558
|
-
textArea.style.textAlign = textNode.align();
|
|
19559
|
-
textArea.style.color = `${textNode.fill()}`;
|
|
19898
|
+
this.textArea.style.fontWeight = fontWeight;
|
|
19899
|
+
this.textArea.style.backgroundColor = "transparent";
|
|
19900
|
+
this.textArea.style.fontStyle = fontStyle;
|
|
19901
|
+
this.textArea.style.fontVariant = textNode.fontVariant();
|
|
19902
|
+
this.textArea.style.textDecoration = textNode.textDecoration();
|
|
19903
|
+
this.textArea.style.textAlign = textNode.align();
|
|
19904
|
+
this.textArea.style.color = `${textNode.fill()}`;
|
|
19560
19905
|
}
|
|
19561
19906
|
createTextAreaDOM(textNode, position) {
|
|
19562
19907
|
const stage = this.instance.getStage();
|
|
19563
|
-
|
|
19564
|
-
textAreaSuperContainer.id = `${textNode.id()}_supercontainer`;
|
|
19565
|
-
textAreaSuperContainer.style.position = "absolute";
|
|
19566
|
-
textAreaSuperContainer.style.top = "0px";
|
|
19567
|
-
textAreaSuperContainer.style.left = "0px";
|
|
19568
|
-
textAreaSuperContainer.style.bottom = "0px";
|
|
19569
|
-
textAreaSuperContainer.style.right = "0px";
|
|
19570
|
-
textAreaSuperContainer.style.overflow = "hidden";
|
|
19571
|
-
textAreaSuperContainer.style.pointerEvents = "none";
|
|
19572
|
-
|
|
19573
|
-
textAreaContainer.id = `${textNode.id()}_container`;
|
|
19908
|
+
this.textAreaSuperContainer = document.createElement("div");
|
|
19909
|
+
this.textAreaSuperContainer.id = `${textNode.id()}_supercontainer`;
|
|
19910
|
+
this.textAreaSuperContainer.style.position = "absolute";
|
|
19911
|
+
this.textAreaSuperContainer.style.top = "0px";
|
|
19912
|
+
this.textAreaSuperContainer.style.left = "0px";
|
|
19913
|
+
this.textAreaSuperContainer.style.bottom = "0px";
|
|
19914
|
+
this.textAreaSuperContainer.style.right = "0px";
|
|
19915
|
+
this.textAreaSuperContainer.style.overflow = "hidden";
|
|
19916
|
+
this.textAreaSuperContainer.style.pointerEvents = "none";
|
|
19917
|
+
this.textAreaContainer = document.createElement("div");
|
|
19918
|
+
this.textAreaContainer.id = `${textNode.id()}_container`;
|
|
19574
19919
|
this.textArea = document.createElement("textarea");
|
|
19575
19920
|
this.textArea.id = textNode.id();
|
|
19576
|
-
textAreaContainer.appendChild(this.textArea);
|
|
19577
|
-
textAreaSuperContainer.appendChild(textAreaContainer);
|
|
19578
|
-
stage.container().appendChild(textAreaSuperContainer);
|
|
19579
|
-
textAreaContainer.style.pointerEvents = "auto";
|
|
19580
|
-
textAreaContainer.style.backgroundColor = "transparent";
|
|
19921
|
+
this.textAreaContainer.appendChild(this.textArea);
|
|
19922
|
+
this.textAreaSuperContainer.appendChild(this.textAreaContainer);
|
|
19923
|
+
stage.container().appendChild(this.textAreaSuperContainer);
|
|
19924
|
+
this.textAreaContainer.style.pointerEvents = "auto";
|
|
19925
|
+
this.textAreaContainer.style.backgroundColor = "transparent";
|
|
19581
19926
|
this.textArea.style.pointerEvents = "auto";
|
|
19582
19927
|
this.instance.addEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
|
|
19583
19928
|
this.instance.addEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
|
|
19584
19929
|
window.weaveTextEditing[textNode.id()] = "editing";
|
|
19585
19930
|
this.textArea.value = textNode.text();
|
|
19586
19931
|
this.textArea.id = textNode.id();
|
|
19587
|
-
textAreaContainer.style.overflow = "hidden";
|
|
19588
|
-
textAreaContainer.style.display = "flex";
|
|
19589
|
-
textAreaContainer.style.justifyContent = "start";
|
|
19590
|
-
if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
|
|
19591
|
-
if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
|
|
19592
|
-
if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
|
|
19593
|
-
textAreaContainer.style.position = "absolute";
|
|
19594
|
-
textAreaContainer.style.top = position.y + "px";
|
|
19595
|
-
textAreaContainer.style.left = position.x + "px";
|
|
19932
|
+
this.textAreaContainer.style.overflow = "hidden";
|
|
19933
|
+
this.textAreaContainer.style.display = "flex";
|
|
19934
|
+
this.textAreaContainer.style.justifyContent = "start";
|
|
19935
|
+
if (textNode.getAttrs().verticalAlign === "top") this.textAreaContainer.style.alignItems = "start";
|
|
19936
|
+
if (textNode.getAttrs().verticalAlign === "middle") this.textAreaContainer.style.alignItems = "center";
|
|
19937
|
+
if (textNode.getAttrs().verticalAlign === "bottom") this.textAreaContainer.style.alignItems = "end";
|
|
19938
|
+
this.textAreaContainer.style.position = "absolute";
|
|
19939
|
+
this.textAreaContainer.style.top = position.y + "px";
|
|
19940
|
+
this.textAreaContainer.style.left = position.x + "px";
|
|
19596
19941
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
19597
|
-
textAreaContainer.style.width = this.textArea.scrollWidth + "px";
|
|
19598
|
-
textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19942
|
+
this.textAreaContainer.style.width = this.textArea.scrollWidth + "px";
|
|
19943
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19599
19944
|
}
|
|
19600
19945
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19601
|
-
textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19602
|
-
textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19946
|
+
this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19947
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19603
19948
|
}
|
|
19604
19949
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
|
|
19605
|
-
textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19606
|
-
textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19950
|
+
this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19951
|
+
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + 2 + "px";
|
|
19607
19952
|
}
|
|
19608
|
-
textAreaContainer.style.border = "solid 1px #1e40af";
|
|
19953
|
+
this.textAreaContainer.style.border = "solid 1px #1e40af";
|
|
19609
19954
|
this.textArea.style.position = "absolute";
|
|
19610
19955
|
this.textArea.style.top = "0px";
|
|
19611
19956
|
this.textArea.style.left = "0px";
|
|
@@ -19623,30 +19968,33 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19623
19968
|
this.textArea.style.outline = "none";
|
|
19624
19969
|
this.textArea.style.resize = "none";
|
|
19625
19970
|
this.textArea.style.backgroundColor = "transparent";
|
|
19626
|
-
textAreaContainer.style.transformOrigin = "left top";
|
|
19627
|
-
this.mimicTextNode(textNode
|
|
19971
|
+
this.textAreaContainer.style.transformOrigin = "left top";
|
|
19972
|
+
this.mimicTextNode(textNode);
|
|
19628
19973
|
this.textArea.onfocus = () => {
|
|
19629
|
-
this.textAreaDomResize(
|
|
19974
|
+
this.textAreaDomResize(textNode);
|
|
19630
19975
|
};
|
|
19631
19976
|
this.textArea.onkeydown = () => {
|
|
19632
|
-
this.textAreaDomResize(
|
|
19977
|
+
this.textAreaDomResize(textNode);
|
|
19633
19978
|
};
|
|
19634
19979
|
this.textArea.onkeyup = () => {
|
|
19635
|
-
this.textAreaDomResize(
|
|
19980
|
+
this.textAreaDomResize(textNode);
|
|
19636
19981
|
};
|
|
19637
19982
|
this.textArea.onpaste = () => {
|
|
19638
|
-
this.textAreaDomResize(
|
|
19983
|
+
this.textAreaDomResize(textNode);
|
|
19639
19984
|
};
|
|
19640
19985
|
this.textArea.oninput = () => {
|
|
19641
|
-
this.textAreaDomResize(
|
|
19986
|
+
this.textAreaDomResize(textNode);
|
|
19642
19987
|
};
|
|
19643
|
-
textAreaSuperContainer.addEventListener("scroll", () => {
|
|
19644
|
-
textAreaSuperContainer
|
|
19645
|
-
|
|
19988
|
+
this.textAreaSuperContainer.addEventListener("scroll", () => {
|
|
19989
|
+
if (this.textAreaSuperContainer) {
|
|
19990
|
+
this.textAreaSuperContainer.scrollTop = 0;
|
|
19991
|
+
this.textAreaSuperContainer.scrollLeft = 0;
|
|
19992
|
+
}
|
|
19646
19993
|
});
|
|
19647
|
-
textAreaContainer.addEventListener("scroll", () => {
|
|
19648
|
-
textAreaContainer
|
|
19649
|
-
textAreaContainer.
|
|
19994
|
+
this.textAreaContainer.addEventListener("scroll", () => {
|
|
19995
|
+
if (!this.textAreaContainer) return;
|
|
19996
|
+
this.textAreaContainer.scrollTop = 0;
|
|
19997
|
+
this.textAreaContainer.scrollLeft = 0;
|
|
19650
19998
|
});
|
|
19651
19999
|
this.textArea.addEventListener("scroll", () => {
|
|
19652
20000
|
if (!this.textArea) return;
|
|
@@ -19656,11 +20004,11 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19656
20004
|
const rotation = textNode.getAbsoluteRotation();
|
|
19657
20005
|
if (rotation) {
|
|
19658
20006
|
const transform$1 = "rotate(" + rotation + "deg)";
|
|
19659
|
-
textAreaContainer.style.transform = transform$1;
|
|
20007
|
+
this.textAreaContainer.style.transform = transform$1;
|
|
19660
20008
|
}
|
|
19661
20009
|
const measures = textNode.measureSize(textNode.text());
|
|
19662
20010
|
const px = 0 * stage.scaleX();
|
|
19663
|
-
const py =
|
|
20011
|
+
const py = measures.actualBoundingBoxDescent * stage.scaleY();
|
|
19664
20012
|
let transform = "";
|
|
19665
20013
|
transform += "translateX(" + px + "px)";
|
|
19666
20014
|
transform += "translateY(" + py + "px)";
|
|
@@ -19673,6 +20021,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19673
20021
|
textNode.width(textAreaWidth + 3.2);
|
|
19674
20022
|
}
|
|
19675
20023
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) textNode.height((this.textArea.scrollHeight + 1.6) * (1 / textNode.getAbsoluteScale().x));
|
|
20024
|
+
console.log({ text: this.textArea.value });
|
|
19676
20025
|
textNode.text(this.textArea.value);
|
|
19677
20026
|
this.removeTextAreaDOM(textNode);
|
|
19678
20027
|
this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
|
|
@@ -19686,10 +20035,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19686
20035
|
textNode.text(this.textArea.value);
|
|
19687
20036
|
if (this.textArea && textNode) {
|
|
19688
20037
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19689
|
-
textAreaContainer
|
|
19690
|
-
|
|
20038
|
+
if (this.textAreaContainer) {
|
|
20039
|
+
this.textAreaContainer.style.height = "auto";
|
|
20040
|
+
this.textAreaContainer.style.height = this.textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
|
|
20041
|
+
}
|
|
19691
20042
|
}
|
|
19692
|
-
this.textAreaDomResize(
|
|
20043
|
+
this.textAreaDomResize(textNode);
|
|
19693
20044
|
}
|
|
19694
20045
|
};
|
|
19695
20046
|
this.textArea.addEventListener("keydown", handleKeyDown);
|
|
@@ -19718,52 +20069,47 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19718
20069
|
this.editing = true;
|
|
19719
20070
|
}
|
|
19720
20071
|
updateTextAreaDOM(textNode) {
|
|
19721
|
-
|
|
19722
|
-
const textArea = document.getElementById(textNode.id());
|
|
19723
|
-
if (!textAreaContainer || !textArea) return;
|
|
20072
|
+
if (!this.textAreaContainer || !this.textArea) return;
|
|
19724
20073
|
const stage = this.instance.getStage();
|
|
19725
20074
|
const textPosition = textNode.getClientRect();
|
|
19726
20075
|
const position = {
|
|
19727
20076
|
x: textPosition.x,
|
|
19728
20077
|
y: textPosition.y
|
|
19729
20078
|
};
|
|
19730
|
-
textAreaContainer.style.top = position.y + "px";
|
|
19731
|
-
textAreaContainer.style.left = position.x + "px";
|
|
19732
|
-
if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
|
|
19733
|
-
if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
|
|
19734
|
-
if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
|
|
19735
|
-
this.mimicTextNode(textNode
|
|
19736
|
-
this.textAreaDomResize(
|
|
19737
|
-
this.textAreaDomResize(
|
|
20079
|
+
this.textAreaContainer.style.top = position.y + "px";
|
|
20080
|
+
this.textAreaContainer.style.left = position.x + "px";
|
|
20081
|
+
if (textNode.getAttrs().verticalAlign === "top") this.textAreaContainer.style.alignItems = "start";
|
|
20082
|
+
if (textNode.getAttrs().verticalAlign === "middle") this.textAreaContainer.style.alignItems = "center";
|
|
20083
|
+
if (textNode.getAttrs().verticalAlign === "bottom") this.textAreaContainer.style.alignItems = "end";
|
|
20084
|
+
this.mimicTextNode(textNode);
|
|
20085
|
+
this.textAreaDomResize(textNode);
|
|
20086
|
+
this.textAreaDomResize(textNode);
|
|
19738
20087
|
const rotation = textNode.getAbsoluteRotation();
|
|
19739
20088
|
if (rotation) {
|
|
19740
20089
|
const transform$1 = "rotate(" + rotation + "deg)";
|
|
19741
|
-
textAreaContainer.style.transform = transform$1;
|
|
20090
|
+
this.textAreaContainer.style.transform = transform$1;
|
|
19742
20091
|
}
|
|
19743
20092
|
const px = 0;
|
|
19744
20093
|
const py = -3 * stage.scaleY();
|
|
19745
20094
|
let transform = "";
|
|
19746
20095
|
transform += "translateX(" + px + "px)";
|
|
19747
20096
|
transform += "translateY(" + py + "px)";
|
|
19748
|
-
textArea.style.transform = transform;
|
|
20097
|
+
this.textArea.style.transform = transform;
|
|
19749
20098
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
19750
20099
|
if (selectionPlugin) {
|
|
19751
20100
|
const tr = selectionPlugin.getTransformer();
|
|
19752
20101
|
this.instance.disablePlugin("nodesSelection");
|
|
19753
20102
|
tr.hide();
|
|
19754
20103
|
}
|
|
20104
|
+
console.log(`Updating text area for text node ${textNode.id()}`, this.editing);
|
|
19755
20105
|
if (this.editing) textNode.visible(false);
|
|
19756
20106
|
else textNode.visible(true);
|
|
19757
20107
|
}
|
|
19758
20108
|
removeTextAreaDOM(textNode) {
|
|
20109
|
+
this.editing = false;
|
|
19759
20110
|
const stage = this.instance.getStage();
|
|
19760
20111
|
delete window.weaveTextEditing[textNode.id()];
|
|
19761
|
-
|
|
19762
|
-
if (textAreaSuperContainer) textAreaSuperContainer.remove();
|
|
19763
|
-
const textAreaContainer = document.getElementById(`${textNode.id()}_container`);
|
|
19764
|
-
if (textAreaContainer) textAreaContainer.remove();
|
|
19765
|
-
const textArea = document.getElementById(textNode.id());
|
|
19766
|
-
if (textArea) textArea.remove();
|
|
20112
|
+
if (this.textAreaSuperContainer) this.textAreaSuperContainer.remove();
|
|
19767
20113
|
textNode.visible(true);
|
|
19768
20114
|
this.updateNode(textNode);
|
|
19769
20115
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -19776,7 +20122,6 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19776
20122
|
}
|
|
19777
20123
|
this.instance.triggerAction("selectionTool");
|
|
19778
20124
|
}
|
|
19779
|
-
this.editing = false;
|
|
19780
20125
|
stage.container().tabIndex = 1;
|
|
19781
20126
|
stage.container().click();
|
|
19782
20127
|
stage.container().focus();
|
|
@@ -19848,7 +20193,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
19848
20193
|
this.instance.addEventListener("onStageDrop", (e) => {
|
|
19849
20194
|
if (window.weaveDragImageURL) {
|
|
19850
20195
|
this.instance.getStage().setPointersPositions(e);
|
|
19851
|
-
const position = this.instance.getStage().
|
|
20196
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
19852
20197
|
this.instance.triggerAction("imageTool", {
|
|
19853
20198
|
imageURL: window.weaveDragImageURL,
|
|
19854
20199
|
position
|
|
@@ -19924,8 +20269,8 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
19924
20269
|
stage.container().style.cursor = "crosshair";
|
|
19925
20270
|
stage.container().focus();
|
|
19926
20271
|
if (position) {
|
|
19927
|
-
this.handleAdding(position);
|
|
19928
20272
|
this.setState(IMAGE_TOOL_STATE.ADDING);
|
|
20273
|
+
this.handleAdding(position);
|
|
19929
20274
|
return;
|
|
19930
20275
|
}
|
|
19931
20276
|
if (this.imageId) {
|
|
@@ -20170,6 +20515,14 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20170
20515
|
});
|
|
20171
20516
|
this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
|
|
20172
20517
|
};
|
|
20518
|
+
this.instance.getStage().on("pointerdown", (e) => {
|
|
20519
|
+
const isStage = e.target instanceof konva.default.Stage;
|
|
20520
|
+
const isContainerEmptyArea = typeof e.target.getAttrs().isContainerPrincipal !== "undefined" && !e.target.getAttrs().isContainerPrincipal;
|
|
20521
|
+
if (isStage || isContainerEmptyArea) this.cancel();
|
|
20522
|
+
});
|
|
20523
|
+
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
20524
|
+
if (typeof activeAction !== "undefined") this.cancel();
|
|
20525
|
+
});
|
|
20173
20526
|
this.cropRect.on("dragstart", (e) => {
|
|
20174
20527
|
this.instance.emitEvent("onDrag", e.target);
|
|
20175
20528
|
});
|
|
@@ -20204,6 +20557,7 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20204
20557
|
if (!["Enter", "Escape"].includes(e.key)) return;
|
|
20205
20558
|
this.image.setAttrs({ cropping: false });
|
|
20206
20559
|
if (e.key === "Enter") this.handleClipEnd();
|
|
20560
|
+
const stage = this.instance.getStage();
|
|
20207
20561
|
this.onClose();
|
|
20208
20562
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
20209
20563
|
utilityLayer?.destroyChildren();
|
|
@@ -20224,6 +20578,8 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20224
20578
|
selectionTransformer.forceUpdate();
|
|
20225
20579
|
}, 0);
|
|
20226
20580
|
}
|
|
20581
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
20582
|
+
this.instance.emitEvent("onImageCropEnd", { instance: this.image });
|
|
20227
20583
|
}
|
|
20228
20584
|
drawGridLines(x, y, width, height) {
|
|
20229
20585
|
if (!this.image.getAttrs().cropping) return;
|
|
@@ -20376,6 +20732,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20376
20732
|
constructor(params) {
|
|
20377
20733
|
super();
|
|
20378
20734
|
const { config } = params ?? {};
|
|
20735
|
+
this.tapStart = {
|
|
20736
|
+
x: 0,
|
|
20737
|
+
y: 0,
|
|
20738
|
+
time: 0
|
|
20739
|
+
};
|
|
20740
|
+
this.lastTapTime = 0;
|
|
20379
20741
|
this.config = {
|
|
20380
20742
|
crossOrigin: config?.crossOrigin ?? "anonymous",
|
|
20381
20743
|
transform: {
|
|
@@ -20389,17 +20751,40 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20389
20751
|
}
|
|
20390
20752
|
triggerCrop(imageNode) {
|
|
20391
20753
|
const stage = this.instance.getStage();
|
|
20754
|
+
stage.mode(WEAVE_STAGE_MODE.cropping);
|
|
20392
20755
|
const image = stage.findOne(`#${imageNode.getAttrs().id}`);
|
|
20393
20756
|
const internalImage = image?.findOne(`#${image.getAttrs().id}-image`);
|
|
20394
20757
|
const cropGroup = image?.findOne(`#${image.getAttrs().id}-cropGroup`);
|
|
20395
20758
|
if (!image || !internalImage || !cropGroup) return;
|
|
20396
20759
|
this.imageCrop = new WeaveImageCrop(this.instance, this, image, internalImage, cropGroup);
|
|
20397
20760
|
this.imageCrop.show(() => {
|
|
20761
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
20398
20762
|
this.instance.emitEvent("onImageCropEnd", { instance: image });
|
|
20399
20763
|
this.imageCrop = null;
|
|
20400
20764
|
});
|
|
20401
20765
|
this.instance.emitEvent("onImageCropStart", { instance: image });
|
|
20402
20766
|
}
|
|
20767
|
+
closeCrop = (imageNode, type) => {
|
|
20768
|
+
if (!this.imageCrop) return;
|
|
20769
|
+
const stage = this.instance.getStage();
|
|
20770
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
20771
|
+
if (type === WEAVE_IMAGE_CROP_END_TYPE.ACCEPT) {
|
|
20772
|
+
this.imageCrop.accept();
|
|
20773
|
+
this.instance.emitEvent("onImageCropEnd", { instance: imageNode });
|
|
20774
|
+
}
|
|
20775
|
+
if (type === WEAVE_IMAGE_CROP_END_TYPE.CANCEL) {
|
|
20776
|
+
this.imageCrop.cancel();
|
|
20777
|
+
this.instance.emitEvent("onImageCropEnd", { instance: imageNode });
|
|
20778
|
+
}
|
|
20779
|
+
};
|
|
20780
|
+
resetCrop = (imageNode) => {
|
|
20781
|
+
const internalImage = imageNode.findOne(`#${imageNode.getAttrs().id}-image`);
|
|
20782
|
+
const cropGroup = imageNode.findOne(`#${imageNode.getAttrs().id}-cropGroup`);
|
|
20783
|
+
if (!internalImage || !cropGroup) return;
|
|
20784
|
+
const imageCrop = new WeaveImageCrop(this.instance, this, imageNode, internalImage, cropGroup);
|
|
20785
|
+
imageCrop.unCrop();
|
|
20786
|
+
this.cachedCropInfo[imageNode.getAttrs().id ?? ""] = void 0;
|
|
20787
|
+
};
|
|
20403
20788
|
onRender(props) {
|
|
20404
20789
|
const imageProperties = props.imageProperties;
|
|
20405
20790
|
const imageProps = props;
|
|
@@ -20426,23 +20811,10 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20426
20811
|
this.cachedCropInfo[image$1.getAttrs().id ?? ""] = void 0;
|
|
20427
20812
|
};
|
|
20428
20813
|
image.triggerCrop = () => {
|
|
20429
|
-
|
|
20430
|
-
const image$1 = stage.findOne(`#${id}`);
|
|
20431
|
-
if (!image$1) return;
|
|
20432
|
-
this.triggerCrop(image$1);
|
|
20814
|
+
this.triggerCrop(image);
|
|
20433
20815
|
};
|
|
20434
20816
|
image.closeCrop = (type) => {
|
|
20435
|
-
|
|
20436
|
-
const image$1 = stage.findOne(`#${id}`);
|
|
20437
|
-
if (!image$1 || !this.imageCrop) return;
|
|
20438
|
-
if (type === WEAVE_IMAGE_CROP_END_TYPE.ACCEPT) {
|
|
20439
|
-
this.imageCrop.accept();
|
|
20440
|
-
this.instance.emitEvent("onImageCropEnd", { instance: image$1 });
|
|
20441
|
-
}
|
|
20442
|
-
if (type === WEAVE_IMAGE_CROP_END_TYPE.CANCEL) {
|
|
20443
|
-
this.imageCrop.cancel();
|
|
20444
|
-
this.instance.emitEvent("onImageCropEnd", { instance: image$1 });
|
|
20445
|
-
}
|
|
20817
|
+
this.closeCrop(image, type);
|
|
20446
20818
|
};
|
|
20447
20819
|
image.resetCrop = () => {
|
|
20448
20820
|
const stage = this.instance.getStage();
|
|
@@ -20486,7 +20858,8 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20486
20858
|
height: 0,
|
|
20487
20859
|
strokeScaleEnabled: true,
|
|
20488
20860
|
draggable: false,
|
|
20489
|
-
visible: false
|
|
20861
|
+
visible: false,
|
|
20862
|
+
name: void 0
|
|
20490
20863
|
});
|
|
20491
20864
|
image.add(internalImage);
|
|
20492
20865
|
const cropGroup = new konva.default.Group({
|
|
@@ -20499,13 +20872,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20499
20872
|
});
|
|
20500
20873
|
image.add(cropGroup);
|
|
20501
20874
|
this.setupDefaultNodeEvents(image);
|
|
20502
|
-
image.
|
|
20503
|
-
evt.cancelBubble = true;
|
|
20875
|
+
image.dblClick = () => {
|
|
20504
20876
|
if (image.getAttrs().cropping ?? false) return;
|
|
20505
20877
|
if (!internalImage.getAttr("image")) return;
|
|
20506
20878
|
if (!(this.isSelecting() && this.isNodeSelected(image))) return;
|
|
20507
20879
|
this.triggerCrop(image);
|
|
20508
|
-
}
|
|
20880
|
+
};
|
|
20509
20881
|
const imageActionTool = this.getImageToolAction();
|
|
20510
20882
|
const preloadImg = imageActionTool.getPreloadedImage(imageProps.id);
|
|
20511
20883
|
if (preloadImg) {
|
|
@@ -20962,30 +21334,18 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
20962
21334
|
const frame = new konva.default.Group({
|
|
20963
21335
|
...frameParams,
|
|
20964
21336
|
id,
|
|
21337
|
+
isContainerPrincipal: true,
|
|
20965
21338
|
containerId: `${id}-group-internal`,
|
|
21339
|
+
measureContainerId: `${id}-selection-area`,
|
|
20966
21340
|
containerOffsetX: 0,
|
|
20967
21341
|
containerOffsetY: borderWidth,
|
|
20968
21342
|
width: props.frameWidth,
|
|
20969
21343
|
height: props.frameHeight,
|
|
20970
21344
|
fill: "transparent",
|
|
20971
|
-
draggable:
|
|
20972
|
-
clip: void 0
|
|
21345
|
+
draggable: true,
|
|
21346
|
+
clip: void 0,
|
|
21347
|
+
name: "node containerCapable"
|
|
20973
21348
|
});
|
|
20974
|
-
frame.getRealClientRect = function(config) {
|
|
20975
|
-
const node = frame.getStage()?.findOne(`#${`${id}-selector-area`}`);
|
|
20976
|
-
const nodeTitle = frame.getStage()?.findOne(`#${`${id}-title`}`);
|
|
20977
|
-
if (!node || !nodeTitle) return {
|
|
20978
|
-
x: 0,
|
|
20979
|
-
y: 0,
|
|
20980
|
-
width: 0,
|
|
20981
|
-
height: 0
|
|
20982
|
-
};
|
|
20983
|
-
const rectContainer = node.getClientRect(config);
|
|
20984
|
-
const rectTitle = nodeTitle.getClientRect(config);
|
|
20985
|
-
rectContainer.y = rectContainer.y - rectTitle.height - titleMargin;
|
|
20986
|
-
rectContainer.height = rectContainer.height + rectTitle.height + titleMargin;
|
|
20987
|
-
return rectContainer;
|
|
20988
|
-
};
|
|
20989
21349
|
this.setupDefaultNodeAugmentation(frame);
|
|
20990
21350
|
const frameInternalGroup = new konva.default.Group({
|
|
20991
21351
|
id: `${id}-selector`,
|
|
@@ -21029,97 +21389,15 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21029
21389
|
draggable: false
|
|
21030
21390
|
});
|
|
21031
21391
|
const textMeasures = text.measureSize(text.getAttrs().text ?? "");
|
|
21392
|
+
const textWidth = textMeasures.width;
|
|
21032
21393
|
const textHeight = textMeasures.height;
|
|
21033
21394
|
text.y(-textHeight - titleMargin);
|
|
21395
|
+
text.width(textWidth);
|
|
21034
21396
|
text.height(textHeight);
|
|
21035
21397
|
frameInternalGroup.add(text);
|
|
21036
|
-
|
|
21037
|
-
...frameParams,
|
|
21038
|
-
id: `${id}-selector-area`,
|
|
21039
|
-
name: "node",
|
|
21040
|
-
nodeId: id,
|
|
21041
|
-
containerId: `${id}-group-internal`,
|
|
21042
|
-
x: 0,
|
|
21043
|
-
y: 0,
|
|
21044
|
-
strokeWidth: 0,
|
|
21045
|
-
strokeScaleEnabled: false,
|
|
21046
|
-
width: props.frameWidth,
|
|
21047
|
-
height: props.frameHeight,
|
|
21048
|
-
fill: "transparent",
|
|
21049
|
-
draggable: false
|
|
21050
|
-
});
|
|
21051
|
-
selectorArea.getTransformerProperties = () => {
|
|
21398
|
+
frame.getTransformerProperties = () => {
|
|
21052
21399
|
return this.config.transform;
|
|
21053
21400
|
};
|
|
21054
|
-
selectorArea.updatePosition = (position) => {
|
|
21055
|
-
frame.setAbsolutePosition(position);
|
|
21056
|
-
selectorArea.setAttrs({
|
|
21057
|
-
x: 0,
|
|
21058
|
-
y: 0
|
|
21059
|
-
});
|
|
21060
|
-
this.instance.updateNode(this.serialize(selectorArea));
|
|
21061
|
-
};
|
|
21062
|
-
const updateFrame = (e) => {
|
|
21063
|
-
const selectorArea$1 = e.target;
|
|
21064
|
-
const stage = selectorArea$1.getStage();
|
|
21065
|
-
if (!stage) return;
|
|
21066
|
-
const absPos = selectorArea$1.getAbsolutePosition();
|
|
21067
|
-
const absRot = selectorArea$1.getAbsoluteRotation();
|
|
21068
|
-
const scaleX = selectorArea$1.scaleX();
|
|
21069
|
-
const scaleY = selectorArea$1.scaleY();
|
|
21070
|
-
selectorArea$1.x(0);
|
|
21071
|
-
selectorArea$1.y(0);
|
|
21072
|
-
frame.setAbsolutePosition(absPos);
|
|
21073
|
-
frame.rotation(absRot);
|
|
21074
|
-
frame.width(selectorArea$1.width());
|
|
21075
|
-
frame.height(selectorArea$1.height());
|
|
21076
|
-
frameInternalGroup.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21077
|
-
frameInternalGroup.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21078
|
-
background.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21079
|
-
background.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21080
|
-
text.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21081
|
-
const textMeasures$1 = text.measureSize(text.getAttrs().text ?? "");
|
|
21082
|
-
const textHeight$1 = textMeasures$1.height;
|
|
21083
|
-
text.height(textHeight$1 * scaleY);
|
|
21084
|
-
frameInternal.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21085
|
-
frameInternal.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21086
|
-
};
|
|
21087
|
-
const handleSelectorAreaTransform = (e) => {
|
|
21088
|
-
updateFrame(e);
|
|
21089
|
-
const node = e.target;
|
|
21090
|
-
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
21091
|
-
if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.evaluateGuidelines(e);
|
|
21092
|
-
const clonedSA = selectorArea.clone();
|
|
21093
|
-
const scaleX = clonedSA.scaleX();
|
|
21094
|
-
const scaleY = clonedSA.scaleY();
|
|
21095
|
-
clonedSA.x(0);
|
|
21096
|
-
clonedSA.y(0);
|
|
21097
|
-
clonedSA.width(Math.max(5, clonedSA.width() * scaleX));
|
|
21098
|
-
clonedSA.height(Math.max(5, clonedSA.height() * scaleY));
|
|
21099
|
-
clonedSA.scaleX(1);
|
|
21100
|
-
clonedSA.scaleY(1);
|
|
21101
|
-
e.cancelBubble = true;
|
|
21102
|
-
};
|
|
21103
|
-
selectorArea.on("transformend", (e) => {
|
|
21104
|
-
this.instance.emitEvent("onTransform", e.target);
|
|
21105
|
-
});
|
|
21106
|
-
selectorArea.on("transform", (0, import_lodash.throttle)(handleSelectorAreaTransform, 50));
|
|
21107
|
-
selectorArea.on("transformend", (e) => {
|
|
21108
|
-
this.instance.emitEvent("onTransform", null);
|
|
21109
|
-
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
21110
|
-
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
21111
|
-
const scaleX = selectorArea.scaleX();
|
|
21112
|
-
const scaleY = selectorArea.scaleY();
|
|
21113
|
-
selectorArea.x(0);
|
|
21114
|
-
selectorArea.y(0);
|
|
21115
|
-
selectorArea.width(Math.max(5, selectorArea.width() * scaleX));
|
|
21116
|
-
selectorArea.height(Math.max(5, selectorArea.height() * scaleY));
|
|
21117
|
-
selectorArea.scaleX(1);
|
|
21118
|
-
selectorArea.scaleY(1);
|
|
21119
|
-
updateFrame(e);
|
|
21120
|
-
this.instance.updateNode(this.serialize(selectorArea));
|
|
21121
|
-
});
|
|
21122
|
-
frameInternalGroup.add(selectorArea);
|
|
21123
21401
|
const frameInternal = new konva.default.Group({
|
|
21124
21402
|
id: `${id}-group-internal`,
|
|
21125
21403
|
nodeId: id,
|
|
@@ -21128,17 +21406,65 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21128
21406
|
width: props.frameWidth - borderWidth * 2,
|
|
21129
21407
|
height: props.frameHeight - borderWidth * 2,
|
|
21130
21408
|
strokeScaleEnabled: true,
|
|
21131
|
-
|
|
21409
|
+
clipFunc: (ctx) => {
|
|
21410
|
+
const width = (frameInternal.width() + borderWidth) * frameInternal.scaleX();
|
|
21411
|
+
const height = (frameInternal.height() + borderWidth) * frameInternal.scaleY();
|
|
21412
|
+
ctx.rect(-(borderWidth / 2) * frameInternal.scaleX(), -(borderWidth / 2) * frameInternal.scaleY(), width, height);
|
|
21413
|
+
},
|
|
21414
|
+
listening: true,
|
|
21415
|
+
draggable: false,
|
|
21416
|
+
isTargetable: false
|
|
21417
|
+
});
|
|
21418
|
+
frame.add(frameInternal);
|
|
21419
|
+
const selectionArea = new konva.default.Rect({
|
|
21420
|
+
...frameParams,
|
|
21421
|
+
x: 0,
|
|
21422
|
+
y: 0,
|
|
21423
|
+
width: props.frameWidth,
|
|
21424
|
+
height: props.frameHeight,
|
|
21425
|
+
hitFunc: function(ctx, shape) {
|
|
21426
|
+
ctx.beginPath();
|
|
21427
|
+
ctx.rect(0, -textHeight - titleMargin, textWidth, textHeight);
|
|
21428
|
+
ctx.fillStrokeShape(shape);
|
|
21429
|
+
},
|
|
21430
|
+
fill: "transparent",
|
|
21431
|
+
id: `${id}-selection-area`,
|
|
21432
|
+
listening: true,
|
|
21433
|
+
draggable: true,
|
|
21434
|
+
isContainerPrincipal: void 0,
|
|
21435
|
+
name: void 0
|
|
21132
21436
|
});
|
|
21133
|
-
|
|
21134
|
-
|
|
21135
|
-
|
|
21136
|
-
|
|
21437
|
+
const containerArea = new konva.default.Rect({
|
|
21438
|
+
x: 0,
|
|
21439
|
+
y: 0,
|
|
21440
|
+
width: props.frameWidth,
|
|
21441
|
+
height: props.frameHeight,
|
|
21442
|
+
hitFunc: function(ctx, shape) {
|
|
21443
|
+
ctx.beginPath();
|
|
21444
|
+
ctx.rect(0, 0, props.frameWidth, props.frameHeight);
|
|
21445
|
+
ctx.fillStrokeShape(shape);
|
|
21446
|
+
},
|
|
21447
|
+
fill: "transparent",
|
|
21448
|
+
id: `${id}-container-area`,
|
|
21449
|
+
listening: false,
|
|
21450
|
+
draggable: false
|
|
21137
21451
|
});
|
|
21138
|
-
|
|
21452
|
+
frame.getClientRect = (config) => {
|
|
21453
|
+
return containerArea.getClientRect(config);
|
|
21454
|
+
};
|
|
21455
|
+
frame.add(containerArea);
|
|
21456
|
+
frame.add(selectionArea);
|
|
21457
|
+
selectionArea.moveToTop();
|
|
21458
|
+
frameInternal.moveToTop();
|
|
21459
|
+
this.setupDefaultNodeEvents(selectionArea);
|
|
21460
|
+
selectionArea.off("transformstart");
|
|
21461
|
+
selectionArea.off("transform");
|
|
21462
|
+
selectionArea.off("transformend");
|
|
21463
|
+
selectionArea.off("dragstart");
|
|
21464
|
+
selectionArea.off("dragmove");
|
|
21465
|
+
selectionArea.off("dragend");
|
|
21139
21466
|
this.setupDefaultNodeEvents(frame);
|
|
21140
|
-
frame.
|
|
21141
|
-
frame.on("dragend", () => {});
|
|
21467
|
+
frame.off("pointerover");
|
|
21142
21468
|
frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
|
|
21143
21469
|
background.setAttrs({
|
|
21144
21470
|
stroke: onTargetLeaveBorderColor,
|
|
@@ -21156,59 +21482,30 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21156
21482
|
return frame;
|
|
21157
21483
|
}
|
|
21158
21484
|
onUpdate(nodeInstance, nextProps) {
|
|
21159
|
-
const
|
|
21160
|
-
const frameNode = nodeInstance;
|
|
21485
|
+
const stage = this.instance.getStage();
|
|
21161
21486
|
const newProps = { ...nextProps };
|
|
21162
21487
|
const { titleMargin, borderWidth } = this.config;
|
|
21163
21488
|
nodeInstance.setAttrs({
|
|
21164
21489
|
...newProps,
|
|
21490
|
+
name: "node containerCapable",
|
|
21165
21491
|
containerOffsetX: 0,
|
|
21166
21492
|
containerOffsetY: borderWidth,
|
|
21167
21493
|
clip: void 0
|
|
21168
21494
|
});
|
|
21169
|
-
const
|
|
21170
|
-
|
|
21171
|
-
|
|
21172
|
-
|
|
21173
|
-
const
|
|
21174
|
-
|
|
21175
|
-
|
|
21176
|
-
|
|
21177
|
-
|
|
21178
|
-
|
|
21179
|
-
|
|
21180
|
-
|
|
21181
|
-
|
|
21182
|
-
|
|
21183
|
-
y: 0,
|
|
21184
|
-
width: width * selectorArea.scaleX(),
|
|
21185
|
-
height: height * selectorArea.scaleY()
|
|
21186
|
-
});
|
|
21187
|
-
const background = frameNode.findOne(`#${id}-bg`);
|
|
21188
|
-
if (background) background.setAttrs({
|
|
21189
|
-
x: 0,
|
|
21190
|
-
y: 0,
|
|
21191
|
-
width: width * selectorArea.scaleX(),
|
|
21192
|
-
height: height * selectorArea.scaleY()
|
|
21193
|
-
});
|
|
21194
|
-
const text = frameNode.findOne(`#${id}-title`);
|
|
21195
|
-
if (text) {
|
|
21196
|
-
text.setAttrs({
|
|
21197
|
-
x: 0,
|
|
21198
|
-
text: nextProps.title,
|
|
21199
|
-
width: width * selectorArea.scaleX()
|
|
21200
|
-
});
|
|
21201
|
-
const textMeasures = text.measureSize(text.getAttrs().text ?? "");
|
|
21202
|
-
const textHeight = textMeasures.height;
|
|
21203
|
-
text.y(-textHeight - titleMargin);
|
|
21204
|
-
text.height(textHeight * selectorArea.scaleY());
|
|
21205
|
-
}
|
|
21206
|
-
const frameInternal = frameNode.findOne(`#${id}-group-internal`);
|
|
21207
|
-
if (frameInternal) frameInternal.setAttrs({
|
|
21208
|
-
x: borderWidth,
|
|
21209
|
-
y: borderWidth,
|
|
21210
|
-
width: (width - borderWidth * 2) * selectorArea.scaleX(),
|
|
21211
|
-
height: (height - borderWidth * 2) * selectorArea.scaleY()
|
|
21495
|
+
const title = stage.findOne(`#${newProps.id}-title`);
|
|
21496
|
+
const selectionArea = stage.findOne(`#${newProps.id}-selection-area`);
|
|
21497
|
+
if (title && selectionArea) {
|
|
21498
|
+
title.text(newProps.title);
|
|
21499
|
+
const textMeasures = title.measureSize(title.getAttrs().text ?? "");
|
|
21500
|
+
const textWidth = textMeasures.width;
|
|
21501
|
+
const textHeight = textMeasures.height;
|
|
21502
|
+
title.y(-textHeight - titleMargin);
|
|
21503
|
+
title.width(textWidth);
|
|
21504
|
+
title.height(textHeight);
|
|
21505
|
+
selectionArea.hitFunc(function(ctx, shape) {
|
|
21506
|
+
ctx.beginPath();
|
|
21507
|
+
ctx.rect(0, -textHeight - titleMargin, textWidth, textHeight);
|
|
21508
|
+
ctx.fillStrokeShape(shape);
|
|
21212
21509
|
});
|
|
21213
21510
|
}
|
|
21214
21511
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -21217,10 +21514,8 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21217
21514
|
serialize(instance) {
|
|
21218
21515
|
const stage = this.instance.getStage();
|
|
21219
21516
|
const attrs = instance.getAttrs();
|
|
21220
|
-
|
|
21221
|
-
|
|
21222
|
-
let frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21223
|
-
if (attrs.id?.indexOf("-selector-area") !== -1) frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21517
|
+
const mainNode = instance;
|
|
21518
|
+
const frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21224
21519
|
const childrenMapped = [];
|
|
21225
21520
|
if (frameInternal) {
|
|
21226
21521
|
const children = [...frameInternal.getChildren()];
|
|
@@ -21246,10 +21541,125 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21246
21541
|
}
|
|
21247
21542
|
};
|
|
21248
21543
|
|
|
21544
|
+
//#endregion
|
|
21545
|
+
//#region src/nodes/stroke/constants.ts
|
|
21546
|
+
const WEAVE_STROKE_NODE_TYPE = "stroke";
|
|
21547
|
+
|
|
21548
|
+
//#endregion
|
|
21549
|
+
//#region src/nodes/stroke/stroke.ts
|
|
21550
|
+
var WeaveStrokeNode = class extends WeaveNode {
|
|
21551
|
+
nodeType = WEAVE_STROKE_NODE_TYPE;
|
|
21552
|
+
constructor(params) {
|
|
21553
|
+
super();
|
|
21554
|
+
const { config } = params ?? {};
|
|
21555
|
+
this.config = { transform: {
|
|
21556
|
+
...__inditextech_weave_types.WEAVE_DEFAULT_TRANSFORM_PROPERTIES,
|
|
21557
|
+
...config?.transform
|
|
21558
|
+
} };
|
|
21559
|
+
}
|
|
21560
|
+
drawStroke(strokeElements, context, shape) {
|
|
21561
|
+
context.strokeStyle = shape.getAttrs().stroke ?? "black";
|
|
21562
|
+
context.lineCap = "round";
|
|
21563
|
+
context.lineJoin = "round";
|
|
21564
|
+
const l = strokeElements.length - 1;
|
|
21565
|
+
if (strokeElements.length >= 3) {
|
|
21566
|
+
const xc = (strokeElements[l].x + strokeElements[l - 1].x) / 2;
|
|
21567
|
+
const yc = (strokeElements[l].y + strokeElements[l - 1].y) / 2;
|
|
21568
|
+
context.lineWidth = strokeElements[l - 1].lineWidth;
|
|
21569
|
+
context.quadraticCurveTo(strokeElements[l - 1].x, strokeElements[l - 1].y, xc, yc);
|
|
21570
|
+
context.stroke();
|
|
21571
|
+
context.beginPath();
|
|
21572
|
+
context.moveTo(xc, yc);
|
|
21573
|
+
} else {
|
|
21574
|
+
const point = strokeElements[l];
|
|
21575
|
+
context.lineWidth = point.lineWidth;
|
|
21576
|
+
context.beginPath();
|
|
21577
|
+
context.moveTo(point.x, point.y);
|
|
21578
|
+
context.stroke();
|
|
21579
|
+
}
|
|
21580
|
+
}
|
|
21581
|
+
onRender(props) {
|
|
21582
|
+
const stroke = new konva.default.Shape({
|
|
21583
|
+
...props,
|
|
21584
|
+
name: "node",
|
|
21585
|
+
sceneFunc: (context, shape) => {
|
|
21586
|
+
context.beginPath();
|
|
21587
|
+
const strokeElements = shape.getAttrs().strokeElements;
|
|
21588
|
+
const strokePath = [];
|
|
21589
|
+
strokeElements.forEach((point) => {
|
|
21590
|
+
strokePath.push(point);
|
|
21591
|
+
this.drawStroke(strokePath, context, shape);
|
|
21592
|
+
});
|
|
21593
|
+
},
|
|
21594
|
+
hitFunc: (context, shape) => {
|
|
21595
|
+
context.beginPath();
|
|
21596
|
+
context.rect(0, 0, shape.width(), shape.height());
|
|
21597
|
+
context.closePath();
|
|
21598
|
+
context.fillStrokeShape(shape);
|
|
21599
|
+
}
|
|
21600
|
+
});
|
|
21601
|
+
this.setupDefaultNodeAugmentation(stroke);
|
|
21602
|
+
stroke.getTransformerProperties = () => {
|
|
21603
|
+
return this.config.transform;
|
|
21604
|
+
};
|
|
21605
|
+
this.setupDefaultNodeEvents(stroke);
|
|
21606
|
+
return stroke;
|
|
21607
|
+
}
|
|
21608
|
+
onUpdate(nodeInstance, nextProps) {
|
|
21609
|
+
nodeInstance.setAttrs({ ...nextProps });
|
|
21610
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
21611
|
+
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
21612
|
+
}
|
|
21613
|
+
scaleReset(node) {
|
|
21614
|
+
const strokeNode = node;
|
|
21615
|
+
const oldPoints = [...strokeNode.getAttrs().strokeElements];
|
|
21616
|
+
const newPoints = [];
|
|
21617
|
+
for (const actPoint of oldPoints) {
|
|
21618
|
+
const point = {
|
|
21619
|
+
...actPoint,
|
|
21620
|
+
x: actPoint.x * strokeNode.scaleX(),
|
|
21621
|
+
y: actPoint.y * strokeNode.scaleY()
|
|
21622
|
+
};
|
|
21623
|
+
newPoints.push(point);
|
|
21624
|
+
}
|
|
21625
|
+
strokeNode.setAttrs({ strokeElements: newPoints });
|
|
21626
|
+
node.width(Math.max(5, node.width() * node.scaleX()));
|
|
21627
|
+
node.height(Math.max(5, node.height() * node.scaleY()));
|
|
21628
|
+
node.scaleX(1);
|
|
21629
|
+
node.scaleY(1);
|
|
21630
|
+
}
|
|
21631
|
+
serialize(instance) {
|
|
21632
|
+
const attrs = instance.getAttrs();
|
|
21633
|
+
const cleanedAttrs = { ...attrs };
|
|
21634
|
+
delete cleanedAttrs.draggable;
|
|
21635
|
+
delete cleanedAttrs.sceneFunc;
|
|
21636
|
+
delete cleanedAttrs.hitFunc;
|
|
21637
|
+
return {
|
|
21638
|
+
key: attrs.id ?? "",
|
|
21639
|
+
type: attrs.nodeType,
|
|
21640
|
+
props: {
|
|
21641
|
+
...cleanedAttrs,
|
|
21642
|
+
id: attrs.id ?? "",
|
|
21643
|
+
nodeType: attrs.nodeType,
|
|
21644
|
+
children: []
|
|
21645
|
+
}
|
|
21646
|
+
};
|
|
21647
|
+
}
|
|
21648
|
+
};
|
|
21649
|
+
|
|
21249
21650
|
//#endregion
|
|
21250
21651
|
//#region src/plugins/stage-zoom/constants.ts
|
|
21652
|
+
const WEAVE_STAGE_ZOOM_TYPE = {
|
|
21653
|
+
MOUSE_WHEEL: "mouseWheel",
|
|
21654
|
+
PINCH_ZOOM: "pinchZoom"
|
|
21655
|
+
};
|
|
21251
21656
|
const WEAVE_STAGE_ZOOM_KEY = "stageZoom";
|
|
21252
21657
|
const WEAVE_STAGE_ZOOM_DEFAULT_CONFIG = {
|
|
21658
|
+
zoomInertia: {
|
|
21659
|
+
friction: .9,
|
|
21660
|
+
mouseWheelStep: .01,
|
|
21661
|
+
trackpadStep: .005
|
|
21662
|
+
},
|
|
21253
21663
|
zoomSteps: [
|
|
21254
21664
|
.01,
|
|
21255
21665
|
.05,
|
|
@@ -22953,15 +23363,23 @@ var import_hammer = __toESM(require_hammer(), 1);
|
|
|
22953
23363
|
var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
22954
23364
|
getLayerName = void 0;
|
|
22955
23365
|
initLayer = void 0;
|
|
23366
|
+
zooming = false;
|
|
23367
|
+
isTrackpad = false;
|
|
23368
|
+
zoomVelocity = 0;
|
|
23369
|
+
zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL;
|
|
23370
|
+
initialScale = 0;
|
|
23371
|
+
lastTime = 0;
|
|
23372
|
+
center = {
|
|
23373
|
+
x: 0,
|
|
23374
|
+
y: 0
|
|
23375
|
+
};
|
|
22956
23376
|
defaultStep = 3;
|
|
22957
23377
|
constructor(params) {
|
|
22958
23378
|
super();
|
|
22959
23379
|
const { config } = params ?? {};
|
|
22960
|
-
this.config =
|
|
22961
|
-
...WEAVE_STAGE_ZOOM_DEFAULT_CONFIG,
|
|
22962
|
-
...config
|
|
22963
|
-
};
|
|
23380
|
+
this.config = (0, import_lodash.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
|
|
22964
23381
|
if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
|
|
23382
|
+
this.isTrackpad = false;
|
|
22965
23383
|
this.isCtrlOrMetaPressed = false;
|
|
22966
23384
|
this.updatedMinimumZoom = false;
|
|
22967
23385
|
this.actualStep = this.config.zoomSteps.findIndex((step) => step === this.config.defaultZoom);
|
|
@@ -23100,6 +23518,10 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23100
23518
|
const scale = Math.min(scaleX, scaleY);
|
|
23101
23519
|
return scale;
|
|
23102
23520
|
}
|
|
23521
|
+
getSelectionPlugin() {
|
|
23522
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23523
|
+
return selectionPlugin;
|
|
23524
|
+
}
|
|
23103
23525
|
fitToScreen() {
|
|
23104
23526
|
if (!this.enabled) return;
|
|
23105
23527
|
const mainLayer = this.instance.getMainLayer();
|
|
@@ -23140,7 +23562,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23140
23562
|
fitToSelection() {
|
|
23141
23563
|
if (!this.enabled) return;
|
|
23142
23564
|
const stage = this.instance.getStage();
|
|
23143
|
-
const selectionPlugin = this.
|
|
23565
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
23144
23566
|
if (!selectionPlugin) return;
|
|
23145
23567
|
const nodes = selectionPlugin.getTransformer().getNodes();
|
|
23146
23568
|
if (nodes.length === 0) return;
|
|
@@ -23214,38 +23636,68 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23214
23636
|
threshold: 0,
|
|
23215
23637
|
pointers: 2
|
|
23216
23638
|
}));
|
|
23217
|
-
|
|
23218
|
-
|
|
23219
|
-
|
|
23220
|
-
|
|
23221
|
-
|
|
23222
|
-
sc.on("pinchstart", (ev) => {
|
|
23223
|
-
initialScale = stage.scaleX();
|
|
23224
|
-
center = {
|
|
23225
|
-
x: ev.center.x,
|
|
23226
|
-
y: ev.center.y
|
|
23639
|
+
sc.on("pinchstart", (e) => {
|
|
23640
|
+
this.initialScale = this.instance.getStage().scaleX();
|
|
23641
|
+
this.center = {
|
|
23642
|
+
x: e.center.x,
|
|
23643
|
+
y: e.center.y
|
|
23227
23644
|
};
|
|
23645
|
+
this.lastTime = performance.now();
|
|
23646
|
+
});
|
|
23647
|
+
sc.on("pinchmove", (e) => {
|
|
23648
|
+
const now = performance.now();
|
|
23649
|
+
const newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], this.initialScale * e.scale));
|
|
23650
|
+
this.setZoom(newScale, false, this.center);
|
|
23651
|
+
const dt = now - this.lastTime;
|
|
23652
|
+
this.zoomVelocity = (newScale - 1) / (dt * 16.6);
|
|
23653
|
+
this.lastTime = now;
|
|
23228
23654
|
});
|
|
23229
|
-
sc.on("
|
|
23230
|
-
|
|
23231
|
-
|
|
23232
|
-
this.
|
|
23655
|
+
sc.on("pinchend", () => {
|
|
23656
|
+
this.zooming = true;
|
|
23657
|
+
this.zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.PINCH_ZOOM;
|
|
23658
|
+
requestAnimationFrame(this.zoomTick.bind(this));
|
|
23233
23659
|
});
|
|
23234
23660
|
const handleWheel = (e) => {
|
|
23235
23661
|
e.evt.preventDefault();
|
|
23236
23662
|
const stage$1 = this.instance.getStage();
|
|
23237
23663
|
const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.evt.ctrlKey && e.evt.deltaMode === 0;
|
|
23238
23664
|
if (!this.enabled || !stage$1.isFocused() || !performZoom) return;
|
|
23239
|
-
const
|
|
23240
|
-
|
|
23241
|
-
|
|
23242
|
-
|
|
23243
|
-
|
|
23244
|
-
|
|
23245
|
-
|
|
23665
|
+
const delta = e.evt.deltaY > 0 ? 1 : -1;
|
|
23666
|
+
this.zoomVelocity += delta;
|
|
23667
|
+
this.isTrackpad = Math.abs(e.evt.deltaY) < 15 && e.evt.deltaMode === 0;
|
|
23668
|
+
if (!this.zooming) {
|
|
23669
|
+
this.zooming = true;
|
|
23670
|
+
this.zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL;
|
|
23671
|
+
requestAnimationFrame(this.zoomTick.bind(this));
|
|
23672
|
+
}
|
|
23246
23673
|
};
|
|
23247
23674
|
stage.on("wheel", handleWheel);
|
|
23248
23675
|
}
|
|
23676
|
+
getInertiaScale() {
|
|
23677
|
+
const stage = this.instance.getStage();
|
|
23678
|
+
let step = 1;
|
|
23679
|
+
if (this.zoomInertiaType === WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL && !this.isTrackpad) step = this.config.zoomInertia.mouseWheelStep;
|
|
23680
|
+
if (this.zoomInertiaType === WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL && this.isTrackpad) step = this.config.zoomInertia.trackpadStep;
|
|
23681
|
+
const oldScale = stage.scaleX();
|
|
23682
|
+
let newScale = oldScale * (1 - this.zoomVelocity * step);
|
|
23683
|
+
newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], newScale));
|
|
23684
|
+
return newScale;
|
|
23685
|
+
}
|
|
23686
|
+
zoomTick() {
|
|
23687
|
+
if (Math.abs(this.zoomVelocity) < .001) {
|
|
23688
|
+
this.zooming = false;
|
|
23689
|
+
return;
|
|
23690
|
+
}
|
|
23691
|
+
let pointer = this.center;
|
|
23692
|
+
if (this.zoomInertiaType === WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL) {
|
|
23693
|
+
const stage = this.instance.getStage();
|
|
23694
|
+
pointer = stage.getPointerPosition();
|
|
23695
|
+
}
|
|
23696
|
+
if (!pointer) return;
|
|
23697
|
+
this.setZoom(this.getInertiaScale(), false, pointer);
|
|
23698
|
+
this.zoomVelocity *= this.config.zoomInertia.friction;
|
|
23699
|
+
requestAnimationFrame(this.zoomTick.bind(this));
|
|
23700
|
+
}
|
|
23249
23701
|
};
|
|
23250
23702
|
|
|
23251
23703
|
//#endregion
|
|
@@ -23570,7 +24022,10 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
23570
24022
|
stage.container().focus();
|
|
23571
24023
|
this.cancelAction = cancelAction;
|
|
23572
24024
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23573
|
-
if (selectionPlugin)
|
|
24025
|
+
if (selectionPlugin) {
|
|
24026
|
+
selectionPlugin.setSelectedNodes([]);
|
|
24027
|
+
selectionPlugin.disable();
|
|
24028
|
+
}
|
|
23574
24029
|
this.setEraser();
|
|
23575
24030
|
}
|
|
23576
24031
|
cleanup() {
|
|
@@ -23638,19 +24093,23 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
23638
24093
|
return;
|
|
23639
24094
|
}
|
|
23640
24095
|
});
|
|
23641
|
-
stage.on("pointerdown", () => {
|
|
24096
|
+
stage.on("pointerdown", (e) => {
|
|
24097
|
+
this.setTapStart(e);
|
|
23642
24098
|
if (this.state === RECTANGLE_TOOL_STATE.ADDING) {
|
|
23643
24099
|
this.creating = true;
|
|
23644
24100
|
this.handleAdding();
|
|
23645
24101
|
}
|
|
23646
24102
|
});
|
|
23647
|
-
stage.on("pointermove", () => {
|
|
24103
|
+
stage.on("pointermove", (e) => {
|
|
24104
|
+
if (!this.isPressed(e)) return;
|
|
23648
24105
|
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
|
|
23649
24106
|
this.moved = true;
|
|
23650
24107
|
this.handleMovement();
|
|
23651
24108
|
}
|
|
23652
24109
|
});
|
|
23653
|
-
stage.on("pointerup", () => {
|
|
24110
|
+
stage.on("pointerup", (e) => {
|
|
24111
|
+
const isTap = this.isTap(e);
|
|
24112
|
+
if (isTap) this.moved = false;
|
|
23654
24113
|
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
|
|
23655
24114
|
this.creating = false;
|
|
23656
24115
|
this.handleSettingSize();
|
|
@@ -23813,19 +24272,23 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
23813
24272
|
return;
|
|
23814
24273
|
}
|
|
23815
24274
|
});
|
|
23816
|
-
stage.on("pointerdown", () => {
|
|
24275
|
+
stage.on("pointerdown", (e) => {
|
|
24276
|
+
this.setTapStart(e);
|
|
23817
24277
|
if (this.state === ELLIPSE_TOOL_STATE.ADDING) {
|
|
23818
24278
|
this.creating = true;
|
|
23819
24279
|
this.handleAdding();
|
|
23820
24280
|
}
|
|
23821
24281
|
});
|
|
23822
|
-
stage.on("pointermove", () => {
|
|
24282
|
+
stage.on("pointermove", (e) => {
|
|
24283
|
+
if (!this.isPressed(e)) return;
|
|
23823
24284
|
if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
|
|
23824
24285
|
this.moved = true;
|
|
23825
24286
|
this.handleMovement();
|
|
23826
24287
|
}
|
|
23827
24288
|
});
|
|
23828
|
-
stage.on("pointerup", () => {
|
|
24289
|
+
stage.on("pointerup", (e) => {
|
|
24290
|
+
const isTap = this.isTap(e);
|
|
24291
|
+
if (isTap) this.moved = false;
|
|
23829
24292
|
if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
|
|
23830
24293
|
this.creating = false;
|
|
23831
24294
|
this.handleSettingSize();
|
|
@@ -24195,11 +24658,13 @@ const BRUSH_TOOL_STATE = {
|
|
|
24195
24658
|
//#region src/actions/brush-tool/brush-tool.ts
|
|
24196
24659
|
var WeaveBrushToolAction = class extends WeaveAction {
|
|
24197
24660
|
initialized = false;
|
|
24661
|
+
lineWidth = 0;
|
|
24198
24662
|
onPropsChange = void 0;
|
|
24199
24663
|
onInit = void 0;
|
|
24200
24664
|
constructor() {
|
|
24201
24665
|
super();
|
|
24202
24666
|
this.initialized = false;
|
|
24667
|
+
this.lineWidth = 0;
|
|
24203
24668
|
this.state = BRUSH_TOOL_STATE.INACTIVE;
|
|
24204
24669
|
this.strokeId = null;
|
|
24205
24670
|
this.clickPoint = null;
|
|
@@ -24217,6 +24682,11 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
24217
24682
|
opacity: 1
|
|
24218
24683
|
};
|
|
24219
24684
|
}
|
|
24685
|
+
getPointPressure(e) {
|
|
24686
|
+
let pressure = 1;
|
|
24687
|
+
if (e.evt instanceof PointerEvent && e.evt.pointerType === "pen") pressure = e.evt.pressure;
|
|
24688
|
+
return pressure;
|
|
24689
|
+
}
|
|
24220
24690
|
setupEvents() {
|
|
24221
24691
|
const stage = this.instance.getStage();
|
|
24222
24692
|
stage.container().tabIndex = 1;
|
|
@@ -24231,75 +24701,132 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
24231
24701
|
return;
|
|
24232
24702
|
}
|
|
24233
24703
|
});
|
|
24234
|
-
|
|
24704
|
+
const handlePointerDown = (e) => {
|
|
24235
24705
|
if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
|
|
24706
|
+
const pointPressure = this.getPointPressure(e);
|
|
24707
|
+
this.lineWidth = Math.log(pointPressure + 1) * this.props.strokeWidth;
|
|
24236
24708
|
this.handleStartStroke();
|
|
24237
24709
|
e.evt.stopPropagation();
|
|
24238
|
-
}
|
|
24239
|
-
stage.on("
|
|
24710
|
+
};
|
|
24711
|
+
stage.on("pointerdown touchstart", handlePointerDown);
|
|
24712
|
+
const handlePointerMove = (e) => {
|
|
24240
24713
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
24714
|
+
const pointPressure = this.getPointPressure(e);
|
|
24715
|
+
this.lineWidth = Math.log(pointPressure + 1) * this.props.strokeWidth * .2 + this.lineWidth * .8;
|
|
24241
24716
|
this.handleMovement();
|
|
24242
24717
|
e.evt.stopPropagation();
|
|
24243
|
-
}
|
|
24244
|
-
stage.on("
|
|
24718
|
+
};
|
|
24719
|
+
stage.on("pointermove touchmove", handlePointerMove);
|
|
24720
|
+
const handlePointerUp = (e) => {
|
|
24245
24721
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
24246
24722
|
this.handleEndStroke();
|
|
24247
24723
|
e.evt.stopPropagation();
|
|
24248
|
-
}
|
|
24724
|
+
};
|
|
24725
|
+
stage.on("pointerup touchend", handlePointerUp);
|
|
24249
24726
|
this.initialized = true;
|
|
24250
24727
|
}
|
|
24251
24728
|
setState(state) {
|
|
24252
24729
|
this.state = state;
|
|
24253
24730
|
}
|
|
24731
|
+
getBoundingBox(strokeElements) {
|
|
24732
|
+
if (strokeElements.length === 0) return {
|
|
24733
|
+
x: 0,
|
|
24734
|
+
y: 0,
|
|
24735
|
+
width: 0,
|
|
24736
|
+
height: 0
|
|
24737
|
+
};
|
|
24738
|
+
let minX = strokeElements[0].x;
|
|
24739
|
+
let maxX = strokeElements[0].x;
|
|
24740
|
+
let minY = strokeElements[0].y;
|
|
24741
|
+
let maxY = strokeElements[0].y;
|
|
24742
|
+
strokeElements.forEach((point) => {
|
|
24743
|
+
minX = Math.min(minX, point.x);
|
|
24744
|
+
maxX = Math.max(maxX, point.x);
|
|
24745
|
+
minY = Math.min(minY, point.y);
|
|
24746
|
+
maxY = Math.max(maxY, point.y);
|
|
24747
|
+
});
|
|
24748
|
+
return {
|
|
24749
|
+
x: minX,
|
|
24750
|
+
y: minY,
|
|
24751
|
+
width: maxX - minX,
|
|
24752
|
+
height: maxY - minY
|
|
24753
|
+
};
|
|
24754
|
+
}
|
|
24254
24755
|
handleStartStroke() {
|
|
24255
24756
|
const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
|
|
24256
24757
|
this.clickPoint = mousePoint;
|
|
24257
24758
|
this.container = container;
|
|
24258
24759
|
this.measureContainer = measureContainer;
|
|
24259
24760
|
this.strokeId = v4_default();
|
|
24260
|
-
const nodeHandler = this.instance.getNodeHandler("
|
|
24761
|
+
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
24261
24762
|
if (nodeHandler) {
|
|
24262
24763
|
const node = nodeHandler.create(this.strokeId, {
|
|
24263
24764
|
...this.props,
|
|
24264
24765
|
strokeScaleEnabled: true,
|
|
24265
|
-
x:
|
|
24266
|
-
y:
|
|
24267
|
-
|
|
24766
|
+
x: 0,
|
|
24767
|
+
y: 0,
|
|
24768
|
+
width: 0,
|
|
24769
|
+
height: 0,
|
|
24770
|
+
strokeElements: []
|
|
24268
24771
|
});
|
|
24269
|
-
|
|
24772
|
+
const nodeInstance = nodeHandler.onRender(node.props);
|
|
24773
|
+
this.measureContainer?.add(nodeInstance);
|
|
24270
24774
|
}
|
|
24271
24775
|
this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
|
|
24272
24776
|
}
|
|
24777
|
+
handleMovement() {
|
|
24778
|
+
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
24779
|
+
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
24780
|
+
if (this.measureContainer && tempStroke) {
|
|
24781
|
+
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
24782
|
+
const newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
24783
|
+
newStrokeElements.push({
|
|
24784
|
+
x: mousePoint.x - tempStroke.x(),
|
|
24785
|
+
y: mousePoint.y - tempStroke.y(),
|
|
24786
|
+
lineWidth: this.lineWidth
|
|
24787
|
+
});
|
|
24788
|
+
const box = this.getBoundingBox(newStrokeElements);
|
|
24789
|
+
tempStroke.setAttrs({
|
|
24790
|
+
width: box.width,
|
|
24791
|
+
height: box.height,
|
|
24792
|
+
x: 0,
|
|
24793
|
+
y: 0,
|
|
24794
|
+
strokeElements: newStrokeElements
|
|
24795
|
+
});
|
|
24796
|
+
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
24797
|
+
if (nodeHandler) nodeHandler.onUpdate(tempStroke, tempStroke.getAttrs());
|
|
24798
|
+
}
|
|
24799
|
+
}
|
|
24273
24800
|
handleEndStroke() {
|
|
24274
24801
|
const stage = this.instance.getStage();
|
|
24275
24802
|
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
24276
24803
|
if (tempStroke) {
|
|
24277
|
-
const nodeHandler = this.instance.getNodeHandler("
|
|
24278
|
-
|
|
24279
|
-
|
|
24280
|
-
|
|
24281
|
-
|
|
24282
|
-
|
|
24804
|
+
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
24805
|
+
if (nodeHandler) {
|
|
24806
|
+
const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
|
|
24807
|
+
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
24808
|
+
newStrokeElements = newStrokeElements.map((point) => ({
|
|
24809
|
+
...point,
|
|
24810
|
+
x: point.x - box.x,
|
|
24811
|
+
y: point.y - box.y
|
|
24812
|
+
}));
|
|
24813
|
+
tempStroke.setAttrs({
|
|
24814
|
+
width: box.width,
|
|
24815
|
+
height: box.height,
|
|
24816
|
+
x: box.x,
|
|
24817
|
+
y: box.y,
|
|
24818
|
+
strokeElements: newStrokeElements
|
|
24819
|
+
});
|
|
24820
|
+
const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
|
|
24821
|
+
if (realNode) realNode.destroy();
|
|
24822
|
+
this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
24823
|
+
}
|
|
24283
24824
|
this.clickPoint = null;
|
|
24284
24825
|
stage.container().tabIndex = 1;
|
|
24285
24826
|
stage.container().focus();
|
|
24286
24827
|
this.setState(BRUSH_TOOL_STATE.IDLE);
|
|
24287
24828
|
}
|
|
24288
24829
|
}
|
|
24289
|
-
handleMovement() {
|
|
24290
|
-
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
24291
|
-
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
24292
|
-
if (this.measureContainer && tempStroke) {
|
|
24293
|
-
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
24294
|
-
tempStroke.points([
|
|
24295
|
-
...tempStroke.points(),
|
|
24296
|
-
mousePoint.x - tempStroke.x(),
|
|
24297
|
-
mousePoint.y - tempStroke.y()
|
|
24298
|
-
]);
|
|
24299
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24300
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempStroke));
|
|
24301
|
-
}
|
|
24302
|
-
}
|
|
24303
24830
|
trigger(cancel) {
|
|
24304
24831
|
if (!this.instance) throw new Error("Instance not defined");
|
|
24305
24832
|
if (!this.initialized) this.setupEvents();
|
|
@@ -24493,19 +25020,23 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
24493
25020
|
return;
|
|
24494
25021
|
}
|
|
24495
25022
|
});
|
|
24496
|
-
stage.on("pointerdown", () => {
|
|
25023
|
+
stage.on("pointerdown", (e) => {
|
|
25024
|
+
this.setTapStart(e);
|
|
24497
25025
|
if (this.state === STAR_TOOL_STATE.ADDING) {
|
|
24498
25026
|
this.creating = true;
|
|
24499
25027
|
this.handleAdding();
|
|
24500
25028
|
}
|
|
24501
25029
|
});
|
|
24502
|
-
stage.on("pointermove", () => {
|
|
25030
|
+
stage.on("pointermove", (e) => {
|
|
25031
|
+
if (!this.isPressed(e)) return;
|
|
24503
25032
|
if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
|
|
24504
25033
|
this.moved = true;
|
|
24505
25034
|
this.handleMovement();
|
|
24506
25035
|
}
|
|
24507
25036
|
});
|
|
24508
|
-
stage.on("pointerup", () => {
|
|
25037
|
+
stage.on("pointerup", (e) => {
|
|
25038
|
+
const isTap = this.isTap(e);
|
|
25039
|
+
if (isTap) this.moved = false;
|
|
24509
25040
|
if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
|
|
24510
25041
|
this.creating = false;
|
|
24511
25042
|
this.handleSettingSize();
|
|
@@ -24931,19 +25462,23 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
24931
25462
|
return;
|
|
24932
25463
|
}
|
|
24933
25464
|
});
|
|
24934
|
-
stage.on("pointerdown", () => {
|
|
25465
|
+
stage.on("pointerdown", (e) => {
|
|
25466
|
+
this.setTapStart(e);
|
|
24935
25467
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.ADDING) {
|
|
24936
25468
|
this.creating = true;
|
|
24937
25469
|
this.handleAdding();
|
|
24938
25470
|
}
|
|
24939
25471
|
});
|
|
24940
|
-
stage.on("pointermove", () => {
|
|
25472
|
+
stage.on("pointermove", (e) => {
|
|
25473
|
+
if (!this.isPressed(e)) return;
|
|
24941
25474
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
|
|
24942
25475
|
this.moved = true;
|
|
24943
25476
|
this.handleMovement();
|
|
24944
25477
|
}
|
|
24945
25478
|
});
|
|
24946
|
-
stage.on("pointerup", () => {
|
|
25479
|
+
stage.on("pointerup", (e) => {
|
|
25480
|
+
const isTap = this.isTap(e);
|
|
25481
|
+
if (isTap) this.moved = false;
|
|
24947
25482
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
|
|
24948
25483
|
this.creating = false;
|
|
24949
25484
|
this.handleSettingSize();
|
|
@@ -25593,8 +26128,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
25593
26128
|
};
|
|
25594
26129
|
stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
|
|
25595
26130
|
stage.on("pointermove", () => {
|
|
25596
|
-
if (
|
|
25597
|
-
this.onRender();
|
|
26131
|
+
if (this.enabled) this.onRender();
|
|
25598
26132
|
});
|
|
25599
26133
|
window.addEventListener("wheel", () => {
|
|
25600
26134
|
if (!this.enabled || this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed) return;
|
|
@@ -26360,12 +26894,16 @@ var WeaveStageDropAreaPlugin = class extends WeavePlugin {
|
|
|
26360
26894
|
initEvents() {
|
|
26361
26895
|
const stage = this.instance.getStage();
|
|
26362
26896
|
stage.container().addEventListener("dragover", (e) => {
|
|
26897
|
+
e.preventDefault();
|
|
26363
26898
|
e.stopPropagation();
|
|
26364
26899
|
});
|
|
26365
26900
|
stage.container().addEventListener("drop", (e) => {
|
|
26901
|
+
e.preventDefault();
|
|
26366
26902
|
e.stopPropagation();
|
|
26367
26903
|
this.instance.emitEvent("onStageDrop", e);
|
|
26368
26904
|
});
|
|
26905
|
+
window.addEventListener("dragover", (e) => e.preventDefault(), { passive: false });
|
|
26906
|
+
window.addEventListener("drop", (e) => e.preventDefault(), { passive: false });
|
|
26369
26907
|
}
|
|
26370
26908
|
enable() {
|
|
26371
26909
|
this.enabled = true;
|
|
@@ -26544,6 +27082,22 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26544
27082
|
});
|
|
26545
27083
|
}
|
|
26546
27084
|
}
|
|
27085
|
+
nodeIntersectsViewport(node) {
|
|
27086
|
+
const stage = this.instance.getStage();
|
|
27087
|
+
const scale = stage.scaleX();
|
|
27088
|
+
const stageWidth = stage.width() / scale;
|
|
27089
|
+
const stageHeight = stage.height() / scale;
|
|
27090
|
+
const viewportRect = {
|
|
27091
|
+
x: -stage.x() / scale,
|
|
27092
|
+
y: -stage.y() / scale,
|
|
27093
|
+
width: stageWidth,
|
|
27094
|
+
height: stageHeight
|
|
27095
|
+
};
|
|
27096
|
+
if (!node.isVisible()) return false;
|
|
27097
|
+
const box = node.getClientRect({ relativeTo: stage });
|
|
27098
|
+
const intersects = box.x + box.width > viewportRect.x && box.x < viewportRect.x + viewportRect.width && box.y + box.height > viewportRect.y && box.y < viewportRect.y + viewportRect.height;
|
|
27099
|
+
return intersects;
|
|
27100
|
+
}
|
|
26547
27101
|
getLineGuideStops(skipNodes) {
|
|
26548
27102
|
const stage = this.instance.getStage();
|
|
26549
27103
|
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
@@ -26559,7 +27113,10 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26559
27113
|
stage.height()
|
|
26560
27114
|
];
|
|
26561
27115
|
stage.find(".node").forEach((guideItem) => {
|
|
27116
|
+
if (guideItem.getParent()?.getAttrs().nodeType === "group") return;
|
|
27117
|
+
if (skipNodes.includes(guideItem.getParent()?.getAttrs().nodeId)) return;
|
|
26562
27118
|
if (skipNodes.includes(guideItem.getAttrs().id ?? "")) return;
|
|
27119
|
+
if (!this.nodeIntersectsViewport(guideItem)) return;
|
|
26563
27120
|
const box = guideItem.getClientRect({ skipStroke: true });
|
|
26564
27121
|
vertical.push([
|
|
26565
27122
|
box.x,
|
|
@@ -26806,8 +27363,10 @@ exports.WEAVE_NODES_SNAPPING_KEY = WEAVE_NODES_SNAPPING_KEY
|
|
|
26806
27363
|
exports.WEAVE_RECTANGLE_NODE_TYPE = WEAVE_RECTANGLE_NODE_TYPE
|
|
26807
27364
|
exports.WEAVE_REGULAR_POLYGON_NODE_TYPE = WEAVE_REGULAR_POLYGON_NODE_TYPE
|
|
26808
27365
|
exports.WEAVE_STAGE_GRID_KEY = WEAVE_STAGE_GRID_KEY
|
|
27366
|
+
exports.WEAVE_STAGE_MODE = WEAVE_STAGE_MODE
|
|
26809
27367
|
exports.WEAVE_STAGE_NODE_TYPE = WEAVE_STAGE_NODE_TYPE
|
|
26810
27368
|
exports.WEAVE_STAR_NODE_TYPE = WEAVE_STAR_NODE_TYPE
|
|
27369
|
+
exports.WEAVE_STROKE_NODE_TYPE = WEAVE_STROKE_NODE_TYPE
|
|
26811
27370
|
exports.WEAVE_TEXT_NODE_TYPE = WEAVE_TEXT_NODE_TYPE
|
|
26812
27371
|
exports.WEAVE_USERS_POINTERS_KEY = WEAVE_USERS_POINTERS_KEY
|
|
26813
27372
|
exports.WEAVE_USERS_SELECTION_KEY = WEAVE_USERS_SELECTION_KEY
|
|
@@ -26857,6 +27416,7 @@ exports.WeaveStageZoomPlugin = WeaveStageZoomPlugin
|
|
|
26857
27416
|
exports.WeaveStarNode = WeaveStarNode
|
|
26858
27417
|
exports.WeaveStarToolAction = WeaveStarToolAction
|
|
26859
27418
|
exports.WeaveStore = WeaveStore
|
|
27419
|
+
exports.WeaveStrokeNode = WeaveStrokeNode
|
|
26860
27420
|
exports.WeaveTextNode = WeaveTextNode
|
|
26861
27421
|
exports.WeaveTextToolAction = WeaveTextToolAction
|
|
26862
27422
|
exports.WeaveUsersPointersPlugin = WeaveUsersPointersPlugin
|
|
@@ -26867,6 +27427,7 @@ exports.checkIfOverContainer = checkIfOverContainer
|
|
|
26867
27427
|
exports.clearContainerTargets = clearContainerTargets
|
|
26868
27428
|
exports.getBoundingBox = getBoundingBox
|
|
26869
27429
|
exports.getContrastTextColor = getContrastTextColor
|
|
27430
|
+
exports.getTargetedNode = getTargetedNode
|
|
26870
27431
|
exports.moveNodeToContainer = moveNodeToContainer
|
|
26871
27432
|
exports.resetScale = resetScale
|
|
26872
27433
|
exports.stringToColor = stringToColor
|