@univerjs/sheets-thread-comment 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1 +1,632 @@
1
- import{DependentOn as e,Disposable as t,ICommandService as n,IUniverInstanceService as r,Inject as i,Injector as a,ObjectMatrix as o,Plugin as s,UniverInstanceType as c,generateRandomId as l,sequenceExecuteAsync as u,toDisposable as d,touchDependencies as f}from"@univerjs/core";import{serializeRange as p,singleReferenceToGrid as m}from"@univerjs/engine-formula";import{CopySheetCommand as h,RefRangeService as g,RemoveSheetCommand as _,SheetInterceptorService as v,SheetsSelectionsService as y,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as b}from"@univerjs/sheets";import{AddCommentMutation as x,DeleteCommentMutation as S,IThreadCommentDataSourceService as C,ThreadCommentModel as w,UniverThreadCommentPlugin as T,UpdateCommentRefMutation as E}from"@univerjs/thread-comment";import{Subject as D}from"rxjs";function O(e){"@babel/helpers - typeof";return O=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},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(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}function M(e,t){return function(n,r){t(n,r,e)}}function N(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 P=class extends t{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,j(this,`_matrixMap`,new Map),j(this,`_locationMap`,new Map),j(this,`_commentUpdate$`,new D),j(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let r=n.get(t);return r||(r=new o,n.set(t,r)),r}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,n){let r=m(n.ref),i=n.parentId,{row:a,column:o}=r,s=n.id,{matrix:c,locationMap:l}=this._ensure(e,t);!i&&a>=0&&o>=0&&(this._addCommentToMatrix(c,a,o,s),l.set(s,{row:a,column:o})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`,isRoot:!i,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UNIVER_SHEET)return}catch{}let{matrix:r,locationMap:i}=this._ensure(t,n);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:n}=e.payload;if(t){let t=m(n.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(r,i,a,n.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:r}=e.payload,i=this._threadCommentModel.getComment(t,n,r);if(!i)return;let a=m(i.ref);this._commentUpdate$.next({...e,...a});break}case`updateRef`:{let t=m(e.payload.ref),{commentId:n}=e.payload,a=i.get(n);if(!a)return;let{row:o,column:s}=a;this._deleteCommentFromMatrix(r,o,s,n),i.delete(n),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(r,t.row,t.column,n),i.set(n,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};P=N([M(0,i(w)),M(1,r)],P);let F=class extends t{constructor(e,t,n,r,i){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._selectionManagerService=r,this._commandService=i,j(this,`_disposableMap`,new Map),j(this,`_watcherMap`,new Map),j(this,`_handleRangeChange`,(e,t,n,r,i)=>{let a=n.id,o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(r),commentId:a},silent:i}}],undos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(o),commentId:a},silent:i}}]}:{redos:[{id:S.id,params:{unitId:e,subUnitId:t,commentId:a}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,comment:n,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.registerRefRange(i,r=>{let a=b(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,o,!1)},e,t))}_watch(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watcherMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,i,!0);u(a,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e,i=m(r.ref),a={...r,...i};this._register(t,n,a),this._watch(t,n,a)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe(d(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};F=N([M(0,i(g)),M(1,i(P)),M(2,i(w)),M(3,i(y)),M(4,n)],F);var I=`@univerjs/sheets-thread-comment`,L=`0.20.1`;const R={};let z=class extends t{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===_.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._threadCommentModel.ensureMap(r,i),o=Array.from(a.values()).filter(e=>!e.parentId),s=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return o.forEach(({children:e,...t})=>{l.push({id:S.id,params:{unitId:r,subUnitId:i,commentId:t.id}}),u.push({id:x.id,params:{unitId:r,subUnitId:i,comment:{...t,children:s?e:void 0},sync:!s}})}),{redos:l,undos:u}}else if(e.id===h.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._threadCommentModel.ensureMap(t,n),a=Array.from(i.values()).map(e=>({...e,subUnitId:r,id:l(),threadId:l()})).filter(e=>!e.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,s=[],c=[];return a.forEach(({children:e,...n})=>{s.push({id:x.id,params:{unitId:t,subUnitId:r,comment:{...n,children:o?e:void 0},sync:!o}}),c.push({id:S.id,params:{unitId:t,subUnitId:r,commentId:n.id}})}),{redos:s,undos:c}}return{redos:[],undos:[]}}}))}};z=N([M(0,r),M(1,i(v)),M(2,i(w)),M(3,C)],z);let B=class extends s{constructor(e=R,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[P],[F],[z]].forEach(e=>{this._injector.add(e)}),f(this._injector,[[F],[z]])}};j(B,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),j(B,`packageName`,I),j(B,`version`,L),j(B,`type`,c.UNIVER_SHEET),B=N([e(T),M(1,i(a)),M(2,i(n))],B);export{P as SheetsThreadCommentModel,F as SheetsThreadCommentRefRangeController,B as UniverSheetsThreadCommentPlugin};
1
+ import { DependentOn, Disposable, ICommandService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, UniverInstanceType, generateRandomId, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
2
+ import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
3
+ import { CopySheetCommand, RefRangeService, RemoveSheetCommand, SheetInterceptorService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
4
+ import { AddCommentMutation, DeleteCommentMutation, IThreadCommentDataSourceService, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentRefMutation } from "@univerjs/thread-comment";
5
+ import { Subject } from "rxjs";
6
+
7
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
8
+ function _typeof(o) {
9
+ "@babel/helpers - typeof";
10
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
11
+ return typeof o;
12
+ } : function(o) {
13
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
14
+ }, _typeof(o);
15
+ }
16
+
17
+ //#endregion
18
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
19
+ function toPrimitive(t, r) {
20
+ if ("object" != _typeof(t) || !t) return t;
21
+ var e = t[Symbol.toPrimitive];
22
+ if (void 0 !== e) {
23
+ var i = e.call(t, r || "default");
24
+ if ("object" != _typeof(i)) return i;
25
+ throw new TypeError("@@toPrimitive must return a primitive value.");
26
+ }
27
+ return ("string" === r ? String : Number)(t);
28
+ }
29
+
30
+ //#endregion
31
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
32
+ function toPropertyKey(t) {
33
+ var i = toPrimitive(t, "string");
34
+ return "symbol" == _typeof(i) ? i : i + "";
35
+ }
36
+
37
+ //#endregion
38
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
39
+ function _defineProperty(e, r, t) {
40
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
+ value: t,
42
+ enumerable: !0,
43
+ configurable: !0,
44
+ writable: !0
45
+ }) : e[r] = t, e;
46
+ }
47
+
48
+ //#endregion
49
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
50
+ function __decorateParam(paramIndex, decorator) {
51
+ return function(target, key) {
52
+ decorator(target, key, paramIndex);
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
58
+ function __decorate(decorators, target, key, desc) {
59
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
61
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
62
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/models/sheets-thread-comment.model.ts
67
+ let SheetsThreadCommentModel = class SheetsThreadCommentModel extends Disposable {
68
+ constructor(_threadCommentModel, _univerInstanceService) {
69
+ super();
70
+ this._threadCommentModel = _threadCommentModel;
71
+ this._univerInstanceService = _univerInstanceService;
72
+ _defineProperty(this, "_matrixMap", /* @__PURE__ */ new Map());
73
+ _defineProperty(this, "_locationMap", /* @__PURE__ */ new Map());
74
+ _defineProperty(this, "_commentUpdate$", new Subject());
75
+ _defineProperty(this, "commentUpdate$", this._commentUpdate$.asObservable());
76
+ this._init();
77
+ this.disposeWithMe(() => {
78
+ this._commentUpdate$.complete();
79
+ });
80
+ }
81
+ _init() {
82
+ this._initData();
83
+ this._initUpdateTransform();
84
+ }
85
+ _ensureCommentMatrix(unitId, subUnitId) {
86
+ let unitMap = this._matrixMap.get(unitId);
87
+ if (!unitMap) {
88
+ unitMap = /* @__PURE__ */ new Map();
89
+ this._matrixMap.set(unitId, unitMap);
90
+ }
91
+ let subUnitMap = unitMap.get(subUnitId);
92
+ if (!subUnitMap) {
93
+ subUnitMap = new ObjectMatrix();
94
+ unitMap.set(subUnitId, subUnitMap);
95
+ }
96
+ return subUnitMap;
97
+ }
98
+ _ensureCommentLocationMap(unitId, subUnitId) {
99
+ let unitMap = this._locationMap.get(unitId);
100
+ if (!unitMap) {
101
+ unitMap = /* @__PURE__ */ new Map();
102
+ this._locationMap.set(unitId, unitMap);
103
+ }
104
+ let subUnitMap = unitMap.get(subUnitId);
105
+ if (!subUnitMap) {
106
+ subUnitMap = /* @__PURE__ */ new Map();
107
+ unitMap.set(subUnitId, subUnitMap);
108
+ }
109
+ return subUnitMap;
110
+ }
111
+ _addCommentToMatrix(matrix, row, column, commentId) {
112
+ var _matrix$getValue;
113
+ const current = (_matrix$getValue = matrix.getValue(row, column)) !== null && _matrix$getValue !== void 0 ? _matrix$getValue : /* @__PURE__ */ new Set();
114
+ current.add(commentId);
115
+ matrix.setValue(row, column, current);
116
+ }
117
+ _deleteCommentFromMatrix(matrix, row, column, commentId) {
118
+ if (row >= 0 && column >= 0) {
119
+ const current = matrix.getValue(row, column);
120
+ if (current && current.has(commentId)) {
121
+ current.delete(commentId);
122
+ if (current.size === 0) matrix.realDeleteValue(row, column);
123
+ }
124
+ }
125
+ }
126
+ _ensure(unitId, subUnitId) {
127
+ return {
128
+ matrix: this._ensureCommentMatrix(unitId, subUnitId),
129
+ locationMap: this._ensureCommentLocationMap(unitId, subUnitId)
130
+ };
131
+ }
132
+ _initData() {
133
+ const datas = this._threadCommentModel.getAll();
134
+ for (const data of datas) for (const thread of data.threads) {
135
+ const { unitId, subUnitId, root } = thread;
136
+ this._addComment(unitId, subUnitId, root);
137
+ }
138
+ }
139
+ _addComment(unitId, subUnitId, comment) {
140
+ const location = singleReferenceToGrid(comment.ref);
141
+ const parentId = comment.parentId;
142
+ const { row, column } = location;
143
+ const commentId = comment.id;
144
+ const { matrix, locationMap } = this._ensure(unitId, subUnitId);
145
+ if (!parentId && row >= 0 && column >= 0) {
146
+ this._addCommentToMatrix(matrix, row, column, commentId);
147
+ locationMap.set(commentId, {
148
+ row,
149
+ column
150
+ });
151
+ }
152
+ if (!parentId) this._commentUpdate$.next({
153
+ unitId,
154
+ subUnitId,
155
+ payload: comment,
156
+ type: "add",
157
+ isRoot: !parentId,
158
+ ...location
159
+ });
160
+ }
161
+ _initUpdateTransform() {
162
+ this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((update) => {
163
+ const { unitId, subUnitId } = update;
164
+ try {
165
+ if (this._univerInstanceService.getUnitType(unitId) !== UniverInstanceType.UNIVER_SHEET) return;
166
+ } catch (error) {}
167
+ const { matrix, locationMap } = this._ensure(unitId, subUnitId);
168
+ switch (update.type) {
169
+ case "add":
170
+ this._addComment(update.unitId, update.subUnitId, update.payload);
171
+ break;
172
+ case "delete": {
173
+ const { isRoot, comment } = update.payload;
174
+ if (isRoot) {
175
+ const location = singleReferenceToGrid(comment.ref);
176
+ const { row, column } = location;
177
+ this._deleteCommentFromMatrix(matrix, row, column, comment.id);
178
+ this._commentUpdate$.next({
179
+ ...update,
180
+ ...location
181
+ });
182
+ }
183
+ break;
184
+ }
185
+ case "update": {
186
+ const { commentId } = update.payload;
187
+ const comment = this._threadCommentModel.getComment(unitId, subUnitId, commentId);
188
+ if (!comment) return;
189
+ const location = singleReferenceToGrid(comment.ref);
190
+ this._commentUpdate$.next({
191
+ ...update,
192
+ ...location
193
+ });
194
+ break;
195
+ }
196
+ case "updateRef": {
197
+ const location = singleReferenceToGrid(update.payload.ref);
198
+ const { commentId } = update.payload;
199
+ const currentLoc = locationMap.get(commentId);
200
+ if (!currentLoc) return;
201
+ const { row, column } = currentLoc;
202
+ this._deleteCommentFromMatrix(matrix, row, column, commentId);
203
+ locationMap.delete(commentId);
204
+ if (location.row >= 0 && location.column >= 0) {
205
+ this._addCommentToMatrix(matrix, location.row, location.column, commentId);
206
+ locationMap.set(commentId, {
207
+ row: location.row,
208
+ column: location.column
209
+ });
210
+ }
211
+ this._commentUpdate$.next({
212
+ ...update,
213
+ ...location
214
+ });
215
+ break;
216
+ }
217
+ case "resolve": {
218
+ const { unitId, subUnitId, payload } = update;
219
+ const { locationMap } = this._ensure(unitId, subUnitId);
220
+ const location = locationMap.get(payload.commentId);
221
+ if (location) this._commentUpdate$.next({
222
+ ...update,
223
+ ...location
224
+ });
225
+ break;
226
+ }
227
+ default: break;
228
+ }
229
+ }));
230
+ }
231
+ getByLocation(unitId, subUnitId, row, column) {
232
+ var _activeComments$;
233
+ return (_activeComments$ = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved)[0]) === null || _activeComments$ === void 0 ? void 0 : _activeComments$.id;
234
+ }
235
+ getAllByLocation(unitId, subUnitId, row, column) {
236
+ const current = this._ensureCommentMatrix(unitId, subUnitId).getValue(row, column);
237
+ if (!current) return [];
238
+ return Array.from(current).map((id) => this.getComment(unitId, subUnitId, id)).filter(Boolean);
239
+ }
240
+ getComment(unitId, subUnitId, commentId) {
241
+ return this._threadCommentModel.getComment(unitId, subUnitId, commentId);
242
+ }
243
+ getCommentWithChildren(unitId, subUnitId, row, column) {
244
+ const commentId = this.getByLocation(unitId, subUnitId, row, column);
245
+ if (!commentId) return;
246
+ const comment = this.getComment(unitId, subUnitId, commentId);
247
+ if (!comment) return;
248
+ return this._threadCommentModel.getThread(unitId, subUnitId, comment.threadId);
249
+ }
250
+ showCommentMarker(unitId, subUnitId, row, column) {
251
+ const commentId = this.getByLocation(unitId, subUnitId, row, column);
252
+ if (!commentId) return false;
253
+ const comment = this.getComment(unitId, subUnitId, commentId);
254
+ if (comment && !comment.resolved) return true;
255
+ return false;
256
+ }
257
+ getSubUnitAll(unitId, subUnitId) {
258
+ return this._threadCommentModel.getUnit(unitId).filter((i) => i.subUnitId === subUnitId).map((i) => i.root);
259
+ }
260
+ };
261
+ SheetsThreadCommentModel = __decorate([__decorateParam(0, Inject(ThreadCommentModel)), __decorateParam(1, IUniverInstanceService)], SheetsThreadCommentModel);
262
+
263
+ //#endregion
264
+ //#region src/controllers/sheets-thread-comment-ref-range.controller.ts
265
+ let SheetsThreadCommentRefRangeController = class SheetsThreadCommentRefRangeController extends Disposable {
266
+ constructor(_refRangeService, _sheetsThreadCommentModel, _threadCommentModel, _selectionManagerService, _commandService) {
267
+ super();
268
+ this._refRangeService = _refRangeService;
269
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
270
+ this._threadCommentModel = _threadCommentModel;
271
+ this._selectionManagerService = _selectionManagerService;
272
+ this._commandService = _commandService;
273
+ _defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
274
+ _defineProperty(this, "_watcherMap", /* @__PURE__ */ new Map());
275
+ _defineProperty(this, "_handleRangeChange", (unitId, subUnitId, comment, resultRange, silent) => {
276
+ const commentId = comment.id;
277
+ const oldRange = {
278
+ startColumn: comment.column,
279
+ endColumn: comment.column,
280
+ startRow: comment.row,
281
+ endRow: comment.row
282
+ };
283
+ if (!resultRange) return {
284
+ redos: [{
285
+ id: DeleteCommentMutation.id,
286
+ params: {
287
+ unitId,
288
+ subUnitId,
289
+ commentId
290
+ }
291
+ }],
292
+ undos: [{
293
+ id: AddCommentMutation.id,
294
+ params: {
295
+ unitId,
296
+ subUnitId,
297
+ comment,
298
+ sync: true
299
+ }
300
+ }]
301
+ };
302
+ return {
303
+ redos: [{
304
+ id: UpdateCommentRefMutation.id,
305
+ params: {
306
+ unitId,
307
+ subUnitId,
308
+ payload: {
309
+ ref: serializeRange(resultRange),
310
+ commentId
311
+ },
312
+ silent
313
+ }
314
+ }],
315
+ undos: [{
316
+ id: UpdateCommentRefMutation.id,
317
+ params: {
318
+ unitId,
319
+ subUnitId,
320
+ payload: {
321
+ ref: serializeRange(oldRange),
322
+ commentId
323
+ },
324
+ silent
325
+ }
326
+ }]
327
+ };
328
+ });
329
+ this._initData();
330
+ this._initRefRange();
331
+ }
332
+ _getIdWithUnitId(unitId, subUnitId, id) {
333
+ return `${unitId}-${subUnitId}-${id}`;
334
+ }
335
+ _register(unitId, subUnitId, comment) {
336
+ const commentId = comment.id;
337
+ const oldRange = {
338
+ startColumn: comment.column,
339
+ endColumn: comment.column,
340
+ startRow: comment.row,
341
+ endRow: comment.row
342
+ };
343
+ this._disposableMap.set(this._getIdWithUnitId(unitId, subUnitId, commentId), this._refRangeService.registerRefRange(oldRange, (commandInfo) => {
344
+ const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
345
+ const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
346
+ if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) return {
347
+ undos: [],
348
+ redos: []
349
+ };
350
+ return this._handleRangeChange(unitId, subUnitId, comment, resultRange, false);
351
+ }, unitId, subUnitId));
352
+ }
353
+ _watch(unitId, subUnitId, comment) {
354
+ const commentId = comment.id;
355
+ const oldRange = {
356
+ startColumn: comment.column,
357
+ endColumn: comment.column,
358
+ startRow: comment.row,
359
+ endRow: comment.row
360
+ };
361
+ this._watcherMap.set(this._getIdWithUnitId(unitId, subUnitId, commentId), this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
362
+ const { redos } = this._handleRangeChange(unitId, subUnitId, comment, after, true);
363
+ sequenceExecuteAsync(redos, this._commandService, { onlyLocal: true });
364
+ }, true));
365
+ }
366
+ _unwatch(unitId, subUnitId, commentId) {
367
+ var _this$_watcherMap$get;
368
+ const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
369
+ (_this$_watcherMap$get = this._watcherMap.get(id)) === null || _this$_watcherMap$get === void 0 || _this$_watcherMap$get.dispose();
370
+ this._watcherMap.delete(id);
371
+ }
372
+ _unregister(unitId, subUnitId, commentId) {
373
+ var _this$_disposableMap$;
374
+ const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
375
+ (_this$_disposableMap$ = this._disposableMap.get(id)) === null || _this$_disposableMap$ === void 0 || _this$_disposableMap$.dispose();
376
+ this._disposableMap.delete(id);
377
+ }
378
+ _initData() {
379
+ const datas = this._threadCommentModel.getAll();
380
+ for (const data of datas) for (const thread of data.threads) {
381
+ const { unitId, subUnitId, root } = thread;
382
+ const pos = singleReferenceToGrid(root.ref);
383
+ const sheetComment = {
384
+ ...root,
385
+ ...pos
386
+ };
387
+ this._register(unitId, subUnitId, sheetComment);
388
+ this._watch(unitId, subUnitId, sheetComment);
389
+ }
390
+ }
391
+ _initRefRange() {
392
+ this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe((option) => {
393
+ const { unitId, subUnitId } = option;
394
+ switch (option.type) {
395
+ case "add": {
396
+ if (option.payload.parentId) return;
397
+ const comment = {
398
+ ...option.payload,
399
+ row: option.row,
400
+ column: option.column
401
+ };
402
+ this._register(option.unitId, option.subUnitId, comment);
403
+ this._watch(option.unitId, option.subUnitId, comment);
404
+ break;
405
+ }
406
+ case "delete":
407
+ this._unregister(unitId, subUnitId, option.payload.commentId);
408
+ this._unwatch(unitId, subUnitId, option.payload.commentId);
409
+ break;
410
+ case "updateRef": {
411
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, option.payload.commentId);
412
+ if (!comment) return;
413
+ this._unregister(unitId, subUnitId, option.payload.commentId);
414
+ const sheetComment = {
415
+ ...comment,
416
+ row: option.row,
417
+ column: option.column
418
+ };
419
+ if (!option.silent) {
420
+ this._unwatch(unitId, subUnitId, option.payload.commentId);
421
+ this._watch(unitId, subUnitId, sheetComment);
422
+ }
423
+ this._register(option.unitId, option.subUnitId, sheetComment);
424
+ break;
425
+ }
426
+ }
427
+ }));
428
+ this.disposeWithMe(toDisposable(() => {
429
+ this._disposableMap.forEach((item) => {
430
+ item.dispose();
431
+ });
432
+ this._disposableMap.clear();
433
+ }));
434
+ }
435
+ };
436
+ SheetsThreadCommentRefRangeController = __decorate([
437
+ __decorateParam(0, Inject(RefRangeService)),
438
+ __decorateParam(1, Inject(SheetsThreadCommentModel)),
439
+ __decorateParam(2, Inject(ThreadCommentModel)),
440
+ __decorateParam(3, Inject(SheetsSelectionsService)),
441
+ __decorateParam(4, ICommandService)
442
+ ], SheetsThreadCommentRefRangeController);
443
+
444
+ //#endregion
445
+ //#region package.json
446
+ var name = "@univerjs/sheets-thread-comment";
447
+ var version = "0.21.0";
448
+
449
+ //#endregion
450
+ //#region src/config/config.ts
451
+ /**
452
+ * Copyright 2023-present DreamNum Co., Ltd.
453
+ *
454
+ * Licensed under the Apache License, Version 2.0 (the "License");
455
+ * you may not use this file except in compliance with the License.
456
+ * You may obtain a copy of the License at
457
+ *
458
+ * http://www.apache.org/licenses/LICENSE-2.0
459
+ *
460
+ * Unless required by applicable law or agreed to in writing, software
461
+ * distributed under the License is distributed on an "AS IS" BASIS,
462
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
463
+ * See the License for the specific language governing permissions and
464
+ * limitations under the License.
465
+ */
466
+ const SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
467
+ const configSymbol = Symbol(SHEETS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
468
+ const defaultPluginConfig = {};
469
+
470
+ //#endregion
471
+ //#region src/controllers/sheets-thread-comment-resource.controller.ts
472
+ let SheetsThreadCommentResourceController = class SheetsThreadCommentResourceController extends Disposable {
473
+ constructor(_univerInstanceService, _sheetInterceptorService, _threadCommentModel, _threadCommentDataSourceService) {
474
+ super();
475
+ this._univerInstanceService = _univerInstanceService;
476
+ this._sheetInterceptorService = _sheetInterceptorService;
477
+ this._threadCommentModel = _threadCommentModel;
478
+ this._threadCommentDataSourceService = _threadCommentDataSourceService;
479
+ this._initSheetChange();
480
+ }
481
+ _initSheetChange() {
482
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
483
+ if (commandInfo.id === RemoveSheetCommand.id) {
484
+ var _getActiveSheet;
485
+ const params = commandInfo.params;
486
+ const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
487
+ const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
488
+ if (!unitId || !subUnitId) return {
489
+ redos: [],
490
+ undos: []
491
+ };
492
+ const commentMap = this._threadCommentModel.ensureMap(unitId, subUnitId);
493
+ const comments = Array.from(commentMap.values()).filter((comment) => !comment.parentId);
494
+ const shouldSync = this._threadCommentDataSourceService.syncUpdateMutationToColla;
495
+ const redos = [];
496
+ const undos = [];
497
+ comments.forEach(({ children, ...comment }) => {
498
+ redos.push({
499
+ id: DeleteCommentMutation.id,
500
+ params: {
501
+ unitId,
502
+ subUnitId,
503
+ commentId: comment.id
504
+ }
505
+ });
506
+ undos.push({
507
+ id: AddCommentMutation.id,
508
+ params: {
509
+ unitId,
510
+ subUnitId,
511
+ comment: {
512
+ ...comment,
513
+ children: shouldSync ? children : void 0
514
+ },
515
+ sync: !shouldSync
516
+ }
517
+ });
518
+ });
519
+ return {
520
+ redos,
521
+ undos
522
+ };
523
+ } else if (commandInfo.id === CopySheetCommand.id) {
524
+ const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
525
+ if (!unitId || !subUnitId || !targetSubUnitId) return {
526
+ redos: [],
527
+ undos: []
528
+ };
529
+ const commentMap = this._threadCommentModel.ensureMap(unitId, subUnitId);
530
+ const comments = Array.from(commentMap.values()).map((comment) => {
531
+ return {
532
+ ...comment,
533
+ subUnitId: targetSubUnitId,
534
+ id: generateRandomId(),
535
+ threadId: generateRandomId()
536
+ };
537
+ }).filter((comment) => !comment.parentId);
538
+ const shouldSync = this._threadCommentDataSourceService.syncUpdateMutationToColla;
539
+ const redos = [];
540
+ const undos = [];
541
+ comments.forEach(({ children, ...comment }) => {
542
+ redos.push({
543
+ id: AddCommentMutation.id,
544
+ params: {
545
+ unitId,
546
+ subUnitId: targetSubUnitId,
547
+ comment: {
548
+ ...comment,
549
+ children: shouldSync ? children : void 0
550
+ },
551
+ sync: !shouldSync
552
+ }
553
+ });
554
+ undos.push({
555
+ id: DeleteCommentMutation.id,
556
+ params: {
557
+ unitId,
558
+ subUnitId: targetSubUnitId,
559
+ commentId: comment.id
560
+ }
561
+ });
562
+ });
563
+ return {
564
+ redos,
565
+ undos
566
+ };
567
+ }
568
+ return {
569
+ redos: [],
570
+ undos: []
571
+ };
572
+ } }));
573
+ }
574
+ };
575
+ SheetsThreadCommentResourceController = __decorate([
576
+ __decorateParam(0, IUniverInstanceService),
577
+ __decorateParam(1, Inject(SheetInterceptorService)),
578
+ __decorateParam(2, Inject(ThreadCommentModel)),
579
+ __decorateParam(3, IThreadCommentDataSourceService)
580
+ ], SheetsThreadCommentResourceController);
581
+
582
+ //#endregion
583
+ //#region src/types/const.ts
584
+ /**
585
+ * Copyright 2023-present DreamNum Co., Ltd.
586
+ *
587
+ * Licensed under the Apache License, Version 2.0 (the "License");
588
+ * you may not use this file except in compliance with the License.
589
+ * You may obtain a copy of the License at
590
+ *
591
+ * http://www.apache.org/licenses/LICENSE-2.0
592
+ *
593
+ * Unless required by applicable law or agreed to in writing, software
594
+ * distributed under the License is distributed on an "AS IS" BASIS,
595
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
596
+ * See the License for the specific language governing permissions and
597
+ * limitations under the License.
598
+ */
599
+ const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
600
+
601
+ //#endregion
602
+ //#region src/plugin.ts
603
+ let UniverSheetsThreadCommentPlugin = class UniverSheetsThreadCommentPlugin extends Plugin {
604
+ constructor(_config = defaultPluginConfig, _injector, _commandService) {
605
+ super();
606
+ this._config = _config;
607
+ this._injector = _injector;
608
+ this._commandService = _commandService;
609
+ }
610
+ onStarting() {
611
+ [
612
+ [SheetsThreadCommentModel],
613
+ [SheetsThreadCommentRefRangeController],
614
+ [SheetsThreadCommentResourceController]
615
+ ].forEach((dep) => {
616
+ this._injector.add(dep);
617
+ });
618
+ touchDependencies(this._injector, [[SheetsThreadCommentRefRangeController], [SheetsThreadCommentResourceController]]);
619
+ }
620
+ };
621
+ _defineProperty(UniverSheetsThreadCommentPlugin, "pluginName", SHEET_THREAD_COMMENT_BASE);
622
+ _defineProperty(UniverSheetsThreadCommentPlugin, "packageName", name);
623
+ _defineProperty(UniverSheetsThreadCommentPlugin, "version", version);
624
+ _defineProperty(UniverSheetsThreadCommentPlugin, "type", UniverInstanceType.UNIVER_SHEET);
625
+ UniverSheetsThreadCommentPlugin = __decorate([
626
+ DependentOn(UniverThreadCommentPlugin),
627
+ __decorateParam(1, Inject(Injector)),
628
+ __decorateParam(2, Inject(ICommandService))
629
+ ], UniverSheetsThreadCommentPlugin);
630
+
631
+ //#endregion
632
+ export { SheetsThreadCommentModel, SheetsThreadCommentRefRangeController, UniverSheetsThreadCommentPlugin };