@univerjs/sheets-thread-comment 0.4.2-nightly.202411061606 → 0.4.2-nightly.202411081606

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.
@@ -0,0 +1 @@
1
+ "use strict";var M=Object.defineProperty;var b=(a,e,t)=>e in a?M(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var u=(a,e,t)=>b(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),_=require("@univerjs/sheets/facade"),c=require("@univerjs/thread-comment"),C=require("@univerjs/engine-formula"),I=require("rxjs");var v=Object.defineProperty,U=Object.getOwnPropertyDescriptor,T=(a,e,t,n)=>{for(var o=n>1?void 0:n?U(e,t):e,i=a.length-1,r;i>=0;i--)(r=a[i])&&(o=(n?r(e,t,o):r(o))||o);return n&&o&&v(e,t,o),o},f=(a,e)=>(t,n)=>e(t,n,a);let g=class extends m.Disposable{constructor(e,t){super();u(this,"_matrixMap",new Map);u(this,"_locationMap",new Map);u(this,"_commentUpdate$",new I.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=t,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 o=n.get(t);return o||(o=new m.ObjectMatrix,n.set(t,o)),o}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_addCommentToMatrix(e,t,n,o){var r;const i=(r=e.getValue(t,n))!=null?r:new Set;i.add(o),e.setValue(t,n,i)}_deleteCommentFromMatrix(e,t,n,o){if(t>=0&&n>=0){const i=e.getValue(t,n);i&&i.has(o)&&(i.delete(o),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){const n=this._ensureCommentMatrix(e,t),o=this._ensureCommentLocationMap(e,t);return{matrix:n,locationMap:o}}_initData(){const e=this._threadCommentModel.getAll();for(const t of e)for(const n of t.threads){const{unitId:o,subUnitId:i,root:r}=n;this._addComment(o,i,r)}}_addComment(e,t,n){const o=C.singleReferenceToGrid(n.ref),i=n.parentId,{row:r,column:s}=o,d=n.id,{matrix:l,locationMap:h}=this._ensure(e,t);!i&&r>=0&&s>=0&&(this._addCommentToMatrix(l,r,s,d),h.set(d,{row:r,column:s})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:"add",isRoot:!i,...o})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==m.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:o,locationMap:i}=this._ensure(t,n);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:r,comment:s}=e.payload;if(r){const d=C.singleReferenceToGrid(s.ref),{row:l,column:h}=d;this._deleteCommentFromMatrix(o,l,h,s.id),this._commentUpdate$.next({...e,...d})}break}case"update":{const{commentId:r}=e.payload,s=this._threadCommentModel.getComment(t,n,r);if(!s)return;const d=C.singleReferenceToGrid(s.ref);this._commentUpdate$.next({...e,...d});break}case"updateRef":{const r=C.singleReferenceToGrid(e.payload.ref),{commentId:s}=e.payload,d=i.get(s);if(!d)return;const{row:l,column:h}=d;this._deleteCommentFromMatrix(o,l,h,s),i.delete(s),r.row>=0&&r.column>=0&&(this._addCommentToMatrix(o,r.row,r.column,s),i.set(s,{row:r.row,column:r.column})),this._commentUpdate$.next({...e,...r});break}case"resolve":{const{unitId:r,subUnitId:s,payload:d}=e,{locationMap:l}=this._ensure(r,s),h=l.get(d.commentId);h&&this._commentUpdate$.next({...e,...h});break}}}))}getByLocation(e,t,n,o){var s;return(s=this.getAllByLocation(e,t,n,o).filter(d=>!d.resolved)[0])==null?void 0:s.id}getAllByLocation(e,t,n,o){const r=this._ensureCommentMatrix(e,t).getValue(n,o);return r?Array.from(r).map(s=>this.getComment(e,t,s)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,o){const i=this.getByLocation(e,t,n,o);if(!i)return;const r=this.getComment(e,t,i);if(r)return this._threadCommentModel.getThread(e,t,r.threadId)}showCommentMarker(e,t,n,o){const i=this.getByLocation(e,t,n,o);if(!i)return!1;const r=this.getComment(e,t,i);return!!(r&&!r.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(n=>n.subUnitId===t).map(n=>n.root)}};g=T([f(0,m.Inject(c.ThreadCommentModel)),f(1,m.IUniverInstanceService)],g);var x=Object.defineProperty,w=Object.getOwnPropertyDescriptor,S=(a,e,t,n)=>{for(var o=n>1?void 0:n?w(e,t):e,i=a.length-1,r;i>=0;i--)(r=a[i])&&(o=(n?r(e,t,o):r(o))||o);return n&&o&&x(e,t,o),o},p=(a,e)=>(t,n)=>e(t,n,a);exports.FThreadComment=class{constructor(e,t,n,o,i,r){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=r}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return C.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...t}=this._thread;return t}getReplies(){var n;const e=this._getRef(),t=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(n=t==null?void 0:t.children)==null?void 0:n.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,m.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;const n=this._getRef();return this._injector.createInstance(_.FRange,e,t,n)}getContent(){return this._thread.text}delete(){return this._commandService.executeCommand(this.getIsRoot()?c.DeleteCommentTreeCommand.id:c.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(e){const t=c.getDT();return await this._commandService.executeCommand(c.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:e,updated:!0,updateT:t}})}resolve(e){return this._commandService.executeCommand(c.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}};exports.FThreadComment=S([p(2,m.Inject(m.Injector)),p(3,m.ICommandService),p(4,m.IUniverInstanceService),p(5,m.Inject(g))],exports.FThreadComment);class k extends _.FRange{getComment(){const t=this._injector.get(g),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=t.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!i)return null;const r=t.getComment(n,o,i);return r?this._injector.createInstance(exports.FThreadComment,r):null}addComment(e){var h;const t=this._injector,n=(h=this.getComment())==null?void 0:h.getCommentData(),o=t.get(m.ICommandService),i=t.get(m.UserManagerService),r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),d=`${m.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,l=i.getCurrentUser();return o.executeCommand(c.AddCommentCommand.id,{unitId:r,subUnitId:s,comment:{text:e,attachments:[],dT:c.getDT(),id:m.Tools.generateRandomId(),ref:d,personId:l.userID,parentId:n==null?void 0:n.id,unitId:r,subUnitId:s,threadId:n==null?void 0:n.threadId}})}clearComment(){var r;const e=this._injector,t=(r=this.getComment())==null?void 0:r.getCommentData(),n=e.get(m.ICommandService),o=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return t?n.executeCommand(c.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:i,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}}_.FRange.extend(k);class y extends _.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(c.ThreadCommentModel)}})}onThreadCommentChange(e){return m.toDisposable(this._threadCommentModel.commentUpdate$.pipe(I.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===c.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===c.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===c.DeleteCommentCommand.id||t.id===c.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}_.FWorkbook.extend(y);class j extends _.FWorksheet{getComments(){return this._injector.get(g).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.FThreadComment,n))}}_.FWorksheet.extend(j);
@@ -0,0 +1 @@
1
+ "use strict";var w=Object.defineProperty;var S=(c,a,e)=>a in c?w(c,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[a]=e;var _=(c,a,e)=>S(c,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),u=require("@univerjs/engine-formula"),g=require("@univerjs/sheets"),f=require("@univerjs/thread-comment"),T=require("rxjs");var I=Object.defineProperty,y=Object.getOwnPropertyDescriptor,b=(c,a,e,n)=>{for(var t=n>1?void 0:n?y(a,e):a,r=c.length-1,o;r>=0;r--)(o=c[r])&&(t=(n?o(a,e,t):o(t))||t);return n&&t&&I(a,e,t),t},C=(c,a)=>(e,n)=>a(e,n,c);exports.SheetsThreadCommentModel=class extends d.Disposable{constructor(e,n){super();_(this,"_matrixMap",new Map);_(this,"_locationMap",new Map);_(this,"_commentUpdate$",new T.Subject);_(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new d.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var s;const o=(s=e.getValue(n,t))!=null?s:new Set;o.add(r),e.setValue(n,t,o)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const o=e.getValue(n,t);o&&o.has(r)&&(o.delete(r),o.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:o,root:s}=t;this._addComment(r,o,s)}}_addComment(e,n,t){const r=u.singleReferenceToGrid(t.ref),o=t.parentId,{row:s,column:i}=r,m=t.id,{matrix:h,locationMap:l}=this._ensure(e,n);!o&&s>=0&&i>=0&&(this._addCommentToMatrix(h,s,i,m),l.set(m,{row:s,column:i})),o||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!o,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==d.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:o}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:s,comment:i}=e.payload;if(s){const m=u.singleReferenceToGrid(i.ref),{row:h,column:l}=m;this._deleteCommentFromMatrix(r,h,l,i.id),this._commentUpdate$.next({...e,...m})}break}case"update":{const{commentId:s}=e.payload,i=this._threadCommentModel.getComment(n,t,s);if(!i)return;const m=u.singleReferenceToGrid(i.ref);this._commentUpdate$.next({...e,...m});break}case"updateRef":{const s=u.singleReferenceToGrid(e.payload.ref),{commentId:i}=e.payload,m=o.get(i);if(!m)return;const{row:h,column:l}=m;this._deleteCommentFromMatrix(r,h,l,i),o.delete(i),s.row>=0&&s.column>=0&&(this._addCommentToMatrix(r,s.row,s.column,i),o.set(i,{row:s.row,column:s.column})),this._commentUpdate$.next({...e,...s});break}case"resolve":{const{unitId:s,subUnitId:i,payload:m}=e,{locationMap:h}=this._ensure(s,i),l=h.get(m.commentId);l&&this._commentUpdate$.next({...e,...l});break}}}))}getByLocation(e,n,t,r){var i;return(i=this.getAllByLocation(e,n,t,r).filter(m=>!m.resolved)[0])==null?void 0:i.id}getAllByLocation(e,n,t,r){const s=this._ensureCommentMatrix(e,n).getValue(t,r);return s?Array.from(s).map(i=>this.getComment(e,n,i)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const o=this.getByLocation(e,n,t,r);if(!o)return;const s=this.getComment(e,n,o);if(s)return this._threadCommentModel.getThread(e,n,s.threadId)}showCommentMarker(e,n,t,r){const o=this.getByLocation(e,n,t,r);if(!o)return!1;const s=this.getComment(e,n,o);return!!(s&&!s.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}};exports.SheetsThreadCommentModel=b([C(0,d.Inject(f.ThreadCommentModel)),C(1,d.IUniverInstanceService)],exports.SheetsThreadCommentModel);var U=Object.defineProperty,x=Object.getOwnPropertyDescriptor,P=(c,a,e,n)=>{for(var t=n>1?void 0:n?x(a,e):a,r=c.length-1,o;r>=0;r--)(o=c[r])&&(t=(n?o(a,e,t):o(t))||t);return n&&t&&U(a,e,t),t},p=(c,a)=>(e,n)=>a(e,n,c);exports.SheetsThreadCommentRefRangeController=class extends d.Disposable{constructor(e,n,t,r,o){super();_(this,"_disposableMap",new Map);_(this,"_watcherMap",new Map);_(this,"_handleRangeChange",(e,n,t,r,o)=>{const s=t.id,i={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:f.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:u.serializeRange(r),commentId:s},silent:o}}],undos:[{id:f.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:u.serializeRange(i),commentId:s},silent:o}}]}:{redos:[{id:f.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:s}}],undos:[{id:f.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=o,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,o={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(o,s=>{const i=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(o,s,{selectionManagerService:this._selectionManagerService}),m=Array.isArray(i)?i[0]:i;return m&&m.startColumn===o.startColumn&&m.startRow===o.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,m,!1)},e,n))}_watch(e,n,t){const r=t.id,o={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,o,(s,i)=>{const{redos:m}=this._handleRangeChange(e,n,t,i,!0);d.sequenceExecuteAsync(m,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var o;const r=this._getIdWithUnitId(e,n,t);(o=this._watcherMap.get(r))==null||o.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var o;const r=this._getIdWithUnitId(e,n,t);(o=this._disposableMap.get(r))==null||o.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:o,root:s}=t,i=u.singleReferenceToGrid(s.ref),m={...s,...i};this._register(r,o,m),this._watch(r,o,m)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const o={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,o)),this._register(e.unitId,e.subUnitId,o);break}}})),this.disposeWithMe(d.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};exports.SheetsThreadCommentRefRangeController=P([p(0,d.Inject(g.RefRangeService)),p(1,d.Inject(exports.SheetsThreadCommentModel)),p(2,d.Inject(f.ThreadCommentModel)),p(3,d.Inject(g.SheetsSelectionsService)),p(4,d.ICommandService)],exports.SheetsThreadCommentRefRangeController);const $="SHEET_THREAD_COMMENT_BASE_PLUGIN";var v=Object.defineProperty,E=Object.getOwnPropertyDescriptor,j=(c,a,e)=>a in c?v(c,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[a]=e,D=(c,a,e,n)=>{for(var t=n>1?void 0:n?E(a,e):a,r=c.length-1,o;r>=0;r--)(o=c[r])&&(t=(n?o(a,e,t):o(t))||t);return n&&t&&v(a,e,t),t},M=(c,a)=>(e,n)=>a(e,n,c),R=(c,a,e)=>j(c,typeof a!="symbol"?a+"":a,e);exports.UniverSheetsThreadCommentPlugin=class extends d.Plugin{constructor(a,e,n){super(),this._injector=e,this._commandService=n}onStarting(){[[exports.SheetsThreadCommentModel],[exports.SheetsThreadCommentRefRangeController]].forEach(a=>{this._injector.add(a)}),this._injector.get(exports.SheetsThreadCommentRefRangeController)}};R(exports.UniverSheetsThreadCommentPlugin,"pluginName",$);R(exports.UniverSheetsThreadCommentPlugin,"type",d.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=D([d.DependentOn(f.UniverThreadCommentPlugin),M(1,d.Inject(d.Injector)),M(2,d.Inject(d.ICommandService))],exports.UniverSheetsThreadCommentPlugin);
package/lib/es/facade.js CHANGED
@@ -1,24 +1,182 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
3
- import { Inject, Injector, UniverInstanceType, ICommandService, IUniverInstanceService, UserManagerService, Tools, toDisposable } from "@univerjs/core";
4
- import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
5
- import { DeleteCommentTreeCommand, DeleteCommentCommand, getDT, UpdateCommentCommand, ResolveCommentCommand, AddCommentCommand, ThreadCommentModel } from "@univerjs/thread-comment";
6
- import { S as SheetsThreadCommentModel } from "../sheets-thread-comment.model-17mh6Jez.mjs";
7
- import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
8
- import { filter } from "rxjs";
9
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
10
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
11
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
12
- return kind && result && __defProp2(target, key, result), result;
13
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
14
- let FThreadComment = (_a = class {
15
- constructor(_thread, _parent, _injector, _commandService, _univerInstanceService, _threadCommentModel) {
16
- this._thread = _thread, this._parent = _parent, this._injector = _injector, this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._threadCommentModel = _threadCommentModel;
1
+ var D = Object.defineProperty;
2
+ var $ = (s, t, e) => t in s ? D(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var h = (s, t, e) => $(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { Inject as f, Disposable as B, ObjectMatrix as E, UniverInstanceType as v, IUniverInstanceService as x, Injector as P, ICommandService as g, UserManagerService as A, Tools as b, toDisposable as u } from "@univerjs/core";
5
+ import { FRange as I, FWorkbook as w, FWorksheet as S } from "@univerjs/sheets/facade";
6
+ import { ThreadCommentModel as T, DeleteCommentTreeCommand as M, DeleteCommentCommand as k, getDT as y, UpdateCommentCommand as j, ResolveCommentCommand as O, AddCommentCommand as R } from "@univerjs/thread-comment";
7
+ import { singleReferenceToGrid as p, deserializeRangeWithSheet as F } from "@univerjs/engine-formula";
8
+ import { Subject as L, filter as W } from "rxjs";
9
+ var V = Object.defineProperty, z = Object.getOwnPropertyDescriptor, H = (s, t, e, n) => {
10
+ for (var o = n > 1 ? void 0 : n ? z(t, e) : t, i = s.length - 1, r; i >= 0; i--)
11
+ (r = s[i]) && (o = (n ? r(t, e, o) : r(o)) || o);
12
+ return n && o && V(t, e, o), o;
13
+ }, U = (s, t) => (e, n) => t(e, n, s);
14
+ let _ = class extends B {
15
+ constructor(t, e) {
16
+ super();
17
+ h(this, "_matrixMap", /* @__PURE__ */ new Map());
18
+ h(this, "_locationMap", /* @__PURE__ */ new Map());
19
+ h(this, "_commentUpdate$", new L());
20
+ h(this, "commentUpdate$", this._commentUpdate$.asObservable());
21
+ this._threadCommentModel = t, this._univerInstanceService = e, this._init(), this.disposeWithMe(() => {
22
+ this._commentUpdate$.complete();
23
+ });
24
+ }
25
+ _init() {
26
+ this._initData(), this._initUpdateTransform();
27
+ }
28
+ _ensureCommentMatrix(t, e) {
29
+ let n = this._matrixMap.get(t);
30
+ n || (n = /* @__PURE__ */ new Map(), this._matrixMap.set(t, n));
31
+ let o = n.get(e);
32
+ return o || (o = new E(), n.set(e, o)), o;
33
+ }
34
+ _ensureCommentLocationMap(t, e) {
35
+ let n = this._locationMap.get(t);
36
+ n || (n = /* @__PURE__ */ new Map(), this._locationMap.set(t, n));
37
+ let o = n.get(e);
38
+ return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
39
+ }
40
+ _addCommentToMatrix(t, e, n, o) {
41
+ var r;
42
+ const i = (r = t.getValue(e, n)) != null ? r : /* @__PURE__ */ new Set();
43
+ i.add(o), t.setValue(e, n, i);
44
+ }
45
+ _deleteCommentFromMatrix(t, e, n, o) {
46
+ if (e >= 0 && n >= 0) {
47
+ const i = t.getValue(e, n);
48
+ i && i.has(o) && (i.delete(o), i.size === 0 && t.realDeleteValue(e, n));
49
+ }
50
+ }
51
+ _ensure(t, e) {
52
+ const n = this._ensureCommentMatrix(t, e), o = this._ensureCommentLocationMap(t, e);
53
+ return { matrix: n, locationMap: o };
54
+ }
55
+ _initData() {
56
+ const t = this._threadCommentModel.getAll();
57
+ for (const e of t)
58
+ for (const n of e.threads) {
59
+ const { unitId: o, subUnitId: i, root: r } = n;
60
+ this._addComment(o, i, r);
61
+ }
62
+ }
63
+ _addComment(t, e, n) {
64
+ const o = p(n.ref), i = n.parentId, { row: r, column: a } = o, m = n.id, { matrix: c, locationMap: d } = this._ensure(t, e);
65
+ !i && r >= 0 && a >= 0 && (this._addCommentToMatrix(c, r, a, m), d.set(m, { row: r, column: a })), i || this._commentUpdate$.next({
66
+ unitId: t,
67
+ subUnitId: e,
68
+ payload: n,
69
+ type: "add",
70
+ isRoot: !i,
71
+ ...o
72
+ });
73
+ }
74
+ // eslint-disable-next-line max-lines-per-function
75
+ _initUpdateTransform() {
76
+ this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((t) => {
77
+ const { unitId: e, subUnitId: n } = t;
78
+ try {
79
+ if (this._univerInstanceService.getUnitType(e) !== v.UNIVER_SHEET)
80
+ return;
81
+ } catch {
82
+ }
83
+ const { matrix: o, locationMap: i } = this._ensure(e, n);
84
+ switch (t.type) {
85
+ case "add": {
86
+ this._addComment(t.unitId, t.subUnitId, t.payload);
87
+ break;
88
+ }
89
+ case "delete": {
90
+ const { isRoot: r, comment: a } = t.payload;
91
+ if (r) {
92
+ const m = p(a.ref), { row: c, column: d } = m;
93
+ this._deleteCommentFromMatrix(o, c, d, a.id), this._commentUpdate$.next({
94
+ ...t,
95
+ ...m
96
+ });
97
+ }
98
+ break;
99
+ }
100
+ case "update": {
101
+ const { commentId: r } = t.payload, a = this._threadCommentModel.getComment(e, n, r);
102
+ if (!a)
103
+ return;
104
+ const m = p(a.ref);
105
+ this._commentUpdate$.next({
106
+ ...t,
107
+ ...m
108
+ });
109
+ break;
110
+ }
111
+ case "updateRef": {
112
+ const r = p(t.payload.ref), { commentId: a } = t.payload, m = i.get(a);
113
+ if (!m)
114
+ return;
115
+ const { row: c, column: d } = m;
116
+ this._deleteCommentFromMatrix(o, c, d, a), i.delete(a), r.row >= 0 && r.column >= 0 && (this._addCommentToMatrix(o, r.row, r.column, a), i.set(a, { row: r.row, column: r.column })), this._commentUpdate$.next({
117
+ ...t,
118
+ ...r
119
+ });
120
+ break;
121
+ }
122
+ case "resolve": {
123
+ const { unitId: r, subUnitId: a, payload: m } = t, { locationMap: c } = this._ensure(r, a), d = c.get(m.commentId);
124
+ d && this._commentUpdate$.next({
125
+ ...t,
126
+ ...d
127
+ });
128
+ break;
129
+ }
130
+ }
131
+ }));
132
+ }
133
+ getByLocation(t, e, n, o) {
134
+ var a;
135
+ return (a = this.getAllByLocation(t, e, n, o).filter((m) => !m.resolved)[0]) == null ? void 0 : a.id;
136
+ }
137
+ getAllByLocation(t, e, n, o) {
138
+ const r = this._ensureCommentMatrix(t, e).getValue(n, o);
139
+ return r ? Array.from(r).map((a) => this.getComment(t, e, a)).filter(Boolean) : [];
140
+ }
141
+ getComment(t, e, n) {
142
+ return this._threadCommentModel.getComment(t, e, n);
143
+ }
144
+ getCommentWithChildren(t, e, n, o) {
145
+ const i = this.getByLocation(t, e, n, o);
146
+ if (!i)
147
+ return;
148
+ const r = this.getComment(t, e, i);
149
+ if (r)
150
+ return this._threadCommentModel.getThread(t, e, r.threadId);
151
+ }
152
+ showCommentMarker(t, e, n, o) {
153
+ const i = this.getByLocation(t, e, n, o);
154
+ if (!i)
155
+ return !1;
156
+ const r = this.getComment(t, e, i);
157
+ return !!(r && !r.resolved);
158
+ }
159
+ getSubUnitAll(t, e) {
160
+ return this._threadCommentModel.getUnit(t).filter((n) => n.subUnitId === e).map((n) => n.root);
161
+ }
162
+ };
163
+ _ = H([
164
+ U(0, f(T)),
165
+ U(1, x)
166
+ ], _);
167
+ var N = Object.defineProperty, G = Object.getOwnPropertyDescriptor, q = (s, t, e, n) => {
168
+ for (var o = n > 1 ? void 0 : n ? G(t, e) : t, i = s.length - 1, r; i >= 0; i--)
169
+ (r = s[i]) && (o = (n ? r(t, e, o) : r(o)) || o);
170
+ return n && o && N(t, e, o), o;
171
+ }, C = (s, t) => (e, n) => t(e, n, s);
172
+ let l = class {
173
+ constructor(s, t, e, n, o, i) {
174
+ this._thread = s, this._parent = t, this._injector = e, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = i;
17
175
  }
18
176
  _getRef() {
19
- var _a2;
20
- const ref = ((_a2 = this._parent) == null ? void 0 : _a2.ref) || this._thread.ref;
21
- return deserializeRangeWithSheet(ref).range;
177
+ var e;
178
+ const s = ((e = this._parent) == null ? void 0 : e.ref) || this._thread.ref;
179
+ return F(s).range;
22
180
  }
23
181
  /**
24
182
  * Whether the comment is a root comment
@@ -32,31 +190,31 @@ let FThreadComment = (_a = class {
32
190
  * @returns The comment data
33
191
  */
34
192
  getCommentData() {
35
- const { children, ...comment } = this._thread;
36
- return comment;
193
+ const { children: s, ...t } = this._thread;
194
+ return t;
37
195
  }
38
196
  /**
39
197
  * Get the replies of the comment
40
198
  * @returns the replies of the comment
41
199
  */
42
200
  getReplies() {
43
- var _a2;
44
- const range = this._getRef(), comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
45
- return (_a2 = comments == null ? void 0 : comments.children) == null ? void 0 : _a2.map((child) => this._injector.createInstance(FThreadComment, child));
201
+ var e;
202
+ const s = this._getRef(), t = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, s.startRow, s.startColumn);
203
+ return (e = t == null ? void 0 : t.children) == null ? void 0 : e.map((n) => this._injector.createInstance(l, n));
46
204
  }
47
205
  /**
48
206
  * Get the range of the comment
49
207
  * @returns The range of the comment
50
208
  */
51
209
  getRange() {
52
- const workbook = this._univerInstanceService.getUnit(this._thread.unitId, UniverInstanceType.UNIVER_SHEET);
53
- if (!workbook)
210
+ const s = this._univerInstanceService.getUnit(this._thread.unitId, v.UNIVER_SHEET);
211
+ if (!s)
54
212
  return null;
55
- const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
56
- if (!worksheet)
213
+ const t = s.getSheetBySheetId(this._thread.subUnitId);
214
+ if (!t)
57
215
  return null;
58
- const range = this._getRef();
59
- return this._injector.createInstance(FRange, workbook, worksheet, range);
216
+ const e = this._getRef();
217
+ return this._injector.createInstance(I, s, t, e);
60
218
  }
61
219
  /**
62
220
  * Get the content of the comment
@@ -71,7 +229,7 @@ let FThreadComment = (_a = class {
71
229
  */
72
230
  delete() {
73
231
  return this._commandService.executeCommand(
74
- this.getIsRoot() ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id,
232
+ this.getIsRoot() ? M.id : k.id,
75
233
  {
76
234
  commentId: this._thread.id,
77
235
  unitId: this._thread.unitId,
@@ -84,18 +242,18 @@ let FThreadComment = (_a = class {
84
242
  * @param content The new content of the comment
85
243
  * @returns success or not
86
244
  */
87
- async update(content) {
88
- const dt = getDT();
245
+ async update(s) {
246
+ const t = y();
89
247
  return await this._commandService.executeCommand(
90
- UpdateCommentCommand.id,
248
+ j.id,
91
249
  {
92
250
  unitId: this._thread.unitId,
93
251
  subUnitId: this._thread.subUnitId,
94
252
  payload: {
95
253
  commentId: this._thread.id,
96
- text: content,
254
+ text: s,
97
255
  updated: !0,
98
- updateT: dt
256
+ updateT: t
99
257
  }
100
258
  }
101
259
  );
@@ -105,122 +263,116 @@ let FThreadComment = (_a = class {
105
263
  * @param resolved Whether the comment is resolved
106
264
  * @returns success or not
107
265
  */
108
- resolve(resolved) {
266
+ resolve(s) {
109
267
  return this._commandService.executeCommand(
110
- ResolveCommentCommand.id,
268
+ O.id,
111
269
  {
112
270
  unitId: this._thread.unitId,
113
271
  subUnitId: this._thread.subUnitId,
114
272
  commentId: this._thread.id,
115
- resolved: resolved != null ? resolved : !this._thread.resolved
273
+ resolved: s != null ? s : !this._thread.resolved
116
274
  }
117
275
  );
118
276
  }
119
- }, __name(_a, "FThreadComment"), _a);
120
- FThreadComment = __decorateClass([
121
- __decorateParam(2, Inject(Injector)),
122
- __decorateParam(3, ICommandService),
123
- __decorateParam(4, IUniverInstanceService),
124
- __decorateParam(5, Inject(SheetsThreadCommentModel))
125
- ], FThreadComment);
126
- const _FRangeCommentMixin = class _FRangeCommentMixin extends FRange {
277
+ };
278
+ l = q([
279
+ C(2, f(P)),
280
+ C(3, g),
281
+ C(4, x),
282
+ C(5, f(_))
283
+ ], l);
284
+ class J extends I {
127
285
  getComment() {
128
- const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
129
- if (!commentId)
286
+ const e = this._injector.get(_), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), i = e.getByLocation(n, o, this._range.startRow, this._range.startColumn);
287
+ if (!i)
130
288
  return null;
131
- const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
132
- return comment ? this._injector.createInstance(FThreadComment, comment) : null;
133
- }
134
- addComment(content) {
135
- var _a2;
136
- const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), userService = injector.get(UserManagerService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, currentUser = userService.getCurrentUser();
137
- return commentService.executeCommand(AddCommentCommand.id, {
138
- unitId,
139
- subUnitId: sheetId,
289
+ const r = e.getComment(n, o, i);
290
+ return r ? this._injector.createInstance(l, r) : null;
291
+ }
292
+ addComment(t) {
293
+ var d;
294
+ const e = this._injector, n = (d = this.getComment()) == null ? void 0 : d.getCommentData(), o = e.get(g), i = e.get(A), r = this._workbook.getUnitId(), a = this._worksheet.getSheetId(), m = `${b.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, c = i.getCurrentUser();
295
+ return o.executeCommand(R.id, {
296
+ unitId: r,
297
+ subUnitId: a,
140
298
  comment: {
141
- text: content,
299
+ text: t,
142
300
  attachments: [],
143
- dT: getDT(),
144
- id: Tools.generateRandomId(),
145
- ref: refStr,
146
- personId: currentUser.userID,
147
- parentId: currentComment == null ? void 0 : currentComment.id,
148
- unitId,
149
- subUnitId: sheetId,
150
- threadId: currentComment == null ? void 0 : currentComment.threadId
301
+ dT: y(),
302
+ id: b.generateRandomId(),
303
+ ref: m,
304
+ personId: c.userID,
305
+ parentId: n == null ? void 0 : n.id,
306
+ unitId: r,
307
+ subUnitId: a,
308
+ threadId: n == null ? void 0 : n.threadId
151
309
  }
152
310
  });
153
311
  }
154
312
  clearComment() {
155
- var _a2;
156
- const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId();
157
- return currentComment ? commentService.executeCommand(DeleteCommentTreeCommand.id, {
158
- unitId,
159
- subUnitId: sheetId,
160
- threadId: currentComment.threadId,
161
- commentId: currentComment.id
313
+ var r;
314
+ const t = this._injector, e = (r = this.getComment()) == null ? void 0 : r.getCommentData(), n = t.get(g), o = this._workbook.getUnitId(), i = this._worksheet.getSheetId();
315
+ return e ? n.executeCommand(M.id, {
316
+ unitId: o,
317
+ subUnitId: i,
318
+ threadId: e.threadId,
319
+ commentId: e.id
162
320
  }) : Promise.resolve(!0);
163
321
  }
164
- };
165
- __name(_FRangeCommentMixin, "FRangeCommentMixin");
166
- let FRangeCommentMixin = _FRangeCommentMixin;
167
- FRange.extend(FRangeCommentMixin);
168
- const _FWorkbookThreadCommentMixin = class _FWorkbookThreadCommentMixin extends FWorkbook {
322
+ }
323
+ I.extend(J);
324
+ class K extends w {
169
325
  _initialize() {
170
326
  Object.defineProperty(this, "_threadCommentModel", {
171
327
  get() {
172
- return this._injector.get(ThreadCommentModel);
328
+ return this._injector.get(T);
173
329
  }
174
330
  });
175
331
  }
176
- onThreadCommentChange(callback) {
177
- return toDisposable(this._threadCommentModel.commentUpdate$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
332
+ onThreadCommentChange(t) {
333
+ return u(this._threadCommentModel.commentUpdate$.pipe(W((e) => e.unitId === this._workbook.getUnitId())).subscribe(t));
178
334
  }
179
- onBeforeAddThreadComment(callback) {
180
- return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
181
- const params = commandInfo.params;
182
- if (commandInfo.id === AddCommentCommand.id) {
183
- if (params.unitId !== this._workbook.getUnitId())
335
+ onBeforeAddThreadComment(t) {
336
+ return u(this._commandService.beforeCommandExecuted((e, n) => {
337
+ const o = e.params;
338
+ if (e.id === R.id) {
339
+ if (o.unitId !== this._workbook.getUnitId())
184
340
  return;
185
- if (callback(params, options) === !1)
341
+ if (t(o, n) === !1)
186
342
  throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
187
343
  }
188
344
  }));
189
345
  }
190
- onBeforeUpdateThreadComment(callback) {
191
- return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
192
- const params = commandInfo.params;
193
- if (commandInfo.id === UpdateCommentCommand.id) {
194
- if (params.unitId !== this._workbook.getUnitId())
346
+ onBeforeUpdateThreadComment(t) {
347
+ return u(this._commandService.beforeCommandExecuted((e, n) => {
348
+ const o = e.params;
349
+ if (e.id === j.id) {
350
+ if (o.unitId !== this._workbook.getUnitId())
195
351
  return;
196
- if (callback(params, options) === !1)
352
+ if (t(o, n) === !1)
197
353
  throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
198
354
  }
199
355
  }));
200
356
  }
201
- onBeforeDeleteThreadComment(callback) {
202
- return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
203
- const params = commandInfo.params;
204
- if (commandInfo.id === DeleteCommentCommand.id || commandInfo.id === DeleteCommentTreeCommand.id) {
205
- if (params.unitId !== this._workbook.getUnitId())
357
+ onBeforeDeleteThreadComment(t) {
358
+ return u(this._commandService.beforeCommandExecuted((e, n) => {
359
+ const o = e.params;
360
+ if (e.id === k.id || e.id === M.id) {
361
+ if (o.unitId !== this._workbook.getUnitId())
206
362
  return;
207
- if (callback(params, options) === !1)
363
+ if (t(o, n) === !1)
208
364
  throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
209
365
  }
210
366
  }));
211
367
  }
212
- };
213
- __name(_FWorkbookThreadCommentMixin, "FWorkbookThreadCommentMixin");
214
- let FWorkbookThreadCommentMixin = _FWorkbookThreadCommentMixin;
215
- FWorkbook.extend(FWorkbookThreadCommentMixin);
216
- const _FWorksheetCommentMixin = class _FWorksheetCommentMixin extends FWorksheet {
368
+ }
369
+ w.extend(K);
370
+ class Q extends S {
217
371
  getComments() {
218
- return this._injector.get(SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((comment) => this._injector.createInstance(FThreadComment, comment));
372
+ return this._injector.get(_).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(l, n));
219
373
  }
220
- };
221
- __name(_FWorksheetCommentMixin, "FWorksheetCommentMixin");
222
- let FWorksheetCommentMixin = _FWorksheetCommentMixin;
223
- FWorksheet.extend(FWorksheetCommentMixin);
374
+ }
375
+ S.extend(Q);
224
376
  export {
225
- FThreadComment
377
+ l as FThreadComment
226
378
  };
package/lib/es/index.js CHANGED
@@ -1,210 +1,367 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { Inject, Disposable, sequenceExecuteAsync, toDisposable, ICommandService, UniverInstanceType, DependentOn, Injector, Plugin } from "@univerjs/core";
6
- import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
7
- import { RefRangeService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
8
- import { ThreadCommentModel, DeleteCommentMutation, AddCommentMutation, UpdateCommentRefMutation, UniverThreadCommentPlugin } from "@univerjs/thread-comment";
9
- import { S as SheetsThreadCommentModel } from "../sheets-thread-comment.model-17mh6Jez.mjs";
10
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
11
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
12
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
13
- return kind && result && __defProp$1(target, key, result), result;
14
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
15
- let SheetsThreadCommentRefRangeController = (_a = class extends Disposable {
16
- constructor(_refRangeService, _sheetsThreadCommentModel, _threadCommentModel, _selectionManagerService, _commandService) {
1
+ var x = Object.defineProperty;
2
+ var T = (i, e, r) => e in i ? x(i, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[e] = r;
3
+ var h = (i, e, r) => T(i, typeof e != "symbol" ? e + "" : e, r);
4
+ import { Inject as l, Disposable as R, ObjectMatrix as $, UniverInstanceType as y, IUniverInstanceService as E, sequenceExecuteAsync as P, toDisposable as D, ICommandService as b, DependentOn as O, Injector as A, Plugin as j } from "@univerjs/core";
5
+ import { singleReferenceToGrid as p, serializeRange as M } from "@univerjs/engine-formula";
6
+ import { RefRangeService as W, SheetsSelectionsService as L, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as B } from "@univerjs/sheets";
7
+ import { ThreadCommentModel as S, DeleteCommentMutation as N, AddCommentMutation as V, UpdateCommentRefMutation as C, UniverThreadCommentPlugin as H } from "@univerjs/thread-comment";
8
+ import { Subject as F } from "rxjs";
9
+ var z = Object.defineProperty, G = Object.getOwnPropertyDescriptor, q = (i, e, r, t) => {
10
+ for (var n = t > 1 ? void 0 : t ? G(e, r) : e, s = i.length - 1, o; s >= 0; s--)
11
+ (o = i[s]) && (n = (t ? o(e, r, n) : o(n)) || n);
12
+ return t && n && z(e, r, n), n;
13
+ }, w = (i, e) => (r, t) => e(r, t, i);
14
+ let u = class extends R {
15
+ constructor(e, r) {
17
16
  super();
18
- __publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
19
- __publicField(this, "_watcherMap", /* @__PURE__ */ new Map());
20
- __publicField(this, "_handleRangeChange", /* @__PURE__ */ __name((unitId, subUnitId, comment, resultRange, silent) => {
21
- const commentId = comment.id, oldRange = {
22
- startColumn: comment.column,
23
- endColumn: comment.column,
24
- startRow: comment.row,
25
- endRow: comment.row
17
+ h(this, "_matrixMap", /* @__PURE__ */ new Map());
18
+ h(this, "_locationMap", /* @__PURE__ */ new Map());
19
+ h(this, "_commentUpdate$", new F());
20
+ h(this, "commentUpdate$", this._commentUpdate$.asObservable());
21
+ this._threadCommentModel = e, this._univerInstanceService = r, this._init(), this.disposeWithMe(() => {
22
+ this._commentUpdate$.complete();
23
+ });
24
+ }
25
+ _init() {
26
+ this._initData(), this._initUpdateTransform();
27
+ }
28
+ _ensureCommentMatrix(e, r) {
29
+ let t = this._matrixMap.get(e);
30
+ t || (t = /* @__PURE__ */ new Map(), this._matrixMap.set(e, t));
31
+ let n = t.get(r);
32
+ return n || (n = new $(), t.set(r, n)), n;
33
+ }
34
+ _ensureCommentLocationMap(e, r) {
35
+ let t = this._locationMap.get(e);
36
+ t || (t = /* @__PURE__ */ new Map(), this._locationMap.set(e, t));
37
+ let n = t.get(r);
38
+ return n || (n = /* @__PURE__ */ new Map(), t.set(r, n)), n;
39
+ }
40
+ _addCommentToMatrix(e, r, t, n) {
41
+ var o;
42
+ const s = (o = e.getValue(r, t)) != null ? o : /* @__PURE__ */ new Set();
43
+ s.add(n), e.setValue(r, t, s);
44
+ }
45
+ _deleteCommentFromMatrix(e, r, t, n) {
46
+ if (r >= 0 && t >= 0) {
47
+ const s = e.getValue(r, t);
48
+ s && s.has(n) && (s.delete(n), s.size === 0 && e.realDeleteValue(r, t));
49
+ }
50
+ }
51
+ _ensure(e, r) {
52
+ const t = this._ensureCommentMatrix(e, r), n = this._ensureCommentLocationMap(e, r);
53
+ return { matrix: t, locationMap: n };
54
+ }
55
+ _initData() {
56
+ const e = this._threadCommentModel.getAll();
57
+ for (const r of e)
58
+ for (const t of r.threads) {
59
+ const { unitId: n, subUnitId: s, root: o } = t;
60
+ this._addComment(n, s, o);
61
+ }
62
+ }
63
+ _addComment(e, r, t) {
64
+ const n = p(t.ref), s = t.parentId, { row: o, column: a } = n, c = t.id, { matrix: m, locationMap: d } = this._ensure(e, r);
65
+ !s && o >= 0 && a >= 0 && (this._addCommentToMatrix(m, o, a, c), d.set(c, { row: o, column: a })), s || this._commentUpdate$.next({
66
+ unitId: e,
67
+ subUnitId: r,
68
+ payload: t,
69
+ type: "add",
70
+ isRoot: !s,
71
+ ...n
72
+ });
73
+ }
74
+ // eslint-disable-next-line max-lines-per-function
75
+ _initUpdateTransform() {
76
+ this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((e) => {
77
+ const { unitId: r, subUnitId: t } = e;
78
+ try {
79
+ if (this._univerInstanceService.getUnitType(r) !== y.UNIVER_SHEET)
80
+ return;
81
+ } catch {
82
+ }
83
+ const { matrix: n, locationMap: s } = this._ensure(r, t);
84
+ switch (e.type) {
85
+ case "add": {
86
+ this._addComment(e.unitId, e.subUnitId, e.payload);
87
+ break;
88
+ }
89
+ case "delete": {
90
+ const { isRoot: o, comment: a } = e.payload;
91
+ if (o) {
92
+ const c = p(a.ref), { row: m, column: d } = c;
93
+ this._deleteCommentFromMatrix(n, m, d, a.id), this._commentUpdate$.next({
94
+ ...e,
95
+ ...c
96
+ });
97
+ }
98
+ break;
99
+ }
100
+ case "update": {
101
+ const { commentId: o } = e.payload, a = this._threadCommentModel.getComment(r, t, o);
102
+ if (!a)
103
+ return;
104
+ const c = p(a.ref);
105
+ this._commentUpdate$.next({
106
+ ...e,
107
+ ...c
108
+ });
109
+ break;
110
+ }
111
+ case "updateRef": {
112
+ const o = p(e.payload.ref), { commentId: a } = e.payload, c = s.get(a);
113
+ if (!c)
114
+ return;
115
+ const { row: m, column: d } = c;
116
+ this._deleteCommentFromMatrix(n, m, d, a), s.delete(a), o.row >= 0 && o.column >= 0 && (this._addCommentToMatrix(n, o.row, o.column, a), s.set(a, { row: o.row, column: o.column })), this._commentUpdate$.next({
117
+ ...e,
118
+ ...o
119
+ });
120
+ break;
121
+ }
122
+ case "resolve": {
123
+ const { unitId: o, subUnitId: a, payload: c } = e, { locationMap: m } = this._ensure(o, a), d = m.get(c.commentId);
124
+ d && this._commentUpdate$.next({
125
+ ...e,
126
+ ...d
127
+ });
128
+ break;
129
+ }
130
+ }
131
+ }));
132
+ }
133
+ getByLocation(e, r, t, n) {
134
+ var a;
135
+ return (a = this.getAllByLocation(e, r, t, n).filter((c) => !c.resolved)[0]) == null ? void 0 : a.id;
136
+ }
137
+ getAllByLocation(e, r, t, n) {
138
+ const o = this._ensureCommentMatrix(e, r).getValue(t, n);
139
+ return o ? Array.from(o).map((a) => this.getComment(e, r, a)).filter(Boolean) : [];
140
+ }
141
+ getComment(e, r, t) {
142
+ return this._threadCommentModel.getComment(e, r, t);
143
+ }
144
+ getCommentWithChildren(e, r, t, n) {
145
+ const s = this.getByLocation(e, r, t, n);
146
+ if (!s)
147
+ return;
148
+ const o = this.getComment(e, r, s);
149
+ if (o)
150
+ return this._threadCommentModel.getThread(e, r, o.threadId);
151
+ }
152
+ showCommentMarker(e, r, t, n) {
153
+ const s = this.getByLocation(e, r, t, n);
154
+ if (!s)
155
+ return !1;
156
+ const o = this.getComment(e, r, s);
157
+ return !!(o && !o.resolved);
158
+ }
159
+ getSubUnitAll(e, r) {
160
+ return this._threadCommentModel.getUnit(e).filter((t) => t.subUnitId === r).map((t) => t.root);
161
+ }
162
+ };
163
+ u = q([
164
+ w(0, l(S)),
165
+ w(1, E)
166
+ ], u);
167
+ var J = Object.defineProperty, K = Object.getOwnPropertyDescriptor, Q = (i, e, r, t) => {
168
+ for (var n = t > 1 ? void 0 : t ? K(e, r) : e, s = i.length - 1, o; s >= 0; s--)
169
+ (o = i[s]) && (n = (t ? o(e, r, n) : o(n)) || n);
170
+ return t && n && J(e, r, n), n;
171
+ }, _ = (i, e) => (r, t) => e(r, t, i);
172
+ let f = class extends R {
173
+ constructor(e, r, t, n, s) {
174
+ super();
175
+ h(this, "_disposableMap", /* @__PURE__ */ new Map());
176
+ h(this, "_watcherMap", /* @__PURE__ */ new Map());
177
+ h(this, "_handleRangeChange", (e, r, t, n, s) => {
178
+ const o = t.id, a = {
179
+ startColumn: t.column,
180
+ endColumn: t.column,
181
+ startRow: t.row,
182
+ endRow: t.row
26
183
  };
27
- return resultRange ? {
184
+ return n ? {
28
185
  redos: [{
29
- id: UpdateCommentRefMutation.id,
186
+ id: C.id,
30
187
  params: {
31
- unitId,
32
- subUnitId,
188
+ unitId: e,
189
+ subUnitId: r,
33
190
  payload: {
34
- ref: serializeRange(resultRange),
35
- commentId
191
+ ref: M(n),
192
+ commentId: o
36
193
  },
37
- silent
194
+ silent: s
38
195
  }
39
196
  }],
40
197
  undos: [{
41
- id: UpdateCommentRefMutation.id,
198
+ id: C.id,
42
199
  params: {
43
- unitId,
44
- subUnitId,
200
+ unitId: e,
201
+ subUnitId: r,
45
202
  payload: {
46
- ref: serializeRange(oldRange),
47
- commentId
203
+ ref: M(a),
204
+ commentId: o
48
205
  },
49
- silent
206
+ silent: s
50
207
  }
51
208
  }]
52
209
  } : {
53
210
  redos: [{
54
- id: DeleteCommentMutation.id,
211
+ id: N.id,
55
212
  params: {
56
- unitId,
57
- subUnitId,
58
- commentId
213
+ unitId: e,
214
+ subUnitId: r,
215
+ commentId: o
59
216
  }
60
217
  }],
61
218
  undos: [{
62
- id: AddCommentMutation.id,
219
+ id: V.id,
63
220
  params: {
64
- unitId,
65
- subUnitId,
66
- comment,
221
+ unitId: e,
222
+ subUnitId: r,
223
+ comment: t,
67
224
  sync: !0
68
225
  }
69
226
  }]
70
227
  };
71
- }, "_handleRangeChange"));
72
- this._refRangeService = _refRangeService, this._sheetsThreadCommentModel = _sheetsThreadCommentModel, this._threadCommentModel = _threadCommentModel, this._selectionManagerService = _selectionManagerService, this._commandService = _commandService, this._initData(), this._initRefRange();
73
- }
74
- _getIdWithUnitId(unitId, subUnitId, id) {
75
- return `${unitId}-${subUnitId}-${id}`;
76
- }
77
- _register(unitId, subUnitId, comment) {
78
- const commentId = comment.id, oldRange = {
79
- startColumn: comment.column,
80
- endColumn: comment.column,
81
- startRow: comment.row,
82
- endRow: comment.row
228
+ });
229
+ this._refRangeService = e, this._sheetsThreadCommentModel = r, this._threadCommentModel = t, this._selectionManagerService = n, this._commandService = s, this._initData(), this._initRefRange();
230
+ }
231
+ _getIdWithUnitId(e, r, t) {
232
+ return `${e}-${r}-${t}`;
233
+ }
234
+ _register(e, r, t) {
235
+ const n = t.id, s = {
236
+ startColumn: t.column,
237
+ endColumn: t.column,
238
+ startRow: t.row,
239
+ endRow: t.row
83
240
  };
84
241
  this._disposableMap.set(
85
- this._getIdWithUnitId(unitId, subUnitId, commentId),
86
- this._refRangeService.registerRefRange(oldRange, (commandInfo) => {
87
- const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService }), resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
88
- return resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow ? {
242
+ this._getIdWithUnitId(e, r, n),
243
+ this._refRangeService.registerRefRange(s, (o) => {
244
+ const a = B(s, o, { selectionManagerService: this._selectionManagerService }), c = Array.isArray(a) ? a[0] : a;
245
+ return c && c.startColumn === s.startColumn && c.startRow === s.startRow ? {
89
246
  undos: [],
90
247
  redos: []
91
- } : this._handleRangeChange(unitId, subUnitId, comment, resultRange, !1);
92
- }, unitId, subUnitId)
248
+ } : this._handleRangeChange(e, r, t, c, !1);
249
+ }, e, r)
93
250
  );
94
251
  }
95
- _watch(unitId, subUnitId, comment) {
96
- const commentId = comment.id, oldRange = {
97
- startColumn: comment.column,
98
- endColumn: comment.column,
99
- startRow: comment.row,
100
- endRow: comment.row
252
+ _watch(e, r, t) {
253
+ const n = t.id, s = {
254
+ startColumn: t.column,
255
+ endColumn: t.column,
256
+ startRow: t.row,
257
+ endRow: t.row
101
258
  };
102
259
  this._watcherMap.set(
103
- this._getIdWithUnitId(unitId, subUnitId, commentId),
104
- this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
105
- const { redos } = this._handleRangeChange(unitId, subUnitId, comment, after, !0);
106
- sequenceExecuteAsync(redos, this._commandService, { onlyLocal: !0 });
260
+ this._getIdWithUnitId(e, r, n),
261
+ this._refRangeService.watchRange(e, r, s, (o, a) => {
262
+ const { redos: c } = this._handleRangeChange(e, r, t, a, !0);
263
+ P(c, this._commandService, { onlyLocal: !0 });
107
264
  }, !0)
108
265
  );
109
266
  }
110
- _unwatch(unitId, subUnitId, commentId) {
111
- var _a3;
112
- const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
113
- (_a3 = this._watcherMap.get(id)) == null || _a3.dispose(), this._watcherMap.delete(id);
267
+ _unwatch(e, r, t) {
268
+ var s;
269
+ const n = this._getIdWithUnitId(e, r, t);
270
+ (s = this._watcherMap.get(n)) == null || s.dispose(), this._watcherMap.delete(n);
114
271
  }
115
- _unregister(unitId, subUnitId, commentId) {
116
- var _a3;
117
- const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
118
- (_a3 = this._disposableMap.get(id)) == null || _a3.dispose(), this._disposableMap.delete(id);
272
+ _unregister(e, r, t) {
273
+ var s;
274
+ const n = this._getIdWithUnitId(e, r, t);
275
+ (s = this._disposableMap.get(n)) == null || s.dispose(), this._disposableMap.delete(n);
119
276
  }
120
277
  _initData() {
121
- const datas = this._threadCommentModel.getAll();
122
- for (const data of datas)
123
- for (const thread of data.threads) {
124
- const { unitId, subUnitId, root } = thread, pos = singleReferenceToGrid(root.ref), sheetComment = {
125
- ...root,
126
- ...pos
278
+ const e = this._threadCommentModel.getAll();
279
+ for (const r of e)
280
+ for (const t of r.threads) {
281
+ const { unitId: n, subUnitId: s, root: o } = t, a = p(o.ref), c = {
282
+ ...o,
283
+ ...a
127
284
  };
128
- this._register(unitId, subUnitId, sheetComment), this._watch(unitId, subUnitId, sheetComment);
285
+ this._register(n, s, c), this._watch(n, s, c);
129
286
  }
130
287
  }
131
288
  _initRefRange() {
132
289
  this.disposeWithMe(
133
- this._sheetsThreadCommentModel.commentUpdate$.subscribe((option) => {
134
- const { unitId, subUnitId } = option;
135
- switch (option.type) {
290
+ this._sheetsThreadCommentModel.commentUpdate$.subscribe((e) => {
291
+ const { unitId: r, subUnitId: t } = e;
292
+ switch (e.type) {
136
293
  case "add": {
137
- if (option.payload.parentId)
294
+ if (e.payload.parentId)
138
295
  return;
139
- const comment = {
140
- ...option.payload,
141
- row: option.row,
142
- column: option.column
296
+ const n = {
297
+ ...e.payload,
298
+ row: e.row,
299
+ column: e.column
143
300
  };
144
- this._register(option.unitId, option.subUnitId, comment), this._watch(option.unitId, option.subUnitId, comment);
301
+ this._register(e.unitId, e.subUnitId, n), this._watch(e.unitId, e.subUnitId, n);
145
302
  break;
146
303
  }
147
304
  case "delete": {
148
- this._unregister(unitId, subUnitId, option.payload.commentId), this._unwatch(unitId, subUnitId, option.payload.commentId);
305
+ this._unregister(r, t, e.payload.commentId), this._unwatch(r, t, e.payload.commentId);
149
306
  break;
150
307
  }
151
308
  case "updateRef": {
152
- const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, option.payload.commentId);
153
- if (!comment)
309
+ const n = this._sheetsThreadCommentModel.getComment(r, t, e.payload.commentId);
310
+ if (!n)
154
311
  return;
155
- this._unregister(unitId, subUnitId, option.payload.commentId);
156
- const sheetComment = {
157
- ...comment,
158
- row: option.row,
159
- column: option.column
312
+ this._unregister(r, t, e.payload.commentId);
313
+ const s = {
314
+ ...n,
315
+ row: e.row,
316
+ column: e.column
160
317
  };
161
- option.silent || (this._unwatch(unitId, subUnitId, option.payload.commentId), this._watch(unitId, subUnitId, sheetComment)), this._register(option.unitId, option.subUnitId, sheetComment);
318
+ e.silent || (this._unwatch(r, t, e.payload.commentId), this._watch(r, t, s)), this._register(e.unitId, e.subUnitId, s);
162
319
  break;
163
320
  }
164
321
  }
165
322
  })
166
- ), this.disposeWithMe(toDisposable(() => {
167
- this._disposableMap.forEach((item) => {
168
- item.dispose();
323
+ ), this.disposeWithMe(D(() => {
324
+ this._disposableMap.forEach((e) => {
325
+ e.dispose();
169
326
  }), this._disposableMap.clear();
170
327
  }));
171
328
  }
172
- }, __name(_a, "SheetsThreadCommentRefRangeController"), _a);
173
- SheetsThreadCommentRefRangeController = __decorateClass$1([
174
- __decorateParam$1(0, Inject(RefRangeService)),
175
- __decorateParam$1(1, Inject(SheetsThreadCommentModel)),
176
- __decorateParam$1(2, Inject(ThreadCommentModel)),
177
- __decorateParam$1(3, Inject(SheetsSelectionsService)),
178
- __decorateParam$1(4, ICommandService)
179
- ], SheetsThreadCommentRefRangeController);
180
- const SHEET_THREAD_COMMENT_BASE = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
181
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
182
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
183
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
184
- return kind && result && __defProp2(target, key, result), result;
185
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a2;
186
- let UniverSheetsThreadCommentPlugin = (_a2 = class extends Plugin {
187
- constructor(config, _injector, _commandService) {
188
- super(), this._injector = _injector, this._commandService = _commandService;
329
+ };
330
+ f = Q([
331
+ _(0, l(W)),
332
+ _(1, l(u)),
333
+ _(2, l(S)),
334
+ _(3, l(L)),
335
+ _(4, b)
336
+ ], f);
337
+ const X = "SHEET_THREAD_COMMENT_BASE_PLUGIN";
338
+ var I = Object.defineProperty, Y = Object.getOwnPropertyDescriptor, Z = (i, e, r) => e in i ? I(i, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[e] = r, k = (i, e, r, t) => {
339
+ for (var n = t > 1 ? void 0 : t ? Y(e, r) : e, s = i.length - 1, o; s >= 0; s--)
340
+ (o = i[s]) && (n = (t ? o(e, r, n) : o(n)) || n);
341
+ return t && n && I(e, r, n), n;
342
+ }, v = (i, e) => (r, t) => e(r, t, i), U = (i, e, r) => Z(i, typeof e != "symbol" ? e + "" : e, r);
343
+ let g = class extends j {
344
+ constructor(i, e, r) {
345
+ super(), this._injector = e, this._commandService = r;
189
346
  }
190
347
  onStarting() {
191
348
  [
192
- [SheetsThreadCommentModel],
193
- [SheetsThreadCommentRefRangeController]
194
- ].forEach((dep) => {
195
- this._injector.add(dep);
196
- }), this._injector.get(SheetsThreadCommentRefRangeController);
197
- }
198
- }, __name(_a2, "UniverSheetsThreadCommentPlugin"), _a2);
199
- __publicField2(UniverSheetsThreadCommentPlugin, "pluginName", SHEET_THREAD_COMMENT_BASE);
200
- __publicField2(UniverSheetsThreadCommentPlugin, "type", UniverInstanceType.UNIVER_SHEET);
201
- UniverSheetsThreadCommentPlugin = __decorateClass([
202
- DependentOn(UniverThreadCommentPlugin),
203
- __decorateParam(1, Inject(Injector)),
204
- __decorateParam(2, Inject(ICommandService))
205
- ], UniverSheetsThreadCommentPlugin);
349
+ [u],
350
+ [f]
351
+ ].forEach((i) => {
352
+ this._injector.add(i);
353
+ }), this._injector.get(f);
354
+ }
355
+ };
356
+ U(g, "pluginName", X);
357
+ U(g, "type", y.UNIVER_SHEET);
358
+ g = k([
359
+ O(H),
360
+ v(1, l(A)),
361
+ v(2, l(b))
362
+ ], g);
206
363
  export {
207
- SheetsThreadCommentModel,
208
- SheetsThreadCommentRefRangeController,
209
- UniverSheetsThreadCommentPlugin
364
+ u as SheetsThreadCommentModel,
365
+ f as SheetsThreadCommentRefRangeController,
366
+ g as UniverSheetsThreadCommentPlugin
210
367
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-thread-comment",
3
- "version": "0.4.2-nightly.202411061606",
3
+ "version": "0.4.2-nightly.202411081606",
4
4
  "private": false,
5
5
  "description": "Univer sheets thread comment base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -21,17 +21,20 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "import": "./lib/es/index.js",
24
+ "require": "./lib/cjs/index.js",
24
25
  "types": "./lib/types/index.d.ts"
25
26
  },
26
27
  "./*": {
27
28
  "import": "./lib/es/*",
29
+ "require": "./lib/cjs/*",
28
30
  "types": "./lib/types/index.d.ts"
29
31
  },
30
- "./lib/*": "./lib/*",
31
32
  "./facade": {
32
33
  "import": "./lib/es/facade.js",
34
+ "require": "./lib/cjs/facade.js",
33
35
  "types": "./lib/types/facade/index.d.ts"
34
- }
36
+ },
37
+ "./lib/*": "./lib/*"
35
38
  },
36
39
  "main": "./lib/es/index.js",
37
40
  "types": "./lib/types/index.d.ts",
@@ -49,10 +52,10 @@
49
52
  },
50
53
  "dependencies": {
51
54
  "@vitejs/plugin-react": "4.3.3",
52
- "@univerjs/core": "0.4.2-nightly.202411061606",
53
- "@univerjs/engine-formula": "0.4.2-nightly.202411061606",
54
- "@univerjs/sheets": "0.4.2-nightly.202411061606",
55
- "@univerjs/thread-comment": "0.4.2-nightly.202411061606"
55
+ "@univerjs/core": "0.4.2-nightly.202411081606",
56
+ "@univerjs/engine-formula": "0.4.2-nightly.202411081606",
57
+ "@univerjs/sheets": "0.4.2-nightly.202411081606",
58
+ "@univerjs/thread-comment": "0.4.2-nightly.202411081606"
56
59
  },
57
60
  "devDependencies": {
58
61
  "rxjs": "^7.8.1",
@@ -61,27 +64,30 @@
61
64
  "vitest": "^2.1.4",
62
65
  "@univerjs-infra/shared": "0.4.2"
63
66
  },
64
- "univerSpace": {
67
+ "space": {
65
68
  ".": {
66
69
  "import": "./lib/es/index.js",
70
+ "require": "./lib/cjs/index.js",
67
71
  "types": "./lib/types/index.d.ts"
68
72
  },
69
73
  "./*": {
70
74
  "import": "./lib/es/*",
75
+ "require": "./lib/cjs/*",
71
76
  "types": "./lib/types/index.d.ts"
72
77
  },
73
- "./lib/*": "./lib/*",
74
78
  "./facade": {
75
79
  "import": "./lib/es/facade.js",
80
+ "require": "./lib/cjs/facade.js",
76
81
  "types": "./lib/types/facade/index.d.ts"
77
- }
82
+ },
83
+ "./lib/*": "./lib/*"
78
84
  },
79
85
  "scripts": {
80
86
  "test": "vitest run",
81
87
  "test:watch": "vitest",
82
88
  "coverage": "vitest run --coverage",
83
89
  "lint:types": "tsc --noEmit",
84
- "build": "tsc && vite build"
90
+ "build": "tsx build.ts"
85
91
  },
86
92
  "module": "./lib/es/index.js"
87
93
  }
@@ -1,169 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { Inject, Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService } from "@univerjs/core";
6
- import { singleReferenceToGrid } from "@univerjs/engine-formula";
7
- import { ThreadCommentModel } from "@univerjs/thread-comment";
8
- import { Subject } from "rxjs";
9
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
10
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
11
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
12
- return kind && result && __defProp2(target, key, result), result;
13
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
14
- let SheetsThreadCommentModel = (_a = class extends Disposable {
15
- constructor(_threadCommentModel, _univerInstanceService) {
16
- super();
17
- __publicField(this, "_matrixMap", /* @__PURE__ */ new Map());
18
- __publicField(this, "_locationMap", /* @__PURE__ */ new Map());
19
- __publicField(this, "_commentUpdate$", new Subject());
20
- __publicField(this, "commentUpdate$", this._commentUpdate$.asObservable());
21
- this._threadCommentModel = _threadCommentModel, this._univerInstanceService = _univerInstanceService, this._init(), this.disposeWithMe(() => {
22
- this._commentUpdate$.complete();
23
- });
24
- }
25
- _init() {
26
- this._initData(), this._initUpdateTransform();
27
- }
28
- _ensureCommentMatrix(unitId, subUnitId) {
29
- let unitMap = this._matrixMap.get(unitId);
30
- unitMap || (unitMap = /* @__PURE__ */ new Map(), this._matrixMap.set(unitId, unitMap));
31
- let subUnitMap = unitMap.get(subUnitId);
32
- return subUnitMap || (subUnitMap = new ObjectMatrix(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
33
- }
34
- _ensureCommentLocationMap(unitId, subUnitId) {
35
- let unitMap = this._locationMap.get(unitId);
36
- unitMap || (unitMap = /* @__PURE__ */ new Map(), this._locationMap.set(unitId, unitMap));
37
- let subUnitMap = unitMap.get(subUnitId);
38
- return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
39
- }
40
- _addCommentToMatrix(matrix, row, column, commentId) {
41
- var _a2;
42
- const current = (_a2 = matrix.getValue(row, column)) != null ? _a2 : /* @__PURE__ */ new Set();
43
- current.add(commentId), matrix.setValue(row, column, current);
44
- }
45
- _deleteCommentFromMatrix(matrix, row, column, commentId) {
46
- if (row >= 0 && column >= 0) {
47
- const current = matrix.getValue(row, column);
48
- current && current.has(commentId) && (current.delete(commentId), current.size === 0 && matrix.realDeleteValue(row, column));
49
- }
50
- }
51
- _ensure(unitId, subUnitId) {
52
- const matrix = this._ensureCommentMatrix(unitId, subUnitId), locationMap = this._ensureCommentLocationMap(unitId, subUnitId);
53
- return { matrix, locationMap };
54
- }
55
- _initData() {
56
- const datas = this._threadCommentModel.getAll();
57
- for (const data of datas)
58
- for (const thread of data.threads) {
59
- const { unitId, subUnitId, root } = thread;
60
- this._addComment(unitId, subUnitId, root);
61
- }
62
- }
63
- _addComment(unitId, subUnitId, comment) {
64
- const location = singleReferenceToGrid(comment.ref), parentId = comment.parentId, { row, column } = location, commentId = comment.id, { matrix, locationMap } = this._ensure(unitId, subUnitId);
65
- !parentId && row >= 0 && column >= 0 && (this._addCommentToMatrix(matrix, row, column, commentId), locationMap.set(commentId, { row, column })), parentId || this._commentUpdate$.next({
66
- unitId,
67
- subUnitId,
68
- payload: comment,
69
- type: "add",
70
- isRoot: !parentId,
71
- ...location
72
- });
73
- }
74
- // eslint-disable-next-line max-lines-per-function
75
- _initUpdateTransform() {
76
- this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((update) => {
77
- const { unitId, subUnitId } = update;
78
- try {
79
- if (this._univerInstanceService.getUnitType(unitId) !== UniverInstanceType.UNIVER_SHEET)
80
- return;
81
- } catch {
82
- }
83
- const { matrix, locationMap } = this._ensure(unitId, subUnitId);
84
- switch (update.type) {
85
- case "add": {
86
- this._addComment(update.unitId, update.subUnitId, update.payload);
87
- break;
88
- }
89
- case "delete": {
90
- const { isRoot, comment } = update.payload;
91
- if (isRoot) {
92
- const location = singleReferenceToGrid(comment.ref), { row, column } = location;
93
- this._deleteCommentFromMatrix(matrix, row, column, comment.id), this._commentUpdate$.next({
94
- ...update,
95
- ...location
96
- });
97
- }
98
- break;
99
- }
100
- case "update": {
101
- const { commentId } = update.payload, comment = this._threadCommentModel.getComment(unitId, subUnitId, commentId);
102
- if (!comment)
103
- return;
104
- const location = singleReferenceToGrid(comment.ref);
105
- this._commentUpdate$.next({
106
- ...update,
107
- ...location
108
- });
109
- break;
110
- }
111
- case "updateRef": {
112
- const location = singleReferenceToGrid(update.payload.ref), { commentId } = update.payload, currentLoc = locationMap.get(commentId);
113
- if (!currentLoc)
114
- return;
115
- const { row, column } = currentLoc;
116
- this._deleteCommentFromMatrix(matrix, row, column, commentId), locationMap.delete(commentId), location.row >= 0 && location.column >= 0 && (this._addCommentToMatrix(matrix, location.row, location.column, commentId), locationMap.set(commentId, { row: location.row, column: location.column })), this._commentUpdate$.next({
117
- ...update,
118
- ...location
119
- });
120
- break;
121
- }
122
- case "resolve": {
123
- const { unitId: unitId2, subUnitId: subUnitId2, payload } = update, { locationMap: locationMap2 } = this._ensure(unitId2, subUnitId2), location = locationMap2.get(payload.commentId);
124
- location && this._commentUpdate$.next({
125
- ...update,
126
- ...location
127
- });
128
- break;
129
- }
130
- }
131
- }));
132
- }
133
- getByLocation(unitId, subUnitId, row, column) {
134
- var _a2;
135
- return (_a2 = this.getAllByLocation(unitId, subUnitId, row, column).filter((comment) => !comment.resolved)[0]) == null ? void 0 : _a2.id;
136
- }
137
- getAllByLocation(unitId, subUnitId, row, column) {
138
- const current = this._ensureCommentMatrix(unitId, subUnitId).getValue(row, column);
139
- return current ? Array.from(current).map((id) => this.getComment(unitId, subUnitId, id)).filter(Boolean) : [];
140
- }
141
- getComment(unitId, subUnitId, commentId) {
142
- return this._threadCommentModel.getComment(unitId, subUnitId, commentId);
143
- }
144
- getCommentWithChildren(unitId, subUnitId, row, column) {
145
- const commentId = this.getByLocation(unitId, subUnitId, row, column);
146
- if (!commentId)
147
- return;
148
- const comment = this.getComment(unitId, subUnitId, commentId);
149
- if (comment)
150
- return this._threadCommentModel.getThread(unitId, subUnitId, comment.threadId);
151
- }
152
- showCommentMarker(unitId, subUnitId, row, column) {
153
- const commentId = this.getByLocation(unitId, subUnitId, row, column);
154
- if (!commentId)
155
- return !1;
156
- const comment = this.getComment(unitId, subUnitId, commentId);
157
- return !!(comment && !comment.resolved);
158
- }
159
- getSubUnitAll(unitId, subUnitId) {
160
- return this._threadCommentModel.getUnit(unitId).filter((i) => i.subUnitId === subUnitId).map((i) => i.root);
161
- }
162
- }, __name(_a, "SheetsThreadCommentModel"), _a);
163
- SheetsThreadCommentModel = __decorateClass([
164
- __decorateParam(0, Inject(ThreadCommentModel)),
165
- __decorateParam(1, IUniverInstanceService)
166
- ], SheetsThreadCommentModel);
167
- export {
168
- SheetsThreadCommentModel as S
169
- };