@inditextech/weave-sdk 0.58.0 → 0.60.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 +1278 -75
- package/dist/sdk.d.cts +392 -13
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +392 -13
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1264 -75
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -18256,13 +18256,6 @@ function getVisibleNodesInViewport(stage, referenceLayer) {
|
|
|
18256
18256
|
});
|
|
18257
18257
|
return visibleNodes;
|
|
18258
18258
|
}
|
|
18259
|
-
function getClosestParentWithId(el) {
|
|
18260
|
-
while (el) {
|
|
18261
|
-
if (el.id) return el;
|
|
18262
|
-
el = el.parentElement;
|
|
18263
|
-
}
|
|
18264
|
-
return null;
|
|
18265
|
-
}
|
|
18266
18259
|
function isInShadowDOM(el) {
|
|
18267
18260
|
return el?.getRootNode() instanceof ShadowRoot;
|
|
18268
18261
|
}
|
|
@@ -20334,7 +20327,6 @@ var WeaveNode = class {
|
|
|
20334
20327
|
}
|
|
20335
20328
|
});
|
|
20336
20329
|
node.on("pointerover", (e) => {
|
|
20337
|
-
e.cancelBubble = true;
|
|
20338
20330
|
const stage = this.instance.getStage();
|
|
20339
20331
|
const activeAction = this.instance.getActiveAction();
|
|
20340
20332
|
const isNodeSelectionEnabled = this.getSelectionPlugin()?.isEnabled();
|
|
@@ -20345,16 +20337,22 @@ var WeaveNode = class {
|
|
|
20345
20337
|
if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isLocked$1) {
|
|
20346
20338
|
const stage$1 = this.instance.getStage();
|
|
20347
20339
|
stage$1.container().style.cursor = "default";
|
|
20340
|
+
e.cancelBubble = true;
|
|
20348
20341
|
}
|
|
20349
20342
|
if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !isLocked$1 && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
|
|
20350
20343
|
const stage$1 = this.instance.getStage();
|
|
20351
20344
|
stage$1.container().style.cursor = "pointer";
|
|
20352
20345
|
this.setHoverState(realNode);
|
|
20346
|
+
e.cancelBubble = true;
|
|
20347
|
+
}
|
|
20348
|
+
if (!isTargetable) {
|
|
20349
|
+
this.hideHoverState();
|
|
20350
|
+
e.cancelBubble = true;
|
|
20353
20351
|
}
|
|
20354
|
-
if (!isTargetable) this.hideHoverState();
|
|
20355
20352
|
if (this.isPasting()) {
|
|
20356
20353
|
const stage$1 = this.instance.getStage();
|
|
20357
20354
|
stage$1.container().style.cursor = "crosshair";
|
|
20355
|
+
e.cancelBubble = true;
|
|
20358
20356
|
}
|
|
20359
20357
|
});
|
|
20360
20358
|
}
|
|
@@ -22023,7 +22021,7 @@ var WeaveRegisterManager = class {
|
|
|
22023
22021
|
|
|
22024
22022
|
//#endregion
|
|
22025
22023
|
//#region package.json
|
|
22026
|
-
var version = "0.
|
|
22024
|
+
var version = "0.60.0";
|
|
22027
22025
|
|
|
22028
22026
|
//#endregion
|
|
22029
22027
|
//#region src/managers/setup.ts
|
|
@@ -22559,6 +22557,17 @@ var Weave = class {
|
|
|
22559
22557
|
getContainerNodes() {
|
|
22560
22558
|
return this.stageManager.getContainerNodes();
|
|
22561
22559
|
}
|
|
22560
|
+
getClosestParentWithWeaveId(el) {
|
|
22561
|
+
const weaveContainer = this.getStageConfiguration().container;
|
|
22562
|
+
let weaveId = void 0;
|
|
22563
|
+
if (weaveContainer instanceof HTMLElement) weaveId = weaveContainer.id;
|
|
22564
|
+
if (typeof weaveContainer === "string") weaveId = weaveContainer;
|
|
22565
|
+
while (el) {
|
|
22566
|
+
if (el.id && el.id === weaveId) return el;
|
|
22567
|
+
el = el.parentElement;
|
|
22568
|
+
}
|
|
22569
|
+
return null;
|
|
22570
|
+
}
|
|
22562
22571
|
getRegisterManager() {
|
|
22563
22572
|
return this.registerManager;
|
|
22564
22573
|
}
|
|
@@ -23728,15 +23737,17 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23728
23737
|
const position = this.instance.getStage().getRelativePointerPosition();
|
|
23729
23738
|
this.instance.triggerAction(IMAGE_TOOL_ACTION_NAME, {
|
|
23730
23739
|
imageURL: window.weaveDragImageURL,
|
|
23740
|
+
imageId: window.weaveDragImageId,
|
|
23731
23741
|
position
|
|
23732
23742
|
});
|
|
23733
23743
|
window.weaveDragImageURL = void 0;
|
|
23744
|
+
window.weaveDragImageId = void 0;
|
|
23734
23745
|
}
|
|
23735
23746
|
});
|
|
23736
23747
|
}
|
|
23737
23748
|
setupEvents() {
|
|
23738
23749
|
const stage = this.instance.getStage();
|
|
23739
|
-
|
|
23750
|
+
window.addEventListener("keydown", (e) => {
|
|
23740
23751
|
if (e.key === "Escape" && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME) {
|
|
23741
23752
|
this.cancelAction();
|
|
23742
23753
|
return;
|
|
@@ -23755,13 +23766,13 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23755
23766
|
if (this.state === IMAGE_TOOL_STATE.DEFINING_POSITION) this.state = IMAGE_TOOL_STATE.SELECTED_POSITION;
|
|
23756
23767
|
});
|
|
23757
23768
|
stage.on("pointermove", (e) => {
|
|
23769
|
+
if (this.state === IMAGE_TOOL_STATE.IDLE) return;
|
|
23770
|
+
this.setCursor();
|
|
23758
23771
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME) {
|
|
23759
23772
|
this.state = IMAGE_TOOL_STATE.DEFINING_POSITION;
|
|
23760
23773
|
return;
|
|
23761
23774
|
}
|
|
23762
23775
|
if ([IMAGE_TOOL_STATE.DEFINING_POSITION, IMAGE_TOOL_STATE.SELECTED_POSITION].includes(this.state) && this.tempImageNode && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME && e.evt.pointerType === "mouse") {
|
|
23763
|
-
stage.container().style.cursor = "crosshair";
|
|
23764
|
-
stage.container().focus();
|
|
23765
23776
|
const mousePos = stage.getRelativePointerPosition();
|
|
23766
23777
|
this.tempImageNode.setAttrs({
|
|
23767
23778
|
x: (mousePos?.x ?? 0) + this.cursorPadding,
|
|
@@ -23779,13 +23790,12 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23779
23790
|
this.state = state;
|
|
23780
23791
|
}
|
|
23781
23792
|
loadImage(imageURL, options, position) {
|
|
23782
|
-
const stage = this.instance.getStage();
|
|
23783
23793
|
const imageOptions = {
|
|
23784
23794
|
crossOrigin: "anonymous",
|
|
23785
23795
|
...options
|
|
23786
23796
|
};
|
|
23787
|
-
|
|
23788
|
-
|
|
23797
|
+
this.setCursor();
|
|
23798
|
+
this.setFocusStage();
|
|
23789
23799
|
this.imageId = v4_default();
|
|
23790
23800
|
this.imageURL = imageURL;
|
|
23791
23801
|
this.preloadImgs[this.imageId] = new Image();
|
|
@@ -23812,8 +23822,8 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23812
23822
|
}
|
|
23813
23823
|
addImageNode(position) {
|
|
23814
23824
|
const stage = this.instance.getStage();
|
|
23815
|
-
|
|
23816
|
-
|
|
23825
|
+
this.setCursor();
|
|
23826
|
+
this.setFocusStage();
|
|
23817
23827
|
if (position) {
|
|
23818
23828
|
this.setState(IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
23819
23829
|
this.handleAdding(position);
|
|
@@ -23890,6 +23900,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23890
23900
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23891
23901
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
23892
23902
|
this.forceMainContainer = params?.forceMainContainer ?? false;
|
|
23903
|
+
if (params?.imageId) this.updateProps({ imageId: params.imageId });
|
|
23893
23904
|
if (params?.imageURL) {
|
|
23894
23905
|
this.loadImage(params.imageURL, params?.options ?? void 0, params?.position ?? void 0);
|
|
23895
23906
|
return;
|
|
@@ -23918,6 +23929,16 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23918
23929
|
this.clickPoint = null;
|
|
23919
23930
|
this.setState(IMAGE_TOOL_STATE.IDLE);
|
|
23920
23931
|
}
|
|
23932
|
+
setCursor() {
|
|
23933
|
+
const stage = this.instance.getStage();
|
|
23934
|
+
stage.container().style.cursor = "crosshair";
|
|
23935
|
+
}
|
|
23936
|
+
setFocusStage() {
|
|
23937
|
+
const stage = this.instance.getStage();
|
|
23938
|
+
stage.container().tabIndex = 1;
|
|
23939
|
+
stage.container().blur();
|
|
23940
|
+
stage.container().focus();
|
|
23941
|
+
}
|
|
23921
23942
|
};
|
|
23922
23943
|
|
|
23923
23944
|
//#endregion
|
|
@@ -24276,6 +24297,7 @@ const WEAVE_IMAGE_CROP_END_TYPE = {
|
|
|
24276
24297
|
["ACCEPT"]: "accept",
|
|
24277
24298
|
["CANCEL"]: "cancel"
|
|
24278
24299
|
};
|
|
24300
|
+
const WEAVE_IMAGE_DEFAULT_CONFIG = { crossOrigin: "anonymous" };
|
|
24279
24301
|
|
|
24280
24302
|
//#endregion
|
|
24281
24303
|
//#region src/nodes/image/image.ts
|
|
@@ -24290,16 +24312,15 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
24290
24312
|
time: 0
|
|
24291
24313
|
};
|
|
24292
24314
|
this.lastTapTime = 0;
|
|
24293
|
-
this.config =
|
|
24294
|
-
crossOrigin: config?.crossOrigin ?? "anonymous",
|
|
24295
|
-
transform: { ...config?.transform }
|
|
24296
|
-
};
|
|
24315
|
+
this.config = (0, import_lodash.merge)(WEAVE_IMAGE_DEFAULT_CONFIG, config);
|
|
24297
24316
|
this.imageCrop = null;
|
|
24298
24317
|
this.cachedCropInfo = {};
|
|
24299
24318
|
this.imageLoaded = false;
|
|
24300
24319
|
}
|
|
24301
24320
|
triggerCrop(imageNode) {
|
|
24302
24321
|
const stage = this.instance.getStage();
|
|
24322
|
+
if (imageNode.getAttrs().cropping ?? false) return;
|
|
24323
|
+
if (!(this.isSelecting() && this.isNodeSelected(imageNode))) return;
|
|
24303
24324
|
stage.mode("cropping");
|
|
24304
24325
|
const image = stage.findOne(`#${imageNode.getAttrs().id}`);
|
|
24305
24326
|
const internalImage = image?.findOne(`#${image.getAttrs().id}-image`);
|
|
@@ -24431,10 +24452,7 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
24431
24452
|
image.add(cropGroup);
|
|
24432
24453
|
this.setupDefaultNodeEvents(image);
|
|
24433
24454
|
image.dblClick = () => {
|
|
24434
|
-
|
|
24435
|
-
if (!internalImage.getAttr("image")) return;
|
|
24436
|
-
if (!(this.isSelecting() && this.isNodeSelected(image))) return;
|
|
24437
|
-
this.triggerCrop(image);
|
|
24455
|
+
this.config.onDblClick?.(this, image);
|
|
24438
24456
|
};
|
|
24439
24457
|
const imageActionTool = this.getImageToolAction();
|
|
24440
24458
|
const preloadImg = imageActionTool.getPreloadedImage(imageProps.id);
|
|
@@ -25406,6 +25424,706 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
25406
25424
|
}
|
|
25407
25425
|
};
|
|
25408
25426
|
|
|
25427
|
+
//#endregion
|
|
25428
|
+
//#region src/nodes/comment/constants.ts
|
|
25429
|
+
const WEAVE_COMMENT_STATUS = {
|
|
25430
|
+
PENDING: "pending",
|
|
25431
|
+
RESOLVED: "resolved"
|
|
25432
|
+
};
|
|
25433
|
+
const WEAVE_COMMENT_CREATE_ACTION = {
|
|
25434
|
+
CREATE: "create",
|
|
25435
|
+
CLOSE: "close"
|
|
25436
|
+
};
|
|
25437
|
+
const WEAVE_COMMENT_VIEW_ACTION = {
|
|
25438
|
+
REPLY: "reply",
|
|
25439
|
+
MARK_RESOLVED: "markResolved",
|
|
25440
|
+
EDIT: "edit",
|
|
25441
|
+
DELETE: "delete",
|
|
25442
|
+
CLOSE: "close"
|
|
25443
|
+
};
|
|
25444
|
+
const WEAVE_COMMENT_NODE_ACTION = {
|
|
25445
|
+
IDLE: "idle",
|
|
25446
|
+
CREATING: "creating",
|
|
25447
|
+
VIEWING: "viewing"
|
|
25448
|
+
};
|
|
25449
|
+
const WEAVE_COMMENT_NODE_TYPE = "comment";
|
|
25450
|
+
const WEAVE_COMMENT_NODE_DEFAULTS = {
|
|
25451
|
+
style: {
|
|
25452
|
+
stroke: "#000000",
|
|
25453
|
+
strokeWidth: 0,
|
|
25454
|
+
shadowColor: "rgba(0,0,0,0.25)",
|
|
25455
|
+
shadowBlur: 4,
|
|
25456
|
+
shadowOffsetX: 0,
|
|
25457
|
+
shadowOffsetY: 0,
|
|
25458
|
+
shadowOpacity: .8,
|
|
25459
|
+
contracted: {
|
|
25460
|
+
width: 40,
|
|
25461
|
+
height: 40,
|
|
25462
|
+
circlePadding: 2,
|
|
25463
|
+
userName: {
|
|
25464
|
+
fontFamily: "arial, sans-serif",
|
|
25465
|
+
fontSize: 14,
|
|
25466
|
+
fontStyle: "normal"
|
|
25467
|
+
}
|
|
25468
|
+
},
|
|
25469
|
+
expanded: {
|
|
25470
|
+
width: 250,
|
|
25471
|
+
userNameLeftMargin: 8,
|
|
25472
|
+
dateLeftMargin: 8,
|
|
25473
|
+
contentTopMargin: 8,
|
|
25474
|
+
contentBottomMargin: 12,
|
|
25475
|
+
userName: {
|
|
25476
|
+
fontFamily: "arial, sans-serif",
|
|
25477
|
+
fontSize: 12,
|
|
25478
|
+
fontStyle: "bold",
|
|
25479
|
+
color: "#000000"
|
|
25480
|
+
},
|
|
25481
|
+
date: {
|
|
25482
|
+
fontFamily: "arial, sans-serif",
|
|
25483
|
+
fontSize: 12,
|
|
25484
|
+
fontStyle: "normal",
|
|
25485
|
+
color: "#757575"
|
|
25486
|
+
},
|
|
25487
|
+
content: {
|
|
25488
|
+
fontFamily: "arial, sans-serif",
|
|
25489
|
+
fontSize: 12,
|
|
25490
|
+
maxLines: 3,
|
|
25491
|
+
fontStyle: "normal",
|
|
25492
|
+
color: "#000000"
|
|
25493
|
+
}
|
|
25494
|
+
},
|
|
25495
|
+
creating: {
|
|
25496
|
+
paddingX: 8,
|
|
25497
|
+
paddingY: -4,
|
|
25498
|
+
stroke: "#1a1aff",
|
|
25499
|
+
strokeWidth: 2
|
|
25500
|
+
},
|
|
25501
|
+
viewing: {
|
|
25502
|
+
paddingX: 8,
|
|
25503
|
+
paddingY: -18,
|
|
25504
|
+
stroke: "#1a1aff",
|
|
25505
|
+
strokeWidth: 2
|
|
25506
|
+
}
|
|
25507
|
+
},
|
|
25508
|
+
formatDate: (date) => date
|
|
25509
|
+
};
|
|
25510
|
+
|
|
25511
|
+
//#endregion
|
|
25512
|
+
//#region src/nodes/comment/text-max-lines.ts
|
|
25513
|
+
var TextWithMaxLines = class extends konva.default.Text {
|
|
25514
|
+
constructor(config) {
|
|
25515
|
+
super(config);
|
|
25516
|
+
this._maxLines = config.maxLines;
|
|
25517
|
+
this._fullText = config.text?.toString() ?? "";
|
|
25518
|
+
this.on("textChange widthChange fontSizeChange fontFamilyChange fontStyleChange paddingChange alignChange letterSpacingChange lineHeightChange wrapChange", () => this._applyTruncation());
|
|
25519
|
+
this._applyTruncation();
|
|
25520
|
+
}
|
|
25521
|
+
get maxLines() {
|
|
25522
|
+
return this._maxLines;
|
|
25523
|
+
}
|
|
25524
|
+
set maxLines(v) {
|
|
25525
|
+
this._maxLines = v;
|
|
25526
|
+
this._applyTruncation();
|
|
25527
|
+
}
|
|
25528
|
+
setText(text) {
|
|
25529
|
+
if (typeof text === "undefined") return this;
|
|
25530
|
+
this._fullText = text ?? "";
|
|
25531
|
+
super.setText(this._fullText);
|
|
25532
|
+
this._applyTruncation();
|
|
25533
|
+
return this;
|
|
25534
|
+
}
|
|
25535
|
+
_applyTruncation() {
|
|
25536
|
+
if (!this._maxLines || this._maxLines <= 0) {
|
|
25537
|
+
super.setText(this._fullText);
|
|
25538
|
+
return;
|
|
25539
|
+
}
|
|
25540
|
+
super.setText(this._fullText);
|
|
25541
|
+
const selfAny = this;
|
|
25542
|
+
if (typeof selfAny._setTextData === "function") selfAny._setTextData();
|
|
25543
|
+
let textArr = selfAny.textArr || [];
|
|
25544
|
+
if (textArr.length > this._maxLines) {
|
|
25545
|
+
const visible = textArr.slice(0, this._maxLines).map((l) => l.text);
|
|
25546
|
+
const candidate = visible[visible.length - 1] + "…";
|
|
25547
|
+
super.setText([...visible.slice(0, -1), candidate].join("\n"));
|
|
25548
|
+
if (typeof selfAny._setTextData === "function") selfAny._setTextData();
|
|
25549
|
+
textArr = selfAny.textArr || [];
|
|
25550
|
+
}
|
|
25551
|
+
const lines = textArr.length;
|
|
25552
|
+
const fontSize = this.fontSize();
|
|
25553
|
+
const lineHeight = this.lineHeight() || 1;
|
|
25554
|
+
this.height(fontSize * lineHeight * lines);
|
|
25555
|
+
}
|
|
25556
|
+
};
|
|
25557
|
+
|
|
25558
|
+
//#endregion
|
|
25559
|
+
//#region src/nodes/comment/comment.ts
|
|
25560
|
+
var WeaveCommentNode = class extends WeaveNode {
|
|
25561
|
+
nodeType = WEAVE_COMMENT_NODE_TYPE;
|
|
25562
|
+
constructor(params) {
|
|
25563
|
+
super();
|
|
25564
|
+
this.config = (0, import_lodash.merge)(WEAVE_COMMENT_NODE_DEFAULTS, params.config);
|
|
25565
|
+
this.commentDomVisibleId = null;
|
|
25566
|
+
this.commentDomVisible = false;
|
|
25567
|
+
this.commentDomAction = null;
|
|
25568
|
+
this.showResolved = false;
|
|
25569
|
+
}
|
|
25570
|
+
onRender(props) {
|
|
25571
|
+
const { id } = props;
|
|
25572
|
+
const commentParams = { ...props };
|
|
25573
|
+
delete commentParams.zIndex;
|
|
25574
|
+
const widthContracted = this.config.style.contracted.width;
|
|
25575
|
+
const heightContracted = this.config.style.contracted.height;
|
|
25576
|
+
const circlePaddingContracted = this.config.style.contracted.circlePadding;
|
|
25577
|
+
const widthExpanded = this.config.style.expanded.width;
|
|
25578
|
+
const userNameLeftMargin = this.config.style.expanded.userNameLeftMargin;
|
|
25579
|
+
const dateLeftMargin = this.config.style.expanded.dateLeftMargin;
|
|
25580
|
+
const contentTopMargin = this.config.style.expanded.contentTopMargin;
|
|
25581
|
+
const contentBottomMargin = this.config.style.expanded.contentBottomMargin;
|
|
25582
|
+
const userNameShortFontFamily = this.config.style.contracted.userName.fontFamily;
|
|
25583
|
+
const userNameShortFontSize = this.config.style.contracted.userName.fontSize;
|
|
25584
|
+
const userNameShortFontStyle = this.config.style.contracted.userName.fontStyle;
|
|
25585
|
+
const userNameFontFamily = this.config.style.expanded.userName.fontFamily;
|
|
25586
|
+
const userNameFontSize = this.config.style.expanded.userName.fontSize;
|
|
25587
|
+
const userNameFontStyle = this.config.style.expanded.userName.fontStyle;
|
|
25588
|
+
const userNameColor = this.config.style.expanded.userName.color;
|
|
25589
|
+
const dateFontFamily = this.config.style.expanded.date.fontFamily;
|
|
25590
|
+
const dateFontSize = this.config.style.expanded.date.fontSize;
|
|
25591
|
+
const dateFontStyle = this.config.style.expanded.date.fontStyle;
|
|
25592
|
+
const dateColor = this.config.style.expanded.date.color;
|
|
25593
|
+
const contentMaxLines = this.config.style.expanded.content.maxLines;
|
|
25594
|
+
const contentFontFamily = this.config.style.expanded.content.fontFamily;
|
|
25595
|
+
const contentFontSize = this.config.style.expanded.content.fontSize;
|
|
25596
|
+
const contentFontStyle = this.config.style.expanded.content.fontStyle;
|
|
25597
|
+
const contentColor = this.config.style.expanded.content.color;
|
|
25598
|
+
const commentNode = new konva.default.Group({
|
|
25599
|
+
...commentParams,
|
|
25600
|
+
name: "comment",
|
|
25601
|
+
isTargetable: false,
|
|
25602
|
+
isExpanded: false,
|
|
25603
|
+
commentAction: null,
|
|
25604
|
+
listening: true,
|
|
25605
|
+
draggable: this.config.model.canUserDrag(commentParams.commentModel)
|
|
25606
|
+
});
|
|
25607
|
+
this.setupDefaultNodeAugmentation(commentNode);
|
|
25608
|
+
const background = new konva.default.Shape({
|
|
25609
|
+
id: `${id}-bg`,
|
|
25610
|
+
x: 0,
|
|
25611
|
+
y: -heightContracted,
|
|
25612
|
+
isTargetable: false,
|
|
25613
|
+
fill: commentParams.userBackgroundColor ?? "#0000FF",
|
|
25614
|
+
stroke: this.config.style.stroke,
|
|
25615
|
+
strokeWidth: this.config.style.strokeWidth,
|
|
25616
|
+
width: widthContracted,
|
|
25617
|
+
height: heightContracted,
|
|
25618
|
+
shadowColor: this.config.style.shadowColor,
|
|
25619
|
+
shadowBlur: this.config.style.shadowBlur,
|
|
25620
|
+
shadowOffsetX: this.config.style.shadowOffsetX,
|
|
25621
|
+
shadowOffsetY: this.config.style.shadowOffsetY,
|
|
25622
|
+
shadowOpacity: this.config.style.shadowOpacity,
|
|
25623
|
+
strokeScaleEnabled: false,
|
|
25624
|
+
listening: true,
|
|
25625
|
+
draggable: false,
|
|
25626
|
+
hitFunc: (ctx, shape) => {
|
|
25627
|
+
ctx.beginPath();
|
|
25628
|
+
ctx.rect(0, 0, shape.width(), shape.height());
|
|
25629
|
+
ctx.closePath();
|
|
25630
|
+
ctx.fillStrokeShape(shape);
|
|
25631
|
+
},
|
|
25632
|
+
sceneFunc: (ctx, shape) => {
|
|
25633
|
+
ctx.imageSmoothingEnabled = false;
|
|
25634
|
+
const w = shape.width();
|
|
25635
|
+
const h = shape.height();
|
|
25636
|
+
const rWant = shape.getParent()?.getAttrs().isExpanded ? widthContracted / 2 : shape.width() / 2;
|
|
25637
|
+
const r = Math.min(rWant, w / 2, h / 2);
|
|
25638
|
+
ctx.beginPath();
|
|
25639
|
+
ctx.moveTo(r, 0);
|
|
25640
|
+
ctx.lineTo(w - r, 0);
|
|
25641
|
+
ctx.arcTo(w, 0, w, r, r);
|
|
25642
|
+
ctx.lineTo(w, h - r);
|
|
25643
|
+
ctx.arcTo(w, h, w - r, h, r);
|
|
25644
|
+
ctx.lineTo(0, h);
|
|
25645
|
+
ctx.lineTo(0, r);
|
|
25646
|
+
ctx.arcTo(0, 0, r, 0, r);
|
|
25647
|
+
ctx.closePath();
|
|
25648
|
+
ctx.fillStrokeShape(shape);
|
|
25649
|
+
}
|
|
25650
|
+
});
|
|
25651
|
+
commentNode.add(background);
|
|
25652
|
+
const internalCircleBigName = new konva.default.Circle({
|
|
25653
|
+
id: `${id}-circle-big-name`,
|
|
25654
|
+
x: widthContracted / 2,
|
|
25655
|
+
y: -(heightContracted / 2),
|
|
25656
|
+
fill: commentParams.userBackgroundColor ?? "#0000FF",
|
|
25657
|
+
radius: widthContracted / 2 - 2 * circlePaddingContracted,
|
|
25658
|
+
listening: false,
|
|
25659
|
+
draggable: false
|
|
25660
|
+
});
|
|
25661
|
+
internalCircleBigName.hide();
|
|
25662
|
+
commentNode.add(internalCircleBigName);
|
|
25663
|
+
const internalBigName = new konva.default.Text({
|
|
25664
|
+
id: `${id}-big-name`,
|
|
25665
|
+
x: circlePaddingContracted,
|
|
25666
|
+
y: -(heightContracted - circlePaddingContracted),
|
|
25667
|
+
text: this.config.model.getUserShortName(commentParams.commentModel),
|
|
25668
|
+
fontFamily: userNameShortFontFamily,
|
|
25669
|
+
fontSize: userNameShortFontSize,
|
|
25670
|
+
fontStyle: userNameShortFontStyle,
|
|
25671
|
+
fill: commentParams.userForegroundColor ?? "#FFFFFF",
|
|
25672
|
+
align: "center",
|
|
25673
|
+
verticalAlign: "middle",
|
|
25674
|
+
width: widthContracted - 2 * circlePaddingContracted,
|
|
25675
|
+
height: heightContracted - 2 * circlePaddingContracted,
|
|
25676
|
+
listening: false,
|
|
25677
|
+
draggable: false
|
|
25678
|
+
});
|
|
25679
|
+
internalBigName.hide();
|
|
25680
|
+
commentNode.add(internalBigName);
|
|
25681
|
+
const internalUserName = new konva.default.Text({
|
|
25682
|
+
id: `${id}-user-name`,
|
|
25683
|
+
x: widthContracted - 2 * circlePaddingContracted + userNameLeftMargin,
|
|
25684
|
+
text: this.config.model.getUserFullName(commentParams.commentModel),
|
|
25685
|
+
wrap: "none",
|
|
25686
|
+
ellipsis: true,
|
|
25687
|
+
fontFamily: userNameFontFamily,
|
|
25688
|
+
fontSize: userNameFontSize,
|
|
25689
|
+
fontStyle: userNameFontStyle,
|
|
25690
|
+
fill: userNameColor,
|
|
25691
|
+
align: "left",
|
|
25692
|
+
verticalAlign: "middle",
|
|
25693
|
+
width: (widthExpanded - (widthContracted - 2 * circlePaddingContracted) - 8) / 2,
|
|
25694
|
+
height: heightContracted - 2 * circlePaddingContracted,
|
|
25695
|
+
listening: false,
|
|
25696
|
+
draggable: false
|
|
25697
|
+
});
|
|
25698
|
+
internalUserName.hide();
|
|
25699
|
+
commentNode.add(internalUserName);
|
|
25700
|
+
const commentDate = this.config.formatDate(this.config.model.getDate(commentParams.commentModel));
|
|
25701
|
+
const internalDate = new konva.default.Text({
|
|
25702
|
+
id: `${id}-date`,
|
|
25703
|
+
x: widthContracted - 2 * circlePaddingContracted + userNameLeftMargin + (widthExpanded - (widthContracted - 2 * circlePaddingContracted) - 8) / 2,
|
|
25704
|
+
text: commentDate,
|
|
25705
|
+
ellipsis: true,
|
|
25706
|
+
fontFamily: dateFontFamily,
|
|
25707
|
+
fontStyle: dateFontStyle,
|
|
25708
|
+
fontSize: dateFontSize,
|
|
25709
|
+
fill: dateColor,
|
|
25710
|
+
align: "left",
|
|
25711
|
+
verticalAlign: "middle",
|
|
25712
|
+
width: (widthExpanded - (widthContracted - 2 * circlePaddingContracted) - 8) / 2,
|
|
25713
|
+
height: heightContracted - 2 * circlePaddingContracted,
|
|
25714
|
+
listening: false,
|
|
25715
|
+
draggable: false
|
|
25716
|
+
});
|
|
25717
|
+
internalDate.hide();
|
|
25718
|
+
commentNode.add(internalDate);
|
|
25719
|
+
const dateWidth = internalDate.measureSize(commentDate);
|
|
25720
|
+
internalDate.setAttrs({
|
|
25721
|
+
x: widthExpanded - circlePaddingContracted - dateWidth.width - userNameLeftMargin,
|
|
25722
|
+
width: dateWidth.width
|
|
25723
|
+
});
|
|
25724
|
+
internalUserName.setAttrs({ width: widthExpanded - (widthContracted - 2 * circlePaddingContracted) - userNameLeftMargin - dateLeftMargin - dateWidth.width });
|
|
25725
|
+
const commentContent = this.config.model.getContent(commentParams.commentModel);
|
|
25726
|
+
const internalComment = new TextWithMaxLines({
|
|
25727
|
+
id: `${id}-comment`,
|
|
25728
|
+
x: widthContracted - 2 * circlePaddingContracted + userNameLeftMargin,
|
|
25729
|
+
text: commentContent,
|
|
25730
|
+
wrap: "word",
|
|
25731
|
+
ellipsis: true,
|
|
25732
|
+
fontFamily: contentFontFamily,
|
|
25733
|
+
fontSize: contentFontSize,
|
|
25734
|
+
maxLines: contentMaxLines,
|
|
25735
|
+
fontStyle: contentFontStyle,
|
|
25736
|
+
lineHeight: 1.2,
|
|
25737
|
+
fill: contentColor,
|
|
25738
|
+
align: "left",
|
|
25739
|
+
verticalAlign: "top",
|
|
25740
|
+
width: widthExpanded - (widthContracted - 2 * circlePaddingContracted) - userNameLeftMargin - dateLeftMargin,
|
|
25741
|
+
height: heightContracted - 2 * circlePaddingContracted,
|
|
25742
|
+
listening: false,
|
|
25743
|
+
draggable: false
|
|
25744
|
+
});
|
|
25745
|
+
internalComment.hide();
|
|
25746
|
+
commentNode.add(internalComment);
|
|
25747
|
+
const expandedHeight = internalCircleBigName.getClientRect().height + internalComment.getClientRect().height + contentBottomMargin;
|
|
25748
|
+
internalUserName.setAttrs({ y: -expandedHeight + circlePaddingContracted });
|
|
25749
|
+
internalDate.setAttrs({ y: -expandedHeight + circlePaddingContracted });
|
|
25750
|
+
internalComment.setAttrs({ y: -expandedHeight + circlePaddingContracted + heightContracted - contentTopMargin });
|
|
25751
|
+
commentNode.getTransformerProperties = () => {
|
|
25752
|
+
const baseConfig = this.defaultGetTransformerProperties({});
|
|
25753
|
+
return {
|
|
25754
|
+
...baseConfig,
|
|
25755
|
+
resizeEnabled: false,
|
|
25756
|
+
rotateEnabled: false,
|
|
25757
|
+
enabledAnchors: [],
|
|
25758
|
+
borderStrokeWidth: 0,
|
|
25759
|
+
padding: 0
|
|
25760
|
+
};
|
|
25761
|
+
};
|
|
25762
|
+
commentNode.allowedAnchors = () => {
|
|
25763
|
+
return [];
|
|
25764
|
+
};
|
|
25765
|
+
commentNode.on("dragstart", (e) => {
|
|
25766
|
+
this.contractNode(e.target);
|
|
25767
|
+
e.target.setAttrs({ isDragging: true });
|
|
25768
|
+
this.onUpdate(e.target, {});
|
|
25769
|
+
});
|
|
25770
|
+
commentNode.on("dragend", (e) => {
|
|
25771
|
+
e.target.setAttrs({ isDragging: false });
|
|
25772
|
+
this.onUpdate(e.target, {});
|
|
25773
|
+
this.normalizeNodeSize(e.target);
|
|
25774
|
+
this.instance.emitEvent("onCommentDragEnd", { node: e.target });
|
|
25775
|
+
});
|
|
25776
|
+
commentNode.on("pointerup", (e) => {
|
|
25777
|
+
const node = e.target.getParent();
|
|
25778
|
+
if (this.commentDomVisible) {
|
|
25779
|
+
const nodeToClose = this.instance.getStage().findOne(`#${this.commentDomVisibleId}`);
|
|
25780
|
+
if (nodeToClose) {
|
|
25781
|
+
this.closeCommentDOM(nodeToClose);
|
|
25782
|
+
this.contractNode(nodeToClose);
|
|
25783
|
+
}
|
|
25784
|
+
}
|
|
25785
|
+
this.openCommentDOM(node);
|
|
25786
|
+
});
|
|
25787
|
+
commentNode.on("pointermove", (e) => {
|
|
25788
|
+
const stage$1 = this.instance.getStage();
|
|
25789
|
+
stage$1.container().style.cursor = "pointer";
|
|
25790
|
+
e.cancelBubble = true;
|
|
25791
|
+
});
|
|
25792
|
+
commentNode.on("pointerenter", (e) => {
|
|
25793
|
+
const node = e.target.getParent();
|
|
25794
|
+
const commentAction = node.getAttrs().commentAction;
|
|
25795
|
+
if (commentAction !== WEAVE_COMMENT_NODE_ACTION.IDLE) return;
|
|
25796
|
+
if (this.commentDomVisible && this.commentDomVisibleId === node.getAttrs().id) return;
|
|
25797
|
+
node.setAttrs({ isHovered: true });
|
|
25798
|
+
this.expandNode(node);
|
|
25799
|
+
});
|
|
25800
|
+
commentNode.on("pointerleave", (e) => {
|
|
25801
|
+
const node = e.target.getParent();
|
|
25802
|
+
const commentAction = node.getAttrs().commentAction;
|
|
25803
|
+
if (commentAction !== WEAVE_COMMENT_NODE_ACTION.IDLE) return;
|
|
25804
|
+
if (this.commentDomVisible && this.commentDomVisibleId === node.getAttrs().id) return;
|
|
25805
|
+
node.setAttrs({ isHovered: false });
|
|
25806
|
+
this.contractNode(node);
|
|
25807
|
+
});
|
|
25808
|
+
const stage = this.instance.getStage();
|
|
25809
|
+
stage?.on("scaleXChange scaleYChange", () => {
|
|
25810
|
+
this.normalizeNodeSize(commentNode);
|
|
25811
|
+
});
|
|
25812
|
+
return commentNode;
|
|
25813
|
+
}
|
|
25814
|
+
onUpdate(nodeInstance, nextProps) {
|
|
25815
|
+
const commentNode = nodeInstance;
|
|
25816
|
+
commentNode.setAttrs({ ...nextProps });
|
|
25817
|
+
const commentAction = commentNode.getAttrs().commentAction;
|
|
25818
|
+
if (this.config.model.getStatus(commentNode.getAttrs()?.commentModel) === "resolved" && !commentNode.getAttrs().isExpanded && commentNode.getAttrs().commentAction !== WEAVE_COMMENT_NODE_ACTION.VIEWING) commentNode.setAttrs({ opacity: .5 });
|
|
25819
|
+
else commentNode.setAttrs({ opacity: 1 });
|
|
25820
|
+
if (this.showResolved && this.config.model.getStatus(commentNode.getAttrs()?.commentModel) === WEAVE_COMMENT_STATUS.RESOLVED) commentNode.show();
|
|
25821
|
+
if (!this.showResolved && this.config.model.getStatus(commentNode.getAttrs()?.commentModel) === WEAVE_COMMENT_STATUS.RESOLVED) commentNode.hide();
|
|
25822
|
+
const background = commentNode.findOne(`#${commentNode.id()}-bg`);
|
|
25823
|
+
if (background && commentNode.getAttrs().commentAction === WEAVE_COMMENT_NODE_ACTION.VIEWING) background.setAttrs({
|
|
25824
|
+
stroke: this.config.style.viewing.stroke,
|
|
25825
|
+
strokeWidth: this.config.style.viewing.strokeWidth
|
|
25826
|
+
});
|
|
25827
|
+
if (background && commentNode.getAttrs().commentAction === WEAVE_COMMENT_NODE_ACTION.CREATING) background.setAttrs({
|
|
25828
|
+
stroke: this.config.style.creating.stroke,
|
|
25829
|
+
strokeWidth: this.config.style.creating.strokeWidth
|
|
25830
|
+
});
|
|
25831
|
+
if (background && commentNode.getAttrs().commentAction === WEAVE_COMMENT_NODE_ACTION.IDLE) background.setAttrs({
|
|
25832
|
+
stroke: this.config.style.stroke,
|
|
25833
|
+
strokeWidth: this.config.style.strokeWidth
|
|
25834
|
+
});
|
|
25835
|
+
if (background && commentNode.getAttrs().isDragging) background.setAttrs({
|
|
25836
|
+
stroke: this.config.style.viewing.stroke,
|
|
25837
|
+
strokeWidth: this.config.style.viewing.strokeWidth
|
|
25838
|
+
});
|
|
25839
|
+
if (commentAction === WEAVE_COMMENT_NODE_ACTION.CREATING) {
|
|
25840
|
+
const commentDomElement = this.createCommentDOM(commentNode);
|
|
25841
|
+
commentNode.setAttrs({ commentAction: WEAVE_COMMENT_NODE_ACTION.CREATING });
|
|
25842
|
+
this.commentDomAction = WEAVE_COMMENT_NODE_ACTION.CREATING;
|
|
25843
|
+
this.commentDomVisibleId = commentNode.id();
|
|
25844
|
+
this.commentDomVisible = true;
|
|
25845
|
+
this.config.createComment(commentDomElement, commentNode, (node, content, action) => {
|
|
25846
|
+
this.finishCreateCommentDOM(node);
|
|
25847
|
+
if (action === WEAVE_COMMENT_CREATE_ACTION.CLOSE) {
|
|
25848
|
+
this.onDestroy(node);
|
|
25849
|
+
this.instance.emitEvent("onCommentFinishCreate", {
|
|
25850
|
+
node,
|
|
25851
|
+
action
|
|
25852
|
+
});
|
|
25853
|
+
return;
|
|
25854
|
+
}
|
|
25855
|
+
if (action === WEAVE_COMMENT_CREATE_ACTION.CREATE && content !== "") {
|
|
25856
|
+
this.instance.emitEvent("onCommentCreate", {
|
|
25857
|
+
node,
|
|
25858
|
+
position: {
|
|
25859
|
+
x: node.x(),
|
|
25860
|
+
y: node.y()
|
|
25861
|
+
},
|
|
25862
|
+
content
|
|
25863
|
+
});
|
|
25864
|
+
this.onUpdate(node, {
|
|
25865
|
+
commentModel: this.config.model.setContent(node.getAttrs().commentModel ?? {}, content),
|
|
25866
|
+
commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE
|
|
25867
|
+
});
|
|
25868
|
+
this.contractNode(node);
|
|
25869
|
+
this.instance.emitEvent("onCommentFinishCreate", {
|
|
25870
|
+
node,
|
|
25871
|
+
action
|
|
25872
|
+
});
|
|
25873
|
+
}
|
|
25874
|
+
});
|
|
25875
|
+
this.normalizeNodeSize(commentNode);
|
|
25876
|
+
return;
|
|
25877
|
+
}
|
|
25878
|
+
if (commentAction === WEAVE_COMMENT_NODE_ACTION.IDLE) {
|
|
25879
|
+
const internalRect = commentNode.findOne(`#${commentNode.id()}-bg`);
|
|
25880
|
+
internalRect?.setAttrs({ fill: "#FFFFFF" });
|
|
25881
|
+
const internalCircleBigName = commentNode.findOne(`#${commentNode.id()}-circle-big-name`);
|
|
25882
|
+
internalCircleBigName?.show();
|
|
25883
|
+
const internalBigName = commentNode.findOne(`#${commentNode.id()}-big-name`);
|
|
25884
|
+
internalBigName?.show();
|
|
25885
|
+
this.normalizeNodeSize(commentNode);
|
|
25886
|
+
return;
|
|
25887
|
+
}
|
|
25888
|
+
this.normalizeNodeSize(commentNode);
|
|
25889
|
+
}
|
|
25890
|
+
onDestroy(nodeInstance) {
|
|
25891
|
+
nodeInstance.destroy();
|
|
25892
|
+
}
|
|
25893
|
+
expandNode(commentNode) {
|
|
25894
|
+
const widthExpanded = this.config.style.expanded.width;
|
|
25895
|
+
const circlePaddingContracted = this.config.style.contracted.circlePadding;
|
|
25896
|
+
const internalCircleBigName = commentNode.findOne(`#${commentNode.id()}-circle-big-name`);
|
|
25897
|
+
const internalComment = commentNode.findOne(`#${commentNode.id()}-comment`);
|
|
25898
|
+
const heightExpanded = (internalCircleBigName?.getClientRect().height ?? 0) + (internalComment?.getClientRect().height ?? 0) + 12;
|
|
25899
|
+
const background = commentNode.findOne(`#${commentNode.id()}-bg`);
|
|
25900
|
+
background?.setAttrs({
|
|
25901
|
+
y: -heightExpanded,
|
|
25902
|
+
width: widthExpanded,
|
|
25903
|
+
height: heightExpanded
|
|
25904
|
+
});
|
|
25905
|
+
internalCircleBigName?.setAttrs({ y: -heightExpanded + circlePaddingContracted * 2 + internalCircleBigName.radius() });
|
|
25906
|
+
const internalBigName = commentNode.findOne(`#${commentNode.id()}-big-name`);
|
|
25907
|
+
internalBigName?.setAttrs({ y: -heightExpanded + circlePaddingContracted });
|
|
25908
|
+
const internalUserName = commentNode.findOne(`#${commentNode.id()}-user-name`);
|
|
25909
|
+
internalUserName?.show();
|
|
25910
|
+
const internalDateName = commentNode.findOne(`#${commentNode.id()}-date`);
|
|
25911
|
+
internalDateName?.show();
|
|
25912
|
+
internalComment?.show();
|
|
25913
|
+
commentNode.setAttrs({
|
|
25914
|
+
isExpanded: true,
|
|
25915
|
+
opacity: 1
|
|
25916
|
+
});
|
|
25917
|
+
const actualZIndex = commentNode.zIndex();
|
|
25918
|
+
commentNode.setAttrs({ contractedZIndex: actualZIndex });
|
|
25919
|
+
commentNode.moveToTop();
|
|
25920
|
+
this.normalizeNodeSize(commentNode);
|
|
25921
|
+
}
|
|
25922
|
+
contractNode(commentNode) {
|
|
25923
|
+
const widthContracted = this.config.style.contracted.width;
|
|
25924
|
+
const heightContracted = this.config.style.contracted.height;
|
|
25925
|
+
const circlePaddingContracted = this.config.style.contracted.circlePadding;
|
|
25926
|
+
const background = commentNode.findOne(`#${commentNode.id()}-bg`);
|
|
25927
|
+
background?.setAttrs({
|
|
25928
|
+
y: -heightContracted,
|
|
25929
|
+
width: widthContracted,
|
|
25930
|
+
height: heightContracted
|
|
25931
|
+
});
|
|
25932
|
+
const internalCircleBigName = commentNode.findOne(`#${commentNode.id()}-circle-big-name`);
|
|
25933
|
+
internalCircleBigName?.setAttrs({ y: -(heightContracted / 2) });
|
|
25934
|
+
const internalBigName = commentNode.findOne(`#${commentNode.id()}-big-name`);
|
|
25935
|
+
internalBigName?.setAttrs({ y: -(heightContracted - circlePaddingContracted) });
|
|
25936
|
+
const internalUserName = commentNode.findOne(`#${commentNode.id()}-user-name`);
|
|
25937
|
+
internalUserName?.hide();
|
|
25938
|
+
const internalDateName = commentNode.findOne(`#${commentNode.id()}-date`);
|
|
25939
|
+
internalDateName?.hide();
|
|
25940
|
+
const internalComment = commentNode.findOne(`#${commentNode.id()}-comment`);
|
|
25941
|
+
internalComment?.hide();
|
|
25942
|
+
if (this.config.model.getStatus(commentNode.getAttrs()?.commentModel) === WEAVE_COMMENT_STATUS.RESOLVED && commentNode.getAttrs().commentAction !== WEAVE_COMMENT_NODE_ACTION.VIEWING) commentNode.setAttrs({ opacity: .5 });
|
|
25943
|
+
commentNode.setAttrs({ isExpanded: false });
|
|
25944
|
+
if (commentNode.getAttrs().contractedZIndex) {
|
|
25945
|
+
commentNode.zIndex(commentNode.getAttrs().contractedZIndex);
|
|
25946
|
+
commentNode.setAttrs({ contractedZIndex: void 0 });
|
|
25947
|
+
}
|
|
25948
|
+
this.normalizeNodeSize(commentNode);
|
|
25949
|
+
}
|
|
25950
|
+
finishCreateCommentDOM(commentNode) {
|
|
25951
|
+
this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(commentNode).bind(this));
|
|
25952
|
+
this.instance.removeEventListener("onStageMove", this.onStageMoveHandler(commentNode).bind(this));
|
|
25953
|
+
const superContainer = document.getElementById(`${commentNode.id()}_supercontainer`);
|
|
25954
|
+
if (!superContainer) return;
|
|
25955
|
+
superContainer.remove();
|
|
25956
|
+
this.commentDomAction = null;
|
|
25957
|
+
this.commentDomVisibleId = null;
|
|
25958
|
+
this.commentDomVisible = false;
|
|
25959
|
+
}
|
|
25960
|
+
setCommentDOMPosition(commentNode, commentAction) {
|
|
25961
|
+
const stage = this.instance.getStage();
|
|
25962
|
+
const rect = commentNode.getClientRect({ relativeTo: stage });
|
|
25963
|
+
const scaleX = stage.scaleX();
|
|
25964
|
+
const scaleY = stage.scaleY();
|
|
25965
|
+
const stagePos = stage.position();
|
|
25966
|
+
let paddingX = 8;
|
|
25967
|
+
let paddingY = 0;
|
|
25968
|
+
if (commentAction === WEAVE_COMMENT_NODE_ACTION.CREATING) {
|
|
25969
|
+
paddingX = this.config.style.creating.paddingX;
|
|
25970
|
+
paddingY = this.config.style.creating.paddingY;
|
|
25971
|
+
}
|
|
25972
|
+
if (commentAction === WEAVE_COMMENT_NODE_ACTION.VIEWING) {
|
|
25973
|
+
paddingX = this.config.style.viewing.paddingX;
|
|
25974
|
+
paddingY = this.config.style.viewing.paddingY;
|
|
25975
|
+
}
|
|
25976
|
+
const x = stagePos.x + rect.x * scaleX + rect.width * scaleX + paddingX;
|
|
25977
|
+
const y = stagePos.y + rect.y * scaleY + paddingY;
|
|
25978
|
+
const position = {
|
|
25979
|
+
x,
|
|
25980
|
+
y
|
|
25981
|
+
};
|
|
25982
|
+
const container = document.getElementById(`${commentNode.id()}_container`);
|
|
25983
|
+
if (!container) return;
|
|
25984
|
+
container.style.position = "absolute";
|
|
25985
|
+
container.style.top = position.y + "px";
|
|
25986
|
+
container.style.left = position.x + "px";
|
|
25987
|
+
}
|
|
25988
|
+
createCommentDOM(commentNode) {
|
|
25989
|
+
const stage = this.instance.getStage();
|
|
25990
|
+
const superContainer = document.createElement("div");
|
|
25991
|
+
superContainer.id = `${commentNode.id()}_supercontainer`;
|
|
25992
|
+
superContainer.style.position = "absolute";
|
|
25993
|
+
superContainer.style.top = "0px";
|
|
25994
|
+
superContainer.style.left = "0px";
|
|
25995
|
+
superContainer.style.bottom = "0px";
|
|
25996
|
+
superContainer.style.right = "0px";
|
|
25997
|
+
superContainer.style.overflow = "hidden";
|
|
25998
|
+
superContainer.style.pointerEvents = "none";
|
|
25999
|
+
const container = document.createElement("div");
|
|
26000
|
+
container.id = `${commentNode.id()}_container`;
|
|
26001
|
+
superContainer.appendChild(container);
|
|
26002
|
+
stage.container().appendChild(superContainer);
|
|
26003
|
+
this.setCommentDOMPosition(commentNode, commentNode.getAttrs().commentAction);
|
|
26004
|
+
this.instance.addEventListener("onZoomChange", this.onZoomChangeHandler(commentNode).bind(this));
|
|
26005
|
+
this.instance.addEventListener("onStageMove", this.onStageMoveHandler(commentNode).bind(this));
|
|
26006
|
+
return container;
|
|
26007
|
+
}
|
|
26008
|
+
onZoomChangeHandler = (commentNode) => () => {
|
|
26009
|
+
if (!this.commentDomVisible) return;
|
|
26010
|
+
const node = this.instance.getStage().findOne(`#${commentNode.id()}`);
|
|
26011
|
+
if (node) this.setCommentDOMPosition(node, commentNode.getAttrs().commentAction);
|
|
26012
|
+
};
|
|
26013
|
+
normalizeNodeSize(node) {
|
|
26014
|
+
const abs = node.getAbsoluteScale();
|
|
26015
|
+
node.scale({
|
|
26016
|
+
x: node.scaleX() / abs.x,
|
|
26017
|
+
y: node.scaleY() / abs.y
|
|
26018
|
+
});
|
|
26019
|
+
if (node instanceof konva.default.Group) node.getChildren().forEach((child) => this.normalizeNodeSize(child));
|
|
26020
|
+
}
|
|
26021
|
+
onStageMoveHandler = (commentNode) => () => {
|
|
26022
|
+
if (!this.commentDomVisible) return;
|
|
26023
|
+
const node = this.instance.getStage().findOne(`#${commentNode.id()}`);
|
|
26024
|
+
if (node) this.setCommentDOMPosition(node, commentNode.getAttrs().commentAction);
|
|
26025
|
+
};
|
|
26026
|
+
openCommentDOM(commentNode) {
|
|
26027
|
+
this.contractNode(commentNode);
|
|
26028
|
+
commentNode.setAttrs({ commentAction: WEAVE_COMMENT_NODE_ACTION.VIEWING });
|
|
26029
|
+
this.onUpdate(commentNode, { commentAction: WEAVE_COMMENT_NODE_ACTION.VIEWING });
|
|
26030
|
+
this.commentDomAction = WEAVE_COMMENT_NODE_ACTION.VIEWING;
|
|
26031
|
+
this.commentDomVisibleId = commentNode.id();
|
|
26032
|
+
this.commentDomVisible = true;
|
|
26033
|
+
const commentDomElement = this.createCommentDOM(commentNode);
|
|
26034
|
+
this.instance.emitEvent("onCommentView", { node: commentNode });
|
|
26035
|
+
this.config.viewComment(commentDomElement, commentNode, (nodeF, content, action) => {
|
|
26036
|
+
switch (action) {
|
|
26037
|
+
case WEAVE_COMMENT_VIEW_ACTION.REPLY: break;
|
|
26038
|
+
case WEAVE_COMMENT_VIEW_ACTION.MARK_RESOLVED: {
|
|
26039
|
+
this.finishCreateCommentDOM(nodeF);
|
|
26040
|
+
this.onUpdate(nodeF, { commentModel: this.config.model.setMarkResolved(nodeF.getAttrs().commentModel ?? {}) });
|
|
26041
|
+
break;
|
|
26042
|
+
}
|
|
26043
|
+
case WEAVE_COMMENT_VIEW_ACTION.EDIT: {
|
|
26044
|
+
nodeF.setAttrs({ content });
|
|
26045
|
+
this.onUpdate(nodeF, { commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE });
|
|
26046
|
+
break;
|
|
26047
|
+
}
|
|
26048
|
+
case WEAVE_COMMENT_VIEW_ACTION.DELETE: {
|
|
26049
|
+
this.finishCreateCommentDOM(nodeF);
|
|
26050
|
+
nodeF.destroy();
|
|
26051
|
+
break;
|
|
26052
|
+
}
|
|
26053
|
+
case WEAVE_COMMENT_VIEW_ACTION.CLOSE: {
|
|
26054
|
+
this.finishCreateCommentDOM(nodeF);
|
|
26055
|
+
this.contractNode(nodeF);
|
|
26056
|
+
nodeF.setAttrs({ commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE });
|
|
26057
|
+
this.onUpdate(nodeF, { commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE });
|
|
26058
|
+
this.instance.emitEvent("onCommentFinishCreate", {
|
|
26059
|
+
node: nodeF,
|
|
26060
|
+
action
|
|
26061
|
+
});
|
|
26062
|
+
break;
|
|
26063
|
+
}
|
|
26064
|
+
default: break;
|
|
26065
|
+
}
|
|
26066
|
+
});
|
|
26067
|
+
}
|
|
26068
|
+
closeCommentDOM(commentNode) {
|
|
26069
|
+
this.finishCreateCommentDOM(commentNode);
|
|
26070
|
+
if (commentNode.getAttrs().isHovered) this.expandNode(commentNode);
|
|
26071
|
+
commentNode.setAttrs({ commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE });
|
|
26072
|
+
this.onUpdate(commentNode, { commentAction: WEAVE_COMMENT_NODE_ACTION.IDLE });
|
|
26073
|
+
}
|
|
26074
|
+
afterCreatePersist(commentNode, comment) {
|
|
26075
|
+
commentNode.setAttrs({ commentModel: comment });
|
|
26076
|
+
this.normalizeNodeSize(commentNode);
|
|
26077
|
+
}
|
|
26078
|
+
open(commentNode) {
|
|
26079
|
+
this.openCommentDOM(commentNode);
|
|
26080
|
+
}
|
|
26081
|
+
focusOn(nodeId, duration = .5) {
|
|
26082
|
+
if (this.commentDomVisible && this.commentDomVisibleId) {
|
|
26083
|
+
const commentNode = this.instance.getStage().findOne(`#${this.commentDomVisibleId}`);
|
|
26084
|
+
if (commentNode) {
|
|
26085
|
+
this.closeCommentDOM(commentNode);
|
|
26086
|
+
this.contractNode(commentNode);
|
|
26087
|
+
}
|
|
26088
|
+
}
|
|
26089
|
+
const node = this.instance.getStage().findOne(`#${nodeId}`);
|
|
26090
|
+
if (node) {
|
|
26091
|
+
const stage = this.instance.getStage();
|
|
26092
|
+
const stageWidth = stage.width();
|
|
26093
|
+
const stageHeight = stage.height();
|
|
26094
|
+
const scale = stage.scaleX();
|
|
26095
|
+
const box = node.getClientRect({ relativeTo: stage });
|
|
26096
|
+
const nodeCenterX = box.x + box.width / 2;
|
|
26097
|
+
const nodeCenterY = box.y + box.height / 2;
|
|
26098
|
+
const targetX = stageWidth / 2 - nodeCenterX * scale;
|
|
26099
|
+
const targetY = stageHeight / 2 - nodeCenterY * scale;
|
|
26100
|
+
const tween = new konva.default.Tween({
|
|
26101
|
+
node: stage,
|
|
26102
|
+
duration,
|
|
26103
|
+
x: targetX,
|
|
26104
|
+
y: targetY,
|
|
26105
|
+
easing: konva.default.Easings.EaseInOut,
|
|
26106
|
+
onFinish: () => {
|
|
26107
|
+
this.openCommentDOM(node);
|
|
26108
|
+
}
|
|
26109
|
+
});
|
|
26110
|
+
tween.play();
|
|
26111
|
+
}
|
|
26112
|
+
}
|
|
26113
|
+
isCommentViewing() {
|
|
26114
|
+
return this.commentDomAction === WEAVE_COMMENT_NODE_ACTION.VIEWING && this.commentDomVisible;
|
|
26115
|
+
}
|
|
26116
|
+
isCommentCreating() {
|
|
26117
|
+
return this.commentDomAction === WEAVE_COMMENT_NODE_ACTION.CREATING && this.commentDomVisible;
|
|
26118
|
+
}
|
|
26119
|
+
getCommentId(node) {
|
|
26120
|
+
return this.config.model.getId(node.getAttrs().commentModel);
|
|
26121
|
+
}
|
|
26122
|
+
setShowResolved(show) {
|
|
26123
|
+
this.showResolved = show;
|
|
26124
|
+
}
|
|
26125
|
+
};
|
|
26126
|
+
|
|
25409
26127
|
//#endregion
|
|
25410
26128
|
//#region src/plugins/stage-zoom/constants.ts
|
|
25411
26129
|
const WEAVE_STAGE_ZOOM_TYPE = {
|
|
@@ -25817,7 +26535,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
25817
26535
|
const shadowHost = getTopmostShadowHost(stage.container());
|
|
25818
26536
|
if (shadowHost) elementUnderMouse = shadowHost.elementFromPoint(mouseX, mouseY);
|
|
25819
26537
|
}
|
|
25820
|
-
if (!this.enabled || !performZoom ||
|
|
26538
|
+
if (!this.enabled || !performZoom || this.instance.getClosestParentWithWeaveId(elementUnderMouse) !== stage.container()) return;
|
|
25821
26539
|
e.preventDefault();
|
|
25822
26540
|
const delta = e.deltaY > 0 ? 1 : -1;
|
|
25823
26541
|
this.zoomVelocity += delta;
|
|
@@ -26029,7 +26747,7 @@ var WeaveMoveToolAction = class extends WeaveAction {
|
|
|
26029
26747
|
}
|
|
26030
26748
|
setupEvents() {
|
|
26031
26749
|
const stage = this.instance.getStage();
|
|
26032
|
-
|
|
26750
|
+
window.addEventListener("keydown", (e) => {
|
|
26033
26751
|
if (e.key === "Escape" && this.instance.getActiveAction() === MOVE_TOOL_ACTION_NAME) {
|
|
26034
26752
|
this.cancelAction();
|
|
26035
26753
|
return;
|
|
@@ -26165,6 +26883,10 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
26165
26883
|
}
|
|
26166
26884
|
setupEvents() {
|
|
26167
26885
|
const stage = this.instance.getStage();
|
|
26886
|
+
stage.on("pointermove", () => {
|
|
26887
|
+
if (this.state === ERASER_TOOL_STATE.IDLE) return;
|
|
26888
|
+
this.setCursor();
|
|
26889
|
+
});
|
|
26168
26890
|
stage.on("pointerclick", () => {
|
|
26169
26891
|
if (!this.erasing) return;
|
|
26170
26892
|
const nodeIntersected = this.instance.pointIntersectsElement();
|
|
@@ -26180,7 +26902,7 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
26180
26902
|
}
|
|
26181
26903
|
}
|
|
26182
26904
|
});
|
|
26183
|
-
|
|
26905
|
+
window.addEventListener("keydown", (e) => {
|
|
26184
26906
|
if (e.key === "Escape" && this.instance.getActiveAction() === ERASER_TOOL_ACTION_NAME) {
|
|
26185
26907
|
this.cancelAction();
|
|
26186
26908
|
return;
|
|
@@ -26192,9 +26914,8 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
26192
26914
|
this.state = state;
|
|
26193
26915
|
}
|
|
26194
26916
|
setEraser() {
|
|
26195
|
-
|
|
26196
|
-
|
|
26197
|
-
stage.container().focus();
|
|
26917
|
+
this.setCursor();
|
|
26918
|
+
this.setFocusStage();
|
|
26198
26919
|
this.erasing = true;
|
|
26199
26920
|
this.setState(ERASER_TOOL_STATE.ERASING);
|
|
26200
26921
|
}
|
|
@@ -26223,6 +26944,16 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
26223
26944
|
}
|
|
26224
26945
|
this.setState(ERASER_TOOL_STATE.IDLE);
|
|
26225
26946
|
}
|
|
26947
|
+
setCursor() {
|
|
26948
|
+
const stage = this.instance.getStage();
|
|
26949
|
+
stage.container().style.cursor = "crosshair";
|
|
26950
|
+
}
|
|
26951
|
+
setFocusStage() {
|
|
26952
|
+
const stage = this.instance.getStage();
|
|
26953
|
+
stage.container().tabIndex = 1;
|
|
26954
|
+
stage.container().blur();
|
|
26955
|
+
stage.container().focus();
|
|
26956
|
+
}
|
|
26226
26957
|
};
|
|
26227
26958
|
|
|
26228
26959
|
//#endregion
|
|
@@ -26269,7 +27000,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
26269
27000
|
}
|
|
26270
27001
|
setupEvents() {
|
|
26271
27002
|
const stage = this.instance.getStage();
|
|
26272
|
-
|
|
27003
|
+
window.addEventListener("keydown", (e) => {
|
|
26273
27004
|
if (e.key === "Enter" && this.instance.getActiveAction() === RECTANGLE_TOOL_ACTION_NAME) {
|
|
26274
27005
|
this.cancelAction();
|
|
26275
27006
|
return;
|
|
@@ -26279,6 +27010,10 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
26279
27010
|
return;
|
|
26280
27011
|
}
|
|
26281
27012
|
});
|
|
27013
|
+
stage.on("pointermove", () => {
|
|
27014
|
+
if (this.state === RECTANGLE_TOOL_STATE.IDLE) return;
|
|
27015
|
+
this.setCursor();
|
|
27016
|
+
});
|
|
26282
27017
|
stage.on("pointerdown", (e) => {
|
|
26283
27018
|
this.setTapStart(e);
|
|
26284
27019
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -26292,6 +27027,8 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
26292
27027
|
if (this.state === RECTANGLE_TOOL_STATE.ADDING) this.handleAdding();
|
|
26293
27028
|
});
|
|
26294
27029
|
stage.on("pointermove", (e) => {
|
|
27030
|
+
if (this.state === RECTANGLE_TOOL_STATE.IDLE) return;
|
|
27031
|
+
this.setCursor();
|
|
26295
27032
|
if (!this.isPressed(e)) return;
|
|
26296
27033
|
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
26297
27034
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === RECTANGLE_TOOL_ACTION_NAME) {
|
|
@@ -26312,9 +27049,8 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
26312
27049
|
this.state = state;
|
|
26313
27050
|
}
|
|
26314
27051
|
addRectangle() {
|
|
26315
|
-
|
|
26316
|
-
|
|
26317
|
-
stage.container().focus();
|
|
27052
|
+
this.setCursor();
|
|
27053
|
+
this.setFocusStage();
|
|
26318
27054
|
this.instance.emitEvent("onAddingRectangle");
|
|
26319
27055
|
this.clickPoint = null;
|
|
26320
27056
|
this.setState(RECTANGLE_TOOL_STATE.ADDING);
|
|
@@ -26417,6 +27153,16 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
26417
27153
|
this.clickPoint = null;
|
|
26418
27154
|
this.setState(RECTANGLE_TOOL_STATE.IDLE);
|
|
26419
27155
|
}
|
|
27156
|
+
setCursor() {
|
|
27157
|
+
const stage = this.instance.getStage();
|
|
27158
|
+
stage.container().style.cursor = "crosshair";
|
|
27159
|
+
}
|
|
27160
|
+
setFocusStage() {
|
|
27161
|
+
const stage = this.instance.getStage();
|
|
27162
|
+
stage.container().tabIndex = 1;
|
|
27163
|
+
stage.container().blur();
|
|
27164
|
+
stage.container().focus();
|
|
27165
|
+
}
|
|
26420
27166
|
};
|
|
26421
27167
|
|
|
26422
27168
|
//#endregion
|
|
@@ -26463,7 +27209,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
26463
27209
|
}
|
|
26464
27210
|
setupEvents() {
|
|
26465
27211
|
const stage = this.instance.getStage();
|
|
26466
|
-
|
|
27212
|
+
window.addEventListener("keydown", (e) => {
|
|
26467
27213
|
if (e.key === "Enter" && this.instance.getActiveAction() === ELLIPSE_TOOL_ACTION_NAME) {
|
|
26468
27214
|
this.cancelAction();
|
|
26469
27215
|
return;
|
|
@@ -26489,6 +27235,8 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
26489
27235
|
}
|
|
26490
27236
|
});
|
|
26491
27237
|
stage.on("pointermove", (e) => {
|
|
27238
|
+
if (this.state === ELLIPSE_TOOL_STATE.IDLE) return;
|
|
27239
|
+
this.setCursor();
|
|
26492
27240
|
if (!this.isPressed(e)) return;
|
|
26493
27241
|
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
26494
27242
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === ELLIPSE_TOOL_ACTION_NAME) {
|
|
@@ -26515,9 +27263,8 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
26515
27263
|
this.state = state;
|
|
26516
27264
|
}
|
|
26517
27265
|
addEllipse() {
|
|
26518
|
-
|
|
26519
|
-
|
|
26520
|
-
stage.container().focus();
|
|
27266
|
+
this.setCursor();
|
|
27267
|
+
this.setFocusStage();
|
|
26521
27268
|
this.instance.emitEvent("onAddingEllipse");
|
|
26522
27269
|
this.clickPoint = null;
|
|
26523
27270
|
this.setState(ELLIPSE_TOOL_STATE.ADDING);
|
|
@@ -26623,6 +27370,16 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
26623
27370
|
this.clickPoint = null;
|
|
26624
27371
|
this.setState(ELLIPSE_TOOL_STATE.IDLE);
|
|
26625
27372
|
}
|
|
27373
|
+
setCursor() {
|
|
27374
|
+
const stage = this.instance.getStage();
|
|
27375
|
+
stage.container().style.cursor = "crosshair";
|
|
27376
|
+
}
|
|
27377
|
+
setFocusStage() {
|
|
27378
|
+
const stage = this.instance.getStage();
|
|
27379
|
+
stage.container().tabIndex = 1;
|
|
27380
|
+
stage.container().blur();
|
|
27381
|
+
stage.container().focus();
|
|
27382
|
+
}
|
|
26626
27383
|
};
|
|
26627
27384
|
|
|
26628
27385
|
//#endregion
|
|
@@ -26670,7 +27427,7 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
26670
27427
|
}
|
|
26671
27428
|
setupEvents() {
|
|
26672
27429
|
const stage = this.instance.getStage();
|
|
26673
|
-
|
|
27430
|
+
window.addEventListener("keydown", (e) => {
|
|
26674
27431
|
if (e.key === "Enter" && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
|
|
26675
27432
|
this.cancelAction();
|
|
26676
27433
|
return;
|
|
@@ -26694,6 +27451,8 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
26694
27451
|
if (this.tempMainLineNode && this.state === PEN_TOOL_STATE.ADDING) this.state = PEN_TOOL_STATE.DEFINING_SIZE;
|
|
26695
27452
|
});
|
|
26696
27453
|
stage.on("pointermove", () => {
|
|
27454
|
+
if (this.state === PEN_TOOL_STATE.IDLE) return;
|
|
27455
|
+
this.setCursor();
|
|
26697
27456
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
|
|
26698
27457
|
this.state = PEN_TOOL_STATE.ADDING;
|
|
26699
27458
|
return;
|
|
@@ -26710,9 +27469,8 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
26710
27469
|
this.state = state;
|
|
26711
27470
|
}
|
|
26712
27471
|
addLine() {
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
stage.container().focus();
|
|
27472
|
+
this.setCursor();
|
|
27473
|
+
this.setFocusStage();
|
|
26716
27474
|
this.instance.emitEvent("onAddingPen");
|
|
26717
27475
|
this.tempPoint = void 0;
|
|
26718
27476
|
this.tempNextPoint = void 0;
|
|
@@ -26865,6 +27623,16 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
26865
27623
|
this.clickPoint = null;
|
|
26866
27624
|
this.setState(PEN_TOOL_STATE.IDLE);
|
|
26867
27625
|
}
|
|
27626
|
+
setCursor() {
|
|
27627
|
+
const stage = this.instance.getStage();
|
|
27628
|
+
stage.container().style.cursor = "crosshair";
|
|
27629
|
+
}
|
|
27630
|
+
setFocusStage() {
|
|
27631
|
+
const stage = this.instance.getStage();
|
|
27632
|
+
stage.container().tabIndex = 1;
|
|
27633
|
+
stage.container().blur();
|
|
27634
|
+
stage.container().focus();
|
|
27635
|
+
}
|
|
26868
27636
|
};
|
|
26869
27637
|
|
|
26870
27638
|
//#endregion
|
|
@@ -26910,9 +27678,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26910
27678
|
}
|
|
26911
27679
|
setupEvents() {
|
|
26912
27680
|
const stage = this.instance.getStage();
|
|
26913
|
-
|
|
26914
|
-
stage.container().focus();
|
|
26915
|
-
stage.container().addEventListener("keydown", (e) => {
|
|
27681
|
+
window.addEventListener("keydown", (e) => {
|
|
26916
27682
|
if (e.key === "Enter" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
|
|
26917
27683
|
this.cancelAction();
|
|
26918
27684
|
return;
|
|
@@ -26931,9 +27697,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26931
27697
|
};
|
|
26932
27698
|
stage.on("pointerdown", handlePointerDown);
|
|
26933
27699
|
const handlePointerMove = (e) => {
|
|
27700
|
+
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
27701
|
+
this.setCursor();
|
|
26934
27702
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26935
27703
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
26936
|
-
stage.container().style.cursor = "crosshair";
|
|
26937
27704
|
const pointPressure = this.getEventPressure(e);
|
|
26938
27705
|
this.handleMovement(pointPressure);
|
|
26939
27706
|
e.evt.stopPropagation();
|
|
@@ -27027,7 +27794,6 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
27027
27794
|
}
|
|
27028
27795
|
}
|
|
27029
27796
|
handleEndStroke() {
|
|
27030
|
-
const stage = this.instance.getStage();
|
|
27031
27797
|
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
27032
27798
|
if (tempStroke) {
|
|
27033
27799
|
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
@@ -27051,9 +27817,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
27051
27817
|
if (tempStroke.getAttrs().strokeElements.length >= 3) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
27052
27818
|
}
|
|
27053
27819
|
this.clickPoint = null;
|
|
27054
|
-
|
|
27055
|
-
|
|
27056
|
-
stage.container().focus();
|
|
27820
|
+
this.setCursor();
|
|
27821
|
+
this.setFocusStage();
|
|
27057
27822
|
this.setState(BRUSH_TOOL_STATE.IDLE);
|
|
27058
27823
|
}
|
|
27059
27824
|
}
|
|
@@ -27073,7 +27838,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
27073
27838
|
this.props = this.initProps();
|
|
27074
27839
|
this.setState(BRUSH_TOOL_STATE.IDLE);
|
|
27075
27840
|
this.instance.emitEvent("onAddingBrush");
|
|
27076
|
-
|
|
27841
|
+
this.setCursor();
|
|
27842
|
+
this.setFocusStage();
|
|
27077
27843
|
}
|
|
27078
27844
|
cleanup() {
|
|
27079
27845
|
const stage = this.instance.getStage();
|
|
@@ -27092,6 +27858,16 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
27092
27858
|
const zoomPlugin = this.instance.getPlugin("stageZoom");
|
|
27093
27859
|
return zoomPlugin;
|
|
27094
27860
|
}
|
|
27861
|
+
setCursor() {
|
|
27862
|
+
const stage = this.instance.getStage();
|
|
27863
|
+
stage.container().style.cursor = "crosshair";
|
|
27864
|
+
}
|
|
27865
|
+
setFocusStage() {
|
|
27866
|
+
const stage = this.instance.getStage();
|
|
27867
|
+
stage.container().tabIndex = 1;
|
|
27868
|
+
stage.container().blur();
|
|
27869
|
+
stage.container().focus();
|
|
27870
|
+
}
|
|
27095
27871
|
};
|
|
27096
27872
|
|
|
27097
27873
|
//#endregion
|
|
@@ -27127,12 +27903,16 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
27127
27903
|
}
|
|
27128
27904
|
setupEvents() {
|
|
27129
27905
|
const stage = this.instance.getStage();
|
|
27130
|
-
|
|
27906
|
+
window.addEventListener("keydown", (e) => {
|
|
27131
27907
|
if (e.key === "Escape" && this.instance.getActiveAction() === TEXT_TOOL_ACTION_NAME) {
|
|
27132
27908
|
this.cancelAction();
|
|
27133
27909
|
return;
|
|
27134
27910
|
}
|
|
27135
27911
|
});
|
|
27912
|
+
stage.on("pointermove", () => {
|
|
27913
|
+
if (this.state === TEXT_TOOL_STATE.IDLE) return;
|
|
27914
|
+
this.setCursor();
|
|
27915
|
+
});
|
|
27136
27916
|
stage.on("pointerclick", () => {
|
|
27137
27917
|
if (this.state === TEXT_TOOL_STATE.IDLE) return;
|
|
27138
27918
|
if (this.state === TEXT_TOOL_STATE.ADDING) {
|
|
@@ -27146,14 +27926,13 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
27146
27926
|
this.state = state;
|
|
27147
27927
|
}
|
|
27148
27928
|
addText() {
|
|
27149
|
-
const stage = this.instance.getStage();
|
|
27150
27929
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
27151
27930
|
if (selectionPlugin) {
|
|
27152
27931
|
const tr = selectionPlugin.getTransformer();
|
|
27153
27932
|
tr.hide();
|
|
27154
27933
|
}
|
|
27155
|
-
|
|
27156
|
-
|
|
27934
|
+
this.setCursor();
|
|
27935
|
+
this.setFocusStage();
|
|
27157
27936
|
this.instance.emitEvent("onAddingText");
|
|
27158
27937
|
this.clickPoint = null;
|
|
27159
27938
|
this.setState(TEXT_TOOL_STATE.ADDING);
|
|
@@ -27203,6 +27982,16 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
27203
27982
|
this.clickPoint = null;
|
|
27204
27983
|
this.setState(TEXT_TOOL_STATE.IDLE);
|
|
27205
27984
|
}
|
|
27985
|
+
setCursor() {
|
|
27986
|
+
const stage = this.instance.getStage();
|
|
27987
|
+
stage.container().style.cursor = "crosshair";
|
|
27988
|
+
}
|
|
27989
|
+
setFocusStage() {
|
|
27990
|
+
const stage = this.instance.getStage();
|
|
27991
|
+
stage.container().tabIndex = 1;
|
|
27992
|
+
stage.container().blur();
|
|
27993
|
+
stage.container().focus();
|
|
27994
|
+
}
|
|
27206
27995
|
};
|
|
27207
27996
|
|
|
27208
27997
|
//#endregion
|
|
@@ -27250,7 +28039,7 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
27250
28039
|
}
|
|
27251
28040
|
setupEvents() {
|
|
27252
28041
|
const stage = this.instance.getStage();
|
|
27253
|
-
|
|
28042
|
+
window.addEventListener("keydown", (e) => {
|
|
27254
28043
|
if (e.key === "Enter" && this.instance.getActiveAction() === STAR_TOOL_ACTION_NAME) {
|
|
27255
28044
|
this.cancelAction();
|
|
27256
28045
|
return;
|
|
@@ -27276,6 +28065,8 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
27276
28065
|
}
|
|
27277
28066
|
});
|
|
27278
28067
|
stage.on("pointermove", (e) => {
|
|
28068
|
+
if (this.state === STAR_TOOL_STATE.IDLE) return;
|
|
28069
|
+
this.setCursor();
|
|
27279
28070
|
if (!this.isPressed(e)) return;
|
|
27280
28071
|
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
27281
28072
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === STAR_TOOL_ACTION_NAME) {
|
|
@@ -27302,9 +28093,8 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
27302
28093
|
this.state = state;
|
|
27303
28094
|
}
|
|
27304
28095
|
addStar() {
|
|
27305
|
-
|
|
27306
|
-
|
|
27307
|
-
stage.container().focus();
|
|
28096
|
+
this.setCursor();
|
|
28097
|
+
this.setFocusStage();
|
|
27308
28098
|
this.instance.emitEvent("onAddingStar");
|
|
27309
28099
|
this.clickPoint = null;
|
|
27310
28100
|
this.setState(STAR_TOOL_STATE.ADDING);
|
|
@@ -27411,6 +28201,16 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
27411
28201
|
this.clickPoint = null;
|
|
27412
28202
|
this.setState(STAR_TOOL_STATE.IDLE);
|
|
27413
28203
|
}
|
|
28204
|
+
setCursor() {
|
|
28205
|
+
const stage = this.instance.getStage();
|
|
28206
|
+
stage.container().style.cursor = "crosshair";
|
|
28207
|
+
}
|
|
28208
|
+
setFocusStage() {
|
|
28209
|
+
const stage = this.instance.getStage();
|
|
28210
|
+
stage.container().tabIndex = 1;
|
|
28211
|
+
stage.container().blur();
|
|
28212
|
+
stage.container().focus();
|
|
28213
|
+
}
|
|
27414
28214
|
};
|
|
27415
28215
|
|
|
27416
28216
|
//#endregion
|
|
@@ -27463,7 +28263,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
27463
28263
|
}
|
|
27464
28264
|
setupEvents() {
|
|
27465
28265
|
const stage = this.instance.getStage();
|
|
27466
|
-
|
|
28266
|
+
window.addEventListener("keydown", (e) => {
|
|
27467
28267
|
if (e.key === "Enter" && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
|
|
27468
28268
|
this.cancelAction();
|
|
27469
28269
|
return;
|
|
@@ -27487,6 +28287,8 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
27487
28287
|
if (this.tempMainArrowNode && this.state === ARROW_TOOL_STATE.ADDING) this.state = ARROW_TOOL_STATE.DEFINING_SIZE;
|
|
27488
28288
|
});
|
|
27489
28289
|
stage.on("pointermove", () => {
|
|
28290
|
+
if (this.state === ARROW_TOOL_STATE.IDLE) return;
|
|
28291
|
+
this.setCursor();
|
|
27490
28292
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === ARROW_TOOL_ACTION_NAME) {
|
|
27491
28293
|
this.state = ARROW_TOOL_STATE.ADDING;
|
|
27492
28294
|
return;
|
|
@@ -27503,9 +28305,8 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
27503
28305
|
this.state = state;
|
|
27504
28306
|
}
|
|
27505
28307
|
addArrow() {
|
|
27506
|
-
|
|
27507
|
-
|
|
27508
|
-
stage.container().focus();
|
|
28308
|
+
this.setCursor();
|
|
28309
|
+
this.setFocusStage();
|
|
27509
28310
|
this.instance.emitEvent("onAddingArrow");
|
|
27510
28311
|
this.tempPoint = void 0;
|
|
27511
28312
|
this.tempNextPoint = void 0;
|
|
@@ -27658,6 +28459,16 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
27658
28459
|
this.clickPoint = null;
|
|
27659
28460
|
this.setState(ARROW_TOOL_STATE.IDLE);
|
|
27660
28461
|
}
|
|
28462
|
+
setCursor() {
|
|
28463
|
+
const stage = this.instance.getStage();
|
|
28464
|
+
stage.container().style.cursor = "crosshair";
|
|
28465
|
+
}
|
|
28466
|
+
setFocusStage() {
|
|
28467
|
+
const stage = this.instance.getStage();
|
|
28468
|
+
stage.container().tabIndex = 1;
|
|
28469
|
+
stage.container().blur();
|
|
28470
|
+
stage.container().focus();
|
|
28471
|
+
}
|
|
27661
28472
|
};
|
|
27662
28473
|
|
|
27663
28474
|
//#endregion
|
|
@@ -27703,7 +28514,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
27703
28514
|
}
|
|
27704
28515
|
setupEvents() {
|
|
27705
28516
|
const stage = this.instance.getStage();
|
|
27706
|
-
|
|
28517
|
+
window.addEventListener("keydown", (e) => {
|
|
27707
28518
|
if (e.key === "Enter" && this.instance.getActiveAction() === REGULAR_POLYGON_TOOL_ACTION_NAME) {
|
|
27708
28519
|
this.cancelAction();
|
|
27709
28520
|
return;
|
|
@@ -27729,6 +28540,8 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
27729
28540
|
}
|
|
27730
28541
|
});
|
|
27731
28542
|
stage.on("pointermove", (e) => {
|
|
28543
|
+
if (this.state === REGULAR_POLYGON_TOOL_STATE.IDLE) return;
|
|
28544
|
+
this.setCursor();
|
|
27732
28545
|
if (!this.isPressed(e)) return;
|
|
27733
28546
|
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
27734
28547
|
if (this.pointers.size === 2 && this.instance.getActiveAction() === REGULAR_POLYGON_TOOL_ACTION_NAME) {
|
|
@@ -27755,9 +28568,8 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
27755
28568
|
this.state = state;
|
|
27756
28569
|
}
|
|
27757
28570
|
addRegularPolygon() {
|
|
27758
|
-
|
|
27759
|
-
|
|
27760
|
-
stage.container().focus();
|
|
28571
|
+
this.setCursor();
|
|
28572
|
+
this.setFocusStage();
|
|
27761
28573
|
this.instance.emitEvent("onAddingRegularPolygon");
|
|
27762
28574
|
this.clickPoint = null;
|
|
27763
28575
|
this.setState(REGULAR_POLYGON_TOOL_STATE.ADDING);
|
|
@@ -27857,6 +28669,16 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
27857
28669
|
this.clickPoint = null;
|
|
27858
28670
|
this.setState(REGULAR_POLYGON_TOOL_STATE.IDLE);
|
|
27859
28671
|
}
|
|
28672
|
+
setCursor() {
|
|
28673
|
+
const stage = this.instance.getStage();
|
|
28674
|
+
stage.container().style.cursor = "crosshair";
|
|
28675
|
+
}
|
|
28676
|
+
setFocusStage() {
|
|
28677
|
+
const stage = this.instance.getStage();
|
|
28678
|
+
stage.container().tabIndex = 1;
|
|
28679
|
+
stage.container().blur();
|
|
28680
|
+
stage.container().focus();
|
|
28681
|
+
}
|
|
27860
28682
|
};
|
|
27861
28683
|
|
|
27862
28684
|
//#endregion
|
|
@@ -27894,12 +28716,16 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
27894
28716
|
}
|
|
27895
28717
|
setupEvents() {
|
|
27896
28718
|
const stage = this.instance.getStage();
|
|
27897
|
-
|
|
28719
|
+
window.addEventListener("keydown", (e) => {
|
|
27898
28720
|
if (e.key === "Escape" && this.instance.getActiveAction() === FRAME_TOOL_ACTION_NAME) {
|
|
27899
28721
|
this.cancelAction();
|
|
27900
28722
|
return;
|
|
27901
28723
|
}
|
|
27902
28724
|
});
|
|
28725
|
+
stage.on("pointermove", () => {
|
|
28726
|
+
if (this.state === FRAME_TOOL_STATE.IDLE) return;
|
|
28727
|
+
this.setCursor();
|
|
28728
|
+
});
|
|
27903
28729
|
stage.on("pointerclick", () => {
|
|
27904
28730
|
if (this.state === FRAME_TOOL_STATE.IDLE) return;
|
|
27905
28731
|
if (this.state === FRAME_TOOL_STATE.ADDING) {
|
|
@@ -27913,9 +28739,8 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
27913
28739
|
this.state = state;
|
|
27914
28740
|
}
|
|
27915
28741
|
addFrame() {
|
|
27916
|
-
|
|
27917
|
-
|
|
27918
|
-
stage.container().focus();
|
|
28742
|
+
this.setCursor();
|
|
28743
|
+
this.setFocusStage();
|
|
27919
28744
|
this.instance.emitEvent("onAddingFrame");
|
|
27920
28745
|
this.frameId = null;
|
|
27921
28746
|
this.clickPoint = null;
|
|
@@ -27968,6 +28793,16 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
27968
28793
|
this.clickPoint = null;
|
|
27969
28794
|
this.setState(FRAME_TOOL_STATE.IDLE);
|
|
27970
28795
|
}
|
|
28796
|
+
setCursor() {
|
|
28797
|
+
const stage = this.instance.getStage();
|
|
28798
|
+
stage.container().style.cursor = "crosshair";
|
|
28799
|
+
}
|
|
28800
|
+
setFocusStage() {
|
|
28801
|
+
const stage = this.instance.getStage();
|
|
28802
|
+
stage.container().tabIndex = 1;
|
|
28803
|
+
stage.container().blur();
|
|
28804
|
+
stage.container().focus();
|
|
28805
|
+
}
|
|
27971
28806
|
};
|
|
27972
28807
|
|
|
27973
28808
|
//#endregion
|
|
@@ -28315,6 +29150,271 @@ var WeaveAlignNodesToolAction = class extends WeaveAction {
|
|
|
28315
29150
|
}
|
|
28316
29151
|
};
|
|
28317
29152
|
|
|
29153
|
+
//#endregion
|
|
29154
|
+
//#region src/actions/comment-tool/constants.ts
|
|
29155
|
+
const WEAVE_COMMENT_TOOL_ACTION_NAME = "commentTool";
|
|
29156
|
+
const WEAVE_COMMENT_TOOL_LAYER_NAME = "commentsLayer";
|
|
29157
|
+
const WEAVE_COMMENT_TOOL_STATE = {
|
|
29158
|
+
["IDLE"]: "idle",
|
|
29159
|
+
["ADDING"]: "adding",
|
|
29160
|
+
["SELECTED_POSITION"]: "selectedPosition",
|
|
29161
|
+
["CREATING_COMMENT"]: "creatingComment",
|
|
29162
|
+
["ADDED"]: "added"
|
|
29163
|
+
};
|
|
29164
|
+
const WEAVE_COMMENT_TOOL_DEFAULT_CONFIG = { style: { cursor: {
|
|
29165
|
+
add: "crosshair",
|
|
29166
|
+
block: "not-allowed"
|
|
29167
|
+
} } };
|
|
29168
|
+
|
|
29169
|
+
//#endregion
|
|
29170
|
+
//#region src/plugins/comments-renderer/constants.ts
|
|
29171
|
+
const WEAVE_COMMENTS_RENDERER_KEY = "commentsRenderer";
|
|
29172
|
+
|
|
29173
|
+
//#endregion
|
|
29174
|
+
//#region src/actions/comment-tool/comment-tool.ts
|
|
29175
|
+
var WeaveCommentToolAction = class extends WeaveAction {
|
|
29176
|
+
initialized = false;
|
|
29177
|
+
onPropsChange = void 0;
|
|
29178
|
+
constructor(params) {
|
|
29179
|
+
super();
|
|
29180
|
+
const { config } = params ?? {};
|
|
29181
|
+
this.config = (0, import_lodash.merge)(WEAVE_COMMENT_TOOL_DEFAULT_CONFIG, config);
|
|
29182
|
+
this.pointers = new Map();
|
|
29183
|
+
this.initialized = false;
|
|
29184
|
+
this.state = WEAVE_COMMENT_TOOL_STATE.IDLE;
|
|
29185
|
+
this.commentId = null;
|
|
29186
|
+
this.clickPoint = null;
|
|
29187
|
+
}
|
|
29188
|
+
getName() {
|
|
29189
|
+
return WEAVE_COMMENT_TOOL_ACTION_NAME;
|
|
29190
|
+
}
|
|
29191
|
+
initProps() {
|
|
29192
|
+
return {
|
|
29193
|
+
colorToken: "#000000",
|
|
29194
|
+
width: 300,
|
|
29195
|
+
height: 300,
|
|
29196
|
+
opacity: 1
|
|
29197
|
+
};
|
|
29198
|
+
}
|
|
29199
|
+
extractCursorUrl(cursor) {
|
|
29200
|
+
const lower = cursor.toLowerCase();
|
|
29201
|
+
const start = lower.indexOf("url(");
|
|
29202
|
+
if (start === -1) return null;
|
|
29203
|
+
let i = start + 4;
|
|
29204
|
+
const len = cursor.length;
|
|
29205
|
+
while (i < len && /\s/.test(cursor[i])) i++;
|
|
29206
|
+
let quote = null;
|
|
29207
|
+
if (cursor[i] === "\"" || cursor[i] === "'") {
|
|
29208
|
+
quote = cursor[i];
|
|
29209
|
+
i++;
|
|
29210
|
+
}
|
|
29211
|
+
let buf = "";
|
|
29212
|
+
for (; i < len; i++) {
|
|
29213
|
+
const ch = cursor[i];
|
|
29214
|
+
if (quote) {
|
|
29215
|
+
if (ch === quote) {
|
|
29216
|
+
i++;
|
|
29217
|
+
break;
|
|
29218
|
+
}
|
|
29219
|
+
buf += ch;
|
|
29220
|
+
} else {
|
|
29221
|
+
if (ch === ")") break;
|
|
29222
|
+
buf += ch;
|
|
29223
|
+
}
|
|
29224
|
+
}
|
|
29225
|
+
const url = buf.trim();
|
|
29226
|
+
if (!url) return null;
|
|
29227
|
+
return this.isAllowedUrl(url) ? url : null;
|
|
29228
|
+
}
|
|
29229
|
+
isAllowedUrl(value) {
|
|
29230
|
+
if (/^https?:\/\//i.test(value)) return true;
|
|
29231
|
+
if (/^(javascript|data|blob|ftp):/i.test(value)) return false;
|
|
29232
|
+
return true;
|
|
29233
|
+
}
|
|
29234
|
+
preloadCursors() {
|
|
29235
|
+
const stage = this.instance.getStage();
|
|
29236
|
+
const cursorUrls = [{
|
|
29237
|
+
src: this.extractCursorUrl(this.config.style.cursor.add) ?? "",
|
|
29238
|
+
cursor: this.config.style.cursor.add
|
|
29239
|
+
}, {
|
|
29240
|
+
src: this.extractCursorUrl(this.config.style.cursor.block) ?? "",
|
|
29241
|
+
cursor: this.config.style.cursor.block
|
|
29242
|
+
}];
|
|
29243
|
+
const actualCursor = stage.container().style.cursor;
|
|
29244
|
+
cursorUrls.forEach(({ src, cursor }) => {
|
|
29245
|
+
const img = new Image();
|
|
29246
|
+
img.onload = () => {
|
|
29247
|
+
stage.container().style.cursor = cursor;
|
|
29248
|
+
stage.container().style.cursor = actualCursor;
|
|
29249
|
+
};
|
|
29250
|
+
img.src = src;
|
|
29251
|
+
});
|
|
29252
|
+
}
|
|
29253
|
+
onInit() {
|
|
29254
|
+
this.preloadCursors();
|
|
29255
|
+
const stage = this.instance.getStage();
|
|
29256
|
+
stage.on("pointermove", () => {
|
|
29257
|
+
if (this.state === WEAVE_COMMENT_TOOL_STATE.IDLE) return;
|
|
29258
|
+
this.setCursor();
|
|
29259
|
+
});
|
|
29260
|
+
this.instance.addEventListener("onCommentView", () => {
|
|
29261
|
+
if (this.instance.getActiveAction() !== WEAVE_COMMENT_TOOL_ACTION_NAME) return;
|
|
29262
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29263
|
+
});
|
|
29264
|
+
this.instance.addEventListener("onCommentFinishCreate", ({ action }) => {
|
|
29265
|
+
if (this.instance.getActiveAction() !== WEAVE_COMMENT_TOOL_ACTION_NAME) return;
|
|
29266
|
+
if (this.state !== WEAVE_COMMENT_TOOL_STATE.CREATING_COMMENT) {
|
|
29267
|
+
this.setCursor();
|
|
29268
|
+
return;
|
|
29269
|
+
}
|
|
29270
|
+
if (action !== "create") {
|
|
29271
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29272
|
+
this.setCursor();
|
|
29273
|
+
return;
|
|
29274
|
+
}
|
|
29275
|
+
this.setCursor();
|
|
29276
|
+
this.commentId = null;
|
|
29277
|
+
this.clickPoint = null;
|
|
29278
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29279
|
+
});
|
|
29280
|
+
}
|
|
29281
|
+
setupEvents() {
|
|
29282
|
+
const stage = this.instance.getStage();
|
|
29283
|
+
const commentNodeHandler = this.instance.getNodeHandler("comment");
|
|
29284
|
+
window.addEventListener("keydown", (e) => {
|
|
29285
|
+
if (this.instance.getActiveAction() !== WEAVE_COMMENT_TOOL_ACTION_NAME) return;
|
|
29286
|
+
if (commentNodeHandler?.isCommentViewing()) return;
|
|
29287
|
+
if (e.key === "Escape" && this.state == WEAVE_COMMENT_TOOL_STATE.ADDING) {
|
|
29288
|
+
this.cancelAction();
|
|
29289
|
+
return;
|
|
29290
|
+
}
|
|
29291
|
+
if (e.key === "Escape" && this.state === WEAVE_COMMENT_TOOL_STATE.CREATING_COMMENT) this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29292
|
+
});
|
|
29293
|
+
stage.on("pointermove", (e) => {
|
|
29294
|
+
if (this.state === WEAVE_COMMENT_TOOL_STATE.IDLE) return;
|
|
29295
|
+
if (commentNodeHandler?.isCommentViewing()) {
|
|
29296
|
+
this.setCursorBlock();
|
|
29297
|
+
return;
|
|
29298
|
+
}
|
|
29299
|
+
if (commentNodeHandler?.isCommentCreating()) {
|
|
29300
|
+
this.setCursorBlock();
|
|
29301
|
+
return;
|
|
29302
|
+
}
|
|
29303
|
+
const isCommentNode = this.isCommentNode(e.target);
|
|
29304
|
+
if (isCommentNode) return;
|
|
29305
|
+
this.setCursor();
|
|
29306
|
+
});
|
|
29307
|
+
stage.on("pointerdown", (e) => {
|
|
29308
|
+
this.setTapStart(e);
|
|
29309
|
+
this.pointers.set(e.evt.pointerId, {
|
|
29310
|
+
x: e.evt.clientX,
|
|
29311
|
+
y: e.evt.clientY
|
|
29312
|
+
});
|
|
29313
|
+
if (this.state === WEAVE_COMMENT_TOOL_STATE.IDLE) return;
|
|
29314
|
+
if (commentNodeHandler?.isCommentViewing()) return;
|
|
29315
|
+
if (commentNodeHandler?.isCommentCreating()) return;
|
|
29316
|
+
const isCommentNode = this.isCommentNode(e.target);
|
|
29317
|
+
if (!isCommentNode && this.pointers.size === 1 && this.instance.getActiveAction() === WEAVE_COMMENT_TOOL_ACTION_NAME && this.state === WEAVE_COMMENT_TOOL_STATE.ADDING) {
|
|
29318
|
+
this.setCursor();
|
|
29319
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.SELECTED_POSITION);
|
|
29320
|
+
return;
|
|
29321
|
+
}
|
|
29322
|
+
if (isCommentNode && this.instance.getActiveAction() === WEAVE_COMMENT_TOOL_ACTION_NAME) this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29323
|
+
});
|
|
29324
|
+
stage.on("pointerup", (e) => {
|
|
29325
|
+
this.pointers.delete(e.evt.pointerId);
|
|
29326
|
+
if (this.state === WEAVE_COMMENT_TOOL_STATE.IDLE) return;
|
|
29327
|
+
if (commentNodeHandler?.isCommentViewing()) return;
|
|
29328
|
+
const isCommentNode = this.isCommentNode(e.target);
|
|
29329
|
+
if (!isCommentNode && this.state === WEAVE_COMMENT_TOOL_STATE.SELECTED_POSITION) {
|
|
29330
|
+
this.handleAdding();
|
|
29331
|
+
e.cancelBubble = true;
|
|
29332
|
+
}
|
|
29333
|
+
if (isCommentNode && this.instance.getActiveAction() === WEAVE_COMMENT_TOOL_ACTION_NAME) this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29334
|
+
});
|
|
29335
|
+
this.initialized = true;
|
|
29336
|
+
}
|
|
29337
|
+
setState(state) {
|
|
29338
|
+
this.state = state;
|
|
29339
|
+
}
|
|
29340
|
+
enableAddingComment() {
|
|
29341
|
+
const commentNodeHandler = this.instance.getNodeHandler("comment");
|
|
29342
|
+
if (commentNodeHandler) {
|
|
29343
|
+
const commentVisible = commentNodeHandler?.isCommentViewing() || commentNodeHandler?.isCommentCreating();
|
|
29344
|
+
if (commentVisible) this.setCursorBlock();
|
|
29345
|
+
if (!commentVisible) this.setCursor();
|
|
29346
|
+
} else this.setCursor();
|
|
29347
|
+
this.instance.emitEvent("onStartAddingComment");
|
|
29348
|
+
this.commentId = null;
|
|
29349
|
+
this.clickPoint = null;
|
|
29350
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
29351
|
+
}
|
|
29352
|
+
handleAdding() {
|
|
29353
|
+
const { mousePoint } = this.instance.getMousePointer();
|
|
29354
|
+
this.clickPoint = mousePoint;
|
|
29355
|
+
this.commentId = v4_default();
|
|
29356
|
+
const nodeHandler = this.instance.getNodeHandler("comment");
|
|
29357
|
+
if (nodeHandler) {
|
|
29358
|
+
const node = nodeHandler.onRender({
|
|
29359
|
+
id: this.commentId,
|
|
29360
|
+
x: this.clickPoint.x,
|
|
29361
|
+
y: this.clickPoint.y,
|
|
29362
|
+
userForegroundColor: this.config.getUserForegroundColor(this.config.getUser()),
|
|
29363
|
+
userBackgroundColor: this.config.getUserBackgroundColor(this.config.getUser()),
|
|
29364
|
+
content: "",
|
|
29365
|
+
commentModel: this.config.model.getCreateModel()
|
|
29366
|
+
});
|
|
29367
|
+
node.moveToTop();
|
|
29368
|
+
this.getCommentsLayer()?.add(node);
|
|
29369
|
+
nodeHandler.onUpdate(node, { commentAction: WEAVE_COMMENT_NODE_ACTION.CREATING });
|
|
29370
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.CREATING_COMMENT);
|
|
29371
|
+
}
|
|
29372
|
+
}
|
|
29373
|
+
trigger(cancelAction) {
|
|
29374
|
+
if (!this.instance) throw new Error("Instance not defined");
|
|
29375
|
+
if (!this.initialized) this.setupEvents();
|
|
29376
|
+
const stage = this.instance.getStage();
|
|
29377
|
+
stage.container().tabIndex = 1;
|
|
29378
|
+
stage.container().focus();
|
|
29379
|
+
this.cancelAction = cancelAction;
|
|
29380
|
+
this.props = this.initProps();
|
|
29381
|
+
this.enableAddingComment();
|
|
29382
|
+
}
|
|
29383
|
+
cleanup() {
|
|
29384
|
+
const stage = this.instance.getStage();
|
|
29385
|
+
stage.container().style.cursor = "default";
|
|
29386
|
+
this.instance.emitEvent("onFinishAddingComment");
|
|
29387
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
29388
|
+
if (selectionPlugin) {
|
|
29389
|
+
const node = stage.findOne(`#${this.commentId}`);
|
|
29390
|
+
if (node) selectionPlugin.setSelectedNodes([node]);
|
|
29391
|
+
this.instance.triggerAction("selectionTool");
|
|
29392
|
+
}
|
|
29393
|
+
this.commentId = null;
|
|
29394
|
+
this.clickPoint = null;
|
|
29395
|
+
this.setState(WEAVE_COMMENT_TOOL_STATE.IDLE);
|
|
29396
|
+
}
|
|
29397
|
+
getCommentsLayer() {
|
|
29398
|
+
const commentsRendererPlugin = this.instance.getPlugin(WEAVE_COMMENTS_RENDERER_KEY);
|
|
29399
|
+
if (commentsRendererPlugin) return commentsRendererPlugin.getCommentsLayer();
|
|
29400
|
+
return null;
|
|
29401
|
+
}
|
|
29402
|
+
isCommentNode(node) {
|
|
29403
|
+
if (node.getAttrs().name?.includes("comment")) return true;
|
|
29404
|
+
if (node.getParent() && node.getParent() === this.instance.getStage()) return false;
|
|
29405
|
+
if (node.getParent() && node.getParent() !== this.instance.getStage()) return this.isCommentNode(node.getParent());
|
|
29406
|
+
return false;
|
|
29407
|
+
}
|
|
29408
|
+
setCursor() {
|
|
29409
|
+
const stage = this.instance.getStage();
|
|
29410
|
+
stage.container().style.cursor = this.config.style.cursor.add;
|
|
29411
|
+
}
|
|
29412
|
+
setCursorBlock() {
|
|
29413
|
+
const stage = this.instance.getStage();
|
|
29414
|
+
stage.container().style.cursor = this.config.style.cursor.block;
|
|
29415
|
+
}
|
|
29416
|
+
};
|
|
29417
|
+
|
|
28318
29418
|
//#endregion
|
|
28319
29419
|
//#region src/plugins/stage-grid/stage-grid.ts
|
|
28320
29420
|
var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
@@ -28707,7 +29807,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
28707
29807
|
const shadowHost = getTopmostShadowHost(stage.container());
|
|
28708
29808
|
if (shadowHost) elementUnderMouse = shadowHost.elementFromPoint(mouseX, mouseY);
|
|
28709
29809
|
}
|
|
28710
|
-
if (!this.enabled || this.isCtrlOrMetaPressed || e.buttons === 4 || !performPanning ||
|
|
29810
|
+
if (!this.enabled || this.isCtrlOrMetaPressed || e.buttons === 4 || !performPanning || this.instance.getClosestParentWithWeaveId(elementUnderMouse) !== stage.container()) return;
|
|
28711
29811
|
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
28712
29812
|
stage.x(stage.x() - e.deltaX);
|
|
28713
29813
|
stage.y(stage.y() - e.deltaY);
|
|
@@ -30083,6 +31183,95 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
30083
31183
|
}
|
|
30084
31184
|
};
|
|
30085
31185
|
|
|
31186
|
+
//#endregion
|
|
31187
|
+
//#region src/plugins/comments-renderer/comments-renderer.ts
|
|
31188
|
+
var WeaveCommentsRendererPlugin = class extends WeavePlugin {
|
|
31189
|
+
comments = [];
|
|
31190
|
+
getLayerName = void 0;
|
|
31191
|
+
constructor(params) {
|
|
31192
|
+
super();
|
|
31193
|
+
const { config } = params ?? {};
|
|
31194
|
+
this.config = config;
|
|
31195
|
+
this.comments = [];
|
|
31196
|
+
}
|
|
31197
|
+
getName() {
|
|
31198
|
+
return WEAVE_COMMENTS_RENDERER_KEY;
|
|
31199
|
+
}
|
|
31200
|
+
onInit() {}
|
|
31201
|
+
setComments(comments) {
|
|
31202
|
+
this.comments = comments;
|
|
31203
|
+
}
|
|
31204
|
+
initCommentsLayer() {
|
|
31205
|
+
const stage = this.instance.getStage();
|
|
31206
|
+
const commentsLayer = new konva.default.Layer({ id: WEAVE_COMMENT_TOOL_LAYER_NAME });
|
|
31207
|
+
stage.add(commentsLayer);
|
|
31208
|
+
const selectionLayer = this.instance.getSelectionLayer();
|
|
31209
|
+
if (selectionLayer) {
|
|
31210
|
+
const selectionLayerZIndex = selectionLayer.getZIndex();
|
|
31211
|
+
commentsLayer.setZIndex(selectionLayerZIndex + 1);
|
|
31212
|
+
}
|
|
31213
|
+
return commentsLayer;
|
|
31214
|
+
}
|
|
31215
|
+
deleteComments() {
|
|
31216
|
+
const commentsLayer = this.getCommentsLayer();
|
|
31217
|
+
if (commentsLayer) commentsLayer.destroyChildren();
|
|
31218
|
+
}
|
|
31219
|
+
render() {
|
|
31220
|
+
if (!this.isEnabled()) return;
|
|
31221
|
+
this.deleteComments();
|
|
31222
|
+
const resolved = this.comments.filter((comment) => this.config.model.getStatus(comment) === WEAVE_COMMENT_STATUS.RESOLVED);
|
|
31223
|
+
for (let i = 0; i < resolved.length; i++) {
|
|
31224
|
+
const comment = resolved[i];
|
|
31225
|
+
const commentsNodeHandler = this.instance.getNodeHandler(WEAVE_COMMENT_NODE_TYPE);
|
|
31226
|
+
if (commentsNodeHandler) {
|
|
31227
|
+
const node = commentsNodeHandler.onRender({
|
|
31228
|
+
id: this.config.model.getId(comment),
|
|
31229
|
+
x: this.config.model.getPosition(comment).x,
|
|
31230
|
+
y: this.config.model.getPosition(comment).y,
|
|
31231
|
+
userForegroundColor: this.config.getUserForegroundColor(this.config.model.getUser(comment)),
|
|
31232
|
+
userBackgroundColor: this.config.getUserBackgroundColor(this.config.model.getUser(comment)),
|
|
31233
|
+
commentModel: comment
|
|
31234
|
+
});
|
|
31235
|
+
node.moveToBottom();
|
|
31236
|
+
this.getCommentsLayer()?.add(node);
|
|
31237
|
+
commentsNodeHandler.onUpdate(node, { commentAction: "idle" });
|
|
31238
|
+
}
|
|
31239
|
+
}
|
|
31240
|
+
const pending = this.comments.filter((comment) => this.config.model.getStatus(comment) === WEAVE_COMMENT_STATUS.PENDING);
|
|
31241
|
+
for (let i = 0; i < pending.length; i++) {
|
|
31242
|
+
const comment = pending[i];
|
|
31243
|
+
const commentsNodeHandler = this.instance.getNodeHandler(WEAVE_COMMENT_NODE_TYPE);
|
|
31244
|
+
if (commentsNodeHandler) {
|
|
31245
|
+
const node = commentsNodeHandler.onRender({
|
|
31246
|
+
id: this.config.model.getId(comment),
|
|
31247
|
+
x: this.config.model.getPosition(comment).x,
|
|
31248
|
+
y: this.config.model.getPosition(comment).y,
|
|
31249
|
+
userForegroundColor: this.config.getUserForegroundColor(this.config.model.getUser(comment)),
|
|
31250
|
+
userBackgroundColor: this.config.getUserBackgroundColor(this.config.model.getUser(comment)),
|
|
31251
|
+
commentModel: comment
|
|
31252
|
+
});
|
|
31253
|
+
node.moveToTop();
|
|
31254
|
+
this.getCommentsLayer()?.add(node);
|
|
31255
|
+
commentsNodeHandler.onUpdate(node, { commentAction: "idle" });
|
|
31256
|
+
}
|
|
31257
|
+
}
|
|
31258
|
+
}
|
|
31259
|
+
getCommentsLayer() {
|
|
31260
|
+
const commentsLayerId = `#${WEAVE_COMMENT_TOOL_LAYER_NAME}`;
|
|
31261
|
+
const commentLayer = this.instance.getStage()?.findOne(commentsLayerId);
|
|
31262
|
+
if (!commentLayer) return this.initCommentsLayer();
|
|
31263
|
+
return commentLayer;
|
|
31264
|
+
}
|
|
31265
|
+
enable() {
|
|
31266
|
+
this.enabled = true;
|
|
31267
|
+
this.render();
|
|
31268
|
+
}
|
|
31269
|
+
disable() {
|
|
31270
|
+
this.enabled = false;
|
|
31271
|
+
this.deleteComments();
|
|
31272
|
+
}
|
|
31273
|
+
};
|
|
31274
|
+
|
|
30086
31275
|
//#endregion
|
|
30087
31276
|
exports.ALIGN_NODES_ALIGN_TO = ALIGN_NODES_ALIGN_TO
|
|
30088
31277
|
exports.ALIGN_NODES_TOOL_ACTION_NAME = ALIGN_NODES_TOOL_ACTION_NAME
|
|
@@ -30130,6 +31319,17 @@ exports.TEXT_LAYOUT = TEXT_LAYOUT
|
|
|
30130
31319
|
exports.TEXT_TOOL_ACTION_NAME = TEXT_TOOL_ACTION_NAME
|
|
30131
31320
|
exports.TEXT_TOOL_STATE = TEXT_TOOL_STATE
|
|
30132
31321
|
exports.WEAVE_ARROW_NODE_TYPE = WEAVE_ARROW_NODE_TYPE
|
|
31322
|
+
exports.WEAVE_COMMENTS_RENDERER_KEY = WEAVE_COMMENTS_RENDERER_KEY
|
|
31323
|
+
exports.WEAVE_COMMENT_CREATE_ACTION = WEAVE_COMMENT_CREATE_ACTION
|
|
31324
|
+
exports.WEAVE_COMMENT_NODE_ACTION = WEAVE_COMMENT_NODE_ACTION
|
|
31325
|
+
exports.WEAVE_COMMENT_NODE_DEFAULTS = WEAVE_COMMENT_NODE_DEFAULTS
|
|
31326
|
+
exports.WEAVE_COMMENT_NODE_TYPE = WEAVE_COMMENT_NODE_TYPE
|
|
31327
|
+
exports.WEAVE_COMMENT_STATUS = WEAVE_COMMENT_STATUS
|
|
31328
|
+
exports.WEAVE_COMMENT_TOOL_ACTION_NAME = WEAVE_COMMENT_TOOL_ACTION_NAME
|
|
31329
|
+
exports.WEAVE_COMMENT_TOOL_DEFAULT_CONFIG = WEAVE_COMMENT_TOOL_DEFAULT_CONFIG
|
|
31330
|
+
exports.WEAVE_COMMENT_TOOL_LAYER_NAME = WEAVE_COMMENT_TOOL_LAYER_NAME
|
|
31331
|
+
exports.WEAVE_COMMENT_TOOL_STATE = WEAVE_COMMENT_TOOL_STATE
|
|
31332
|
+
exports.WEAVE_COMMENT_VIEW_ACTION = WEAVE_COMMENT_VIEW_ACTION
|
|
30133
31333
|
exports.WEAVE_COPY_PASTE_CONFIG_DEFAULT = WEAVE_COPY_PASTE_CONFIG_DEFAULT
|
|
30134
31334
|
exports.WEAVE_COPY_PASTE_NODES_KEY = WEAVE_COPY_PASTE_NODES_KEY
|
|
30135
31335
|
exports.WEAVE_COPY_PASTE_PASTE_CATCHER_ID = WEAVE_COPY_PASTE_PASTE_CATCHER_ID
|
|
@@ -30153,6 +31353,7 @@ exports.WEAVE_GRID_LAYER_ID = WEAVE_GRID_LAYER_ID
|
|
|
30153
31353
|
exports.WEAVE_GRID_TYPES = WEAVE_GRID_TYPES
|
|
30154
31354
|
exports.WEAVE_GROUP_NODE_TYPE = WEAVE_GROUP_NODE_TYPE
|
|
30155
31355
|
exports.WEAVE_IMAGE_CROP_END_TYPE = WEAVE_IMAGE_CROP_END_TYPE
|
|
31356
|
+
exports.WEAVE_IMAGE_DEFAULT_CONFIG = WEAVE_IMAGE_DEFAULT_CONFIG
|
|
30156
31357
|
exports.WEAVE_IMAGE_NODE_TYPE = WEAVE_IMAGE_NODE_TYPE
|
|
30157
31358
|
exports.WEAVE_LAYER_NODE_TYPE = WEAVE_LAYER_NODE_TYPE
|
|
30158
31359
|
exports.WEAVE_LINE_NODE_TYPE = WEAVE_LINE_NODE_TYPE
|
|
@@ -30181,6 +31382,9 @@ exports.WeaveAlignNodesToolAction = WeaveAlignNodesToolAction
|
|
|
30181
31382
|
exports.WeaveArrowNode = WeaveArrowNode
|
|
30182
31383
|
exports.WeaveArrowToolAction = WeaveArrowToolAction
|
|
30183
31384
|
exports.WeaveBrushToolAction = WeaveBrushToolAction
|
|
31385
|
+
exports.WeaveCommentNode = WeaveCommentNode
|
|
31386
|
+
exports.WeaveCommentToolAction = WeaveCommentToolAction
|
|
31387
|
+
exports.WeaveCommentsRendererPlugin = WeaveCommentsRendererPlugin
|
|
30184
31388
|
exports.WeaveConnectedUsersPlugin = WeaveConnectedUsersPlugin
|
|
30185
31389
|
exports.WeaveContextMenuPlugin = WeaveContextMenuPlugin
|
|
30186
31390
|
exports.WeaveCopyPasteNodesPlugin = WeaveCopyPasteNodesPlugin
|
|
@@ -30230,7 +31434,6 @@ exports.clearContainerTargets = clearContainerTargets
|
|
|
30230
31434
|
exports.containerOverCursor = containerOverCursor
|
|
30231
31435
|
exports.containsNodeDeep = containsNodeDeep
|
|
30232
31436
|
exports.getBoundingBox = getBoundingBox
|
|
30233
|
-
exports.getClosestParentWithId = getClosestParentWithId
|
|
30234
31437
|
exports.getExportBoundingBox = getExportBoundingBox
|
|
30235
31438
|
exports.getSelectedNodesMetadata = getSelectedNodesMetadata
|
|
30236
31439
|
exports.getTargetAndSkipNodes = getTargetAndSkipNodes
|