@univerjs/sheets-thread-comment 0.5.1 → 0.5.2
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),c=require("@univerjs/sheets-thread-comment"),a=require("@univerjs/sheets/facade"),i=require("@univerjs/thread-comment"),g=require("@univerjs/engine-formula"),l=require("rxjs");var p=Object.defineProperty,b=Object.getOwnPropertyDescriptor,f=(m,t,e,n)=>{for(var o=n>1?void 0:n?b(t,e):t,d=m.length-1,s;d>=0;d--)(s=m[d])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&p(t,e,o),o},h=(m,t)=>(e,n)=>t(e,n,m);exports.FThreadComment=class{constructor(t,e,n,o,d,s){this._thread=t,this._parent=e,this._injector=n,this._commandService=o,this._univerInstanceService=d,this._threadCommentModel=s}_getRef(){var n;const t=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return g.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...e}=this._thread;return e}getReplies(){var n;const t=this._getRef(),e=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(n=e==null?void 0:e.children)==null?void 0:n.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const e=t.getSheetBySheetId(this._thread.subUnitId);if(!e)return null;const n=this._getRef();return this._injector.createInstance(a.FRange,t,e,n)}getContent(){return this._thread.text}delete(){return this._commandService.executeCommand(this.getIsRoot()?i.DeleteCommentTreeCommand.id:i.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(t){const e=i.getDT();return await this._commandService.executeCommand(i.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:e}})}resolve(t){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}};exports.FThreadComment=f([h(2,r.Inject(r.Injector)),h(3,r.ICommandService),h(4,r.IUniverInstanceService),h(5,r.Inject(c.SheetsThreadCommentModel))],exports.FThreadComment);class S extends a.FRange{getComment(){const e=this._injector.get(c.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),d=e.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!d)return null;const s=e.getComment(n,o,d);return s?this._injector.createInstance(exports.FThreadComment,s):null}addComment(t){var C;const e=this._injector,n=(C=this.getComment())==null?void 0:C.getCommentData(),o=e.get(r.ICommandService),d=e.get(r.UserManagerService),s=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),_=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=d.getCurrentUser();return o.executeCommand(i.AddCommentCommand.id,{unitId:s,subUnitId:u,comment:{text:t,attachments:[],dT:i.getDT(),id:r.Tools.generateRandomId(),ref:_,personId:I.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:u,threadId:n==null?void 0:n.threadId}})}clearComment(){var s;const t=this._injector,e=(s=this.getComment())==null?void 0:s.getCommentData(),n=t.get(r.ICommandService),o=this._workbook.getUnitId(),d=this._worksheet.getSheetId();return e?n.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:d,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}a.FRange.extend(S);class T extends a.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(i.ThreadCommentModel)}})}onThreadCommentChange(t){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(l.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.DeleteCommentCommand.id||e.id===i.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}a.FWorkbook.extend(T);class v extends a.FWorksheet{getComments(){return this._injector.get(c.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.FThreadComment,n))}onCommented(t){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===i.AddCommentCommand.id){const o=n.params;t(o)}})}}a.FWorksheet.extend(v);
|
package/lib/es/facade.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Inject as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DeleteCommentTreeCommand as _, DeleteCommentCommand as
|
|
5
|
-
import { deserializeRangeWithSheet as
|
|
6
|
-
import { filter as
|
|
7
|
-
var
|
|
8
|
-
for (var
|
|
9
|
-
(s =
|
|
10
|
-
return n &&
|
|
11
|
-
}, a = (
|
|
1
|
+
import { Inject as l, Injector as x, UniverInstanceType as T, ICommandService as h, IUniverInstanceService as j, UserManagerService as R, Tools as p, toDisposable as m } from "@univerjs/core";
|
|
2
|
+
import { SheetsThreadCommentModel as c } from "@univerjs/sheets-thread-comment";
|
|
3
|
+
import { FRange as u, FWorkbook as f, FWorksheet as b } from "@univerjs/sheets/facade";
|
|
4
|
+
import { DeleteCommentTreeCommand as _, DeleteCommentCommand as U, getDT as v, UpdateCommentCommand as S, ResolveCommentCommand as M, AddCommentCommand as I, ThreadCommentModel as D } from "@univerjs/thread-comment";
|
|
5
|
+
import { deserializeRangeWithSheet as E } from "@univerjs/engine-formula";
|
|
6
|
+
import { filter as y } from "rxjs";
|
|
7
|
+
var B = Object.defineProperty, F = Object.getOwnPropertyDescriptor, P = (o, t, e, n) => {
|
|
8
|
+
for (var r = n > 1 ? void 0 : n ? F(t, e) : t, i = o.length - 1, s; i >= 0; i--)
|
|
9
|
+
(s = o[i]) && (r = (n ? s(t, e, r) : s(r)) || r);
|
|
10
|
+
return n && r && B(t, e, r), r;
|
|
11
|
+
}, a = (o, t) => (e, n) => t(e, n, o);
|
|
12
12
|
let d = class {
|
|
13
|
-
constructor(
|
|
14
|
-
this._thread =
|
|
13
|
+
constructor(o, t, e, n, r, i) {
|
|
14
|
+
this._thread = o, this._parent = t, this._injector = e, this._commandService = n, this._univerInstanceService = r, this._threadCommentModel = i;
|
|
15
15
|
}
|
|
16
16
|
_getRef() {
|
|
17
17
|
var e;
|
|
18
|
-
const
|
|
19
|
-
return
|
|
18
|
+
const o = ((e = this._parent) == null ? void 0 : e.ref) || this._thread.ref;
|
|
19
|
+
return E(o).range;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Whether the comment is a root comment
|
|
@@ -30,7 +30,7 @@ let d = class {
|
|
|
30
30
|
* @returns The comment data
|
|
31
31
|
*/
|
|
32
32
|
getCommentData() {
|
|
33
|
-
const { children:
|
|
33
|
+
const { children: o, ...t } = this._thread;
|
|
34
34
|
return t;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
@@ -39,7 +39,7 @@ let d = class {
|
|
|
39
39
|
*/
|
|
40
40
|
getReplies() {
|
|
41
41
|
var e;
|
|
42
|
-
const
|
|
42
|
+
const o = this._getRef(), t = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, o.startRow, o.startColumn);
|
|
43
43
|
return (e = t == null ? void 0 : t.children) == null ? void 0 : e.map((n) => this._injector.createInstance(d, n));
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -47,14 +47,14 @@ let d = class {
|
|
|
47
47
|
* @returns The range of the comment
|
|
48
48
|
*/
|
|
49
49
|
getRange() {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
50
|
+
const o = this._univerInstanceService.getUnit(this._thread.unitId, T.UNIVER_SHEET);
|
|
51
|
+
if (!o)
|
|
52
52
|
return null;
|
|
53
|
-
const t =
|
|
53
|
+
const t = o.getSheetBySheetId(this._thread.subUnitId);
|
|
54
54
|
if (!t)
|
|
55
55
|
return null;
|
|
56
56
|
const e = this._getRef();
|
|
57
|
-
return this._injector.createInstance(
|
|
57
|
+
return this._injector.createInstance(u, o, t, e);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Get the content of the comment
|
|
@@ -69,7 +69,7 @@ let d = class {
|
|
|
69
69
|
*/
|
|
70
70
|
delete() {
|
|
71
71
|
return this._commandService.executeCommand(
|
|
72
|
-
this.getIsRoot() ? _.id :
|
|
72
|
+
this.getIsRoot() ? _.id : U.id,
|
|
73
73
|
{
|
|
74
74
|
commentId: this._thread.id,
|
|
75
75
|
unitId: this._thread.unitId,
|
|
@@ -82,16 +82,16 @@ let d = class {
|
|
|
82
82
|
* @param content The new content of the comment
|
|
83
83
|
* @returns success or not
|
|
84
84
|
*/
|
|
85
|
-
async update(
|
|
86
|
-
const t =
|
|
85
|
+
async update(o) {
|
|
86
|
+
const t = v();
|
|
87
87
|
return await this._commandService.executeCommand(
|
|
88
|
-
|
|
88
|
+
S.id,
|
|
89
89
|
{
|
|
90
90
|
unitId: this._thread.unitId,
|
|
91
91
|
subUnitId: this._thread.subUnitId,
|
|
92
92
|
payload: {
|
|
93
93
|
commentId: this._thread.id,
|
|
94
|
-
text:
|
|
94
|
+
text: o,
|
|
95
95
|
updated: !0,
|
|
96
96
|
updateT: t
|
|
97
97
|
}
|
|
@@ -103,65 +103,65 @@ let d = class {
|
|
|
103
103
|
* @param resolved Whether the comment is resolved
|
|
104
104
|
* @returns success or not
|
|
105
105
|
*/
|
|
106
|
-
resolve(
|
|
106
|
+
resolve(o) {
|
|
107
107
|
return this._commandService.executeCommand(
|
|
108
108
|
M.id,
|
|
109
109
|
{
|
|
110
110
|
unitId: this._thread.unitId,
|
|
111
111
|
subUnitId: this._thread.subUnitId,
|
|
112
112
|
commentId: this._thread.id,
|
|
113
|
-
resolved:
|
|
113
|
+
resolved: o != null ? o : !this._thread.resolved
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
d = P([
|
|
119
|
-
a(2,
|
|
119
|
+
a(2, l(x)),
|
|
120
120
|
a(3, h),
|
|
121
121
|
a(4, j),
|
|
122
|
-
a(5,
|
|
122
|
+
a(5, l(c))
|
|
123
123
|
], d);
|
|
124
|
-
class A extends
|
|
124
|
+
class A extends u {
|
|
125
125
|
getComment() {
|
|
126
|
-
const e = this._injector.get(
|
|
126
|
+
const e = this._injector.get(c), n = this._workbook.getUnitId(), r = this._worksheet.getSheetId(), i = e.getByLocation(n, r, this._range.startRow, this._range.startColumn);
|
|
127
127
|
if (!i)
|
|
128
128
|
return null;
|
|
129
|
-
const s = e.getComment(n,
|
|
129
|
+
const s = e.getComment(n, r, i);
|
|
130
130
|
return s ? this._injector.createInstance(d, s) : null;
|
|
131
131
|
}
|
|
132
132
|
addComment(t) {
|
|
133
|
-
var
|
|
134
|
-
const e = this._injector, n = (
|
|
135
|
-
return
|
|
133
|
+
var g;
|
|
134
|
+
const e = this._injector, n = (g = this.getComment()) == null ? void 0 : g.getCommentData(), r = e.get(h), i = e.get(R), s = this._workbook.getUnitId(), C = this._worksheet.getSheetId(), k = `${p.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, w = i.getCurrentUser();
|
|
135
|
+
return r.executeCommand(I.id, {
|
|
136
136
|
unitId: s,
|
|
137
|
-
subUnitId:
|
|
137
|
+
subUnitId: C,
|
|
138
138
|
comment: {
|
|
139
139
|
text: t,
|
|
140
140
|
attachments: [],
|
|
141
|
-
dT:
|
|
142
|
-
id:
|
|
143
|
-
ref:
|
|
144
|
-
personId:
|
|
141
|
+
dT: v(),
|
|
142
|
+
id: p.generateRandomId(),
|
|
143
|
+
ref: k,
|
|
144
|
+
personId: w.userID,
|
|
145
145
|
parentId: n == null ? void 0 : n.id,
|
|
146
146
|
unitId: s,
|
|
147
|
-
subUnitId:
|
|
147
|
+
subUnitId: C,
|
|
148
148
|
threadId: n == null ? void 0 : n.threadId
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
clearComment() {
|
|
153
153
|
var s;
|
|
154
|
-
const t = this._injector, e = (s = this.getComment()) == null ? void 0 : s.getCommentData(), n = t.get(h),
|
|
154
|
+
const t = this._injector, e = (s = this.getComment()) == null ? void 0 : s.getCommentData(), n = t.get(h), r = this._workbook.getUnitId(), i = this._worksheet.getSheetId();
|
|
155
155
|
return e ? n.executeCommand(_.id, {
|
|
156
|
-
unitId:
|
|
156
|
+
unitId: r,
|
|
157
157
|
subUnitId: i,
|
|
158
158
|
threadId: e.threadId,
|
|
159
159
|
commentId: e.id
|
|
160
160
|
}) : Promise.resolve(!0);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
class W extends
|
|
163
|
+
u.extend(A);
|
|
164
|
+
class W extends f {
|
|
165
165
|
_initialize() {
|
|
166
166
|
Object.defineProperty(this, "_threadCommentModel", {
|
|
167
167
|
get() {
|
|
@@ -170,49 +170,61 @@ class W extends p {
|
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
onThreadCommentChange(t) {
|
|
173
|
-
return m(this._threadCommentModel.commentUpdate$.pipe(
|
|
173
|
+
return m(this._threadCommentModel.commentUpdate$.pipe(y((e) => e.unitId === this._workbook.getUnitId())).subscribe(t));
|
|
174
174
|
}
|
|
175
175
|
onBeforeAddThreadComment(t) {
|
|
176
176
|
return m(this._commandService.beforeCommandExecuted((e, n) => {
|
|
177
|
-
const
|
|
178
|
-
if (e.id ===
|
|
179
|
-
if (
|
|
177
|
+
const r = e.params;
|
|
178
|
+
if (e.id === I.id) {
|
|
179
|
+
if (r.unitId !== this._workbook.getUnitId())
|
|
180
180
|
return;
|
|
181
|
-
if (t(
|
|
181
|
+
if (t(r, n) === !1)
|
|
182
182
|
throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
|
|
183
183
|
}
|
|
184
184
|
}));
|
|
185
185
|
}
|
|
186
186
|
onBeforeUpdateThreadComment(t) {
|
|
187
187
|
return m(this._commandService.beforeCommandExecuted((e, n) => {
|
|
188
|
-
const
|
|
189
|
-
if (e.id ===
|
|
190
|
-
if (
|
|
188
|
+
const r = e.params;
|
|
189
|
+
if (e.id === S.id) {
|
|
190
|
+
if (r.unitId !== this._workbook.getUnitId())
|
|
191
191
|
return;
|
|
192
|
-
if (t(
|
|
192
|
+
if (t(r, n) === !1)
|
|
193
193
|
throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
|
|
194
194
|
}
|
|
195
195
|
}));
|
|
196
196
|
}
|
|
197
197
|
onBeforeDeleteThreadComment(t) {
|
|
198
198
|
return m(this._commandService.beforeCommandExecuted((e, n) => {
|
|
199
|
-
const
|
|
200
|
-
if (e.id ===
|
|
201
|
-
if (
|
|
199
|
+
const r = e.params;
|
|
200
|
+
if (e.id === U.id || e.id === _.id) {
|
|
201
|
+
if (r.unitId !== this._workbook.getUnitId())
|
|
202
202
|
return;
|
|
203
|
-
if (t(
|
|
203
|
+
if (t(r, n) === !1)
|
|
204
204
|
throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
|
|
205
205
|
}
|
|
206
206
|
}));
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
|
|
210
|
-
class O extends
|
|
209
|
+
f.extend(W);
|
|
210
|
+
class O extends b {
|
|
211
211
|
getComments() {
|
|
212
|
-
return this._injector.get(
|
|
212
|
+
return this._injector.get(c).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(d, n));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Subscribe to comment events.
|
|
216
|
+
* @param callback Callback function, param contains comment info and target cell.
|
|
217
|
+
*/
|
|
218
|
+
onCommented(t) {
|
|
219
|
+
return this._injector.get(h).onCommandExecuted((n) => {
|
|
220
|
+
if (n.id === I.id) {
|
|
221
|
+
const r = n.params;
|
|
222
|
+
t(r);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
213
225
|
}
|
|
214
226
|
}
|
|
215
|
-
|
|
227
|
+
b.extend(O);
|
|
216
228
|
export {
|
|
217
229
|
d as FThreadComment
|
|
218
230
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IDisposable } from '@univerjs/core';
|
|
2
|
+
import { IAddCommentCommandParams } from '@univerjs/thread-comment';
|
|
1
3
|
import { FWorksheet } from '@univerjs/sheets/facade';
|
|
2
4
|
import { FThreadComment } from './f-thread-comment';
|
|
3
5
|
export interface IFWorksheetCommentMixin {
|
|
@@ -9,6 +11,11 @@ export interface IFWorksheetCommentMixin {
|
|
|
9
11
|
}
|
|
10
12
|
export declare class FWorksheetCommentMixin extends FWorksheet implements IFWorksheetCommentMixin {
|
|
11
13
|
getComments(): FThreadComment[];
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe to comment events.
|
|
16
|
+
* @param callback Callback function, param contains comment info and target cell.
|
|
17
|
+
*/
|
|
18
|
+
onCommented(callback: (params: IAddCommentCommandParams) => void): IDisposable;
|
|
12
19
|
}
|
|
13
20
|
declare module '@univerjs/sheets/facade' {
|
|
14
21
|
interface FWorksheet extends IFWorksheetCommentMixin {
|
|
@@ -24,7 +24,7 @@ export declare class SheetsThreadCommentModel extends Disposable {
|
|
|
24
24
|
getByLocation(unitId: string, subUnitId: string, row: number, column: number): string | undefined;
|
|
25
25
|
getAllByLocation(unitId: string, subUnitId: string, row: number, column: number): IThreadComment[];
|
|
26
26
|
getComment(unitId: string, subUnitId: string, commentId: string): IThreadComment | undefined;
|
|
27
|
-
getCommentWithChildren(unitId: string, subUnitId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/thread-comment
|
|
27
|
+
getCommentWithChildren(unitId: string, subUnitId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/thread-comment').IThreadInfo>;
|
|
28
28
|
showCommentMarker(unitId: string, subUnitId: string, row: number, column: number): boolean;
|
|
29
29
|
getSubUnitAll(unitId: string, subUnitId: string): IThreadComment[];
|
|
30
30
|
}
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/sheets
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o.UniverSheetsThreadCommentFacade={},o.UniverCore,o.UniverSheetsThreadComment,o.UniverSheetsFacade,o.UniverThreadComment,o.UniverEngineFormula,o.rxjs))})(this,function(o,i,u,h,s,I,g){"use strict";var l=Object.defineProperty,v=Object.getOwnPropertyDescriptor,f=(a,t,e,n)=>{for(var r=n>1?void 0:n?v(t,e):t,m=a.length-1,d;m>=0;m--)(d=a[m])&&(r=(n?d(t,e,r):d(r))||r);return n&&r&&l(t,e,r),r},c=(a,t)=>(e,n)=>t(e,n,a);o.FThreadComment=class{constructor(t,e,n,r,m,d){this._thread=t,this._parent=e,this._injector=n,this._commandService=r,this._univerInstanceService=m,this._threadCommentModel=d}_getRef(){var n;const t=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return I.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...e}=this._thread;return e}getReplies(){var n;const t=this._getRef(),e=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(n=e==null?void 0:e.children)==null?void 0:n.map(r=>this._injector.createInstance(o.FThreadComment,r))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,i.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const e=t.getSheetBySheetId(this._thread.subUnitId);if(!e)return null;const n=this._getRef();return this._injector.createInstance(h.FRange,t,e,n)}getContent(){return this._thread.text}delete(){return this._commandService.executeCommand(this.getIsRoot()?s.DeleteCommentTreeCommand.id:s.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(t){const e=s.getDT();return await this._commandService.executeCommand(s.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:e}})}resolve(t){return this._commandService.executeCommand(s.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}},o.FThreadComment=f([c(2,i.Inject(i.Injector)),c(3,i.ICommandService),c(4,i.IUniverInstanceService),c(5,i.Inject(u.SheetsThreadCommentModel))],o.FThreadComment);class p extends h.FRange{getComment(){const e=this._injector.get(u.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),m=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!m)return null;const d=e.getComment(n,r,m);return d?this._injector.createInstance(o.FThreadComment,d):null}addComment(t){var _;const e=this._injector,n=(_=this.getComment())==null?void 0:_.getCommentData(),r=e.get(i.ICommandService),m=e.get(i.UserManagerService),d=this._workbook.getUnitId(),C=this._worksheet.getSheetId(),T=`${i.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,b=m.getCurrentUser();return r.executeCommand(s.AddCommentCommand.id,{unitId:d,subUnitId:C,comment:{text:t,attachments:[],dT:s.getDT(),id:i.Tools.generateRandomId(),ref:T,personId:b.userID,parentId:n==null?void 0:n.id,unitId:d,subUnitId:C,threadId:n==null?void 0:n.threadId}})}clearComment(){var d;const t=this._injector,e=(d=this.getComment())==null?void 0:d.getCommentData(),n=t.get(i.ICommandService),r=this._workbook.getUnitId(),m=this._worksheet.getSheetId();return e?n.executeCommand(s.DeleteCommentTreeCommand.id,{unitId:r,subUnitId:m,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}h.FRange.extend(p);class S extends h.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(s.ThreadCommentModel)}})}onThreadCommentChange(t){return i.toDisposable(this._threadCommentModel.commentUpdate$.pipe(g.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===s.AddCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===s.UpdateCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===s.DeleteCommentCommand.id||e.id===s.DeleteCommentTreeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}h.FWorkbook.extend(S);class U extends h.FWorksheet{getComments(){return this._injector.get(u.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(o.FThreadComment,n))}onCommented(t){return this._injector.get(i.ICommandService).onCommandExecuted(n=>{if(n.id===s.AddCommentCommand.id){const r=n.params;t(r)}})}}h.FWorksheet.extend(U),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-thread-comment",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer sheets thread comment base plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
"rxjs": ">=7.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@univerjs/core": "0.5.
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/thread-comment": "0.5.
|
|
57
|
-
"@univerjs/
|
|
54
|
+
"@univerjs/core": "0.5.2",
|
|
55
|
+
"@univerjs/sheets": "0.5.2",
|
|
56
|
+
"@univerjs/thread-comment": "0.5.2",
|
|
57
|
+
"@univerjs/engine-formula": "0.5.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
61
61
|
"typescript": "^5.7.2",
|
|
62
|
-
"vite": "^6.0.
|
|
63
|
-
"vitest": "^2.1.
|
|
64
|
-
"@univerjs-infra/shared": "0.5.
|
|
62
|
+
"vite": "^6.0.3",
|
|
63
|
+
"vitest": "^2.1.8",
|
|
64
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
65
65
|
},
|
|
66
66
|
"space": {
|
|
67
67
|
".": {
|