@univerjs/thread-comment 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var 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),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((r,a)=>{n[a]={};const s=n[a];r.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:r}=this.ensureMap(e,o);let a=t.parentId;if(a){let s=n[a];for(;s!=null&&s.parentId;)s=n[s.parentId],a=s.parentId;if(s){let c=r.get(a);c||(c=[]),c.push(t.id),r.set(a,c)}}else r.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){const{commentMap:n}=this.ensureMap(e,o),r=n[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}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.ref=t.ref,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"updateRef",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(e,o,t,n){const{commentMap:r}=this.ensureMap(e,o),a=r[t];return a?(a.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:r}=this.ensureMap(e,o),a=n[t];if(!a)return;const s=new Set,c=(p=r.get(t))!=null?p:[],i=c==null?void 0:c.map(u=>n[u]);return[a,...i].forEach(u=>{var M;s.add(u.personId),(M=u.text.customRanges)==null||M.forEach(_=>{_.rangeType===d.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:a,children:i,relativeUsers:s}}deleteComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return!1;if(a.parentId){const s=r.get(a.parentId);if(s){const c=s.indexOf(t);s.splice(c,1)}delete n[t]}else delete n[t],r.delete(t);return this._commentUpdate$.next({unitId:e,subUnitId:o,type:"delete",payload:{commentId:t,isRoot:!a.parentId,comment:a}}),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(r=>{this.deleteComment(e,t,r.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,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(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),r={};return n?(n.forEach(([a,s])=>{r[a]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},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 r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(t,a,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:r}=e;return o.addComment(t,n,r)}},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:r}=e;return o.updateComment(t,n,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:r}=e;return o.updateCommentRef(t,n,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:r,commentId:a}=e;return o.resolveComment(t,n,a,r)}},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:r}=e;return o.deleteComment(t,n,r)}},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:r,subUnitId:a,comment:s}=e,c=await n.addComment(s),i={id:I.id,params:e},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return t.pushUndoRedo({undoMutations:[p],redoMutations:[i],unitID:r}),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,r=m.get(d.ICommandService),a=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 a.pushUndoRedo({undoMutations:[M],redoMutations:[u],unitID:o}),r.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:r}=e,a=m.get(l),c=m.get(h).getComment(o,t,r);return!c||!await a.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),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getComment(a,s,c);if(!i||!await t.deleteComment(c))return!1;const p={id:T.id,params:e},u={id:I.id,params:{unitId:a,subUnitId:s,comment:i}};return r.pushUndoRedo({undoMutations:[u],redoMutations:[p],unitID:a}),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),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getCommentWithChildren(a,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:a,subUnitId:s,commentId:v.id}})),M=p.map(v=>({id:I.id,params:{unitId:a,subUnitId:s,comment:v}})),_=d.sequenceExecute(u,t);return _.result&&r.pushUndoRedo({undoMutations:M,redoMutations:u,unitID:a}),_.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,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(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 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),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;
package/lib/es/index.js CHANGED
@@ -37,10 +37,10 @@ class h {
37
37
  this._commentsTreeMap.forEach((n, t) => {
38
38
  e[t] = {};
39
39
  const o = e[t];
40
- n.forEach((m, s) => {
41
- o[s] = {};
42
- const a = o[s];
43
- m.forEach((d, c) => {
40
+ n.forEach((s, m) => {
41
+ o[m] = {};
42
+ const a = o[m];
43
+ s.forEach((d, c) => {
44
44
  a[c] = d;
45
45
  });
46
46
  });
@@ -54,18 +54,18 @@ class h {
54
54
  };
55
55
  }
56
56
  addComment(e, n, t) {
57
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n);
58
- let s = t.parentId;
59
- if (s) {
60
- let a = o[s];
57
+ const { commentMap: o, commentChildrenMap: s } = this.ensureMap(e, n);
58
+ let m = t.parentId;
59
+ if (m) {
60
+ let a = o[m];
61
61
  for (; a != null && a.parentId; )
62
- a = o[a.parentId], s = a.parentId;
62
+ a = o[a.parentId], m = a.parentId;
63
63
  if (a) {
64
- let d = m.get(s);
65
- d || (d = []), d.push(t.id), m.set(s, d);
64
+ let d = s.get(m);
65
+ d || (d = []), d.push(t.id), s.set(m, d);
66
66
  }
67
67
  } else
68
- m.set(t.id, []);
68
+ s.set(t.id, []);
69
69
  return o[t.id] = t, this._commentUpdate$.next({
70
70
  unitId: e,
71
71
  subUnitId: n,
@@ -73,27 +73,29 @@ class h {
73
73
  payload: t
74
74
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0;
75
75
  }
76
- updateComment(e, n, t) {
77
- const { commentMap: o } = this.ensureMap(e, n), m = o[t.commentId];
76
+ updateComment(e, n, t, o) {
77
+ const { commentMap: s } = this.ensureMap(e, n), m = s[t.commentId];
78
78
  return m ? (m.updated = !0, m.text = t.text, m.attachments = t.attachments, m.updateT = t.updateT, this._commentUpdate$.next({
79
79
  unitId: e,
80
80
  subUnitId: n,
81
81
  type: "update",
82
- payload: t
82
+ payload: t,
83
+ silent: o
83
84
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
84
85
  }
85
- updateCommentRef(e, n, t) {
86
- const { commentMap: o } = this.ensureMap(e, n), m = o[t.commentId];
86
+ updateCommentRef(e, n, t, o) {
87
+ const { commentMap: s } = this.ensureMap(e, n), m = s[t.commentId];
87
88
  return m ? (m.ref = t.ref, this._commentUpdate$.next({
88
89
  unitId: e,
89
90
  subUnitId: n,
90
91
  type: "updateRef",
91
- payload: t
92
+ payload: t,
93
+ silent: o
92
94
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
93
95
  }
94
96
  resolveComment(e, n, t, o) {
95
- const { commentMap: m } = this.ensureMap(e, n), s = m[t];
96
- return s ? (s.resolved = o, this._commentUpdate$.next({
97
+ const { commentMap: s } = this.ensureMap(e, n), m = s[t];
98
+ return m ? (m.resolved = o, this._commentUpdate$.next({
97
99
  unitId: e,
98
100
  subUnitId: n,
99
101
  type: "resolve",
@@ -112,42 +114,42 @@ class h {
112
114
  }
113
115
  getCommentWithChildren(e, n, t) {
114
116
  var u;
115
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n), s = o[t];
116
- if (!s)
117
+ const { commentMap: o, commentChildrenMap: s } = this.ensureMap(e, n), m = o[t];
118
+ if (!m)
117
119
  return;
118
- const a = /* @__PURE__ */ new Set(), d = (u = m.get(t)) != null ? u : [], c = d == null ? void 0 : d.map((i) => o[i]);
119
- return [s, ...c].forEach((i) => {
120
+ const a = /* @__PURE__ */ new Set(), d = (u = s.get(t)) != null ? u : [], c = d == null ? void 0 : d.map((i) => o[i]);
121
+ return [m, ...c].forEach((i) => {
120
122
  var C;
121
123
  a.add(i.personId), (C = i.text.customRanges) == null || C.forEach((_) => {
122
124
  _.rangeType === L.MENTION && a.add(_.rangeId);
123
125
  });
124
126
  }), {
125
- root: s,
127
+ root: m,
126
128
  children: c,
127
129
  relativeUsers: a
128
130
  };
129
131
  }
130
132
  deleteComment(e, n, t) {
131
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n), s = o[t];
132
- if (!s)
133
+ const { commentMap: o, commentChildrenMap: s } = this.ensureMap(e, n), m = o[t];
134
+ if (!m)
133
135
  return !1;
134
- if (s.parentId) {
135
- const a = m.get(s.parentId);
136
+ if (m.parentId) {
137
+ const a = s.get(m.parentId);
136
138
  if (a) {
137
139
  const d = a.indexOf(t);
138
140
  a.splice(d, 1);
139
141
  }
140
142
  delete o[t];
141
143
  } else
142
- delete o[t], m.delete(t);
144
+ delete o[t], s.delete(t);
143
145
  return this._commentUpdate$.next({
144
146
  unitId: e,
145
147
  subUnitId: n,
146
148
  type: "delete",
147
149
  payload: {
148
150
  commentId: t,
149
- isRoot: !s.parentId,
150
- comment: s
151
+ isRoot: !m.parentId,
152
+ comment: m
151
153
  }
152
154
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0;
153
155
  }
@@ -158,8 +160,8 @@ class h {
158
160
  deleteUnit(e) {
159
161
  const n = this._commentsMap[e];
160
162
  n && Object.entries(n).forEach(([t, o]) => {
161
- Object.values(o).forEach((m) => {
162
- this.deleteComment(e, t, m.id);
163
+ Object.values(o).forEach((s) => {
164
+ this.deleteComment(e, t, s.id);
163
165
  });
164
166
  });
165
167
  }
@@ -203,8 +205,8 @@ class z {
203
205
  }
204
206
  const f = Z("univer.thread-comment.data-source-service");
205
207
  var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, Y = (r, e, n, t) => {
206
- for (var o = t > 1 ? void 0 : t ? X(e, n) : e, m = r.length - 1, s; m >= 0; m--)
207
- (s = r[m]) && (o = (t ? s(e, n, o) : s(o)) || o);
208
+ for (var o = t > 1 ? void 0 : t ? X(e, n) : e, s = r.length - 1, m; s >= 0; s--)
209
+ (m = r[s]) && (o = (t ? m(e, n, o) : m(o)) || o);
208
210
  return t && o && Q(e, n, o), o;
209
211
  }, N = (r, e) => (n, t) => e(n, t, r);
210
212
  let U = class extends V {
@@ -214,8 +216,8 @@ let U = class extends V {
214
216
  _initSnapshot() {
215
217
  const r = (n) => {
216
218
  const t = this._threadCommentModel.getUnit(n), o = {};
217
- return t ? (t.forEach(([m, s]) => {
218
- o[m] = s;
219
+ return t ? (t.forEach(([s, m]) => {
220
+ o[s] = m;
219
221
  }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o))) : "";
220
222
  }, e = (n) => {
221
223
  if (!n)
@@ -237,9 +239,9 @@ let U = class extends V {
237
239
  },
238
240
  onLoad: async (n, t) => {
239
241
  const o = await this._threadCommentDataSourceService.loadFormSnapshot(t);
240
- Object.keys(o).forEach((m) => {
241
- t[m].forEach((a) => {
242
- this._threadCommentModel.addComment(n, m, a);
242
+ Object.keys(o).forEach((s) => {
243
+ t[s].forEach((a) => {
244
+ this._threadCommentModel.addComment(n, s, a);
243
245
  });
244
246
  });
245
247
  }
@@ -259,8 +261,8 @@ const T = {
259
261
  handler(r, e) {
260
262
  if (!e)
261
263
  return !1;
262
- const n = r.get(h), { unitId: t, subUnitId: o, comment: m } = e;
263
- return n.addComment(t, o, m);
264
+ const n = r.get(h), { unitId: t, subUnitId: o, comment: s } = e;
265
+ return n.addComment(t, o, s);
264
266
  }
265
267
  }, g = {
266
268
  id: "thread-comment.mutation.update-comment",
@@ -268,8 +270,8 @@ const T = {
268
270
  handler(r, e) {
269
271
  if (!e)
270
272
  return !1;
271
- const n = r.get(h), { unitId: t, subUnitId: o, payload: m } = e;
272
- return n.updateComment(t, o, m);
273
+ const n = r.get(h), { unitId: t, subUnitId: o, payload: s, silent: m } = e;
274
+ return n.updateComment(t, o, s, m);
273
275
  }
274
276
  }, k = {
275
277
  id: "thread-comment.mutation.update-comment-ref",
@@ -277,8 +279,8 @@ const T = {
277
279
  handler(r, e) {
278
280
  if (!e)
279
281
  return !1;
280
- const n = r.get(h), { unitId: t, subUnitId: o, payload: m } = e;
281
- return n.updateCommentRef(t, o, m);
282
+ const n = r.get(h), { unitId: t, subUnitId: o, payload: s, silent: m } = e;
283
+ return n.updateCommentRef(t, o, s, m);
282
284
  }
283
285
  }, w = {
284
286
  id: "thread-comment.mutation.resolve-comment",
@@ -286,8 +288,8 @@ const T = {
286
288
  handler(r, e) {
287
289
  if (!e)
288
290
  return !1;
289
- const n = r.get(h), { unitId: t, subUnitId: o, resolved: m, commentId: s } = e;
290
- return n.resolveComment(t, o, s, m);
291
+ const n = r.get(h), { unitId: t, subUnitId: o, resolved: s, commentId: m } = e;
292
+ return n.resolveComment(t, o, m, s);
291
293
  }
292
294
  }, y = {
293
295
  id: "thread-comment.mutation.delete-comment",
@@ -295,8 +297,8 @@ const T = {
295
297
  handler(r, e) {
296
298
  if (!e)
297
299
  return !1;
298
- const n = r.get(h), { unitId: t, subUnitId: o, commentId: m } = e;
299
- return n.deleteComment(t, o, m);
300
+ const n = r.get(h), { unitId: t, subUnitId: o, commentId: s } = e;
301
+ return n.deleteComment(t, o, s);
300
302
  }
301
303
  }, ee = {
302
304
  id: "thread-comment.command.add-comment",
@@ -304,21 +306,21 @@ const T = {
304
306
  async handler(r, e) {
305
307
  if (!e)
306
308
  return !1;
307
- const n = r.get(M), t = r.get(S), o = r.get(f), { unitId: m, subUnitId: s, comment: a } = e, d = await o.addComment(a), c = {
309
+ const n = r.get(M), t = r.get(S), o = r.get(f), { unitId: s, subUnitId: m, comment: a } = e, d = await o.addComment(a), c = {
308
310
  id: T.id,
309
311
  params: e
310
312
  }, u = {
311
313
  id: y.id,
312
314
  params: {
313
- unitId: m,
314
- subUnitId: s,
315
+ unitId: s,
316
+ subUnitId: m,
315
317
  commentId: d.id
316
318
  }
317
319
  };
318
320
  return t.pushUndoRedo({
319
321
  undoMutations: [u],
320
322
  redoMutations: [c],
321
- unitID: m
323
+ unitID: s
322
324
  }), n.executeCommand(c.id, c.params), !0;
323
325
  }
324
326
  }, te = {
@@ -327,7 +329,7 @@ const T = {
327
329
  async handler(r, e) {
328
330
  if (!e)
329
331
  return !1;
330
- const { unitId: n, subUnitId: t, payload: o } = e, m = r.get(M), s = r.get(S), a = r.get(h), d = r.get(f), c = a.getComment(
332
+ const { unitId: n, subUnitId: t, payload: o } = e, s = r.get(M), m = r.get(S), a = r.get(h), d = r.get(f), c = a.getComment(
331
333
  n,
332
334
  t,
333
335
  o.commentId
@@ -354,11 +356,11 @@ const T = {
354
356
  }
355
357
  }
356
358
  };
357
- return s.pushUndoRedo({
359
+ return m.pushUndoRedo({
358
360
  undoMutations: [C],
359
361
  redoMutations: [i],
360
362
  unitID: n
361
- }), m.executeCommand(i.id, i.params), !0;
363
+ }), s.executeCommand(i.id, i.params), !0;
362
364
  }
363
365
  };
364
366
  l.COMMAND;
@@ -368,8 +370,8 @@ const ne = {
368
370
  async handler(r, e) {
369
371
  if (!e)
370
372
  return !1;
371
- const { unitId: n, subUnitId: t, resolved: o, commentId: m } = e, s = r.get(f), d = r.get(h).getComment(n, t, m);
372
- return !d || !await s.updateComment({
373
+ const { unitId: n, subUnitId: t, resolved: o, commentId: s } = e, m = r.get(f), d = r.get(h).getComment(n, t, s);
374
+ return !d || !await m.updateComment({
373
375
  ...d,
374
376
  resolved: o
375
377
  }) ? !1 : (r.get(M).executeCommand(
@@ -383,7 +385,7 @@ const ne = {
383
385
  async handler(r, e) {
384
386
  if (!e)
385
387
  return !1;
386
- const n = r.get(h), t = r.get(f), o = r.get(M), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getComment(s, a, d);
388
+ const n = r.get(h), t = r.get(f), o = r.get(M), s = r.get(S), { unitId: m, subUnitId: a, commentId: d } = e, c = n.getComment(m, a, d);
387
389
  if (!c || !await t.deleteComment(d))
388
390
  return !1;
389
391
  const u = {
@@ -392,15 +394,15 @@ const ne = {
392
394
  }, i = {
393
395
  id: T.id,
394
396
  params: {
395
- unitId: s,
397
+ unitId: m,
396
398
  subUnitId: a,
397
399
  comment: c
398
400
  }
399
401
  };
400
- return m.pushUndoRedo({
402
+ return s.pushUndoRedo({
401
403
  undoMutations: [i],
402
404
  redoMutations: [u],
403
- unitID: s
405
+ unitID: m
404
406
  }), o.executeCommand(u.id, u.params);
405
407
  }
406
408
  }, re = {
@@ -409,7 +411,7 @@ const ne = {
409
411
  async handler(r, e) {
410
412
  if (!e)
411
413
  return !1;
412
- const n = r.get(h), t = r.get(M), o = r.get(f), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getCommentWithChildren(s, a, d);
414
+ const n = r.get(h), t = r.get(M), o = r.get(f), s = r.get(S), { unitId: m, subUnitId: a, commentId: d } = e, c = n.getCommentWithChildren(m, a, d);
413
415
  if (!c)
414
416
  return !1;
415
417
  const u = [c.root, ...c.children];
@@ -418,28 +420,28 @@ const ne = {
418
420
  const i = u.map((v) => ({
419
421
  id: y.id,
420
422
  params: {
421
- unitId: s,
423
+ unitId: m,
422
424
  subUnitId: a,
423
425
  commentId: v.id
424
426
  }
425
427
  })), C = u.map((v) => ({
426
428
  id: T.id,
427
429
  params: {
428
- unitId: s,
430
+ unitId: m,
429
431
  subUnitId: a,
430
432
  comment: v
431
433
  }
432
434
  })), _ = G(i, t);
433
- return _.result && m.pushUndoRedo({
435
+ return _.result && s.pushUndoRedo({
434
436
  undoMutations: C,
435
437
  redoMutations: i,
436
- unitID: s
438
+ unitID: m
437
439
  }), _.result;
438
440
  }
439
441
  };
440
442
  var me = Object.defineProperty, se = Object.getOwnPropertyDescriptor, ae = (r, e, n, t) => {
441
- for (var o = t > 1 ? void 0 : t ? se(e, n) : e, m = r.length - 1, s; m >= 0; m--)
442
- (s = r[m]) && (o = (t ? s(e, n, o) : s(o)) || o);
443
+ for (var o = t > 1 ? void 0 : t ? se(e, n) : e, s = r.length - 1, m; s >= 0; s--)
444
+ (m = r[s]) && (o = (t ? m(e, n, o) : m(o)) || o);
443
445
  return t && o && me(e, n, o), o;
444
446
  }, $ = (r, e) => (n, t) => e(n, t, r), I;
445
447
  let D = (I = class extends B {
@@ -18,6 +18,7 @@ export interface IUpdateCommentMutationParams {
18
18
  unitId: string;
19
19
  subUnitId: string;
20
20
  payload: IUpdateCommentPayload;
21
+ silent?: boolean;
21
22
  }
22
23
  export declare const UpdateCommentMutation: ICommand<IUpdateCommentMutationParams>;
23
24
  export interface IUpdateCommentRefPayload {
@@ -28,6 +29,7 @@ export interface IUpdateCommentRefMutationParams {
28
29
  unitId: string;
29
30
  subUnitId: string;
30
31
  payload: IUpdateCommentRefPayload;
32
+ silent?: boolean;
31
33
  }
32
34
  export declare const UpdateCommentRefMutation: ICommand<IUpdateCommentRefMutationParams>;
33
35
  export interface IResolveCommentMutationParams {
@@ -4,16 +4,14 @@ import { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mut
4
4
  export type CommentUpdate = {
5
5
  unitId: string;
6
6
  subUnitId: string;
7
+ silent?: boolean;
8
+ } & ({
7
9
  type: 'add';
8
10
  payload: IThreadComment;
9
11
  } | {
10
- unitId: string;
11
- subUnitId: string;
12
12
  type: 'update';
13
13
  payload: IUpdateCommentPayload;
14
14
  } | {
15
- unitId: string;
16
- subUnitId: string;
17
15
  type: 'delete';
18
16
  payload: {
19
17
  commentId: string;
@@ -21,19 +19,15 @@ export type CommentUpdate = {
21
19
  comment: IThreadComment;
22
20
  };
23
21
  } | {
24
- unitId: string;
25
- subUnitId: string;
26
22
  type: 'updateRef';
27
23
  payload: IUpdateCommentRefPayload;
28
24
  } | {
29
- unitId: string;
30
- subUnitId: string;
31
25
  type: 'resolve';
32
26
  payload: {
33
27
  commentId: string;
34
28
  resolved: boolean;
35
29
  };
36
- };
30
+ });
37
31
  export declare class ThreadCommentModel {
38
32
  private _commentsMap;
39
33
  private _commentsTreeMap;
@@ -52,8 +46,8 @@ export declare class ThreadCommentModel {
52
46
  commentChildrenMap: Map<string, string[]>;
53
47
  };
54
48
  addComment(unitId: string, subUnitId: string, comment: IThreadComment): boolean;
55
- updateComment(unitId: string, subUnitId: string, payload: IUpdateCommentPayload): boolean;
56
- updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload): boolean;
49
+ updateComment(unitId: string, subUnitId: string, payload: IUpdateCommentPayload, silent?: boolean): boolean;
50
+ updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload, silent?: boolean): boolean;
57
51
  resolveComment(unitId: string, subUnitId: string, commentId: string, resolved: boolean): boolean;
58
52
  getComment(unitId: string, subUnitId: string, commentId: string): IThreadComment | undefined;
59
53
  getComment$(unitId: string, subUnitId: string, commentId: string): import('rxjs').Observable<IThreadComment>;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,h,d,U){"use strict";var B=Object.defineProperty;var K=(s,h,d)=>h in s?B(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var f=(s,h,d)=>(K(s,typeof h!="symbol"?h+"":h,d),d);var y;class l{constructor(){f(this,"_commentsMap",{});f(this,"_commentsTreeMap",new Map);f(this,"_commentUpdate$",new h.Subject);f(this,"_commentsTreeMap$",new h.BehaviorSubject({}));f(this,"_commentsMap$",new h.BehaviorSubject({}));f(this,"commentUpdate$",this._commentUpdate$.asObservable());f(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());f(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((r,a)=>{n[a]={};const i=n[a];r.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m);let a=e.parentId;if(a){let i=n[a];for(;i!=null&&i.parentId;)i=n[i.parentId],a=i.parentId;if(i){let c=r.get(a);c||(c=[]),c.push(e.id),r.set(a,c)}}else r.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:r}=this.ensureMap(t,m),a=r[e];return a?(a.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var p;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return;const i=new Set,c=(p=r.get(e))!=null?p:[],u=c==null?void 0:c.map(C=>n[C]);return[a,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:a,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return!1;if(a.parentId){const i=r.get(a.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],r.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(r=>{this.deleteComment(t,e,r.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var D=(o=>(o[o.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",o[o.UNIVER_DOC=1]="UNIVER_DOC",o[o.UNIVER_SHEET=2]="UNIVER_SHEET",o[o.UNIVER_SLIDE=3]="UNIVER_SLIDE",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const M=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(o,t,m,e)=>{for(var n=e>1?void 0:e?W(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&V(t,m,n),n},N=(o,t)=>(m,e)=>t(m,e,o);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),r={};return n?(n.forEach(([a,i])=>{r[a]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(e,a,c)})})}}))}},s.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(l)),N(2,M)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,comment:r}=t;return m.addComment(e,n,r)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateComment(e,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateCommentRef(e,n,r)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,resolved:r,commentId:a}=t;return m.resolveComment(e,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,commentId:r}=t;return m.deleteComment(e,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(d.ICommandService),e=o.get(d.IUndoRedoService),n=o.get(M),{unitId:r,subUnitId:a,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return e.pushUndoRedo({undoMutations:[p],redoMutations:[u],unitID:r}),m.executeCommand(u.id,u.params),!0}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,r=o.get(d.ICommandService),a=o.get(d.IUndoRedoService),i=o.get(l),c=o.get(M),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return a.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),r.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:r}=t,a=o.get(M),c=o.get(l).getComment(m,e,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(o.get(d.ICommandService).executeCommand(O.id,t),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(M),n=o.get(d.ICommandService),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getComment(a,i,c);if(!u||!await e.deleteComment(c))return!1;const p={id:T.id,params:t},C={id:S.id,params:{unitId:a,subUnitId:i,comment:u}};return r.pushUndoRedo({undoMutations:[C],redoMutations:[p],unitID:a}),n.executeCommand(p.id,p.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(d.ICommandService),n=o.get(M),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(a,i,c);if(!u)return!1;const p=[u.root,...u.children];if(!await n.deleteCommentBatch(p.map(g=>g.id)))return!1;const C=p.map(g=>({id:T.id,params:{unitId:a,subUnitId:i,commentId:g.id}})),_=p.map(g=>({id:S.id,params:{unitId:a,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&r.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:a}),I.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(o,t,m,e)=>{for(var n=e>1?void 0:e?H(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&G(t,m,n),n},L=(o,t)=>(m,e)=>t(m,e,o);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();f(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){var e;d.mergeOverrideWithDependencies([[l],[s.ThreadCommentResourceController],[M,{useClass:$}]],(e=this._config)==null?void 0:e.overrides).forEach(n=>{m.add(n)}),[b,w,P,A,j,S,v,E,T,O].forEach(n=>{this._commandService.registerCommand(n)})}},f(y,"pluginName",R),f(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=q([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=b,s.AddCommentMutation=S,s.DeleteCommentCommand=P,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=j,s.IThreadCommentDataSourceService=M,s.ResolveCommentCommand=A,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=$,s.ThreadCommentModel=l,s.UpdateCommentCommand=w,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,h,d,U){"use strict";var B=Object.defineProperty;var K=(s,h,d)=>h in s?B(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var f=(s,h,d)=>(K(s,typeof h!="symbol"?h+"":h,d),d);var y;class p{constructor(){f(this,"_commentsMap",{});f(this,"_commentsTreeMap",new Map);f(this,"_commentUpdate$",new h.Subject);f(this,"_commentsTreeMap$",new h.BehaviorSubject({}));f(this,"_commentsMap$",new h.BehaviorSubject({}));f(this,"commentUpdate$",this._commentUpdate$.asObservable());f(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());f(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((a,o)=>{n[o]={};const i=n[o];a.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m);let o=e.parentId;if(o){let i=n[o];for(;i!=null&&i.parentId;)i=n[i.parentId],o=i.parentId;if(i){let c=a.get(o);c||(c=[]),c.push(e.id),a.set(o,c)}}else a.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e.commentId];return o?(o.updated=!0,o.text=e.text,o.attachments=e.attachments,o.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e.commentId];return o?(o.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e];return o?(o.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var l;const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m),o=n[e];if(!o)return;const i=new Set,c=(l=a.get(e))!=null?l:[],u=c==null?void 0:c.map(C=>n[C]);return[o,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:o,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m),o=n[e];if(!o)return!1;if(o.parentId){const i=a.get(o.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],a.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!o.parentId,comment:o}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(a=>{this.deleteComment(t,e,a.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var D=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const M=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(r,t,m,e)=>{for(var n=e>1?void 0:e?W(t,m):t,a=r.length-1,o;a>=0;a--)(o=r[a])&&(n=(e?o(t,m,n):o(n))||n);return e&&n&&V(t,m,n),n},N=(r,t)=>(m,e)=>t(m,e,r);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),a={};return n?(n.forEach(([o,i])=>{a[o]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(a))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const a=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(a).forEach(o=>{n[o].forEach(c=>{this._threadCommentModel.addComment(e,o,c)})})}}))}},s.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(p)),N(2,M)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,comment:a}=t;return m.addComment(e,n,a)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,payload:a,silent:o}=t;return m.updateComment(e,n,a,o)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,payload:a,silent:o}=t;return m.updateCommentRef(e,n,a,o)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,resolved:a,commentId:o}=t;return m.resolveComment(e,n,o,a)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,commentId:a}=t;return m.deleteComment(e,n,a)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(d.ICommandService),e=r.get(d.IUndoRedoService),n=r.get(M),{unitId:a,subUnitId:o,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},l={id:T.id,params:{unitId:a,subUnitId:o,commentId:c.id}};return e.pushUndoRedo({undoMutations:[l],redoMutations:[u],unitID:a}),m.executeCommand(u.id,u.params),!0}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,a=r.get(d.ICommandService),o=r.get(d.IUndoRedoService),i=r.get(p),c=r.get(M),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return o.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),a.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:a}=t,o=r.get(M),c=r.get(p).getComment(m,e,a);return!c||!await o.updateComment({...c,resolved:n})?!1:(r.get(d.ICommandService).executeCommand(O.id,t),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(p),e=r.get(M),n=r.get(d.ICommandService),a=r.get(d.IUndoRedoService),{unitId:o,subUnitId:i,commentId:c}=t,u=m.getComment(o,i,c);if(!u||!await e.deleteComment(c))return!1;const l={id:T.id,params:t},C={id:S.id,params:{unitId:o,subUnitId:i,comment:u}};return a.pushUndoRedo({undoMutations:[C],redoMutations:[l],unitID:o}),n.executeCommand(l.id,l.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(p),e=r.get(d.ICommandService),n=r.get(M),a=r.get(d.IUndoRedoService),{unitId:o,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(o,i,c);if(!u)return!1;const l=[u.root,...u.children];if(!await n.deleteCommentBatch(l.map(g=>g.id)))return!1;const C=l.map(g=>({id:T.id,params:{unitId:o,subUnitId:i,commentId:g.id}})),_=l.map(g=>({id:S.id,params:{unitId:o,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&a.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:o}),I.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(r,t,m,e)=>{for(var n=e>1?void 0:e?H(t,m):t,a=r.length-1,o;a>=0;a--)(o=r[a])&&(n=(e?o(t,m,n):o(n))||n);return e&&n&&G(t,m,n),n},L=(r,t)=>(m,e)=>t(m,e,r);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();f(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){var e;d.mergeOverrideWithDependencies([[p],[s.ThreadCommentResourceController],[M,{useClass:$}]],(e=this._config)==null?void 0:e.overrides).forEach(n=>{m.add(n)}),[b,w,P,A,j,S,v,E,T,O].forEach(n=>{this._commandService.registerCommand(n)})}},f(y,"pluginName",R),f(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=q([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=b,s.AddCommentMutation=S,s.DeleteCommentCommand=P,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=j,s.IThreadCommentDataSourceService=M,s.ResolveCommentCommand=A,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=$,s.ThreadCommentModel=p,s.UpdateCommentCommand=w,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/thread-comment",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "private": false,
5
5
  "description": "Univer thread comment core plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -47,23 +47,23 @@
47
47
  "lib"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@wendellhu/redi": "0.15.2",
50
+ "@wendellhu/redi": "0.15.4",
51
51
  "rxjs": ">=7.0.0",
52
- "@univerjs/core": "0.1.14"
52
+ "@univerjs/core": "0.1.15"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/protocol": "^0.1.36"
55
+ "@univerjs/protocol": "0.1.38-alpha.3"
56
56
  },
57
57
  "devDependencies": {
58
- "@wendellhu/redi": "0.15.2",
58
+ "@wendellhu/redi": "0.15.4",
59
59
  "rxjs": "^7.8.1",
60
60
  "typescript": "^5.4.5",
61
- "vite": "^5.2.12",
61
+ "vite": "^5.2.13",
62
62
  "vitest": "^1.6.0",
63
- "@univerjs/design": "0.1.14",
64
- "@univerjs/shared": "0.1.14",
65
- "@univerjs/ui": "0.1.14",
66
- "@univerjs/core": "0.1.14"
63
+ "@univerjs/core": "0.1.15",
64
+ "@univerjs/shared": "0.1.15",
65
+ "@univerjs/design": "0.1.15",
66
+ "@univerjs/ui": "0.1.15"
67
67
  },
68
68
  "univerSpace": {
69
69
  ".": {
@@ -83,6 +83,7 @@
83
83
  "test:watch": "vitest",
84
84
  "coverage": "vitest run --coverage",
85
85
  "lint:types": "tsc --noEmit",
86
- "build": "tsc && vite build"
86
+ "build": "tsc && vite build",
87
+ "sync:cnpm": "cnpm sync"
87
88
  }
88
89
  }