@univerjs/thread-comment 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +411 -387
- package/lib/types/commands/commands/comment.command.d.ts +3 -10
- package/lib/types/commands/mutations/comment.mutation.d.ts +1 -0
- package/lib/types/index.d.ts +4 -4
- package/lib/types/models/thread-comment.model.d.ts +18 -8
- package/lib/types/services/tc-datasource.service.d.ts +62 -13
- package/lib/types/types/interfaces/i-thread-comment.d.ts +9 -5
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty;var L=(m,e,o)=>e in m?j(m,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[e]=o;var C=(m,e,o)=>L(m,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("rxjs"),d=require("@univerjs/core"),U=require("@wendellhu/redi");class h{constructor(){C(this,"_commentsMap",{});C(this,"_commentsTreeMap",new Map);C(this,"_commentUpdate$",new S.Subject);C(this,"_commentsTreeMap$",new S.BehaviorSubject({}));C(this,"_commentsMap$",new S.BehaviorSubject({}));C(this,"commentUpdate$",this._commentUpdate$.asObservable());C(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());C(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(e,o){let t=this._commentsMap[e];t||(t={},this._commentsMap[e]=t);let n=t[o];return n||(n={},t[o]=n),n}_ensureCommentChildrenMap(e,o){let t=this._commentsTreeMap.get(e);t||(t=new Map,this._commentsTreeMap.set(e,t));let n=t.get(o);return n||(n=new Map,t.set(o,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const e={};this._commentsTreeMap.forEach((o,t)=>{e[t]={};const n=e[t];o.forEach((a,r)=>{n[r]={};const s=n[r];a.forEach((c,i)=>{s[i]=c})})}),this._commentsTreeMap$.next(e)}ensureMap(e,o){const t=this._ensureCommentMap(e,o),n=this._ensureCommentChildrenMap(e,o);return{commentMap:t,commentChildrenMap:n}}addComment(e,o,t){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(e,o);let r=t.parentId;if(r){let s=n[r];for(;s!=null&&s.parentId;)s=n[s.parentId],r=s.parentId;if(s){let c=a.get(r);c||(c=[]),c.push(t.id),a.set(r,c)}}else a.set(t.id,[]);return n[t.id]=t,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"add",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(e,o,t,n){const{commentMap:a}=this.ensureMap(e,o),r=a[t.commentId];return r?(r.updated=!0,r.text=t.text,r.attachments=t.attachments,r.updateT=t.updateT,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"update",payload:t,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(e,o,t,n){const{commentMap:a}=this.ensureMap(e,o),r=a[t.commentId];return r?(r.ref=t.ref,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"updateRef",payload:t,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(e,o,t,n){const{commentMap:a}=this.ensureMap(e,o),r=a[t];return r?(r.resolved=n,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"resolve",payload:{commentId:t,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o);return n[t]}getComment$(e,o,t){return this._commentsMap$.pipe(S.map(n=>n[e][o][t]))}getCommentWithChildren(e,o,t){var p;const{commentMap:n,commentChildrenMap:a}=this.ensureMap(e,o),r=n[t];if(!r)return;const s=new Set,c=(p=a.get(t))!=null?p:[],i=c==null?void 0:c.map(u=>n[u]);return[r,...i].forEach(u=>{var M;s.add(u.personId),(M=u.text.customRanges)==null||M.forEach(_=>{_.rangeType===d.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:r,children:i,relativeUsers:s}}deleteComment(e,o,t){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(e,o),r=n[t];if(!r)return!1;if(r.parentId){const s=a.get(r.parentId);if(s){const c=s.indexOf(t);s.splice(c,1)}delete n[t]}else delete n[t],a.delete(t);return this._commentUpdate$.next({unitId:e,subUnitId:o,type:"delete",payload:{commentId:t,isRoot:!r.parentId,comment:r}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(e){const o=this._commentsMap[e];return o?Array.from(Object.entries(o)).map(([t,n])=>[t,Array.from(Object.values(n))]):[]}deleteUnit(e){const o=this._commentsMap[e];o&&Object.entries(o).forEach(([t,n])=>{Object.values(n).forEach(a=>{this.deleteComment(e,t,a.id)})})}getRootCommentIds(e,o){const t=this._ensureCommentChildrenMap(e,o);return Array.from(t.keys())}getRootCommentIds$(e,o){return this._commentsTreeMap$.pipe(S.map(t=>{var n;return Object.keys((n=t[e])==null?void 0:n[o])}))}getAll(){return this._commentsMap}}var D=(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.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(e){return e}async updateComment(e){return!0}async deleteComment(e){return!0}async deleteCommentBatch(e){return!0}async loadFormSnapshot(e){return e}saveToSnapshot(e){return e}}const l=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(m,e,o,t)=>{for(var n=t>1?void 0:t?W(e,o):e,a=m.length-1,r;a>=0;a--)(r=m[a])&&(n=(t?r(e,o,n):r(n))||n);return t&&n&&V(e,o,n),n},y=(m,e)=>(o,t)=>e(o,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(e,o,t){super(),this._resourceManagerService=e,this._threadCommentModel=o,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const e=t=>{const n=this._threadCommentModel.getUnit(t),a={};return n?(n.forEach(([r,s])=>{a[r]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(a))):""},o=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:t=>e(t),parseJson:t=>o(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{const a=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(a).forEach(r=>{n[r].forEach(c=>{this._threadCommentModel.addComment(t,r,c)})})}}))}};exports.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,exports.ThreadCommentResourceController),y(0,d.IResourceManagerService),y(1,U.Inject(h)),y(2,l)],exports.ThreadCommentResourceController);const I={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,comment:a}=e;return o.addComment(t,n,a)}},f={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:a,silent:r}=e;return o.updateComment(t,n,a,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:a,silent:r}=e;return o.updateCommentRef(t,n,a,r)}},N={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,resolved:a,commentId:r}=e;return o.resolveComment(t,n,r,a)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,commentId:a}=e;return o.deleteComment(t,n,a)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(d.ICommandService),t=m.get(d.IUndoRedoService),n=m.get(l),{unitId:a,subUnitId:r,comment:s}=e,c=await n.addComment(s),i={id:I.id,params:e},p={id:T.id,params:{unitId:a,subUnitId:r,commentId:c.id}};return t.pushUndoRedo({undoMutations:[p],redoMutations:[i],unitID:a}),o.executeCommand(i.id,i.params),!0}},x={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,payload:n}=e,a=m.get(d.ICommandService),r=m.get(d.IUndoRedoService),s=m.get(h),c=m.get(l),i=s.getComment(o,t,n.commentId);if(!i||!await c.updateComment({...i,...n}))return!1;const u={id:f.id,params:e},M={id:f.id,params:{unitId:o,subUnitId:t,payload:{commentId:n.commentId,text:i.text,attachments:i.attachments,updateT:i.updateT,updated:i.updated}}};return r.pushUndoRedo({undoMutations:[M],redoMutations:[u],unitID:o}),a.executeCommand(u.id,u.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,resolved:n,commentId:a}=e,r=m.get(l),c=m.get(h).getComment(o,t,a);return!c||!await r.updateComment({...c,resolved:n})?!1:(m.get(d.ICommandService).executeCommand(N.id,e),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(l),n=m.get(d.ICommandService),a=m.get(d.IUndoRedoService),{unitId:r,subUnitId:s,commentId:c}=e,i=o.getComment(r,s,c);if(!i||!await t.deleteComment(c))return!1;const p={id:T.id,params:e},u={id:I.id,params:{unitId:r,subUnitId:s,comment:i}};return a.pushUndoRedo({undoMutations:[u],redoMutations:[p],unitID:r}),n.executeCommand(p.id,p.params)}},w={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(d.ICommandService),n=m.get(l),a=m.get(d.IUndoRedoService),{unitId:r,subUnitId:s,commentId:c}=e,i=o.getCommentWithChildren(r,s,c);if(!i)return!1;const p=[i.root,...i.children];if(!await n.deleteCommentBatch(p.map(v=>v.id)))return!1;const u=p.map(v=>({id:T.id,params:{unitId:r,subUnitId:s,commentId:v.id}})),M=p.map(v=>({id:I.id,params:{unitId:r,subUnitId:s,comment:v}})),_=d.sequenceExecute(u,t);return _.result&&a.pushUndoRedo({undoMutations:M,redoMutations:u,unitID:r}),_.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(m,e,o,t)=>{for(var n=t>1?void 0:t?H(e,o):e,a=m.length-1,r;a>=0;a--)(r=m[a])&&(n=(t?r(e,o,n):r(n))||n);return t&&n&&G(e,o,n),n},O=(m,e)=>(o,t)=>e(o,t,m),g;exports.UniverThreadCommentPlugin=(g=class extends d.Plugin{constructor(o,t,n){super();C(this,"_config");this._injector=t,this._commandService=n,this._config=o}onStarting(o){var t;d.mergeOverrideWithDependencies([[h],[exports.ThreadCommentResourceController],[l,{useClass:$}]],(t=this._config)==null?void 0:t.overrides).forEach(n=>{o.add(n)}),[b,x,P,A,w,I,f,E,T,N].forEach(n=>{this._commandService.registerCommand(n)})}},C(g,"pluginName",R),C(g,"type",d.UniverInstanceType.UNIVER_UNKNOWN),g);exports.UniverThreadCommentPlugin=q([O(1,U.Inject(U.Injector)),O(2,d.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=b;exports.AddCommentMutation=I;exports.DeleteCommentCommand=P;exports.DeleteCommentMutation=T;exports.DeleteCommentTreeCommand=w;exports.IThreadCommentDataSourceService=l;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=N;exports.TC_PLUGIN_NAME=R;exports.ThreadCommentDataSourceService=$;exports.ThreadCommentModel=h;exports.UpdateCommentCommand=x;exports.UpdateCommentMutation=f;exports.UpdateCommentRefMutation=E;
|
|
1
|
+
"use strict";var j=Object.defineProperty;var b=(m,n,t)=>n in m?j(m,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[n]=t;var l=(m,n,t)=>b(m,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("rxjs"),c=require("@univerjs/core"),f=require("@wendellhu/redi");class E extends c.Disposable{constructor(){super();l(this,"_dataSource",null);l(this,"syncUpdateMutationToColla",!0)}set dataSource(t){this._dataSource=t}get dataSource(){return this._dataSource}async getThreadComment(t,e,o){return this._dataSource?(await this._dataSource.listComments(t,e,[o]))[0]:null}async addComment(t){return this._dataSource?this._dataSource.addComment(t):t}async updateComment(t){return this._dataSource?this._dataSource.updateComment(t):!0}async resolveComment(t){return this._dataSource?this._dataSource.resolveComment(t):!0}async deleteComment(t,e,o,a){return this._dataSource?this._dataSource.deleteComment(t,e,o,a):!0}async listThreadComments(t,e,o){return this.dataSource?this.dataSource.listComments(t,e,o):[]}saveToSnapshot(t,e){if(this._dataSource){const o={};return Object.keys(t).forEach(a=>{const r=t[a];o[a]=r.map(this.dataSource.saveCommentToSnapshot)}),o}return t}}const C=f.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(m,n,t,e)=>{for(var o=e>1?void 0:e?V(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&L(n,t,o),o},O=(m,n)=>(t,e)=>n(t,e,m);exports.ThreadCommentModel=class{constructor(n,t){l(this,"_commentsMap",{});l(this,"_commentsTreeMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new v.Subject);l(this,"_commentsMap$",new v.BehaviorSubject({}));l(this,"commentUpdate$",this._commentUpdate$.asObservable());l(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=n,this._commandService=t}_ensureCommentMap(n,t){let e=this._commentsMap[n];e||(e={},this._commentsMap[n]=e);let o=e[t];return o||(o={},e[t]=o),o}_ensureCommentChildrenMap(n,t){let e=this._commentsTreeMap.get(n);e||(e=new Map,this._commentsTreeMap.set(n,e));let o=e.get(t);return o||(o=new Map,e.set(t,o)),o}_ensureThreadMap(n){let t=this._threadMap.get(n);return t||(t=new Map,this._threadMap.set(n,t)),t}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(n,t){const e=this._ensureCommentMap(n,t),o=this._ensureCommentChildrenMap(n,t);return{commentMap:e,commentChildrenMap:o}}_replaceComment(n,t,e){var s;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e.id];if(r){const d={...e,ref:r.ref};o[e.id]=d,(s=e.children)==null||s.forEach(i=>{o[i.id]={...i,ref:""}}),a.set(e.id,d),this._commentUpdate$.next({unitId:n,subUnitId:t,type:"syncUpdate",payload:d}),!!e.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e.id,resolved:!!e.resolved}})}}async syncThreadComments(n,t,e){const o=await this._dataSourceService.listThreadComments(n,t,e);if(!o.length)return;const a=new Set(e);o.forEach(r=>{this._replaceComment(n,t,r),a.delete(r.threadId)}),a.forEach(r=>{const s=this.getThread(n,r);s&&this.deleteComment(s.unitId,s.subUnitId,s.id)}),this._refreshCommentsMap$()}addComment(n,t,e,o){var h,p;const{commentMap:a,commentChildrenMap:r}=this.ensureMap(n,t),s=e,d=u=>{a[u.id]=u,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"add",payload:u,isRoot:!u.parentId})},i=s.parentId;if(i){const u=a[i];u.children=[...(h=u.children)!=null?h:[],s],d(s)}else r.set(s.id,s),this._ensureThreadMap(n).set(s.threadId,s),d(s),(p=s.children)==null||p.forEach(M=>d({...M,ref:""}));return this._refreshCommentsMap$(),o&&this.syncThreadComments(n,t,[s.threadId]),!0}updateComment(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"update",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"updateRef",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}resolveComment(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e];return r?(r.resolved=o,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e,resolved:o}}),this._refreshCommentsMap$(),!0):!1}getComment(n,t,e){const{commentMap:o}=this.ensureMap(n,t);return o[e]}getComment$(n,t,e){return this._commentsMap$.pipe(v.map(o=>o[n][t][e]))}getCommentWithChildren(n,t,e){var i,h;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e];if(!r)return;const s=new Set,d=a.get(e);if(d)return[d,...(i=d.children)!=null?i:[]].forEach(p=>{var u;s.add(p.personId),(u=p.text.customRanges)==null||u.forEach(M=>{M.rangeType===c.CustomRangeType.MENTION&&s.add(M.rangeId)})}),{root:r,children:(h=d.children)!=null?h:[],relativeUsers:s}}deleteComment(n,t,e){var s;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e];if(!r)return!0;if(r.parentId){const d=a.get(r.parentId);if(d&&d.children){const i=d.children.findIndex(h=>h.id=e);d.children.splice(i,1)}delete o[e]}else{delete o[e];const d=a.get(e);a.delete(e),this._ensureThreadMap(n).delete(r.threadId),(s=d==null?void 0:d.children)==null||s.forEach(h=>{delete o[h.id],this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:h.id,isRoot:!1,comment:h}})})}return this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:e,isRoot:!r.parentId,comment:r}}),this._refreshCommentsMap$(),!0}getUnit(n){const t=this._commentsMap[n];return t?Array.from(Object.entries(t)).map(([e,o])=>[e,Array.from(Object.values(o))]):[]}deleteUnit(n){const t=this._commentsMap[n];t&&Object.entries(t).forEach(([e,o])=>{Object.values(o).forEach(a=>{this.deleteComment(n,e,a.id)})})}getRootCommentIds(n,t){const e=this._ensureCommentChildrenMap(n,t);return Array.from(e.keys())}getAll(){return this._commentsMap}getThread(n,t){return this._ensureThreadMap(n).get(t)}};exports.ThreadCommentModel=W([O(0,f.Inject(C)),O(1,c.ICommandService)],exports.ThreadCommentModel);var y=(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.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(y||{});const g="THREAD_COMMENT_PLUGIN";var J=Object.defineProperty,G=Object.getOwnPropertyDescriptor,H=(m,n,t,e)=>{for(var o=e>1?void 0:e?G(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&J(n,t,o),o},S=(m,n)=>(t,e)=>n(t,e,m);exports.ThreadCommentResourceController=class extends c.Disposable{constructor(n,t,e){super(),this._resourceManagerService=n,this._threadCommentModel=t,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const n=e=>{const o=this._threadCommentModel.getUnit(e),a={};return o?(o.forEach(([r,s])=>{a[r]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(a,e))):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${g}`,businesses:[y.UNIVER_SHEET,y.UNIVER_DOC],toJson:e=>n(e),parseJson:e=>t(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,o)=>{Object.keys(o).forEach(a=>{const r=o[a];r.forEach(s=>{this._threadCommentModel.addComment(e,a,s)}),this._threadCommentModel.syncThreadComments(e,a,r.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=H([c.OnLifecycle(c.LifecycleStages.Starting,exports.ThreadCommentResourceController),S(0,c.IResourceManagerService),S(1,f.Inject(exports.ThreadCommentModel)),S(2,C)],exports.ThreadCommentResourceController);const U={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(m,n,t){if(!n)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:o,subUnitId:a,comment:r,sync:s}=n,d=s||(t==null?void 0:t.fromChangeset)&&!r.parentId;return e.addComment(o,a,r,d)}},I={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:e,subUnitId:o,payload:a,silent:r}=n;return t.updateComment(e,o,a,r)}},$={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:e,subUnitId:o,payload:a,silent:r}=n;return t.updateCommentRef(e,o,a,r)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:e,subUnitId:o,resolved:a,commentId:r}=n;return t.resolveComment(e,o,r,a)}},T={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:e,subUnitId:o,commentId:a}=n;return t.deleteComment(e,o,a)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(c.ICommandService),e=m.get(C),{comment:o}=n,a=await e.addComment(o),r=e.syncUpdateMutationToColla,s=!o.parentId,d={id:U.id,params:{...n,comment:a}};return s?await t.executeCommand(d.id,d.params):t.executeCommand(d.id,d.params,{onlyLocal:!r})}},w={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const{unitId:t,subUnitId:e,payload:o}=n,a=m.get(c.ICommandService),r=m.get(exports.ThreadCommentModel),s=m.get(C),d=s.syncUpdateMutationToColla,i=r.getComment(t,e,o.commentId);if(!i)return!1;const{children:h,...p}=i;if(!await s.updateComment({...p,...o}))return!1;const M={id:I.id,params:n};return a.executeCommand(M.id,M.params,{onlyLocal:!d}),!0}},P={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const{unitId:t,subUnitId:e,resolved:o,commentId:a}=n,r=m.get(C),d=m.get(exports.ThreadCommentModel).getComment(t,e,a),i=r.syncUpdateMutationToColla;return!d||!await r.resolveComment({...d,resolved:o})?!1:m.get(c.ICommandService).executeCommand(N.id,n,{onlyLocal:!i})}},x={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),e=m.get(C),o=m.get(c.ICommandService),{unitId:a,subUnitId:r,commentId:s}=n,d=e.syncUpdateMutationToColla,i=t.getComment(a,r,s);if(!i||!await e.deleteComment(a,r,i.threadId,s))return!1;const h={id:T.id,params:n};return o.executeCommand(h.id,h.params,{onlyLocal:!d})}},A={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(exports.ThreadCommentModel),e=m.get(c.ICommandService),o=m.get(C),{unitId:a,subUnitId:r,commentId:s}=n,d=t.getCommentWithChildren(a,r,s);return!d||!await o.deleteComment(a,r,d.root.threadId,s)?!1:await e.executeCommand(T.id,{unitId:a,subUnitId:r,commentId:d.root.id})}};var B=Object.defineProperty,q=Object.getOwnPropertyDescriptor,K=(m,n,t,e)=>{for(var o=e>1?void 0:e?q(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&B(n,t,o),o},R=(m,n)=>(t,e)=>n(t,e,m),_;exports.UniverThreadCommentPlugin=(_=class extends c.Plugin{constructor(t,e,o){super();l(this,"_config");this._injector=e,this._commandService=o,this._config=t}onStarting(t){var e;c.mergeOverrideWithDependencies([[C,{useClass:E}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(e=this._config)==null?void 0:e.overrides).forEach(o=>{t.add(o)}),[D,w,x,P,A,U,I,$,T,N].forEach(o=>{this._commandService.registerCommand(o)})}},l(_,"pluginName",g),l(_,"type",c.UniverInstanceType.UNIVER_UNKNOWN),_);exports.UniverThreadCommentPlugin=K([R(1,f.Inject(f.Injector)),R(2,c.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=D;exports.AddCommentMutation=U;exports.DeleteCommentCommand=x;exports.DeleteCommentMutation=T;exports.DeleteCommentTreeCommand=A;exports.IThreadCommentDataSourceService=C;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=N;exports.TC_PLUGIN_NAME=g;exports.ThreadCommentDataSourceService=E;exports.UpdateCommentCommand=w;exports.UpdateCommentMutation=I;exports.UpdateCommentRefMutation=$;
|