@inditextech/weave-sdk 0.38.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 +881 -657
- package/dist/sdk.d.cts +199 -156
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +199 -156
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +880 -658
- 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,12 +15782,14 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15655
15782
|
initLayer = void 0;
|
|
15656
15783
|
constructor(params) {
|
|
15657
15784
|
super();
|
|
15658
|
-
this.
|
|
15659
|
-
this.dragging = false;
|
|
15660
|
-
this.transforming = false;
|
|
15661
|
-
this.touchTimer = void 0;
|
|
15785
|
+
this.timer = null;
|
|
15662
15786
|
this.tapHold = false;
|
|
15663
15787
|
this.contextMenuVisible = false;
|
|
15788
|
+
this.tapStart = {
|
|
15789
|
+
x: 0,
|
|
15790
|
+
y: 0,
|
|
15791
|
+
time: 0
|
|
15792
|
+
};
|
|
15664
15793
|
this.tapHoldTimeout = WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT;
|
|
15665
15794
|
const { config } = params ?? {};
|
|
15666
15795
|
this.config = {
|
|
@@ -15676,34 +15805,40 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15676
15805
|
onInit() {
|
|
15677
15806
|
this.initEvents();
|
|
15678
15807
|
}
|
|
15679
|
-
|
|
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) {
|
|
15680
15819
|
const stage = this.instance.getStage();
|
|
15681
|
-
const selectionPlugin = this.
|
|
15682
|
-
let clickOnTransformer = false;
|
|
15683
|
-
if (selectionPlugin) {
|
|
15684
|
-
const transformer = selectionPlugin.getTransformer();
|
|
15685
|
-
const box = transformer.getClientRect();
|
|
15686
|
-
const mousePos = stage.getPointerPosition();
|
|
15687
|
-
if (mousePos && mousePos.x >= box.x && mousePos.x <= box.x + box.width && mousePos.y >= box.y && mousePos.y <= box.y + box.height) clickOnTransformer = true;
|
|
15688
|
-
}
|
|
15820
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
15689
15821
|
let nodes = [];
|
|
15690
|
-
if (target
|
|
15691
|
-
const transformer = selectionPlugin.getTransformer();
|
|
15692
|
-
nodes = transformer.getNodes().map((node) => {
|
|
15693
|
-
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15694
|
-
return {
|
|
15695
|
-
instance: node,
|
|
15696
|
-
node: nodeHandler?.serialize(node)
|
|
15697
|
-
};
|
|
15698
|
-
}).filter((node) => typeof node !== "undefined");
|
|
15699
|
-
}
|
|
15700
|
-
if (target !== stage && !clickOnTransformer) {
|
|
15822
|
+
if (target && target !== stage) {
|
|
15701
15823
|
const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
|
|
15702
15824
|
nodes = [{
|
|
15703
15825
|
instance: target,
|
|
15704
15826
|
node: nodeHandler?.serialize(target)
|
|
15705
15827
|
}];
|
|
15706
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
|
+
}
|
|
15707
15842
|
const containerRect = stage.container().getBoundingClientRect();
|
|
15708
15843
|
const pointerPos = stage.getPointerPosition();
|
|
15709
15844
|
if (containerRect && pointerPos) {
|
|
@@ -15730,58 +15865,49 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15730
15865
|
visible: false
|
|
15731
15866
|
});
|
|
15732
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
|
+
}
|
|
15733
15878
|
initEvents() {
|
|
15734
15879
|
const stage = this.instance.getStage();
|
|
15735
|
-
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
15736
|
-
this.onAction = activeAction;
|
|
15737
|
-
});
|
|
15738
|
-
this.instance.addEventListener("onDrag", (node) => {
|
|
15739
|
-
this.actualNode = node;
|
|
15740
|
-
if (node) this.dragging = true;
|
|
15741
|
-
else this.dragging = false;
|
|
15742
|
-
});
|
|
15743
|
-
this.instance.addEventListener("onTransform", (node) => {
|
|
15744
|
-
this.actualNode = node;
|
|
15745
|
-
if (node) this.transforming = true;
|
|
15746
|
-
else this.transforming = false;
|
|
15747
|
-
});
|
|
15748
15880
|
stage.on("pointerdown", (e) => {
|
|
15881
|
+
this.setTapStart(e);
|
|
15749
15882
|
this.pointers[e.evt.pointerId] = e.evt;
|
|
15883
|
+
if (e.evt.buttons === 0) return;
|
|
15750
15884
|
if (e.evt.pointerType === "mouse") return;
|
|
15751
15885
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
15752
|
-
this.
|
|
15886
|
+
if (this.timer) return;
|
|
15887
|
+
this.timer = setTimeout(() => {
|
|
15753
15888
|
this.tapHold = true;
|
|
15754
15889
|
const actualActions = this.instance.getActiveAction();
|
|
15755
15890
|
if (actualActions !== "selectionTool") return;
|
|
15756
|
-
const shouldKillLongPressTimer = this.touchTimer && (typeof this.onAction === "undefined" || typeof this.onAction !== "undefined" && ["selectionTool"].includes(this.onAction)) && (typeof this.dragging !== "undefined" && this.dragging || typeof this.transforming !== "undefined" && this.transforming);
|
|
15757
|
-
if (shouldKillLongPressTimer) {
|
|
15758
|
-
clearTimeout(this.touchTimer);
|
|
15759
|
-
return;
|
|
15760
|
-
}
|
|
15761
|
-
this.actualNode?.stopDrag();
|
|
15762
15891
|
delete this.pointers[e.evt.pointerId];
|
|
15763
|
-
this.
|
|
15892
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
15893
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
15764
15894
|
}, this.tapHoldTimeout);
|
|
15765
15895
|
});
|
|
15766
|
-
stage.on("pointermove", (e) => {
|
|
15767
|
-
if (["mouse"].includes(e.evt.pointerType)) return;
|
|
15768
|
-
if (["pen"].includes(e.evt.pointerType) && e.evt.pressure === 0) return;
|
|
15769
|
-
if (["pen"].includes(e.evt.pointerType) && (e.evt.movementX >= -1 && e.evt.movementX <= 1 || e.evt.movementY >= -1 && e.evt.movementY >= 1)) return;
|
|
15770
|
-
if (this.touchTimer) clearTimeout(this.touchTimer);
|
|
15771
|
-
});
|
|
15772
15896
|
stage.on("pointerup", (e) => {
|
|
15773
15897
|
delete this.pointers[e.evt.pointerId];
|
|
15774
15898
|
if (e.evt.pointerType === "mouse") return;
|
|
15775
15899
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
15776
|
-
if (this.
|
|
15777
|
-
clearTimeout(this.
|
|
15900
|
+
if (this.timer) {
|
|
15901
|
+
clearTimeout(this.timer);
|
|
15902
|
+
this.timer = null;
|
|
15778
15903
|
this.tapHold = false;
|
|
15779
15904
|
}
|
|
15780
15905
|
});
|
|
15781
15906
|
stage.on("contextmenu", (e) => {
|
|
15782
15907
|
e.evt.preventDefault();
|
|
15783
15908
|
if (!this.enabled) return;
|
|
15784
|
-
this.
|
|
15909
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
15910
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
15785
15911
|
});
|
|
15786
15912
|
this.instance.addEventListener("onStageSelection", () => {
|
|
15787
15913
|
if (this.tapHold) return;
|
|
@@ -15814,118 +15940,19 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15814
15940
|
}
|
|
15815
15941
|
};
|
|
15816
15942
|
|
|
15817
|
-
//#endregion
|
|
15818
|
-
//#region src/utils.ts
|
|
15819
|
-
function resetScale(node) {
|
|
15820
|
-
node.width(Math.round((Math.max(1, node.width() * node.scaleX()) + Number.EPSILON) * 100) / 100);
|
|
15821
|
-
node.height(Math.round((Math.max(1, node.height() * node.scaleY()) + Number.EPSILON) * 100) / 100);
|
|
15822
|
-
node.scaleX(1);
|
|
15823
|
-
node.scaleY(1);
|
|
15824
|
-
node.x(Math.round((node.x() + Number.EPSILON) * 100) / 100);
|
|
15825
|
-
node.y(Math.round((node.y() + Number.EPSILON) * 100) / 100);
|
|
15826
|
-
node.rotation(Math.round((node.rotation() + Number.EPSILON) * 100) / 100);
|
|
15827
|
-
}
|
|
15828
|
-
function clearContainerTargets(instance) {
|
|
15829
|
-
const getContainers = instance.getContainerNodes();
|
|
15830
|
-
for (const container of getContainers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
|
|
15831
|
-
}
|
|
15832
|
-
function checkIfOverContainer(instance, node) {
|
|
15833
|
-
const nodesIntersected = instance.pointIntersectsContainerElement(node.getParent());
|
|
15834
|
-
let nodeActualContainer = node.getParent();
|
|
15835
|
-
if (nodeActualContainer?.getAttrs().nodeId) nodeActualContainer = instance.getStage().findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
|
|
15836
|
-
let layerToMove = void 0;
|
|
15837
|
-
if (!node.getAttrs().containerId && nodesIntersected && nodeActualContainer?.getAttrs().id !== nodesIntersected.getAttrs().id) layerToMove = nodesIntersected;
|
|
15838
|
-
return layerToMove;
|
|
15839
|
-
}
|
|
15840
|
-
function moveNodeToContainer(instance, node, ignoreContainers = []) {
|
|
15841
|
-
const nodeIntersected = instance.pointIntersectsContainerElement();
|
|
15842
|
-
let realNodeIntersected = nodeIntersected;
|
|
15843
|
-
if (realNodeIntersected && realNodeIntersected.getAttrs().nodeType === "frame" && !realNodeIntersected.getAttrs().nodeId) realNodeIntersected = instance.getStage().findOne(`#${realNodeIntersected.getAttrs().id}-selector-area`);
|
|
15844
|
-
if (realNodeIntersected && ignoreContainers.includes(realNodeIntersected)) return void 0;
|
|
15845
|
-
const isLocked = instance.allNodesLocked([node]);
|
|
15846
|
-
if (isLocked) return;
|
|
15847
|
-
let nodeActualContainer = node.getParent();
|
|
15848
|
-
if (!nodeActualContainer) return void 0;
|
|
15849
|
-
const actualContainerAttrs = nodeActualContainer.getAttrs();
|
|
15850
|
-
const nodeAttrs = node.getAttrs();
|
|
15851
|
-
if (actualContainerAttrs.nodeId) nodeActualContainer = instance.getStage().findOne(`#${actualContainerAttrs.nodeId}`);
|
|
15852
|
-
let layerToMove = void 0;
|
|
15853
|
-
if (!nodeAttrs.containerId && nodeIntersected && actualContainerAttrs.id !== nodeIntersected.getAttrs().id) layerToMove = nodeIntersected;
|
|
15854
|
-
if (!nodeIntersected && actualContainerAttrs.id !== __inditextech_weave_types.WEAVE_NODE_LAYER_ID) layerToMove = instance.getMainLayer();
|
|
15855
|
-
if (layerToMove && actualContainerAttrs.id !== layerToMove.getAttrs().id && actualContainerAttrs.id !== layerToMove.getAttrs().containerId) {
|
|
15856
|
-
const layerToMoveAttrs = layerToMove.getAttrs();
|
|
15857
|
-
const nodePos = node.getAbsolutePosition();
|
|
15858
|
-
const nodeRotation = node.getAbsoluteRotation();
|
|
15859
|
-
node.moveTo(layerToMove);
|
|
15860
|
-
node.setAbsolutePosition(nodePos);
|
|
15861
|
-
node.rotation(nodeRotation);
|
|
15862
|
-
node.x(node.x() - (layerToMoveAttrs.containerOffsetX ?? 0));
|
|
15863
|
-
node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
|
|
15864
|
-
node.movedToContainer(layerToMove);
|
|
15865
|
-
const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15866
|
-
if (nodeHandler) {
|
|
15867
|
-
const actualNode = nodeHandler.serialize(node);
|
|
15868
|
-
instance.removeNode(actualNode);
|
|
15869
|
-
instance.addNode(actualNode, layerToMoveAttrs.id);
|
|
15870
|
-
return layerToMove;
|
|
15871
|
-
}
|
|
15872
|
-
}
|
|
15873
|
-
return void 0;
|
|
15874
|
-
}
|
|
15875
|
-
function getContrastTextColor(hex) {
|
|
15876
|
-
const cleaned = hex.replace(/^#/, "");
|
|
15877
|
-
const r = parseInt(cleaned.slice(0, 2), 16);
|
|
15878
|
-
const g = parseInt(cleaned.slice(2, 4), 16);
|
|
15879
|
-
const b = parseInt(cleaned.slice(4, 6), 16);
|
|
15880
|
-
const luminance = (.299 * r + .587 * g + .114 * b) / 255;
|
|
15881
|
-
return luminance > .5 ? "black" : "white";
|
|
15882
|
-
}
|
|
15883
|
-
function stringToColor(str) {
|
|
15884
|
-
let hash = 0;
|
|
15885
|
-
str.split("").forEach((char) => {
|
|
15886
|
-
hash = char.charCodeAt(0) + ((hash << 5) - hash);
|
|
15887
|
-
});
|
|
15888
|
-
let color = "#";
|
|
15889
|
-
for (let i = 0; i < 3; i++) {
|
|
15890
|
-
const value = hash >> i * 8 & 255;
|
|
15891
|
-
color += value.toString(16).padStart(2, "0");
|
|
15892
|
-
}
|
|
15893
|
-
return color;
|
|
15894
|
-
}
|
|
15895
|
-
function getBoundingBox(stage, nodes) {
|
|
15896
|
-
if (nodes.length === 0) return {
|
|
15897
|
-
x: 0,
|
|
15898
|
-
y: 0,
|
|
15899
|
-
width: 0,
|
|
15900
|
-
height: 0
|
|
15901
|
-
};
|
|
15902
|
-
let minX = Infinity;
|
|
15903
|
-
let minY = Infinity;
|
|
15904
|
-
let maxX = -Infinity;
|
|
15905
|
-
let maxY = -Infinity;
|
|
15906
|
-
for (const node of nodes) {
|
|
15907
|
-
let realNode = node;
|
|
15908
|
-
if (realNode.getAttrs().containerId) realNode = stage.findOne(`#${realNode.getAttrs().containerId}`);
|
|
15909
|
-
if (!realNode) continue;
|
|
15910
|
-
const box = node.getRealClientRect({ skipTransform: false });
|
|
15911
|
-
minX = Math.min(minX, box.x);
|
|
15912
|
-
minY = Math.min(minY, box.y);
|
|
15913
|
-
maxX = Math.max(maxX, box.x + box.width);
|
|
15914
|
-
maxY = Math.max(maxY, box.y + box.height);
|
|
15915
|
-
}
|
|
15916
|
-
return {
|
|
15917
|
-
x: minX,
|
|
15918
|
-
y: minY,
|
|
15919
|
-
width: maxX - minX,
|
|
15920
|
-
height: maxY - minY
|
|
15921
|
-
};
|
|
15922
|
-
}
|
|
15923
|
-
|
|
15924
15943
|
//#endregion
|
|
15925
15944
|
//#region src/plugins/users-selection/constants.ts
|
|
15926
15945
|
const WEAVE_USERS_SELECTION_KEY = "usersSelection";
|
|
15927
15946
|
const WEAVE_USER_SELECTION_KEY = "userSelection";
|
|
15928
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
|
+
|
|
15929
15956
|
//#endregion
|
|
15930
15957
|
//#region src/plugins/nodes-selection/nodes-selection.ts
|
|
15931
15958
|
var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
@@ -15951,16 +15978,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15951
15978
|
keepRatio: false,
|
|
15952
15979
|
useSingleNodeRotation: true,
|
|
15953
15980
|
shouldOverdrawWholeArea: true,
|
|
15954
|
-
enabledAnchors: [
|
|
15955
|
-
"top-left",
|
|
15956
|
-
"top-center",
|
|
15957
|
-
"top-right",
|
|
15958
|
-
"middle-right",
|
|
15959
|
-
"middle-left",
|
|
15960
|
-
"bottom-left",
|
|
15961
|
-
"bottom-center",
|
|
15962
|
-
"bottom-right"
|
|
15963
|
-
],
|
|
15964
15981
|
anchorStyleFunc: (anchor) => {
|
|
15965
15982
|
anchor.stroke("#27272aff");
|
|
15966
15983
|
anchor.cornerRadius(12);
|
|
@@ -15978,6 +15995,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15978
15995
|
}
|
|
15979
15996
|
},
|
|
15980
15997
|
borderStroke: "#0074ffcc",
|
|
15998
|
+
borderStrokeWidth: 3,
|
|
15981
15999
|
...config?.transformer
|
|
15982
16000
|
},
|
|
15983
16001
|
transformations: {
|
|
@@ -15996,12 +16014,17 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15996
16014
|
"bottom-center",
|
|
15997
16015
|
"bottom-right"
|
|
15998
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;
|
|
15999
16025
|
this.active = false;
|
|
16000
|
-
this.cameFromSelectingMultiple = false;
|
|
16001
16026
|
this.didMove = false;
|
|
16002
|
-
this.selectionTriggered = false;
|
|
16003
16027
|
this.selecting = false;
|
|
16004
|
-
this.dragging = false;
|
|
16005
16028
|
this.initialized = false;
|
|
16006
16029
|
this.enabled = false;
|
|
16007
16030
|
this.pointers = {};
|
|
@@ -16052,18 +16075,34 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16052
16075
|
...this.config.transformer
|
|
16053
16076
|
});
|
|
16054
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);
|
|
16055
16088
|
tr.on("transformstart", () => {
|
|
16056
16089
|
this.triggerSelectedNodesEvent();
|
|
16057
16090
|
});
|
|
16058
|
-
const handleTransform = () => {
|
|
16091
|
+
const handleTransform = (e) => {
|
|
16092
|
+
const moved = this.checkMoved(e);
|
|
16093
|
+
if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
16059
16094
|
this.triggerSelectedNodesEvent();
|
|
16060
16095
|
};
|
|
16061
16096
|
tr.on("transform", (0, import_lodash.throttle)(handleTransform, 50));
|
|
16062
16097
|
tr.on("transformend", () => {
|
|
16063
16098
|
this.triggerSelectedNodesEvent();
|
|
16064
16099
|
});
|
|
16100
|
+
let initialPos = null;
|
|
16065
16101
|
tr.on("dragstart", (e) => {
|
|
16066
|
-
|
|
16102
|
+
initialPos = {
|
|
16103
|
+
x: e.target.x(),
|
|
16104
|
+
y: e.target.y()
|
|
16105
|
+
};
|
|
16067
16106
|
this.didMove = false;
|
|
16068
16107
|
const stage$1 = this.instance.getStage();
|
|
16069
16108
|
if (stage$1.isMouseWheelPressed()) {
|
|
@@ -16071,15 +16110,23 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16071
16110
|
e.target.stopDrag();
|
|
16072
16111
|
return;
|
|
16073
16112
|
}
|
|
16113
|
+
e.cancelBubble = true;
|
|
16074
16114
|
const selectedNodes = tr.nodes();
|
|
16075
16115
|
for (let i = 0; i < selectedNodes.length; i++) {
|
|
16076
16116
|
const node = selectedNodes[i];
|
|
16077
16117
|
node.updatePosition(node.getAbsolutePosition());
|
|
16078
16118
|
}
|
|
16079
16119
|
tr.forceUpdate();
|
|
16080
|
-
e.cancelBubble = true;
|
|
16081
16120
|
});
|
|
16082
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
|
+
}
|
|
16083
16130
|
const stage$1 = this.instance.getStage();
|
|
16084
16131
|
if (stage$1.isMouseWheelPressed()) {
|
|
16085
16132
|
e.cancelBubble = true;
|
|
@@ -16105,7 +16152,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16105
16152
|
tr.on("dragmove", handleDragMove);
|
|
16106
16153
|
tr.on("dragend", (e) => {
|
|
16107
16154
|
if (!this.didMove) return;
|
|
16108
|
-
this.dragging = false;
|
|
16109
16155
|
e.cancelBubble = true;
|
|
16110
16156
|
const selectedNodes = tr.nodes();
|
|
16111
16157
|
let hasFrames = false;
|
|
@@ -16123,7 +16169,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16123
16169
|
const nodeUpdatePromise = (node) => {
|
|
16124
16170
|
return new Promise((resolve) => {
|
|
16125
16171
|
setTimeout(() => {
|
|
16126
|
-
|
|
16172
|
+
clearContainerTargets(this.instance);
|
|
16173
|
+
if (!hasFrames) moveNodeToContainer(this.instance, node);
|
|
16127
16174
|
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
16128
16175
|
if (!nodeHandler) return resolve();
|
|
16129
16176
|
toSelect.push(node.getAttrs().id ?? "");
|
|
@@ -16151,14 +16198,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16151
16198
|
tr.forceUpdate();
|
|
16152
16199
|
});
|
|
16153
16200
|
this.tr = tr;
|
|
16201
|
+
this.trHover = trHover;
|
|
16154
16202
|
this.selectionRectangle = selectionRectangle;
|
|
16155
|
-
this.tr.on("pointerdblclick", (e) => {
|
|
16156
|
-
e.cancelBubble = true;
|
|
16157
|
-
if (this.tr.getNodes().length === 1) {
|
|
16158
|
-
const node = this.tr.getNodes()[0];
|
|
16159
|
-
node.fire("pointerdblclick");
|
|
16160
|
-
}
|
|
16161
|
-
});
|
|
16162
16203
|
this.initEvents();
|
|
16163
16204
|
this.initialized = true;
|
|
16164
16205
|
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
@@ -16210,6 +16251,63 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16210
16251
|
this.tr.nodes([]);
|
|
16211
16252
|
this.triggerSelectedNodesEvent();
|
|
16212
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
|
+
}
|
|
16213
16311
|
initEvents() {
|
|
16214
16312
|
let x1, y1, x2, y2;
|
|
16215
16313
|
this.selecting = false;
|
|
@@ -16221,14 +16319,31 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16221
16319
|
}
|
|
16222
16320
|
});
|
|
16223
16321
|
stage.on("pointerdown", (e) => {
|
|
16322
|
+
this.setTapStart(e);
|
|
16224
16323
|
this.pointers[e.evt.pointerId] = e.evt;
|
|
16225
16324
|
if (!this.initialized) return;
|
|
16226
16325
|
if (!this.active) return;
|
|
16227
16326
|
if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
|
|
16228
16327
|
if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
|
|
16229
16328
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
16230
|
-
|
|
16231
|
-
|
|
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
|
+
}
|
|
16232
16347
|
const intStage = this.instance.getStage();
|
|
16233
16348
|
x1 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
16234
16349
|
y1 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
@@ -16239,30 +16354,27 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16239
16354
|
this.selectionRectangle.width(0);
|
|
16240
16355
|
this.selectionRectangle.height(0);
|
|
16241
16356
|
this.selecting = true;
|
|
16357
|
+
this.tr.nodes([]);
|
|
16242
16358
|
this.instance.emitEvent("onSelectionState", true);
|
|
16243
16359
|
});
|
|
16244
16360
|
const handleMouseMove = (e) => {
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
this.selectionRectangle.setAttrs({ visible: false });
|
|
16248
|
-
return;
|
|
16249
|
-
}
|
|
16361
|
+
const moved = this.checkMoved(e);
|
|
16362
|
+
if (e.evt.buttons === 0) return;
|
|
16250
16363
|
if (!this.initialized) return;
|
|
16251
16364
|
if (!this.active) return;
|
|
16252
|
-
if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
|
|
16253
16365
|
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
16254
|
-
const contextMenuPlugin = this.
|
|
16366
|
+
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
16367
|
+
if (moved) contextMenuPlugin?.cancelLongPressTimer();
|
|
16368
|
+
else this.hideSelectorArea();
|
|
16255
16369
|
if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
|
|
16256
16370
|
this.selecting = false;
|
|
16257
16371
|
return;
|
|
16258
16372
|
}
|
|
16259
|
-
if (!this.selecting)
|
|
16260
|
-
this.cameFromSelectingMultiple = false;
|
|
16261
|
-
return;
|
|
16262
|
-
}
|
|
16373
|
+
if (!this.selecting) return;
|
|
16263
16374
|
const intStage = this.instance.getStage();
|
|
16264
16375
|
x2 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
16265
16376
|
y2 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
16377
|
+
this.getTransformer().nodes([]);
|
|
16266
16378
|
this.selectionRectangle.setAttrs({
|
|
16267
16379
|
visible: true,
|
|
16268
16380
|
x: Math.min(x1, x2),
|
|
@@ -16273,33 +16385,59 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16273
16385
|
};
|
|
16274
16386
|
stage.on("pointermove", handleMouseMove);
|
|
16275
16387
|
stage.on("pointerup", (e) => {
|
|
16388
|
+
const moved = this.checkMoved(e);
|
|
16389
|
+
this.checkDoubleTap(e);
|
|
16276
16390
|
delete this.pointers[e.evt.pointerId];
|
|
16277
|
-
|
|
16278
|
-
|
|
16279
|
-
|
|
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();
|
|
16399
|
+
return;
|
|
16400
|
+
}
|
|
16401
|
+
this.selecting = false;
|
|
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();
|
|
16280
16426
|
return;
|
|
16281
16427
|
}
|
|
16282
|
-
if (!this.initialized) return;
|
|
16283
|
-
if (!this.active) return;
|
|
16284
|
-
if (!this.selecting) return;
|
|
16285
|
-
if (e.evt.pointerType === "pen" && e.evt.pressure > 0) return;
|
|
16286
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
16287
|
-
const contextMenuPlugin = this.instance.getPlugin("contextMenu");
|
|
16288
16428
|
if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
|
|
16289
16429
|
this.selecting = false;
|
|
16290
16430
|
return;
|
|
16291
16431
|
}
|
|
16292
|
-
this.selecting = false;
|
|
16293
|
-
this.instance.emitEvent("onSelectionState", false);
|
|
16294
16432
|
if (!this.selectionRectangle.visible()) {
|
|
16295
|
-
this.
|
|
16433
|
+
this.hideSelectorArea();
|
|
16296
16434
|
return;
|
|
16297
16435
|
}
|
|
16298
|
-
this.selectionRectangle.visible(false);
|
|
16299
16436
|
const shapes = stage.find((node) => {
|
|
16300
16437
|
return ["Shape", "Group"].includes(node.getType()) && typeof node.getAttrs().id !== "undefined";
|
|
16301
16438
|
});
|
|
16302
16439
|
const box = this.selectionRectangle.getClientRect();
|
|
16440
|
+
this.selectionRectangle.visible(false);
|
|
16303
16441
|
const selected = shapes.filter((shape) => {
|
|
16304
16442
|
let parent = this.instance.getInstanceRecursive(shape.getParent());
|
|
16305
16443
|
if (parent.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
@@ -16313,124 +16451,148 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16313
16451
|
return false;
|
|
16314
16452
|
});
|
|
16315
16453
|
const selectedNodes = new Set();
|
|
16316
|
-
const
|
|
16317
|
-
return
|
|
16454
|
+
const containerNodes = selected.filter((node) => {
|
|
16455
|
+
return typeof node.getAttrs().isContainerPrincipal !== "undefined" && node.getAttrs().isContainerPrincipal;
|
|
16318
16456
|
});
|
|
16319
|
-
let
|
|
16320
|
-
|
|
16321
|
-
return shape;
|
|
16322
|
-
}).filter((shape) => {
|
|
16323
|
-
return shape.getAttrs().nodeType === "frame";
|
|
16324
|
-
}).map((shape) => {
|
|
16325
|
-
return shape.getAttrs().id;
|
|
16457
|
+
let containerNodesIds = containerNodes.map((node) => {
|
|
16458
|
+
return node.getAttrs().id;
|
|
16326
16459
|
});
|
|
16327
|
-
const
|
|
16328
|
-
|
|
16329
|
-
const otherNodes = selected.filter((shape) => shape.getAttrs().
|
|
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);
|
|
16330
16463
|
otherNodes.forEach((node) => {
|
|
16331
16464
|
let parent = this.instance.getInstanceRecursive(node.getParent());
|
|
16332
16465
|
if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
16333
|
-
if (parent && !
|
|
16466
|
+
if (parent && !containerNodesIds.includes(parent?.getAttrs().id) && !node.getAttrs().locked) selectedNodes.add(node);
|
|
16334
16467
|
});
|
|
16335
|
-
|
|
16468
|
+
containerNodes.forEach((node) => {
|
|
16336
16469
|
const frameNode = node;
|
|
16337
|
-
if (!frameNode.getAttrs().locked) selectedNodes.add(
|
|
16470
|
+
if (!frameNode.getAttrs().locked) selectedNodes.add(node);
|
|
16338
16471
|
});
|
|
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
|
+
}
|
|
16339
16485
|
this.selecting = false;
|
|
16340
|
-
this.tr.nodes(
|
|
16486
|
+
this.tr.nodes(nodesArray);
|
|
16341
16487
|
this.triggerSelectedNodesEvent();
|
|
16342
16488
|
stage.container().tabIndex = 1;
|
|
16343
16489
|
stage.container().focus();
|
|
16344
16490
|
});
|
|
16345
|
-
|
|
16346
|
-
|
|
16347
|
-
|
|
16348
|
-
|
|
16349
|
-
|
|
16350
|
-
|
|
16351
|
-
|
|
16352
|
-
|
|
16353
|
-
|
|
16354
|
-
|
|
16355
|
-
|
|
16356
|
-
|
|
16357
|
-
|
|
16358
|
-
|
|
16359
|
-
|
|
16360
|
-
|
|
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) {
|
|
16361
16518
|
const mousePos = stage.getPointerPosition();
|
|
16362
|
-
|
|
16363
|
-
|
|
16364
|
-
|
|
16365
|
-
|
|
16366
|
-
if (
|
|
16367
|
-
|
|
16368
|
-
|
|
16369
|
-
|
|
16370
|
-
|
|
16371
|
-
|
|
16372
|
-
|
|
16373
|
-
return false;
|
|
16374
|
-
}
|
|
16375
|
-
let areNodesSelected = false;
|
|
16376
|
-
let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
|
|
16377
|
-
if (nodeTargeted.getParent() instanceof konva.default.Transformer) {
|
|
16378
|
-
const intersections = stage.getAllIntersections(mousePos);
|
|
16379
|
-
const nodesIntersected = intersections.filter((ele) => ele.getAttrs().nodeType);
|
|
16380
|
-
let targetNode = null;
|
|
16381
|
-
if (nodesIntersected.length > 0) targetNode = this.instance.getInstanceRecursive(nodesIntersected[nodesIntersected.length - 1]);
|
|
16382
|
-
if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
|
|
16383
|
-
}
|
|
16384
|
-
if (!nodeTargeted.getAttrs().nodeType) return;
|
|
16385
|
-
let nodesSelected = 0;
|
|
16386
|
-
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
16387
|
-
const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
|
|
16388
|
-
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
16389
|
-
});
|
|
16390
|
-
const isSelected = nodeSelectedIndex !== -1;
|
|
16391
|
-
if (nodeTargeted.getAttrs().locked) return;
|
|
16392
|
-
if (!metaPressed) {
|
|
16393
|
-
this.tr.nodes([nodeTargeted]);
|
|
16394
|
-
nodesSelected = this.tr.nodes().length;
|
|
16395
|
-
this.tr.show();
|
|
16396
|
-
areNodesSelected = true;
|
|
16397
|
-
} else if (metaPressed && isSelected) {
|
|
16398
|
-
const nodes = this.tr.nodes().slice();
|
|
16399
|
-
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
16400
|
-
this.tr.nodes(nodes);
|
|
16401
|
-
nodesSelected = this.tr.nodes().length;
|
|
16402
|
-
areNodesSelected = true;
|
|
16403
|
-
} else if (metaPressed && !isSelected) {
|
|
16404
|
-
const nodes = this.tr.nodes().concat([nodeTargeted]);
|
|
16405
|
-
this.tr.nodes(nodes);
|
|
16406
|
-
nodesSelected = this.tr.nodes().length;
|
|
16407
|
-
areNodesSelected = true;
|
|
16408
|
-
}
|
|
16409
|
-
if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16410
|
-
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16411
|
-
if (nodesSelected === 1) {
|
|
16412
|
-
this.tr.setAttrs({ ...nodeTargeted.getTransformerProperties() });
|
|
16413
|
-
this.tr.forceUpdate();
|
|
16414
|
-
}
|
|
16415
|
-
if (areNodesSelected) {
|
|
16416
|
-
stage.container().tabIndex = 1;
|
|
16417
|
-
stage.container().focus();
|
|
16418
|
-
stage.container().style.cursor = "grab";
|
|
16419
|
-
}
|
|
16420
|
-
this.selectionTriggered = true;
|
|
16421
|
-
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;
|
|
16422
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();
|
|
16423
16576
|
}
|
|
16424
16577
|
getTransformer() {
|
|
16425
16578
|
return this.tr;
|
|
16426
16579
|
}
|
|
16580
|
+
getHoverTransformer() {
|
|
16581
|
+
return this.trHover;
|
|
16582
|
+
}
|
|
16427
16583
|
setSelectedNodes(nodes) {
|
|
16428
16584
|
this.tr.setNodes(nodes);
|
|
16429
16585
|
const nodesSelected = nodes.length;
|
|
16430
16586
|
if (nodesSelected > 1 && !this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && !this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16431
16587
|
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16432
16588
|
if (nodesSelected === 1) {
|
|
16433
|
-
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 });
|
|
16434
16596
|
this.tr.forceUpdate();
|
|
16435
16597
|
}
|
|
16436
16598
|
this.triggerSelectedNodesEvent();
|
|
@@ -16467,6 +16629,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16467
16629
|
this.getLayer()?.hide();
|
|
16468
16630
|
this.enabled = false;
|
|
16469
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
|
+
}
|
|
16470
16640
|
};
|
|
16471
16641
|
|
|
16472
16642
|
//#endregion
|
|
@@ -16538,11 +16708,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16538
16708
|
try {
|
|
16539
16709
|
const continueToPaste = await this.readClipboardData();
|
|
16540
16710
|
if (continueToPaste) {
|
|
16541
|
-
|
|
16542
|
-
|
|
16543
|
-
this.state = COPY_PASTE_NODES_PLUGIN_STATE.PASTING;
|
|
16544
|
-
this.handlePaste(position);
|
|
16545
|
-
}
|
|
16711
|
+
this.state = COPY_PASTE_NODES_PLUGIN_STATE.PASTING;
|
|
16712
|
+
this.handlePaste();
|
|
16546
16713
|
}
|
|
16547
16714
|
} catch (ex) {
|
|
16548
16715
|
this.instance.emitEvent("onPaste", ex);
|
|
@@ -16551,7 +16718,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16551
16718
|
const items = await navigator.clipboard.read();
|
|
16552
16719
|
if (items && items.length === 1) {
|
|
16553
16720
|
const item = items[0];
|
|
16554
|
-
const position = this.instance.getStage().
|
|
16721
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
16555
16722
|
if (position) this.instance.emitEvent("onPasteExternal", {
|
|
16556
16723
|
position,
|
|
16557
16724
|
item
|
|
@@ -16584,9 +16751,9 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16584
16751
|
if (child.props.children) this.recursivelyUpdateKeys(child.props.children);
|
|
16585
16752
|
}
|
|
16586
16753
|
}
|
|
16587
|
-
handlePaste(
|
|
16754
|
+
handlePaste() {
|
|
16588
16755
|
if (this.toPaste) {
|
|
16589
|
-
const { mousePoint, container } = this.instance.getMousePointer(
|
|
16756
|
+
const { mousePoint, container } = this.instance.getMousePointer();
|
|
16590
16757
|
for (const element of Object.keys(this.toPaste.weave)) {
|
|
16591
16758
|
const node = this.toPaste.weave[element];
|
|
16592
16759
|
if (node.props.children) this.recursivelyUpdateKeys(node.props.children);
|
|
@@ -16596,7 +16763,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16596
16763
|
node.props.id = newNodeId;
|
|
16597
16764
|
node.props.x = mousePoint.x + (node.props.x - this.toPaste.weaveMinPoint.x);
|
|
16598
16765
|
node.props.y = mousePoint.y + (node.props.y - this.toPaste.weaveMinPoint.y);
|
|
16599
|
-
this.instance.addNode(node, container?.
|
|
16766
|
+
this.instance.addNode(node, container?.getAttrs().id);
|
|
16600
16767
|
this.instance.emitEvent("onPaste");
|
|
16601
16768
|
this.instance.emitEvent("onPaste", void 0);
|
|
16602
16769
|
}
|
|
@@ -16636,10 +16803,10 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16636
16803
|
async copy() {
|
|
16637
16804
|
await this.performCopy();
|
|
16638
16805
|
}
|
|
16639
|
-
async paste(
|
|
16806
|
+
async paste() {
|
|
16640
16807
|
try {
|
|
16641
16808
|
const continueToPaste = await this.readClipboardData();
|
|
16642
|
-
if (continueToPaste) this.handlePaste(
|
|
16809
|
+
if (continueToPaste) this.handlePaste();
|
|
16643
16810
|
} catch (ex) {
|
|
16644
16811
|
this.instance.emitEvent("onPaste", ex);
|
|
16645
16812
|
}
|
|
@@ -16647,6 +16814,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
16647
16814
|
const items = await navigator.clipboard.read();
|
|
16648
16815
|
if (items && items.length === 1) {
|
|
16649
16816
|
const item = items[0];
|
|
16817
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
16650
16818
|
if (position) this.instance.emitEvent("onPasteExternal", {
|
|
16651
16819
|
position,
|
|
16652
16820
|
item
|
|
@@ -16705,6 +16873,7 @@ const augmentKonvaNodeClass = (config) => {
|
|
|
16705
16873
|
konva.default.Node.prototype.triggerCrop = function() {};
|
|
16706
16874
|
konva.default.Node.prototype.closeCrop = function() {};
|
|
16707
16875
|
konva.default.Node.prototype.resetCrop = function() {};
|
|
16876
|
+
konva.default.Node.prototype.dblClick = function() {};
|
|
16708
16877
|
};
|
|
16709
16878
|
var WeaveNode = class {
|
|
16710
16879
|
register(instance) {
|
|
@@ -16721,7 +16890,6 @@ var WeaveNode = class {
|
|
|
16721
16890
|
}
|
|
16722
16891
|
getSelectionPlugin() {
|
|
16723
16892
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16724
|
-
if (!selectionPlugin) throw new Error("WeaveNodesSelectionPlugin plugin not found");
|
|
16725
16893
|
return selectionPlugin;
|
|
16726
16894
|
}
|
|
16727
16895
|
isSelecting() {
|
|
@@ -16742,9 +16910,8 @@ var WeaveNode = class {
|
|
|
16742
16910
|
}
|
|
16743
16911
|
isNodeSelected(ele) {
|
|
16744
16912
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
return selected;
|
|
16913
|
+
if (selectionPlugin?.getSelectedNodes().map((node) => node.getAttrs().id).includes(ele.getAttrs().id)) return true;
|
|
16914
|
+
return false;
|
|
16748
16915
|
}
|
|
16749
16916
|
scaleReset(node) {
|
|
16750
16917
|
node.width(Math.max(5, node.width() * node.scaleX()));
|
|
@@ -16752,6 +16919,20 @@ var WeaveNode = class {
|
|
|
16752
16919
|
node.scaleX(1);
|
|
16753
16920
|
node.scaleY(1);
|
|
16754
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
|
+
}
|
|
16755
16936
|
setupDefaultNodeEvents(node) {
|
|
16756
16937
|
this.instance.addEventListener("onNodesChange", () => {
|
|
16757
16938
|
if (!this.isLocked(node) && this.isSelecting() && this.isNodeSelected(node)) {
|
|
@@ -16802,6 +16983,10 @@ var WeaveNode = class {
|
|
|
16802
16983
|
});
|
|
16803
16984
|
node.on("dragstart", (e) => {
|
|
16804
16985
|
this.didMove = false;
|
|
16986
|
+
if (e.evt?.buttons === 0) {
|
|
16987
|
+
e.target.stopDrag();
|
|
16988
|
+
return;
|
|
16989
|
+
}
|
|
16805
16990
|
const stage = this.instance.getStage();
|
|
16806
16991
|
const isErasing = this.instance.getActiveAction() === "eraseTool";
|
|
16807
16992
|
if (isErasing) {
|
|
@@ -16815,6 +17000,10 @@ var WeaveNode = class {
|
|
|
16815
17000
|
}
|
|
16816
17001
|
});
|
|
16817
17002
|
const handleDragMove = (e) => {
|
|
17003
|
+
if (e.evt?.buttons === 0) {
|
|
17004
|
+
e.target.stopDrag();
|
|
17005
|
+
return;
|
|
17006
|
+
}
|
|
16818
17007
|
this.didMove = true;
|
|
16819
17008
|
const stage = this.instance.getStage();
|
|
16820
17009
|
const isErasing = this.instance.getActiveAction() === "eraseTool";
|
|
@@ -16827,7 +17016,7 @@ var WeaveNode = class {
|
|
|
16827
17016
|
e.target.stopDrag();
|
|
16828
17017
|
return;
|
|
16829
17018
|
}
|
|
16830
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
17019
|
+
if (this.isSelecting() && this.isNodeSelected(node) && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
|
|
16831
17020
|
clearContainerTargets(this.instance);
|
|
16832
17021
|
const layerToMove = checkIfOverContainer(this.instance, e.target);
|
|
16833
17022
|
if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
@@ -16842,7 +17031,7 @@ var WeaveNode = class {
|
|
|
16842
17031
|
return;
|
|
16843
17032
|
}
|
|
16844
17033
|
this.instance.emitEvent("onDrag", null);
|
|
16845
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
17034
|
+
if (this.isSelecting() && this.isNodeSelected(node) && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
|
|
16846
17035
|
clearContainerTargets(this.instance);
|
|
16847
17036
|
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
16848
17037
|
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
@@ -16851,19 +17040,25 @@ var WeaveNode = class {
|
|
|
16851
17040
|
this.instance.updateNode(this.serialize(node));
|
|
16852
17041
|
}
|
|
16853
17042
|
});
|
|
16854
|
-
node.on("
|
|
17043
|
+
node.on("pointerover", (e) => {
|
|
17044
|
+
e.cancelBubble = true;
|
|
17045
|
+
const stage = this.instance.getStage();
|
|
16855
17046
|
const realNode = this.instance.getInstanceRecursive(node);
|
|
17047
|
+
const isTargetable = e.target.getAttrs().isTargetable !== false;
|
|
16856
17048
|
const isLocked$1 = realNode.getAttrs().locked ?? false;
|
|
16857
|
-
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
|
|
16858
|
-
const stage = this.instance.getStage();
|
|
16859
|
-
stage.container().style.cursor =
|
|
16860
|
-
e.cancelBubble = true;
|
|
16861
|
-
return;
|
|
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";
|
|
16862
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);
|
|
17057
|
+
}
|
|
17058
|
+
if (!isTargetable) this.hideHoverState();
|
|
16863
17059
|
if (this.isPasting()) {
|
|
16864
|
-
const stage = this.instance.getStage();
|
|
16865
|
-
stage.container().style.cursor = "crosshair";
|
|
16866
|
-
e.cancelBubble = true;
|
|
17060
|
+
const stage$1 = this.instance.getStage();
|
|
17061
|
+
stage$1.container().style.cursor = "crosshair";
|
|
16867
17062
|
}
|
|
16868
17063
|
});
|
|
16869
17064
|
}
|
|
@@ -17615,24 +17810,77 @@ var WeaveTargetingManager = class {
|
|
|
17615
17810
|
const intersectedNode = mainLayer.getIntersection(relativeMousePointer);
|
|
17616
17811
|
return intersectedNode;
|
|
17617
17812
|
}
|
|
17618
|
-
|
|
17813
|
+
isBoundingBoxIntersecting(nodeA, nodeB) {
|
|
17619
17814
|
const stage = this.instance.getStage();
|
|
17620
|
-
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 {
|
|
17621
17828
|
x: 0,
|
|
17622
|
-
y: 0
|
|
17829
|
+
y: 0,
|
|
17830
|
+
width: 0,
|
|
17831
|
+
height: 0
|
|
17832
|
+
};
|
|
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
|
|
17623
17843
|
};
|
|
17624
|
-
|
|
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
|
+
}
|
|
17625
17873
|
let intersectedNode = void 0;
|
|
17626
|
-
|
|
17627
|
-
if (node.getAttrs().nodeId) {
|
|
17628
|
-
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}`);
|
|
17629
17877
|
if (!parent) continue;
|
|
17630
17878
|
const resolvedNode = this.resolveNode(parent);
|
|
17631
|
-
if (resolvedNode && resolvedNode.getAttrs().
|
|
17879
|
+
if (resolvedNode && resolvedNode.getAttrs().id !== actualLayer?.getAttrs().id) intersectedNode = parent;
|
|
17632
17880
|
continue;
|
|
17633
17881
|
}
|
|
17634
|
-
if (node.getAttrs().
|
|
17635
|
-
intersectedNode = node;
|
|
17882
|
+
if (node$1.getAttrs().id !== actualLayer?.getAttrs().id) {
|
|
17883
|
+
intersectedNode = node$1;
|
|
17636
17884
|
continue;
|
|
17637
17885
|
}
|
|
17638
17886
|
}
|
|
@@ -17642,7 +17890,7 @@ var WeaveTargetingManager = class {
|
|
|
17642
17890
|
this.logger.debug({ point }, "getMousePointer");
|
|
17643
17891
|
const stage = this.instance.getStage();
|
|
17644
17892
|
const mainLayer = this.instance.getMainLayer();
|
|
17645
|
-
let relativeMousePointer = point ? point :
|
|
17893
|
+
let relativeMousePointer = point ? point : mainLayer?.getRelativePointerPosition() ?? {
|
|
17646
17894
|
x: 0,
|
|
17647
17895
|
y: 0
|
|
17648
17896
|
};
|
|
@@ -17650,18 +17898,19 @@ var WeaveTargetingManager = class {
|
|
|
17650
17898
|
let container = mainLayer;
|
|
17651
17899
|
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
17652
17900
|
if (nodesSelection) nodesSelection.disable();
|
|
17653
|
-
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);
|
|
17654
17909
|
if (intersectedNode) {
|
|
17655
|
-
const
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
measureContainer = node.findOne(`#${node.getAttrs().containerId}`);
|
|
17660
|
-
container = node;
|
|
17661
|
-
}
|
|
17662
|
-
if (nodeParent && nodeParent instanceof konva.default.Group && nodeParent.getAttrs().containerId) {
|
|
17663
|
-
measureContainer = nodeParent.findOne(`#${nodeParent.getAttrs().containerId}`);
|
|
17664
|
-
container = nodeParent;
|
|
17910
|
+
const containerOfNode = stage.findOne(`#${intersectedNode.getAttrs().containerId}`);
|
|
17911
|
+
if (containerOfNode) {
|
|
17912
|
+
container = intersectedNode;
|
|
17913
|
+
measureContainer = containerOfNode;
|
|
17665
17914
|
}
|
|
17666
17915
|
}
|
|
17667
17916
|
if (container?.getAttrs().nodeType !== "layer") relativeMousePointer = measureContainer?.getRelativePointerPosition() ?? relativeMousePointer;
|
|
@@ -17670,6 +17919,7 @@ var WeaveTargetingManager = class {
|
|
|
17670
17919
|
y: 0
|
|
17671
17920
|
};
|
|
17672
17921
|
if (nodesSelection) nodesSelection.enable();
|
|
17922
|
+
dummyRect.destroy();
|
|
17673
17923
|
return {
|
|
17674
17924
|
mousePoint: relativeMousePointer,
|
|
17675
17925
|
container,
|
|
@@ -18398,7 +18648,7 @@ var WeaveRegisterManager = class {
|
|
|
18398
18648
|
|
|
18399
18649
|
//#endregion
|
|
18400
18650
|
//#region package.json
|
|
18401
|
-
var version = "0.
|
|
18651
|
+
var version = "0.39.0";
|
|
18402
18652
|
|
|
18403
18653
|
//#endregion
|
|
18404
18654
|
//#region src/managers/setup.ts
|
|
@@ -18470,6 +18720,10 @@ var WeaveStageManager = class {
|
|
|
18470
18720
|
const stage = this.getStage();
|
|
18471
18721
|
return stage.findOne(`#${__inditextech_weave_types.WEAVE_NODE_LAYER_ID}`);
|
|
18472
18722
|
}
|
|
18723
|
+
getSelectionLayer() {
|
|
18724
|
+
const stage = this.getStage();
|
|
18725
|
+
return stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
|
|
18726
|
+
}
|
|
18473
18727
|
getUtilityLayer() {
|
|
18474
18728
|
const stage = this.getStage();
|
|
18475
18729
|
return stage.findOne(`#${__inditextech_weave_types.WEAVE_UTILITY_LAYER_ID}`);
|
|
@@ -18845,6 +19099,9 @@ var Weave = class {
|
|
|
18845
19099
|
getMainLayer() {
|
|
18846
19100
|
return this.stageManager.getMainLayer();
|
|
18847
19101
|
}
|
|
19102
|
+
getSelectionLayer() {
|
|
19103
|
+
return this.stageManager.getSelectionLayer();
|
|
19104
|
+
}
|
|
18848
19105
|
getUtilityLayer() {
|
|
18849
19106
|
return this.stageManager.getUtilityLayer();
|
|
18850
19107
|
}
|
|
@@ -18994,8 +19251,8 @@ var Weave = class {
|
|
|
18994
19251
|
pointIntersectsElement(point) {
|
|
18995
19252
|
return this.targetingManager.pointIntersectsElement(point);
|
|
18996
19253
|
}
|
|
18997
|
-
|
|
18998
|
-
return this.targetingManager.
|
|
19254
|
+
nodeIntersectsContainerElement(node, actualLayer) {
|
|
19255
|
+
return this.targetingManager.nodeIntersectsContainerElement(node, actualLayer);
|
|
18999
19256
|
}
|
|
19000
19257
|
getMousePointer(point) {
|
|
19001
19258
|
return this.targetingManager.getMousePointer(point);
|
|
@@ -19008,8 +19265,7 @@ var Weave = class {
|
|
|
19008
19265
|
if (selectionPlugin) {
|
|
19009
19266
|
const stage = this.getStage();
|
|
19010
19267
|
const instanceNodes = nodesIds.map((nodeId) => {
|
|
19011
|
-
|
|
19012
|
-
if (nodeInstance && nodeInstance.getAttrs().nodeType === "frame") nodeInstance = stage.findOne(`#${nodeId}-selector-area`);
|
|
19268
|
+
const nodeInstance = stage.findOne(`#${nodeId}`);
|
|
19013
19269
|
return nodeInstance;
|
|
19014
19270
|
});
|
|
19015
19271
|
selectionPlugin.setSelectedNodes(instanceNodes);
|
|
@@ -19116,10 +19372,6 @@ var Weave = class {
|
|
|
19116
19372
|
}
|
|
19117
19373
|
};
|
|
19118
19374
|
|
|
19119
|
-
//#endregion
|
|
19120
|
-
//#region src/nodes/stage/constants.ts
|
|
19121
|
-
const WEAVE_STAGE_NODE_TYPE = "stage";
|
|
19122
|
-
|
|
19123
19375
|
//#endregion
|
|
19124
19376
|
//#region src/nodes/stage/stage.ts
|
|
19125
19377
|
var WeaveStageNode = class extends WeaveNode {
|
|
@@ -19139,6 +19391,10 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19139
19391
|
stage.container().addEventListener("blur", () => {
|
|
19140
19392
|
this.stageFocused = false;
|
|
19141
19393
|
});
|
|
19394
|
+
konva.default.Stage.prototype.mode = function(mode) {
|
|
19395
|
+
if (typeof mode !== "undefined") this._mode = mode;
|
|
19396
|
+
return this._mode;
|
|
19397
|
+
};
|
|
19142
19398
|
konva.default.Stage.prototype.allowActions = function(actions) {
|
|
19143
19399
|
if (typeof actions !== "undefined") this._allowActions = actions;
|
|
19144
19400
|
return this._allowActions;
|
|
@@ -19151,6 +19407,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19151
19407
|
if (typeof allowSelection !== "undefined") this._allowSelection = allowSelection;
|
|
19152
19408
|
return this._allowSelection;
|
|
19153
19409
|
};
|
|
19410
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
19154
19411
|
stage.on("pointermove", (e) => {
|
|
19155
19412
|
if (stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
|
|
19156
19413
|
const stage$1 = this.instance.getStage();
|
|
@@ -19161,6 +19418,13 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19161
19418
|
stage$1.container().style.cursor = "default";
|
|
19162
19419
|
}
|
|
19163
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
|
+
});
|
|
19164
19428
|
stage.on("pointerdown", (e) => {
|
|
19165
19429
|
if (e.evt.button === 1) this.wheelMousePressed = true;
|
|
19166
19430
|
});
|
|
@@ -19229,6 +19493,7 @@ var WeaveGroupNode = class extends WeaveNode {
|
|
|
19229
19493
|
onRender(props) {
|
|
19230
19494
|
const group = new konva.default.Group({
|
|
19231
19495
|
...props,
|
|
19496
|
+
isContainerPrincipal: true,
|
|
19232
19497
|
name: "node"
|
|
19233
19498
|
});
|
|
19234
19499
|
this.setupDefaultNodeAugmentation(group);
|
|
@@ -19445,6 +19710,8 @@ const TEXT_LAYOUT = {
|
|
|
19445
19710
|
var WeaveTextNode = class extends WeaveNode {
|
|
19446
19711
|
nodeType = WEAVE_TEXT_NODE_TYPE;
|
|
19447
19712
|
editing = false;
|
|
19713
|
+
textAreaSuperContainer = null;
|
|
19714
|
+
textAreaContainer = null;
|
|
19448
19715
|
textArea = null;
|
|
19449
19716
|
constructor(params) {
|
|
19450
19717
|
super();
|
|
@@ -19506,8 +19773,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19506
19773
|
}
|
|
19507
19774
|
}
|
|
19508
19775
|
});
|
|
19509
|
-
text.
|
|
19510
|
-
e.cancelBubble = true;
|
|
19776
|
+
text.dblClick = () => {
|
|
19511
19777
|
if (this.editing) return;
|
|
19512
19778
|
if (!(this.isSelecting() && this.isNodeSelected(text))) return;
|
|
19513
19779
|
const stage = this.instance.getStage();
|
|
@@ -19517,7 +19783,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19517
19783
|
const onlyTextElements = elements.filter((ele) => ele.getAttrs().nodeType === WEAVE_TEXT_NODE_TYPE);
|
|
19518
19784
|
if (onlyTextElements.length > 0) this.triggerEditMode(onlyTextElements[0]);
|
|
19519
19785
|
}
|
|
19520
|
-
}
|
|
19786
|
+
};
|
|
19521
19787
|
text.on("transform", (e) => {
|
|
19522
19788
|
if (this.isSelecting() && this.isNodeSelected(text)) {
|
|
19523
19789
|
text.setAttrs({
|
|
@@ -19583,19 +19849,20 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19583
19849
|
if (!this.editing) return;
|
|
19584
19850
|
this.updateTextAreaDOM(textNode);
|
|
19585
19851
|
};
|
|
19586
|
-
textAreaDomResize(
|
|
19852
|
+
textAreaDomResize(textNode) {
|
|
19853
|
+
if (!this.textArea || !this.textAreaContainer) return;
|
|
19587
19854
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
19588
|
-
const { width: textAreaWidth } = this.textRenderedSize(textArea.value, textNode);
|
|
19589
|
-
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";
|
|
19590
19857
|
}
|
|
19591
|
-
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";
|
|
19592
19859
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19593
|
-
textAreaContainer.style.height = "auto";
|
|
19594
|
-
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";
|
|
19595
19862
|
}
|
|
19596
|
-
textArea.style.height = "auto";
|
|
19597
|
-
textArea.style.height = textArea.scrollHeight + 1.6 * textNode.getAbsoluteScale().x + "px";
|
|
19598
|
-
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;
|
|
19599
19866
|
}
|
|
19600
19867
|
measureMultilineText(textNode) {
|
|
19601
19868
|
return () => {
|
|
@@ -19616,73 +19883,74 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19616
19883
|
height
|
|
19617
19884
|
};
|
|
19618
19885
|
}
|
|
19619
|
-
mimicTextNode(textNode
|
|
19620
|
-
|
|
19621
|
-
textArea.
|
|
19622
|
-
textArea.
|
|
19623
|
-
textArea.style.
|
|
19624
|
-
textArea.style.
|
|
19625
|
-
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();
|
|
19626
19894
|
let fontWeight = "normal";
|
|
19627
19895
|
let fontStyle = "normal";
|
|
19628
19896
|
if ((textNode.fontStyle() ?? "normal").indexOf("bold") !== -1) fontWeight = "bold";
|
|
19629
19897
|
if ((textNode.fontStyle() ?? "normal").indexOf("italic") !== -1) fontStyle = "italic";
|
|
19630
|
-
textArea.style.fontWeight = fontWeight;
|
|
19631
|
-
textArea.style.backgroundColor = "transparent";
|
|
19632
|
-
textArea.style.fontStyle = fontStyle;
|
|
19633
|
-
textArea.style.fontVariant = textNode.fontVariant();
|
|
19634
|
-
textArea.style.textDecoration = textNode.textDecoration();
|
|
19635
|
-
textArea.style.textAlign = textNode.align();
|
|
19636
|
-
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()}`;
|
|
19637
19905
|
}
|
|
19638
19906
|
createTextAreaDOM(textNode, position) {
|
|
19639
19907
|
const stage = this.instance.getStage();
|
|
19640
|
-
|
|
19641
|
-
textAreaSuperContainer.id = `${textNode.id()}_supercontainer`;
|
|
19642
|
-
textAreaSuperContainer.style.position = "absolute";
|
|
19643
|
-
textAreaSuperContainer.style.top = "0px";
|
|
19644
|
-
textAreaSuperContainer.style.left = "0px";
|
|
19645
|
-
textAreaSuperContainer.style.bottom = "0px";
|
|
19646
|
-
textAreaSuperContainer.style.right = "0px";
|
|
19647
|
-
textAreaSuperContainer.style.overflow = "hidden";
|
|
19648
|
-
textAreaSuperContainer.style.pointerEvents = "none";
|
|
19649
|
-
|
|
19650
|
-
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`;
|
|
19651
19919
|
this.textArea = document.createElement("textarea");
|
|
19652
19920
|
this.textArea.id = textNode.id();
|
|
19653
|
-
textAreaContainer.appendChild(this.textArea);
|
|
19654
|
-
textAreaSuperContainer.appendChild(textAreaContainer);
|
|
19655
|
-
stage.container().appendChild(textAreaSuperContainer);
|
|
19656
|
-
textAreaContainer.style.pointerEvents = "auto";
|
|
19657
|
-
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";
|
|
19658
19926
|
this.textArea.style.pointerEvents = "auto";
|
|
19659
19927
|
this.instance.addEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
|
|
19660
19928
|
this.instance.addEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
|
|
19661
19929
|
window.weaveTextEditing[textNode.id()] = "editing";
|
|
19662
19930
|
this.textArea.value = textNode.text();
|
|
19663
19931
|
this.textArea.id = textNode.id();
|
|
19664
|
-
textAreaContainer.style.overflow = "hidden";
|
|
19665
|
-
textAreaContainer.style.display = "flex";
|
|
19666
|
-
textAreaContainer.style.justifyContent = "start";
|
|
19667
|
-
if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
|
|
19668
|
-
if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
|
|
19669
|
-
if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
|
|
19670
|
-
textAreaContainer.style.position = "absolute";
|
|
19671
|
-
textAreaContainer.style.top = position.y + "px";
|
|
19672
|
-
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";
|
|
19673
19941
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
19674
|
-
textAreaContainer.style.width = this.textArea.scrollWidth + "px";
|
|
19675
|
-
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";
|
|
19676
19944
|
}
|
|
19677
19945
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19678
|
-
textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19679
|
-
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";
|
|
19680
19948
|
}
|
|
19681
19949
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.FIXED) {
|
|
19682
|
-
textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
19683
|
-
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";
|
|
19684
19952
|
}
|
|
19685
|
-
textAreaContainer.style.border = "solid 1px #1e40af";
|
|
19953
|
+
this.textAreaContainer.style.border = "solid 1px #1e40af";
|
|
19686
19954
|
this.textArea.style.position = "absolute";
|
|
19687
19955
|
this.textArea.style.top = "0px";
|
|
19688
19956
|
this.textArea.style.left = "0px";
|
|
@@ -19700,30 +19968,33 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19700
19968
|
this.textArea.style.outline = "none";
|
|
19701
19969
|
this.textArea.style.resize = "none";
|
|
19702
19970
|
this.textArea.style.backgroundColor = "transparent";
|
|
19703
|
-
textAreaContainer.style.transformOrigin = "left top";
|
|
19704
|
-
this.mimicTextNode(textNode
|
|
19971
|
+
this.textAreaContainer.style.transformOrigin = "left top";
|
|
19972
|
+
this.mimicTextNode(textNode);
|
|
19705
19973
|
this.textArea.onfocus = () => {
|
|
19706
|
-
this.textAreaDomResize(
|
|
19974
|
+
this.textAreaDomResize(textNode);
|
|
19707
19975
|
};
|
|
19708
19976
|
this.textArea.onkeydown = () => {
|
|
19709
|
-
this.textAreaDomResize(
|
|
19977
|
+
this.textAreaDomResize(textNode);
|
|
19710
19978
|
};
|
|
19711
19979
|
this.textArea.onkeyup = () => {
|
|
19712
|
-
this.textAreaDomResize(
|
|
19980
|
+
this.textAreaDomResize(textNode);
|
|
19713
19981
|
};
|
|
19714
19982
|
this.textArea.onpaste = () => {
|
|
19715
|
-
this.textAreaDomResize(
|
|
19983
|
+
this.textAreaDomResize(textNode);
|
|
19716
19984
|
};
|
|
19717
19985
|
this.textArea.oninput = () => {
|
|
19718
|
-
this.textAreaDomResize(
|
|
19986
|
+
this.textAreaDomResize(textNode);
|
|
19719
19987
|
};
|
|
19720
|
-
textAreaSuperContainer.addEventListener("scroll", () => {
|
|
19721
|
-
textAreaSuperContainer
|
|
19722
|
-
|
|
19988
|
+
this.textAreaSuperContainer.addEventListener("scroll", () => {
|
|
19989
|
+
if (this.textAreaSuperContainer) {
|
|
19990
|
+
this.textAreaSuperContainer.scrollTop = 0;
|
|
19991
|
+
this.textAreaSuperContainer.scrollLeft = 0;
|
|
19992
|
+
}
|
|
19723
19993
|
});
|
|
19724
|
-
textAreaContainer.addEventListener("scroll", () => {
|
|
19725
|
-
textAreaContainer
|
|
19726
|
-
textAreaContainer.
|
|
19994
|
+
this.textAreaContainer.addEventListener("scroll", () => {
|
|
19995
|
+
if (!this.textAreaContainer) return;
|
|
19996
|
+
this.textAreaContainer.scrollTop = 0;
|
|
19997
|
+
this.textAreaContainer.scrollLeft = 0;
|
|
19727
19998
|
});
|
|
19728
19999
|
this.textArea.addEventListener("scroll", () => {
|
|
19729
20000
|
if (!this.textArea) return;
|
|
@@ -19733,7 +20004,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19733
20004
|
const rotation = textNode.getAbsoluteRotation();
|
|
19734
20005
|
if (rotation) {
|
|
19735
20006
|
const transform$1 = "rotate(" + rotation + "deg)";
|
|
19736
|
-
textAreaContainer.style.transform = transform$1;
|
|
20007
|
+
this.textAreaContainer.style.transform = transform$1;
|
|
19737
20008
|
}
|
|
19738
20009
|
const measures = textNode.measureSize(textNode.text());
|
|
19739
20010
|
const px = 0 * stage.scaleX();
|
|
@@ -19750,6 +20021,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19750
20021
|
textNode.width(textAreaWidth + 3.2);
|
|
19751
20022
|
}
|
|
19752
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 });
|
|
19753
20025
|
textNode.text(this.textArea.value);
|
|
19754
20026
|
this.removeTextAreaDOM(textNode);
|
|
19755
20027
|
this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
|
|
@@ -19763,10 +20035,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19763
20035
|
textNode.text(this.textArea.value);
|
|
19764
20036
|
if (this.textArea && textNode) {
|
|
19765
20037
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT) {
|
|
19766
|
-
textAreaContainer
|
|
19767
|
-
|
|
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
|
+
}
|
|
19768
20042
|
}
|
|
19769
|
-
this.textAreaDomResize(
|
|
20043
|
+
this.textAreaDomResize(textNode);
|
|
19770
20044
|
}
|
|
19771
20045
|
};
|
|
19772
20046
|
this.textArea.addEventListener("keydown", handleKeyDown);
|
|
@@ -19795,52 +20069,47 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19795
20069
|
this.editing = true;
|
|
19796
20070
|
}
|
|
19797
20071
|
updateTextAreaDOM(textNode) {
|
|
19798
|
-
|
|
19799
|
-
const textArea = document.getElementById(textNode.id());
|
|
19800
|
-
if (!textAreaContainer || !textArea) return;
|
|
20072
|
+
if (!this.textAreaContainer || !this.textArea) return;
|
|
19801
20073
|
const stage = this.instance.getStage();
|
|
19802
20074
|
const textPosition = textNode.getClientRect();
|
|
19803
20075
|
const position = {
|
|
19804
20076
|
x: textPosition.x,
|
|
19805
20077
|
y: textPosition.y
|
|
19806
20078
|
};
|
|
19807
|
-
textAreaContainer.style.top = position.y + "px";
|
|
19808
|
-
textAreaContainer.style.left = position.x + "px";
|
|
19809
|
-
if (textNode.getAttrs().verticalAlign === "top") textAreaContainer.style.alignItems = "start";
|
|
19810
|
-
if (textNode.getAttrs().verticalAlign === "middle") textAreaContainer.style.alignItems = "center";
|
|
19811
|
-
if (textNode.getAttrs().verticalAlign === "bottom") textAreaContainer.style.alignItems = "end";
|
|
19812
|
-
this.mimicTextNode(textNode
|
|
19813
|
-
this.textAreaDomResize(
|
|
19814
|
-
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);
|
|
19815
20087
|
const rotation = textNode.getAbsoluteRotation();
|
|
19816
20088
|
if (rotation) {
|
|
19817
20089
|
const transform$1 = "rotate(" + rotation + "deg)";
|
|
19818
|
-
textAreaContainer.style.transform = transform$1;
|
|
20090
|
+
this.textAreaContainer.style.transform = transform$1;
|
|
19819
20091
|
}
|
|
19820
20092
|
const px = 0;
|
|
19821
20093
|
const py = -3 * stage.scaleY();
|
|
19822
20094
|
let transform = "";
|
|
19823
20095
|
transform += "translateX(" + px + "px)";
|
|
19824
20096
|
transform += "translateY(" + py + "px)";
|
|
19825
|
-
textArea.style.transform = transform;
|
|
20097
|
+
this.textArea.style.transform = transform;
|
|
19826
20098
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
19827
20099
|
if (selectionPlugin) {
|
|
19828
20100
|
const tr = selectionPlugin.getTransformer();
|
|
19829
20101
|
this.instance.disablePlugin("nodesSelection");
|
|
19830
20102
|
tr.hide();
|
|
19831
20103
|
}
|
|
20104
|
+
console.log(`Updating text area for text node ${textNode.id()}`, this.editing);
|
|
19832
20105
|
if (this.editing) textNode.visible(false);
|
|
19833
20106
|
else textNode.visible(true);
|
|
19834
20107
|
}
|
|
19835
20108
|
removeTextAreaDOM(textNode) {
|
|
20109
|
+
this.editing = false;
|
|
19836
20110
|
const stage = this.instance.getStage();
|
|
19837
20111
|
delete window.weaveTextEditing[textNode.id()];
|
|
19838
|
-
|
|
19839
|
-
if (textAreaSuperContainer) textAreaSuperContainer.remove();
|
|
19840
|
-
const textAreaContainer = document.getElementById(`${textNode.id()}_container`);
|
|
19841
|
-
if (textAreaContainer) textAreaContainer.remove();
|
|
19842
|
-
const textArea = document.getElementById(textNode.id());
|
|
19843
|
-
if (textArea) textArea.remove();
|
|
20112
|
+
if (this.textAreaSuperContainer) this.textAreaSuperContainer.remove();
|
|
19844
20113
|
textNode.visible(true);
|
|
19845
20114
|
this.updateNode(textNode);
|
|
19846
20115
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -19853,7 +20122,6 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19853
20122
|
}
|
|
19854
20123
|
this.instance.triggerAction("selectionTool");
|
|
19855
20124
|
}
|
|
19856
|
-
this.editing = false;
|
|
19857
20125
|
stage.container().tabIndex = 1;
|
|
19858
20126
|
stage.container().click();
|
|
19859
20127
|
stage.container().focus();
|
|
@@ -19925,7 +20193,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
19925
20193
|
this.instance.addEventListener("onStageDrop", (e) => {
|
|
19926
20194
|
if (window.weaveDragImageURL) {
|
|
19927
20195
|
this.instance.getStage().setPointersPositions(e);
|
|
19928
|
-
const position = this.instance.getStage().
|
|
20196
|
+
const position = this.instance.getStage().getRelativePointerPosition();
|
|
19929
20197
|
this.instance.triggerAction("imageTool", {
|
|
19930
20198
|
imageURL: window.weaveDragImageURL,
|
|
19931
20199
|
position
|
|
@@ -20001,8 +20269,8 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
20001
20269
|
stage.container().style.cursor = "crosshair";
|
|
20002
20270
|
stage.container().focus();
|
|
20003
20271
|
if (position) {
|
|
20004
|
-
this.handleAdding(position);
|
|
20005
20272
|
this.setState(IMAGE_TOOL_STATE.ADDING);
|
|
20273
|
+
this.handleAdding(position);
|
|
20006
20274
|
return;
|
|
20007
20275
|
}
|
|
20008
20276
|
if (this.imageId) {
|
|
@@ -20247,6 +20515,14 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20247
20515
|
});
|
|
20248
20516
|
this.drawGridLines(cropRect$1.x, cropRect$1.y, cropRect$1.width, cropRect$1.height);
|
|
20249
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
|
+
});
|
|
20250
20526
|
this.cropRect.on("dragstart", (e) => {
|
|
20251
20527
|
this.instance.emitEvent("onDrag", e.target);
|
|
20252
20528
|
});
|
|
@@ -20281,6 +20557,7 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20281
20557
|
if (!["Enter", "Escape"].includes(e.key)) return;
|
|
20282
20558
|
this.image.setAttrs({ cropping: false });
|
|
20283
20559
|
if (e.key === "Enter") this.handleClipEnd();
|
|
20560
|
+
const stage = this.instance.getStage();
|
|
20284
20561
|
this.onClose();
|
|
20285
20562
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
20286
20563
|
utilityLayer?.destroyChildren();
|
|
@@ -20301,6 +20578,8 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
20301
20578
|
selectionTransformer.forceUpdate();
|
|
20302
20579
|
}, 0);
|
|
20303
20580
|
}
|
|
20581
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
20582
|
+
this.instance.emitEvent("onImageCropEnd", { instance: this.image });
|
|
20304
20583
|
}
|
|
20305
20584
|
drawGridLines(x, y, width, height) {
|
|
20306
20585
|
if (!this.image.getAttrs().cropping) return;
|
|
@@ -20453,6 +20732,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20453
20732
|
constructor(params) {
|
|
20454
20733
|
super();
|
|
20455
20734
|
const { config } = params ?? {};
|
|
20735
|
+
this.tapStart = {
|
|
20736
|
+
x: 0,
|
|
20737
|
+
y: 0,
|
|
20738
|
+
time: 0
|
|
20739
|
+
};
|
|
20740
|
+
this.lastTapTime = 0;
|
|
20456
20741
|
this.config = {
|
|
20457
20742
|
crossOrigin: config?.crossOrigin ?? "anonymous",
|
|
20458
20743
|
transform: {
|
|
@@ -20466,17 +20751,40 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20466
20751
|
}
|
|
20467
20752
|
triggerCrop(imageNode) {
|
|
20468
20753
|
const stage = this.instance.getStage();
|
|
20754
|
+
stage.mode(WEAVE_STAGE_MODE.cropping);
|
|
20469
20755
|
const image = stage.findOne(`#${imageNode.getAttrs().id}`);
|
|
20470
20756
|
const internalImage = image?.findOne(`#${image.getAttrs().id}-image`);
|
|
20471
20757
|
const cropGroup = image?.findOne(`#${image.getAttrs().id}-cropGroup`);
|
|
20472
20758
|
if (!image || !internalImage || !cropGroup) return;
|
|
20473
20759
|
this.imageCrop = new WeaveImageCrop(this.instance, this, image, internalImage, cropGroup);
|
|
20474
20760
|
this.imageCrop.show(() => {
|
|
20761
|
+
stage.mode(WEAVE_STAGE_MODE.normal);
|
|
20475
20762
|
this.instance.emitEvent("onImageCropEnd", { instance: image });
|
|
20476
20763
|
this.imageCrop = null;
|
|
20477
20764
|
});
|
|
20478
20765
|
this.instance.emitEvent("onImageCropStart", { instance: image });
|
|
20479
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
|
+
};
|
|
20480
20788
|
onRender(props) {
|
|
20481
20789
|
const imageProperties = props.imageProperties;
|
|
20482
20790
|
const imageProps = props;
|
|
@@ -20503,23 +20811,10 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20503
20811
|
this.cachedCropInfo[image$1.getAttrs().id ?? ""] = void 0;
|
|
20504
20812
|
};
|
|
20505
20813
|
image.triggerCrop = () => {
|
|
20506
|
-
|
|
20507
|
-
const image$1 = stage.findOne(`#${id}`);
|
|
20508
|
-
if (!image$1) return;
|
|
20509
|
-
this.triggerCrop(image$1);
|
|
20814
|
+
this.triggerCrop(image);
|
|
20510
20815
|
};
|
|
20511
20816
|
image.closeCrop = (type) => {
|
|
20512
|
-
|
|
20513
|
-
const image$1 = stage.findOne(`#${id}`);
|
|
20514
|
-
if (!image$1 || !this.imageCrop) return;
|
|
20515
|
-
if (type === WEAVE_IMAGE_CROP_END_TYPE.ACCEPT) {
|
|
20516
|
-
this.imageCrop.accept();
|
|
20517
|
-
this.instance.emitEvent("onImageCropEnd", { instance: image$1 });
|
|
20518
|
-
}
|
|
20519
|
-
if (type === WEAVE_IMAGE_CROP_END_TYPE.CANCEL) {
|
|
20520
|
-
this.imageCrop.cancel();
|
|
20521
|
-
this.instance.emitEvent("onImageCropEnd", { instance: image$1 });
|
|
20522
|
-
}
|
|
20817
|
+
this.closeCrop(image, type);
|
|
20523
20818
|
};
|
|
20524
20819
|
image.resetCrop = () => {
|
|
20525
20820
|
const stage = this.instance.getStage();
|
|
@@ -20563,7 +20858,8 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20563
20858
|
height: 0,
|
|
20564
20859
|
strokeScaleEnabled: true,
|
|
20565
20860
|
draggable: false,
|
|
20566
|
-
visible: false
|
|
20861
|
+
visible: false,
|
|
20862
|
+
name: void 0
|
|
20567
20863
|
});
|
|
20568
20864
|
image.add(internalImage);
|
|
20569
20865
|
const cropGroup = new konva.default.Group({
|
|
@@ -20576,13 +20872,12 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20576
20872
|
});
|
|
20577
20873
|
image.add(cropGroup);
|
|
20578
20874
|
this.setupDefaultNodeEvents(image);
|
|
20579
|
-
image.
|
|
20580
|
-
evt.cancelBubble = true;
|
|
20875
|
+
image.dblClick = () => {
|
|
20581
20876
|
if (image.getAttrs().cropping ?? false) return;
|
|
20582
20877
|
if (!internalImage.getAttr("image")) return;
|
|
20583
20878
|
if (!(this.isSelecting() && this.isNodeSelected(image))) return;
|
|
20584
20879
|
this.triggerCrop(image);
|
|
20585
|
-
}
|
|
20880
|
+
};
|
|
20586
20881
|
const imageActionTool = this.getImageToolAction();
|
|
20587
20882
|
const preloadImg = imageActionTool.getPreloadedImage(imageProps.id);
|
|
20588
20883
|
if (preloadImg) {
|
|
@@ -21039,30 +21334,18 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21039
21334
|
const frame = new konva.default.Group({
|
|
21040
21335
|
...frameParams,
|
|
21041
21336
|
id,
|
|
21337
|
+
isContainerPrincipal: true,
|
|
21042
21338
|
containerId: `${id}-group-internal`,
|
|
21339
|
+
measureContainerId: `${id}-selection-area`,
|
|
21043
21340
|
containerOffsetX: 0,
|
|
21044
21341
|
containerOffsetY: borderWidth,
|
|
21045
21342
|
width: props.frameWidth,
|
|
21046
21343
|
height: props.frameHeight,
|
|
21047
21344
|
fill: "transparent",
|
|
21048
|
-
draggable:
|
|
21049
|
-
clip: void 0
|
|
21345
|
+
draggable: true,
|
|
21346
|
+
clip: void 0,
|
|
21347
|
+
name: "node containerCapable"
|
|
21050
21348
|
});
|
|
21051
|
-
frame.getRealClientRect = function(config) {
|
|
21052
|
-
const node = frame.getStage()?.findOne(`#${`${id}-selector-area`}`);
|
|
21053
|
-
const nodeTitle = frame.getStage()?.findOne(`#${`${id}-title`}`);
|
|
21054
|
-
if (!node || !nodeTitle) return {
|
|
21055
|
-
x: 0,
|
|
21056
|
-
y: 0,
|
|
21057
|
-
width: 0,
|
|
21058
|
-
height: 0
|
|
21059
|
-
};
|
|
21060
|
-
const rectContainer = node.getClientRect(config);
|
|
21061
|
-
const rectTitle = nodeTitle.getClientRect(config);
|
|
21062
|
-
rectContainer.y = rectContainer.y - rectTitle.height - titleMargin;
|
|
21063
|
-
rectContainer.height = rectContainer.height + rectTitle.height + titleMargin;
|
|
21064
|
-
return rectContainer;
|
|
21065
|
-
};
|
|
21066
21349
|
this.setupDefaultNodeAugmentation(frame);
|
|
21067
21350
|
const frameInternalGroup = new konva.default.Group({
|
|
21068
21351
|
id: `${id}-selector`,
|
|
@@ -21106,117 +21389,15 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21106
21389
|
draggable: false
|
|
21107
21390
|
});
|
|
21108
21391
|
const textMeasures = text.measureSize(text.getAttrs().text ?? "");
|
|
21392
|
+
const textWidth = textMeasures.width;
|
|
21109
21393
|
const textHeight = textMeasures.height;
|
|
21110
21394
|
text.y(-textHeight - titleMargin);
|
|
21395
|
+
text.width(textWidth);
|
|
21111
21396
|
text.height(textHeight);
|
|
21112
21397
|
frameInternalGroup.add(text);
|
|
21113
|
-
|
|
21114
|
-
...frameParams,
|
|
21115
|
-
id: `${id}-selector-area`,
|
|
21116
|
-
name: "node",
|
|
21117
|
-
nodeId: id,
|
|
21118
|
-
containerId: `${id}-group-internal`,
|
|
21119
|
-
x: 0,
|
|
21120
|
-
y: 0,
|
|
21121
|
-
strokeWidth: 0,
|
|
21122
|
-
strokeScaleEnabled: false,
|
|
21123
|
-
width: props.frameWidth,
|
|
21124
|
-
height: props.frameHeight,
|
|
21125
|
-
fill: "transparent",
|
|
21126
|
-
draggable: true
|
|
21127
|
-
});
|
|
21128
|
-
selectorArea.on("dragmove", () => {
|
|
21129
|
-
if (this.isSelecting() && this.isNodeSelected(selectorArea)) {
|
|
21130
|
-
clearContainerTargets(this.instance);
|
|
21131
|
-
frame.setAbsolutePosition(selectorArea.getAbsolutePosition());
|
|
21132
|
-
selectorArea.setAttrs({
|
|
21133
|
-
x: 0,
|
|
21134
|
-
y: 0
|
|
21135
|
-
});
|
|
21136
|
-
}
|
|
21137
|
-
});
|
|
21138
|
-
selectorArea.on("dragend", () => {
|
|
21139
|
-
if (this.isSelecting() && this.isNodeSelected(selectorArea)) {
|
|
21140
|
-
clearContainerTargets(this.instance);
|
|
21141
|
-
frame.setAbsolutePosition(selectorArea.getAbsolutePosition());
|
|
21142
|
-
selectorArea.setAttrs({
|
|
21143
|
-
x: 0,
|
|
21144
|
-
y: 0
|
|
21145
|
-
});
|
|
21146
|
-
this.instance.updateNode(this.serialize(selectorArea));
|
|
21147
|
-
}
|
|
21148
|
-
});
|
|
21149
|
-
selectorArea.getTransformerProperties = () => {
|
|
21398
|
+
frame.getTransformerProperties = () => {
|
|
21150
21399
|
return this.config.transform;
|
|
21151
21400
|
};
|
|
21152
|
-
selectorArea.updatePosition = (position) => {
|
|
21153
|
-
frame.setAbsolutePosition(position);
|
|
21154
|
-
selectorArea.setAttrs({
|
|
21155
|
-
x: 0,
|
|
21156
|
-
y: 0
|
|
21157
|
-
});
|
|
21158
|
-
};
|
|
21159
|
-
const updateFrame = (e) => {
|
|
21160
|
-
const selectorArea$1 = e.target;
|
|
21161
|
-
const stage = selectorArea$1.getStage();
|
|
21162
|
-
if (!stage) return;
|
|
21163
|
-
const absPos = selectorArea$1.getAbsolutePosition();
|
|
21164
|
-
const absRot = selectorArea$1.getAbsoluteRotation();
|
|
21165
|
-
const scaleX = selectorArea$1.scaleX();
|
|
21166
|
-
const scaleY = selectorArea$1.scaleY();
|
|
21167
|
-
selectorArea$1.x(0);
|
|
21168
|
-
selectorArea$1.y(0);
|
|
21169
|
-
frame.setAbsolutePosition(absPos);
|
|
21170
|
-
frame.rotation(absRot);
|
|
21171
|
-
frame.width(selectorArea$1.width());
|
|
21172
|
-
frame.height(selectorArea$1.height());
|
|
21173
|
-
frameInternalGroup.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21174
|
-
frameInternalGroup.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21175
|
-
background.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21176
|
-
background.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21177
|
-
text.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21178
|
-
const textMeasures$1 = text.measureSize(text.getAttrs().text ?? "");
|
|
21179
|
-
const textHeight$1 = textMeasures$1.height;
|
|
21180
|
-
text.height(textHeight$1 * scaleY);
|
|
21181
|
-
frameInternal.width(Math.max(5, selectorArea$1.width() * scaleX));
|
|
21182
|
-
frameInternal.height(Math.max(5, selectorArea$1.height() * scaleY));
|
|
21183
|
-
};
|
|
21184
|
-
const handleSelectorAreaTransform = (e) => {
|
|
21185
|
-
updateFrame(e);
|
|
21186
|
-
const node = e.target;
|
|
21187
|
-
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
21188
|
-
if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.evaluateGuidelines(e);
|
|
21189
|
-
const clonedSA = selectorArea.clone();
|
|
21190
|
-
const scaleX = clonedSA.scaleX();
|
|
21191
|
-
const scaleY = clonedSA.scaleY();
|
|
21192
|
-
clonedSA.x(0);
|
|
21193
|
-
clonedSA.y(0);
|
|
21194
|
-
clonedSA.width(Math.max(5, clonedSA.width() * scaleX));
|
|
21195
|
-
clonedSA.height(Math.max(5, clonedSA.height() * scaleY));
|
|
21196
|
-
clonedSA.scaleX(1);
|
|
21197
|
-
clonedSA.scaleY(1);
|
|
21198
|
-
e.cancelBubble = true;
|
|
21199
|
-
};
|
|
21200
|
-
selectorArea.on("transformend", (e) => {
|
|
21201
|
-
this.instance.emitEvent("onTransform", e.target);
|
|
21202
|
-
});
|
|
21203
|
-
selectorArea.on("transform", (0, import_lodash.throttle)(handleSelectorAreaTransform, 50));
|
|
21204
|
-
selectorArea.on("transformend", (e) => {
|
|
21205
|
-
this.instance.emitEvent("onTransform", null);
|
|
21206
|
-
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
21207
|
-
if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
21208
|
-
const scaleX = selectorArea.scaleX();
|
|
21209
|
-
const scaleY = selectorArea.scaleY();
|
|
21210
|
-
selectorArea.x(0);
|
|
21211
|
-
selectorArea.y(0);
|
|
21212
|
-
selectorArea.width(Math.max(5, selectorArea.width() * scaleX));
|
|
21213
|
-
selectorArea.height(Math.max(5, selectorArea.height() * scaleY));
|
|
21214
|
-
selectorArea.scaleX(1);
|
|
21215
|
-
selectorArea.scaleY(1);
|
|
21216
|
-
updateFrame(e);
|
|
21217
|
-
this.instance.updateNode(this.serialize(selectorArea));
|
|
21218
|
-
});
|
|
21219
|
-
frameInternalGroup.add(selectorArea);
|
|
21220
21401
|
const frameInternal = new konva.default.Group({
|
|
21221
21402
|
id: `${id}-group-internal`,
|
|
21222
21403
|
nodeId: id,
|
|
@@ -21230,13 +21411,60 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21230
21411
|
const height = (frameInternal.height() + borderWidth) * frameInternal.scaleY();
|
|
21231
21412
|
ctx.rect(-(borderWidth / 2) * frameInternal.scaleX(), -(borderWidth / 2) * frameInternal.scaleY(), width, height);
|
|
21232
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
|
|
21436
|
+
});
|
|
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,
|
|
21233
21450
|
draggable: false
|
|
21234
21451
|
});
|
|
21235
|
-
|
|
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");
|
|
21236
21466
|
this.setupDefaultNodeEvents(frame);
|
|
21237
|
-
frame.off("
|
|
21238
|
-
frame.off("dragmove");
|
|
21239
|
-
frame.off("dragend");
|
|
21467
|
+
frame.off("pointerover");
|
|
21240
21468
|
frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
|
|
21241
21469
|
background.setAttrs({
|
|
21242
21470
|
stroke: onTargetLeaveBorderColor,
|
|
@@ -21254,59 +21482,30 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21254
21482
|
return frame;
|
|
21255
21483
|
}
|
|
21256
21484
|
onUpdate(nodeInstance, nextProps) {
|
|
21257
|
-
const
|
|
21258
|
-
const frameNode = nodeInstance;
|
|
21485
|
+
const stage = this.instance.getStage();
|
|
21259
21486
|
const newProps = { ...nextProps };
|
|
21260
21487
|
const { titleMargin, borderWidth } = this.config;
|
|
21261
21488
|
nodeInstance.setAttrs({
|
|
21262
21489
|
...newProps,
|
|
21490
|
+
name: "node containerCapable",
|
|
21263
21491
|
containerOffsetX: 0,
|
|
21264
21492
|
containerOffsetY: borderWidth,
|
|
21265
21493
|
clip: void 0
|
|
21266
21494
|
});
|
|
21267
|
-
const
|
|
21268
|
-
|
|
21269
|
-
|
|
21270
|
-
|
|
21271
|
-
const
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
|
|
21275
|
-
|
|
21276
|
-
|
|
21277
|
-
|
|
21278
|
-
|
|
21279
|
-
|
|
21280
|
-
|
|
21281
|
-
y: 0,
|
|
21282
|
-
width: width * selectorArea.scaleX(),
|
|
21283
|
-
height: height * selectorArea.scaleY()
|
|
21284
|
-
});
|
|
21285
|
-
const background = frameNode.findOne(`#${id}-bg`);
|
|
21286
|
-
if (background) background.setAttrs({
|
|
21287
|
-
x: 0,
|
|
21288
|
-
y: 0,
|
|
21289
|
-
width: width * selectorArea.scaleX(),
|
|
21290
|
-
height: height * selectorArea.scaleY()
|
|
21291
|
-
});
|
|
21292
|
-
const text = frameNode.findOne(`#${id}-title`);
|
|
21293
|
-
if (text) {
|
|
21294
|
-
text.setAttrs({
|
|
21295
|
-
x: 0,
|
|
21296
|
-
text: nextProps.title,
|
|
21297
|
-
width: width * selectorArea.scaleX()
|
|
21298
|
-
});
|
|
21299
|
-
const textMeasures = text.measureSize(text.getAttrs().text ?? "");
|
|
21300
|
-
const textHeight = textMeasures.height;
|
|
21301
|
-
text.y(-textHeight - titleMargin);
|
|
21302
|
-
text.height(textHeight * selectorArea.scaleY());
|
|
21303
|
-
}
|
|
21304
|
-
const frameInternal = frameNode.findOne(`#${id}-group-internal`);
|
|
21305
|
-
if (frameInternal) frameInternal.setAttrs({
|
|
21306
|
-
x: borderWidth,
|
|
21307
|
-
y: borderWidth,
|
|
21308
|
-
width: (width - borderWidth * 2) * selectorArea.scaleX(),
|
|
21309
|
-
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);
|
|
21310
21509
|
});
|
|
21311
21510
|
}
|
|
21312
21511
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -21315,10 +21514,8 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21315
21514
|
serialize(instance) {
|
|
21316
21515
|
const stage = this.instance.getStage();
|
|
21317
21516
|
const attrs = instance.getAttrs();
|
|
21318
|
-
|
|
21319
|
-
|
|
21320
|
-
let frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21321
|
-
if (attrs.id?.indexOf("-selector-area") !== -1) frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21517
|
+
const mainNode = instance;
|
|
21518
|
+
const frameInternal = stage.findOne(`#${attrs.containerId}`);
|
|
21322
21519
|
const childrenMapped = [];
|
|
21323
21520
|
if (frameInternal) {
|
|
21324
21521
|
const children = [...frameInternal.getChildren()];
|
|
@@ -23321,6 +23518,10 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23321
23518
|
const scale = Math.min(scaleX, scaleY);
|
|
23322
23519
|
return scale;
|
|
23323
23520
|
}
|
|
23521
|
+
getSelectionPlugin() {
|
|
23522
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23523
|
+
return selectionPlugin;
|
|
23524
|
+
}
|
|
23324
23525
|
fitToScreen() {
|
|
23325
23526
|
if (!this.enabled) return;
|
|
23326
23527
|
const mainLayer = this.instance.getMainLayer();
|
|
@@ -23361,7 +23562,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23361
23562
|
fitToSelection() {
|
|
23362
23563
|
if (!this.enabled) return;
|
|
23363
23564
|
const stage = this.instance.getStage();
|
|
23364
|
-
const selectionPlugin = this.
|
|
23565
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
23365
23566
|
if (!selectionPlugin) return;
|
|
23366
23567
|
const nodes = selectionPlugin.getTransformer().getNodes();
|
|
23367
23568
|
if (nodes.length === 0) return;
|
|
@@ -24569,7 +24770,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
24569
24770
|
strokeElements: []
|
|
24570
24771
|
});
|
|
24571
24772
|
const nodeInstance = nodeHandler.onRender(node.props);
|
|
24572
|
-
this.
|
|
24773
|
+
this.measureContainer?.add(nodeInstance);
|
|
24573
24774
|
}
|
|
24574
24775
|
this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
|
|
24575
24776
|
}
|
|
@@ -25927,8 +26128,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
25927
26128
|
};
|
|
25928
26129
|
stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
|
|
25929
26130
|
stage.on("pointermove", () => {
|
|
25930
|
-
if (
|
|
25931
|
-
this.onRender();
|
|
26131
|
+
if (this.enabled) this.onRender();
|
|
25932
26132
|
});
|
|
25933
26133
|
window.addEventListener("wheel", () => {
|
|
25934
26134
|
if (!this.enabled || this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed) return;
|
|
@@ -26698,9 +26898,12 @@ var WeaveStageDropAreaPlugin = class extends WeavePlugin {
|
|
|
26698
26898
|
e.stopPropagation();
|
|
26699
26899
|
});
|
|
26700
26900
|
stage.container().addEventListener("drop", (e) => {
|
|
26901
|
+
e.preventDefault();
|
|
26701
26902
|
e.stopPropagation();
|
|
26702
26903
|
this.instance.emitEvent("onStageDrop", e);
|
|
26703
26904
|
});
|
|
26905
|
+
window.addEventListener("dragover", (e) => e.preventDefault(), { passive: false });
|
|
26906
|
+
window.addEventListener("drop", (e) => e.preventDefault(), { passive: false });
|
|
26704
26907
|
}
|
|
26705
26908
|
enable() {
|
|
26706
26909
|
this.enabled = true;
|
|
@@ -26879,6 +27082,22 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26879
27082
|
});
|
|
26880
27083
|
}
|
|
26881
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
|
+
}
|
|
26882
27101
|
getLineGuideStops(skipNodes) {
|
|
26883
27102
|
const stage = this.instance.getStage();
|
|
26884
27103
|
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
@@ -26894,7 +27113,10 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
26894
27113
|
stage.height()
|
|
26895
27114
|
];
|
|
26896
27115
|
stage.find(".node").forEach((guideItem) => {
|
|
27116
|
+
if (guideItem.getParent()?.getAttrs().nodeType === "group") return;
|
|
27117
|
+
if (skipNodes.includes(guideItem.getParent()?.getAttrs().nodeId)) return;
|
|
26897
27118
|
if (skipNodes.includes(guideItem.getAttrs().id ?? "")) return;
|
|
27119
|
+
if (!this.nodeIntersectsViewport(guideItem)) return;
|
|
26898
27120
|
const box = guideItem.getClientRect({ skipStroke: true });
|
|
26899
27121
|
vertical.push([
|
|
26900
27122
|
box.x,
|
|
@@ -27141,6 +27363,7 @@ exports.WEAVE_NODES_SNAPPING_KEY = WEAVE_NODES_SNAPPING_KEY
|
|
|
27141
27363
|
exports.WEAVE_RECTANGLE_NODE_TYPE = WEAVE_RECTANGLE_NODE_TYPE
|
|
27142
27364
|
exports.WEAVE_REGULAR_POLYGON_NODE_TYPE = WEAVE_REGULAR_POLYGON_NODE_TYPE
|
|
27143
27365
|
exports.WEAVE_STAGE_GRID_KEY = WEAVE_STAGE_GRID_KEY
|
|
27366
|
+
exports.WEAVE_STAGE_MODE = WEAVE_STAGE_MODE
|
|
27144
27367
|
exports.WEAVE_STAGE_NODE_TYPE = WEAVE_STAGE_NODE_TYPE
|
|
27145
27368
|
exports.WEAVE_STAR_NODE_TYPE = WEAVE_STAR_NODE_TYPE
|
|
27146
27369
|
exports.WEAVE_STROKE_NODE_TYPE = WEAVE_STROKE_NODE_TYPE
|
|
@@ -27204,6 +27427,7 @@ exports.checkIfOverContainer = checkIfOverContainer
|
|
|
27204
27427
|
exports.clearContainerTargets = clearContainerTargets
|
|
27205
27428
|
exports.getBoundingBox = getBoundingBox
|
|
27206
27429
|
exports.getContrastTextColor = getContrastTextColor
|
|
27430
|
+
exports.getTargetedNode = getTargetedNode
|
|
27207
27431
|
exports.moveNodeToContainer = moveNodeToContainer
|
|
27208
27432
|
exports.resetScale = resetScale
|
|
27209
27433
|
exports.stringToColor = stringToColor
|