@univerjs/thread-comment 0.4.2 → 0.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +395 -392
- package/lib/types/common/utils.d.ts +16 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
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){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;
|
|
1
|
+
"use strict";var x=Object.defineProperty;var A=(m,a,e)=>a in m?x(m,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[a]=e;var l=(m,a,e)=>A(m,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),j=require("rxjs");class E extends d.Disposable{constructor(){super();l(this,"_dataSource",null);l(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const r=e[o];n[o]=r.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const p=d.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(m,a,e,t)=>{for(var n=t>1?void 0:t?V(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&L(a,e,n),n},I=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new j.Subject);l(this,"commentUpdate$",this._commentUpdate$.asObservable());l(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:r,subUnitId:s,threadIds:c})=>{let i=o.get(r);i||(i=new Map,o.set(r,i));let h=i.get(s);h||(h=new Set,i.set(s,h));for(const u of c)h.add(u)}),this._tasks=[],o.forEach((r,s)=>{r.forEach((c,i)=>{this.syncThreadComments(s,i,Array.from(c))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n.id);if(r){const{children:s,...c}=n,i={...c,ref:r.ref};o.set(n.id,i),s==null||s.forEach(h=>{o.set(h.id,{...h,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:i}),!!n.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),r=this._ensureCommentMap(e,t),s=await this._dataSourceService.listThreadComments(e,t,n);if(!s)return;const c=new Set(n);s.forEach(i=>{this._replaceComment(e,t,i),c.delete(i.threadId)}),c.forEach(i=>{o.delete(i),r.forEach((h,u)=>{h.threadId===i&&r.delete(u)})})}addComment(e,t,n,o){const r=this._ensureCommentMap(e,t),{parentId:s,children:c=[],...i}=n,h={...i,parentId:s===n.id?void 0:s};h.threadId||(h.threadId=h.parentId||h.id);const u=C=>{r.set(C.id,C),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:C,isRoot:!C.parentId})};u(h);const N=this._ensureThreadMap(e,t);if(!h.parentId){N.set(h.threadId,h);for(const C of c)u(C)}return o&&this.syncThreadComments(e,t,[h.threadId]),!0}updateComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s&&(s.updated=!0,s.text=n.text,s.attachments=n.attachments,s.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s?(s.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:s.threadId}),!0):!1}resolveComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n);return s?(s.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),r=Array.from(o.values()).filter(h=>h.threadId===n);let s;const c=[],i=new Set;for(const h of r)h.parentId?c.push(h):s=h,i.add(h.personId);if(s)return{root:s,children:c,relativeUsers:i,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n);r&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!r.parentId,comment:r}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(s=>{s.threadId===n&&this._deleteComment(e,t,s.id)})}deleteComment(e,t,n){const r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(r=>{this.deleteComment(e,o,r.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,r)=>{o.forEach((s,c)=>{const i=this.getThread(e,r,c);i&&n.push(i)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};exports.ThreadCommentModel=W([I(0,d.Inject(p)),I(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var v=(m=>(m[m.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",m[m.UNIVER_DOC=1]="UNIVER_DOC",m[m.UNIVER_SHEET=2]="UNIVER_SHEET",m[m.UNIVER_SLIDE=3]="UNIVER_SLIDE",m[m.UNIVER_PROJECT=4]="UNIVER_PROJECT",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(m,a,e,t)=>{for(var n=t>1?void 0:t?J(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&b(a,e,n),n},_=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(a,e,t){super(),this._resourceManagerService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const a=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(r=>{var c;const s=(c=o[r.subUnitId])!=null?c:[];s.push({...r.root,children:r.children}),o[r.subUnitId]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>a(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const r=n[o];r.forEach(s=>{this._threadCommentModel.addComment(t,o,s)}),this._threadCommentModel.syncThreadComments(t,o,r.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=G([_(0,d.IResourceManagerService),_(1,d.Inject(exports.ThreadCommentModel)),_(2,p)],exports.ThreadCommentResourceController);const g={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,a,e){if(!a)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=a,c=s||(e==null?void 0:e.fromChangeset)&&!r.parentId;return t.addComment(n,o,r,c)}},y={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateComment(t,n,o,r)}},R={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=a;return e.resolveComment(t,n,r,o)}},M={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=a;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(d.ICommandService),t=m.get(p),{comment:n}=a,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:g.id,params:{...a,comment:o}};return s?await e.executeCommand(c.id,c.params):e.executeCommand(c.id,c.params,{onlyLocal:!r})}},D={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,payload:n}=a,o=m.get(d.ICommandService),r=m.get(exports.ThreadCommentModel),s=m.get(p),c=s.syncUpdateMutationToColla,i=r.getComment(e,t,n.commentId);if(!i)return!1;const{children:h,...u}=i;if(!await s.updateComment({...u,...n}))return!1;const C={id:y.id,params:a};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},P={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=a,r=m.get(p),c=m.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:m.get(d.ICommandService).executeCommand(U.id,a,{onlyLocal:!i})}},w={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(p),n=m.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=a,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:M.id,params:a};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},$={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(d.ICommandService),n=m.get(p),{unitId:o,subUnitId:r,commentId:s}=a,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(M.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},H="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(m,a,e,t)=>{for(var n=t>1?void 0:t?B(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&K(a,e,n),n},T=(m,a)=>(e,t)=>a(e,t,m),f;exports.UniverThreadCommentPlugin=(f=class extends d.Plugin{constructor(a=Y,e,t,n){super(),this._config=a,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(H,o)}onStarting(){var a;d.mergeOverrideWithDependencies([[p,{useClass:E}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(a=this._config)==null?void 0:a.overrides).forEach(e=>{this._injector.add(e)}),[O,D,w,P,$,g,y,R,M,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(f,"pluginName",S),l(f,"type",d.UniverInstanceType.UNIVER_UNKNOWN),f);exports.UniverThreadCommentPlugin=q([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function Z(){return d.dayjs().format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=O;exports.AddCommentMutation=g;exports.DeleteCommentCommand=w;exports.DeleteCommentMutation=M;exports.DeleteCommentTreeCommand=$;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=U;exports.TC_PLUGIN_NAME=S;exports.ThreadCommentDataSourceService=E;exports.UpdateCommentCommand=D;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=R;exports.getDT=Z;
|
package/lib/es/index.js
CHANGED
|
@@ -1,529 +1,532 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const _ThreadCommentDataSourceService = class _ThreadCommentDataSourceService extends Disposable {
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var A = (s, t, e) => t in s ? x(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var u = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createIdentifier as j, Disposable as U, Inject as v, LifecycleService as L, LifecycleStages as O, IResourceManagerService as V, CommandType as l, ICommandService as f, Plugin as W, UniverInstanceType as J, mergeOverrideWithDependencies as H, Injector as G, IConfigService as b, dayjs as Y } from "@univerjs/core";
|
|
5
|
+
import { Subject as K } from "rxjs";
|
|
6
|
+
class B extends U {
|
|
8
7
|
constructor() {
|
|
9
8
|
super();
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
u(this, "_dataSource", null);
|
|
10
|
+
u(this, "syncUpdateMutationToColla", !0);
|
|
12
11
|
}
|
|
13
|
-
set dataSource(
|
|
14
|
-
this._dataSource =
|
|
12
|
+
set dataSource(e) {
|
|
13
|
+
this._dataSource = e;
|
|
15
14
|
}
|
|
16
15
|
get dataSource() {
|
|
17
16
|
return this._dataSource;
|
|
18
17
|
}
|
|
19
|
-
async getThreadComment(
|
|
20
|
-
return this._dataSource ? (await this._dataSource.listComments(
|
|
18
|
+
async getThreadComment(e, n, o) {
|
|
19
|
+
return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
|
|
21
20
|
}
|
|
22
|
-
async addComment(
|
|
23
|
-
var
|
|
24
|
-
return this._dataSource ? this._dataSource.addComment(
|
|
21
|
+
async addComment(e) {
|
|
22
|
+
var n;
|
|
23
|
+
return this._dataSource ? this._dataSource.addComment(e) : { ...e, threadId: (n = e.threadId) != null ? n : e.id };
|
|
25
24
|
}
|
|
26
|
-
async updateComment(
|
|
27
|
-
return this._dataSource ? this._dataSource.updateComment(
|
|
25
|
+
async updateComment(e) {
|
|
26
|
+
return this._dataSource ? this._dataSource.updateComment(e) : !0;
|
|
28
27
|
}
|
|
29
|
-
async resolveComment(
|
|
30
|
-
return this._dataSource ? this._dataSource.resolveComment(
|
|
28
|
+
async resolveComment(e) {
|
|
29
|
+
return this._dataSource ? this._dataSource.resolveComment(e) : !0;
|
|
31
30
|
}
|
|
32
|
-
async deleteComment(
|
|
33
|
-
return this._dataSource ? this._dataSource.deleteComment(
|
|
31
|
+
async deleteComment(e, n, o, r) {
|
|
32
|
+
return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : !0;
|
|
34
33
|
}
|
|
35
|
-
async listThreadComments(
|
|
36
|
-
return this.dataSource ? this.dataSource.listComments(
|
|
34
|
+
async listThreadComments(e, n, o) {
|
|
35
|
+
return this.dataSource ? this.dataSource.listComments(e, n, o) : !1;
|
|
37
36
|
}
|
|
38
|
-
saveToSnapshot(
|
|
37
|
+
saveToSnapshot(e, n) {
|
|
39
38
|
if (this._dataSource) {
|
|
40
|
-
const
|
|
41
|
-
return Object.keys(
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
}),
|
|
39
|
+
const o = {};
|
|
40
|
+
return Object.keys(e).forEach((r) => {
|
|
41
|
+
const a = e[r];
|
|
42
|
+
o[r] = a.map(this.dataSource.saveCommentToSnapshot);
|
|
43
|
+
}), o;
|
|
45
44
|
}
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let ThreadCommentModel = (_a = class extends Disposable {
|
|
58
|
-
constructor(_dataSourceService, _lifecycleService) {
|
|
45
|
+
return e;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const p = j("univer.thread-comment.data-source-service");
|
|
49
|
+
var Z = Object.defineProperty, F = Object.getOwnPropertyDescriptor, q = (s, t, e, n) => {
|
|
50
|
+
for (var o = n > 1 ? void 0 : n ? F(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
51
|
+
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
52
|
+
return n && o && Z(t, e, o), o;
|
|
53
|
+
}, I = (s, t) => (e, n) => t(e, n, s);
|
|
54
|
+
let i = class extends U {
|
|
55
|
+
constructor(t, e) {
|
|
59
56
|
super();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this._dataSourceService =
|
|
57
|
+
u(this, "_commentsMap", /* @__PURE__ */ new Map());
|
|
58
|
+
u(this, "_threadMap", /* @__PURE__ */ new Map());
|
|
59
|
+
u(this, "_commentUpdate$", new K());
|
|
60
|
+
u(this, "commentUpdate$", this._commentUpdate$.asObservable());
|
|
61
|
+
u(this, "_tasks", []);
|
|
62
|
+
this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
|
|
66
63
|
this._commentUpdate$.complete();
|
|
67
|
-
}), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
for (const
|
|
75
|
-
|
|
76
|
-
}), this._tasks = [],
|
|
77
|
-
|
|
78
|
-
this.syncThreadComments(
|
|
64
|
+
}), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
|
|
65
|
+
const o = /* @__PURE__ */ new Map();
|
|
66
|
+
n === O.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => {
|
|
67
|
+
let m = o.get(r);
|
|
68
|
+
m || (m = /* @__PURE__ */ new Map(), o.set(r, m));
|
|
69
|
+
let c = m.get(a);
|
|
70
|
+
c || (c = /* @__PURE__ */ new Set(), m.set(a, c));
|
|
71
|
+
for (const h of d)
|
|
72
|
+
c.add(h);
|
|
73
|
+
}), this._tasks = [], o.forEach((r, a) => {
|
|
74
|
+
r.forEach((d, m) => {
|
|
75
|
+
this.syncThreadComments(a, m, Array.from(d));
|
|
79
76
|
});
|
|
80
77
|
}));
|
|
81
78
|
}));
|
|
82
79
|
}
|
|
83
|
-
_ensureCommentMap(
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
ensureMap(
|
|
90
|
-
return this._ensureCommentMap(
|
|
91
|
-
}
|
|
92
|
-
_ensureThreadMap(
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
let
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
_replaceComment(
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const { children, ...
|
|
102
|
-
...
|
|
103
|
-
ref:
|
|
80
|
+
_ensureCommentMap(t, e) {
|
|
81
|
+
let n = this._commentsMap.get(t);
|
|
82
|
+
n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
|
|
83
|
+
let o = n.get(e);
|
|
84
|
+
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
|
|
85
|
+
}
|
|
86
|
+
ensureMap(t, e) {
|
|
87
|
+
return this._ensureCommentMap(t, e);
|
|
88
|
+
}
|
|
89
|
+
_ensureThreadMap(t, e) {
|
|
90
|
+
let n = this._threadMap.get(t);
|
|
91
|
+
n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
|
|
92
|
+
let o = n.get(e);
|
|
93
|
+
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
|
|
94
|
+
}
|
|
95
|
+
_replaceComment(t, e, n) {
|
|
96
|
+
const o = this._ensureCommentMap(t, e), r = o.get(n.id);
|
|
97
|
+
if (r) {
|
|
98
|
+
const { children: a, ...d } = n, m = {
|
|
99
|
+
...d,
|
|
100
|
+
ref: r.ref
|
|
104
101
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
...
|
|
102
|
+
o.set(n.id, m), a == null || a.forEach((c) => {
|
|
103
|
+
o.set(c.id, {
|
|
104
|
+
...c,
|
|
108
105
|
ref: ""
|
|
109
106
|
});
|
|
110
107
|
}), this._commentUpdate$.next({
|
|
111
|
-
unitId,
|
|
112
|
-
subUnitId,
|
|
108
|
+
unitId: t,
|
|
109
|
+
subUnitId: e,
|
|
113
110
|
type: "syncUpdate",
|
|
114
|
-
payload:
|
|
115
|
-
}), !!
|
|
116
|
-
unitId,
|
|
117
|
-
subUnitId,
|
|
111
|
+
payload: m
|
|
112
|
+
}), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
|
|
113
|
+
unitId: t,
|
|
114
|
+
subUnitId: e,
|
|
118
115
|
type: "resolve",
|
|
119
116
|
payload: {
|
|
120
|
-
commentId:
|
|
121
|
-
resolved: !!
|
|
117
|
+
commentId: n.id,
|
|
118
|
+
resolved: !!n.resolved
|
|
122
119
|
}
|
|
123
120
|
});
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
|
-
async syncThreadComments(
|
|
127
|
-
if (this._lifecycleService.stage <
|
|
128
|
-
this._tasks.push({ unitId, subUnitId, threadIds });
|
|
123
|
+
async syncThreadComments(t, e, n) {
|
|
124
|
+
if (this._lifecycleService.stage < O.Rendered) {
|
|
125
|
+
this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
|
|
129
126
|
return;
|
|
130
127
|
}
|
|
131
|
-
const
|
|
132
|
-
if (!
|
|
128
|
+
const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
|
|
129
|
+
if (!a)
|
|
133
130
|
return;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
this._replaceComment(
|
|
137
|
-
}),
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
const d = new Set(n);
|
|
132
|
+
a.forEach((m) => {
|
|
133
|
+
this._replaceComment(t, e, m), d.delete(m.threadId);
|
|
134
|
+
}), d.forEach((m) => {
|
|
135
|
+
o.delete(m), r.forEach((c, h) => {
|
|
136
|
+
c.threadId === m && r.delete(h);
|
|
140
137
|
});
|
|
141
138
|
});
|
|
142
139
|
}
|
|
143
|
-
addComment(
|
|
144
|
-
const
|
|
145
|
-
...
|
|
146
|
-
parentId:
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
140
|
+
addComment(t, e, n, o) {
|
|
141
|
+
const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = {
|
|
142
|
+
...m,
|
|
143
|
+
parentId: a === n.id ? void 0 : a
|
|
144
|
+
};
|
|
145
|
+
c.threadId || (c.threadId = c.parentId || c.id);
|
|
146
|
+
const h = (C) => {
|
|
147
|
+
r.set(C.id, C), this._commentUpdate$.next({
|
|
148
|
+
unitId: t,
|
|
149
|
+
subUnitId: e,
|
|
151
150
|
type: "add",
|
|
152
|
-
payload:
|
|
153
|
-
isRoot: !
|
|
151
|
+
payload: C,
|
|
152
|
+
isRoot: !C.parentId
|
|
154
153
|
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
|
|
160
|
-
for (const
|
|
161
|
-
|
|
154
|
+
};
|
|
155
|
+
h(c);
|
|
156
|
+
const _ = this._ensureThreadMap(t, e);
|
|
157
|
+
if (!c.parentId) {
|
|
158
|
+
_.set(c.threadId, c);
|
|
159
|
+
for (const C of d)
|
|
160
|
+
h(C);
|
|
162
161
|
}
|
|
163
|
-
return
|
|
162
|
+
return o && this.syncThreadComments(t, e, [c.threadId]), !0;
|
|
164
163
|
}
|
|
165
|
-
updateComment(
|
|
166
|
-
const
|
|
167
|
-
return
|
|
168
|
-
unitId,
|
|
169
|
-
subUnitId,
|
|
164
|
+
updateComment(t, e, n, o) {
|
|
165
|
+
const a = this._ensureCommentMap(t, e).get(n.commentId);
|
|
166
|
+
return a && (a.updated = !0, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({
|
|
167
|
+
unitId: t,
|
|
168
|
+
subUnitId: e,
|
|
170
169
|
type: "update",
|
|
171
|
-
payload,
|
|
172
|
-
silent
|
|
170
|
+
payload: n,
|
|
171
|
+
silent: o
|
|
173
172
|
})), !0;
|
|
174
173
|
}
|
|
175
|
-
updateCommentRef(
|
|
176
|
-
const
|
|
177
|
-
return
|
|
178
|
-
unitId,
|
|
179
|
-
subUnitId,
|
|
174
|
+
updateCommentRef(t, e, n, o) {
|
|
175
|
+
const a = this._ensureCommentMap(t, e).get(n.commentId);
|
|
176
|
+
return a ? (a.ref = n.ref, this._commentUpdate$.next({
|
|
177
|
+
unitId: t,
|
|
178
|
+
subUnitId: e,
|
|
180
179
|
type: "updateRef",
|
|
181
|
-
payload,
|
|
182
|
-
silent,
|
|
183
|
-
threadId:
|
|
180
|
+
payload: n,
|
|
181
|
+
silent: o,
|
|
182
|
+
threadId: a.threadId
|
|
184
183
|
}), !0) : !1;
|
|
185
184
|
}
|
|
186
|
-
resolveComment(
|
|
187
|
-
const
|
|
188
|
-
return
|
|
189
|
-
unitId,
|
|
190
|
-
subUnitId,
|
|
185
|
+
resolveComment(t, e, n, o) {
|
|
186
|
+
const a = this._ensureCommentMap(t, e).get(n);
|
|
187
|
+
return a ? (a.resolved = o, this._commentUpdate$.next({
|
|
188
|
+
unitId: t,
|
|
189
|
+
subUnitId: e,
|
|
191
190
|
type: "resolve",
|
|
192
191
|
payload: {
|
|
193
|
-
commentId,
|
|
194
|
-
resolved
|
|
192
|
+
commentId: n,
|
|
193
|
+
resolved: o
|
|
195
194
|
}
|
|
196
195
|
}), !0) : !1;
|
|
197
196
|
}
|
|
198
|
-
getComment(
|
|
199
|
-
return this._ensureCommentMap(
|
|
197
|
+
getComment(t, e, n) {
|
|
198
|
+
return this._ensureCommentMap(t, e).get(n);
|
|
200
199
|
}
|
|
201
|
-
getRootComment(
|
|
202
|
-
return this._ensureThreadMap(
|
|
200
|
+
getRootComment(t, e, n) {
|
|
201
|
+
return this._ensureThreadMap(t, e).get(n);
|
|
203
202
|
}
|
|
204
|
-
getThread(
|
|
205
|
-
const
|
|
206
|
-
let
|
|
207
|
-
const
|
|
208
|
-
for (const
|
|
209
|
-
|
|
210
|
-
if (
|
|
203
|
+
getThread(t, e, n) {
|
|
204
|
+
const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n);
|
|
205
|
+
let a;
|
|
206
|
+
const d = [], m = /* @__PURE__ */ new Set();
|
|
207
|
+
for (const c of r)
|
|
208
|
+
c.parentId ? d.push(c) : a = c, m.add(c.personId);
|
|
209
|
+
if (a)
|
|
211
210
|
return {
|
|
212
|
-
root,
|
|
213
|
-
children,
|
|
214
|
-
relativeUsers,
|
|
215
|
-
unitId,
|
|
216
|
-
subUnitId,
|
|
217
|
-
threadId
|
|
211
|
+
root: a,
|
|
212
|
+
children: d,
|
|
213
|
+
relativeUsers: m,
|
|
214
|
+
unitId: t,
|
|
215
|
+
subUnitId: e,
|
|
216
|
+
threadId: n
|
|
218
217
|
};
|
|
219
218
|
}
|
|
220
|
-
getCommentWithChildren(
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
return this.getThread(
|
|
219
|
+
getCommentWithChildren(t, e, n) {
|
|
220
|
+
const o = this.getComment(t, e, n);
|
|
221
|
+
if (o)
|
|
222
|
+
return this.getThread(t, e, o.threadId);
|
|
224
223
|
}
|
|
225
|
-
_deleteComment(
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
unitId,
|
|
229
|
-
subUnitId,
|
|
224
|
+
_deleteComment(t, e, n) {
|
|
225
|
+
const o = this._ensureCommentMap(t, e), r = o.get(n);
|
|
226
|
+
r && (o.delete(n), this._commentUpdate$.next({
|
|
227
|
+
unitId: t,
|
|
228
|
+
subUnitId: e,
|
|
230
229
|
type: "delete",
|
|
231
230
|
payload: {
|
|
232
|
-
commentId,
|
|
233
|
-
isRoot: !
|
|
234
|
-
comment:
|
|
231
|
+
commentId: n,
|
|
232
|
+
isRoot: !r.parentId,
|
|
233
|
+
comment: r
|
|
235
234
|
}
|
|
236
235
|
}));
|
|
237
236
|
}
|
|
238
|
-
deleteThread(
|
|
239
|
-
this._ensureThreadMap(
|
|
240
|
-
|
|
237
|
+
deleteThread(t, e, n) {
|
|
238
|
+
this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
|
|
239
|
+
a.threadId === n && this._deleteComment(t, e, a.id);
|
|
241
240
|
});
|
|
242
241
|
}
|
|
243
|
-
deleteComment(
|
|
244
|
-
const
|
|
245
|
-
return
|
|
242
|
+
deleteComment(t, e, n) {
|
|
243
|
+
const r = this._ensureCommentMap(t, e).get(n);
|
|
244
|
+
return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), !0;
|
|
246
245
|
}
|
|
247
|
-
deleteUnit(
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
this.deleteComment(
|
|
246
|
+
deleteUnit(t) {
|
|
247
|
+
const e = this._commentsMap.get(t);
|
|
248
|
+
e && e.forEach((n, o) => {
|
|
249
|
+
n.forEach((r) => {
|
|
250
|
+
this.deleteComment(t, o, r.id);
|
|
252
251
|
});
|
|
253
252
|
});
|
|
254
253
|
}
|
|
255
|
-
getUnit(
|
|
256
|
-
const
|
|
257
|
-
if (!
|
|
254
|
+
getUnit(t) {
|
|
255
|
+
const e = this._threadMap.get(t);
|
|
256
|
+
if (!e)
|
|
258
257
|
return [];
|
|
259
|
-
const
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
258
|
+
const n = [];
|
|
259
|
+
return e.forEach((o, r) => {
|
|
260
|
+
o.forEach((a, d) => {
|
|
261
|
+
const m = this.getThread(t, r, d);
|
|
262
|
+
m && n.push(m);
|
|
264
263
|
});
|
|
265
|
-
}),
|
|
264
|
+
}), n;
|
|
266
265
|
}
|
|
267
266
|
getAll() {
|
|
268
|
-
const
|
|
269
|
-
return this._commentsMap.forEach((
|
|
270
|
-
|
|
271
|
-
unitId,
|
|
272
|
-
threads: this.getUnit(
|
|
267
|
+
const t = [];
|
|
268
|
+
return this._commentsMap.forEach((e, n) => {
|
|
269
|
+
t.push({
|
|
270
|
+
unitId: n,
|
|
271
|
+
threads: this.getUnit(n)
|
|
273
272
|
});
|
|
274
|
-
}),
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
],
|
|
281
|
-
var
|
|
282
|
-
const
|
|
283
|
-
var
|
|
284
|
-
for (var
|
|
285
|
-
(
|
|
286
|
-
return
|
|
287
|
-
},
|
|
288
|
-
let
|
|
289
|
-
constructor(
|
|
290
|
-
super(), this._resourceManagerService =
|
|
273
|
+
}), t;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
i = q([
|
|
277
|
+
I(0, v(p)),
|
|
278
|
+
I(1, v(L))
|
|
279
|
+
], i);
|
|
280
|
+
var T = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(T || {});
|
|
281
|
+
const D = "UNIVER_THREAD_COMMENT_PLUGIN";
|
|
282
|
+
var z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, X = (s, t, e, n) => {
|
|
283
|
+
for (var o = n > 1 ? void 0 : n ? Q(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
284
|
+
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
285
|
+
return n && o && z(t, e, o), o;
|
|
286
|
+
}, S = (s, t) => (e, n) => t(e, n, s);
|
|
287
|
+
let g = class extends U {
|
|
288
|
+
constructor(s, t, e) {
|
|
289
|
+
super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
|
|
291
290
|
}
|
|
292
291
|
_initSnapshot() {
|
|
293
|
-
const
|
|
294
|
-
const
|
|
295
|
-
return
|
|
296
|
-
var
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
...
|
|
300
|
-
children:
|
|
301
|
-
}),
|
|
302
|
-
}), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(
|
|
303
|
-
},
|
|
304
|
-
if (!
|
|
292
|
+
const s = (e) => {
|
|
293
|
+
const n = this._threadCommentModel.getUnit(e), o = {};
|
|
294
|
+
return n ? (n.forEach((r) => {
|
|
295
|
+
var d;
|
|
296
|
+
const a = (d = o[r.subUnitId]) != null ? d : [];
|
|
297
|
+
a.push({
|
|
298
|
+
...r.root,
|
|
299
|
+
children: r.children
|
|
300
|
+
}), o[r.subUnitId] = a;
|
|
301
|
+
}), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
|
|
302
|
+
}, t = (e) => {
|
|
303
|
+
if (!e)
|
|
305
304
|
return {};
|
|
306
305
|
try {
|
|
307
|
-
return JSON.parse(
|
|
306
|
+
return JSON.parse(e);
|
|
308
307
|
} catch {
|
|
309
308
|
return {};
|
|
310
309
|
}
|
|
311
|
-
}
|
|
310
|
+
};
|
|
312
311
|
this.disposeWithMe(
|
|
313
312
|
this._resourceManagerService.registerPluginResource({
|
|
314
|
-
pluginName: `SHEET_${
|
|
315
|
-
businesses: [
|
|
316
|
-
toJson:
|
|
317
|
-
parseJson:
|
|
318
|
-
onUnLoad:
|
|
319
|
-
this._threadCommentModel.deleteUnit(
|
|
320
|
-
},
|
|
321
|
-
onLoad:
|
|
322
|
-
Object.keys(
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
this._threadCommentModel.addComment(
|
|
326
|
-
}), this._threadCommentModel.syncThreadComments(
|
|
313
|
+
pluginName: `SHEET_${D}`,
|
|
314
|
+
businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
|
|
315
|
+
toJson: (e) => s(e),
|
|
316
|
+
parseJson: (e) => t(e),
|
|
317
|
+
onUnLoad: (e) => {
|
|
318
|
+
this._threadCommentModel.deleteUnit(e);
|
|
319
|
+
},
|
|
320
|
+
onLoad: async (e, n) => {
|
|
321
|
+
Object.keys(n).forEach((o) => {
|
|
322
|
+
const r = n[o];
|
|
323
|
+
r.forEach((a) => {
|
|
324
|
+
this._threadCommentModel.addComment(e, o, a);
|
|
325
|
+
}), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
|
|
327
326
|
});
|
|
328
|
-
}
|
|
327
|
+
}
|
|
329
328
|
})
|
|
330
329
|
);
|
|
331
330
|
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
],
|
|
338
|
-
const
|
|
331
|
+
};
|
|
332
|
+
g = X([
|
|
333
|
+
S(0, V),
|
|
334
|
+
S(1, v(i)),
|
|
335
|
+
S(2, p)
|
|
336
|
+
], g);
|
|
337
|
+
const w = {
|
|
339
338
|
id: "thread-comment.mutation.add-comment",
|
|
340
|
-
type:
|
|
341
|
-
handler(
|
|
342
|
-
if (!
|
|
339
|
+
type: l.MUTATION,
|
|
340
|
+
handler(s, t, e) {
|
|
341
|
+
if (!t)
|
|
343
342
|
return !1;
|
|
344
|
-
const
|
|
345
|
-
return
|
|
343
|
+
const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
|
|
344
|
+
return n.addComment(o, r, a, m);
|
|
346
345
|
}
|
|
347
|
-
},
|
|
346
|
+
}, P = {
|
|
348
347
|
id: "thread-comment.mutation.update-comment",
|
|
349
|
-
type:
|
|
350
|
-
handler(
|
|
351
|
-
if (!
|
|
348
|
+
type: l.MUTATION,
|
|
349
|
+
handler(s, t) {
|
|
350
|
+
if (!t)
|
|
352
351
|
return !1;
|
|
353
|
-
const
|
|
354
|
-
return
|
|
352
|
+
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
353
|
+
return e.updateComment(n, o, r, a);
|
|
355
354
|
}
|
|
356
|
-
},
|
|
355
|
+
}, k = {
|
|
357
356
|
id: "thread-comment.mutation.update-comment-ref",
|
|
358
|
-
type:
|
|
359
|
-
handler(
|
|
360
|
-
if (!
|
|
357
|
+
type: l.MUTATION,
|
|
358
|
+
handler(s, t) {
|
|
359
|
+
if (!t)
|
|
361
360
|
return !1;
|
|
362
|
-
const
|
|
363
|
-
return
|
|
361
|
+
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
362
|
+
return e.updateCommentRef(n, o, r, a);
|
|
364
363
|
}
|
|
365
|
-
},
|
|
364
|
+
}, $ = {
|
|
366
365
|
id: "thread-comment.mutation.resolve-comment",
|
|
367
|
-
type:
|
|
368
|
-
handler(
|
|
369
|
-
if (!
|
|
366
|
+
type: l.MUTATION,
|
|
367
|
+
handler(s, t) {
|
|
368
|
+
if (!t)
|
|
370
369
|
return !1;
|
|
371
|
-
const
|
|
372
|
-
return
|
|
370
|
+
const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
|
|
371
|
+
return e.resolveComment(n, o, a, r);
|
|
373
372
|
}
|
|
374
|
-
},
|
|
373
|
+
}, N = {
|
|
375
374
|
id: "thread-comment.mutation.delete-comment",
|
|
376
|
-
type:
|
|
377
|
-
handler(
|
|
378
|
-
if (!
|
|
375
|
+
type: l.MUTATION,
|
|
376
|
+
handler(s, t) {
|
|
377
|
+
if (!t)
|
|
379
378
|
return !1;
|
|
380
|
-
const
|
|
381
|
-
return
|
|
379
|
+
const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
|
|
380
|
+
return e.deleteComment(n, o, r);
|
|
382
381
|
}
|
|
383
|
-
},
|
|
382
|
+
}, ee = {
|
|
384
383
|
id: "thread-comment.command.add-comment",
|
|
385
|
-
type:
|
|
386
|
-
async handler(
|
|
387
|
-
if (!
|
|
384
|
+
type: l.COMMAND,
|
|
385
|
+
async handler(s, t) {
|
|
386
|
+
if (!t)
|
|
388
387
|
return !1;
|
|
389
|
-
const
|
|
390
|
-
id:
|
|
388
|
+
const e = s.get(f), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
|
|
389
|
+
id: w.id,
|
|
391
390
|
params: {
|
|
392
|
-
...
|
|
393
|
-
comment
|
|
391
|
+
...t,
|
|
392
|
+
comment: r
|
|
394
393
|
}
|
|
395
394
|
};
|
|
396
|
-
return
|
|
397
|
-
onlyLocal: !
|
|
395
|
+
return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
|
|
396
|
+
onlyLocal: !a
|
|
398
397
|
});
|
|
399
398
|
}
|
|
400
|
-
},
|
|
399
|
+
}, te = {
|
|
401
400
|
id: "thread-comment.command.update-comment",
|
|
402
|
-
type:
|
|
403
|
-
async handler(
|
|
404
|
-
if (!
|
|
401
|
+
type: l.COMMAND,
|
|
402
|
+
async handler(s, t) {
|
|
403
|
+
if (!t)
|
|
405
404
|
return !1;
|
|
406
|
-
const { unitId, subUnitId, payload } =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
405
|
+
const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(f), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
|
|
406
|
+
e,
|
|
407
|
+
n,
|
|
408
|
+
o.commentId
|
|
410
409
|
);
|
|
411
|
-
if (!
|
|
410
|
+
if (!c)
|
|
412
411
|
return !1;
|
|
413
|
-
const { children, ...
|
|
414
|
-
if (!await
|
|
415
|
-
...
|
|
416
|
-
...
|
|
412
|
+
const { children: h, ..._ } = c;
|
|
413
|
+
if (!await d.updateComment({
|
|
414
|
+
..._,
|
|
415
|
+
...o
|
|
417
416
|
}))
|
|
418
417
|
return !1;
|
|
419
|
-
const
|
|
420
|
-
id:
|
|
421
|
-
params
|
|
418
|
+
const E = {
|
|
419
|
+
id: P.id,
|
|
420
|
+
params: t
|
|
422
421
|
};
|
|
423
|
-
return
|
|
422
|
+
return r.executeCommand(E.id, E.params, { onlyLocal: !m }), !0;
|
|
424
423
|
}
|
|
425
|
-
},
|
|
424
|
+
}, ne = {
|
|
426
425
|
id: "thread-comment.command.resolve-comment",
|
|
427
|
-
type:
|
|
428
|
-
async handler(
|
|
429
|
-
if (!
|
|
426
|
+
type: l.COMMAND,
|
|
427
|
+
async handler(s, t) {
|
|
428
|
+
if (!t)
|
|
430
429
|
return !1;
|
|
431
|
-
const { unitId, subUnitId, resolved, commentId } =
|
|
432
|
-
return !
|
|
433
|
-
...
|
|
434
|
-
resolved
|
|
435
|
-
}) ? !1 :
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
{ onlyLocal: !
|
|
430
|
+
const { unitId: e, subUnitId: n, resolved: o, commentId: r } = t, a = s.get(p), m = s.get(i).getComment(e, n, r), c = a.syncUpdateMutationToColla;
|
|
431
|
+
return !m || !await a.resolveComment({
|
|
432
|
+
...m,
|
|
433
|
+
resolved: o
|
|
434
|
+
}) ? !1 : s.get(f).executeCommand(
|
|
435
|
+
$.id,
|
|
436
|
+
t,
|
|
437
|
+
{ onlyLocal: !c }
|
|
439
438
|
);
|
|
440
439
|
}
|
|
441
|
-
},
|
|
440
|
+
}, oe = {
|
|
442
441
|
id: "thread-comment.command.delete-comment",
|
|
443
|
-
type:
|
|
444
|
-
async handler(
|
|
445
|
-
if (!
|
|
442
|
+
type: l.COMMAND,
|
|
443
|
+
async handler(s, t) {
|
|
444
|
+
if (!t)
|
|
446
445
|
return !1;
|
|
447
|
-
const
|
|
448
|
-
if (!
|
|
446
|
+
const e = s.get(i), n = s.get(p), o = s.get(f), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
|
|
447
|
+
if (!c || !await n.deleteComment(r, a, c.threadId, d))
|
|
449
448
|
return !1;
|
|
450
|
-
const
|
|
451
|
-
id:
|
|
452
|
-
params
|
|
449
|
+
const h = {
|
|
450
|
+
id: N.id,
|
|
451
|
+
params: t
|
|
453
452
|
};
|
|
454
|
-
return
|
|
453
|
+
return o.executeCommand(h.id, h.params, { onlyLocal: !m });
|
|
455
454
|
}
|
|
456
|
-
},
|
|
455
|
+
}, re = {
|
|
457
456
|
id: "thread-comment.command.delete-comment-tree",
|
|
458
|
-
type:
|
|
459
|
-
async handler(
|
|
460
|
-
if (!
|
|
457
|
+
type: l.COMMAND,
|
|
458
|
+
async handler(s, t) {
|
|
459
|
+
if (!t)
|
|
461
460
|
return !1;
|
|
462
|
-
const
|
|
463
|
-
return !
|
|
464
|
-
unitId,
|
|
465
|
-
subUnitId,
|
|
466
|
-
commentId:
|
|
461
|
+
const e = s.get(i), n = s.get(f), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
|
|
462
|
+
return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? !1 : await n.executeCommand(N.id, {
|
|
463
|
+
unitId: r,
|
|
464
|
+
subUnitId: a,
|
|
465
|
+
commentId: m.root.id
|
|
467
466
|
});
|
|
468
467
|
}
|
|
469
|
-
},
|
|
470
|
-
var
|
|
471
|
-
for (var
|
|
472
|
-
(
|
|
473
|
-
return
|
|
474
|
-
},
|
|
475
|
-
let
|
|
476
|
-
constructor(
|
|
477
|
-
super(), this._config =
|
|
478
|
-
const { ...
|
|
479
|
-
this._configService.setConfig(
|
|
468
|
+
}, ae = "thread-comment.config", se = {};
|
|
469
|
+
var me = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, de = (s, t, e, n) => {
|
|
470
|
+
for (var o = n > 1 ? void 0 : n ? ce(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
471
|
+
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
472
|
+
return n && o && me(t, e, o), o;
|
|
473
|
+
}, y = (s, t) => (e, n) => t(e, n, s), M;
|
|
474
|
+
let R = (M = class extends W {
|
|
475
|
+
constructor(s = se, t, e, n) {
|
|
476
|
+
super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
|
|
477
|
+
const { ...o } = this._config;
|
|
478
|
+
this._configService.setConfig(ae, o);
|
|
480
479
|
}
|
|
481
480
|
onStarting() {
|
|
482
|
-
var
|
|
483
|
-
|
|
484
|
-
[
|
|
485
|
-
[
|
|
486
|
-
[
|
|
487
|
-
], (
|
|
488
|
-
(
|
|
489
|
-
this._injector.add(
|
|
481
|
+
var s;
|
|
482
|
+
H([
|
|
483
|
+
[p, { useClass: B }],
|
|
484
|
+
[i],
|
|
485
|
+
[g]
|
|
486
|
+
], (s = this._config) == null ? void 0 : s.overrides).forEach(
|
|
487
|
+
(t) => {
|
|
488
|
+
this._injector.add(t);
|
|
490
489
|
}
|
|
491
490
|
), [
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
].forEach((
|
|
503
|
-
this._commandService.registerCommand(
|
|
504
|
-
}), this._injector.get(
|
|
505
|
-
}
|
|
506
|
-
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
],
|
|
491
|
+
ee,
|
|
492
|
+
te,
|
|
493
|
+
oe,
|
|
494
|
+
ne,
|
|
495
|
+
re,
|
|
496
|
+
w,
|
|
497
|
+
P,
|
|
498
|
+
k,
|
|
499
|
+
N,
|
|
500
|
+
$
|
|
501
|
+
].forEach((t) => {
|
|
502
|
+
this._commandService.registerCommand(t);
|
|
503
|
+
}), this._injector.get(g);
|
|
504
|
+
}
|
|
505
|
+
}, u(M, "pluginName", D), u(M, "type", J.UNIVER_UNKNOWN), M);
|
|
506
|
+
R = de([
|
|
507
|
+
y(1, v(G)),
|
|
508
|
+
y(2, f),
|
|
509
|
+
y(3, b)
|
|
510
|
+
], R);
|
|
511
|
+
function le() {
|
|
512
|
+
return Y().format("YYYY/MM/DD HH:mm");
|
|
513
|
+
}
|
|
512
514
|
export {
|
|
513
|
-
AddCommentCommand,
|
|
514
|
-
AddCommentMutation,
|
|
515
|
-
DeleteCommentCommand,
|
|
516
|
-
DeleteCommentMutation,
|
|
517
|
-
DeleteCommentTreeCommand,
|
|
518
|
-
IThreadCommentDataSourceService,
|
|
519
|
-
ResolveCommentCommand,
|
|
520
|
-
ResolveCommentMutation,
|
|
521
|
-
TC_PLUGIN_NAME,
|
|
522
|
-
ThreadCommentDataSourceService,
|
|
523
|
-
ThreadCommentModel,
|
|
524
|
-
ThreadCommentResourceController,
|
|
525
|
-
UniverThreadCommentPlugin,
|
|
526
|
-
UpdateCommentCommand,
|
|
527
|
-
UpdateCommentMutation,
|
|
528
|
-
UpdateCommentRefMutation
|
|
515
|
+
ee as AddCommentCommand,
|
|
516
|
+
w as AddCommentMutation,
|
|
517
|
+
oe as DeleteCommentCommand,
|
|
518
|
+
N as DeleteCommentMutation,
|
|
519
|
+
re as DeleteCommentTreeCommand,
|
|
520
|
+
p as IThreadCommentDataSourceService,
|
|
521
|
+
ne as ResolveCommentCommand,
|
|
522
|
+
$ as ResolveCommentMutation,
|
|
523
|
+
D as TC_PLUGIN_NAME,
|
|
524
|
+
B as ThreadCommentDataSourceService,
|
|
525
|
+
i as ThreadCommentModel,
|
|
526
|
+
g as ThreadCommentResourceController,
|
|
527
|
+
R as UniverThreadCommentPlugin,
|
|
528
|
+
te as UpdateCommentCommand,
|
|
529
|
+
P as UpdateCommentMutation,
|
|
530
|
+
k as UpdateCommentRefMutation,
|
|
531
|
+
le as getDT
|
|
529
532
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDT(): string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { ThreadCommentResourceController } from './controllers/tc-resource.contr
|
|
|
18
18
|
export { TC_PLUGIN_NAME } from './types/const';
|
|
19
19
|
export type { IBaseComment, IThreadComment, IThreadCommentMention } from './types/interfaces/i-thread-comment';
|
|
20
20
|
export { UniverThreadCommentPlugin } from './plugin';
|
|
21
|
+
export { getDT } from './common/utils';
|
|
21
22
|
export { type IThreadCommentDataSource, IThreadCommentDataSourceService, ThreadCommentDataSourceService, type ThreadCommentJSON, } from './services/tc-datasource.service';
|
|
22
23
|
export { AddCommentMutation, DeleteCommentMutation, ResolveCommentMutation, UpdateCommentMutation, UpdateCommentRefMutation, } from './commands/mutations/comment.mutation';
|
|
23
24
|
export type { IAddCommentMutationParams, IDeleteCommentMutationParams, IResolveCommentMutationParams, IUpdateCommentMutationParams, IUpdateCommentPayload, IUpdateCommentRefMutationParams, } from './commands/mutations/comment.mutation';
|
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){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"})});
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,function(s,c,M){"use strict";var F=Object.defineProperty;var z=(s,c,M)=>c in s?F(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>z(s,typeof c!="symbol"?c+"":c,M);var v;class E extends c.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=c.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(r,m,e,t)=>{for(var n=t>1?void 0:t?V(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&L(m,e,n),n},R=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentModel=class extends c.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===c.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:d,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(d);l||(l=new Set,h.set(d,l));for(const f of i)l.add(f)}),this._tasks=[],o.forEach((a,d)=>{a.forEach((i,h)=>{this.syncThreadComments(d,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:d,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),d==null||d.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<c.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const i=new Set(n);d.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,f)=>{l.threadId===h&&a.delete(f)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:d,children:i=[],...h}=n,l={...h,parentId:d===n.id?void 0:d};l.threadId||(l.threadId=l.parentId||l.id);const f=p=>{a.set(p.id,p),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})};f(l);const A=this._ensureThreadMap(e,t);if(!l.parentId){A.set(l.threadId,l);for(const p of i)f(p)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d&&(d.updated=!0,d.text=n.text,d.attachments=n.attachments,d.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d?(d.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n);return d?(d.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let d;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):d=l,h.add(l.personId);if(d)return{root:d,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(d=>{d.threadId===n&&this._deleteComment(e,t,d.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((d,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},s.ThreadCommentModel=W([R(0,c.Inject(C)),R(1,c.Inject(c.LifecycleService))],s.ThreadCommentModel);var T=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(T||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(r,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&b(m,e,n),n},g=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentResourceController=class extends c.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const d=(i=o[a.subUnitId])!=null?i:[];d.push({...a.root,children:a.children}),o[a.subUnitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[T.UNIVER_SHEET,T.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(d=>{this._threadCommentModel.addComment(t,o,d)}),this._threadCommentModel.syncThreadComments(t,o,a.map(d=>d.threadId))})}}))}},s.ThreadCommentResourceController=G([g(0,c.IResourceManagerService),g(1,c.Inject(s.ThreadCommentModel)),g(2,C)],s.ThreadCommentResourceController);const y={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(r,m,e){if(!m)return!1;const t=r.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=m,i=d||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},U={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(c.ICommandService),t=r.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...m,comment:o}};return d?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},P={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=r.get(c.ICommandService),a=r.get(s.ThreadCommentModel),d=r.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...f}=h;if(!await d.updateComment({...f,...n}))return!1;const p={id:U.id,params:m};return o.executeCommand(p.id,p.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=r.get(C),i=r.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:r.get(c.ICommandService).executeCommand(N.id,m,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(C),n=r.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,d);if(!h||!await t.deleteComment(o,a,h.threadId,d))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},$={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(c.ICommandService),n=r.get(C),{unitId:o,subUnitId:a,commentId:d}=m,i=e.getCommentWithChildren(o,a,d);return!i||!await n.deleteComment(o,a,i.root.threadId,d)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}},H="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(r,m,e,t)=>{for(var n=t>1?void 0:t?B(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&K(m,e,n),n},I=(r,m)=>(e,t)=>m(e,t,r);s.UniverThreadCommentPlugin=(v=class extends c.Plugin{constructor(m=Y,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(H,o)}onStarting(){var m;c.mergeOverrideWithDependencies([[C,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[D,P,j,w,$,y,U,O,_,N].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(v,"pluginName",S),u(v,"type",c.UniverInstanceType.UNIVER_UNKNOWN),v),s.UniverThreadCommentPlugin=q([I(1,c.Inject(c.Injector)),I(2,c.ICommandService),I(3,c.IConfigService)],s.UniverThreadCommentPlugin);function Z(){return c.dayjs().format("YYYY/MM/DD HH:mm")}s.AddCommentCommand=D,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=$,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=N,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=P,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=O,s.getDT=Z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/thread-comment",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment core plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"./lib/*": "./lib/*"
|
|
33
33
|
},
|
|
34
|
-
"main": "./lib/
|
|
35
|
-
"module": "./lib/es/index.js",
|
|
34
|
+
"main": "./lib/es/index.js",
|
|
36
35
|
"types": "./lib/types/index.d.ts",
|
|
37
36
|
"publishConfig": {
|
|
38
37
|
"access": "public"
|
|
@@ -47,17 +46,17 @@
|
|
|
47
46
|
"rxjs": ">=7.0.0"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"@univerjs/protocol": "0.1.39-alpha.
|
|
51
|
-
"@univerjs/core": "0.
|
|
49
|
+
"@univerjs/protocol": "0.1.39-alpha.45",
|
|
50
|
+
"@univerjs/core": "0.5.0-beta.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"rxjs": "^7.8.1",
|
|
55
54
|
"typescript": "^5.6.3",
|
|
56
|
-
"vite": "^5.4.
|
|
57
|
-
"vitest": "^2.1.
|
|
58
|
-
"@univerjs-infra/shared": "0.
|
|
55
|
+
"vite": "^5.4.11",
|
|
56
|
+
"vitest": "^2.1.5",
|
|
57
|
+
"@univerjs-infra/shared": "0.5.0-beta.0"
|
|
59
58
|
},
|
|
60
|
-
"
|
|
59
|
+
"space": {
|
|
61
60
|
".": {
|
|
62
61
|
"import": "./lib/es/index.js",
|
|
63
62
|
"require": "./lib/cjs/index.js",
|
|
@@ -75,6 +74,7 @@
|
|
|
75
74
|
"test:watch": "vitest",
|
|
76
75
|
"coverage": "vitest run --coverage",
|
|
77
76
|
"lint:types": "tsc --noEmit",
|
|
78
|
-
"build": "
|
|
79
|
-
}
|
|
77
|
+
"build": "univer-cli build"
|
|
78
|
+
},
|
|
79
|
+
"module": "./lib/es/index.js"
|
|
80
80
|
}
|