@inditextech/weave-sdk 0.52.3 → 0.54.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 +233 -134
- package/dist/sdk.d.cts +68 -11
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +68 -11
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +243 -148
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -15925,6 +15925,27 @@ function getTopmostShadowHost(el) {
|
|
|
15925
15925
|
}
|
|
15926
15926
|
return current?.shadowRoot || null;
|
|
15927
15927
|
}
|
|
15928
|
+
function getVisibleNodes(instance, stage, nodeParent, skipNodes, referenceLayer) {
|
|
15929
|
+
const nodesSelection = instance.getPlugin("nodesSelection");
|
|
15930
|
+
if (nodesSelection) nodesSelection.getTransformer().hide();
|
|
15931
|
+
const nodes = getVisibleNodesInViewport(stage, referenceLayer);
|
|
15932
|
+
const finalVisibleNodes = [];
|
|
15933
|
+
nodes.forEach((node) => {
|
|
15934
|
+
const actualNodeParent = instance.getNodeContainer(node);
|
|
15935
|
+
if (actualNodeParent?.getAttrs().id !== nodeParent?.getAttrs().id) return;
|
|
15936
|
+
if (node.getParent()?.getAttrs().nodeType === "group") return;
|
|
15937
|
+
if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
|
|
15938
|
+
if (skipNodes.includes(node.getAttrs().id ?? "")) return;
|
|
15939
|
+
if (node.getParent() !== referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
|
|
15940
|
+
if (node.getParent() !== referenceLayer && node.getParent()?.getAttrs().nodeId) {
|
|
15941
|
+
const realNode = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
|
|
15942
|
+
if (realNode && realNode !== referenceLayer) return;
|
|
15943
|
+
}
|
|
15944
|
+
finalVisibleNodes.push(node);
|
|
15945
|
+
});
|
|
15946
|
+
if (nodesSelection) nodesSelection.getTransformer().show();
|
|
15947
|
+
return finalVisibleNodes;
|
|
15948
|
+
}
|
|
15928
15949
|
|
|
15929
15950
|
//#endregion
|
|
15930
15951
|
//#region src/actions/selection-tool/constants.ts
|
|
@@ -16160,6 +16181,22 @@ const NODE_SNAP = {
|
|
|
16160
16181
|
const WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY = "nodesDistanceSnapping";
|
|
16161
16182
|
const GUIDE_HORIZONTAL_LINE_NAME = "guide-distance-snapping-horizontal-line";
|
|
16162
16183
|
const GUIDE_VERTICAL_LINE_NAME = "guide-distance-snapping-vertical-line";
|
|
16184
|
+
const GUIDE_DISTANCE_LINE_DEFAULT_CONFIG = {
|
|
16185
|
+
line: {
|
|
16186
|
+
stroke: "#E12D3C",
|
|
16187
|
+
strokeWidth: 1
|
|
16188
|
+
},
|
|
16189
|
+
label: {
|
|
16190
|
+
linePadding: 10,
|
|
16191
|
+
height: 20,
|
|
16192
|
+
cornerRadius: 0,
|
|
16193
|
+
fill: "#E12D3C",
|
|
16194
|
+
fontStyle: "normal",
|
|
16195
|
+
fontSize: 14,
|
|
16196
|
+
fontFamily: "Arial",
|
|
16197
|
+
paddingX: 4
|
|
16198
|
+
}
|
|
16199
|
+
};
|
|
16163
16200
|
const GUIDE_ENTER_SNAPPING_TOLERANCE = 3;
|
|
16164
16201
|
const GUIDE_EXIT_SNAPPING_TOLERANCE = 5;
|
|
16165
16202
|
const NODE_SNAP_HORIZONTAL = {
|
|
@@ -16943,12 +16980,24 @@ const COPY_PASTE_NODES_PLUGIN_STATE = {
|
|
|
16943
16980
|
["IDLE"]: "idle",
|
|
16944
16981
|
["PASTING"]: "pasting"
|
|
16945
16982
|
};
|
|
16983
|
+
const WEAVE_COPY_PASTE_CONFIG_DEFAULT = { paddingOnPaste: {
|
|
16984
|
+
enabled: false,
|
|
16985
|
+
paddingX: 0,
|
|
16986
|
+
paddingY: 0
|
|
16987
|
+
} };
|
|
16946
16988
|
|
|
16947
16989
|
//#endregion
|
|
16948
16990
|
//#region src/plugins/copy-paste-nodes/copy-paste-nodes.ts
|
|
16949
16991
|
var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
16950
|
-
constructor() {
|
|
16992
|
+
constructor(params) {
|
|
16951
16993
|
super();
|
|
16994
|
+
this.config = {
|
|
16995
|
+
...WEAVE_COPY_PASTE_CONFIG_DEFAULT,
|
|
16996
|
+
...params?.config
|
|
16997
|
+
};
|
|
16998
|
+
this.actualInternalPaddingX = 0;
|
|
16999
|
+
this.actualInternalPaddingY = 0;
|
|
17000
|
+
this.lastInternalPasteSnapshot = "";
|
|
16952
17001
|
this.state = COPY_PASTE_NODES_PLUGIN_STATE.IDLE;
|
|
16953
17002
|
}
|
|
16954
17003
|
getName() {
|
|
@@ -17006,6 +17055,20 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17006
17055
|
const catcher = this.getCatcherElement();
|
|
17007
17056
|
catcher?.focus();
|
|
17008
17057
|
}
|
|
17058
|
+
checkIfInternalElementsAreNew(newData) {
|
|
17059
|
+
if (!this.config.paddingOnPaste.enabled) return false;
|
|
17060
|
+
if (this.lastInternalPasteSnapshot !== newData) {
|
|
17061
|
+
this.lastInternalPasteSnapshot = newData;
|
|
17062
|
+
return true;
|
|
17063
|
+
}
|
|
17064
|
+
return false;
|
|
17065
|
+
}
|
|
17066
|
+
updateInternalPastePadding() {
|
|
17067
|
+
if (this.config.paddingOnPaste.enabled) {
|
|
17068
|
+
this.actualInternalPaddingX = this.actualInternalPaddingX + this.config.paddingOnPaste.paddingX;
|
|
17069
|
+
this.actualInternalPaddingY = this.actualInternalPaddingY + this.config.paddingOnPaste.paddingY;
|
|
17070
|
+
}
|
|
17071
|
+
}
|
|
17009
17072
|
initEvents() {
|
|
17010
17073
|
const stage = this.instance.getStage();
|
|
17011
17074
|
this.createPasteCatcher();
|
|
@@ -17099,6 +17162,12 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17099
17162
|
const stage = this.instance.getStage();
|
|
17100
17163
|
if (this.toPaste) {
|
|
17101
17164
|
const nodesToSelect = [];
|
|
17165
|
+
const newElements = this.checkIfInternalElementsAreNew(JSON.stringify(this.toPaste));
|
|
17166
|
+
if (this.config.paddingOnPaste.enabled && newElements) {
|
|
17167
|
+
this.actualInternalPaddingX = 0;
|
|
17168
|
+
this.actualInternalPaddingY = 0;
|
|
17169
|
+
}
|
|
17170
|
+
this.updateInternalPastePadding();
|
|
17102
17171
|
for (const element of Object.keys(this.toPaste.weave)) {
|
|
17103
17172
|
const node = this.toPaste.weave[element].element;
|
|
17104
17173
|
const posRelativeToSelection = this.toPaste.weave[element].posRelativeToSelection;
|
|
@@ -17116,8 +17185,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17116
17185
|
const scale = stage.scaleX();
|
|
17117
17186
|
const stagePos = stage.position();
|
|
17118
17187
|
localPos = {
|
|
17119
|
-
x: (localPos.x - stagePos.x) / scale,
|
|
17120
|
-
y: (localPos.y - stagePos.y) / scale
|
|
17188
|
+
x: (localPos.x - stagePos.x + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingX : 0)) / scale,
|
|
17189
|
+
y: (localPos.y - stagePos.y + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingY : 0)) / scale
|
|
17121
17190
|
};
|
|
17122
17191
|
}
|
|
17123
17192
|
if (container && container.getAttrs().nodeType === "frame") {
|
|
@@ -17130,15 +17199,27 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17130
17199
|
node.props.x = localPos.x + realOffset.x + posRelativeToSelection.x;
|
|
17131
17200
|
node.props.y = localPos.y + realOffset.y + posRelativeToSelection.y;
|
|
17132
17201
|
}
|
|
17202
|
+
} else {
|
|
17203
|
+
const nodeHandler = this.instance.getNodeHandler(node.props.nodeType ?? "");
|
|
17204
|
+
if (nodeHandler) {
|
|
17205
|
+
node.props.x = node.props.x + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingX : 0);
|
|
17206
|
+
node.props.y = node.props.y + (this.config.paddingOnPaste.enabled ? this.actualInternalPaddingY : 0);
|
|
17207
|
+
}
|
|
17133
17208
|
}
|
|
17134
17209
|
this.instance.addNode(node, containerId);
|
|
17135
17210
|
const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
|
|
17136
17211
|
if (realNode) nodesToSelect.push(realNode);
|
|
17137
|
-
this.instance.emitEvent("onPaste");
|
|
17138
17212
|
}
|
|
17139
|
-
this.instance.emitEvent("onPaste",
|
|
17213
|
+
this.instance.emitEvent("onPaste", {
|
|
17214
|
+
error: void 0,
|
|
17215
|
+
pastedNodes: nodesToSelect.map((n) => n.getAttrs().id ?? "")
|
|
17216
|
+
});
|
|
17140
17217
|
const nodesSelectionPlugin = this.getNodesSelectionPlugin();
|
|
17141
17218
|
nodesSelectionPlugin?.setSelectedNodes(nodesToSelect);
|
|
17219
|
+
this.instance?.triggerAction("fitToSelectionTool", {
|
|
17220
|
+
previousAction: "selectionTool",
|
|
17221
|
+
smartZoom: true
|
|
17222
|
+
});
|
|
17142
17223
|
this.toPaste = void 0;
|
|
17143
17224
|
}
|
|
17144
17225
|
this.cancel();
|
|
@@ -17184,9 +17265,12 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17184
17265
|
}
|
|
17185
17266
|
try {
|
|
17186
17267
|
await this.writeClipboardData(JSON.stringify(copyClipboard));
|
|
17268
|
+
this.actualInternalPaddingX = 0;
|
|
17269
|
+
this.actualInternalPaddingY = 0;
|
|
17270
|
+
this.lastInternalPasteSnapshot = "";
|
|
17187
17271
|
this.instance.emitEvent("onCopy");
|
|
17188
17272
|
} catch (ex) {
|
|
17189
|
-
this.instance.emitEvent("onCopy", ex);
|
|
17273
|
+
this.instance.emitEvent("onCopy", { error: ex });
|
|
17190
17274
|
}
|
|
17191
17275
|
}
|
|
17192
17276
|
async copy() {
|
|
@@ -17202,7 +17286,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17202
17286
|
return;
|
|
17203
17287
|
}
|
|
17204
17288
|
} catch (ex) {
|
|
17205
|
-
this.instance.emitEvent("onPaste", ex);
|
|
17289
|
+
this.instance.emitEvent("onPaste", { error: ex });
|
|
17206
17290
|
}
|
|
17207
17291
|
try {
|
|
17208
17292
|
const items = await navigator.clipboard.read();
|
|
@@ -17228,7 +17312,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
17228
17312
|
items
|
|
17229
17313
|
});
|
|
17230
17314
|
} catch (ex) {
|
|
17231
|
-
this.instance.emitEvent("onPaste", ex);
|
|
17315
|
+
this.instance.emitEvent("onPaste", { error: ex });
|
|
17232
17316
|
}
|
|
17233
17317
|
}
|
|
17234
17318
|
getSelectedNodes() {
|
|
@@ -19190,7 +19274,7 @@ var WeaveRegisterManager = class {
|
|
|
19190
19274
|
|
|
19191
19275
|
//#endregion
|
|
19192
19276
|
//#region package.json
|
|
19193
|
-
var version = "0.
|
|
19277
|
+
var version = "0.54.0";
|
|
19194
19278
|
|
|
19195
19279
|
//#endregion
|
|
19196
19280
|
//#region src/managers/setup.ts
|
|
@@ -19781,6 +19865,15 @@ var Weave = class {
|
|
|
19781
19865
|
}
|
|
19782
19866
|
return nodeContainer;
|
|
19783
19867
|
}
|
|
19868
|
+
getNodeContainer(node) {
|
|
19869
|
+
const stage = this.getStage();
|
|
19870
|
+
let nodeContainer = node.getParent();
|
|
19871
|
+
if (typeof node.getParent()?.getAttrs().nodeId !== "undefined") {
|
|
19872
|
+
const realContainer = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
|
|
19873
|
+
if (realContainer) nodeContainer = realContainer;
|
|
19874
|
+
}
|
|
19875
|
+
return nodeContainer;
|
|
19876
|
+
}
|
|
19784
19877
|
moveUp(node) {
|
|
19785
19878
|
this.zIndexManager.moveUp(node);
|
|
19786
19879
|
}
|
|
@@ -25596,8 +25689,11 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25596
25689
|
super();
|
|
25597
25690
|
this.pointers = new Map();
|
|
25598
25691
|
this.panning = false;
|
|
25692
|
+
this.isDragging = false;
|
|
25693
|
+
this.enableMove = false;
|
|
25599
25694
|
this.enabled = true;
|
|
25600
25695
|
this.moveToolActive = false;
|
|
25696
|
+
this.isMouseLeftButtonPressed = false;
|
|
25601
25697
|
this.isMouseMiddleButtonPressed = false;
|
|
25602
25698
|
this.isCtrlOrMetaPressed = false;
|
|
25603
25699
|
this.isSpaceKeyPressed = false;
|
|
@@ -25609,7 +25705,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25609
25705
|
onInit() {
|
|
25610
25706
|
this.initEvents();
|
|
25611
25707
|
}
|
|
25612
|
-
|
|
25708
|
+
setCursor() {
|
|
25613
25709
|
const stage = this.instance.getStage();
|
|
25614
25710
|
if (stage.container().style.cursor !== "grabbing") {
|
|
25615
25711
|
this.previousPointer = stage.container().style.cursor;
|
|
@@ -25633,7 +25729,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25633
25729
|
this.getNodesEdgeSnappingPlugin()?.disable();
|
|
25634
25730
|
this.getNodesDistanceSnappingPlugin()?.disable();
|
|
25635
25731
|
this.isSpaceKeyPressed = true;
|
|
25636
|
-
this.
|
|
25732
|
+
this.setCursor();
|
|
25637
25733
|
}
|
|
25638
25734
|
});
|
|
25639
25735
|
window.addEventListener("keyup", (e) => {
|
|
@@ -25648,7 +25744,6 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25648
25744
|
}
|
|
25649
25745
|
});
|
|
25650
25746
|
let lastPos = null;
|
|
25651
|
-
let isDragging = false;
|
|
25652
25747
|
stage.on("pointerdown", (e) => {
|
|
25653
25748
|
this.pointers.set(e.evt.pointerId, {
|
|
25654
25749
|
x: e.evt.clientX,
|
|
@@ -25656,14 +25751,15 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25656
25751
|
});
|
|
25657
25752
|
if (this.pointers.size > 1) return;
|
|
25658
25753
|
const activeAction = this.instance.getActiveAction();
|
|
25659
|
-
|
|
25660
|
-
if (
|
|
25661
|
-
if (
|
|
25662
|
-
if (
|
|
25663
|
-
if (
|
|
25664
|
-
|
|
25754
|
+
this.enableMove = false;
|
|
25755
|
+
if (activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
|
|
25756
|
+
if (e.evt.pointerType === "mouse" && e.evt.buttons === 1) this.isMouseLeftButtonPressed = true;
|
|
25757
|
+
if (e.evt.pointerType === "mouse" && e.evt.buttons === 4) this.isMouseMiddleButtonPressed = true;
|
|
25758
|
+
if (this.enabled && (this.isSpaceKeyPressed || this.moveToolActive && this.isMouseLeftButtonPressed || this.isMouseMiddleButtonPressed)) this.enableMove = true;
|
|
25759
|
+
if (this.enableMove) {
|
|
25760
|
+
this.isDragging = true;
|
|
25665
25761
|
lastPos = stage.getPointerPosition();
|
|
25666
|
-
this.
|
|
25762
|
+
this.setCursor();
|
|
25667
25763
|
}
|
|
25668
25764
|
});
|
|
25669
25765
|
stage.on("pointercancel", (e) => {
|
|
@@ -25677,7 +25773,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25677
25773
|
});
|
|
25678
25774
|
if (this.pointers.size > 1) return;
|
|
25679
25775
|
if (this.isSpaceKeyPressed) stage.container().style.cursor = "grabbing";
|
|
25680
|
-
if (!isDragging) return;
|
|
25776
|
+
if (!this.isDragging) return;
|
|
25681
25777
|
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
25682
25778
|
const pos = stage.getPointerPosition();
|
|
25683
25779
|
if (pos && lastPos) {
|
|
@@ -25692,7 +25788,11 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
25692
25788
|
stage.on("pointermove", handleMouseMove);
|
|
25693
25789
|
stage.on("pointerup", (e) => {
|
|
25694
25790
|
this.pointers.delete(e.evt.pointerId);
|
|
25695
|
-
|
|
25791
|
+
this.isMouseLeftButtonPressed = false;
|
|
25792
|
+
this.isMouseMiddleButtonPressed = false;
|
|
25793
|
+
this.moveToolActive = false;
|
|
25794
|
+
this.isDragging = false;
|
|
25795
|
+
this.enableMove = false;
|
|
25696
25796
|
this.panning = false;
|
|
25697
25797
|
});
|
|
25698
25798
|
const handleWheel = (e) => {
|
|
@@ -26263,7 +26363,10 @@ var WeaveNodesEdgeSnappingPlugin = class extends WeavePlugin {
|
|
|
26263
26363
|
if (!utilityLayer) return;
|
|
26264
26364
|
const { targetNode: node, skipNodes } = getTargetAndSkipNodes(this.instance, e);
|
|
26265
26365
|
if (typeof node === "undefined") return;
|
|
26266
|
-
const
|
|
26366
|
+
const nodeParent = this.instance.getNodeContainer(node);
|
|
26367
|
+
if (nodeParent === null) return;
|
|
26368
|
+
const stage = this.instance.getStage();
|
|
26369
|
+
const visibleNodes = getVisibleNodes(this.instance, stage, nodeParent, skipNodes, this.instance.getMainLayer());
|
|
26267
26370
|
const lineGuideStops = this.getLineGuideStops(visibleNodes);
|
|
26268
26371
|
const itemBounds = this.getObjectSnappingEdges(node);
|
|
26269
26372
|
const guides = this.getGuides(lineGuideStops, itemBounds, e.type);
|
|
@@ -26341,21 +26444,6 @@ var WeaveNodesEdgeSnappingPlugin = class extends WeavePlugin {
|
|
|
26341
26444
|
});
|
|
26342
26445
|
}
|
|
26343
26446
|
}
|
|
26344
|
-
getVisibleNodes(skipNodes) {
|
|
26345
|
-
const stage = this.instance.getStage();
|
|
26346
|
-
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
26347
|
-
if (nodesSelection) nodesSelection.getTransformer().hide();
|
|
26348
|
-
const nodes = getVisibleNodesInViewport(stage, this.instance.getMainLayer());
|
|
26349
|
-
const finalVisibleNodes = [];
|
|
26350
|
-
nodes.forEach((node) => {
|
|
26351
|
-
if (node.getParent()?.getAttrs().nodeType === "group") return;
|
|
26352
|
-
if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
|
|
26353
|
-
if (skipNodes.includes(node.getAttrs().id ?? "")) return;
|
|
26354
|
-
finalVisibleNodes.push(node);
|
|
26355
|
-
});
|
|
26356
|
-
if (nodesSelection) nodesSelection.getTransformer().show();
|
|
26357
|
-
return finalVisibleNodes;
|
|
26358
|
-
}
|
|
26359
26447
|
getLineGuideStops(nodes) {
|
|
26360
26448
|
const vertical = [];
|
|
26361
26449
|
const horizontal = [];
|
|
@@ -26577,6 +26665,7 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26577
26665
|
const { config } = params ?? {};
|
|
26578
26666
|
this.enterSnappingTolerance = config?.enterSnappingTolerance ?? GUIDE_ENTER_SNAPPING_TOLERANCE;
|
|
26579
26667
|
this.exitSnappingTolerance = config?.exitSnappingTolerance ?? GUIDE_EXIT_SNAPPING_TOLERANCE;
|
|
26668
|
+
this.uiConfig = import_lodash.default.merge(GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, config?.ui);
|
|
26580
26669
|
this.enabled = true;
|
|
26581
26670
|
}
|
|
26582
26671
|
getName() {
|
|
@@ -26596,19 +26685,16 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26596
26685
|
}
|
|
26597
26686
|
}
|
|
26598
26687
|
evaluateGuidelines(e) {
|
|
26599
|
-
const stage = this.instance.getStage();
|
|
26600
|
-
const mainLayer = this.instance.getMainLayer();
|
|
26601
26688
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
26602
26689
|
if (!this.enabled) return;
|
|
26603
26690
|
if (!utilityLayer) return;
|
|
26604
26691
|
const { targetNode: node, skipNodes } = getTargetAndSkipNodes(this.instance, e);
|
|
26605
26692
|
if (typeof node === "undefined") return;
|
|
26606
|
-
|
|
26607
|
-
if (
|
|
26608
|
-
|
|
26609
|
-
|
|
26610
|
-
|
|
26611
|
-
const visibleNodes = this.getVisibleNodes(skipNodes);
|
|
26693
|
+
const nodeParent = this.instance.getNodeContainer(node);
|
|
26694
|
+
if (nodeParent === null) return;
|
|
26695
|
+
const stage = this.instance.getStage();
|
|
26696
|
+
this.referenceLayer = nodeParent;
|
|
26697
|
+
const visibleNodes = getVisibleNodes(this.instance, stage, nodeParent, skipNodes, this.referenceLayer);
|
|
26612
26698
|
const { intersectedNodes: sortedHorizontalIntersectedNodes, intersectedNodesWithDistances: horizontalIntersectedNodes } = this.getHorizontallyIntersectingNodes(node, visibleNodes);
|
|
26613
26699
|
const { intersectedNodes: sortedVerticalIntersectedNodes, intersectedNodesWithDistances: verticalIntersectedNodes } = this.getVerticallyIntersectingNodes(node, visibleNodes);
|
|
26614
26700
|
this.cleanupGuidelines();
|
|
@@ -26839,6 +26925,11 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26839
26925
|
});
|
|
26840
26926
|
}
|
|
26841
26927
|
}
|
|
26928
|
+
isOverlapping(node1, node2) {
|
|
26929
|
+
const box1 = this.getBoxClientRect(node1);
|
|
26930
|
+
const box2 = this.getBoxClientRect(node2);
|
|
26931
|
+
return !(box1.x + box1.width <= box2.x || box2.x + box2.width <= box1.x || box1.y + box1.height <= box2.y || box2.y + box2.height <= box1.y);
|
|
26932
|
+
}
|
|
26842
26933
|
getVerticallyIntersectingNodes(targetNode, nodes) {
|
|
26843
26934
|
const targetBox = this.getBoxClientRect(targetNode);
|
|
26844
26935
|
const intersectedNodes = [];
|
|
@@ -26855,30 +26946,32 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26855
26946
|
return ay - by;
|
|
26856
26947
|
});
|
|
26857
26948
|
const intersectedNodesWithDistances = [];
|
|
26858
|
-
for (let i = 0; i < intersectedNodes.length
|
|
26859
|
-
const
|
|
26860
|
-
const
|
|
26861
|
-
|
|
26862
|
-
|
|
26863
|
-
|
|
26864
|
-
|
|
26865
|
-
|
|
26866
|
-
|
|
26867
|
-
|
|
26868
|
-
|
|
26869
|
-
|
|
26870
|
-
|
|
26871
|
-
|
|
26872
|
-
|
|
26873
|
-
|
|
26874
|
-
|
|
26875
|
-
|
|
26876
|
-
|
|
26877
|
-
|
|
26878
|
-
|
|
26879
|
-
|
|
26880
|
-
|
|
26881
|
-
|
|
26949
|
+
for (let i = 0; i < intersectedNodes.length; i++) for (let j = i + 1; j < intersectedNodes.length; j++) {
|
|
26950
|
+
const nodeA = intersectedNodes[i];
|
|
26951
|
+
const nodeB = intersectedNodes[j];
|
|
26952
|
+
if (!this.isOverlapping(nodeA, nodeB)) {
|
|
26953
|
+
const boxA = this.getBoxClientRect(nodeA);
|
|
26954
|
+
const boxB = this.getBoxClientRect(nodeB);
|
|
26955
|
+
const aBottom = boxA.y + boxA.height;
|
|
26956
|
+
const bTop = boxB.y;
|
|
26957
|
+
const distance = Math.abs(aBottom - bTop);
|
|
26958
|
+
const left = Math.max(boxA.x, boxB.x);
|
|
26959
|
+
const right = Math.min(boxA.x + boxA.width, boxB.x + boxB.width);
|
|
26960
|
+
let midX;
|
|
26961
|
+
if (right > left) midX = left + (right - left) / 2;
|
|
26962
|
+
else {
|
|
26963
|
+
const aCenterX = boxA.x + boxA.width / 2;
|
|
26964
|
+
const bCenterX = boxB.x + boxB.width / 2;
|
|
26965
|
+
midX = (aCenterX + bCenterX) / 2;
|
|
26966
|
+
}
|
|
26967
|
+
intersectedNodesWithDistances.push({
|
|
26968
|
+
index: i,
|
|
26969
|
+
from: nodeA,
|
|
26970
|
+
to: nodeB,
|
|
26971
|
+
midX,
|
|
26972
|
+
distance: Math.round(distance)
|
|
26973
|
+
});
|
|
26974
|
+
}
|
|
26882
26975
|
}
|
|
26883
26976
|
return {
|
|
26884
26977
|
intersectedNodes,
|
|
@@ -26901,56 +26994,38 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26901
26994
|
return ax - bx;
|
|
26902
26995
|
});
|
|
26903
26996
|
const intersectedNodesWithDistances = [];
|
|
26904
|
-
for (let i = 0; i < intersectedNodes.length
|
|
26905
|
-
const
|
|
26906
|
-
const
|
|
26907
|
-
|
|
26908
|
-
|
|
26909
|
-
|
|
26910
|
-
|
|
26911
|
-
|
|
26912
|
-
|
|
26913
|
-
|
|
26914
|
-
|
|
26915
|
-
|
|
26916
|
-
|
|
26917
|
-
|
|
26918
|
-
|
|
26919
|
-
|
|
26920
|
-
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
26997
|
+
for (let i = 0; i < intersectedNodes.length; i++) for (let j = i + 1; j < intersectedNodes.length; j++) {
|
|
26998
|
+
const nodeA = intersectedNodes[i];
|
|
26999
|
+
const nodeB = intersectedNodes[j];
|
|
27000
|
+
if (!this.isOverlapping(nodeA, nodeB)) {
|
|
27001
|
+
const boxA = this.getBoxClientRect(nodeA);
|
|
27002
|
+
const boxB = this.getBoxClientRect(nodeB);
|
|
27003
|
+
const aRight = boxA.x + boxA.width;
|
|
27004
|
+
const bLeft = boxB.x;
|
|
27005
|
+
const distance = Math.abs(Math.round(aRight - bLeft));
|
|
27006
|
+
const top = Math.max(boxA.y, boxB.y);
|
|
27007
|
+
const bottom = Math.min(boxA.y + boxA.height, boxB.y + boxB.height);
|
|
27008
|
+
let midY;
|
|
27009
|
+
if (bottom > top) midY = top + (bottom - top) / 2;
|
|
27010
|
+
else {
|
|
27011
|
+
const aCenterY = boxA.y + boxA.height / 2;
|
|
27012
|
+
const bCenterY = boxB.y + boxB.height / 2;
|
|
27013
|
+
midY = (aCenterY + bCenterY) / 2;
|
|
27014
|
+
}
|
|
27015
|
+
intersectedNodesWithDistances.push({
|
|
27016
|
+
index: i,
|
|
27017
|
+
from: nodeA,
|
|
27018
|
+
to: nodeB,
|
|
27019
|
+
midY,
|
|
27020
|
+
distance: Math.round(distance)
|
|
27021
|
+
});
|
|
27022
|
+
}
|
|
26928
27023
|
}
|
|
26929
27024
|
return {
|
|
26930
27025
|
intersectedNodes,
|
|
26931
27026
|
intersectedNodesWithDistances
|
|
26932
27027
|
};
|
|
26933
27028
|
}
|
|
26934
|
-
getVisibleNodes(skipNodes) {
|
|
26935
|
-
const stage = this.instance.getStage();
|
|
26936
|
-
const nodesSelection = this.instance.getPlugin("nodesSelection");
|
|
26937
|
-
if (nodesSelection) nodesSelection.getTransformer().hide();
|
|
26938
|
-
const nodes = getVisibleNodesInViewport(stage, this.referenceLayer);
|
|
26939
|
-
const finalVisibleNodes = [];
|
|
26940
|
-
nodes.forEach((node) => {
|
|
26941
|
-
if (node.getParent()?.getAttrs().nodeType === "group") return;
|
|
26942
|
-
if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
|
|
26943
|
-
if (skipNodes.includes(node.getAttrs().id ?? "")) return;
|
|
26944
|
-
if (node.getParent() !== this.referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
|
|
26945
|
-
if (node.getParent() !== this.referenceLayer && node.getParent()?.getAttrs().nodeId) {
|
|
26946
|
-
const realNode = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
|
|
26947
|
-
if (realNode && realNode !== this.referenceLayer) return;
|
|
26948
|
-
}
|
|
26949
|
-
finalVisibleNodes.push(node);
|
|
26950
|
-
});
|
|
26951
|
-
if (nodesSelection) nodesSelection.getTransformer().show();
|
|
26952
|
-
return finalVisibleNodes;
|
|
26953
|
-
}
|
|
26954
27029
|
drawSizeGuidesHorizontally(intersectionsH, peerDistance) {
|
|
26955
27030
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
26956
27031
|
if (utilityLayer) intersectionsH.forEach((pairInfo) => {
|
|
@@ -26967,40 +27042,60 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
26967
27042
|
if (pairInfo.distance === peerDistance) this.renderVerticalLineWithDistanceBetweenNodes(from, to, pairInfo.midX, `${pairInfo.distance}`);
|
|
26968
27043
|
});
|
|
26969
27044
|
}
|
|
26970
|
-
renderDistanceLabel(ctx, stage, labelText, { canvasMidX, canvasMidY }) {
|
|
27045
|
+
renderDistanceLabel(ctx, stage, labelText, orientation, { canvasMidX, canvasMidY }, config) {
|
|
26971
27046
|
const scaleX = stage?.scaleX() || 1;
|
|
26972
27047
|
const scaleY = stage?.scaleY() || 1;
|
|
26973
|
-
const fontSize =
|
|
26974
|
-
const fontFamily =
|
|
26975
|
-
const
|
|
27048
|
+
const fontSize = config.label.fontSize;
|
|
27049
|
+
const fontFamily = config.label.fontFamily;
|
|
27050
|
+
const fontStyle = config.label.fontStyle;
|
|
27051
|
+
const cornerRadius = config.label.cornerRadius;
|
|
27052
|
+
const linePadding = config.label.linePadding;
|
|
27053
|
+
const fill = config.label.fill;
|
|
27054
|
+
const height = config.label.height;
|
|
27055
|
+
const paddingX = config.label.paddingX;
|
|
26976
27056
|
const tempText = new konva.default.Text({
|
|
26977
27057
|
text: labelText,
|
|
26978
27058
|
fontSize,
|
|
27059
|
+
fontStyle,
|
|
26979
27060
|
fontFamily,
|
|
26980
27061
|
visible: false
|
|
26981
27062
|
});
|
|
26982
27063
|
const textWidth = tempText.width();
|
|
26983
|
-
const
|
|
26984
|
-
const
|
|
26985
|
-
const labelHeight = textHeight + padding * 2;
|
|
27064
|
+
const labelWidth = textWidth + paddingX * 2;
|
|
27065
|
+
const labelHeight = height;
|
|
26986
27066
|
ctx.save();
|
|
26987
27067
|
ctx.scale(1 / scaleX, 1 / scaleY);
|
|
26988
|
-
|
|
26989
|
-
|
|
27068
|
+
let labelX = canvasMidX - labelWidth / 2;
|
|
27069
|
+
let labelY = canvasMidY + linePadding;
|
|
27070
|
+
if (orientation === "vertical") {
|
|
27071
|
+
labelX = canvasMidX + linePadding;
|
|
27072
|
+
labelY = canvasMidY - labelWidth / 2;
|
|
27073
|
+
}
|
|
27074
|
+
const r = Math.min(cornerRadius, labelWidth / 2, labelHeight / 2);
|
|
26990
27075
|
ctx.beginPath();
|
|
26991
|
-
ctx.
|
|
26992
|
-
ctx.
|
|
27076
|
+
ctx.moveTo(labelX + r, labelY);
|
|
27077
|
+
ctx.lineTo(labelX + labelWidth - r, labelY);
|
|
27078
|
+
ctx.quadraticCurveTo(labelX + labelWidth, labelY, labelX + labelWidth, labelY + r);
|
|
27079
|
+
ctx.lineTo(labelX + labelWidth, labelY + labelHeight - r);
|
|
27080
|
+
ctx.quadraticCurveTo(labelX + labelWidth, labelY + labelHeight, labelX + labelWidth - r, labelY + labelHeight);
|
|
27081
|
+
ctx.lineTo(labelX + r, labelY + labelHeight);
|
|
27082
|
+
ctx.quadraticCurveTo(labelX, labelY + labelHeight, labelX, labelY + labelHeight - r);
|
|
27083
|
+
ctx.lineTo(labelX, labelY + r);
|
|
27084
|
+
ctx.quadraticCurveTo(labelX, labelY, labelX + r, labelY);
|
|
27085
|
+
ctx.closePath();
|
|
27086
|
+
ctx.fillStyle = fill;
|
|
26993
27087
|
ctx.fill();
|
|
26994
|
-
ctx.font =
|
|
27088
|
+
ctx.font = `${fontStyle} ${fontSize}px ${fontFamily}`;
|
|
26995
27089
|
ctx.fillStyle = "white";
|
|
26996
27090
|
ctx.textAlign = "center";
|
|
26997
27091
|
ctx.textBaseline = "middle";
|
|
26998
|
-
ctx.fillText(labelText,
|
|
27092
|
+
ctx.fillText(labelText, labelX + labelWidth / 2, labelY + labelHeight / 2);
|
|
26999
27093
|
ctx.restore();
|
|
27000
27094
|
}
|
|
27001
27095
|
renderHorizontalLineWithDistanceBetweenNodes(from, to, midY, labelText) {
|
|
27002
27096
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
27003
27097
|
const renderLabel = this.renderDistanceLabel;
|
|
27098
|
+
const uiConfig = this.uiConfig;
|
|
27004
27099
|
const lineWithLabel = new konva.default.Shape({
|
|
27005
27100
|
name: GUIDE_HORIZONTAL_LINE_NAME,
|
|
27006
27101
|
sceneFunc: function(ctx, shape) {
|
|
@@ -27014,8 +27109,8 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
27014
27109
|
ctx.moveTo(x1, y);
|
|
27015
27110
|
ctx.lineTo(x2, y);
|
|
27016
27111
|
ctx.closePath();
|
|
27017
|
-
ctx.strokeStyle =
|
|
27018
|
-
ctx.lineWidth =
|
|
27112
|
+
ctx.strokeStyle = uiConfig.line.stroke;
|
|
27113
|
+
ctx.lineWidth = uiConfig.line.strokeWidth;
|
|
27019
27114
|
ctx.setLineDash([]);
|
|
27020
27115
|
ctx.stroke();
|
|
27021
27116
|
ctx.closePath();
|
|
@@ -27023,10 +27118,10 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
27023
27118
|
const worldMidY = y;
|
|
27024
27119
|
const canvasMidX = worldMidX * scaleX;
|
|
27025
27120
|
const canvasMidY = worldMidY * scaleY;
|
|
27026
|
-
renderLabel(ctx, stage, labelText, {
|
|
27121
|
+
renderLabel(ctx, stage, labelText, "horizontal", {
|
|
27027
27122
|
canvasMidX,
|
|
27028
27123
|
canvasMidY
|
|
27029
|
-
});
|
|
27124
|
+
}, uiConfig);
|
|
27030
27125
|
ctx.fillStrokeShape(shape);
|
|
27031
27126
|
}
|
|
27032
27127
|
});
|
|
@@ -27036,6 +27131,7 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
27036
27131
|
renderVerticalLineWithDistanceBetweenNodes(from, to, midX, labelText) {
|
|
27037
27132
|
const utilityLayer = this.instance.getUtilityLayer();
|
|
27038
27133
|
const renderLabel = this.renderDistanceLabel;
|
|
27134
|
+
const uiConfig = this.uiConfig;
|
|
27039
27135
|
const lineWithLabel = new konva.default.Shape({
|
|
27040
27136
|
name: GUIDE_VERTICAL_LINE_NAME,
|
|
27041
27137
|
sceneFunc: function(ctx, shape) {
|
|
@@ -27049,18 +27145,18 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
27049
27145
|
ctx.setLineDash([]);
|
|
27050
27146
|
ctx.moveTo(x, y1);
|
|
27051
27147
|
ctx.lineTo(x, y2);
|
|
27052
|
-
ctx.strokeStyle =
|
|
27053
|
-
ctx.lineWidth =
|
|
27148
|
+
ctx.strokeStyle = uiConfig.line.stroke;
|
|
27149
|
+
ctx.lineWidth = uiConfig.line.strokeWidth;
|
|
27054
27150
|
ctx.stroke();
|
|
27055
27151
|
ctx.closePath();
|
|
27056
27152
|
const worldMidX = x;
|
|
27057
27153
|
const worldMidY = (y1 + y2) / 2;
|
|
27058
27154
|
const canvasMidX = worldMidX * scaleX;
|
|
27059
27155
|
const canvasMidY = worldMidY * scaleY;
|
|
27060
|
-
renderLabel(ctx, stage, labelText, {
|
|
27156
|
+
renderLabel(ctx, stage, labelText, "vertical", {
|
|
27061
27157
|
canvasMidX,
|
|
27062
27158
|
canvasMidY
|
|
27063
|
-
});
|
|
27159
|
+
}, uiConfig);
|
|
27064
27160
|
ctx.fillStrokeShape(shape);
|
|
27065
27161
|
}
|
|
27066
27162
|
});
|
|
@@ -27090,6 +27186,7 @@ exports.ERASER_TOOL_ACTION_NAME = ERASER_TOOL_ACTION_NAME
|
|
|
27090
27186
|
exports.ERASER_TOOL_STATE = ERASER_TOOL_STATE
|
|
27091
27187
|
exports.FRAME_TOOL_ACTION_NAME = FRAME_TOOL_ACTION_NAME
|
|
27092
27188
|
exports.FRAME_TOOL_STATE = FRAME_TOOL_STATE
|
|
27189
|
+
exports.GUIDE_DISTANCE_LINE_DEFAULT_CONFIG = GUIDE_DISTANCE_LINE_DEFAULT_CONFIG
|
|
27093
27190
|
exports.GUIDE_ENTER_SNAPPING_TOLERANCE = GUIDE_ENTER_SNAPPING_TOLERANCE
|
|
27094
27191
|
exports.GUIDE_EXIT_SNAPPING_TOLERANCE = GUIDE_EXIT_SNAPPING_TOLERANCE
|
|
27095
27192
|
exports.GUIDE_HORIZONTAL_LINE_NAME = GUIDE_HORIZONTAL_LINE_NAME
|
|
@@ -27120,6 +27217,7 @@ exports.TEXT_LAYOUT = TEXT_LAYOUT
|
|
|
27120
27217
|
exports.TEXT_TOOL_ACTION_NAME = TEXT_TOOL_ACTION_NAME
|
|
27121
27218
|
exports.TEXT_TOOL_STATE = TEXT_TOOL_STATE
|
|
27122
27219
|
exports.WEAVE_ARROW_NODE_TYPE = WEAVE_ARROW_NODE_TYPE
|
|
27220
|
+
exports.WEAVE_COPY_PASTE_CONFIG_DEFAULT = WEAVE_COPY_PASTE_CONFIG_DEFAULT
|
|
27123
27221
|
exports.WEAVE_COPY_PASTE_NODES_KEY = WEAVE_COPY_PASTE_NODES_KEY
|
|
27124
27222
|
exports.WEAVE_COPY_PASTE_PASTE_CATCHER_ID = WEAVE_COPY_PASTE_PASTE_CATCHER_ID
|
|
27125
27223
|
exports.WEAVE_COPY_PASTE_PASTE_MODES = WEAVE_COPY_PASTE_PASTE_MODES
|
|
@@ -27224,6 +27322,7 @@ exports.getSelectedNodesMetadata = getSelectedNodesMetadata
|
|
|
27224
27322
|
exports.getTargetAndSkipNodes = getTargetAndSkipNodes
|
|
27225
27323
|
exports.getTargetedNode = getTargetedNode
|
|
27226
27324
|
exports.getTopmostShadowHost = getTopmostShadowHost
|
|
27325
|
+
exports.getVisibleNodes = getVisibleNodes
|
|
27227
27326
|
exports.getVisibleNodesInViewport = getVisibleNodesInViewport
|
|
27228
27327
|
exports.hasFrames = hasFrames
|
|
27229
27328
|
exports.hasImages = hasImages
|