@univerjs/thread-comment 0.17.0 → 0.18.0-insiders.20260328-0842384
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 +1 -541
- package/lib/index.js +1 -541
- package/lib/types/commands/commands/comment.command.d.ts +18 -3
- package/lib/types/commands/mutations/comment.mutation.d.ts +17 -2
- package/lib/types/config/config.d.ts +16 -1
- package/lib/types/controllers/tc-resource.controller.d.ts +16 -1
- package/lib/types/models/thread-comment.model.d.ts +20 -4
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/tc-datasource.service.d.ts +19 -3
- package/lib/types/types/interfaces/i-thread-comment.d.ts +16 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -7
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty;var L=(s,a,e)=>a in s?j(s,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[a]=e;var l=(s,a,e)=>L(s,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),H=require("rxjs");class D extends c.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=c.createIdentifier("univer.thread-comment.data-source-service");var W=Object.getOwnPropertyDescriptor,G=(s,a,e,t)=>{for(var n=t>1?void 0:t?W(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(n=r(n)||n);return n},E=(s,a)=>(e,t)=>a(e,t,s);exports.ThreadCommentModel=class extends c.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new H.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===c.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:r,subUnitId:m,threadIds:d})=>{let i=o.get(r);i||(i=new Map,o.set(r,i));let h=i.get(m);h||(h=new Set,i.set(m,h));for(const u of d)h.add(u)}),this._tasks=[],o.forEach((r,m)=>{r.forEach((d,i)=>{this.syncThreadComments(m,i,Array.from(d))})}))}))}_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:m,...d}=n,i={...d,ref:r.ref};o.set(n.id,i),m==null||m.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<c.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),r=this._ensureCommentMap(e,t),m=await this._dataSourceService.listThreadComments(e,t,n);if(!m)return;const d=new Set(n);m.forEach(i=>{this._replaceComment(e,t,i),d.delete(i.threadId)}),d.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:m,children:d=[],...i}=n,h={...i,parentId:m===n.id?void 0:m};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 U=this._ensureThreadMap(e,t);if(!h.parentId){U.set(h.threadId,h);for(const C of d)u(C)}return o&&this.syncThreadComments(e,t,[h.threadId]),!0}updateComment(e,t,n,o){const m=this._ensureCommentMap(e,t).get(n.commentId);return m&&(m.updated=!0,m.text=n.text,m.attachments=n.attachments,m.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const m=this._ensureCommentMap(e,t).get(n.commentId);return m?(m.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:m.threadId}),!0):!1}resolveComment(e,t,n,o){const m=this._ensureCommentMap(e,t).get(n);return m?(m.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 m;const d=[],i=new Set;for(const h of r)h.parentId?d.push(h):m=h,i.add(h.personId);if(m)return{root:m,children:d,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(m=>{m.threadId===n&&this._deleteComment(e,t,m.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((m,d)=>{const i=this.getThread(e,r,d);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=G([E(0,c.Inject(p)),E(1,c.Inject(c.LifecycleService))],exports.ThreadCommentModel);const v={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(s,a,e){if(!a)return!1;const t=s.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:m}=a,d=m||(e==null?void 0:e.fromChangeset)&&!r.parentId;return t.addComment(n,o,r,d)}},g={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateComment(t,n,o,r)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateCommentRef(t,n,o,r)}},S={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=a;return e.resolveComment(t,n,r,o)}},f={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=a;return e.deleteComment(t,n,o)}},R={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(s,a){if(!a)return!1;const e=s.get(c.ICommandService),t=s.get(p),{comment:n}=a,o=await t.addComment(n),r=t.syncUpdateMutationToColla,m=!n.parentId,d={id:v.id,params:{...a,comment:o}};return m?await e.executeCommand(d.id,d.params):e.executeCommand(d.id,d.params,{onlyLocal:!r})}},w={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(s,a){if(!a)return!1;const{unitId:e,subUnitId:t,payload:n}=a,o=s.get(c.ICommandService),r=s.get(exports.ThreadCommentModel),m=s.get(p),d=m.syncUpdateMutationToColla,i=r.getComment(e,t,n.commentId);if(!i)return!1;const{children:h,...u}=i;if(!await m.updateComment({...u,...n}))return!1;const C={id:g.id,params:a};return o.executeCommand(C.id,C.params,{onlyLocal:!d}),!0}},A={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(s,a){if(!a)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=a,r=s.get(p),d=s.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!d||!await r.resolveComment({...d,resolved:n})?!1:s.get(c.ICommandService).executeCommand(S.id,a,{onlyLocal:!i})}},P={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),t=s.get(p),n=s.get(c.ICommandService),{unitId:o,subUnitId:r,commentId:m}=a,d=t.syncUpdateMutationToColla,i=e.getComment(o,r,m);if(!i||!await t.deleteComment(o,r,i.threadId,m))return!1;const h={id:f.id,params:a};return n.executeCommand(h.id,h.params,{onlyLocal:!d})}},x={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(s,a){if(!a)return!1;const e=s.get(exports.ThreadCommentModel),t=s.get(c.ICommandService),n=s.get(p),{unitId:o,subUnitId:r,commentId:m}=a,d=e.getCommentWithChildren(o,r,m);return!d||!await n.deleteComment(o,r,d.root.threadId,m)?!1:await t.executeCommand(f.id,{unitId:o,subUnitId:r,commentId:d.root.id})}};function b(s){return c.dayjs(s).format("YYYY/MM/DD HH:mm")}const y="UNIVER_THREAD_COMMENT_PLUGIN";var k=Object.getOwnPropertyDescriptor,J=(s,a,e,t)=>{for(var n=t>1?void 0:t?k(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(n=r(n)||n);return n},_=(s,a)=>(e,t)=>a(e,t,s);const $=`SHEET_${y}`;exports.ThreadCommentResourceController=class extends c.Disposable{constructor(a,e,t){super(),this._resourceManagerService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const a=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(r=>{var d;const m=(d=o[r.subUnitId])!=null?d:[];m.push({...r.root,children:r.children}),o[r.subUnitId]=m}),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:$,businesses:[c.UniverInstanceType.UNIVER_SHEET,c.UniverInstanceType.UNIVER_DOC],toJson:t=>a(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const r=n[o];r.forEach(m=>{this._threadCommentModel.addComment(t,o,m)}),this._threadCommentModel.syncThreadComments(t,o,r.map(m=>m.threadId))})}}))}};exports.ThreadCommentResourceController=J([_(0,c.IResourceManagerService),_(1,c.Inject(exports.ThreadCommentModel)),_(2,p)],exports.ThreadCommentResourceController);const V="@univerjs/thread-comment",Y="0.17.0",I={name:V,version:Y},B="thread-comment.config",N={};var q=Object.getOwnPropertyDescriptor,K=(s,a,e,t)=>{for(var n=t>1?void 0:t?q(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(n=r(n)||n);return n},T=(s,a)=>(e,t)=>a(e,t,s),M;exports.UniverThreadCommentPlugin=(M=class extends c.Plugin{constructor(a=N,e,t,n){super(),this._config=a,this._injector=e,this._commandService=t,this._configService=n;const{...o}=c.merge({},N,this._config);this._configService.setConfig(B,o)}onStarting(){var a;c.mergeOverrideWithDependencies([[p,{useClass:D}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(a=this._config)==null?void 0:a.overrides).forEach(e=>{this._injector.add(e)}),[R,w,P,A,x,v,g,O,f,S].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(M,"pluginName",y),l(M,"packageName",I.name),l(M,"version",I.version),l(M,"type",c.UniverInstanceType.UNIVER_UNKNOWN),M);exports.UniverThreadCommentPlugin=K([T(1,c.Inject(c.Injector)),T(2,c.ICommandService),T(3,c.IConfigService)],exports.UniverThreadCommentPlugin);exports.AddCommentCommand=R;exports.AddCommentMutation=v;exports.DeleteCommentCommand=P;exports.DeleteCommentMutation=f;exports.DeleteCommentTreeCommand=x;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=A;exports.ResolveCommentMutation=S;exports.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=$;exports.TC_PLUGIN_NAME=y;exports.ThreadCommentDataSourceService=D;exports.UpdateCommentCommand=w;exports.UpdateCommentMutation=g;exports.UpdateCommentRefMutation=O;exports.getDT=b;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`rxjs`);function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}function a(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=class extends e.Disposable{set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}constructor(){super(),a(this,`_dataSource`,null),a(this,`syncUpdateMutationToColla`,!0)}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?e.id:t}}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,r){return this._dataSource?this._dataSource.deleteComment(e,t,n,r):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n].map(this.dataSource.saveCommentToSnapshot)}),t}return e}};const s=(0,e.createIdentifier)(`univer.thread-comment.data-source-service`);function c(e,t){return function(n,r){t(n,r,e)}}function l(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let u=class extends e.Disposable{constructor(n,r){super(),this._dataSourceService=n,this._lifecycleService=r,a(this,`_commentsMap`,new Map),a(this,`_threadMap`,new Map),a(this,`_commentUpdate$`,new t.Subject),a(this,`commentUpdate$`,this._commentUpdate$.asObservable()),a(this,`_tasks`,[]),this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(t=>{let n=new Map;t===e.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:e,subUnitId:t,threadIds:r})=>{let i=n.get(e);i||(i=new Map,n.set(e,i));let a=i.get(t);a||(a=new Set,i.set(t,a));for(let e of r)a.add(e)}),this._tasks=[],n.forEach((e,t)=>{e.forEach((e,n)=>{this.syncThreadComments(t,n,Array.from(e))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}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 r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_replaceComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n.id);if(i){let{children:a,...o}=n,s={...o,ref:i.ref};r.set(n.id,s),a==null||a.forEach(e=>{r.set(e.id,{...e,ref:``})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`syncUpdate`,payload:s}),!!n.resolved!=!!i.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(t,n,r){if(this._lifecycleService.stage<e.LifecycleStages.Rendered){this._tasks.push({unitId:t,subUnitId:n,threadIds:r});return}let i=this._ensureThreadMap(t,n),a=this._ensureCommentMap(t,n),o=await this._dataSourceService.listThreadComments(t,n,r);if(!o)return;let s=new Set(r);o.forEach(e=>{this._replaceComment(t,n,e),s.delete(e.threadId)}),s.forEach(e=>{i.delete(e),a.forEach((t,n)=>{t.threadId===e&&a.delete(n)})})}addComment(e,t,n,r){let i=this._ensureCommentMap(e,t),{parentId:a,children:o=[],...s}=n,c={...s,parentId:a===n.id?void 0:a};c.threadId||(c.threadId=c.parentId||c.id);let l=n=>{i.set(n.id,n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`add`,payload:n,isRoot:!n.parentId})};l(c);let u=this._ensureThreadMap(e,t);if(!c.parentId){u.set(c.threadId,c);for(let e of o)l(e)}return r&&this.syncThreadComments(e,t,[c.threadId]),!0}updateComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.updated=!0,i.text=n.text,i.attachments=n.attachments,i.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`update`,payload:n,silent:r}),!0):!0}updateCommentRef(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`updateRef`,payload:n,silent:r,threadId:i.threadId}),!0):!1}resolveComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n);return i?(i.resolved=r,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n,resolved:r}}),!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){let r=this._ensureCommentMap(e,t),i=Array.from(r.values()).filter(e=>e.threadId===n),a,o=[],s=new Set;for(let e of i)e.parentId?o.push(e):a=e,s.add(e.personId);if(a)return{root:a,children:o,relativeUsers:s,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){let r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n);i&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`delete`,payload:{commentId:n,isRoot:!i.parentId,comment:i}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){let 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){let t=this._commentsMap.get(e);t&&t.forEach((t,n)=>{t.forEach(t=>{this.deleteComment(e,n,t.id)})})}getUnit(e){let t=this._threadMap.get(e);if(!t)return[];let n=[];return t.forEach((t,r)=>{t.forEach((t,i)=>{let a=this.getThread(e,r,i);a&&n.push(a)})}),n}getAll(){let e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};u=l([c(0,(0,e.Inject)(s)),c(1,(0,e.Inject)(e.LifecycleService))],u);const d={id:`thread-comment.mutation.add-comment`,type:e.CommandType.MUTATION,handler(e,t,n){if(!t)return!1;let r=e.get(u),{unitId:i,subUnitId:a,comment:o,sync:s}=t,c=s||(n==null?void 0:n.fromChangeset)&&!o.parentId;return r.addComment(i,a,o,c)}},f={id:`thread-comment.mutation.update-comment`,type:e.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(u),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateComment(r,i,a,o)}},p={id:`thread-comment.mutation.update-comment-ref`,type:e.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(u),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateCommentRef(r,i,a,o)}},m={id:`thread-comment.mutation.resolve-comment`,type:e.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(u),{unitId:r,subUnitId:i,resolved:a,commentId:o}=t;return n.resolveComment(r,i,o,a)}},h={id:`thread-comment.mutation.delete-comment`,type:e.CommandType.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(u),{unitId:r,subUnitId:i,commentId:a}=t;return n.deleteComment(r,i,a)}},g={id:`thread-comment.command.add-comment`,type:e.CommandType.COMMAND,async handler(t,n){if(!n)return!1;let r=t.get(e.ICommandService),i=t.get(s),{comment:a}=n,o=await i.addComment(a),c=i.syncUpdateMutationToColla,l=!a.parentId,u={id:d.id,params:{...n,comment:o}};return l?await r.executeCommand(u.id,u.params):r.executeCommand(u.id,u.params,{onlyLocal:!c})}},_={id:`thread-comment.command.update-comment`,type:e.CommandType.COMMAND,async handler(t,n){if(!n)return!1;let{unitId:r,subUnitId:i,payload:a}=n,o=t.get(e.ICommandService),c=t.get(u),l=t.get(s),d=l.syncUpdateMutationToColla,p=c.getComment(r,i,a.commentId);if(!p)return!1;let{children:m,...h}=p;if(!await l.updateComment({...h,...a}))return!1;let g={id:f.id,params:n};return o.executeCommand(g.id,g.params,{onlyLocal:!d}),!0}},v={id:`thread-comment.command.resolve-comment`,type:e.CommandType.COMMAND,async handler(t,n){if(!n)return!1;let{unitId:r,subUnitId:i,resolved:a,commentId:o}=n,c=t.get(s),l=t.get(u).getComment(r,i,o),d=c.syncUpdateMutationToColla;return!l||!await c.resolveComment({...l,resolved:a})?!1:t.get(e.ICommandService).executeCommand(m.id,n,{onlyLocal:!d})}},y={id:`thread-comment.command.delete-comment`,type:e.CommandType.COMMAND,async handler(t,n){if(!n)return!1;let r=t.get(u),i=t.get(s),a=t.get(e.ICommandService),{unitId:o,subUnitId:c,commentId:l}=n,d=i.syncUpdateMutationToColla,f=r.getComment(o,c,l);if(!f||!await i.deleteComment(o,c,f.threadId,l))return!1;let p={id:h.id,params:n};return a.executeCommand(p.id,p.params,{onlyLocal:!d})}},b={id:`thread-comment.command.delete-comment-tree`,type:e.CommandType.COMMAND,async handler(t,n){if(!n)return!1;let r=t.get(u),i=t.get(e.ICommandService),a=t.get(s),{unitId:o,subUnitId:c,commentId:l}=n,d=r.getCommentWithChildren(o,c,l);return!d||!await a.deleteComment(o,c,d.root.threadId,l)?!1:await i.executeCommand(h.id,{unitId:o,subUnitId:c,commentId:d.root.id})}};function x(t){return(0,e.dayjs)(t).format(`YYYY/MM/DD HH:mm`)}const S=`UNIVER_THREAD_COMMENT_PLUGIN`,C=`SHEET_${S}`;let w=class extends e.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){let t=e=>{let t=this._threadCommentModel.getUnit(e),n={};return t?(t.forEach(e=>{var t;let r=(t=n[e.subUnitId])==null?[]:t;r.push({...e.root,children:e.children}),n[e.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(n,e))):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:C,businesses:[e.UniverInstanceType.UNIVER_SHEET,e.UniverInstanceType.UNIVER_DOC],toJson:e=>t(e),parseJson:e=>n(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{let r=t[n];r.forEach(t=>{this._threadCommentModel.addComment(e,n,t)}),this._threadCommentModel.syncThreadComments(e,n,r.map(e=>e.threadId))})}}))}};w=l([c(0,e.IResourceManagerService),c(1,(0,e.Inject)(u)),c(2,s)],w);var T=`@univerjs/thread-comment`,E=`0.18.0-insiders.20260328-0842384`;const D=`thread-comment.config`;Symbol(D);const O={};let k=class extends e.Plugin{constructor(t=O,n,r,i){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,e.merge)({},O,this._config);this._configService.setConfig(D,a)}onStarting(){var t;(0,e.mergeOverrideWithDependencies)([[s,{useClass:o}],[u],[w]],(t=this._config)==null?void 0:t.overrides).forEach(e=>{this._injector.add(e)}),[g,_,y,v,b,d,f,p,h,m].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(w)}};a(k,`pluginName`,S),a(k,`packageName`,T),a(k,`version`,E),a(k,`type`,e.UniverInstanceType.UNIVER_UNKNOWN),k=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.ICommandService),c(3,e.IConfigService)],k),exports.AddCommentCommand=g,exports.AddCommentMutation=d,exports.DeleteCommentCommand=y,exports.DeleteCommentMutation=h,exports.DeleteCommentTreeCommand=b,exports.IThreadCommentDataSourceService=s,exports.ResolveCommentCommand=v,exports.ResolveCommentMutation=m,exports.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=C,exports.TC_PLUGIN_NAME=S,exports.ThreadCommentDataSourceService=o,Object.defineProperty(exports,`ThreadCommentModel`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`ThreadCommentResourceController`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`UniverThreadCommentPlugin`,{enumerable:!0,get:function(){return k}}),exports.UpdateCommentCommand=_,exports.UpdateCommentMutation=f,exports.UpdateCommentRefMutation=p,exports.getDT=x;
|
package/lib/es/index.js
CHANGED
|
@@ -1,541 +1 @@
|
|
|
1
|
-
var L = Object.defineProperty;
|
|
2
|
-
var j = (s, t, e) => t in s ? L(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
-
var h = (s, t, e) => j(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { createIdentifier as H, Disposable as U, Inject as g, LifecycleService as W, LifecycleStages as O, CommandType as l, ICommandService as M, dayjs as k, IResourceManagerService as J, UniverInstanceType as T, Plugin as G, merge as V, mergeOverrideWithDependencies as Y, Injector as B, IConfigService as b } from "@univerjs/core";
|
|
5
|
-
import { Subject as K } from "rxjs";
|
|
6
|
-
class F extends U {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
h(this, "_dataSource", null);
|
|
10
|
-
h(this, "syncUpdateMutationToColla", !0);
|
|
11
|
-
}
|
|
12
|
-
set dataSource(e) {
|
|
13
|
-
this._dataSource = e;
|
|
14
|
-
}
|
|
15
|
-
get dataSource() {
|
|
16
|
-
return this._dataSource;
|
|
17
|
-
}
|
|
18
|
-
async getThreadComment(e, n, o) {
|
|
19
|
-
return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
|
|
20
|
-
}
|
|
21
|
-
async addComment(e) {
|
|
22
|
-
var n;
|
|
23
|
-
return this._dataSource ? this._dataSource.addComment(e) : { ...e, threadId: (n = e.threadId) != null ? n : e.id };
|
|
24
|
-
}
|
|
25
|
-
async updateComment(e) {
|
|
26
|
-
return this._dataSource ? this._dataSource.updateComment(e) : !0;
|
|
27
|
-
}
|
|
28
|
-
async resolveComment(e) {
|
|
29
|
-
return this._dataSource ? this._dataSource.resolveComment(e) : !0;
|
|
30
|
-
}
|
|
31
|
-
async deleteComment(e, n, o, r) {
|
|
32
|
-
return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : !0;
|
|
33
|
-
}
|
|
34
|
-
async listThreadComments(e, n, o) {
|
|
35
|
-
return this.dataSource ? this.dataSource.listComments(e, n, o) : !1;
|
|
36
|
-
}
|
|
37
|
-
saveToSnapshot(e, n) {
|
|
38
|
-
if (this._dataSource) {
|
|
39
|
-
const o = {};
|
|
40
|
-
return Object.keys(e).forEach((r) => {
|
|
41
|
-
const a = e[r];
|
|
42
|
-
o[r] = a.map(this.dataSource.saveCommentToSnapshot);
|
|
43
|
-
}), o;
|
|
44
|
-
}
|
|
45
|
-
return e;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const p = H("univer.thread-comment.data-source-service");
|
|
49
|
-
var q = Object.getOwnPropertyDescriptor, z = (s, t, e, n) => {
|
|
50
|
-
for (var o = n > 1 ? void 0 : n ? q(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
51
|
-
(a = s[r]) && (o = a(o) || o);
|
|
52
|
-
return o;
|
|
53
|
-
}, w = (s, t) => (e, n) => t(e, n, s);
|
|
54
|
-
let i = class extends U {
|
|
55
|
-
constructor(t, e) {
|
|
56
|
-
super();
|
|
57
|
-
h(this, "_commentsMap", /* @__PURE__ */ new Map());
|
|
58
|
-
h(this, "_threadMap", /* @__PURE__ */ new Map());
|
|
59
|
-
h(this, "_commentUpdate$", new K());
|
|
60
|
-
h(this, "commentUpdate$", this._commentUpdate$.asObservable());
|
|
61
|
-
h(this, "_tasks", []);
|
|
62
|
-
this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
|
|
63
|
-
this._commentUpdate$.complete();
|
|
64
|
-
}), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
|
|
65
|
-
const o = /* @__PURE__ */ new Map();
|
|
66
|
-
n === O.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => {
|
|
67
|
-
let m = o.get(r);
|
|
68
|
-
m || (m = /* @__PURE__ */ new Map(), o.set(r, m));
|
|
69
|
-
let c = m.get(a);
|
|
70
|
-
c || (c = /* @__PURE__ */ new Set(), m.set(a, c));
|
|
71
|
-
for (const u of d)
|
|
72
|
-
c.add(u);
|
|
73
|
-
}), this._tasks = [], o.forEach((r, a) => {
|
|
74
|
-
r.forEach((d, m) => {
|
|
75
|
-
this.syncThreadComments(a, m, Array.from(d));
|
|
76
|
-
});
|
|
77
|
-
}));
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
_ensureCommentMap(t, e) {
|
|
81
|
-
let n = this._commentsMap.get(t);
|
|
82
|
-
n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
|
|
83
|
-
let o = n.get(e);
|
|
84
|
-
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
|
|
85
|
-
}
|
|
86
|
-
ensureMap(t, e) {
|
|
87
|
-
return this._ensureCommentMap(t, e);
|
|
88
|
-
}
|
|
89
|
-
_ensureThreadMap(t, e) {
|
|
90
|
-
let n = this._threadMap.get(t);
|
|
91
|
-
n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
|
|
92
|
-
let o = n.get(e);
|
|
93
|
-
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
|
|
94
|
-
}
|
|
95
|
-
_replaceComment(t, e, n) {
|
|
96
|
-
const o = this._ensureCommentMap(t, e), r = o.get(n.id);
|
|
97
|
-
if (r) {
|
|
98
|
-
const { children: a, ...d } = n, m = {
|
|
99
|
-
...d,
|
|
100
|
-
ref: r.ref
|
|
101
|
-
};
|
|
102
|
-
o.set(n.id, m), a == null || a.forEach((c) => {
|
|
103
|
-
o.set(c.id, {
|
|
104
|
-
...c,
|
|
105
|
-
ref: ""
|
|
106
|
-
});
|
|
107
|
-
}), this._commentUpdate$.next({
|
|
108
|
-
unitId: t,
|
|
109
|
-
subUnitId: e,
|
|
110
|
-
type: "syncUpdate",
|
|
111
|
-
payload: m
|
|
112
|
-
}), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
|
|
113
|
-
unitId: t,
|
|
114
|
-
subUnitId: e,
|
|
115
|
-
type: "resolve",
|
|
116
|
-
payload: {
|
|
117
|
-
commentId: n.id,
|
|
118
|
-
resolved: !!n.resolved
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async syncThreadComments(t, e, n) {
|
|
124
|
-
if (this._lifecycleService.stage < O.Rendered) {
|
|
125
|
-
this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
|
|
129
|
-
if (!a)
|
|
130
|
-
return;
|
|
131
|
-
const d = new Set(n);
|
|
132
|
-
a.forEach((m) => {
|
|
133
|
-
this._replaceComment(t, e, m), d.delete(m.threadId);
|
|
134
|
-
}), d.forEach((m) => {
|
|
135
|
-
o.delete(m), r.forEach((c, u) => {
|
|
136
|
-
c.threadId === m && r.delete(u);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
addComment(t, e, n, o) {
|
|
141
|
-
const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = {
|
|
142
|
-
...m,
|
|
143
|
-
parentId: a === n.id ? void 0 : a
|
|
144
|
-
};
|
|
145
|
-
c.threadId || (c.threadId = c.parentId || c.id);
|
|
146
|
-
const u = (C) => {
|
|
147
|
-
r.set(C.id, C), this._commentUpdate$.next({
|
|
148
|
-
unitId: t,
|
|
149
|
-
subUnitId: e,
|
|
150
|
-
type: "add",
|
|
151
|
-
payload: C,
|
|
152
|
-
isRoot: !C.parentId
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
u(c);
|
|
156
|
-
const _ = this._ensureThreadMap(t, e);
|
|
157
|
-
if (!c.parentId) {
|
|
158
|
-
_.set(c.threadId, c);
|
|
159
|
-
for (const C of d)
|
|
160
|
-
u(C);
|
|
161
|
-
}
|
|
162
|
-
return o && this.syncThreadComments(t, e, [c.threadId]), !0;
|
|
163
|
-
}
|
|
164
|
-
updateComment(t, e, n, o) {
|
|
165
|
-
const a = this._ensureCommentMap(t, e).get(n.commentId);
|
|
166
|
-
return a && (a.updated = !0, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({
|
|
167
|
-
unitId: t,
|
|
168
|
-
subUnitId: e,
|
|
169
|
-
type: "update",
|
|
170
|
-
payload: n,
|
|
171
|
-
silent: o
|
|
172
|
-
})), !0;
|
|
173
|
-
}
|
|
174
|
-
updateCommentRef(t, e, n, o) {
|
|
175
|
-
const a = this._ensureCommentMap(t, e).get(n.commentId);
|
|
176
|
-
return a ? (a.ref = n.ref, this._commentUpdate$.next({
|
|
177
|
-
unitId: t,
|
|
178
|
-
subUnitId: e,
|
|
179
|
-
type: "updateRef",
|
|
180
|
-
payload: n,
|
|
181
|
-
silent: o,
|
|
182
|
-
threadId: a.threadId
|
|
183
|
-
}), !0) : !1;
|
|
184
|
-
}
|
|
185
|
-
resolveComment(t, e, n, o) {
|
|
186
|
-
const a = this._ensureCommentMap(t, e).get(n);
|
|
187
|
-
return a ? (a.resolved = o, this._commentUpdate$.next({
|
|
188
|
-
unitId: t,
|
|
189
|
-
subUnitId: e,
|
|
190
|
-
type: "resolve",
|
|
191
|
-
payload: {
|
|
192
|
-
commentId: n,
|
|
193
|
-
resolved: o
|
|
194
|
-
}
|
|
195
|
-
}), !0) : !1;
|
|
196
|
-
}
|
|
197
|
-
getComment(t, e, n) {
|
|
198
|
-
return this._ensureCommentMap(t, e).get(n);
|
|
199
|
-
}
|
|
200
|
-
getRootComment(t, e, n) {
|
|
201
|
-
return this._ensureThreadMap(t, e).get(n);
|
|
202
|
-
}
|
|
203
|
-
getThread(t, e, n) {
|
|
204
|
-
const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n);
|
|
205
|
-
let a;
|
|
206
|
-
const d = [], m = /* @__PURE__ */ new Set();
|
|
207
|
-
for (const c of r)
|
|
208
|
-
c.parentId ? d.push(c) : a = c, m.add(c.personId);
|
|
209
|
-
if (a)
|
|
210
|
-
return {
|
|
211
|
-
root: a,
|
|
212
|
-
children: d,
|
|
213
|
-
relativeUsers: m,
|
|
214
|
-
unitId: t,
|
|
215
|
-
subUnitId: e,
|
|
216
|
-
threadId: n
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
getCommentWithChildren(t, e, n) {
|
|
220
|
-
const o = this.getComment(t, e, n);
|
|
221
|
-
if (o)
|
|
222
|
-
return this.getThread(t, e, o.threadId);
|
|
223
|
-
}
|
|
224
|
-
_deleteComment(t, e, n) {
|
|
225
|
-
const o = this._ensureCommentMap(t, e), r = o.get(n);
|
|
226
|
-
r && (o.delete(n), this._commentUpdate$.next({
|
|
227
|
-
unitId: t,
|
|
228
|
-
subUnitId: e,
|
|
229
|
-
type: "delete",
|
|
230
|
-
payload: {
|
|
231
|
-
commentId: n,
|
|
232
|
-
isRoot: !r.parentId,
|
|
233
|
-
comment: r
|
|
234
|
-
}
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
deleteThread(t, e, n) {
|
|
238
|
-
this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
|
|
239
|
-
a.threadId === n && this._deleteComment(t, e, a.id);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
deleteComment(t, e, n) {
|
|
243
|
-
const r = this._ensureCommentMap(t, e).get(n);
|
|
244
|
-
return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), !0;
|
|
245
|
-
}
|
|
246
|
-
deleteUnit(t) {
|
|
247
|
-
const e = this._commentsMap.get(t);
|
|
248
|
-
e && e.forEach((n, o) => {
|
|
249
|
-
n.forEach((r) => {
|
|
250
|
-
this.deleteComment(t, o, r.id);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
getUnit(t) {
|
|
255
|
-
const e = this._threadMap.get(t);
|
|
256
|
-
if (!e)
|
|
257
|
-
return [];
|
|
258
|
-
const n = [];
|
|
259
|
-
return e.forEach((o, r) => {
|
|
260
|
-
o.forEach((a, d) => {
|
|
261
|
-
const m = this.getThread(t, r, d);
|
|
262
|
-
m && n.push(m);
|
|
263
|
-
});
|
|
264
|
-
}), n;
|
|
265
|
-
}
|
|
266
|
-
getAll() {
|
|
267
|
-
const t = [];
|
|
268
|
-
return this._commentsMap.forEach((e, n) => {
|
|
269
|
-
t.push({
|
|
270
|
-
unitId: n,
|
|
271
|
-
threads: this.getUnit(n)
|
|
272
|
-
});
|
|
273
|
-
}), t;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
i = z([
|
|
277
|
-
w(0, g(p)),
|
|
278
|
-
w(1, g(W))
|
|
279
|
-
], i);
|
|
280
|
-
const x = {
|
|
281
|
-
id: "thread-comment.mutation.add-comment",
|
|
282
|
-
type: l.MUTATION,
|
|
283
|
-
handler(s, t, e) {
|
|
284
|
-
if (!t)
|
|
285
|
-
return !1;
|
|
286
|
-
const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
|
|
287
|
-
return n.addComment(o, r, a, m);
|
|
288
|
-
}
|
|
289
|
-
}, A = {
|
|
290
|
-
id: "thread-comment.mutation.update-comment",
|
|
291
|
-
type: l.MUTATION,
|
|
292
|
-
handler(s, t) {
|
|
293
|
-
if (!t)
|
|
294
|
-
return !1;
|
|
295
|
-
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
296
|
-
return e.updateComment(n, o, r, a);
|
|
297
|
-
}
|
|
298
|
-
}, Q = {
|
|
299
|
-
id: "thread-comment.mutation.update-comment-ref",
|
|
300
|
-
type: l.MUTATION,
|
|
301
|
-
handler(s, t) {
|
|
302
|
-
if (!t)
|
|
303
|
-
return !1;
|
|
304
|
-
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
|
|
305
|
-
return e.updateCommentRef(n, o, r, a);
|
|
306
|
-
}
|
|
307
|
-
}, $ = {
|
|
308
|
-
id: "thread-comment.mutation.resolve-comment",
|
|
309
|
-
type: l.MUTATION,
|
|
310
|
-
handler(s, t) {
|
|
311
|
-
if (!t)
|
|
312
|
-
return !1;
|
|
313
|
-
const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
|
|
314
|
-
return e.resolveComment(n, o, a, r);
|
|
315
|
-
}
|
|
316
|
-
}, E = {
|
|
317
|
-
id: "thread-comment.mutation.delete-comment",
|
|
318
|
-
type: l.MUTATION,
|
|
319
|
-
handler(s, t) {
|
|
320
|
-
if (!t)
|
|
321
|
-
return !1;
|
|
322
|
-
const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
|
|
323
|
-
return e.deleteComment(n, o, r);
|
|
324
|
-
}
|
|
325
|
-
}, X = {
|
|
326
|
-
id: "thread-comment.command.add-comment",
|
|
327
|
-
type: l.COMMAND,
|
|
328
|
-
async handler(s, t) {
|
|
329
|
-
if (!t)
|
|
330
|
-
return !1;
|
|
331
|
-
const e = s.get(M), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
|
|
332
|
-
id: x.id,
|
|
333
|
-
params: {
|
|
334
|
-
...t,
|
|
335
|
-
comment: r
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
|
|
339
|
-
onlyLocal: !a
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
}, Z = {
|
|
343
|
-
id: "thread-comment.command.update-comment",
|
|
344
|
-
type: l.COMMAND,
|
|
345
|
-
async handler(s, t) {
|
|
346
|
-
if (!t)
|
|
347
|
-
return !1;
|
|
348
|
-
const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(M), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
|
|
349
|
-
e,
|
|
350
|
-
n,
|
|
351
|
-
o.commentId
|
|
352
|
-
);
|
|
353
|
-
if (!c)
|
|
354
|
-
return !1;
|
|
355
|
-
const { children: u, ..._ } = c;
|
|
356
|
-
if (!await d.updateComment({
|
|
357
|
-
..._,
|
|
358
|
-
...o
|
|
359
|
-
}))
|
|
360
|
-
return !1;
|
|
361
|
-
const N = {
|
|
362
|
-
id: A.id,
|
|
363
|
-
params: t
|
|
364
|
-
};
|
|
365
|
-
return r.executeCommand(N.id, N.params, { onlyLocal: !m }), !0;
|
|
366
|
-
}
|
|
367
|
-
}, ee = {
|
|
368
|
-
id: "thread-comment.command.resolve-comment",
|
|
369
|
-
type: l.COMMAND,
|
|
370
|
-
async handler(s, t) {
|
|
371
|
-
if (!t)
|
|
372
|
-
return !1;
|
|
373
|
-
const { unitId: e, subUnitId: n, resolved: o, commentId: r } = t, a = s.get(p), m = s.get(i).getComment(e, n, r), c = a.syncUpdateMutationToColla;
|
|
374
|
-
return !m || !await a.resolveComment({
|
|
375
|
-
...m,
|
|
376
|
-
resolved: o
|
|
377
|
-
}) ? !1 : s.get(M).executeCommand(
|
|
378
|
-
$.id,
|
|
379
|
-
t,
|
|
380
|
-
{ onlyLocal: !c }
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
}, te = {
|
|
384
|
-
id: "thread-comment.command.delete-comment",
|
|
385
|
-
type: l.COMMAND,
|
|
386
|
-
async handler(s, t) {
|
|
387
|
-
if (!t)
|
|
388
|
-
return !1;
|
|
389
|
-
const e = s.get(i), n = s.get(p), o = s.get(M), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
|
|
390
|
-
if (!c || !await n.deleteComment(r, a, c.threadId, d))
|
|
391
|
-
return !1;
|
|
392
|
-
const u = {
|
|
393
|
-
id: E.id,
|
|
394
|
-
params: t
|
|
395
|
-
};
|
|
396
|
-
return o.executeCommand(u.id, u.params, { onlyLocal: !m });
|
|
397
|
-
}
|
|
398
|
-
}, ne = {
|
|
399
|
-
id: "thread-comment.command.delete-comment-tree",
|
|
400
|
-
type: l.COMMAND,
|
|
401
|
-
async handler(s, t) {
|
|
402
|
-
if (!t)
|
|
403
|
-
return !1;
|
|
404
|
-
const e = s.get(i), n = s.get(M), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
|
|
405
|
-
return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? !1 : await n.executeCommand(E.id, {
|
|
406
|
-
unitId: r,
|
|
407
|
-
subUnitId: a,
|
|
408
|
-
commentId: m.root.id
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
function pe(s) {
|
|
413
|
-
return k(s).format("YYYY/MM/DD HH:mm");
|
|
414
|
-
}
|
|
415
|
-
const P = "UNIVER_THREAD_COMMENT_PLUGIN";
|
|
416
|
-
var oe = Object.getOwnPropertyDescriptor, re = (s, t, e, n) => {
|
|
417
|
-
for (var o = n > 1 ? void 0 : n ? oe(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
418
|
-
(a = s[r]) && (o = a(o) || o);
|
|
419
|
-
return o;
|
|
420
|
-
}, S = (s, t) => (e, n) => t(e, n, s);
|
|
421
|
-
const ae = `SHEET_${P}`;
|
|
422
|
-
let v = class extends U {
|
|
423
|
-
constructor(s, t, e) {
|
|
424
|
-
super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
|
|
425
|
-
}
|
|
426
|
-
_initSnapshot() {
|
|
427
|
-
const s = (e) => {
|
|
428
|
-
const n = this._threadCommentModel.getUnit(e), o = {};
|
|
429
|
-
return n ? (n.forEach((r) => {
|
|
430
|
-
var d;
|
|
431
|
-
const a = (d = o[r.subUnitId]) != null ? d : [];
|
|
432
|
-
a.push({
|
|
433
|
-
...r.root,
|
|
434
|
-
children: r.children
|
|
435
|
-
}), o[r.subUnitId] = a;
|
|
436
|
-
}), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
|
|
437
|
-
}, t = (e) => {
|
|
438
|
-
if (!e)
|
|
439
|
-
return {};
|
|
440
|
-
try {
|
|
441
|
-
return JSON.parse(e);
|
|
442
|
-
} catch {
|
|
443
|
-
return {};
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
this.disposeWithMe(
|
|
447
|
-
this._resourceManagerService.registerPluginResource({
|
|
448
|
-
pluginName: ae,
|
|
449
|
-
businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
|
|
450
|
-
toJson: (e) => s(e),
|
|
451
|
-
parseJson: (e) => t(e),
|
|
452
|
-
onUnLoad: (e) => {
|
|
453
|
-
this._threadCommentModel.deleteUnit(e);
|
|
454
|
-
},
|
|
455
|
-
onLoad: async (e, n) => {
|
|
456
|
-
Object.keys(n).forEach((o) => {
|
|
457
|
-
const r = n[o];
|
|
458
|
-
r.forEach((a) => {
|
|
459
|
-
this._threadCommentModel.addComment(e, o, a);
|
|
460
|
-
}), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
})
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
v = re([
|
|
468
|
-
S(0, J),
|
|
469
|
-
S(1, g(i)),
|
|
470
|
-
S(2, p)
|
|
471
|
-
], v);
|
|
472
|
-
const se = "@univerjs/thread-comment", me = "0.17.0", D = {
|
|
473
|
-
name: se,
|
|
474
|
-
version: me
|
|
475
|
-
}, ce = "thread-comment.config", I = {};
|
|
476
|
-
var de = Object.getOwnPropertyDescriptor, ie = (s, t, e, n) => {
|
|
477
|
-
for (var o = n > 1 ? void 0 : n ? de(t, e) : t, r = s.length - 1, a; r >= 0; r--)
|
|
478
|
-
(a = s[r]) && (o = a(o) || o);
|
|
479
|
-
return o;
|
|
480
|
-
}, y = (s, t) => (e, n) => t(e, n, s), f;
|
|
481
|
-
let R = (f = class extends G {
|
|
482
|
-
constructor(s = I, t, e, n) {
|
|
483
|
-
super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
|
|
484
|
-
const { ...o } = V(
|
|
485
|
-
{},
|
|
486
|
-
I,
|
|
487
|
-
this._config
|
|
488
|
-
);
|
|
489
|
-
this._configService.setConfig(ce, o);
|
|
490
|
-
}
|
|
491
|
-
onStarting() {
|
|
492
|
-
var s;
|
|
493
|
-
Y([
|
|
494
|
-
[p, { useClass: F }],
|
|
495
|
-
[i],
|
|
496
|
-
[v]
|
|
497
|
-
], (s = this._config) == null ? void 0 : s.overrides).forEach(
|
|
498
|
-
(t) => {
|
|
499
|
-
this._injector.add(t);
|
|
500
|
-
}
|
|
501
|
-
), [
|
|
502
|
-
X,
|
|
503
|
-
Z,
|
|
504
|
-
te,
|
|
505
|
-
ee,
|
|
506
|
-
ne,
|
|
507
|
-
x,
|
|
508
|
-
A,
|
|
509
|
-
Q,
|
|
510
|
-
E,
|
|
511
|
-
$
|
|
512
|
-
].forEach((t) => {
|
|
513
|
-
this._commandService.registerCommand(t);
|
|
514
|
-
}), this._injector.get(v);
|
|
515
|
-
}
|
|
516
|
-
}, h(f, "pluginName", P), h(f, "packageName", D.name), h(f, "version", D.version), h(f, "type", T.UNIVER_UNKNOWN), f);
|
|
517
|
-
R = ie([
|
|
518
|
-
y(1, g(B)),
|
|
519
|
-
y(2, M),
|
|
520
|
-
y(3, b)
|
|
521
|
-
], R);
|
|
522
|
-
export {
|
|
523
|
-
X as AddCommentCommand,
|
|
524
|
-
x as AddCommentMutation,
|
|
525
|
-
te as DeleteCommentCommand,
|
|
526
|
-
E as DeleteCommentMutation,
|
|
527
|
-
ne as DeleteCommentTreeCommand,
|
|
528
|
-
p as IThreadCommentDataSourceService,
|
|
529
|
-
ee as ResolveCommentCommand,
|
|
530
|
-
$ as ResolveCommentMutation,
|
|
531
|
-
ae as SHEET_UNIVER_THREAD_COMMENT_PLUGIN,
|
|
532
|
-
P as TC_PLUGIN_NAME,
|
|
533
|
-
F as ThreadCommentDataSourceService,
|
|
534
|
-
i as ThreadCommentModel,
|
|
535
|
-
v as ThreadCommentResourceController,
|
|
536
|
-
R as UniverThreadCommentPlugin,
|
|
537
|
-
Z as UpdateCommentCommand,
|
|
538
|
-
A as UpdateCommentMutation,
|
|
539
|
-
Q as UpdateCommentRefMutation,
|
|
540
|
-
pe as getDT
|
|
541
|
-
};
|
|
1
|
+
import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,IResourceManagerService as i,Inject as a,Injector as o,LifecycleService as s,LifecycleStages as c,Plugin as l,UniverInstanceType as u,createIdentifier as d,dayjs as f,merge as p,mergeOverrideWithDependencies as m}from"@univerjs/core";import{Subject as h}from"rxjs";function g(e){"@babel/helpers - typeof";return g=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var b=class extends t{set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}constructor(){super(),y(this,`_dataSource`,null),y(this,`syncUpdateMutationToColla`,!0)}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?e.id:t}}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,r){return this._dataSource?this._dataSource.deleteComment(e,t,n,r):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n].map(this.dataSource.saveCommentToSnapshot)}),t}return e}};const x=d(`univer.thread-comment.data-source-service`);function S(e,t){return function(n,r){t(n,r,e)}}function C(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let w=class extends t{constructor(e,t){super(),this._dataSourceService=e,this._lifecycleService=t,y(this,`_commentsMap`,new Map),y(this,`_threadMap`,new Map),y(this,`_commentUpdate$`,new h),y(this,`commentUpdate$`,this._commentUpdate$.asObservable()),y(this,`_tasks`,[]),this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(e=>{let t=new Map;e===c.Rendered&&(this._tasks.forEach(({unitId:e,subUnitId:n,threadIds:r})=>{let i=t.get(e);i||(i=new Map,t.set(e,i));let a=i.get(n);a||(a=new Set,i.set(n,a));for(let e of r)a.add(e)}),this._tasks=[],t.forEach((e,t)=>{e.forEach((e,n)=>{this.syncThreadComments(t,n,Array.from(e))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}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 r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_replaceComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n.id);if(i){let{children:a,...o}=n,s={...o,ref:i.ref};r.set(n.id,s),a==null||a.forEach(e=>{r.set(e.id,{...e,ref:``})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`syncUpdate`,payload:s}),!!n.resolved!=!!i.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.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}let r=this._ensureThreadMap(e,t),i=this._ensureCommentMap(e,t),a=await this._dataSourceService.listThreadComments(e,t,n);if(!a)return;let o=new Set(n);a.forEach(n=>{this._replaceComment(e,t,n),o.delete(n.threadId)}),o.forEach(e=>{r.delete(e),i.forEach((t,n)=>{t.threadId===e&&i.delete(n)})})}addComment(e,t,n,r){let i=this._ensureCommentMap(e,t),{parentId:a,children:o=[],...s}=n,c={...s,parentId:a===n.id?void 0:a};c.threadId||(c.threadId=c.parentId||c.id);let l=n=>{i.set(n.id,n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`add`,payload:n,isRoot:!n.parentId})};l(c);let u=this._ensureThreadMap(e,t);if(!c.parentId){u.set(c.threadId,c);for(let e of o)l(e)}return r&&this.syncThreadComments(e,t,[c.threadId]),!0}updateComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.updated=!0,i.text=n.text,i.attachments=n.attachments,i.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`update`,payload:n,silent:r}),!0):!0}updateCommentRef(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`updateRef`,payload:n,silent:r,threadId:i.threadId}),!0):!1}resolveComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n);return i?(i.resolved=r,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n,resolved:r}}),!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){let r=this._ensureCommentMap(e,t),i=Array.from(r.values()).filter(e=>e.threadId===n),a,o=[],s=new Set;for(let e of i)e.parentId?o.push(e):a=e,s.add(e.personId);if(a)return{root:a,children:o,relativeUsers:s,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){let r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n);i&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`delete`,payload:{commentId:n,isRoot:!i.parentId,comment:i}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){let 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){let t=this._commentsMap.get(e);t&&t.forEach((t,n)=>{t.forEach(t=>{this.deleteComment(e,n,t.id)})})}getUnit(e){let t=this._threadMap.get(e);if(!t)return[];let n=[];return t.forEach((t,r)=>{t.forEach((t,i)=>{let a=this.getThread(e,r,i);a&&n.push(a)})}),n}getAll(){let e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};w=C([S(0,a(x)),S(1,a(s))],w);const T={id:`thread-comment.mutation.add-comment`,type:e.MUTATION,handler(e,t,n){if(!t)return!1;let r=e.get(w),{unitId:i,subUnitId:a,comment:o,sync:s}=t,c=s||(n==null?void 0:n.fromChangeset)&&!o.parentId;return r.addComment(i,a,o,c)}},E={id:`thread-comment.mutation.update-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateComment(r,i,a,o)}},D={id:`thread-comment.mutation.update-comment-ref`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateCommentRef(r,i,a,o)}},O={id:`thread-comment.mutation.resolve-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,resolved:a,commentId:o}=t;return n.resolveComment(r,i,o,a)}},k={id:`thread-comment.mutation.delete-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,commentId:a}=t;return n.deleteComment(r,i,a)}},A={id:`thread-comment.command.add-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(n),i=e.get(x),{comment:a}=t,o=await i.addComment(a),s=i.syncUpdateMutationToColla,c=!a.parentId,l={id:T.id,params:{...t,comment:o}};return c?await r.executeCommand(l.id,l.params):r.executeCommand(l.id,l.params,{onlyLocal:!s})}},j={id:`thread-comment.command.update-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let{unitId:r,subUnitId:i,payload:a}=t,o=e.get(n),s=e.get(w),c=e.get(x),l=c.syncUpdateMutationToColla,u=s.getComment(r,i,a.commentId);if(!u)return!1;let{children:d,...f}=u;if(!await c.updateComment({...f,...a}))return!1;let p={id:E.id,params:t};return o.executeCommand(p.id,p.params,{onlyLocal:!l}),!0}},M={id:`thread-comment.command.resolve-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let{unitId:r,subUnitId:i,resolved:a,commentId:o}=t,s=e.get(x),c=e.get(w).getComment(r,i,o),l=s.syncUpdateMutationToColla;return!c||!await s.resolveComment({...c,resolved:a})?!1:e.get(n).executeCommand(O.id,t,{onlyLocal:!l})}},N={id:`thread-comment.command.delete-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(w),i=e.get(x),a=e.get(n),{unitId:o,subUnitId:s,commentId:c}=t,l=i.syncUpdateMutationToColla,u=r.getComment(o,s,c);if(!u||!await i.deleteComment(o,s,u.threadId,c))return!1;let d={id:k.id,params:t};return a.executeCommand(d.id,d.params,{onlyLocal:!l})}},P={id:`thread-comment.command.delete-comment-tree`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(w),i=e.get(n),a=e.get(x),{unitId:o,subUnitId:s,commentId:c}=t,l=r.getCommentWithChildren(o,s,c);return!l||!await a.deleteComment(o,s,l.root.threadId,c)?!1:await i.executeCommand(k.id,{unitId:o,subUnitId:s,commentId:l.root.id})}};function F(e){return f(e).format(`YYYY/MM/DD HH:mm`)}const I=`UNIVER_THREAD_COMMENT_PLUGIN`,L=`SHEET_${I}`;let R=class extends t{constructor(e,t,n){super(),this._resourceManagerService=e,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._threadCommentModel.getUnit(e),n={};return t?(t.forEach(e=>{var t;let r=(t=n[e.subUnitId])==null?[]:t;r.push({...e.root,children:e.children}),n[e.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(n,e))):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:L,businesses:[u.UNIVER_SHEET,u.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>t(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{let r=t[n];r.forEach(t=>{this._threadCommentModel.addComment(e,n,t)}),this._threadCommentModel.syncThreadComments(e,n,r.map(e=>e.threadId))})}}))}};R=C([S(0,i),S(1,a(w)),S(2,x)],R);var z=`@univerjs/thread-comment`,B=`0.18.0-insiders.20260328-0842384`;const V=`thread-comment.config`;Symbol(V);const H={};let U=class extends l{constructor(e=H,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{...i}=p({},H,this._config);this._configService.setConfig(V,i)}onStarting(){var e;m([[x,{useClass:b}],[w],[R]],(e=this._config)==null?void 0:e.overrides).forEach(e=>{this._injector.add(e)}),[A,j,N,M,P,T,E,D,k,O].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(R)}};y(U,`pluginName`,I),y(U,`packageName`,z),y(U,`version`,B),y(U,`type`,u.UNIVER_UNKNOWN),U=C([S(1,a(o)),S(2,n),S(3,r)],U);export{A as AddCommentCommand,T as AddCommentMutation,N as DeleteCommentCommand,k as DeleteCommentMutation,P as DeleteCommentTreeCommand,x as IThreadCommentDataSourceService,M as ResolveCommentCommand,O as ResolveCommentMutation,L as SHEET_UNIVER_THREAD_COMMENT_PLUGIN,I as TC_PLUGIN_NAME,b as ThreadCommentDataSourceService,w as ThreadCommentModel,R as ThreadCommentResourceController,U as UniverThreadCommentPlugin,j as UpdateCommentCommand,E as UpdateCommentMutation,D as UpdateCommentRefMutation,F as getDT};
|