@univerjs/thread-comment 0.2.3 → 0.2.4-alpha.0

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