@inditextech/weave-sdk 0.42.2 → 0.44.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 +249 -239
- package/dist/sdk.d.cts +24 -5
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +24 -5
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +262 -253
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -15958,7 +15958,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15958
15958
|
super();
|
|
15959
15959
|
const { config } = params ?? {};
|
|
15960
15960
|
this.config = {
|
|
15961
|
-
|
|
15961
|
+
selection: {
|
|
15962
15962
|
rotationSnaps: [
|
|
15963
15963
|
0,
|
|
15964
15964
|
45,
|
|
@@ -15993,16 +15993,27 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
15993
15993
|
}
|
|
15994
15994
|
},
|
|
15995
15995
|
borderStroke: "#0074ffcc",
|
|
15996
|
-
borderStrokeWidth:
|
|
15997
|
-
...config?.
|
|
15996
|
+
borderStrokeWidth: 1,
|
|
15997
|
+
...config?.selection
|
|
15998
15998
|
},
|
|
15999
|
-
|
|
15999
|
+
hover: {
|
|
16000
|
+
borderStrokeWidth: 1,
|
|
16001
|
+
...config?.hover
|
|
16002
|
+
},
|
|
16003
|
+
selectionArea: {
|
|
16004
|
+
fill: "#93c5fd40",
|
|
16005
|
+
stroke: "#1e40afff",
|
|
16006
|
+
strokeWidth: 1,
|
|
16007
|
+
dash: [12, 4],
|
|
16008
|
+
...config?.selectionArea
|
|
16009
|
+
},
|
|
16010
|
+
behaviors: {
|
|
16000
16011
|
singleSelection: { enabled: true },
|
|
16001
16012
|
multipleSelection: { enabled: false },
|
|
16002
|
-
...config?.
|
|
16013
|
+
...config?.behaviors
|
|
16003
16014
|
}
|
|
16004
16015
|
};
|
|
16005
|
-
this.defaultEnabledAnchors = this.config.
|
|
16016
|
+
this.defaultEnabledAnchors = this.config.selection?.enabledAnchors ?? [
|
|
16006
16017
|
"top-left",
|
|
16007
16018
|
"top-center",
|
|
16008
16019
|
"top-right",
|
|
@@ -16060,23 +16071,21 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16060
16071
|
stage.container().tabIndex = 1;
|
|
16061
16072
|
stage.container().focus();
|
|
16062
16073
|
const selectionRectangle = new konva.default.Rect({
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
|
|
16066
|
-
dash: [12 * stage.scaleX(), 4 * stage.scaleX()],
|
|
16074
|
+
...this.config.selectionArea,
|
|
16075
|
+
...this.config.selectionArea.strokeWidth && { strokeWidth: this.config.selectionArea.strokeWidth / stage.scaleX() },
|
|
16076
|
+
...this.config.selectionArea.dash && { dash: this.config.selectionArea.dash.map((d) => d / stage.scaleX()) },
|
|
16067
16077
|
visible: false,
|
|
16068
16078
|
listening: false
|
|
16069
16079
|
});
|
|
16070
16080
|
selectionLayer?.add(selectionRectangle);
|
|
16071
16081
|
const tr = new konva.default.Transformer({
|
|
16072
16082
|
id: "selectionTransformer",
|
|
16073
|
-
...this.config.
|
|
16083
|
+
...this.config.selection
|
|
16074
16084
|
});
|
|
16075
16085
|
selectionLayer?.add(tr);
|
|
16076
16086
|
const trHover = new konva.default.Transformer({
|
|
16077
16087
|
id: "hoverTransformer",
|
|
16078
|
-
...this.config.
|
|
16079
|
-
borderStrokeWidth: 3,
|
|
16088
|
+
...this.config.hover,
|
|
16080
16089
|
rotateEnabled: false,
|
|
16081
16090
|
resizeEnabled: false,
|
|
16082
16091
|
enabledAnchors: [],
|
|
@@ -16347,8 +16356,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16347
16356
|
y1 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
16348
16357
|
x2 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
16349
16358
|
y2 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
16350
|
-
this.selectionRectangle.strokeWidth(
|
|
16351
|
-
this.selectionRectangle.dash(
|
|
16359
|
+
this.selectionRectangle.strokeWidth(this.config.selectionArea.strokeWidth / stage.scaleX());
|
|
16360
|
+
this.selectionRectangle.dash(this.config.selectionArea.dash?.map((d) => d / stage.scaleX()) ?? []);
|
|
16352
16361
|
this.selectionRectangle.width(0);
|
|
16353
16362
|
this.selectionRectangle.height(0);
|
|
16354
16363
|
this.selecting = true;
|
|
@@ -16468,16 +16477,16 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16468
16477
|
if (!frameNode.getAttrs().locked) selectedNodes.add(node);
|
|
16469
16478
|
});
|
|
16470
16479
|
const nodesArray = [...selectedNodes];
|
|
16471
|
-
if (nodesArray.length > 1 && !this.config.
|
|
16472
|
-
if (nodesArray.length > 1 && this.config.
|
|
16480
|
+
if (nodesArray.length > 1 && !this.config.behaviors.multipleSelection.enabled || nodesArray.length === 1 && !this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16481
|
+
if (nodesArray.length > 1 && this.config.behaviors.multipleSelection.enabled || nodesArray.length === 1 && this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16473
16482
|
if (nodesArray.length === 1) {
|
|
16474
16483
|
this.tr.setAttrs({
|
|
16475
|
-
...this.config.
|
|
16484
|
+
...this.config.selection,
|
|
16476
16485
|
...nodesArray[0].getTransformerProperties()
|
|
16477
16486
|
});
|
|
16478
16487
|
this.tr.forceUpdate();
|
|
16479
16488
|
} else {
|
|
16480
|
-
this.tr.setAttrs({ ...this.config.
|
|
16489
|
+
this.tr.setAttrs({ ...this.config.selection });
|
|
16481
16490
|
this.tr.forceUpdate();
|
|
16482
16491
|
}
|
|
16483
16492
|
this.selecting = false;
|
|
@@ -16521,7 +16530,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16521
16530
|
if (targetNode && targetNode.getAttrs().nodeType) nodeTargeted = targetNode;
|
|
16522
16531
|
}
|
|
16523
16532
|
if (!nodeTargeted.getAttrs().nodeType) return;
|
|
16524
|
-
let nodesSelected = 0;
|
|
16525
16533
|
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
16526
16534
|
const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
|
|
16527
16535
|
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
@@ -16539,7 +16547,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16539
16547
|
}
|
|
16540
16548
|
if (!metaPressed) {
|
|
16541
16549
|
this.tr.nodes([nodeTargeted]);
|
|
16542
|
-
nodesSelected = this.tr.nodes().length;
|
|
16543
16550
|
this.tr.show();
|
|
16544
16551
|
areNodesSelected = true;
|
|
16545
16552
|
}
|
|
@@ -16547,24 +16554,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16547
16554
|
const nodes = this.tr.nodes().slice();
|
|
16548
16555
|
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
16549
16556
|
this.tr.nodes(nodes);
|
|
16550
|
-
nodesSelected = this.tr.nodes().length;
|
|
16551
16557
|
areNodesSelected = true;
|
|
16552
16558
|
}
|
|
16553
16559
|
if (metaPressed && !isSelected) {
|
|
16554
16560
|
const nodes = this.tr.nodes().concat([nodeTargeted]);
|
|
16555
16561
|
this.tr.nodes(nodes);
|
|
16556
|
-
nodesSelected = this.tr.nodes().length;
|
|
16557
16562
|
areNodesSelected = true;
|
|
16558
16563
|
}
|
|
16559
|
-
|
|
16560
|
-
if (nodesSelected > 1 && this.config.transformations.multipleSelection.enabled || nodesSelected === 1 && this.config.transformations.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16561
|
-
if (nodesSelected === 1) {
|
|
16562
|
-
this.tr.setAttrs({
|
|
16563
|
-
...this.config.transformer,
|
|
16564
|
-
...nodeTargeted.getTransformerProperties()
|
|
16565
|
-
});
|
|
16566
|
-
this.tr.forceUpdate();
|
|
16567
|
-
}
|
|
16564
|
+
this.handleBehaviors();
|
|
16568
16565
|
if (areNodesSelected) {
|
|
16569
16566
|
stage.container().tabIndex = 1;
|
|
16570
16567
|
stage.container().focus();
|
|
@@ -16578,21 +16575,25 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
16578
16575
|
getHoverTransformer() {
|
|
16579
16576
|
return this.trHover;
|
|
16580
16577
|
}
|
|
16581
|
-
|
|
16582
|
-
this.
|
|
16583
|
-
const nodesSelected =
|
|
16584
|
-
if (nodesSelected > 1 && !this.config.
|
|
16585
|
-
if (nodesSelected > 1 && this.config.
|
|
16578
|
+
handleBehaviors() {
|
|
16579
|
+
const nodes = this.getSelectedNodes();
|
|
16580
|
+
const nodesSelected = this.getSelectedNodes().length;
|
|
16581
|
+
if (nodesSelected > 1 && !this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && !this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors([]);
|
|
16582
|
+
if (nodesSelected > 1 && this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && this.config.behaviors.singleSelection.enabled) this.tr.enabledAnchors(this.defaultEnabledAnchors);
|
|
16586
16583
|
if (nodesSelected === 1) {
|
|
16587
16584
|
this.tr.setAttrs({
|
|
16588
|
-
...this.config.
|
|
16585
|
+
...this.config.selection,
|
|
16589
16586
|
...nodes[0].getTransformerProperties()
|
|
16590
16587
|
});
|
|
16591
16588
|
this.tr.forceUpdate();
|
|
16592
16589
|
} else if (nodesSelected > 1) {
|
|
16593
|
-
this.tr.setAttrs({ ...this.config.
|
|
16590
|
+
this.tr.setAttrs({ ...this.config.selection });
|
|
16594
16591
|
this.tr.forceUpdate();
|
|
16595
16592
|
}
|
|
16593
|
+
}
|
|
16594
|
+
setSelectedNodes(nodes) {
|
|
16595
|
+
this.tr.setNodes(nodes);
|
|
16596
|
+
this.handleBehaviors();
|
|
16596
16597
|
this.triggerSelectedNodesEvent();
|
|
16597
16598
|
}
|
|
16598
16599
|
getSelectedNodes() {
|
|
@@ -18450,6 +18451,7 @@ var WeaveStateManager = class {
|
|
|
18450
18451
|
return;
|
|
18451
18452
|
}
|
|
18452
18453
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18454
|
+
const userId = this.instance.getStore().getUser().id;
|
|
18453
18455
|
doc.transact(() => {
|
|
18454
18456
|
if (!parent.props.children) parent.props.children = [];
|
|
18455
18457
|
if (index) {
|
|
@@ -18468,7 +18470,7 @@ var WeaveStateManager = class {
|
|
|
18468
18470
|
parent.props.children.push(nodeToAdd);
|
|
18469
18471
|
}
|
|
18470
18472
|
this.instance.emitEvent("onNodeAdded", node);
|
|
18471
|
-
});
|
|
18473
|
+
}, userId);
|
|
18472
18474
|
}
|
|
18473
18475
|
deepSyncSyncedStore(target, source) {
|
|
18474
18476
|
for (const key in target) if (!(key in source)) delete target[key];
|
|
@@ -18512,9 +18514,10 @@ var WeaveStateManager = class {
|
|
|
18512
18514
|
return;
|
|
18513
18515
|
}
|
|
18514
18516
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18517
|
+
const userId = this.instance.getStore().getUser().id;
|
|
18515
18518
|
doc.transact(() => {
|
|
18516
18519
|
this.deepSyncSyncedStore(nodeState.props, node.props);
|
|
18517
|
-
});
|
|
18520
|
+
}, userId);
|
|
18518
18521
|
this.instance.emitEvent("onNodeUpdated", node);
|
|
18519
18522
|
}
|
|
18520
18523
|
removeNode(node) {
|
|
@@ -18536,6 +18539,7 @@ var WeaveStateManager = class {
|
|
|
18536
18539
|
return;
|
|
18537
18540
|
}
|
|
18538
18541
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18542
|
+
const userId = this.instance.getStore().getUser().id;
|
|
18539
18543
|
doc.transact(() => {
|
|
18540
18544
|
if (parent.props.children) {
|
|
18541
18545
|
for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
|
|
@@ -18545,7 +18549,7 @@ var WeaveStateManager = class {
|
|
|
18545
18549
|
for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
|
|
18546
18550
|
this.instance.emitEvent("onNodeRemoved", node);
|
|
18547
18551
|
}
|
|
18548
|
-
});
|
|
18552
|
+
}, userId);
|
|
18549
18553
|
}
|
|
18550
18554
|
removeNodes(nodes) {
|
|
18551
18555
|
for (const node of nodes) this.removeNode(node);
|
|
@@ -18577,6 +18581,7 @@ var WeaveStateManager = class {
|
|
|
18577
18581
|
return;
|
|
18578
18582
|
}
|
|
18579
18583
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18584
|
+
const userId = this.instance.getStore().getUser().id;
|
|
18580
18585
|
doc.transact(() => {
|
|
18581
18586
|
if (parent.props.children) {
|
|
18582
18587
|
const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
|
|
@@ -18587,7 +18592,7 @@ var WeaveStateManager = class {
|
|
|
18587
18592
|
if (item && position === __inditextech_weave_types.WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
|
|
18588
18593
|
for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
|
|
18589
18594
|
}
|
|
18590
|
-
});
|
|
18595
|
+
}, userId);
|
|
18591
18596
|
}
|
|
18592
18597
|
}
|
|
18593
18598
|
getElementsTree() {
|
|
@@ -18673,7 +18678,7 @@ var WeaveRegisterManager = class {
|
|
|
18673
18678
|
|
|
18674
18679
|
//#endregion
|
|
18675
18680
|
//#region package.json
|
|
18676
|
-
var version = "0.
|
|
18681
|
+
var version = "0.44.0";
|
|
18677
18682
|
|
|
18678
18683
|
//#endregion
|
|
18679
18684
|
//#region src/managers/setup.ts
|
|
@@ -21323,7 +21328,7 @@ const WEAVE_FRAME_NODE_DEFAULT_CONFIG = {
|
|
|
21323
21328
|
rotateEnabled: false,
|
|
21324
21329
|
resizeEnabled: false,
|
|
21325
21330
|
enabledAnchors: [],
|
|
21326
|
-
borderStrokeWidth:
|
|
21331
|
+
borderStrokeWidth: 1,
|
|
21327
21332
|
padding: 0
|
|
21328
21333
|
}
|
|
21329
21334
|
};
|
|
@@ -21408,13 +21413,15 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21408
21413
|
draggable: false
|
|
21409
21414
|
});
|
|
21410
21415
|
frameInternalGroup.add(background);
|
|
21416
|
+
const stage = this.instance.getStage();
|
|
21411
21417
|
const text = new konva.default.Text({
|
|
21412
21418
|
id: `${id}-title`,
|
|
21413
21419
|
x: 0,
|
|
21414
|
-
width: props.frameWidth,
|
|
21415
|
-
fontSize,
|
|
21420
|
+
width: props.frameWidth / stage.scaleX(),
|
|
21421
|
+
fontSize: fontSize / stage.scaleX(),
|
|
21416
21422
|
fontFamily,
|
|
21417
21423
|
fontStyle,
|
|
21424
|
+
verticalAlign: "middle",
|
|
21418
21425
|
align: "left",
|
|
21419
21426
|
text: props.title,
|
|
21420
21427
|
fill: fontColor,
|
|
@@ -21424,10 +21431,8 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21424
21431
|
draggable: false
|
|
21425
21432
|
});
|
|
21426
21433
|
const textMeasures = text.measureSize(text.getAttrs().text ?? "");
|
|
21427
|
-
const
|
|
21428
|
-
|
|
21429
|
-
text.y(-textHeight - titleMargin);
|
|
21430
|
-
text.width(textWidth);
|
|
21434
|
+
const textHeight = textMeasures.height + 2 * titleMargin / stage.scaleX();
|
|
21435
|
+
text.y(-textHeight);
|
|
21431
21436
|
text.height(textHeight);
|
|
21432
21437
|
frameInternalGroup.add(text);
|
|
21433
21438
|
frame.getTransformerProperties = () => {
|
|
@@ -21459,7 +21464,7 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21459
21464
|
height: props.frameHeight,
|
|
21460
21465
|
hitFunc: function(ctx, shape) {
|
|
21461
21466
|
ctx.beginPath();
|
|
21462
|
-
ctx.rect(0, -textHeight
|
|
21467
|
+
ctx.rect(0, -textHeight, props.frameWidth, textHeight);
|
|
21463
21468
|
ctx.fillStrokeShape(shape);
|
|
21464
21469
|
},
|
|
21465
21470
|
fill: "transparent",
|
|
@@ -21499,6 +21504,20 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21499
21504
|
selectionArea.off("dragmove");
|
|
21500
21505
|
selectionArea.off("dragend");
|
|
21501
21506
|
this.setupDefaultNodeEvents(frame);
|
|
21507
|
+
this.instance.addEventListener("onZoomChange", () => {
|
|
21508
|
+
const stage$1 = this.instance.getStage();
|
|
21509
|
+
text.fontSize(fontSize / stage$1.scaleX());
|
|
21510
|
+
text.width(props.frameWidth / stage$1.scaleX());
|
|
21511
|
+
const textMeasures$1 = text.measureSize(text.getAttrs().text ?? "");
|
|
21512
|
+
const textHeight$1 = textMeasures$1.height + 2 * titleMargin / stage$1.scaleX();
|
|
21513
|
+
text.y(-textHeight$1);
|
|
21514
|
+
text.height(textHeight$1);
|
|
21515
|
+
selectionArea.hitFunc(function(ctx, shape) {
|
|
21516
|
+
ctx.beginPath();
|
|
21517
|
+
ctx.rect(0, -textHeight$1, props.frameWidth, textHeight$1);
|
|
21518
|
+
ctx.fillStrokeShape(shape);
|
|
21519
|
+
});
|
|
21520
|
+
});
|
|
21502
21521
|
frame.off("pointerover");
|
|
21503
21522
|
frame.on(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, () => {
|
|
21504
21523
|
background.setAttrs({
|
|
@@ -21532,14 +21551,12 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21532
21551
|
if (title && selectionArea) {
|
|
21533
21552
|
title.text(newProps.title);
|
|
21534
21553
|
const textMeasures = title.measureSize(title.getAttrs().text ?? "");
|
|
21535
|
-
const
|
|
21536
|
-
|
|
21537
|
-
title.y(-textHeight - titleMargin);
|
|
21538
|
-
title.width(textWidth);
|
|
21554
|
+
const textHeight = textMeasures.height + 2 * titleMargin / stage.scaleX();
|
|
21555
|
+
title.y(-textHeight);
|
|
21539
21556
|
title.height(textHeight);
|
|
21540
21557
|
selectionArea.hitFunc(function(ctx, shape) {
|
|
21541
21558
|
ctx.beginPath();
|
|
21542
|
-
ctx.rect(0, -textHeight
|
|
21559
|
+
ctx.rect(0, -textHeight, nextProps.frameWidth, textHeight);
|
|
21543
21560
|
ctx.fillStrokeShape(shape);
|
|
21544
21561
|
});
|
|
21545
21562
|
}
|
|
@@ -24137,9 +24154,10 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24137
24154
|
this.initialized = false;
|
|
24138
24155
|
this.state = RECTANGLE_TOOL_STATE.IDLE;
|
|
24139
24156
|
this.rectId = null;
|
|
24140
|
-
this.
|
|
24157
|
+
this.tempRectNode = null;
|
|
24141
24158
|
this.moved = false;
|
|
24142
24159
|
this.container = void 0;
|
|
24160
|
+
this.measureContainer = void 0;
|
|
24143
24161
|
this.clickPoint = null;
|
|
24144
24162
|
this.props = this.initProps();
|
|
24145
24163
|
}
|
|
@@ -24178,10 +24196,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24178
24196
|
this.state = RECTANGLE_TOOL_STATE.ADDING;
|
|
24179
24197
|
return;
|
|
24180
24198
|
}
|
|
24181
|
-
if (this.state === RECTANGLE_TOOL_STATE.ADDING)
|
|
24182
|
-
this.creating = true;
|
|
24183
|
-
this.handleAdding();
|
|
24184
|
-
}
|
|
24199
|
+
if (this.state === RECTANGLE_TOOL_STATE.ADDING) this.handleAdding();
|
|
24185
24200
|
});
|
|
24186
24201
|
stage.on("pointermove", (e) => {
|
|
24187
24202
|
if (!this.isPressed(e)) return;
|
|
@@ -24190,19 +24205,13 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24190
24205
|
this.state = RECTANGLE_TOOL_STATE.ADDING;
|
|
24191
24206
|
return;
|
|
24192
24207
|
}
|
|
24193
|
-
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE)
|
|
24194
|
-
this.moved = true;
|
|
24195
|
-
this.handleMovement();
|
|
24196
|
-
}
|
|
24208
|
+
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) this.handleMovement();
|
|
24197
24209
|
});
|
|
24198
24210
|
stage.on("pointerup", (e) => {
|
|
24199
24211
|
this.pointers.delete(e.evt.pointerId);
|
|
24200
24212
|
const isTap = this.isTap(e);
|
|
24201
24213
|
if (isTap) this.moved = false;
|
|
24202
|
-
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE)
|
|
24203
|
-
this.creating = false;
|
|
24204
|
-
this.handleSettingSize();
|
|
24205
|
-
}
|
|
24214
|
+
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) this.handleSettingSize();
|
|
24206
24215
|
});
|
|
24207
24216
|
this.initialized = true;
|
|
24208
24217
|
}
|
|
@@ -24218,29 +24227,28 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24218
24227
|
this.setState(RECTANGLE_TOOL_STATE.ADDING);
|
|
24219
24228
|
}
|
|
24220
24229
|
handleAdding() {
|
|
24221
|
-
const { mousePoint, container } = this.instance.getMousePointer();
|
|
24230
|
+
const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
|
|
24222
24231
|
this.clickPoint = mousePoint;
|
|
24223
24232
|
this.container = container;
|
|
24233
|
+
this.measureContainer = measureContainer;
|
|
24224
24234
|
this.rectId = v4_default();
|
|
24225
|
-
|
|
24226
|
-
|
|
24227
|
-
const node = nodeHandler.create(this.rectId, {
|
|
24235
|
+
if (!this.tempRectNode) {
|
|
24236
|
+
this.tempRectNode = new konva.default.Rect({
|
|
24228
24237
|
...this.props,
|
|
24238
|
+
id: this.rectId,
|
|
24229
24239
|
strokeScaleEnabled: true,
|
|
24230
24240
|
x: this.clickPoint?.x ?? 0,
|
|
24231
24241
|
y: this.clickPoint?.y ?? 0,
|
|
24232
24242
|
width: 0,
|
|
24233
24243
|
height: 0
|
|
24234
24244
|
});
|
|
24235
|
-
this.
|
|
24245
|
+
this.measureContainer?.add(this.tempRectNode);
|
|
24236
24246
|
}
|
|
24237
24247
|
this.setState(RECTANGLE_TOOL_STATE.DEFINING_SIZE);
|
|
24238
24248
|
}
|
|
24239
24249
|
handleSettingSize() {
|
|
24240
|
-
|
|
24241
|
-
if (this.rectId && this.clickPoint && this.container && rectangle) {
|
|
24250
|
+
if (this.rectId && this.tempRectNode && this.clickPoint && this.container) {
|
|
24242
24251
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.container);
|
|
24243
|
-
const nodeHandler = this.instance.getNodeHandler("rectangle");
|
|
24244
24252
|
const rectPos = {
|
|
24245
24253
|
x: this.clickPoint.x,
|
|
24246
24254
|
y: this.clickPoint.y
|
|
@@ -24253,31 +24261,38 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24253
24261
|
rectWidth = Math.abs(this.clickPoint.x - mousePoint.x);
|
|
24254
24262
|
rectHeight = Math.abs(this.clickPoint.y - mousePoint.y);
|
|
24255
24263
|
}
|
|
24256
|
-
|
|
24264
|
+
this.tempRectNode.setAttrs({
|
|
24257
24265
|
...this.props,
|
|
24258
24266
|
x: rectPos.x,
|
|
24259
24267
|
y: rectPos.y,
|
|
24260
24268
|
width: rectWidth,
|
|
24261
24269
|
height: rectHeight
|
|
24262
24270
|
});
|
|
24263
|
-
|
|
24271
|
+
const nodeHandler = this.instance.getNodeHandler("rectangle");
|
|
24272
|
+
if (nodeHandler) {
|
|
24273
|
+
const clonedRectNode = this.tempRectNode.clone();
|
|
24274
|
+
this.tempRectNode.destroy();
|
|
24275
|
+
const node = nodeHandler.create(this.rectId, {
|
|
24276
|
+
...this.props,
|
|
24277
|
+
...clonedRectNode.getAttrs()
|
|
24278
|
+
});
|
|
24279
|
+
this.instance.addNode(node, this.container?.getAttrs().id);
|
|
24280
|
+
}
|
|
24264
24281
|
this.instance.emitEvent("onAddedRectangle");
|
|
24265
24282
|
}
|
|
24266
24283
|
this.cancelAction();
|
|
24267
24284
|
}
|
|
24268
24285
|
handleMovement() {
|
|
24269
24286
|
if (this.state !== RECTANGLE_TOOL_STATE.DEFINING_SIZE) return;
|
|
24270
|
-
|
|
24271
|
-
|
|
24272
|
-
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.
|
|
24287
|
+
if (this.rectId && this.tempRectNode && this.measureContainer && this.clickPoint) {
|
|
24288
|
+
this.moved = true;
|
|
24289
|
+
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
24273
24290
|
const deltaX = mousePoint.x - this.clickPoint?.x;
|
|
24274
24291
|
const deltaY = mousePoint.y - this.clickPoint?.y;
|
|
24275
|
-
|
|
24276
|
-
rectangle.setAttrs({
|
|
24292
|
+
this.tempRectNode.setAttrs({
|
|
24277
24293
|
width: deltaX,
|
|
24278
24294
|
height: deltaY
|
|
24279
24295
|
});
|
|
24280
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
|
|
24281
24296
|
}
|
|
24282
24297
|
}
|
|
24283
24298
|
trigger(cancelAction) {
|
|
@@ -24302,9 +24317,10 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24302
24317
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
24303
24318
|
}
|
|
24304
24319
|
this.rectId = null;
|
|
24305
|
-
this.
|
|
24320
|
+
this.tempRectNode = null;
|
|
24306
24321
|
this.moved = false;
|
|
24307
24322
|
this.container = void 0;
|
|
24323
|
+
this.measureContainer = void 0;
|
|
24308
24324
|
this.clickPoint = null;
|
|
24309
24325
|
this.setState(RECTANGLE_TOOL_STATE.IDLE);
|
|
24310
24326
|
}
|
|
@@ -24540,6 +24556,8 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24540
24556
|
this.state = PEN_TOOL_STATE.IDLE;
|
|
24541
24557
|
this.lineId = null;
|
|
24542
24558
|
this.tempLineId = null;
|
|
24559
|
+
this.tempMainLineNode = null;
|
|
24560
|
+
this.tempLineNode = null;
|
|
24543
24561
|
this.container = void 0;
|
|
24544
24562
|
this.measureContainer = void 0;
|
|
24545
24563
|
this.clickPoint = null;
|
|
@@ -24579,11 +24597,10 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24579
24597
|
this.state = PEN_TOOL_STATE.ADDING;
|
|
24580
24598
|
return;
|
|
24581
24599
|
}
|
|
24582
|
-
if (this.state === PEN_TOOL_STATE.ADDING) this.handleAdding();
|
|
24600
|
+
if (!this.tempMainLineNode && this.state === PEN_TOOL_STATE.ADDING) this.handleAdding();
|
|
24601
|
+
if (this.tempMainLineNode && this.state === PEN_TOOL_STATE.ADDING) this.state = PEN_TOOL_STATE.DEFINING_SIZE;
|
|
24583
24602
|
});
|
|
24584
|
-
stage.on("pointermove", (
|
|
24585
|
-
if (!this.isPressed(e)) return;
|
|
24586
|
-
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
24603
|
+
stage.on("pointermove", () => {
|
|
24587
24604
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
|
|
24588
24605
|
this.state = PEN_TOOL_STATE.ADDING;
|
|
24589
24606
|
return;
|
|
@@ -24602,6 +24619,8 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24602
24619
|
addLine() {
|
|
24603
24620
|
const stage = this.instance.getStage();
|
|
24604
24621
|
stage.container().style.cursor = "crosshair";
|
|
24622
|
+
stage.container().focus();
|
|
24623
|
+
this.instance.emitEvent("onAddingPen");
|
|
24605
24624
|
this.tempPoint = void 0;
|
|
24606
24625
|
this.tempNextPoint = void 0;
|
|
24607
24626
|
this.clickPoint = null;
|
|
@@ -24615,63 +24634,58 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24615
24634
|
this.measureContainer = measureContainer;
|
|
24616
24635
|
this.lineId = v4_default();
|
|
24617
24636
|
this.tempLineId = v4_default();
|
|
24618
|
-
|
|
24619
|
-
|
|
24620
|
-
const node = nodeHandler.create(this.lineId, {
|
|
24637
|
+
if (!this.tempLineNode) {
|
|
24638
|
+
this.tempMainLineNode = new konva.default.Line({
|
|
24621
24639
|
...this.props,
|
|
24640
|
+
id: this.lineId,
|
|
24622
24641
|
strokeScaleEnabled: true,
|
|
24623
24642
|
x: this.clickPoint?.x ?? 0,
|
|
24624
24643
|
y: this.clickPoint?.y ?? 0,
|
|
24625
24644
|
points: [0, 0]
|
|
24626
24645
|
});
|
|
24627
|
-
this.
|
|
24628
|
-
|
|
24629
|
-
|
|
24630
|
-
|
|
24631
|
-
|
|
24632
|
-
|
|
24633
|
-
|
|
24634
|
-
|
|
24635
|
-
|
|
24636
|
-
|
|
24637
|
-
|
|
24638
|
-
|
|
24639
|
-
if (nodeHandler) {
|
|
24640
|
-
const tempLine = nodeHandler.create(this.tempLineId, {
|
|
24646
|
+
this.measureContainer?.add(this.tempMainLineNode);
|
|
24647
|
+
this.tempPoint = new konva.default.Circle({
|
|
24648
|
+
x: this.clickPoint?.x ?? 0,
|
|
24649
|
+
y: this.clickPoint?.y ?? 0,
|
|
24650
|
+
radius: 5 / stage.scaleX(),
|
|
24651
|
+
strokeScaleEnabled: true,
|
|
24652
|
+
stroke: "#cccccc",
|
|
24653
|
+
strokeWidth: 0,
|
|
24654
|
+
fill: "#cccccc"
|
|
24655
|
+
});
|
|
24656
|
+
this.measureContainer?.add(this.tempPoint);
|
|
24657
|
+
this.tempLineNode = new konva.default.Line({
|
|
24641
24658
|
...this.props,
|
|
24659
|
+
id: this.tempLineId,
|
|
24642
24660
|
x: this.clickPoint?.x ?? 0,
|
|
24643
24661
|
y: this.clickPoint?.y ?? 0,
|
|
24644
24662
|
strokeScaleEnabled: true,
|
|
24645
24663
|
points: [0, 0]
|
|
24646
24664
|
});
|
|
24647
|
-
this.
|
|
24665
|
+
this.measureContainer?.add(this.tempLineNode);
|
|
24666
|
+
this.tempNextPoint = new konva.default.Circle({
|
|
24667
|
+
x: this.clickPoint?.x ?? 0,
|
|
24668
|
+
y: this.clickPoint?.y ?? 0,
|
|
24669
|
+
radius: 5 / stage.scaleX(),
|
|
24670
|
+
strokeScaleEnabled: true,
|
|
24671
|
+
stroke: "#cccccc",
|
|
24672
|
+
strokeWidth: 0,
|
|
24673
|
+
fill: "#cccccc"
|
|
24674
|
+
});
|
|
24675
|
+
this.measureContainer?.add(this.tempNextPoint);
|
|
24676
|
+
this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
|
|
24648
24677
|
}
|
|
24649
|
-
this.tempNextPoint = new konva.default.Circle({
|
|
24650
|
-
x: this.clickPoint?.x ?? 0,
|
|
24651
|
-
y: this.clickPoint?.y ?? 0,
|
|
24652
|
-
radius: 5 / stage.scaleX(),
|
|
24653
|
-
strokeScaleEnabled: true,
|
|
24654
|
-
stroke: "#cccccc",
|
|
24655
|
-
strokeWidth: 0,
|
|
24656
|
-
fill: "#cccccc"
|
|
24657
|
-
});
|
|
24658
|
-
this.measureContainer?.add(this.tempNextPoint);
|
|
24659
|
-
this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
|
|
24660
24678
|
}
|
|
24661
24679
|
handleSettingSize() {
|
|
24662
|
-
|
|
24663
|
-
const tempMainLine = this.instance.getStage().findOne(`#${this.lineId}`);
|
|
24664
|
-
if (this.lineId && this.tempPoint && this.tempNextPoint && this.measureContainer && tempMainLine && tempLine) {
|
|
24680
|
+
if (this.lineId && this.tempLineNode && this.tempMainLineNode && this.tempPoint && this.tempNextPoint && this.measureContainer) {
|
|
24665
24681
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
24666
|
-
const newPoints = [...
|
|
24667
|
-
newPoints.push(mousePoint.x -
|
|
24668
|
-
newPoints.push(mousePoint.y -
|
|
24669
|
-
|
|
24682
|
+
const newPoints = [...this.tempMainLineNode.points()];
|
|
24683
|
+
newPoints.push(mousePoint.x - this.tempMainLineNode.x());
|
|
24684
|
+
newPoints.push(mousePoint.y - this.tempMainLineNode.y());
|
|
24685
|
+
this.tempMainLineNode.setAttrs({
|
|
24670
24686
|
...this.props,
|
|
24671
24687
|
points: newPoints
|
|
24672
24688
|
});
|
|
24673
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24674
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
|
|
24675
24689
|
this.tempPoint.setAttrs({
|
|
24676
24690
|
x: mousePoint.x,
|
|
24677
24691
|
y: mousePoint.y
|
|
@@ -24680,32 +24694,28 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24680
24694
|
x: mousePoint.x,
|
|
24681
24695
|
y: mousePoint.y
|
|
24682
24696
|
});
|
|
24683
|
-
|
|
24697
|
+
this.tempLineNode.setAttrs({
|
|
24684
24698
|
...this.props,
|
|
24685
24699
|
x: mousePoint.x,
|
|
24686
24700
|
y: mousePoint.y,
|
|
24687
24701
|
points: [0, 0]
|
|
24688
24702
|
});
|
|
24689
|
-
|
|
24703
|
+
this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
|
|
24690
24704
|
}
|
|
24691
|
-
this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
|
|
24692
24705
|
}
|
|
24693
24706
|
handleMovement() {
|
|
24694
24707
|
if (this.state !== PEN_TOOL_STATE.DEFINING_SIZE) return;
|
|
24695
|
-
|
|
24696
|
-
if (this.lineId && this.measureContainer && this.tempNextPoint && tempLine) {
|
|
24708
|
+
if (this.tempLineNode && this.measureContainer && this.tempNextPoint) {
|
|
24697
24709
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
24698
|
-
|
|
24710
|
+
this.tempLineNode.setAttrs({
|
|
24699
24711
|
...this.props,
|
|
24700
24712
|
points: [
|
|
24701
|
-
|
|
24702
|
-
|
|
24703
|
-
mousePoint.x -
|
|
24704
|
-
mousePoint.y -
|
|
24713
|
+
this.tempLineNode.points()[0],
|
|
24714
|
+
this.tempLineNode.points()[1],
|
|
24715
|
+
mousePoint.x - this.tempLineNode.x(),
|
|
24716
|
+
mousePoint.y - this.tempLineNode.y()
|
|
24705
24717
|
]
|
|
24706
24718
|
});
|
|
24707
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24708
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
|
|
24709
24719
|
this.tempNextPoint.setAttrs({
|
|
24710
24720
|
x: mousePoint.x,
|
|
24711
24721
|
y: mousePoint.y
|
|
@@ -24728,24 +24738,20 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24728
24738
|
const stage = this.instance.getStage();
|
|
24729
24739
|
this.tempPoint?.destroy();
|
|
24730
24740
|
this.tempNextPoint?.destroy();
|
|
24731
|
-
|
|
24732
|
-
|
|
24733
|
-
if (tempLine) {
|
|
24734
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24735
|
-
if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempLine));
|
|
24736
|
-
}
|
|
24737
|
-
if (this.lineId && tempMainLine && tempMainLine.points().length < 4) {
|
|
24738
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24739
|
-
if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainLine));
|
|
24740
|
-
}
|
|
24741
|
-
if (this.lineId && tempMainLine && tempMainLine.points().length >= 4) {
|
|
24741
|
+
this.tempLineNode?.destroy();
|
|
24742
|
+
if (this.lineId && this.tempMainLineNode && this.tempMainLineNode.points().length >= 4) {
|
|
24742
24743
|
const nodeHandler = this.instance.getNodeHandler("line");
|
|
24743
|
-
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
|
|
24747
|
-
|
|
24748
|
-
|
|
24744
|
+
if (nodeHandler) {
|
|
24745
|
+
const clonedLine = this.tempMainLineNode.clone();
|
|
24746
|
+
this.tempMainLineNode.destroy();
|
|
24747
|
+
const node = nodeHandler.create(this.lineId, {
|
|
24748
|
+
...this.props,
|
|
24749
|
+
...clonedLine.getAttrs(),
|
|
24750
|
+
hitStrokeWidth: 16
|
|
24751
|
+
});
|
|
24752
|
+
this.instance.addNode(node, this.container?.getAttrs().id);
|
|
24753
|
+
this.instance.emitEvent("onAddedPen");
|
|
24754
|
+
}
|
|
24749
24755
|
}
|
|
24750
24756
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
24751
24757
|
if (selectionPlugin) {
|
|
@@ -24758,8 +24764,11 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24758
24764
|
this.tempPoint = void 0;
|
|
24759
24765
|
this.tempNextPoint = void 0;
|
|
24760
24766
|
this.lineId = null;
|
|
24767
|
+
this.tempMainLineNode = null;
|
|
24761
24768
|
this.tempLineId = null;
|
|
24769
|
+
this.tempLineNode = null;
|
|
24762
24770
|
this.container = void 0;
|
|
24771
|
+
this.measureContainer = void 0;
|
|
24763
24772
|
this.clickPoint = null;
|
|
24764
24773
|
this.setState(PEN_TOOL_STATE.IDLE);
|
|
24765
24774
|
}
|
|
@@ -24962,11 +24971,13 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
24962
24971
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
24963
24972
|
this.props = this.initProps();
|
|
24964
24973
|
this.setState(BRUSH_TOOL_STATE.IDLE);
|
|
24974
|
+
this.instance.emitEvent("onAddingBrush");
|
|
24965
24975
|
stage.container().style.cursor = "crosshair";
|
|
24966
24976
|
}
|
|
24967
24977
|
cleanup() {
|
|
24968
24978
|
const stage = this.instance.getStage();
|
|
24969
24979
|
stage.container().style.cursor = "default";
|
|
24980
|
+
this.instance.emitEvent("onAddedBrush");
|
|
24970
24981
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
24971
24982
|
if (selectionPlugin) {
|
|
24972
24983
|
const node = stage.findOne(`#${this.strokeId}`);
|
|
@@ -25037,6 +25048,8 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
25037
25048
|
tr.hide();
|
|
25038
25049
|
}
|
|
25039
25050
|
stage.container().style.cursor = "crosshair";
|
|
25051
|
+
stage.container().focus();
|
|
25052
|
+
this.instance.emitEvent("onAddingText");
|
|
25040
25053
|
this.clickPoint = null;
|
|
25041
25054
|
this.setState(TEXT_TOOL_STATE.ADDING);
|
|
25042
25055
|
}
|
|
@@ -25054,6 +25067,7 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
25054
25067
|
draggable: true
|
|
25055
25068
|
});
|
|
25056
25069
|
this.instance.addNode(node, this.container?.getAttrs().id);
|
|
25070
|
+
this.instance.emitEvent("onAddedArrow");
|
|
25057
25071
|
}
|
|
25058
25072
|
this.setState(TEXT_TOOL_STATE.FINISHED);
|
|
25059
25073
|
this.cancelAction();
|
|
@@ -25313,10 +25327,13 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25313
25327
|
onInit = void 0;
|
|
25314
25328
|
constructor() {
|
|
25315
25329
|
super();
|
|
25330
|
+
this.pointers = new Map();
|
|
25316
25331
|
this.initialized = false;
|
|
25317
25332
|
this.state = ARROW_TOOL_STATE.IDLE;
|
|
25318
25333
|
this.arrowId = null;
|
|
25319
25334
|
this.tempArrowId = null;
|
|
25335
|
+
this.tempMainArrowNode = null;
|
|
25336
|
+
this.tempArrowNode = null;
|
|
25320
25337
|
this.container = void 0;
|
|
25321
25338
|
this.measureContainer = void 0;
|
|
25322
25339
|
this.clickPoint = null;
|
|
@@ -25351,22 +25368,29 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25351
25368
|
return;
|
|
25352
25369
|
}
|
|
25353
25370
|
});
|
|
25354
|
-
stage.on("
|
|
25355
|
-
this.
|
|
25356
|
-
|
|
25357
|
-
|
|
25358
|
-
|
|
25359
|
-
|
|
25360
|
-
|
|
25371
|
+
stage.on("pointerdown", (e) => {
|
|
25372
|
+
this.setTapStart(e);
|
|
25373
|
+
this.pointers.set(e.evt.pointerId, {
|
|
25374
|
+
x: e.evt.clientX,
|
|
25375
|
+
y: e.evt.clientY
|
|
25376
|
+
});
|
|
25377
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
|
|
25378
|
+
this.state = ARROW_TOOL_STATE.ADDING;
|
|
25361
25379
|
return;
|
|
25362
25380
|
}
|
|
25363
|
-
if (this.state === ARROW_TOOL_STATE.
|
|
25364
|
-
|
|
25381
|
+
if (!this.tempMainArrowNode && this.state === ARROW_TOOL_STATE.ADDING) this.handleAdding();
|
|
25382
|
+
if (this.tempMainArrowNode && this.state === ARROW_TOOL_STATE.ADDING) this.state = ARROW_TOOL_STATE.DEFINING_SIZE;
|
|
25383
|
+
});
|
|
25384
|
+
stage.on("pointermove", () => {
|
|
25385
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
|
|
25386
|
+
this.state = ARROW_TOOL_STATE.ADDING;
|
|
25365
25387
|
return;
|
|
25366
25388
|
}
|
|
25389
|
+
if (this.state === ARROW_TOOL_STATE.DEFINING_SIZE) this.handleMovement();
|
|
25367
25390
|
});
|
|
25368
|
-
stage.on("
|
|
25369
|
-
this.
|
|
25391
|
+
stage.on("pointerup", (e) => {
|
|
25392
|
+
this.pointers.delete(e.evt.pointerId);
|
|
25393
|
+
if (this.state === ARROW_TOOL_STATE.DEFINING_SIZE) this.handleSettingSize();
|
|
25370
25394
|
});
|
|
25371
25395
|
this.initialized = true;
|
|
25372
25396
|
}
|
|
@@ -25376,6 +25400,8 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25376
25400
|
addArrow() {
|
|
25377
25401
|
const stage = this.instance.getStage();
|
|
25378
25402
|
stage.container().style.cursor = "crosshair";
|
|
25403
|
+
stage.container().focus();
|
|
25404
|
+
this.instance.emitEvent("onAddingArrow");
|
|
25379
25405
|
this.tempPoint = void 0;
|
|
25380
25406
|
this.tempNextPoint = void 0;
|
|
25381
25407
|
this.clickPoint = null;
|
|
@@ -25389,65 +25415,58 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25389
25415
|
this.measureContainer = measureContainer;
|
|
25390
25416
|
this.arrowId = v4_default();
|
|
25391
25417
|
this.tempArrowId = v4_default();
|
|
25392
|
-
|
|
25393
|
-
|
|
25394
|
-
if (lineNodeHandler) {
|
|
25395
|
-
const node = lineNodeHandler.create(this.arrowId, {
|
|
25418
|
+
if (!this.tempMainArrowNode) {
|
|
25419
|
+
this.tempMainArrowNode = new konva.default.Line({
|
|
25396
25420
|
...this.props,
|
|
25421
|
+
id: this.arrowId,
|
|
25397
25422
|
strokeScaleEnabled: true,
|
|
25398
25423
|
x: this.clickPoint?.x ?? 0,
|
|
25399
25424
|
y: this.clickPoint?.y ?? 0,
|
|
25400
25425
|
points: [0, 0]
|
|
25401
25426
|
});
|
|
25402
|
-
this.
|
|
25403
|
-
|
|
25404
|
-
this.tempPoint = new konva.default.Circle({
|
|
25405
|
-
x: this.clickPoint?.x ?? 0,
|
|
25406
|
-
y: this.clickPoint?.y ?? 0,
|
|
25407
|
-
radius: 5 / stage.scaleX(),
|
|
25408
|
-
strokeScaleEnabled: true,
|
|
25409
|
-
stroke: "#cccccc",
|
|
25410
|
-
strokeWidth: 0,
|
|
25411
|
-
fill: "#cccccc"
|
|
25412
|
-
});
|
|
25413
|
-
this.measureContainer?.add(this.tempPoint);
|
|
25414
|
-
if (nodeHandler) {
|
|
25415
|
-
const tempArrow = nodeHandler.create(this.tempArrowId, {
|
|
25416
|
-
...this.props,
|
|
25427
|
+
this.measureContainer?.add(this.tempMainArrowNode);
|
|
25428
|
+
this.tempPoint = new konva.default.Circle({
|
|
25417
25429
|
x: this.clickPoint?.x ?? 0,
|
|
25418
25430
|
y: this.clickPoint?.y ?? 0,
|
|
25431
|
+
radius: 5 / stage.scaleX(),
|
|
25419
25432
|
strokeScaleEnabled: true,
|
|
25433
|
+
stroke: "#cccccc",
|
|
25434
|
+
strokeWidth: 0,
|
|
25435
|
+
fill: "#cccccc"
|
|
25436
|
+
});
|
|
25437
|
+
this.measureContainer?.add(this.tempPoint);
|
|
25438
|
+
this.tempArrowNode = new konva.default.Arrow({
|
|
25439
|
+
...this.props,
|
|
25440
|
+
id: this.tempArrowId,
|
|
25441
|
+
strokeScaleEnabled: true,
|
|
25442
|
+
x: this.clickPoint?.x ?? 0,
|
|
25443
|
+
y: this.clickPoint?.y ?? 0,
|
|
25420
25444
|
points: [0, 0]
|
|
25421
25445
|
});
|
|
25422
|
-
this.
|
|
25446
|
+
this.measureContainer?.add(this.tempArrowNode);
|
|
25447
|
+
this.tempNextPoint = new konva.default.Circle({
|
|
25448
|
+
x: this.clickPoint?.x ?? 0,
|
|
25449
|
+
y: this.clickPoint?.y ?? 0,
|
|
25450
|
+
radius: 5 / stage.scaleX(),
|
|
25451
|
+
strokeScaleEnabled: true,
|
|
25452
|
+
stroke: "#cccccc",
|
|
25453
|
+
strokeWidth: 0,
|
|
25454
|
+
fill: "#cccccc"
|
|
25455
|
+
});
|
|
25456
|
+
this.measureContainer?.add(this.tempNextPoint);
|
|
25457
|
+
this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
|
|
25423
25458
|
}
|
|
25424
|
-
this.tempNextPoint = new konva.default.Circle({
|
|
25425
|
-
x: this.clickPoint?.x ?? 0,
|
|
25426
|
-
y: this.clickPoint?.y ?? 0,
|
|
25427
|
-
radius: 5 / stage.scaleX(),
|
|
25428
|
-
strokeScaleEnabled: true,
|
|
25429
|
-
stroke: "#cccccc",
|
|
25430
|
-
strokeWidth: 0,
|
|
25431
|
-
fill: "#cccccc"
|
|
25432
|
-
});
|
|
25433
|
-
this.measureContainer?.add(this.tempNextPoint);
|
|
25434
|
-
this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
|
|
25435
25459
|
}
|
|
25436
25460
|
handleSettingSize() {
|
|
25437
|
-
|
|
25438
|
-
const tempMainArrow = this.instance.getStage().findOne(`#${this.arrowId}`);
|
|
25439
|
-
if (this.arrowId && this.tempPoint && this.tempNextPoint && this.measureContainer && tempMainArrow && tempArrow) {
|
|
25461
|
+
if (this.arrowId && this.tempMainArrowNode && this.tempArrowNode && this.tempPoint && this.tempNextPoint && this.measureContainer) {
|
|
25440
25462
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
25441
|
-
const newPoints = [...
|
|
25442
|
-
newPoints.push(mousePoint.x -
|
|
25443
|
-
newPoints.push(mousePoint.y -
|
|
25444
|
-
|
|
25463
|
+
const newPoints = [...this.tempMainArrowNode.points()];
|
|
25464
|
+
newPoints.push(mousePoint.x - this.tempMainArrowNode.x());
|
|
25465
|
+
newPoints.push(mousePoint.y - this.tempMainArrowNode.y());
|
|
25466
|
+
this.tempMainArrowNode.setAttrs({
|
|
25445
25467
|
...this.props,
|
|
25446
25468
|
points: newPoints
|
|
25447
25469
|
});
|
|
25448
|
-
const nodeHandler = this.instance.getNodeHandler("arrow");
|
|
25449
|
-
const lineNodeHandler = this.instance.getNodeHandler("line");
|
|
25450
|
-
if (lineNodeHandler) this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
|
|
25451
25470
|
this.tempPoint.setAttrs({
|
|
25452
25471
|
x: mousePoint.x,
|
|
25453
25472
|
y: mousePoint.y
|
|
@@ -25456,32 +25475,28 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25456
25475
|
x: mousePoint.x,
|
|
25457
25476
|
y: mousePoint.y
|
|
25458
25477
|
});
|
|
25459
|
-
|
|
25478
|
+
this.tempArrowNode.setAttrs({
|
|
25460
25479
|
...this.props,
|
|
25461
25480
|
x: mousePoint.x,
|
|
25462
25481
|
y: mousePoint.y,
|
|
25463
25482
|
points: [0, 0]
|
|
25464
25483
|
});
|
|
25465
|
-
|
|
25484
|
+
this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
|
|
25466
25485
|
}
|
|
25467
|
-
this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
|
|
25468
25486
|
}
|
|
25469
25487
|
handleMovement() {
|
|
25470
25488
|
if (this.state !== ARROW_TOOL_STATE.DEFINING_SIZE) return;
|
|
25471
|
-
|
|
25472
|
-
if (this.arrowId && this.measureContainer && this.tempNextPoint && tempArrow) {
|
|
25489
|
+
if (this.arrowId && this.tempArrowNode && this.measureContainer && this.tempNextPoint) {
|
|
25473
25490
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
25474
|
-
|
|
25491
|
+
this.tempArrowNode.setAttrs({
|
|
25475
25492
|
...this.props,
|
|
25476
25493
|
points: [
|
|
25477
|
-
|
|
25478
|
-
|
|
25479
|
-
mousePoint.x -
|
|
25480
|
-
mousePoint.y -
|
|
25494
|
+
this.tempArrowNode.points()[0],
|
|
25495
|
+
this.tempArrowNode.points()[1],
|
|
25496
|
+
mousePoint.x - this.tempArrowNode.x(),
|
|
25497
|
+
mousePoint.y - this.tempArrowNode.y()
|
|
25481
25498
|
]
|
|
25482
25499
|
});
|
|
25483
|
-
const nodeHandler = this.instance.getNodeHandler("arrow");
|
|
25484
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
|
|
25485
25500
|
this.tempNextPoint.setAttrs({
|
|
25486
25501
|
x: mousePoint.x,
|
|
25487
25502
|
y: mousePoint.y
|
|
@@ -25504,29 +25519,19 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25504
25519
|
const stage = this.instance.getStage();
|
|
25505
25520
|
this.tempPoint?.destroy();
|
|
25506
25521
|
this.tempNextPoint?.destroy();
|
|
25507
|
-
|
|
25508
|
-
|
|
25509
|
-
if (tempArrow) {
|
|
25522
|
+
this.tempArrowNode?.destroy();
|
|
25523
|
+
if (this.arrowId && this.tempMainArrowNode && this.tempMainArrowNode.points().length >= 4) {
|
|
25510
25524
|
const nodeHandler = this.instance.getNodeHandler("arrow");
|
|
25511
|
-
if (nodeHandler)
|
|
25512
|
-
|
|
25513
|
-
|
|
25514
|
-
const nodeHandler = this.instance.getNodeHandler("line");
|
|
25515
|
-
if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
|
|
25516
|
-
}
|
|
25517
|
-
if (this.arrowId && tempMainArrow && tempMainArrow.points().length >= 4) {
|
|
25518
|
-
const nodeHandler = this.instance.getNodeHandler("arrow");
|
|
25519
|
-
const lineNodeHandler = this.instance.getNodeHandler("line");
|
|
25520
|
-
if (nodeHandler && lineNodeHandler) {
|
|
25525
|
+
if (nodeHandler) {
|
|
25526
|
+
const clonedLine = this.tempMainArrowNode.clone();
|
|
25527
|
+
this.tempMainArrowNode.destroy();
|
|
25521
25528
|
const finalArrow = nodeHandler.create(this.arrowId, {
|
|
25522
|
-
...tempMainArrow.getAttrs(),
|
|
25523
25529
|
...this.props,
|
|
25524
|
-
|
|
25525
|
-
strokeWidth: 1,
|
|
25530
|
+
...clonedLine.getAttrs(),
|
|
25526
25531
|
hitStrokeWidth: 16
|
|
25527
25532
|
});
|
|
25528
|
-
this.instance.removeNode(lineNodeHandler.serialize(tempMainArrow));
|
|
25529
25533
|
this.instance.addNode(finalArrow, this.container?.getAttrs().id);
|
|
25534
|
+
this.instance.emitEvent("onAddedArrow");
|
|
25530
25535
|
}
|
|
25531
25536
|
}
|
|
25532
25537
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
@@ -25541,7 +25546,10 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
25541
25546
|
this.tempNextPoint = void 0;
|
|
25542
25547
|
this.arrowId = null;
|
|
25543
25548
|
this.tempArrowId = null;
|
|
25549
|
+
this.tempMainArrowNode = null;
|
|
25550
|
+
this.tempArrowNode = null;
|
|
25544
25551
|
this.container = void 0;
|
|
25552
|
+
this.measureContainer = void 0;
|
|
25545
25553
|
this.clickPoint = null;
|
|
25546
25554
|
this.setState(ARROW_TOOL_STATE.IDLE);
|
|
25547
25555
|
}
|
|
@@ -25803,6 +25811,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
25803
25811
|
const stage = this.instance.getStage();
|
|
25804
25812
|
stage.container().style.cursor = "crosshair";
|
|
25805
25813
|
stage.container().focus();
|
|
25814
|
+
this.instance.emitEvent("onAddingFrame");
|
|
25806
25815
|
this.frameId = null;
|
|
25807
25816
|
this.clickPoint = null;
|
|
25808
25817
|
this.setState(FRAME_TOOL_STATE.ADDING);
|
|
@@ -25824,6 +25833,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
25824
25833
|
y: this.clickPoint.y
|
|
25825
25834
|
});
|
|
25826
25835
|
this.instance.addNode(node, this.container?.getAttrs().id);
|
|
25836
|
+
this.instance.emitEvent("onAddedFrame");
|
|
25827
25837
|
}
|
|
25828
25838
|
this.cancelAction?.();
|
|
25829
25839
|
}
|