@univerjs/thread-comment 0.2.3 → 0.2.4

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