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