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