@univerjs/thread-comment 0.6.1 → 0.6.2-nightly.202503031606
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 +53 -51
- package/lib/types/controllers/tc-resource.controller.d.ts +1 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var j=(a,m,e)=>m in a?$(a,m,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[m]=e;var l=(a,m,e)=>j(a,typeof m!="symbol"?m+"":m,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.getOwnPropertyDescriptor,W=(a,m,e,t)=>{for(var n=t>1?void 0:t?V(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},I=(a,m)=>(e,t)=>m(e,t,a);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=W([I(0,d.Inject(p)),I(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var g=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNIVER_PROJECT=4]="UNIVER_PROJECT",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))(g||{});const v="UNIVER_THREAD_COMMENT_PLUGIN";var H=Object.getOwnPropertyDescriptor,J=(a,m,e,t)=>{for(var n=t>1?void 0:t?H(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},_=(a,m)=>(e,t)=>m(e,t,a);exports.ThreadCommentResourceController=class extends d.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(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_${v}`,businesses:[g.UNIVER_SHEET,g.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 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 S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(a,m,e){if(!m)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=m,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(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=m;return e.updateComment(t,n,o,r)}},O={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=m;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=m;return e.resolveComment(t,n,r,o)}},f={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(d.ICommandService),t=a.get(p),{comment:n}=m,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:S.id,params:{...m,comment:o}};return s?await e.executeCommand(c.id,c.params):e.executeCommand(c.id,c.params,{onlyLocal:!r})}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=a.get(d.ICommandService),r=a.get(exports.ThreadCommentModel),s=a.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:m};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},P={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,r=a.get(p),c=a.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:a.get(d.ICommandService).executeCommand(U.id,m,{onlyLocal:!i})}},A={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(p),n=a.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=m,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:f.id,params:m};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},x={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(d.ICommandService),n=a.get(p),{unitId:o,subUnitId:r,commentId:s}=m,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(f.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},G="thread-comment.config",E={};var b=Object.getOwnPropertyDescriptor,Y=(a,m,e,t)=>{for(var n=t>1?void 0:t?b(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},T=(a,m)=>(e,t)=>m(e,t,a),M;exports.UniverThreadCommentPlugin=(M=class extends d.Plugin{constructor(m=E,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=d.merge({},E,this._config);this._configService.setConfig(G,o)}onStarting(){var m;d.mergeOverrideWithDependencies([[p,{useClass:R}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[D,w,A,P,x,S,y,O,f,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(M,"pluginName",v),l(M,"type",d.UniverInstanceType.UNIVER_UNKNOWN),M);exports.UniverThreadCommentPlugin=Y([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function k(a){return d.dayjs(a).format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=D;exports.AddCommentMutation=S;exports.DeleteCommentCommand=A;exports.DeleteCommentMutation=f;exports.DeleteCommentTreeCommand=x;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=U;exports.TC_PLUGIN_NAME=v;exports.ThreadCommentDataSourceService=R;exports.UpdateCommentCommand=w;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=O;exports.getDT=k;
|
|
1
|
+
"use strict";var L=Object.defineProperty;var j=(a,m,e)=>m in a?L(a,m,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[m]=e;var l=(a,m,e)=>j(a,typeof m!="symbol"?m+"":m,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),V=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 H=Object.getOwnPropertyDescriptor,W=(a,m,e,t)=>{for(var n=t>1?void 0:t?H(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},E=(a,m)=>(e,t)=>m(e,t,a);exports.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new V.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([E(0,d.Inject(p)),E(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var g=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNIVER_PROJECT=4]="UNIVER_PROJECT",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))(g||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var G=Object.getOwnPropertyDescriptor,J=(a,m,e,t)=>{for(var n=t>1?void 0:t?G(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},_=(a,m)=>(e,t)=>m(e,t,a);const O=`SHEET_${S}`;exports.ThreadCommentResourceController=class extends d.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(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:O,businesses:[g.UNIVER_SHEET,g.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 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 v={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(a,m,e){if(!m)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=m,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(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=m;return e.updateComment(t,n,o,r)}},D={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=m;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=m;return e.resolveComment(t,n,r,o)}},f={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},w={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(d.ICommandService),t=a.get(p),{comment:n}=m,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:v.id,params:{...m,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(a,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=a.get(d.ICommandService),r=a.get(exports.ThreadCommentModel),s=a.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:m};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,r=a.get(p),c=a.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:a.get(d.ICommandService).executeCommand(U.id,m,{onlyLocal:!i})}},x={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(p),n=a.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=m,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:f.id,params:m};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},$={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(a,m){if(!m)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(d.ICommandService),n=a.get(p),{unitId:o,subUnitId:r,commentId:s}=m,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(f.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},b="thread-comment.config",I={};var Y=Object.getOwnPropertyDescriptor,k=(a,m,e,t)=>{for(var n=t>1?void 0:t?Y(m,e):m,o=a.length-1,r;o>=0;o--)(r=a[o])&&(n=r(n)||n);return n},T=(a,m)=>(e,t)=>m(e,t,a),M;exports.UniverThreadCommentPlugin=(M=class extends d.Plugin{constructor(m=I,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=d.merge({},I,this._config);this._configService.setConfig(b,o)}onStarting(){var m;d.mergeOverrideWithDependencies([[p,{useClass:R}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[w,P,x,A,$,v,y,D,f,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(M,"pluginName",S),l(M,"type",d.UniverInstanceType.UNIVER_UNKNOWN),M);exports.UniverThreadCommentPlugin=k([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function K(a){return d.dayjs(a).format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=w;exports.AddCommentMutation=v;exports.DeleteCommentCommand=x;exports.DeleteCommentMutation=f;exports.DeleteCommentTreeCommand=$;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=U;exports.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=O;exports.TC_PLUGIN_NAME=S;exports.ThreadCommentDataSourceService=R;exports.UpdateCommentCommand=P;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=D;exports.getDT=K;
|
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var L = (a, t, e) => t in a ?
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var L = (a, t, e) => t in a ? $(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
3
|
var u = (a, t, e) => L(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { createIdentifier as V, Disposable as U, Inject as g, LifecycleService as j, LifecycleStages as O, IResourceManagerService as
|
|
4
|
+
import { createIdentifier as V, Disposable as U, Inject as g, LifecycleService as j, LifecycleStages as O, IResourceManagerService as H, CommandType as l, ICommandService as f, Plugin as W, merge as J, UniverInstanceType as G, mergeOverrideWithDependencies as Y, Injector as k, IConfigService as K, dayjs as B } from "@univerjs/core";
|
|
5
5
|
import { Subject as b } from "rxjs";
|
|
6
6
|
class Z extends U {
|
|
7
7
|
constructor() {
|
|
@@ -153,9 +153,9 @@ let i = class extends U {
|
|
|
153
153
|
});
|
|
154
154
|
};
|
|
155
155
|
h(c);
|
|
156
|
-
const
|
|
156
|
+
const _ = this._ensureThreadMap(t, e);
|
|
157
157
|
if (!c.parentId) {
|
|
158
|
-
|
|
158
|
+
_.set(c.threadId, c);
|
|
159
159
|
for (const C of d)
|
|
160
160
|
h(C);
|
|
161
161
|
}
|
|
@@ -283,8 +283,9 @@ var z = Object.getOwnPropertyDescriptor, Q = (a, t, e, n) => {
|
|
|
283
283
|
for (var o = n > 1 ? void 0 : n ? z(t, e) : t, r = a.length - 1, s; r >= 0; r--)
|
|
284
284
|
(s = a[r]) && (o = s(o) || o);
|
|
285
285
|
return o;
|
|
286
|
-
},
|
|
287
|
-
|
|
286
|
+
}, v = (a, t) => (e, n) => t(e, n, a);
|
|
287
|
+
const X = `SHEET_${w}`;
|
|
288
|
+
let S = class extends U {
|
|
288
289
|
constructor(a, t, e) {
|
|
289
290
|
super(), this._resourceManagerService = a, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
|
|
290
291
|
}
|
|
@@ -310,7 +311,7 @@ let v = class extends U {
|
|
|
310
311
|
};
|
|
311
312
|
this.disposeWithMe(
|
|
312
313
|
this._resourceManagerService.registerPluginResource({
|
|
313
|
-
pluginName:
|
|
314
|
+
pluginName: X,
|
|
314
315
|
businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
|
|
315
316
|
toJson: (e) => a(e),
|
|
316
317
|
parseJson: (e) => t(e),
|
|
@@ -329,11 +330,11 @@ let v = class extends U {
|
|
|
329
330
|
);
|
|
330
331
|
}
|
|
331
332
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
],
|
|
333
|
+
S = Q([
|
|
334
|
+
v(0, H),
|
|
335
|
+
v(1, g(i)),
|
|
336
|
+
v(2, p)
|
|
337
|
+
], S);
|
|
337
338
|
const x = {
|
|
338
339
|
id: "thread-comment.mutation.add-comment",
|
|
339
340
|
type: l.MUTATION,
|
|
@@ -343,7 +344,7 @@ const x = {
|
|
|
343
344
|
const n = a.get(i), { unitId: o, subUnitId: r, comment: s, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !s.parentId;
|
|
344
345
|
return n.addComment(o, r, s, m);
|
|
345
346
|
}
|
|
346
|
-
},
|
|
347
|
+
}, A = {
|
|
347
348
|
id: "thread-comment.mutation.update-comment",
|
|
348
349
|
type: l.MUTATION,
|
|
349
350
|
handler(a, t) {
|
|
@@ -352,7 +353,7 @@ const x = {
|
|
|
352
353
|
const e = a.get(i), { unitId: n, subUnitId: o, payload: r, silent: s } = t;
|
|
353
354
|
return e.updateComment(n, o, r, s);
|
|
354
355
|
}
|
|
355
|
-
},
|
|
356
|
+
}, ee = {
|
|
356
357
|
id: "thread-comment.mutation.update-comment-ref",
|
|
357
358
|
type: l.MUTATION,
|
|
358
359
|
handler(a, t) {
|
|
@@ -361,7 +362,7 @@ const x = {
|
|
|
361
362
|
const e = a.get(i), { unitId: n, subUnitId: o, payload: r, silent: s } = t;
|
|
362
363
|
return e.updateCommentRef(n, o, r, s);
|
|
363
364
|
}
|
|
364
|
-
},
|
|
365
|
+
}, P = {
|
|
365
366
|
id: "thread-comment.mutation.resolve-comment",
|
|
366
367
|
type: l.MUTATION,
|
|
367
368
|
handler(a, t) {
|
|
@@ -379,7 +380,7 @@ const x = {
|
|
|
379
380
|
const e = a.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
|
|
380
381
|
return e.deleteComment(n, o, r);
|
|
381
382
|
}
|
|
382
|
-
},
|
|
383
|
+
}, te = {
|
|
383
384
|
id: "thread-comment.command.add-comment",
|
|
384
385
|
type: l.COMMAND,
|
|
385
386
|
async handler(a, t) {
|
|
@@ -396,7 +397,7 @@ const x = {
|
|
|
396
397
|
onlyLocal: !s
|
|
397
398
|
});
|
|
398
399
|
}
|
|
399
|
-
},
|
|
400
|
+
}, ne = {
|
|
400
401
|
id: "thread-comment.command.update-comment",
|
|
401
402
|
type: l.COMMAND,
|
|
402
403
|
async handler(a, t) {
|
|
@@ -409,19 +410,19 @@ const x = {
|
|
|
409
410
|
);
|
|
410
411
|
if (!c)
|
|
411
412
|
return !1;
|
|
412
|
-
const { children: h, ...
|
|
413
|
+
const { children: h, ..._ } = c;
|
|
413
414
|
if (!await d.updateComment({
|
|
414
|
-
...
|
|
415
|
+
..._,
|
|
415
416
|
...o
|
|
416
417
|
}))
|
|
417
418
|
return !1;
|
|
418
419
|
const E = {
|
|
419
|
-
id:
|
|
420
|
+
id: A.id,
|
|
420
421
|
params: t
|
|
421
422
|
};
|
|
422
423
|
return r.executeCommand(E.id, E.params, { onlyLocal: !m }), !0;
|
|
423
424
|
}
|
|
424
|
-
},
|
|
425
|
+
}, oe = {
|
|
425
426
|
id: "thread-comment.command.resolve-comment",
|
|
426
427
|
type: l.COMMAND,
|
|
427
428
|
async handler(a, t) {
|
|
@@ -432,12 +433,12 @@ const x = {
|
|
|
432
433
|
...m,
|
|
433
434
|
resolved: o
|
|
434
435
|
}) ? !1 : a.get(f).executeCommand(
|
|
435
|
-
|
|
436
|
+
P.id,
|
|
436
437
|
t,
|
|
437
438
|
{ onlyLocal: !c }
|
|
438
439
|
);
|
|
439
440
|
}
|
|
440
|
-
},
|
|
441
|
+
}, re = {
|
|
441
442
|
id: "thread-comment.command.delete-comment",
|
|
442
443
|
type: l.COMMAND,
|
|
443
444
|
async handler(a, t) {
|
|
@@ -452,7 +453,7 @@ const x = {
|
|
|
452
453
|
};
|
|
453
454
|
return o.executeCommand(h.id, h.params, { onlyLocal: !m });
|
|
454
455
|
}
|
|
455
|
-
},
|
|
456
|
+
}, ae = {
|
|
456
457
|
id: "thread-comment.command.delete-comment-tree",
|
|
457
458
|
type: l.COMMAND,
|
|
458
459
|
async handler(a, t) {
|
|
@@ -465,13 +466,13 @@ const x = {
|
|
|
465
466
|
commentId: m.root.id
|
|
466
467
|
});
|
|
467
468
|
}
|
|
468
|
-
},
|
|
469
|
-
var
|
|
470
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
469
|
+
}, se = "thread-comment.config", R = {};
|
|
470
|
+
var me = Object.getOwnPropertyDescriptor, ce = (a, t, e, n) => {
|
|
471
|
+
for (var o = n > 1 ? void 0 : n ? me(t, e) : t, r = a.length - 1, s; r >= 0; r--)
|
|
471
472
|
(s = a[r]) && (o = s(o) || o);
|
|
472
473
|
return o;
|
|
473
|
-
}, y = (a, t) => (e, n) => t(e, n, a),
|
|
474
|
-
let D = (
|
|
474
|
+
}, y = (a, t) => (e, n) => t(e, n, a), M;
|
|
475
|
+
let D = (M = class extends W {
|
|
475
476
|
constructor(a = R, t, e, n) {
|
|
476
477
|
super(), this._config = a, this._injector = t, this._commandService = e, this._configService = n;
|
|
477
478
|
const { ...o } = J(
|
|
@@ -479,58 +480,59 @@ let D = (_ = class extends H {
|
|
|
479
480
|
R,
|
|
480
481
|
this._config
|
|
481
482
|
);
|
|
482
|
-
this._configService.setConfig(
|
|
483
|
+
this._configService.setConfig(se, o);
|
|
483
484
|
}
|
|
484
485
|
onStarting() {
|
|
485
486
|
var a;
|
|
486
487
|
Y([
|
|
487
488
|
[p, { useClass: Z }],
|
|
488
489
|
[i],
|
|
489
|
-
[
|
|
490
|
+
[S]
|
|
490
491
|
], (a = this._config) == null ? void 0 : a.overrides).forEach(
|
|
491
492
|
(t) => {
|
|
492
493
|
this._injector.add(t);
|
|
493
494
|
}
|
|
494
495
|
), [
|
|
495
|
-
ee,
|
|
496
496
|
te,
|
|
497
|
-
oe,
|
|
498
497
|
ne,
|
|
499
498
|
re,
|
|
499
|
+
oe,
|
|
500
|
+
ae,
|
|
500
501
|
x,
|
|
501
|
-
|
|
502
|
-
|
|
502
|
+
A,
|
|
503
|
+
ee,
|
|
503
504
|
N,
|
|
504
|
-
|
|
505
|
+
P
|
|
505
506
|
].forEach((t) => {
|
|
506
507
|
this._commandService.registerCommand(t);
|
|
507
|
-
}), this._injector.get(
|
|
508
|
+
}), this._injector.get(S);
|
|
508
509
|
}
|
|
509
|
-
}, u(
|
|
510
|
-
D =
|
|
510
|
+
}, u(M, "pluginName", w), u(M, "type", G.UNIVER_UNKNOWN), M);
|
|
511
|
+
D = ce([
|
|
511
512
|
y(1, g(k)),
|
|
512
513
|
y(2, f),
|
|
513
514
|
y(3, K)
|
|
514
515
|
], D);
|
|
515
|
-
function
|
|
516
|
+
function ue(a) {
|
|
516
517
|
return B(a).format("YYYY/MM/DD HH:mm");
|
|
517
518
|
}
|
|
518
519
|
export {
|
|
519
|
-
|
|
520
|
+
te as AddCommentCommand,
|
|
520
521
|
x as AddCommentMutation,
|
|
521
|
-
|
|
522
|
+
re as DeleteCommentCommand,
|
|
522
523
|
N as DeleteCommentMutation,
|
|
523
|
-
|
|
524
|
+
ae as DeleteCommentTreeCommand,
|
|
524
525
|
p as IThreadCommentDataSourceService,
|
|
525
|
-
|
|
526
|
-
|
|
526
|
+
oe as ResolveCommentCommand,
|
|
527
|
+
P as ResolveCommentMutation,
|
|
528
|
+
X as SHEET_UNIVER_THREAD_COMMENT_PLUGIN,
|
|
527
529
|
w as TC_PLUGIN_NAME,
|
|
528
530
|
Z as ThreadCommentDataSourceService,
|
|
529
531
|
i as ThreadCommentModel,
|
|
530
|
-
|
|
532
|
+
S as ThreadCommentResourceController,
|
|
531
533
|
D as UniverThreadCommentPlugin,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
534
|
+
ne as UpdateCommentCommand,
|
|
535
|
+
A as UpdateCommentMutation,
|
|
536
|
+
ee as UpdateCommentRefMutation,
|
|
537
|
+
ue as getDT
|
|
536
538
|
};
|
|
@@ -3,6 +3,7 @@ import { Disposable, IResourceManagerService } from '@univerjs/core';
|
|
|
3
3
|
import { ThreadCommentModel } from '../models/thread-comment.model';
|
|
4
4
|
import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
|
|
5
5
|
export type UnitThreadCommentJSON = Record<string, IThreadComment[]>;
|
|
6
|
+
export declare const SHEET_UNIVER_THREAD_COMMENT_PLUGIN = "SHEET_UNIVER_THREAD_COMMENT_PLUGIN";
|
|
6
7
|
export declare class ThreadCommentResourceController extends Disposable {
|
|
7
8
|
private readonly _resourceManagerService;
|
|
8
9
|
private readonly _threadCommentModel;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export { type CommentUpdate, type IThreadInfo, ThreadCommentModel } from './models/thread-comment.model';
|
|
17
|
-
export { ThreadCommentResourceController } from './controllers/tc-resource.controller';
|
|
17
|
+
export { SHEET_UNIVER_THREAD_COMMENT_PLUGIN, 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';
|
|
20
20
|
export { UniverThreadCommentPlugin } from './plugin';
|
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 K=Object.defineProperty;var B=(s,c,M)=>c in s?K(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>B(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.getOwnPropertyDescriptor,W=(m,r,e,t)=>{for(var n=t>1?void 0:t?V(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},R=(m,r)=>(e,t)=>r(e,t,m);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 p of i)l.add(p)}),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,p)=>{l.threadId===h&&a.delete(p)})})}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 p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const L=this._ensureThreadMap(e,t);if(!l.parentId){L.set(l.threadId,l);for(const f of i)p(f)}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=(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 g="UNIVER_THREAD_COMMENT_PLUGIN";var H=Object.getOwnPropertyDescriptor,J=(m,r,e,t)=>{for(var n=t>1?void 0:t?H(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},S=(m,r)=>(e,t)=>r(e,t,m);s.ThreadCommentResourceController=class extends c.Disposable{constructor(r,e,t){super(),this._resourceManagerService=r,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const r=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_${g}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>r(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([S(0,c.IResourceManagerService),S(1,c.Inject(s.ThreadCommentModel)),S(2,C)],s.ThreadCommentResourceController);const y={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(m,r,e){if(!r)return!1;const t=m.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=r,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(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=r;return e.updateComment(t,n,o,a)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=r;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=r;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=r;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(c.ICommandService),t=m.get(C),{comment:n}=r,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...r,comment:o}};return d?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},w={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const{unitId:e,subUnitId:t,payload:n}=r,o=m.get(c.ICommandService),a=m.get(s.ThreadCommentModel),d=m.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await d.updateComment({...p,...n}))return!1;const f={id:U.id,params:r};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},P={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=r,a=m.get(C),i=m.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:m.get(c.ICommandService).executeCommand(N.id,r,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),t=m.get(C),n=m.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=r,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:r};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},A={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),t=m.get(c.ICommandService),n=m.get(C),{unitId:o,subUnitId:a,commentId:d}=r,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",$={};var b=Object.getOwnPropertyDescriptor,Y=(m,r,e,t)=>{for(var n=t>1?void 0:t?b(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},I=(m,r)=>(e,t)=>r(e,t,m);s.UniverThreadCommentPlugin=(T=class extends c.Plugin{constructor(r=$,e,t,n){super(),this._config=r,this._injector=e,this._commandService=t,this._configService=n;const{...o}=c.merge({},$,this._config);this._configService.setConfig(G,o)}onStarting(){var r;c.mergeOverrideWithDependencies([[C,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(r=this._config)==null?void 0:r.overrides).forEach(e=>{this._injector.add(e)}),[D,w,j,P,A,y,U,O,_,N].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(T,"pluginName",g),u(T,"type",c.UniverInstanceType.UNIVER_UNKNOWN),T),s.UniverThreadCommentPlugin=Y([I(1,c.Inject(c.Injector)),I(2,c.ICommandService),I(3,c.IConfigService)],s.UniverThreadCommentPlugin);function k(m){return c.dayjs(m).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=P,s.ResolveCommentMutation=N,s.TC_PLUGIN_NAME=g,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=w,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=O,s.getDT=k,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 B=Object.defineProperty;var q=(s,c,M)=>c in s?B(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>q(s,typeof c!="symbol"?c+"":c,M);var T;class I 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 H=Object.getOwnPropertyDescriptor,W=(m,r,e,t)=>{for(var n=t>1?void 0:t?H(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},R=(m,r)=>(e,t)=>r(e,t,m);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 p of i)l.add(p)}),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,p)=>{l.threadId===h&&a.delete(p)})})}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 p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const V=this._ensureThreadMap(e,t);if(!l.parentId){V.set(l.threadId,l);for(const f of i)p(f)}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=(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 G=Object.getOwnPropertyDescriptor,J=(m,r,e,t)=>{for(var n=t>1?void 0:t?G(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},g=(m,r)=>(e,t)=>r(e,t,m);const O=`SHEET_${S}`;s.ThreadCommentResourceController=class extends c.Disposable{constructor(r,e,t){super(),this._resourceManagerService=r,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const r=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:O,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>r(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(m,r,e){if(!r)return!1;const t=m.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=r,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(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=r;return e.updateComment(t,n,o,a)}},D={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=r;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=r;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=r;return e.deleteComment(t,n,o)}},w={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(c.ICommandService),t=m.get(C),{comment:n}=r,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...r,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(m,r){if(!r)return!1;const{unitId:e,subUnitId:t,payload:n}=r,o=m.get(c.ICommandService),a=m.get(s.ThreadCommentModel),d=m.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await d.updateComment({...p,...n}))return!1;const f={id:U.id,params:r};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},A={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=r,a=m.get(C),i=m.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:m.get(c.ICommandService).executeCommand(N.id,r,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),t=m.get(C),n=m.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=r,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:r};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},$={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(m,r){if(!r)return!1;const e=m.get(s.ThreadCommentModel),t=m.get(c.ICommandService),n=m.get(C),{unitId:o,subUnitId:a,commentId:d}=r,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})}},b="thread-comment.config",L={};var Y=Object.getOwnPropertyDescriptor,k=(m,r,e,t)=>{for(var n=t>1?void 0:t?Y(r,e):r,o=m.length-1,a;o>=0;o--)(a=m[o])&&(n=a(n)||n);return n},E=(m,r)=>(e,t)=>r(e,t,m);s.UniverThreadCommentPlugin=(T=class extends c.Plugin{constructor(r=L,e,t,n){super(),this._config=r,this._injector=e,this._commandService=t,this._configService=n;const{...o}=c.merge({},L,this._config);this._configService.setConfig(b,o)}onStarting(){var r;c.mergeOverrideWithDependencies([[C,{useClass:I}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(r=this._config)==null?void 0:r.overrides).forEach(e=>{this._injector.add(e)}),[w,P,j,A,$,y,U,D,_,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=k([E(1,c.Inject(c.Injector)),E(2,c.ICommandService),E(3,c.IConfigService)],s.UniverThreadCommentPlugin);function K(m){return c.dayjs(m).format("YYYY/MM/DD HH:mm")}s.AddCommentCommand=w,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=$,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=A,s.ResolveCommentMutation=N,s.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=O,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=I,s.UpdateCommentCommand=P,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=D,s.getDT=K,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.6.
|
|
3
|
+
"version": "0.6.2-nightly.202503031606",
|
|
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.43",
|
|
50
|
-
"@univerjs/core": "0.6.
|
|
50
|
+
"@univerjs/core": "0.6.2-nightly.202503031606"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.1",
|
|
54
|
-
"typescript": "^5.
|
|
55
|
-
"vite": "^6.
|
|
56
|
-
"vitest": "^3.0.
|
|
57
|
-
"@univerjs-infra/shared": "0.6.
|
|
54
|
+
"typescript": "^5.8.2",
|
|
55
|
+
"vite": "^6.2.0",
|
|
56
|
+
"vitest": "^3.0.7",
|
|
57
|
+
"@univerjs-infra/shared": "0.6.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|