@univerjs/thread-comment 0.5.1 → 0.5.2
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 +72 -68
- package/lib/types/index.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var x=(m,a,e)=>a in m?$(m,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[a]=e;var l=(m,a,e)=>x(m,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),j=require("rxjs");class E extends d.Disposable{constructor(){super();l(this,"_dataSource",null);l(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const r=e[o];n[o]=r.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const p=d.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(m,a,e,t)=>{for(var n=t>1?void 0:t?V(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&L(a,e,n),n},I=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new j.Subject);l(this,"commentUpdate$",this._commentUpdate$.asObservable());l(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:r,subUnitId:s,threadIds:c})=>{let i=o.get(r);i||(i=new Map,o.set(r,i));let h=i.get(s);h||(h=new Set,i.set(s,h));for(const u of c)h.add(u)}),this._tasks=[],o.forEach((r,s)=>{r.forEach((c,i)=>{this.syncThreadComments(s,i,Array.from(c))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n.id);if(r){const{children:s,...c}=n,i={...c,ref:r.ref};o.set(n.id,i),s==null||s.forEach(h=>{o.set(h.id,{...h,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:i}),!!n.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),r=this._ensureCommentMap(e,t),s=await this._dataSourceService.listThreadComments(e,t,n);if(!s)return;const c=new Set(n);s.forEach(i=>{this._replaceComment(e,t,i),c.delete(i.threadId)}),c.forEach(i=>{o.delete(i),r.forEach((h,u)=>{h.threadId===i&&r.delete(u)})})}addComment(e,t,n,o){const r=this._ensureCommentMap(e,t),{parentId:s,children:c=[],...i}=n,h={...i,parentId:s===n.id?void 0:s};h.threadId||(h.threadId=h.parentId||h.id);const u=C=>{r.set(C.id,C),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:C,isRoot:!C.parentId})};u(h);const N=this._ensureThreadMap(e,t);if(!h.parentId){N.set(h.threadId,h);for(const C of c)u(C)}return o&&this.syncThreadComments(e,t,[h.threadId]),!0}updateComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s&&(s.updated=!0,s.text=n.text,s.attachments=n.attachments,s.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s?(s.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:s.threadId}),!0):!1}resolveComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n);return s?(s.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),r=Array.from(o.values()).filter(h=>h.threadId===n);let s;const c=[],i=new Set;for(const h of r)h.parentId?c.push(h):s=h,i.add(h.personId);if(s)return{root:s,children:c,relativeUsers:i,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n);r&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!r.parentId,comment:r}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(s=>{s.threadId===n&&this._deleteComment(e,t,s.id)})}deleteComment(e,t,n){const r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(r=>{this.deleteComment(e,o,r.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,r)=>{o.forEach((s,c)=>{const i=this.getThread(e,r,c);i&&n.push(i)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};exports.ThreadCommentModel=W([I(0,d.Inject(p)),I(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var v=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,H=Object.getOwnPropertyDescriptor,J=(m,a,e,t)=>{for(var n=t>1?void 0:t?H(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&b(a,e,n),n},_=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(a,e,t){super(),this._resourceManagerService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const a=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(r=>{var c;const s=(c=o[r.subUnitId])!=null?c:[];s.push({...r.root,children:r.children}),o[r.subUnitId]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>a(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const r=n[o];r.forEach(s=>{this._threadCommentModel.addComment(t,o,s)}),this._threadCommentModel.syncThreadComments(t,o,r.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=J([_(0,d.IResourceManagerService),_(1,d.Inject(exports.ThreadCommentModel)),_(2,p)],exports.ThreadCommentResourceController);const g={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,a,e){if(!a)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=a,c=s||(e==null?void 0:e.fromChangeset)&&!r.parentId;return t.addComment(n,o,r,c)}},y={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateComment(t,n,o,r)}},R={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=a;return e.resolveComment(t,n,r,o)}},M={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=a;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(d.ICommandService),t=m.get(p),{comment:n}=a,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:g.id,params:{...a,comment:o}};return s?await e.executeCommand(c.id,c.params):e.executeCommand(c.id,c.params,{onlyLocal:!r})}},D={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,payload:n}=a,o=m.get(d.ICommandService),r=m.get(exports.ThreadCommentModel),s=m.get(p),c=s.syncUpdateMutationToColla,i=r.getComment(e,t,n.commentId);if(!i)return!1;const{children:h,...u}=i;if(!await s.updateComment({...u,...n}))return!1;const C={id:y.id,params:a};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},P={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=a,r=m.get(p),c=m.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:m.get(d.ICommandService).executeCommand(U.id,a,{onlyLocal:!i})}},w={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(p),n=m.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=a,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:M.id,params:a};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},A={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(d.ICommandService),n=m.get(p),{unitId:o,subUnitId:r,commentId:s}=a,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(M.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},G="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(m,a,e,t)=>{for(var n=t>1?void 0:t?B(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&K(a,e,n),n},T=(m,a)=>(e,t)=>a(e,t,m),f;exports.UniverThreadCommentPlugin=(f=class extends d.Plugin{constructor(a=Y,e,t,n){super(),this._config=a,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(G,o)}onStarting(){var a;d.mergeOverrideWithDependencies([[p,{useClass:E}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(a=this._config)==null?void 0:a.overrides).forEach(e=>{this._injector.add(e)}),[O,D,w,P,A,g,y,R,M,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(f,"pluginName",S),l(f,"type",d.UniverInstanceType.UNIVER_UNKNOWN),f);exports.UniverThreadCommentPlugin=q([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function Z(){return d.dayjs().format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=O;exports.AddCommentMutation=g;exports.DeleteCommentCommand=w;exports.DeleteCommentMutation=M;exports.DeleteCommentTreeCommand=A;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=U;exports.TC_PLUGIN_NAME=S;exports.ThreadCommentDataSourceService=E;exports.UpdateCommentCommand=D;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=R;exports.getDT=Z;
|
|
1
|
+
"use strict";var x=Object.defineProperty;var j=(m,a,e)=>a in m?x(m,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[a]=e;var l=(m,a,e)=>j(m,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),L=require("rxjs");class R extends d.Disposable{constructor(){super();l(this,"_dataSource",null);l(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const r=e[o];n[o]=r.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const p=d.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,b=(m,a,e,t)=>{for(var n=t>1?void 0:t?W(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&V(a,e,n),n},I=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new L.Subject);l(this,"commentUpdate$",this._commentUpdate$.asObservable());l(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:r,subUnitId:s,threadIds:c})=>{let i=o.get(r);i||(i=new Map,o.set(r,i));let h=i.get(s);h||(h=new Set,i.set(s,h));for(const u of c)h.add(u)}),this._tasks=[],o.forEach((r,s)=>{r.forEach((c,i)=>{this.syncThreadComments(s,i,Array.from(c))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n.id);if(r){const{children:s,...c}=n,i={...c,ref:r.ref};o.set(n.id,i),s==null||s.forEach(h=>{o.set(h.id,{...h,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:i}),!!n.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),r=this._ensureCommentMap(e,t),s=await this._dataSourceService.listThreadComments(e,t,n);if(!s)return;const c=new Set(n);s.forEach(i=>{this._replaceComment(e,t,i),c.delete(i.threadId)}),c.forEach(i=>{o.delete(i),r.forEach((h,u)=>{h.threadId===i&&r.delete(u)})})}addComment(e,t,n,o){const r=this._ensureCommentMap(e,t),{parentId:s,children:c=[],...i}=n,h={...i,parentId:s===n.id?void 0:s};h.threadId||(h.threadId=h.parentId||h.id);const u=C=>{r.set(C.id,C),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:C,isRoot:!C.parentId})};u(h);const N=this._ensureThreadMap(e,t);if(!h.parentId){N.set(h.threadId,h);for(const C of c)u(C)}return o&&this.syncThreadComments(e,t,[h.threadId]),!0}updateComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s&&(s.updated=!0,s.text=n.text,s.attachments=n.attachments,s.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s?(s.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:s.threadId}),!0):!1}resolveComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n);return s?(s.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),r=Array.from(o.values()).filter(h=>h.threadId===n);let s;const c=[],i=new Set;for(const h of r)h.parentId?c.push(h):s=h,i.add(h.personId);if(s)return{root:s,children:c,relativeUsers:i,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n);r&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!r.parentId,comment:r}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(s=>{s.threadId===n&&this._deleteComment(e,t,s.id)})}deleteComment(e,t,n){const r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(r=>{this.deleteComment(e,o,r.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,r)=>{o.forEach((s,c)=>{const i=this.getThread(e,r,c);i&&n.push(i)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};exports.ThreadCommentModel=b([I(0,d.Inject(p)),I(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var v=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var H=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(m,a,e,t)=>{for(var n=t>1?void 0:t?J(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&H(a,e,n),n},_=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(a,e,t){super(),this._resourceManagerService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const a=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(r=>{var c;const s=(c=o[r.subUnitId])!=null?c:[];s.push({...r.root,children:r.children}),o[r.subUnitId]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>a(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const r=n[o];r.forEach(s=>{this._threadCommentModel.addComment(t,o,s)}),this._threadCommentModel.syncThreadComments(t,o,r.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=G([_(0,d.IResourceManagerService),_(1,d.Inject(exports.ThreadCommentModel)),_(2,p)],exports.ThreadCommentResourceController);const g={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,a,e){if(!a)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=a,c=s||(e==null?void 0:e.fromChangeset)&&!r.parentId;return t.addComment(n,o,r,c)}},y={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateComment(t,n,o,r)}},O={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=a;return e.resolveComment(t,n,r,o)}},M={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=a;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(d.ICommandService),t=m.get(p),{comment:n}=a,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:g.id,params:{...a,comment:o}};return s?await e.executeCommand(c.id,c.params):e.executeCommand(c.id,c.params,{onlyLocal:!r})}},P={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,payload:n}=a,o=m.get(d.ICommandService),r=m.get(exports.ThreadCommentModel),s=m.get(p),c=s.syncUpdateMutationToColla,i=r.getComment(e,t,n.commentId);if(!i)return!1;const{children:h,...u}=i;if(!await s.updateComment({...u,...n}))return!1;const C={id:y.id,params:a};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},w={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=a,r=m.get(p),c=m.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:m.get(d.ICommandService).executeCommand(U.id,a,{onlyLocal:!i})}},A={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(p),n=m.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=a,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:M.id,params:a};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},$={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(d.ICommandService),n=m.get(p),{unitId:o,subUnitId:r,commentId:s}=a,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(M.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},Y="thread-comment.config",E={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(m,a,e,t)=>{for(var n=t>1?void 0:t?B(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&K(a,e,n),n},T=(m,a)=>(e,t)=>a(e,t,m),f;exports.UniverThreadCommentPlugin=(f=class extends d.Plugin{constructor(a=E,e,t,n){super(),this._config=a,this._injector=e,this._commandService=t,this._configService=n;const{...o}=d.merge({},E,this._config);this._configService.setConfig(Y,o)}onStarting(){var a;d.mergeOverrideWithDependencies([[p,{useClass:R}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(a=this._config)==null?void 0:a.overrides).forEach(e=>{this._injector.add(e)}),[D,P,A,w,$,g,y,O,M,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(f,"pluginName",S),l(f,"type",d.UniverInstanceType.UNIVER_UNKNOWN),f);exports.UniverThreadCommentPlugin=q([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function Z(){return d.dayjs().format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=D;exports.AddCommentMutation=g;exports.DeleteCommentCommand=A;exports.DeleteCommentMutation=M;exports.DeleteCommentTreeCommand=$;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=w;exports.ResolveCommentMutation=U;exports.TC_PLUGIN_NAME=S;exports.ThreadCommentDataSourceService=R;exports.UpdateCommentCommand=P;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=O;exports.getDT=Z;
|
package/lib/es/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (s, t, e) =>
|
|
4
|
-
import { createIdentifier as
|
|
5
|
-
import { Subject as
|
|
6
|
-
class
|
|
1
|
+
var A = Object.defineProperty;
|
|
2
|
+
var j = (s, t, e) => t in s ? A(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var u = (s, t, e) => j(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createIdentifier as L, Disposable as U, Inject as v, LifecycleService as V, LifecycleStages as O, IResourceManagerService as W, CommandType as l, ICommandService as f, Plugin as H, merge as J, UniverInstanceType as G, mergeOverrideWithDependencies as b, Injector as Y, IConfigService as K, dayjs as B } from "@univerjs/core";
|
|
5
|
+
import { Subject as Z } from "rxjs";
|
|
6
|
+
class F extends U {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
9
9
|
u(this, "_dataSource", null);
|
|
@@ -45,18 +45,18 @@ class B extends U {
|
|
|
45
45
|
return e;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
const p =
|
|
49
|
-
var
|
|
50
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
48
|
+
const p = L("univer.thread-comment.data-source-service");
|
|
49
|
+
var q = Object.defineProperty, z = Object.getOwnPropertyDescriptor, Q = (s, t, e, n) => {
|
|
50
|
+
for (var o = n > 1 ? void 0 : n ? z(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
51
51
|
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
52
|
-
return n && o &&
|
|
52
|
+
return n && o && q(t, e, o), o;
|
|
53
53
|
}, I = (s, t) => (e, n) => t(e, n, s);
|
|
54
54
|
let i = class extends U {
|
|
55
55
|
constructor(t, e) {
|
|
56
56
|
super();
|
|
57
57
|
u(this, "_commentsMap", /* @__PURE__ */ new Map());
|
|
58
58
|
u(this, "_threadMap", /* @__PURE__ */ new Map());
|
|
59
|
-
u(this, "_commentUpdate$", new
|
|
59
|
+
u(this, "_commentUpdate$", new Z());
|
|
60
60
|
u(this, "commentUpdate$", this._commentUpdate$.asObservable());
|
|
61
61
|
u(this, "_tasks", []);
|
|
62
62
|
this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
|
|
@@ -273,16 +273,16 @@ let i = class extends U {
|
|
|
273
273
|
}), t;
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
|
-
i =
|
|
276
|
+
i = Q([
|
|
277
277
|
I(0, v(p)),
|
|
278
|
-
I(1, v(
|
|
278
|
+
I(1, v(V))
|
|
279
279
|
], i);
|
|
280
280
|
var T = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(T || {});
|
|
281
|
-
const
|
|
282
|
-
var
|
|
283
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
281
|
+
const w = "UNIVER_THREAD_COMMENT_PLUGIN";
|
|
282
|
+
var X = Object.defineProperty, k = Object.getOwnPropertyDescriptor, ee = (s, t, e, n) => {
|
|
283
|
+
for (var o = n > 1 ? void 0 : n ? k(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
284
284
|
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
285
|
-
return n && o &&
|
|
285
|
+
return n && o && X(t, e, o), o;
|
|
286
286
|
}, S = (s, t) => (e, n) => t(e, n, s);
|
|
287
287
|
let g = class extends U {
|
|
288
288
|
constructor(s, t, e) {
|
|
@@ -310,7 +310,7 @@ let g = class extends U {
|
|
|
310
310
|
};
|
|
311
311
|
this.disposeWithMe(
|
|
312
312
|
this._resourceManagerService.registerPluginResource({
|
|
313
|
-
pluginName: `SHEET_${
|
|
313
|
+
pluginName: `SHEET_${w}`,
|
|
314
314
|
businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
|
|
315
315
|
toJson: (e) => s(e),
|
|
316
316
|
parseJson: (e) => t(e),
|
|
@@ -329,12 +329,12 @@ let g = class extends U {
|
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
};
|
|
332
|
-
g =
|
|
333
|
-
S(0,
|
|
332
|
+
g = ee([
|
|
333
|
+
S(0, W),
|
|
334
334
|
S(1, v(i)),
|
|
335
335
|
S(2, p)
|
|
336
336
|
], g);
|
|
337
|
-
const
|
|
337
|
+
const P = {
|
|
338
338
|
id: "thread-comment.mutation.add-comment",
|
|
339
339
|
type: l.MUTATION,
|
|
340
340
|
handler(s, t, e) {
|
|
@@ -343,7 +343,7 @@ const w = {
|
|
|
343
343
|
const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
|
|
344
344
|
return n.addComment(o, r, a, m);
|
|
345
345
|
}
|
|
346
|
-
},
|
|
346
|
+
}, $ = {
|
|
347
347
|
id: "thread-comment.mutation.update-comment",
|
|
348
348
|
type: l.MUTATION,
|
|
349
349
|
handler(s, t) {
|
|
@@ -352,7 +352,7 @@ const w = {
|
|
|
352
352
|
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
353
353
|
return e.updateComment(n, o, r, a);
|
|
354
354
|
}
|
|
355
|
-
},
|
|
355
|
+
}, te = {
|
|
356
356
|
id: "thread-comment.mutation.update-comment-ref",
|
|
357
357
|
type: l.MUTATION,
|
|
358
358
|
handler(s, t) {
|
|
@@ -361,7 +361,7 @@ const w = {
|
|
|
361
361
|
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
362
362
|
return e.updateCommentRef(n, o, r, a);
|
|
363
363
|
}
|
|
364
|
-
},
|
|
364
|
+
}, x = {
|
|
365
365
|
id: "thread-comment.mutation.resolve-comment",
|
|
366
366
|
type: l.MUTATION,
|
|
367
367
|
handler(s, t) {
|
|
@@ -379,14 +379,14 @@ const w = {
|
|
|
379
379
|
const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
|
|
380
380
|
return e.deleteComment(n, o, r);
|
|
381
381
|
}
|
|
382
|
-
},
|
|
382
|
+
}, ne = {
|
|
383
383
|
id: "thread-comment.command.add-comment",
|
|
384
384
|
type: l.COMMAND,
|
|
385
385
|
async handler(s, t) {
|
|
386
386
|
if (!t)
|
|
387
387
|
return !1;
|
|
388
388
|
const e = s.get(f), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
|
|
389
|
-
id:
|
|
389
|
+
id: P.id,
|
|
390
390
|
params: {
|
|
391
391
|
...t,
|
|
392
392
|
comment: r
|
|
@@ -396,7 +396,7 @@ const w = {
|
|
|
396
396
|
onlyLocal: !a
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
|
-
},
|
|
399
|
+
}, oe = {
|
|
400
400
|
id: "thread-comment.command.update-comment",
|
|
401
401
|
type: l.COMMAND,
|
|
402
402
|
async handler(s, t) {
|
|
@@ -416,12 +416,12 @@ const w = {
|
|
|
416
416
|
}))
|
|
417
417
|
return !1;
|
|
418
418
|
const E = {
|
|
419
|
-
id:
|
|
419
|
+
id: $.id,
|
|
420
420
|
params: t
|
|
421
421
|
};
|
|
422
422
|
return r.executeCommand(E.id, E.params, { onlyLocal: !m }), !0;
|
|
423
423
|
}
|
|
424
|
-
},
|
|
424
|
+
}, re = {
|
|
425
425
|
id: "thread-comment.command.resolve-comment",
|
|
426
426
|
type: l.COMMAND,
|
|
427
427
|
async handler(s, t) {
|
|
@@ -432,12 +432,12 @@ const w = {
|
|
|
432
432
|
...m,
|
|
433
433
|
resolved: o
|
|
434
434
|
}) ? !1 : s.get(f).executeCommand(
|
|
435
|
-
|
|
435
|
+
x.id,
|
|
436
436
|
t,
|
|
437
437
|
{ onlyLocal: !c }
|
|
438
438
|
);
|
|
439
439
|
}
|
|
440
|
-
},
|
|
440
|
+
}, ae = {
|
|
441
441
|
id: "thread-comment.command.delete-comment",
|
|
442
442
|
type: l.COMMAND,
|
|
443
443
|
async handler(s, t) {
|
|
@@ -452,7 +452,7 @@ const w = {
|
|
|
452
452
|
};
|
|
453
453
|
return o.executeCommand(h.id, h.params, { onlyLocal: !m });
|
|
454
454
|
}
|
|
455
|
-
},
|
|
455
|
+
}, se = {
|
|
456
456
|
id: "thread-comment.command.delete-comment-tree",
|
|
457
457
|
type: l.COMMAND,
|
|
458
458
|
async handler(s, t) {
|
|
@@ -465,22 +465,26 @@ const w = {
|
|
|
465
465
|
commentId: m.root.id
|
|
466
466
|
});
|
|
467
467
|
}
|
|
468
|
-
},
|
|
469
|
-
var
|
|
470
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
468
|
+
}, me = "thread-comment.config", R = {};
|
|
469
|
+
var ce = Object.defineProperty, de = Object.getOwnPropertyDescriptor, ie = (s, t, e, n) => {
|
|
470
|
+
for (var o = n > 1 ? void 0 : n ? de(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
471
471
|
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
|
|
472
|
-
return n && o &&
|
|
472
|
+
return n && o && ce(t, e, o), o;
|
|
473
473
|
}, y = (s, t) => (e, n) => t(e, n, s), M;
|
|
474
|
-
let
|
|
475
|
-
constructor(s =
|
|
474
|
+
let D = (M = class extends H {
|
|
475
|
+
constructor(s = R, t, e, n) {
|
|
476
476
|
super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
|
|
477
|
-
const { ...o } =
|
|
478
|
-
|
|
477
|
+
const { ...o } = J(
|
|
478
|
+
{},
|
|
479
|
+
R,
|
|
480
|
+
this._config
|
|
481
|
+
);
|
|
482
|
+
this._configService.setConfig(me, o);
|
|
479
483
|
}
|
|
480
484
|
onStarting() {
|
|
481
485
|
var s;
|
|
482
|
-
|
|
483
|
-
[p, { useClass:
|
|
486
|
+
b([
|
|
487
|
+
[p, { useClass: F }],
|
|
484
488
|
[i],
|
|
485
489
|
[g]
|
|
486
490
|
], (s = this._config) == null ? void 0 : s.overrides).forEach(
|
|
@@ -488,45 +492,45 @@ let R = (M = class extends W {
|
|
|
488
492
|
this._injector.add(t);
|
|
489
493
|
}
|
|
490
494
|
), [
|
|
491
|
-
ee,
|
|
492
|
-
te,
|
|
493
|
-
oe,
|
|
494
495
|
ne,
|
|
496
|
+
oe,
|
|
497
|
+
ae,
|
|
495
498
|
re,
|
|
496
|
-
|
|
499
|
+
se,
|
|
497
500
|
P,
|
|
498
|
-
|
|
501
|
+
$,
|
|
502
|
+
te,
|
|
499
503
|
N,
|
|
500
|
-
|
|
504
|
+
x
|
|
501
505
|
].forEach((t) => {
|
|
502
506
|
this._commandService.registerCommand(t);
|
|
503
507
|
}), this._injector.get(g);
|
|
504
508
|
}
|
|
505
|
-
}, u(M, "pluginName",
|
|
506
|
-
|
|
507
|
-
y(1, v(
|
|
509
|
+
}, u(M, "pluginName", w), u(M, "type", G.UNIVER_UNKNOWN), M);
|
|
510
|
+
D = ie([
|
|
511
|
+
y(1, v(Y)),
|
|
508
512
|
y(2, f),
|
|
509
|
-
y(3,
|
|
510
|
-
],
|
|
511
|
-
function
|
|
512
|
-
return
|
|
513
|
+
y(3, K)
|
|
514
|
+
], D);
|
|
515
|
+
function pe() {
|
|
516
|
+
return B().format("YYYY/MM/DD HH:mm");
|
|
513
517
|
}
|
|
514
518
|
export {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
519
|
+
ne as AddCommentCommand,
|
|
520
|
+
P as AddCommentMutation,
|
|
521
|
+
ae as DeleteCommentCommand,
|
|
518
522
|
N as DeleteCommentMutation,
|
|
519
|
-
|
|
523
|
+
se as DeleteCommentTreeCommand,
|
|
520
524
|
p as IThreadCommentDataSourceService,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
+
re as ResolveCommentCommand,
|
|
526
|
+
x as ResolveCommentMutation,
|
|
527
|
+
w as TC_PLUGIN_NAME,
|
|
528
|
+
F as ThreadCommentDataSourceService,
|
|
525
529
|
i as ThreadCommentModel,
|
|
526
530
|
g as ThreadCommentResourceController,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
D as UniverThreadCommentPlugin,
|
|
532
|
+
oe as UpdateCommentCommand,
|
|
533
|
+
$ as UpdateCommentMutation,
|
|
534
|
+
te as UpdateCommentRefMutation,
|
|
535
|
+
pe as getDT
|
|
532
536
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { type CommentUpdate, ThreadCommentModel } from './models/thread-comment.model';
|
|
16
|
+
export { type CommentUpdate, type IThreadInfo, ThreadCommentModel } from './models/thread-comment.model';
|
|
17
17
|
export { ThreadCommentResourceController } from './controllers/tc-resource.controller';
|
|
18
18
|
export { TC_PLUGIN_NAME } from './types/const';
|
|
19
19
|
export type { IBaseComment, IThreadComment, IThreadCommentMention } from './types/interfaces/i-thread-comment';
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,function(s,c,M){"use strict";var F=Object.defineProperty;var z=(s,c,M)=>c in s?F(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>z(s,typeof c!="symbol"?c+"":c,M);var T;class E extends c.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=c.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(r,m,e,t)=>{for(var n=t>1?void 0:t?V(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&L(m,e,n),n},R=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentModel=class extends c.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===c.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:d,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(d);l||(l=new Set,h.set(d,l));for(const f of i)l.add(f)}),this._tasks=[],o.forEach((a,d)=>{a.forEach((i,h)=>{this.syncThreadComments(d,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:d,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),d==null||d.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<c.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const i=new Set(n);d.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,f)=>{l.threadId===h&&a.delete(f)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:d,children:i=[],...h}=n,l={...h,parentId:d===n.id?void 0:d};l.threadId||(l.threadId=l.parentId||l.id);const f=p=>{a.set(p.id,p),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})};f(l);const $=this._ensureThreadMap(e,t);if(!l.parentId){$.set(l.threadId,l);for(const p of i)f(p)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d&&(d.updated=!0,d.text=n.text,d.attachments=n.attachments,d.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d?(d.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n);return d?(d.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let d;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):d=l,h.add(l.personId);if(d)return{root:d,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(d=>{d.threadId===n&&this._deleteComment(e,t,d.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((d,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},s.ThreadCommentModel=W([R(0,c.Inject(C)),R(1,c.Inject(c.LifecycleService))],s.ThreadCommentModel);var v=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,H=Object.getOwnPropertyDescriptor,J=(r,m,e,t)=>{for(var n=t>1?void 0:t?H(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&b(m,e,n),n},g=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentResourceController=class extends c.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const d=(i=o[a.subUnitId])!=null?i:[];d.push({...a.root,children:a.children}),o[a.subUnitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(d=>{this._threadCommentModel.addComment(t,o,d)}),this._threadCommentModel.syncThreadComments(t,o,a.map(d=>d.threadId))})}}))}},s.ThreadCommentResourceController=J([g(0,c.IResourceManagerService),g(1,c.Inject(s.ThreadCommentModel)),g(2,C)],s.ThreadCommentResourceController);const y={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(r,m,e){if(!m)return!1;const t=r.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=m,i=d||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},U={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(c.ICommandService),t=r.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...m,comment:o}};return d?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},P={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=r.get(c.ICommandService),a=r.get(s.ThreadCommentModel),d=r.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...f}=h;if(!await d.updateComment({...f,...n}))return!1;const p={id:U.id,params:m};return o.executeCommand(p.id,p.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=r.get(C),i=r.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:r.get(c.ICommandService).executeCommand(N.id,m,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(C),n=r.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,d);if(!h||!await t.deleteComment(o,a,h.threadId,d))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},A={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(c.ICommandService),n=r.get(C),{unitId:o,subUnitId:a,commentId:d}=m,i=e.getCommentWithChildren(o,a,d);return!i||!await n.deleteComment(o,a,i.root.threadId,d)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}},G="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(r,m,e,t)=>{for(var n=t>1?void 0:t?B(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&K(m,e,n),n},I=(r,m)=>(e,t)=>m(e,t,r);s.UniverThreadCommentPlugin=(T=class extends c.Plugin{constructor(m=Y,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(G,o)}onStarting(){var m;c.mergeOverrideWithDependencies([[C,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[D,P,j,w,A,y,U,O,_,N].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(T,"pluginName",S),u(T,"type",c.UniverInstanceType.UNIVER_UNKNOWN),T),s.UniverThreadCommentPlugin=q([I(1,c.Inject(c.Injector)),I(2,c.ICommandService),I(3,c.IConfigService)],s.UniverThreadCommentPlugin);function Z(){return c.dayjs().format("YYYY/MM/DD HH:mm")}s.AddCommentCommand=D,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=A,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=N,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=P,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=O,s.getDT=Z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,function(s,c,M){"use strict";var F=Object.defineProperty;var z=(s,c,M)=>c in s?F(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>z(s,typeof c!="symbol"?c+"":c,M);var T;class E extends c.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=c.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,b=(r,m,e,t)=>{for(var n=t>1?void 0:t?W(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&V(m,e,n),n},R=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentModel=class extends c.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===c.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:d,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(d);l||(l=new Set,h.set(d,l));for(const f of i)l.add(f)}),this._tasks=[],o.forEach((a,d)=>{a.forEach((i,h)=>{this.syncThreadComments(d,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:d,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),d==null||d.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<c.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const i=new Set(n);d.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,f)=>{l.threadId===h&&a.delete(f)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:d,children:i=[],...h}=n,l={...h,parentId:d===n.id?void 0:d};l.threadId||(l.threadId=l.parentId||l.id);const f=p=>{a.set(p.id,p),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})};f(l);const L=this._ensureThreadMap(e,t);if(!l.parentId){L.set(l.threadId,l);for(const p of i)f(p)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d&&(d.updated=!0,d.text=n.text,d.attachments=n.attachments,d.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d?(d.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n);return d?(d.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let d;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):d=l,h.add(l.personId);if(d)return{root:d,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(d=>{d.threadId===n&&this._deleteComment(e,t,d.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((d,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},s.ThreadCommentModel=b([R(0,c.Inject(C)),R(1,c.Inject(c.LifecycleService))],s.ThreadCommentModel);var v=(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.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var H=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(r,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&H(m,e,n),n},g=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentResourceController=class extends c.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const d=(i=o[a.subUnitId])!=null?i:[];d.push({...a.root,children:a.children}),o[a.subUnitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(d=>{this._threadCommentModel.addComment(t,o,d)}),this._threadCommentModel.syncThreadComments(t,o,a.map(d=>d.threadId))})}}))}},s.ThreadCommentResourceController=G([g(0,c.IResourceManagerService),g(1,c.Inject(s.ThreadCommentModel)),g(2,C)],s.ThreadCommentResourceController);const y={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(r,m,e){if(!m)return!1;const t=r.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=m,i=d||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},U={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(c.ICommandService),t=r.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...m,comment:o}};return d?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},P={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=r.get(c.ICommandService),a=r.get(s.ThreadCommentModel),d=r.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...f}=h;if(!await d.updateComment({...f,...n}))return!1;const p={id:U.id,params:m};return o.executeCommand(p.id,p.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=r.get(C),i=r.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:r.get(c.ICommandService).executeCommand(N.id,m,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(C),n=r.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,d);if(!h||!await t.deleteComment(o,a,h.threadId,d))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},A={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(c.ICommandService),n=r.get(C),{unitId:o,subUnitId:a,commentId:d}=m,i=e.getCommentWithChildren(o,a,d);return!i||!await n.deleteComment(o,a,i.root.threadId,d)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}},Y="thread-comment.config",$={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(r,m,e,t)=>{for(var n=t>1?void 0:t?B(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&K(m,e,n),n},I=(r,m)=>(e,t)=>m(e,t,r);s.UniverThreadCommentPlugin=(T=class extends c.Plugin{constructor(m=$,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=c.merge({},$,this._config);this._configService.setConfig(Y,o)}onStarting(){var m;c.mergeOverrideWithDependencies([[C,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[D,P,j,w,A,y,U,O,_,N].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(T,"pluginName",S),u(T,"type",c.UniverInstanceType.UNIVER_UNKNOWN),T),s.UniverThreadCommentPlugin=q([I(1,c.Inject(c.Injector)),I(2,c.ICommandService),I(3,c.IConfigService)],s.UniverThreadCommentPlugin);function Z(){return c.dayjs().format("YYYY/MM/DD HH:mm")}s.AddCommentCommand=D,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=A,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=N,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=P,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=O,s.getDT=Z,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.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment core plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@univerjs/protocol": "0.1.39",
|
|
50
|
-
"@univerjs/core": "0.5.
|
|
50
|
+
"@univerjs/core": "0.5.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.1",
|
|
54
54
|
"typescript": "^5.7.2",
|
|
55
|
-
"vite": "^6.0.
|
|
56
|
-
"vitest": "^2.1.
|
|
57
|
-
"@univerjs-infra/shared": "0.5.
|
|
55
|
+
"vite": "^6.0.3",
|
|
56
|
+
"vitest": "^2.1.8",
|
|
57
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
58
58
|
},
|
|
59
59
|
"space": {
|
|
60
60
|
".": {
|