@univerjs/thread-comment 0.24.0 → 0.25.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/index.js CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _univerjs_core = require("@univerjs/core");
3
3
  let rxjs = require("rxjs");
4
4
 
5
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
5
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
6
6
  function _typeof(o) {
7
7
  "@babel/helpers - typeof";
8
8
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -13,7 +13,7 @@ function _typeof(o) {
13
13
  }
14
14
 
15
15
  //#endregion
16
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
16
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
17
17
  function toPrimitive(t, r) {
18
18
  if ("object" != _typeof(t) || !t) return t;
19
19
  var e = t[Symbol.toPrimitive];
@@ -26,14 +26,14 @@ function toPrimitive(t, r) {
26
26
  }
27
27
 
28
28
  //#endregion
29
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
29
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
30
30
  function toPropertyKey(t) {
31
31
  var i = toPrimitive(t, "string");
32
32
  return "symbol" == _typeof(i) ? i : i + "";
33
33
  }
34
34
 
35
35
  //#endregion
36
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
36
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
37
37
  function _defineProperty(e, r, t) {
38
38
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
39
  value: t,
@@ -65,11 +65,10 @@ var ThreadCommentDataSourceService = class extends _univerjs_core.Disposable {
65
65
  return null;
66
66
  }
67
67
  async addComment(comment) {
68
- var _comment$threadId;
69
- if (this._dataSource) return this._dataSource.addComment(comment);
68
+ const savedComment = this._dataSource ? await this._dataSource.addComment(comment) : comment;
70
69
  return {
71
- ...comment,
72
- threadId: (_comment$threadId = comment.threadId) !== null && _comment$threadId !== void 0 ? _comment$threadId : comment.id
70
+ ...savedComment,
71
+ threadId: savedComment.threadId || savedComment.id
73
72
  };
74
73
  }
75
74
  async updateComment(comment) {
@@ -102,7 +101,7 @@ var ThreadCommentDataSourceService = class extends _univerjs_core.Disposable {
102
101
  const IThreadCommentDataSourceService = (0, _univerjs_core.createIdentifier)("univer.thread-comment.data-source-service");
103
102
 
104
103
  //#endregion
105
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
104
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
106
105
  function __decorateParam(paramIndex, decorator) {
107
106
  return function(target, key) {
108
107
  decorator(target, key, paramIndex);
@@ -110,7 +109,7 @@ function __decorateParam(paramIndex, decorator) {
110
109
  }
111
110
 
112
111
  //#endregion
113
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
112
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
114
113
  function __decorate(decorators, target, key, desc) {
115
114
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
116
115
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -190,35 +189,37 @@ let ThreadCommentModel = class ThreadCommentModel extends _univerjs_core.Disposa
190
189
  _replaceComment(unitId, subUnitId, comment) {
191
190
  const commentMap = this._ensureCommentMap(unitId, subUnitId);
192
191
  const currentComment = commentMap.get(comment.id);
193
- if (currentComment) {
194
- const { children, ...rest } = comment;
195
- const newComment = {
196
- ...rest,
197
- ref: currentComment.ref
198
- };
199
- commentMap.set(comment.id, newComment);
200
- children === null || children === void 0 || children.forEach((child) => {
201
- commentMap.set(child.id, {
202
- ...child,
203
- ref: ""
204
- });
205
- });
206
- this._commentUpdate$.next({
207
- unitId,
208
- subUnitId,
209
- type: "syncUpdate",
210
- payload: newComment
211
- });
212
- if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
213
- unitId,
214
- subUnitId,
215
- type: "resolve",
216
- payload: {
217
- commentId: comment.id,
218
- resolved: Boolean(comment.resolved)
219
- }
220
- });
192
+ if (!currentComment) {
193
+ this.addComment(unitId, subUnitId, comment);
194
+ return;
221
195
  }
196
+ const { children, ...rest } = comment;
197
+ const newComment = {
198
+ ...rest,
199
+ ref: currentComment.ref
200
+ };
201
+ commentMap.set(comment.id, newComment);
202
+ children === null || children === void 0 || children.forEach((child) => {
203
+ commentMap.set(child.id, {
204
+ ...child,
205
+ ref: ""
206
+ });
207
+ });
208
+ this._commentUpdate$.next({
209
+ unitId,
210
+ subUnitId,
211
+ type: "syncUpdate",
212
+ payload: newComment
213
+ });
214
+ if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
215
+ unitId,
216
+ subUnitId,
217
+ type: "resolve",
218
+ payload: {
219
+ commentId: comment.id,
220
+ resolved: Boolean(comment.resolved)
221
+ }
222
+ });
222
223
  }
223
224
  async syncThreadComments(unitId, subUnitId, threadIds) {
224
225
  if (this._lifecycleService.stage < _univerjs_core.LifecycleStages.Rendered) {
@@ -235,6 +236,7 @@ let ThreadCommentModel = class ThreadCommentModel extends _univerjs_core.Disposa
235
236
  if (!comments) return;
236
237
  const deleteThreads = new Set(threadIds);
237
238
  comments.forEach((comment) => {
239
+ if (!deleteThreads.has(comment.threadId)) return;
238
240
  this._replaceComment(unitId, subUnitId, comment);
239
241
  deleteThreads.delete(comment.threadId);
240
242
  });
@@ -681,7 +683,7 @@ ThreadCommentResourceController = __decorate([
681
683
  //#endregion
682
684
  //#region package.json
683
685
  var name = "@univerjs/thread-comment";
684
- var version = "0.24.0";
686
+ var version = "0.25.0";
685
687
 
686
688
  //#endregion
687
689
  //#region src/config/config.ts
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CommandType, Disposable, ICommandService, IConfigService, IResourceManagerService, Inject, Injector, LifecycleService, LifecycleStages, Plugin, UniverInstanceType, createIdentifier, dateKit, merge, mergeOverrideWithDependencies } from "@univerjs/core";
2
2
  import { Subject } from "rxjs";
3
3
 
4
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
4
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
5
5
  function _typeof(o) {
6
6
  "@babel/helpers - typeof";
7
7
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -12,7 +12,7 @@ function _typeof(o) {
12
12
  }
13
13
 
14
14
  //#endregion
15
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
15
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
16
16
  function toPrimitive(t, r) {
17
17
  if ("object" != _typeof(t) || !t) return t;
18
18
  var e = t[Symbol.toPrimitive];
@@ -25,14 +25,14 @@ function toPrimitive(t, r) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
28
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
29
29
  function toPropertyKey(t) {
30
30
  var i = toPrimitive(t, "string");
31
31
  return "symbol" == _typeof(i) ? i : i + "";
32
32
  }
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
35
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
36
36
  function _defineProperty(e, r, t) {
37
37
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
38
  value: t,
@@ -64,11 +64,10 @@ var ThreadCommentDataSourceService = class extends Disposable {
64
64
  return null;
65
65
  }
66
66
  async addComment(comment) {
67
- var _comment$threadId;
68
- if (this._dataSource) return this._dataSource.addComment(comment);
67
+ const savedComment = this._dataSource ? await this._dataSource.addComment(comment) : comment;
69
68
  return {
70
- ...comment,
71
- threadId: (_comment$threadId = comment.threadId) !== null && _comment$threadId !== void 0 ? _comment$threadId : comment.id
69
+ ...savedComment,
70
+ threadId: savedComment.threadId || savedComment.id
72
71
  };
73
72
  }
74
73
  async updateComment(comment) {
@@ -101,7 +100,7 @@ var ThreadCommentDataSourceService = class extends Disposable {
101
100
  const IThreadCommentDataSourceService = createIdentifier("univer.thread-comment.data-source-service");
102
101
 
103
102
  //#endregion
104
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
103
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
105
104
  function __decorateParam(paramIndex, decorator) {
106
105
  return function(target, key) {
107
106
  decorator(target, key, paramIndex);
@@ -109,7 +108,7 @@ function __decorateParam(paramIndex, decorator) {
109
108
  }
110
109
 
111
110
  //#endregion
112
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
111
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
113
112
  function __decorate(decorators, target, key, desc) {
114
113
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
115
114
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -189,35 +188,37 @@ let ThreadCommentModel = class ThreadCommentModel extends Disposable {
189
188
  _replaceComment(unitId, subUnitId, comment) {
190
189
  const commentMap = this._ensureCommentMap(unitId, subUnitId);
191
190
  const currentComment = commentMap.get(comment.id);
192
- if (currentComment) {
193
- const { children, ...rest } = comment;
194
- const newComment = {
195
- ...rest,
196
- ref: currentComment.ref
197
- };
198
- commentMap.set(comment.id, newComment);
199
- children === null || children === void 0 || children.forEach((child) => {
200
- commentMap.set(child.id, {
201
- ...child,
202
- ref: ""
203
- });
204
- });
205
- this._commentUpdate$.next({
206
- unitId,
207
- subUnitId,
208
- type: "syncUpdate",
209
- payload: newComment
210
- });
211
- if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
212
- unitId,
213
- subUnitId,
214
- type: "resolve",
215
- payload: {
216
- commentId: comment.id,
217
- resolved: Boolean(comment.resolved)
218
- }
219
- });
191
+ if (!currentComment) {
192
+ this.addComment(unitId, subUnitId, comment);
193
+ return;
220
194
  }
195
+ const { children, ...rest } = comment;
196
+ const newComment = {
197
+ ...rest,
198
+ ref: currentComment.ref
199
+ };
200
+ commentMap.set(comment.id, newComment);
201
+ children === null || children === void 0 || children.forEach((child) => {
202
+ commentMap.set(child.id, {
203
+ ...child,
204
+ ref: ""
205
+ });
206
+ });
207
+ this._commentUpdate$.next({
208
+ unitId,
209
+ subUnitId,
210
+ type: "syncUpdate",
211
+ payload: newComment
212
+ });
213
+ if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
214
+ unitId,
215
+ subUnitId,
216
+ type: "resolve",
217
+ payload: {
218
+ commentId: comment.id,
219
+ resolved: Boolean(comment.resolved)
220
+ }
221
+ });
221
222
  }
222
223
  async syncThreadComments(unitId, subUnitId, threadIds) {
223
224
  if (this._lifecycleService.stage < LifecycleStages.Rendered) {
@@ -234,6 +235,7 @@ let ThreadCommentModel = class ThreadCommentModel extends Disposable {
234
235
  if (!comments) return;
235
236
  const deleteThreads = new Set(threadIds);
236
237
  comments.forEach((comment) => {
238
+ if (!deleteThreads.has(comment.threadId)) return;
237
239
  this._replaceComment(unitId, subUnitId, comment);
238
240
  deleteThreads.delete(comment.threadId);
239
241
  });
@@ -680,7 +682,7 @@ ThreadCommentResourceController = __decorate([
680
682
  //#endregion
681
683
  //#region package.json
682
684
  var name = "@univerjs/thread-comment";
683
- var version = "0.24.0";
685
+ var version = "0.25.0";
684
686
 
685
687
  //#endregion
686
688
  //#region src/config/config.ts
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CommandType, Disposable, ICommandService, IConfigService, IResourceManagerService, Inject, Injector, LifecycleService, LifecycleStages, Plugin, UniverInstanceType, createIdentifier, dateKit, merge, mergeOverrideWithDependencies } from "@univerjs/core";
2
2
  import { Subject } from "rxjs";
3
3
 
4
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
4
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
5
5
  function _typeof(o) {
6
6
  "@babel/helpers - typeof";
7
7
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -12,7 +12,7 @@ function _typeof(o) {
12
12
  }
13
13
 
14
14
  //#endregion
15
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
15
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
16
16
  function toPrimitive(t, r) {
17
17
  if ("object" != _typeof(t) || !t) return t;
18
18
  var e = t[Symbol.toPrimitive];
@@ -25,14 +25,14 @@ function toPrimitive(t, r) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
28
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
29
29
  function toPropertyKey(t) {
30
30
  var i = toPrimitive(t, "string");
31
31
  return "symbol" == _typeof(i) ? i : i + "";
32
32
  }
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
35
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
36
36
  function _defineProperty(e, r, t) {
37
37
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
38
  value: t,
@@ -64,11 +64,10 @@ var ThreadCommentDataSourceService = class extends Disposable {
64
64
  return null;
65
65
  }
66
66
  async addComment(comment) {
67
- var _comment$threadId;
68
- if (this._dataSource) return this._dataSource.addComment(comment);
67
+ const savedComment = this._dataSource ? await this._dataSource.addComment(comment) : comment;
69
68
  return {
70
- ...comment,
71
- threadId: (_comment$threadId = comment.threadId) !== null && _comment$threadId !== void 0 ? _comment$threadId : comment.id
69
+ ...savedComment,
70
+ threadId: savedComment.threadId || savedComment.id
72
71
  };
73
72
  }
74
73
  async updateComment(comment) {
@@ -101,7 +100,7 @@ var ThreadCommentDataSourceService = class extends Disposable {
101
100
  const IThreadCommentDataSourceService = createIdentifier("univer.thread-comment.data-source-service");
102
101
 
103
102
  //#endregion
104
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
103
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
105
104
  function __decorateParam(paramIndex, decorator) {
106
105
  return function(target, key) {
107
106
  decorator(target, key, paramIndex);
@@ -109,7 +108,7 @@ function __decorateParam(paramIndex, decorator) {
109
108
  }
110
109
 
111
110
  //#endregion
112
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
111
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
113
112
  function __decorate(decorators, target, key, desc) {
114
113
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
115
114
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -189,35 +188,37 @@ let ThreadCommentModel = class ThreadCommentModel extends Disposable {
189
188
  _replaceComment(unitId, subUnitId, comment) {
190
189
  const commentMap = this._ensureCommentMap(unitId, subUnitId);
191
190
  const currentComment = commentMap.get(comment.id);
192
- if (currentComment) {
193
- const { children, ...rest } = comment;
194
- const newComment = {
195
- ...rest,
196
- ref: currentComment.ref
197
- };
198
- commentMap.set(comment.id, newComment);
199
- children === null || children === void 0 || children.forEach((child) => {
200
- commentMap.set(child.id, {
201
- ...child,
202
- ref: ""
203
- });
204
- });
205
- this._commentUpdate$.next({
206
- unitId,
207
- subUnitId,
208
- type: "syncUpdate",
209
- payload: newComment
210
- });
211
- if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
212
- unitId,
213
- subUnitId,
214
- type: "resolve",
215
- payload: {
216
- commentId: comment.id,
217
- resolved: Boolean(comment.resolved)
218
- }
219
- });
191
+ if (!currentComment) {
192
+ this.addComment(unitId, subUnitId, comment);
193
+ return;
220
194
  }
195
+ const { children, ...rest } = comment;
196
+ const newComment = {
197
+ ...rest,
198
+ ref: currentComment.ref
199
+ };
200
+ commentMap.set(comment.id, newComment);
201
+ children === null || children === void 0 || children.forEach((child) => {
202
+ commentMap.set(child.id, {
203
+ ...child,
204
+ ref: ""
205
+ });
206
+ });
207
+ this._commentUpdate$.next({
208
+ unitId,
209
+ subUnitId,
210
+ type: "syncUpdate",
211
+ payload: newComment
212
+ });
213
+ if (Boolean(comment.resolved) !== Boolean(currentComment.resolved)) this._commentUpdate$.next({
214
+ unitId,
215
+ subUnitId,
216
+ type: "resolve",
217
+ payload: {
218
+ commentId: comment.id,
219
+ resolved: Boolean(comment.resolved)
220
+ }
221
+ });
221
222
  }
222
223
  async syncThreadComments(unitId, subUnitId, threadIds) {
223
224
  if (this._lifecycleService.stage < LifecycleStages.Rendered) {
@@ -234,6 +235,7 @@ let ThreadCommentModel = class ThreadCommentModel extends Disposable {
234
235
  if (!comments) return;
235
236
  const deleteThreads = new Set(threadIds);
236
237
  comments.forEach((comment) => {
238
+ if (!deleteThreads.has(comment.threadId)) return;
237
239
  this._replaceComment(unitId, subUnitId, comment);
238
240
  deleteThreads.delete(comment.threadId);
239
241
  });
@@ -680,7 +682,7 @@ ThreadCommentResourceController = __decorate([
680
682
  //#endregion
681
683
  //#region package.json
682
684
  var name = "@univerjs/thread-comment";
683
- var version = "0.24.0";
685
+ var version = "0.25.0";
684
686
 
685
687
  //#endregion
686
688
  //#region src/config/config.ts
@@ -78,7 +78,23 @@ export declare class ThreadCommentDataSourceService extends Disposable implement
78
78
  get dataSource(): Nullable<IThreadCommentDataSource>;
79
79
  constructor();
80
80
  getThreadComment(unitId: string, subUnitId: string, threadId: string): Promise<Nullable<IBaseComment>>;
81
- addComment(comment: IThreadComment): Promise<IThreadComment>;
81
+ addComment(comment: IThreadComment): Promise<{
82
+ threadId: string;
83
+ ref: string;
84
+ id: string;
85
+ dT: string;
86
+ updateT?: string;
87
+ personId: string;
88
+ text: import("@univerjs/core").IDocumentBody;
89
+ attachments?: string[];
90
+ updated?: boolean;
91
+ mentions?: string[];
92
+ parentId?: string;
93
+ resolved?: boolean;
94
+ unitId: string;
95
+ subUnitId: string;
96
+ children?: IBaseComment[];
97
+ }>;
82
98
  updateComment(comment: IThreadComment): Promise<boolean>;
83
99
  resolveComment(comment: IThreadComment): Promise<boolean>;
84
100
  deleteComment(unitId: string, subUnitId: string, threadId: string, commentId: string): Promise<boolean>;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverThreadComment={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){"@babel/helpers - typeof";return r=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},r(e)}function i(e,t){if(r(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||`default`);if(r(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function a(e){var t=i(e,`string`);return r(t)==`symbol`?t:t+``}function o(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s=class extends t.Disposable{set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}constructor(){super(),o(this,`_dataSource`,null),o(this,`syncUpdateMutationToColla`,!0)}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)==null?e.id:t}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,r){return this._dataSource?this._dataSource.deleteComment(e,t,n,r):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n].map(this.dataSource.saveCommentToSnapshot)}),t}return e}};let c=(0,t.createIdentifier)(`univer.thread-comment.data-source-service`);function l(e,t){return function(n,r){t(n,r,e)}}function u(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}let d=class extends t.Disposable{constructor(e,r){super(),this._dataSourceService=e,this._lifecycleService=r,o(this,`_commentsMap`,new Map),o(this,`_threadMap`,new Map),o(this,`_commentUpdate$`,new n.Subject),o(this,`commentUpdate$`,this._commentUpdate$.asObservable()),o(this,`_tasks`,[]),this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(e=>{let n=new Map;e===t.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:e,subUnitId:t,threadIds:r})=>{let i=n.get(e);i||(i=new Map,n.set(e,i));let a=i.get(t);a||(a=new Set,i.set(t,a));for(let e of r)a.add(e)}),this._tasks=[],n.forEach((e,t)=>{e.forEach((e,n)=>{this.syncThreadComments(t,n,Array.from(e))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_replaceComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n.id);if(i){let{children:a,...o}=n,s={...o,ref:i.ref};r.set(n.id,s),a==null||a.forEach(e=>{r.set(e.id,{...e,ref:``})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`syncUpdate`,payload:s}),!!n.resolved!=!!i.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,n,r){if(this._lifecycleService.stage<t.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:n,threadIds:r});return}let i=this._ensureThreadMap(e,n),a=this._ensureCommentMap(e,n),o=await this._dataSourceService.listThreadComments(e,n,r);if(!o)return;let s=new Set(r);o.forEach(t=>{this._replaceComment(e,n,t),s.delete(t.threadId)}),s.forEach(e=>{i.delete(e),a.forEach((t,n)=>{t.threadId===e&&a.delete(n)})})}addComment(e,t,n,r){let i=this._ensureCommentMap(e,t),{parentId:a,children:o=[],...s}=n,c={...s,parentId:a===n.id?void 0:a};c.threadId||(c.threadId=c.parentId||c.id);let l=n=>{i.set(n.id,n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`add`,payload:n,isRoot:!n.parentId})};l(c);let u=this._ensureThreadMap(e,t);if(!c.parentId){u.set(c.threadId,c);for(let e of o)l(e)}return r&&this.syncThreadComments(e,t,[c.threadId]),!0}updateComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.updated=!0,i.text=n.text,i.attachments=n.attachments,i.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`update`,payload:n,silent:r}),!0):!0}updateCommentRef(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`updateRef`,payload:n,silent:r,threadId:i.threadId}),!0):!1}resolveComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n);return i?(i.resolved=r,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n,resolved:r}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){let r=this._ensureCommentMap(e,t),i=Array.from(r.values()).filter(e=>e.threadId===n),a,o=[],s=new Set;for(let e of i)e.parentId?o.push(e):a=e,s.add(e.personId);if(a)return{root:a,children:o,relativeUsers:s,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){let r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n);i&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`delete`,payload:{commentId:n,isRoot:!i.parentId,comment:i}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){let r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){let t=this._commentsMap.get(e);t&&t.forEach((t,n)=>{t.forEach(t=>{this.deleteComment(e,n,t.id)})})}getUnit(e){let t=this._threadMap.get(e);if(!t)return[];let n=[];return t.forEach((t,r)=>{t.forEach((t,i)=>{let a=this.getThread(e,r,i);a&&n.push(a)})}),n}getAll(){let e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};d=u([l(0,(0,t.Inject)(c)),l(1,(0,t.Inject)(t.LifecycleService))],d);let f={id:`thread-comment.mutation.add-comment`,type:t.CommandType.MUTATION,handler(e,t,n){if(!t)return!1;let r=e.get(d),{unitId:i,subUnitId:a,comment:o,sync:s}=t,c=s||(n==null?void 0:n.fromChangeset)&&!o.parentId;return r.addComment(i,a,o,c)}},p={id:`thread-comment.mutation.update-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateComment(r,i,a,o)}},m={id:`thread-comment.mutation.update-comment-ref`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateCommentRef(r,i,a,o)}},h={id:`thread-comment.mutation.resolve-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,resolved:a,commentId:o}=t;return n.resolveComment(r,i,o,a)}},g={id:`thread-comment.mutation.delete-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,commentId:a}=t;return n.deleteComment(r,i,a)}},_={id:`thread-comment.command.add-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(t.ICommandService),i=e.get(c),{comment:a}=n,o=await i.addComment(a),s=i.syncUpdateMutationToColla,l=!a.parentId,u={id:f.id,params:{...n,comment:o}};return l?await r.executeCommand(u.id,u.params):r.executeCommand(u.id,u.params,{onlyLocal:!s})}},v={id:`thread-comment.command.update-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,payload:a}=n,o=e.get(t.ICommandService),s=e.get(d),l=e.get(c),u=l.syncUpdateMutationToColla,f=s.getComment(r,i,a.commentId);if(!f)return!1;let{children:m,...h}=f;if(!await l.updateComment({...h,...a}))return!1;let g={id:p.id,params:n};return o.executeCommand(g.id,g.params,{onlyLocal:!u}),!0}},y={id:`thread-comment.command.resolve-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,resolved:a,commentId:o}=n,s=e.get(c),l=e.get(d).getComment(r,i,o),u=s.syncUpdateMutationToColla;return!l||!await s.resolveComment({...l,resolved:a})?!1:e.get(t.ICommandService).executeCommand(h.id,n,{onlyLocal:!u})}},b={id:`thread-comment.command.delete-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(d),i=e.get(c),a=e.get(t.ICommandService),{unitId:o,subUnitId:s,commentId:l}=n,u=i.syncUpdateMutationToColla,f=r.getComment(o,s,l);if(!f||!await i.deleteComment(o,s,f.threadId,l))return!1;let p={id:g.id,params:n};return a.executeCommand(p.id,p.params,{onlyLocal:!u})}},x={id:`thread-comment.command.delete-comment-tree`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(d),i=e.get(t.ICommandService),a=e.get(c),{unitId:o,subUnitId:s,commentId:l}=n,u=r.getCommentWithChildren(o,s,l);return!u||!await a.deleteComment(o,s,u.root.threadId,l)?!1:await i.executeCommand(g.id,{unitId:o,subUnitId:s,commentId:u.root.id})}};function S(e){return(0,t.dateKit)(e).format(`YYYY/MM/DD HH:mm`)}let C=`UNIVER_THREAD_COMMENT_PLUGIN`,w=`SHEET_${C}`,T=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._threadCommentModel.getUnit(e),n={};return t?(t.forEach(e=>{var t;let r=(t=n[e.subUnitId])==null?[]:t;r.push({...e.root,children:e.children}),n[e.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(n,e))):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:w,businesses:[t.UniverInstanceType.UNIVER_SHEET,t.UniverInstanceType.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{let r=t[n];r.forEach(t=>{this._threadCommentModel.addComment(e,n,t)}),this._threadCommentModel.syncThreadComments(e,n,r.map(e=>e.threadId))})}}))}};T=u([l(0,t.IResourceManagerService),l(1,(0,t.Inject)(d)),l(2,c)],T);var E=`@univerjs/thread-comment`,D=`0.24.0`;let O=`thread-comment.config`;Symbol(O);let k={},A=class extends t.Plugin{constructor(e=k,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},k,this._config);this._configService.setConfig(O,a)}onStarting(){var e;(0,t.mergeOverrideWithDependencies)([[c,{useClass:s}],[d],[T]],(e=this._config)==null?void 0:e.overrides).forEach(e=>{this._injector.add(e)}),[_,v,b,y,x,f,p,m,g,h].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(T)}};o(A,`pluginName`,C),o(A,`packageName`,E),o(A,`version`,D),o(A,`type`,t.UniverInstanceType.UNIVER_UNKNOWN),A=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.ICommandService),l(3,t.IConfigService)],A),e.AddCommentCommand=_,e.AddCommentMutation=f,e.DeleteCommentCommand=b,e.DeleteCommentMutation=g,e.DeleteCommentTreeCommand=x,e.IThreadCommentDataSourceService=c,e.ResolveCommentCommand=y,e.ResolveCommentMutation=h,e.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=w,e.TC_PLUGIN_NAME=C,e.ThreadCommentDataSourceService=s,Object.defineProperty(e,`ThreadCommentModel`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,`ThreadCommentResourceController`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`UniverThreadCommentPlugin`,{enumerable:!0,get:function(){return A}}),e.UpdateCommentCommand=v,e.UpdateCommentMutation=p,e.UpdateCommentRefMutation=m,e.getDT=S});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverThreadComment={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){"@babel/helpers - typeof";return r=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},r(e)}function i(e,t){if(r(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||`default`);if(r(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function a(e){var t=i(e,`string`);return r(t)==`symbol`?t:t+``}function o(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s=class extends t.Disposable{set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}constructor(){super(),o(this,`_dataSource`,null),o(this,`syncUpdateMutationToColla`,!0)}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){let t=this._dataSource?await this._dataSource.addComment(e):e;return{...t,threadId:t.threadId||t.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,r){return this._dataSource?this._dataSource.deleteComment(e,t,n,r):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n].map(this.dataSource.saveCommentToSnapshot)}),t}return e}};let c=(0,t.createIdentifier)(`univer.thread-comment.data-source-service`);function l(e,t){return function(n,r){t(n,r,e)}}function u(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}let d=class extends t.Disposable{constructor(e,r){super(),this._dataSourceService=e,this._lifecycleService=r,o(this,`_commentsMap`,new Map),o(this,`_threadMap`,new Map),o(this,`_commentUpdate$`,new n.Subject),o(this,`commentUpdate$`,this._commentUpdate$.asObservable()),o(this,`_tasks`,[]),this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(e=>{let n=new Map;e===t.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:e,subUnitId:t,threadIds:r})=>{let i=n.get(e);i||(i=new Map,n.set(e,i));let a=i.get(t);a||(a=new Set,i.set(t,a));for(let e of r)a.add(e)}),this._tasks=[],n.forEach((e,t)=>{e.forEach((e,n)=>{this.syncThreadComments(t,n,Array.from(e))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_replaceComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n.id);if(!i){this.addComment(e,t,n);return}let{children:a,...o}=n,s={...o,ref:i.ref};r.set(n.id,s),a==null||a.forEach(e=>{r.set(e.id,{...e,ref:``})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`syncUpdate`,payload:s}),!!n.resolved!=!!i.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n.id,resolved:!!n.resolved}})}async syncThreadComments(e,n,r){if(this._lifecycleService.stage<t.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:n,threadIds:r});return}let i=this._ensureThreadMap(e,n),a=this._ensureCommentMap(e,n),o=await this._dataSourceService.listThreadComments(e,n,r);if(!o)return;let s=new Set(r);o.forEach(t=>{s.has(t.threadId)&&(this._replaceComment(e,n,t),s.delete(t.threadId))}),s.forEach(e=>{i.delete(e),a.forEach((t,n)=>{t.threadId===e&&a.delete(n)})})}addComment(e,t,n,r){let i=this._ensureCommentMap(e,t),{parentId:a,children:o=[],...s}=n,c={...s,parentId:a===n.id?void 0:a};c.threadId||(c.threadId=c.parentId||c.id);let l=n=>{i.set(n.id,n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`add`,payload:n,isRoot:!n.parentId})};l(c);let u=this._ensureThreadMap(e,t);if(!c.parentId){u.set(c.threadId,c);for(let e of o)l(e)}return r&&this.syncThreadComments(e,t,[c.threadId]),!0}updateComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.updated=!0,i.text=n.text,i.attachments=n.attachments,i.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`update`,payload:n,silent:r}),!0):!0}updateCommentRef(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`updateRef`,payload:n,silent:r,threadId:i.threadId}),!0):!1}resolveComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n);return i?(i.resolved=r,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n,resolved:r}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){let r=this._ensureCommentMap(e,t),i=Array.from(r.values()).filter(e=>e.threadId===n),a,o=[],s=new Set;for(let e of i)e.parentId?o.push(e):a=e,s.add(e.personId);if(a)return{root:a,children:o,relativeUsers:s,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){let r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n);i&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`delete`,payload:{commentId:n,isRoot:!i.parentId,comment:i}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){let r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){let t=this._commentsMap.get(e);t&&t.forEach((t,n)=>{t.forEach(t=>{this.deleteComment(e,n,t.id)})})}getUnit(e){let t=this._threadMap.get(e);if(!t)return[];let n=[];return t.forEach((t,r)=>{t.forEach((t,i)=>{let a=this.getThread(e,r,i);a&&n.push(a)})}),n}getAll(){let e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};d=u([l(0,(0,t.Inject)(c)),l(1,(0,t.Inject)(t.LifecycleService))],d);let f={id:`thread-comment.mutation.add-comment`,type:t.CommandType.MUTATION,handler(e,t,n){if(!t)return!1;let r=e.get(d),{unitId:i,subUnitId:a,comment:o,sync:s}=t,c=s||(n==null?void 0:n.fromChangeset)&&!o.parentId;return r.addComment(i,a,o,c)}},p={id:`thread-comment.mutation.update-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateComment(r,i,a,o)}},m={id:`thread-comment.mutation.update-comment-ref`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateCommentRef(r,i,a,o)}},h={id:`thread-comment.mutation.resolve-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,resolved:a,commentId:o}=t;return n.resolveComment(r,i,o,a)}},g={id:`thread-comment.mutation.delete-comment`,type:t.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,commentId:a}=t;return n.deleteComment(r,i,a)}},_={id:`thread-comment.command.add-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(t.ICommandService),i=e.get(c),{comment:a}=n,o=await i.addComment(a),s=i.syncUpdateMutationToColla,l=!a.parentId,u={id:f.id,params:{...n,comment:o}};return l?await r.executeCommand(u.id,u.params):r.executeCommand(u.id,u.params,{onlyLocal:!s})}},v={id:`thread-comment.command.update-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,payload:a}=n,o=e.get(t.ICommandService),s=e.get(d),l=e.get(c),u=l.syncUpdateMutationToColla,f=s.getComment(r,i,a.commentId);if(!f)return!1;let{children:m,...h}=f;if(!await l.updateComment({...h,...a}))return!1;let g={id:p.id,params:n};return o.executeCommand(g.id,g.params,{onlyLocal:!u}),!0}},y={id:`thread-comment.command.resolve-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,resolved:a,commentId:o}=n,s=e.get(c),l=e.get(d).getComment(r,i,o),u=s.syncUpdateMutationToColla;return!l||!await s.resolveComment({...l,resolved:a})?!1:e.get(t.ICommandService).executeCommand(h.id,n,{onlyLocal:!u})}},b={id:`thread-comment.command.delete-comment`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(d),i=e.get(c),a=e.get(t.ICommandService),{unitId:o,subUnitId:s,commentId:l}=n,u=i.syncUpdateMutationToColla,f=r.getComment(o,s,l);if(!f||!await i.deleteComment(o,s,f.threadId,l))return!1;let p={id:g.id,params:n};return a.executeCommand(p.id,p.params,{onlyLocal:!u})}},x={id:`thread-comment.command.delete-comment-tree`,type:t.CommandType.COMMAND,async handler(e,n){if(!n)return!1;let r=e.get(d),i=e.get(t.ICommandService),a=e.get(c),{unitId:o,subUnitId:s,commentId:l}=n,u=r.getCommentWithChildren(o,s,l);return!u||!await a.deleteComment(o,s,u.root.threadId,l)?!1:await i.executeCommand(g.id,{unitId:o,subUnitId:s,commentId:u.root.id})}};function S(e){return(0,t.dateKit)(e).format(`YYYY/MM/DD HH:mm`)}let C=`UNIVER_THREAD_COMMENT_PLUGIN`,w=`SHEET_${C}`,T=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._threadCommentModel.getUnit(e),n={};return t?(t.forEach(e=>{var t;let r=(t=n[e.subUnitId])==null?[]:t;r.push({...e.root,children:e.children}),n[e.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(n,e))):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:w,businesses:[t.UniverInstanceType.UNIVER_SHEET,t.UniverInstanceType.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{let r=t[n];r.forEach(t=>{this._threadCommentModel.addComment(e,n,t)}),this._threadCommentModel.syncThreadComments(e,n,r.map(e=>e.threadId))})}}))}};T=u([l(0,t.IResourceManagerService),l(1,(0,t.Inject)(d)),l(2,c)],T);var E=`@univerjs/thread-comment`,D=`0.25.0`;let O={},k=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},O,this._config);this._configService.setConfig(`thread-comment.config`,a)}onStarting(){var e;(0,t.mergeOverrideWithDependencies)([[c,{useClass:s}],[d],[T]],(e=this._config)==null?void 0:e.overrides).forEach(e=>{this._injector.add(e)}),[_,v,b,y,x,f,p,m,g,h].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(T)}};o(k,`pluginName`,C),o(k,`packageName`,E),o(k,`version`,D),o(k,`type`,t.UniverInstanceType.UNIVER_UNKNOWN),k=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.ICommandService),l(3,t.IConfigService)],k),e.AddCommentCommand=_,e.AddCommentMutation=f,e.DeleteCommentCommand=b,e.DeleteCommentMutation=g,e.DeleteCommentTreeCommand=x,e.IThreadCommentDataSourceService=c,e.ResolveCommentCommand=y,e.ResolveCommentMutation=h,e.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=w,e.TC_PLUGIN_NAME=C,e.ThreadCommentDataSourceService=s,Object.defineProperty(e,"ThreadCommentModel",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"ThreadCommentResourceController",{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,"UniverThreadCommentPlugin",{enumerable:!0,get:function(){return k}}),e.UpdateCommentCommand=v,e.UpdateCommentMutation=p,e.UpdateCommentRefMutation=m,e.getDT=S});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/thread-comment",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "private": false,
5
5
  "description": "Shared thread comment models, commands, and services for Univer.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -52,13 +52,13 @@
52
52
  "rxjs": ">=7.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/core": "0.24.0"
55
+ "@univerjs/core": "0.25.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.2",
59
59
  "typescript": "^6.0.3",
60
- "vitest": "^4.1.5",
61
- "@univerjs-infra/shared": "0.24.0"
60
+ "vitest": "^4.1.7",
61
+ "@univerjs-infra/shared": "0.25.0"
62
62
  },
63
63
  "scripts": {
64
64
  "test": "vitest run",