@univerjs/preset-sheets-thread-comment 0.6.6-nightly.202503251606 → 0.6.7-experimental.20250402-cbaeae1
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/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @univerjs/thread-comment/index
|
|
2
|
-
(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 R 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},N=(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([N(0,c.Inject(C)),N(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)}},E={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)}},U={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:E.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(U.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},I=(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:R}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(r=this._config)==null?void 0:r.overrides).forEach(e=>{this._injector.add(e)}),[w,P,j,A,$,y,E,D,_,U].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([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=w,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=$,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=A,s.ResolveCommentMutation=U,s.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=O,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=R,s.UpdateCommentCommand=P,s.UpdateCommentMutation=E,s.UpdateCommentRefMutation=D,s.getDT=K,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
(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"})});
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @univerjs/sheets-thread-comment/index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-thread-comment",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7-experimental.20250402-cbaeae1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -52,22 +52,22 @@
|
|
|
52
52
|
"lib"
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"react": "
|
|
56
|
-
"react-dom": "
|
|
55
|
+
"react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
|
|
56
|
+
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/sheets-thread-comment": "0.6.
|
|
61
|
-
"@univerjs/sheets-thread-comment-ui": "0.6.
|
|
62
|
-
"@univerjs/thread-comment": "0.6.
|
|
63
|
-
"@univerjs/thread-comment-ui": "0.6.
|
|
60
|
+
"@univerjs/sheets-thread-comment": "0.6.7-experimental.20250402-cbaeae1",
|
|
61
|
+
"@univerjs/sheets-thread-comment-ui": "0.6.7-experimental.20250402-cbaeae1",
|
|
62
|
+
"@univerjs/thread-comment": "0.6.7-experimental.20250402-cbaeae1",
|
|
63
|
+
"@univerjs/thread-comment-ui": "0.6.7-experimental.20250402-cbaeae1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@univerjs/core": "0.6.
|
|
66
|
+
"@univerjs/core": "0.6.7-experimental.20250402-cbaeae1",
|
|
67
67
|
"react": "18.3.1",
|
|
68
68
|
"react-dom": "18.3.1",
|
|
69
69
|
"typescript": "^5.8.2",
|
|
70
|
-
"@univerjs-infra/shared": "0.6.
|
|
70
|
+
"@univerjs-infra/shared": "0.6.9"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"prebuild:preset": "tsx prepare.ts",
|