@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 o=require("@univerjs/core"),a=require("@univerjs/sheets/facade"),c=require("@univerjs/sheets-thread-comment"),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 r=n>1?void 0:n?b(t,e):t,d=m.length-1,s;d>=0;d--)(s=m[d])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&p(t,e,r),r},h=(m,t)=>(e,n)=>t(e,n,m);exports.FThreadComment=class{constructor(t,e,n,r,d,s){this._thread=t,this._parent=e,this._injector=n,this._commandService=r,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(r=>this._injector.createInstance(exports.FThreadComment,r))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,o.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,o.Inject(o.Injector)),h(3,o.ICommandService),h(4,o.IUniverInstanceService),h(5,o.Inject(c.SheetsThreadCommentModel))],exports.FThreadComment);class T extends a.FRange{getComment(){const e=this._injector.get(c.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),d=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!d)return null;const s=e.getComment(n,r,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(),r=e.get(o.ICommandService),d=e.get(o.UserManagerService),s=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),_=`${o.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=d.getCurrentUser();return r.executeCommand(i.AddCommentCommand.id,{unitId:s,subUnitId:u,comment:{text:t,attachments:[],dT:i.getDT(),id:o.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(o.ICommandService),r=this._workbook.getUnitId(),d=this._worksheet.getSheetId();return e?n.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:r,subUnitId:d,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}a.FRange.extend(T);class S extends a.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(i.ThreadCommentModel)}})}onThreadCommentChange(t){return o.toDisposable(this._threadCommentModel.commentUpdate$.pipe(l.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return o.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===i.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 o.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===i.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 o.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const r=e.params;if(e.id===i.DeleteCommentCommand.id||e.id===i.DeleteCommentTreeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}a.FWorkbook.extend(S);class U 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))}}a.FWorksheet.extend(U);
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 g, Injector as x, UniverInstanceType as T, ICommandService as h, IUniverInstanceService as j, UserManagerService as R, Tools as l, toDisposable as m } from "@univerjs/core";
2
- import { FRange as c, FWorkbook as p, FWorksheet as f } from "@univerjs/sheets/facade";
3
- import { SheetsThreadCommentModel as u } from "@univerjs/sheets-thread-comment";
4
- import { DeleteCommentTreeCommand as _, DeleteCommentCommand as b, getDT as U, UpdateCommentCommand as k, ResolveCommentCommand as M, AddCommentCommand as v, ThreadCommentModel as D } from "@univerjs/thread-comment";
5
- import { deserializeRangeWithSheet as y } from "@univerjs/engine-formula";
6
- import { filter as B } from "rxjs";
7
- var E = Object.defineProperty, F = Object.getOwnPropertyDescriptor, P = (r, t, e, n) => {
8
- for (var o = n > 1 ? void 0 : n ? F(t, e) : t, i = r.length - 1, s; i >= 0; i--)
9
- (s = r[i]) && (o = (n ? s(t, e, o) : s(o)) || o);
10
- return n && o && E(t, e, o), o;
11
- }, a = (r, t) => (e, n) => t(e, n, r);
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(r, t, e, n, o, i) {
14
- this._thread = r, this._parent = t, this._injector = e, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = i;
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 r = ((e = this._parent) == null ? void 0 : e.ref) || this._thread.ref;
19
- return y(r).range;
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: r, ...t } = this._thread;
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 r = this._getRef(), t = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, r.startRow, r.startColumn);
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 r = this._univerInstanceService.getUnit(this._thread.unitId, T.UNIVER_SHEET);
51
- if (!r)
50
+ const o = this._univerInstanceService.getUnit(this._thread.unitId, T.UNIVER_SHEET);
51
+ if (!o)
52
52
  return null;
53
- const t = r.getSheetBySheetId(this._thread.subUnitId);
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(c, r, t, e);
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 : b.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(r) {
86
- const t = U();
85
+ async update(o) {
86
+ const t = v();
87
87
  return await this._commandService.executeCommand(
88
- k.id,
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: r,
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(r) {
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: r != null ? r : !this._thread.resolved
113
+ resolved: o != null ? o : !this._thread.resolved
114
114
  }
115
115
  );
116
116
  }
117
117
  };
118
118
  d = P([
119
- a(2, g(x)),
119
+ a(2, l(x)),
120
120
  a(3, h),
121
121
  a(4, j),
122
- a(5, g(u))
122
+ a(5, l(c))
123
123
  ], d);
124
- class A extends c {
124
+ class A extends u {
125
125
  getComment() {
126
- const e = this._injector.get(u), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), i = e.getByLocation(n, o, this._range.startRow, this._range.startColumn);
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, o, i);
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 C;
134
- const e = this._injector, n = (C = this.getComment()) == null ? void 0 : C.getCommentData(), o = e.get(h), i = e.get(R), s = this._workbook.getUnitId(), I = this._worksheet.getSheetId(), w = `${l.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, S = i.getCurrentUser();
135
- return o.executeCommand(v.id, {
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: I,
137
+ subUnitId: C,
138
138
  comment: {
139
139
  text: t,
140
140
  attachments: [],
141
- dT: U(),
142
- id: l.generateRandomId(),
143
- ref: w,
144
- personId: S.userID,
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: I,
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), o = this._workbook.getUnitId(), i = this._worksheet.getSheetId();
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: o,
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
- c.extend(A);
164
- class W extends p {
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(B((e) => e.unitId === this._workbook.getUnitId())).subscribe(t));
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 o = e.params;
178
- if (e.id === v.id) {
179
- if (o.unitId !== this._workbook.getUnitId())
177
+ const r = e.params;
178
+ if (e.id === I.id) {
179
+ if (r.unitId !== this._workbook.getUnitId())
180
180
  return;
181
- if (t(o, n) === !1)
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 o = e.params;
189
- if (e.id === k.id) {
190
- if (o.unitId !== this._workbook.getUnitId())
188
+ const r = e.params;
189
+ if (e.id === S.id) {
190
+ if (r.unitId !== this._workbook.getUnitId())
191
191
  return;
192
- if (t(o, n) === !1)
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 o = e.params;
200
- if (e.id === b.id || e.id === _.id) {
201
- if (o.unitId !== this._workbook.getUnitId())
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(o, n) === !1)
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
- p.extend(W);
210
- class O extends f {
209
+ f.extend(W);
210
+ class O extends b {
211
211
  getComments() {
212
- return this._injector.get(u).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(d, n));
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
- f.extend(O);
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/models/thread-comment.model.js').IThreadInfo>;
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/facade"),require("@univerjs/sheets-thread-comment"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets/facade","@univerjs/sheets-thread-comment","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o.UniverSheetsThreadCommentFacade={},o.UniverCore,o.UniverSheetsFacade,o.UniverSheetsThreadComment,o.UniverThreadComment,o.UniverEngineFormula,o.rxjs))})(this,function(o,i,h,u,d,I,g){"use strict";var l=Object.defineProperty,f=Object.getOwnPropertyDescriptor,v=(a,t,e,n)=>{for(var r=n>1?void 0:n?f(t,e):t,m=a.length-1,s;m>=0;m--)(s=a[m])&&(r=(n?s(t,e,r):s(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,s){this._thread=t,this._parent=e,this._injector=n,this._commandService=r,this._univerInstanceService=m,this._threadCommentModel=s}_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()?d.DeleteCommentTreeCommand.id:d.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(t){const e=d.getDT();return await this._commandService.executeCommand(d.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(d.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}},o.FThreadComment=v([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 s=e.getComment(n,r,m);return s?this._injector.createInstance(o.FThreadComment,s):null}addComment(t){var C;const e=this._injector,n=(C=this.getComment())==null?void 0:C.getCommentData(),r=e.get(i.ICommandService),m=e.get(i.UserManagerService),s=this._workbook.getUnitId(),_=this._worksheet.getSheetId(),b=`${i.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,j=m.getCurrentUser();return r.executeCommand(d.AddCommentCommand.id,{unitId:s,subUnitId:_,comment:{text:t,attachments:[],dT:d.getDT(),id:i.Tools.generateRandomId(),ref:b,personId:j.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:_,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(i.ICommandService),r=this._workbook.getUnitId(),m=this._worksheet.getSheetId();return e?n.executeCommand(d.DeleteCommentTreeCommand.id,{unitId:r,subUnitId:m,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}h.FRange.extend(p);class U extends h.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(d.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===d.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===d.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===d.DeleteCommentCommand.id||e.id===d.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(U);class T 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))}}h.FWorksheet.extend(T),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
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.1",
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.1",
55
- "@univerjs/engine-formula": "0.5.1",
56
- "@univerjs/thread-comment": "0.5.1",
57
- "@univerjs/sheets": "0.5.1"
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.1",
63
- "vitest": "^2.1.6",
64
- "@univerjs-infra/shared": "0.5.1"
62
+ "vite": "^6.0.3",
63
+ "vitest": "^2.1.8",
64
+ "@univerjs-infra/shared": "0.5.2"
65
65
  },
66
66
  "space": {
67
67
  ".": {