@univerjs/thread-comment
Advanced tools
Comparing version 0.5.0-alpha.0 to 0.5.0-beta.0
@@ -1,1 +0,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; | ||
"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; |
@@ -1,11 +0,11 @@ | ||
var Ce = Object.defineProperty; | ||
var _e = (s, t, e) => t in s ? Ce(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var E = (s, t, e) => _e(s, typeof t != "symbol" ? t + "" : t, e); | ||
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"; | ||
import { Subject as we } from "rxjs"; | ||
class Ue extends ee { | ||
var x = Object.defineProperty; | ||
var A = (s, t, e) => t in s ? x(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var u = (s, t, e) => A(s, typeof t != "symbol" ? t + "" : t, e); | ||
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"; | ||
import { Subject as K } from "rxjs"; | ||
class B extends U { | ||
constructor() { | ||
super(); | ||
E(this, "_dataSource", null); | ||
E(this, "syncUpdateMutationToColla", !0); | ||
u(this, "_dataSource", null); | ||
u(this, "syncUpdateMutationToColla", !0); | ||
} | ||
@@ -18,4 +18,4 @@ set dataSource(e) { | ||
} | ||
async getThreadComment(e, n, r) { | ||
return this._dataSource ? (await this._dataSource.listComments(e, n, [r]))[0] : null; | ||
async getThreadComment(e, n, o) { | ||
return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null; | ||
} | ||
@@ -32,15 +32,15 @@ async addComment(e) { | ||
} | ||
async deleteComment(e, n, r, a) { | ||
return this._dataSource ? this._dataSource.deleteComment(e, n, r, a) : !0; | ||
async deleteComment(e, n, o, r) { | ||
return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : !0; | ||
} | ||
async listThreadComments(e, n, r) { | ||
return this.dataSource ? this.dataSource.listComments(e, n, r) : !1; | ||
async listThreadComments(e, n, o) { | ||
return this.dataSource ? this.dataSource.listComments(e, n, o) : !1; | ||
} | ||
saveToSnapshot(e, n) { | ||
if (this._dataSource) { | ||
const r = {}; | ||
return Object.keys(e).forEach((a) => { | ||
const o = e[a]; | ||
r[a] = o.map(this.dataSource.saveCommentToSnapshot); | ||
}), r; | ||
const o = {}; | ||
return Object.keys(e).forEach((r) => { | ||
const a = e[r]; | ||
o[r] = a.map(this.dataSource.saveCommentToSnapshot); | ||
}), o; | ||
} | ||
@@ -50,30 +50,30 @@ return e; | ||
} | ||
const b = ve("univer.thread-comment.data-source-service"); | ||
var Ne = Object.defineProperty, Ee = Object.getOwnPropertyDescriptor, Ie = (s, t, e, n) => { | ||
for (var r = n > 1 ? void 0 : n ? Ee(t, e) : t, a = s.length - 1, o; a >= 0; a--) | ||
(o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r); | ||
return n && r && Ne(t, e, r), r; | ||
}, se = (s, t) => (e, n) => t(e, n, s); | ||
let O = class extends ee { | ||
const p = j("univer.thread-comment.data-source-service"); | ||
var Z = Object.defineProperty, F = Object.getOwnPropertyDescriptor, q = (s, t, e, n) => { | ||
for (var o = n > 1 ? void 0 : n ? F(t, e) : t, r = s.length - 1, a; r >= 0; r--) | ||
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o); | ||
return n && o && Z(t, e, o), o; | ||
}, I = (s, t) => (e, n) => t(e, n, s); | ||
let i = class extends U { | ||
constructor(t, e) { | ||
super(); | ||
E(this, "_commentsMap", /* @__PURE__ */ new Map()); | ||
E(this, "_threadMap", /* @__PURE__ */ new Map()); | ||
E(this, "_commentUpdate$", new we()); | ||
E(this, "commentUpdate$", this._commentUpdate$.asObservable()); | ||
E(this, "_tasks", []); | ||
u(this, "_commentsMap", /* @__PURE__ */ new Map()); | ||
u(this, "_threadMap", /* @__PURE__ */ new Map()); | ||
u(this, "_commentUpdate$", new K()); | ||
u(this, "commentUpdate$", this._commentUpdate$.asObservable()); | ||
u(this, "_tasks", []); | ||
this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => { | ||
this._commentUpdate$.complete(); | ||
}), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => { | ||
const r = /* @__PURE__ */ new Map(); | ||
n === ae.Rendered && (this._tasks.forEach(({ unitId: a, subUnitId: o, threadIds: M }) => { | ||
let u = r.get(a); | ||
u || (u = /* @__PURE__ */ new Map(), r.set(a, u)); | ||
let p = u.get(o); | ||
p || (p = /* @__PURE__ */ new Set(), u.set(o, p)); | ||
for (const S of M) | ||
p.add(S); | ||
}), this._tasks = [], r.forEach((a, o) => { | ||
a.forEach((M, u) => { | ||
this.syncThreadComments(o, u, Array.from(M)); | ||
const o = /* @__PURE__ */ new Map(); | ||
n === O.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => { | ||
let m = o.get(r); | ||
m || (m = /* @__PURE__ */ new Map(), o.set(r, m)); | ||
let c = m.get(a); | ||
c || (c = /* @__PURE__ */ new Set(), m.set(a, c)); | ||
for (const h of d) | ||
c.add(h); | ||
}), this._tasks = [], o.forEach((r, a) => { | ||
r.forEach((d, m) => { | ||
this.syncThreadComments(a, m, Array.from(d)); | ||
}); | ||
@@ -86,4 +86,4 @@ })); | ||
n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n)); | ||
let r = n.get(e); | ||
return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r; | ||
let o = n.get(e); | ||
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o; | ||
} | ||
@@ -96,15 +96,15 @@ ensureMap(t, e) { | ||
n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n)); | ||
let r = n.get(e); | ||
return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r; | ||
let o = n.get(e); | ||
return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o; | ||
} | ||
_replaceComment(t, e, n) { | ||
const r = this._ensureCommentMap(t, e), a = r.get(n.id); | ||
if (a) { | ||
const { children: o, ...M } = n, u = { | ||
...M, | ||
ref: a.ref | ||
const o = this._ensureCommentMap(t, e), r = o.get(n.id); | ||
if (r) { | ||
const { children: a, ...d } = n, m = { | ||
...d, | ||
ref: r.ref | ||
}; | ||
r.set(n.id, u), o == null || o.forEach((p) => { | ||
r.set(p.id, { | ||
...p, | ||
o.set(n.id, m), a == null || a.forEach((c) => { | ||
o.set(c.id, { | ||
...c, | ||
ref: "" | ||
@@ -116,4 +116,4 @@ }); | ||
type: "syncUpdate", | ||
payload: u | ||
}), !!n.resolved != !!a.resolved && this._commentUpdate$.next({ | ||
payload: m | ||
}), !!n.resolved != !!r.resolved && this._commentUpdate$.next({ | ||
unitId: t, | ||
@@ -130,43 +130,45 @@ subUnitId: e, | ||
async syncThreadComments(t, e, n) { | ||
if (this._lifecycleService.stage < ae.Rendered) { | ||
if (this._lifecycleService.stage < O.Rendered) { | ||
this._tasks.push({ unitId: t, subUnitId: e, threadIds: n }); | ||
return; | ||
} | ||
const r = this._ensureThreadMap(t, e), a = this._ensureCommentMap(t, e), o = await this._dataSourceService.listThreadComments(t, e, n); | ||
if (!o) | ||
const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n); | ||
if (!a) | ||
return; | ||
const M = new Set(n); | ||
o.forEach((u) => { | ||
this._replaceComment(t, e, u), M.delete(u.threadId); | ||
}), M.forEach((u) => { | ||
r.delete(u), a.forEach((p, S) => { | ||
p.threadId === u && a.delete(S); | ||
const d = new Set(n); | ||
a.forEach((m) => { | ||
this._replaceComment(t, e, m), d.delete(m.threadId); | ||
}), d.forEach((m) => { | ||
o.delete(m), r.forEach((c, h) => { | ||
c.threadId === m && r.delete(h); | ||
}); | ||
}); | ||
} | ||
addComment(t, e, n, r) { | ||
const a = this._ensureCommentMap(t, e), { parentId: o, children: M = [], ...u } = n, p = { | ||
...u, | ||
parentId: o === n.id ? void 0 : o | ||
}, S = (N) => { | ||
a.set(N.id, N), this._commentUpdate$.next({ | ||
addComment(t, e, n, o) { | ||
const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = { | ||
...m, | ||
parentId: a === n.id ? void 0 : a | ||
}; | ||
c.threadId || (c.threadId = c.parentId || c.id); | ||
const h = (C) => { | ||
r.set(C.id, C), this._commentUpdate$.next({ | ||
unitId: t, | ||
subUnitId: e, | ||
type: "add", | ||
payload: N, | ||
isRoot: !N.parentId | ||
payload: C, | ||
isRoot: !C.parentId | ||
}); | ||
}; | ||
S(p); | ||
const $ = this._ensureThreadMap(t, e); | ||
if (!p.parentId) { | ||
$.set(p.threadId, p); | ||
for (const N of M) | ||
S(N); | ||
h(c); | ||
const _ = this._ensureThreadMap(t, e); | ||
if (!c.parentId) { | ||
_.set(c.threadId, c); | ||
for (const C of d) | ||
h(C); | ||
} | ||
return r && this.syncThreadComments(t, e, [p.threadId]), !0; | ||
return o && this.syncThreadComments(t, e, [c.threadId]), !0; | ||
} | ||
updateComment(t, e, n, r) { | ||
const o = this._ensureCommentMap(t, e).get(n.commentId); | ||
return o && (o.updated = !0, o.text = n.text, o.attachments = n.attachments, o.updateT = n.updateT, this._commentUpdate$.next({ | ||
updateComment(t, e, n, o) { | ||
const a = this._ensureCommentMap(t, e).get(n.commentId); | ||
return a && (a.updated = !0, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({ | ||
unitId: t, | ||
@@ -176,8 +178,8 @@ subUnitId: e, | ||
payload: n, | ||
silent: r | ||
silent: o | ||
})), !0; | ||
} | ||
updateCommentRef(t, e, n, r) { | ||
const o = this._ensureCommentMap(t, e).get(n.commentId); | ||
return o ? (o.ref = n.ref, this._commentUpdate$.next({ | ||
updateCommentRef(t, e, n, o) { | ||
const a = this._ensureCommentMap(t, e).get(n.commentId); | ||
return a ? (a.ref = n.ref, this._commentUpdate$.next({ | ||
unitId: t, | ||
@@ -187,9 +189,9 @@ subUnitId: e, | ||
payload: n, | ||
silent: r, | ||
threadId: o.threadId | ||
silent: o, | ||
threadId: a.threadId | ||
}), !0) : !1; | ||
} | ||
resolveComment(t, e, n, r) { | ||
const o = this._ensureCommentMap(t, e).get(n); | ||
return o ? (o.resolved = r, this._commentUpdate$.next({ | ||
resolveComment(t, e, n, o) { | ||
const a = this._ensureCommentMap(t, e).get(n); | ||
return a ? (a.resolved = o, this._commentUpdate$.next({ | ||
unitId: t, | ||
@@ -200,3 +202,3 @@ subUnitId: e, | ||
commentId: n, | ||
resolved: r | ||
resolved: o | ||
} | ||
@@ -212,12 +214,12 @@ }), !0) : !1; | ||
getThread(t, e, n) { | ||
const r = this._ensureCommentMap(t, e), a = Array.from(r.values()).filter((p) => p.threadId === n); | ||
let o; | ||
const M = [], u = /* @__PURE__ */ new Set(); | ||
for (const p of a) | ||
p.parentId ? M.push(p) : o = p, u.add(p.personId); | ||
if (o) | ||
const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n); | ||
let a; | ||
const d = [], m = /* @__PURE__ */ new Set(); | ||
for (const c of r) | ||
c.parentId ? d.push(c) : a = c, m.add(c.personId); | ||
if (a) | ||
return { | ||
root: o, | ||
children: M, | ||
relativeUsers: u, | ||
root: a, | ||
children: d, | ||
relativeUsers: m, | ||
unitId: t, | ||
@@ -229,9 +231,9 @@ subUnitId: e, | ||
getCommentWithChildren(t, e, n) { | ||
const r = this.getComment(t, e, n); | ||
if (r) | ||
return this.getThread(t, e, r.threadId); | ||
const o = this.getComment(t, e, n); | ||
if (o) | ||
return this.getThread(t, e, o.threadId); | ||
} | ||
_deleteComment(t, e, n) { | ||
const r = this._ensureCommentMap(t, e), a = r.get(n); | ||
a && (r.delete(n), this._commentUpdate$.next({ | ||
const o = this._ensureCommentMap(t, e), r = o.get(n); | ||
r && (o.delete(n), this._commentUpdate$.next({ | ||
unitId: t, | ||
@@ -242,4 +244,4 @@ subUnitId: e, | ||
commentId: n, | ||
isRoot: !a.parentId, | ||
comment: a | ||
isRoot: !r.parentId, | ||
comment: r | ||
} | ||
@@ -249,15 +251,15 @@ })); | ||
deleteThread(t, e, n) { | ||
this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((o) => { | ||
o.threadId === n && this._deleteComment(t, e, o.id); | ||
this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => { | ||
a.threadId === n && this._deleteComment(t, e, a.id); | ||
}); | ||
} | ||
deleteComment(t, e, n) { | ||
const a = this._ensureCommentMap(t, e).get(n); | ||
return a && (a.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, a.threadId)), !0; | ||
const r = this._ensureCommentMap(t, e).get(n); | ||
return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), !0; | ||
} | ||
deleteUnit(t) { | ||
const e = this._commentsMap.get(t); | ||
e && e.forEach((n, r) => { | ||
n.forEach((a) => { | ||
this.deleteComment(t, r, a.id); | ||
e && e.forEach((n, o) => { | ||
n.forEach((r) => { | ||
this.deleteComment(t, o, r.id); | ||
}); | ||
@@ -271,6 +273,6 @@ }); | ||
const n = []; | ||
return e.forEach((r, a) => { | ||
r.forEach((o, M) => { | ||
const u = this.getThread(t, a, M); | ||
u && n.push(u); | ||
return e.forEach((o, r) => { | ||
o.forEach((a, d) => { | ||
const m = this.getThread(t, r, d); | ||
m && n.push(m); | ||
}); | ||
@@ -289,14 +291,14 @@ }), n; | ||
}; | ||
O = Ie([ | ||
se(0, Z(b)), | ||
se(1, Z(ge)) | ||
], O); | ||
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 || {}); | ||
const ce = "UNIVER_THREAD_COMMENT_PLUGIN"; | ||
var Re = Object.defineProperty, be = Object.getOwnPropertyDescriptor, xe = (s, t, e, n) => { | ||
for (var r = n > 1 ? void 0 : n ? be(t, e) : t, a = s.length - 1, o; a >= 0; a--) | ||
(o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r); | ||
return n && r && Re(t, e, r), r; | ||
}, q = (s, t) => (e, n) => t(e, n, s); | ||
let B = class extends ee { | ||
i = q([ | ||
I(0, v(p)), | ||
I(1, v(L)) | ||
], i); | ||
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 || {}); | ||
const D = "UNIVER_THREAD_COMMENT_PLUGIN"; | ||
var z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, X = (s, t, e, n) => { | ||
for (var o = n > 1 ? void 0 : n ? Q(t, e) : t, r = s.length - 1, a; r >= 0; r--) | ||
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o); | ||
return n && o && z(t, e, o), o; | ||
}, S = (s, t) => (e, n) => t(e, n, s); | ||
let g = class extends U { | ||
constructor(s, t, e) { | ||
@@ -307,11 +309,11 @@ super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot(); | ||
const s = (e) => { | ||
const n = this._threadCommentModel.getUnit(e), r = {}; | ||
return n ? (n.forEach((a) => { | ||
var M; | ||
const o = (M = r[a.subUnitId]) != null ? M : []; | ||
o.push({ | ||
...a.root, | ||
children: a.children | ||
}), r[a.unitId] = o; | ||
}), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(r, e))) : ""; | ||
const n = this._threadCommentModel.getUnit(e), o = {}; | ||
return n ? (n.forEach((r) => { | ||
var d; | ||
const a = (d = o[r.subUnitId]) != null ? d : []; | ||
a.push({ | ||
...r.root, | ||
children: r.children | ||
}), o[r.subUnitId] = a; | ||
}), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : ""; | ||
}, t = (e) => { | ||
@@ -328,4 +330,4 @@ if (!e) | ||
this._resourceManagerService.registerPluginResource({ | ||
pluginName: `SHEET_${ce}`, | ||
businesses: [X.UNIVER_SHEET, X.UNIVER_DOC], | ||
pluginName: `SHEET_${D}`, | ||
businesses: [T.UNIVER_SHEET, T.UNIVER_DOC], | ||
toJson: (e) => s(e), | ||
@@ -337,7 +339,7 @@ parseJson: (e) => t(e), | ||
onLoad: async (e, n) => { | ||
Object.keys(n).forEach((r) => { | ||
const a = n[r]; | ||
a.forEach((o) => { | ||
this._threadCommentModel.addComment(e, r, o); | ||
}), this._threadCommentModel.syncThreadComments(e, r, a.map((o) => o.threadId)); | ||
Object.keys(n).forEach((o) => { | ||
const r = n[o]; | ||
r.forEach((a) => { | ||
this._threadCommentModel.addComment(e, o, a); | ||
}), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId)); | ||
}); | ||
@@ -349,156 +351,156 @@ } | ||
}; | ||
B = xe([ | ||
q(0, ye), | ||
q(1, Z(O)), | ||
q(2, b) | ||
], B); | ||
const me = { | ||
g = X([ | ||
S(0, V), | ||
S(1, v(i)), | ||
S(2, p) | ||
], g); | ||
const w = { | ||
id: "thread-comment.mutation.add-comment", | ||
type: I.MUTATION, | ||
type: l.MUTATION, | ||
handler(s, t, e) { | ||
if (!t) | ||
return !1; | ||
const n = s.get(O), { unitId: r, subUnitId: a, comment: o, sync: M } = t, u = M || (e == null ? void 0 : e.fromChangeset) && !o.parentId; | ||
return n.addComment(r, a, o, u); | ||
const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId; | ||
return n.addComment(o, r, a, m); | ||
} | ||
}, de = { | ||
}, P = { | ||
id: "thread-comment.mutation.update-comment", | ||
type: I.MUTATION, | ||
type: l.MUTATION, | ||
handler(s, t) { | ||
if (!t) | ||
return !1; | ||
const e = s.get(O), { unitId: n, subUnitId: r, payload: a, silent: o } = t; | ||
return e.updateComment(n, r, a, o); | ||
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t; | ||
return e.updateComment(n, o, r, a); | ||
} | ||
}, Pe = { | ||
}, k = { | ||
id: "thread-comment.mutation.update-comment-ref", | ||
type: I.MUTATION, | ||
type: l.MUTATION, | ||
handler(s, t) { | ||
if (!t) | ||
return !1; | ||
const e = s.get(O), { unitId: n, subUnitId: r, payload: a, silent: o } = t; | ||
return e.updateCommentRef(n, r, a, o); | ||
const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t; | ||
return e.updateCommentRef(n, o, r, a); | ||
} | ||
}, ue = { | ||
}, $ = { | ||
id: "thread-comment.mutation.resolve-comment", | ||
type: I.MUTATION, | ||
type: l.MUTATION, | ||
handler(s, t) { | ||
if (!t) | ||
return !1; | ||
const e = s.get(O), { unitId: n, subUnitId: r, resolved: a, commentId: o } = t; | ||
return e.resolveComment(n, r, o, a); | ||
const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t; | ||
return e.resolveComment(n, o, a, r); | ||
} | ||
}, te = { | ||
}, N = { | ||
id: "thread-comment.mutation.delete-comment", | ||
type: I.MUTATION, | ||
type: l.MUTATION, | ||
handler(s, t) { | ||
if (!t) | ||
return !1; | ||
const e = s.get(O), { unitId: n, subUnitId: r, commentId: a } = t; | ||
return e.deleteComment(n, r, a); | ||
const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t; | ||
return e.deleteComment(n, o, r); | ||
} | ||
}, je = { | ||
}, ee = { | ||
id: "thread-comment.command.add-comment", | ||
type: I.COMMAND, | ||
type: l.COMMAND, | ||
async handler(s, t) { | ||
if (!t) | ||
return !1; | ||
const e = s.get(H), n = s.get(b), { comment: r } = t, a = await n.addComment(r), o = n.syncUpdateMutationToColla, M = !r.parentId, u = { | ||
id: me.id, | ||
const e = s.get(f), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = { | ||
id: w.id, | ||
params: { | ||
...t, | ||
comment: a | ||
comment: r | ||
} | ||
}; | ||
return M ? await e.executeCommand(u.id, u.params) : e.executeCommand(u.id, u.params, { | ||
onlyLocal: !o | ||
return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, { | ||
onlyLocal: !a | ||
}); | ||
} | ||
}, Ae = { | ||
}, te = { | ||
id: "thread-comment.command.update-comment", | ||
type: I.COMMAND, | ||
type: l.COMMAND, | ||
async handler(s, t) { | ||
if (!t) | ||
return !1; | ||
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( | ||
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( | ||
e, | ||
n, | ||
r.commentId | ||
o.commentId | ||
); | ||
if (!p) | ||
if (!c) | ||
return !1; | ||
const { children: S, ...$ } = p; | ||
if (!await M.updateComment({ | ||
...$, | ||
...r | ||
const { children: h, ..._ } = c; | ||
if (!await d.updateComment({ | ||
..._, | ||
...o | ||
})) | ||
return !1; | ||
const U = { | ||
id: de.id, | ||
const E = { | ||
id: P.id, | ||
params: t | ||
}; | ||
return a.executeCommand(U.id, U.params, { onlyLocal: !u }), !0; | ||
return r.executeCommand(E.id, E.params, { onlyLocal: !m }), !0; | ||
} | ||
}, Le = { | ||
}, ne = { | ||
id: "thread-comment.command.resolve-comment", | ||
type: I.COMMAND, | ||
type: l.COMMAND, | ||
async handler(s, t) { | ||
if (!t) | ||
return !1; | ||
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; | ||
return !u || !await o.resolveComment({ | ||
...u, | ||
resolved: r | ||
}) ? !1 : s.get(H).executeCommand( | ||
ue.id, | ||
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; | ||
return !m || !await a.resolveComment({ | ||
...m, | ||
resolved: o | ||
}) ? !1 : s.get(f).executeCommand( | ||
$.id, | ||
t, | ||
{ onlyLocal: !p } | ||
{ onlyLocal: !c } | ||
); | ||
} | ||
}, He = { | ||
}, oe = { | ||
id: "thread-comment.command.delete-comment", | ||
type: I.COMMAND, | ||
type: l.COMMAND, | ||
async handler(s, t) { | ||
if (!t) | ||
return !1; | ||
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); | ||
if (!p || !await n.deleteComment(a, o, p.threadId, M)) | ||
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); | ||
if (!c || !await n.deleteComment(r, a, c.threadId, d)) | ||
return !1; | ||
const S = { | ||
id: te.id, | ||
const h = { | ||
id: N.id, | ||
params: t | ||
}; | ||
return r.executeCommand(S.id, S.params, { onlyLocal: !u }); | ||
return o.executeCommand(h.id, h.params, { onlyLocal: !m }); | ||
} | ||
}, We = { | ||
}, re = { | ||
id: "thread-comment.command.delete-comment-tree", | ||
type: I.COMMAND, | ||
type: l.COMMAND, | ||
async handler(s, t) { | ||
if (!t) | ||
return !1; | ||
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); | ||
return !u || !await r.deleteComment(a, o, u.root.threadId, M) ? !1 : await n.executeCommand(te.id, { | ||
unitId: a, | ||
subUnitId: o, | ||
commentId: u.root.id | ||
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); | ||
return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? !1 : await n.executeCommand(N.id, { | ||
unitId: r, | ||
subUnitId: a, | ||
commentId: m.root.id | ||
}); | ||
} | ||
}, Ye = "thread-comment.config", Ve = {}; | ||
var Je = Object.defineProperty, ke = Object.getOwnPropertyDescriptor, Ge = (s, t, e, n) => { | ||
for (var r = n > 1 ? void 0 : n ? ke(t, e) : t, a = s.length - 1, o; a >= 0; a--) | ||
(o = s[a]) && (r = (n ? o(t, e, r) : o(r)) || r); | ||
return n && r && Je(t, e, r), r; | ||
}, Q = (s, t) => (e, n) => t(e, n, s), F; | ||
let ie = (F = class extends Se { | ||
constructor(s = Ve, t, e, n) { | ||
}, ae = "thread-comment.config", se = {}; | ||
var me = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, de = (s, t, e, n) => { | ||
for (var o = n > 1 ? void 0 : n ? ce(t, e) : t, r = s.length - 1, a; r >= 0; r--) | ||
(a = s[r]) && (o = (n ? a(t, e, o) : a(o)) || o); | ||
return n && o && me(t, e, o), o; | ||
}, y = (s, t) => (e, n) => t(e, n, s), M; | ||
let R = (M = class extends W { | ||
constructor(s = se, t, e, n) { | ||
super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n; | ||
const { ...r } = this._config; | ||
this._configService.setConfig(Ye, r); | ||
const { ...o } = this._config; | ||
this._configService.setConfig(ae, o); | ||
} | ||
onStarting() { | ||
var s; | ||
Te([ | ||
[b, { useClass: Ue }], | ||
[O], | ||
[B] | ||
H([ | ||
[p, { useClass: B }], | ||
[i], | ||
[g] | ||
], (s = this._config) == null ? void 0 : s.overrides).forEach( | ||
@@ -509,325 +511,43 @@ (t) => { | ||
), [ | ||
je, | ||
Ae, | ||
He, | ||
Le, | ||
We, | ||
me, | ||
de, | ||
Pe, | ||
ee, | ||
te, | ||
ue | ||
oe, | ||
ne, | ||
re, | ||
w, | ||
P, | ||
k, | ||
N, | ||
$ | ||
].forEach((t) => { | ||
this._commandService.registerCommand(t); | ||
}), this._injector.get(B); | ||
}), this._injector.get(g); | ||
} | ||
}, E(F, "pluginName", ce), E(F, "type", $e.UNIVER_UNKNOWN), F); | ||
ie = Ge([ | ||
Q(1, Z(De)), | ||
Q(2, H), | ||
Q(3, Oe) | ||
], ie); | ||
var Fe = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; | ||
function Ze(s) { | ||
return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s; | ||
}, u(M, "pluginName", D), u(M, "type", J.UNIVER_UNKNOWN), M); | ||
R = de([ | ||
y(1, v(G)), | ||
y(2, f), | ||
y(3, b) | ||
], R); | ||
function le() { | ||
return Y().format("YYYY/MM/DD HH:mm"); | ||
} | ||
var he = { exports: {} }; | ||
(function(s, t) { | ||
(function(e, n) { | ||
s.exports = n(); | ||
})(Fe, function() { | ||
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) { | ||
var m = ["th", "st", "nd", "rd"], i = h % 100; | ||
return "[" + h + (m[(i - 20) % 10] || m[i] || m[0]) + "]"; | ||
} }, K = function(h, m, i) { | ||
var d = String(h); | ||
return !d || d.length >= m ? h : "" + Array(m + 1 - d.length).join(i) + h; | ||
}, Me = { s: K, z: function(h) { | ||
var m = -h.utcOffset(), i = Math.abs(m), d = Math.floor(i / 60), c = i % 60; | ||
return (m <= 0 ? "+" : "-") + K(d, 2, "0") + ":" + K(c, 2, "0"); | ||
}, m: function h(m, i) { | ||
if (m.date() < i.date()) return -h(i, m); | ||
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), $); | ||
return +(-(d + (i - c) / (l ? c - f : f - c)) || 0); | ||
}, a: function(h) { | ||
return h < 0 ? Math.ceil(h) || 0 : Math.floor(h); | ||
}, p: function(h) { | ||
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$/, ""); | ||
}, u: function(h) { | ||
return h === void 0; | ||
} }, W = "en", x = {}; | ||
x[W] = pe; | ||
var re = "$isDayjsObject", z = function(h) { | ||
return h instanceof k || !(!h || !h[re]); | ||
}, J = function h(m, i, d) { | ||
var c; | ||
if (!m) return W; | ||
if (typeof m == "string") { | ||
var l = m.toLowerCase(); | ||
x[l] && (c = l), i && (x[l] = i, c = l); | ||
var f = m.split("-"); | ||
if (!c && f.length > 1) return h(f[0]); | ||
} else { | ||
var _ = m.name; | ||
x[_] = m, c = _; | ||
} | ||
return !d && c && (W = c), c || !d && W; | ||
}, g = function(h, m) { | ||
if (z(h)) return h.clone(); | ||
var i = typeof m == "object" ? m : {}; | ||
return i.date = h, i.args = arguments, new k(i); | ||
}, C = Me; | ||
C.l = J, C.i = z, C.w = function(h, m) { | ||
return g(h, { locale: m.$L, utc: m.$u, x: m.$x, $offset: m.$offset }); | ||
}; | ||
var k = function() { | ||
function h(i) { | ||
this.$L = J(i.locale, null, !0), this.parse(i), this.$x = this.$x || i.x || {}, this[re] = !0; | ||
} | ||
var m = h.prototype; | ||
return m.parse = function(i) { | ||
this.$d = function(d) { | ||
var c = d.date, l = d.utc; | ||
if (c === null) return /* @__PURE__ */ new Date(NaN); | ||
if (C.u(c)) return /* @__PURE__ */ new Date(); | ||
if (c instanceof Date) return new Date(c); | ||
if (typeof c == "string" && !/Z$/i.test(c)) { | ||
var f = c.match(le); | ||
if (f) { | ||
var _ = f[2] - 1 || 0, v = (f[7] || "0").substring(0, 3); | ||
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); | ||
} | ||
} | ||
return new Date(c); | ||
}(i), this.init(); | ||
}, m.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(); | ||
}, m.$utils = function() { | ||
return C; | ||
}, m.isValid = function() { | ||
return this.$d.toString() !== ne; | ||
}, m.isSame = function(i, d) { | ||
var c = g(i); | ||
return this.startOf(d) <= c && c <= this.endOf(d); | ||
}, m.isAfter = function(i, d) { | ||
return g(i) < this.startOf(d); | ||
}, m.isBefore = function(i, d) { | ||
return this.endOf(d) < g(i); | ||
}, m.$g = function(i, d, c) { | ||
return C.u(i) ? this[d] : this.set(c, i); | ||
}, m.unix = function() { | ||
return Math.floor(this.valueOf() / 1e3); | ||
}, m.valueOf = function() { | ||
return this.$d.getTime(); | ||
}, m.startOf = function(i, d) { | ||
var c = this, l = !!C.u(d) || d, f = C.p(i), _ = function(j, D) { | ||
var R = C.w(c.$u ? Date.UTC(c.$y, D, j) : new Date(c.$y, D, j), c); | ||
return l ? R : R.endOf(p); | ||
}, v = function(j, D) { | ||
return C.w(c.toDate()[j].apply(c.toDate("s"), (l ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(D)), c); | ||
}, y = this.$W, T = this.$M, w = this.$D, L = "set" + (this.$u ? "UTC" : ""); | ||
switch (f) { | ||
case U: | ||
return l ? _(1, 0) : _(31, 11); | ||
case $: | ||
return l ? _(1, T) : _(0, T + 1); | ||
case S: | ||
var P = this.$locale().weekStart || 0, Y = (y < P ? y + 7 : y) - P; | ||
return _(l ? w - Y : w + (6 - Y), T); | ||
case p: | ||
case A: | ||
return v(L + "Hours", 0); | ||
case u: | ||
return v(L + "Minutes", 1); | ||
case M: | ||
return v(L + "Seconds", 2); | ||
case o: | ||
return v(L + "Milliseconds", 3); | ||
default: | ||
return this.clone(); | ||
} | ||
}, m.endOf = function(i) { | ||
return this.startOf(i, !1); | ||
}, m.$set = function(i, d) { | ||
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; | ||
if (l === $ || l === U) { | ||
var y = this.clone().set(A, 1); | ||
y.$d[_](v), y.init(), this.$d = y.set(A, Math.min(this.$D, y.daysInMonth())).$d; | ||
} else _ && this.$d[_](v); | ||
return this.init(), this; | ||
}, m.set = function(i, d) { | ||
return this.clone().$set(i, d); | ||
}, m.get = function(i) { | ||
return this[C.p(i)](); | ||
}, m.add = function(i, d) { | ||
var c, l = this; | ||
i = Number(i); | ||
var f = C.p(d), _ = function(T) { | ||
var w = g(l); | ||
return C.w(w.date(w.date() + Math.round(T * i)), l); | ||
}; | ||
if (f === $) return this.set($, this.$M + i); | ||
if (f === U) return this.set(U, this.$y + i); | ||
if (f === p) return _(1); | ||
if (f === S) return _(7); | ||
var v = (c = {}, c[M] = n, c[u] = r, c[o] = e, c)[f] || 1, y = this.$d.getTime() + i * v; | ||
return C.w(y, this); | ||
}, m.subtract = function(i, d) { | ||
return this.add(-1 * i, d); | ||
}, m.format = function(i) { | ||
var d = this, c = this.$locale(); | ||
if (!this.isValid()) return c.invalidDate || ne; | ||
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) { | ||
return D && (D[R] || D(d, l)) || V[R].slice(0, G); | ||
}, Y = function(D) { | ||
return C.s(_ % 12 || 12, D, "0"); | ||
}, j = L || function(D, R, V) { | ||
var G = D < 12 ? "AM" : "PM"; | ||
return V ? G.toLowerCase() : G; | ||
}; | ||
return l.replace(fe, function(D, R) { | ||
return R || function(V) { | ||
switch (V) { | ||
case "YY": | ||
return String(d.$y).slice(-2); | ||
case "YYYY": | ||
return C.s(d.$y, 4, "0"); | ||
case "M": | ||
return y + 1; | ||
case "MM": | ||
return C.s(y + 1, 2, "0"); | ||
case "MMM": | ||
return P(c.monthsShort, y, w, 3); | ||
case "MMMM": | ||
return P(w, y); | ||
case "D": | ||
return d.$D; | ||
case "DD": | ||
return C.s(d.$D, 2, "0"); | ||
case "d": | ||
return String(d.$W); | ||
case "dd": | ||
return P(c.weekdaysMin, d.$W, T, 2); | ||
case "ddd": | ||
return P(c.weekdaysShort, d.$W, T, 3); | ||
case "dddd": | ||
return T[d.$W]; | ||
case "H": | ||
return String(_); | ||
case "HH": | ||
return C.s(_, 2, "0"); | ||
case "h": | ||
return Y(1); | ||
case "hh": | ||
return Y(2); | ||
case "a": | ||
return j(_, v, !0); | ||
case "A": | ||
return j(_, v, !1); | ||
case "m": | ||
return String(v); | ||
case "mm": | ||
return C.s(v, 2, "0"); | ||
case "s": | ||
return String(d.$s); | ||
case "ss": | ||
return C.s(d.$s, 2, "0"); | ||
case "SSS": | ||
return C.s(d.$ms, 3, "0"); | ||
case "Z": | ||
return f; | ||
} | ||
return null; | ||
}(D) || f.replace(":", ""); | ||
}); | ||
}, m.utcOffset = function() { | ||
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); | ||
}, m.diff = function(i, d, c) { | ||
var l, f = this, _ = C.p(d), v = g(i), y = (v.utcOffset() - this.utcOffset()) * n, T = this - v, w = function() { | ||
return C.m(f, v); | ||
}; | ||
switch (_) { | ||
case U: | ||
l = w() / 12; | ||
break; | ||
case $: | ||
l = w(); | ||
break; | ||
case N: | ||
l = w() / 3; | ||
break; | ||
case S: | ||
l = (T - y) / 6048e5; | ||
break; | ||
case p: | ||
l = (T - y) / 864e5; | ||
break; | ||
case u: | ||
l = T / r; | ||
break; | ||
case M: | ||
l = T / n; | ||
break; | ||
case o: | ||
l = T / e; | ||
break; | ||
default: | ||
l = T; | ||
} | ||
return c ? l : C.a(l); | ||
}, m.daysInMonth = function() { | ||
return this.endOf($).$D; | ||
}, m.$locale = function() { | ||
return x[this.$L]; | ||
}, m.locale = function(i, d) { | ||
if (!i) return this.$L; | ||
var c = this.clone(), l = J(i, d, !0); | ||
return l && (c.$L = l), c; | ||
}, m.clone = function() { | ||
return C.w(this.$d, this); | ||
}, m.toDate = function() { | ||
return new Date(this.valueOf()); | ||
}, m.toJSON = function() { | ||
return this.isValid() ? this.toISOString() : null; | ||
}, m.toISOString = function() { | ||
return this.$d.toISOString(); | ||
}, m.toString = function() { | ||
return this.$d.toUTCString(); | ||
}, h; | ||
}(), oe = k.prototype; | ||
return g.prototype = oe, [["$ms", a], ["$s", o], ["$m", M], ["$H", u], ["$W", p], ["$M", $], ["$y", U], ["$D", A]].forEach(function(h) { | ||
oe[h[1]] = function(m) { | ||
return this.$g(m, h[0], h[1]); | ||
}; | ||
}), g.extend = function(h, m) { | ||
return h.$i || (h(m, k, g), h.$i = !0), g; | ||
}, g.locale = J, g.isDayjs = z, g.unix = function(h) { | ||
return g(1e3 * h); | ||
}, g.en = x[W], g.Ls = x, g.p = {}, g; | ||
}); | ||
})(he); | ||
var Be = he.exports; | ||
const Ke = /* @__PURE__ */ Ze(Be); | ||
function Xe() { | ||
return Ke().format("YYYY/MM/DD HH:mm"); | ||
} | ||
export { | ||
je as AddCommentCommand, | ||
me as AddCommentMutation, | ||
He as DeleteCommentCommand, | ||
te as DeleteCommentMutation, | ||
We as DeleteCommentTreeCommand, | ||
b as IThreadCommentDataSourceService, | ||
Le as ResolveCommentCommand, | ||
ue as ResolveCommentMutation, | ||
ce as TC_PLUGIN_NAME, | ||
Ue as ThreadCommentDataSourceService, | ||
O as ThreadCommentModel, | ||
B as ThreadCommentResourceController, | ||
ie as UniverThreadCommentPlugin, | ||
Ae as UpdateCommentCommand, | ||
de as UpdateCommentMutation, | ||
Pe as UpdateCommentRefMutation, | ||
Xe as getDT | ||
ee as AddCommentCommand, | ||
w as AddCommentMutation, | ||
oe as DeleteCommentCommand, | ||
N as DeleteCommentMutation, | ||
re as DeleteCommentTreeCommand, | ||
p as IThreadCommentDataSourceService, | ||
ne as ResolveCommentCommand, | ||
$ as ResolveCommentMutation, | ||
D as TC_PLUGIN_NAME, | ||
B as ThreadCommentDataSourceService, | ||
i as ThreadCommentModel, | ||
g as ThreadCommentResourceController, | ||
R as UniverThreadCommentPlugin, | ||
te as UpdateCommentCommand, | ||
P as UpdateCommentMutation, | ||
k as UpdateCommentRefMutation, | ||
le as getDT | ||
}; |
@@ -1,1 +0,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"})}); | ||
(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"})}); |
{ | ||
"name": "@univerjs/thread-comment", | ||
"version": "0.5.0-alpha.0", | ||
"version": "0.5.0-beta.0", | ||
"private": false, | ||
@@ -49,5 +49,4 @@ "description": "Univer thread comment core plugin", | ||
"dependencies": { | ||
"@univerjs/protocol": "0.1.39-alpha.38", | ||
"dayjs": "^1.11.13", | ||
"@univerjs/core": "0.5.0-alpha.0" | ||
"@univerjs/protocol": "0.1.39-alpha.45", | ||
"@univerjs/core": "0.5.0-beta.0" | ||
}, | ||
@@ -57,5 +56,5 @@ "devDependencies": { | ||
"typescript": "^5.6.3", | ||
"vite": "^5.4.10", | ||
"vitest": "^2.1.4", | ||
"@univerjs-infra/shared": "0.5.0-alpha.0" | ||
"vite": "^5.4.11", | ||
"vitest": "^2.1.5", | ||
"@univerjs-infra/shared": "0.5.0-beta.0" | ||
}, | ||
@@ -80,5 +79,5 @@ "space": { | ||
"lint:types": "tsc --noEmit", | ||
"build": "tsx build.ts" | ||
"build": "univer-cli build" | ||
}, | ||
"module": "./lib/es/index.js" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3
0
248
248
69198
977
+ Added@univerjs/core@0.5.0-beta.0(transitive)
+ Added@univerjs/protocol@0.1.39-alpha.45(transitive)
- Removeddayjs@^1.11.13
- Removed@univerjs/core@0.5.0-alpha.0(transitive)
- Removed@univerjs/protocol@0.1.39-alpha.38(transitive)
Updated@univerjs/core@0.5.0-beta.0