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