@univerjs/thread-comment 0.24.0 → 0.25.0-insiders.20260608-e4336f7

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.134.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.134.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.134.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.134.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.134.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.134.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-insiders.20260608-e4336f7";
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.134.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.134.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.134.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.134.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.134.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.134.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-insiders.20260608-e4336f7";
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.134.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.134.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.134.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.134.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.134.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.134.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-insiders.20260608-e4336f7";
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-insiders.20260608-e4336f7`;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-insiders.20260608-e4336f7",
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-insiders.20260608-e4336f7"
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.8",
61
+ "@univerjs-infra/shared": "0.25.0"
62
62
  },
63
63
  "scripts": {
64
64
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS