@univerjs/thread-comment 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var L=(a,r,t)=>r in a?j(a,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[r]=t;var C=(a,r,t)=>L(a,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("rxjs"),i=require("@univerjs/core"),f=require("@wendellhu/redi");class $ extends i.Disposable{constructor(){super();C(this,"_dataSource",null);C(this,"syncUpdateMutationToColla",!0)}set dataSource(t){this._dataSource=t}get dataSource(){return this._dataSource}async getThreadComment(t,n,e){return this._dataSource?(await this._dataSource.listComments(t,n,[e]))[0]:null}async addComment(t){return this._dataSource?this._dataSource.addComment(t):t}async updateComment(t){return this._dataSource?this._dataSource.updateComment(t):!0}async resolveComment(t){return this._dataSource?this._dataSource.resolveComment(t):!0}async deleteComment(t,n,e,o){return this._dataSource?this._dataSource.deleteComment(t,n,e,o):!0}async listThreadComments(t,n,e){return this.dataSource?this.dataSource.listComments(t,n,e):[]}saveToSnapshot(t,n){if(this._dataSource){const e={};return Object.keys(t).forEach(o=>{const m=t[o];e[o]=m.map(this.dataSource.saveCommentToSnapshot)}),e}return t}}const p=f.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(a,r,t,n)=>{for(var e=n>1?void 0:n?W(r,t):r,o=a.length-1,m;o>=0;o--)(m=a[o])&&(e=(n?m(r,t,e):m(e))||e);return n&&e&&V(r,t,e),e},R=(a,r)=>(t,n)=>r(t,n,a);exports.ThreadCommentModel=class extends i.Disposable{constructor(t,n){super();C(this,"_commentsMap",{});C(this,"_commentsTreeMap",new Map);C(this,"_threadMap",new Map);C(this,"_commentUpdate$",new S.Subject);C(this,"_commentsMap$",new S.BehaviorSubject({}));C(this,"commentUpdate$",this._commentUpdate$.asObservable());C(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=t,this._commandService=n,this.disposeWithMe(()=>{this._commentUpdate$.complete(),this._commentsMap$.complete()})}_ensureCommentMap(t,n){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let o=e[n];return o||(o={},e[n]=o),o}_ensureCommentChildrenMap(t,n){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let o=e.get(n);return o||(o=new Map,e.set(n,o)),o}_ensureThreadMap(t){let n=this._threadMap.get(t);return n||(n=new Map,this._threadMap.set(t,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(t,n){const e=this._ensureCommentMap(t,n),o=this._ensureCommentChildrenMap(t,n);return{commentMap:e,commentChildrenMap:o}}_replaceComment(t,n,e){var d;const{commentMap:o,commentChildrenMap:m}=this.ensureMap(t,n),s=o[e.id];if(s){const c={...e,ref:s.ref};o[e.id]=c,(d=e.children)==null||d.forEach(h=>{o[h.id]={...h,ref:""}}),m.set(e.id,c),this._commentUpdate$.next({unitId:t,subUnitId:n,type:"syncUpdate",payload:c}),!!e.resolved!=!!s.resolved&&this._commentUpdate$.next({unitId:t,subUnitId:n,type:"resolve",payload:{commentId:e.id,resolved:!!e.resolved}})}}async syncThreadComments(t,n,e){const o=await this._dataSourceService.listThreadComments(t,n,e);if(!o.length)return;const m=new Set(e);o.forEach(s=>{this._replaceComment(t,n,s),m.delete(s.threadId)}),m.forEach(s=>{const d=this.getThread(t,s);d&&this.deleteComment(d.unitId,d.subUnitId,d.id)}),this._refreshCommentsMap$()}addComment(t,n,e,o){var l,M;const{commentMap:m,commentChildrenMap:s}=this.ensureMap(t,n),d=e,c=u=>{m[u.id]=u,this._commentUpdate$.next({unitId:t,subUnitId:n,type:"add",payload:u,isRoot:!u.parentId})},h=d.parentId;if(h){const u=m[h];u.children=[...(l=u.children)!=null?l:[],d],c(d)}else s.set(d.id,d),this._ensureThreadMap(t).set(d.threadId,d),c(d),(M=d.children)==null||M.forEach(_=>c({..._,ref:""}));return this._refreshCommentsMap$(),o&&this.syncThreadComments(t,n,[d.threadId]),!0}updateComment(t,n,e,o){const{commentMap:m}=this.ensureMap(t,n),s=m[e.commentId];return s?(s.updated=!0,s.text=e.text,s.attachments=e.attachments,s.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:n,type:"update",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(t,n,e,o){const{commentMap:m}=this.ensureMap(t,n),s=m[e.commentId];return s?(s.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:n,type:"updateRef",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}resolveComment(t,n,e,o){const{commentMap:m}=this.ensureMap(t,n),s=m[e];return s?(s.resolved=o,this._commentUpdate$.next({unitId:t,subUnitId:n,type:"resolve",payload:{commentId:e,resolved:o}}),this._refreshCommentsMap$(),!0):!1}getComment(t,n,e){const{commentMap:o}=this.ensureMap(t,n);return o[e]}getComment$(t,n,e){return this._commentsMap$.pipe(S.map(o=>o[t][n][e]))}getCommentWithChildren(t,n,e){var h,l;const{commentMap:o,commentChildrenMap:m}=this.ensureMap(t,n),s=o[e];if(!s)return;const d=new Set,c=m.get(e);if(c)return[c,...(h=c.children)!=null?h:[]].forEach(M=>{var u;d.add(M.personId),(u=M.text.customRanges)==null||u.forEach(_=>{_.rangeType===i.CustomRangeType.MENTION&&d.add(_.rangeId)})}),{root:s,children:(l=c.children)!=null?l:[],relativeUsers:d}}deleteComment(t,n,e){var d;const{commentMap:o,commentChildrenMap:m}=this.ensureMap(t,n),s=o[e];if(!s)return!0;if(s.parentId){const c=m.get(s.parentId);if(c&&c.children){const h=c.children.findIndex(l=>l.id=e);c.children.splice(h,1)}delete o[e]}else{delete o[e];const c=m.get(e);m.delete(e),this._ensureThreadMap(t).delete(s.threadId),(d=c==null?void 0:c.children)==null||d.forEach(l=>{delete o[l.id],this._commentUpdate$.next({unitId:t,subUnitId:n,type:"delete",payload:{commentId:l.id,isRoot:!1,comment:l}})})}return this._commentUpdate$.next({unitId:t,subUnitId:n,type:"delete",payload:{commentId:e,isRoot:!s.parentId,comment:s}}),this._refreshCommentsMap$(),!0}getUnit(t){const n=this._commentsMap[t];return n?Array.from(Object.entries(n)).map(([e,o])=>[e,Array.from(Object.values(o))]):[]}deleteUnit(t){const n=this._commentsMap[t];n&&Object.entries(n).forEach(([e,o])=>{Object.values(o).forEach(m=>{this.deleteComment(t,e,m.id)})})}getRootCommentIds(t,n){const e=this._ensureCommentChildrenMap(t,n);return Array.from(e.keys())}getAll(){return this._commentsMap}getThread(t,n){return this._ensureThreadMap(t).get(n)}};exports.ThreadCommentModel=J([R(0,f.Inject(p)),R(1,i.ICommandService)],exports.ThreadCommentModel);var g=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))(g||{});const U="THREAD_COMMENT_PLUGIN";var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,B=(a,r,t,n)=>{for(var e=n>1?void 0:n?H(r,t):r,o=a.length-1,m;o>=0;o--)(m=a[o])&&(e=(n?m(r,t,e):m(e))||e);return n&&e&&G(r,t,e),e},y=(a,r)=>(t,n)=>r(t,n,a);exports.ThreadCommentResourceController=class extends i.Disposable{constructor(r,t,n){super(),this._resourceManagerService=r,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){const r=n=>{const e=this._threadCommentModel.getUnit(n),o={};return e?(e.forEach(([m,s])=>{o[m]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,n))):""},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${U}`,businesses:[g.UNIVER_SHEET,g.UNIVER_DOC],toJson:n=>r(n),parseJson:n=>t(n),onUnLoad:n=>{this._threadCommentModel.deleteUnit(n)},onLoad:async(n,e)=>{Object.keys(e).forEach(o=>{const m=e[o];m.forEach(s=>{this._threadCommentModel.addComment(n,o,s)}),this._threadCommentModel.syncThreadComments(n,o,m.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=B([i.OnLifecycle(i.LifecycleStages.Starting,exports.ThreadCommentResourceController),y(0,i.IResourceManagerService),y(1,f.Inject(exports.ThreadCommentModel)),y(2,p)],exports.ThreadCommentResourceController);const I={id:"thread-comment.mutation.add-comment",type:i.CommandType.MUTATION,handler(a,r,t){if(!r)return!1;const n=a.get(exports.ThreadCommentModel),{unitId:e,subUnitId:o,comment:m,sync:s}=r,d=s||(t==null?void 0:t.fromChangeset)&&!m.parentId;return n.addComment(e,o,m,d)}},N={id:"thread-comment.mutation.update-comment",type:i.CommandType.MUTATION,handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:e,payload:o,silent:m}=r;return t.updateComment(n,e,o,m)}},D={id:"thread-comment.mutation.update-comment-ref",type:i.CommandType.MUTATION,handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:e,payload:o,silent:m}=r;return t.updateCommentRef(n,e,o,m)}},O={id:"thread-comment.mutation.resolve-comment",type:i.CommandType.MUTATION,handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:e,resolved:o,commentId:m}=r;return t.resolveComment(n,e,m,o)}},v={id:"thread-comment.mutation.delete-comment",type:i.CommandType.MUTATION,handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:e,commentId:o}=r;return t.deleteComment(n,e,o)}},w={id:"thread-comment.command.add-comment",type:i.CommandType.COMMAND,async handler(a,r){if(!r)return!1;const t=a.get(i.ICommandService),n=a.get(p),{comment:e}=r,o=await n.addComment(e),m=n.syncUpdateMutationToColla,s=!e.parentId,d={id:I.id,params:{...r,comment:o}};return s?await t.executeCommand(d.id,d.params):t.executeCommand(d.id,d.params,{onlyLocal:!m})}},x={id:"thread-comment.command.update-comment",type:i.CommandType.COMMAND,async handler(a,r){if(!r)return!1;const{unitId:t,subUnitId:n,payload:e}=r,o=a.get(i.ICommandService),m=a.get(exports.ThreadCommentModel),s=a.get(p),d=s.syncUpdateMutationToColla,c=m.getComment(t,n,e.commentId);if(!c)return!1;const{children:h,...l}=c;if(!await s.updateComment({...l,...e}))return!1;const u={id:N.id,params:r};return o.executeCommand(u.id,u.params,{onlyLocal:!d}),!0}},P={id:"thread-comment.command.resolve-comment",type:i.CommandType.COMMAND,async handler(a,r){if(!r)return!1;const{unitId:t,subUnitId:n,resolved:e,commentId:o}=r,m=a.get(p),d=a.get(exports.ThreadCommentModel).getComment(t,n,o),c=m.syncUpdateMutationToColla;return!d||!await m.resolveComment({...d,resolved:e})?!1:a.get(i.ICommandService).executeCommand(O.id,r,{onlyLocal:!c})}},A={id:"thread-comment.command.delete-comment",type:i.CommandType.COMMAND,async handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),n=a.get(p),e=a.get(i.ICommandService),{unitId:o,subUnitId:m,commentId:s}=r,d=n.syncUpdateMutationToColla,c=t.getComment(o,m,s);if(!c||!await n.deleteComment(o,m,c.threadId,s))return!1;const h={id:v.id,params:r};return e.executeCommand(h.id,h.params,{onlyLocal:!d})}},b={id:"thread-comment.command.delete-comment-tree",type:i.CommandType.COMMAND,async handler(a,r){if(!r)return!1;const t=a.get(exports.ThreadCommentModel),n=a.get(i.ICommandService),e=a.get(p),{unitId:o,subUnitId:m,commentId:s}=r,d=t.getCommentWithChildren(o,m,s);return!d||!await e.deleteComment(o,m,d.root.threadId,s)?!1:await n.executeCommand(v.id,{unitId:o,subUnitId:m,commentId:d.root.id})}};var q=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Z=(a,r,t,n)=>{for(var e=n>1?void 0:n?K(r,t):r,o=a.length-1,m;o>=0;o--)(m=a[o])&&(e=(n?m(r,t,e):m(e))||e);return n&&e&&q(r,t,e),e},E=(a,r)=>(t,n)=>r(t,n,a),T;exports.UniverThreadCommentPlugin=(T=class extends i.Plugin{constructor(t,n,e){super();C(this,"_config");this._injector=n,this._commandService=e,this._config=t}onStarting(t){var n;i.mergeOverrideWithDependencies([[p,{useClass:$}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(n=this._config)==null?void 0:n.overrides).forEach(e=>{t.add(e)}),[w,x,A,P,b,I,N,D,v,O].forEach(e=>{this._commandService.registerCommand(e)})}},C(T,"pluginName",U),C(T,"type",i.UniverInstanceType.UNIVER_UNKNOWN),T);exports.UniverThreadCommentPlugin=Z([E(1,f.Inject(f.Injector)),E(2,i.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=w;exports.AddCommentMutation=I;exports.DeleteCommentCommand=A;exports.DeleteCommentMutation=v;exports.DeleteCommentTreeCommand=b;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=O;exports.TC_PLUGIN_NAME=U;exports.ThreadCommentDataSourceService=$;exports.UpdateCommentCommand=x;exports.UpdateCommentMutation=N;exports.UpdateCommentRefMutation=D;
1
+ "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const rxjs=require("rxjs"),core=require("@univerjs/core"),_ThreadCommentDataSourceService=class _ThreadCommentDataSourceService extends core.Disposable{constructor(){super();__publicField(this,"_dataSource",null);__publicField(this,"syncUpdateMutationToColla",!0)}set dataSource(dataSource){this._dataSource=dataSource}get dataSource(){return this._dataSource}async getThreadComment(unitId,subUnitId,threadId){return this._dataSource?(await this._dataSource.listComments(unitId,subUnitId,[threadId]))[0]:null}async addComment(comment){return this._dataSource?this._dataSource.addComment(comment):comment}async updateComment(comment){return this._dataSource?this._dataSource.updateComment(comment):!0}async resolveComment(comment){return this._dataSource?this._dataSource.resolveComment(comment):!0}async deleteComment(unitId,subUnitId,threadId,commentId){return this._dataSource?this._dataSource.deleteComment(unitId,subUnitId,threadId,commentId):!0}async listThreadComments(unitId,subUnitId,threadIds){return this.dataSource?this.dataSource.listComments(unitId,subUnitId,threadIds):[]}saveToSnapshot(unitComments,unitId){if(this._dataSource){const map={};return Object.keys(unitComments).forEach(subUnitId=>{const comments=unitComments[subUnitId];map[subUnitId]=comments.map(this.dataSource.saveCommentToSnapshot)}),map}return unitComments}};__name(_ThreadCommentDataSourceService,"ThreadCommentDataSourceService");let ThreadCommentDataSourceService=_ThreadCommentDataSourceService;const IThreadCommentDataSourceService=core.createIdentifier("univer.thread-comment.data-source-service");var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a;exports.ThreadCommentModel=(_a=class extends core.Disposable{constructor(_dataSourceService,_commandService){super();__publicField(this,"_commentsMap",{});__publicField(this,"_commentsTreeMap",new Map);__publicField(this,"_threadMap",new Map);__publicField(this,"_commentUpdate$",new rxjs.Subject);__publicField(this,"_commentsMap$",new rxjs.BehaviorSubject({}));__publicField(this,"commentUpdate$",this._commentUpdate$.asObservable());__publicField(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=_dataSourceService,this._commandService=_commandService,this.disposeWithMe(()=>{this._commentUpdate$.complete(),this._commentsMap$.complete()})}_ensureCommentMap(unitId,subUnitId){let unitMap=this._commentsMap[unitId];unitMap||(unitMap={},this._commentsMap[unitId]=unitMap);let subUnitMap=unitMap[subUnitId];return subUnitMap||(subUnitMap={},unitMap[subUnitId]=subUnitMap),subUnitMap}_ensureCommentChildrenMap(unitId,subUnitId){let unitMap=this._commentsTreeMap.get(unitId);unitMap||(unitMap=new Map,this._commentsTreeMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_ensureThreadMap(unitId){let unitMap=this._threadMap.get(unitId);return unitMap||(unitMap=new Map,this._threadMap.set(unitId,unitMap)),unitMap}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(unitId,subUnitId){const commentMap=this._ensureCommentMap(unitId,subUnitId),commentChildrenMap=this._ensureCommentChildrenMap(unitId,subUnitId);return{commentMap,commentChildrenMap}}_replaceComment(unitId,subUnitId,comment){var _a4;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),currentComment=commentMap[comment.id];if(currentComment){const newComment={...comment,ref:currentComment.ref};commentMap[comment.id]=newComment,(_a4=comment.children)==null||_a4.forEach(child=>{commentMap[child.id]={...child,ref:""}}),commentChildrenMap.set(comment.id,newComment),this._commentUpdate$.next({unitId,subUnitId,type:"syncUpdate",payload:newComment}),!!comment.resolved!=!!currentComment.resolved&&this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId:comment.id,resolved:!!comment.resolved}})}}async syncThreadComments(unitId,subUnitId,threadIds){const comments=await this._dataSourceService.listThreadComments(unitId,subUnitId,threadIds);if(!comments.length)return;const deleteThreads=new Set(threadIds);comments.forEach(comment=>{this._replaceComment(unitId,subUnitId,comment),deleteThreads.delete(comment.threadId)}),deleteThreads.forEach(id=>{const thread=this.getThread(unitId,id);thread&&this.deleteComment(thread.unitId,thread.subUnitId,thread.id)}),this._refreshCommentsMap$()}addComment(unitId,subUnitId,origin,shouldSync){var _a4,_b;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),comment=origin,addCommentItem=__name(item=>{commentMap[item.id]=item,this._commentUpdate$.next({unitId,subUnitId,type:"add",payload:item,isRoot:!item.parentId})},"addCommentItem"),parentId=comment.parentId;if(parentId){const parent=commentMap[parentId];parent.children=[...(_a4=parent.children)!=null?_a4:[],comment],addCommentItem(comment)}else commentChildrenMap.set(comment.id,comment),this._ensureThreadMap(unitId).set(comment.threadId,comment),addCommentItem(comment),(_b=comment.children)==null||_b.forEach(child=>addCommentItem({...child,ref:""}));return this._refreshCommentsMap$(),shouldSync&&this.syncThreadComments(unitId,subUnitId,[comment.threadId]),!0}updateComment(unitId,subUnitId,payload,silent){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[payload.commentId];return oldComment?(oldComment.updated=!0,oldComment.text=payload.text,oldComment.attachments=payload.attachments,oldComment.updateT=payload.updateT,this._commentUpdate$.next({unitId,subUnitId,type:"update",payload,silent}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(unitId,subUnitId,payload,silent){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[payload.commentId];return oldComment?(oldComment.ref=payload.ref,this._commentUpdate$.next({unitId,subUnitId,type:"updateRef",payload,silent}),this._refreshCommentsMap$(),!0):!1}resolveComment(unitId,subUnitId,commentId,resolved){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[commentId];return oldComment?(oldComment.resolved=resolved,this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId,resolved}}),this._refreshCommentsMap$(),!0):!1}getComment(unitId,subUnitId,commentId){const{commentMap}=this.ensureMap(unitId,subUnitId);return commentMap[commentId]}getComment$(unitId,subUnitId,commentId){return this._commentsMap$.pipe(rxjs.map(records=>records[unitId][subUnitId][commentId]))}getCommentWithChildren(unitId,subUnitId,commentId){var _a4,_b;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),current=commentMap[commentId];if(!current)return;const relativeUsers=new Set,root=commentChildrenMap.get(commentId);if(root)return[root,...(_a4=root.children)!=null?_a4:[]].forEach(comment=>{var _a5;relativeUsers.add(comment.personId),(_a5=comment.text.customRanges)==null||_a5.forEach(range=>{range.rangeType===core.CustomRangeType.MENTION&&relativeUsers.add(range.rangeId)})}),{root:current,children:(_b=root.children)!=null?_b:[],relativeUsers}}deleteComment(unitId,subUnitId,commentId){var _a4;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),current=commentMap[commentId];if(!current)return!0;if(current.parentId){const root=commentChildrenMap.get(current.parentId);if(root&&root.children){const index=root.children.findIndex(comment=>comment.id=commentId);root.children.splice(index,1)}delete commentMap[commentId]}else{delete commentMap[commentId];const comment=commentChildrenMap.get(commentId);commentChildrenMap.delete(commentId),this._ensureThreadMap(unitId).delete(current.threadId),(_a4=comment==null?void 0:comment.children)==null||_a4.forEach(child=>{delete commentMap[child.id],this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId:child.id,isRoot:!1,comment:child}})})}return this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId,isRoot:!current.parentId,comment:current}}),this._refreshCommentsMap$(),!0}getUnit(unitId){const unitMap=this._commentsMap[unitId];return unitMap?Array.from(Object.entries(unitMap)).map(([subUnitId,subUnitMap])=>[subUnitId,Array.from(Object.values(subUnitMap))]):[]}deleteUnit(unitId){const unitMap=this._commentsMap[unitId];unitMap&&Object.entries(unitMap).forEach(([subUnitId,subUnitMap])=>{Object.values(subUnitMap).forEach(comment=>{this.deleteComment(unitId,subUnitId,comment.id)})})}getRootCommentIds(unitId,subUnitId){const commentChildrenMap=this._ensureCommentChildrenMap(unitId,subUnitId);return Array.from(commentChildrenMap.keys())}getAll(){return this._commentsMap}getThread(unitId,threadId){return this._ensureThreadMap(unitId).get(threadId)}},__name(_a,"ThreadCommentModel"),_a);exports.ThreadCommentModel=__decorateClass$2([__decorateParam$2(0,core.Inject(IThreadCommentDataSourceService)),__decorateParam$2(1,core.ICommandService)],exports.ThreadCommentModel);var I=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(I||{});const TC_PLUGIN_NAME="THREAD_COMMENT_PLUGIN";var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a2;exports.ThreadCommentResourceController=(_a2=class extends core.Disposable{constructor(_resourceManagerService,_threadCommentModel,_threadCommentDataSourceService){super(),this._resourceManagerService=_resourceManagerService,this._threadCommentModel=_threadCommentModel,this._threadCommentDataSourceService=_threadCommentDataSourceService,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._threadCommentModel.getUnit(unitID),resultMap={};return map?(map.forEach(([key,v])=>{resultMap[key]=v}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(resultMap,unitID))):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${TC_PLUGIN_NAME}`,businesses:[I.UNIVER_SHEET,I.UNIVER_DOC],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._threadCommentModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{const commentList=value[subunitId];commentList.forEach(comment=>{this._threadCommentModel.addComment(unitID,subunitId,comment)}),this._threadCommentModel.syncThreadComments(unitID,subunitId,commentList.map(i=>i.threadId))})},"onLoad")}))}},__name(_a2,"ThreadCommentResourceController"),_a2);exports.ThreadCommentResourceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Starting,exports.ThreadCommentResourceController),__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports.ThreadCommentModel)),__decorateParam$1(2,IThreadCommentDataSourceService)],exports.ThreadCommentResourceController);const AddCommentMutation={id:"thread-comment.mutation.add-comment",type:core.CommandType.MUTATION,handler(accessor,params,options){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),{unitId,subUnitId,comment,sync}=params,shouldSync=sync||(options==null?void 0:options.fromChangeset)&&!comment.parentId;return threadCommentModel.addComment(unitId,subUnitId,comment,shouldSync)}},UpdateCommentMutation={id:"thread-comment.mutation.update-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),{unitId,subUnitId,payload,silent}=params;return threadCommentModel.updateComment(unitId,subUnitId,payload,silent)}},UpdateCommentRefMutation={id:"thread-comment.mutation.update-comment-ref",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),{unitId,subUnitId,payload,silent}=params;return threadCommentModel.updateCommentRef(unitId,subUnitId,payload,silent)}},ResolveCommentMutation={id:"thread-comment.mutation.resolve-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),{unitId,subUnitId,resolved,commentId}=params;return threadCommentModel.resolveComment(unitId,subUnitId,commentId,resolved)}},DeleteCommentMutation={id:"thread-comment.mutation.delete-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),{unitId,subUnitId,commentId}=params;return threadCommentModel.deleteComment(unitId,subUnitId,commentId)}},AddCommentCommand={id:"thread-comment.command.add-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const commandService=accessor.get(core.ICommandService),dataSourceService=accessor.get(IThreadCommentDataSourceService),{comment:originComment}=params,comment=await dataSourceService.addComment(originComment),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,isRoot=!originComment.parentId,redo={id:AddCommentMutation.id,params:{...params,comment}};return isRoot?await commandService.executeCommand(redo.id,redo.params):commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla})}},UpdateCommentCommand={id:"thread-comment.command.update-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{unitId,subUnitId,payload}=params,commandService=accessor.get(core.ICommandService),threadCommentModel=accessor.get(exports.ThreadCommentModel),dataSourceService=accessor.get(IThreadCommentDataSourceService),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,current=threadCommentModel.getComment(unitId,subUnitId,payload.commentId);if(!current)return!1;const{children,...currentComment}=current;if(!await dataSourceService.updateComment({...currentComment,...payload}))return!1;const redo={id:UpdateCommentMutation.id,params};return commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla}),!0}},ResolveCommentCommand={id:"thread-comment.command.resolve-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{unitId,subUnitId,resolved,commentId}=params,dataSourceService=accessor.get(IThreadCommentDataSourceService),currentComment=accessor.get(exports.ThreadCommentModel).getComment(unitId,subUnitId,commentId),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla;return!currentComment||!await dataSourceService.resolveComment({...currentComment,resolved})?!1:accessor.get(core.ICommandService).executeCommand(ResolveCommentMutation.id,params,{onlyLocal:!syncUpdateMutationToColla})}},DeleteCommentCommand={id:"thread-comment.command.delete-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),dataSourceService=accessor.get(IThreadCommentDataSourceService),commandService=accessor.get(core.ICommandService),{unitId,subUnitId,commentId}=params,syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,comment=threadCommentModel.getComment(unitId,subUnitId,commentId);if(!comment||!await dataSourceService.deleteComment(unitId,subUnitId,comment.threadId,commentId))return!1;const redo={id:DeleteCommentMutation.id,params};return commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla})}},DeleteCommentTreeCommand={id:"thread-comment.command.delete-comment-tree",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports.ThreadCommentModel),commandService=accessor.get(core.ICommandService),dataSourceService=accessor.get(IThreadCommentDataSourceService),{unitId,subUnitId,commentId}=params,commentWithChildren=threadCommentModel.getCommentWithChildren(unitId,subUnitId,commentId);return!commentWithChildren||!await dataSourceService.deleteComment(unitId,subUnitId,commentWithChildren.root.threadId,commentId)?!1:await commandService.executeCommand(DeleteCommentMutation.id,{unitId,subUnitId,commentId:commentWithChildren.root.id})}};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a3;exports.UniverThreadCommentPlugin=(_a3=class extends core.Plugin{constructor(config,_injector,_commandService){super();__publicField(this,"_config");this._injector=_injector,this._commandService=_commandService,this._config=config}onStarting(){var _a4;core.mergeOverrideWithDependencies([[IThreadCommentDataSourceService,{useClass:ThreadCommentDataSourceService}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(_a4=this._config)==null?void 0:_a4.overrides).forEach(d=>{this._injector.add(d)}),[AddCommentCommand,UpdateCommentCommand,DeleteCommentCommand,ResolveCommentCommand,DeleteCommentTreeCommand,AddCommentMutation,UpdateCommentMutation,UpdateCommentRefMutation,DeleteCommentMutation,ResolveCommentMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_a3,"UniverThreadCommentPlugin"),__publicField(_a3,"pluginName",TC_PLUGIN_NAME),__publicField(_a3,"type",core.UniverInstanceType.UNIVER_UNKNOWN),_a3);exports.UniverThreadCommentPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=AddCommentCommand;exports.AddCommentMutation=AddCommentMutation;exports.DeleteCommentCommand=DeleteCommentCommand;exports.DeleteCommentMutation=DeleteCommentMutation;exports.DeleteCommentTreeCommand=DeleteCommentTreeCommand;exports.IThreadCommentDataSourceService=IThreadCommentDataSourceService;exports.ResolveCommentCommand=ResolveCommentCommand;exports.ResolveCommentMutation=ResolveCommentMutation;exports.TC_PLUGIN_NAME=TC_PLUGIN_NAME;exports.ThreadCommentDataSourceService=ThreadCommentDataSourceService;exports.UpdateCommentCommand=UpdateCommentCommand;exports.UpdateCommentMutation=UpdateCommentMutation;exports.UpdateCommentRefMutation=UpdateCommentRefMutation;
package/lib/es/index.js CHANGED
@@ -1,527 +1,529 @@
1
- var x = Object.defineProperty;
2
- var P = (a, t, e) => t in a ? x(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var h = (a, t, e) => P(a, typeof t != "symbol" ? t + "" : t, e);
4
- import { Subject as A, BehaviorSubject as b, map as j } from "rxjs";
5
- import { Disposable as T, CustomRangeType as L, ICommandService as _, OnLifecycle as V, LifecycleStages as W, IResourceManagerService as J, CommandType as p, Plugin as H, UniverInstanceType as B, mergeOverrideWithDependencies as G } from "@univerjs/core";
6
- import { createIdentifier as K, Inject as U, Injector as Z } from "@wendellhu/redi";
7
- class q extends T {
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 { Subject, BehaviorSubject, map } from "rxjs";
6
+ import { Disposable, createIdentifier, CustomRangeType, Inject, ICommandService, OnLifecycle, LifecycleStages, IResourceManagerService, CommandType, Plugin, UniverInstanceType, mergeOverrideWithDependencies, Injector } from "@univerjs/core";
7
+ const _ThreadCommentDataSourceService = class _ThreadCommentDataSourceService extends Disposable {
8
8
  constructor() {
9
9
  super();
10
- h(this, "_dataSource", null);
11
- h(this, "syncUpdateMutationToColla", !0);
10
+ __publicField(this, "_dataSource", null);
11
+ __publicField(this, "syncUpdateMutationToColla", !0);
12
12
  }
13
- set dataSource(e) {
14
- this._dataSource = e;
13
+ set dataSource(dataSource) {
14
+ this._dataSource = dataSource;
15
15
  }
16
16
  get dataSource() {
17
17
  return this._dataSource;
18
18
  }
19
- async getThreadComment(e, n, r) {
20
- return this._dataSource ? (await this._dataSource.listComments(e, n, [r]))[0] : null;
19
+ async getThreadComment(unitId, subUnitId, threadId) {
20
+ return this._dataSource ? (await this._dataSource.listComments(unitId, subUnitId, [threadId]))[0] : null;
21
21
  }
22
- async addComment(e) {
23
- return this._dataSource ? this._dataSource.addComment(e) : e;
22
+ async addComment(comment) {
23
+ return this._dataSource ? this._dataSource.addComment(comment) : comment;
24
24
  }
25
- async updateComment(e) {
26
- return this._dataSource ? this._dataSource.updateComment(e) : !0;
25
+ async updateComment(comment) {
26
+ return this._dataSource ? this._dataSource.updateComment(comment) : !0;
27
27
  }
28
- async resolveComment(e) {
29
- return this._dataSource ? this._dataSource.resolveComment(e) : !0;
28
+ async resolveComment(comment) {
29
+ return this._dataSource ? this._dataSource.resolveComment(comment) : !0;
30
30
  }
31
- async deleteComment(e, n, r, m) {
32
- return this._dataSource ? this._dataSource.deleteComment(e, n, r, m) : !0;
31
+ async deleteComment(unitId, subUnitId, threadId, commentId) {
32
+ return this._dataSource ? this._dataSource.deleteComment(unitId, subUnitId, threadId, commentId) : !0;
33
33
  }
34
- async listThreadComments(e, n, r) {
35
- return this.dataSource ? this.dataSource.listComments(e, n, r) : [];
34
+ async listThreadComments(unitId, subUnitId, threadIds) {
35
+ return this.dataSource ? this.dataSource.listComments(unitId, subUnitId, threadIds) : [];
36
36
  }
37
- saveToSnapshot(e, n) {
37
+ saveToSnapshot(unitComments, unitId) {
38
38
  if (this._dataSource) {
39
- const r = {};
40
- return Object.keys(e).forEach((m) => {
41
- const o = e[m];
42
- r[m] = o.map(this.dataSource.saveCommentToSnapshot);
43
- }), r;
39
+ const map2 = {};
40
+ return Object.keys(unitComments).forEach((subUnitId) => {
41
+ const comments = unitComments[subUnitId];
42
+ map2[subUnitId] = comments.map(this.dataSource.saveCommentToSnapshot);
43
+ }), map2;
44
44
  }
45
- return e;
46
- }
47
- }
48
- const f = K("univer.thread-comment.data-source-service");
49
- var z = Object.defineProperty, F = Object.getOwnPropertyDescriptor, Q = (a, t, e, n) => {
50
- for (var r = n > 1 ? void 0 : n ? F(t, e) : t, m = a.length - 1, o; m >= 0; m--)
51
- (o = a[m]) && (r = (n ? o(t, e, r) : o(r)) || r);
52
- return n && r && z(t, e, r), r;
53
- }, O = (a, t) => (e, n) => t(e, n, a);
54
- let u = class extends T {
55
- constructor(t, e) {
45
+ return unitComments;
46
+ }
47
+ };
48
+ __name(_ThreadCommentDataSourceService, "ThreadCommentDataSourceService");
49
+ let ThreadCommentDataSourceService = _ThreadCommentDataSourceService;
50
+ const IThreadCommentDataSourceService = createIdentifier("univer.thread-comment.data-source-service");
51
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
52
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
53
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
54
+ return kind && result && __defProp$2(target, key, result), result;
55
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a;
56
+ let ThreadCommentModel = (_a = class extends Disposable {
57
+ constructor(_dataSourceService, _commandService) {
56
58
  super();
57
- h(this, "_commentsMap", {});
58
- h(this, "_commentsTreeMap", /* @__PURE__ */ new Map());
59
- h(this, "_threadMap", /* @__PURE__ */ new Map());
60
- h(this, "_commentUpdate$", new A());
61
- h(this, "_commentsMap$", new b({}));
62
- h(this, "commentUpdate$", this._commentUpdate$.asObservable());
63
- h(this, "commentMap$", this._commentsMap$.asObservable());
64
- this._dataSourceService = t, this._commandService = e, this.disposeWithMe(() => {
59
+ __publicField(this, "_commentsMap", {});
60
+ __publicField(this, "_commentsTreeMap", /* @__PURE__ */ new Map());
61
+ __publicField(this, "_threadMap", /* @__PURE__ */ new Map());
62
+ __publicField(this, "_commentUpdate$", new Subject());
63
+ __publicField(this, "_commentsMap$", new BehaviorSubject({}));
64
+ __publicField(this, "commentUpdate$", this._commentUpdate$.asObservable());
65
+ __publicField(this, "commentMap$", this._commentsMap$.asObservable());
66
+ this._dataSourceService = _dataSourceService, this._commandService = _commandService, this.disposeWithMe(() => {
65
67
  this._commentUpdate$.complete(), this._commentsMap$.complete();
66
68
  });
67
69
  }
68
- _ensureCommentMap(t, e) {
69
- let n = this._commentsMap[t];
70
- n || (n = {}, this._commentsMap[t] = n);
71
- let r = n[e];
72
- return r || (r = {}, n[e] = r), r;
70
+ _ensureCommentMap(unitId, subUnitId) {
71
+ let unitMap = this._commentsMap[unitId];
72
+ unitMap || (unitMap = {}, this._commentsMap[unitId] = unitMap);
73
+ let subUnitMap = unitMap[subUnitId];
74
+ return subUnitMap || (subUnitMap = {}, unitMap[subUnitId] = subUnitMap), subUnitMap;
73
75
  }
74
- _ensureCommentChildrenMap(t, e) {
75
- let n = this._commentsTreeMap.get(t);
76
- n || (n = /* @__PURE__ */ new Map(), this._commentsTreeMap.set(t, n));
77
- let r = n.get(e);
78
- return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r;
76
+ _ensureCommentChildrenMap(unitId, subUnitId) {
77
+ let unitMap = this._commentsTreeMap.get(unitId);
78
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._commentsTreeMap.set(unitId, unitMap));
79
+ let subUnitMap = unitMap.get(subUnitId);
80
+ return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
79
81
  }
80
- _ensureThreadMap(t) {
81
- let e = this._threadMap.get(t);
82
- return e || (e = /* @__PURE__ */ new Map(), this._threadMap.set(t, e)), e;
82
+ _ensureThreadMap(unitId) {
83
+ let unitMap = this._threadMap.get(unitId);
84
+ return unitMap || (unitMap = /* @__PURE__ */ new Map(), this._threadMap.set(unitId, unitMap)), unitMap;
83
85
  }
84
86
  _refreshCommentsMap$() {
85
87
  this._commentsMap$.next({
86
88
  ...this._commentsMap
87
89
  });
88
90
  }
89
- ensureMap(t, e) {
90
- const n = this._ensureCommentMap(t, e), r = this._ensureCommentChildrenMap(t, e);
91
+ ensureMap(unitId, subUnitId) {
92
+ const commentMap = this._ensureCommentMap(unitId, subUnitId), commentChildrenMap = this._ensureCommentChildrenMap(unitId, subUnitId);
91
93
  return {
92
- commentMap: n,
93
- commentChildrenMap: r
94
+ commentMap,
95
+ commentChildrenMap
94
96
  };
95
97
  }
96
- _replaceComment(t, e, n) {
97
- var s;
98
- const { commentMap: r, commentChildrenMap: m } = this.ensureMap(t, e), o = r[n.id];
99
- if (o) {
100
- const c = {
101
- ...n,
102
- ref: o.ref
98
+ _replaceComment(unitId, subUnitId, comment) {
99
+ var _a4;
100
+ const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), currentComment = commentMap[comment.id];
101
+ if (currentComment) {
102
+ const newComment = {
103
+ ...comment,
104
+ ref: currentComment.ref
103
105
  };
104
- r[n.id] = c, (s = n.children) == null || s.forEach((d) => {
105
- r[d.id] = {
106
- ...d,
106
+ commentMap[comment.id] = newComment, (_a4 = comment.children) == null || _a4.forEach((child) => {
107
+ commentMap[child.id] = {
108
+ ...child,
107
109
  ref: ""
108
110
  };
109
- }), m.set(n.id, c), this._commentUpdate$.next({
110
- unitId: t,
111
- subUnitId: e,
111
+ }), commentChildrenMap.set(comment.id, newComment), this._commentUpdate$.next({
112
+ unitId,
113
+ subUnitId,
112
114
  type: "syncUpdate",
113
- payload: c
114
- }), !!n.resolved != !!o.resolved && this._commentUpdate$.next({
115
- unitId: t,
116
- subUnitId: e,
115
+ payload: newComment
116
+ }), !!comment.resolved != !!currentComment.resolved && this._commentUpdate$.next({
117
+ unitId,
118
+ subUnitId,
117
119
  type: "resolve",
118
120
  payload: {
119
- commentId: n.id,
120
- resolved: !!n.resolved
121
+ commentId: comment.id,
122
+ resolved: !!comment.resolved
121
123
  }
122
124
  });
123
125
  }
124
126
  }
125
- async syncThreadComments(t, e, n) {
126
- const r = await this._dataSourceService.listThreadComments(t, e, n);
127
- if (!r.length)
127
+ async syncThreadComments(unitId, subUnitId, threadIds) {
128
+ const comments = await this._dataSourceService.listThreadComments(unitId, subUnitId, threadIds);
129
+ if (!comments.length)
128
130
  return;
129
- const m = new Set(n);
130
- r.forEach((o) => {
131
- this._replaceComment(t, e, o), m.delete(o.threadId);
132
- }), m.forEach((o) => {
133
- const s = this.getThread(t, o);
134
- s && this.deleteComment(s.unitId, s.subUnitId, s.id);
131
+ const deleteThreads = new Set(threadIds);
132
+ comments.forEach((comment) => {
133
+ this._replaceComment(unitId, subUnitId, comment), deleteThreads.delete(comment.threadId);
134
+ }), deleteThreads.forEach((id) => {
135
+ const thread = this.getThread(unitId, id);
136
+ thread && this.deleteComment(thread.unitId, thread.subUnitId, thread.id);
135
137
  }), this._refreshCommentsMap$();
136
138
  }
137
- addComment(t, e, n, r) {
138
- var i, C;
139
- const { commentMap: m, commentChildrenMap: o } = this.ensureMap(t, e), s = n, c = (l) => {
140
- m[l.id] = l, this._commentUpdate$.next({
141
- unitId: t,
142
- subUnitId: e,
139
+ addComment(unitId, subUnitId, origin, shouldSync) {
140
+ var _a4, _b;
141
+ const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), comment = origin, addCommentItem = /* @__PURE__ */ __name((item) => {
142
+ commentMap[item.id] = item, this._commentUpdate$.next({
143
+ unitId,
144
+ subUnitId,
143
145
  type: "add",
144
- payload: l,
145
- isRoot: !l.parentId
146
+ payload: item,
147
+ isRoot: !item.parentId
146
148
  });
147
- }, d = s.parentId;
148
- if (d) {
149
- const l = m[d];
150
- l.children = [
151
- ...(i = l.children) != null ? i : [],
152
- s
153
- ], c(s);
149
+ }, "addCommentItem"), parentId = comment.parentId;
150
+ if (parentId) {
151
+ const parent = commentMap[parentId];
152
+ parent.children = [
153
+ ...(_a4 = parent.children) != null ? _a4 : [],
154
+ comment
155
+ ], addCommentItem(comment);
154
156
  } else
155
- o.set(s.id, s), this._ensureThreadMap(t).set(s.threadId, s), c(s), (C = s.children) == null || C.forEach((M) => c({
156
- ...M,
157
+ commentChildrenMap.set(comment.id, comment), this._ensureThreadMap(unitId).set(comment.threadId, comment), addCommentItem(comment), (_b = comment.children) == null || _b.forEach((child) => addCommentItem({
158
+ ...child,
157
159
  ref: ""
158
160
  }));
159
- return this._refreshCommentsMap$(), r && this.syncThreadComments(t, e, [s.threadId]), !0;
161
+ return this._refreshCommentsMap$(), shouldSync && this.syncThreadComments(unitId, subUnitId, [comment.threadId]), !0;
160
162
  }
161
- updateComment(t, e, n, r) {
162
- const { commentMap: m } = this.ensureMap(t, e), o = m[n.commentId];
163
- return o ? (o.updated = !0, o.text = n.text, o.attachments = n.attachments, o.updateT = n.updateT, this._commentUpdate$.next({
164
- unitId: t,
165
- subUnitId: e,
163
+ updateComment(unitId, subUnitId, payload, silent) {
164
+ const { commentMap } = this.ensureMap(unitId, subUnitId), oldComment = commentMap[payload.commentId];
165
+ return oldComment ? (oldComment.updated = !0, oldComment.text = payload.text, oldComment.attachments = payload.attachments, oldComment.updateT = payload.updateT, this._commentUpdate$.next({
166
+ unitId,
167
+ subUnitId,
166
168
  type: "update",
167
- payload: n,
168
- silent: r
169
+ payload,
170
+ silent
169
171
  }), this._refreshCommentsMap$(), !0) : !1;
170
172
  }
171
- updateCommentRef(t, e, n, r) {
172
- const { commentMap: m } = this.ensureMap(t, e), o = m[n.commentId];
173
- return o ? (o.ref = n.ref, this._commentUpdate$.next({
174
- unitId: t,
175
- subUnitId: e,
173
+ updateCommentRef(unitId, subUnitId, payload, silent) {
174
+ const { commentMap } = this.ensureMap(unitId, subUnitId), oldComment = commentMap[payload.commentId];
175
+ return oldComment ? (oldComment.ref = payload.ref, this._commentUpdate$.next({
176
+ unitId,
177
+ subUnitId,
176
178
  type: "updateRef",
177
- payload: n,
178
- silent: r
179
+ payload,
180
+ silent
179
181
  }), this._refreshCommentsMap$(), !0) : !1;
180
182
  }
181
- resolveComment(t, e, n, r) {
182
- const { commentMap: m } = this.ensureMap(t, e), o = m[n];
183
- return o ? (o.resolved = r, this._commentUpdate$.next({
184
- unitId: t,
185
- subUnitId: e,
183
+ resolveComment(unitId, subUnitId, commentId, resolved) {
184
+ const { commentMap } = this.ensureMap(unitId, subUnitId), oldComment = commentMap[commentId];
185
+ return oldComment ? (oldComment.resolved = resolved, this._commentUpdate$.next({
186
+ unitId,
187
+ subUnitId,
186
188
  type: "resolve",
187
189
  payload: {
188
- commentId: n,
189
- resolved: r
190
+ commentId,
191
+ resolved
190
192
  }
191
193
  }), this._refreshCommentsMap$(), !0) : !1;
192
194
  }
193
- getComment(t, e, n) {
194
- const { commentMap: r } = this.ensureMap(t, e);
195
- return r[n];
195
+ getComment(unitId, subUnitId, commentId) {
196
+ const { commentMap } = this.ensureMap(unitId, subUnitId);
197
+ return commentMap[commentId];
196
198
  }
197
- getComment$(t, e, n) {
198
- return this._commentsMap$.pipe(j((r) => r[t][e][n]));
199
+ getComment$(unitId, subUnitId, commentId) {
200
+ return this._commentsMap$.pipe(map((records) => records[unitId][subUnitId][commentId]));
199
201
  }
200
- getCommentWithChildren(t, e, n) {
201
- var d, i;
202
- const { commentMap: r, commentChildrenMap: m } = this.ensureMap(t, e), o = r[n];
203
- if (!o)
202
+ getCommentWithChildren(unitId, subUnitId, commentId) {
203
+ var _a4, _b;
204
+ const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), current = commentMap[commentId];
205
+ if (!current)
204
206
  return;
205
- const s = /* @__PURE__ */ new Set(), c = m.get(n);
206
- if (c)
207
- return [c, ...(d = c.children) != null ? d : []].forEach((C) => {
208
- var l;
209
- s.add(C.personId), (l = C.text.customRanges) == null || l.forEach((M) => {
210
- M.rangeType === L.MENTION && s.add(M.rangeId);
207
+ const relativeUsers = /* @__PURE__ */ new Set(), root = commentChildrenMap.get(commentId);
208
+ if (root)
209
+ return [root, ...(_a4 = root.children) != null ? _a4 : []].forEach((comment) => {
210
+ var _a5;
211
+ relativeUsers.add(comment.personId), (_a5 = comment.text.customRanges) == null || _a5.forEach((range) => {
212
+ range.rangeType === CustomRangeType.MENTION && relativeUsers.add(range.rangeId);
211
213
  });
212
214
  }), {
213
- root: o,
214
- children: (i = c.children) != null ? i : [],
215
- relativeUsers: s
215
+ root: current,
216
+ children: (_b = root.children) != null ? _b : [],
217
+ relativeUsers
216
218
  };
217
219
  }
218
- deleteComment(t, e, n) {
219
- var s;
220
- const { commentMap: r, commentChildrenMap: m } = this.ensureMap(t, e), o = r[n];
221
- if (!o)
220
+ deleteComment(unitId, subUnitId, commentId) {
221
+ var _a4;
222
+ const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), current = commentMap[commentId];
223
+ if (!current)
222
224
  return !0;
223
- if (o.parentId) {
224
- const c = m.get(o.parentId);
225
- if (c && c.children) {
226
- const d = c.children.findIndex((i) => i.id = n);
227
- c.children.splice(d, 1);
225
+ if (current.parentId) {
226
+ const root = commentChildrenMap.get(current.parentId);
227
+ if (root && root.children) {
228
+ const index = root.children.findIndex((comment) => comment.id = commentId);
229
+ root.children.splice(index, 1);
228
230
  }
229
- delete r[n];
231
+ delete commentMap[commentId];
230
232
  } else {
231
- delete r[n];
232
- const c = m.get(n);
233
- m.delete(n), this._ensureThreadMap(t).delete(o.threadId), (s = c == null ? void 0 : c.children) == null || s.forEach((i) => {
234
- delete r[i.id], this._commentUpdate$.next({
235
- unitId: t,
236
- subUnitId: e,
233
+ delete commentMap[commentId];
234
+ const comment = commentChildrenMap.get(commentId);
235
+ commentChildrenMap.delete(commentId), this._ensureThreadMap(unitId).delete(current.threadId), (_a4 = comment == null ? void 0 : comment.children) == null || _a4.forEach((child) => {
236
+ delete commentMap[child.id], this._commentUpdate$.next({
237
+ unitId,
238
+ subUnitId,
237
239
  type: "delete",
238
240
  payload: {
239
- commentId: i.id,
241
+ commentId: child.id,
240
242
  isRoot: !1,
241
- comment: i
243
+ comment: child
242
244
  }
243
245
  });
244
246
  });
245
247
  }
246
248
  return this._commentUpdate$.next({
247
- unitId: t,
248
- subUnitId: e,
249
+ unitId,
250
+ subUnitId,
249
251
  type: "delete",
250
252
  payload: {
251
- commentId: n,
252
- isRoot: !o.parentId,
253
- comment: o
253
+ commentId,
254
+ isRoot: !current.parentId,
255
+ comment: current
254
256
  }
255
257
  }), this._refreshCommentsMap$(), !0;
256
258
  }
257
- getUnit(t) {
258
- const e = this._commentsMap[t];
259
- return e ? Array.from(Object.entries(e)).map(([n, r]) => [n, Array.from(Object.values(r))]) : [];
259
+ getUnit(unitId) {
260
+ const unitMap = this._commentsMap[unitId];
261
+ return unitMap ? Array.from(Object.entries(unitMap)).map(([subUnitId, subUnitMap]) => [subUnitId, Array.from(Object.values(subUnitMap))]) : [];
260
262
  }
261
- deleteUnit(t) {
262
- const e = this._commentsMap[t];
263
- e && Object.entries(e).forEach(([n, r]) => {
264
- Object.values(r).forEach((m) => {
265
- this.deleteComment(t, n, m.id);
263
+ deleteUnit(unitId) {
264
+ const unitMap = this._commentsMap[unitId];
265
+ unitMap && Object.entries(unitMap).forEach(([subUnitId, subUnitMap]) => {
266
+ Object.values(subUnitMap).forEach((comment) => {
267
+ this.deleteComment(unitId, subUnitId, comment.id);
266
268
  });
267
269
  });
268
270
  }
269
- getRootCommentIds(t, e) {
270
- const n = this._ensureCommentChildrenMap(t, e);
271
- return Array.from(n.keys());
271
+ getRootCommentIds(unitId, subUnitId) {
272
+ const commentChildrenMap = this._ensureCommentChildrenMap(unitId, subUnitId);
273
+ return Array.from(commentChildrenMap.keys());
272
274
  }
273
275
  getAll() {
274
276
  return this._commentsMap;
275
277
  }
276
- getThread(t, e) {
277
- return this._ensureThreadMap(t).get(e);
278
- }
279
- };
280
- u = Q([
281
- O(0, U(f)),
282
- O(1, _)
283
- ], u);
284
- var g = /* @__PURE__ */ ((a) => (a[a.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", a[a.UNIVER_DOC = 1] = "UNIVER_DOC", a[a.UNIVER_SHEET = 2] = "UNIVER_SHEET", a[a.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", a[a.UNRECOGNIZED = -1] = "UNRECOGNIZED", a))(g || {});
285
- const E = "THREAD_COMMENT_PLUGIN";
286
- var X = Object.defineProperty, Y = Object.getOwnPropertyDescriptor, k = (a, t, e, n) => {
287
- for (var r = n > 1 ? void 0 : n ? Y(t, e) : t, m = a.length - 1, o; m >= 0; m--)
288
- (o = a[m]) && (r = (n ? o(t, e, r) : o(r)) || r);
289
- return n && r && X(t, e, r), r;
290
- }, y = (a, t) => (e, n) => t(e, n, a);
291
- let S = class extends T {
292
- constructor(a, t, e) {
293
- super(), this._resourceManagerService = a, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
278
+ getThread(unitId, threadId) {
279
+ return this._ensureThreadMap(unitId).get(threadId);
280
+ }
281
+ }, __name(_a, "ThreadCommentModel"), _a);
282
+ ThreadCommentModel = __decorateClass$2([
283
+ __decorateParam$2(0, Inject(IThreadCommentDataSourceService)),
284
+ __decorateParam$2(1, ICommandService)
285
+ ], ThreadCommentModel);
286
+ var I = /* @__PURE__ */ ((E) => (E[E.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", E[E.UNIVER_DOC = 1] = "UNIVER_DOC", E[E.UNIVER_SHEET = 2] = "UNIVER_SHEET", E[E.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(I || {});
287
+ const TC_PLUGIN_NAME = "THREAD_COMMENT_PLUGIN";
288
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
289
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
290
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
291
+ return kind && result && __defProp$1(target, key, result), result;
292
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a2;
293
+ let ThreadCommentResourceController = (_a2 = class extends Disposable {
294
+ constructor(_resourceManagerService, _threadCommentModel, _threadCommentDataSourceService) {
295
+ super(), this._resourceManagerService = _resourceManagerService, this._threadCommentModel = _threadCommentModel, this._threadCommentDataSourceService = _threadCommentDataSourceService, this._initSnapshot();
294
296
  }
295
297
  _initSnapshot() {
296
- const a = (e) => {
297
- const n = this._threadCommentModel.getUnit(e), r = {};
298
- return n ? (n.forEach(([m, o]) => {
299
- r[m] = o;
300
- }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r, e))) : "";
301
- }, t = (e) => {
302
- if (!e)
298
+ const toJson = /* @__PURE__ */ __name((unitID) => {
299
+ const map2 = this._threadCommentModel.getUnit(unitID), resultMap = {};
300
+ return map2 ? (map2.forEach(([key, v]) => {
301
+ resultMap[key] = v;
302
+ }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(resultMap, unitID))) : "";
303
+ }, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
304
+ if (!json)
303
305
  return {};
304
306
  try {
305
- return JSON.parse(e);
307
+ return JSON.parse(json);
306
308
  } catch {
307
309
  return {};
308
310
  }
309
- };
311
+ }, "parseJson");
310
312
  this.disposeWithMe(
311
313
  this._resourceManagerService.registerPluginResource({
312
- pluginName: `SHEET_${E}`,
313
- businesses: [g.UNIVER_SHEET, g.UNIVER_DOC],
314
- toJson: (e) => a(e),
315
- parseJson: (e) => t(e),
316
- onUnLoad: (e) => {
317
- this._threadCommentModel.deleteUnit(e);
318
- },
319
- onLoad: async (e, n) => {
320
- Object.keys(n).forEach((r) => {
321
- const m = n[r];
322
- m.forEach((o) => {
323
- this._threadCommentModel.addComment(e, r, o);
324
- }), this._threadCommentModel.syncThreadComments(e, r, m.map((o) => o.threadId));
314
+ pluginName: `SHEET_${TC_PLUGIN_NAME}`,
315
+ businesses: [I.UNIVER_SHEET, I.UNIVER_DOC],
316
+ toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
317
+ parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
318
+ onUnLoad: /* @__PURE__ */ __name((unitID) => {
319
+ this._threadCommentModel.deleteUnit(unitID);
320
+ }, "onUnLoad"),
321
+ onLoad: /* @__PURE__ */ __name(async (unitID, value) => {
322
+ Object.keys(value).forEach((subunitId) => {
323
+ const commentList = value[subunitId];
324
+ commentList.forEach((comment) => {
325
+ this._threadCommentModel.addComment(unitID, subunitId, comment);
326
+ }), this._threadCommentModel.syncThreadComments(unitID, subunitId, commentList.map((i) => i.threadId));
325
327
  });
326
- }
328
+ }, "onLoad")
327
329
  })
328
330
  );
329
331
  }
330
- };
331
- S = k([
332
- V(W.Starting, S),
333
- y(0, J),
334
- y(1, U(u)),
335
- y(2, f)
336
- ], S);
337
- const R = {
332
+ }, __name(_a2, "ThreadCommentResourceController"), _a2);
333
+ ThreadCommentResourceController = __decorateClass$1([
334
+ OnLifecycle(LifecycleStages.Starting, ThreadCommentResourceController),
335
+ __decorateParam$1(0, IResourceManagerService),
336
+ __decorateParam$1(1, Inject(ThreadCommentModel)),
337
+ __decorateParam$1(2, IThreadCommentDataSourceService)
338
+ ], ThreadCommentResourceController);
339
+ const AddCommentMutation = {
338
340
  id: "thread-comment.mutation.add-comment",
339
- type: p.MUTATION,
340
- handler(a, t, e) {
341
- if (!t)
341
+ type: CommandType.MUTATION,
342
+ handler(accessor, params, options) {
343
+ if (!params)
342
344
  return !1;
343
- const n = a.get(u), { unitId: r, subUnitId: m, comment: o, sync: s } = t, c = s || (e == null ? void 0 : e.fromChangeset) && !o.parentId;
344
- return n.addComment(r, m, o, c);
345
+ const threadCommentModel = accessor.get(ThreadCommentModel), { unitId, subUnitId, comment, sync } = params, shouldSync = sync || (options == null ? void 0 : options.fromChangeset) && !comment.parentId;
346
+ return threadCommentModel.addComment(unitId, subUnitId, comment, shouldSync);
345
347
  }
346
- }, D = {
348
+ }, UpdateCommentMutation = {
347
349
  id: "thread-comment.mutation.update-comment",
348
- type: p.MUTATION,
349
- handler(a, t) {
350
- if (!t)
350
+ type: CommandType.MUTATION,
351
+ handler(accessor, params) {
352
+ if (!params)
351
353
  return !1;
352
- const e = a.get(u), { unitId: n, subUnitId: r, payload: m, silent: o } = t;
353
- return e.updateComment(n, r, m, o);
354
+ const threadCommentModel = accessor.get(ThreadCommentModel), { unitId, subUnitId, payload, silent } = params;
355
+ return threadCommentModel.updateComment(unitId, subUnitId, payload, silent);
354
356
  }
355
- }, ee = {
357
+ }, UpdateCommentRefMutation = {
356
358
  id: "thread-comment.mutation.update-comment-ref",
357
- type: p.MUTATION,
358
- handler(a, t) {
359
- if (!t)
359
+ type: CommandType.MUTATION,
360
+ handler(accessor, params) {
361
+ if (!params)
360
362
  return !1;
361
- const e = a.get(u), { unitId: n, subUnitId: r, payload: m, silent: o } = t;
362
- return e.updateCommentRef(n, r, m, o);
363
+ const threadCommentModel = accessor.get(ThreadCommentModel), { unitId, subUnitId, payload, silent } = params;
364
+ return threadCommentModel.updateCommentRef(unitId, subUnitId, payload, silent);
363
365
  }
364
- }, w = {
366
+ }, ResolveCommentMutation = {
365
367
  id: "thread-comment.mutation.resolve-comment",
366
- type: p.MUTATION,
367
- handler(a, t) {
368
- if (!t)
368
+ type: CommandType.MUTATION,
369
+ handler(accessor, params) {
370
+ if (!params)
369
371
  return !1;
370
- const e = a.get(u), { unitId: n, subUnitId: r, resolved: m, commentId: o } = t;
371
- return e.resolveComment(n, r, o, m);
372
+ const threadCommentModel = accessor.get(ThreadCommentModel), { unitId, subUnitId, resolved, commentId } = params;
373
+ return threadCommentModel.resolveComment(unitId, subUnitId, commentId, resolved);
372
374
  }
373
- }, N = {
375
+ }, DeleteCommentMutation = {
374
376
  id: "thread-comment.mutation.delete-comment",
375
- type: p.MUTATION,
376
- handler(a, t) {
377
- if (!t)
377
+ type: CommandType.MUTATION,
378
+ handler(accessor, params) {
379
+ if (!params)
378
380
  return !1;
379
- const e = a.get(u), { unitId: n, subUnitId: r, commentId: m } = t;
380
- return e.deleteComment(n, r, m);
381
+ const threadCommentModel = accessor.get(ThreadCommentModel), { unitId, subUnitId, commentId } = params;
382
+ return threadCommentModel.deleteComment(unitId, subUnitId, commentId);
381
383
  }
382
- }, te = {
384
+ }, AddCommentCommand = {
383
385
  id: "thread-comment.command.add-comment",
384
- type: p.COMMAND,
385
- async handler(a, t) {
386
- if (!t)
386
+ type: CommandType.COMMAND,
387
+ async handler(accessor, params) {
388
+ if (!params)
387
389
  return !1;
388
- const e = a.get(_), n = a.get(f), { comment: r } = t, m = await n.addComment(r), o = n.syncUpdateMutationToColla, s = !r.parentId, c = {
389
- id: R.id,
390
+ const commandService = accessor.get(ICommandService), dataSourceService = accessor.get(IThreadCommentDataSourceService), { comment: originComment } = params, comment = await dataSourceService.addComment(originComment), syncUpdateMutationToColla = dataSourceService.syncUpdateMutationToColla, isRoot = !originComment.parentId, redo = {
391
+ id: AddCommentMutation.id,
390
392
  params: {
391
- ...t,
392
- comment: m
393
+ ...params,
394
+ comment
393
395
  }
394
396
  };
395
- return s ? await e.executeCommand(c.id, c.params) : e.executeCommand(c.id, c.params, {
396
- onlyLocal: !o
397
+ return isRoot ? await commandService.executeCommand(redo.id, redo.params) : commandService.executeCommand(redo.id, redo.params, {
398
+ onlyLocal: !syncUpdateMutationToColla
397
399
  });
398
400
  }
399
- }, ne = {
401
+ }, UpdateCommentCommand = {
400
402
  id: "thread-comment.command.update-comment",
401
- type: p.COMMAND,
402
- async handler(a, t) {
403
- if (!t)
403
+ type: CommandType.COMMAND,
404
+ async handler(accessor, params) {
405
+ if (!params)
404
406
  return !1;
405
- const { unitId: e, subUnitId: n, payload: r } = t, m = a.get(_), o = a.get(u), s = a.get(f), c = s.syncUpdateMutationToColla, d = o.getComment(
406
- e,
407
- n,
408
- r.commentId
407
+ const { unitId, subUnitId, payload } = params, commandService = accessor.get(ICommandService), threadCommentModel = accessor.get(ThreadCommentModel), dataSourceService = accessor.get(IThreadCommentDataSourceService), syncUpdateMutationToColla = dataSourceService.syncUpdateMutationToColla, current = threadCommentModel.getComment(
408
+ unitId,
409
+ subUnitId,
410
+ payload.commentId
409
411
  );
410
- if (!d)
412
+ if (!current)
411
413
  return !1;
412
- const { children: i, ...C } = d;
413
- if (!await s.updateComment({
414
- ...C,
415
- ...r
414
+ const { children, ...currentComment } = current;
415
+ if (!await dataSourceService.updateComment({
416
+ ...currentComment,
417
+ ...payload
416
418
  }))
417
419
  return !1;
418
- const M = {
419
- id: D.id,
420
- params: t
420
+ const redo = {
421
+ id: UpdateCommentMutation.id,
422
+ params
421
423
  };
422
- return m.executeCommand(M.id, M.params, { onlyLocal: !c }), !0;
424
+ return commandService.executeCommand(redo.id, redo.params, { onlyLocal: !syncUpdateMutationToColla }), !0;
423
425
  }
424
- }, re = {
426
+ }, ResolveCommentCommand = {
425
427
  id: "thread-comment.command.resolve-comment",
426
- type: p.COMMAND,
427
- async handler(a, t) {
428
- if (!t)
428
+ type: CommandType.COMMAND,
429
+ async handler(accessor, params) {
430
+ if (!params)
429
431
  return !1;
430
- const { unitId: e, subUnitId: n, resolved: r, commentId: m } = t, o = a.get(f), c = a.get(u).getComment(e, n, m), d = o.syncUpdateMutationToColla;
431
- return !c || !await o.resolveComment({
432
- ...c,
433
- resolved: r
434
- }) ? !1 : a.get(_).executeCommand(
435
- w.id,
436
- t,
437
- { onlyLocal: !d }
432
+ const { unitId, subUnitId, resolved, commentId } = params, dataSourceService = accessor.get(IThreadCommentDataSourceService), currentComment = accessor.get(ThreadCommentModel).getComment(unitId, subUnitId, commentId), syncUpdateMutationToColla = dataSourceService.syncUpdateMutationToColla;
433
+ return !currentComment || !await dataSourceService.resolveComment({
434
+ ...currentComment,
435
+ resolved
436
+ }) ? !1 : accessor.get(ICommandService).executeCommand(
437
+ ResolveCommentMutation.id,
438
+ params,
439
+ { onlyLocal: !syncUpdateMutationToColla }
438
440
  );
439
441
  }
440
- }, oe = {
442
+ }, DeleteCommentCommand = {
441
443
  id: "thread-comment.command.delete-comment",
442
- type: p.COMMAND,
443
- async handler(a, t) {
444
- if (!t)
444
+ type: CommandType.COMMAND,
445
+ async handler(accessor, params) {
446
+ if (!params)
445
447
  return !1;
446
- const e = a.get(u), n = a.get(f), r = a.get(_), { unitId: m, subUnitId: o, commentId: s } = t, c = n.syncUpdateMutationToColla, d = e.getComment(m, o, s);
447
- if (!d || !await n.deleteComment(m, o, d.threadId, s))
448
+ const threadCommentModel = accessor.get(ThreadCommentModel), dataSourceService = accessor.get(IThreadCommentDataSourceService), commandService = accessor.get(ICommandService), { unitId, subUnitId, commentId } = params, syncUpdateMutationToColla = dataSourceService.syncUpdateMutationToColla, comment = threadCommentModel.getComment(unitId, subUnitId, commentId);
449
+ if (!comment || !await dataSourceService.deleteComment(unitId, subUnitId, comment.threadId, commentId))
448
450
  return !1;
449
- const i = {
450
- id: N.id,
451
- params: t
451
+ const redo = {
452
+ id: DeleteCommentMutation.id,
453
+ params
452
454
  };
453
- return r.executeCommand(i.id, i.params, { onlyLocal: !c });
455
+ return commandService.executeCommand(redo.id, redo.params, { onlyLocal: !syncUpdateMutationToColla });
454
456
  }
455
- }, ae = {
457
+ }, DeleteCommentTreeCommand = {
456
458
  id: "thread-comment.command.delete-comment-tree",
457
- type: p.COMMAND,
458
- async handler(a, t) {
459
- if (!t)
459
+ type: CommandType.COMMAND,
460
+ async handler(accessor, params) {
461
+ if (!params)
460
462
  return !1;
461
- const e = a.get(u), n = a.get(_), r = a.get(f), { unitId: m, subUnitId: o, commentId: s } = t, c = e.getCommentWithChildren(m, o, s);
462
- return !c || !await r.deleteComment(m, o, c.root.threadId, s) ? !1 : await n.executeCommand(N.id, {
463
- unitId: m,
464
- subUnitId: o,
465
- commentId: c.root.id
463
+ const threadCommentModel = accessor.get(ThreadCommentModel), commandService = accessor.get(ICommandService), dataSourceService = accessor.get(IThreadCommentDataSourceService), { unitId, subUnitId, commentId } = params, commentWithChildren = threadCommentModel.getCommentWithChildren(unitId, subUnitId, commentId);
464
+ return !commentWithChildren || !await dataSourceService.deleteComment(unitId, subUnitId, commentWithChildren.root.threadId, commentId) ? !1 : await commandService.executeCommand(DeleteCommentMutation.id, {
465
+ unitId,
466
+ subUnitId,
467
+ commentId: commentWithChildren.root.id
466
468
  });
467
469
  }
468
470
  };
469
- var me = Object.defineProperty, se = Object.getOwnPropertyDescriptor, ce = (a, t, e, n) => {
470
- for (var r = n > 1 ? void 0 : n ? se(t, e) : t, m = a.length - 1, o; m >= 0; m--)
471
- (o = a[m]) && (r = (n ? o(t, e, r) : o(r)) || r);
472
- return n && r && me(t, e, r), r;
473
- }, I = (a, t) => (e, n) => t(e, n, a), v;
474
- let $ = (v = class extends H {
475
- constructor(t, e, n) {
471
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
472
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
473
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
474
+ return kind && result && __defProp2(target, key, result), result;
475
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a3;
476
+ let UniverThreadCommentPlugin = (_a3 = class extends Plugin {
477
+ constructor(config, _injector, _commandService) {
476
478
  super();
477
- h(this, "_config");
478
- this._injector = e, this._commandService = n, this._config = t;
479
- }
480
- onStarting(t) {
481
- var e;
482
- G([
483
- [f, { useClass: q }],
484
- [u],
485
- [S]
486
- ], (e = this._config) == null ? void 0 : e.overrides).forEach(
487
- (n) => {
488
- t.add(n);
479
+ __publicField(this, "_config");
480
+ this._injector = _injector, this._commandService = _commandService, this._config = config;
481
+ }
482
+ onStarting() {
483
+ var _a4;
484
+ mergeOverrideWithDependencies([
485
+ [IThreadCommentDataSourceService, { useClass: ThreadCommentDataSourceService }],
486
+ [ThreadCommentModel],
487
+ [ThreadCommentResourceController]
488
+ ], (_a4 = this._config) == null ? void 0 : _a4.overrides).forEach(
489
+ (d) => {
490
+ this._injector.add(d);
489
491
  }
490
492
  ), [
491
- te,
492
- ne,
493
- oe,
494
- re,
495
- ae,
496
- R,
497
- D,
498
- ee,
499
- N,
500
- w
501
- ].forEach((n) => {
502
- this._commandService.registerCommand(n);
493
+ AddCommentCommand,
494
+ UpdateCommentCommand,
495
+ DeleteCommentCommand,
496
+ ResolveCommentCommand,
497
+ DeleteCommentTreeCommand,
498
+ AddCommentMutation,
499
+ UpdateCommentMutation,
500
+ UpdateCommentRefMutation,
501
+ DeleteCommentMutation,
502
+ ResolveCommentMutation
503
+ ].forEach((command) => {
504
+ this._commandService.registerCommand(command);
503
505
  });
504
506
  }
505
- }, h(v, "pluginName", E), h(v, "type", B.UNIVER_UNKNOWN), v);
506
- $ = ce([
507
- I(1, U(Z)),
508
- I(2, _)
509
- ], $);
507
+ }, __name(_a3, "UniverThreadCommentPlugin"), __publicField(_a3, "pluginName", TC_PLUGIN_NAME), __publicField(_a3, "type", UniverInstanceType.UNIVER_UNKNOWN), _a3);
508
+ UniverThreadCommentPlugin = __decorateClass([
509
+ __decorateParam(1, Inject(Injector)),
510
+ __decorateParam(2, ICommandService)
511
+ ], UniverThreadCommentPlugin);
510
512
  export {
511
- te as AddCommentCommand,
512
- R as AddCommentMutation,
513
- oe as DeleteCommentCommand,
514
- N as DeleteCommentMutation,
515
- ae as DeleteCommentTreeCommand,
516
- f as IThreadCommentDataSourceService,
517
- re as ResolveCommentCommand,
518
- w as ResolveCommentMutation,
519
- E as TC_PLUGIN_NAME,
520
- q as ThreadCommentDataSourceService,
521
- u as ThreadCommentModel,
522
- S as ThreadCommentResourceController,
523
- $ as UniverThreadCommentPlugin,
524
- ne as UpdateCommentCommand,
525
- D as UpdateCommentMutation,
526
- ee as UpdateCommentRefMutation
513
+ AddCommentCommand,
514
+ AddCommentMutation,
515
+ DeleteCommentCommand,
516
+ DeleteCommentMutation,
517
+ DeleteCommentTreeCommand,
518
+ IThreadCommentDataSourceService,
519
+ ResolveCommentCommand,
520
+ ResolveCommentMutation,
521
+ TC_PLUGIN_NAME,
522
+ ThreadCommentDataSourceService,
523
+ ThreadCommentModel,
524
+ ThreadCommentResourceController,
525
+ UniverThreadCommentPlugin,
526
+ UpdateCommentCommand,
527
+ UpdateCommentMutation,
528
+ UpdateCommentRefMutation
527
529
  };
@@ -1,5 +1,4 @@
1
- import { DependencyOverride, ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
2
- import { Injector } from '@wendellhu/redi';
1
+ import { DependencyOverride, ICommandService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
2
 
4
3
  export interface IUniverThreadCommentConfig {
5
4
  overrides?: DependencyOverride;
@@ -11,5 +10,5 @@ export declare class UniverThreadCommentPlugin extends Plugin {
11
10
  static type: UniverInstanceType;
12
11
  private _config;
13
12
  constructor(config: IUniverThreadCommentConfig, _injector: Injector, _commandService: ICommandService);
14
- onStarting(injector: Injector): void;
13
+ onStarting(): void;
15
14
  }
@@ -1,4 +1,4 @@
1
- import { Nullable, Disposable } from '@univerjs/core';
1
+ import { Disposable, Nullable } from '@univerjs/core';
2
2
  import { IBaseComment, IThreadComment } from '../types/interfaces/i-thread-comment';
3
3
 
4
4
  export type ThreadCommentJSON = {
@@ -70,5 +70,5 @@ export declare class ThreadCommentDataSourceService extends Disposable implement
70
70
  listThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<IBaseComment[]>;
71
71
  saveToSnapshot(unitComments: Record<string, IThreadComment[]>, unitId: string): Record<string, ThreadCommentJSON[]>;
72
72
  }
73
- export declare const IThreadCommentDataSourceService: import('@wendellhu/redi').IdentifierDecorator<IThreadCommentDataSourceService>;
73
+ export declare const IThreadCommentDataSourceService: import('@univerjs/core').IdentifierDecorator<IThreadCommentDataSourceService>;
74
74
  export {};
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(s,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],l):(s=typeof globalThis<"u"?globalThis:s||self,l(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,l,i,v){"use strict";var z=Object.defineProperty;var F=(s,l,i)=>l in s?z(s,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[l]=i;var M=(s,l,i)=>F(s,typeof l!="symbol"?l+"":l,i);var S;class E extends i.Disposable{constructor(){super();M(this,"_dataSource",null);M(this,"syncUpdateMutationToColla",!0)}set dataSource(n){this._dataSource=n}get dataSource(){return this._dataSource}async getThreadComment(n,t,e){return this._dataSource?(await this._dataSource.listComments(n,t,[e]))[0]:null}async addComment(n){return this._dataSource?this._dataSource.addComment(n):n}async updateComment(n){return this._dataSource?this._dataSource.updateComment(n):!0}async resolveComment(n){return this._dataSource?this._dataSource.resolveComment(n):!0}async deleteComment(n,t,e,o){return this._dataSource?this._dataSource.deleteComment(n,t,e,o):!0}async listThreadComments(n,t,e){return this.dataSource?this.dataSource.listComments(n,t,e):[]}saveToSnapshot(n,t){if(this._dataSource){const e={};return Object.keys(n).forEach(o=>{const r=n[o];e[o]=r.map(this.dataSource.saveCommentToSnapshot)}),e}return n}}const f=v.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(a,m,n,t)=>{for(var e=t>1?void 0:t?W(m,n):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(e=(t?r(m,n,e):r(e))||e);return t&&e&&V(m,n,e),e},$=(a,m)=>(n,t)=>m(n,t,a);s.ThreadCommentModel=class extends i.Disposable{constructor(n,t){super();M(this,"_commentsMap",{});M(this,"_commentsTreeMap",new Map);M(this,"_threadMap",new Map);M(this,"_commentUpdate$",new l.Subject);M(this,"_commentsMap$",new l.BehaviorSubject({}));M(this,"commentUpdate$",this._commentUpdate$.asObservable());M(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=n,this._commandService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete(),this._commentsMap$.complete()})}_ensureCommentMap(n,t){let e=this._commentsMap[n];e||(e={},this._commentsMap[n]=e);let o=e[t];return o||(o={},e[t]=o),o}_ensureCommentChildrenMap(n,t){let e=this._commentsTreeMap.get(n);e||(e=new Map,this._commentsTreeMap.set(n,e));let o=e.get(t);return o||(o=new Map,e.set(t,o)),o}_ensureThreadMap(n){let t=this._threadMap.get(n);return t||(t=new Map,this._threadMap.set(n,t)),t}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(n,t){const e=this._ensureCommentMap(n,t),o=this._ensureCommentChildrenMap(n,t);return{commentMap:e,commentChildrenMap:o}}_replaceComment(n,t,e){var c;const{commentMap:o,commentChildrenMap:r}=this.ensureMap(n,t),d=o[e.id];if(d){const h={...e,ref:d.ref};o[e.id]=h,(c=e.children)==null||c.forEach(u=>{o[u.id]={...u,ref:""}}),r.set(e.id,h),this._commentUpdate$.next({unitId:n,subUnitId:t,type:"syncUpdate",payload:h}),!!e.resolved!=!!d.resolved&&this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e.id,resolved:!!e.resolved}})}}async syncThreadComments(n,t,e){const o=await this._dataSourceService.listThreadComments(n,t,e);if(!o.length)return;const r=new Set(e);o.forEach(d=>{this._replaceComment(n,t,d),r.delete(d.threadId)}),r.forEach(d=>{const c=this.getThread(n,d);c&&this.deleteComment(c.unitId,c.subUnitId,c.id)}),this._refreshCommentsMap$()}addComment(n,t,e,o){var C,_;const{commentMap:r,commentChildrenMap:d}=this.ensureMap(n,t),c=e,h=p=>{r[p.id]=p,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})},u=c.parentId;if(u){const p=r[u];p.children=[...(C=p.children)!=null?C:[],c],h(c)}else d.set(c.id,c),this._ensureThreadMap(n).set(c.threadId,c),h(c),(_=c.children)==null||_.forEach(y=>h({...y,ref:""}));return this._refreshCommentsMap$(),o&&this.syncThreadComments(n,t,[c.threadId]),!0}updateComment(n,t,e,o){const{commentMap:r}=this.ensureMap(n,t),d=r[e.commentId];return d?(d.updated=!0,d.text=e.text,d.attachments=e.attachments,d.updateT=e.updateT,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"update",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(n,t,e,o){const{commentMap:r}=this.ensureMap(n,t),d=r[e.commentId];return d?(d.ref=e.ref,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"updateRef",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}resolveComment(n,t,e,o){const{commentMap:r}=this.ensureMap(n,t),d=r[e];return d?(d.resolved=o,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e,resolved:o}}),this._refreshCommentsMap$(),!0):!1}getComment(n,t,e){const{commentMap:o}=this.ensureMap(n,t);return o[e]}getComment$(n,t,e){return this._commentsMap$.pipe(l.map(o=>o[n][t][e]))}getCommentWithChildren(n,t,e){var u,C;const{commentMap:o,commentChildrenMap:r}=this.ensureMap(n,t),d=o[e];if(!d)return;const c=new Set,h=r.get(e);if(h)return[h,...(u=h.children)!=null?u:[]].forEach(_=>{var p;c.add(_.personId),(p=_.text.customRanges)==null||p.forEach(y=>{y.rangeType===i.CustomRangeType.MENTION&&c.add(y.rangeId)})}),{root:d,children:(C=h.children)!=null?C:[],relativeUsers:c}}deleteComment(n,t,e){var c;const{commentMap:o,commentChildrenMap:r}=this.ensureMap(n,t),d=o[e];if(!d)return!0;if(d.parentId){const h=r.get(d.parentId);if(h&&h.children){const u=h.children.findIndex(C=>C.id=e);h.children.splice(u,1)}delete o[e]}else{delete o[e];const h=r.get(e);r.delete(e),this._ensureThreadMap(n).delete(d.threadId),(c=h==null?void 0:h.children)==null||c.forEach(C=>{delete o[C.id],this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:C.id,isRoot:!1,comment:C}})})}return this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:e,isRoot:!d.parentId,comment:d}}),this._refreshCommentsMap$(),!0}getUnit(n){const t=this._commentsMap[n];return t?Array.from(Object.entries(t)).map(([e,o])=>[e,Array.from(Object.values(o))]):[]}deleteUnit(n){const t=this._commentsMap[n];t&&Object.entries(t).forEach(([e,o])=>{Object.values(o).forEach(r=>{this.deleteComment(n,e,r.id)})})}getRootCommentIds(n,t){const e=this._ensureCommentChildrenMap(n,t);return Array.from(e.keys())}getAll(){return this._commentsMap}getThread(n,t){return this._ensureThreadMap(n).get(t)}},s.ThreadCommentModel=J([$(0,v.Inject(f)),$(1,i.ICommandService)],s.ThreadCommentModel);var g=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))(g||{});const U="THREAD_COMMENT_PLUGIN";var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,B=(a,m,n,t)=>{for(var e=t>1?void 0:t?H(m,n):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(e=(t?r(m,n,e):r(e))||e);return t&&e&&G(m,n,e),e},I=(a,m)=>(n,t)=>m(n,t,a);s.ThreadCommentResourceController=class extends i.Disposable{constructor(m,n,t){super(),this._resourceManagerService=m,this._threadCommentModel=n,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const e=this._threadCommentModel.getUnit(t),o={};return e?(e.forEach(([r,d])=>{o[r]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},n=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${U}`,businesses:[g.UNIVER_SHEET,g.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>n(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,e)=>{Object.keys(e).forEach(o=>{const r=e[o];r.forEach(d=>{this._threadCommentModel.addComment(t,o,d)}),this._threadCommentModel.syncThreadComments(t,o,r.map(d=>d.threadId))})}}))}},s.ThreadCommentResourceController=B([i.OnLifecycle(i.LifecycleStages.Starting,s.ThreadCommentResourceController),I(0,i.IResourceManagerService),I(1,v.Inject(s.ThreadCommentModel)),I(2,f)],s.ThreadCommentResourceController);const N={id:"thread-comment.mutation.add-comment",type:i.CommandType.MUTATION,handler(a,m,n){if(!m)return!1;const t=a.get(s.ThreadCommentModel),{unitId:e,subUnitId:o,comment:r,sync:d}=m,c=d||(n==null?void 0:n.fromChangeset)&&!r.parentId;return t.addComment(e,o,r,c)}},O={id:"thread-comment.mutation.update-comment",type:i.CommandType.MUTATION,handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),{unitId:t,subUnitId:e,payload:o,silent:r}=m;return n.updateComment(t,e,o,r)}},D={id:"thread-comment.mutation.update-comment-ref",type:i.CommandType.MUTATION,handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),{unitId:t,subUnitId:e,payload:o,silent:r}=m;return n.updateCommentRef(t,e,o,r)}},R={id:"thread-comment.mutation.resolve-comment",type:i.CommandType.MUTATION,handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),{unitId:t,subUnitId:e,resolved:o,commentId:r}=m;return n.resolveComment(t,e,r,o)}},T={id:"thread-comment.mutation.delete-comment",type:i.CommandType.MUTATION,handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),{unitId:t,subUnitId:e,commentId:o}=m;return n.deleteComment(t,e,o)}},w={id:"thread-comment.command.add-comment",type:i.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const n=a.get(i.ICommandService),t=a.get(f),{comment:e}=m,o=await t.addComment(e),r=t.syncUpdateMutationToColla,d=!e.parentId,c={id:N.id,params:{...m,comment:o}};return d?await n.executeCommand(c.id,c.params):n.executeCommand(c.id,c.params,{onlyLocal:!r})}},P={id:"thread-comment.command.update-comment",type:i.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const{unitId:n,subUnitId:t,payload:e}=m,o=a.get(i.ICommandService),r=a.get(s.ThreadCommentModel),d=a.get(f),c=d.syncUpdateMutationToColla,h=r.getComment(n,t,e.commentId);if(!h)return!1;const{children:u,...C}=h;if(!await d.updateComment({...C,...e}))return!1;const p={id:O.id,params:m};return o.executeCommand(p.id,p.params,{onlyLocal:!c}),!0}},j={id:"thread-comment.command.resolve-comment",type:i.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const{unitId:n,subUnitId:t,resolved:e,commentId:o}=m,r=a.get(f),c=a.get(s.ThreadCommentModel).getComment(n,t,o),h=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:e})?!1:a.get(i.ICommandService).executeCommand(R.id,m,{onlyLocal:!h})}},A={id:"thread-comment.command.delete-comment",type:i.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),t=a.get(f),e=a.get(i.ICommandService),{unitId:o,subUnitId:r,commentId:d}=m,c=t.syncUpdateMutationToColla,h=n.getComment(o,r,d);if(!h||!await t.deleteComment(o,r,h.threadId,d))return!1;const u={id:T.id,params:m};return e.executeCommand(u.id,u.params,{onlyLocal:!c})}},b={id:"thread-comment.command.delete-comment-tree",type:i.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const n=a.get(s.ThreadCommentModel),t=a.get(i.ICommandService),e=a.get(f),{unitId:o,subUnitId:r,commentId:d}=m,c=n.getCommentWithChildren(o,r,d);return!c||!await e.deleteComment(o,r,c.root.threadId,d)?!1:await t.executeCommand(T.id,{unitId:o,subUnitId:r,commentId:c.root.id})}};var q=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Z=(a,m,n,t)=>{for(var e=t>1?void 0:t?K(m,n):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(e=(t?r(m,n,e):r(e))||e);return t&&e&&q(m,n,e),e},L=(a,m)=>(n,t)=>m(n,t,a);s.UniverThreadCommentPlugin=(S=class extends i.Plugin{constructor(n,t,e){super();M(this,"_config");this._injector=t,this._commandService=e,this._config=n}onStarting(n){var t;i.mergeOverrideWithDependencies([[f,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(t=this._config)==null?void 0:t.overrides).forEach(e=>{n.add(e)}),[w,P,A,j,b,N,O,D,T,R].forEach(e=>{this._commandService.registerCommand(e)})}},M(S,"pluginName",U),M(S,"type",i.UniverInstanceType.UNIVER_UNKNOWN),S),s.UniverThreadCommentPlugin=Z([L(1,v.Inject(v.Injector)),L(2,i.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=w,s.AddCommentMutation=N,s.DeleteCommentCommand=A,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=b,s.IThreadCommentDataSourceService=f,s.ResolveCommentCommand=j,s.ResolveCommentMutation=R,s.TC_PLUGIN_NAME=U,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=P,s.UpdateCommentMutation=O,s.UpdateCommentRefMutation=D,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("rxjs"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverThreadComment={},global.rxjs,global.UniverCore))})(this,function(exports2,rxjs,core){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c;const _ThreadCommentDataSourceService=class _ThreadCommentDataSourceService extends core.Disposable{constructor(){super();__publicField(this,"_dataSource",null);__publicField(this,"syncUpdateMutationToColla",!0)}set dataSource(dataSource){this._dataSource=dataSource}get dataSource(){return this._dataSource}async getThreadComment(unitId,subUnitId,threadId){return this._dataSource?(await this._dataSource.listComments(unitId,subUnitId,[threadId]))[0]:null}async addComment(comment){return this._dataSource?this._dataSource.addComment(comment):comment}async updateComment(comment){return this._dataSource?this._dataSource.updateComment(comment):!0}async resolveComment(comment){return this._dataSource?this._dataSource.resolveComment(comment):!0}async deleteComment(unitId,subUnitId,threadId,commentId){return this._dataSource?this._dataSource.deleteComment(unitId,subUnitId,threadId,commentId):!0}async listThreadComments(unitId,subUnitId,threadIds){return this.dataSource?this.dataSource.listComments(unitId,subUnitId,threadIds):[]}saveToSnapshot(unitComments,unitId){if(this._dataSource){const map={};return Object.keys(unitComments).forEach(subUnitId=>{const comments=unitComments[subUnitId];map[subUnitId]=comments.map(this.dataSource.saveCommentToSnapshot)}),map}return unitComments}};__name(_ThreadCommentDataSourceService,"ThreadCommentDataSourceService");let ThreadCommentDataSourceService=_ThreadCommentDataSourceService;const IThreadCommentDataSourceService=core.createIdentifier("univer.thread-comment.data-source-service");var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");exports2.ThreadCommentModel=(_a=class extends core.Disposable{constructor(_dataSourceService,_commandService){super();__publicField(this,"_commentsMap",{});__publicField(this,"_commentsTreeMap",new Map);__publicField(this,"_threadMap",new Map);__publicField(this,"_commentUpdate$",new rxjs.Subject);__publicField(this,"_commentsMap$",new rxjs.BehaviorSubject({}));__publicField(this,"commentUpdate$",this._commentUpdate$.asObservable());__publicField(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=_dataSourceService,this._commandService=_commandService,this.disposeWithMe(()=>{this._commentUpdate$.complete(),this._commentsMap$.complete()})}_ensureCommentMap(unitId,subUnitId){let unitMap=this._commentsMap[unitId];unitMap||(unitMap={},this._commentsMap[unitId]=unitMap);let subUnitMap=unitMap[subUnitId];return subUnitMap||(subUnitMap={},unitMap[subUnitId]=subUnitMap),subUnitMap}_ensureCommentChildrenMap(unitId,subUnitId){let unitMap=this._commentsTreeMap.get(unitId);unitMap||(unitMap=new Map,this._commentsTreeMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_ensureThreadMap(unitId){let unitMap=this._threadMap.get(unitId);return unitMap||(unitMap=new Map,this._threadMap.set(unitId,unitMap)),unitMap}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(unitId,subUnitId){const commentMap=this._ensureCommentMap(unitId,subUnitId),commentChildrenMap=this._ensureCommentChildrenMap(unitId,subUnitId);return{commentMap,commentChildrenMap}}_replaceComment(unitId,subUnitId,comment){var _a2;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),currentComment=commentMap[comment.id];if(currentComment){const newComment={...comment,ref:currentComment.ref};commentMap[comment.id]=newComment,(_a2=comment.children)==null||_a2.forEach(child=>{commentMap[child.id]={...child,ref:""}}),commentChildrenMap.set(comment.id,newComment),this._commentUpdate$.next({unitId,subUnitId,type:"syncUpdate",payload:newComment}),!!comment.resolved!=!!currentComment.resolved&&this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId:comment.id,resolved:!!comment.resolved}})}}async syncThreadComments(unitId,subUnitId,threadIds){const comments=await this._dataSourceService.listThreadComments(unitId,subUnitId,threadIds);if(!comments.length)return;const deleteThreads=new Set(threadIds);comments.forEach(comment=>{this._replaceComment(unitId,subUnitId,comment),deleteThreads.delete(comment.threadId)}),deleteThreads.forEach(id=>{const thread=this.getThread(unitId,id);thread&&this.deleteComment(thread.unitId,thread.subUnitId,thread.id)}),this._refreshCommentsMap$()}addComment(unitId,subUnitId,origin,shouldSync){var _a2,_b2;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),comment=origin,addCommentItem=__name(item=>{commentMap[item.id]=item,this._commentUpdate$.next({unitId,subUnitId,type:"add",payload:item,isRoot:!item.parentId})},"addCommentItem"),parentId=comment.parentId;if(parentId){const parent=commentMap[parentId];parent.children=[...(_a2=parent.children)!=null?_a2:[],comment],addCommentItem(comment)}else commentChildrenMap.set(comment.id,comment),this._ensureThreadMap(unitId).set(comment.threadId,comment),addCommentItem(comment),(_b2=comment.children)==null||_b2.forEach(child=>addCommentItem({...child,ref:""}));return this._refreshCommentsMap$(),shouldSync&&this.syncThreadComments(unitId,subUnitId,[comment.threadId]),!0}updateComment(unitId,subUnitId,payload,silent){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[payload.commentId];return oldComment?(oldComment.updated=!0,oldComment.text=payload.text,oldComment.attachments=payload.attachments,oldComment.updateT=payload.updateT,this._commentUpdate$.next({unitId,subUnitId,type:"update",payload,silent}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(unitId,subUnitId,payload,silent){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[payload.commentId];return oldComment?(oldComment.ref=payload.ref,this._commentUpdate$.next({unitId,subUnitId,type:"updateRef",payload,silent}),this._refreshCommentsMap$(),!0):!1}resolveComment(unitId,subUnitId,commentId,resolved){const{commentMap}=this.ensureMap(unitId,subUnitId),oldComment=commentMap[commentId];return oldComment?(oldComment.resolved=resolved,this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId,resolved}}),this._refreshCommentsMap$(),!0):!1}getComment(unitId,subUnitId,commentId){const{commentMap}=this.ensureMap(unitId,subUnitId);return commentMap[commentId]}getComment$(unitId,subUnitId,commentId){return this._commentsMap$.pipe(rxjs.map(records=>records[unitId][subUnitId][commentId]))}getCommentWithChildren(unitId,subUnitId,commentId){var _a2,_b2;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),current=commentMap[commentId];if(!current)return;const relativeUsers=new Set,root=commentChildrenMap.get(commentId);if(root)return[root,...(_a2=root.children)!=null?_a2:[]].forEach(comment=>{var _a3;relativeUsers.add(comment.personId),(_a3=comment.text.customRanges)==null||_a3.forEach(range=>{range.rangeType===core.CustomRangeType.MENTION&&relativeUsers.add(range.rangeId)})}),{root:current,children:(_b2=root.children)!=null?_b2:[],relativeUsers}}deleteComment(unitId,subUnitId,commentId){var _a2;const{commentMap,commentChildrenMap}=this.ensureMap(unitId,subUnitId),current=commentMap[commentId];if(!current)return!0;if(current.parentId){const root=commentChildrenMap.get(current.parentId);if(root&&root.children){const index=root.children.findIndex(comment=>comment.id=commentId);root.children.splice(index,1)}delete commentMap[commentId]}else{delete commentMap[commentId];const comment=commentChildrenMap.get(commentId);commentChildrenMap.delete(commentId),this._ensureThreadMap(unitId).delete(current.threadId),(_a2=comment==null?void 0:comment.children)==null||_a2.forEach(child=>{delete commentMap[child.id],this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId:child.id,isRoot:!1,comment:child}})})}return this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId,isRoot:!current.parentId,comment:current}}),this._refreshCommentsMap$(),!0}getUnit(unitId){const unitMap=this._commentsMap[unitId];return unitMap?Array.from(Object.entries(unitMap)).map(([subUnitId,subUnitMap])=>[subUnitId,Array.from(Object.values(subUnitMap))]):[]}deleteUnit(unitId){const unitMap=this._commentsMap[unitId];unitMap&&Object.entries(unitMap).forEach(([subUnitId,subUnitMap])=>{Object.values(subUnitMap).forEach(comment=>{this.deleteComment(unitId,subUnitId,comment.id)})})}getRootCommentIds(unitId,subUnitId){const commentChildrenMap=this._ensureCommentChildrenMap(unitId,subUnitId);return Array.from(commentChildrenMap.keys())}getAll(){return this._commentsMap}getThread(unitId,threadId){return this._ensureThreadMap(unitId).get(threadId)}},__name(_a,"ThreadCommentModel"),_a),exports2.ThreadCommentModel=__decorateClass$2([__decorateParam$2(0,core.Inject(IThreadCommentDataSourceService)),__decorateParam$2(1,core.ICommandService)],exports2.ThreadCommentModel);var I=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(I||{});const TC_PLUGIN_NAME="THREAD_COMMENT_PLUGIN";var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.ThreadCommentResourceController=(_b=class extends core.Disposable{constructor(_resourceManagerService,_threadCommentModel,_threadCommentDataSourceService){super(),this._resourceManagerService=_resourceManagerService,this._threadCommentModel=_threadCommentModel,this._threadCommentDataSourceService=_threadCommentDataSourceService,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._threadCommentModel.getUnit(unitID),resultMap={};return map?(map.forEach(([key,v])=>{resultMap[key]=v}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(resultMap,unitID))):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${TC_PLUGIN_NAME}`,businesses:[I.UNIVER_SHEET,I.UNIVER_DOC],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._threadCommentModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{const commentList=value[subunitId];commentList.forEach(comment=>{this._threadCommentModel.addComment(unitID,subunitId,comment)}),this._threadCommentModel.syncThreadComments(unitID,subunitId,commentList.map(i=>i.threadId))})},"onLoad")}))}},__name(_b,"ThreadCommentResourceController"),_b),exports2.ThreadCommentResourceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Starting,exports2.ThreadCommentResourceController),__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports2.ThreadCommentModel)),__decorateParam$1(2,IThreadCommentDataSourceService)],exports2.ThreadCommentResourceController);const AddCommentMutation={id:"thread-comment.mutation.add-comment",type:core.CommandType.MUTATION,handler(accessor,params,options){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),{unitId,subUnitId,comment,sync}=params,shouldSync=sync||(options==null?void 0:options.fromChangeset)&&!comment.parentId;return threadCommentModel.addComment(unitId,subUnitId,comment,shouldSync)}},UpdateCommentMutation={id:"thread-comment.mutation.update-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),{unitId,subUnitId,payload,silent}=params;return threadCommentModel.updateComment(unitId,subUnitId,payload,silent)}},UpdateCommentRefMutation={id:"thread-comment.mutation.update-comment-ref",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),{unitId,subUnitId,payload,silent}=params;return threadCommentModel.updateCommentRef(unitId,subUnitId,payload,silent)}},ResolveCommentMutation={id:"thread-comment.mutation.resolve-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),{unitId,subUnitId,resolved,commentId}=params;return threadCommentModel.resolveComment(unitId,subUnitId,commentId,resolved)}},DeleteCommentMutation={id:"thread-comment.mutation.delete-comment",type:core.CommandType.MUTATION,handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),{unitId,subUnitId,commentId}=params;return threadCommentModel.deleteComment(unitId,subUnitId,commentId)}},AddCommentCommand={id:"thread-comment.command.add-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const commandService=accessor.get(core.ICommandService),dataSourceService=accessor.get(IThreadCommentDataSourceService),{comment:originComment}=params,comment=await dataSourceService.addComment(originComment),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,isRoot=!originComment.parentId,redo={id:AddCommentMutation.id,params:{...params,comment}};return isRoot?await commandService.executeCommand(redo.id,redo.params):commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla})}},UpdateCommentCommand={id:"thread-comment.command.update-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{unitId,subUnitId,payload}=params,commandService=accessor.get(core.ICommandService),threadCommentModel=accessor.get(exports2.ThreadCommentModel),dataSourceService=accessor.get(IThreadCommentDataSourceService),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,current=threadCommentModel.getComment(unitId,subUnitId,payload.commentId);if(!current)return!1;const{children,...currentComment}=current;if(!await dataSourceService.updateComment({...currentComment,...payload}))return!1;const redo={id:UpdateCommentMutation.id,params};return commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla}),!0}},ResolveCommentCommand={id:"thread-comment.command.resolve-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{unitId,subUnitId,resolved,commentId}=params,dataSourceService=accessor.get(IThreadCommentDataSourceService),currentComment=accessor.get(exports2.ThreadCommentModel).getComment(unitId,subUnitId,commentId),syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla;return!currentComment||!await dataSourceService.resolveComment({...currentComment,resolved})?!1:accessor.get(core.ICommandService).executeCommand(ResolveCommentMutation.id,params,{onlyLocal:!syncUpdateMutationToColla})}},DeleteCommentCommand={id:"thread-comment.command.delete-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),dataSourceService=accessor.get(IThreadCommentDataSourceService),commandService=accessor.get(core.ICommandService),{unitId,subUnitId,commentId}=params,syncUpdateMutationToColla=dataSourceService.syncUpdateMutationToColla,comment=threadCommentModel.getComment(unitId,subUnitId,commentId);if(!comment||!await dataSourceService.deleteComment(unitId,subUnitId,comment.threadId,commentId))return!1;const redo={id:DeleteCommentMutation.id,params};return commandService.executeCommand(redo.id,redo.params,{onlyLocal:!syncUpdateMutationToColla})}},DeleteCommentTreeCommand={id:"thread-comment.command.delete-comment-tree",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const threadCommentModel=accessor.get(exports2.ThreadCommentModel),commandService=accessor.get(core.ICommandService),dataSourceService=accessor.get(IThreadCommentDataSourceService),{unitId,subUnitId,commentId}=params,commentWithChildren=threadCommentModel.getCommentWithChildren(unitId,subUnitId,commentId);return!commentWithChildren||!await dataSourceService.deleteComment(unitId,subUnitId,commentWithChildren.root.threadId,commentId)?!1:await commandService.executeCommand(DeleteCommentMutation.id,{unitId,subUnitId,commentId:commentWithChildren.root.id})}};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");exports2.UniverThreadCommentPlugin=(_c=class extends core.Plugin{constructor(config,_injector,_commandService){super();__publicField(this,"_config");this._injector=_injector,this._commandService=_commandService,this._config=config}onStarting(){var _a2;core.mergeOverrideWithDependencies([[IThreadCommentDataSourceService,{useClass:ThreadCommentDataSourceService}],[exports2.ThreadCommentModel],[exports2.ThreadCommentResourceController]],(_a2=this._config)==null?void 0:_a2.overrides).forEach(d=>{this._injector.add(d)}),[AddCommentCommand,UpdateCommentCommand,DeleteCommentCommand,ResolveCommentCommand,DeleteCommentTreeCommand,AddCommentMutation,UpdateCommentMutation,UpdateCommentRefMutation,DeleteCommentMutation,ResolveCommentMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_c,"UniverThreadCommentPlugin"),__publicField(_c,"pluginName",TC_PLUGIN_NAME),__publicField(_c,"type",core.UniverInstanceType.UNIVER_UNKNOWN),_c),exports2.UniverThreadCommentPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports2.UniverThreadCommentPlugin),exports2.AddCommentCommand=AddCommentCommand,exports2.AddCommentMutation=AddCommentMutation,exports2.DeleteCommentCommand=DeleteCommentCommand,exports2.DeleteCommentMutation=DeleteCommentMutation,exports2.DeleteCommentTreeCommand=DeleteCommentTreeCommand,exports2.IThreadCommentDataSourceService=IThreadCommentDataSourceService,exports2.ResolveCommentCommand=ResolveCommentCommand,exports2.ResolveCommentMutation=ResolveCommentMutation,exports2.TC_PLUGIN_NAME=TC_PLUGIN_NAME,exports2.ThreadCommentDataSourceService=ThreadCommentDataSourceService,exports2.UpdateCommentCommand=UpdateCommentCommand,exports2.UpdateCommentMutation=UpdateCommentMutation,exports2.UpdateCommentRefMutation=UpdateCommentRefMutation,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/thread-comment",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "private": false,
5
5
  "description": "Univer thread comment core plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -47,21 +47,19 @@
47
47
  "lib"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@wendellhu/redi": "0.16.0",
51
50
  "rxjs": ">=7.0.0",
52
- "@univerjs/core": "0.2.4"
51
+ "@univerjs/core": "0.2.6"
53
52
  },
54
53
  "dependencies": {
55
54
  "@univerjs/protocol": "0.1.38-alpha.23"
56
55
  },
57
56
  "devDependencies": {
58
- "@wendellhu/redi": "0.16.0",
59
57
  "rxjs": "^7.8.1",
60
- "typescript": "^5.5.3",
61
- "vite": "^5.3.4",
62
- "vitest": "^2.0.3",
63
- "@univerjs/shared": "0.2.4",
64
- "@univerjs/core": "0.2.4"
58
+ "typescript": "^5.5.4",
59
+ "vite": "^5.3.5",
60
+ "vitest": "^2.0.4",
61
+ "@univerjs/core": "0.2.6",
62
+ "@univerjs/shared": "0.2.6"
65
63
  },
66
64
  "univerSpace": {
67
65
  ".": {