@univerjs/preset-docs-thread-comment 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/umd/index.js +7 -7
  2. package/package.json +6 -6
package/lib/umd/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  // @univerjs/thread-comment/index
2
- (function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.UniverThreadComment={},d.UniverCore,d.rxjs))})(this,(function(d,s,M){"use strict";var B=Object.defineProperty;var q=(d,s,M)=>s in d?B(d,s,{enumerable:!0,configurable:!0,writable:!0,value:M}):d[s]=M;var u=(d,s,M)=>q(d,typeof s!="symbol"?s+"":s,M);var T;class I extends s.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=s.createIdentifier("univer.thread-comment.data-source-service");var H=Object.getOwnPropertyDescriptor,W=(c,m,e,t)=>{for(var n=t>1?void 0:t?H(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},N=(c,m)=>(e,t)=>m(e,t,c);d.ThreadCommentModel=class extends s.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===s.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:r,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(r);l||(l=new Set,h.set(r,l));for(const p of i)l.add(p)}),this._tasks=[],o.forEach((a,r)=>{a.forEach((i,h)=>{this.syncThreadComments(r,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:r,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),r==null||r.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<s.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),r=await this._dataSourceService.listThreadComments(e,t,n);if(!r)return;const i=new Set(n);r.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,p)=>{l.threadId===h&&a.delete(p)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:r,children:i=[],...h}=n,l={...h,parentId:r===n.id?void 0:r};l.threadId||(l.threadId=l.parentId||l.id);const p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const L=this._ensureThreadMap(e,t);if(!l.parentId){L.set(l.threadId,l);for(const f of i)p(f)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r&&(r.updated=!0,r.text=n.text,r.attachments=n.attachments,r.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r?(r.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:r.threadId}),!0):!1}resolveComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n);return r?(r.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 r;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):r=l,h.add(l.personId);if(r)return{root:r,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(r=>{r.threadId===n&&this._deleteComment(e,t,r.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((r,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}},d.ThreadCommentModel=W([N(0,s.Inject(C)),N(1,s.Inject(s.LifecycleService))],d.ThreadCommentModel);const v={id:"thread-comment.mutation.add-comment",type:s.CommandType.MUTATION,handler(c,m,e){if(!m)return!1;const t=c.get(d.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:r}=m,i=r||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},g={id:"thread-comment.mutation.update-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},D={id:"thread-comment.mutation.update-comment-ref",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},S={id:"thread-comment.mutation.resolve-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ICommandService),t=c.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,r=!n.parentId,i={id:v.id,params:{...m,comment:o}};return r?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},R={id:"thread-comment.command.update-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=c.get(s.ICommandService),a=c.get(d.ThreadCommentModel),r=c.get(C),i=r.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await r.updateComment({...p,...n}))return!1;const f={id:g.id,params:m};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=c.get(C),i=c.get(d.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:c.get(s.ICommandService).executeCommand(S.id,m,{onlyLocal:!h})}},A={id:"thread-comment.command.delete-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),t=c.get(C),n=c.get(s.ICommandService),{unitId:o,subUnitId:a,commentId:r}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,r);if(!h||!await t.deleteComment(o,a,h.threadId,r))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},P={id:"thread-comment.command.delete-comment-tree",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),t=c.get(s.ICommandService),n=c.get(C),{unitId:o,subUnitId:a,commentId:r}=m,i=e.getCommentWithChildren(o,a,r);return!i||!await n.deleteComment(o,a,i.root.threadId,r)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}};function G(c){return s.dayjs(c).format("YYYY/MM/DD HH:mm")}const y="UNIVER_THREAD_COMMENT_PLUGIN";var J=Object.getOwnPropertyDescriptor,V=(c,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},U=(c,m)=>(e,t)=>m(e,t,c);const j=`SHEET_${y}`;d.ThreadCommentResourceController=class extends s.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 r=(i=o[a.subUnitId])!=null?i:[];r.push({...a.root,children:a.children}),o[a.subUnitId]=r}),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:j,businesses:[s.UniverInstanceType.UNIVER_SHEET,s.UniverInstanceType.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(r=>{this._threadCommentModel.addComment(t,o,r)}),this._threadCommentModel.syncThreadComments(t,o,a.map(r=>r.threadId))})}}))}},d.ThreadCommentResourceController=V([U(0,s.IResourceManagerService),U(1,s.Inject(d.ThreadCommentModel)),U(2,C)],d.ThreadCommentResourceController);const b="thread-comment.config",$={};var Y=Object.getOwnPropertyDescriptor,k=(c,m,e,t)=>{for(var n=t>1?void 0:t?Y(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},E=(c,m)=>(e,t)=>m(e,t,c);d.UniverThreadCommentPlugin=(T=class extends s.Plugin{constructor(m=$,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=s.merge({},$,this._config);this._configService.setConfig(b,o)}onStarting(){var m;s.mergeOverrideWithDependencies([[C,{useClass:I}],[d.ThreadCommentModel],[d.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[O,R,A,w,P,v,g,D,_,S].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(d.ThreadCommentResourceController)}},u(T,"pluginName",y),u(T,"type",s.UniverInstanceType.UNIVER_UNKNOWN),T),d.UniverThreadCommentPlugin=k([E(1,s.Inject(s.Injector)),E(2,s.ICommandService),E(3,s.IConfigService)],d.UniverThreadCommentPlugin),d.AddCommentCommand=O,d.AddCommentMutation=v,d.DeleteCommentCommand=A,d.DeleteCommentMutation=_,d.DeleteCommentTreeCommand=P,d.IThreadCommentDataSourceService=C,d.ResolveCommentCommand=w,d.ResolveCommentMutation=S,d.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=j,d.TC_PLUGIN_NAME=y,d.ThreadCommentDataSourceService=I,d.UpdateCommentCommand=R,d.UpdateCommentMutation=g,d.UpdateCommentRefMutation=D,d.getDT=G,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
2
+ (function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,(function(s,d,M){"use strict";var q=Object.defineProperty;var K=(s,d,M)=>d in s?q(s,d,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[d]=M;var u=(s,d,M)=>K(s,typeof d!="symbol"?d+"":d,M);var _;class I extends d.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=d.createIdentifier("univer.thread-comment.data-source-service");var W=Object.getOwnPropertyDescriptor,G=(c,m,e,t)=>{for(var n=t>1?void 0:t?W(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},N=(c,m)=>(e,t)=>m(e,t,c);s.ThreadCommentModel=class extends d.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===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:r,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(r);l||(l=new Set,h.set(r,l));for(const p of i)l.add(p)}),this._tasks=[],o.forEach((a,r)=>{a.forEach((i,h)=>{this.syncThreadComments(r,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:r,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),r==null||r.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<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),r=await this._dataSourceService.listThreadComments(e,t,n);if(!r)return;const i=new Set(n);r.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,p)=>{l.threadId===h&&a.delete(p)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:r,children:i=[],...h}=n,l={...h,parentId:r===n.id?void 0:r};l.threadId||(l.threadId=l.parentId||l.id);const p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const H=this._ensureThreadMap(e,t);if(!l.parentId){H.set(l.threadId,l);for(const f of i)p(f)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r&&(r.updated=!0,r.text=n.text,r.attachments=n.attachments,r.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r?(r.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:r.threadId}),!0):!1}resolveComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n);return r?(r.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 r;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):r=l,h.add(l.personId);if(r)return{root:r,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(r=>{r.threadId===n&&this._deleteComment(e,t,r.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((r,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=G([N(0,d.Inject(C)),N(1,d.Inject(d.LifecycleService))],s.ThreadCommentModel);const v={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(c,m,e){if(!m)return!1;const t=c.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:r}=m,i=r||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},g={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},D={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},S={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ICommandService),t=c.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,r=!n.parentId,i={id:v.id,params:{...m,comment:o}};return r?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},R={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=c.get(d.ICommandService),a=c.get(s.ThreadCommentModel),r=c.get(C),i=r.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await r.updateComment({...p,...n}))return!1;const f={id:g.id,params:m};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=c.get(C),i=c.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:c.get(d.ICommandService).executeCommand(S.id,m,{onlyLocal:!h})}},A={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),t=c.get(C),n=c.get(d.ICommandService),{unitId:o,subUnitId:a,commentId:r}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,r);if(!h||!await t.deleteComment(o,a,h.threadId,r))return!1;const l={id:T.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},P={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),t=c.get(d.ICommandService),n=c.get(C),{unitId:o,subUnitId:a,commentId:r}=m,i=e.getCommentWithChildren(o,a,r);return!i||!await n.deleteComment(o,a,i.root.threadId,r)?!1:await t.executeCommand(T.id,{unitId:o,subUnitId:a,commentId:i.root.id})}};function k(c){return d.dayjs(c).format("YYYY/MM/DD HH:mm")}const y="UNIVER_THREAD_COMMENT_PLUGIN";var J=Object.getOwnPropertyDescriptor,V=(c,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},U=(c,m)=>(e,t)=>m(e,t,c);const j=`SHEET_${y}`;s.ThreadCommentResourceController=class extends d.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const r=(i=o[a.subUnitId])!=null?i:[];r.push({...a.root,children:a.children}),o[a.subUnitId]=r}),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:j,businesses:[d.UniverInstanceType.UNIVER_SHEET,d.UniverInstanceType.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(r=>{this._threadCommentModel.addComment(t,o,r)}),this._threadCommentModel.syncThreadComments(t,o,a.map(r=>r.threadId))})}}))}},s.ThreadCommentResourceController=V([U(0,d.IResourceManagerService),U(1,d.Inject(s.ThreadCommentModel)),U(2,C)],s.ThreadCommentResourceController);const $={name:"@univerjs/thread-comment",version:"0.17.0"},b="thread-comment.config",L={};var Y=Object.getOwnPropertyDescriptor,B=(c,m,e,t)=>{for(var n=t>1?void 0:t?Y(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},E=(c,m)=>(e,t)=>m(e,t,c);s.UniverThreadCommentPlugin=(_=class extends d.Plugin{constructor(m=L,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=d.merge({},L,this._config);this._configService.setConfig(b,o)}onStarting(){var m;d.mergeOverrideWithDependencies([[C,{useClass:I}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[O,R,A,w,P,v,g,D,T,S].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(_,"pluginName",y),u(_,"packageName",$.name),u(_,"version",$.version),u(_,"type",d.UniverInstanceType.UNIVER_UNKNOWN),_),s.UniverThreadCommentPlugin=B([E(1,d.Inject(d.Injector)),E(2,d.ICommandService),E(3,d.IConfigService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=O,s.AddCommentMutation=v,s.DeleteCommentCommand=A,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=P,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=S,s.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=j,s.TC_PLUGIN_NAME=y,s.ThreadCommentDataSourceService=I,s.UpdateCommentCommand=R,s.UpdateCommentMutation=g,s.UpdateCommentRefMutation=D,s.getDT=k,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
3
3
 
4
4
 
5
5
  // @univerjs/thread-comment-ui/index
6
- (function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/thread-comment"),require("react/jsx-runtime"),require("@univerjs/design"),require("react"),require("@univerjs/docs-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/thread-comment","react/jsx-runtime","@univerjs/design","react","@univerjs/docs-ui"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.UniverThreadCommentUi={},u.UniverCore,u.UniverUi,u.rxjs,u.UniverThreadComment,u.React,u.UniverDesign,u.React,u.UniverDocsUi))})(this,(function(u,s,m,Q,V,i,U,d,ie){"use strict";var Fe=Object.defineProperty;var qe=(u,s,m)=>s in u?Fe(u,s,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[s]=m;var G=(u,s,m)=>qe(u,typeof s!="symbol"?s+"":s,m);var ye=Object.getOwnPropertyDescriptor,Se=(r,e,t,n)=>{for(var o=n>1?void 0:n?ye(e,t):e,a=r.length-1,v;a>=0;a--)(v=r[a])&&(o=v(o)||o);return o},oe=(r,e)=>(t,n)=>e(t,n,r);u.ThreadCommentPanelService=class extends s.Disposable{constructor(t,n){super();G(this,"_panelVisible",!1);G(this,"_panelVisible$",new Q.BehaviorSubject(!1));G(this,"_activeCommentId");G(this,"_activeCommentId$",new Q.BehaviorSubject(void 0));G(this,"panelVisible$",this._panelVisible$.asObservable());G(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._activeCommentId$.complete(),this._panelVisible$.complete()})}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).pipe(Q.filter(t=>!t)).subscribe(()=>{this._sidebarService.close()}))}get panelVisible(){return this._panelVisible}get activeCommentId(){return this._activeCommentId}setPanelVisible(t){this._panelVisible=t,this._panelVisible$.next(t)}setActiveComment(t){this._activeCommentId=t,this._activeCommentId$.next(t)}},u.ThreadCommentPanelService=Se([oe(0,s.Inject(m.ISidebarService)),oe(1,s.IUniverInstanceService)],u.ThreadCommentPanelService);const ae="thread-comment-panel",_e="UNIVER_THREAD_COMMENT_UI_PLUGIN",le={id:"thread-comment-ui.operation.toggle-panel",type:s.CommandType.OPERATION,handler(r){const e=r.get(m.ISidebarService),t=r.get(u.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:ae},width:360}),t.setPanelVisible(!0)),!0}},F={id:"thread-comment-ui.operation.set-active-comment",type:s.CommandType.OPERATION,handler(r,e){return r.get(u.ThreadCommentPanelService).setActiveComment(e),!0}},we="thread-comment-ui.config",de={};var Te=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Ue=(r,e,t)=>e in r?Te(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,De=(r,e,t,n)=>{for(var o=n>1?void 0:n?Ne(e,t):e,a=r.length-1,v;a>=0;a--)(v=r[a])&&(o=v(o)||o);return o},se=(r,e)=>(t,n)=>e(t,n,r),ce=(r,e,t)=>Ue(r,typeof e!="symbol"?e+"":e,t);u.UniverThreadCommentUIPlugin=class extends s.Plugin{constructor(e=de,t,n,o){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=o;const{menu:a,...v}=s.merge({},de,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(we,v)}onStarting(){var e;s.mergeOverrideWithDependencies([[u.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[le,F].forEach(t=>{this._commandService.registerCommand(t)})}},ce(u.UniverThreadCommentUIPlugin,"pluginName",_e),ce(u.UniverThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_UNKNOWN),u.UniverThreadCommentUIPlugin=De([s.DependentOn(V.UniverThreadCommentPlugin),se(1,s.Inject(s.Injector)),se(2,s.ICommandService),se(3,s.IConfigService)],u.UniverThreadCommentUIPlugin);function q({ref:r,...e}){const{icon:t,id:n,className:o,extend:a,...v}=e,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),g=d.useRef(`_${ke()}`);return ue(t,`${n}`,{defIds:t.defIds,idSuffix:g.current},{ref:r,className:S,...v},a)}function ue(r,e,t,n,o){return d.createElement(r.tag,{key:e,...Ee(r,t,o),...n},($e(r,t).children||[]).map((a,v)=>ue(a,`${e}-${r.tag}-${v}`,t,void 0,o)))}function Ee(r,e,t){const n={...r.attrs};t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+e.idSuffix),Object.entries(n).forEach(([a,v])=>{a==="mask"&&typeof v=="string"&&(n[a]=v.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:o}=e;return!o||o.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(([a,v])=>{typeof v=="string"&&(n[a]=v.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),n}function $e(r,e){var n;const{defIds:t}=e;return!t||t.length===0?r:r.tag==="defs"&&((n=r.children)!=null&&n.length)?{...r,children:r.children.map(o=>typeof o.attrs.id=="string"&&t&&t.includes(o.attrs.id)?{...o,attrs:{...o.attrs,id:o.attrs.id+e.idSuffix}}:o)}:r}function ke(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";const Me={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ve=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"delete-icon",ref:t,icon:Me}))});ve.displayName="DeleteIcon";const Oe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},me=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"increase-icon",ref:t,icon:Oe}))});me.displayName="IncreaseIcon";const je={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z"}}]},he=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"more-horizontal-icon",ref:t,icon:je}))});he.displayName="MoreHorizontalIcon";const Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{stroke:"currentColor",d:"M7.48389 10.3267V12.1905C7.48389 12.7428 7.9316 13.1905 8.48389 13.1905H11.2216L12.2955 14.2644L13.3695 13.1905H14.1593C14.7116 13.1905 15.1593 12.7428 15.1593 12.1905V8.46289C15.1593 7.91061 14.7116 7.46289 14.1593 7.46289H12.2955",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M0.840332 3.73535C0.840332 2.63078 1.73576 1.73535 2.84033 1.73535H10.2955C11.4001 1.73535 12.2955 2.63078 12.2955 3.73535V8.32676C12.2955 9.43132 11.4001 10.3268 10.2955 10.3268H5.6014L4.1695 11.7587L3.05978 10.3268H2.84033C1.73576 10.3268 0.840332 9.43133 0.840332 8.32676V3.73535Z",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.41016 6.1311H6.76813",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M8.91626 6.1311H9.27424",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},fe=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"reply-to-comment-icon",ref:t,icon:Pe}))});fe.displayName="ReplyToCommentIcon";const Le={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6106 15.4036C12.4766 15.4036 15.6106 12.2696 15.6106 8.40356C15.6106 4.53757 12.4766 1.40356 8.6106 1.40356C4.7446 1.40356 1.6106 4.53757 1.6106 8.40356C1.6106 12.2696 4.7446 15.4036 8.6106 15.4036ZM12.3351 6.82773C12.5694 6.59342 12.5694 6.21352 12.3351 5.9792C12.1007 5.74489 11.7208 5.74489 11.4865 5.9792L7.91079 9.55494L6.33506 7.9792C6.10074 7.74489 5.72084 7.74489 5.48653 7.9792C5.25221 8.21352 5.25221 8.59342 5.48653 8.82773L7.48653 10.8277C7.72084 11.062 8.10074 11.062 8.33506 10.8277L12.3351 6.82773Z",fillRule:"evenodd",clipRule:"evenodd"}}]},pe=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"resolved-icon",ref:t,icon:Le}))});pe.displayName="ResolvedIcon";const He={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"circle",attrs:{cx:8.73,cy:8.4,r:6.4,stroke:"currentColor",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.02637 8.40356L8.02637 10.4036L12.0264 6.40356",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}}]},Ce=d.forwardRef(function(e,t){return d.createElement(q,Object.assign({},e,{id:"solve-icon",ref:t,icon:He}))});Ce.displayName="SolveIcon";function ge(r){return{id:"d",body:r,documentStyle:{}}}const Ie=d.forwardRef((r,e)=>{var L;const{comment:t,onSave:n,id:o,onCancel:a,autoFocus:v,unitId:S,type:g}=r,D=m.useDependency(s.ICommandService),$=m.useDependency(s.LocaleService),[W,k]=d.useState(!1),_=m.useDependency(ie.IEditorService),f=d.useRef(null),p=g===s.UniverInstanceType.UNIVER_DOC?s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:S,[M,w]=d.useState(()=>{var h,C,I;return s.BuildTextUtils.transform.getPlainText((I=(C=(h=f.current)==null?void 0:h.getDocumentData().body)==null?void 0:C.dataStream)!=null?I:"")});d.useEffect(()=>{var C,I,T,b;w(s.BuildTextUtils.transform.getPlainText((T=(I=(C=f.current)==null?void 0:C.getDocumentData().body)==null?void 0:I.dataStream)!=null?T:""));const h=(b=f.current)==null?void 0:b.selectionChange$.subscribe(()=>{var l,N,z;w(s.BuildTextUtils.transform.getPlainText((z=(N=(l=f.current)==null?void 0:l.getDocumentData().body)==null?void 0:N.dataStream)!=null?z:""))});return()=>h==null?void 0:h.unsubscribe()},[(L=f.current)==null?void 0:L.selectionChange$]);const Z=d.useMemo(()=>({keyCodes:[{keyCode:m.KeyCode.ENTER}],handler:h=>{h===m.KeyCode.ENTER&&D.executeCommand(ie.BreakLineCommand.id)}}),[D]);d.useImperativeHandle(e,()=>({reply(h){var I,T;if(!f.current)return;_.focus((I=f.current.getEditorId())!=null?I:"");const C=ge(h);(T=f.current)==null||T.setDocumentData(C,[{startOffset:C.body.dataStream.length-2,endOffset:C.body.dataStream.length-2,collapsed:!0}])}}));const x=()=>{if(f.current){const h=s.Tools.deepClone(f.current.getDocumentData().body);k(!1),n==null||n({...t,text:h}),f.current.replaceText(""),setTimeout(()=>{var C,I;(C=f.current)==null||C.setSelectionRanges([]),(I=f.current)==null||I.blur()},10)}};return i.jsxs("div",{onClick:h=>h.preventDefault(),children:[i.jsx(ie.RichTextEditor,{className:"univer-w-full",editorRef:f,editorId:s.DOCS_COMMENT_EDITOR_UNIT_ID_KEY,autoFocus:v,keyboardEventConfig:Z,placeholder:$.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&ge(t.text),onFocusChange:h=>h&&k(h),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{_.focus(p)},30)}}),W?i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[i.jsx(U.Button,{onClick:()=>{var h;a==null||a(),k(!1),(h=f.current)==null||h.replaceText("",!0),D.executeCommand(F.id)},children:$.t("threadCommentUI.editor.cancel")}),i.jsx(U.Button,{variant:"primary",disabled:!M,onClick:x,children:$.t(o?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Ve=r=>{const{dataStream:e,customRanges:t}=r,n=e.endsWith(`\r
7
- `)?e.length-2:e.length,o=[];let a=0;return t==null||t.forEach(v=>{a<v.startIndex&&o.push({type:"text",content:e.slice(a,v.startIndex)}),o.push({type:"mention",content:{label:e.slice(v.startIndex,v.endIndex+1),id:v.rangeId}}),a=v.endIndex+1}),o.push({type:"text",content:e.slice(a,n)}),o},Be=r=>{if(!r)return[];const{paragraphs:e=[]}=r;return e.map((t,n)=>{const o=n===0?0:e[n-1].startIndex+1,a=s.getBodySlice(r,o,t.startIndex);return Ve(a)})},Ae=r=>{let e="";const t=[];return r.forEach(n=>{switch(n.type){case"text":e+=n.content;break;case"mention":{const o=e.length;e+=n.content.label;const a=e.length-1;t.push({rangeId:n.content.id,rangeType:s.CustomRangeType.MENTION,startIndex:o,endIndex:a,properties:{},wholeEntity:!0});break}}}),e+=`\r
8
- `,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},be="__mock__",We=r=>{const{item:e,unitId:t,subUnitId:n,editing:o,onEditingChange:a,onReply:v,resolved:S,isRoot:g,onClose:D,onDeleteComment:$,type:W}=r,k=m.useDependency(s.ICommandService),_=m.useDependency(s.LocaleService),f=m.useDependency(s.UserManagerService),p=f.getUser(e.personId),M=m.useObservable(f.currentUser$),w=(M==null?void 0:M.userID)===e.personId,Z=e.id===be,[x,L]=d.useState(!1),h=m.useConfigValue(m.UI_PLUGIN_CONFIG_KEY),C=h==null?void 0:h.avatarFallback,I=()=>{($==null?void 0:$(e))!==!1&&(k.executeCommand(g?V.DeleteCommentTreeCommand.id:V.DeleteCommentCommand.id,{unitId:t,subUnitId:n,commentId:e.id}),g&&(D==null||D()))};return i.jsxs("div",{className:"univer-relative univer-mb-3 univer-pl-[30px]",onMouseLeave:()=>L(!1),onMouseEnter:()=>L(!0),children:[i.jsx("div",{className:"univer-absolute univer-left-0 univer-top-0 univer-size-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",style:{backgroundImage:`url(${(p==null?void 0:p.avatar)||C})`}}),p?i.jsxs("div",{className:"univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",children:[i.jsx("div",{className:"univer-text-sm univer-font-medium univer-leading-5",children:(p==null?void 0:p.name)||" "}),i.jsxs("div",{children:[Z||S?null:x&&p?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",onClick:()=>v(p),children:i.jsx(fe,{})}):null,w&&!Z&&!S?i.jsx(U.Dropdown,{overlay:i.jsx("div",{className:"univer-rounded-lg",children:i.jsxs("ul",{className:"univer-m-0 univer-box-border univer-grid univer-list-none univer-p-1.5 univer-text-sm [&_a]:univer-block [&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5 [&_a]:univer-transition-colors",children:[i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:()=>a==null?void 0:a(!0),children:_.t("threadCommentUI.item.edit")})}),i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:I,children:_.t("threadCommentUI.item.delete")})})]})}),children:i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",children:i.jsx(he,{})})}):null]})]}):null,i.jsx("time",{className:"univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",children:e.dT}),o?i.jsx(Ie,{type:W,id:e.id,comment:e,onCancel:()=>a==null?void 0:a(!1),autoFocus:!0,unitId:t,subUnitId:n,onSave:({text:T,attachments:b})=>{a==null||a(!1),k.executeCommand(V.UpdateCommentCommand.id,{unitId:t,subUnitId:n,payload:{commentId:e.id,text:T,attachments:b}})}}):i.jsx("div",{className:"univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:Be(e.text).map((T,b)=>i.jsx("div",{className:"univer-break-words",children:T.map((l,N)=>l.type==="mention"?i.jsxs("a",{className:"univer-text-primary-600",children:[l.content.label," "]},N):l.content)},b))})]})},xe=r=>{var re,J,c;const{id:e,unitId:t,subUnitId:n,refStr:o,showEdit:a=!0,onClick:v,showHighlight:S,onClose:g,getSubUnitName:D,prefix:$,autoFocus:W,onMouseEnter:k,onMouseLeave:_,onAddComment:f,onDeleteComment:p,onResolve:M,type:w,style:Z,full:x}=r,L=m.useDependency(V.ThreadCommentModel),[h,C]=d.useState(!1),[I,T]=d.useState(""),b=d.useMemo(()=>L.commentUpdate$.pipe(Q.debounceTime(16)),[L]);m.useObservable(b);const l=e?L.getCommentWithChildren(t,n,e):null,N=m.useDependency(s.ICommandService),z=m.useDependency(s.UserManagerService),O=l==null?void 0:l.root.resolved,j=m.useObservable(z.currentUser$),B=d.useRef(null),Y=[...l?[l.root]:[{id:be,text:{dataStream:`
9
- \r`},personId:(re=j==null?void 0:j.userID)!=null?re:"",ref:o!=null?o:"",dT:"",unitId:t,subUnitId:n,threadId:""}],...(J=l==null?void 0:l.children)!=null?J:[]],H=d.useRef(null),X=y=>{y.stopPropagation(),O?N.executeCommand(F.id,{unitId:t,subUnitId:n,commentId:e}):N.executeCommand(F.id),N.executeCommand(V.ResolveCommentCommand.id,{unitId:t,subUnitId:n,commentId:e,resolved:!O}),M==null||M(!O)},R=y=>{y.stopPropagation(),N.executeCommand(F.id),!(l!=null&&l.root&&(p==null?void 0:p(l.root))===!1)&&(N.executeCommand(V.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:n,commentId:e}),g==null||g())};d.useEffect(()=>_==null?void 0:_(),[]);const ee=D((c=l==null?void 0:l.root.subUnitId)!=null?c:n),te=a&&!I&&!O,ne=`${o||(l==null?void 0:l.root.ref)||""}${ee?" · ":""}${ee}`;return i.jsxs("div",{id:`${$}-${t}-${n}-${e}`,className:U.clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white",U.borderClassName,{"univer-w-[278px]":!x,"univer-w-full":x,"univer-shadow":!O&&(S||h||$==="cell")}),style:Z,onClick:v,onMouseEnter:()=>{k==null||k(),C(!0)},onMouseLeave:()=>{_==null||_(),C(!1)},children:[!O&&S&&i.jsx("div",{className:"univer-absolute univer-left-0 univer-right-0 univer-top-0 univer-h-1.5 univer-rounded-t-md univer-bg-yellow-400"}),i.jsxs("div",{className:"univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",children:[i.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",children:[i.jsx("div",{className:"univer-mr-2 univer-h-3.5 univer-w-[3px] univer-flex-shrink-0 univer-flex-grow-0 univer-rounded-sm univer-bg-yellow-500"}),i.jsx(U.Tooltip,{showIfEllipsis:!0,title:ne,children:i.jsx("span",{className:"univer-flex-1 univer-truncate",children:ne})})]}),!!l&&i.jsxs("div",{className:"univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",children:[i.jsx("div",{className:U.clsx("univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",{"univer-text-green-500":O}),onClick:X,children:O?i.jsx(pe,{}):i.jsx(Ce,{})}),(j==null?void 0:j.userID)===l.root.personId?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",onClick:R,children:i.jsx(ve,{})}):null]})]}),i.jsx("div",{ref:H,className:U.clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden",U.scrollbarClassName),children:Y.map(y=>i.jsx(We,{unitId:t,subUnitId:n,item:y,isRoot:y.id===(l==null?void 0:l.root.id),editing:I===y.id,resolved:l==null?void 0:l.root.resolved,type:w,onClose:g,onEditingChange:P=>{T(P?y.id:"")},onReply:P=>{P&&requestAnimationFrame(()=>{var A;(A=B.current)==null||A.reply(Ae([{type:"mention",content:{id:P.userID,label:`@${P.name}`}},{type:"text",content:" "}]))})},onAddComment:f,onDeleteComment:p},y.id))}),te&&i.jsx("div",{children:i.jsx(Ie,{ref:B,type:w,unitId:t,subUnitId:n,onSave:async({text:y,attachments:P})=>{const A={text:y,attachments:P,dT:V.getDT(),id:s.generateRandomId(),ref:o,personId:j==null?void 0:j.userID,parentId:l==null?void 0:l.root.id,unitId:t,subUnitId:n,threadId:l==null?void 0:l.root.threadId};(f==null?void 0:f(A))!==!1&&(await N.executeCommand(V.AddCommentCommand.id,{unitId:t,subUnitId:n,comment:A}),H.current&&(H.current.scrollTop=H.current.scrollHeight))},autoFocus:W||!l,onCancel:()=>{l||g==null||g()}},`${W}`)})]})},Ze=r=>{const{unitId:e,subUnitId$:t,type:n,onAdd:o,getSubUnitName:a,onResolve:v,sortComments:S,onItemLeave:g,onItemEnter:D,disableAdd:$,tempComment:W,onAddComment:k,onDeleteComment:_,showComments:f}=r,[p,M]=d.useState("all"),[w,Z]=d.useState("all"),x=m.useDependency(s.LocaleService),L=m.useDependency(s.UserManagerService),h=m.useDependency(V.ThreadCommentModel),[C,I]=d.useState(()=>h.getUnit(e)),T=m.useDependency(u.ThreadCommentPanelService),b=m.useObservable(T.activeCommentId$),l=m.useObservable(h.commentUpdate$),N=m.useDependency(s.ICommandService),z=m.useObservable(t),O=d.useRef(!0),j="panel",B=m.useObservable(L.currentUser$),Y=d.useMemo(()=>{var A;const c=p==="all"?C:(A=C.filter(E=>E.subUnitId===z))!=null?A:[],y=S!=null?S:(E=>E),P=c.map(E=>{var K;return{...E.root,children:(K=E.children)!=null?K:[],users:E.relativeUsers}});if(f){const E=new Map;return P.forEach(K=>{E.set(K.id,K)}),[...f,""].map(K=>E.get(K)).filter(Boolean)}else return y(P)},[f,p,C,S,z]),H=d.useMemo(()=>[...Y.filter(c=>!c.resolved),...Y.filter(c=>c.resolved)],[Y]),X=d.useMemo(()=>w==="resolved"?H.filter(c=>c.resolved):w==="unsolved"?H.filter(c=>!c.resolved):w==="concern_me"&&B!=null&&B.userID?H.filter(c=>c==null?void 0:c.users.has(B.userID)):H,[H,B==null?void 0:B.userID,w]),R=W?[W,...X]:X,ee=R.filter(c=>!c.resolved),te=R.filter(c=>c.resolved),ne=w!=="all"||p!=="all",re=()=>{Z("all"),M("all")};d.useEffect(()=>{e&&I(h.getUnit(e))},[e,h,l]),d.useEffect(()=>{var E;if(!b)return;if(!O.current){O.current=!0;return}const{unitId:c,subUnitId:y,commentId:P}=b,A=`${j}-${c}-${y}-${P}`;(E=document.getElementById(A))==null||E.scrollIntoView({block:"center"})},[b]);const J=c=>i.jsx(xe,{prefix:j,getSubUnitName:a,id:c.id,unitId:c.unitId,subUnitId:c.subUnitId,refStr:c.ref,type:n,showEdit:(b==null?void 0:b.commentId)===c.id,showHighlight:(b==null?void 0:b.commentId)===c.id,onClick:()=>{O.current=!1,c.resolved?N.executeCommand(F.id):N.executeCommand(F.id,{unitId:c.unitId,subUnitId:c.subUnitId,commentId:c.id,temp:!1})},onMouseEnter:()=>D==null?void 0:D(c),onMouseLeave:()=>g==null?void 0:g(c),onAddComment:k,onDeleteComment:_,onResolve:y=>v==null?void 0:v(c.id,y)},c.id);return i.jsxs("div",{className:"univer-flex univer-min-h-full univer-flex-col univer-pb-3",children:[i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-between",children:[n===s.UniverInstanceType.UNIVER_SHEET?i.jsx(U.Select,{borderless:!0,value:p,options:[{value:"current",label:x.t("threadCommentUI.filter.sheet.current")},{value:"all",label:x.t("threadCommentUI.filter.sheet.all")}],onChange:M}):null,i.jsx(U.Select,{borderless:!0,value:w,options:[{value:"all",label:x.t("threadCommentUI.filter.status.all")},{value:"resolved",label:x.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:x.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:x.t("threadCommentUI.filter.status.concernMe")}],onChange:Z})]}),R.length===0?i.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:[x.t("threadCommentUI.panel.empty"),ne?i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsx(U.Button,{onClick:re,children:x.t("threadCommentUI.panel.reset")})}):$?null:i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsxs(U.Button,{onClick:o,children:[i.jsx(me,{className:"univer-mr-1.5"}),x.t("threadCommentUI.panel.addComment")]})})]}):i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-col univer-gap-3",children:[ee.map(J),te.length>0&&i.jsx("div",{className:"univer-text-xs",children:x.t("threadCommentUI.panel.solved")}),te.map(J)]})]})};u.SetActiveCommentOperation=F,u.THREAD_COMMENT_PANEL=ae,u.ThreadCommentPanel=Ze,u.ThreadCommentTree=xe,u.ToggleSheetCommentPanelOperation=le,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
6
+ (function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/thread-comment"),require("react/jsx-runtime"),require("@univerjs/design"),require("react"),require("@univerjs/docs-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/thread-comment","react/jsx-runtime","@univerjs/design","react","@univerjs/docs-ui"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.UniverThreadCommentUi={},d.UniverCore,d.UniverUi,d.rxjs,d.UniverThreadComment,d.React,d.UniverDesign,d.React,d.UniverDocsUi))})(this,(function(d,s,m,Q,V,i,N,c,se){"use strict";var qe=Object.defineProperty;var ze=(d,s,m)=>s in d?qe(d,s,{enumerable:!0,configurable:!0,writable:!0,value:m}):d[s]=m;var G=(d,s,m)=>ze(d,typeof s!="symbol"?s+"":s,m);var Se=Object.getOwnPropertyDescriptor,_e=(r,e,t,n)=>{for(var o=n>1?void 0:n?Se(e,t):e,a=r.length-1,v;a>=0;a--)(v=r[a])&&(o=v(o)||o);return o},ae=(r,e)=>(t,n)=>e(t,n,r);d.ThreadCommentPanelService=class extends s.Disposable{constructor(t,n){super();G(this,"_panelVisible",!1);G(this,"_panelVisible$",new Q.BehaviorSubject(!1));G(this,"_activeCommentId");G(this,"_activeCommentId$",new Q.BehaviorSubject(void 0));G(this,"panelVisible$",this._panelVisible$.asObservable());G(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._activeCommentId$.complete(),this._panelVisible$.complete()})}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).pipe(Q.filter(t=>!t)).subscribe(()=>{this._sidebarService.close()}))}get panelVisible(){return this._panelVisible}get activeCommentId(){return this._activeCommentId}setPanelVisible(t){this._panelVisible=t,this._panelVisible$.next(t)}setActiveComment(t){this._activeCommentId=t,this._activeCommentId$.next(t)}},d.ThreadCommentPanelService=_e([ae(0,s.Inject(m.ISidebarService)),ae(1,s.IUniverInstanceService)],d.ThreadCommentPanelService);const le="thread-comment-panel",we="UNIVER_THREAD_COMMENT_UI_PLUGIN",de={id:"thread-comment-ui.operation.toggle-panel",type:s.CommandType.OPERATION,handler(r){const e=r.get(m.ISidebarService),t=r.get(d.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:le},width:360}),t.setPanelVisible(!0)),!0}},F={id:"thread-comment-ui.operation.set-active-comment",type:s.CommandType.OPERATION,handler(r,e){return r.get(d.ThreadCommentPanelService).setActiveComment(e),!0}},ce={name:"@univerjs/thread-comment-ui",version:"0.17.0"},Te="thread-comment-ui.config",ue={};var Ue=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,De=(r,e,t)=>e in r?Ue(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ee=(r,e,t,n)=>{for(var o=n>1?void 0:n?Ne(e,t):e,a=r.length-1,v;a>=0;a--)(v=r[a])&&(o=v(o)||o);return o},oe=(r,e)=>(t,n)=>e(t,n,r),X=(r,e,t)=>De(r,typeof e!="symbol"?e+"":e,t);d.UniverThreadCommentUIPlugin=class extends s.Plugin{constructor(e=ue,t,n,o){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=o;const{menu:a,...v}=s.merge({},ue,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(Te,v)}onStarting(){var e;s.mergeOverrideWithDependencies([[d.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[de,F].forEach(t=>{this._commandService.registerCommand(t)})}},X(d.UniverThreadCommentUIPlugin,"pluginName",we),X(d.UniverThreadCommentUIPlugin,"packageName",ce.name),X(d.UniverThreadCommentUIPlugin,"version",ce.version),X(d.UniverThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_UNKNOWN),d.UniverThreadCommentUIPlugin=Ee([s.DependentOn(V.UniverThreadCommentPlugin),oe(1,s.Inject(s.Injector)),oe(2,s.ICommandService),oe(3,s.IConfigService)],d.UniverThreadCommentUIPlugin);function q({ref:r,...e}){const{icon:t,id:n,className:o,extend:a,...v}=e,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),g=c.useRef(`_${Me()}`);return ve(t,`${n}`,{defIds:t.defIds,idSuffix:g.current},{ref:r,className:S,...v},a)}function ve(r,e,t,n,o){return c.createElement(r.tag,{key:e,...ke(r,t,o),...n},($e(r,t).children||[]).map((a,v)=>ve(a,`${e}-${r.tag}-${v}`,t,void 0,o)))}function ke(r,e,t){const n={...r.attrs};t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+e.idSuffix),Object.entries(n).forEach(([a,v])=>{a==="mask"&&typeof v=="string"&&(n[a]=v.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:o}=e;return!o||o.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(([a,v])=>{typeof v=="string"&&(n[a]=v.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),n}function $e(r,e){var n;const{defIds:t}=e;return!t||t.length===0?r:r.tag==="defs"&&((n=r.children)!=null&&n.length)?{...r,children:r.children.map(o=>typeof o.attrs.id=="string"&&t&&t.includes(o.attrs.id)?{...o,attrs:{...o.attrs,id:o.attrs.id+e.idSuffix}}:o)}:r}function Me(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";const Oe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},me=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"delete-icon",ref:t,icon:Oe}))});me.displayName="DeleteIcon";const je={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},he=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"increase-icon",ref:t,icon:je}))});he.displayName="IncreaseIcon";const Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z"}}]},fe=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"more-horizontal-icon",ref:t,icon:Pe}))});fe.displayName="MoreHorizontalIcon";const Le={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{stroke:"currentColor",d:"M7.48389 10.3267V12.1905C7.48389 12.7428 7.9316 13.1905 8.48389 13.1905H11.2216L12.2955 14.2644L13.3695 13.1905H14.1593C14.7116 13.1905 15.1593 12.7428 15.1593 12.1905V8.46289C15.1593 7.91061 14.7116 7.46289 14.1593 7.46289H12.2955",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M0.840332 3.73535C0.840332 2.63078 1.73576 1.73535 2.84033 1.73535H10.2955C11.4001 1.73535 12.2955 2.63078 12.2955 3.73535V8.32676C12.2955 9.43132 11.4001 10.3268 10.2955 10.3268H5.6014L4.1695 11.7587L3.05978 10.3268H2.84033C1.73576 10.3268 0.840332 9.43133 0.840332 8.32676V3.73535Z",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.41016 6.1311H6.76813",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M8.91626 6.1311H9.27424",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},Ce=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"reply-to-comment-icon",ref:t,icon:Le}))});Ce.displayName="ReplyToCommentIcon";const He={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6106 15.4036C12.4766 15.4036 15.6106 12.2696 15.6106 8.40356C15.6106 4.53757 12.4766 1.40356 8.6106 1.40356C4.7446 1.40356 1.6106 4.53757 1.6106 8.40356C1.6106 12.2696 4.7446 15.4036 8.6106 15.4036ZM12.3351 6.82773C12.5694 6.59342 12.5694 6.21352 12.3351 5.9792C12.1007 5.74489 11.7208 5.74489 11.4865 5.9792L7.91079 9.55494L6.33506 7.9792C6.10074 7.74489 5.72084 7.74489 5.48653 7.9792C5.25221 8.21352 5.25221 8.59342 5.48653 8.82773L7.48653 10.8277C7.72084 11.062 8.10074 11.062 8.33506 10.8277L12.3351 6.82773Z",fillRule:"evenodd",clipRule:"evenodd"}}]},pe=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"resolved-icon",ref:t,icon:He}))});pe.displayName="ResolvedIcon";const Ve={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"circle",attrs:{cx:8.73,cy:8.4,r:6.4,stroke:"currentColor",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.02637 8.40356L8.02637 10.4036L12.0264 6.40356",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}}]},ge=c.forwardRef(function(e,t){return c.createElement(q,Object.assign({},e,{id:"solve-icon",ref:t,icon:Ve}))});ge.displayName="SolveIcon";function Ie(r){return{id:"d",body:r,documentStyle:{}}}const be=c.forwardRef((r,e)=>{var L;const{comment:t,onSave:n,id:o,onCancel:a,autoFocus:v,unitId:S,type:g}=r,D=m.useDependency(s.ICommandService),k=m.useDependency(s.LocaleService),[W,$]=c.useState(!1),_=m.useDependency(se.IEditorService),f=c.useRef(null),C=g===s.UniverInstanceType.UNIVER_DOC?s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:S,[M,w]=c.useState(()=>{var h,p,I;return s.BuildTextUtils.transform.getPlainText((I=(p=(h=f.current)==null?void 0:h.getDocumentData().body)==null?void 0:p.dataStream)!=null?I:"")});c.useEffect(()=>{var p,I,T,b;w(s.BuildTextUtils.transform.getPlainText((T=(I=(p=f.current)==null?void 0:p.getDocumentData().body)==null?void 0:I.dataStream)!=null?T:""));const h=(b=f.current)==null?void 0:b.selectionChange$.subscribe(()=>{var l,U,z;w(s.BuildTextUtils.transform.getPlainText((z=(U=(l=f.current)==null?void 0:l.getDocumentData().body)==null?void 0:U.dataStream)!=null?z:""))});return()=>h==null?void 0:h.unsubscribe()},[(L=f.current)==null?void 0:L.selectionChange$]);const Z=c.useMemo(()=>({keyCodes:[{keyCode:m.KeyCode.ENTER}],handler:h=>{h===m.KeyCode.ENTER&&D.executeCommand(se.BreakLineCommand.id)}}),[D]);c.useImperativeHandle(e,()=>({reply(h){var I,T;if(!f.current)return;_.focus((I=f.current.getEditorId())!=null?I:"");const p=Ie(h);(T=f.current)==null||T.setDocumentData(p,[{startOffset:p.body.dataStream.length-2,endOffset:p.body.dataStream.length-2,collapsed:!0}])}}));const x=()=>{if(f.current){const h=s.Tools.deepClone(f.current.getDocumentData().body);$(!1),n==null||n({...t,text:h}),f.current.replaceText(""),setTimeout(()=>{var p,I;(p=f.current)==null||p.setSelectionRanges([]),(I=f.current)==null||I.blur()},10)}};return i.jsxs("div",{onClick:h=>h.preventDefault(),children:[i.jsx(se.RichTextEditor,{className:"univer-w-full",editorRef:f,editorId:s.DOCS_COMMENT_EDITOR_UNIT_ID_KEY,autoFocus:v,keyboardEventConfig:Z,placeholder:k.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&Ie(t.text),onFocusChange:h=>h&&$(h),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{_.focus(C)},30)}}),W?i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[i.jsx(N.Button,{onClick:()=>{var h;a==null||a(),$(!1),(h=f.current)==null||h.replaceText("",!0),D.executeCommand(F.id)},children:k.t("threadCommentUI.editor.cancel")}),i.jsx(N.Button,{variant:"primary",disabled:!M,onClick:x,children:k.t(o?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Be=r=>{const{dataStream:e,customRanges:t}=r,n=e.endsWith(`\r
7
+ `)?e.length-2:e.length,o=[];let a=0;return t==null||t.forEach(v=>{a<v.startIndex&&o.push({type:"text",content:e.slice(a,v.startIndex)}),o.push({type:"mention",content:{label:e.slice(v.startIndex,v.endIndex+1),id:v.rangeId}}),a=v.endIndex+1}),o.push({type:"text",content:e.slice(a,n)}),o},Ae=r=>{if(!r)return[];const{paragraphs:e=[]}=r;return e.map((t,n)=>{const o=n===0?0:e[n-1].startIndex+1,a=s.getBodySlice(r,o,t.startIndex);return Be(a)})},We=r=>{let e="";const t=[];return r.forEach(n=>{switch(n.type){case"text":e+=n.content;break;case"mention":{const o=e.length;e+=n.content.label;const a=e.length-1;t.push({rangeId:n.content.id,rangeType:s.CustomRangeType.MENTION,startIndex:o,endIndex:a,properties:{},wholeEntity:!0});break}}}),e+=`\r
8
+ `,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},xe="__mock__",Ze=r=>{const{item:e,unitId:t,subUnitId:n,editing:o,onEditingChange:a,onReply:v,resolved:S,isRoot:g,onClose:D,onDeleteComment:k,type:W}=r,$=m.useDependency(s.ICommandService),_=m.useDependency(s.LocaleService),f=m.useDependency(s.UserManagerService),C=f.getUser(e.personId),M=m.useObservable(f.currentUser$),w=(M==null?void 0:M.userID)===e.personId,Z=e.id===xe,[x,L]=c.useState(!1),h=m.useConfigValue(m.UI_PLUGIN_CONFIG_KEY),p=h==null?void 0:h.avatarFallback,I=()=>{(k==null?void 0:k(e))!==!1&&($.executeCommand(g?V.DeleteCommentTreeCommand.id:V.DeleteCommentCommand.id,{unitId:t,subUnitId:n,commentId:e.id}),g&&(D==null||D()))};return i.jsxs("div",{className:"univer-relative univer-mb-3 univer-pl-[30px]",onMouseLeave:()=>L(!1),onMouseEnter:()=>L(!0),children:[i.jsx("div",{className:"univer-absolute univer-left-0 univer-top-0 univer-size-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",style:{backgroundImage:`url(${(C==null?void 0:C.avatar)||p})`}}),C?i.jsxs("div",{className:"univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",children:[i.jsx("div",{className:"univer-text-sm univer-font-medium univer-leading-5",children:(C==null?void 0:C.name)||" "}),i.jsxs("div",{children:[Z||S?null:x&&C?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",onClick:()=>v(C),children:i.jsx(Ce,{})}):null,w&&!Z&&!S?i.jsx(N.Dropdown,{overlay:i.jsx("div",{className:"univer-rounded-lg",children:i.jsxs("ul",{className:"univer-m-0 univer-box-border univer-grid univer-list-none univer-p-1.5 univer-text-sm [&_a]:univer-block [&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5 [&_a]:univer-transition-colors",children:[i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:()=>a==null?void 0:a(!0),children:_.t("threadCommentUI.item.edit")})}),i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:I,children:_.t("threadCommentUI.item.delete")})})]})}),children:i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",children:i.jsx(fe,{})})}):null]})]}):null,i.jsx("time",{className:"univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",children:e.dT}),o?i.jsx(be,{type:W,id:e.id,comment:e,onCancel:()=>a==null?void 0:a(!1),autoFocus:!0,unitId:t,subUnitId:n,onSave:({text:T,attachments:b})=>{a==null||a(!1),$.executeCommand(V.UpdateCommentCommand.id,{unitId:t,subUnitId:n,payload:{commentId:e.id,text:T,attachments:b}})}}):i.jsx("div",{className:"univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:Ae(e.text).map((T,b)=>i.jsx("div",{className:"univer-break-words",children:T.map((l,U)=>l.type==="mention"?i.jsxs("a",{className:"univer-text-primary-600",children:[l.content.label," "]},U):l.content)},b))})]})},ye=r=>{var ie,J,u;const{id:e,unitId:t,subUnitId:n,refStr:o,showEdit:a=!0,onClick:v,showHighlight:S,onClose:g,getSubUnitName:D,prefix:k,autoFocus:W,onMouseEnter:$,onMouseLeave:_,onAddComment:f,onDeleteComment:C,onResolve:M,type:w,style:Z,full:x}=r,L=m.useDependency(V.ThreadCommentModel),[h,p]=c.useState(!1),[I,T]=c.useState(""),b=c.useMemo(()=>L.commentUpdate$.pipe(Q.debounceTime(16)),[L]);m.useObservable(b);const l=e?L.getCommentWithChildren(t,n,e):null,U=m.useDependency(s.ICommandService),z=m.useDependency(s.UserManagerService),O=l==null?void 0:l.root.resolved,j=m.useObservable(z.currentUser$),B=c.useRef(null),Y=[...l?[l.root]:[{id:xe,text:{dataStream:`
9
+ \r`},personId:(ie=j==null?void 0:j.userID)!=null?ie:"",ref:o!=null?o:"",dT:"",unitId:t,subUnitId:n,threadId:""}],...(J=l==null?void 0:l.children)!=null?J:[]],H=c.useRef(null),ee=y=>{y.stopPropagation(),O?U.executeCommand(F.id,{unitId:t,subUnitId:n,commentId:e}):U.executeCommand(F.id),U.executeCommand(V.ResolveCommentCommand.id,{unitId:t,subUnitId:n,commentId:e,resolved:!O}),M==null||M(!O)},R=y=>{y.stopPropagation(),U.executeCommand(F.id),!(l!=null&&l.root&&(C==null?void 0:C(l.root))===!1)&&(U.executeCommand(V.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:n,commentId:e}),g==null||g())};c.useEffect(()=>_==null?void 0:_(),[]);const te=D((u=l==null?void 0:l.root.subUnitId)!=null?u:n),ne=a&&!I&&!O,re=`${o||(l==null?void 0:l.root.ref)||""}${te?" · ":""}${te}`;return i.jsxs("div",{id:`${k}-${t}-${n}-${e}`,className:N.clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white",N.borderClassName,{"univer-w-[278px]":!x,"univer-w-full":x,"univer-shadow":!O&&(S||h||k==="cell")}),style:Z,onClick:v,onMouseEnter:()=>{$==null||$(),p(!0)},onMouseLeave:()=>{_==null||_(),p(!1)},children:[!O&&S&&i.jsx("div",{className:"univer-absolute univer-left-0 univer-right-0 univer-top-0 univer-h-1.5 univer-rounded-t-md univer-bg-yellow-400"}),i.jsxs("div",{className:"univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",children:[i.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",children:[i.jsx("div",{className:"univer-mr-2 univer-h-3.5 univer-w-[3px] univer-flex-shrink-0 univer-flex-grow-0 univer-rounded-sm univer-bg-yellow-500"}),i.jsx(N.Tooltip,{showIfEllipsis:!0,title:re,children:i.jsx("span",{className:"univer-flex-1 univer-truncate",children:re})})]}),!!l&&i.jsxs("div",{className:"univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",children:[i.jsx("div",{className:N.clsx("univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",{"univer-text-green-500":O}),onClick:ee,children:O?i.jsx(pe,{}):i.jsx(ge,{})}),(j==null?void 0:j.userID)===l.root.personId?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",onClick:R,children:i.jsx(me,{})}):null]})]}),i.jsx("div",{ref:H,className:N.clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden",N.scrollbarClassName),children:Y.map(y=>i.jsx(Ze,{unitId:t,subUnitId:n,item:y,isRoot:y.id===(l==null?void 0:l.root.id),editing:I===y.id,resolved:l==null?void 0:l.root.resolved,type:w,onClose:g,onEditingChange:P=>{T(P?y.id:"")},onReply:P=>{P&&requestAnimationFrame(()=>{var A;(A=B.current)==null||A.reply(We([{type:"mention",content:{id:P.userID,label:`@${P.name}`}},{type:"text",content:" "}]))})},onAddComment:f,onDeleteComment:C},y.id))}),ne&&i.jsx("div",{children:i.jsx(be,{ref:B,type:w,unitId:t,subUnitId:n,onSave:async({text:y,attachments:P})=>{const A={text:y,attachments:P,dT:V.getDT(),id:s.generateRandomId(),ref:o,personId:j==null?void 0:j.userID,parentId:l==null?void 0:l.root.id,unitId:t,subUnitId:n,threadId:l==null?void 0:l.root.threadId};(f==null?void 0:f(A))!==!1&&(await U.executeCommand(V.AddCommentCommand.id,{unitId:t,subUnitId:n,comment:A}),H.current&&(H.current.scrollTop=H.current.scrollHeight))},autoFocus:W||!l,onCancel:()=>{l||g==null||g()}},`${W}`)})]})},Fe=r=>{const{unitId:e,subUnitId$:t,type:n,onAdd:o,getSubUnitName:a,onResolve:v,sortComments:S,onItemLeave:g,onItemEnter:D,disableAdd:k,tempComment:W,onAddComment:$,onDeleteComment:_,showComments:f}=r,[C,M]=c.useState("all"),[w,Z]=c.useState("all"),x=m.useDependency(s.LocaleService),L=m.useDependency(s.UserManagerService),h=m.useDependency(V.ThreadCommentModel),[p,I]=c.useState(()=>h.getUnit(e)),T=m.useDependency(d.ThreadCommentPanelService),b=m.useObservable(T.activeCommentId$),l=m.useObservable(h.commentUpdate$),U=m.useDependency(s.ICommandService),z=m.useObservable(t),O=c.useRef(!0),j="panel",B=m.useObservable(L.currentUser$),Y=c.useMemo(()=>{var A;const u=C==="all"?p:(A=p.filter(E=>E.subUnitId===z))!=null?A:[],y=S!=null?S:(E=>E),P=u.map(E=>{var K;return{...E.root,children:(K=E.children)!=null?K:[],users:E.relativeUsers}});if(f){const E=new Map;return P.forEach(K=>{E.set(K.id,K)}),[...f,""].map(K=>E.get(K)).filter(Boolean)}else return y(P)},[f,C,p,S,z]),H=c.useMemo(()=>[...Y.filter(u=>!u.resolved),...Y.filter(u=>u.resolved)],[Y]),ee=c.useMemo(()=>w==="resolved"?H.filter(u=>u.resolved):w==="unsolved"?H.filter(u=>!u.resolved):w==="concern_me"&&B!=null&&B.userID?H.filter(u=>u==null?void 0:u.users.has(B.userID)):H,[H,B==null?void 0:B.userID,w]),R=W?[W,...ee]:ee,te=R.filter(u=>!u.resolved),ne=R.filter(u=>u.resolved),re=w!=="all"||C!=="all",ie=()=>{Z("all"),M("all")};c.useEffect(()=>{e&&I(h.getUnit(e))},[e,h,l]),c.useEffect(()=>{var E;if(!b)return;if(!O.current){O.current=!0;return}const{unitId:u,subUnitId:y,commentId:P}=b,A=`${j}-${u}-${y}-${P}`;(E=document.getElementById(A))==null||E.scrollIntoView({block:"center"})},[b]);const J=u=>i.jsx(ye,{prefix:j,getSubUnitName:a,id:u.id,unitId:u.unitId,subUnitId:u.subUnitId,refStr:u.ref,type:n,showEdit:(b==null?void 0:b.commentId)===u.id,showHighlight:(b==null?void 0:b.commentId)===u.id,onClick:()=>{O.current=!1,u.resolved?U.executeCommand(F.id):U.executeCommand(F.id,{unitId:u.unitId,subUnitId:u.subUnitId,commentId:u.id,temp:!1})},onMouseEnter:()=>D==null?void 0:D(u),onMouseLeave:()=>g==null?void 0:g(u),onAddComment:$,onDeleteComment:_,onResolve:y=>v==null?void 0:v(u.id,y)},u.id);return i.jsxs("div",{className:"univer-flex univer-min-h-full univer-flex-col univer-pb-3",children:[i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-between",children:[n===s.UniverInstanceType.UNIVER_SHEET?i.jsx(N.Select,{borderless:!0,value:C,options:[{value:"current",label:x.t("threadCommentUI.filter.sheet.current")},{value:"all",label:x.t("threadCommentUI.filter.sheet.all")}],onChange:M}):null,i.jsx(N.Select,{borderless:!0,value:w,options:[{value:"all",label:x.t("threadCommentUI.filter.status.all")},{value:"resolved",label:x.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:x.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:x.t("threadCommentUI.filter.status.concernMe")}],onChange:Z})]}),R.length===0?i.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:[x.t("threadCommentUI.panel.empty"),re?i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsx(N.Button,{onClick:ie,children:x.t("threadCommentUI.panel.reset")})}):k?null:i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsxs(N.Button,{onClick:o,children:[i.jsx(he,{className:"univer-mr-1.5"}),x.t("threadCommentUI.panel.addComment")]})})]}):i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-col univer-gap-3",children:[te.map(J),ne.length>0&&i.jsx("div",{className:"univer-text-xs",children:x.t("threadCommentUI.panel.solved")}),ne.map(J)]})]})};d.SetActiveCommentOperation=F,d.THREAD_COMMENT_PANEL=le,d.ThreadCommentPanel=Fe,d.ThreadCommentTree=ye,d.ToggleSheetCommentPanelOperation=de,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
10
10
 
11
11
 
12
12
  // @univerjs/docs-thread-comment-ui/index
13
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/thread-comment","@univerjs/thread-comment-ui","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","react"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverDocsThreadCommentUi={},c.UniverCore,c.UniverDocsUi,c.UniverThreadComment,c.UniverThreadCommentUi,c.UniverDocs,c.UniverEngineRender,c.UniverUi,c.rxjs,c.React,c.React))})(this,(function(c,o,S,$,_,T,y,u,E,ne,D){"use strict";var Oe=Object.defineProperty;var Ue=(c,o,S)=>o in c?Oe(c,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):c[o]=S;var J=(c,o,S)=>Ue(c,typeof o!="symbol"?o+"":o,S);const ie="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",F={id:"docs.command.add-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:i,unitId:n}=t,s=await e.get($.IThreadCommentDataSourceService).addComment(i),d=e.get(o.ICommandService),a=S.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(a){const h={id:$.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},f={id:_.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([h,a,f],d)).result}return!1}},H={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:i,unitId:n}=t,r=e.get(o.ICommandService),s=S.deleteCustomDecorationFactory(e,{id:i,unitId:n});return s?(await o.sequenceExecute([s],r)).result:!1}};var re=Object.getOwnPropertyDescriptor,oe=(e,t,i,n)=>{for(var r=n>1?void 0:n?re(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},Y=(e,t)=>(i,n)=>t(i,n,e);let R=class extends o.Disposable{constructor(t,i){super();J(this,"_addingComment$",new E.BehaviorSubject(void 0));J(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=i,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};R=oe([Y(0,u.ISidebarService),Y(1,o.Inject(_.ThreadCommentPanelService))],R);const z=e=>{var d;const t=e.get(y.IRenderManagerService),i=e.get(T.DocSelectionManagerService),n=(d=y.withCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_DOC,T.DocSkeletonManagerService,e.get(o.IUniverInstanceService),t))==null?void 0:d.getSkeleton(),r=n==null?void 0:n.getViewModel().getEditArea();if(r===y.DocumentEditArea.FOOTER||r===y.DocumentEditArea.HEADER)return!0;const s=i.getActiveTextRange();return!!(s==null||s.collapsed)};function se(e){return{id:w.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,void 0,o.SHEET_EDITOR_UNITS),disabled$:new E.Observable(function(t){const n=e.get(T.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}function de(e){return{id:L.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC)}}const b=()=>{const e=u.useDependency(o.IUniverInstanceService),t=u.useDependency(o.Injector),i=D.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(E.filter(m=>!!m&&!o.isInternalEditorID(m.getUnitId()))),[e]),n=u.useObservable(i),r=D.useMemo(()=>new E.Observable(m=>m.next(M)),[]),s=u.useDependency(T.DocSelectionManagerService),d=D.useMemo(()=>s.textSelection$.pipe(E.debounceTime(16)),[s.textSelection$]);u.useObservable(d);const a=u.useDependency(o.ICommandService),h=u.useDependency(R),f=u.useObservable(h.addingComment$),[l,I]=D.useState([]);if(D.useEffect(()=>{var A;const m=new Set,C=n==null?void 0:n.getCustomDecorations();I((A=C==null?void 0:C.map(v=>v.id).filter(v=>{const U=m.has(v);return m.add(v),!U}))!=null?A:[]);const O=a.onCommandExecuted(v=>{var U;if(v.id===T.RichTextEditingMutation.id){const N=new Set,G=n==null?void 0:n.getCustomDecorations();I((U=G==null?void 0:G.map(q=>q.id).filter(q=>{const Me=N.has(q);return N.add(q),!Me}))!=null?U:[])}});return()=>{O.dispose()}},[a,n]),!n)return null;const g=z(t),p=n.getUnitId();return ne.jsx(_.ThreadCommentPanel,{unitId:p,subUnitId$:r,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{a.executeCommand(w.id)},getSubUnitName:()=>"",disableAdd:g,tempComment:f,onAddComment:m=>{if(!m.parentId){const C={unitId:p,range:f,comment:m};return a.executeCommand(F.id,C),h.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const C={unitId:p,commentId:m.id};return a.executeCommand(H.id,C),!1}return!0},showComments:l})};b.componentKey="univer.doc.thread-comment-panel";const j={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var r;const i=e.get(_.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!i.panelVisible||((r=n.options.children)==null?void 0:r.label)!==b.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>i.setPanelVisible(!1)}),i.setPanelVisible(!0)),t&&i.setActiveComment(t==null?void 0:t.activeComment),!0}},L={id:"docs.operation.toggle-comment-panel",type:o.CommandType.OPERATION,handler(e){var n;const t=e.get(_.ThreadCommentPanelService),i=e.get(u.ISidebarService);return!t.panelVisible||((n=i.options.children)==null?void 0:n.label)!==b.componentKey?(i.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(i.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},w={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var v,U,N;const t=e.get(_.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),r=e.get(T.DocSelectionManagerService),s=e.get(y.IRenderManagerService),d=e.get(o.UserManagerService),a=e.get(R),h=e.get(o.ICommandService),f=e.get(u.ISidebarService),l=r.getActiveTextRange();if(!n||!l)return!1;const I=(v=s.getRenderById(n.getUnitId()))==null?void 0:v.with(S.DocSelectionRenderService);if(I==null||I.setReserveRangesStatus(!0),l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),f.close()):h.executeCommand(j.id),!0;h.executeCommand(j.id);const g=n.getUnitId(),p=((N=(U=n.getBody())==null?void 0:U.dataStream)!=null?N:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(p),C=M,O="",A={unitId:g,subUnitId:C,id:O,ref:m,dT:$.getDT(),personId:d.getCurrentUser().userID,text:{dataStream:`\r
14
- `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:O};return I==null||I.blur(),a.startAdd(A),t.setActiveComment({unitId:g,subUnitId:C,commentId:O}),!0}},ae="docs-thread-comment-ui.config",Q={};var ce=Object.getOwnPropertyDescriptor,me=(e,t,i,n)=>{for(var r=n>1?void 0:n?ce(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},x=(e,t)=>(i,n)=>t(i,n,e);let V=class extends o.Disposable{constructor(e,t,i,n,r,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=i,this._docThreadCommentService=n,this._renderManagerService=r,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i,n,r,s;if(t.id===T.SetTextSelectionsOperation.id){const d=t.params,{unitId:a,ranges:h}=d;if(o.isInternalEditorID(a))return;const f=this._univerInstanceService.getUnit(a,o.UniverInstanceType.UNIVER_DOC),l=h[0];if((e==null?void 0:e.startOffset)===(l==null?void 0:l.startOffset)&&(e==null?void 0:e.endOffset)===(l==null?void 0:l.endOffset))return;if(e=l,l&&f){const{startOffset:I,endOffset:g,collapsed:p}=l;let m;if(p?m=(n=(i=f.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(C=>C.startIndex<=I&&C.endIndex>=g-1):m=(s=(r=f.getBody())==null?void 0:r.customDecorations)==null?void 0:s.find(C=>C.startIndex<=I&&C.endIndex>=g-1),m){const C=this._threadCommentModel.getComment(a,M,m.id);C&&!C.resolved&&this._commandService.executeCommand(j.id,{activeComment:{unitId:a,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(_.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,i,n,r;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const d=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(S.DocBackScrollRenderController),a=(n=(i=s.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(h=>h.id===e.commentId);a&&d&&d.scrollToRange({startOffset:a.startIndex,endOffset:a.endIndex,collapsed:!1})}}(!e||e.commentId!==((r=this._docThreadCommentService.addingComment)==null?void 0:r.id))&&this._docThreadCommentService.endAdd()}))}};V=me([x(0,o.Inject(_.ThreadCommentPanelService)),x(1,o.IUniverInstanceService),x(2,o.ICommandService),x(3,o.Inject(R)),x(4,y.IRenderManagerService),x(5,o.Inject($.ThreadCommentModel))],V);function X({ref:e,...t}){const{icon:i,id:n,className:r,extend:s,...d}=t,a=`univerjs-icon univerjs-icon-${n} ${r||""}`.trim(),h=D.useRef(`_${Ce()}`);return k(i,`${n}`,{defIds:i.defIds,idSuffix:h.current},{ref:e,className:a,...d},s)}function k(e,t,i,n,r){return D.createElement(e.tag,{key:t,...le(e,i,r),...n},(ue(e,i).children||[]).map((s,d)=>k(s,`${t}-${e.tag}-${d}`,i,void 0,r)))}function le(e,t,i){const n={...e.attrs};i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([s,d])=>{s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,d])=>{typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function ue(e,t){var n;const{defIds:i}=t;return!i||i.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&i&&i.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function Ce(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";const he={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ee=D.forwardRef(function(t,i){return D.createElement(X,Object.assign({},t,{id:"comment-icon",ref:i,icon:he}))});ee.displayName="CommentIcon";const ve={[u.RibbonInsertGroup.MEDIA]:{[L.id]:{order:3,menuItemFactory:de}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[w.id]:{order:1,menuItemFactory:se}}}};var fe=Object.getOwnPropertyDescriptor,Ie=(e,t,i,n)=>{for(var r=n>1?void 0:n?fe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},W=(e,t)=>(i,n)=>t(i,n,e);let B=class extends o.Disposable{constructor(e,t,i){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[F,H,j,w,L].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(ve)}_initComponents(){[[b.componentKey,b],["CommentIcon",ee]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=Ie([W(0,o.ICommandService),W(1,u.IMenuManagerService),W(2,o.Inject(u.ComponentManager))],B);var pe=Object.getOwnPropertyDescriptor,ge=(e,t,i,n)=>{for(var r=n>1?void 0:n?pe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},P=(e,t)=>(i,n)=>t(i,n,e);let Z=class extends o.Disposable{constructor(e,t,i,n,r,s,d){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=i,this._docRenderController=n,this._univerInstanceService=r,this._threadCommentModel=s,this._commandService=d,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var i;if(e){this._docRenderController.reRender(e.unitId);return}const t=(i=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:i.getUnitId();t&&this._docRenderController.reRender(t)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type==="resolve"&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(T.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,i)=>{if(!e)return i(e);const{unitId:n,index:r,customDecorations:s}=t,d=this._threadCommentPanelService.activeCommentId,{commentId:a,unitId:h}=d||{},f=s.find(p=>p.id===a),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return i({...e,show:!1});const I=f&&r>=f.startIndex&&r<=f.endIndex,g=h===n&&e.id===a;return i({...e,active:g||I,show:!l.resolved})}})}_initSyncComments(){var r,s,d;const e=this._context.unit.getUnitId(),t=M,i=(d=(s=(r=this._context.unit.getBody())==null?void 0:r.customDecorations)==null?void 0:s.filter(a=>a.type===o.CustomDecorationType.COMMENT).map(a=>a.id))!=null?d:[];i.forEach(a=>{this._threadCommentModel.getComment(e,t,a)||this._threadCommentModel.addComment(e,t,{id:a,threadId:a,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),i.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,i);let n=i.sort();this.disposeWithMe(this._commandService.onCommandExecuted(a=>{var h,f,l;if(a.id===T.RichTextEditingMutation.id){if(a.params.unitId!==this._context.unit.getUnitId())return;const g=(l=(f=(h=this._context.unit.getBody())==null?void 0:h.customDecorations)==null?void 0:f.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],p=g.sort();if(JSON.stringify(n)!==JSON.stringify(p)){const m=new Set(n),C=new Set(p),O=new Set,A=new Set;g.forEach(v=>{m.has(v)||O.add(v)}),n.forEach(v=>{C.has(v)||A.add(v)}),n=p,O.forEach(v=>{this._threadCommentModel.getComment(e,t,v)||this._threadCommentModel.addComment(e,t,{id:v,threadId:v,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...O])}}}))}};Z=ge([P(1,o.Inject(T.DocInterceptorService)),P(2,o.Inject(_.ThreadCommentPanelService)),P(3,o.Inject(S.DocRenderController)),P(4,o.IUniverInstanceService),P(5,o.Inject($.ThreadCommentModel)),P(6,o.ICommandService)],Z);var Se=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,Te=(e,t,i)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,De=(e,t,i,n)=>{for(var r=n>1?void 0:n?_e(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},K=(e,t)=>(i,n)=>t(i,n,e),te=(e,t,i)=>Te(e,typeof t!="symbol"?t+"":t,i);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=Q,i,n,r){super(),this._config=t,this._injector=i,this._renderManagerSrv=n,this._configService=r;const{menu:s,...d}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ae,d)}onStarting(){[[B],[V],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(V),this._injector.get(B)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},te(c.UniverDocsThreadCommentUIPlugin,"pluginName",ie),te(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=De([o.DependentOn(_.UniverThreadCommentUIPlugin),K(1,o.Inject(o.Injector)),K(2,y.IRenderManagerService),K(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=F,c.DeleteDocCommentComment=H,c.ShowCommentPanelOperation=j,c.StartAddCommentOperation=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
13
+ (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/thread-comment","@univerjs/thread-comment-ui","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","react"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverDocsThreadCommentUi={},c.UniverCore,c.UniverDocsUi,c.UniverThreadComment,c.UniverThreadCommentUi,c.UniverDocs,c.UniverEngineRender,c.UniverUi,c.rxjs,c.React,c.React))})(this,(function(c,o,S,j,_,T,y,u,E,ie,D){"use strict";var Ue=Object.defineProperty;var ye=(c,o,S)=>o in c?Ue(c,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):c[o]=S;var k=(c,o,S)=>ye(c,typeof o!="symbol"?o+"":o,S);const re="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",H={id:"docs.command.add-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:i,unitId:n}=t,s=await e.get(j.IThreadCommentDataSourceService).addComment(i),d=e.get(o.ICommandService),a=S.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(a){const h={id:j.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},f={id:_.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([h,a,f],d)).result}return!1}},L={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:i,unitId:n}=t,r=e.get(o.ICommandService),s=S.deleteCustomDecorationFactory(e,{id:i,unitId:n});return s?(await o.sequenceExecute([s],r)).result:!1}};var oe=Object.getOwnPropertyDescriptor,se=(e,t,i,n)=>{for(var r=n>1?void 0:n?oe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},Y=(e,t)=>(i,n)=>t(i,n,e);let R=class extends o.Disposable{constructor(t,i){super();k(this,"_addingComment$",new E.BehaviorSubject(void 0));k(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=i,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};R=se([Y(0,u.ISidebarService),Y(1,o.Inject(_.ThreadCommentPanelService))],R);const z=e=>{var d;const t=e.get(y.IRenderManagerService),i=e.get(T.DocSelectionManagerService),n=(d=y.withCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_DOC,T.DocSkeletonManagerService,e.get(o.IUniverInstanceService),t))==null?void 0:d.getSkeleton(),r=n==null?void 0:n.getViewModel().getEditArea();if(r===y.DocumentEditArea.FOOTER||r===y.DocumentEditArea.HEADER)return!0;const s=i.getActiveTextRange();return!!(s==null||s.collapsed)};function de(e){return{id:w.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,void 0,o.SHEET_EDITOR_UNITS),disabled$:new E.Observable(function(t){const n=e.get(T.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}function ae(e){return{id:W.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC)}}const b=()=>{const e=u.useDependency(o.IUniverInstanceService),t=u.useDependency(o.Injector),i=D.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(E.filter(m=>!!m&&!o.isInternalEditorID(m.getUnitId()))),[e]),n=u.useObservable(i),r=D.useMemo(()=>new E.Observable(m=>m.next(M)),[]),s=u.useDependency(T.DocSelectionManagerService),d=D.useMemo(()=>s.textSelection$.pipe(E.debounceTime(16)),[s.textSelection$]);u.useObservable(d);const a=u.useDependency(o.ICommandService),h=u.useDependency(R),f=u.useObservable(h.addingComment$),[l,I]=D.useState([]);if(D.useEffect(()=>{var A;const m=new Set,C=n==null?void 0:n.getCustomDecorations();I((A=C==null?void 0:C.map(v=>v.id).filter(v=>{const U=m.has(v);return m.add(v),!U}))!=null?A:[]);const O=a.onCommandExecuted(v=>{var U;if(v.id===T.RichTextEditingMutation.id){const N=new Set,J=n==null?void 0:n.getCustomDecorations();I((U=J==null?void 0:J.map(F=>F.id).filter(F=>{const Oe=N.has(F);return N.add(F),!Oe}))!=null?U:[])}});return()=>{O.dispose()}},[a,n]),!n)return null;const p=z(t),g=n.getUnitId();return ie.jsx(_.ThreadCommentPanel,{unitId:g,subUnitId$:r,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{a.executeCommand(w.id)},getSubUnitName:()=>"",disableAdd:p,tempComment:f,onAddComment:m=>{if(!m.parentId){const C={unitId:g,range:f,comment:m};return a.executeCommand(H.id,C),h.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const C={unitId:g,commentId:m.id};return a.executeCommand(L.id,C),!1}return!0},showComments:l})};b.componentKey="univer.doc.thread-comment-panel";const $={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var r;const i=e.get(_.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!i.panelVisible||((r=n.options.children)==null?void 0:r.label)!==b.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>i.setPanelVisible(!1)}),i.setPanelVisible(!0)),t&&i.setActiveComment(t==null?void 0:t.activeComment),!0}},W={id:"docs.operation.toggle-comment-panel",type:o.CommandType.OPERATION,handler(e){var n;const t=e.get(_.ThreadCommentPanelService),i=e.get(u.ISidebarService);return!t.panelVisible||((n=i.options.children)==null?void 0:n.label)!==b.componentKey?(i.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(i.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},w={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var v,U,N;const t=e.get(_.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),r=e.get(T.DocSelectionManagerService),s=e.get(y.IRenderManagerService),d=e.get(o.UserManagerService),a=e.get(R),h=e.get(o.ICommandService),f=e.get(u.ISidebarService),l=r.getActiveTextRange();if(!n||!l)return!1;const I=(v=s.getRenderById(n.getUnitId()))==null?void 0:v.with(S.DocSelectionRenderService);if(I==null||I.setReserveRangesStatus(!0),l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),f.close()):h.executeCommand($.id),!0;h.executeCommand($.id);const p=n.getUnitId(),g=((N=(U=n.getBody())==null?void 0:U.dataStream)!=null?N:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(g),C=M,O="",A={unitId:p,subUnitId:C,id:O,ref:m,dT:j.getDT(),personId:d.getCurrentUser().userID,text:{dataStream:`\r
14
+ `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:O};return I==null||I.blur(),a.startAdd(A),t.setActiveComment({unitId:p,subUnitId:C,commentId:O}),!0}},Q={name:"@univerjs/docs-thread-comment-ui",version:"0.17.0"},ce="docs-thread-comment-ui.config",X={};var me=Object.getOwnPropertyDescriptor,le=(e,t,i,n)=>{for(var r=n>1?void 0:n?me(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},P=(e,t)=>(i,n)=>t(i,n,e);let V=class extends o.Disposable{constructor(e,t,i,n,r,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=i,this._docThreadCommentService=n,this._renderManagerService=r,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i,n,r,s;if(t.id===T.SetTextSelectionsOperation.id){const d=t.params,{unitId:a,ranges:h}=d;if(o.isInternalEditorID(a))return;const f=this._univerInstanceService.getUnit(a,o.UniverInstanceType.UNIVER_DOC),l=h[0];if((e==null?void 0:e.startOffset)===(l==null?void 0:l.startOffset)&&(e==null?void 0:e.endOffset)===(l==null?void 0:l.endOffset))return;if(e=l,l&&f){const{startOffset:I,endOffset:p,collapsed:g}=l;let m;if(g?m=(n=(i=f.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(C=>C.startIndex<=I&&C.endIndex>=p-1):m=(s=(r=f.getBody())==null?void 0:r.customDecorations)==null?void 0:s.find(C=>C.startIndex<=I&&C.endIndex>=p-1),m){const C=this._threadCommentModel.getComment(a,M,m.id);C&&!C.resolved&&this._commandService.executeCommand($.id,{activeComment:{unitId:a,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(_.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,i,n,r;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const d=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(S.DocBackScrollRenderController),a=(n=(i=s.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(h=>h.id===e.commentId);a&&d&&d.scrollToRange({startOffset:a.startIndex,endOffset:a.endIndex,collapsed:!1})}}(!e||e.commentId!==((r=this._docThreadCommentService.addingComment)==null?void 0:r.id))&&this._docThreadCommentService.endAdd()}))}};V=le([P(0,o.Inject(_.ThreadCommentPanelService)),P(1,o.IUniverInstanceService),P(2,o.ICommandService),P(3,o.Inject(R)),P(4,y.IRenderManagerService),P(5,o.Inject(j.ThreadCommentModel))],V);function ee({ref:e,...t}){const{icon:i,id:n,className:r,extend:s,...d}=t,a=`univerjs-icon univerjs-icon-${n} ${r||""}`.trim(),h=D.useRef(`_${he()}`);return te(i,`${n}`,{defIds:i.defIds,idSuffix:h.current},{ref:e,className:a,...d},s)}function te(e,t,i,n,r){return D.createElement(e.tag,{key:t,...ue(e,i,r),...n},(Ce(e,i).children||[]).map((s,d)=>te(s,`${t}-${e.tag}-${d}`,i,void 0,r)))}function ue(e,t,i){const n={...e.attrs};i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([s,d])=>{s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,d])=>{typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Ce(e,t){var n;const{defIds:i}=t;return!i||i.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&i&&i.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function he(){return Math.random().toString(36).substring(2,8)}ee.displayName="UniverIcon";const ve={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ne=D.forwardRef(function(t,i){return D.createElement(ee,Object.assign({},t,{id:"comment-icon",ref:i,icon:ve}))});ne.displayName="CommentIcon";const fe={[u.RibbonInsertGroup.MEDIA]:{[W.id]:{order:3,menuItemFactory:ae}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[w.id]:{order:1,menuItemFactory:de}}}};var Ie=Object.getOwnPropertyDescriptor,ge=(e,t,i,n)=>{for(var r=n>1?void 0:n?Ie(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},Z=(e,t)=>(i,n)=>t(i,n,e);let B=class extends o.Disposable{constructor(e,t,i){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,L,$,w,W].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(fe)}_initComponents(){[[b.componentKey,b],["CommentIcon",ne]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=ge([Z(0,o.ICommandService),Z(1,u.IMenuManagerService),Z(2,o.Inject(u.ComponentManager))],B);var pe=Object.getOwnPropertyDescriptor,Se=(e,t,i,n)=>{for(var r=n>1?void 0:n?pe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},x=(e,t)=>(i,n)=>t(i,n,e);let K=class extends o.Disposable{constructor(e,t,i,n,r,s,d){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=i,this._docRenderController=n,this._univerInstanceService=r,this._threadCommentModel=s,this._commandService=d,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var i;if(e){this._docRenderController.reRender(e.unitId);return}const t=(i=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:i.getUnitId();t&&this._docRenderController.reRender(t)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type==="resolve"&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(T.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,i)=>{if(!e)return i(e);const{unitId:n,index:r,customDecorations:s}=t,d=this._threadCommentPanelService.activeCommentId,{commentId:a,unitId:h}=d||{},f=s.find(g=>g.id===a),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return i({...e,show:!1});const I=f&&r>=f.startIndex&&r<=f.endIndex,p=h===n&&e.id===a;return i({...e,active:p||I,show:!l.resolved})}})}_initSyncComments(){var r,s,d;const e=this._context.unit.getUnitId(),t=M,i=(d=(s=(r=this._context.unit.getBody())==null?void 0:r.customDecorations)==null?void 0:s.filter(a=>a.type===o.CustomDecorationType.COMMENT).map(a=>a.id))!=null?d:[];i.forEach(a=>{this._threadCommentModel.getComment(e,t,a)||this._threadCommentModel.addComment(e,t,{id:a,threadId:a,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),i.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,i);let n=i.sort();this.disposeWithMe(this._commandService.onCommandExecuted(a=>{var h,f,l;if(a.id===T.RichTextEditingMutation.id){if(a.params.unitId!==this._context.unit.getUnitId())return;const p=(l=(f=(h=this._context.unit.getBody())==null?void 0:h.customDecorations)==null?void 0:f.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],g=p.sort();if(JSON.stringify(n)!==JSON.stringify(g)){const m=new Set(n),C=new Set(g),O=new Set,A=new Set;p.forEach(v=>{m.has(v)||O.add(v)}),n.forEach(v=>{C.has(v)||A.add(v)}),n=g,O.forEach(v=>{this._threadCommentModel.getComment(e,t,v)||this._threadCommentModel.addComment(e,t,{id:v,threadId:v,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...O])}}}))}};K=Se([x(1,o.Inject(T.DocInterceptorService)),x(2,o.Inject(_.ThreadCommentPanelService)),x(3,o.Inject(S.DocRenderController)),x(4,o.IUniverInstanceService),x(5,o.Inject(j.ThreadCommentModel)),x(6,o.ICommandService)],K);var _e=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,De=(e,t,i)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Me=(e,t,i,n)=>{for(var r=n>1?void 0:n?Te(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},G=(e,t)=>(i,n)=>t(i,n,e),q=(e,t,i)=>De(e,typeof t!="symbol"?t+"":t,i);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=X,i,n,r){super(),this._config=t,this._injector=i,this._renderManagerSrv=n,this._configService=r;const{menu:s,...d}=o.merge({},X,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ce,d)}onStarting(){[[B],[V],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(V),this._injector.get(B)}_initRenderModule(){[K].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},q(c.UniverDocsThreadCommentUIPlugin,"pluginName",re),q(c.UniverDocsThreadCommentUIPlugin,"packageName",Q.name),q(c.UniverDocsThreadCommentUIPlugin,"version",Q.version),q(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(_.UniverThreadCommentUIPlugin),G(1,o.Inject(o.Injector)),G(2,y.IRenderManagerService),G(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=H,c.DeleteDocCommentComment=L,c.ShowCommentPanelOperation=$,c.StartAddCommentOperation=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
15
15
 
16
16
 
17
17
  // index
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-docs-thread-comment",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -58,17 +58,17 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/docs-thread-comment-ui": "0.16.1",
62
- "@univerjs/thread-comment": "0.16.1",
63
- "@univerjs/thread-comment-ui": "0.16.1"
61
+ "@univerjs/docs-thread-comment-ui": "0.17.0",
62
+ "@univerjs/thread-comment": "0.17.0",
63
+ "@univerjs/thread-comment-ui": "0.17.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@univerjs/core": "0.16.1",
66
+ "@univerjs/core": "0.17.0",
67
67
  "react": "18.3.1",
68
68
  "react-dom": "18.3.1",
69
69
  "rxjs": "7.8.2",
70
70
  "typescript": "^5.9.3",
71
- "@univerjs-infra/shared": "0.16.1"
71
+ "@univerjs-infra/shared": "0.17.0"
72
72
  },
73
73
  "scripts": {
74
74
  "prebuild:preset": "tsx prepare.ts",