@univerjs/sheets-thread-comment 0.20.1 → 0.21.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/lib/cjs/facade.js +1020 -1
- package/lib/cjs/index.js +650 -1
- package/lib/es/facade.js +1014 -1
- package/lib/es/index.js +632 -1
- package/lib/facade.js +1014 -1
- package/lib/index.js +632 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1,1020 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-thread-comment`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/thread-comment`),i=require(`@univerjs/engine-formula`),a=require(`rxjs`),o=require(`@univerjs/core/facade`);function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var p,m=class t{static create(e){return new t(e)}constructor(t){u(this,`_comment`,{id:(0,e.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:e.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),t&&(this._comment=t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return e.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return h.create(e.Tools.deepClone(this._comment))}},h=class t extends m{static create(e){return new t(e)}setContent(t){return t instanceof e.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=(0,r.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let g=p=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,i.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(p,e))}getRange(){let t=this._univerInstanceService.getUnit(this._thread.unitId,e.UniverInstanceType.UNIVER_SHEET);if(!t)return null;let r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;let i=this._getRef();return this._injector.createInstance(n.FRange,t,r,i)}getContent(){return this._thread.text}getRichText(){let t=this._thread.text;return e.RichTextValue.create({body:t,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?r.DeleteCommentTreeCommand.id:r.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(t){let n=t instanceof e.RichTextValue?t.getData().body:t,i=(0,r.getDT)();return await this._commandService.executeCommand(r.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:i}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(r.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(t){var n;let i=t.build();return this._commandService.executeCommand(r.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,e.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:i.text,attachments:i.attachments,dT:i.dT||(0,r.getDT)(),personId:i.personId||this._userManagerService.getCurrentUser().userID}})}};g=p=f([d(2,(0,e.Inject)(e.Injector)),d(3,e.ICommandService),d(4,e.IUniverInstanceService),d(5,(0,e.Inject)(t.SheetsThreadCommentModel)),d(6,(0,e.Inject)(e.UserManagerService))],g);var _=class extends n.FRange{getComment(){let e=this._injector.get(t.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(n,r,i);return a?this._injector.createInstance(g,a):null}getComments(){let n=this._injector.get(t.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return e.Range.foreach(this._range,(e,t)=>{let o=n.getByLocation(r,i,e,t);if(o){let e=n.getComment(r,i,o);e&&a.push(this._injector.createInstance(g,e))}}),a}addComment(t){var n;let i=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=i.get(e.ICommandService),s=i.get(e.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${e.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=t instanceof h?t.build():{text:t};return o.executeCommand(r.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,r.getDT)(),attachments:[],id:f.id||(0,e.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,e.generateRandomId)()}})}clearComment(){var t;let n=this._injector,i=(t=this.getComment())==null?void 0:t.getCommentData(),a=n.get(e.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return i?a.executeCommand(r.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:i.threadId,commentId:i.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};n.FRange.extend(_);var v=class extends n.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(r.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(g,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(t){return(0,e.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,a.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.AddCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.UpdateCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.DeleteCommentCommand.id||e.id===r.DeleteCommentTreeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};n.FWorkbook.extend(v);var y=class extends n.FWorksheet{getComments(){return this._injector.get(t.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(g,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(t){return this._injector.get(e.ICommandService).onCommandExecuted(e=>{if(e.id===r.AddCommentCommand.id){let n=e.params;t(n)}})}getCommentById(e){let n=this._injector.get(t.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(g,n)}};n.FWorksheet.extend(y);var b=class extends o.FEventName{get CommentAdded(){return`CommentAdded`}get BeforeCommentAdd(){return`BeforeCommentAdd`}get CommentUpdated(){return`CommentUpdated`}get BeforeCommentUpdate(){return`BeforeCommentUpdate`}get CommentDeleted(){return`CommentDeleted`}get BeforeCommentDelete(){return`BeforeCommentDelete`}get CommentResolved(){return`CommentResolved`}get BeforeCommentResolve(){return`BeforeCommentResolve`}};o.FEventName.extend(b);var x=class extends o.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(t){let n=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.AddCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{comment:l}=e.params,u=c.getCommentById(l.id);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};this.fireEvent(this.Event.CommentAdded,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.UpdateCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{payload:l}=e.params,u=c.getCommentById(l.commentId);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};this.fireEvent(this.Event.CommentUpdated,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==r.DeleteCommentCommand.id&&e.id!==r.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a}=e.params,o={workbook:n,worksheet:i,commentId:a};this.fireEvent(this.Event.CommentDeleted,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.ResolveCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l,resolved:u}=e.params,d=c.getCommentById(l);if(!d)return;let f={workbook:s,worksheet:c,row:(t=(n=d.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=d.getRange())==null?void 0:a.getColumn())==null?0:i,comment:d,resolved:u};this.fireEvent(this.Event.CommentResolved,f)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.AddCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:a,worksheet:o}=n,{comment:s}=t.params,{range:c}=(0,i.deserializeRangeWithSheet)(s.ref),l={workbook:a,worksheet:o,row:c.startRow,col:c.startColumn,comment:m.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{var n,i,a,o;if(t.id!==r.UpdateCommentCommand.id)return;let s=this._getTargetSheet(t.params);if(!s)return;let{workbook:c,worksheet:l}=s,{payload:u}=t.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(i=d.getRange())==null?void 0:i.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d,newContent:e.RichTextValue.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{var n,i,a,o;if(t.id!==r.DeleteCommentCommand.id&&t.id!==r.DeleteCommentTreeCommand.id)return;let s=this._getTargetSheet(t.params);if(!s)return;let{workbook:c,worksheet:l}=s,{commentId:u}=t.params,d=l.getCommentById(u);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(i=d.getRange())==null?void 0:i.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d};if(this.fireEvent(this.Event.BeforeCommentDelete,f),f.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{var n,i;if(t.id!==r.ResolveCommentCommand.id)return;let a=this._getTargetSheet(t.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=t.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(n=u.getRange().getRow())==null?0:n,col:(i=u.getRange().getColumn())==null?0:i,comment:u,resolved:l};if(this.fireEvent(this.Event.BeforeCommentResolve,d),d.cancel)throw new e.CanceledError})))}newTheadComment(e){return new h(e)}};o.FUniver.extend(x),Object.defineProperty(exports,`FThreadComment`,{enumerable:!0,get:function(){return g}});
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_sheets_thread_comment = require("@univerjs/sheets-thread-comment");
|
|
4
|
+
let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
|
|
5
|
+
let _univerjs_thread_comment = require("@univerjs/thread-comment");
|
|
6
|
+
let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
7
|
+
let rxjs = require("rxjs");
|
|
8
|
+
let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
9
|
+
|
|
10
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
11
|
+
function _typeof(o) {
|
|
12
|
+
"@babel/helpers - typeof";
|
|
13
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
14
|
+
return typeof o;
|
|
15
|
+
} : function(o) {
|
|
16
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
17
|
+
}, _typeof(o);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
22
|
+
function toPrimitive(t, r) {
|
|
23
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
24
|
+
var e = t[Symbol.toPrimitive];
|
|
25
|
+
if (void 0 !== e) {
|
|
26
|
+
var i = e.call(t, r || "default");
|
|
27
|
+
if ("object" != _typeof(i)) return i;
|
|
28
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
29
|
+
}
|
|
30
|
+
return ("string" === r ? String : Number)(t);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
35
|
+
function toPropertyKey(t) {
|
|
36
|
+
var i = toPrimitive(t, "string");
|
|
37
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
42
|
+
function _defineProperty(e, r, t) {
|
|
43
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
44
|
+
value: t,
|
|
45
|
+
enumerable: !0,
|
|
46
|
+
configurable: !0,
|
|
47
|
+
writable: !0
|
|
48
|
+
}) : e[r] = t, e;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
53
|
+
function __decorateParam(paramIndex, decorator) {
|
|
54
|
+
return function(target, key) {
|
|
55
|
+
decorator(target, key, paramIndex);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
61
|
+
function __decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
64
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
65
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/facade/f-thread-comment.ts
|
|
70
|
+
var _FThreadComment;
|
|
71
|
+
/**
|
|
72
|
+
* An readonly class that represents a comment.
|
|
73
|
+
* @ignore
|
|
74
|
+
*/
|
|
75
|
+
var FTheadCommentItem = class FTheadCommentItem {
|
|
76
|
+
/**
|
|
77
|
+
* Create a new FTheadCommentItem
|
|
78
|
+
* @param {IThreadComment|undefined} comment The comment
|
|
79
|
+
* @returns {FTheadCommentItem} A new instance of FTheadCommentItem
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
83
|
+
* console.log(commentBuilder);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
static create(comment) {
|
|
87
|
+
return new FTheadCommentItem(comment);
|
|
88
|
+
}
|
|
89
|
+
constructor(comment) {
|
|
90
|
+
_defineProperty(this, "_comment", {
|
|
91
|
+
id: (0, _univerjs_core.generateRandomId)(),
|
|
92
|
+
ref: "",
|
|
93
|
+
threadId: "",
|
|
94
|
+
dT: "",
|
|
95
|
+
personId: "",
|
|
96
|
+
text: _univerjs_core.RichTextBuilder.newEmptyData().body,
|
|
97
|
+
attachments: [],
|
|
98
|
+
unitId: "",
|
|
99
|
+
subUnitId: ""
|
|
100
|
+
});
|
|
101
|
+
if (comment) this._comment = comment;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the person id of the comment
|
|
105
|
+
* @returns {string} The person id of the comment
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
109
|
+
* console.log(commentBuilder.personId);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
get personId() {
|
|
113
|
+
return this._comment.personId;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the date time of the comment
|
|
117
|
+
* @returns {string} The date time of the comment
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
121
|
+
* console.log(commentBuilder.dateTime);
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
get dateTime() {
|
|
125
|
+
return this._comment.dT;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the content of the comment
|
|
129
|
+
* @returns {RichTextValue} The content of the comment
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
133
|
+
* console.log(commentBuilder.content);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
get content() {
|
|
137
|
+
return _univerjs_core.RichTextValue.createByBody(this._comment.text);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the id of the comment
|
|
141
|
+
* @returns {string} The id of the comment
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
145
|
+
* console.log(commentBuilder.id);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
get id() {
|
|
149
|
+
return this._comment.id;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the thread id of the comment
|
|
153
|
+
* @returns {string} The thread id of the comment
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
157
|
+
* console.log(commentBuilder.threadId);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
get threadId() {
|
|
161
|
+
return this._comment.threadId;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Copy the comment
|
|
165
|
+
* @returns {FTheadCommentBuilder} The comment builder
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const commentBuilder = univerAPI.newTheadComment();
|
|
169
|
+
* const newCommentBuilder = commentBuilder.copy();
|
|
170
|
+
* console.log(newCommentBuilder);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
copy() {
|
|
174
|
+
return FTheadCommentBuilder.create(_univerjs_core.Tools.deepClone(this._comment));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* A builder for thread comment. use {@link FUniver} `univerAPI.newTheadComment()` to create a new builder.
|
|
179
|
+
*/
|
|
180
|
+
var FTheadCommentBuilder = class FTheadCommentBuilder extends FTheadCommentItem {
|
|
181
|
+
static create(comment) {
|
|
182
|
+
return new FTheadCommentBuilder(comment);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Set the content of the comment
|
|
186
|
+
* @param {IDocumentBody | RichTextValue} content The content of the comment
|
|
187
|
+
* @returns {FTheadCommentBuilder} The comment builder for chaining
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* // Create a new comment
|
|
191
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
192
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
193
|
+
* .setContent(richText);
|
|
194
|
+
* console.log(commentBuilder.content);
|
|
195
|
+
*
|
|
196
|
+
* // Add the comment to the cell A1
|
|
197
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
198
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
199
|
+
* const cell = fWorksheet.getRange('A1');
|
|
200
|
+
* const result = await cell.addCommentAsync(commentBuilder);
|
|
201
|
+
* console.log(result);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
setContent(content) {
|
|
205
|
+
if (content instanceof _univerjs_core.RichTextValue) this._comment.text = content.getData().body;
|
|
206
|
+
else this._comment.text = content;
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Set the person id of the comment
|
|
211
|
+
* @param {string} userId The person id of the comment
|
|
212
|
+
* @returns {FTheadCommentBuilder} The comment builder for chaining
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* // Create a new comment
|
|
216
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
217
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
218
|
+
* .setContent(richText)
|
|
219
|
+
* .setPersonId('mock-user-id');
|
|
220
|
+
* console.log(commentBuilder.personId);
|
|
221
|
+
*
|
|
222
|
+
* // Add the comment to the cell A1
|
|
223
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
224
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
225
|
+
* const cell = fWorksheet.getRange('A1');
|
|
226
|
+
* const result = await cell.addCommentAsync(commentBuilder);
|
|
227
|
+
* console.log(result);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
setPersonId(userId) {
|
|
231
|
+
this._comment.personId = userId;
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Set the date time of the comment
|
|
236
|
+
* @param {Date} date The date time of the comment
|
|
237
|
+
* @returns {FTheadCommentBuilder} The comment builder for chaining
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* // Create a new comment
|
|
241
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
242
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
243
|
+
* .setContent(richText)
|
|
244
|
+
* .setDateTime(new Date('2025-02-21 14:22:22'));
|
|
245
|
+
* console.log(commentBuilder.dateTime);
|
|
246
|
+
*
|
|
247
|
+
* // Add the comment to the cell A1
|
|
248
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
249
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
250
|
+
* const cell = fWorksheet.getRange('A1');
|
|
251
|
+
* const result = await cell.addCommentAsync(commentBuilder);
|
|
252
|
+
* console.log(result);
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
setDateTime(date) {
|
|
256
|
+
this._comment.dT = (0, _univerjs_thread_comment.getDT)(date);
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Set the id of the comment
|
|
261
|
+
* @param {string} id The id of the comment
|
|
262
|
+
* @returns {FTheadCommentBuilder} The comment builder for chaining
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* // Create a new comment
|
|
266
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
267
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
268
|
+
* .setContent(richText)
|
|
269
|
+
* .setId('mock-comment-id');
|
|
270
|
+
* console.log(commentBuilder.id);
|
|
271
|
+
*
|
|
272
|
+
* // Add the comment to the cell A1
|
|
273
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
274
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
275
|
+
* const cell = fWorksheet.getRange('A1');
|
|
276
|
+
* const result = await cell.addCommentAsync(commentBuilder);
|
|
277
|
+
* console.log(result);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
setId(id) {
|
|
281
|
+
this._comment.id = id;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Set the thread id of the comment
|
|
286
|
+
* @param {string} threadId The thread id of the comment
|
|
287
|
+
* @returns {FTheadCommentBuilder} The comment builder
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* // Create a new comment
|
|
291
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
292
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
293
|
+
* .setContent(richText)
|
|
294
|
+
* .setThreadId('mock-thread-id');
|
|
295
|
+
* console.log(commentBuilder.threadId);
|
|
296
|
+
*
|
|
297
|
+
* // Add the comment to the cell A1
|
|
298
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
299
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
300
|
+
* const cell = fWorksheet.getRange('A1');
|
|
301
|
+
* const result = await cell.addCommentAsync(commentBuilder);
|
|
302
|
+
* console.log(result);
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
setThreadId(threadId) {
|
|
306
|
+
this._comment.threadId = threadId;
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Build the comment
|
|
311
|
+
* @returns {IThreadComment} The comment
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
315
|
+
* const comment = univerAPI.newTheadComment()
|
|
316
|
+
* .setContent(richText)
|
|
317
|
+
* .setPersonId('mock-user-id')
|
|
318
|
+
* .setDateTime(new Date('2025-02-21 14:22:22'))
|
|
319
|
+
* .setId('mock-comment-id')
|
|
320
|
+
* .setThreadId('mock-thread-id')
|
|
321
|
+
* .build();
|
|
322
|
+
* console.log(comment);
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
build() {
|
|
326
|
+
return this._comment;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
let FThreadComment = _FThreadComment = class FThreadComment {
|
|
330
|
+
/**
|
|
331
|
+
* @ignore
|
|
332
|
+
*/
|
|
333
|
+
constructor(_thread, _parent, _injector, _commandService, _univerInstanceService, _threadCommentModel, _userManagerService) {
|
|
334
|
+
this._thread = _thread;
|
|
335
|
+
this._parent = _parent;
|
|
336
|
+
this._injector = _injector;
|
|
337
|
+
this._commandService = _commandService;
|
|
338
|
+
this._univerInstanceService = _univerInstanceService;
|
|
339
|
+
this._threadCommentModel = _threadCommentModel;
|
|
340
|
+
this._userManagerService = _userManagerService;
|
|
341
|
+
}
|
|
342
|
+
_getRef() {
|
|
343
|
+
var _this$_parent;
|
|
344
|
+
return (0, _univerjs_engine_formula.deserializeRangeWithSheet)(((_this$_parent = this._parent) === null || _this$_parent === void 0 ? void 0 : _this$_parent.ref) || this._thread.ref).range;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Whether the comment is a root comment
|
|
348
|
+
* @returns {boolean} Whether the comment is a root comment
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
352
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
353
|
+
* const comments = fWorksheet.getComments();
|
|
354
|
+
* comments.forEach((comment) => {
|
|
355
|
+
* console.log(comment.getIsRoot());
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
getIsRoot() {
|
|
360
|
+
return !this._parent;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Get the comment data
|
|
364
|
+
* @returns {IBaseComment} The comment data
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
368
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
369
|
+
* const comments = fWorksheet.getComments();
|
|
370
|
+
* comments.forEach((comment) => {
|
|
371
|
+
* console.log(comment.getCommentData());
|
|
372
|
+
* });
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
getCommentData() {
|
|
376
|
+
const { children, ...comment } = this._thread;
|
|
377
|
+
return comment;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Get the replies of the comment
|
|
381
|
+
* @returns {FThreadComment[]} the replies of the comment
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
385
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
386
|
+
* const comments = fWorksheet.getComments();
|
|
387
|
+
* comments.forEach((comment) => {
|
|
388
|
+
* if (comment.getIsRoot()) {
|
|
389
|
+
* const replies = comment.getReplies();
|
|
390
|
+
* replies.forEach((reply) => {
|
|
391
|
+
* console.log(reply.getCommentData());
|
|
392
|
+
* });
|
|
393
|
+
* }
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
getReplies() {
|
|
398
|
+
var _comments$children;
|
|
399
|
+
const range = this._getRef();
|
|
400
|
+
const comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
|
|
401
|
+
return comments === null || comments === void 0 || (_comments$children = comments.children) === null || _comments$children === void 0 ? void 0 : _comments$children.map((child) => this._injector.createInstance(_FThreadComment, child));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Get the range of the comment
|
|
405
|
+
* @returns {FRange | null} The range of the comment
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
409
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
410
|
+
* const comments = fWorksheet.getComments();
|
|
411
|
+
* comments.forEach((comment) => {
|
|
412
|
+
* console.log(comment.getRange().getA1Notation());
|
|
413
|
+
* });
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
getRange() {
|
|
417
|
+
const workbook = this._univerInstanceService.getUnit(this._thread.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
418
|
+
if (!workbook) return null;
|
|
419
|
+
const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
|
|
420
|
+
if (!worksheet) return null;
|
|
421
|
+
const range = this._getRef();
|
|
422
|
+
return this._injector.createInstance(_univerjs_sheets_facade.FRange, workbook, worksheet, range);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* @deprecated use `getRichText` as instead
|
|
426
|
+
*/
|
|
427
|
+
getContent() {
|
|
428
|
+
return this._thread.text;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Get the rich text of the comment
|
|
432
|
+
* @returns {RichTextValue} The rich text of the comment
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
436
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
437
|
+
* const comments = fWorksheet.getComments();
|
|
438
|
+
* comments.forEach((comment) => {
|
|
439
|
+
* console.log(comment.getRichText());
|
|
440
|
+
* });
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
getRichText() {
|
|
444
|
+
const body = this._thread.text;
|
|
445
|
+
return _univerjs_core.RichTextValue.create({
|
|
446
|
+
body,
|
|
447
|
+
documentStyle: {},
|
|
448
|
+
id: "d"
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Delete the comment and it's replies
|
|
453
|
+
* @returns {Promise<boolean>} Whether the comment is deleted successfully
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
457
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
458
|
+
* const comments = fWorksheet.getComments();
|
|
459
|
+
*
|
|
460
|
+
* // Delete the first comment
|
|
461
|
+
* const result = await comments[0]?.deleteAsync();
|
|
462
|
+
* console.log(result);
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
deleteAsync() {
|
|
466
|
+
return this._commandService.executeCommand(this.getIsRoot() ? _univerjs_thread_comment.DeleteCommentTreeCommand.id : _univerjs_thread_comment.DeleteCommentCommand.id, {
|
|
467
|
+
commentId: this._thread.id,
|
|
468
|
+
unitId: this._thread.unitId,
|
|
469
|
+
subUnitId: this._thread.subUnitId
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* @deprecated use `deleteAsync` as instead.
|
|
474
|
+
*/
|
|
475
|
+
delete() {
|
|
476
|
+
return this.deleteAsync();
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* @deprecated use `updateAsync` as instead
|
|
480
|
+
*/
|
|
481
|
+
async update(content) {
|
|
482
|
+
return this.updateAsync(content);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Update the comment content
|
|
486
|
+
* @param {IDocumentBody | RichTextValue} content The new content of the comment
|
|
487
|
+
* @returns {Promise<boolean>} Whether the comment is updated successfully
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts
|
|
490
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
491
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
492
|
+
*
|
|
493
|
+
* // Create a new comment
|
|
494
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
495
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
496
|
+
* .setContent(richText)
|
|
497
|
+
* .setId('mock-comment-id');
|
|
498
|
+
* const cell = fWorksheet.getRange('A1');
|
|
499
|
+
* await cell.addCommentAsync(commentBuilder);
|
|
500
|
+
*
|
|
501
|
+
* // Update the comment after 3 seconds
|
|
502
|
+
* setTimeout(async () => {
|
|
503
|
+
* const comment = fWorksheet.getCommentById('mock-comment-id');
|
|
504
|
+
* const newRichText = univerAPI.newRichText().insertText('Hello Univer AI');
|
|
505
|
+
* const result = await comment.updateAsync(newRichText);
|
|
506
|
+
* console.log(result);
|
|
507
|
+
* }, 3000);
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
async updateAsync(content) {
|
|
511
|
+
const body = content instanceof _univerjs_core.RichTextValue ? content.getData().body : content;
|
|
512
|
+
const dt = (0, _univerjs_thread_comment.getDT)();
|
|
513
|
+
return await this._commandService.executeCommand(_univerjs_thread_comment.UpdateCommentCommand.id, {
|
|
514
|
+
unitId: this._thread.unitId,
|
|
515
|
+
subUnitId: this._thread.subUnitId,
|
|
516
|
+
payload: {
|
|
517
|
+
commentId: this._thread.id,
|
|
518
|
+
text: body,
|
|
519
|
+
updated: true,
|
|
520
|
+
updateT: dt
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* @deprecated use `resolveAsync` as instead
|
|
526
|
+
*/
|
|
527
|
+
resolve(resolved) {
|
|
528
|
+
return this.resolveAsync(resolved);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Resolve the comment
|
|
532
|
+
* @param {boolean} resolved Whether the comment is resolved
|
|
533
|
+
* @returns {Promise<boolean>} Set the comment to resolved or not operation result
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
537
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
538
|
+
*
|
|
539
|
+
* // Create a new comment
|
|
540
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
541
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
542
|
+
* .setContent(richText)
|
|
543
|
+
* .setId('mock-comment-id');
|
|
544
|
+
* const cell = fWorksheet.getRange('A1');
|
|
545
|
+
* await cell.addCommentAsync(commentBuilder);
|
|
546
|
+
*
|
|
547
|
+
* // Resolve the comment after 3 seconds
|
|
548
|
+
* setTimeout(async () => {
|
|
549
|
+
* const comment = fWorksheet.getCommentById('mock-comment-id');
|
|
550
|
+
* const result = await comment.resolveAsync(true);
|
|
551
|
+
* console.log(result);
|
|
552
|
+
* }, 3000);
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
resolveAsync(resolved) {
|
|
556
|
+
return this._commandService.executeCommand(_univerjs_thread_comment.ResolveCommentCommand.id, {
|
|
557
|
+
unitId: this._thread.unitId,
|
|
558
|
+
subUnitId: this._thread.subUnitId,
|
|
559
|
+
commentId: this._thread.id,
|
|
560
|
+
resolved: resolved !== null && resolved !== void 0 ? resolved : !this._thread.resolved
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Reply to the comment
|
|
565
|
+
* @param {FTheadCommentBuilder} comment The comment to reply to
|
|
566
|
+
* @returns {Promise<boolean>} Whether the comment is replied successfully
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts
|
|
569
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
570
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
571
|
+
*
|
|
572
|
+
* // Create a new comment
|
|
573
|
+
* const richText = univerAPI.newRichText().insertText('hello univer');
|
|
574
|
+
* const commentBuilder = univerAPI.newTheadComment()
|
|
575
|
+
* .setContent(richText)
|
|
576
|
+
* .setId('mock-comment-id');
|
|
577
|
+
* const cell = fWorksheet.getRange('A1');
|
|
578
|
+
* await cell.addCommentAsync(commentBuilder);
|
|
579
|
+
*
|
|
580
|
+
* // Reply to the comment
|
|
581
|
+
* const replyText = univerAPI.newRichText().insertText('Hello Univer AI');
|
|
582
|
+
* const reply = univerAPI.newTheadComment().setContent(replyText);
|
|
583
|
+
* const comment = fWorksheet.getCommentById('mock-comment-id');
|
|
584
|
+
* const result = await comment.replyAsync(reply);
|
|
585
|
+
* console.log(result);
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
replyAsync(comment) {
|
|
589
|
+
var _this$_parent2;
|
|
590
|
+
const commentData = comment.build();
|
|
591
|
+
return this._commandService.executeCommand(_univerjs_thread_comment.AddCommentCommand.id, {
|
|
592
|
+
unitId: this._thread.unitId,
|
|
593
|
+
subUnitId: this._thread.subUnitId,
|
|
594
|
+
comment: {
|
|
595
|
+
id: (0, _univerjs_core.generateRandomId)(),
|
|
596
|
+
parentId: this._thread.id,
|
|
597
|
+
threadId: this._thread.threadId,
|
|
598
|
+
ref: ((_this$_parent2 = this._parent) === null || _this$_parent2 === void 0 ? void 0 : _this$_parent2.ref) || this._thread.ref,
|
|
599
|
+
unitId: this._thread.unitId,
|
|
600
|
+
subUnitId: this._thread.subUnitId,
|
|
601
|
+
text: commentData.text,
|
|
602
|
+
attachments: commentData.attachments,
|
|
603
|
+
dT: commentData.dT || (0, _univerjs_thread_comment.getDT)(),
|
|
604
|
+
personId: commentData.personId || this._userManagerService.getCurrentUser().userID
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
FThreadComment = _FThreadComment = __decorate([
|
|
610
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
611
|
+
__decorateParam(3, _univerjs_core.ICommandService),
|
|
612
|
+
__decorateParam(4, _univerjs_core.IUniverInstanceService),
|
|
613
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_thread_comment.SheetsThreadCommentModel)),
|
|
614
|
+
__decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.UserManagerService))
|
|
615
|
+
], FThreadComment);
|
|
616
|
+
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/facade/f-range.ts
|
|
619
|
+
/**
|
|
620
|
+
* @ignore
|
|
621
|
+
*/
|
|
622
|
+
var FRangeSheetsThreadCommentMixin = class extends _univerjs_sheets_facade.FRange {
|
|
623
|
+
getComment() {
|
|
624
|
+
const sheetsTheadCommentModel = this._injector.get(_univerjs_sheets_thread_comment.SheetsThreadCommentModel);
|
|
625
|
+
const unitId = this._workbook.getUnitId();
|
|
626
|
+
const sheetId = this._worksheet.getSheetId();
|
|
627
|
+
const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
|
|
628
|
+
if (!commentId) return null;
|
|
629
|
+
const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
|
|
630
|
+
if (comment) return this._injector.createInstance(FThreadComment, comment);
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
getComments() {
|
|
634
|
+
const sheetsTheadCommentModel = this._injector.get(_univerjs_sheets_thread_comment.SheetsThreadCommentModel);
|
|
635
|
+
const unitId = this._workbook.getUnitId();
|
|
636
|
+
const sheetId = this._worksheet.getSheetId();
|
|
637
|
+
const comments = [];
|
|
638
|
+
_univerjs_core.Range.foreach(this._range, (row, col) => {
|
|
639
|
+
const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, row, col);
|
|
640
|
+
if (commentId) {
|
|
641
|
+
const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
|
|
642
|
+
if (comment) comments.push(this._injector.createInstance(FThreadComment, comment));
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
return comments;
|
|
646
|
+
}
|
|
647
|
+
addComment(content) {
|
|
648
|
+
var _this$getComment;
|
|
649
|
+
const injector = this._injector;
|
|
650
|
+
const currentComment = (_this$getComment = this.getComment()) === null || _this$getComment === void 0 ? void 0 : _this$getComment.getCommentData();
|
|
651
|
+
const commentService = injector.get(_univerjs_core.ICommandService);
|
|
652
|
+
const userService = injector.get(_univerjs_core.UserManagerService);
|
|
653
|
+
const unitId = this._workbook.getUnitId();
|
|
654
|
+
const sheetId = this._worksheet.getSheetId();
|
|
655
|
+
const refStr = `${_univerjs_core.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
|
|
656
|
+
const currentUser = userService.getCurrentUser();
|
|
657
|
+
const commentData = content instanceof FTheadCommentBuilder ? content.build() : { text: content };
|
|
658
|
+
return commentService.executeCommand(_univerjs_thread_comment.AddCommentCommand.id, {
|
|
659
|
+
unitId,
|
|
660
|
+
subUnitId: sheetId,
|
|
661
|
+
comment: {
|
|
662
|
+
text: commentData.text,
|
|
663
|
+
dT: commentData.dT || (0, _univerjs_thread_comment.getDT)(),
|
|
664
|
+
attachments: [],
|
|
665
|
+
id: commentData.id || (0, _univerjs_core.generateRandomId)(),
|
|
666
|
+
ref: refStr,
|
|
667
|
+
personId: commentData.personId || currentUser.userID,
|
|
668
|
+
parentId: currentComment === null || currentComment === void 0 ? void 0 : currentComment.id,
|
|
669
|
+
unitId,
|
|
670
|
+
subUnitId: sheetId,
|
|
671
|
+
threadId: (currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId) || (0, _univerjs_core.generateRandomId)()
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
clearComment() {
|
|
676
|
+
var _this$getComment2;
|
|
677
|
+
const injector = this._injector;
|
|
678
|
+
const currentComment = (_this$getComment2 = this.getComment()) === null || _this$getComment2 === void 0 ? void 0 : _this$getComment2.getCommentData();
|
|
679
|
+
const commentService = injector.get(_univerjs_core.ICommandService);
|
|
680
|
+
const unitId = this._workbook.getUnitId();
|
|
681
|
+
const sheetId = this._worksheet.getSheetId();
|
|
682
|
+
if (currentComment) return commentService.executeCommand(_univerjs_thread_comment.DeleteCommentTreeCommand.id, {
|
|
683
|
+
unitId,
|
|
684
|
+
subUnitId: sheetId,
|
|
685
|
+
threadId: currentComment.threadId,
|
|
686
|
+
commentId: currentComment.id
|
|
687
|
+
});
|
|
688
|
+
return Promise.resolve(true);
|
|
689
|
+
}
|
|
690
|
+
clearComments() {
|
|
691
|
+
const promises = this.getComments().map((comment) => comment.deleteAsync());
|
|
692
|
+
return Promise.all(promises).then(() => true);
|
|
693
|
+
}
|
|
694
|
+
addCommentAsync(content) {
|
|
695
|
+
return this.addComment(content);
|
|
696
|
+
}
|
|
697
|
+
clearCommentAsync() {
|
|
698
|
+
return this.clearComment();
|
|
699
|
+
}
|
|
700
|
+
clearCommentsAsync() {
|
|
701
|
+
return this.clearComments();
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
_univerjs_sheets_facade.FRange.extend(FRangeSheetsThreadCommentMixin);
|
|
705
|
+
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region src/facade/f-workbook.ts
|
|
708
|
+
/**
|
|
709
|
+
* @ignore
|
|
710
|
+
*/
|
|
711
|
+
var FWorkbookSheetsThreadCommentMixin = class extends _univerjs_sheets_facade.FWorkbook {
|
|
712
|
+
/**
|
|
713
|
+
* @ignore
|
|
714
|
+
*/
|
|
715
|
+
_initialize() {
|
|
716
|
+
Object.defineProperty(this, "_threadCommentModel", { get() {
|
|
717
|
+
return this._injector.get(_univerjs_thread_comment.ThreadCommentModel);
|
|
718
|
+
} });
|
|
719
|
+
}
|
|
720
|
+
getComments() {
|
|
721
|
+
return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((i) => this._injector.createInstance(FThreadComment, i.root));
|
|
722
|
+
}
|
|
723
|
+
clearComments() {
|
|
724
|
+
const promises = this.getComments().map((comment) => comment.deleteAsync());
|
|
725
|
+
return Promise.all(promises).then(() => true);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* @param callback
|
|
729
|
+
* @deprecated
|
|
730
|
+
*/
|
|
731
|
+
onThreadCommentChange(callback) {
|
|
732
|
+
return (0, _univerjs_core.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0, rxjs.filter)((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* @param callback
|
|
736
|
+
* @deprecated
|
|
737
|
+
*/
|
|
738
|
+
onBeforeAddThreadComment(callback) {
|
|
739
|
+
return (0, _univerjs_core.toDisposable)(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
740
|
+
const params = commandInfo.params;
|
|
741
|
+
if (commandInfo.id === _univerjs_thread_comment.AddCommentCommand.id) {
|
|
742
|
+
if (params.unitId !== this._workbook.getUnitId()) return;
|
|
743
|
+
if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
|
|
744
|
+
}
|
|
745
|
+
}));
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* @param callback
|
|
749
|
+
* @deprecated
|
|
750
|
+
*/
|
|
751
|
+
onBeforeUpdateThreadComment(callback) {
|
|
752
|
+
return (0, _univerjs_core.toDisposable)(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
753
|
+
const params = commandInfo.params;
|
|
754
|
+
if (commandInfo.id === _univerjs_thread_comment.UpdateCommentCommand.id) {
|
|
755
|
+
if (params.unitId !== this._workbook.getUnitId()) return;
|
|
756
|
+
if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
|
|
757
|
+
}
|
|
758
|
+
}));
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* @param callback
|
|
762
|
+
* @deprecated
|
|
763
|
+
*/
|
|
764
|
+
onBeforeDeleteThreadComment(callback) {
|
|
765
|
+
return (0, _univerjs_core.toDisposable)(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
766
|
+
const params = commandInfo.params;
|
|
767
|
+
if (commandInfo.id === _univerjs_thread_comment.DeleteCommentCommand.id || commandInfo.id === _univerjs_thread_comment.DeleteCommentTreeCommand.id) {
|
|
768
|
+
if (params.unitId !== this._workbook.getUnitId()) return;
|
|
769
|
+
if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
|
|
770
|
+
}
|
|
771
|
+
}));
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
_univerjs_sheets_facade.FWorkbook.extend(FWorkbookSheetsThreadCommentMixin);
|
|
775
|
+
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region src/facade/f-worksheet.ts
|
|
778
|
+
/**
|
|
779
|
+
* @ignore
|
|
780
|
+
*/
|
|
781
|
+
var FWorksheetCommentMixin = class extends _univerjs_sheets_facade.FWorksheet {
|
|
782
|
+
getComments() {
|
|
783
|
+
return this._injector.get(_univerjs_sheets_thread_comment.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((comment) => this._injector.createInstance(FThreadComment, comment));
|
|
784
|
+
}
|
|
785
|
+
clearComments() {
|
|
786
|
+
const promises = this.getComments().map((comment) => comment.deleteAsync());
|
|
787
|
+
return Promise.all(promises).then(() => true);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Subscribe to comment events.
|
|
791
|
+
* @param callback Callback function, param contains comment info and target cell.
|
|
792
|
+
*/
|
|
793
|
+
onCommented(callback) {
|
|
794
|
+
return this._injector.get(_univerjs_core.ICommandService).onCommandExecuted((command) => {
|
|
795
|
+
if (command.id === _univerjs_thread_comment.AddCommentCommand.id) {
|
|
796
|
+
const params = command.params;
|
|
797
|
+
callback(params);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
getCommentById(commentId) {
|
|
802
|
+
const comment = this._injector.get(_univerjs_sheets_thread_comment.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), commentId);
|
|
803
|
+
if (comment) return this._injector.createInstance(FThreadComment, comment);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
_univerjs_sheets_facade.FWorksheet.extend(FWorksheetCommentMixin);
|
|
807
|
+
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/facade/f-event.ts
|
|
810
|
+
/**
|
|
811
|
+
* @ignore
|
|
812
|
+
*/
|
|
813
|
+
var FSheetsThreadCommentEventNameMixin = class extends _univerjs_core_facade.FEventName {
|
|
814
|
+
get CommentAdded() {
|
|
815
|
+
return "CommentAdded";
|
|
816
|
+
}
|
|
817
|
+
get BeforeCommentAdd() {
|
|
818
|
+
return "BeforeCommentAdd";
|
|
819
|
+
}
|
|
820
|
+
get CommentUpdated() {
|
|
821
|
+
return "CommentUpdated";
|
|
822
|
+
}
|
|
823
|
+
get BeforeCommentUpdate() {
|
|
824
|
+
return "BeforeCommentUpdate";
|
|
825
|
+
}
|
|
826
|
+
get CommentDeleted() {
|
|
827
|
+
return "CommentDeleted";
|
|
828
|
+
}
|
|
829
|
+
get BeforeCommentDelete() {
|
|
830
|
+
return "BeforeCommentDelete";
|
|
831
|
+
}
|
|
832
|
+
get CommentResolved() {
|
|
833
|
+
return "CommentResolved";
|
|
834
|
+
}
|
|
835
|
+
get BeforeCommentResolve() {
|
|
836
|
+
return "BeforeCommentResolve";
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
_univerjs_core_facade.FEventName.extend(FSheetsThreadCommentEventNameMixin);
|
|
840
|
+
|
|
841
|
+
//#endregion
|
|
842
|
+
//#region src/facade/f-univer.ts
|
|
843
|
+
/**
|
|
844
|
+
* @ignore
|
|
845
|
+
*/
|
|
846
|
+
var FUniverSheetsThreadCommentMixin = class extends _univerjs_core_facade.FUniver {
|
|
847
|
+
_getTargetSheet(params = {}) {
|
|
848
|
+
var _this$getActiveWorkbo;
|
|
849
|
+
const workbook = params.unitId ? this.getUniverSheet(params.unitId) : (_this$getActiveWorkbo = this.getActiveWorkbook) === null || _this$getActiveWorkbo === void 0 ? void 0 : _this$getActiveWorkbo.call(this);
|
|
850
|
+
if (!workbook) return null;
|
|
851
|
+
const worksheet = params.subUnitId ? workbook.getSheetBySheetId(params.subUnitId) : workbook.getActiveSheet();
|
|
852
|
+
if (!worksheet) return null;
|
|
853
|
+
return {
|
|
854
|
+
workbook,
|
|
855
|
+
worksheet
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
_initialize(injector) {
|
|
859
|
+
const commandService = injector.get(_univerjs_core.ICommandService);
|
|
860
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded, () => commandService.onCommandExecuted((commandInfo) => {
|
|
861
|
+
var _threadComment$getRan, _threadComment$getRan2, _threadComment$getRan3, _threadComment$getRan4;
|
|
862
|
+
if (commandInfo.id !== _univerjs_thread_comment.AddCommentCommand.id) return;
|
|
863
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
864
|
+
if (!target) return;
|
|
865
|
+
const { workbook, worksheet } = target;
|
|
866
|
+
const { comment } = commandInfo.params;
|
|
867
|
+
const threadComment = worksheet.getCommentById(comment.id);
|
|
868
|
+
if (!threadComment) return;
|
|
869
|
+
const eventParams = {
|
|
870
|
+
workbook,
|
|
871
|
+
worksheet,
|
|
872
|
+
row: (_threadComment$getRan = (_threadComment$getRan2 = threadComment.getRange()) === null || _threadComment$getRan2 === void 0 ? void 0 : _threadComment$getRan2.getRow()) !== null && _threadComment$getRan !== void 0 ? _threadComment$getRan : 0,
|
|
873
|
+
col: (_threadComment$getRan3 = (_threadComment$getRan4 = threadComment.getRange()) === null || _threadComment$getRan4 === void 0 ? void 0 : _threadComment$getRan4.getColumn()) !== null && _threadComment$getRan3 !== void 0 ? _threadComment$getRan3 : 0,
|
|
874
|
+
comment: threadComment
|
|
875
|
+
};
|
|
876
|
+
this.fireEvent(this.Event.CommentAdded, eventParams);
|
|
877
|
+
})));
|
|
878
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated, () => commandService.onCommandExecuted((commandInfo) => {
|
|
879
|
+
var _threadComment$getRan5, _threadComment$getRan6, _threadComment$getRan7, _threadComment$getRan8;
|
|
880
|
+
if (commandInfo.id !== _univerjs_thread_comment.UpdateCommentCommand.id) return;
|
|
881
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
882
|
+
if (!target) return;
|
|
883
|
+
const { workbook, worksheet } = target;
|
|
884
|
+
const { payload } = commandInfo.params;
|
|
885
|
+
const threadComment = worksheet.getCommentById(payload.commentId);
|
|
886
|
+
if (!threadComment) return;
|
|
887
|
+
const eventParams = {
|
|
888
|
+
workbook,
|
|
889
|
+
worksheet,
|
|
890
|
+
row: (_threadComment$getRan5 = (_threadComment$getRan6 = threadComment.getRange()) === null || _threadComment$getRan6 === void 0 ? void 0 : _threadComment$getRan6.getRow()) !== null && _threadComment$getRan5 !== void 0 ? _threadComment$getRan5 : 0,
|
|
891
|
+
col: (_threadComment$getRan7 = (_threadComment$getRan8 = threadComment.getRange()) === null || _threadComment$getRan8 === void 0 ? void 0 : _threadComment$getRan8.getColumn()) !== null && _threadComment$getRan7 !== void 0 ? _threadComment$getRan7 : 0,
|
|
892
|
+
comment: threadComment
|
|
893
|
+
};
|
|
894
|
+
this.fireEvent(this.Event.CommentUpdated, eventParams);
|
|
895
|
+
})));
|
|
896
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted, () => commandService.onCommandExecuted((commandInfo) => {
|
|
897
|
+
if (commandInfo.id !== _univerjs_thread_comment.DeleteCommentCommand.id && commandInfo.id !== _univerjs_thread_comment.DeleteCommentTreeCommand.id) return;
|
|
898
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
899
|
+
if (!target) return;
|
|
900
|
+
const { workbook, worksheet } = target;
|
|
901
|
+
const { commentId } = commandInfo.params;
|
|
902
|
+
const eventParams = {
|
|
903
|
+
workbook,
|
|
904
|
+
worksheet,
|
|
905
|
+
commentId
|
|
906
|
+
};
|
|
907
|
+
this.fireEvent(this.Event.CommentDeleted, eventParams);
|
|
908
|
+
})));
|
|
909
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved, () => commandService.onCommandExecuted((commandInfo) => {
|
|
910
|
+
var _threadComment$getRan9, _threadComment$getRan10, _threadComment$getRan11, _threadComment$getRan12;
|
|
911
|
+
if (commandInfo.id !== _univerjs_thread_comment.ResolveCommentCommand.id) return;
|
|
912
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
913
|
+
if (!target) return;
|
|
914
|
+
const { workbook, worksheet } = target;
|
|
915
|
+
const { commentId, resolved } = commandInfo.params;
|
|
916
|
+
const threadComment = worksheet.getCommentById(commentId);
|
|
917
|
+
if (!threadComment) return;
|
|
918
|
+
const eventParams = {
|
|
919
|
+
workbook,
|
|
920
|
+
worksheet,
|
|
921
|
+
row: (_threadComment$getRan9 = (_threadComment$getRan10 = threadComment.getRange()) === null || _threadComment$getRan10 === void 0 ? void 0 : _threadComment$getRan10.getRow()) !== null && _threadComment$getRan9 !== void 0 ? _threadComment$getRan9 : 0,
|
|
922
|
+
col: (_threadComment$getRan11 = (_threadComment$getRan12 = threadComment.getRange()) === null || _threadComment$getRan12 === void 0 ? void 0 : _threadComment$getRan12.getColumn()) !== null && _threadComment$getRan11 !== void 0 ? _threadComment$getRan11 : 0,
|
|
923
|
+
comment: threadComment,
|
|
924
|
+
resolved
|
|
925
|
+
};
|
|
926
|
+
this.fireEvent(this.Event.CommentResolved, eventParams);
|
|
927
|
+
})));
|
|
928
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
929
|
+
if (commandInfo.id !== _univerjs_thread_comment.AddCommentCommand.id) return;
|
|
930
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
931
|
+
if (!target) return;
|
|
932
|
+
const { workbook, worksheet } = target;
|
|
933
|
+
const { comment } = commandInfo.params;
|
|
934
|
+
const { range } = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(comment.ref);
|
|
935
|
+
const eventParams = {
|
|
936
|
+
workbook,
|
|
937
|
+
worksheet,
|
|
938
|
+
row: range.startRow,
|
|
939
|
+
col: range.startColumn,
|
|
940
|
+
comment: FTheadCommentItem.create(comment)
|
|
941
|
+
};
|
|
942
|
+
this.fireEvent(this.Event.BeforeCommentAdd, eventParams);
|
|
943
|
+
if (eventParams.cancel) throw new _univerjs_core.CanceledError();
|
|
944
|
+
})));
|
|
945
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
946
|
+
var _threadComment$getRan13, _threadComment$getRan14, _threadComment$getRan15, _threadComment$getRan16;
|
|
947
|
+
if (commandInfo.id !== _univerjs_thread_comment.UpdateCommentCommand.id) return;
|
|
948
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
949
|
+
if (!target) return;
|
|
950
|
+
const { workbook, worksheet } = target;
|
|
951
|
+
const { payload } = commandInfo.params;
|
|
952
|
+
const threadComment = worksheet.getCommentById(payload.commentId);
|
|
953
|
+
if (!threadComment) return;
|
|
954
|
+
const eventParams = {
|
|
955
|
+
workbook,
|
|
956
|
+
worksheet,
|
|
957
|
+
row: (_threadComment$getRan13 = (_threadComment$getRan14 = threadComment.getRange()) === null || _threadComment$getRan14 === void 0 ? void 0 : _threadComment$getRan14.getRow()) !== null && _threadComment$getRan13 !== void 0 ? _threadComment$getRan13 : 0,
|
|
958
|
+
col: (_threadComment$getRan15 = (_threadComment$getRan16 = threadComment.getRange()) === null || _threadComment$getRan16 === void 0 ? void 0 : _threadComment$getRan16.getColumn()) !== null && _threadComment$getRan15 !== void 0 ? _threadComment$getRan15 : 0,
|
|
959
|
+
comment: threadComment,
|
|
960
|
+
newContent: _univerjs_core.RichTextValue.createByBody(payload.text)
|
|
961
|
+
};
|
|
962
|
+
this.fireEvent(this.Event.BeforeCommentUpdate, eventParams);
|
|
963
|
+
if (eventParams.cancel) throw new _univerjs_core.CanceledError();
|
|
964
|
+
})));
|
|
965
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
966
|
+
var _threadComment$getRan17, _threadComment$getRan18, _threadComment$getRan19, _threadComment$getRan20;
|
|
967
|
+
if (commandInfo.id !== _univerjs_thread_comment.DeleteCommentCommand.id && commandInfo.id !== _univerjs_thread_comment.DeleteCommentTreeCommand.id) return;
|
|
968
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
969
|
+
if (!target) return;
|
|
970
|
+
const { workbook, worksheet } = target;
|
|
971
|
+
const { commentId } = commandInfo.params;
|
|
972
|
+
const threadComment = worksheet.getCommentById(commentId);
|
|
973
|
+
if (!threadComment) return;
|
|
974
|
+
const eventParams = {
|
|
975
|
+
workbook,
|
|
976
|
+
worksheet,
|
|
977
|
+
row: (_threadComment$getRan17 = (_threadComment$getRan18 = threadComment.getRange()) === null || _threadComment$getRan18 === void 0 ? void 0 : _threadComment$getRan18.getRow()) !== null && _threadComment$getRan17 !== void 0 ? _threadComment$getRan17 : 0,
|
|
978
|
+
col: (_threadComment$getRan19 = (_threadComment$getRan20 = threadComment.getRange()) === null || _threadComment$getRan20 === void 0 ? void 0 : _threadComment$getRan20.getColumn()) !== null && _threadComment$getRan19 !== void 0 ? _threadComment$getRan19 : 0,
|
|
979
|
+
comment: threadComment
|
|
980
|
+
};
|
|
981
|
+
this.fireEvent(this.Event.BeforeCommentDelete, eventParams);
|
|
982
|
+
if (eventParams.cancel) throw new _univerjs_core.CanceledError();
|
|
983
|
+
})));
|
|
984
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
985
|
+
var _getRow, _getColumn;
|
|
986
|
+
if (commandInfo.id !== _univerjs_thread_comment.ResolveCommentCommand.id) return;
|
|
987
|
+
const target = this._getTargetSheet(commandInfo.params);
|
|
988
|
+
if (!target) return;
|
|
989
|
+
const { workbook, worksheet } = target;
|
|
990
|
+
const { commentId, resolved } = commandInfo.params;
|
|
991
|
+
const threadComment = worksheet.getCommentById(commentId);
|
|
992
|
+
if (!threadComment) return;
|
|
993
|
+
const eventParams = {
|
|
994
|
+
workbook,
|
|
995
|
+
worksheet,
|
|
996
|
+
row: (_getRow = threadComment.getRange().getRow()) !== null && _getRow !== void 0 ? _getRow : 0,
|
|
997
|
+
col: (_getColumn = threadComment.getRange().getColumn()) !== null && _getColumn !== void 0 ? _getColumn : 0,
|
|
998
|
+
comment: threadComment,
|
|
999
|
+
resolved
|
|
1000
|
+
};
|
|
1001
|
+
this.fireEvent(this.Event.BeforeCommentResolve, eventParams);
|
|
1002
|
+
if (eventParams.cancel) throw new _univerjs_core.CanceledError();
|
|
1003
|
+
})));
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* @ignore
|
|
1007
|
+
*/
|
|
1008
|
+
newTheadComment(comment) {
|
|
1009
|
+
return new FTheadCommentBuilder(comment);
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
_univerjs_core_facade.FUniver.extend(FUniverSheetsThreadCommentMixin);
|
|
1013
|
+
|
|
1014
|
+
//#endregion
|
|
1015
|
+
Object.defineProperty(exports, 'FThreadComment', {
|
|
1016
|
+
enumerable: true,
|
|
1017
|
+
get: function () {
|
|
1018
|
+
return FThreadComment;
|
|
1019
|
+
}
|
|
1020
|
+
});
|