@univerjs/thread-comment 0.4.1 → 0.4.2

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 __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 core=require("@univerjs/core"),rxjs=require("rxjs"),_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 R=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(R||{});const TC_PLUGIN_NAME="UNIVER_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:[R.UNIVER_SHEET,R.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([__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})}},PLUGIN_CONFIG_KEY="thread-comment.config",defaultPluginConfig={};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=defaultPluginConfig,_injector,_commandService,_configService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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)}),this._injector.get(exports.ThreadCommentResourceController)}},__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),__decorateParam(3,core.IConfigService)],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;
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 core=require("@univerjs/core"),rxjs=require("rxjs"),_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){var _a4;return this._dataSource?this._dataSource.addComment(comment):{...comment,threadId:(_a4=comment.threadId)!=null?_a4:comment.id}}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):!1}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,_lifecycleService){super();__publicField(this,"_commentsMap",new Map);__publicField(this,"_threadMap",new Map);__publicField(this,"_commentUpdate$",new rxjs.Subject);__publicField(this,"commentUpdate$",this._commentUpdate$.asObservable());__publicField(this,"_tasks",[]);this._dataSourceService=_dataSourceService,this._lifecycleService=_lifecycleService,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(stage=>{const taskMap=new Map;stage===core.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId,subUnitId,threadIds})=>{let unitMap=taskMap.get(unitId);unitMap||(unitMap=new Map,taskMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);subUnitMap||(subUnitMap=new Set,unitMap.set(subUnitId,subUnitMap));for(const threadId of threadIds)subUnitMap.add(threadId)}),this._tasks=[],taskMap.forEach((subUnitMap,unitId)=>{subUnitMap.forEach((threadIds,subUnitId)=>{this.syncThreadComments(unitId,subUnitId,Array.from(threadIds))})}))}))}_ensureCommentMap(unitId,subUnitId){let unitMap=this._commentsMap.get(unitId);unitMap||(unitMap=new Map,this._commentsMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}ensureMap(unitId,subUnitId){return this._ensureCommentMap(unitId,subUnitId)}_ensureThreadMap(unitId,subUnitId){let unitMap=this._threadMap.get(unitId);unitMap||(unitMap=new Map,this._threadMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_replaceComment(unitId,subUnitId,comment){const commentMap=this._ensureCommentMap(unitId,subUnitId),currentComment=commentMap.get(comment.id);if(currentComment){const{children,...rest}=comment,newComment={...rest,ref:currentComment.ref};commentMap.set(comment.id,newComment),children==null||children.forEach(child=>{commentMap.set(child.id,{...child,ref:""})}),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){if(this._lifecycleService.stage<core.LifecycleStages.Rendered){this._tasks.push({unitId,subUnitId,threadIds});return}const threadMap=this._ensureThreadMap(unitId,subUnitId),commentMap=this._ensureCommentMap(unitId,subUnitId),comments=await this._dataSourceService.listThreadComments(unitId,subUnitId,threadIds);if(!comments)return;const deleteThreads=new Set(threadIds);comments.forEach(comment=>{this._replaceComment(unitId,subUnitId,comment),deleteThreads.delete(comment.threadId)}),deleteThreads.forEach(id=>{threadMap.delete(id),commentMap.forEach((comment,commentId)=>{comment.threadId===id&&commentMap.delete(commentId)})})}addComment(unitId,subUnitId,origin,shouldSync){const commentMap=this._ensureCommentMap(unitId,subUnitId),{parentId,children=[],...rest}=origin,comment={...rest,parentId:parentId===origin.id?void 0:parentId},addCommentItem=__name(item=>{commentMap.set(item.id,item),this._commentUpdate$.next({unitId,subUnitId,type:"add",payload:item,isRoot:!item.parentId})},"addCommentItem");addCommentItem(comment);const threadMap=this._ensureThreadMap(unitId,subUnitId);if(!comment.parentId){threadMap.set(comment.threadId,comment);for(const child of children)addCommentItem(child)}return shouldSync&&this.syncThreadComments(unitId,subUnitId,[comment.threadId]),!0}updateComment(unitId,subUnitId,payload,silent){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(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})),!0}updateCommentRef(unitId,subUnitId,payload,silent){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(payload.commentId);return oldComment?(oldComment.ref=payload.ref,this._commentUpdate$.next({unitId,subUnitId,type:"updateRef",payload,silent,threadId:oldComment.threadId}),!0):!1}resolveComment(unitId,subUnitId,commentId,resolved){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(commentId);return oldComment?(oldComment.resolved=resolved,this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId,resolved}}),!0):!1}getComment(unitId,subUnitId,commentId){return this._ensureCommentMap(unitId,subUnitId).get(commentId)}getRootComment(unitId,subUnitId,threadId){return this._ensureThreadMap(unitId,subUnitId).get(threadId)}getThread(unitId,subUnitId,threadId){const commentMap=this._ensureCommentMap(unitId,subUnitId),comments=Array.from(commentMap.values()).filter(comment=>comment.threadId===threadId);let root;const children=[],relativeUsers=new Set;for(const comment of comments)comment.parentId?children.push(comment):root=comment,relativeUsers.add(comment.personId);if(root)return{root,children,relativeUsers,unitId,subUnitId,threadId}}getCommentWithChildren(unitId,subUnitId,commentId){const comment=this.getComment(unitId,subUnitId,commentId);if(comment)return this.getThread(unitId,subUnitId,comment.threadId)}_deleteComment(unitId,subUnitId,commentId){const commentMap=this._ensureCommentMap(unitId,subUnitId),current=commentMap.get(commentId);current&&(commentMap.delete(commentId),this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId,isRoot:!current.parentId,comment:current}}))}deleteThread(unitId,subUnitId,threadId){this._ensureThreadMap(unitId,subUnitId).delete(threadId),this._ensureCommentMap(unitId,subUnitId).forEach(comment=>{comment.threadId===threadId&&this._deleteComment(unitId,subUnitId,comment.id)})}deleteComment(unitId,subUnitId,commentId){const current=this._ensureCommentMap(unitId,subUnitId).get(commentId);return current&&(current.parentId?this._deleteComment(unitId,subUnitId,commentId):this.deleteThread(unitId,subUnitId,current.threadId)),!0}deleteUnit(unitId){const unitMap=this._commentsMap.get(unitId);unitMap&&unitMap.forEach((subUnitMap,subUnitId)=>{subUnitMap.forEach(comment=>{this.deleteComment(unitId,subUnitId,comment.id)})})}getUnit(unitId){const unitMap=this._threadMap.get(unitId);if(!unitMap)return[];const threads=[];return unitMap.forEach((subUnitSet,subUnitId)=>{subUnitSet.forEach((threadComment,threadId)=>{const thread=this.getThread(unitId,subUnitId,threadId);thread&&threads.push(thread)})}),threads}getAll(){const all=[];return this._commentsMap.forEach((unitMap,unitId)=>{all.push({unitId,threads:this.getUnit(unitId)})}),all}},__name(_a,"ThreadCommentModel"),_a);exports.ThreadCommentModel=__decorateClass$2([__decorateParam$2(0,core.Inject(IThreadCommentDataSourceService)),__decorateParam$2(1,core.Inject(core.LifecycleService))],exports.ThreadCommentModel);var _=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(_||{});const TC_PLUGIN_NAME="UNIVER_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(info=>{var _a4;const subUnitComments=(_a4=resultMap[info.subUnitId])!=null?_a4:[];subUnitComments.push({...info.root,children:info.children}),resultMap[info.unitId]=subUnitComments}),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:[_.UNIVER_SHEET,_.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([__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})}},PLUGIN_CONFIG_KEY="thread-comment.config",defaultPluginConfig={};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=defaultPluginConfig,_injector,_commandService,_configService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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)}),this._injector.get(exports.ThreadCommentResourceController)}},__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),__decorateParam(3,core.IConfigService)],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
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { createIdentifier, Disposable, Inject, CustomRangeType, ICommandService, IResourceManagerService, CommandType, Plugin, UniverInstanceType, mergeOverrideWithDependencies, Injector, IConfigService } from "@univerjs/core";
6
- import { Subject, BehaviorSubject, map } from "rxjs";
5
+ import { createIdentifier, Disposable, Inject, LifecycleService, LifecycleStages, IResourceManagerService, CommandType, ICommandService, Plugin, UniverInstanceType, mergeOverrideWithDependencies, Injector, IConfigService } from "@univerjs/core";
6
+ import { Subject } from "rxjs";
7
7
  const _ThreadCommentDataSourceService = class _ThreadCommentDataSourceService extends Disposable {
8
8
  constructor() {
9
9
  super();
@@ -20,7 +20,8 @@ const _ThreadCommentDataSourceService = class _ThreadCommentDataSourceService ex
20
20
  return this._dataSource ? (await this._dataSource.listComments(unitId, subUnitId, [threadId]))[0] : null;
21
21
  }
22
22
  async addComment(comment) {
23
- return this._dataSource ? this._dataSource.addComment(comment) : comment;
23
+ var _a4;
24
+ return this._dataSource ? this._dataSource.addComment(comment) : { ...comment, threadId: (_a4 = comment.threadId) != null ? _a4 : comment.id };
24
25
  }
25
26
  async updateComment(comment) {
26
27
  return this._dataSource ? this._dataSource.updateComment(comment) : !0;
@@ -32,15 +33,15 @@ const _ThreadCommentDataSourceService = class _ThreadCommentDataSourceService ex
32
33
  return this._dataSource ? this._dataSource.deleteComment(unitId, subUnitId, threadId, commentId) : !0;
33
34
  }
34
35
  async listThreadComments(unitId, subUnitId, threadIds) {
35
- return this.dataSource ? this.dataSource.listComments(unitId, subUnitId, threadIds) : [];
36
+ return this.dataSource ? this.dataSource.listComments(unitId, subUnitId, threadIds) : !1;
36
37
  }
37
38
  saveToSnapshot(unitComments, unitId) {
38
39
  if (this._dataSource) {
39
- const map2 = {};
40
+ const map = {};
40
41
  return Object.keys(unitComments).forEach((subUnitId) => {
41
42
  const comments = unitComments[subUnitId];
42
- map2[subUnitId] = comments.map(this.dataSource.saveCommentToSnapshot);
43
- }), map2;
43
+ map[subUnitId] = comments.map(this.dataSource.saveCommentToSnapshot);
44
+ }), map;
44
45
  }
45
46
  return unitComments;
46
47
  }
@@ -54,61 +55,59 @@ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPrope
54
55
  return kind && result && __defProp$2(target, key, result), result;
55
56
  }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a;
56
57
  let ThreadCommentModel = (_a = class extends Disposable {
57
- constructor(_dataSourceService, _commandService) {
58
+ constructor(_dataSourceService, _lifecycleService) {
58
59
  super();
59
- __publicField(this, "_commentsMap", {});
60
- __publicField(this, "_commentsTreeMap", /* @__PURE__ */ new Map());
60
+ __publicField(this, "_commentsMap", /* @__PURE__ */ new Map());
61
61
  __publicField(this, "_threadMap", /* @__PURE__ */ new Map());
62
62
  __publicField(this, "_commentUpdate$", new Subject());
63
- __publicField(this, "_commentsMap$", new BehaviorSubject({}));
64
63
  __publicField(this, "commentUpdate$", this._commentUpdate$.asObservable());
65
- __publicField(this, "commentMap$", this._commentsMap$.asObservable());
66
- this._dataSourceService = _dataSourceService, this._commandService = _commandService, this.disposeWithMe(() => {
67
- this._commentUpdate$.complete(), this._commentsMap$.complete();
68
- });
64
+ __publicField(this, "_tasks", []);
65
+ this._dataSourceService = _dataSourceService, this._lifecycleService = _lifecycleService, this.disposeWithMe(() => {
66
+ this._commentUpdate$.complete();
67
+ }), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((stage) => {
68
+ const taskMap = /* @__PURE__ */ new Map();
69
+ stage === LifecycleStages.Rendered && (this._tasks.forEach(({ unitId, subUnitId, threadIds }) => {
70
+ let unitMap = taskMap.get(unitId);
71
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), taskMap.set(unitId, unitMap));
72
+ let subUnitMap = unitMap.get(subUnitId);
73
+ subUnitMap || (subUnitMap = /* @__PURE__ */ new Set(), unitMap.set(subUnitId, subUnitMap));
74
+ for (const threadId of threadIds)
75
+ subUnitMap.add(threadId);
76
+ }), this._tasks = [], taskMap.forEach((subUnitMap, unitId) => {
77
+ subUnitMap.forEach((threadIds, subUnitId) => {
78
+ this.syncThreadComments(unitId, subUnitId, Array.from(threadIds));
79
+ });
80
+ }));
81
+ }));
69
82
  }
70
83
  _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;
75
- }
76
- _ensureCommentChildrenMap(unitId, subUnitId) {
77
- let unitMap = this._commentsTreeMap.get(unitId);
78
- unitMap || (unitMap = /* @__PURE__ */ new Map(), this._commentsTreeMap.set(unitId, unitMap));
84
+ let unitMap = this._commentsMap.get(unitId);
85
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._commentsMap.set(unitId, unitMap));
79
86
  let subUnitMap = unitMap.get(subUnitId);
80
87
  return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
81
88
  }
82
- _ensureThreadMap(unitId) {
83
- let unitMap = this._threadMap.get(unitId);
84
- return unitMap || (unitMap = /* @__PURE__ */ new Map(), this._threadMap.set(unitId, unitMap)), unitMap;
85
- }
86
- _refreshCommentsMap$() {
87
- this._commentsMap$.next({
88
- ...this._commentsMap
89
- });
90
- }
91
89
  ensureMap(unitId, subUnitId) {
92
- const commentMap = this._ensureCommentMap(unitId, subUnitId), commentChildrenMap = this._ensureCommentChildrenMap(unitId, subUnitId);
93
- return {
94
- commentMap,
95
- commentChildrenMap
96
- };
90
+ return this._ensureCommentMap(unitId, subUnitId);
91
+ }
92
+ _ensureThreadMap(unitId, subUnitId) {
93
+ let unitMap = this._threadMap.get(unitId);
94
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._threadMap.set(unitId, unitMap));
95
+ let subUnitMap = unitMap.get(subUnitId);
96
+ return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
97
97
  }
98
98
  _replaceComment(unitId, subUnitId, comment) {
99
- var _a4;
100
- const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), currentComment = commentMap[comment.id];
99
+ const commentMap = this._ensureCommentMap(unitId, subUnitId), currentComment = commentMap.get(comment.id);
101
100
  if (currentComment) {
102
- const newComment = {
103
- ...comment,
101
+ const { children, ...rest } = comment, newComment = {
102
+ ...rest,
104
103
  ref: currentComment.ref
105
104
  };
106
- commentMap[comment.id] = newComment, (_a4 = comment.children) == null || _a4.forEach((child) => {
107
- commentMap[child.id] = {
105
+ commentMap.set(comment.id, newComment), children == null || children.forEach((child) => {
106
+ commentMap.set(child.id, {
108
107
  ...child,
109
108
  ref: ""
110
- };
111
- }), commentChildrenMap.set(comment.id, newComment), this._commentUpdate$.next({
109
+ });
110
+ }), this._commentUpdate$.next({
112
111
  unitId,
113
112
  subUnitId,
114
113
  type: "syncUpdate",
@@ -125,63 +124,67 @@ let ThreadCommentModel = (_a = class extends Disposable {
125
124
  }
126
125
  }
127
126
  async syncThreadComments(unitId, subUnitId, threadIds) {
128
- const comments = await this._dataSourceService.listThreadComments(unitId, subUnitId, threadIds);
129
- if (!comments.length)
127
+ if (this._lifecycleService.stage < LifecycleStages.Rendered) {
128
+ this._tasks.push({ unitId, subUnitId, threadIds });
129
+ return;
130
+ }
131
+ const threadMap = this._ensureThreadMap(unitId, subUnitId), commentMap = this._ensureCommentMap(unitId, subUnitId), comments = await this._dataSourceService.listThreadComments(unitId, subUnitId, threadIds);
132
+ if (!comments)
130
133
  return;
131
134
  const deleteThreads = new Set(threadIds);
132
135
  comments.forEach((comment) => {
133
136
  this._replaceComment(unitId, subUnitId, comment), deleteThreads.delete(comment.threadId);
134
137
  }), deleteThreads.forEach((id) => {
135
- const thread = this.getThread(unitId, id);
136
- thread && this.deleteComment(thread.unitId, thread.subUnitId, thread.id);
137
- }), this._refreshCommentsMap$();
138
+ threadMap.delete(id), commentMap.forEach((comment, commentId) => {
139
+ comment.threadId === id && commentMap.delete(commentId);
140
+ });
141
+ });
138
142
  }
139
143
  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({
144
+ const commentMap = this._ensureCommentMap(unitId, subUnitId), { parentId, children = [], ...rest } = origin, comment = {
145
+ ...rest,
146
+ parentId: parentId === origin.id ? void 0 : parentId
147
+ }, addCommentItem = /* @__PURE__ */ __name((item) => {
148
+ commentMap.set(item.id, item), this._commentUpdate$.next({
143
149
  unitId,
144
150
  subUnitId,
145
151
  type: "add",
146
152
  payload: item,
147
153
  isRoot: !item.parentId
148
154
  });
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);
156
- } else
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,
159
- ref: ""
160
- }));
161
- return this._refreshCommentsMap$(), shouldSync && this.syncThreadComments(unitId, subUnitId, [comment.threadId]), !0;
155
+ }, "addCommentItem");
156
+ addCommentItem(comment);
157
+ const threadMap = this._ensureThreadMap(unitId, subUnitId);
158
+ if (!comment.parentId) {
159
+ threadMap.set(comment.threadId, comment);
160
+ for (const child of children)
161
+ addCommentItem(child);
162
+ }
163
+ return shouldSync && this.syncThreadComments(unitId, subUnitId, [comment.threadId]), !0;
162
164
  }
163
165
  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
+ const oldComment = this._ensureCommentMap(unitId, subUnitId).get(payload.commentId);
167
+ return oldComment && (oldComment.updated = !0, oldComment.text = payload.text, oldComment.attachments = payload.attachments, oldComment.updateT = payload.updateT, this._commentUpdate$.next({
166
168
  unitId,
167
169
  subUnitId,
168
170
  type: "update",
169
171
  payload,
170
172
  silent
171
- }), this._refreshCommentsMap$(), !0) : !1;
173
+ })), !0;
172
174
  }
173
175
  updateCommentRef(unitId, subUnitId, payload, silent) {
174
- const { commentMap } = this.ensureMap(unitId, subUnitId), oldComment = commentMap[payload.commentId];
176
+ const oldComment = this._ensureCommentMap(unitId, subUnitId).get(payload.commentId);
175
177
  return oldComment ? (oldComment.ref = payload.ref, this._commentUpdate$.next({
176
178
  unitId,
177
179
  subUnitId,
178
180
  type: "updateRef",
179
181
  payload,
180
- silent
181
- }), this._refreshCommentsMap$(), !0) : !1;
182
+ silent,
183
+ threadId: oldComment.threadId
184
+ }), !0) : !1;
182
185
  }
183
186
  resolveComment(unitId, subUnitId, commentId, resolved) {
184
- const { commentMap } = this.ensureMap(unitId, subUnitId), oldComment = commentMap[commentId];
187
+ const oldComment = this._ensureCommentMap(unitId, subUnitId).get(commentId);
185
188
  return oldComment ? (oldComment.resolved = resolved, this._commentUpdate$.next({
186
189
  unitId,
187
190
  subUnitId,
@@ -190,62 +193,38 @@ let ThreadCommentModel = (_a = class extends Disposable {
190
193
  commentId,
191
194
  resolved
192
195
  }
193
- }), this._refreshCommentsMap$(), !0) : !1;
196
+ }), !0) : !1;
194
197
  }
195
198
  getComment(unitId, subUnitId, commentId) {
196
- const { commentMap } = this.ensureMap(unitId, subUnitId);
197
- return commentMap[commentId];
199
+ return this._ensureCommentMap(unitId, subUnitId).get(commentId);
198
200
  }
199
- getComment$(unitId, subUnitId, commentId) {
200
- return this._commentsMap$.pipe(map((records) => records[unitId][subUnitId][commentId]));
201
+ getRootComment(unitId, subUnitId, threadId) {
202
+ return this._ensureThreadMap(unitId, subUnitId).get(threadId);
201
203
  }
202
- getCommentWithChildren(unitId, subUnitId, commentId) {
203
- var _a4, _b;
204
- const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), current = commentMap[commentId];
205
- if (!current)
206
- return;
207
- const relativeUsers = /* @__PURE__ */ new Set(), root = commentChildrenMap.get(commentId);
204
+ getThread(unitId, subUnitId, threadId) {
205
+ const commentMap = this._ensureCommentMap(unitId, subUnitId), comments = Array.from(commentMap.values()).filter((comment) => comment.threadId === threadId);
206
+ let root;
207
+ const children = [], relativeUsers = /* @__PURE__ */ new Set();
208
+ for (const comment of comments)
209
+ comment.parentId ? children.push(comment) : root = comment, relativeUsers.add(comment.personId);
208
210
  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);
213
- });
214
- }), {
215
- root: current,
216
- children: (_b = root.children) != null ? _b : [],
217
- relativeUsers
211
+ return {
212
+ root,
213
+ children,
214
+ relativeUsers,
215
+ unitId,
216
+ subUnitId,
217
+ threadId
218
218
  };
219
219
  }
220
- deleteComment(unitId, subUnitId, commentId) {
221
- var _a4;
222
- const { commentMap, commentChildrenMap } = this.ensureMap(unitId, subUnitId), current = commentMap[commentId];
223
- if (!current)
224
- return !0;
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);
230
- }
231
- delete commentMap[commentId];
232
- } else {
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,
239
- type: "delete",
240
- payload: {
241
- commentId: child.id,
242
- isRoot: !1,
243
- comment: child
244
- }
245
- });
246
- });
247
- }
248
- return this._commentUpdate$.next({
220
+ getCommentWithChildren(unitId, subUnitId, commentId) {
221
+ const comment = this.getComment(unitId, subUnitId, commentId);
222
+ if (comment)
223
+ return this.getThread(unitId, subUnitId, comment.threadId);
224
+ }
225
+ _deleteComment(unitId, subUnitId, commentId) {
226
+ const commentMap = this._ensureCommentMap(unitId, subUnitId), current = commentMap.get(commentId);
227
+ current && (commentMap.delete(commentId), this._commentUpdate$.next({
249
228
  unitId,
250
229
  subUnitId,
251
230
  type: "delete",
@@ -254,36 +233,52 @@ let ThreadCommentModel = (_a = class extends Disposable {
254
233
  isRoot: !current.parentId,
255
234
  comment: current
256
235
  }
257
- }), this._refreshCommentsMap$(), !0;
236
+ }));
258
237
  }
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))]) : [];
238
+ deleteThread(unitId, subUnitId, threadId) {
239
+ this._ensureThreadMap(unitId, subUnitId).delete(threadId), this._ensureCommentMap(unitId, subUnitId).forEach((comment) => {
240
+ comment.threadId === threadId && this._deleteComment(unitId, subUnitId, comment.id);
241
+ });
242
+ }
243
+ deleteComment(unitId, subUnitId, commentId) {
244
+ const current = this._ensureCommentMap(unitId, subUnitId).get(commentId);
245
+ return current && (current.parentId ? this._deleteComment(unitId, subUnitId, commentId) : this.deleteThread(unitId, subUnitId, current.threadId)), !0;
262
246
  }
263
247
  deleteUnit(unitId) {
264
- const unitMap = this._commentsMap[unitId];
265
- unitMap && Object.entries(unitMap).forEach(([subUnitId, subUnitMap]) => {
266
- Object.values(subUnitMap).forEach((comment) => {
248
+ const unitMap = this._commentsMap.get(unitId);
249
+ unitMap && unitMap.forEach((subUnitMap, subUnitId) => {
250
+ subUnitMap.forEach((comment) => {
267
251
  this.deleteComment(unitId, subUnitId, comment.id);
268
252
  });
269
253
  });
270
254
  }
271
- getRootCommentIds(unitId, subUnitId) {
272
- const commentChildrenMap = this._ensureCommentChildrenMap(unitId, subUnitId);
273
- return Array.from(commentChildrenMap.keys());
255
+ getUnit(unitId) {
256
+ const unitMap = this._threadMap.get(unitId);
257
+ if (!unitMap)
258
+ return [];
259
+ const threads = [];
260
+ return unitMap.forEach((subUnitSet, subUnitId) => {
261
+ subUnitSet.forEach((threadComment, threadId) => {
262
+ const thread = this.getThread(unitId, subUnitId, threadId);
263
+ thread && threads.push(thread);
264
+ });
265
+ }), threads;
274
266
  }
275
267
  getAll() {
276
- return this._commentsMap;
277
- }
278
- getThread(unitId, threadId) {
279
- return this._ensureThreadMap(unitId).get(threadId);
268
+ const all = [];
269
+ return this._commentsMap.forEach((unitMap, unitId) => {
270
+ all.push({
271
+ unitId,
272
+ threads: this.getUnit(unitId)
273
+ });
274
+ }), all;
280
275
  }
281
276
  }, __name(_a, "ThreadCommentModel"), _a);
282
277
  ThreadCommentModel = __decorateClass$2([
283
278
  __decorateParam$2(0, Inject(IThreadCommentDataSourceService)),
284
- __decorateParam$2(1, ICommandService)
279
+ __decorateParam$2(1, Inject(LifecycleService))
285
280
  ], ThreadCommentModel);
286
- var R = /* @__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.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(R || {});
281
+ var _ = /* @__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.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(_ || {});
287
282
  const TC_PLUGIN_NAME = "UNIVER_THREAD_COMMENT_PLUGIN";
288
283
  var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
289
284
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -296,9 +291,14 @@ let ThreadCommentResourceController = (_a2 = class extends Disposable {
296
291
  }
297
292
  _initSnapshot() {
298
293
  const toJson = /* @__PURE__ */ __name((unitID) => {
299
- const map2 = this._threadCommentModel.getUnit(unitID), resultMap = {};
300
- return map2 ? (map2.forEach(([key, v]) => {
301
- resultMap[key] = v;
294
+ const map = this._threadCommentModel.getUnit(unitID), resultMap = {};
295
+ return map ? (map.forEach((info) => {
296
+ var _a4;
297
+ const subUnitComments = (_a4 = resultMap[info.subUnitId]) != null ? _a4 : [];
298
+ subUnitComments.push({
299
+ ...info.root,
300
+ children: info.children
301
+ }), resultMap[info.unitId] = subUnitComments;
302
302
  }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(resultMap, unitID))) : "";
303
303
  }, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
304
304
  if (!json)
@@ -312,7 +312,7 @@ let ThreadCommentResourceController = (_a2 = class extends Disposable {
312
312
  this.disposeWithMe(
313
313
  this._resourceManagerService.registerPluginResource({
314
314
  pluginName: `SHEET_${TC_PLUGIN_NAME}`,
315
- businesses: [R.UNIVER_SHEET, R.UNIVER_DOC],
315
+ businesses: [_.UNIVER_SHEET, _.UNIVER_DOC],
316
316
  toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
317
317
  parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
318
318
  onUnLoad: /* @__PURE__ */ __name((unitID) => {
@@ -1,6 +1,6 @@
1
+ import { IThreadComment } from '../../types/interfaces/i-thread-comment';
1
2
  import { ICommand } from '@univerjs/core';
2
3
  import { IUpdateCommentPayload } from '../mutations/comment.mutation';
3
- import { IThreadComment } from '../../types/interfaces/i-thread-comment';
4
4
  export interface IAddCommentCommandParams {
5
5
  unitId: string;
6
6
  subUnitId: string;
@@ -1,7 +1,7 @@
1
- import { Disposable, ICommandService } from '@univerjs/core';
2
- import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
1
+ import { Nullable, Disposable, LifecycleService } from '@univerjs/core';
3
2
  import { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mutations/comment.mutation';
4
- import { IBaseComment, IThreadComment } from '../types/interfaces/i-thread-comment';
3
+ import { IThreadComment } from '../types/interfaces/i-thread-comment';
4
+ import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
5
5
  export type CommentUpdate = {
6
6
  unitId: string;
7
7
  subUnitId: string;
@@ -23,6 +23,7 @@ export type CommentUpdate = {
23
23
  } | {
24
24
  type: 'updateRef';
25
25
  payload: IUpdateCommentRefPayload;
26
+ threadId: string;
26
27
  } | {
27
28
  type: 'resolve';
28
29
  payload: {
@@ -33,25 +34,26 @@ export type CommentUpdate = {
33
34
  type: 'syncUpdate';
34
35
  payload: IThreadComment;
35
36
  });
37
+ export interface IThreadInfo {
38
+ unitId: string;
39
+ subUnitId: string;
40
+ threadId: string;
41
+ root: IThreadComment;
42
+ children: IThreadComment[];
43
+ relativeUsers: Set<string>;
44
+ }
36
45
  export declare class ThreadCommentModel extends Disposable {
37
46
  private readonly _dataSourceService;
38
- private readonly _commandService;
47
+ private readonly _lifecycleService;
39
48
  private _commentsMap;
40
- private _commentsTreeMap;
41
49
  private _threadMap;
42
50
  private _commentUpdate$;
43
- private _commentsMap$;
44
51
  commentUpdate$: import('rxjs').Observable<CommentUpdate>;
45
- commentMap$: import('rxjs').Observable<Record<string, Record<string, Record<string, IThreadComment>>>>;
46
- constructor(_dataSourceService: IThreadCommentDataSourceService, _commandService: ICommandService);
52
+ private _tasks;
53
+ constructor(_dataSourceService: IThreadCommentDataSourceService, _lifecycleService: LifecycleService);
47
54
  private _ensureCommentMap;
48
- private _ensureCommentChildrenMap;
55
+ ensureMap(unitId: string, subUnitId: string): Map<string, IThreadComment>;
49
56
  private _ensureThreadMap;
50
- private _refreshCommentsMap$;
51
- ensureMap(unitId: string, subUnitId: string): {
52
- commentMap: Record<string, IThreadComment>;
53
- commentChildrenMap: Map<string, IThreadComment>;
54
- };
55
57
  private _replaceComment;
56
58
  syncThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<void>;
57
59
  addComment(unitId: string, subUnitId: string, origin: IThreadComment, shouldSync?: boolean): boolean;
@@ -59,16 +61,16 @@ export declare class ThreadCommentModel extends Disposable {
59
61
  updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload, silent?: boolean): boolean;
60
62
  resolveComment(unitId: string, subUnitId: string, commentId: string, resolved: boolean): boolean;
61
63
  getComment(unitId: string, subUnitId: string, commentId: string): IThreadComment | undefined;
62
- getComment$(unitId: string, subUnitId: string, commentId: string): import('rxjs').Observable<IThreadComment>;
63
- getCommentWithChildren(unitId: string, subUnitId: string, commentId: string): {
64
- root: IThreadComment;
65
- children: IBaseComment[];
66
- relativeUsers: Set<string>;
67
- } | undefined;
64
+ getRootComment(unitId: string, subUnitId: string, threadId: string): IThreadComment | undefined;
65
+ getThread(unitId: string, subUnitId: string, threadId: string): Nullable<IThreadInfo>;
66
+ getCommentWithChildren(unitId: string, subUnitId: string, commentId: string): Nullable<IThreadInfo>;
67
+ private _deleteComment;
68
+ deleteThread(unitId: string, subUnitId: string, threadId: string): void;
68
69
  deleteComment(unitId: string, subUnitId: string, commentId: string): boolean;
69
- getUnit(unitId: string): (readonly [string, IThreadComment[]])[];
70
70
  deleteUnit(unitId: string): void;
71
- getRootCommentIds(unitId: string, subUnitId: string): string[];
72
- getAll(): Record<string, Record<string, Record<string, IThreadComment>>>;
73
- getThread(unitId: string, threadId: string): IThreadComment | undefined;
71
+ getUnit(unitId: string): IThreadInfo[];
72
+ getAll(): {
73
+ unitId: string;
74
+ threads: IThreadInfo[];
75
+ }[];
74
76
  }
@@ -1,4 +1,4 @@
1
- import { Disposable, Nullable } from '@univerjs/core';
1
+ import { Nullable, Disposable } from '@univerjs/core';
2
2
  import { IBaseComment, IThreadComment } from '../types/interfaces/i-thread-comment';
3
3
  export type ThreadCommentJSON = {
4
4
  id: string;
@@ -50,7 +50,7 @@ export interface IThreadCommentDataSourceService {
50
50
  deleteComment: (unitId: string, subUnitId: string, threadId: string, commentId: string) => Promise<Success>;
51
51
  saveToSnapshot: (unitComments: Record<string, IThreadComment[]>, unitId: string) => Record<string, ThreadCommentJSON[]>;
52
52
  getThreadComment: (unitId: string, subUnitId: string, threadId: string) => Promise<Nullable<IBaseComment>>;
53
- listThreadComments: (unitId: string, subUnitId: string, threadId: string[]) => Promise<IBaseComment[]>;
53
+ listThreadComments: (unitId: string, subUnitId: string, threadId: string[]) => Promise<IBaseComment[] | false>;
54
54
  }
55
55
  /**
56
56
  * Preserve for import async comment system
@@ -66,7 +66,7 @@ export declare class ThreadCommentDataSourceService extends Disposable implement
66
66
  updateComment(comment: IThreadComment): Promise<boolean>;
67
67
  resolveComment(comment: IThreadComment): Promise<boolean>;
68
68
  deleteComment(unitId: string, subUnitId: string, threadId: string, commentId: string): Promise<boolean>;
69
- listThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<IBaseComment[]>;
69
+ listThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<false | IBaseComment[]>;
70
70
  saveToSnapshot(unitComments: Record<string, IThreadComment[]>, unitId: string): Record<string, ThreadCommentJSON[]>;
71
71
  }
72
72
  export declare const IThreadCommentDataSourceService: import('@wendellhu/redi').IdentifierDecorator<IThreadCommentDataSourceService>;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverThreadComment={},global.UniverCore,global.rxjs))})(this,function(exports2,core,rxjs){"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 R=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(R||{});const TC_PLUGIN_NAME="UNIVER_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:[R.UNIVER_SHEET,R.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([__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})}},PLUGIN_CONFIG_KEY="thread-comment.config",defaultPluginConfig={};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=defaultPluginConfig,_injector,_commandService,_configService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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)}),this._injector.get(exports2.ThreadCommentResourceController)}},__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),__decorateParam(3,core.IConfigService)],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"})});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverThreadComment={},global.UniverCore,global.rxjs))})(this,function(exports2,core,rxjs){"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){var _a2;return this._dataSource?this._dataSource.addComment(comment):{...comment,threadId:(_a2=comment.threadId)!=null?_a2:comment.id}}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):!1}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,_lifecycleService){super();__publicField(this,"_commentsMap",new Map);__publicField(this,"_threadMap",new Map);__publicField(this,"_commentUpdate$",new rxjs.Subject);__publicField(this,"commentUpdate$",this._commentUpdate$.asObservable());__publicField(this,"_tasks",[]);this._dataSourceService=_dataSourceService,this._lifecycleService=_lifecycleService,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(stage=>{const taskMap=new Map;stage===core.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId,subUnitId,threadIds})=>{let unitMap=taskMap.get(unitId);unitMap||(unitMap=new Map,taskMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);subUnitMap||(subUnitMap=new Set,unitMap.set(subUnitId,subUnitMap));for(const threadId of threadIds)subUnitMap.add(threadId)}),this._tasks=[],taskMap.forEach((subUnitMap,unitId)=>{subUnitMap.forEach((threadIds,subUnitId)=>{this.syncThreadComments(unitId,subUnitId,Array.from(threadIds))})}))}))}_ensureCommentMap(unitId,subUnitId){let unitMap=this._commentsMap.get(unitId);unitMap||(unitMap=new Map,this._commentsMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}ensureMap(unitId,subUnitId){return this._ensureCommentMap(unitId,subUnitId)}_ensureThreadMap(unitId,subUnitId){let unitMap=this._threadMap.get(unitId);unitMap||(unitMap=new Map,this._threadMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_replaceComment(unitId,subUnitId,comment){const commentMap=this._ensureCommentMap(unitId,subUnitId),currentComment=commentMap.get(comment.id);if(currentComment){const{children,...rest}=comment,newComment={...rest,ref:currentComment.ref};commentMap.set(comment.id,newComment),children==null||children.forEach(child=>{commentMap.set(child.id,{...child,ref:""})}),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){if(this._lifecycleService.stage<core.LifecycleStages.Rendered){this._tasks.push({unitId,subUnitId,threadIds});return}const threadMap=this._ensureThreadMap(unitId,subUnitId),commentMap=this._ensureCommentMap(unitId,subUnitId),comments=await this._dataSourceService.listThreadComments(unitId,subUnitId,threadIds);if(!comments)return;const deleteThreads=new Set(threadIds);comments.forEach(comment=>{this._replaceComment(unitId,subUnitId,comment),deleteThreads.delete(comment.threadId)}),deleteThreads.forEach(id=>{threadMap.delete(id),commentMap.forEach((comment,commentId)=>{comment.threadId===id&&commentMap.delete(commentId)})})}addComment(unitId,subUnitId,origin,shouldSync){const commentMap=this._ensureCommentMap(unitId,subUnitId),{parentId,children=[],...rest}=origin,comment={...rest,parentId:parentId===origin.id?void 0:parentId},addCommentItem=__name(item=>{commentMap.set(item.id,item),this._commentUpdate$.next({unitId,subUnitId,type:"add",payload:item,isRoot:!item.parentId})},"addCommentItem");addCommentItem(comment);const threadMap=this._ensureThreadMap(unitId,subUnitId);if(!comment.parentId){threadMap.set(comment.threadId,comment);for(const child of children)addCommentItem(child)}return shouldSync&&this.syncThreadComments(unitId,subUnitId,[comment.threadId]),!0}updateComment(unitId,subUnitId,payload,silent){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(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})),!0}updateCommentRef(unitId,subUnitId,payload,silent){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(payload.commentId);return oldComment?(oldComment.ref=payload.ref,this._commentUpdate$.next({unitId,subUnitId,type:"updateRef",payload,silent,threadId:oldComment.threadId}),!0):!1}resolveComment(unitId,subUnitId,commentId,resolved){const oldComment=this._ensureCommentMap(unitId,subUnitId).get(commentId);return oldComment?(oldComment.resolved=resolved,this._commentUpdate$.next({unitId,subUnitId,type:"resolve",payload:{commentId,resolved}}),!0):!1}getComment(unitId,subUnitId,commentId){return this._ensureCommentMap(unitId,subUnitId).get(commentId)}getRootComment(unitId,subUnitId,threadId){return this._ensureThreadMap(unitId,subUnitId).get(threadId)}getThread(unitId,subUnitId,threadId){const commentMap=this._ensureCommentMap(unitId,subUnitId),comments=Array.from(commentMap.values()).filter(comment=>comment.threadId===threadId);let root;const children=[],relativeUsers=new Set;for(const comment of comments)comment.parentId?children.push(comment):root=comment,relativeUsers.add(comment.personId);if(root)return{root,children,relativeUsers,unitId,subUnitId,threadId}}getCommentWithChildren(unitId,subUnitId,commentId){const comment=this.getComment(unitId,subUnitId,commentId);if(comment)return this.getThread(unitId,subUnitId,comment.threadId)}_deleteComment(unitId,subUnitId,commentId){const commentMap=this._ensureCommentMap(unitId,subUnitId),current=commentMap.get(commentId);current&&(commentMap.delete(commentId),this._commentUpdate$.next({unitId,subUnitId,type:"delete",payload:{commentId,isRoot:!current.parentId,comment:current}}))}deleteThread(unitId,subUnitId,threadId){this._ensureThreadMap(unitId,subUnitId).delete(threadId),this._ensureCommentMap(unitId,subUnitId).forEach(comment=>{comment.threadId===threadId&&this._deleteComment(unitId,subUnitId,comment.id)})}deleteComment(unitId,subUnitId,commentId){const current=this._ensureCommentMap(unitId,subUnitId).get(commentId);return current&&(current.parentId?this._deleteComment(unitId,subUnitId,commentId):this.deleteThread(unitId,subUnitId,current.threadId)),!0}deleteUnit(unitId){const unitMap=this._commentsMap.get(unitId);unitMap&&unitMap.forEach((subUnitMap,subUnitId)=>{subUnitMap.forEach(comment=>{this.deleteComment(unitId,subUnitId,comment.id)})})}getUnit(unitId){const unitMap=this._threadMap.get(unitId);if(!unitMap)return[];const threads=[];return unitMap.forEach((subUnitSet,subUnitId)=>{subUnitSet.forEach((threadComment,threadId)=>{const thread=this.getThread(unitId,subUnitId,threadId);thread&&threads.push(thread)})}),threads}getAll(){const all=[];return this._commentsMap.forEach((unitMap,unitId)=>{all.push({unitId,threads:this.getUnit(unitId)})}),all}},__name(_a,"ThreadCommentModel"),_a),exports2.ThreadCommentModel=__decorateClass$2([__decorateParam$2(0,core.Inject(IThreadCommentDataSourceService)),__decorateParam$2(1,core.Inject(core.LifecycleService))],exports2.ThreadCommentModel);var _=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(_||{});const TC_PLUGIN_NAME="UNIVER_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(info=>{var _a2;const subUnitComments=(_a2=resultMap[info.subUnitId])!=null?_a2:[];subUnitComments.push({...info.root,children:info.children}),resultMap[info.unitId]=subUnitComments}),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:[_.UNIVER_SHEET,_.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([__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})}},PLUGIN_CONFIG_KEY="thread-comment.config",defaultPluginConfig={};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=defaultPluginConfig,_injector,_commandService,_configService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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)}),this._injector.get(exports2.ThreadCommentResourceController)}},__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),__decorateParam(3,core.IConfigService)],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.4.1",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "description": "Univer thread comment core plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -47,15 +47,15 @@
47
47
  "rxjs": ">=7.0.0"
48
48
  },
49
49
  "dependencies": {
50
- "@univerjs/protocol": "0.1.39-alpha.30",
51
- "@univerjs/core": "0.4.1"
50
+ "@univerjs/protocol": "0.1.39-alpha.38",
51
+ "@univerjs/core": "0.4.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "rxjs": "^7.8.1",
55
55
  "typescript": "^5.6.3",
56
56
  "vite": "^5.4.8",
57
57
  "vitest": "^2.1.2",
58
- "@univerjs-infra/shared": "0.4.1"
58
+ "@univerjs-infra/shared": "0.4.2"
59
59
  },
60
60
  "univerSpace": {
61
61
  ".": {