@univerjs/sheets-thread-comment 0.5.3 → 0.5.4

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/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),c=require("@univerjs/sheets-thread-comment"),a=require("@univerjs/sheets/facade"),i=require("@univerjs/thread-comment"),g=require("@univerjs/engine-formula"),l=require("rxjs");var p=Object.defineProperty,b=Object.getOwnPropertyDescriptor,f=(m,t,e,n)=>{for(var o=n>1?void 0:n?b(t,e):t,d=m.length-1,s;d>=0;d--)(s=m[d])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&p(t,e,o),o},h=(m,t)=>(e,n)=>t(e,n,m);exports.FThreadComment=class{constructor(t,e,n,o,d,s){this._thread=t,this._parent=e,this._injector=n,this._commandService=o,this._univerInstanceService=d,this._threadCommentModel=s}_getRef(){var n;const t=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return g.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...e}=this._thread;return e}getReplies(){var n;const t=this._getRef(),e=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(n=e==null?void 0:e.children)==null?void 0:n.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const e=t.getSheetBySheetId(this._thread.subUnitId);if(!e)return null;const n=this._getRef();return this._injector.createInstance(a.FRange,t,e,n)}getContent(){return this._thread.text}delete(){return this._commandService.executeCommand(this.getIsRoot()?i.DeleteCommentTreeCommand.id:i.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(t){const e=i.getDT();return await this._commandService.executeCommand(i.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:e}})}resolve(t){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}};exports.FThreadComment=f([h(2,r.Inject(r.Injector)),h(3,r.ICommandService),h(4,r.IUniverInstanceService),h(5,r.Inject(c.SheetsThreadCommentModel))],exports.FThreadComment);class S extends a.FRange{getComment(){const e=this._injector.get(c.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),d=e.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!d)return null;const s=e.getComment(n,o,d);return s?this._injector.createInstance(exports.FThreadComment,s):null}addComment(t){var C;const e=this._injector,n=(C=this.getComment())==null?void 0:C.getCommentData(),o=e.get(r.ICommandService),d=e.get(r.UserManagerService),s=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),_=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=d.getCurrentUser();return o.executeCommand(i.AddCommentCommand.id,{unitId:s,subUnitId:u,comment:{text:t,attachments:[],dT:i.getDT(),id:r.Tools.generateRandomId(),ref:_,personId:I.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:u,threadId:n==null?void 0:n.threadId}})}clearComment(){var s;const t=this._injector,e=(s=this.getComment())==null?void 0:s.getCommentData(),n=t.get(r.ICommandService),o=this._workbook.getUnitId(),d=this._worksheet.getSheetId();return e?n.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:d,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}a.FRange.extend(S);class T extends a.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(i.ThreadCommentModel)}})}onThreadCommentChange(t){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(l.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.DeleteCommentCommand.id||e.id===i.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}a.FWorkbook.extend(T);class v extends a.FWorksheet{getComments(){return this._injector.get(c.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.FThreadComment,n))}onCommented(t){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===i.AddCommentCommand.id){const o=n.params;t(o)}})}}a.FWorksheet.extend(v);
1
+ "use strict";var b=Object.defineProperty;var U=(d,e,t)=>e in d?b(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var T=(d,e,t)=>U(d,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),C=require("@univerjs/sheets-thread-comment"),h=require("@univerjs/sheets/facade"),m=require("@univerjs/thread-comment"),v=require("@univerjs/engine-formula"),S=require("rxjs");var x=Object.defineProperty,k=Object.getOwnPropertyDescriptor,y=(d,e,t,n)=>{for(var o=n>1?void 0:n?k(e,t):e,i=d.length-1,s;i>=0;i--)(s=d[i])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&x(e,t,o),o},u=(d,e)=>(t,n)=>e(t,n,d);class p{constructor(e){T(this,"_comment",{id:r.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:r.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new p(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return r.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return g.create(r.Tools.deepClone(this._comment))}}class g extends p{static create(e){return new g(e)}setContent(e){return e instanceof r.RichTextValue?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=m.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}exports.FThreadComment=class{constructor(e,t,n,o,i,s,c){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=s,this._userManagerService=c}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return v.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,r.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(h.FRange,e,t,n)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return r.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?m.DeleteCommentTreeCommand.id:m.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){const t=e instanceof r.RichTextValue?e.getData().body:e,n=m.getDT();return await this._commandService.executeCommand(m.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:n}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(m.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}async replyAsync(e){var n;const t=e.build();return this._commandService.executeCommand(m.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:r.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(n=this._parent)==null?void 0:n.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:t.text,attachments:t.attachments,dT:t.dT||m.getDT(),personId:t.personId||this._userManagerService.getCurrentUser().userID}})}};exports.FThreadComment=y([u(2,r.Inject(r.Injector)),u(3,r.ICommandService),u(4,r.IUniverInstanceService),u(5,r.Inject(C.SheetsThreadCommentModel)),u(6,r.Inject(r.UserManagerService))],exports.FThreadComment);class D extends h.FRange{getComment(){const t=this._injector.get(C.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=t.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!i)return null;const s=t.getComment(n,o,i);return s?this._injector.createInstance(exports.FThreadComment,s):null}getComments(){const t=this._injector.get(C.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=[];return r.Range.foreach(this._range,(s,c)=>{const l=t.getByLocation(n,o,s,c);if(l){const I=t.getComment(n,o,l);I&&i.push(this._injector.createInstance(exports.FThreadComment,I))}}),i}addComment(e){var f;const t=this._injector,n=(f=this.getComment())==null?void 0:f.getCommentData(),o=t.get(r.ICommandService),i=t.get(r.UserManagerService),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),l=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=i.getCurrentUser(),_=e instanceof g?e.build():{text:e};return o.executeCommand(m.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:_.text,dT:_.dT||m.getDT(),attachments:[],id:_.id||r.generateRandomId(),ref:l,personId:_.personId||I.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:c,threadId:(n==null?void 0:n.threadId)||r.generateRandomId()}})}clearComment(){var s;const e=this._injector,t=(s=this.getComment())==null?void 0:s.getCommentData(),n=e.get(r.ICommandService),o=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return t?n.executeCommand(m.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:i,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}}h.FRange.extend(D);class R extends h.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(m.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(exports.FThreadComment,e.root))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onThreadCommentChange(e){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(S.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.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 r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.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 r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.DeleteCommentCommand.id||t.id===m.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}h.FWorkbook.extend(R);class w extends h.FWorksheet{getComments(){return this._injector.get(C.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.FThreadComment,n))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onCommented(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===m.AddCommentCommand.id){const o=n.params;e(o)}})}getCommentById(e){const n=this._injector.get(C.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(exports.FThreadComment,n)}}h.FWorksheet.extend(w);const a={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class j extends r.FEventName{get CommentAdded(){return a.CommentAdded}get BeforeCommentAdd(){return a.BeforeCommentAdd}get CommentUpdated(){return a.CommentUpdated}get BeforeCommentUpdate(){return a.BeforeCommentUpdate}get CommentDeleted(){return a.CommentDeleted}get BeforeCommentDeleted(){return a.BeforeCommentDeleted}get CommentResolved(){return a.CommentResolved}get BeforeCommentResolve(){return a.BeforeCommentResolve}}r.FEventName.extend(j);
package/lib/cjs/index.js CHANGED
@@ -1 +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);
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 R=Object.defineProperty,E=Object.getOwnPropertyDescriptor,j=(c,a,e)=>a in c?R(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&&R(a,e,t),t},M=(c,a)=>(e,n)=>a(e,n,c),v=(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)}};v(exports.UniverSheetsThreadCommentPlugin,"pluginName",$);v(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);