@univerjs/thread-comment 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +120 -119
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
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 j=Object.defineProperty;var L=(m,e,o)=>e in m?j(m,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):m[e]=o;var C=(m,e,o)=>(L(m,typeof e!="symbol"?e+"":e,o),o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("rxjs"),d=require("@univerjs/core"),U=require("@wendellhu/redi");class h{constructor(){C(this,"_commentsMap",{});C(this,"_commentsTreeMap",new Map);C(this,"_commentUpdate$",new S.Subject);C(this,"_commentsTreeMap$",new S.BehaviorSubject({}));C(this,"_commentsMap$",new S.BehaviorSubject({}));C(this,"commentUpdate$",this._commentUpdate$.asObservable());C(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());C(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(e,o){let t=this._commentsMap[e];t||(t={},this._commentsMap[e]=t);let n=t[o];return n||(n={},t[o]=n),n}_ensureCommentChildrenMap(e,o){let t=this._commentsTreeMap.get(e);t||(t=new Map,this._commentsTreeMap.set(e,t));let n=t.get(o);return n||(n=new Map,t.set(o,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const e={};this._commentsTreeMap.forEach((o,t)=>{e[t]={};const n=e[t];o.forEach((r,a)=>{n[a]={};const s=n[a];r.forEach((c,i)=>{s[i]=c})})}),this._commentsTreeMap$.next(e)}ensureMap(e,o){const t=this._ensureCommentMap(e,o),n=this._ensureCommentChildrenMap(e,o);return{commentMap:t,commentChildrenMap:n}}addComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o);let a=t.parentId;if(a){let s=n[a];for(;s!=null&&s.parentId;)s=n[s.parentId],a=s.parentId;if(s){let c=r.get(a);c||(c=[]),c.push(t.id),r.set(a,c)}}else r.set(t.id,[]);return n[t.id]=t,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"add",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.updated=!0,r.text=t.text,r.attachments=t.attachments,r.updateT=t.updateT,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"update",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(e,o,t){const{commentMap:n}=this.ensureMap(e,o),r=n[t.commentId];return r?(r.ref=t.ref,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"updateRef",payload:t}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(e,o,t,n){const{commentMap:r}=this.ensureMap(e,o),a=r[t];return a?(a.resolved=n,this._commentUpdate$.next({unitId:e,subUnitId:o,type:"resolve",payload:{commentId:t,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(e,o,t){const{commentMap:n}=this.ensureMap(e,o);return n[t]}getComment$(e,o,t){return this._commentsMap$.pipe(S.map(n=>n[e][o][t]))}getCommentWithChildren(e,o,t){var p;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return;const s=new Set,c=(p=r.get(t))!=null?p:[],i=c==null?void 0:c.map(u=>n[u]);return[a,...i].forEach(u=>{var M;s.add(u.personId),(M=u.text.customRanges)==null||M.forEach(_=>{_.rangeType===d.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:a,children:i,relativeUsers:s}}deleteComment(e,o,t){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(e,o),a=n[t];if(!a)return!1;if(a.parentId){const s=r.get(a.parentId);if(s){const c=s.indexOf(t);s.splice(c,1)}delete n[t]}else delete n[t],r.delete(t);return this._commentUpdate$.next({unitId:e,subUnitId:o,type:"delete",payload:{commentId:t,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(e){const o=this._commentsMap[e];return o?Array.from(Object.entries(o)).map(([t,n])=>[t,Array.from(Object.values(n))]):[]}deleteUnit(e){const o=this._commentsMap[e];o&&Object.entries(o).forEach(([t,n])=>{Object.values(n).forEach(r=>{this.deleteComment(e,t,r.id)})})}getRootCommentIds(e,o){const t=this._ensureCommentChildrenMap(e,o);return Array.from(t.keys())}getRootCommentIds$(e,o){return this._commentsTreeMap$.pipe(S.map(t=>{var n;return Object.keys((n=t[e])==null?void 0:n[o])}))}getAll(){return this._commentsMap}}var D=(m=>(m[m.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",m[m.UNIVER_DOC=1]="UNIVER_DOC",m[m.UNIVER_SHEET=2]="UNIVER_SHEET",m[m.UNIVER_SLIDE=3]="UNIVER_SLIDE",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(e){return e}async updateComment(e){return!0}async deleteComment(e){return!0}async deleteCommentBatch(e){return!0}async loadFormSnapshot(e){return e}saveToSnapshot(e){return e}}const l=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(m,e,o,t)=>{for(var n=t>1?void 0:t?W(e,o):e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(n))||n);return t&&n&&V(e,o,n),n},y=(m,e)=>(o,t)=>e(o,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(e,o,t){super(),this._resourceManagerService=e,this._threadCommentModel=o,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const e=t=>{const n=this._threadCommentModel.getUnit(t),r={};return n?(n.forEach(([a,s])=>{r[a]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},o=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:t=>e(t),parseJson:t=>o(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(t,a,c)})})}}))}};exports.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,exports.ThreadCommentResourceController),y(0,d.IResourceManagerService),y(1,U.Inject(h)),y(2,l)],exports.ThreadCommentResourceController);const I={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,comment:r}=e;return o.addComment(t,n,r)}},f={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:r}=e;return o.updateComment(t,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,payload:r}=e;return o.updateCommentRef(t,n,r)}},N={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,resolved:r,commentId:a}=e;return o.resolveComment(t,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,e){if(!e)return!1;const o=m.get(h),{unitId:t,subUnitId:n,commentId:r}=e;return o.deleteComment(t,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(d.ICommandService),t=m.get(d.IUndoRedoService),n=m.get(l),{unitId:r,subUnitId:a,comment:s}=e,c=await n.addComment(s),i={id:I.id,params:e},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return t.pushUndoRedo({undoMutations:[p],redoMutations:[i],unitID:r}),o.executeCommand(i.id,i.params),!0}},x={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,payload:n}=e,r=m.get(d.ICommandService),a=m.get(d.IUndoRedoService),s=m.get(h),c=m.get(l),i=s.getComment(o,t,n.commentId);if(!i||!await c.updateComment({...i,...n}))return!1;const u={id:f.id,params:e},M={id:f.id,params:{unitId:o,subUnitId:t,payload:{commentId:n.commentId,text:i.text,attachments:i.attachments,updateT:i.updateT,updated:i.updated}}};return a.pushUndoRedo({undoMutations:[M],redoMutations:[u],unitID:o}),r.executeCommand(u.id,u.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const{unitId:o,subUnitId:t,resolved:n,commentId:r}=e,a=m.get(l),c=m.get(h).getComment(o,t,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(m.get(d.ICommandService).executeCommand(N.id,e),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(l),n=m.get(d.ICommandService),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getComment(a,s,c);if(!i||!await t.deleteComment(c))return!1;const p={id:T.id,params:e},u={id:I.id,params:{unitId:a,subUnitId:s,comment:i}};return r.pushUndoRedo({undoMutations:[u],redoMutations:[p],unitID:a}),n.executeCommand(p.id,p.params)}},w={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,e){if(!e)return!1;const o=m.get(h),t=m.get(d.ICommandService),n=m.get(l),r=m.get(d.IUndoRedoService),{unitId:a,subUnitId:s,commentId:c}=e,i=o.getCommentWithChildren(a,s,c);if(!i)return!1;const p=[i.root,...i.children];if(!await n.deleteCommentBatch(p.map(v=>v.id)))return!1;const u=p.map(v=>({id:T.id,params:{unitId:a,subUnitId:s,commentId:v.id}})),M=p.map(v=>({id:I.id,params:{unitId:a,subUnitId:s,comment:v}})),_=d.sequenceExecute(u,t);return _.result&&r.pushUndoRedo({undoMutations:M,redoMutations:u,unitID:a}),_.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(m,e,o,t)=>{for(var n=t>1?void 0:t?H(e,o):e,r=m.length-1,a;r>=0;r--)(a=m[r])&&(n=(t?a(e,o,n):a(n))||n);return t&&n&&G(e,o,n),n},O=(m,e)=>(o,t)=>e(o,t,m),g;exports.UniverThreadCommentPlugin=(g=class extends d.Plugin{constructor(o,t,n){super();C(this,"_config");this._injector=t,this._commandService=n,this._config=o}onStarting(o){var t;d.mergeOverrideWithDependencies([[h],[exports.ThreadCommentResourceController],[l,{useClass:$}]],(t=this._config)==null?void 0:t.overrides).forEach(n=>{o.add(n)}),[b,x,P,A,w,I,f,E,T,N].forEach(n=>{this._commandService.registerCommand(n)})}},C(g,"pluginName",R),C(g,"type",d.UniverInstanceType.UNIVER_UNKNOWN),g);exports.UniverThreadCommentPlugin=q([O(1,U.Inject(U.Injector)),O(2,d.ICommandService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=b;exports.AddCommentMutation=I;exports.DeleteCommentCommand=P;exports.DeleteCommentMutation=T;exports.DeleteCommentTreeCommand=w;exports.IThreadCommentDataSourceService=l;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=N;exports.TC_PLUGIN_NAME=R;exports.ThreadCommentDataSourceService=$;exports.ThreadCommentModel=h;exports.UpdateCommentCommand=x;exports.UpdateCommentMutation=f;exports.UpdateCommentRefMutation=E;
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var A = Object.defineProperty;
|
|
2
|
-
var P = (r, e,
|
|
3
|
-
var p = (r, e,
|
|
2
|
+
var P = (r, e, n) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
|
|
3
|
+
var p = (r, e, n) => (P(r, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
4
|
import { Subject as j, BehaviorSubject as O, map as R } from "rxjs";
|
|
5
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
6
|
import { createIdentifier as Z, Inject as E, Injector as q } from "@wendellhu/redi";
|
|
@@ -15,17 +15,17 @@ class h {
|
|
|
15
15
|
p(this, "commentTreeMap$", this._commentsTreeMap$.asObservable());
|
|
16
16
|
p(this, "commentMap$", this._commentsMap$.asObservable());
|
|
17
17
|
}
|
|
18
|
-
_ensureCommentMap(e,
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
let o = n
|
|
22
|
-
return o || (o = {}, n
|
|
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
23
|
}
|
|
24
|
-
_ensureCommentChildrenMap(e,
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
let o =
|
|
28
|
-
return o || (o = /* @__PURE__ */ new Map(),
|
|
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((
|
|
38
|
-
e[
|
|
39
|
-
const o = e[
|
|
40
|
-
|
|
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,76 +46,76 @@ class h {
|
|
|
46
46
|
});
|
|
47
47
|
}), this._commentsTreeMap$.next(e);
|
|
48
48
|
}
|
|
49
|
-
ensureMap(e,
|
|
50
|
-
const
|
|
49
|
+
ensureMap(e, n) {
|
|
50
|
+
const t = this._ensureCommentMap(e, n), o = this._ensureCommentChildrenMap(e, n);
|
|
51
51
|
return {
|
|
52
|
-
commentMap:
|
|
52
|
+
commentMap: t,
|
|
53
53
|
commentChildrenMap: o
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
addComment(e,
|
|
57
|
-
const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e,
|
|
58
|
-
let s =
|
|
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(
|
|
65
|
+
d || (d = []), d.push(t.id), m.set(s, d);
|
|
66
66
|
}
|
|
67
67
|
} else
|
|
68
|
-
m.set(
|
|
69
|
-
return o[
|
|
68
|
+
m.set(t.id, []);
|
|
69
|
+
return o[t.id] = t, this._commentUpdate$.next({
|
|
70
70
|
unitId: e,
|
|
71
|
-
subUnitId:
|
|
71
|
+
subUnitId: n,
|
|
72
72
|
type: "add",
|
|
73
|
-
payload:
|
|
73
|
+
payload: t
|
|
74
74
|
}), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0;
|
|
75
75
|
}
|
|
76
|
-
updateComment(e,
|
|
77
|
-
const { commentMap: o } = this.ensureMap(e,
|
|
78
|
-
return m ? (m.updated = !0, m.text =
|
|
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:
|
|
80
|
+
subUnitId: n,
|
|
81
81
|
type: "update",
|
|
82
|
-
payload:
|
|
82
|
+
payload: t
|
|
83
83
|
}), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
|
|
84
84
|
}
|
|
85
|
-
updateCommentRef(e,
|
|
86
|
-
const { commentMap: o } = this.ensureMap(e,
|
|
87
|
-
return m ? (m.ref =
|
|
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:
|
|
89
|
+
subUnitId: n,
|
|
90
90
|
type: "updateRef",
|
|
91
|
-
payload:
|
|
91
|
+
payload: t
|
|
92
92
|
}), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
|
|
93
93
|
}
|
|
94
|
-
resolveComment(e,
|
|
95
|
-
const { commentMap: m } = this.ensureMap(e,
|
|
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:
|
|
98
|
+
subUnitId: n,
|
|
99
99
|
type: "resolve",
|
|
100
100
|
payload: {
|
|
101
|
-
commentId:
|
|
101
|
+
commentId: t,
|
|
102
102
|
resolved: o
|
|
103
103
|
}
|
|
104
104
|
}), this._refreshCommentsMap$(), this._refreshCommentsTreeMap$(), !0) : !1;
|
|
105
105
|
}
|
|
106
|
-
getComment(e,
|
|
107
|
-
const { commentMap: o } = this.ensureMap(e,
|
|
108
|
-
return o[
|
|
106
|
+
getComment(e, n, t) {
|
|
107
|
+
const { commentMap: o } = this.ensureMap(e, n);
|
|
108
|
+
return o[t];
|
|
109
109
|
}
|
|
110
|
-
getComment$(e,
|
|
111
|
-
return this._commentsMap$.pipe(R((o) => o[e][
|
|
110
|
+
getComment$(e, n, t) {
|
|
111
|
+
return this._commentsMap$.pipe(R((o) => o[e][n][t]));
|
|
112
112
|
}
|
|
113
|
-
getCommentWithChildren(e,
|
|
113
|
+
getCommentWithChildren(e, n, t) {
|
|
114
114
|
var u;
|
|
115
|
-
const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e,
|
|
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(
|
|
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((_) => {
|
|
@@ -127,51 +127,51 @@ class h {
|
|
|
127
127
|
relativeUsers: a
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
deleteComment(e,
|
|
131
|
-
const { commentMap: o, commentChildrenMap: m } = this.ensureMap(e,
|
|
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(
|
|
137
|
+
const d = a.indexOf(t);
|
|
138
138
|
a.splice(d, 1);
|
|
139
139
|
}
|
|
140
|
-
delete o[
|
|
140
|
+
delete o[t];
|
|
141
141
|
} else
|
|
142
|
-
delete o[
|
|
142
|
+
delete o[t], m.delete(t);
|
|
143
143
|
return this._commentUpdate$.next({
|
|
144
144
|
unitId: e,
|
|
145
|
-
subUnitId:
|
|
145
|
+
subUnitId: n,
|
|
146
146
|
type: "delete",
|
|
147
147
|
payload: {
|
|
148
|
-
commentId:
|
|
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
|
|
156
|
-
return
|
|
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
|
|
160
|
-
|
|
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,
|
|
162
|
+
this.deleteComment(e, t, m.id);
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
getRootCommentIds(e,
|
|
167
|
-
const
|
|
168
|
-
return Array.from(
|
|
166
|
+
getRootCommentIds(e, n) {
|
|
167
|
+
const t = this._ensureCommentChildrenMap(e, n);
|
|
168
|
+
return Array.from(t.keys());
|
|
169
169
|
}
|
|
170
|
-
getRootCommentIds$(e,
|
|
170
|
+
getRootCommentIds$(e, n) {
|
|
171
171
|
return this._commentsTreeMap$.pipe(R(
|
|
172
|
-
(
|
|
172
|
+
(t) => {
|
|
173
173
|
var o;
|
|
174
|
-
return Object.keys((o =
|
|
174
|
+
return Object.keys((o = t[e]) == null ? void 0 : o[n]);
|
|
175
175
|
}
|
|
176
176
|
));
|
|
177
177
|
}
|
|
@@ -202,26 +202,26 @@ class z {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
const f = Z("univer.thread-comment.data-source-service");
|
|
205
|
-
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, Y = (r, e,
|
|
206
|
-
for (var o =
|
|
207
|
-
(s = r[m]) && (o = (
|
|
208
|
-
return
|
|
209
|
-
}, N = (r, e) => (
|
|
205
|
+
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, Y = (r, e, n, t) => {
|
|
206
|
+
for (var o = t > 1 ? void 0 : t ? X(e, n) : e, m = r.length - 1, s; m >= 0; m--)
|
|
207
|
+
(s = r[m]) && (o = (t ? s(e, n, o) : s(o)) || o);
|
|
208
|
+
return t && o && Q(e, n, o), o;
|
|
209
|
+
}, N = (r, e) => (n, t) => e(n, t, r);
|
|
210
210
|
let U = class extends V {
|
|
211
|
-
constructor(r, e,
|
|
212
|
-
super(), this._resourceManagerService = r, this._threadCommentModel = e, this._threadCommentDataSourceService =
|
|
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 = (
|
|
216
|
-
const
|
|
217
|
-
return
|
|
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 = (
|
|
221
|
-
if (!
|
|
220
|
+
}, e = (n) => {
|
|
221
|
+
if (!n)
|
|
222
222
|
return {};
|
|
223
223
|
try {
|
|
224
|
-
return JSON.parse(
|
|
224
|
+
return JSON.parse(n);
|
|
225
225
|
} catch {
|
|
226
226
|
return {};
|
|
227
227
|
}
|
|
@@ -230,16 +230,16 @@ let U = class extends V {
|
|
|
230
230
|
this._resourceManagerService.registerPluginResource({
|
|
231
231
|
pluginName: `SHEET_${x}`,
|
|
232
232
|
businesses: [b.UNIVER_SHEET],
|
|
233
|
-
toJson: (
|
|
234
|
-
parseJson: (
|
|
235
|
-
onUnLoad: (
|
|
236
|
-
this._threadCommentModel.deleteUnit(
|
|
233
|
+
toJson: (n) => r(n),
|
|
234
|
+
parseJson: (n) => e(n),
|
|
235
|
+
onUnLoad: (n) => {
|
|
236
|
+
this._threadCommentModel.deleteUnit(n);
|
|
237
237
|
},
|
|
238
|
-
onLoad: async (
|
|
239
|
-
const o = await this._threadCommentDataSourceService.loadFormSnapshot(
|
|
238
|
+
onLoad: async (n, t) => {
|
|
239
|
+
const o = await this._threadCommentDataSourceService.loadFormSnapshot(t);
|
|
240
240
|
Object.keys(o).forEach((m) => {
|
|
241
|
-
|
|
242
|
-
this._threadCommentModel.addComment(
|
|
241
|
+
t[m].forEach((a) => {
|
|
242
|
+
this._threadCommentModel.addComment(n, m, a);
|
|
243
243
|
});
|
|
244
244
|
});
|
|
245
245
|
}
|
|
@@ -259,8 +259,8 @@ const T = {
|
|
|
259
259
|
handler(r, e) {
|
|
260
260
|
if (!e)
|
|
261
261
|
return !1;
|
|
262
|
-
const
|
|
263
|
-
return
|
|
262
|
+
const n = r.get(h), { unitId: t, subUnitId: o, comment: m } = e;
|
|
263
|
+
return n.addComment(t, o, m);
|
|
264
264
|
}
|
|
265
265
|
}, g = {
|
|
266
266
|
id: "thread-comment.mutation.update-comment",
|
|
@@ -268,8 +268,8 @@ const T = {
|
|
|
268
268
|
handler(r, e) {
|
|
269
269
|
if (!e)
|
|
270
270
|
return !1;
|
|
271
|
-
const
|
|
272
|
-
return
|
|
271
|
+
const n = r.get(h), { unitId: t, subUnitId: o, payload: m } = e;
|
|
272
|
+
return n.updateComment(t, o, m);
|
|
273
273
|
}
|
|
274
274
|
}, k = {
|
|
275
275
|
id: "thread-comment.mutation.update-comment-ref",
|
|
@@ -277,8 +277,8 @@ const T = {
|
|
|
277
277
|
handler(r, e) {
|
|
278
278
|
if (!e)
|
|
279
279
|
return !1;
|
|
280
|
-
const
|
|
281
|
-
return
|
|
280
|
+
const n = r.get(h), { unitId: t, subUnitId: o, payload: m } = e;
|
|
281
|
+
return n.updateCommentRef(t, o, m);
|
|
282
282
|
}
|
|
283
283
|
}, w = {
|
|
284
284
|
id: "thread-comment.mutation.resolve-comment",
|
|
@@ -286,8 +286,8 @@ const T = {
|
|
|
286
286
|
handler(r, e) {
|
|
287
287
|
if (!e)
|
|
288
288
|
return !1;
|
|
289
|
-
const
|
|
290
|
-
return
|
|
289
|
+
const n = r.get(h), { 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,8 +295,8 @@ const T = {
|
|
|
295
295
|
handler(r, e) {
|
|
296
296
|
if (!e)
|
|
297
297
|
return !1;
|
|
298
|
-
const
|
|
299
|
-
return
|
|
298
|
+
const n = r.get(h), { unitId: t, subUnitId: o, commentId: m } = e;
|
|
299
|
+
return n.deleteComment(t, o, m);
|
|
300
300
|
}
|
|
301
301
|
}, ee = {
|
|
302
302
|
id: "thread-comment.command.add-comment",
|
|
@@ -304,7 +304,7 @@ const T = {
|
|
|
304
304
|
async handler(r, e) {
|
|
305
305
|
if (!e)
|
|
306
306
|
return !1;
|
|
307
|
-
const
|
|
307
|
+
const n = r.get(M), t = r.get(S), o = r.get(f), { unitId: m, subUnitId: s, comment: a } = e, d = await o.addComment(a), c = {
|
|
308
308
|
id: T.id,
|
|
309
309
|
params: e
|
|
310
310
|
}, u = {
|
|
@@ -315,11 +315,11 @@ const T = {
|
|
|
315
315
|
commentId: d.id
|
|
316
316
|
}
|
|
317
317
|
};
|
|
318
|
-
return
|
|
318
|
+
return t.pushUndoRedo({
|
|
319
319
|
undoMutations: [u],
|
|
320
320
|
redoMutations: [c],
|
|
321
321
|
unitID: m
|
|
322
|
-
}),
|
|
322
|
+
}), n.executeCommand(c.id, c.params), !0;
|
|
323
323
|
}
|
|
324
324
|
}, te = {
|
|
325
325
|
id: "thread-comment.command.update-comment",
|
|
@@ -327,9 +327,9 @@ const T = {
|
|
|
327
327
|
async handler(r, e) {
|
|
328
328
|
if (!e)
|
|
329
329
|
return !1;
|
|
330
|
-
const { unitId:
|
|
331
|
-
t,
|
|
330
|
+
const { unitId: n, subUnitId: t, payload: o } = e, m = r.get(M), s = r.get(S), a = r.get(h), d = r.get(f), c = a.getComment(
|
|
332
331
|
n,
|
|
332
|
+
t,
|
|
333
333
|
o.commentId
|
|
334
334
|
);
|
|
335
335
|
if (!c || !await d.updateComment({
|
|
@@ -343,8 +343,8 @@ const T = {
|
|
|
343
343
|
}, C = {
|
|
344
344
|
id: g.id,
|
|
345
345
|
params: {
|
|
346
|
-
unitId:
|
|
347
|
-
subUnitId:
|
|
346
|
+
unitId: n,
|
|
347
|
+
subUnitId: t,
|
|
348
348
|
payload: {
|
|
349
349
|
commentId: o.commentId,
|
|
350
350
|
text: c.text,
|
|
@@ -357,7 +357,7 @@ const T = {
|
|
|
357
357
|
return s.pushUndoRedo({
|
|
358
358
|
undoMutations: [C],
|
|
359
359
|
redoMutations: [i],
|
|
360
|
-
unitID:
|
|
360
|
+
unitID: n
|
|
361
361
|
}), m.executeCommand(i.id, i.params), !0;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
@@ -368,7 +368,7 @@ const ne = {
|
|
|
368
368
|
async handler(r, e) {
|
|
369
369
|
if (!e)
|
|
370
370
|
return !1;
|
|
371
|
-
const { unitId:
|
|
371
|
+
const { unitId: n, subUnitId: t, resolved: o, commentId: m } = e, s = r.get(f), d = r.get(h).getComment(n, t, m);
|
|
372
372
|
return !d || !await s.updateComment({
|
|
373
373
|
...d,
|
|
374
374
|
resolved: o
|
|
@@ -383,8 +383,8 @@ const ne = {
|
|
|
383
383
|
async handler(r, e) {
|
|
384
384
|
if (!e)
|
|
385
385
|
return !1;
|
|
386
|
-
const
|
|
387
|
-
if (!c || !await
|
|
386
|
+
const n = r.get(h), t = r.get(f), o = r.get(M), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getComment(s, a, d);
|
|
387
|
+
if (!c || !await t.deleteComment(d))
|
|
388
388
|
return !1;
|
|
389
389
|
const u = {
|
|
390
390
|
id: y.id,
|
|
@@ -409,7 +409,7 @@ const ne = {
|
|
|
409
409
|
async handler(r, e) {
|
|
410
410
|
if (!e)
|
|
411
411
|
return !1;
|
|
412
|
-
const
|
|
412
|
+
const n = r.get(h), t = r.get(M), o = r.get(f), m = r.get(S), { unitId: s, subUnitId: a, commentId: d } = e, c = n.getCommentWithChildren(s, a, d);
|
|
413
413
|
if (!c)
|
|
414
414
|
return !1;
|
|
415
415
|
const u = [c.root, ...c.children];
|
|
@@ -429,7 +429,7 @@ const ne = {
|
|
|
429
429
|
subUnitId: a,
|
|
430
430
|
comment: v
|
|
431
431
|
}
|
|
432
|
-
})), _ = G(i,
|
|
432
|
+
})), _ = G(i, t);
|
|
433
433
|
return _.result && m.pushUndoRedo({
|
|
434
434
|
undoMutations: C,
|
|
435
435
|
redoMutations: i,
|
|
@@ -437,23 +437,24 @@ const ne = {
|
|
|
437
437
|
}), _.result;
|
|
438
438
|
}
|
|
439
439
|
};
|
|
440
|
-
var me = Object.defineProperty, se = Object.getOwnPropertyDescriptor, ae = (r, e,
|
|
441
|
-
for (var o =
|
|
442
|
-
(s = r[m]) && (o = (
|
|
443
|
-
return
|
|
444
|
-
}, $ = (r, e) => (
|
|
440
|
+
var me = Object.defineProperty, se = Object.getOwnPropertyDescriptor, ae = (r, e, n, t) => {
|
|
441
|
+
for (var o = t > 1 ? void 0 : t ? se(e, n) : e, m = r.length - 1, s; m >= 0; m--)
|
|
442
|
+
(s = r[m]) && (o = (t ? s(e, n, o) : s(o)) || o);
|
|
443
|
+
return t && o && me(e, n, o), o;
|
|
444
|
+
}, $ = (r, e) => (n, t) => e(n, t, r), I;
|
|
445
445
|
let D = (I = class extends B {
|
|
446
|
-
constructor(e,
|
|
446
|
+
constructor(e, n, t) {
|
|
447
447
|
super();
|
|
448
448
|
p(this, "_config");
|
|
449
|
-
this._injector =
|
|
449
|
+
this._injector = n, this._commandService = t, this._config = e;
|
|
450
450
|
}
|
|
451
451
|
onStarting(e) {
|
|
452
|
+
var n;
|
|
452
453
|
F([
|
|
453
454
|
[h],
|
|
454
455
|
[U],
|
|
455
456
|
[f, { useClass: z }]
|
|
456
|
-
], this._config.overrides).forEach(
|
|
457
|
+
], (n = this._config) == null ? void 0 : n.overrides).forEach(
|
|
457
458
|
(t) => {
|
|
458
459
|
e.add(t);
|
|
459
460
|
}
|
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 B=Object.defineProperty;var K=(s,h,d)=>h in s?B(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var f=(s,h,d)=>(K(s,typeof h!="symbol"?h+"":h,d),d);var y;class l{constructor(){f(this,"_commentsMap",{});f(this,"_commentsTreeMap",new Map);f(this,"_commentUpdate$",new h.Subject);f(this,"_commentsTreeMap$",new h.BehaviorSubject({}));f(this,"_commentsMap$",new h.BehaviorSubject({}));f(this,"commentUpdate$",this._commentUpdate$.asObservable());f(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());f(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((r,a)=>{n[a]={};const i=n[a];r.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m);let a=e.parentId;if(a){let i=n[a];for(;i!=null&&i.parentId;)i=n[i.parentId],a=i.parentId;if(i){let c=r.get(a);c||(c=[]),c.push(e.id),r.set(a,c)}}else r.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e){const{commentMap:n}=this.ensureMap(t,m),r=n[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:r}=this.ensureMap(t,m),a=r[e];return a?(a.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var p;const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return;const i=new Set,c=(p=r.get(e))!=null?p:[],u=c==null?void 0:c.map(C=>n[C]);return[a,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:a,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:r}=this.ensureMap(t,m),a=n[e];if(!a)return!1;if(a.parentId){const i=r.get(a.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],r.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!a.parentId,comment:a}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(r=>{this.deleteComment(t,e,r.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var D=(o=>(o[o.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",o[o.UNIVER_DOC=1]="UNIVER_DOC",o[o.UNIVER_SHEET=2]="UNIVER_SHEET",o[o.UNIVER_SLIDE=3]="UNIVER_SLIDE",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const M=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(o,t,m,e)=>{for(var n=e>1?void 0:e?W(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&V(t,m,n),n},N=(o,t)=>(m,e)=>t(m,e,o);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),r={};return n?(n.forEach(([a,i])=>{r[a]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const r=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(r).forEach(a=>{n[a].forEach(c=>{this._threadCommentModel.addComment(e,a,c)})})}}))}},s.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(l)),N(2,M)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,comment:r}=t;return m.addComment(e,n,r)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateComment(e,n,r)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,payload:r}=t;return m.updateCommentRef(e,n,r)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,resolved:r,commentId:a}=t;return m.resolveComment(e,n,a,r)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(o,t){if(!t)return!1;const m=o.get(l),{unitId:e,subUnitId:n,commentId:r}=t;return m.deleteComment(e,n,r)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(d.ICommandService),e=o.get(d.IUndoRedoService),n=o.get(M),{unitId:r,subUnitId:a,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},p={id:T.id,params:{unitId:r,subUnitId:a,commentId:c.id}};return e.pushUndoRedo({undoMutations:[p],redoMutations:[u],unitID:r}),m.executeCommand(u.id,u.params),!0}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,r=o.get(d.ICommandService),a=o.get(d.IUndoRedoService),i=o.get(l),c=o.get(M),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return a.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),r.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:r}=t,a=o.get(M),c=o.get(l).getComment(m,e,r);return!c||!await a.updateComment({...c,resolved:n})?!1:(o.get(d.ICommandService).executeCommand(O.id,t),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(M),n=o.get(d.ICommandService),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getComment(a,i,c);if(!u||!await e.deleteComment(c))return!1;const p={id:T.id,params:t},C={id:S.id,params:{unitId:a,subUnitId:i,comment:u}};return r.pushUndoRedo({undoMutations:[C],redoMutations:[p],unitID:a}),n.executeCommand(p.id,p.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(o,t){if(!t)return!1;const m=o.get(l),e=o.get(d.ICommandService),n=o.get(M),r=o.get(d.IUndoRedoService),{unitId:a,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(a,i,c);if(!u)return!1;const p=[u.root,...u.children];if(!await n.deleteCommentBatch(p.map(g=>g.id)))return!1;const C=p.map(g=>({id:T.id,params:{unitId:a,subUnitId:i,commentId:g.id}})),_=p.map(g=>({id:S.id,params:{unitId:a,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&r.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:a}),I.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(o,t,m,e)=>{for(var n=e>1?void 0:e?H(t,m):t,r=o.length-1,a;r>=0;r--)(a=o[r])&&(n=(e?a(t,m,n):a(n))||n);return e&&n&&G(t,m,n),n},L=(o,t)=>(m,e)=>t(m,e,o);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();f(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){var e;d.mergeOverrideWithDependencies([[l],[s.ThreadCommentResourceController],[M,{useClass:$}]],(e=this._config)==null?void 0:e.overrides).forEach(n=>{m.add(n)}),[b,w,P,A,j,S,v,E,T,O].forEach(n=>{this._commandService.registerCommand(n)})}},f(y,"pluginName",R),f(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=q([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=b,s.AddCommentMutation=S,s.DeleteCommentCommand=P,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=j,s.IThreadCommentDataSourceService=M,s.ResolveCommentCommand=A,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=$,s.ThreadCommentModel=l,s.UpdateCommentCommand=w,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/thread-comment",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment core plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@wendellhu/redi": "0.15.2",
|
|
51
51
|
"rxjs": ">=7.0.0",
|
|
52
|
-
"@univerjs/core": "0.1.
|
|
52
|
+
"@univerjs/core": "0.1.13"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@univerjs/protocol": "^0.1.32"
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"@wendellhu/redi": "0.15.2",
|
|
59
59
|
"rxjs": "^7.8.1",
|
|
60
60
|
"typescript": "^5.4.5",
|
|
61
|
-
"vite": "^5.2.
|
|
61
|
+
"vite": "^5.2.12",
|
|
62
62
|
"vitest": "^1.6.0",
|
|
63
|
-
"@univerjs/core": "0.1.
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/ui": "0.1.
|
|
63
|
+
"@univerjs/core": "0.1.13",
|
|
64
|
+
"@univerjs/shared": "0.1.13",
|
|
65
|
+
"@univerjs/design": "0.1.13",
|
|
66
|
+
"@univerjs/ui": "0.1.13"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "vitest run",
|