@univerjs/thread-comment 0.5.0-alpha.0 → 0.5.0-beta.0

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var Me=Object.defineProperty;var _e=(a,s,e)=>s in a?Me(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e;var N=(a,s,e)=>_e(a,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("@univerjs/core"),ve=require("rxjs");class ae extends M.Disposable{constructor(){super();N(this,"_dataSource",null);N(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,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){const n={};return Object.keys(e).forEach(r=>{const o=e[r];n[r]=o.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const I=M.createIdentifier("univer.thread-comment.data-source-service");var ge=Object.defineProperty,ye=Object.getOwnPropertyDescriptor,Se=(a,s,e,t)=>{for(var n=t>1?void 0:t?ye(s,e):s,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(s,e,n):o(n))||n);return t&&n&&ge(s,e,n),n},oe=(a,s)=>(e,t)=>s(e,t,a);exports.ThreadCommentModel=class extends M.Disposable{constructor(e,t){super();N(this,"_commentsMap",new Map);N(this,"_threadMap",new Map);N(this,"_commentUpdate$",new ve.Subject);N(this,"commentUpdate$",this._commentUpdate$.asObservable());N(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const r=new Map;n===M.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:o,subUnitId:d,threadIds:l})=>{let f=r.get(o);f||(f=new Map,r.set(o,f));let _=f.get(d);_||(_=new Set,f.set(d,_));for(const y of l)_.add(y)}),this._tasks=[],r.forEach((o,d)=>{o.forEach((l,f)=>{this.syncThreadComments(d,f,Array.from(l))})}))}))}_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){const r=this._ensureCommentMap(e,t),o=r.get(n.id);if(o){const{children:d,...l}=n,f={...l,ref:o.ref};r.set(n.id,f),d==null||d.forEach(_=>{r.set(_.id,{..._,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:f}),!!n.resolved!=!!o.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<M.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const r=this._ensureThreadMap(e,t),o=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const l=new Set(n);d.forEach(f=>{this._replaceComment(e,t,f),l.delete(f.threadId)}),l.forEach(f=>{r.delete(f),o.forEach((_,y)=>{_.threadId===f&&o.delete(y)})})}addComment(e,t,n,r){const o=this._ensureCommentMap(e,t),{parentId:d,children:l=[],...f}=n,_={...f,parentId:d===n.id?void 0:d},y=T=>{o.set(T.id,T),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:T,isRoot:!T.parentId})};y(_);const A=this._ensureThreadMap(e,t);if(!_.parentId){A.set(_.threadId,_);for(const T of l)y(T)}return r&&this.syncThreadComments(e,t,[_.threadId]),!0}updateComment(e,t,n,r){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:r})),!0}updateCommentRef(e,t,n,r){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:r,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,r){const d=this._ensureCommentMap(e,t).get(n);return d?(d.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){const r=this._ensureCommentMap(e,t),o=Array.from(r.values()).filter(_=>_.threadId===n);let d;const l=[],f=new Set;for(const _ of o)_.parentId?l.push(_):d=_,f.add(_.personId);if(d)return{root:d,children:l,relativeUsers:f,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){const r=this._ensureCommentMap(e,t),o=r.get(n);o&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!o.parentId,comment:o}}))}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 o=this._ensureCommentMap(e,t).get(n);return o&&(o.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,o.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,r)=>{n.forEach(o=>{this.deleteComment(e,r,o.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((r,o)=>{r.forEach((d,l)=>{const f=this.getThread(e,o,l);f&&n.push(f)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};exports.ThreadCommentModel=Se([oe(0,M.Inject(I)),oe(1,M.Inject(M.LifecycleService))],exports.ThreadCommentModel);var q=(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))(q||{});const z="UNIVER_THREAD_COMMENT_PLUGIN";var Te=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,De=(a,s,e,t)=>{for(var n=t>1?void 0:t?$e(s,e):s,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(s,e,n):o(n))||n);return t&&n&&Te(s,e,n),n},B=(a,s)=>(e,t)=>s(e,t,a);exports.ThreadCommentResourceController=class extends M.Disposable{constructor(s,e,t){super(),this._resourceManagerService=s,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const s=t=>{const n=this._threadCommentModel.getUnit(t),r={};return n?(n.forEach(o=>{var l;const d=(l=r[o.subUnitId])!=null?l:[];d.push({...o.root,children:o.children}),r[o.unitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${z}`,businesses:[q.UNIVER_SHEET,q.UNIVER_DOC],toJson:t=>s(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(r=>{const o=n[r];o.forEach(d=>{this._threadCommentModel.addComment(t,r,d)}),this._threadCommentModel.syncThreadComments(t,r,o.map(d=>d.threadId))})}}))}};exports.ThreadCommentResourceController=De([B(0,M.IResourceManagerService),B(1,M.Inject(exports.ThreadCommentModel)),B(2,I)],exports.ThreadCommentResourceController);const Q={id:"thread-comment.mutation.add-comment",type:M.CommandType.MUTATION,handler(a,s,e){if(!s)return!1;const t=a.get(exports.ThreadCommentModel),{unitId:n,subUnitId:r,comment:o,sync:d}=s,l=d||(e==null?void 0:e.fromChangeset)&&!o.parentId;return t.addComment(n,r,o,l)}},X={id:"thread-comment.mutation.update-comment",type:M.CommandType.MUTATION,handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:r,silent:o}=s;return e.updateComment(t,n,r,o)}},se={id:"thread-comment.mutation.update-comment-ref",type:M.CommandType.MUTATION,handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:r,silent:o}=s;return e.updateCommentRef(t,n,r,o)}},ee={id:"thread-comment.mutation.resolve-comment",type:M.CommandType.MUTATION,handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:r,commentId:o}=s;return e.resolveComment(t,n,o,r)}},k={id:"thread-comment.mutation.delete-comment",type:M.CommandType.MUTATION,handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:r}=s;return e.deleteComment(t,n,r)}},ie={id:"thread-comment.command.add-comment",type:M.CommandType.COMMAND,async handler(a,s){if(!s)return!1;const e=a.get(M.ICommandService),t=a.get(I),{comment:n}=s,r=await t.addComment(n),o=t.syncUpdateMutationToColla,d=!n.parentId,l={id:Q.id,params:{...s,comment:r}};return d?await e.executeCommand(l.id,l.params):e.executeCommand(l.id,l.params,{onlyLocal:!o})}},me={id:"thread-comment.command.update-comment",type:M.CommandType.COMMAND,async handler(a,s){if(!s)return!1;const{unitId:e,subUnitId:t,payload:n}=s,r=a.get(M.ICommandService),o=a.get(exports.ThreadCommentModel),d=a.get(I),l=d.syncUpdateMutationToColla,f=o.getComment(e,t,n.commentId);if(!f)return!1;const{children:_,...y}=f;if(!await d.updateComment({...y,...n}))return!1;const T={id:X.id,params:s};return r.executeCommand(T.id,T.params,{onlyLocal:!l}),!0}},ce={id:"thread-comment.command.resolve-comment",type:M.CommandType.COMMAND,async handler(a,s){if(!s)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:r}=s,o=a.get(I),l=a.get(exports.ThreadCommentModel).getComment(e,t,r),f=o.syncUpdateMutationToColla;return!l||!await o.resolveComment({...l,resolved:n})?!1:a.get(M.ICommandService).executeCommand(ee.id,s,{onlyLocal:!f})}},de={id:"thread-comment.command.delete-comment",type:M.CommandType.COMMAND,async handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(I),n=a.get(M.ICommandService),{unitId:r,subUnitId:o,commentId:d}=s,l=t.syncUpdateMutationToColla,f=e.getComment(r,o,d);if(!f||!await t.deleteComment(r,o,f.threadId,d))return!1;const _={id:k.id,params:s};return n.executeCommand(_.id,_.params,{onlyLocal:!l})}},ue={id:"thread-comment.command.delete-comment-tree",type:M.CommandType.COMMAND,async handler(a,s){if(!s)return!1;const e=a.get(exports.ThreadCommentModel),t=a.get(M.ICommandService),n=a.get(I),{unitId:r,subUnitId:o,commentId:d}=s,l=e.getCommentWithChildren(r,o,d);return!l||!await n.deleteComment(r,o,l.root.threadId,d)?!1:await t.executeCommand(k.id,{unitId:r,subUnitId:o,commentId:l.root.id})}},Oe="thread-comment.config",Ue={};var we=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Ie=(a,s,e,t)=>{for(var n=t>1?void 0:t?Ne(s,e):s,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(s,e,n):o(n))||n);return t&&n&&we(s,e,n),n},K=(a,s)=>(e,t)=>s(e,t,a),G;exports.UniverThreadCommentPlugin=(G=class extends M.Plugin{constructor(s=Ue,e,t,n){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=n;const{...r}=this._config;this._configService.setConfig(Oe,r)}onStarting(){var s;M.mergeOverrideWithDependencies([[I,{useClass:ae}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(s=this._config)==null?void 0:s.overrides).forEach(e=>{this._injector.add(e)}),[ie,me,de,ce,ue,Q,X,se,k,ee].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},N(G,"pluginName",z),N(G,"type",M.UniverInstanceType.UNIVER_UNKNOWN),G);exports.UniverThreadCommentPlugin=Ie([K(1,M.Inject(M.Injector)),K(2,M.ICommandService),K(3,M.IConfigService)],exports.UniverThreadCommentPlugin);var Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Re(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var he={exports:{}};(function(a,s){(function(e,t){a.exports=t()})(Ee,function(){var e=1e3,t=6e4,n=36e5,r="millisecond",o="second",d="minute",l="hour",f="day",_="week",y="month",A="quarter",T="year",x="date",te="Invalid Date",le=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,fe=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,pe={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(h){var c=["th","st","nd","rd"],i=h%100;return"["+h+(c[(i-20)%10]||c[i]||c[0])+"]"}},F=function(h,c,i){var u=String(h);return!u||u.length>=c?h:""+Array(c+1-u.length).join(i)+h},Ce={s:F,z:function(h){var c=-h.utcOffset(),i=Math.abs(c),u=Math.floor(i/60),m=i%60;return(c<=0?"+":"-")+F(u,2,"0")+":"+F(m,2,"0")},m:function h(c,i){if(c.date()<i.date())return-h(i,c);var u=12*(i.year()-c.year())+(i.month()-c.month()),m=c.clone().add(u,y),p=i-m<0,C=c.clone().add(u+(p?-1:1),y);return+(-(u+(i-m)/(p?m-C:C-m))||0)},a:function(h){return h<0?Math.ceil(h)||0:Math.floor(h)},p:function(h){return{M:y,y:T,w:_,d:f,D:x,h:l,m:d,s:o,ms:r,Q:A}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(h){return h===void 0}},L="en",R={};R[L]=pe;var ne="$isDayjsObject",Z=function(h){return h instanceof V||!(!h||!h[ne])},Y=function h(c,i,u){var m;if(!c)return L;if(typeof c=="string"){var p=c.toLowerCase();R[p]&&(m=p),i&&(R[p]=i,m=p);var C=c.split("-");if(!m&&C.length>1)return h(C[0])}else{var g=c.name;R[g]=c,m=g}return!u&&m&&(L=m),m||!u&&L},$=function(h,c){if(Z(h))return h.clone();var i=typeof c=="object"?c:{};return i.date=h,i.args=arguments,new V(i)},v=Ce;v.l=Y,v.i=Z,v.w=function(h,c){return $(h,{locale:c.$L,utc:c.$u,x:c.$x,$offset:c.$offset})};var V=function(){function h(i){this.$L=Y(i.locale,null,!0),this.parse(i),this.$x=this.$x||i.x||{},this[ne]=!0}var c=h.prototype;return c.parse=function(i){this.$d=function(u){var m=u.date,p=u.utc;if(m===null)return new Date(NaN);if(v.u(m))return new Date;if(m instanceof Date)return new Date(m);if(typeof m=="string"&&!/Z$/i.test(m)){var C=m.match(le);if(C){var g=C[2]-1||0,S=(C[7]||"0").substring(0,3);return p?new Date(Date.UTC(C[1],g,C[3]||1,C[4]||0,C[5]||0,C[6]||0,S)):new Date(C[1],g,C[3]||1,C[4]||0,C[5]||0,C[6]||0,S)}}return new Date(m)}(i),this.init()},c.init=function(){var i=this.$d;this.$y=i.getFullYear(),this.$M=i.getMonth(),this.$D=i.getDate(),this.$W=i.getDay(),this.$H=i.getHours(),this.$m=i.getMinutes(),this.$s=i.getSeconds(),this.$ms=i.getMilliseconds()},c.$utils=function(){return v},c.isValid=function(){return this.$d.toString()!==te},c.isSame=function(i,u){var m=$(i);return this.startOf(u)<=m&&m<=this.endOf(u)},c.isAfter=function(i,u){return $(i)<this.startOf(u)},c.isBefore=function(i,u){return this.endOf(u)<$(i)},c.$g=function(i,u,m){return v.u(i)?this[u]:this.set(m,i)},c.unix=function(){return Math.floor(this.valueOf()/1e3)},c.valueOf=function(){return this.$d.getTime()},c.startOf=function(i,u){var m=this,p=!!v.u(u)||u,C=v.p(i),g=function(P,U){var E=v.w(m.$u?Date.UTC(m.$y,U,P):new Date(m.$y,U,P),m);return p?E:E.endOf(f)},S=function(P,U){return v.w(m.toDate()[P].apply(m.toDate("s"),(p?[0,0,0,0]:[23,59,59,999]).slice(U)),m)},D=this.$W,O=this.$M,w=this.$D,j="set"+(this.$u?"UTC":"");switch(C){case T:return p?g(1,0):g(31,11);case y:return p?g(1,O):g(0,O+1);case _:var b=this.$locale().weekStart||0,H=(D<b?D+7:D)-b;return g(p?w-H:w+(6-H),O);case f:case x:return S(j+"Hours",0);case l:return S(j+"Minutes",1);case d:return S(j+"Seconds",2);case o:return S(j+"Milliseconds",3);default:return this.clone()}},c.endOf=function(i){return this.startOf(i,!1)},c.$set=function(i,u){var m,p=v.p(i),C="set"+(this.$u?"UTC":""),g=(m={},m[f]=C+"Date",m[x]=C+"Date",m[y]=C+"Month",m[T]=C+"FullYear",m[l]=C+"Hours",m[d]=C+"Minutes",m[o]=C+"Seconds",m[r]=C+"Milliseconds",m)[p],S=p===f?this.$D+(u-this.$W):u;if(p===y||p===T){var D=this.clone().set(x,1);D.$d[g](S),D.init(),this.$d=D.set(x,Math.min(this.$D,D.daysInMonth())).$d}else g&&this.$d[g](S);return this.init(),this},c.set=function(i,u){return this.clone().$set(i,u)},c.get=function(i){return this[v.p(i)]()},c.add=function(i,u){var m,p=this;i=Number(i);var C=v.p(u),g=function(O){var w=$(p);return v.w(w.date(w.date()+Math.round(O*i)),p)};if(C===y)return this.set(y,this.$M+i);if(C===T)return this.set(T,this.$y+i);if(C===f)return g(1);if(C===_)return g(7);var S=(m={},m[d]=t,m[l]=n,m[o]=e,m)[C]||1,D=this.$d.getTime()+i*S;return v.w(D,this)},c.subtract=function(i,u){return this.add(-1*i,u)},c.format=function(i){var u=this,m=this.$locale();if(!this.isValid())return m.invalidDate||te;var p=i||"YYYY-MM-DDTHH:mm:ssZ",C=v.z(this),g=this.$H,S=this.$m,D=this.$M,O=m.weekdays,w=m.months,j=m.meridiem,b=function(U,E,W,J){return U&&(U[E]||U(u,p))||W[E].slice(0,J)},H=function(U){return v.s(g%12||12,U,"0")},P=j||function(U,E,W){var J=U<12?"AM":"PM";return W?J.toLowerCase():J};return p.replace(fe,function(U,E){return E||function(W){switch(W){case"YY":return String(u.$y).slice(-2);case"YYYY":return v.s(u.$y,4,"0");case"M":return D+1;case"MM":return v.s(D+1,2,"0");case"MMM":return b(m.monthsShort,D,w,3);case"MMMM":return b(w,D);case"D":return u.$D;case"DD":return v.s(u.$D,2,"0");case"d":return String(u.$W);case"dd":return b(m.weekdaysMin,u.$W,O,2);case"ddd":return b(m.weekdaysShort,u.$W,O,3);case"dddd":return O[u.$W];case"H":return String(g);case"HH":return v.s(g,2,"0");case"h":return H(1);case"hh":return H(2);case"a":return P(g,S,!0);case"A":return P(g,S,!1);case"m":return String(S);case"mm":return v.s(S,2,"0");case"s":return String(u.$s);case"ss":return v.s(u.$s,2,"0");case"SSS":return v.s(u.$ms,3,"0");case"Z":return C}return null}(U)||C.replace(":","")})},c.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},c.diff=function(i,u,m){var p,C=this,g=v.p(u),S=$(i),D=(S.utcOffset()-this.utcOffset())*t,O=this-S,w=function(){return v.m(C,S)};switch(g){case T:p=w()/12;break;case y:p=w();break;case A:p=w()/3;break;case _:p=(O-D)/6048e5;break;case f:p=(O-D)/864e5;break;case l:p=O/n;break;case d:p=O/t;break;case o:p=O/e;break;default:p=O}return m?p:v.a(p)},c.daysInMonth=function(){return this.endOf(y).$D},c.$locale=function(){return R[this.$L]},c.locale=function(i,u){if(!i)return this.$L;var m=this.clone(),p=Y(i,u,!0);return p&&(m.$L=p),m},c.clone=function(){return v.w(this.$d,this)},c.toDate=function(){return new Date(this.valueOf())},c.toJSON=function(){return this.isValid()?this.toISOString():null},c.toISOString=function(){return this.$d.toISOString()},c.toString=function(){return this.$d.toUTCString()},h}(),re=V.prototype;return $.prototype=re,[["$ms",r],["$s",o],["$m",d],["$H",l],["$W",f],["$M",y],["$y",T],["$D",x]].forEach(function(h){re[h[1]]=function(c){return this.$g(c,h[0],h[1])}}),$.extend=function(h,c){return h.$i||(h(c,V,$),h.$i=!0),$},$.locale=Y,$.isDayjs=Z,$.unix=function(h){return $(1e3*h)},$.en=R[L],$.Ls=R,$.p={},$})})(he);var be=he.exports;const Pe=Re(be);function xe(){return Pe().format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=ie;exports.AddCommentMutation=Q;exports.DeleteCommentCommand=de;exports.DeleteCommentMutation=k;exports.DeleteCommentTreeCommand=ue;exports.IThreadCommentDataSourceService=I;exports.ResolveCommentCommand=ce;exports.ResolveCommentMutation=ee;exports.TC_PLUGIN_NAME=z;exports.ThreadCommentDataSourceService=ae;exports.UpdateCommentCommand=me;exports.UpdateCommentMutation=X;exports.UpdateCommentRefMutation=se;exports.getDT=xe;
1
+ "use strict";var x=Object.defineProperty;var A=(m,a,e)=>a in m?x(m,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[a]=e;var l=(m,a,e)=>A(m,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),j=require("rxjs");class E extends d.Disposable{constructor(){super();l(this,"_dataSource",null);l(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const r=e[o];n[o]=r.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const p=d.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(m,a,e,t)=>{for(var n=t>1?void 0:t?V(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&L(a,e,n),n},I=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();l(this,"_commentsMap",new Map);l(this,"_threadMap",new Map);l(this,"_commentUpdate$",new j.Subject);l(this,"commentUpdate$",this._commentUpdate$.asObservable());l(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:r,subUnitId:s,threadIds:c})=>{let i=o.get(r);i||(i=new Map,o.set(r,i));let h=i.get(s);h||(h=new Set,i.set(s,h));for(const u of c)h.add(u)}),this._tasks=[],o.forEach((r,s)=>{r.forEach((c,i)=>{this.syncThreadComments(s,i,Array.from(c))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n.id);if(r){const{children:s,...c}=n,i={...c,ref:r.ref};o.set(n.id,i),s==null||s.forEach(h=>{o.set(h.id,{...h,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:i}),!!n.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),r=this._ensureCommentMap(e,t),s=await this._dataSourceService.listThreadComments(e,t,n);if(!s)return;const c=new Set(n);s.forEach(i=>{this._replaceComment(e,t,i),c.delete(i.threadId)}),c.forEach(i=>{o.delete(i),r.forEach((h,u)=>{h.threadId===i&&r.delete(u)})})}addComment(e,t,n,o){const r=this._ensureCommentMap(e,t),{parentId:s,children:c=[],...i}=n,h={...i,parentId:s===n.id?void 0:s};h.threadId||(h.threadId=h.parentId||h.id);const u=C=>{r.set(C.id,C),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:C,isRoot:!C.parentId})};u(h);const N=this._ensureThreadMap(e,t);if(!h.parentId){N.set(h.threadId,h);for(const C of c)u(C)}return o&&this.syncThreadComments(e,t,[h.threadId]),!0}updateComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s&&(s.updated=!0,s.text=n.text,s.attachments=n.attachments,s.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n.commentId);return s?(s.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:s.threadId}),!0):!1}resolveComment(e,t,n,o){const s=this._ensureCommentMap(e,t).get(n);return s?(s.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),r=Array.from(o.values()).filter(h=>h.threadId===n);let s;const c=[],i=new Set;for(const h of r)h.parentId?c.push(h):s=h,i.add(h.personId);if(s)return{root:s,children:c,relativeUsers:i,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),r=o.get(n);r&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!r.parentId,comment:r}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(s=>{s.threadId===n&&this._deleteComment(e,t,s.id)})}deleteComment(e,t,n){const r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(r=>{this.deleteComment(e,o,r.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,r)=>{o.forEach((s,c)=>{const i=this.getThread(e,r,c);i&&n.push(i)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};exports.ThreadCommentModel=W([I(0,d.Inject(p)),I(1,d.Inject(d.LifecycleService))],exports.ThreadCommentModel);var v=(m=>(m[m.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",m[m.UNIVER_DOC=1]="UNIVER_DOC",m[m.UNIVER_SHEET=2]="UNIVER_SHEET",m[m.UNIVER_SLIDE=3]="UNIVER_SLIDE",m[m.UNIVER_PROJECT=4]="UNIVER_PROJECT",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(v||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(m,a,e,t)=>{for(var n=t>1?void 0:t?J(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&b(a,e,n),n},_=(m,a)=>(e,t)=>a(e,t,m);exports.ThreadCommentResourceController=class extends d.Disposable{constructor(a,e,t){super(),this._resourceManagerService=a,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const a=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(r=>{var c;const s=(c=o[r.subUnitId])!=null?c:[];s.push({...r.root,children:r.children}),o[r.subUnitId]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[v.UNIVER_SHEET,v.UNIVER_DOC],toJson:t=>a(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const r=n[o];r.forEach(s=>{this._threadCommentModel.addComment(t,o,s)}),this._threadCommentModel.syncThreadComments(t,o,r.map(s=>s.threadId))})}}))}};exports.ThreadCommentResourceController=G([_(0,d.IResourceManagerService),_(1,d.Inject(exports.ThreadCommentModel)),_(2,p)],exports.ThreadCommentResourceController);const g={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(m,a,e){if(!a)return!1;const t=m.get(exports.ThreadCommentModel),{unitId:n,subUnitId:o,comment:r,sync:s}=a,c=s||(e==null?void 0:e.fromChangeset)&&!r.parentId;return t.addComment(n,o,r,c)}},y={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateComment(t,n,o,r)}},R={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:r}=a;return e.updateCommentRef(t,n,o,r)}},U={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:r}=a;return e.resolveComment(t,n,r,o)}},M={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=a;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(d.ICommandService),t=m.get(p),{comment:n}=a,o=await t.addComment(n),r=t.syncUpdateMutationToColla,s=!n.parentId,c={id:g.id,params:{...a,comment:o}};return s?await e.executeCommand(c.id,c.params):e.executeCommand(c.id,c.params,{onlyLocal:!r})}},D={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,payload:n}=a,o=m.get(d.ICommandService),r=m.get(exports.ThreadCommentModel),s=m.get(p),c=s.syncUpdateMutationToColla,i=r.getComment(e,t,n.commentId);if(!i)return!1;const{children:h,...u}=i;if(!await s.updateComment({...u,...n}))return!1;const C={id:y.id,params:a};return o.executeCommand(C.id,C.params,{onlyLocal:!c}),!0}},P={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=a,r=m.get(p),c=m.get(exports.ThreadCommentModel).getComment(e,t,o),i=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:n})?!1:m.get(d.ICommandService).executeCommand(U.id,a,{onlyLocal:!i})}},w={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(p),n=m.get(d.ICommandService),{unitId:o,subUnitId:r,commentId:s}=a,c=t.syncUpdateMutationToColla,i=e.getComment(o,r,s);if(!i||!await t.deleteComment(o,r,i.threadId,s))return!1;const h={id:M.id,params:a};return n.executeCommand(h.id,h.params,{onlyLocal:!c})}},$={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(m,a){if(!a)return!1;const e=m.get(exports.ThreadCommentModel),t=m.get(d.ICommandService),n=m.get(p),{unitId:o,subUnitId:r,commentId:s}=a,c=e.getCommentWithChildren(o,r,s);return!c||!await n.deleteComment(o,r,c.root.threadId,s)?!1:await t.executeCommand(M.id,{unitId:o,subUnitId:r,commentId:c.root.id})}},H="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(m,a,e,t)=>{for(var n=t>1?void 0:t?B(a,e):a,o=m.length-1,r;o>=0;o--)(r=m[o])&&(n=(t?r(a,e,n):r(n))||n);return t&&n&&K(a,e,n),n},T=(m,a)=>(e,t)=>a(e,t,m),f;exports.UniverThreadCommentPlugin=(f=class extends d.Plugin{constructor(a=Y,e,t,n){super(),this._config=a,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(H,o)}onStarting(){var a;d.mergeOverrideWithDependencies([[p,{useClass:E}],[exports.ThreadCommentModel],[exports.ThreadCommentResourceController]],(a=this._config)==null?void 0:a.overrides).forEach(e=>{this._injector.add(e)}),[O,D,w,P,$,g,y,R,M,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(exports.ThreadCommentResourceController)}},l(f,"pluginName",S),l(f,"type",d.UniverInstanceType.UNIVER_UNKNOWN),f);exports.UniverThreadCommentPlugin=q([T(1,d.Inject(d.Injector)),T(2,d.ICommandService),T(3,d.IConfigService)],exports.UniverThreadCommentPlugin);function Z(){return d.dayjs().format("YYYY/MM/DD HH:mm")}exports.AddCommentCommand=O;exports.AddCommentMutation=g;exports.DeleteCommentCommand=w;exports.DeleteCommentMutation=M;exports.DeleteCommentTreeCommand=$;exports.IThreadCommentDataSourceService=p;exports.ResolveCommentCommand=P;exports.ResolveCommentMutation=U;exports.TC_PLUGIN_NAME=S;exports.ThreadCommentDataSourceService=E;exports.UpdateCommentCommand=D;exports.UpdateCommentMutation=y;exports.UpdateCommentRefMutation=R;exports.getDT=Z;
package/lib/es/index.js CHANGED
@@ -1,13 +1,13 @@
1
- var Ce = Object.defineProperty;
2
- var _e = (s, t, e) => t in s ? Ce(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var E = (s, t, e) => _e(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { createIdentifier as ve, Disposable as ee, Inject as Z, LifecycleService as ge, LifecycleStages as ae, IResourceManagerService as ye, CommandType as I, ICommandService as H, Plugin as Se, UniverInstanceType as $e, mergeOverrideWithDependencies as Te, Injector as De, IConfigService as Oe } from "@univerjs/core";
5
- import { Subject as we } from "rxjs";
6
- class Ue extends ee {
1
+ var x = Object.defineProperty;
2
+ var A = (s, t, e) => t in s ? x(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var u = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { createIdentifier as j, Disposable as U, Inject as v, LifecycleService as L, LifecycleStages as O, IResourceManagerService as V, CommandType as l, ICommandService as f, Plugin as W, UniverInstanceType as J, mergeOverrideWithDependencies as H, Injector as G, IConfigService as b, dayjs as Y } from "@univerjs/core";
5
+ import { Subject as K } from "rxjs";
6
+ class B extends U {
7
7
  constructor() {
8
8
  super();
9
- E(this, "_dataSource", null);
10
- E(this, "syncUpdateMutationToColla", !0);
9
+ u(this, "_dataSource", null);
10
+ u(this, "syncUpdateMutationToColla", !0);
11
11
  }
12
12
  set dataSource(e) {
13
13
  this._dataSource = e;
@@ -15,8 +15,8 @@ class Ue extends ee {
15
15
  get dataSource() {
16
16
  return this._dataSource;
17
17
  }
18
- async getThreadComment(e, n, r) {
19
- return this._dataSource ? (await this._dataSource.listComments(e, n, [r]))[0] : null;
18
+ async getThreadComment(e, n, o) {
19
+ return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
20
20
  }
21
21
  async addComment(e) {
22
22
  var n;
@@ -28,51 +28,51 @@ class Ue extends ee {
28
28
  async resolveComment(e) {
29
29
  return this._dataSource ? this._dataSource.resolveComment(e) : !0;
30
30
  }
31
- async deleteComment(e, n, r, a) {
32
- return this._dataSource ? this._dataSource.deleteComment(e, n, r, a) : !0;
31
+ async deleteComment(e, n, o, r) {
32
+ return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : !0;
33
33
  }
34
- async listThreadComments(e, n, r) {
35
- return this.dataSource ? this.dataSource.listComments(e, n, r) : !1;
34
+ async listThreadComments(e, n, o) {
35
+ return this.dataSource ? this.dataSource.listComments(e, n, o) : !1;
36
36
  }
37
37
  saveToSnapshot(e, n) {
38
38
  if (this._dataSource) {
39
- const r = {};
40
- return Object.keys(e).forEach((a) => {
41
- const o = e[a];
42
- r[a] = o.map(this.dataSource.saveCommentToSnapshot);
43
- }), r;
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
44
  }
45
45
  return e;
46
46
  }
47
47
  }
48
- const b = ve("univer.thread-comment.data-source-service");
49
- var Ne = Object.defineProperty, Ee = Object.getOwnPropertyDescriptor, Ie = (s, t, e, n) => {
50
- for (var r = n > 1 ? void 0 : n ? Ee(t, e) : t, a = s.length - 1, o; a >= 0; a--)
51
- (o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r);
52
- return n && r && Ne(t, e, r), r;
53
- }, se = (s, t) => (e, n) => t(e, n, s);
54
- let O = class extends ee {
48
+ const p = j("univer.thread-comment.data-source-service");
49
+ var Z = Object.defineProperty, F = Object.getOwnPropertyDescriptor, q = (s, t, e, n) => {
50
+ for (var o = n > 1 ? void 0 : n ? F(t, e) : t, r = s.length - 1, a; r >= 0; r--)
51
+ (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
52
+ return n && o && Z(t, e, o), o;
53
+ }, I = (s, t) => (e, n) => t(e, n, s);
54
+ let i = class extends U {
55
55
  constructor(t, e) {
56
56
  super();
57
- E(this, "_commentsMap", /* @__PURE__ */ new Map());
58
- E(this, "_threadMap", /* @__PURE__ */ new Map());
59
- E(this, "_commentUpdate$", new we());
60
- E(this, "commentUpdate$", this._commentUpdate$.asObservable());
61
- E(this, "_tasks", []);
57
+ u(this, "_commentsMap", /* @__PURE__ */ new Map());
58
+ u(this, "_threadMap", /* @__PURE__ */ new Map());
59
+ u(this, "_commentUpdate$", new K());
60
+ u(this, "commentUpdate$", this._commentUpdate$.asObservable());
61
+ u(this, "_tasks", []);
62
62
  this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
63
63
  this._commentUpdate$.complete();
64
64
  }), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
65
- const r = /* @__PURE__ */ new Map();
66
- n === ae.Rendered && (this._tasks.forEach(({ unitId: a, subUnitId: o, threadIds: M }) => {
67
- let u = r.get(a);
68
- u || (u = /* @__PURE__ */ new Map(), r.set(a, u));
69
- let p = u.get(o);
70
- p || (p = /* @__PURE__ */ new Set(), u.set(o, p));
71
- for (const S of M)
72
- p.add(S);
73
- }), this._tasks = [], r.forEach((a, o) => {
74
- a.forEach((M, u) => {
75
- this.syncThreadComments(o, u, Array.from(M));
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 h of d)
72
+ c.add(h);
73
+ }), this._tasks = [], o.forEach((r, a) => {
74
+ r.forEach((d, m) => {
75
+ this.syncThreadComments(a, m, Array.from(d));
76
76
  });
77
77
  }));
78
78
  }));
@@ -80,8 +80,8 @@ let O = class extends ee {
80
80
  _ensureCommentMap(t, e) {
81
81
  let n = this._commentsMap.get(t);
82
82
  n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
83
- let r = n.get(e);
84
- return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r;
83
+ let o = n.get(e);
84
+ return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
85
85
  }
86
86
  ensureMap(t, e) {
87
87
  return this._ensureCommentMap(t, e);
@@ -89,27 +89,27 @@ let O = class extends ee {
89
89
  _ensureThreadMap(t, e) {
90
90
  let n = this._threadMap.get(t);
91
91
  n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
92
- let r = n.get(e);
93
- return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r;
92
+ let o = n.get(e);
93
+ return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
94
94
  }
95
95
  _replaceComment(t, e, n) {
96
- const r = this._ensureCommentMap(t, e), a = r.get(n.id);
97
- if (a) {
98
- const { children: o, ...M } = n, u = {
99
- ...M,
100
- ref: a.ref
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
101
  };
102
- r.set(n.id, u), o == null || o.forEach((p) => {
103
- r.set(p.id, {
104
- ...p,
102
+ o.set(n.id, m), a == null || a.forEach((c) => {
103
+ o.set(c.id, {
104
+ ...c,
105
105
  ref: ""
106
106
  });
107
107
  }), this._commentUpdate$.next({
108
108
  unitId: t,
109
109
  subUnitId: e,
110
110
  type: "syncUpdate",
111
- payload: u
112
- }), !!n.resolved != !!a.resolved && this._commentUpdate$.next({
111
+ payload: m
112
+ }), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
113
113
  unitId: t,
114
114
  subUnitId: e,
115
115
  type: "resolve",
@@ -121,74 +121,76 @@ let O = class extends ee {
121
121
  }
122
122
  }
123
123
  async syncThreadComments(t, e, n) {
124
- if (this._lifecycleService.stage < ae.Rendered) {
124
+ if (this._lifecycleService.stage < O.Rendered) {
125
125
  this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
126
126
  return;
127
127
  }
128
- const r = this._ensureThreadMap(t, e), a = this._ensureCommentMap(t, e), o = await this._dataSourceService.listThreadComments(t, e, n);
129
- if (!o)
128
+ const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
129
+ if (!a)
130
130
  return;
131
- const M = new Set(n);
132
- o.forEach((u) => {
133
- this._replaceComment(t, e, u), M.delete(u.threadId);
134
- }), M.forEach((u) => {
135
- r.delete(u), a.forEach((p, S) => {
136
- p.threadId === u && a.delete(S);
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, h) => {
136
+ c.threadId === m && r.delete(h);
137
137
  });
138
138
  });
139
139
  }
140
- addComment(t, e, n, r) {
141
- const a = this._ensureCommentMap(t, e), { parentId: o, children: M = [], ...u } = n, p = {
142
- ...u,
143
- parentId: o === n.id ? void 0 : o
144
- }, S = (N) => {
145
- a.set(N.id, N), this._commentUpdate$.next({
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 h = (C) => {
147
+ r.set(C.id, C), this._commentUpdate$.next({
146
148
  unitId: t,
147
149
  subUnitId: e,
148
150
  type: "add",
149
- payload: N,
150
- isRoot: !N.parentId
151
+ payload: C,
152
+ isRoot: !C.parentId
151
153
  });
152
154
  };
153
- S(p);
154
- const $ = this._ensureThreadMap(t, e);
155
- if (!p.parentId) {
156
- $.set(p.threadId, p);
157
- for (const N of M)
158
- S(N);
155
+ h(c);
156
+ const _ = this._ensureThreadMap(t, e);
157
+ if (!c.parentId) {
158
+ _.set(c.threadId, c);
159
+ for (const C of d)
160
+ h(C);
159
161
  }
160
- return r && this.syncThreadComments(t, e, [p.threadId]), !0;
162
+ return o && this.syncThreadComments(t, e, [c.threadId]), !0;
161
163
  }
162
- updateComment(t, e, n, r) {
163
- const o = this._ensureCommentMap(t, e).get(n.commentId);
164
- return o && (o.updated = !0, o.text = n.text, o.attachments = n.attachments, o.updateT = n.updateT, this._commentUpdate$.next({
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({
165
167
  unitId: t,
166
168
  subUnitId: e,
167
169
  type: "update",
168
170
  payload: n,
169
- silent: r
171
+ silent: o
170
172
  })), !0;
171
173
  }
172
- updateCommentRef(t, e, n, r) {
173
- const o = this._ensureCommentMap(t, e).get(n.commentId);
174
- return o ? (o.ref = n.ref, this._commentUpdate$.next({
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({
175
177
  unitId: t,
176
178
  subUnitId: e,
177
179
  type: "updateRef",
178
180
  payload: n,
179
- silent: r,
180
- threadId: o.threadId
181
+ silent: o,
182
+ threadId: a.threadId
181
183
  }), !0) : !1;
182
184
  }
183
- resolveComment(t, e, n, r) {
184
- const o = this._ensureCommentMap(t, e).get(n);
185
- return o ? (o.resolved = r, this._commentUpdate$.next({
185
+ resolveComment(t, e, n, o) {
186
+ const a = this._ensureCommentMap(t, e).get(n);
187
+ return a ? (a.resolved = o, this._commentUpdate$.next({
186
188
  unitId: t,
187
189
  subUnitId: e,
188
190
  type: "resolve",
189
191
  payload: {
190
192
  commentId: n,
191
- resolved: r
193
+ resolved: o
192
194
  }
193
195
  }), !0) : !1;
194
196
  }
@@ -199,53 +201,53 @@ let O = class extends ee {
199
201
  return this._ensureThreadMap(t, e).get(n);
200
202
  }
201
203
  getThread(t, e, n) {
202
- const r = this._ensureCommentMap(t, e), a = Array.from(r.values()).filter((p) => p.threadId === n);
203
- let o;
204
- const M = [], u = /* @__PURE__ */ new Set();
205
- for (const p of a)
206
- p.parentId ? M.push(p) : o = p, u.add(p.personId);
207
- if (o)
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)
208
210
  return {
209
- root: o,
210
- children: M,
211
- relativeUsers: u,
211
+ root: a,
212
+ children: d,
213
+ relativeUsers: m,
212
214
  unitId: t,
213
215
  subUnitId: e,
214
216
  threadId: n
215
217
  };
216
218
  }
217
219
  getCommentWithChildren(t, e, n) {
218
- const r = this.getComment(t, e, n);
219
- if (r)
220
- return this.getThread(t, e, r.threadId);
220
+ const o = this.getComment(t, e, n);
221
+ if (o)
222
+ return this.getThread(t, e, o.threadId);
221
223
  }
222
224
  _deleteComment(t, e, n) {
223
- const r = this._ensureCommentMap(t, e), a = r.get(n);
224
- a && (r.delete(n), this._commentUpdate$.next({
225
+ const o = this._ensureCommentMap(t, e), r = o.get(n);
226
+ r && (o.delete(n), this._commentUpdate$.next({
225
227
  unitId: t,
226
228
  subUnitId: e,
227
229
  type: "delete",
228
230
  payload: {
229
231
  commentId: n,
230
- isRoot: !a.parentId,
231
- comment: a
232
+ isRoot: !r.parentId,
233
+ comment: r
232
234
  }
233
235
  }));
234
236
  }
235
237
  deleteThread(t, e, n) {
236
- this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((o) => {
237
- o.threadId === n && this._deleteComment(t, e, o.id);
238
+ this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
239
+ a.threadId === n && this._deleteComment(t, e, a.id);
238
240
  });
239
241
  }
240
242
  deleteComment(t, e, n) {
241
- const a = this._ensureCommentMap(t, e).get(n);
242
- return a && (a.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, a.threadId)), !0;
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;
243
245
  }
244
246
  deleteUnit(t) {
245
247
  const e = this._commentsMap.get(t);
246
- e && e.forEach((n, r) => {
247
- n.forEach((a) => {
248
- this.deleteComment(t, r, a.id);
248
+ e && e.forEach((n, o) => {
249
+ n.forEach((r) => {
250
+ this.deleteComment(t, o, r.id);
249
251
  });
250
252
  });
251
253
  }
@@ -254,10 +256,10 @@ let O = class extends ee {
254
256
  if (!e)
255
257
  return [];
256
258
  const n = [];
257
- return e.forEach((r, a) => {
258
- r.forEach((o, M) => {
259
- const u = this.getThread(t, a, M);
260
- u && n.push(u);
259
+ return e.forEach((o, r) => {
260
+ o.forEach((a, d) => {
261
+ const m = this.getThread(t, r, d);
262
+ m && n.push(m);
261
263
  });
262
264
  }), n;
263
265
  }
@@ -271,32 +273,32 @@ let O = class extends ee {
271
273
  }), t;
272
274
  }
273
275
  };
274
- O = Ie([
275
- se(0, Z(b)),
276
- se(1, Z(ge))
277
- ], O);
278
- var X = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(X || {});
279
- const ce = "UNIVER_THREAD_COMMENT_PLUGIN";
280
- var Re = Object.defineProperty, be = Object.getOwnPropertyDescriptor, xe = (s, t, e, n) => {
281
- for (var r = n > 1 ? void 0 : n ? be(t, e) : t, a = s.length - 1, o; a >= 0; a--)
282
- (o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r);
283
- return n && r && Re(t, e, r), r;
284
- }, q = (s, t) => (e, n) => t(e, n, s);
285
- let B = class extends ee {
276
+ i = q([
277
+ I(0, v(p)),
278
+ I(1, v(L))
279
+ ], i);
280
+ var T = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(T || {});
281
+ const D = "UNIVER_THREAD_COMMENT_PLUGIN";
282
+ var z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, X = (s, t, e, n) => {
283
+ for (var o = n > 1 ? void 0 : n ? Q(t, e) : t, r = s.length - 1, a; r >= 0; r--)
284
+ (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
285
+ return n && o && z(t, e, o), o;
286
+ }, S = (s, t) => (e, n) => t(e, n, s);
287
+ let g = class extends U {
286
288
  constructor(s, t, e) {
287
289
  super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
288
290
  }
289
291
  _initSnapshot() {
290
292
  const s = (e) => {
291
- const n = this._threadCommentModel.getUnit(e), r = {};
292
- return n ? (n.forEach((a) => {
293
- var M;
294
- const o = (M = r[a.subUnitId]) != null ? M : [];
295
- o.push({
296
- ...a.root,
297
- children: a.children
298
- }), r[a.unitId] = o;
299
- }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r, e))) : "";
293
+ const n = this._threadCommentModel.getUnit(e), o = {};
294
+ return n ? (n.forEach((r) => {
295
+ var d;
296
+ const a = (d = o[r.subUnitId]) != null ? d : [];
297
+ a.push({
298
+ ...r.root,
299
+ children: r.children
300
+ }), o[r.subUnitId] = a;
301
+ }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
300
302
  }, t = (e) => {
301
303
  if (!e)
302
304
  return {};
@@ -308,505 +310,223 @@ let B = class extends ee {
308
310
  };
309
311
  this.disposeWithMe(
310
312
  this._resourceManagerService.registerPluginResource({
311
- pluginName: `SHEET_${ce}`,
312
- businesses: [X.UNIVER_SHEET, X.UNIVER_DOC],
313
+ pluginName: `SHEET_${D}`,
314
+ businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
313
315
  toJson: (e) => s(e),
314
316
  parseJson: (e) => t(e),
315
317
  onUnLoad: (e) => {
316
318
  this._threadCommentModel.deleteUnit(e);
317
319
  },
318
320
  onLoad: async (e, n) => {
319
- Object.keys(n).forEach((r) => {
320
- const a = n[r];
321
- a.forEach((o) => {
322
- this._threadCommentModel.addComment(e, r, o);
323
- }), this._threadCommentModel.syncThreadComments(e, r, a.map((o) => o.threadId));
321
+ Object.keys(n).forEach((o) => {
322
+ const r = n[o];
323
+ r.forEach((a) => {
324
+ this._threadCommentModel.addComment(e, o, a);
325
+ }), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
324
326
  });
325
327
  }
326
328
  })
327
329
  );
328
330
  }
329
331
  };
330
- B = xe([
331
- q(0, ye),
332
- q(1, Z(O)),
333
- q(2, b)
334
- ], B);
335
- const me = {
332
+ g = X([
333
+ S(0, V),
334
+ S(1, v(i)),
335
+ S(2, p)
336
+ ], g);
337
+ const w = {
336
338
  id: "thread-comment.mutation.add-comment",
337
- type: I.MUTATION,
339
+ type: l.MUTATION,
338
340
  handler(s, t, e) {
339
341
  if (!t)
340
342
  return !1;
341
- const n = s.get(O), { unitId: r, subUnitId: a, comment: o, sync: M } = t, u = M || (e == null ? void 0 : e.fromChangeset) && !o.parentId;
342
- return n.addComment(r, a, o, u);
343
+ const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
344
+ return n.addComment(o, r, a, m);
343
345
  }
344
- }, de = {
346
+ }, P = {
345
347
  id: "thread-comment.mutation.update-comment",
346
- type: I.MUTATION,
348
+ type: l.MUTATION,
347
349
  handler(s, t) {
348
350
  if (!t)
349
351
  return !1;
350
- const e = s.get(O), { unitId: n, subUnitId: r, payload: a, silent: o } = t;
351
- return e.updateComment(n, r, a, o);
352
+ const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
353
+ return e.updateComment(n, o, r, a);
352
354
  }
353
- }, Pe = {
355
+ }, k = {
354
356
  id: "thread-comment.mutation.update-comment-ref",
355
- type: I.MUTATION,
357
+ type: l.MUTATION,
356
358
  handler(s, t) {
357
359
  if (!t)
358
360
  return !1;
359
- const e = s.get(O), { unitId: n, subUnitId: r, payload: a, silent: o } = t;
360
- return e.updateCommentRef(n, r, a, o);
361
+ const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
362
+ return e.updateCommentRef(n, o, r, a);
361
363
  }
362
- }, ue = {
364
+ }, $ = {
363
365
  id: "thread-comment.mutation.resolve-comment",
364
- type: I.MUTATION,
366
+ type: l.MUTATION,
365
367
  handler(s, t) {
366
368
  if (!t)
367
369
  return !1;
368
- const e = s.get(O), { unitId: n, subUnitId: r, resolved: a, commentId: o } = t;
369
- return e.resolveComment(n, r, o, a);
370
+ const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
371
+ return e.resolveComment(n, o, a, r);
370
372
  }
371
- }, te = {
373
+ }, N = {
372
374
  id: "thread-comment.mutation.delete-comment",
373
- type: I.MUTATION,
375
+ type: l.MUTATION,
374
376
  handler(s, t) {
375
377
  if (!t)
376
378
  return !1;
377
- const e = s.get(O), { unitId: n, subUnitId: r, commentId: a } = t;
378
- return e.deleteComment(n, r, a);
379
+ const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
380
+ return e.deleteComment(n, o, r);
379
381
  }
380
- }, je = {
382
+ }, ee = {
381
383
  id: "thread-comment.command.add-comment",
382
- type: I.COMMAND,
384
+ type: l.COMMAND,
383
385
  async handler(s, t) {
384
386
  if (!t)
385
387
  return !1;
386
- const e = s.get(H), n = s.get(b), { comment: r } = t, a = await n.addComment(r), o = n.syncUpdateMutationToColla, M = !r.parentId, u = {
387
- id: me.id,
388
+ const e = s.get(f), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
389
+ id: w.id,
388
390
  params: {
389
391
  ...t,
390
- comment: a
392
+ comment: r
391
393
  }
392
394
  };
393
- return M ? await e.executeCommand(u.id, u.params) : e.executeCommand(u.id, u.params, {
394
- onlyLocal: !o
395
+ return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
396
+ onlyLocal: !a
395
397
  });
396
398
  }
397
- }, Ae = {
399
+ }, te = {
398
400
  id: "thread-comment.command.update-comment",
399
- type: I.COMMAND,
401
+ type: l.COMMAND,
400
402
  async handler(s, t) {
401
403
  if (!t)
402
404
  return !1;
403
- const { unitId: e, subUnitId: n, payload: r } = t, a = s.get(H), o = s.get(O), M = s.get(b), u = M.syncUpdateMutationToColla, p = o.getComment(
405
+ const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(f), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
404
406
  e,
405
407
  n,
406
- r.commentId
408
+ o.commentId
407
409
  );
408
- if (!p)
410
+ if (!c)
409
411
  return !1;
410
- const { children: S, ...$ } = p;
411
- if (!await M.updateComment({
412
- ...$,
413
- ...r
412
+ const { children: h, ..._ } = c;
413
+ if (!await d.updateComment({
414
+ ..._,
415
+ ...o
414
416
  }))
415
417
  return !1;
416
- const U = {
417
- id: de.id,
418
+ const E = {
419
+ id: P.id,
418
420
  params: t
419
421
  };
420
- return a.executeCommand(U.id, U.params, { onlyLocal: !u }), !0;
422
+ return r.executeCommand(E.id, E.params, { onlyLocal: !m }), !0;
421
423
  }
422
- }, Le = {
424
+ }, ne = {
423
425
  id: "thread-comment.command.resolve-comment",
424
- type: I.COMMAND,
426
+ type: l.COMMAND,
425
427
  async handler(s, t) {
426
428
  if (!t)
427
429
  return !1;
428
- const { unitId: e, subUnitId: n, resolved: r, commentId: a } = t, o = s.get(b), u = s.get(O).getComment(e, n, a), p = o.syncUpdateMutationToColla;
429
- return !u || !await o.resolveComment({
430
- ...u,
431
- resolved: r
432
- }) ? !1 : s.get(H).executeCommand(
433
- ue.id,
430
+ 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;
431
+ return !m || !await a.resolveComment({
432
+ ...m,
433
+ resolved: o
434
+ }) ? !1 : s.get(f).executeCommand(
435
+ $.id,
434
436
  t,
435
- { onlyLocal: !p }
437
+ { onlyLocal: !c }
436
438
  );
437
439
  }
438
- }, He = {
440
+ }, oe = {
439
441
  id: "thread-comment.command.delete-comment",
440
- type: I.COMMAND,
442
+ type: l.COMMAND,
441
443
  async handler(s, t) {
442
444
  if (!t)
443
445
  return !1;
444
- const e = s.get(O), n = s.get(b), r = s.get(H), { unitId: a, subUnitId: o, commentId: M } = t, u = n.syncUpdateMutationToColla, p = e.getComment(a, o, M);
445
- if (!p || !await n.deleteComment(a, o, p.threadId, M))
446
+ const e = s.get(i), n = s.get(p), o = s.get(f), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
447
+ if (!c || !await n.deleteComment(r, a, c.threadId, d))
446
448
  return !1;
447
- const S = {
448
- id: te.id,
449
+ const h = {
450
+ id: N.id,
449
451
  params: t
450
452
  };
451
- return r.executeCommand(S.id, S.params, { onlyLocal: !u });
453
+ return o.executeCommand(h.id, h.params, { onlyLocal: !m });
452
454
  }
453
- }, We = {
455
+ }, re = {
454
456
  id: "thread-comment.command.delete-comment-tree",
455
- type: I.COMMAND,
457
+ type: l.COMMAND,
456
458
  async handler(s, t) {
457
459
  if (!t)
458
460
  return !1;
459
- const e = s.get(O), n = s.get(H), r = s.get(b), { unitId: a, subUnitId: o, commentId: M } = t, u = e.getCommentWithChildren(a, o, M);
460
- return !u || !await r.deleteComment(a, o, u.root.threadId, M) ? !1 : await n.executeCommand(te.id, {
461
- unitId: a,
462
- subUnitId: o,
463
- commentId: u.root.id
461
+ const e = s.get(i), n = s.get(f), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
462
+ return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? !1 : await n.executeCommand(N.id, {
463
+ unitId: r,
464
+ subUnitId: a,
465
+ commentId: m.root.id
464
466
  });
465
467
  }
466
- }, Ye = "thread-comment.config", Ve = {};
467
- var Je = Object.defineProperty, ke = Object.getOwnPropertyDescriptor, Ge = (s, t, e, n) => {
468
- for (var r = n > 1 ? void 0 : n ? ke(t, e) : t, a = s.length - 1, o; a >= 0; a--)
469
- (o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r);
470
- return n && r && Je(t, e, r), r;
471
- }, Q = (s, t) => (e, n) => t(e, n, s), F;
472
- let ie = (F = class extends Se {
473
- constructor(s = Ve, t, e, n) {
468
+ }, ae = "thread-comment.config", se = {};
469
+ var me = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, de = (s, t, e, n) => {
470
+ for (var o = n > 1 ? void 0 : n ? ce(t, e) : t, r = s.length - 1, a; r >= 0; r--)
471
+ (a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o);
472
+ return n && o && me(t, e, o), o;
473
+ }, y = (s, t) => (e, n) => t(e, n, s), M;
474
+ let R = (M = class extends W {
475
+ constructor(s = se, t, e, n) {
474
476
  super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
475
- const { ...r } = this._config;
476
- this._configService.setConfig(Ye, r);
477
+ const { ...o } = this._config;
478
+ this._configService.setConfig(ae, o);
477
479
  }
478
480
  onStarting() {
479
481
  var s;
480
- Te([
481
- [b, { useClass: Ue }],
482
- [O],
483
- [B]
482
+ H([
483
+ [p, { useClass: B }],
484
+ [i],
485
+ [g]
484
486
  ], (s = this._config) == null ? void 0 : s.overrides).forEach(
485
487
  (t) => {
486
488
  this._injector.add(t);
487
489
  }
488
490
  ), [
489
- je,
490
- Ae,
491
- He,
492
- Le,
493
- We,
494
- me,
495
- de,
496
- Pe,
491
+ ee,
497
492
  te,
498
- ue
493
+ oe,
494
+ ne,
495
+ re,
496
+ w,
497
+ P,
498
+ k,
499
+ N,
500
+ $
499
501
  ].forEach((t) => {
500
502
  this._commandService.registerCommand(t);
501
- }), this._injector.get(B);
502
- }
503
- }, E(F, "pluginName", ce), E(F, "type", $e.UNIVER_UNKNOWN), F);
504
- ie = Ge([
505
- Q(1, Z(De)),
506
- Q(2, H),
507
- Q(3, Oe)
508
- ], ie);
509
- var Fe = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
510
- function Ze(s) {
511
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
512
- }
513
- var he = { exports: {} };
514
- (function(s, t) {
515
- (function(e, n) {
516
- s.exports = n();
517
- })(Fe, function() {
518
- var e = 1e3, n = 6e4, r = 36e5, a = "millisecond", o = "second", M = "minute", u = "hour", p = "day", S = "week", $ = "month", N = "quarter", U = "year", A = "date", ne = "Invalid Date", le = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, fe = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, pe = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(h) {
519
- var m = ["th", "st", "nd", "rd"], i = h % 100;
520
- return "[" + h + (m[(i - 20) % 10] || m[i] || m[0]) + "]";
521
- } }, K = function(h, m, i) {
522
- var d = String(h);
523
- return !d || d.length >= m ? h : "" + Array(m + 1 - d.length).join(i) + h;
524
- }, Me = { s: K, z: function(h) {
525
- var m = -h.utcOffset(), i = Math.abs(m), d = Math.floor(i / 60), c = i % 60;
526
- return (m <= 0 ? "+" : "-") + K(d, 2, "0") + ":" + K(c, 2, "0");
527
- }, m: function h(m, i) {
528
- if (m.date() < i.date()) return -h(i, m);
529
- var d = 12 * (i.year() - m.year()) + (i.month() - m.month()), c = m.clone().add(d, $), l = i - c < 0, f = m.clone().add(d + (l ? -1 : 1), $);
530
- return +(-(d + (i - c) / (l ? c - f : f - c)) || 0);
531
- }, a: function(h) {
532
- return h < 0 ? Math.ceil(h) || 0 : Math.floor(h);
533
- }, p: function(h) {
534
- return { M: $, y: U, w: S, d: p, D: A, h: u, m: M, s: o, ms: a, Q: N }[h] || String(h || "").toLowerCase().replace(/s$/, "");
535
- }, u: function(h) {
536
- return h === void 0;
537
- } }, W = "en", x = {};
538
- x[W] = pe;
539
- var re = "$isDayjsObject", z = function(h) {
540
- return h instanceof k || !(!h || !h[re]);
541
- }, J = function h(m, i, d) {
542
- var c;
543
- if (!m) return W;
544
- if (typeof m == "string") {
545
- var l = m.toLowerCase();
546
- x[l] && (c = l), i && (x[l] = i, c = l);
547
- var f = m.split("-");
548
- if (!c && f.length > 1) return h(f[0]);
549
- } else {
550
- var _ = m.name;
551
- x[_] = m, c = _;
552
- }
553
- return !d && c && (W = c), c || !d && W;
554
- }, g = function(h, m) {
555
- if (z(h)) return h.clone();
556
- var i = typeof m == "object" ? m : {};
557
- return i.date = h, i.args = arguments, new k(i);
558
- }, C = Me;
559
- C.l = J, C.i = z, C.w = function(h, m) {
560
- return g(h, { locale: m.$L, utc: m.$u, x: m.$x, $offset: m.$offset });
561
- };
562
- var k = function() {
563
- function h(i) {
564
- this.$L = J(i.locale, null, !0), this.parse(i), this.$x = this.$x || i.x || {}, this[re] = !0;
565
- }
566
- var m = h.prototype;
567
- return m.parse = function(i) {
568
- this.$d = function(d) {
569
- var c = d.date, l = d.utc;
570
- if (c === null) return /* @__PURE__ */ new Date(NaN);
571
- if (C.u(c)) return /* @__PURE__ */ new Date();
572
- if (c instanceof Date) return new Date(c);
573
- if (typeof c == "string" && !/Z$/i.test(c)) {
574
- var f = c.match(le);
575
- if (f) {
576
- var _ = f[2] - 1 || 0, v = (f[7] || "0").substring(0, 3);
577
- return l ? new Date(Date.UTC(f[1], _, f[3] || 1, f[4] || 0, f[5] || 0, f[6] || 0, v)) : new Date(f[1], _, f[3] || 1, f[4] || 0, f[5] || 0, f[6] || 0, v);
578
- }
579
- }
580
- return new Date(c);
581
- }(i), this.init();
582
- }, m.init = function() {
583
- var i = this.$d;
584
- this.$y = i.getFullYear(), this.$M = i.getMonth(), this.$D = i.getDate(), this.$W = i.getDay(), this.$H = i.getHours(), this.$m = i.getMinutes(), this.$s = i.getSeconds(), this.$ms = i.getMilliseconds();
585
- }, m.$utils = function() {
586
- return C;
587
- }, m.isValid = function() {
588
- return this.$d.toString() !== ne;
589
- }, m.isSame = function(i, d) {
590
- var c = g(i);
591
- return this.startOf(d) <= c && c <= this.endOf(d);
592
- }, m.isAfter = function(i, d) {
593
- return g(i) < this.startOf(d);
594
- }, m.isBefore = function(i, d) {
595
- return this.endOf(d) < g(i);
596
- }, m.$g = function(i, d, c) {
597
- return C.u(i) ? this[d] : this.set(c, i);
598
- }, m.unix = function() {
599
- return Math.floor(this.valueOf() / 1e3);
600
- }, m.valueOf = function() {
601
- return this.$d.getTime();
602
- }, m.startOf = function(i, d) {
603
- var c = this, l = !!C.u(d) || d, f = C.p(i), _ = function(j, D) {
604
- var R = C.w(c.$u ? Date.UTC(c.$y, D, j) : new Date(c.$y, D, j), c);
605
- return l ? R : R.endOf(p);
606
- }, v = function(j, D) {
607
- return C.w(c.toDate()[j].apply(c.toDate("s"), (l ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(D)), c);
608
- }, y = this.$W, T = this.$M, w = this.$D, L = "set" + (this.$u ? "UTC" : "");
609
- switch (f) {
610
- case U:
611
- return l ? _(1, 0) : _(31, 11);
612
- case $:
613
- return l ? _(1, T) : _(0, T + 1);
614
- case S:
615
- var P = this.$locale().weekStart || 0, Y = (y < P ? y + 7 : y) - P;
616
- return _(l ? w - Y : w + (6 - Y), T);
617
- case p:
618
- case A:
619
- return v(L + "Hours", 0);
620
- case u:
621
- return v(L + "Minutes", 1);
622
- case M:
623
- return v(L + "Seconds", 2);
624
- case o:
625
- return v(L + "Milliseconds", 3);
626
- default:
627
- return this.clone();
628
- }
629
- }, m.endOf = function(i) {
630
- return this.startOf(i, !1);
631
- }, m.$set = function(i, d) {
632
- var c, l = C.p(i), f = "set" + (this.$u ? "UTC" : ""), _ = (c = {}, c[p] = f + "Date", c[A] = f + "Date", c[$] = f + "Month", c[U] = f + "FullYear", c[u] = f + "Hours", c[M] = f + "Minutes", c[o] = f + "Seconds", c[a] = f + "Milliseconds", c)[l], v = l === p ? this.$D + (d - this.$W) : d;
633
- if (l === $ || l === U) {
634
- var y = this.clone().set(A, 1);
635
- y.$d[_](v), y.init(), this.$d = y.set(A, Math.min(this.$D, y.daysInMonth())).$d;
636
- } else _ && this.$d[_](v);
637
- return this.init(), this;
638
- }, m.set = function(i, d) {
639
- return this.clone().$set(i, d);
640
- }, m.get = function(i) {
641
- return this[C.p(i)]();
642
- }, m.add = function(i, d) {
643
- var c, l = this;
644
- i = Number(i);
645
- var f = C.p(d), _ = function(T) {
646
- var w = g(l);
647
- return C.w(w.date(w.date() + Math.round(T * i)), l);
648
- };
649
- if (f === $) return this.set($, this.$M + i);
650
- if (f === U) return this.set(U, this.$y + i);
651
- if (f === p) return _(1);
652
- if (f === S) return _(7);
653
- var v = (c = {}, c[M] = n, c[u] = r, c[o] = e, c)[f] || 1, y = this.$d.getTime() + i * v;
654
- return C.w(y, this);
655
- }, m.subtract = function(i, d) {
656
- return this.add(-1 * i, d);
657
- }, m.format = function(i) {
658
- var d = this, c = this.$locale();
659
- if (!this.isValid()) return c.invalidDate || ne;
660
- var l = i || "YYYY-MM-DDTHH:mm:ssZ", f = C.z(this), _ = this.$H, v = this.$m, y = this.$M, T = c.weekdays, w = c.months, L = c.meridiem, P = function(D, R, V, G) {
661
- return D && (D[R] || D(d, l)) || V[R].slice(0, G);
662
- }, Y = function(D) {
663
- return C.s(_ % 12 || 12, D, "0");
664
- }, j = L || function(D, R, V) {
665
- var G = D < 12 ? "AM" : "PM";
666
- return V ? G.toLowerCase() : G;
667
- };
668
- return l.replace(fe, function(D, R) {
669
- return R || function(V) {
670
- switch (V) {
671
- case "YY":
672
- return String(d.$y).slice(-2);
673
- case "YYYY":
674
- return C.s(d.$y, 4, "0");
675
- case "M":
676
- return y + 1;
677
- case "MM":
678
- return C.s(y + 1, 2, "0");
679
- case "MMM":
680
- return P(c.monthsShort, y, w, 3);
681
- case "MMMM":
682
- return P(w, y);
683
- case "D":
684
- return d.$D;
685
- case "DD":
686
- return C.s(d.$D, 2, "0");
687
- case "d":
688
- return String(d.$W);
689
- case "dd":
690
- return P(c.weekdaysMin, d.$W, T, 2);
691
- case "ddd":
692
- return P(c.weekdaysShort, d.$W, T, 3);
693
- case "dddd":
694
- return T[d.$W];
695
- case "H":
696
- return String(_);
697
- case "HH":
698
- return C.s(_, 2, "0");
699
- case "h":
700
- return Y(1);
701
- case "hh":
702
- return Y(2);
703
- case "a":
704
- return j(_, v, !0);
705
- case "A":
706
- return j(_, v, !1);
707
- case "m":
708
- return String(v);
709
- case "mm":
710
- return C.s(v, 2, "0");
711
- case "s":
712
- return String(d.$s);
713
- case "ss":
714
- return C.s(d.$s, 2, "0");
715
- case "SSS":
716
- return C.s(d.$ms, 3, "0");
717
- case "Z":
718
- return f;
719
- }
720
- return null;
721
- }(D) || f.replace(":", "");
722
- });
723
- }, m.utcOffset = function() {
724
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
725
- }, m.diff = function(i, d, c) {
726
- var l, f = this, _ = C.p(d), v = g(i), y = (v.utcOffset() - this.utcOffset()) * n, T = this - v, w = function() {
727
- return C.m(f, v);
728
- };
729
- switch (_) {
730
- case U:
731
- l = w() / 12;
732
- break;
733
- case $:
734
- l = w();
735
- break;
736
- case N:
737
- l = w() / 3;
738
- break;
739
- case S:
740
- l = (T - y) / 6048e5;
741
- break;
742
- case p:
743
- l = (T - y) / 864e5;
744
- break;
745
- case u:
746
- l = T / r;
747
- break;
748
- case M:
749
- l = T / n;
750
- break;
751
- case o:
752
- l = T / e;
753
- break;
754
- default:
755
- l = T;
756
- }
757
- return c ? l : C.a(l);
758
- }, m.daysInMonth = function() {
759
- return this.endOf($).$D;
760
- }, m.$locale = function() {
761
- return x[this.$L];
762
- }, m.locale = function(i, d) {
763
- if (!i) return this.$L;
764
- var c = this.clone(), l = J(i, d, !0);
765
- return l && (c.$L = l), c;
766
- }, m.clone = function() {
767
- return C.w(this.$d, this);
768
- }, m.toDate = function() {
769
- return new Date(this.valueOf());
770
- }, m.toJSON = function() {
771
- return this.isValid() ? this.toISOString() : null;
772
- }, m.toISOString = function() {
773
- return this.$d.toISOString();
774
- }, m.toString = function() {
775
- return this.$d.toUTCString();
776
- }, h;
777
- }(), oe = k.prototype;
778
- return g.prototype = oe, [["$ms", a], ["$s", o], ["$m", M], ["$H", u], ["$W", p], ["$M", $], ["$y", U], ["$D", A]].forEach(function(h) {
779
- oe[h[1]] = function(m) {
780
- return this.$g(m, h[0], h[1]);
781
- };
782
- }), g.extend = function(h, m) {
783
- return h.$i || (h(m, k, g), h.$i = !0), g;
784
- }, g.locale = J, g.isDayjs = z, g.unix = function(h) {
785
- return g(1e3 * h);
786
- }, g.en = x[W], g.Ls = x, g.p = {}, g;
787
- });
788
- })(he);
789
- var Be = he.exports;
790
- const Ke = /* @__PURE__ */ Ze(Be);
791
- function Xe() {
792
- return Ke().format("YYYY/MM/DD HH:mm");
503
+ }), this._injector.get(g);
504
+ }
505
+ }, u(M, "pluginName", D), u(M, "type", J.UNIVER_UNKNOWN), M);
506
+ R = de([
507
+ y(1, v(G)),
508
+ y(2, f),
509
+ y(3, b)
510
+ ], R);
511
+ function le() {
512
+ return Y().format("YYYY/MM/DD HH:mm");
793
513
  }
794
514
  export {
795
- je as AddCommentCommand,
796
- me as AddCommentMutation,
797
- He as DeleteCommentCommand,
798
- te as DeleteCommentMutation,
799
- We as DeleteCommentTreeCommand,
800
- b as IThreadCommentDataSourceService,
801
- Le as ResolveCommentCommand,
802
- ue as ResolveCommentMutation,
803
- ce as TC_PLUGIN_NAME,
804
- Ue as ThreadCommentDataSourceService,
805
- O as ThreadCommentModel,
806
- B as ThreadCommentResourceController,
807
- ie as UniverThreadCommentPlugin,
808
- Ae as UpdateCommentCommand,
809
- de as UpdateCommentMutation,
810
- Pe as UpdateCommentRefMutation,
811
- Xe as getDT
515
+ ee as AddCommentCommand,
516
+ w as AddCommentMutation,
517
+ oe as DeleteCommentCommand,
518
+ N as DeleteCommentMutation,
519
+ re as DeleteCommentTreeCommand,
520
+ p as IThreadCommentDataSourceService,
521
+ ne as ResolveCommentCommand,
522
+ $ as ResolveCommentMutation,
523
+ D as TC_PLUGIN_NAME,
524
+ B as ThreadCommentDataSourceService,
525
+ i as ThreadCommentModel,
526
+ g as ThreadCommentResourceController,
527
+ R as UniverThreadCommentPlugin,
528
+ te as UpdateCommentCommand,
529
+ P as UpdateCommentMutation,
530
+ k as UpdateCommentRefMutation,
531
+ le as getDT
812
532
  };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.UniverThreadComment={},h.UniverCore,h.rxjs))})(this,function(h,l,A){"use strict";var Pe=Object.defineProperty;var Ae=(h,l,A)=>l in h?Pe(h,l,{enumerable:!0,configurable:!0,writable:!0,value:A}):h[l]=A;var I=(h,l,A)=>Ae(h,typeof l!="symbol"?l+"":l,A);var k;class re extends l.Disposable{constructor(){super();I(this,"_dataSource",null);I(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,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){const n={};return Object.keys(e).forEach(r=>{const a=e[r];n[r]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const E=l.createIdentifier("univer.thread-comment.data-source-service");var Ce=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,Me=(s,i,e,t)=>{for(var n=t>1?void 0:t?pe(i,e):i,r=s.length-1,a;r>=0;r--)(a=s[r])&&(n=(t?a(i,e,n):a(n))||n);return t&&n&&Ce(i,e,n),n},ae=(s,i)=>(e,t)=>i(e,t,s);h.ThreadCommentModel=class extends l.Disposable{constructor(e,t){super();I(this,"_commentsMap",new Map);I(this,"_threadMap",new Map);I(this,"_commentUpdate$",new A.Subject);I(this,"commentUpdate$",this._commentUpdate$.asObservable());I(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const r=new Map;n===l.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:d,threadIds:C})=>{let p=r.get(a);p||(p=new Map,r.set(a,p));let v=p.get(d);v||(v=new Set,p.set(d,v));for(const S of C)v.add(S)}),this._tasks=[],r.forEach((a,d)=>{a.forEach((C,p)=>{this.syncThreadComments(d,p,Array.from(C))})}))}))}_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){const r=this._ensureCommentMap(e,t),a=r.get(n.id);if(a){const{children:d,...C}=n,p={...C,ref:a.ref};r.set(n.id,p),d==null||d.forEach(v=>{r.set(v.id,{...v,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:p}),!!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<l.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const r=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const C=new Set(n);d.forEach(p=>{this._replaceComment(e,t,p),C.delete(p.threadId)}),C.forEach(p=>{r.delete(p),a.forEach((v,S)=>{v.threadId===p&&a.delete(S)})})}addComment(e,t,n,r){const a=this._ensureCommentMap(e,t),{parentId:d,children:C=[],...p}=n,v={...p,parentId:d===n.id?void 0:d},S=$=>{a.set($.id,$),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:$,isRoot:!$.parentId})};S(v);const W=this._ensureThreadMap(e,t);if(!v.parentId){W.set(v.threadId,v);for(const $ of C)S($)}return r&&this.syncThreadComments(e,t,[v.threadId]),!0}updateComment(e,t,n,r){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:r})),!0}updateCommentRef(e,t,n,r){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:r,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,r){const d=this._ensureCommentMap(e,t).get(n);return d?(d.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){const r=this._ensureCommentMap(e,t),a=Array.from(r.values()).filter(v=>v.threadId===n);let d;const C=[],p=new Set;for(const v of a)v.parentId?C.push(v):d=v,p.add(v.personId);if(d)return{root:d,children:C,relativeUsers:p,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){const r=this._ensureCommentMap(e,t),a=r.get(n);a&&(r.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,r)=>{n.forEach(a=>{this.deleteComment(e,r,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((r,a)=>{r.forEach((d,C)=>{const p=this.getThread(e,a,C);p&&n.push(p)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},h.ThreadCommentModel=Me([ae(0,l.Inject(E)),ae(1,l.Inject(l.LifecycleService))],h.ThreadCommentModel);var K=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(K||{});const q="UNIVER_THREAD_COMMENT_PLUGIN";var _e=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,ye=(s,i,e,t)=>{for(var n=t>1?void 0:t?ve(i,e):i,r=s.length-1,a;r>=0;r--)(a=s[r])&&(n=(t?a(i,e,n):a(n))||n);return t&&n&&_e(i,e,n),n},z=(s,i)=>(e,t)=>i(e,t,s);h.ThreadCommentResourceController=class extends l.Disposable{constructor(i,e,t){super(),this._resourceManagerService=i,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const i=t=>{const n=this._threadCommentModel.getUnit(t),r={};return n?(n.forEach(a=>{var C;const d=(C=r[a.subUnitId])!=null?C:[];d.push({...a.root,children:a.children}),r[a.unitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${q}`,businesses:[K.UNIVER_SHEET,K.UNIVER_DOC],toJson:t=>i(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(r=>{const a=n[r];a.forEach(d=>{this._threadCommentModel.addComment(t,r,d)}),this._threadCommentModel.syncThreadComments(t,r,a.map(d=>d.threadId))})}}))}},h.ThreadCommentResourceController=ye([z(0,l.IResourceManagerService),z(1,l.Inject(h.ThreadCommentModel)),z(2,E)],h.ThreadCommentResourceController);const Q={id:"thread-comment.mutation.add-comment",type:l.CommandType.MUTATION,handler(s,i,e){if(!i)return!1;const t=s.get(h.ThreadCommentModel),{unitId:n,subUnitId:r,comment:a,sync:d}=i,C=d||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,r,a,C)}},X={id:"thread-comment.mutation.update-comment",type:l.CommandType.MUTATION,handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),{unitId:t,subUnitId:n,payload:r,silent:a}=i;return e.updateComment(t,n,r,a)}},oe={id:"thread-comment.mutation.update-comment-ref",type:l.CommandType.MUTATION,handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),{unitId:t,subUnitId:n,payload:r,silent:a}=i;return e.updateCommentRef(t,n,r,a)}},x={id:"thread-comment.mutation.resolve-comment",type:l.CommandType.MUTATION,handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:r,commentId:a}=i;return e.resolveComment(t,n,a,r)}},G={id:"thread-comment.mutation.delete-comment",type:l.CommandType.MUTATION,handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:r}=i;return e.deleteComment(t,n,r)}},se={id:"thread-comment.command.add-comment",type:l.CommandType.COMMAND,async handler(s,i){if(!i)return!1;const e=s.get(l.ICommandService),t=s.get(E),{comment:n}=i,r=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,C={id:Q.id,params:{...i,comment:r}};return d?await e.executeCommand(C.id,C.params):e.executeCommand(C.id,C.params,{onlyLocal:!a})}},ie={id:"thread-comment.command.update-comment",type:l.CommandType.COMMAND,async handler(s,i){if(!i)return!1;const{unitId:e,subUnitId:t,payload:n}=i,r=s.get(l.ICommandService),a=s.get(h.ThreadCommentModel),d=s.get(E),C=d.syncUpdateMutationToColla,p=a.getComment(e,t,n.commentId);if(!p)return!1;const{children:v,...S}=p;if(!await d.updateComment({...S,...n}))return!1;const $={id:X.id,params:i};return r.executeCommand($.id,$.params,{onlyLocal:!C}),!0}},me={id:"thread-comment.command.resolve-comment",type:l.CommandType.COMMAND,async handler(s,i){if(!i)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:r}=i,a=s.get(E),C=s.get(h.ThreadCommentModel).getComment(e,t,r),p=a.syncUpdateMutationToColla;return!C||!await a.resolveComment({...C,resolved:n})?!1:s.get(l.ICommandService).executeCommand(x.id,i,{onlyLocal:!p})}},ce={id:"thread-comment.command.delete-comment",type:l.CommandType.COMMAND,async handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),t=s.get(E),n=s.get(l.ICommandService),{unitId:r,subUnitId:a,commentId:d}=i,C=t.syncUpdateMutationToColla,p=e.getComment(r,a,d);if(!p||!await t.deleteComment(r,a,p.threadId,d))return!1;const v={id:G.id,params:i};return n.executeCommand(v.id,v.params,{onlyLocal:!C})}},de={id:"thread-comment.command.delete-comment-tree",type:l.CommandType.COMMAND,async handler(s,i){if(!i)return!1;const e=s.get(h.ThreadCommentModel),t=s.get(l.ICommandService),n=s.get(E),{unitId:r,subUnitId:a,commentId:d}=i,C=e.getCommentWithChildren(r,a,d);return!C||!await n.deleteComment(r,a,C.root.threadId,d)?!1:await t.executeCommand(G.id,{unitId:r,subUnitId:a,commentId:C.root.id})}},ge="thread-comment.config",Se={};var Te=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,De=(s,i,e,t)=>{for(var n=t>1?void 0:t?$e(i,e):i,r=s.length-1,a;r>=0;r--)(a=s[r])&&(n=(t?a(i,e,n):a(n))||n);return t&&n&&Te(i,e,n),n},ee=(s,i)=>(e,t)=>i(e,t,s);h.UniverThreadCommentPlugin=(k=class extends l.Plugin{constructor(i=Se,e,t,n){super(),this._config=i,this._injector=e,this._commandService=t,this._configService=n;const{...r}=this._config;this._configService.setConfig(ge,r)}onStarting(){var i;l.mergeOverrideWithDependencies([[E,{useClass:re}],[h.ThreadCommentModel],[h.ThreadCommentResourceController]],(i=this._config)==null?void 0:i.overrides).forEach(e=>{this._injector.add(e)}),[se,ie,ce,me,de,Q,X,oe,G,x].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(h.ThreadCommentResourceController)}},I(k,"pluginName",q),I(k,"type",l.UniverInstanceType.UNIVER_UNKNOWN),k),h.UniverThreadCommentPlugin=De([ee(1,l.Inject(l.Injector)),ee(2,l.ICommandService),ee(3,l.IConfigService)],h.UniverThreadCommentPlugin);var Oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ue(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var ue={exports:{}};(function(s,i){(function(e,t){s.exports=t()})(Oe,function(){var e=1e3,t=6e4,n=36e5,r="millisecond",a="second",d="minute",C="hour",p="day",v="week",S="month",W="quarter",$="year",L="date",he="Invalid Date",Ee=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,Re=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,je={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(f){var c=["th","st","nd","rd"],o=f%100;return"["+f+(c[(o-20)%10]||c[o]||c[0])+"]"}},te=function(f,c,o){var u=String(f);return!u||u.length>=c?f:""+Array(c+1-u.length).join(o)+f},be={s:te,z:function(f){var c=-f.utcOffset(),o=Math.abs(c),u=Math.floor(o/60),m=o%60;return(c<=0?"+":"-")+te(u,2,"0")+":"+te(m,2,"0")},m:function f(c,o){if(c.date()<o.date())return-f(o,c);var u=12*(o.year()-c.year())+(o.month()-c.month()),m=c.clone().add(u,S),M=o-m<0,_=c.clone().add(u+(M?-1:1),S);return+(-(u+(o-m)/(M?m-_:_-m))||0)},a:function(f){return f<0?Math.ceil(f)||0:Math.floor(f)},p:function(f){return{M:S,y:$,w:v,d:p,D:L,h:C,m:d,s:a,ms:r,Q:W}[f]||String(f||"").toLowerCase().replace(/s$/,"")},u:function(f){return f===void 0}},Y="en",j={};j[Y]=je;var le="$isDayjsObject",ne=function(f){return f instanceof Z||!(!f||!f[le])},F=function f(c,o,u){var m;if(!c)return Y;if(typeof c=="string"){var M=c.toLowerCase();j[M]&&(m=M),o&&(j[M]=o,m=M);var _=c.split("-");if(!m&&_.length>1)return f(_[0])}else{var g=c.name;j[g]=c,m=g}return!u&&m&&(Y=m),m||!u&&Y},D=function(f,c){if(ne(f))return f.clone();var o=typeof c=="object"?c:{};return o.date=f,o.args=arguments,new Z(o)},y=be;y.l=F,y.i=ne,y.w=function(f,c){return D(f,{locale:c.$L,utc:c.$u,x:c.$x,$offset:c.$offset})};var Z=function(){function f(o){this.$L=F(o.locale,null,!0),this.parse(o),this.$x=this.$x||o.x||{},this[le]=!0}var c=f.prototype;return c.parse=function(o){this.$d=function(u){var m=u.date,M=u.utc;if(m===null)return new Date(NaN);if(y.u(m))return new Date;if(m instanceof Date)return new Date(m);if(typeof m=="string"&&!/Z$/i.test(m)){var _=m.match(Ee);if(_){var g=_[2]-1||0,T=(_[7]||"0").substring(0,3);return M?new Date(Date.UTC(_[1],g,_[3]||1,_[4]||0,_[5]||0,_[6]||0,T)):new Date(_[1],g,_[3]||1,_[4]||0,_[5]||0,_[6]||0,T)}}return new Date(m)}(o),this.init()},c.init=function(){var o=this.$d;this.$y=o.getFullYear(),this.$M=o.getMonth(),this.$D=o.getDate(),this.$W=o.getDay(),this.$H=o.getHours(),this.$m=o.getMinutes(),this.$s=o.getSeconds(),this.$ms=o.getMilliseconds()},c.$utils=function(){return y},c.isValid=function(){return this.$d.toString()!==he},c.isSame=function(o,u){var m=D(o);return this.startOf(u)<=m&&m<=this.endOf(u)},c.isAfter=function(o,u){return D(o)<this.startOf(u)},c.isBefore=function(o,u){return this.endOf(u)<D(o)},c.$g=function(o,u,m){return y.u(o)?this[u]:this.set(m,o)},c.unix=function(){return Math.floor(this.valueOf()/1e3)},c.valueOf=function(){return this.$d.getTime()},c.startOf=function(o,u){var m=this,M=!!y.u(u)||u,_=y.p(o),g=function(P,w){var R=y.w(m.$u?Date.UTC(m.$y,w,P):new Date(m.$y,w,P),m);return M?R:R.endOf(p)},T=function(P,w){return y.w(m.toDate()[P].apply(m.toDate("s"),(M?[0,0,0,0]:[23,59,59,999]).slice(w)),m)},O=this.$W,U=this.$M,N=this.$D,H="set"+(this.$u?"UTC":"");switch(_){case $:return M?g(1,0):g(31,11);case S:return M?g(1,U):g(0,U+1);case v:var b=this.$locale().weekStart||0,V=(O<b?O+7:O)-b;return g(M?N-V:N+(6-V),U);case p:case L:return T(H+"Hours",0);case C:return T(H+"Minutes",1);case d:return T(H+"Seconds",2);case a:return T(H+"Milliseconds",3);default:return this.clone()}},c.endOf=function(o){return this.startOf(o,!1)},c.$set=function(o,u){var m,M=y.p(o),_="set"+(this.$u?"UTC":""),g=(m={},m[p]=_+"Date",m[L]=_+"Date",m[S]=_+"Month",m[$]=_+"FullYear",m[C]=_+"Hours",m[d]=_+"Minutes",m[a]=_+"Seconds",m[r]=_+"Milliseconds",m)[M],T=M===p?this.$D+(u-this.$W):u;if(M===S||M===$){var O=this.clone().set(L,1);O.$d[g](T),O.init(),this.$d=O.set(L,Math.min(this.$D,O.daysInMonth())).$d}else g&&this.$d[g](T);return this.init(),this},c.set=function(o,u){return this.clone().$set(o,u)},c.get=function(o){return this[y.p(o)]()},c.add=function(o,u){var m,M=this;o=Number(o);var _=y.p(u),g=function(U){var N=D(M);return y.w(N.date(N.date()+Math.round(U*o)),M)};if(_===S)return this.set(S,this.$M+o);if(_===$)return this.set($,this.$y+o);if(_===p)return g(1);if(_===v)return g(7);var T=(m={},m[d]=t,m[C]=n,m[a]=e,m)[_]||1,O=this.$d.getTime()+o*T;return y.w(O,this)},c.subtract=function(o,u){return this.add(-1*o,u)},c.format=function(o){var u=this,m=this.$locale();if(!this.isValid())return m.invalidDate||he;var M=o||"YYYY-MM-DDTHH:mm:ssZ",_=y.z(this),g=this.$H,T=this.$m,O=this.$M,U=m.weekdays,N=m.months,H=m.meridiem,b=function(w,R,J,B){return w&&(w[R]||w(u,M))||J[R].slice(0,B)},V=function(w){return y.s(g%12||12,w,"0")},P=H||function(w,R,J){var B=w<12?"AM":"PM";return J?B.toLowerCase():B};return M.replace(Re,function(w,R){return R||function(J){switch(J){case"YY":return String(u.$y).slice(-2);case"YYYY":return y.s(u.$y,4,"0");case"M":return O+1;case"MM":return y.s(O+1,2,"0");case"MMM":return b(m.monthsShort,O,N,3);case"MMMM":return b(N,O);case"D":return u.$D;case"DD":return y.s(u.$D,2,"0");case"d":return String(u.$W);case"dd":return b(m.weekdaysMin,u.$W,U,2);case"ddd":return b(m.weekdaysShort,u.$W,U,3);case"dddd":return U[u.$W];case"H":return String(g);case"HH":return y.s(g,2,"0");case"h":return V(1);case"hh":return V(2);case"a":return P(g,T,!0);case"A":return P(g,T,!1);case"m":return String(T);case"mm":return y.s(T,2,"0");case"s":return String(u.$s);case"ss":return y.s(u.$s,2,"0");case"SSS":return y.s(u.$ms,3,"0");case"Z":return _}return null}(w)||_.replace(":","")})},c.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},c.diff=function(o,u,m){var M,_=this,g=y.p(u),T=D(o),O=(T.utcOffset()-this.utcOffset())*t,U=this-T,N=function(){return y.m(_,T)};switch(g){case $:M=N()/12;break;case S:M=N();break;case W:M=N()/3;break;case v:M=(U-O)/6048e5;break;case p:M=(U-O)/864e5;break;case C:M=U/n;break;case d:M=U/t;break;case a:M=U/e;break;default:M=U}return m?M:y.a(M)},c.daysInMonth=function(){return this.endOf(S).$D},c.$locale=function(){return j[this.$L]},c.locale=function(o,u){if(!o)return this.$L;var m=this.clone(),M=F(o,u,!0);return M&&(m.$L=M),m},c.clone=function(){return y.w(this.$d,this)},c.toDate=function(){return new Date(this.valueOf())},c.toJSON=function(){return this.isValid()?this.toISOString():null},c.toISOString=function(){return this.$d.toISOString()},c.toString=function(){return this.$d.toUTCString()},f}(),fe=Z.prototype;return D.prototype=fe,[["$ms",r],["$s",a],["$m",d],["$H",C],["$W",p],["$M",S],["$y",$],["$D",L]].forEach(function(f){fe[f[1]]=function(c){return this.$g(c,f[0],f[1])}}),D.extend=function(f,c){return f.$i||(f(c,Z,D),f.$i=!0),D},D.locale=F,D.isDayjs=ne,D.unix=function(f){return D(1e3*f)},D.en=j[Y],D.Ls=j,D.p={},D})})(ue);var we=ue.exports;const Ne=Ue(we);function Ie(){return Ne().format("YYYY/MM/DD HH:mm")}h.AddCommentCommand=se,h.AddCommentMutation=Q,h.DeleteCommentCommand=ce,h.DeleteCommentMutation=G,h.DeleteCommentTreeCommand=de,h.IThreadCommentDataSourceService=E,h.ResolveCommentCommand=me,h.ResolveCommentMutation=x,h.TC_PLUGIN_NAME=q,h.ThreadCommentDataSourceService=re,h.UpdateCommentCommand=ie,h.UpdateCommentMutation=X,h.UpdateCommentRefMutation=oe,h.getDT=Ie,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,function(s,c,M){"use strict";var F=Object.defineProperty;var z=(s,c,M)=>c in s?F(s,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[c]=M;var u=(s,c,M)=>z(s,typeof c!="symbol"?c+"":c,M);var v;class E extends c.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=c.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(r,m,e,t)=>{for(var n=t>1?void 0:t?V(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&L(m,e,n),n},R=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentModel=class extends c.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===c.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:d,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(d);l||(l=new Set,h.set(d,l));for(const f of i)l.add(f)}),this._tasks=[],o.forEach((a,d)=>{a.forEach((i,h)=>{this.syncThreadComments(d,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:d,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),d==null||d.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<c.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),d=await this._dataSourceService.listThreadComments(e,t,n);if(!d)return;const i=new Set(n);d.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,f)=>{l.threadId===h&&a.delete(f)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:d,children:i=[],...h}=n,l={...h,parentId:d===n.id?void 0:d};l.threadId||(l.threadId=l.parentId||l.id);const f=p=>{a.set(p.id,p),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})};f(l);const A=this._ensureThreadMap(e,t);if(!l.parentId){A.set(l.threadId,l);for(const p of i)f(p)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d&&(d.updated=!0,d.text=n.text,d.attachments=n.attachments,d.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n.commentId);return d?(d.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:d.threadId}),!0):!1}resolveComment(e,t,n,o){const d=this._ensureCommentMap(e,t).get(n);return d?(d.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let d;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):d=l,h.add(l.personId);if(d)return{root:d,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(d=>{d.threadId===n&&this._deleteComment(e,t,d.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((d,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},s.ThreadCommentModel=W([R(0,c.Inject(C)),R(1,c.Inject(c.LifecycleService))],s.ThreadCommentModel);var T=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(T||{});const S="UNIVER_THREAD_COMMENT_PLUGIN";var b=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(r,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&b(m,e,n),n},g=(r,m)=>(e,t)=>m(e,t,r);s.ThreadCommentResourceController=class extends c.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const d=(i=o[a.subUnitId])!=null?i:[];d.push({...a.root,children:a.children}),o[a.subUnitId]=d}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${S}`,businesses:[T.UNIVER_SHEET,T.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(d=>{this._threadCommentModel.addComment(t,o,d)}),this._threadCommentModel.syncThreadComments(t,o,a.map(d=>d.threadId))})}}))}},s.ThreadCommentResourceController=G([g(0,c.IResourceManagerService),g(1,c.Inject(s.ThreadCommentModel)),g(2,C)],s.ThreadCommentResourceController);const y={id:"thread-comment.mutation.add-comment",type:c.CommandType.MUTATION,handler(r,m,e){if(!m)return!1;const t=r.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:d}=m,i=d||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},U={id:"thread-comment.mutation.update-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},O={id:"thread-comment.mutation.update-comment-ref",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},N={id:"thread-comment.mutation.resolve-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:c.CommandType.MUTATION,handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},D={id:"thread-comment.command.add-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(c.ICommandService),t=r.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,d=!n.parentId,i={id:y.id,params:{...m,comment:o}};return d?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},P={id:"thread-comment.command.update-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=r.get(c.ICommandService),a=r.get(s.ThreadCommentModel),d=r.get(C),i=d.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...f}=h;if(!await d.updateComment({...f,...n}))return!1;const p={id:U.id,params:m};return o.executeCommand(p.id,p.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=r.get(C),i=r.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:r.get(c.ICommandService).executeCommand(N.id,m,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(C),n=r.get(c.ICommandService),{unitId:o,subUnitId:a,commentId:d}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,d);if(!h||!await t.deleteComment(o,a,h.threadId,d))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},$={id:"thread-comment.command.delete-comment-tree",type:c.CommandType.COMMAND,async handler(r,m){if(!m)return!1;const e=r.get(s.ThreadCommentModel),t=r.get(c.ICommandService),n=r.get(C),{unitId:o,subUnitId:a,commentId:d}=m,i=e.getCommentWithChildren(o,a,d);return!i||!await n.deleteComment(o,a,i.root.threadId,d)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}},H="thread-comment.config",Y={};var K=Object.defineProperty,B=Object.getOwnPropertyDescriptor,q=(r,m,e,t)=>{for(var n=t>1?void 0:t?B(m,e):m,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(t?a(m,e,n):a(n))||n);return t&&n&&K(m,e,n),n},I=(r,m)=>(e,t)=>m(e,t,r);s.UniverThreadCommentPlugin=(v=class extends c.Plugin{constructor(m=Y,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=this._config;this._configService.setConfig(H,o)}onStarting(){var m;c.mergeOverrideWithDependencies([[C,{useClass:E}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[D,P,j,w,$,y,U,O,_,N].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(v,"pluginName",S),u(v,"type",c.UniverInstanceType.UNIVER_UNKNOWN),v),s.UniverThreadCommentPlugin=q([I(1,c.Inject(c.Injector)),I(2,c.ICommandService),I(3,c.IConfigService)],s.UniverThreadCommentPlugin);function Z(){return c.dayjs().format("YYYY/MM/DD HH:mm")}s.AddCommentCommand=D,s.AddCommentMutation=y,s.DeleteCommentCommand=j,s.DeleteCommentMutation=_,s.DeleteCommentTreeCommand=$,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=N,s.TC_PLUGIN_NAME=S,s.ThreadCommentDataSourceService=E,s.UpdateCommentCommand=P,s.UpdateCommentMutation=U,s.UpdateCommentRefMutation=O,s.getDT=Z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/thread-comment",
3
- "version": "0.5.0-alpha.0",
3
+ "version": "0.5.0-beta.0",
4
4
  "private": false,
5
5
  "description": "Univer thread comment core plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -46,16 +46,15 @@
46
46
  "rxjs": ">=7.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@univerjs/protocol": "0.1.39-alpha.38",
50
- "dayjs": "^1.11.13",
51
- "@univerjs/core": "0.5.0-alpha.0"
49
+ "@univerjs/protocol": "0.1.39-alpha.45",
50
+ "@univerjs/core": "0.5.0-beta.0"
52
51
  },
53
52
  "devDependencies": {
54
53
  "rxjs": "^7.8.1",
55
54
  "typescript": "^5.6.3",
56
- "vite": "^5.4.10",
57
- "vitest": "^2.1.4",
58
- "@univerjs-infra/shared": "0.5.0-alpha.0"
55
+ "vite": "^5.4.11",
56
+ "vitest": "^2.1.5",
57
+ "@univerjs-infra/shared": "0.5.0-beta.0"
59
58
  },
60
59
  "space": {
61
60
  ".": {
@@ -75,7 +74,7 @@
75
74
  "test:watch": "vitest",
76
75
  "coverage": "vitest run --coverage",
77
76
  "lint:types": "tsc --noEmit",
78
- "build": "tsx build.ts"
77
+ "build": "univer-cli build"
79
78
  },
80
79
  "module": "./lib/es/index.js"
81
80
  }