@univerjs/thread-comment 0.1.12 → 0.1.13-nightly.202406041140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var L=(m,e,o)=>e in m?j(m,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[e]=o;var C=(m,e,o)=>(L(m,typeof e!="symbol"?e+"":e,o),o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("rxjs"),d=require("@univerjs/core"),U=require("@wendellhu/redi");class h{constructor(){C(this,"_commentsMap",{});C(this,"_commentsTreeMap",new Map);C(this,"_commentUpdate$",new S.Subject);C(this,"_commentsTreeMap$",new S.BehaviorSubject({}));C(this,"_commentsMap$",new S.BehaviorSubject({}));C(this,"commentUpdate$",this._commentUpdate$.asObservable());C(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());C(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(e,o){let t=this._commentsMap[e];t||(t={},this._commentsMap[e]=t);let n=t[o];return n||(n={},t[o]=n),n}_ensureCommentChildrenMap(e,o){let t=this._commentsTreeMap.get(e);t||(t=new Map,this._commentsTreeMap.set(e,t));let n=t.get(o);return n||(n=new Map,t.set(o,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const e={};this._commentsTreeMap.forEach((o,t)=>{e[t]={};const n=e[t];o.forEach((r,a)=>{n[a]={};const s=n[a];r.forEach((c,i)=>{s[i]=c})})}),this._commentsTreeMap$.next(e)}ensureMap(e,o){const t=this._ensureCommentMap(e,o),n=this._ensureCommentChildrenMap(e,o);return{commentMap:t,commentChildrenMap:n}}addComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o);let a=t.parentId;if(a){let s=n[a];for(;s!=null&&s.parentId;)s=n[s.parentId],a=s.parentId;if(s){let c=r.get(a);c||(c=[]),c.push(t.id),r.set(a,c)}}else r.set(t.id,[]);return n[t.id]=t,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"add",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.updated=!0,r.text=t.text,r.attachments=t.attachments,r.updateT=t.updateT,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"update",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.ref=t.ref,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"updateRef",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(e,o,t,n){const{commentMap:r}=this.ensureMap(e,o),a=r[t];return a?(a.resolved=n,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"resolve",payload:{commentId:t,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o);return n[t]}getComment$(e,o,t){return this._commentsMap$.pipe(S.map(n=>n[e][o][t]))}getCommentWithChildren(e,o,t){var p;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return;const s=new Set,c=(p=r.get(t))!=null?p:[],i=c==null?void 0:c.map(u=>n[u]);return[a,...i].forEach(u=>{var M;s.add(u.personId),(M=u.text.customRanges)==null||M.forEach(_=>{_.rangeType===d.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:a,children:i,relativeUsers:s}}deleteComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return!1;if(a.parentId){const s=r.get(a.parentId);if(s){const c=s.indexOf(t);s.splice(c,1)}delete n[t]}else delete n[t],r.delete(t);return this._commentUpdate$.next({unitId:e,subUnitId:o,type:"delete",payload:{commentId:t,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(e){const o=this._commentsMap[e];return o?Array.from(Object.entries(o)).map(([t,n])=>[t,Array.from(Object.values(n))]):[]}deleteUnit(e){const o=this._commentsMap[e];o&&Object.entries(o).forEach(([t,n])=>{Object.values(n).forEach(r=>{this.deleteComment(e,t,r.id)})})}getRootCommentIds(e,o){const t=this._ensureCommentChildrenMap(e,o);return Array.from(t.keys())}getRootCommentIds$(e,o){return this._commentsTreeMap$.pipe(S.map(t=>{var n;return Object.keys((n=t[e])==null?void 0:n[o])}))}getAll(){return this._commentsMap}}var D=(m=>(m[m.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",m[m.UNIVER_DOC=1]="UNIVER_DOC",m[m.UNIVER_SHEET=2]="UNIVER_SHEET",m[m.UNIVER_SLIDE=3]="UNIVER_SLIDE",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(e){return e}async updateComment(e){return!0}async deleteComment(e){return!0}async deleteCommentBatch(e){return!0}async loadFormSnapshot(e){return e}saveToSnapshot(e){return e}}const l=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(m,e,o,t)=>{for(var n=t>1?void 0:t?W(e,o):e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(n))||n);return t&&n&&V(e,o,n),n},y=(m,e)=>(o,t)=>e(o,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(e,o,t){super(),this._resourceManagerService=e,this._threadCommentModel=o,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const e=t=>{const n=this._threadCommentModel.getUnit(t),r={};return n?(n.forEach(([a,s])=>{r[a]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},o=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:t=>e(t),parseJson:t=>o(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(t,a,c)})})}}))}};exports.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,exports.ThreadCommentResourceController),y(0,d.IResourceManagerService),y(1,U.Inject(h)),y(2,l)],exports.ThreadCommentResourceController);const I={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,comment:r}=e;return o.addComment(t,n,r)}},f={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:r}=e;return o.updateComment(t,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:r}=e;return o.updateCommentRef(t,n,r)}},N={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,resolved:r,commentId:a}=e;return o.resolveComment(t,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,commentId:r}=e;return o.deleteComment(t,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(d.ICommandService),t=m.get(d.IUndoRedoService),n=m.get(l),{unitId:r,subUnitId:a,comment:s}=e,c=await n.addComment(s),i={id:I.id,params:e},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return t.pushUndoRedo({undoMutations:[p],redoMutations:[i],unitID:r}),o.executeCommand(i.id,i.params),!0}},x={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,payload:n}=e,r=m.get(d.ICommandService),a=m.get(d.IUndoRedoService),s=m.get(h),c=m.get(l),i=s.getComment(o,t,n.commentId);if(!i||!await c.updateComment({...i,...n}))return!1;const u={id:f.id,params:e},M={id:f.id,params:{unitId:o,subUnitId:t,payload:{commentId:n.commentId,text:i.text,attachments:i.attachments,updateT:i.updateT,updated:i.updated}}};return a.pushUndoRedo({undoMutations:[M],redoMutations:[u],unitID:o}),r.executeCommand(u.id,u.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,resolved:n,commentId:r}=e,a=m.get(l),c=m.get(h).getComment(o,t,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(m.get(d.ICommandService).executeCommand(N.id,e),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(l),n=m.get(d.ICommandService),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getComment(a,s,c);if(!i||!await t.deleteComment(c))return!1;const p={id:T.id,params:e},u={id:I.id,params:{unitId:a,subUnitId:s,comment:i}};return r.pushUndoRedo({undoMutations:[u],redoMutations:[p],unitID:a}),n.executeCommand(p.id,p.params)}},w={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(d.ICommandService),n=m.get(l),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getCommentWithChildren(a,s,c);if(!i)return!1;const p=[i.root,...i.children];if(!await n.deleteCommentBatch(p.map(v=>v.id)))return!1;const u=p.map(v=>({id:T.id,params:{unitId:a,subUnitId:s,commentId:v.id}})),M=p.map(v=>({id:I.id,params:{unitId:a,subUnitId:s,comment:v}})),_=d.sequenceExecute(u,t);return _.result&&r.pushUndoRedo({undoMutations:M,redoMutations:u,unitID:a}),_.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(m,e,o,t)=>{for(var n=t>1?void 0:t?H(e,o):e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(n))||n);return t&&n&&G(e,o,n),n},O=(m,e)=>(o,t)=>e(o,t,m),g;exports.UniverThreadCommentPlugin=(g=class extends d.Plugin{constructor(o,t,n){super();C(this,"_config");this._injector=t,this._commandService=n,this._config=o}onStarting(o){d.mergeOverrideWithDependencies([[h],[exports.ThreadCommentResourceController],[l,{useClass:$}]],this._config.overrides).forEach(t=>{o.add(t)}),[b,x,P,A,w,I,f,E,T,N].forEach(t=>{this._commandService.registerCommand(t)})}},C(g,"pluginName",R),C(g,"type",d.UniverInstanceType.UNIVER_UNKNOWN),g);exports.UniverThreadCommentPlugin=q([O(1,U.Inject(U.Injector)),O(2,d.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=b;exports.AddCommentMutation=I;exports.DeleteCommentCommand=P;exports.DeleteCommentMutation=T;exports.DeleteCommentTreeCommand=w;exports.IThreadCommentDataSourceService=l;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=N;exports.TC_PLUGIN_NAME=R;exports.ThreadCommentDataSourceService=$;exports.ThreadCommentModel=h;exports.UpdateCommentCommand=x;exports.UpdateCommentMutation=f;exports.UpdateCommentRefMutation=E;
1
+ "use strict";var P=Object.defineProperty;var L=(m,e,o)=>e in m?P(m,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[e]=o;var p=(m,e,o)=>(L(m,typeof e!="symbol"?e+"":e,o),o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("rxjs"),d=require("@univerjs/core"),U=require("@wendellhu/redi");class C{constructor(){p(this,"_commentsMap",{});p(this,"_commentsTreeMap",new Map);p(this,"_commentUpdate$",new S.Subject);p(this,"_commentsTreeMap$",new S.BehaviorSubject({}));p(this,"_commentsMap$",new S.BehaviorSubject({}));p(this,"commentUpdate$",this._commentUpdate$.asObservable());p(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());p(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(e,o){let t=this._commentsMap[e];t||(t={},this._commentsMap[e]=t);let n=t[o];return n||(n={},t[o]=n),n}_ensureCommentChildrenMap(e,o){let t=this._commentsTreeMap.get(e);t||(t=new Map,this._commentsTreeMap.set(e,t));let n=t.get(o);return n||(n=new Map,t.set(o,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const e={};this._commentsTreeMap.forEach((o,t)=>{e[t]={};const n=e[t];o.forEach((r,a)=>{n[a]={};const s=n[a];r.forEach((c,i)=>{s[i]=c})})}),this._commentsTreeMap$.next(e)}ensureMap(e,o){const t=this._ensureCommentMap(e,o),n=this._ensureCommentChildrenMap(e,o);return{commentMap:t,commentChildrenMap:n}}addComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o);let a=t.parentId;if(a){let s=n[a];for(;s!=null&&s.parentId;)s=n[s.parentId],a=s.parentId;if(s){let c=r.get(a);c||(c=[]),c.push(t.id),r.set(a,c)}}else r.set(t.id,[]);return n[t.id]=t,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"add",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.updated=!0,r.text=t.text,r.attachments=t.attachments,r.updateT=t.updateT,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"update",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.ref=t.ref,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"updateRef",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(e,o,t,n){const{commentMap:r}=this.ensureMap(e,o),a=r[t];return a?(a.resolved=n,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"resolve",payload:{commentId:t,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o);return n[t]}getComment$(e,o,t){return this._commentsMap$.pipe(S.map(n=>n[e][o][t]))}getCommentWithChildren(e,o,t){var h;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return;const s=new Set,c=(h=r.get(t))!=null?h:[],i=c==null?void 0:c.map(u=>n[u]);return[a,...i].forEach(u=>{var M;s.add(u.personId),(M=u.text.customRanges)==null||M.forEach(_=>{_.rangeType===d.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:a,children:i,relativeUsers:s}}deleteComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return!1;if(a.parentId){const s=r.get(a.parentId);if(s){const c=s.indexOf(t);s.splice(c,1)}delete n[t]}else delete n[t],r.delete(t);return this._commentUpdate$.next({unitId:e,subUnitId:o,type:"delete",payload:{commentId:t,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(e){const o=this._commentsMap[e];return o?Array.from(Object.entries(o)).map(([t,n])=>[t,Array.from(Object.values(n))]):[]}deleteUnit(e){const o=this._commentsMap[e];o&&Object.entries(o).forEach(([t,n])=>{Object.values(n).forEach(r=>{this.deleteComment(e,t,r.id)})})}getRootCommentIds(e,o){const t=this._ensureCommentChildrenMap(e,o);return Array.from(t.keys())}getRootCommentIds$(e,o){return this._commentsTreeMap$.pipe(S.map(t=>{var n;return Object.keys((n=t[e])==null?void 0:n[o])}))}getAll(){return this._commentsMap}}var $=(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))($||{});const R="THREAD_COMMENT_PLUGIN";class D{async addComment(e){return e}async updateComment(e){return!0}async deleteComment(e){return!0}async deleteCommentBatch(e){return!0}async loadFormSnapshot(e){return e}saveToSnapshot(e){return e}}const l=U.createIdentifier("univer.thread-comment.data-source-service");var V=(m,e,o,t)=>{for(var n=e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=a(n)||n);return n},y=(m,e)=>(o,t)=>e(o,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(e,o,t){super(),this._resourceManagerService=e,this._threadCommentModel=o,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const e=t=>{const n=this._threadCommentModel.getUnit(t),r={};return n?(n.forEach(([a,s])=>{r[a]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},o=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[$.UNIVER_SHEET],toJson:t=>e(t),parseJson:t=>o(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(t,a,c)})})}}))}};exports.ThreadCommentResourceController=V([d.OnLifecycle(d.LifecycleStages.Starting,exports.ThreadCommentResourceController),y(0,d.IResourceManagerService),y(1,U.Inject(C)),y(2,l)],exports.ThreadCommentResourceController);const g={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(C),{unitId:t,subUnitId:n,comment:r}=e;return o.addComment(t,n,r)}},f={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(C),{unitId:t,subUnitId:n,payload:r}=e;return o.updateComment(t,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(C),{unitId:t,subUnitId:n,payload:r}=e;return o.updateCommentRef(t,n,r)}},N={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(C),{unitId:t,subUnitId:n,resolved:r,commentId:a}=e;return o.resolveComment(t,n,a,r)}},I={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(C),{unitId:t,subUnitId:n,commentId:r}=e;return o.deleteComment(t,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(d.ICommandService),t=m.get(d.IUndoRedoService),n=m.get(l),{unitId:r,subUnitId:a,comment:s}=e,c=await n.addComment(s),i={id:g.id,params:e},h={id:I.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return t.pushUndoRedo({undoMutations:[h],redoMutations:[i],unitID:r}),o.executeCommand(i.id,i.params),!0}},x={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,payload:n}=e,r=m.get(d.ICommandService),a=m.get(d.IUndoRedoService),s=m.get(C),c=m.get(l),i=s.getComment(o,t,n.commentId);if(!i||!await c.updateComment({...i,...n}))return!1;const u={id:f.id,params:e},M={id:f.id,params:{unitId:o,subUnitId:t,payload:{commentId:n.commentId,text:i.text,attachments:i.attachments,updateT:i.updateT,updated:i.updated}}};return a.pushUndoRedo({undoMutations:[M],redoMutations:[u],unitID:o}),r.executeCommand(u.id,u.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,resolved:n,commentId:r}=e,a=m.get(l),c=m.get(C).getComment(o,t,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(m.get(d.ICommandService).executeCommand(N.id,e),!0)}},w={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(C),t=m.get(l),n=m.get(d.ICommandService),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getComment(a,s,c);if(!i||!await t.deleteComment(c))return!1;const h={id:I.id,params:e},u={id:g.id,params:{unitId:a,subUnitId:s,comment:i}};return r.pushUndoRedo({undoMutations:[u],redoMutations:[h],unitID:a}),n.executeCommand(h.id,h.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(C),t=m.get(d.ICommandService),n=m.get(l),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getCommentWithChildren(a,s,c);if(!i)return!1;const h=[i.root,...i.children];if(!await n.deleteCommentBatch(h.map(v=>v.id)))return!1;const u=h.map(v=>({id:I.id,params:{unitId:a,subUnitId:s,commentId:v.id}})),M=h.map(v=>({id:g.id,params:{unitId:a,subUnitId:s,comment:v}})),_=d.sequenceExecute(u,t);return _.result&&r.pushUndoRedo({undoMutations:M,redoMutations:u,unitID:a}),_.result}};var W=(m,e,o,t)=>{for(var n=e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=a(n)||n);return n},O=(m,e)=>(o,t)=>e(o,t,m),T;exports.UniverThreadCommentPlugin=(T=class extends d.Plugin{constructor(o,t,n){super();p(this,"_config");this._injector=t,this._commandService=n,this._config=o}onStarting(o){var t;d.mergeOverrideWithDependencies([[C],[exports.ThreadCommentResourceController],[l,{useClass:D}]],(t=this._config)==null?void 0:t.overrides).forEach(n=>{o.add(n)}),[b,x,w,A,j,g,f,E,I,N].forEach(n=>{this._commandService.registerCommand(n)})}},p(T,"pluginName",R),p(T,"type",d.UniverInstanceType.UNIVER_UNKNOWN),T);exports.UniverThreadCommentPlugin=W([O(1,U.Inject(U.Injector)),O(2,d.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=b;exports.AddCommentMutation=g;exports.DeleteCommentCommand=w;exports.DeleteCommentMutation=I;exports.DeleteCommentTreeCommand=j;exports.IThreadCommentDataSourceService=l;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=N;exports.TC_PLUGIN_NAME=R;exports.ThreadCommentDataSourceService=D;exports.ThreadCommentModel=C;exports.UpdateCommentCommand=x;exports.UpdateCommentMutation=f;exports.UpdateCommentRefMutation=E;
package/lib/es/index.js CHANGED
@@ -1,31 +1,31 @@
1
- var A = Object.defineProperty;
2
- var P = (r, e, t) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var p = (r, e, t) => (P(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { Subject as j, BehaviorSubject as O, map as R } from "rxjs";
5
- import { CustomRangeType as L, Disposable as V, OnLifecycle as W, LifecycleStages as J, IResourceManagerService as H, CommandType as l, ICommandService as M, IUndoRedoService as S, sequenceExecute as G, Plugin as B, UniverInstanceType as K, mergeOverrideWithDependencies as F } from "@univerjs/core";
6
- import { createIdentifier as Z, Inject as E, Injector as q } from "@wendellhu/redi";
7
- class h {
1
+ var w = Object.defineProperty;
2
+ var j = (r, e, n) => e in r ? w(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
+ var h = (r, e, n) => (j(r, typeof e != "symbol" ? e + "" : e, n), n);
4
+ import { Subject as L, BehaviorSubject as R, map as $ } from "rxjs";
5
+ import { CustomRangeType as V, Disposable as W, OnLifecycle as k, LifecycleStages as P, IResourceManagerService as J, CommandType as l, ICommandService as f, IUndoRedoService as S, sequenceExecute as H, Plugin as G, UniverInstanceType as B, mergeOverrideWithDependencies as K } from "@univerjs/core";
6
+ import { createIdentifier as F, Inject as D, Injector as Z } from "@wendellhu/redi";
7
+ class p {
8
8
  constructor() {
9
- p(this, "_commentsMap", {});
10
- p(this, "_commentsTreeMap", /* @__PURE__ */ new Map());
11
- p(this, "_commentUpdate$", new j());
12
- p(this, "_commentsTreeMap$", new O({}));
13
- p(this, "_commentsMap$", new O({}));
14
- p(this, "commentUpdate$", this._commentUpdate$.asObservable());
15
- p(this, "commentTreeMap$", this._commentsTreeMap$.asObservable());
16
- p(this, "commentMap$", this._commentsMap$.asObservable());
17
- }
18
- _ensureCommentMap(e, t) {
19
- let n = this._commentsMap[e];
20
- n || (n = {}, this._commentsMap[e] = n);
21
- let o = n[t];
22
- return o || (o = {}, n[t] = o), o;
23
- }
24
- _ensureCommentChildrenMap(e, t) {
25
- let n = this._commentsTreeMap.get(e);
26
- n || (n = /* @__PURE__ */ new Map(), this._commentsTreeMap.set(e, n));
27
- let o = n.get(t);
28
- return o || (o = /* @__PURE__ */ new Map(), n.set(t, o)), o;
9
+ h(this, "_commentsMap", {});
10
+ h(this, "_commentsTreeMap", /* @__PURE__ */ new Map());
11
+ h(this, "_commentUpdate$", new L());
12
+ h(this, "_commentsTreeMap$", new R({}));
13
+ h(this, "_commentsMap$", new R({}));
14
+ h(this, "commentUpdate$", this._commentUpdate$.asObservable());
15
+ h(this, "commentTreeMap$", this._commentsTreeMap$.asObservable());
16
+ h(this, "commentMap$", this._commentsMap$.asObservable());
17
+ }
18
+ _ensureCommentMap(e, n) {
19
+ let t = this._commentsMap[e];
20
+ t || (t = {}, this._commentsMap[e] = t);
21
+ let o = t[n];
22
+ return o || (o = {}, t[n] = o), o;
23
+ }
24
+ _ensureCommentChildrenMap(e, n) {
25
+ let t = this._commentsTreeMap.get(e);
26
+ t || (t = /* @__PURE__ */ new Map(), this._commentsTreeMap.set(e, t));
27
+ let o = t.get(n);
28
+ return o || (o = /* @__PURE__ */ new Map(), t.set(n, o)), o;
29
29
  }
30
30
  _refreshCommentsMap$() {
31
31
  this._commentsMap$.next({
@@ -34,10 +34,10 @@ class h {
34
34
  }
35
35
  _refreshCommentsTreeMap$() {
36
36
  const e = {};
37
- this._commentsTreeMap.forEach((t, n) => {
38
- e[n] = {};
39
- const o = e[n];
40
- t.forEach((m, s) => {
37
+ this._commentsTreeMap.forEach((n, t) => {
38
+ e[t] = {};
39
+ const o = e[t];
40
+ n.forEach((m, s) => {
41
41
  o[s] = {};
42
42
  const a = o[s];
43
43
  m.forEach((d, c) => {
@@ -46,80 +46,80 @@ class h {
46
46
  });
47
47
  }), this._commentsTreeMap$.next(e);
48
48
  }
49
- ensureMap(e, t) {
50
- const n = this._ensureCommentMap(e, t), o = this._ensureCommentChildrenMap(e, t);
49
+ ensureMap(e, n) {
50
+ const t = this._ensureCommentMap(e, n), o = this._ensureCommentChildrenMap(e, n);
51
51
  return {
52
- commentMap: n,
52
+ commentMap: t,
53
53
  commentChildrenMap: o
54
54
  };
55
55
  }
56
- addComment(e, t, n) {
57
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, t);
58
- let s = n.parentId;
56
+ addComment(e, n, t) {
57
+ const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n);
58
+ let s = t.parentId;
59
59
  if (s) {
60
60
  let a = o[s];
61
61
  for (; a != null && a.parentId; )
62
62
  a = o[a.parentId], s = a.parentId;
63
63
  if (a) {
64
64
  let d = m.get(s);
65
- d || (d = []), d.push(n.id), m.set(s, d);
65
+ d || (d = []), d.push(t.id), m.set(s, d);
66
66
  }
67
67
  } else
68
- m.set(n.id, []);
69
- return o[n.id] = n, this._commentUpdate$.next({
68
+ m.set(t.id, []);
69
+ return o[t.id] = t, this._commentUpdate$.next({
70
70
  unitId: e,
71
- subUnitId: t,
71
+ subUnitId: n,
72
72
  type: "add",
73
- payload: n
73
+ payload: t
74
74
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0;
75
75
  }
76
- updateComment(e, t, n) {
77
- const { commentMap: o } = this.ensureMap(e, t), m = o[n.commentId];
78
- return m ? (m.updated = !0, m.text = n.text, m.attachments = n.attachments, m.updateT = n.updateT, this._commentUpdate$.next({
76
+ updateComment(e, n, t) {
77
+ const { commentMap: o } = this.ensureMap(e, n), m = o[t.commentId];
78
+ return m ? (m.updated = !0, m.text = t.text, m.attachments = t.attachments, m.updateT = t.updateT, this._commentUpdate$.next({
79
79
  unitId: e,
80
- subUnitId: t,
80
+ subUnitId: n,
81
81
  type: "update",
82
- payload: n
82
+ payload: t
83
83
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
84
84
  }
85
- updateCommentRef(e, t, n) {
86
- const { commentMap: o } = this.ensureMap(e, t), m = o[n.commentId];
87
- return m ? (m.ref = n.ref, this._commentUpdate$.next({
85
+ updateCommentRef(e, n, t) {
86
+ const { commentMap: o } = this.ensureMap(e, n), m = o[t.commentId];
87
+ return m ? (m.ref = t.ref, this._commentUpdate$.next({
88
88
  unitId: e,
89
- subUnitId: t,
89
+ subUnitId: n,
90
90
  type: "updateRef",
91
- payload: n
91
+ payload: t
92
92
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
93
93
  }
94
- resolveComment(e, t, n, o) {
95
- const { commentMap: m } = this.ensureMap(e, t), s = m[n];
94
+ resolveComment(e, n, t, o) {
95
+ const { commentMap: m } = this.ensureMap(e, n), s = m[t];
96
96
  return s ? (s.resolved = o, this._commentUpdate$.next({
97
97
  unitId: e,
98
- subUnitId: t,
98
+ subUnitId: n,
99
99
  type: "resolve",
100
100
  payload: {
101
- commentId: n,
101
+ commentId: t,
102
102
  resolved: o
103
103
  }
104
104
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
105
105
  }
106
- getComment(e, t, n) {
107
- const { commentMap: o } = this.ensureMap(e, t);
108
- return o[n];
106
+ getComment(e, n, t) {
107
+ const { commentMap: o } = this.ensureMap(e, n);
108
+ return o[t];
109
109
  }
110
- getComment$(e, t, n) {
111
- return this._commentsMap$.pipe(R((o) => o[e][t][n]));
110
+ getComment$(e, n, t) {
111
+ return this._commentsMap$.pipe($((o) => o[e][n][t]));
112
112
  }
113
- getCommentWithChildren(e, t, n) {
113
+ getCommentWithChildren(e, n, t) {
114
114
  var u;
115
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, t), s = o[n];
115
+ const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n), s = o[t];
116
116
  if (!s)
117
117
  return;
118
- const a = /* @__PURE__ */ new Set(), d = (u = m.get(n)) != null ? u : [], c = d == null ? void 0 : d.map((i) => o[i]);
118
+ const a = /* @__PURE__ */ new Set(), d = (u = m.get(t)) != null ? u : [], c = d == null ? void 0 : d.map((i) => o[i]);
119
119
  return [s, ...c].forEach((i) => {
120
120
  var C;
121
121
  a.add(i.personId), (C = i.text.customRanges) == null || C.forEach((_) => {
122
- _.rangeType === L.MENTION && a.add(_.rangeId);
122
+ _.rangeType === V.MENTION && a.add(_.rangeId);
123
123
  });
124
124
  }), {
125
125
  root: s,
@@ -127,51 +127,51 @@ class h {
127
127
  relativeUsers: a
128
128
  };
129
129
  }
130
- deleteComment(e, t, n) {
131
- const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, t), s = o[n];
130
+ deleteComment(e, n, t) {
131
+ const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e, n), s = o[t];
132
132
  if (!s)
133
133
  return !1;
134
134
  if (s.parentId) {
135
135
  const a = m.get(s.parentId);
136
136
  if (a) {
137
- const d = a.indexOf(n);
137
+ const d = a.indexOf(t);
138
138
  a.splice(d, 1);
139
139
  }
140
- delete o[n];
140
+ delete o[t];
141
141
  } else
142
- delete o[n], m.delete(n);
142
+ delete o[t], m.delete(t);
143
143
  return this._commentUpdate$.next({
144
144
  unitId: e,
145
- subUnitId: t,
145
+ subUnitId: n,
146
146
  type: "delete",
147
147
  payload: {
148
- commentId: n,
148
+ commentId: t,
149
149
  isRoot: !s.parentId,
150
150
  comment: s
151
151
  }
152
152
  }), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0;
153
153
  }
154
154
  getUnit(e) {
155
- const t = this._commentsMap[e];
156
- return t ? Array.from(Object.entries(t)).map(([n, o]) => [n, Array.from(Object.values(o))]) : [];
155
+ const n = this._commentsMap[e];
156
+ return n ? Array.from(Object.entries(n)).map(([t, o]) => [t, Array.from(Object.values(o))]) : [];
157
157
  }
158
158
  deleteUnit(e) {
159
- const t = this._commentsMap[e];
160
- t && Object.entries(t).forEach(([n, o]) => {
159
+ const n = this._commentsMap[e];
160
+ n && Object.entries(n).forEach(([t, o]) => {
161
161
  Object.values(o).forEach((m) => {
162
- this.deleteComment(e, n, m.id);
162
+ this.deleteComment(e, t, m.id);
163
163
  });
164
164
  });
165
165
  }
166
- getRootCommentIds(e, t) {
167
- const n = this._ensureCommentChildrenMap(e, t);
168
- return Array.from(n.keys());
166
+ getRootCommentIds(e, n) {
167
+ const t = this._ensureCommentChildrenMap(e, n);
168
+ return Array.from(t.keys());
169
169
  }
170
- getRootCommentIds$(e, t) {
171
- return this._commentsTreeMap$.pipe(R(
172
- (n) => {
170
+ getRootCommentIds$(e, n) {
171
+ return this._commentsTreeMap$.pipe($(
172
+ (t) => {
173
173
  var o;
174
- return Object.keys((o = n[e]) == null ? void 0 : o[t]);
174
+ return Object.keys((o = t[e]) == null ? void 0 : o[n]);
175
175
  }
176
176
  ));
177
177
  }
@@ -179,9 +179,9 @@ class h {
179
179
  return this._commentsMap;
180
180
  }
181
181
  }
182
- var b = /* @__PURE__ */ ((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))(b || {});
183
- const x = "THREAD_COMMENT_PLUGIN";
184
- class z {
182
+ var x = /* @__PURE__ */ ((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))(x || {});
183
+ const b = "THREAD_COMMENT_PLUGIN";
184
+ class q {
185
185
  async addComment(e) {
186
186
  return e;
187
187
  }
@@ -201,45 +201,45 @@ class z {
201
201
  return e;
202
202
  }
203
203
  }
204
- const f = Z("univer.thread-comment.data-source-service");
205
- var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, Y = (r, e, t, n) => {
206
- for (var o = n > 1 ? void 0 : n ? X(e, t) : e, m = r.length - 1, s; m >= 0; m--)
207
- (s = r[m]) && (o = (n ? s(e, t, o) : s(o)) || o);
208
- return n && o && Q(e, t, o), o;
209
- }, N = (r, e) => (t, n) => e(t, n, r);
210
- let U = class extends V {
211
- constructor(r, e, t) {
212
- super(), this._resourceManagerService = r, this._threadCommentModel = e, this._threadCommentDataSourceService = t, this._initSnapshot();
204
+ const M = F("univer.thread-comment.data-source-service");
205
+ var z = (r, e, n, t) => {
206
+ for (var o = e, m = r.length - 1, s; m >= 0; m--)
207
+ (s = r[m]) && (o = s(o) || o);
208
+ return o;
209
+ }, N = (r, e) => (n, t) => e(n, t, r);
210
+ let U = class extends W {
211
+ constructor(r, e, n) {
212
+ super(), this._resourceManagerService = r, this._threadCommentModel = e, this._threadCommentDataSourceService = n, this._initSnapshot();
213
213
  }
214
214
  _initSnapshot() {
215
- const r = (t) => {
216
- const n = this._threadCommentModel.getUnit(t), o = {};
217
- return n ? (n.forEach(([m, s]) => {
215
+ const r = (n) => {
216
+ const t = this._threadCommentModel.getUnit(n), o = {};
217
+ return t ? (t.forEach(([m, s]) => {
218
218
  o[m] = s;
219
219
  }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o))) : "";
220
- }, e = (t) => {
221
- if (!t)
220
+ }, e = (n) => {
221
+ if (!n)
222
222
  return {};
223
223
  try {
224
- return JSON.parse(t);
224
+ return JSON.parse(n);
225
225
  } catch {
226
226
  return {};
227
227
  }
228
228
  };
229
229
  this.disposeWithMe(
230
230
  this._resourceManagerService.registerPluginResource({
231
- pluginName: `SHEET_${x}`,
232
- businesses: [b.UNIVER_SHEET],
233
- toJson: (t) => r(t),
234
- parseJson: (t) => e(t),
235
- onUnLoad: (t) => {
236
- this._threadCommentModel.deleteUnit(t);
231
+ pluginName: `SHEET_${b}`,
232
+ businesses: [x.UNIVER_SHEET],
233
+ toJson: (n) => r(n),
234
+ parseJson: (n) => e(n),
235
+ onUnLoad: (n) => {
236
+ this._threadCommentModel.deleteUnit(n);
237
237
  },
238
- onLoad: async (t, n) => {
239
- const o = await this._threadCommentDataSourceService.loadFormSnapshot(n);
238
+ onLoad: async (n, t) => {
239
+ const o = await this._threadCommentDataSourceService.loadFormSnapshot(t);
240
240
  Object.keys(o).forEach((m) => {
241
- n[m].forEach((a) => {
242
- this._threadCommentModel.addComment(t, m, a);
241
+ t[m].forEach((a) => {
242
+ this._threadCommentModel.addComment(n, m, a);
243
243
  });
244
244
  });
245
245
  }
@@ -247,11 +247,11 @@ let U = class extends V {
247
247
  );
248
248
  }
249
249
  };
250
- U = Y([
251
- W(J.Starting, U),
252
- N(0, H),
253
- N(1, E(h)),
254
- N(2, f)
250
+ U = z([
251
+ k(P.Starting, U),
252
+ N(0, J),
253
+ N(1, D(p)),
254
+ N(2, M)
255
255
  ], U);
256
256
  const T = {
257
257
  id: "thread-comment.mutation.add-comment",
@@ -259,35 +259,35 @@ const T = {
259
259
  handler(r, e) {
260
260
  if (!e)
261
261
  return !1;
262
- const t = r.get(h), { unitId: n, subUnitId: o, comment: m } = e;
263
- return t.addComment(n, o, m);
262
+ const n = r.get(p), { unitId: t, subUnitId: o, comment: m } = e;
263
+ return n.addComment(t, o, m);
264
264
  }
265
- }, g = {
265
+ }, v = {
266
266
  id: "thread-comment.mutation.update-comment",
267
267
  type: l.MUTATION,
268
268
  handler(r, e) {
269
269
  if (!e)
270
270
  return !1;
271
- const t = r.get(h), { unitId: n, subUnitId: o, payload: m } = e;
272
- return t.updateComment(n, o, m);
271
+ const n = r.get(p), { unitId: t, subUnitId: o, payload: m } = e;
272
+ return n.updateComment(t, o, m);
273
273
  }
274
- }, k = {
274
+ }, Q = {
275
275
  id: "thread-comment.mutation.update-comment-ref",
276
276
  type: l.MUTATION,
277
277
  handler(r, e) {
278
278
  if (!e)
279
279
  return !1;
280
- const t = r.get(h), { unitId: n, subUnitId: o, payload: m } = e;
281
- return t.updateCommentRef(n, o, m);
280
+ const n = r.get(p), { unitId: t, subUnitId: o, payload: m } = e;
281
+ return n.updateCommentRef(t, o, m);
282
282
  }
283
- }, w = {
283
+ }, A = {
284
284
  id: "thread-comment.mutation.resolve-comment",
285
285
  type: l.MUTATION,
286
286
  handler(r, e) {
287
287
  if (!e)
288
288
  return !1;
289
- const t = r.get(h), { unitId: n, subUnitId: o, resolved: m, commentId: s } = e;
290
- return t.resolveComment(n, o, s, m);
289
+ const n = r.get(p), { unitId: t, subUnitId: o, resolved: m, commentId: s } = e;
290
+ return n.resolveComment(t, o, s, m);
291
291
  }
292
292
  }, y = {
293
293
  id: "thread-comment.mutation.delete-comment",
@@ -295,16 +295,16 @@ const T = {
295
295
  handler(r, e) {
296
296
  if (!e)
297
297
  return !1;
298
- const t = r.get(h), { unitId: n, subUnitId: o, commentId: m } = e;
299
- return t.deleteComment(n, o, m);
298
+ const n = r.get(p), { unitId: t, subUnitId: o, commentId: m } = e;
299
+ return n.deleteComment(t, o, m);
300
300
  }
301
- }, ee = {
301
+ }, X = {
302
302
  id: "thread-comment.command.add-comment",
303
303
  type: l.COMMAND,
304
304
  async handler(r, e) {
305
305
  if (!e)
306
306
  return !1;
307
- const t = r.get(M), n = r.get(S), o = r.get(f), { unitId: m, subUnitId: s, comment: a } = e, d = await o.addComment(a), c = {
307
+ const n = r.get(f), t = r.get(S), o = r.get(M), { unitId: m, subUnitId: s, comment: a } = e, d = await o.addComment(a), c = {
308
308
  id: T.id,
309
309
  params: e
310
310
  }, u = {
@@ -315,21 +315,21 @@ const T = {
315
315
  commentId: d.id
316
316
  }
317
317
  };
318
- return n.pushUndoRedo({
318
+ return t.pushUndoRedo({
319
319
  undoMutations: [u],
320
320
  redoMutations: [c],
321
321
  unitID: m
322
- }), t.executeCommand(c.id, c.params), !0;
322
+ }), n.executeCommand(c.id, c.params), !0;
323
323
  }
324
- }, te = {
324
+ }, Y = {
325
325
  id: "thread-comment.command.update-comment",
326
326
  type: l.COMMAND,
327
327
  async handler(r, e) {
328
328
  if (!e)
329
329
  return !1;
330
- const { unitId: t, subUnitId: n, payload: o } = e, m = r.get(M), s = r.get(S), a = r.get(h), d = r.get(f), c = a.getComment(
331
- t,
330
+ const { unitId: n, subUnitId: t, payload: o } = e, m = r.get(f), s = r.get(S), a = r.get(p), d = r.get(M), c = a.getComment(
332
331
  n,
332
+ t,
333
333
  o.commentId
334
334
  );
335
335
  if (!c || !await d.updateComment({
@@ -338,13 +338,13 @@ const T = {
338
338
  }))
339
339
  return !1;
340
340
  const i = {
341
- id: g.id,
341
+ id: v.id,
342
342
  params: e
343
343
  }, C = {
344
- id: g.id,
344
+ id: v.id,
345
345
  params: {
346
- unitId: t,
347
- subUnitId: n,
346
+ unitId: n,
347
+ subUnitId: t,
348
348
  payload: {
349
349
  commentId: o.commentId,
350
350
  text: c.text,
@@ -357,34 +357,34 @@ const T = {
357
357
  return s.pushUndoRedo({
358
358
  undoMutations: [C],
359
359
  redoMutations: [i],
360
- unitID: t
360
+ unitID: n
361
361
  }), m.executeCommand(i.id, i.params), !0;
362
362
  }
363
363
  };
364
364
  l.COMMAND;
365
- const ne = {
365
+ const ee = {
366
366
  id: "thread-comment.command.resolve-comment",
367
367
  type: l.COMMAND,
368
368
  async handler(r, e) {
369
369
  if (!e)
370
370
  return !1;
371
- const { unitId: t, subUnitId: n, resolved: o, commentId: m } = e, s = r.get(f), d = r.get(h).getComment(t, n, m);
371
+ const { unitId: n, subUnitId: t, resolved: o, commentId: m } = e, s = r.get(M), d = r.get(p).getComment(n, t, m);
372
372
  return !d || !await s.updateComment({
373
373
  ...d,
374
374
  resolved: o
375
- }) ? !1 : (r.get(M).executeCommand(
376
- w.id,
375
+ }) ? !1 : (r.get(f).executeCommand(
376
+ A.id,
377
377
  e
378
378
  ), !0);
379
379
  }
380
- }, oe = {
380
+ }, te = {
381
381
  id: "thread-comment.command.delete-comment",
382
382
  type: l.COMMAND,
383
383
  async handler(r, e) {
384
384
  if (!e)
385
385
  return !1;
386
- const t = r.get(h), n = r.get(f), o = r.get(M), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = t.getComment(s, a, d);
387
- if (!c || !await n.deleteComment(d))
386
+ const n = r.get(p), t = r.get(M), o = r.get(f), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getComment(s, a, d);
387
+ if (!c || !await t.deleteComment(d))
388
388
  return !1;
389
389
  const u = {
390
390
  id: y.id,
@@ -403,33 +403,33 @@ const ne = {
403
403
  unitID: s
404
404
  }), o.executeCommand(u.id, u.params);
405
405
  }
406
- }, re = {
406
+ }, ne = {
407
407
  id: "thread-comment.command.delete-comment-tree",
408
408
  type: l.COMMAND,
409
409
  async handler(r, e) {
410
410
  if (!e)
411
411
  return !1;
412
- const t = r.get(h), n = r.get(M), o = r.get(f), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = t.getCommentWithChildren(s, a, d);
412
+ const n = r.get(p), t = r.get(f), o = r.get(M), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getCommentWithChildren(s, a, d);
413
413
  if (!c)
414
414
  return !1;
415
415
  const u = [c.root, ...c.children];
416
- if (!await o.deleteCommentBatch(u.map((v) => v.id)))
416
+ if (!await o.deleteCommentBatch(u.map((g) => g.id)))
417
417
  return !1;
418
- const i = u.map((v) => ({
418
+ const i = u.map((g) => ({
419
419
  id: y.id,
420
420
  params: {
421
421
  unitId: s,
422
422
  subUnitId: a,
423
- commentId: v.id
423
+ commentId: g.id
424
424
  }
425
- })), C = u.map((v) => ({
425
+ })), C = u.map((g) => ({
426
426
  id: T.id,
427
427
  params: {
428
428
  unitId: s,
429
429
  subUnitId: a,
430
- comment: v
430
+ comment: g
431
431
  }
432
- })), _ = G(i, n);
432
+ })), _ = H(i, t);
433
433
  return _.result && m.pushUndoRedo({
434
434
  undoMutations: C,
435
435
  redoMutations: i,
@@ -437,61 +437,62 @@ const ne = {
437
437
  }), _.result;
438
438
  }
439
439
  };
440
- var me = Object.defineProperty, se = Object.getOwnPropertyDescriptor, ae = (r, e, t, n) => {
441
- for (var o = n > 1 ? void 0 : n ? se(e, t) : e, m = r.length - 1, s; m >= 0; m--)
442
- (s = r[m]) && (o = (n ? s(e, t, o) : s(o)) || o);
443
- return n && o && me(e, t, o), o;
444
- }, $ = (r, e) => (t, n) => e(t, n, r), I;
445
- let D = (I = class extends B {
446
- constructor(e, t, n) {
440
+ var oe = (r, e, n, t) => {
441
+ for (var o = e, m = r.length - 1, s; m >= 0; m--)
442
+ (s = r[m]) && (o = s(o) || o);
443
+ return o;
444
+ }, O = (r, e) => (n, t) => e(n, t, r), I;
445
+ let E = (I = class extends G {
446
+ constructor(e, n, t) {
447
447
  super();
448
- p(this, "_config");
449
- this._injector = t, this._commandService = n, this._config = e;
448
+ h(this, "_config");
449
+ this._injector = n, this._commandService = t, this._config = e;
450
450
  }
451
451
  onStarting(e) {
452
- F([
453
- [h],
452
+ var n;
453
+ K([
454
+ [p],
454
455
  [U],
455
- [f, { useClass: z }]
456
- ], this._config.overrides).forEach(
456
+ [M, { useClass: q }]
457
+ ], (n = this._config) == null ? void 0 : n.overrides).forEach(
457
458
  (t) => {
458
459
  e.add(t);
459
460
  }
460
461
  ), [
461
- ee,
462
+ X,
463
+ Y,
462
464
  te,
463
- oe,
465
+ ee,
464
466
  ne,
465
- re,
466
467
  T,
467
- g,
468
- k,
468
+ v,
469
+ Q,
469
470
  y,
470
- w
471
+ A
471
472
  ].forEach((t) => {
472
473
  this._commandService.registerCommand(t);
473
474
  });
474
475
  }
475
- }, p(I, "pluginName", x), p(I, "type", K.UNIVER_UNKNOWN), I);
476
- D = ae([
477
- $(1, E(q)),
478
- $(2, M)
479
- ], D);
476
+ }, h(I, "pluginName", b), h(I, "type", B.UNIVER_UNKNOWN), I);
477
+ E = oe([
478
+ O(1, D(Z)),
479
+ O(2, f)
480
+ ], E);
480
481
  export {
481
- ee as AddCommentCommand,
482
+ X as AddCommentCommand,
482
483
  T as AddCommentMutation,
483
- oe as DeleteCommentCommand,
484
+ te as DeleteCommentCommand,
484
485
  y as DeleteCommentMutation,
485
- re as DeleteCommentTreeCommand,
486
- f as IThreadCommentDataSourceService,
487
- ne as ResolveCommentCommand,
488
- w as ResolveCommentMutation,
489
- x as TC_PLUGIN_NAME,
490
- z as ThreadCommentDataSourceService,
491
- h as ThreadCommentModel,
486
+ ne as DeleteCommentTreeCommand,
487
+ M as IThreadCommentDataSourceService,
488
+ ee as ResolveCommentCommand,
489
+ A as ResolveCommentMutation,
490
+ b as TC_PLUGIN_NAME,
491
+ q as ThreadCommentDataSourceService,
492
+ p as ThreadCommentModel,
492
493
  U as ThreadCommentResourceController,
493
- D as UniverThreadCommentPlugin,
494
- te as UpdateCommentCommand,
495
- g as UpdateCommentMutation,
496
- k as UpdateCommentRefMutation
494
+ E as UniverThreadCommentPlugin,
495
+ Y as UpdateCommentCommand,
496
+ v as UpdateCommentMutation,
497
+ Q as UpdateCommentRefMutation
497
498
  };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,h,d,U){"use strict";var B=Object.defineProperty;var K=(s,h,d)=>h in s?B(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var f=(s,h,d)=>(K(s,typeof h!="symbol"?h+"":h,d),d);var y;class l{constructor(){f(this,"_commentsMap",{});f(this,"_commentsTreeMap",new Map);f(this,"_commentUpdate$",new h.Subject);f(this,"_commentsTreeMap$",new h.BehaviorSubject({}));f(this,"_commentsMap$",new h.BehaviorSubject({}));f(this,"commentUpdate$",this._commentUpdate$.asObservable());f(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());f(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((r,a)=>{n[a]={};const i=n[a];r.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m);let a=e.parentId;if(a){let i=n[a];for(;i!=null&&i.parentId;)i=n[i.parentId],a=i.parentId;if(i){let c=r.get(a);c||(c=[]),c.push(e.id),r.set(a,c)}}else r.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:r}=this.ensureMap(t,m),a=r[e];return a?(a.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var p;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return;const i=new Set,c=(p=r.get(e))!=null?p:[],u=c==null?void 0:c.map(C=>n[C]);return[a,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:a,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return!1;if(a.parentId){const i=r.get(a.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],r.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(r=>{this.deleteComment(t,e,r.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var D=(o=>(o[o.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",o[o.UNIVER_DOC=1]="UNIVER_DOC",o[o.UNIVER_SHEET=2]="UNIVER_SHEET",o[o.UNIVER_SLIDE=3]="UNIVER_SLIDE",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const M=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(o,t,m,e)=>{for(var n=e>1?void 0:e?W(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&V(t,m,n),n},N=(o,t)=>(m,e)=>t(m,e,o);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),r={};return n?(n.forEach(([a,i])=>{r[a]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(e,a,c)})})}}))}},s.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(l)),N(2,M)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,comment:r}=t;return m.addComment(e,n,r)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateComment(e,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateCommentRef(e,n,r)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,resolved:r,commentId:a}=t;return m.resolveComment(e,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,commentId:r}=t;return m.deleteComment(e,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(d.ICommandService),e=o.get(d.IUndoRedoService),n=o.get(M),{unitId:r,subUnitId:a,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return e.pushUndoRedo({undoMutations:[p],redoMutations:[u],unitID:r}),m.executeCommand(u.id,u.params),!0}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,r=o.get(d.ICommandService),a=o.get(d.IUndoRedoService),i=o.get(l),c=o.get(M),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return a.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),r.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:r}=t,a=o.get(M),c=o.get(l).getComment(m,e,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(o.get(d.ICommandService).executeCommand(O.id,t),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(M),n=o.get(d.ICommandService),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getComment(a,i,c);if(!u||!await e.deleteComment(c))return!1;const p={id:T.id,params:t},C={id:S.id,params:{unitId:a,subUnitId:i,comment:u}};return r.pushUndoRedo({undoMutations:[C],redoMutations:[p],unitID:a}),n.executeCommand(p.id,p.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(d.ICommandService),n=o.get(M),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(a,i,c);if(!u)return!1;const p=[u.root,...u.children];if(!await n.deleteCommentBatch(p.map(g=>g.id)))return!1;const C=p.map(g=>({id:T.id,params:{unitId:a,subUnitId:i,commentId:g.id}})),_=p.map(g=>({id:S.id,params:{unitId:a,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&r.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:a}),I.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(o,t,m,e)=>{for(var n=e>1?void 0:e?H(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&G(t,m,n),n},L=(o,t)=>(m,e)=>t(m,e,o);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();f(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){d.mergeOverrideWithDependencies([[l],[s.ThreadCommentResourceController],[M,{useClass:$}]],this._config.overrides).forEach(e=>{m.add(e)}),[b,w,P,A,j,S,v,E,T,O].forEach(e=>{this._commandService.registerCommand(e)})}},f(y,"pluginName",R),f(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=q([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=b,s.AddCommentMutation=S,s.DeleteCommentCommand=P,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=j,s.IThreadCommentDataSourceService=M,s.ResolveCommentCommand=A,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=$,s.ThreadCommentModel=l,s.UpdateCommentCommand=w,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,h,d,U){"use strict";var k=Object.defineProperty;var J=(s,h,d)=>h in s?k(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var M=(s,h,d)=>(J(s,typeof h!="symbol"?h+"":h,d),d);var y;class p{constructor(){M(this,"_commentsMap",{});M(this,"_commentsTreeMap",new Map);M(this,"_commentUpdate$",new h.Subject);M(this,"_commentsTreeMap$",new h.BehaviorSubject({}));M(this,"_commentsMap$",new h.BehaviorSubject({}));M(this,"commentUpdate$",this._commentUpdate$.asObservable());M(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());M(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((r,a)=>{n[a]={};const i=n[a];r.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m);let a=e.parentId;if(a){let i=n[a];for(;i!=null&&i.parentId;)i=n[i.parentId],a=i.parentId;if(i){let c=r.get(a);c||(c=[]),c.push(e.id),r.set(a,c)}}else r.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:r}=this.ensureMap(t,m),a=r[e];return a?(a.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var l;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return;const i=new Set,c=(l=r.get(e))!=null?l:[],u=c==null?void 0:c.map(C=>n[C]);return[a,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:a,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return!1;if(a.parentId){const i=r.get(a.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],r.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(r=>{this.deleteComment(t,e,r.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var $=(o=>(o[o.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",o[o.UNIVER_DOC=1]="UNIVER_DOC",o[o.UNIVER_SHEET=2]="UNIVER_SHEET",o[o.UNIVER_SLIDE=3]="UNIVER_SLIDE",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))($||{});const R="THREAD_COMMENT_PLUGIN";class D{async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const f=U.createIdentifier("univer.thread-comment.data-source-service");var V=(o,t,m,e)=>{for(var n=t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=a(n)||n);return n},N=(o,t)=>(m,e)=>t(m,e,o);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),r={};return n?(n.forEach(([a,i])=>{r[a]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[$.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(e,a,c)})})}}))}},s.ThreadCommentResourceController=V([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(p)),N(2,f)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(p),{unitId:e,subUnitId:n,comment:r}=t;return m.addComment(e,n,r)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(p),{unitId:e,subUnitId:n,payload:r}=t;return m.updateComment(e,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(p),{unitId:e,subUnitId:n,payload:r}=t;return m.updateCommentRef(e,n,r)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(p),{unitId:e,subUnitId:n,resolved:r,commentId:a}=t;return m.resolveComment(e,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(p),{unitId:e,subUnitId:n,commentId:r}=t;return m.deleteComment(e,n,r)}},A={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(d.ICommandService),e=o.get(d.IUndoRedoService),n=o.get(f),{unitId:r,subUnitId:a,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},l={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return e.pushUndoRedo({undoMutations:[l],redoMutations:[u],unitID:r}),m.executeCommand(u.id,u.params),!0}},b={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,r=o.get(d.ICommandService),a=o.get(d.IUndoRedoService),i=o.get(p),c=o.get(f),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return a.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),r.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const w={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:r}=t,a=o.get(f),c=o.get(p).getComment(m,e,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(o.get(d.ICommandService).executeCommand(O.id,t),!0)}},j={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(p),e=o.get(f),n=o.get(d.ICommandService),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getComment(a,i,c);if(!u||!await e.deleteComment(c))return!1;const l={id:T.id,params:t},C={id:S.id,params:{unitId:a,subUnitId:i,comment:u}};return r.pushUndoRedo({undoMutations:[C],redoMutations:[l],unitID:a}),n.executeCommand(l.id,l.params)}},P={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(p),e=o.get(d.ICommandService),n=o.get(f),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(a,i,c);if(!u)return!1;const l=[u.root,...u.children];if(!await n.deleteCommentBatch(l.map(g=>g.id)))return!1;const C=l.map(g=>({id:T.id,params:{unitId:a,subUnitId:i,commentId:g.id}})),_=l.map(g=>({id:S.id,params:{unitId:a,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&r.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:a}),I.result}};var W=(o,t,m,e)=>{for(var n=t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=a(n)||n);return n},L=(o,t)=>(m,e)=>t(m,e,o);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();M(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){var e;d.mergeOverrideWithDependencies([[p],[s.ThreadCommentResourceController],[f,{useClass:D}]],(e=this._config)==null?void 0:e.overrides).forEach(n=>{m.add(n)}),[A,b,j,w,P,S,v,E,T,O].forEach(n=>{this._commandService.registerCommand(n)})}},M(y,"pluginName",R),M(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=W([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=A,s.AddCommentMutation=S,s.DeleteCommentCommand=j,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=P,s.IThreadCommentDataSourceService=f,s.ResolveCommentCommand=w,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=D,s.ThreadCommentModel=p,s.UpdateCommentCommand=b,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/thread-comment",
3
- "version": "0.1.12",
3
+ "version": "0.1.13-nightly.202406041140",
4
4
  "private": false,
5
5
  "description": "Univer thread comment core plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -49,21 +49,21 @@
49
49
  "peerDependencies": {
50
50
  "@wendellhu/redi": "0.15.2",
51
51
  "rxjs": ">=7.0.0",
52
- "@univerjs/core": "0.1.12"
52
+ "@univerjs/core": "0.1.13-nightly.202406041140"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/protocol": "^0.1.32"
55
+ "@univerjs/protocol": "^0.1.36"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@wendellhu/redi": "0.15.2",
59
59
  "rxjs": "^7.8.1",
60
60
  "typescript": "^5.4.5",
61
- "vite": "^5.2.11",
61
+ "vite": "^5.2.12",
62
62
  "vitest": "^1.6.0",
63
- "@univerjs/core": "0.1.12",
64
- "@univerjs/design": "0.1.12",
65
- "@univerjs/shared": "0.1.12",
66
- "@univerjs/ui": "0.1.12"
63
+ "@univerjs/core": "0.1.13-nightly.202406041140",
64
+ "@univerjs/design": "0.1.13-nightly.202406041140",
65
+ "@univerjs/shared": "0.1.13",
66
+ "@univerjs/ui": "0.1.13-nightly.202406041140"
67
67
  },
68
68
  "scripts": {
69
69
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS