@univerjs/sheets-thread-comment 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +1 -932
- package/lib/es/index.js +1 -463
- package/lib/facade.js +1 -932
- package/lib/index.js +1 -463
- package/lib/types/controllers/sheets-thread-comment-ref-range.controller.d.ts +15 -0
- package/lib/types/controllers/sheets-thread-comment-resource.controller.d.ts +15 -0
- package/lib/types/facade/f-event.d.ts +20 -4
- package/lib/types/facade/f-range.d.ts +16 -1
- package/lib/types/facade/f-thread-comment.d.ts +18 -2
- package/lib/types/facade/f-univer.d.ts +18 -3
- package/lib/types/facade/f-workbook.d.ts +18 -2
- package/lib/types/facade/f-worksheet.d.ts +17 -2
- package/lib/types/models/sheets-thread-comment.model.d.ts +19 -3
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/types/interfaces/i-sheet-thread-comment.d.ts +16 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +10 -9
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var R=Object.defineProperty;var U=(g,e,n)=>e in g?R(g,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[e]=n;var b=(g,e,n)=>U(g,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),v=require("@univerjs/sheets-thread-comment"),I=require("@univerjs/sheets/facade"),a=require("@univerjs/thread-comment"),k=require("@univerjs/engine-formula"),S=require("rxjs"),w=require("@univerjs/core/facade");var E=Object.getOwnPropertyDescriptor,x=(g,e,n,t)=>{for(var o=t>1?void 0:t?E(e,n):e,m=g.length-1,r;m>=0;m--)(r=g[m])&&(o=r(o)||o);return o},p=(g,e)=>(n,t)=>e(n,t,g);class T{constructor(e){b(this,"_comment",{id:s.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:s.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new T(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return f.create(s.Tools.deepClone(this._comment))}}class f extends T{static create(e){return new f(e)}setContent(e){return e instanceof s.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=a.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,n,t,o,m,r,h){this._thread=e,this._parent=n,this._injector=t,this._commandService=o,this._univerInstanceService=m,this._threadCommentModel=r,this._userManagerService=h}_getRef(){var t;const e=((t=this._parent)==null?void 0:t.ref)||this._thread.ref;return k.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...n}=this._thread;return n}getReplies(){var t;const e=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(t=n==null?void 0:n.children)==null?void 0:t.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,s.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const n=e.getSheetBySheetId(this._thread.subUnitId);if(!n)return null;const t=this._getRef();return this._injector.createInstance(I.FRange,e,n,t)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return s.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?a.DeleteCommentTreeCommand.id:a.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 n=e instanceof s.RichTextValue?e.getData().body:e,t=a.getDT();return await this._commandService.executeCommand(a.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:t}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(a.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}replyAsync(e){var t;const n=e.build();return this._commandService.executeCommand(a.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:s.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((t=this._parent)==null?void 0:t.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:n.text,attachments:n.attachments,dT:n.dT||a.getDT(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};exports.FThreadComment=x([p(2,s.Inject(s.Injector)),p(3,s.ICommandService),p(4,s.IUniverInstanceService),p(5,s.Inject(v.SheetsThreadCommentModel)),p(6,s.Inject(s.UserManagerService))],exports.FThreadComment);class y extends I.FRange{getComment(){const n=this._injector.get(v.SheetsThreadCommentModel),t=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),m=n.getByLocation(t,o,this._range.startRow,this._range.startColumn);if(!m)return null;const r=n.getComment(t,o,m);return r?this._injector.createInstance(exports.FThreadComment,r):null}getComments(){const n=this._injector.get(v.SheetsThreadCommentModel),t=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),m=[];return s.Range.foreach(this._range,(r,h)=>{const i=n.getByLocation(t,o,r,h);if(i){const d=n.getComment(t,o,i);d&&m.push(this._injector.createInstance(exports.FThreadComment,d))}}),m}addComment(e){var C;const n=this._injector,t=(C=this.getComment())==null?void 0:C.getCommentData(),o=n.get(s.ICommandService),m=n.get(s.UserManagerService),r=this._workbook.getUnitId(),h=this._worksheet.getSheetId(),i=`${s.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=m.getCurrentUser(),c=e instanceof f?e.build():{text:e};return o.executeCommand(a.AddCommentCommand.id,{unitId:r,subUnitId:h,comment:{text:c.text,dT:c.dT||a.getDT(),attachments:[],id:c.id||s.generateRandomId(),ref:i,personId:c.personId||d.userID,parentId:t==null?void 0:t.id,unitId:r,subUnitId:h,threadId:(t==null?void 0:t.threadId)||s.generateRandomId()}})}clearComment(){var r;const e=this._injector,n=(r=this.getComment())==null?void 0:r.getCommentData(),t=e.get(s.ICommandService),o=this._workbook.getUnitId(),m=this._worksheet.getSheetId();return n?t.executeCommand(a.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:m,threadId:n.threadId,commentId:n.id}):Promise.resolve(!0)}clearComments(){const n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}I.FRange.extend(y);class B extends I.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(a.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(exports.FThreadComment,e.root))}clearComments(){const n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}onThreadCommentChange(e){return s.toDisposable(this._threadCommentModel.commentUpdate$.pipe(S.filter(n=>n.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.DeleteCommentCommand.id||n.id===a.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}I.FWorkbook.extend(B);class D extends I.FWorksheet{getComments(){return this._injector.get(v.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>this._injector.createInstance(exports.FThreadComment,t))}clearComments(){const n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}onCommented(e){return this._injector.get(s.ICommandService).onCommandExecuted(t=>{if(t.id===a.AddCommentCommand.id){const o=t.params;e(o)}})}getCommentById(e){const t=this._injector.get(v.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(exports.FThreadComment,t)}}I.FWorksheet.extend(D);const _={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDelete:"BeforeCommentDelete",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class A extends w.FEventName{get CommentAdded(){return _.CommentAdded}get BeforeCommentAdd(){return _.BeforeCommentAdd}get CommentUpdated(){return _.CommentUpdated}get BeforeCommentUpdate(){return _.BeforeCommentUpdate}get CommentDeleted(){return _.CommentDeleted}get BeforeCommentDelete(){return _.BeforeCommentDelete}get CommentResolved(){return _.CommentResolved}get BeforeCommentResolve(){return _.BeforeCommentResolve}}w.FEventName.extend(A);class M extends w.FUniver{_getTargetSheet(e={}){var o;const n=e.unitId?this.getUniverSheet(e.unitId):(o=this.getActiveWorkbook)==null?void 0:o.call(this);if(!n)return null;const t=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return t?{workbook:n,worksheet:t}:null}_initialize(e){const n=e.get(s.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.AddCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{comment:h}=t.params,i=r.getCommentById(h.id);i&&this.fireEvent(this.Event.CommentAdded,{workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.UpdateCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{payload:h}=t.params,i=r.getCommentById(h.commentId);i&&this.fireEvent(this.Event.CommentUpdated,{workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(t=>{if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h}=t.params;this.fireEvent(this.Event.CommentDeleted,{workbook:m,worksheet:r,commentId:h})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(t=>{var c,C,u,l;if(t.id!==a.ResolveCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h,resolved:i}=t.params,d=r.getCommentById(h);d&&this.fireEvent(this.Event.CommentResolved,{workbook:m,worksheet:r,row:(C=(c=d.getRange())==null?void 0:c.getRow())!=null?C:0,col:(l=(u=d.getRange())==null?void 0:u.getColumn())!=null?l:0,comment:d,resolved:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==a.AddCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{comment:h}=t.params,{range:i}=k.deserializeRangeWithSheet(h.ref),d={workbook:m,worksheet:r,row:i.startRow,col:i.startColumn,comment:T.create(h)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new s.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.UpdateCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{payload:h}=t.params,i=r.getCommentById(h.commentId);if(i){const l={workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i,newContent:s.RichTextValue.createByBody(h.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,l),l.cancel)throw new s.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h}=t.params,i=r.getCommentById(h);if(i){const l={workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i};if(this.fireEvent(this.Event.BeforeCommentDelete,l),l.cancel)throw new s.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{var c,C;if(t.id!==a.ResolveCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h,resolved:i}=t.params,d=r.getCommentById(h);if(d){const u={workbook:m,worksheet:r,row:(c=d.getRange().getRow())!=null?c:0,col:(C=d.getRange().getColumn())!=null?C:0,comment:d,resolved:i};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new s.CanceledError}})))}newTheadComment(e){return new f(e)}}w.FUniver.extend(M);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-thread-comment`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/thread-comment`),i=require(`@univerjs/engine-formula`),a=require(`rxjs`),o=require(`@univerjs/core/facade`);function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var p,m=class t{static create(e){return new t(e)}constructor(t){u(this,`_comment`,{id:(0,e.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:e.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),t&&(this._comment=t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return e.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return h.create(e.Tools.deepClone(this._comment))}},h=class t extends m{static create(e){return new t(e)}setContent(t){return t instanceof e.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=(0,r.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let g=p=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,i.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(p,e))}getRange(){let t=this._univerInstanceService.getUnit(this._thread.unitId,e.UniverInstanceType.UNIVER_SHEET);if(!t)return null;let r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;let i=this._getRef();return this._injector.createInstance(n.FRange,t,r,i)}getContent(){return this._thread.text}getRichText(){let t=this._thread.text;return e.RichTextValue.create({body:t,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?r.DeleteCommentTreeCommand.id:r.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(t){let n=t instanceof e.RichTextValue?t.getData().body:t,i=(0,r.getDT)();return await this._commandService.executeCommand(r.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:i}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(r.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(t){var n;let i=t.build();return this._commandService.executeCommand(r.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,e.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:i.text,attachments:i.attachments,dT:i.dT||(0,r.getDT)(),personId:i.personId||this._userManagerService.getCurrentUser().userID}})}};g=p=f([d(2,(0,e.Inject)(e.Injector)),d(3,e.ICommandService),d(4,e.IUniverInstanceService),d(5,(0,e.Inject)(t.SheetsThreadCommentModel)),d(6,(0,e.Inject)(e.UserManagerService))],g);var _=class extends n.FRange{getComment(){let e=this._injector.get(t.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(n,r,i);return a?this._injector.createInstance(g,a):null}getComments(){let n=this._injector.get(t.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return e.Range.foreach(this._range,(e,t)=>{let o=n.getByLocation(r,i,e,t);if(o){let e=n.getComment(r,i,o);e&&a.push(this._injector.createInstance(g,e))}}),a}addComment(t){var n;let i=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=i.get(e.ICommandService),s=i.get(e.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${e.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=t instanceof h?t.build():{text:t};return o.executeCommand(r.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,r.getDT)(),attachments:[],id:f.id||(0,e.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,e.generateRandomId)()}})}clearComment(){var t;let n=this._injector,i=(t=this.getComment())==null?void 0:t.getCommentData(),a=n.get(e.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return i?a.executeCommand(r.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:i.threadId,commentId:i.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};n.FRange.extend(_);var v=class extends n.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(r.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(g,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(t){return(0,e.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,a.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.AddCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.UpdateCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.DeleteCommentCommand.id||e.id===r.DeleteCommentTreeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};n.FWorkbook.extend(v);var y=class extends n.FWorksheet{getComments(){return this._injector.get(t.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(g,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(t){return this._injector.get(e.ICommandService).onCommandExecuted(e=>{if(e.id===r.AddCommentCommand.id){let n=e.params;t(n)}})}getCommentById(e){let n=this._injector.get(t.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(g,n)}};n.FWorksheet.extend(y);const b={CommentAdded:`CommentAdded`,BeforeCommentAdd:`BeforeCommentAdd`,CommentUpdated:`CommentUpdated`,BeforeCommentUpdate:`BeforeCommentUpdate`,CommentDeleted:`CommentDeleted`,BeforeCommentDelete:`BeforeCommentDelete`,CommentResolved:`CommentResolved`,BeforeCommentResolve:`BeforeCommentResolve`};var x=class extends o.FEventName{get CommentAdded(){return b.CommentAdded}get BeforeCommentAdd(){return b.BeforeCommentAdd}get CommentUpdated(){return b.CommentUpdated}get BeforeCommentUpdate(){return b.BeforeCommentUpdate}get CommentDeleted(){return b.CommentDeleted}get BeforeCommentDelete(){return b.BeforeCommentDelete}get CommentResolved(){return b.CommentResolved}get BeforeCommentResolve(){return b.BeforeCommentResolve}};o.FEventName.extend(x);var S=class extends o.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(t){let n=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{if(e.id!==r.AddCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{comment:a}=e.params,o=i.getCommentById(a.id);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentAdded,{workbook:n,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{if(e.id!==r.UpdateCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{payload:a}=e.params,o=i.getCommentById(a.commentId);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentUpdated,{workbook:n,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==r.DeleteCommentCommand.id&&e.id!==r.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:n,worksheet:i,commentId:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{if(e.id!==r.ResolveCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a,resolved:o}=e.params,s=i.getCommentById(a);if(s){var c,l,u,d;this.fireEvent(this.Event.CommentResolved,{workbook:n,worksheet:i,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,resolved:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.AddCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:a,worksheet:o}=n,{comment:s}=t.params,{range:c}=(0,i.deserializeRangeWithSheet)(s.ref),l={workbook:a,worksheet:o,row:c.startRow,col:c.startColumn,comment:m.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.UpdateCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{payload:o}=t.params,s=a.getCommentById(o.commentId);if(s){var c,l,u,d;let t={workbook:i,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,newContent:e.RichTextValue.createByBody(o.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,t),t.cancel)throw new e.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.DeleteCommentCommand.id&&t.id!==r.DeleteCommentTreeCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{commentId:o}=t.params,s=a.getCommentById(o);if(s){var c,l,u,d;let t={workbook:i,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s};if(this.fireEvent(this.Event.BeforeCommentDelete,t),t.cancel)throw new e.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.ResolveCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{commentId:o,resolved:s}=t.params,c=a.getCommentById(o);if(c){var l,u;let t={workbook:i,worksheet:a,row:(l=c.getRange().getRow())==null?0:l,col:(u=c.getRange().getColumn())==null?0:u,comment:c,resolved:s};if(this.fireEvent(this.Event.BeforeCommentResolve,t),t.cancel)throw new e.CanceledError}})))}newTheadComment(e){return new h(e)}};o.FUniver.extend(S),Object.defineProperty(exports,`FThreadComment`,{enumerable:!0,get:function(){return g}});
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var y=(i,a,e)=>a in i?w(i,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[a]=e;var _=(i,a,e)=>y(i,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),p=require("@univerjs/engine-formula"),C=require("@univerjs/sheets"),u=require("@univerjs/thread-comment"),U=require("rxjs");var b=Object.getOwnPropertyDescriptor,D=(i,a,e,n)=>{for(var t=n>1?void 0:n?b(a,e):a,r=i.length-1,s;r>=0;r--)(s=i[r])&&(t=s(t)||t);return t},I=(i,a)=>(e,n)=>a(e,n,i);exports.SheetsThreadCommentModel=class extends m.Disposable{constructor(e,n){super();_(this,"_matrixMap",new Map);_(this,"_locationMap",new Map);_(this,"_commentUpdate$",new U.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 m.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 o;const s=(o=e.getValue(n,t))!=null?o:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.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:s,root:o}=t;this._addComment(r,s,o)}}_addComment(e,n,t){const r=p.singleReferenceToGrid(t.ref),s=t.parentId,{row:o,column:c}=r,d=t.id,{matrix:l,locationMap:h}=this._ensure(e,n);!s&&o>=0&&c>=0&&(this._addCommentToMatrix(l,o,c,d),h.set(d,{row:o,column:c})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==m.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:o,comment:c}=e.payload;if(o){const d=p.singleReferenceToGrid(c.ref),{row:l,column:h}=d;this._deleteCommentFromMatrix(r,l,h,c.id),this._commentUpdate$.next({...e,...d})}break}case"update":{const{commentId:o}=e.payload,c=this._threadCommentModel.getComment(n,t,o);if(!c)return;const d=p.singleReferenceToGrid(c.ref);this._commentUpdate$.next({...e,...d});break}case"updateRef":{const o=p.singleReferenceToGrid(e.payload.ref),{commentId:c}=e.payload,d=s.get(c);if(!d)return;const{row:l,column:h}=d;this._deleteCommentFromMatrix(r,l,h,c),s.delete(c),o.row>=0&&o.column>=0&&(this._addCommentToMatrix(r,o.row,o.column,c),s.set(c,{row:o.row,column:o.column})),this._commentUpdate$.next({...e,...o});break}case"resolve":{const{unitId:o,subUnitId:c,payload:d}=e,{locationMap:l}=this._ensure(o,c),h=l.get(d.commentId);h&&this._commentUpdate$.next({...e,...h});break}}}))}getByLocation(e,n,t,r){var c;return(c=this.getAllByLocation(e,n,t,r).filter(d=>!d.resolved)[0])==null?void 0:c.id}getAllByLocation(e,n,t,r){const o=this._ensureCommentMatrix(e,n).getValue(t,r);return o?Array.from(o).map(c=>this.getComment(e,n,c)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const o=this.getComment(e,n,s);if(o)return this._threadCommentModel.getThread(e,n,o.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const o=this.getComment(e,n,s);return!!(o&&!o.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}};exports.SheetsThreadCommentModel=D([I(0,m.Inject(u.ThreadCommentModel)),I(1,m.IUniverInstanceService)],exports.SheetsThreadCommentModel);var E=Object.getOwnPropertyDescriptor,P=(i,a,e,n)=>{for(var t=n>1?void 0:n?E(a,e):a,r=i.length-1,s;r>=0;r--)(s=i[r])&&(t=s(t)||t);return t},g=(i,a)=>(e,n)=>a(e,n,i);exports.SheetsThreadCommentRefRangeController=class extends m.Disposable{constructor(e,n,t,r,s){super();_(this,"_disposableMap",new Map);_(this,"_watcherMap",new Map);_(this,"_handleRangeChange",(e,n,t,r,s)=>{const o=t.id,c={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:u.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(r),commentId:o},silent:s}}],undos:[{id:u.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(c),commentId:o},silent:s}}]}:{redos:[{id:u.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:o}}],undos:[{id:u.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=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,o=>{const c=C.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,o,{selectionManagerService:this._selectionManagerService}),d=Array.isArray(c)?c[0]:c;return d&&d.startColumn===s.startColumn&&d.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,d,!1)},e,n))}_watch(e,n,t){const r=t.id,s={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,s,(o,c)=>{const{redos:d}=this._handleRangeChange(e,n,t,c,!0);m.sequenceExecuteAsync(d,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.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:s,root:o}=t,c=p.singleReferenceToGrid(o.ref),d={...o,...c};this._register(r,s,d),this._watch(r,s,d)}}_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 s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(m.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};exports.SheetsThreadCommentRefRangeController=P([g(0,m.Inject(C.RefRangeService)),g(1,m.Inject(exports.SheetsThreadCommentModel)),g(2,m.Inject(u.ThreadCommentModel)),g(3,m.Inject(C.SheetsSelectionsService)),g(4,m.ICommandService)],exports.SheetsThreadCommentRefRangeController);const x="@univerjs/sheets-thread-comment",$="0.17.0",T={name:x,version:$},j={};var O=Object.getOwnPropertyDescriptor,A=(i,a,e,n)=>{for(var t=n>1?void 0:n?O(a,e):a,r=i.length-1,s;r>=0;r--)(s=i[r])&&(t=s(t)||t);return t},f=(i,a)=>(e,n)=>a(e,n,i);let M=class extends m.Disposable{constructor(i,a,e,n){super(),this._univerInstanceService=i,this._sheetInterceptorService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var a;if(i.id===C.RemoveSheetCommand.id){const e=i.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(m.UniverInstanceType.UNIVER_SHEET).getUnitId(),t=e.subUnitId||((a=this._univerInstanceService.getCurrentUnitOfType(m.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:a.getSheetId());if(!n||!t)return{redos:[],undos:[]};const r=this._threadCommentModel.ensureMap(n,t),s=Array.from(r.values()).filter(l=>!l.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,c=[],d=[];return s.forEach(({children:l,...h})=>{c.push({id:u.DeleteCommentMutation.id,params:{unitId:n,subUnitId:t,commentId:h.id}}),d.push({id:u.AddCommentMutation.id,params:{unitId:n,subUnitId:t,comment:{...h,children:o?l:void 0},sync:!o}})}),{redos:c,undos:d}}else if(i.id===C.CopySheetCommand.id){const e=i.params,{unitId:n,subUnitId:t,targetSubUnitId:r}=e;if(!n||!t||!r)return{redos:[],undos:[]};const s=this._threadCommentModel.ensureMap(n,t),o=Array.from(s.values()).map(h=>({...h,subUnitId:r,id:m.generateRandomId(),threadId:m.generateRandomId()})).filter(h=>!h.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,d=[],l=[];return o.forEach(({children:h,...S})=>{d.push({id:u.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:{...S,children:c?h:void 0},sync:!c}}),l.push({id:u.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:S.id}})}),{redos:d,undos:l}}return{redos:[],undos:[]}}}))}};M=A([f(0,m.IUniverInstanceService),f(1,m.Inject(C.SheetInterceptorService)),f(2,m.Inject(u.ThreadCommentModel)),f(3,u.IThreadCommentDataSourceService)],M);const W="SHEET_THREAD_COMMENT_BASE_PLUGIN";var N=Object.defineProperty,L=Object.getOwnPropertyDescriptor,V=(i,a,e)=>a in i?N(i,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[a]=e,B=(i,a,e,n)=>{for(var t=n>1?void 0:n?L(a,e):a,r=i.length-1,s;r>=0;r--)(s=i[r])&&(t=s(t)||t);return t},R=(i,a)=>(e,n)=>a(e,n,i),v=(i,a,e)=>V(i,typeof a!="symbol"?a+"":a,e);exports.UniverSheetsThreadCommentPlugin=class extends m.Plugin{constructor(a=j,e,n){super(),this._config=a,this._injector=e,this._commandService=n}onStarting(){[[exports.SheetsThreadCommentModel],[exports.SheetsThreadCommentRefRangeController],[M]].forEach(a=>{this._injector.add(a)}),m.touchDependencies(this._injector,[[exports.SheetsThreadCommentRefRangeController],[M]])}};v(exports.UniverSheetsThreadCommentPlugin,"pluginName",W);v(exports.UniverSheetsThreadCommentPlugin,"packageName",T.name);v(exports.UniverSheetsThreadCommentPlugin,"version",T.version);v(exports.UniverSheetsThreadCommentPlugin,"type",m.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=B([m.DependentOn(u.UniverThreadCommentPlugin),R(1,m.Inject(m.Injector)),R(2,m.Inject(m.ICommandService))],exports.UniverSheetsThreadCommentPlugin);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-formula`),n=require(`@univerjs/sheets`),r=require(`@univerjs/thread-comment`),i=require(`rxjs`);function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,c(this,`_matrixMap`,new Map),c(this,`_locationMap`,new Map),c(this,`_commentUpdate$`,new i.Subject),c(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(t,n){let r=this._matrixMap.get(t);r||(r=new Map,this._matrixMap.set(t,r));let i=r.get(n);return i||(i=new e.ObjectMatrix,r.set(n,i)),i}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,n,r){let i=(0,t.singleReferenceToGrid)(r.ref),a=r.parentId,{row:o,column:s}=i,c=r.id,{matrix:l,locationMap:u}=this._ensure(e,n);!a&&o>=0&&s>=0&&(this._addCommentToMatrix(l,o,s,c),u.set(c,{row:o,column:s})),a||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:r,type:`add`,isRoot:!a,...i})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(n=>{let{unitId:r,subUnitId:i}=n;try{if(this._univerInstanceService.getUnitType(r)!==e.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:a,locationMap:o}=this._ensure(r,i);switch(n.type){case`add`:this._addComment(n.unitId,n.subUnitId,n.payload);break;case`delete`:{let{isRoot:e,comment:r}=n.payload;if(e){let e=(0,t.singleReferenceToGrid)(r.ref),{row:i,column:o}=e;this._deleteCommentFromMatrix(a,i,o,r.id),this._commentUpdate$.next({...n,...e})}break}case`update`:{let{commentId:e}=n.payload,a=this._threadCommentModel.getComment(r,i,e);if(!a)return;let o=(0,t.singleReferenceToGrid)(a.ref);this._commentUpdate$.next({...n,...o});break}case`updateRef`:{let e=(0,t.singleReferenceToGrid)(n.payload.ref),{commentId:r}=n.payload,i=o.get(r);if(!i)return;let{row:s,column:c}=i;this._deleteCommentFromMatrix(a,s,c,r),o.delete(r),e.row>=0&&e.column>=0&&(this._addCommentToMatrix(a,e.row,e.column,r),o.set(r,{row:e.row,column:e.column})),this._commentUpdate$.next({...n,...e});break}case`resolve`:{let{unitId:e,subUnitId:t,payload:r}=n,{locationMap:i}=this._ensure(e,t),a=i.get(r.commentId);a&&this._commentUpdate$.next({...n,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};d=u([l(0,(0,e.Inject)(r.ThreadCommentModel)),l(1,e.IUniverInstanceService)],d);let f=class extends e.Disposable{constructor(e,n,i,a,o){super(),this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=i,this._selectionManagerService=a,this._commandService=o,c(this,`_disposableMap`,new Map),c(this,`_watcherMap`,new Map),c(this,`_handleRangeChange`,(e,n,i,a,o)=>{let s=i.id,c={startColumn:i.column,endColumn:i.column,startRow:i.row,endRow:i.row};return a?{redos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(a),commentId:s},silent:o}}],undos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(c),commentId:s},silent:o}}]}:{redos:[{id:r.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:s}}],undos:[{id:r.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:i,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._disposableMap.set(this._getIdWithUnitId(e,t,i),this._refRangeService.registerRefRange(a,i=>{let o=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,s,!1)},e,t))}_watch(t,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watcherMap.set(this._getIdWithUnitId(t,n,i),this._refRangeService.watchRange(t,n,a,(i,a)=>{let{redos:o}=this._handleRangeChange(t,n,r,a,!0);(0,e.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let n of e)for(let e of n.threads){let{unitId:n,subUnitId:r,root:i}=e,a=(0,t.singleReferenceToGrid)(i.ref),o={...i,...a};this._register(n,r,o),this._watch(n,r,o)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};f=u([l(0,(0,e.Inject)(n.RefRangeService)),l(1,(0,e.Inject)(d)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,(0,e.Inject)(n.SheetsSelectionsService)),l(4,e.ICommandService)],f);var p=`@univerjs/sheets-thread-comment`,m=`0.18.0`;const h={};let g=class extends e.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.RemoveSheetCommand.id){var i;let n=t.params,a=n.unitId||this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=n.subUnitId||((i=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:i.getSheetId());if(!a||!o)return{redos:[],undos:[]};let s=this._threadCommentModel.ensureMap(a,o),c=Array.from(s.values()).filter(e=>!e.parentId),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=[],d=[];return c.forEach(({children:e,...t})=>{u.push({id:r.DeleteCommentMutation.id,params:{unitId:a,subUnitId:o,commentId:t.id}}),d.push({id:r.AddCommentMutation.id,params:{unitId:a,subUnitId:o,comment:{...t,children:l?e:void 0},sync:!l}})}),{redos:u,undos:d}}else if(t.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:i,targetSubUnitId:a}=t.params;if(!n||!i||!a)return{redos:[],undos:[]};let o=this._threadCommentModel.ensureMap(n,i),s=Array.from(o.values()).map(t=>({...t,subUnitId:a,id:(0,e.generateRandomId)(),threadId:(0,e.generateRandomId)()})).filter(e=>!e.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return s.forEach(({children:e,...t})=>{l.push({id:r.AddCommentMutation.id,params:{unitId:n,subUnitId:a,comment:{...t,children:c?e:void 0},sync:!c}}),u.push({id:r.DeleteCommentMutation.id,params:{unitId:n,subUnitId:a,commentId:t.id}})}),{redos:l,undos:u}}return{redos:[],undos:[]}}}))}};g=u([l(0,e.IUniverInstanceService),l(1,(0,e.Inject)(n.SheetInterceptorService)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,r.IThreadCommentDataSourceService)],g);let _=class extends e.Plugin{constructor(e=h,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[d],[f],[g]].forEach(e=>{this._injector.add(e)}),(0,e.touchDependencies)(this._injector,[[f],[g]])}};c(_,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),c(_,`packageName`,p),c(_,`version`,m),c(_,`type`,e.UniverInstanceType.UNIVER_SHEET),_=u([(0,e.DependentOn)(r.UniverThreadCommentPlugin),l(1,(0,e.Inject)(e.Injector)),l(2,(0,e.Inject)(e.ICommandService))],_),Object.defineProperty(exports,`SheetsThreadCommentModel`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`SheetsThreadCommentRefRangeController`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`UniverSheetsThreadCommentPlugin`,{enumerable:!0,get:function(){return _}});
|