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