@inditextech/weave-sdk 0.4.0 → 0.6.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 +432 -212
- package/dist/sdk.d.cts +150 -34
- package/dist/sdk.d.ts +150 -34
- package/dist/sdk.js +422 -213
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -15627,18 +15627,25 @@ const WEAVE_NODES_SELECTION_LAYER_ID = "selectionLayer";
|
|
|
15627
15627
|
//#endregion
|
|
15628
15628
|
//#region src/plugins/context-menu/constants.ts
|
|
15629
15629
|
const WEAVE_CONTEXT_MENU_KEY = "contextMenu";
|
|
15630
|
+
const WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT = 4;
|
|
15631
|
+
const WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT = 4;
|
|
15630
15632
|
|
|
15631
15633
|
//#endregion
|
|
15632
15634
|
//#region src/plugins/context-menu/context-menu.ts
|
|
15633
15635
|
var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
15634
15636
|
getLayerName = void 0;
|
|
15635
15637
|
initLayer = void 0;
|
|
15636
|
-
constructor(
|
|
15638
|
+
constructor(params) {
|
|
15637
15639
|
super();
|
|
15638
15640
|
this.touchTimer = void 0;
|
|
15639
15641
|
this.tapHold = false;
|
|
15640
|
-
|
|
15641
|
-
this.
|
|
15642
|
+
const { callbacks, config } = params ?? {};
|
|
15643
|
+
this.config = {
|
|
15644
|
+
xOffset: WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT,
|
|
15645
|
+
yOffset: WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT,
|
|
15646
|
+
...config
|
|
15647
|
+
};
|
|
15648
|
+
this.callbacks = { ...callbacks };
|
|
15642
15649
|
}
|
|
15643
15650
|
getName() {
|
|
15644
15651
|
return WEAVE_CONTEXT_MENU_KEY;
|
|
@@ -15648,7 +15655,7 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15648
15655
|
}
|
|
15649
15656
|
triggerContextMenu(target) {
|
|
15650
15657
|
const stage = this.instance.getStage();
|
|
15651
|
-
const selectionPlugin = this.instance.getPlugin(
|
|
15658
|
+
const selectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
|
|
15652
15659
|
let clickOnTransformer = false;
|
|
15653
15660
|
if (selectionPlugin) {
|
|
15654
15661
|
const transformer = selectionPlugin.getTransformer();
|
|
@@ -15729,9 +15736,46 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
|
15729
15736
|
//#endregion
|
|
15730
15737
|
//#region src/plugins/nodes-selection/nodes-selection.ts
|
|
15731
15738
|
var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
15732
|
-
constructor(
|
|
15739
|
+
constructor(params) {
|
|
15733
15740
|
super();
|
|
15734
|
-
|
|
15741
|
+
const { config, callbacks } = params ?? {};
|
|
15742
|
+
this.config = { transformer: {
|
|
15743
|
+
rotationSnaps: [
|
|
15744
|
+
0,
|
|
15745
|
+
45,
|
|
15746
|
+
90,
|
|
15747
|
+
135,
|
|
15748
|
+
180,
|
|
15749
|
+
225,
|
|
15750
|
+
270,
|
|
15751
|
+
315,
|
|
15752
|
+
360
|
|
15753
|
+
],
|
|
15754
|
+
rotationSnapTolerance: 3,
|
|
15755
|
+
ignoreStroke: true,
|
|
15756
|
+
flipEnabled: false,
|
|
15757
|
+
useSingleNodeRotation: true,
|
|
15758
|
+
shouldOverdrawWholeArea: true,
|
|
15759
|
+
anchorStyleFunc: (anchor) => {
|
|
15760
|
+
anchor.stroke("#27272aff");
|
|
15761
|
+
anchor.cornerRadius(12);
|
|
15762
|
+
if (anchor.hasName("top-center") || anchor.hasName("bottom-center")) {
|
|
15763
|
+
anchor.height(8);
|
|
15764
|
+
anchor.offsetY(4);
|
|
15765
|
+
anchor.width(32);
|
|
15766
|
+
anchor.offsetX(16);
|
|
15767
|
+
}
|
|
15768
|
+
if (anchor.hasName("middle-left") || anchor.hasName("middle-right")) {
|
|
15769
|
+
anchor.height(32);
|
|
15770
|
+
anchor.offsetY(16);
|
|
15771
|
+
anchor.width(8);
|
|
15772
|
+
anchor.offsetX(4);
|
|
15773
|
+
}
|
|
15774
|
+
},
|
|
15775
|
+
borderStroke: "#1e40afff",
|
|
15776
|
+
...config?.transformer
|
|
15777
|
+
} };
|
|
15778
|
+
this.callbacks = callbacks ?? {};
|
|
15735
15779
|
this.active = false;
|
|
15736
15780
|
this.cameFromSelectingMultiple = false;
|
|
15737
15781
|
this.selecting = false;
|
|
@@ -15749,6 +15793,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15749
15793
|
const layer = new konva.default.Layer({ id: this.getLayerName() });
|
|
15750
15794
|
stage.add(layer);
|
|
15751
15795
|
}
|
|
15796
|
+
isSelecting() {
|
|
15797
|
+
return this.instance.getActiveAction() === "selectionTool";
|
|
15798
|
+
}
|
|
15799
|
+
isNodeSelected(ele) {
|
|
15800
|
+
let selected = false;
|
|
15801
|
+
if (this.getSelectedNodes().length === 1 && this.getSelectedNodes()[0].getAttrs().id === ele.getAttrs().id) selected = true;
|
|
15802
|
+
return selected;
|
|
15803
|
+
}
|
|
15752
15804
|
onInit() {
|
|
15753
15805
|
const stage = this.instance.getStage();
|
|
15754
15806
|
const selectionLayer = this.getLayer();
|
|
@@ -15765,41 +15817,24 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15765
15817
|
selectionLayer?.add(selectionRectangle);
|
|
15766
15818
|
const tr = new konva.default.Transformer({
|
|
15767
15819
|
id: "selectionTransformer",
|
|
15768
|
-
|
|
15769
|
-
0,
|
|
15770
|
-
45,
|
|
15771
|
-
90,
|
|
15772
|
-
135,
|
|
15773
|
-
180,
|
|
15774
|
-
225,
|
|
15775
|
-
270,
|
|
15776
|
-
315,
|
|
15777
|
-
360
|
|
15778
|
-
],
|
|
15779
|
-
rotationSnapTolerance: 3,
|
|
15780
|
-
ignoreStroke: true,
|
|
15781
|
-
flipEnabled: false,
|
|
15782
|
-
useSingleNodeRotation: true,
|
|
15783
|
-
shouldOverdrawWholeArea: true,
|
|
15784
|
-
anchorStyleFunc: (anchor) => {
|
|
15785
|
-
anchor.stroke("#27272aff");
|
|
15786
|
-
anchor.cornerRadius(12);
|
|
15787
|
-
if (anchor.hasName("top-center") || anchor.hasName("bottom-center")) {
|
|
15788
|
-
anchor.height(8);
|
|
15789
|
-
anchor.offsetY(4);
|
|
15790
|
-
anchor.width(32);
|
|
15791
|
-
anchor.offsetX(16);
|
|
15792
|
-
}
|
|
15793
|
-
if (anchor.hasName("middle-left") || anchor.hasName("middle-right")) {
|
|
15794
|
-
anchor.height(32);
|
|
15795
|
-
anchor.offsetY(16);
|
|
15796
|
-
anchor.width(8);
|
|
15797
|
-
anchor.offsetX(4);
|
|
15798
|
-
}
|
|
15799
|
-
},
|
|
15800
|
-
borderStroke: "#1e40afff"
|
|
15820
|
+
...this.config.transformer
|
|
15801
15821
|
});
|
|
15802
15822
|
selectionLayer?.add(tr);
|
|
15823
|
+
tr.on("transform", (e) => {
|
|
15824
|
+
const node = e.target;
|
|
15825
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
15826
|
+
if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.evaluateGuidelines(e);
|
|
15827
|
+
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
15828
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
15829
|
+
this.instance.updateNode(nodeHandler.serialize(node));
|
|
15830
|
+
e.cancelBubble = true;
|
|
15831
|
+
}
|
|
15832
|
+
});
|
|
15833
|
+
tr.on("transformend", (e) => {
|
|
15834
|
+
const node = e.target;
|
|
15835
|
+
const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
|
|
15836
|
+
if (nodesSnappingPlugin && this.isSelecting() && this.isNodeSelected(node)) nodesSnappingPlugin.cleanupEvaluateGuidelines();
|
|
15837
|
+
});
|
|
15803
15838
|
tr.on("mouseenter", (e) => {
|
|
15804
15839
|
const stage$1 = this.instance.getStage();
|
|
15805
15840
|
stage$1.container().style.cursor = "grab";
|
|
@@ -16065,8 +16100,9 @@ const COPY_PASTE_NODES_PLUGIN_STATE = {
|
|
|
16065
16100
|
//#endregion
|
|
16066
16101
|
//#region src/plugins/copy-paste-nodes/copy-paste-nodes.ts
|
|
16067
16102
|
var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
16068
|
-
constructor(
|
|
16103
|
+
constructor(params) {
|
|
16069
16104
|
super();
|
|
16105
|
+
const { callbacks } = params ?? {};
|
|
16070
16106
|
this.callbacks = callbacks;
|
|
16071
16107
|
this.state = COPY_PASTE_NODES_PLUGIN_STATE.IDLE;
|
|
16072
16108
|
}
|
|
@@ -16329,12 +16365,6 @@ var WeaveNode = class {
|
|
|
16329
16365
|
}
|
|
16330
16366
|
node.draggable(false);
|
|
16331
16367
|
});
|
|
16332
|
-
node.on("transform", (e) => {
|
|
16333
|
-
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16334
|
-
this.instance.updateNode(this.serialize(node));
|
|
16335
|
-
e.cancelBubble = true;
|
|
16336
|
-
}
|
|
16337
|
-
});
|
|
16338
16368
|
node.on("dragmove", (e) => {
|
|
16339
16369
|
if (this.isSelecting() && this.isNodeSelected(node)) {
|
|
16340
16370
|
this.clearContainerTargets();
|
|
@@ -17679,6 +17709,13 @@ var WeaveStateManager = class {
|
|
|
17679
17709
|
}
|
|
17680
17710
|
}, userName);
|
|
17681
17711
|
}
|
|
17712
|
+
getElementsTree() {
|
|
17713
|
+
const state = this.instance.getStore().getState().weave;
|
|
17714
|
+
const jsonState = JSON.parse(JSON.stringify(state, null, 2));
|
|
17715
|
+
const mainLayer = jsonState.props.children.find((node) => node.key === "mainLayer");
|
|
17716
|
+
if (!mainLayer) return [];
|
|
17717
|
+
return mainLayer.props.children;
|
|
17718
|
+
}
|
|
17682
17719
|
};
|
|
17683
17720
|
|
|
17684
17721
|
//#endregion
|
|
@@ -17769,7 +17806,7 @@ var WeaveRegisterManager = class {
|
|
|
17769
17806
|
|
|
17770
17807
|
//#endregion
|
|
17771
17808
|
//#region package.json
|
|
17772
|
-
var version = "0.
|
|
17809
|
+
var version = "0.6.0";
|
|
17773
17810
|
|
|
17774
17811
|
//#endregion
|
|
17775
17812
|
//#region src/managers/setup.ts
|
|
@@ -18349,6 +18386,9 @@ var Weave = class extends Emittery {
|
|
|
18349
18386
|
moveNode(node, position, doRender = true) {
|
|
18350
18387
|
this.stateManager.moveNode(node, position, doRender);
|
|
18351
18388
|
}
|
|
18389
|
+
getElementsTree() {
|
|
18390
|
+
return this.stateManager.getElementsTree();
|
|
18391
|
+
}
|
|
18352
18392
|
moveUp(node) {
|
|
18353
18393
|
this.zIndexManager.moveUp(node);
|
|
18354
18394
|
}
|
|
@@ -18376,6 +18416,17 @@ var Weave = class extends Emittery {
|
|
|
18376
18416
|
getMousePointerRelativeToContainer(container) {
|
|
18377
18417
|
return this.targetingManager.getMousePointerRelativeToContainer(container);
|
|
18378
18418
|
}
|
|
18419
|
+
selectNodesByKey(nodesIds) {
|
|
18420
|
+
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
18421
|
+
if (selectionPlugin) {
|
|
18422
|
+
const stage = this.getStage();
|
|
18423
|
+
const instanceNodes = nodesIds.map((nodeId) => {
|
|
18424
|
+
const nodeInstance = stage.findOne(`#${nodeId}`);
|
|
18425
|
+
return nodeInstance;
|
|
18426
|
+
});
|
|
18427
|
+
selectionPlugin.setSelectedNodes(instanceNodes);
|
|
18428
|
+
}
|
|
18429
|
+
}
|
|
18379
18430
|
nodesToGroupSerialized(instancesToClone) {
|
|
18380
18431
|
return this.cloningManager.nodesToGroupSerialized(instancesToClone);
|
|
18381
18432
|
}
|
|
@@ -19398,44 +19449,129 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
19398
19449
|
//#endregion
|
|
19399
19450
|
//#region src/nodes/frame/constants.ts
|
|
19400
19451
|
const WEAVE_FRAME_NODE_TYPE = "frame";
|
|
19452
|
+
const WEAVE_FRAME_NODE_SIZES_MULTIPLIER = 5;
|
|
19453
|
+
const WEAVE_FRAME_NODE_SIZES_ORIENTATION = {
|
|
19454
|
+
landscape: "landscape",
|
|
19455
|
+
portrait: "portrait"
|
|
19456
|
+
};
|
|
19457
|
+
const WEAVE_FRAME_NODE_SIZES_TYPES = {
|
|
19458
|
+
A1: "A1",
|
|
19459
|
+
A2: "A2",
|
|
19460
|
+
A3: "A3",
|
|
19461
|
+
A4: "A4",
|
|
19462
|
+
CUSTOM: "custom"
|
|
19463
|
+
};
|
|
19464
|
+
const WEAVE_FRAME_NODE_SIZES = {
|
|
19465
|
+
landscape: {
|
|
19466
|
+
A1: {
|
|
19467
|
+
width: 841,
|
|
19468
|
+
height: 594
|
|
19469
|
+
},
|
|
19470
|
+
A2: {
|
|
19471
|
+
width: 592,
|
|
19472
|
+
height: 420
|
|
19473
|
+
},
|
|
19474
|
+
A3: {
|
|
19475
|
+
width: 420,
|
|
19476
|
+
height: 297
|
|
19477
|
+
},
|
|
19478
|
+
A4: {
|
|
19479
|
+
width: 297,
|
|
19480
|
+
height: 210
|
|
19481
|
+
},
|
|
19482
|
+
custom: {
|
|
19483
|
+
width: 0,
|
|
19484
|
+
height: 0
|
|
19485
|
+
}
|
|
19486
|
+
},
|
|
19487
|
+
portrait: {
|
|
19488
|
+
A1: {
|
|
19489
|
+
width: 594,
|
|
19490
|
+
height: 841
|
|
19491
|
+
},
|
|
19492
|
+
A2: {
|
|
19493
|
+
width: 420,
|
|
19494
|
+
height: 594
|
|
19495
|
+
},
|
|
19496
|
+
A3: {
|
|
19497
|
+
width: 297,
|
|
19498
|
+
height: 420
|
|
19499
|
+
},
|
|
19500
|
+
A4: {
|
|
19501
|
+
width: 210,
|
|
19502
|
+
height: 297
|
|
19503
|
+
},
|
|
19504
|
+
custom: {
|
|
19505
|
+
width: 0,
|
|
19506
|
+
height: 0
|
|
19507
|
+
}
|
|
19508
|
+
}
|
|
19509
|
+
};
|
|
19510
|
+
const WEAVE_FRAME_NODE_DEFAULT_PROPS = {
|
|
19511
|
+
title: "Frame XXX",
|
|
19512
|
+
fontFamily: "Arial",
|
|
19513
|
+
titleHeight: 30,
|
|
19514
|
+
borderColor: "#000000ff",
|
|
19515
|
+
borderWidth: 2,
|
|
19516
|
+
frameWidth: WEAVE_FRAME_NODE_SIZES.landscape.A4.width * WEAVE_FRAME_NODE_SIZES_MULTIPLIER,
|
|
19517
|
+
frameHeight: WEAVE_FRAME_NODE_SIZES.landscape.A4.height * WEAVE_FRAME_NODE_SIZES_MULTIPLIER,
|
|
19518
|
+
frameType: WEAVE_FRAME_NODE_SIZES_TYPES.A4,
|
|
19519
|
+
frameOrientation: WEAVE_FRAME_NODE_SIZES_ORIENTATION.landscape
|
|
19520
|
+
};
|
|
19401
19521
|
|
|
19402
19522
|
//#endregion
|
|
19403
19523
|
//#region src/nodes/frame/frame.ts
|
|
19404
19524
|
var WeaveFrameNode = class extends WeaveNode {
|
|
19405
19525
|
nodeType = WEAVE_FRAME_NODE_TYPE;
|
|
19526
|
+
create(key, props) {
|
|
19527
|
+
return {
|
|
19528
|
+
key,
|
|
19529
|
+
type: this.nodeType,
|
|
19530
|
+
props: {
|
|
19531
|
+
...props,
|
|
19532
|
+
id: key,
|
|
19533
|
+
nodeType: this.nodeType,
|
|
19534
|
+
...WEAVE_FRAME_NODE_DEFAULT_PROPS,
|
|
19535
|
+
...props.fontFamily && { title: props.fontFamily },
|
|
19536
|
+
...props.title && { title: props.title },
|
|
19537
|
+
...props.titleHeight && { titleHeight: props.titleHeight },
|
|
19538
|
+
...props.borderColor && { borderColor: props.borderColor },
|
|
19539
|
+
...props.borderWidth && { borderWidth: props.borderWidth },
|
|
19540
|
+
...props.frameWidth && { frameWidth: props.frameWidth },
|
|
19541
|
+
...props.frameHeight && { frameHeight: props.frameHeight },
|
|
19542
|
+
...props.frameType && { frameType: props.frameType },
|
|
19543
|
+
...props.frameOrientation && { frameOrientation: props.frameOrientation },
|
|
19544
|
+
children: []
|
|
19545
|
+
}
|
|
19546
|
+
};
|
|
19547
|
+
}
|
|
19406
19548
|
onRender(props) {
|
|
19407
|
-
const { id } = props;
|
|
19408
|
-
const frameParams = { ...
|
|
19409
|
-
delete frameParams.fontFamily;
|
|
19410
|
-
delete frameParams.zIndex;
|
|
19411
|
-
const frameWidth = 1403;
|
|
19412
|
-
const frameHeight = 992;
|
|
19413
|
-
const titleHeight = 30;
|
|
19414
|
-
const strokeWidth = 2;
|
|
19549
|
+
const { id, zIndex,...restProps } = props;
|
|
19550
|
+
const frameParams = { ...restProps };
|
|
19415
19551
|
const frame = new konva.default.Group({
|
|
19416
19552
|
...frameParams,
|
|
19553
|
+
id,
|
|
19417
19554
|
containerId: `${id}-group-internal`,
|
|
19418
19555
|
containerOffsetX: 0,
|
|
19419
|
-
containerOffsetY: titleHeight +
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
height: frameHeight + titleHeight + strokeWidth * 2,
|
|
19556
|
+
containerOffsetY: props.titleHeight + props.borderWidth,
|
|
19557
|
+
width: props.frameWidth + props.borderWidth * 2,
|
|
19558
|
+
height: props.frameHeight + props.titleHeight + props.borderWidth * 2,
|
|
19423
19559
|
fill: "#ffffffff",
|
|
19424
19560
|
clipX: 0,
|
|
19425
19561
|
clipY: 0,
|
|
19426
|
-
clipWidth: frameWidth +
|
|
19427
|
-
clipHeight: frameHeight + titleHeight +
|
|
19562
|
+
clipWidth: props.frameWidth + props.borderWidth * 2,
|
|
19563
|
+
clipHeight: props.frameHeight + props.titleHeight + props.borderWidth * 2,
|
|
19428
19564
|
name: "node"
|
|
19429
19565
|
});
|
|
19430
19566
|
const background = new konva.default.Rect({
|
|
19431
19567
|
id: `${id}-bg`,
|
|
19432
19568
|
nodeId: id,
|
|
19433
|
-
x:
|
|
19434
|
-
y: titleHeight +
|
|
19435
|
-
width: frameWidth,
|
|
19436
|
-
stroke:
|
|
19437
|
-
strokeWidth:
|
|
19438
|
-
height: frameHeight,
|
|
19569
|
+
x: props.borderWidth,
|
|
19570
|
+
y: props.titleHeight + props.borderWidth,
|
|
19571
|
+
width: props.frameWidth,
|
|
19572
|
+
stroke: props.borderColor,
|
|
19573
|
+
strokeWidth: props.borderWidth,
|
|
19574
|
+
height: props.frameHeight,
|
|
19439
19575
|
fill: "#ffffffff",
|
|
19440
19576
|
draggable: false
|
|
19441
19577
|
});
|
|
@@ -19444,12 +19580,12 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
19444
19580
|
id: `${id}-title`,
|
|
19445
19581
|
x: 0,
|
|
19446
19582
|
y: 0,
|
|
19447
|
-
width: frameWidth,
|
|
19448
|
-
height: titleHeight - 10,
|
|
19583
|
+
width: props.frameWidth,
|
|
19584
|
+
height: props.titleHeight - 10,
|
|
19449
19585
|
fontSize: 20,
|
|
19450
19586
|
fontFamily: props.fontFamily,
|
|
19451
19587
|
align: "left",
|
|
19452
|
-
text:
|
|
19588
|
+
text: props.title,
|
|
19453
19589
|
stroke: "#000000ff",
|
|
19454
19590
|
strokeWidth: 1,
|
|
19455
19591
|
listening: false,
|
|
@@ -19459,31 +19595,31 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
19459
19595
|
const frameInternal = new konva.default.Group({
|
|
19460
19596
|
id: `${id}-group-internal`,
|
|
19461
19597
|
nodeId: id,
|
|
19462
|
-
x:
|
|
19463
|
-
y: titleHeight +
|
|
19464
|
-
width: frameWidth,
|
|
19465
|
-
height: frameHeight,
|
|
19598
|
+
x: props.borderWidth,
|
|
19599
|
+
y: props.titleHeight + props.borderWidth,
|
|
19600
|
+
width: props.frameWidth,
|
|
19601
|
+
height: props.frameHeight,
|
|
19466
19602
|
draggable: false,
|
|
19467
19603
|
stroke: "transparent",
|
|
19468
|
-
|
|
19604
|
+
borderWidth: props.borderWidth,
|
|
19469
19605
|
clipX: 0,
|
|
19470
19606
|
clipY: 0,
|
|
19471
|
-
clipWidth: frameWidth,
|
|
19472
|
-
clipHeight: frameHeight
|
|
19607
|
+
clipWidth: props.frameWidth,
|
|
19608
|
+
clipHeight: props.frameHeight
|
|
19473
19609
|
});
|
|
19474
19610
|
frame.add(frameInternal);
|
|
19475
19611
|
this.setupDefaultNodeEvents(frame);
|
|
19476
19612
|
frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
|
|
19477
19613
|
background.setAttrs({
|
|
19478
19614
|
stroke: "#000000ff",
|
|
19479
|
-
strokeWidth:
|
|
19615
|
+
strokeWidth: props.borderWidth,
|
|
19480
19616
|
fill: "#ffffffff"
|
|
19481
19617
|
});
|
|
19482
19618
|
});
|
|
19483
19619
|
frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, () => {
|
|
19484
19620
|
background.setAttrs({
|
|
19485
19621
|
stroke: "#ff6863ff",
|
|
19486
|
-
strokeWidth:
|
|
19622
|
+
strokeWidth: props.borderWidth,
|
|
19487
19623
|
fill: "#ecececff"
|
|
19488
19624
|
});
|
|
19489
19625
|
});
|
|
@@ -19534,29 +19670,35 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
19534
19670
|
getLayerName = void 0;
|
|
19535
19671
|
initLayer = void 0;
|
|
19536
19672
|
padding = 100;
|
|
19673
|
+
defaultStep = 3;
|
|
19537
19674
|
constructor(params) {
|
|
19538
19675
|
super();
|
|
19539
|
-
const {
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
|
|
19543
|
-
|
|
19544
|
-
|
|
19545
|
-
|
|
19546
|
-
|
|
19547
|
-
|
|
19548
|
-
|
|
19549
|
-
|
|
19550
|
-
|
|
19551
|
-
|
|
19676
|
+
const { config, callbacks } = params;
|
|
19677
|
+
this.config = {
|
|
19678
|
+
zoomSteps: [
|
|
19679
|
+
.1,
|
|
19680
|
+
.25,
|
|
19681
|
+
.5,
|
|
19682
|
+
1,
|
|
19683
|
+
2,
|
|
19684
|
+
4,
|
|
19685
|
+
8
|
|
19686
|
+
],
|
|
19687
|
+
defaultZoom: 1,
|
|
19688
|
+
...config
|
|
19689
|
+
};
|
|
19690
|
+
this.callbacks = callbacks ?? {};
|
|
19691
|
+
if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
|
|
19692
|
+
this.actualStep = this.config.zoomSteps.findIndex((step) => step === this.config.defaultZoom);
|
|
19693
|
+
this.actualScale = this.config.zoomSteps[this.actualStep];
|
|
19552
19694
|
this.defaultStep = this.actualStep;
|
|
19553
|
-
this.onZoomChangeCb = onZoomChange;
|
|
19695
|
+
this.onZoomChangeCb = this.callbacks?.onZoomChange;
|
|
19554
19696
|
}
|
|
19555
19697
|
getName() {
|
|
19556
19698
|
return WEAVE_STAGE_ZOOM_KEY;
|
|
19557
19699
|
}
|
|
19558
19700
|
onInit() {
|
|
19559
|
-
this.setZoom(this.zoomSteps[this.actualStep]);
|
|
19701
|
+
this.setZoom(this.config.zoomSteps[this.actualStep]);
|
|
19560
19702
|
}
|
|
19561
19703
|
setZoom(scale, centered = true) {
|
|
19562
19704
|
const stage = this.instance.getStage();
|
|
@@ -19590,7 +19732,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
19590
19732
|
}
|
|
19591
19733
|
const callbackParams = {
|
|
19592
19734
|
scale,
|
|
19593
|
-
zoomSteps: this.zoomSteps,
|
|
19735
|
+
zoomSteps: this.config.zoomSteps,
|
|
19594
19736
|
actualStep: this.actualStep,
|
|
19595
19737
|
onDefaultStep: this.actualStep === this.defaultStep,
|
|
19596
19738
|
canZoomIn: this.canZoomIn(),
|
|
@@ -19602,52 +19744,52 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
19602
19744
|
}
|
|
19603
19745
|
canZoomOut() {
|
|
19604
19746
|
if (!this.enabled) return false;
|
|
19605
|
-
const actualZoomIsStep = this.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19747
|
+
const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19606
19748
|
if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
|
|
19607
19749
|
return this.actualStep - 1 > 0;
|
|
19608
19750
|
}
|
|
19609
19751
|
canZoomIn() {
|
|
19610
19752
|
if (!this.enabled) return false;
|
|
19611
|
-
const actualZoomIsStep = this.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19753
|
+
const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19612
19754
|
if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
|
|
19613
|
-
return this.actualStep + 1 < this.zoomSteps.length;
|
|
19755
|
+
return this.actualStep + 1 < this.config.zoomSteps.length;
|
|
19614
19756
|
}
|
|
19615
19757
|
zoomToStep(step) {
|
|
19616
19758
|
if (!this.enabled) return;
|
|
19617
|
-
if (step < 0 || step >= this.zoomSteps.length) throw new Error(`Defined step ${step} is out of bounds`);
|
|
19759
|
+
if (step < 0 || step >= this.config.zoomSteps.length) throw new Error(`Defined step ${step} is out of bounds`);
|
|
19618
19760
|
this.actualStep = step;
|
|
19619
|
-
this.setZoom(this.zoomSteps[step]);
|
|
19761
|
+
this.setZoom(this.config.zoomSteps[step]);
|
|
19620
19762
|
}
|
|
19621
19763
|
findClosestStepIndex() {
|
|
19622
19764
|
let closestStepIndex = 0;
|
|
19623
19765
|
let actualDiff = Infinity;
|
|
19624
|
-
for (let i = 0; i < this.zoomSteps.length; i++) if (Math.abs(this.zoomSteps[i] - this.actualScale) < actualDiff) {
|
|
19766
|
+
for (let i = 0; i < this.config.zoomSteps.length; i++) if (Math.abs(this.config.zoomSteps[i] - this.actualScale) < actualDiff) {
|
|
19625
19767
|
closestStepIndex = i;
|
|
19626
|
-
actualDiff = Math.abs(this.zoomSteps[i] - this.actualScale);
|
|
19768
|
+
actualDiff = Math.abs(this.config.zoomSteps[i] - this.actualScale);
|
|
19627
19769
|
}
|
|
19628
19770
|
return closestStepIndex;
|
|
19629
19771
|
}
|
|
19630
19772
|
zoomIn() {
|
|
19631
19773
|
if (!this.enabled) return;
|
|
19632
19774
|
if (!this.canZoomIn()) return;
|
|
19633
|
-
const actualZoomIsStep = this.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19775
|
+
const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19634
19776
|
if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
|
|
19635
19777
|
else this.actualStep += 1;
|
|
19636
|
-
this.setZoom(this.zoomSteps[this.actualStep]);
|
|
19778
|
+
this.setZoom(this.config.zoomSteps[this.actualStep]);
|
|
19637
19779
|
}
|
|
19638
19780
|
zoomOut() {
|
|
19639
19781
|
if (!this.enabled) return;
|
|
19640
19782
|
if (!this.canZoomOut()) return;
|
|
19641
|
-
const actualZoomIsStep = this.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19783
|
+
const actualZoomIsStep = this.config.zoomSteps.findIndex((scale) => scale === this.actualScale);
|
|
19642
19784
|
if (actualZoomIsStep === -1) this.actualStep = this.findClosestStepIndex();
|
|
19643
19785
|
else this.actualStep -= 1;
|
|
19644
|
-
this.setZoom(this.zoomSteps[this.actualStep]);
|
|
19786
|
+
this.setZoom(this.config.zoomSteps[this.actualStep]);
|
|
19645
19787
|
}
|
|
19646
19788
|
fitToScreen() {
|
|
19647
19789
|
if (!this.enabled) return;
|
|
19648
19790
|
const mainLayer = this.instance.getMainLayer();
|
|
19649
19791
|
if (mainLayer?.getChildren().length === 0) {
|
|
19650
|
-
this.setZoom(this.zoomSteps[this.defaultStep]);
|
|
19792
|
+
this.setZoom(this.config.zoomSteps[this.defaultStep]);
|
|
19651
19793
|
return;
|
|
19652
19794
|
}
|
|
19653
19795
|
const stage = this.instance.getStage();
|
|
@@ -20619,8 +20761,8 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
20619
20761
|
}
|
|
20620
20762
|
initProps(params) {
|
|
20621
20763
|
return {
|
|
20622
|
-
title:
|
|
20623
|
-
fontFamily: params?.fontFamily ??
|
|
20764
|
+
title: params?.title ?? WEAVE_FRAME_NODE_DEFAULT_PROPS.title,
|
|
20765
|
+
fontFamily: params?.fontFamily ?? WEAVE_FRAME_NODE_DEFAULT_PROPS.fontFamily,
|
|
20624
20766
|
editing: false,
|
|
20625
20767
|
opacity: 1
|
|
20626
20768
|
};
|
|
@@ -20789,26 +20931,32 @@ var WeaveExportNodeToolAction = class extends WeaveAction {
|
|
|
20789
20931
|
//#endregion
|
|
20790
20932
|
//#region src/plugins/stage-grid/constants.ts
|
|
20791
20933
|
const WEAVE_STAGE_GRID_KEY = "stageGrid";
|
|
20792
|
-
const WEAVE_GRID_DEFAULT_SIZE = 50;
|
|
20793
|
-
const WEAVE_GRID_LAYER_ID = "gridLayer";
|
|
20794
20934
|
const WEAVE_GRID_TYPES = {
|
|
20795
20935
|
["LINES"]: "lines",
|
|
20796
20936
|
["DOTS"]: "dots"
|
|
20797
20937
|
};
|
|
20938
|
+
const WEAVE_GRID_DEFAULT_SIZE = 50;
|
|
20939
|
+
const WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_TYPES.LINES;
|
|
20940
|
+
const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.2)";
|
|
20941
|
+
const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.2)";
|
|
20942
|
+
const WEAVE_GRID_LAYER_ID = "gridLayer";
|
|
20798
20943
|
|
|
20799
20944
|
//#endregion
|
|
20800
20945
|
//#region src/plugins/stage-grid/stage-grid.ts
|
|
20801
20946
|
var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
20802
|
-
type = "lines";
|
|
20803
|
-
gridColor = "rgba(0,0,0,0.2)";
|
|
20804
|
-
originColor = "rgba(255,0,0,0.2)";
|
|
20805
20947
|
constructor(params) {
|
|
20806
20948
|
super();
|
|
20807
|
-
const {
|
|
20949
|
+
const { config } = params ?? {};
|
|
20808
20950
|
this.moveToolActive = false;
|
|
20809
20951
|
this.isMouseMiddleButtonPressed = false;
|
|
20810
20952
|
this.isSpaceKeyPressed = false;
|
|
20811
|
-
this.
|
|
20953
|
+
this.config = {
|
|
20954
|
+
type: WEAVE_GRID_DEFAULT_TYPE,
|
|
20955
|
+
gridColor: WEAVE_GRID_DEFAULT_COLOR,
|
|
20956
|
+
gridOriginColor: WEAVE_GRID_DEFAULT_ORIGIN_COLOR,
|
|
20957
|
+
gridSize: WEAVE_GRID_DEFAULT_SIZE,
|
|
20958
|
+
...config
|
|
20959
|
+
};
|
|
20812
20960
|
}
|
|
20813
20961
|
getName() {
|
|
20814
20962
|
return WEAVE_STAGE_GRID_KEY;
|
|
@@ -20884,7 +21032,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
20884
21032
|
if (!layer) return;
|
|
20885
21033
|
layer.destroyChildren();
|
|
20886
21034
|
if (!this.enabled) return;
|
|
20887
|
-
switch (this.type) {
|
|
21035
|
+
switch (this.config.type) {
|
|
20888
21036
|
case WEAVE_GRID_TYPES.LINES:
|
|
20889
21037
|
this.renderGridLines();
|
|
20890
21038
|
break;
|
|
@@ -20903,41 +21051,41 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
20903
21051
|
const layer = this.getLayer();
|
|
20904
21052
|
if (!layer) return;
|
|
20905
21053
|
const stage = this.instance.getStage();
|
|
20906
|
-
const stageXRound = this.round(stage.x(), this.gridSize) * -1;
|
|
21054
|
+
const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
|
|
20907
21055
|
const pointsX = [];
|
|
20908
|
-
for (let i = stageXRound; i < stageXRound + stage.width(); i += this.gridSize) pointsX.push(i / stage.scaleX());
|
|
20909
|
-
const stageYRound = this.round(stage.y(), this.gridSize) * -1;
|
|
21056
|
+
for (let i = stageXRound; i < stageXRound + stage.width(); i += this.config.gridSize) pointsX.push(i / stage.scaleX());
|
|
21057
|
+
const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
|
|
20910
21058
|
const pointsY = [];
|
|
20911
|
-
for (let i = stageYRound; i < stageYRound + stage.height(); i += this.gridSize) pointsY.push(i / stage.scaleY());
|
|
21059
|
+
for (let i = stageYRound; i < stageYRound + stage.height(); i += this.config.gridSize) pointsY.push(i / stage.scaleY());
|
|
20912
21060
|
for (let index = 0; index < pointsX.length; index++) {
|
|
20913
21061
|
const point = pointsX[index];
|
|
20914
|
-
let color = this.gridColor;
|
|
20915
|
-
if (point === 0) color = this.
|
|
21062
|
+
let color = this.config.gridColor;
|
|
21063
|
+
if (point === 0) color = this.config.gridOriginColor;
|
|
20916
21064
|
layer.add(new konva_lib_shapes_Line.Line({
|
|
20917
21065
|
points: [
|
|
20918
21066
|
point,
|
|
20919
|
-
(-stage.y() - 2 * this.gridSize) / stage.scaleY(),
|
|
21067
|
+
(-stage.y() - 2 * this.config.gridSize) / stage.scaleY(),
|
|
20920
21068
|
point,
|
|
20921
|
-
(stage.height() - stage.y() + 2 * this.gridSize) / stage.scaleY()
|
|
21069
|
+
(stage.height() - stage.y() + 2 * this.config.gridSize) / stage.scaleY()
|
|
20922
21070
|
],
|
|
20923
21071
|
stroke: color,
|
|
20924
|
-
strokeWidth: (point % (10 * (this.gridSize / stage.scaleX())) === 0 ? 2.5 : .5) / stage.scaleX(),
|
|
21072
|
+
strokeWidth: (point % (10 * (this.config.gridSize / stage.scaleX())) === 0 ? 2.5 : .5) / stage.scaleX(),
|
|
20925
21073
|
listening: false
|
|
20926
21074
|
}));
|
|
20927
21075
|
}
|
|
20928
21076
|
for (let index = 0; index < pointsY.length; index++) {
|
|
20929
21077
|
const point = pointsY[index];
|
|
20930
|
-
let color = this.gridColor;
|
|
20931
|
-
if (point === 0) color = this.
|
|
21078
|
+
let color = this.config.gridColor;
|
|
21079
|
+
if (point === 0) color = this.config.gridOriginColor;
|
|
20932
21080
|
layer.add(new konva_lib_shapes_Line.Line({
|
|
20933
21081
|
points: [
|
|
20934
|
-
(-stage.x() - 2 * this.gridSize) / stage.scaleX(),
|
|
21082
|
+
(-stage.x() - 2 * this.config.gridSize) / stage.scaleX(),
|
|
20935
21083
|
point,
|
|
20936
|
-
(stage.width() - stage.x() + 2 * this.gridSize) / stage.scaleX(),
|
|
21084
|
+
(stage.width() - stage.x() + 2 * this.config.gridSize) / stage.scaleX(),
|
|
20937
21085
|
point
|
|
20938
21086
|
],
|
|
20939
21087
|
stroke: color,
|
|
20940
|
-
strokeWidth: (point % (10 * (this.gridSize / stage.scaleY())) === 0 ? 2.5 : .5) / stage.scaleX(),
|
|
21088
|
+
strokeWidth: (point % (10 * (this.config.gridSize / stage.scaleY())) === 0 ? 2.5 : .5) / stage.scaleX(),
|
|
20941
21089
|
listening: false
|
|
20942
21090
|
}));
|
|
20943
21091
|
}
|
|
@@ -20946,18 +21094,18 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
20946
21094
|
const layer = this.getLayer();
|
|
20947
21095
|
if (!layer) return;
|
|
20948
21096
|
const stage = this.instance.getStage();
|
|
20949
|
-
const stageXRound = this.round(stage.x(), this.gridSize) * -1;
|
|
21097
|
+
const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
|
|
20950
21098
|
const pointsX = [];
|
|
20951
|
-
for (let i = stageXRound; i < stageXRound + stage.width(); i += this.gridSize) pointsX.push(i / stage.scaleX());
|
|
20952
|
-
const stageYRound = this.round(stage.y(), this.gridSize) * -1;
|
|
21099
|
+
for (let i = stageXRound; i < stageXRound + stage.width(); i += this.config.gridSize) pointsX.push(i / stage.scaleX());
|
|
21100
|
+
const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
|
|
20953
21101
|
const pointsY = [];
|
|
20954
|
-
for (let i = stageYRound; i < stageYRound + stage.height(); i += this.gridSize) pointsY.push(i / stage.scaleY());
|
|
21102
|
+
for (let i = stageYRound; i < stageYRound + stage.height(); i += this.config.gridSize) pointsY.push(i / stage.scaleY());
|
|
20955
21103
|
for (let indexX = 0; indexX < pointsX.length; indexX++) {
|
|
20956
21104
|
const pointX = pointsX[indexX];
|
|
20957
21105
|
for (let indexY = 0; indexY < pointsY.length; indexY++) {
|
|
20958
21106
|
const pointY = pointsY[indexY];
|
|
20959
|
-
let color = this.gridColor;
|
|
20960
|
-
if (pointX === 0 || pointY === 0) color = this.
|
|
21107
|
+
let color = this.config.gridColor;
|
|
21108
|
+
if (pointX === 0 || pointY === 0) color = this.config.gridOriginColor;
|
|
20961
21109
|
layer.add(new konva_lib_shapes_Circle.Circle({
|
|
20962
21110
|
x: pointX,
|
|
20963
21111
|
y: pointY,
|
|
@@ -20984,10 +21132,10 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
20984
21132
|
this.onRender();
|
|
20985
21133
|
}
|
|
20986
21134
|
getType() {
|
|
20987
|
-
return this.type;
|
|
21135
|
+
return this.config.type;
|
|
20988
21136
|
}
|
|
20989
21137
|
setType(type) {
|
|
20990
|
-
this.type = type;
|
|
21138
|
+
this.config.type = type;
|
|
20991
21139
|
this.onRender();
|
|
20992
21140
|
}
|
|
20993
21141
|
};
|
|
@@ -21167,6 +21315,7 @@ var WeaveStageResizePlugin = class extends WeavePlugin {
|
|
|
21167
21315
|
|
|
21168
21316
|
//#endregion
|
|
21169
21317
|
//#region src/plugins/connected-users/constants.ts
|
|
21318
|
+
const WEAVE_CONNECTED_USERS_KEY = "connectedUsers";
|
|
21170
21319
|
const WEAVE_CONNECTED_USER_INFO_KEY = "userInfo";
|
|
21171
21320
|
|
|
21172
21321
|
//#endregion
|
|
@@ -21176,26 +21325,23 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
|
|
|
21176
21325
|
getLayerName = void 0;
|
|
21177
21326
|
constructor(params) {
|
|
21178
21327
|
super();
|
|
21179
|
-
const {
|
|
21328
|
+
const { config, callbacks } = params ?? {};
|
|
21329
|
+
this.config = config;
|
|
21330
|
+
this.callbacks = callbacks ?? {};
|
|
21180
21331
|
this.connectedUsers = {};
|
|
21181
|
-
this.onConnectedUsersChanged = onConnectedUsersChanged;
|
|
21182
|
-
this.getUser = getUser ?? (() => ({
|
|
21183
|
-
name: "Unknown",
|
|
21184
|
-
email: "unknown@domain.com"
|
|
21185
|
-
}));
|
|
21186
21332
|
}
|
|
21187
21333
|
getName() {
|
|
21188
|
-
return
|
|
21334
|
+
return WEAVE_CONNECTED_USERS_KEY;
|
|
21189
21335
|
}
|
|
21190
21336
|
onInit() {
|
|
21191
21337
|
const store = this.instance.getStore();
|
|
21192
|
-
const userInfo = this.getUser();
|
|
21338
|
+
const userInfo = this.config.getUser();
|
|
21193
21339
|
store.setAwarenessInfo(WEAVE_CONNECTED_USER_INFO_KEY, userInfo);
|
|
21194
|
-
this.onConnectedUsersChanged?.({ [userInfo.name]: userInfo });
|
|
21340
|
+
this.callbacks?.onConnectedUsersChanged?.({ [userInfo.name]: userInfo });
|
|
21195
21341
|
store.onAwarenessChange((changes) => {
|
|
21196
21342
|
if (!this.enabled) {
|
|
21197
21343
|
this.connectedUsers = {};
|
|
21198
|
-
this.onConnectedUsersChanged?.({});
|
|
21344
|
+
this.callbacks?.onConnectedUsersChanged?.({});
|
|
21199
21345
|
return;
|
|
21200
21346
|
}
|
|
21201
21347
|
const newConnectedUsers = {};
|
|
@@ -21206,7 +21352,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
|
|
|
21206
21352
|
newConnectedUsers[userInformation.name] = userInformation;
|
|
21207
21353
|
}
|
|
21208
21354
|
}
|
|
21209
|
-
if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.onConnectedUsersChanged?.(newConnectedUsers);
|
|
21355
|
+
if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.callbacks?.onConnectedUsersChanged?.(newConnectedUsers);
|
|
21210
21356
|
this.connectedUsers = newConnectedUsers;
|
|
21211
21357
|
});
|
|
21212
21358
|
}
|
|
@@ -21236,14 +21382,11 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
|
|
|
21236
21382
|
userPointerBackgroundPaddingY = 8;
|
|
21237
21383
|
constructor(params) {
|
|
21238
21384
|
super();
|
|
21239
|
-
const {
|
|
21385
|
+
const { config } = params;
|
|
21240
21386
|
this.renderCursors = true;
|
|
21241
21387
|
this.usersPointers = {};
|
|
21242
21388
|
this.usersPointersTimers = {};
|
|
21243
|
-
this.
|
|
21244
|
-
name: "Unknown",
|
|
21245
|
-
email: "unknown@domain.com"
|
|
21246
|
-
}));
|
|
21389
|
+
this.config = config;
|
|
21247
21390
|
}
|
|
21248
21391
|
getName() {
|
|
21249
21392
|
return WEAVE_USERS_POINTERS_KEY;
|
|
@@ -21264,7 +21407,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
|
|
|
21264
21407
|
const store = this.instance.getStore();
|
|
21265
21408
|
const stage = this.instance.getStage();
|
|
21266
21409
|
store.onAwarenessChange((changes) => {
|
|
21267
|
-
const selfUser = this.getUser();
|
|
21410
|
+
const selfUser = this.config.getUser();
|
|
21268
21411
|
for (const change of changes) {
|
|
21269
21412
|
if (!change[WEAVE_USER_POINTER_KEY]) continue;
|
|
21270
21413
|
if (change[WEAVE_USER_POINTER_KEY] && selfUser.name !== change[WEAVE_USER_POINTER_KEY].user) {
|
|
@@ -21283,7 +21426,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
|
|
|
21283
21426
|
});
|
|
21284
21427
|
stage.on("dragmove", (e) => {
|
|
21285
21428
|
e.evt.preventDefault();
|
|
21286
|
-
const userInfo = this.getUser();
|
|
21429
|
+
const userInfo = this.config.getUser();
|
|
21287
21430
|
const mousePos = stage.getRelativePointerPosition();
|
|
21288
21431
|
if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
|
|
21289
21432
|
user: userInfo.name,
|
|
@@ -21293,7 +21436,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
|
|
|
21293
21436
|
});
|
|
21294
21437
|
stage.on("pointermove", (e) => {
|
|
21295
21438
|
e.evt.preventDefault();
|
|
21296
|
-
const userInfo = this.getUser();
|
|
21439
|
+
const userInfo = this.config.getUser();
|
|
21297
21440
|
const mousePos = stage.getRelativePointerPosition();
|
|
21298
21441
|
if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
|
|
21299
21442
|
user: userInfo.name,
|
|
@@ -21453,8 +21596,9 @@ const WEAVE_STAGE_DROP_AREA_KEY = "stageDropArea";
|
|
|
21453
21596
|
var WeaveStageDropAreaPlugin = class extends WeavePlugin {
|
|
21454
21597
|
getLayerName = void 0;
|
|
21455
21598
|
initLayer = void 0;
|
|
21456
|
-
constructor(
|
|
21599
|
+
constructor(params) {
|
|
21457
21600
|
super();
|
|
21601
|
+
const { callbacks } = params ?? {};
|
|
21458
21602
|
this.callbacks = callbacks;
|
|
21459
21603
|
this.enabled = true;
|
|
21460
21604
|
}
|
|
@@ -21489,6 +21633,13 @@ var WeaveStageDropAreaPlugin = class extends WeavePlugin {
|
|
|
21489
21633
|
//#region src/plugins/nodes-snapping/constants.ts
|
|
21490
21634
|
const WEAVE_NODES_SNAPPING_KEY = "nodesSnapping";
|
|
21491
21635
|
const GUIDE_LINE_NAME = "guide-line";
|
|
21636
|
+
const GUIDE_LINE_DEFAULT_CONFIG = {
|
|
21637
|
+
stroke: "rgb(0, 161, 255)",
|
|
21638
|
+
strokeWidth: 1,
|
|
21639
|
+
dash: [4, 6]
|
|
21640
|
+
};
|
|
21641
|
+
const GUIDE_LINE_DRAG_SNAPPING_THRESHOLD = 10;
|
|
21642
|
+
const GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD = 10;
|
|
21492
21643
|
const GUIDE_ORIENTATION = {
|
|
21493
21644
|
["HORIZONTAL"]: "H",
|
|
21494
21645
|
["VERTICAL"]: "V"
|
|
@@ -21502,9 +21653,12 @@ const NODE_SNAP = {
|
|
|
21502
21653
|
//#endregion
|
|
21503
21654
|
//#region src/plugins/nodes-snapping/nodes-snapping.ts
|
|
21504
21655
|
var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
21505
|
-
constructor() {
|
|
21656
|
+
constructor(params) {
|
|
21506
21657
|
super();
|
|
21507
|
-
|
|
21658
|
+
const { config } = params ?? {};
|
|
21659
|
+
this.guideLineConfig = config?.guideLine ?? GUIDE_LINE_DEFAULT_CONFIG;
|
|
21660
|
+
this.dragSnappingThreshold = config?.dragSnappingThreshold ?? GUIDE_LINE_DRAG_SNAPPING_THRESHOLD;
|
|
21661
|
+
this.transformSnappingThreshold = config?.transformSnappingThreshold ?? GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD;
|
|
21508
21662
|
this.enabled = true;
|
|
21509
21663
|
}
|
|
21510
21664
|
getName() {
|
|
@@ -21516,42 +21670,76 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21516
21670
|
setEnabled(enabled) {
|
|
21517
21671
|
this.enabled = enabled;
|
|
21518
21672
|
}
|
|
21519
|
-
|
|
21520
|
-
const stage = this.instance.getStage();
|
|
21673
|
+
evaluateGuidelines(e) {
|
|
21521
21674
|
const mainLayer = this.instance.getMainLayer();
|
|
21522
|
-
if (
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
|
|
21531
|
-
|
|
21532
|
-
|
|
21533
|
-
|
|
21534
|
-
|
|
21535
|
-
|
|
21675
|
+
if (!this.enabled) return;
|
|
21676
|
+
if (!mainLayer) return;
|
|
21677
|
+
let node = void 0;
|
|
21678
|
+
if (e.type === "dragmove" && e.target instanceof konva.default.Transformer) {
|
|
21679
|
+
const actualTarget = e.target;
|
|
21680
|
+
node = actualTarget.getNodes()[0];
|
|
21681
|
+
}
|
|
21682
|
+
if (e.type === "transform") node = e.target;
|
|
21683
|
+
if (typeof node === "undefined") return;
|
|
21684
|
+
mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
|
|
21685
|
+
const lineGuideStops = this.getLineGuideStops(node);
|
|
21686
|
+
const itemBounds = this.getObjectSnappingEdges(node);
|
|
21687
|
+
const guides = this.getGuides(lineGuideStops, itemBounds, e.type);
|
|
21688
|
+
if (!guides.length) return;
|
|
21689
|
+
this.drawGuides(guides);
|
|
21690
|
+
if (e.type === "dragmove") {
|
|
21691
|
+
const absPos = node.absolutePosition();
|
|
21692
|
+
guides.forEach((lg) => {
|
|
21693
|
+
switch (lg.orientation) {
|
|
21694
|
+
case GUIDE_ORIENTATION.VERTICAL: {
|
|
21695
|
+
absPos.x = lg.lineGuide + lg.offset;
|
|
21696
|
+
break;
|
|
21697
|
+
}
|
|
21698
|
+
case GUIDE_ORIENTATION.HORIZONTAL: {
|
|
21699
|
+
absPos.y = lg.lineGuide + lg.offset;
|
|
21700
|
+
break;
|
|
21701
|
+
}
|
|
21702
|
+
}
|
|
21703
|
+
});
|
|
21704
|
+
node.absolutePosition(absPos);
|
|
21705
|
+
}
|
|
21706
|
+
if (e.type === "transform") {
|
|
21707
|
+
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
21708
|
+
if (nodesSelectionPlugin) {
|
|
21709
|
+
const transformer = nodesSelectionPlugin.getTransformer();
|
|
21710
|
+
transformer.anchorDragBoundFunc((_, newAbsPos) => {
|
|
21711
|
+
const finalPos = { ...newAbsPos };
|
|
21536
21712
|
guides.forEach((lg) => {
|
|
21537
21713
|
switch (lg.orientation) {
|
|
21538
21714
|
case GUIDE_ORIENTATION.VERTICAL: {
|
|
21539
|
-
|
|
21715
|
+
const distX = Math.sqrt(Math.pow(newAbsPos.x - lg.lineGuide, 2));
|
|
21716
|
+
if (distX < this.transformSnappingThreshold) finalPos.x = lg.lineGuide;
|
|
21540
21717
|
break;
|
|
21541
21718
|
}
|
|
21542
21719
|
case GUIDE_ORIENTATION.HORIZONTAL: {
|
|
21543
|
-
|
|
21720
|
+
const distY = Math.sqrt(Math.pow(newAbsPos.y - lg.lineGuide, 2));
|
|
21721
|
+
if (distY < this.transformSnappingThreshold) finalPos.y = lg.lineGuide;
|
|
21544
21722
|
break;
|
|
21545
21723
|
}
|
|
21546
21724
|
}
|
|
21547
21725
|
});
|
|
21548
|
-
|
|
21549
|
-
}
|
|
21550
|
-
}
|
|
21551
|
-
|
|
21552
|
-
|
|
21553
|
-
|
|
21554
|
-
|
|
21726
|
+
return finalPos;
|
|
21727
|
+
});
|
|
21728
|
+
}
|
|
21729
|
+
}
|
|
21730
|
+
}
|
|
21731
|
+
cleanupEvaluateGuidelines() {
|
|
21732
|
+
const mainLayer = this.instance.getMainLayer();
|
|
21733
|
+
if (!this.enabled) return;
|
|
21734
|
+
if (!mainLayer) return;
|
|
21735
|
+
mainLayer.find(`.${GUIDE_LINE_NAME}`).forEach((l) => l.destroy());
|
|
21736
|
+
}
|
|
21737
|
+
initEvents() {
|
|
21738
|
+
const stage = this.instance.getStage();
|
|
21739
|
+
const mainLayer = this.instance.getMainLayer();
|
|
21740
|
+
if (mainLayer) {
|
|
21741
|
+
stage.on("dragmove", this.evaluateGuidelines.bind(this));
|
|
21742
|
+
stage.on("dragend", this.cleanupEvaluateGuidelines.bind(this));
|
|
21555
21743
|
}
|
|
21556
21744
|
}
|
|
21557
21745
|
getLineGuideStops(skipShape) {
|
|
@@ -21588,7 +21776,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21588
21776
|
getObjectSnappingEdges(node) {
|
|
21589
21777
|
const box = node.getClientRect();
|
|
21590
21778
|
const absPos = node.absolutePosition();
|
|
21591
|
-
|
|
21779
|
+
const snappingEdges = {
|
|
21592
21780
|
vertical: [
|
|
21593
21781
|
{
|
|
21594
21782
|
guide: Math.round(box.x),
|
|
@@ -21624,14 +21812,15 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21624
21812
|
}
|
|
21625
21813
|
]
|
|
21626
21814
|
};
|
|
21815
|
+
return snappingEdges;
|
|
21627
21816
|
}
|
|
21628
|
-
getGuides(lineGuideStops, itemBounds) {
|
|
21817
|
+
getGuides(lineGuideStops, itemBounds, type) {
|
|
21629
21818
|
const resultV = [];
|
|
21630
21819
|
const resultH = [];
|
|
21631
21820
|
lineGuideStops.vertical.forEach((lineGuide) => {
|
|
21632
21821
|
itemBounds.vertical.forEach((itemBound) => {
|
|
21633
21822
|
const diff = Math.abs(lineGuide - itemBound.guide);
|
|
21634
|
-
if (diff < this.
|
|
21823
|
+
if (diff < this.dragSnappingThreshold) resultV.push({
|
|
21635
21824
|
lineGuide,
|
|
21636
21825
|
diff,
|
|
21637
21826
|
snap: itemBound.snap,
|
|
@@ -21642,7 +21831,7 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21642
21831
|
lineGuideStops.horizontal.forEach((lineGuide) => {
|
|
21643
21832
|
itemBounds.horizontal.forEach((itemBound) => {
|
|
21644
21833
|
const diff = Math.abs(lineGuide - itemBound.guide);
|
|
21645
|
-
if (diff < this.
|
|
21834
|
+
if (diff < this.dragSnappingThreshold) resultH.push({
|
|
21646
21835
|
lineGuide,
|
|
21647
21836
|
diff,
|
|
21648
21837
|
snap: itemBound.snap,
|
|
@@ -21651,20 +21840,40 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21651
21840
|
});
|
|
21652
21841
|
});
|
|
21653
21842
|
const guides = [];
|
|
21654
|
-
|
|
21655
|
-
|
|
21656
|
-
|
|
21657
|
-
|
|
21658
|
-
|
|
21659
|
-
|
|
21660
|
-
|
|
21661
|
-
|
|
21662
|
-
|
|
21663
|
-
|
|
21664
|
-
|
|
21665
|
-
|
|
21666
|
-
|
|
21667
|
-
|
|
21843
|
+
if (type === "dragmove") {
|
|
21844
|
+
const minV = resultV.sort((a, b) => a.diff - b.diff)[0];
|
|
21845
|
+
const minH = resultH.sort((a, b) => a.diff - b.diff)[0];
|
|
21846
|
+
if (minV) guides.push({
|
|
21847
|
+
lineGuide: minV.lineGuide,
|
|
21848
|
+
offset: minV.offset,
|
|
21849
|
+
orientation: GUIDE_ORIENTATION.VERTICAL,
|
|
21850
|
+
snap: minV.snap
|
|
21851
|
+
});
|
|
21852
|
+
if (minH) guides.push({
|
|
21853
|
+
lineGuide: minH.lineGuide,
|
|
21854
|
+
offset: minH.offset,
|
|
21855
|
+
orientation: GUIDE_ORIENTATION.HORIZONTAL,
|
|
21856
|
+
snap: minH.snap
|
|
21857
|
+
});
|
|
21858
|
+
}
|
|
21859
|
+
if (type === "transform") {
|
|
21860
|
+
resultV.forEach((v) => {
|
|
21861
|
+
guides.push({
|
|
21862
|
+
lineGuide: v.lineGuide,
|
|
21863
|
+
offset: v.offset,
|
|
21864
|
+
orientation: GUIDE_ORIENTATION.VERTICAL,
|
|
21865
|
+
snap: v.snap
|
|
21866
|
+
});
|
|
21867
|
+
});
|
|
21868
|
+
resultH.forEach((h) => {
|
|
21869
|
+
guides.push({
|
|
21870
|
+
lineGuide: h.lineGuide,
|
|
21871
|
+
offset: h.offset,
|
|
21872
|
+
orientation: GUIDE_ORIENTATION.HORIZONTAL,
|
|
21873
|
+
snap: h.snap
|
|
21874
|
+
});
|
|
21875
|
+
});
|
|
21876
|
+
}
|
|
21668
21877
|
return guides;
|
|
21669
21878
|
}
|
|
21670
21879
|
drawGuides(guides) {
|
|
@@ -21673,16 +21882,16 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21673
21882
|
if (mainLayer) guides.forEach((lg) => {
|
|
21674
21883
|
if (lg.orientation === GUIDE_ORIENTATION.HORIZONTAL) {
|
|
21675
21884
|
const line = new konva.default.Line({
|
|
21885
|
+
...this.guideLineConfig,
|
|
21886
|
+
strokeWidth: (this.guideLineConfig.strokeWidth ?? GUIDE_LINE_DEFAULT_CONFIG.strokeWidth) / stage.scaleX(),
|
|
21887
|
+
dash: this.guideLineConfig.dash?.map((e) => e / stage.scaleX()),
|
|
21676
21888
|
points: [
|
|
21677
21889
|
-6e3,
|
|
21678
21890
|
0,
|
|
21679
21891
|
6e3,
|
|
21680
21892
|
0
|
|
21681
21893
|
],
|
|
21682
|
-
|
|
21683
|
-
strokeWidth: 1 / stage.scaleX(),
|
|
21684
|
-
name: GUIDE_LINE_NAME,
|
|
21685
|
-
dash: [4 / stage.scaleX(), 6 / stage.scaleX()]
|
|
21894
|
+
name: GUIDE_LINE_NAME
|
|
21686
21895
|
});
|
|
21687
21896
|
mainLayer.add(line);
|
|
21688
21897
|
line.absolutePosition({
|
|
@@ -21692,16 +21901,16 @@ var WeaveNodesSnappingPlugin = class extends WeavePlugin {
|
|
|
21692
21901
|
}
|
|
21693
21902
|
if (lg.orientation === GUIDE_ORIENTATION.VERTICAL) {
|
|
21694
21903
|
const line = new konva.default.Line({
|
|
21904
|
+
...this.guideLineConfig,
|
|
21905
|
+
strokeWidth: (this.guideLineConfig.strokeWidth ?? GUIDE_LINE_DEFAULT_CONFIG.strokeWidth) / stage.scaleX(),
|
|
21906
|
+
dash: this.guideLineConfig.dash?.map((e) => e / stage.scaleX()),
|
|
21695
21907
|
points: [
|
|
21696
21908
|
0,
|
|
21697
21909
|
-6e3,
|
|
21698
21910
|
0,
|
|
21699
21911
|
6e3
|
|
21700
21912
|
],
|
|
21701
|
-
|
|
21702
|
-
strokeWidth: 1 / stage.scaleX(),
|
|
21703
|
-
name: GUIDE_LINE_NAME,
|
|
21704
|
-
dash: [4 / stage.scaleX(), 6 / stage.scaleX()]
|
|
21913
|
+
name: GUIDE_LINE_NAME
|
|
21705
21914
|
});
|
|
21706
21915
|
mainLayer.add(line);
|
|
21707
21916
|
line.absolutePosition({
|
|
@@ -21724,7 +21933,10 @@ exports.BRUSH_TOOL_STATE = BRUSH_TOOL_STATE
|
|
|
21724
21933
|
exports.COPY_PASTE_NODES_PLUGIN_STATE = COPY_PASTE_NODES_PLUGIN_STATE
|
|
21725
21934
|
exports.FRAME_TOOL_ACTION_NAME = FRAME_TOOL_ACTION_NAME
|
|
21726
21935
|
exports.FRAME_TOOL_STATE = FRAME_TOOL_STATE
|
|
21936
|
+
exports.GUIDE_LINE_DEFAULT_CONFIG = GUIDE_LINE_DEFAULT_CONFIG
|
|
21937
|
+
exports.GUIDE_LINE_DRAG_SNAPPING_THRESHOLD = GUIDE_LINE_DRAG_SNAPPING_THRESHOLD
|
|
21727
21938
|
exports.GUIDE_LINE_NAME = GUIDE_LINE_NAME
|
|
21939
|
+
exports.GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD = GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD
|
|
21728
21940
|
exports.GUIDE_ORIENTATION = GUIDE_ORIENTATION
|
|
21729
21941
|
exports.IMAGE_TOOL_STATE = IMAGE_TOOL_STATE
|
|
21730
21942
|
exports.MOVE_TOOL_ACTION_NAME = MOVE_TOOL_ACTION_NAME
|
|
@@ -21737,8 +21949,16 @@ exports.SELECTION_TOOL_ACTION_NAME = SELECTION_TOOL_ACTION_NAME
|
|
|
21737
21949
|
exports.SELECTION_TOOL_STATE = SELECTION_TOOL_STATE
|
|
21738
21950
|
exports.TEXT_TOOL_STATE = TEXT_TOOL_STATE
|
|
21739
21951
|
exports.WEAVE_COPY_PASTE_NODES_KEY = WEAVE_COPY_PASTE_NODES_KEY
|
|
21952
|
+
exports.WEAVE_FRAME_NODE_DEFAULT_PROPS = WEAVE_FRAME_NODE_DEFAULT_PROPS
|
|
21953
|
+
exports.WEAVE_FRAME_NODE_SIZES = WEAVE_FRAME_NODE_SIZES
|
|
21954
|
+
exports.WEAVE_FRAME_NODE_SIZES_MULTIPLIER = WEAVE_FRAME_NODE_SIZES_MULTIPLIER
|
|
21955
|
+
exports.WEAVE_FRAME_NODE_SIZES_ORIENTATION = WEAVE_FRAME_NODE_SIZES_ORIENTATION
|
|
21956
|
+
exports.WEAVE_FRAME_NODE_SIZES_TYPES = WEAVE_FRAME_NODE_SIZES_TYPES
|
|
21740
21957
|
exports.WEAVE_FRAME_NODE_TYPE = WEAVE_FRAME_NODE_TYPE
|
|
21958
|
+
exports.WEAVE_GRID_DEFAULT_COLOR = WEAVE_GRID_DEFAULT_COLOR
|
|
21959
|
+
exports.WEAVE_GRID_DEFAULT_ORIGIN_COLOR = WEAVE_GRID_DEFAULT_ORIGIN_COLOR
|
|
21741
21960
|
exports.WEAVE_GRID_DEFAULT_SIZE = WEAVE_GRID_DEFAULT_SIZE
|
|
21961
|
+
exports.WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_DEFAULT_TYPE
|
|
21742
21962
|
exports.WEAVE_GRID_LAYER_ID = WEAVE_GRID_LAYER_ID
|
|
21743
21963
|
exports.WEAVE_GRID_TYPES = WEAVE_GRID_TYPES
|
|
21744
21964
|
exports.WEAVE_NODES_SELECTION_KEY = WEAVE_NODES_SELECTION_KEY
|