@univerjs/docs-thread-comment-ui 0.8.2-nightly.202506261607 → 0.8.3-nightly.202506271607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var re=Object.defineProperty;var ie=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var H=(e,t,r)=>ie(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),b=require("@univerjs/engine-render"),O=require("@univerjs/thread-comment-ui"),_=require("@univerjs/docs"),V=require("@univerjs/docs-ui"),A=require("@univerjs/thread-comment"),u=require("@univerjs/ui"),E=require("rxjs"),oe=require("react/jsx-runtime"),S=require("react"),ce="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",ae="docs-thread-comment-ui.config",J={};var se=Object.getOwnPropertyDescriptor,de=(e,t,r,n)=>{for(var i=n>1?void 0:n?se(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Y=(e,t)=>(r,n)=>t(r,n,e);let P=class extends c.Disposable{constructor(t,r){super();H(this,"_addingComment$",new E.BehaviorSubject(void 0));H(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=r,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};P=de([Y(0,u.ISidebarService),Y(1,c.Inject(O.ThreadCommentPanelService))],P);const K={id:"docs.command.add-comment",type:c.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:r,unitId:n}=t,o=await e.get(A.IThreadCommentDataSourceService).addComment(r),a=e.get(c.ICommandService),s=V.addCustomDecorationBySelectionFactory(e,{id:o.threadId,type:c.CustomDecorationType.COMMENT,unitId:n});if(s){const C={id:A.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:o}},v={id:O.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:o.id}};return(await c.sequenceExecute([C,s,v],a)).result}return!1}},G={id:"docs.command.delete-comment",type:c.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:r,unitId:n}=t,i=e.get(c.ICommandService),o=V.deleteCustomDecorationFactory(e,{id:r,unitId:n});return o?(await c.sequenceExecute([o],i)).result:!1}},z=e=>{var a;const t=e.get(b.IRenderManagerService),r=e.get(_.DocSelectionManagerService),n=(a=b.withCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_DOC,_.DocSkeletonManagerService,e.get(c.IUniverInstanceService),t))==null?void 0:a.getSkeleton(),i=n==null?void 0:n.getViewModel().getEditArea();if(i===b.DocumentEditArea.FOOTER||i===b.DocumentEditArea.HEADER)return!0;const o=r.getActiveTextRange();return!!(o==null||o.collapsed)};function me(e){return{id:j.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_DOC,void 0,c.SHEET_EDITOR_UNITS),disabled$:new E.Observable(function(t){const n=e.get(_.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}function le(e){return{id:k.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_DOC)}}const y=()=>{const e=u.useDependency(c.IUniverInstanceService),t=u.useDependency(c.Injector),r=S.useMemo(()=>e.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(E.filter(d=>!!d&&!c.isInternalEditorID(d.getUnitId()))),[e]),n=u.useObservable(r),i=S.useMemo(()=>new E.Observable(d=>d.next(M)),[]),o=u.useDependency(_.DocSelectionManagerService),a=S.useMemo(()=>o.textSelection$.pipe(E.debounceTime(16)),[o.textSelection$]);u.useObservable(a);const s=u.useDependency(c.ICommandService),C=u.useDependency(P),v=u.useObservable(C.addingComment$),[m,f]=S.useState([]);if(S.useEffect(()=>{var U;const d=new Set,l=n==null?void 0:n.getCustomDecorations();f((U=l==null?void 0:l.map(h=>h.id).filter(h=>{const T=d.has(h);return d.add(h),!T}))!=null?U:[]);const D=s.onCommandExecuted(h=>{var T;if(h.id===_.RichTextEditingMutation.id){const w=new Set,F=n==null?void 0:n.getCustomDecorations();f((T=F==null?void 0:F.map($=>$.id).filter($=>{const ne=w.has($);return w.add($),!ne}))!=null?T:[])}});return()=>{D.dispose()}},[s,n]),!n)return null;const g=z(t),I=n.getUnitId();return oe.jsx(O.ThreadCommentPanel,{unitId:I,subUnitId$:i,type:c.UniverInstanceType.UNIVER_DOC,onAdd:()=>{s.executeCommand(j.id)},getSubUnitName:()=>"",disableAdd:g,tempComment:v,onAddComment:d=>{if(!d.parentId){const l={unitId:I,range:v,comment:d};return s.executeCommand(K.id,l),C.endAdd(),!1}return!0},onDeleteComment:d=>{if(!d.parentId){const l={unitId:I,commentId:d.id};return s.executeCommand(G.id,l),!1}return!0},showComments:m})};y.componentKey="univer.doc.thread-comment-panel";const N={id:"docs.operation.show-comment-panel",type:c.CommandType.OPERATION,handler(e,t){var i;const r=e.get(O.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==y.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:y.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.setActiveComment(t==null?void 0:t.activeComment),!0}},k={id:"docs.operation.toggle-comment-panel",type:c.CommandType.OPERATION,handler(e){var n;const t=e.get(O.ThreadCommentPanelService),r=e.get(u.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==y.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:y.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(r.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},j={id:"docs.operation.start-add-comment",type:c.CommandType.OPERATION,handler(e){var h,T,w;const t=e.get(O.ThreadCommentPanelService),n=e.get(c.IUniverInstanceService).getCurrentUnitForType(c.UniverInstanceType.UNIVER_DOC),i=e.get(_.DocSelectionManagerService),o=e.get(b.IRenderManagerService),a=e.get(c.UserManagerService),s=e.get(P),C=e.get(c.ICommandService),v=e.get(u.ISidebarService),m=i.getActiveTextRange();if(!n||!m)return!1;const f=(h=o.getRenderById(n.getUnitId()))==null?void 0:h.with(V.DocSelectionRenderService);if(f==null||f.setReserveRangesStatus(!0),m.collapsed)return t.panelVisible?(t.setPanelVisible(!1),v.close()):C.executeCommand(N.id),!0;C.executeCommand(N.id);const g=n.getUnitId(),I=((w=(T=n.getBody())==null?void 0:T.dataStream)!=null?w:"").slice(m.startOffset,m.endOffset),d=c.BuildTextUtils.transform.getPlainText(I),l=M,D="",U={unitId:g,subUnitId:l,id:D,ref:d,dT:A.getDT(),personId:a.getCurrentUser().userID,text:{dataStream:`\r
2
- `},startOffset:m.startOffset,endOffset:m.endOffset,collapsed:!0,threadId:D};return f==null||f.blur(),s.startAdd(U),t.setActiveComment({unitId:g,subUnitId:l,commentId:D}),!0}};var ue=Object.getOwnPropertyDescriptor,Ce=(e,t,r,n)=>{for(var i=n>1?void 0:n?ue(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},x=(e,t)=>(r,n)=>t(r,n,e);let B=class extends c.Disposable{constructor(e,t,r,n,i,o){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=o,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,o;if(t.id===_.SetTextSelectionsOperation.id){const a=t.params,{unitId:s,ranges:C}=a;if(c.isInternalEditorID(s))return;const v=this._univerInstanceService.getUnit(s,c.UniverInstanceType.UNIVER_DOC),m=C[0];if((e==null?void 0:e.startOffset)===(m==null?void 0:m.startOffset)&&(e==null?void 0:e.endOffset)===(m==null?void 0:m.endOffset))return;if(e=m,m&&v){const{startOffset:f,endOffset:g,collapsed:I}=m;let d;if(I?d=(n=(r=v.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(l=>l.startIndex<=f&&l.endIndex>=g-1):d=(o=(i=v.getBody())==null?void 0:i.customDecorations)==null?void 0:o.find(l=>l.startIndex<=f&&l.endIndex>=g-1),d){const l=this._threadCommentModel.getComment(s,M,d.id);l&&!l.resolved&&this._commandService.executeCommand(N.id,{activeComment:{unitId:s,subUnitId:M,commentId:d.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(O.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const o=this._univerInstanceService.getUnit(e.unitId);if(o){const a=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(V.DocBackScrollRenderController),s=(n=(r=o.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);s&&a&&a.scrollToRange({startOffset:s.startIndex,endOffset:s.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};B=Ce([x(0,c.Inject(O.ThreadCommentPanelService)),x(1,c.IUniverInstanceService),x(2,c.ICommandService),x(3,c.Inject(P)),x(4,b.IRenderManagerService),x(5,c.Inject(A.ThreadCommentModel))],B);var p=function(){return p=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},p.apply(this,arguments)},he=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},Q=S.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,o=e.extend,a=he(e,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),C=S.useRef("_".concat(Ie()));return X(r,"".concat(n),{defIds:r.defIds,idSuffix:C.current},p({ref:t,className:s},a),o)});function X(e,t,r,n,i){return S.createElement(e.tag,p(p({key:t},ve(e,r,i)),n),(fe(e,r).children||[]).map(function(o,a){return X(o,"".concat(t,"-").concat(e.tag,"-").concat(a),r,void 0,i)}))}function ve(e,t,r){var n=p({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(n[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(n[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function fe(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?p(p({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?p(p({},i),{attrs:p(p({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Ie(){return Math.random().toString(36).substring(2,8)}Q.displayName="UniverIcon";var ge={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=S.forwardRef(function(e,t){return S.createElement(Q,Object.assign({},e,{id:"comment-icon",ref:t,icon:ge}))});ee.displayName="CommentIcon";const pe={[u.RibbonInsertGroup.MEDIA]:{[k.id]:{order:3,menuItemFactory:le}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[j.id]:{order:1,menuItemFactory:me}}}};var Se=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},L=(e,t)=>(r,n)=>t(r,n,e);let q=class extends c.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[K,G,N,j,k].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(pe)}_initComponents(){[[y.componentKey,y],["CommentIcon",ee]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=_e([L(0,c.ICommandService),L(1,u.IMenuManagerService),L(2,c.Inject(u.ComponentManager))],q);var Oe=Object.getOwnPropertyDescriptor,De=(e,t,r,n)=>{for(var i=n>1?void 0:n?Oe(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},R=(e,t)=>(r,n)=>t(r,n,e);let Z=class extends c.Disposable{constructor(e,t,r,n,i,o,a){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=o,this._commandService=a,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var r;if(e){this._docRenderController.reRender(e.unitId);return}const t=(r=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_DOC))==null?void 0:r.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(_.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:o}=t,a=this._threadCommentPanelService.activeCommentId,{commentId:s,unitId:C}=a||{},v=o.find(I=>I.id===s),m=this._threadCommentModel.getComment(n,M,e.id);if(!m)return r({...e,show:!1});const f=v&&i>=v.startIndex&&i<=v.endIndex,g=C===n&&e.id===s;return r({...e,active:g||f,show:!m.resolved})}})}_initSyncComments(){var i,o,a;const e=this._context.unit.getUnitId(),t=M,r=(a=(o=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:o.filter(s=>s.type===c.CustomDecorationType.COMMENT).map(s=>s.id))!=null?a:[];r.forEach(s=>{this._threadCommentModel.getComment(e,t,s)||this._threadCommentModel.addComment(e,t,{id:s,threadId:s,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(s=>{var C,v,m;if(s.id===_.RichTextEditingMutation.id){if(s.params.unitId!==this._context.unit.getUnitId())return;const g=(m=(v=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:v.filter(d=>d.type===c.CustomDecorationType.COMMENT).map(d=>d.id))!=null?m:[],I=g.sort();if(JSON.stringify(n)!==JSON.stringify(I)){const d=new Set(n),l=new Set(I),D=new Set,U=new Set;g.forEach(h=>{d.has(h)||D.add(h)}),n.forEach(h=>{l.has(h)||U.add(h)}),n=I,D.forEach(h=>{this._threadCommentModel.getComment(e,t,h)||this._threadCommentModel.addComment(e,t,{id:h,threadId:h,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...D])}}}))}};Z=De([R(1,c.Inject(_.DocInterceptorService)),R(2,c.Inject(O.ThreadCommentPanelService)),R(3,c.Inject(V.DocRenderController)),R(4,c.IUniverInstanceService),R(5,c.Inject(A.ThreadCommentModel)),R(6,c.ICommandService)],Z);var Me=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,be=(e,t,r)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},W=(e,t)=>(r,n)=>t(r,n,e),te=(e,t,r)=>be(e,typeof t!="symbol"?t+"":t,r);exports.UniverDocsThreadCommentUIPlugin=class extends c.Plugin{constructor(t=J,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:o,...a}=c.merge({},J,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ae,a)}onStarting(){[[q],[B],[P]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(B),this._injector.get(q)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(c.UniverInstanceType.UNIVER_DOC,t)})}};te(exports.UniverDocsThreadCommentUIPlugin,"pluginName",ce);te(exports.UniverDocsThreadCommentUIPlugin,"type",c.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=ye([c.DependentOn(O.UniverThreadCommentUIPlugin),W(1,c.Inject(c.Injector)),W(2,b.IRenderManagerService),W(3,c.IConfigService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=K;exports.DeleteDocCommentComment=G;exports.ShowCommentPanelOperation=N;exports.StartAddCommentOperation=j;
1
+ "use strict";var re=Object.defineProperty;var ie=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var H=(e,t,r)=>ie(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),V=require("@univerjs/docs-ui"),A=require("@univerjs/thread-comment"),O=require("@univerjs/thread-comment-ui"),_=require("@univerjs/docs"),b=require("@univerjs/engine-render"),u=require("@univerjs/ui"),E=require("rxjs"),oe=require("react/jsx-runtime"),S=require("react"),ce="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",K={id:"docs.command.add-comment",type:c.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:r,unitId:n}=t,o=await e.get(A.IThreadCommentDataSourceService).addComment(r),a=e.get(c.ICommandService),s=V.addCustomDecorationBySelectionFactory(e,{id:o.threadId,type:c.CustomDecorationType.COMMENT,unitId:n});if(s){const C={id:A.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:o}},v={id:O.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:o.id}};return(await c.sequenceExecute([C,s,v],a)).result}return!1}},G={id:"docs.command.delete-comment",type:c.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:r,unitId:n}=t,i=e.get(c.ICommandService),o=V.deleteCustomDecorationFactory(e,{id:r,unitId:n});return o?(await c.sequenceExecute([o],i)).result:!1}};var ae=Object.getOwnPropertyDescriptor,se=(e,t,r,n)=>{for(var i=n>1?void 0:n?ae(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},J=(e,t)=>(r,n)=>t(r,n,e);let P=class extends c.Disposable{constructor(t,r){super();H(this,"_addingComment$",new E.BehaviorSubject(void 0));H(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=r,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};P=se([J(0,u.ISidebarService),J(1,c.Inject(O.ThreadCommentPanelService))],P);const z=e=>{var a;const t=e.get(b.IRenderManagerService),r=e.get(_.DocSelectionManagerService),n=(a=b.withCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_DOC,_.DocSkeletonManagerService,e.get(c.IUniverInstanceService),t))==null?void 0:a.getSkeleton(),i=n==null?void 0:n.getViewModel().getEditArea();if(i===b.DocumentEditArea.FOOTER||i===b.DocumentEditArea.HEADER)return!0;const o=r.getActiveTextRange();return!!(o==null||o.collapsed)};function de(e){return{id:j.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_DOC,void 0,c.SHEET_EDITOR_UNITS),disabled$:new E.Observable(function(t){const n=e.get(_.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}function me(e){return{id:k.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_DOC)}}const y=()=>{const e=u.useDependency(c.IUniverInstanceService),t=u.useDependency(c.Injector),r=S.useMemo(()=>e.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(E.filter(d=>!!d&&!c.isInternalEditorID(d.getUnitId()))),[e]),n=u.useObservable(r),i=S.useMemo(()=>new E.Observable(d=>d.next(M)),[]),o=u.useDependency(_.DocSelectionManagerService),a=S.useMemo(()=>o.textSelection$.pipe(E.debounceTime(16)),[o.textSelection$]);u.useObservable(a);const s=u.useDependency(c.ICommandService),C=u.useDependency(P),v=u.useObservable(C.addingComment$),[m,f]=S.useState([]);if(S.useEffect(()=>{var U;const d=new Set,l=n==null?void 0:n.getCustomDecorations();f((U=l==null?void 0:l.map(h=>h.id).filter(h=>{const T=d.has(h);return d.add(h),!T}))!=null?U:[]);const D=s.onCommandExecuted(h=>{var T;if(h.id===_.RichTextEditingMutation.id){const w=new Set,F=n==null?void 0:n.getCustomDecorations();f((T=F==null?void 0:F.map($=>$.id).filter($=>{const ne=w.has($);return w.add($),!ne}))!=null?T:[])}});return()=>{D.dispose()}},[s,n]),!n)return null;const g=z(t),I=n.getUnitId();return oe.jsx(O.ThreadCommentPanel,{unitId:I,subUnitId$:i,type:c.UniverInstanceType.UNIVER_DOC,onAdd:()=>{s.executeCommand(j.id)},getSubUnitName:()=>"",disableAdd:g,tempComment:v,onAddComment:d=>{if(!d.parentId){const l={unitId:I,range:v,comment:d};return s.executeCommand(K.id,l),C.endAdd(),!1}return!0},onDeleteComment:d=>{if(!d.parentId){const l={unitId:I,commentId:d.id};return s.executeCommand(G.id,l),!1}return!0},showComments:m})};y.componentKey="univer.doc.thread-comment-panel";const N={id:"docs.operation.show-comment-panel",type:c.CommandType.OPERATION,handler(e,t){var i;const r=e.get(O.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==y.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:y.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.setActiveComment(t==null?void 0:t.activeComment),!0}},k={id:"docs.operation.toggle-comment-panel",type:c.CommandType.OPERATION,handler(e){var n;const t=e.get(O.ThreadCommentPanelService),r=e.get(u.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==y.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:y.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(r.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},j={id:"docs.operation.start-add-comment",type:c.CommandType.OPERATION,handler(e){var h,T,w;const t=e.get(O.ThreadCommentPanelService),n=e.get(c.IUniverInstanceService).getCurrentUnitForType(c.UniverInstanceType.UNIVER_DOC),i=e.get(_.DocSelectionManagerService),o=e.get(b.IRenderManagerService),a=e.get(c.UserManagerService),s=e.get(P),C=e.get(c.ICommandService),v=e.get(u.ISidebarService),m=i.getActiveTextRange();if(!n||!m)return!1;const f=(h=o.getRenderById(n.getUnitId()))==null?void 0:h.with(V.DocSelectionRenderService);if(f==null||f.setReserveRangesStatus(!0),m.collapsed)return t.panelVisible?(t.setPanelVisible(!1),v.close()):C.executeCommand(N.id),!0;C.executeCommand(N.id);const g=n.getUnitId(),I=((w=(T=n.getBody())==null?void 0:T.dataStream)!=null?w:"").slice(m.startOffset,m.endOffset),d=c.BuildTextUtils.transform.getPlainText(I),l=M,D="",U={unitId:g,subUnitId:l,id:D,ref:d,dT:A.getDT(),personId:a.getCurrentUser().userID,text:{dataStream:`\r
2
+ `},startOffset:m.startOffset,endOffset:m.endOffset,collapsed:!0,threadId:D};return f==null||f.blur(),s.startAdd(U),t.setActiveComment({unitId:g,subUnitId:l,commentId:D}),!0}},le="docs-thread-comment-ui.config",Y={};var ue=Object.getOwnPropertyDescriptor,Ce=(e,t,r,n)=>{for(var i=n>1?void 0:n?ue(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},x=(e,t)=>(r,n)=>t(r,n,e);let B=class extends c.Disposable{constructor(e,t,r,n,i,o){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=o,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,o;if(t.id===_.SetTextSelectionsOperation.id){const a=t.params,{unitId:s,ranges:C}=a;if(c.isInternalEditorID(s))return;const v=this._univerInstanceService.getUnit(s,c.UniverInstanceType.UNIVER_DOC),m=C[0];if((e==null?void 0:e.startOffset)===(m==null?void 0:m.startOffset)&&(e==null?void 0:e.endOffset)===(m==null?void 0:m.endOffset))return;if(e=m,m&&v){const{startOffset:f,endOffset:g,collapsed:I}=m;let d;if(I?d=(n=(r=v.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(l=>l.startIndex<=f&&l.endIndex>=g-1):d=(o=(i=v.getBody())==null?void 0:i.customDecorations)==null?void 0:o.find(l=>l.startIndex<=f&&l.endIndex>=g-1),d){const l=this._threadCommentModel.getComment(s,M,d.id);l&&!l.resolved&&this._commandService.executeCommand(N.id,{activeComment:{unitId:s,subUnitId:M,commentId:d.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(O.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const o=this._univerInstanceService.getUnit(e.unitId);if(o){const a=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(V.DocBackScrollRenderController),s=(n=(r=o.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);s&&a&&a.scrollToRange({startOffset:s.startIndex,endOffset:s.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};B=Ce([x(0,c.Inject(O.ThreadCommentPanelService)),x(1,c.IUniverInstanceService),x(2,c.ICommandService),x(3,c.Inject(P)),x(4,b.IRenderManagerService),x(5,c.Inject(A.ThreadCommentModel))],B);var p=function(){return p=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},p.apply(this,arguments)},he=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},Q=S.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,o=e.extend,a=he(e,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),C=S.useRef("_".concat(Ie()));return X(r,"".concat(n),{defIds:r.defIds,idSuffix:C.current},p({ref:t,className:s},a),o)});function X(e,t,r,n,i){return S.createElement(e.tag,p(p({key:t},ve(e,r,i)),n),(fe(e,r).children||[]).map(function(o,a){return X(o,"".concat(t,"-").concat(e.tag,"-").concat(a),r,void 0,i)}))}function ve(e,t,r){var n=p({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(n[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(n[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function fe(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?p(p({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?p(p({},i),{attrs:p(p({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Ie(){return Math.random().toString(36).substring(2,8)}Q.displayName="UniverIcon";var ge={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=S.forwardRef(function(e,t){return S.createElement(Q,Object.assign({},e,{id:"comment-icon",ref:t,icon:ge}))});ee.displayName="CommentIcon";const pe={[u.RibbonInsertGroup.MEDIA]:{[k.id]:{order:3,menuItemFactory:me}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[j.id]:{order:1,menuItemFactory:de}}}};var Se=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},L=(e,t)=>(r,n)=>t(r,n,e);let q=class extends c.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[K,G,N,j,k].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(pe)}_initComponents(){[[y.componentKey,y],["CommentIcon",ee]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=_e([L(0,c.ICommandService),L(1,u.IMenuManagerService),L(2,c.Inject(u.ComponentManager))],q);var Oe=Object.getOwnPropertyDescriptor,De=(e,t,r,n)=>{for(var i=n>1?void 0:n?Oe(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},R=(e,t)=>(r,n)=>t(r,n,e);let Z=class extends c.Disposable{constructor(e,t,r,n,i,o,a){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=o,this._commandService=a,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var r;if(e){this._docRenderController.reRender(e.unitId);return}const t=(r=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_DOC))==null?void 0:r.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(_.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:o}=t,a=this._threadCommentPanelService.activeCommentId,{commentId:s,unitId:C}=a||{},v=o.find(I=>I.id===s),m=this._threadCommentModel.getComment(n,M,e.id);if(!m)return r({...e,show:!1});const f=v&&i>=v.startIndex&&i<=v.endIndex,g=C===n&&e.id===s;return r({...e,active:g||f,show:!m.resolved})}})}_initSyncComments(){var i,o,a;const e=this._context.unit.getUnitId(),t=M,r=(a=(o=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:o.filter(s=>s.type===c.CustomDecorationType.COMMENT).map(s=>s.id))!=null?a:[];r.forEach(s=>{this._threadCommentModel.getComment(e,t,s)||this._threadCommentModel.addComment(e,t,{id:s,threadId:s,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(s=>{var C,v,m;if(s.id===_.RichTextEditingMutation.id){if(s.params.unitId!==this._context.unit.getUnitId())return;const g=(m=(v=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:v.filter(d=>d.type===c.CustomDecorationType.COMMENT).map(d=>d.id))!=null?m:[],I=g.sort();if(JSON.stringify(n)!==JSON.stringify(I)){const d=new Set(n),l=new Set(I),D=new Set,U=new Set;g.forEach(h=>{d.has(h)||D.add(h)}),n.forEach(h=>{l.has(h)||U.add(h)}),n=I,D.forEach(h=>{this._threadCommentModel.getComment(e,t,h)||this._threadCommentModel.addComment(e,t,{id:h,threadId:h,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...D])}}}))}};Z=De([R(1,c.Inject(_.DocInterceptorService)),R(2,c.Inject(O.ThreadCommentPanelService)),R(3,c.Inject(V.DocRenderController)),R(4,c.IUniverInstanceService),R(5,c.Inject(A.ThreadCommentModel)),R(6,c.ICommandService)],Z);var Me=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,be=(e,t,r)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},W=(e,t)=>(r,n)=>t(r,n,e),te=(e,t,r)=>be(e,typeof t!="symbol"?t+"":t,r);exports.UniverDocsThreadCommentUIPlugin=class extends c.Plugin{constructor(t=Y,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:o,...a}=c.merge({},Y,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(le,a)}onStarting(){[[q],[B],[P]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(B),this._injector.get(q)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(c.UniverInstanceType.UNIVER_DOC,t)})}};te(exports.UniverDocsThreadCommentUIPlugin,"pluginName",ce);te(exports.UniverDocsThreadCommentUIPlugin,"type",c.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=ye([c.DependentOn(O.UniverThreadCommentUIPlugin),W(1,c.Inject(c.Injector)),W(2,b.IRenderManagerService),W(3,c.IConfigService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=K;exports.DeleteDocCommentComment=G;exports.ShowCommentPanelOperation=N;exports.StartAddCommentOperation=j;
package/lib/es/index.js CHANGED
@@ -1,52 +1,23 @@
1
1
  var Oe = Object.defineProperty;
2
2
  var Me = (e, t, r) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var K = (e, t, r) => Me(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as _, Disposable as B, CommandType as P, ICommandService as b, CustomDecorationType as Y, sequenceExecute as ne, UniverInstanceType as p, SHEET_EDITOR_UNITS as be, IUniverInstanceService as w, Injector as re, isInternalEditorID as oe, UserManagerService as De, BuildTextUtils as ye, DependentOn as xe, IConfigService as Te, Plugin as Ue, merge as Re } from "@univerjs/core";
5
- import { IRenderManagerService as F, withCurrentTypeOfRenderer as Ee, DocumentEditArea as X } from "@univerjs/engine-render";
6
- import { ThreadCommentPanelService as U, SetActiveCommentOperation as ie, ThreadCommentPanel as Pe, UniverThreadCommentUIPlugin as we } from "@univerjs/thread-comment-ui";
7
- import { DocSelectionManagerService as H, DocSkeletonManagerService as Ae, RichTextEditingMutation as de, SetTextSelectionsOperation as Ne, DocInterceptorService as Ve, DOC_INTERCEPTOR_POINT as $e } from "@univerjs/docs";
8
- import { addCustomDecorationBySelectionFactory as je, deleteCustomDecorationFactory as Be, DocSelectionRenderService as Fe, DocBackScrollRenderController as He, DocRenderController as Le } from "@univerjs/docs-ui";
9
- import { IThreadCommentDataSourceService as We, AddCommentMutation as Ze, getDT as Ke, ThreadCommentModel as se } from "@univerjs/thread-comment";
4
+ import { CommandType as P, ICommandService as b, CustomDecorationType as Y, sequenceExecute as ne, Inject as _, Disposable as B, UniverInstanceType as p, SHEET_EDITOR_UNITS as be, IUniverInstanceService as w, Injector as re, isInternalEditorID as oe, UserManagerService as De, BuildTextUtils as ye, DependentOn as xe, IConfigService as Te, Plugin as Ue, merge as Re } from "@univerjs/core";
5
+ import { addCustomDecorationBySelectionFactory as Ee, deleteCustomDecorationFactory as Pe, DocSelectionRenderService as we, DocBackScrollRenderController as Ae, DocRenderController as Ne } from "@univerjs/docs-ui";
6
+ import { IThreadCommentDataSourceService as Ve, AddCommentMutation as $e, getDT as je, ThreadCommentModel as ie } from "@univerjs/thread-comment";
7
+ import { SetActiveCommentOperation as de, ThreadCommentPanelService as U, ThreadCommentPanel as Be, UniverThreadCommentUIPlugin as Fe } from "@univerjs/thread-comment-ui";
8
+ import { DocSelectionManagerService as F, DocSkeletonManagerService as He, RichTextEditingMutation as se, SetTextSelectionsOperation as Le, DocInterceptorService as We, DOC_INTERCEPTOR_POINT as Ze } from "@univerjs/docs";
9
+ import { IRenderManagerService as H, withCurrentTypeOfRenderer as Ke, DocumentEditArea as X } from "@univerjs/engine-render";
10
10
  import { ISidebarService as L, getMenuHiddenObservable as ce, MenuItemType as ae, useDependency as E, useObservable as G, ContextMenuPosition as Ge, ContextMenuGroup as ke, RibbonInsertGroup as Je, IMenuManagerService as qe, ComponentManager as Ye } from "@univerjs/ui";
11
11
  import { BehaviorSubject as ze, Observable as me, debounceTime as le, filter as Qe } from "rxjs";
12
12
  import { jsx as Xe } from "react/jsx-runtime";
13
13
  import { useMemo as k, useState as et, useEffect as tt, forwardRef as ue, useRef as nt, createElement as fe } from "react";
14
- const rt = "DOC_THREAD_COMMENT_UI_PLUGIN", S = "default_doc", ot = "docs-thread-comment-ui.config", ee = {};
15
- var it = Object.getOwnPropertyDescriptor, dt = (e, t, r, n) => {
16
- for (var o = n > 1 ? void 0 : n ? it(t, r) : t, i = e.length - 1, d; i >= 0; i--)
17
- (d = e[i]) && (o = d(o) || o);
18
- return o;
19
- }, te = (e, t) => (r, n) => t(r, n, e);
20
- let T = class extends B {
21
- constructor(t, r) {
22
- super();
23
- K(this, "_addingComment$", new ze(void 0));
24
- K(this, "addingComment$", this._addingComment$.asObservable());
25
- this._sidebarService = t, this._threadCommentPanelService = r, this.disposeWithMe(() => {
26
- this._addingComment$.complete();
27
- });
28
- }
29
- get addingComment() {
30
- return this._addingComment$.getValue();
31
- }
32
- startAdd(t) {
33
- this._addingComment$.next(t);
34
- }
35
- endAdd() {
36
- this._addingComment$.next(void 0);
37
- }
38
- };
39
- T = dt([
40
- te(0, L),
41
- te(1, _(U))
42
- ], T);
43
- const he = {
14
+ const rt = "DOC_THREAD_COMMENT_UI_PLUGIN", S = "default_doc", he = {
44
15
  id: "docs.command.add-comment",
45
16
  type: P.COMMAND,
46
17
  async handler(e, t) {
47
18
  if (!t)
48
19
  return !1;
49
- const { comment: r, unitId: n } = t, i = await e.get(We).addComment(r), d = e.get(b), s = je(
20
+ const { comment: r, unitId: n } = t, i = await e.get(Ve).addComment(r), d = e.get(b), s = Ee(
50
21
  e,
51
22
  {
52
23
  id: i.threadId,
@@ -56,14 +27,14 @@ const he = {
56
27
  );
57
28
  if (s) {
58
29
  const l = {
59
- id: Ze.id,
30
+ id: $e.id,
60
31
  params: {
61
32
  unitId: n,
62
33
  subUnitId: S,
63
34
  comment: i
64
35
  }
65
36
  }, f = {
66
- id: ie.id,
37
+ id: de.id,
67
38
  params: {
68
39
  unitId: n,
69
40
  subUnitId: S,
@@ -80,17 +51,46 @@ const he = {
80
51
  async handler(e, t) {
81
52
  if (!t)
82
53
  return !1;
83
- const { commentId: r, unitId: n } = t, o = e.get(b), i = Be(e, {
54
+ const { commentId: r, unitId: n } = t, o = e.get(b), i = Pe(e, {
84
55
  id: r,
85
56
  unitId: n
86
57
  });
87
58
  return i ? (await ne([i], o)).result : !1;
88
59
  }
89
- }, ve = (e) => {
60
+ };
61
+ var ot = Object.getOwnPropertyDescriptor, it = (e, t, r, n) => {
62
+ for (var o = n > 1 ? void 0 : n ? ot(t, r) : t, i = e.length - 1, d; i >= 0; i--)
63
+ (d = e[i]) && (o = d(o) || o);
64
+ return o;
65
+ }, ee = (e, t) => (r, n) => t(r, n, e);
66
+ let T = class extends B {
67
+ constructor(t, r) {
68
+ super();
69
+ K(this, "_addingComment$", new ze(void 0));
70
+ K(this, "addingComment$", this._addingComment$.asObservable());
71
+ this._sidebarService = t, this._threadCommentPanelService = r, this.disposeWithMe(() => {
72
+ this._addingComment$.complete();
73
+ });
74
+ }
75
+ get addingComment() {
76
+ return this._addingComment$.getValue();
77
+ }
78
+ startAdd(t) {
79
+ this._addingComment$.next(t);
80
+ }
81
+ endAdd() {
82
+ this._addingComment$.next(void 0);
83
+ }
84
+ };
85
+ T = it([
86
+ ee(0, L),
87
+ ee(1, _(U))
88
+ ], T);
89
+ const ve = (e) => {
90
90
  var d;
91
- const t = e.get(F), r = e.get(H), n = (d = Ee(
91
+ const t = e.get(H), r = e.get(F), n = (d = Ke(
92
92
  p.UNIVER_DOC,
93
- Ae,
93
+ He,
94
94
  e.get(w),
95
95
  t
96
96
  )) == null ? void 0 : d.getSkeleton(), o = n == null ? void 0 : n.getViewModel().getEditArea();
@@ -99,7 +99,7 @@ const he = {
99
99
  const i = r.getActiveTextRange();
100
100
  return !!(i == null || i.collapsed);
101
101
  };
102
- function st(e) {
102
+ function dt(e) {
103
103
  return {
104
104
  id: W.id,
105
105
  type: ae.BUTTON,
@@ -108,7 +108,7 @@ function st(e) {
108
108
  tooltip: "threadCommentUI.panel.addComment",
109
109
  hidden$: ce(e, p.UNIVER_DOC, void 0, be),
110
110
  disabled$: new me(function(t) {
111
- const n = e.get(H).textSelection$.pipe(le(16)).subscribe(() => {
111
+ const n = e.get(F).textSelection$.pipe(le(16)).subscribe(() => {
112
112
  t.next(ve(e));
113
113
  });
114
114
  return () => {
@@ -117,7 +117,7 @@ function st(e) {
117
117
  })
118
118
  };
119
119
  }
120
- function ct(e) {
120
+ function st(e) {
121
121
  return {
122
122
  id: Q.id,
123
123
  type: ae.BUTTON,
@@ -128,7 +128,7 @@ function ct(e) {
128
128
  };
129
129
  }
130
130
  const M = () => {
131
- const e = E(w), t = E(re), r = k(() => e.getCurrentTypeOfUnit$(p.UNIVER_DOC).pipe(Qe((c) => !!c && !oe(c.getUnitId()))), [e]), n = G(r), o = k(() => new me((c) => c.next(S)), []), i = E(H), d = k(
131
+ const e = E(w), t = E(re), r = k(() => e.getCurrentTypeOfUnit$(p.UNIVER_DOC).pipe(Qe((c) => !!c && !oe(c.getUnitId()))), [e]), n = G(r), o = k(() => new me((c) => c.next(S)), []), i = E(F), d = k(
132
132
  () => i.textSelection$.pipe(le(16)),
133
133
  [i.textSelection$]
134
134
  );
@@ -143,7 +143,7 @@ const M = () => {
143
143
  })) != null ? D : []);
144
144
  const I = s.onCommandExecuted((u) => {
145
145
  var O;
146
- if (u.id === de.id) {
146
+ if (u.id === se.id) {
147
147
  const R = /* @__PURE__ */ new Set(), Z = n == null ? void 0 : n.getCustomDecorations();
148
148
  h((O = Z == null ? void 0 : Z.map((A) => A.id).filter((A) => {
149
149
  const Se = R.has(A);
@@ -158,7 +158,7 @@ const M = () => {
158
158
  return null;
159
159
  const v = ve(t), C = n.getUnitId();
160
160
  return /* @__PURE__ */ Xe(
161
- Pe,
161
+ Be,
162
162
  {
163
163
  unitId: C,
164
164
  subUnitId$: o,
@@ -226,10 +226,10 @@ const N = {
226
226
  type: P.OPERATION,
227
227
  handler(e) {
228
228
  var u, O, R;
229
- const t = e.get(U), n = e.get(w).getCurrentUnitForType(p.UNIVER_DOC), o = e.get(H), i = e.get(F), d = e.get(De), s = e.get(T), l = e.get(b), f = e.get(L), a = o.getActiveTextRange();
229
+ const t = e.get(U), n = e.get(w).getCurrentUnitForType(p.UNIVER_DOC), o = e.get(F), i = e.get(H), d = e.get(De), s = e.get(T), l = e.get(b), f = e.get(L), a = o.getActiveTextRange();
230
230
  if (!n || !a)
231
231
  return !1;
232
- const h = (u = i.getRenderById(n.getUnitId())) == null ? void 0 : u.with(Fe);
232
+ const h = (u = i.getRenderById(n.getUnitId())) == null ? void 0 : u.with(we);
233
233
  if (h == null || h.setReserveRangesStatus(!0), a.collapsed)
234
234
  return t.panelVisible ? (t.setPanelVisible(!1), f.close()) : l.executeCommand(N.id), !0;
235
235
  l.executeCommand(N.id);
@@ -238,7 +238,7 @@ const N = {
238
238
  subUnitId: m,
239
239
  id: I,
240
240
  ref: c,
241
- dT: Ke(),
241
+ dT: je(),
242
242
  personId: d.getCurrentUser().userID,
243
243
  text: {
244
244
  dataStream: `\r
@@ -255,7 +255,7 @@ const N = {
255
255
  commentId: I
256
256
  }), !0;
257
257
  }
258
- };
258
+ }, ct = "docs-thread-comment-ui.config", te = {};
259
259
  var at = Object.getOwnPropertyDescriptor, mt = (e, t, r, n) => {
260
260
  for (var o = n > 1 ? void 0 : n ? at(t, r) : t, i = e.length - 1, d; i >= 0; i--)
261
261
  (d = e[i]) && (o = d(o) || o);
@@ -270,7 +270,7 @@ let V = class extends B {
270
270
  this.disposeWithMe(
271
271
  this._commandService.onCommandExecuted((t) => {
272
272
  var r, n, o, i;
273
- if (t.id === Ne.id) {
273
+ if (t.id === Le.id) {
274
274
  const d = t.params, { unitId: s, ranges: l } = d;
275
275
  if (oe(s)) return;
276
276
  const f = this._univerInstanceService.getUnit(s, p.UNIVER_DOC), a = l[0];
@@ -293,7 +293,7 @@ let V = class extends B {
293
293
  }
294
294
  if (!this._threadCommentPanelService.activeCommentId)
295
295
  return;
296
- this._commandService.executeCommand(ie.id);
296
+ this._commandService.executeCommand(de.id);
297
297
  }
298
298
  })
299
299
  );
@@ -304,7 +304,7 @@ let V = class extends B {
304
304
  if (e) {
305
305
  const i = this._univerInstanceService.getUnit(e.unitId);
306
306
  if (i) {
307
- const d = (t = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : t.with(He), s = (n = (r = i.getBody()) == null ? void 0 : r.customDecorations) == null ? void 0 : n.find((l) => l.id === e.commentId);
307
+ const d = (t = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : t.with(Ae), s = (n = (r = i.getBody()) == null ? void 0 : r.customDecorations) == null ? void 0 : n.find((l) => l.id === e.commentId);
308
308
  s && d && d.scrollToRange({
309
309
  startOffset: s.startIndex,
310
310
  endOffset: s.endIndex,
@@ -321,8 +321,8 @@ V = mt([
321
321
  y(1, w),
322
322
  y(2, b),
323
323
  y(3, _(T)),
324
- y(4, F),
325
- y(5, _(se))
324
+ y(4, H),
325
+ y(5, _(ie))
326
326
  ], V);
327
327
  var g = function() {
328
328
  return g = Object.assign || function(e) {
@@ -382,14 +382,14 @@ const vt = {
382
382
  [Je.MEDIA]: {
383
383
  [Q.id]: {
384
384
  order: 3,
385
- menuItemFactory: ct
385
+ menuItemFactory: st
386
386
  }
387
387
  },
388
388
  [Ge.MAIN_AREA]: {
389
389
  [ke.DATA]: {
390
390
  [W.id]: {
391
391
  order: 1,
392
- menuItemFactory: st
392
+ menuItemFactory: dt
393
393
  }
394
394
  }
395
395
  }
@@ -456,7 +456,7 @@ let z = class extends B {
456
456
  }));
457
457
  }
458
458
  _interceptorViewModel() {
459
- this._docInterceptorService.intercept($e.CUSTOM_DECORATION, {
459
+ this._docInterceptorService.intercept(Ze.CUSTOM_DECORATION, {
460
460
  handler: (e, t, r) => {
461
461
  if (!e)
462
462
  return r(e);
@@ -484,7 +484,7 @@ let z = class extends B {
484
484
  let n = r.sort();
485
485
  this.disposeWithMe(this._commandService.onCommandExecuted((s) => {
486
486
  var l, f, a;
487
- if (s.id === de.id) {
487
+ if (s.id === se.id) {
488
488
  if (s.params.unitId !== this._context.unit.getUnitId())
489
489
  return;
490
490
  const v = (a = (f = (l = this._context.unit.getBody()) == null ? void 0 : l.customDecorations) == null ? void 0 : f.filter((c) => c.type === Y.COMMENT).map((c) => c.id)) != null ? a : [], C = v.sort();
@@ -503,11 +503,11 @@ let z = class extends B {
503
503
  }
504
504
  };
505
505
  z = It([
506
- x(1, _(Ve)),
506
+ x(1, _(We)),
507
507
  x(2, _(U)),
508
- x(3, _(Le)),
508
+ x(3, _(Ne)),
509
509
  x(4, w),
510
- x(5, _(se)),
510
+ x(5, _(ie)),
511
511
  x(6, b)
512
512
  ], z);
513
513
  var St = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Mt = (e, t, r) => t in e ? St(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, bt = (e, t, r, n) => {
@@ -516,14 +516,14 @@ var St = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Mt = (e, t
516
516
  return o;
517
517
  }, q = (e, t) => (r, n) => t(r, n, e), Ie = (e, t, r) => Mt(e, typeof t != "symbol" ? t + "" : t, r);
518
518
  let j = class extends Ue {
519
- constructor(e = ee, t, r, n) {
519
+ constructor(e = te, t, r, n) {
520
520
  super(), this._config = e, this._injector = t, this._renderManagerSrv = r, this._configService = n;
521
521
  const { menu: o, ...i } = Re(
522
522
  {},
523
- ee,
523
+ te,
524
524
  this._config
525
525
  );
526
- o && this._configService.setConfig("menu", o, { merge: !0 }), this._configService.setConfig(ot, i);
526
+ o && this._configService.setConfig("menu", o, { merge: !0 }), this._configService.setConfig(ct, i);
527
527
  }
528
528
  onStarting() {
529
529
  [
@@ -546,9 +546,9 @@ let j = class extends Ue {
546
546
  Ie(j, "pluginName", rt);
547
547
  Ie(j, "type", p.UNIVER_DOC);
548
548
  j = bt([
549
- xe(we),
549
+ xe(Fe),
550
550
  q(1, _(re)),
551
- q(2, F),
551
+ q(2, H),
552
552
  q(3, Te)
553
553
  ], j);
554
554
  export {
package/lib/index.js CHANGED
@@ -1,52 +1,23 @@
1
1
  var Oe = Object.defineProperty;
2
2
  var Me = (e, t, r) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var K = (e, t, r) => Me(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as _, Disposable as B, CommandType as P, ICommandService as b, CustomDecorationType as Y, sequenceExecute as ne, UniverInstanceType as p, SHEET_EDITOR_UNITS as be, IUniverInstanceService as w, Injector as re, isInternalEditorID as oe, UserManagerService as De, BuildTextUtils as ye, DependentOn as xe, IConfigService as Te, Plugin as Ue, merge as Re } from "@univerjs/core";
5
- import { IRenderManagerService as F, withCurrentTypeOfRenderer as Ee, DocumentEditArea as X } from "@univerjs/engine-render";
6
- import { ThreadCommentPanelService as U, SetActiveCommentOperation as ie, ThreadCommentPanel as Pe, UniverThreadCommentUIPlugin as we } from "@univerjs/thread-comment-ui";
7
- import { DocSelectionManagerService as H, DocSkeletonManagerService as Ae, RichTextEditingMutation as de, SetTextSelectionsOperation as Ne, DocInterceptorService as Ve, DOC_INTERCEPTOR_POINT as $e } from "@univerjs/docs";
8
- import { addCustomDecorationBySelectionFactory as je, deleteCustomDecorationFactory as Be, DocSelectionRenderService as Fe, DocBackScrollRenderController as He, DocRenderController as Le } from "@univerjs/docs-ui";
9
- import { IThreadCommentDataSourceService as We, AddCommentMutation as Ze, getDT as Ke, ThreadCommentModel as se } from "@univerjs/thread-comment";
4
+ import { CommandType as P, ICommandService as b, CustomDecorationType as Y, sequenceExecute as ne, Inject as _, Disposable as B, UniverInstanceType as p, SHEET_EDITOR_UNITS as be, IUniverInstanceService as w, Injector as re, isInternalEditorID as oe, UserManagerService as De, BuildTextUtils as ye, DependentOn as xe, IConfigService as Te, Plugin as Ue, merge as Re } from "@univerjs/core";
5
+ import { addCustomDecorationBySelectionFactory as Ee, deleteCustomDecorationFactory as Pe, DocSelectionRenderService as we, DocBackScrollRenderController as Ae, DocRenderController as Ne } from "@univerjs/docs-ui";
6
+ import { IThreadCommentDataSourceService as Ve, AddCommentMutation as $e, getDT as je, ThreadCommentModel as ie } from "@univerjs/thread-comment";
7
+ import { SetActiveCommentOperation as de, ThreadCommentPanelService as U, ThreadCommentPanel as Be, UniverThreadCommentUIPlugin as Fe } from "@univerjs/thread-comment-ui";
8
+ import { DocSelectionManagerService as F, DocSkeletonManagerService as He, RichTextEditingMutation as se, SetTextSelectionsOperation as Le, DocInterceptorService as We, DOC_INTERCEPTOR_POINT as Ze } from "@univerjs/docs";
9
+ import { IRenderManagerService as H, withCurrentTypeOfRenderer as Ke, DocumentEditArea as X } from "@univerjs/engine-render";
10
10
  import { ISidebarService as L, getMenuHiddenObservable as ce, MenuItemType as ae, useDependency as E, useObservable as G, ContextMenuPosition as Ge, ContextMenuGroup as ke, RibbonInsertGroup as Je, IMenuManagerService as qe, ComponentManager as Ye } from "@univerjs/ui";
11
11
  import { BehaviorSubject as ze, Observable as me, debounceTime as le, filter as Qe } from "rxjs";
12
12
  import { jsx as Xe } from "react/jsx-runtime";
13
13
  import { useMemo as k, useState as et, useEffect as tt, forwardRef as ue, useRef as nt, createElement as fe } from "react";
14
- const rt = "DOC_THREAD_COMMENT_UI_PLUGIN", S = "default_doc", ot = "docs-thread-comment-ui.config", ee = {};
15
- var it = Object.getOwnPropertyDescriptor, dt = (e, t, r, n) => {
16
- for (var o = n > 1 ? void 0 : n ? it(t, r) : t, i = e.length - 1, d; i >= 0; i--)
17
- (d = e[i]) && (o = d(o) || o);
18
- return o;
19
- }, te = (e, t) => (r, n) => t(r, n, e);
20
- let T = class extends B {
21
- constructor(t, r) {
22
- super();
23
- K(this, "_addingComment$", new ze(void 0));
24
- K(this, "addingComment$", this._addingComment$.asObservable());
25
- this._sidebarService = t, this._threadCommentPanelService = r, this.disposeWithMe(() => {
26
- this._addingComment$.complete();
27
- });
28
- }
29
- get addingComment() {
30
- return this._addingComment$.getValue();
31
- }
32
- startAdd(t) {
33
- this._addingComment$.next(t);
34
- }
35
- endAdd() {
36
- this._addingComment$.next(void 0);
37
- }
38
- };
39
- T = dt([
40
- te(0, L),
41
- te(1, _(U))
42
- ], T);
43
- const he = {
14
+ const rt = "DOC_THREAD_COMMENT_UI_PLUGIN", S = "default_doc", he = {
44
15
  id: "docs.command.add-comment",
45
16
  type: P.COMMAND,
46
17
  async handler(e, t) {
47
18
  if (!t)
48
19
  return !1;
49
- const { comment: r, unitId: n } = t, i = await e.get(We).addComment(r), d = e.get(b), s = je(
20
+ const { comment: r, unitId: n } = t, i = await e.get(Ve).addComment(r), d = e.get(b), s = Ee(
50
21
  e,
51
22
  {
52
23
  id: i.threadId,
@@ -56,14 +27,14 @@ const he = {
56
27
  );
57
28
  if (s) {
58
29
  const l = {
59
- id: Ze.id,
30
+ id: $e.id,
60
31
  params: {
61
32
  unitId: n,
62
33
  subUnitId: S,
63
34
  comment: i
64
35
  }
65
36
  }, f = {
66
- id: ie.id,
37
+ id: de.id,
67
38
  params: {
68
39
  unitId: n,
69
40
  subUnitId: S,
@@ -80,17 +51,46 @@ const he = {
80
51
  async handler(e, t) {
81
52
  if (!t)
82
53
  return !1;
83
- const { commentId: r, unitId: n } = t, o = e.get(b), i = Be(e, {
54
+ const { commentId: r, unitId: n } = t, o = e.get(b), i = Pe(e, {
84
55
  id: r,
85
56
  unitId: n
86
57
  });
87
58
  return i ? (await ne([i], o)).result : !1;
88
59
  }
89
- }, ve = (e) => {
60
+ };
61
+ var ot = Object.getOwnPropertyDescriptor, it = (e, t, r, n) => {
62
+ for (var o = n > 1 ? void 0 : n ? ot(t, r) : t, i = e.length - 1, d; i >= 0; i--)
63
+ (d = e[i]) && (o = d(o) || o);
64
+ return o;
65
+ }, ee = (e, t) => (r, n) => t(r, n, e);
66
+ let T = class extends B {
67
+ constructor(t, r) {
68
+ super();
69
+ K(this, "_addingComment$", new ze(void 0));
70
+ K(this, "addingComment$", this._addingComment$.asObservable());
71
+ this._sidebarService = t, this._threadCommentPanelService = r, this.disposeWithMe(() => {
72
+ this._addingComment$.complete();
73
+ });
74
+ }
75
+ get addingComment() {
76
+ return this._addingComment$.getValue();
77
+ }
78
+ startAdd(t) {
79
+ this._addingComment$.next(t);
80
+ }
81
+ endAdd() {
82
+ this._addingComment$.next(void 0);
83
+ }
84
+ };
85
+ T = it([
86
+ ee(0, L),
87
+ ee(1, _(U))
88
+ ], T);
89
+ const ve = (e) => {
90
90
  var d;
91
- const t = e.get(F), r = e.get(H), n = (d = Ee(
91
+ const t = e.get(H), r = e.get(F), n = (d = Ke(
92
92
  p.UNIVER_DOC,
93
- Ae,
93
+ He,
94
94
  e.get(w),
95
95
  t
96
96
  )) == null ? void 0 : d.getSkeleton(), o = n == null ? void 0 : n.getViewModel().getEditArea();
@@ -99,7 +99,7 @@ const he = {
99
99
  const i = r.getActiveTextRange();
100
100
  return !!(i == null || i.collapsed);
101
101
  };
102
- function st(e) {
102
+ function dt(e) {
103
103
  return {
104
104
  id: W.id,
105
105
  type: ae.BUTTON,
@@ -108,7 +108,7 @@ function st(e) {
108
108
  tooltip: "threadCommentUI.panel.addComment",
109
109
  hidden$: ce(e, p.UNIVER_DOC, void 0, be),
110
110
  disabled$: new me(function(t) {
111
- const n = e.get(H).textSelection$.pipe(le(16)).subscribe(() => {
111
+ const n = e.get(F).textSelection$.pipe(le(16)).subscribe(() => {
112
112
  t.next(ve(e));
113
113
  });
114
114
  return () => {
@@ -117,7 +117,7 @@ function st(e) {
117
117
  })
118
118
  };
119
119
  }
120
- function ct(e) {
120
+ function st(e) {
121
121
  return {
122
122
  id: Q.id,
123
123
  type: ae.BUTTON,
@@ -128,7 +128,7 @@ function ct(e) {
128
128
  };
129
129
  }
130
130
  const M = () => {
131
- const e = E(w), t = E(re), r = k(() => e.getCurrentTypeOfUnit$(p.UNIVER_DOC).pipe(Qe((c) => !!c && !oe(c.getUnitId()))), [e]), n = G(r), o = k(() => new me((c) => c.next(S)), []), i = E(H), d = k(
131
+ const e = E(w), t = E(re), r = k(() => e.getCurrentTypeOfUnit$(p.UNIVER_DOC).pipe(Qe((c) => !!c && !oe(c.getUnitId()))), [e]), n = G(r), o = k(() => new me((c) => c.next(S)), []), i = E(F), d = k(
132
132
  () => i.textSelection$.pipe(le(16)),
133
133
  [i.textSelection$]
134
134
  );
@@ -143,7 +143,7 @@ const M = () => {
143
143
  })) != null ? D : []);
144
144
  const I = s.onCommandExecuted((u) => {
145
145
  var O;
146
- if (u.id === de.id) {
146
+ if (u.id === se.id) {
147
147
  const R = /* @__PURE__ */ new Set(), Z = n == null ? void 0 : n.getCustomDecorations();
148
148
  h((O = Z == null ? void 0 : Z.map((A) => A.id).filter((A) => {
149
149
  const Se = R.has(A);
@@ -158,7 +158,7 @@ const M = () => {
158
158
  return null;
159
159
  const v = ve(t), C = n.getUnitId();
160
160
  return /* @__PURE__ */ Xe(
161
- Pe,
161
+ Be,
162
162
  {
163
163
  unitId: C,
164
164
  subUnitId$: o,
@@ -226,10 +226,10 @@ const N = {
226
226
  type: P.OPERATION,
227
227
  handler(e) {
228
228
  var u, O, R;
229
- const t = e.get(U), n = e.get(w).getCurrentUnitForType(p.UNIVER_DOC), o = e.get(H), i = e.get(F), d = e.get(De), s = e.get(T), l = e.get(b), f = e.get(L), a = o.getActiveTextRange();
229
+ const t = e.get(U), n = e.get(w).getCurrentUnitForType(p.UNIVER_DOC), o = e.get(F), i = e.get(H), d = e.get(De), s = e.get(T), l = e.get(b), f = e.get(L), a = o.getActiveTextRange();
230
230
  if (!n || !a)
231
231
  return !1;
232
- const h = (u = i.getRenderById(n.getUnitId())) == null ? void 0 : u.with(Fe);
232
+ const h = (u = i.getRenderById(n.getUnitId())) == null ? void 0 : u.with(we);
233
233
  if (h == null || h.setReserveRangesStatus(!0), a.collapsed)
234
234
  return t.panelVisible ? (t.setPanelVisible(!1), f.close()) : l.executeCommand(N.id), !0;
235
235
  l.executeCommand(N.id);
@@ -238,7 +238,7 @@ const N = {
238
238
  subUnitId: m,
239
239
  id: I,
240
240
  ref: c,
241
- dT: Ke(),
241
+ dT: je(),
242
242
  personId: d.getCurrentUser().userID,
243
243
  text: {
244
244
  dataStream: `\r
@@ -255,7 +255,7 @@ const N = {
255
255
  commentId: I
256
256
  }), !0;
257
257
  }
258
- };
258
+ }, ct = "docs-thread-comment-ui.config", te = {};
259
259
  var at = Object.getOwnPropertyDescriptor, mt = (e, t, r, n) => {
260
260
  for (var o = n > 1 ? void 0 : n ? at(t, r) : t, i = e.length - 1, d; i >= 0; i--)
261
261
  (d = e[i]) && (o = d(o) || o);
@@ -270,7 +270,7 @@ let V = class extends B {
270
270
  this.disposeWithMe(
271
271
  this._commandService.onCommandExecuted((t) => {
272
272
  var r, n, o, i;
273
- if (t.id === Ne.id) {
273
+ if (t.id === Le.id) {
274
274
  const d = t.params, { unitId: s, ranges: l } = d;
275
275
  if (oe(s)) return;
276
276
  const f = this._univerInstanceService.getUnit(s, p.UNIVER_DOC), a = l[0];
@@ -293,7 +293,7 @@ let V = class extends B {
293
293
  }
294
294
  if (!this._threadCommentPanelService.activeCommentId)
295
295
  return;
296
- this._commandService.executeCommand(ie.id);
296
+ this._commandService.executeCommand(de.id);
297
297
  }
298
298
  })
299
299
  );
@@ -304,7 +304,7 @@ let V = class extends B {
304
304
  if (e) {
305
305
  const i = this._univerInstanceService.getUnit(e.unitId);
306
306
  if (i) {
307
- const d = (t = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : t.with(He), s = (n = (r = i.getBody()) == null ? void 0 : r.customDecorations) == null ? void 0 : n.find((l) => l.id === e.commentId);
307
+ const d = (t = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : t.with(Ae), s = (n = (r = i.getBody()) == null ? void 0 : r.customDecorations) == null ? void 0 : n.find((l) => l.id === e.commentId);
308
308
  s && d && d.scrollToRange({
309
309
  startOffset: s.startIndex,
310
310
  endOffset: s.endIndex,
@@ -321,8 +321,8 @@ V = mt([
321
321
  y(1, w),
322
322
  y(2, b),
323
323
  y(3, _(T)),
324
- y(4, F),
325
- y(5, _(se))
324
+ y(4, H),
325
+ y(5, _(ie))
326
326
  ], V);
327
327
  var g = function() {
328
328
  return g = Object.assign || function(e) {
@@ -382,14 +382,14 @@ const vt = {
382
382
  [Je.MEDIA]: {
383
383
  [Q.id]: {
384
384
  order: 3,
385
- menuItemFactory: ct
385
+ menuItemFactory: st
386
386
  }
387
387
  },
388
388
  [Ge.MAIN_AREA]: {
389
389
  [ke.DATA]: {
390
390
  [W.id]: {
391
391
  order: 1,
392
- menuItemFactory: st
392
+ menuItemFactory: dt
393
393
  }
394
394
  }
395
395
  }
@@ -456,7 +456,7 @@ let z = class extends B {
456
456
  }));
457
457
  }
458
458
  _interceptorViewModel() {
459
- this._docInterceptorService.intercept($e.CUSTOM_DECORATION, {
459
+ this._docInterceptorService.intercept(Ze.CUSTOM_DECORATION, {
460
460
  handler: (e, t, r) => {
461
461
  if (!e)
462
462
  return r(e);
@@ -484,7 +484,7 @@ let z = class extends B {
484
484
  let n = r.sort();
485
485
  this.disposeWithMe(this._commandService.onCommandExecuted((s) => {
486
486
  var l, f, a;
487
- if (s.id === de.id) {
487
+ if (s.id === se.id) {
488
488
  if (s.params.unitId !== this._context.unit.getUnitId())
489
489
  return;
490
490
  const v = (a = (f = (l = this._context.unit.getBody()) == null ? void 0 : l.customDecorations) == null ? void 0 : f.filter((c) => c.type === Y.COMMENT).map((c) => c.id)) != null ? a : [], C = v.sort();
@@ -503,11 +503,11 @@ let z = class extends B {
503
503
  }
504
504
  };
505
505
  z = It([
506
- x(1, _(Ve)),
506
+ x(1, _(We)),
507
507
  x(2, _(U)),
508
- x(3, _(Le)),
508
+ x(3, _(Ne)),
509
509
  x(4, w),
510
- x(5, _(se)),
510
+ x(5, _(ie)),
511
511
  x(6, b)
512
512
  ], z);
513
513
  var St = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Mt = (e, t, r) => t in e ? St(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, bt = (e, t, r, n) => {
@@ -516,14 +516,14 @@ var St = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Mt = (e, t
516
516
  return o;
517
517
  }, q = (e, t) => (r, n) => t(r, n, e), Ie = (e, t, r) => Mt(e, typeof t != "symbol" ? t + "" : t, r);
518
518
  let j = class extends Ue {
519
- constructor(e = ee, t, r, n) {
519
+ constructor(e = te, t, r, n) {
520
520
  super(), this._config = e, this._injector = t, this._renderManagerSrv = r, this._configService = n;
521
521
  const { menu: o, ...i } = Re(
522
522
  {},
523
- ee,
523
+ te,
524
524
  this._config
525
525
  );
526
- o && this._configService.setConfig("menu", o, { merge: !0 }), this._configService.setConfig(ot, i);
526
+ o && this._configService.setConfig("menu", o, { merge: !0 }), this._configService.setConfig(ct, i);
527
527
  }
528
528
  onStarting() {
529
529
  [
@@ -546,9 +546,9 @@ let j = class extends Ue {
546
546
  Ie(j, "pluginName", rt);
547
547
  Ie(j, "type", p.UNIVER_DOC);
548
548
  j = bt([
549
- xe(we),
549
+ xe(Fe),
550
550
  q(1, _(re)),
551
- q(2, F),
551
+ q(2, H),
552
552
  q(3, Te)
553
553
  ], j);
554
554
  export {
@@ -14,10 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import './global.css';
17
- export { UniverDocsThreadCommentUIPlugin } from './plugin';
18
17
  export { AddDocCommentComment } from './commands/commands/add-doc-comment.command';
19
18
  export type { IAddDocCommentComment } from './commands/commands/add-doc-comment.command';
20
- export { ShowCommentPanelOperation, StartAddCommentOperation } from './commands/operations/show-comment-panel.operation';
21
- export type { IShowCommentPanelOperationParams } from './commands/operations/show-comment-panel.operation';
22
19
  export { DeleteDocCommentComment } from './commands/commands/delete-doc-comment.command';
23
20
  export type { IDeleteDocCommentComment } from './commands/commands/delete-doc-comment.command';
21
+ export { ShowCommentPanelOperation, StartAddCommentOperation } from './commands/operations/show-comment-panel.operation';
22
+ export type { IShowCommentPanelOperationParams } from './commands/operations/show-comment-panel.operation';
23
+ export type { IUniverDocsThreadCommentUIConfig } from './controllers/config.schema';
24
+ export { UniverDocsThreadCommentUIPlugin } from './plugin';
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/thread-comment-ui"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/thread-comment"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/thread-comment-ui","@univerjs/docs","@univerjs/docs-ui","@univerjs/thread-comment","@univerjs/ui","rxjs","react/jsx-runtime","react"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverDocsThreadCommentUi={},c.UniverCore,c.UniverEngineRender,c.UniverThreadCommentUi,c.UniverDocs,c.UniverDocsUi,c.UniverThreadComment,c.UniverUi,c.rxjs,c.React,c.React))})(this,function(c,o,p,O,T,w,A,u,x,re,D){"use strict";var be=Object.defineProperty;var Ue=(c,o,p)=>o in c?be(c,o,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[o]=p;var J=(c,o,p)=>Ue(c,typeof o!="symbol"?o+"":o,p);const ie="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",oe="docs-thread-comment-ui.config",Y={};var se=Object.getOwnPropertyDescriptor,ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?se(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},z=(e,t)=>(r,n)=>t(r,n,e);let E=class extends o.Disposable{constructor(t,r){super();J(this,"_addingComment$",new x.BehaviorSubject(void 0));J(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=r,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};E=ae([z(0,u.ISidebarService),z(1,o.Inject(O.ThreadCommentPanelService))],E);const H={id:"docs.command.add-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:r,unitId:n}=t,s=await e.get(A.IThreadCommentDataSourceService).addComment(r),a=e.get(o.ICommandService),d=w.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(d){const C={id:A.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},h={id:O.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([C,d,h],a)).result}return!1}},L={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:r,unitId:n}=t,i=e.get(o.ICommandService),s=w.deleteCustomDecorationFactory(e,{id:r,unitId:n});return s?(await o.sequenceExecute([s],i)).result:!1}},Q=e=>{var a;const t=e.get(p.IRenderManagerService),r=e.get(T.DocSelectionManagerService),n=(a=p.withCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_DOC,T.DocSkeletonManagerService,e.get(o.IUniverInstanceService),t))==null?void 0:a.getSkeleton(),i=n==null?void 0:n.getViewModel().getEditArea();if(i===p.DocumentEditArea.FOOTER||i===p.DocumentEditArea.HEADER)return!0;const s=r.getActiveTextRange();return!!(s==null||s.collapsed)};function de(e){return{id:V.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 x.Observable(function(t){const n=e.get(T.DocSelectionManagerService).textSelection$.pipe(x.debounceTime(16)).subscribe(()=>{t.next(Q(e))});return()=>{n.unsubscribe()}})}}function ce(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 U=()=>{const e=u.useDependency(o.IUniverInstanceService),t=u.useDependency(o.Injector),r=D.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(x.filter(m=>!!m&&!o.isInternalEditorID(m.getUnitId()))),[e]),n=u.useObservable(r),i=D.useMemo(()=>new x.Observable(m=>m.next(M)),[]),s=u.useDependency(T.DocSelectionManagerService),a=D.useMemo(()=>s.textSelection$.pipe(x.debounceTime(16)),[s.textSelection$]);u.useObservable(a);const d=u.useDependency(o.ICommandService),C=u.useDependency(E),h=u.useObservable(C.addingComment$),[l,I]=D.useState([]);if(D.useEffect(()=>{var j;const m=new Set,v=n==null?void 0:n.getCustomDecorations();I((j=v==null?void 0:v.map(f=>f.id).filter(f=>{const b=m.has(f);return m.add(f),!b}))!=null?j:[]);const y=d.onCommandExecuted(f=>{var b;if(f.id===T.RichTextEditingMutation.id){const $=new Set,k=n==null?void 0:n.getCustomDecorations();I((b=k==null?void 0:k.map(F=>F.id).filter(F=>{const ye=$.has(F);return $.add(F),!ye}))!=null?b:[])}});return()=>{y.dispose()}},[d,n]),!n)return null;const _=Q(t),g=n.getUnitId();return re.jsx(O.ThreadCommentPanel,{unitId:g,subUnitId$:i,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{d.executeCommand(V.id)},getSubUnitName:()=>"",disableAdd:_,tempComment:h,onAddComment:m=>{if(!m.parentId){const v={unitId:g,range:h,comment:m};return d.executeCommand(H.id,v),C.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const v={unitId:g,commentId:m.id};return d.executeCommand(L.id,v),!1}return!0},showComments:l})};U.componentKey="univer.doc.thread-comment-panel";const N={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var i;const r=e.get(O.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==U.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:U.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.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(O.ThreadCommentPanelService),r=e.get(u.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==U.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:U.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(r.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},V={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var f,b,$;const t=e.get(O.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),i=e.get(T.DocSelectionManagerService),s=e.get(p.IRenderManagerService),a=e.get(o.UserManagerService),d=e.get(E),C=e.get(o.ICommandService),h=e.get(u.ISidebarService),l=i.getActiveTextRange();if(!n||!l)return!1;const I=(f=s.getRenderById(n.getUnitId()))==null?void 0:f.with(w.DocSelectionRenderService);if(I==null||I.setReserveRangesStatus(!0),l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),h.close()):C.executeCommand(N.id),!0;C.executeCommand(N.id);const _=n.getUnitId(),g=(($=(b=n.getBody())==null?void 0:b.dataStream)!=null?$:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(g),v=M,y="",j={unitId:_,subUnitId:v,id:y,ref:m,dT:A.getDT(),personId:a.getCurrentUser().userID,text:{dataStream:`\r
2
- `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:y};return I==null||I.blur(),d.startAdd(j),t.setActiveComment({unitId:_,subUnitId:v,commentId:y}),!0}};var me=Object.getOwnPropertyDescriptor,le=(e,t,r,n)=>{for(var i=n>1?void 0:n?me(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},R=(e,t)=>(r,n)=>t(r,n,e);let B=class extends o.Disposable{constructor(e,t,r,n,i,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,s;if(t.id===T.SetTextSelectionsOperation.id){const a=t.params,{unitId:d,ranges:C}=a;if(o.isInternalEditorID(d))return;const h=this._univerInstanceService.getUnit(d,o.UniverInstanceType.UNIVER_DOC),l=C[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&&h){const{startOffset:I,endOffset:_,collapsed:g}=l;let m;if(g?m=(n=(r=h.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(v=>v.startIndex<=I&&v.endIndex>=_-1):m=(s=(i=h.getBody())==null?void 0:i.customDecorations)==null?void 0:s.find(v=>v.startIndex<=I&&v.endIndex>=_-1),m){const v=this._threadCommentModel.getComment(d,M,m.id);v&&!v.resolved&&this._commandService.executeCommand(N.id,{activeComment:{unitId:d,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(O.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const a=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(w.DocBackScrollRenderController),d=(n=(r=s.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);d&&a&&a.scrollToRange({startOffset:d.startIndex,endOffset:d.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};B=le([R(0,o.Inject(O.ThreadCommentPanelService)),R(1,o.IUniverInstanceService),R(2,o.ICommandService),R(3,o.Inject(E)),R(4,p.IRenderManagerService),R(5,o.Inject(A.ThreadCommentModel))],B);var S=function(){return S=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},S.apply(this,arguments)},ue=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},X=D.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,a=ue(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),C=D.useRef("_".concat(fe()));return ee(r,"".concat(n),{defIds:r.defIds,idSuffix:C.current},S({ref:t,className:d},a),s)});function ee(e,t,r,n,i){return D.createElement(e.tag,S(S({key:t},ve(e,r,i)),n),(Ce(e,r).children||[]).map(function(s,a){return ee(s,"".concat(t,"-").concat(e.tag,"-").concat(a),r,void 0,i)}))}function ve(e,t,r){var n=S({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];a==="mask"&&typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Ce(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?S(S({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?S(S({},i),{attrs:S(S({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function fe(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var 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"}}]},te=D.forwardRef(function(e,t){return D.createElement(X,Object.assign({},e,{id:"comment-icon",ref:t,icon:he}))});te.displayName="CommentIcon";const Ie={[u.RibbonInsertGroup.MEDIA]:{[W.id]:{order:3,menuItemFactory:ce}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[V.id]:{order:1,menuItemFactory:de}}}};var ge=Object.getOwnPropertyDescriptor,pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},Z=(e,t)=>(r,n)=>t(r,n,e);let q=class extends o.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,L,N,V,W].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(Ie)}_initComponents(){[[U.componentKey,U],["CommentIcon",te]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=pe([Z(0,o.ICommandService),Z(1,u.IMenuManagerService),Z(2,o.Inject(u.ComponentManager))],q);var Se=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},P=(e,t)=>(r,n)=>t(r,n,e);let K=class extends o.Disposable{constructor(e,t,r,n,i,s,a){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=s,this._commandService=a,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var r;if(e){this._docRenderController.reRender(e.unitId);return}const t=(r=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:r.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,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:s}=t,a=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:C}=a||{},h=s.find(g=>g.id===d),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return r({...e,show:!1});const I=h&&i>=h.startIndex&&i<=h.endIndex,_=C===n&&e.id===d;return r({...e,active:_||I,show:!l.resolved})}})}_initSyncComments(){var i,s,a;const e=this._context.unit.getUnitId(),t=M,r=(a=(s=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:s.filter(d=>d.type===o.CustomDecorationType.COMMENT).map(d=>d.id))!=null?a:[];r.forEach(d=>{this._threadCommentModel.getComment(e,t,d)||this._threadCommentModel.addComment(e,t,{id:d,threadId:d,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(d=>{var C,h,l;if(d.id===T.RichTextEditingMutation.id){if(d.params.unitId!==this._context.unit.getUnitId())return;const _=(l=(h=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:h.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],g=_.sort();if(JSON.stringify(n)!==JSON.stringify(g)){const m=new Set(n),v=new Set(g),y=new Set,j=new Set;_.forEach(f=>{m.has(f)||y.add(f)}),n.forEach(f=>{v.has(f)||j.add(f)}),n=g,y.forEach(f=>{this._threadCommentModel.getComment(e,t,f)||this._threadCommentModel.addComment(e,t,{id:f,threadId:f,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...y])}}}))}};K=_e([P(1,o.Inject(T.DocInterceptorService)),P(2,o.Inject(O.ThreadCommentPanelService)),P(3,o.Inject(w.DocRenderController)),P(4,o.IUniverInstanceService),P(5,o.Inject(A.ThreadCommentModel)),P(6,o.ICommandService)],K);var Oe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,De=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Me=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},G=(e,t)=>(r,n)=>t(r,n,e),ne=(e,t,r)=>De(e,typeof t!="symbol"?t+"":t,r);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=Y,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:s,...a}=o.merge({},Y,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(oe,a)}onStarting(){[[q],[B],[E]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(B),this._injector.get(q)}_initRenderModule(){[K].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},ne(c.UniverDocsThreadCommentUIPlugin,"pluginName",ie),ne(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(O.UniverThreadCommentUIPlugin),G(1,o.Inject(o.Injector)),G(2,p.IRenderManagerService),G(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=H,c.DeleteDocCommentComment=L,c.ShowCommentPanelOperation=N,c.StartAddCommentOperation=V,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (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,_,A,O,T,U,u,E,re,D){"use strict";var be=Object.defineProperty;var Ue=(c,o,_)=>o in c?be(c,o,{enumerable:!0,configurable:!0,writable:!0,value:_}):c[o]=_;var J=(c,o,_)=>Ue(c,typeof o!="symbol"?o+"":o,_);const ie="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:r,unitId:n}=t,s=await e.get(A.IThreadCommentDataSourceService).addComment(r),a=e.get(o.ICommandService),d=_.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(d){const C={id:A.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},h={id:O.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([C,d,h],a)).result}return!1}},L={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:r,unitId:n}=t,i=e.get(o.ICommandService),s=_.deleteCustomDecorationFactory(e,{id:r,unitId:n});return s?(await o.sequenceExecute([s],i)).result:!1}};var oe=Object.getOwnPropertyDescriptor,se=(e,t,r,n)=>{for(var i=n>1?void 0:n?oe(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},Y=(e,t)=>(r,n)=>t(r,n,e);let R=class extends o.Disposable{constructor(t,r){super();J(this,"_addingComment$",new E.BehaviorSubject(void 0));J(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=r,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(O.ThreadCommentPanelService))],R);const z=e=>{var a;const t=e.get(U.IRenderManagerService),r=e.get(T.DocSelectionManagerService),n=(a=U.withCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_DOC,T.DocSkeletonManagerService,e.get(o.IUniverInstanceService),t))==null?void 0:a.getSkeleton(),i=n==null?void 0:n.getViewModel().getEditArea();if(i===U.DocumentEditArea.FOOTER||i===U.DocumentEditArea.HEADER)return!0;const s=r.getActiveTextRange();return!!(s==null||s.collapsed)};function ae(e){return{id:V.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: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 x=()=>{const e=u.useDependency(o.IUniverInstanceService),t=u.useDependency(o.Injector),r=D.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(E.filter(m=>!!m&&!o.isInternalEditorID(m.getUnitId()))),[e]),n=u.useObservable(r),i=D.useMemo(()=>new E.Observable(m=>m.next(M)),[]),s=u.useDependency(T.DocSelectionManagerService),a=D.useMemo(()=>s.textSelection$.pipe(E.debounceTime(16)),[s.textSelection$]);u.useObservable(a);const d=u.useDependency(o.ICommandService),C=u.useDependency(R),h=u.useObservable(C.addingComment$),[l,I]=D.useState([]);if(D.useEffect(()=>{var w;const m=new Set,v=n==null?void 0:n.getCustomDecorations();I((w=v==null?void 0:v.map(f=>f.id).filter(f=>{const b=m.has(f);return m.add(f),!b}))!=null?w:[]);const y=d.onCommandExecuted(f=>{var b;if(f.id===T.RichTextEditingMutation.id){const $=new Set,k=n==null?void 0:n.getCustomDecorations();I((b=k==null?void 0:k.map(F=>F.id).filter(F=>{const ye=$.has(F);return $.add(F),!ye}))!=null?b:[])}});return()=>{y.dispose()}},[d,n]),!n)return null;const S=z(t),g=n.getUnitId();return re.jsx(O.ThreadCommentPanel,{unitId:g,subUnitId$:i,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{d.executeCommand(V.id)},getSubUnitName:()=>"",disableAdd:S,tempComment:h,onAddComment:m=>{if(!m.parentId){const v={unitId:g,range:h,comment:m};return d.executeCommand(H.id,v),C.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const v={unitId:g,commentId:m.id};return d.executeCommand(L.id,v),!1}return!0},showComments:l})};x.componentKey="univer.doc.thread-comment-panel";const N={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var i;const r=e.get(O.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==x.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:x.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.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(O.ThreadCommentPanelService),r=e.get(u.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==x.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:x.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(r.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},V={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var f,b,$;const t=e.get(O.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),i=e.get(T.DocSelectionManagerService),s=e.get(U.IRenderManagerService),a=e.get(o.UserManagerService),d=e.get(R),C=e.get(o.ICommandService),h=e.get(u.ISidebarService),l=i.getActiveTextRange();if(!n||!l)return!1;const I=(f=s.getRenderById(n.getUnitId()))==null?void 0:f.with(_.DocSelectionRenderService);if(I==null||I.setReserveRangesStatus(!0),l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),h.close()):C.executeCommand(N.id),!0;C.executeCommand(N.id);const S=n.getUnitId(),g=(($=(b=n.getBody())==null?void 0:b.dataStream)!=null?$:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(g),v=M,y="",w={unitId:S,subUnitId:v,id:y,ref:m,dT:A.getDT(),personId:a.getCurrentUser().userID,text:{dataStream:`\r
2
+ `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:y};return I==null||I.blur(),d.startAdd(w),t.setActiveComment({unitId:S,subUnitId:v,commentId:y}),!0}},ce="docs-thread-comment-ui.config",Q={};var me=Object.getOwnPropertyDescriptor,le=(e,t,r,n)=>{for(var i=n>1?void 0:n?me(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},P=(e,t)=>(r,n)=>t(r,n,e);let B=class extends o.Disposable{constructor(e,t,r,n,i,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,s;if(t.id===T.SetTextSelectionsOperation.id){const a=t.params,{unitId:d,ranges:C}=a;if(o.isInternalEditorID(d))return;const h=this._univerInstanceService.getUnit(d,o.UniverInstanceType.UNIVER_DOC),l=C[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&&h){const{startOffset:I,endOffset:S,collapsed:g}=l;let m;if(g?m=(n=(r=h.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(v=>v.startIndex<=I&&v.endIndex>=S-1):m=(s=(i=h.getBody())==null?void 0:i.customDecorations)==null?void 0:s.find(v=>v.startIndex<=I&&v.endIndex>=S-1),m){const v=this._threadCommentModel.getComment(d,M,m.id);v&&!v.resolved&&this._commandService.executeCommand(N.id,{activeComment:{unitId:d,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(O.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const a=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(_.DocBackScrollRenderController),d=(n=(r=s.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);d&&a&&a.scrollToRange({startOffset:d.startIndex,endOffset:d.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};B=le([P(0,o.Inject(O.ThreadCommentPanelService)),P(1,o.IUniverInstanceService),P(2,o.ICommandService),P(3,o.Inject(R)),P(4,U.IRenderManagerService),P(5,o.Inject(A.ThreadCommentModel))],B);var p=function(){return p=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},p.apply(this,arguments)},ue=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},X=D.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,a=ue(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),C=D.useRef("_".concat(fe()));return ee(r,"".concat(n),{defIds:r.defIds,idSuffix:C.current},p({ref:t,className:d},a),s)});function ee(e,t,r,n,i){return D.createElement(e.tag,p(p({key:t},ve(e,r,i)),n),(Ce(e,r).children||[]).map(function(s,a){return ee(s,"".concat(t,"-").concat(e.tag,"-").concat(a),r,void 0,i)}))}function ve(e,t,r){var n=p({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];a==="mask"&&typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Ce(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?p(p({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?p(p({},i),{attrs:p(p({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function fe(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var 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"}}]},te=D.forwardRef(function(e,t){return D.createElement(X,Object.assign({},e,{id:"comment-icon",ref:t,icon:he}))});te.displayName="CommentIcon";const Ie={[u.RibbonInsertGroup.MEDIA]:{[W.id]:{order:3,menuItemFactory:de}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[V.id]:{order:1,menuItemFactory:ae}}}};var ge=Object.getOwnPropertyDescriptor,pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},Z=(e,t)=>(r,n)=>t(r,n,e);let q=class extends o.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,L,N,V,W].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(Ie)}_initComponents(){[[x.componentKey,x],["CommentIcon",te]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=pe([Z(0,o.ICommandService),Z(1,u.IMenuManagerService),Z(2,o.Inject(u.ComponentManager))],q);var Se=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},j=(e,t)=>(r,n)=>t(r,n,e);let K=class extends o.Disposable{constructor(e,t,r,n,i,s,a){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=s,this._commandService=a,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var r;if(e){this._docRenderController.reRender(e.unitId);return}const t=(r=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:r.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,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:s}=t,a=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:C}=a||{},h=s.find(g=>g.id===d),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return r({...e,show:!1});const I=h&&i>=h.startIndex&&i<=h.endIndex,S=C===n&&e.id===d;return r({...e,active:S||I,show:!l.resolved})}})}_initSyncComments(){var i,s,a;const e=this._context.unit.getUnitId(),t=M,r=(a=(s=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:s.filter(d=>d.type===o.CustomDecorationType.COMMENT).map(d=>d.id))!=null?a:[];r.forEach(d=>{this._threadCommentModel.getComment(e,t,d)||this._threadCommentModel.addComment(e,t,{id:d,threadId:d,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(d=>{var C,h,l;if(d.id===T.RichTextEditingMutation.id){if(d.params.unitId!==this._context.unit.getUnitId())return;const S=(l=(h=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:h.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],g=S.sort();if(JSON.stringify(n)!==JSON.stringify(g)){const m=new Set(n),v=new Set(g),y=new Set,w=new Set;S.forEach(f=>{m.has(f)||y.add(f)}),n.forEach(f=>{v.has(f)||w.add(f)}),n=g,y.forEach(f=>{this._threadCommentModel.getComment(e,t,f)||this._threadCommentModel.addComment(e,t,{id:f,threadId:f,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...y])}}}))}};K=_e([j(1,o.Inject(T.DocInterceptorService)),j(2,o.Inject(O.ThreadCommentPanelService)),j(3,o.Inject(_.DocRenderController)),j(4,o.IUniverInstanceService),j(5,o.Inject(A.ThreadCommentModel)),j(6,o.ICommandService)],K);var Oe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,De=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Me=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},G=(e,t)=>(r,n)=>t(r,n,e),ne=(e,t,r)=>De(e,typeof t!="symbol"?t+"":t,r);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=Q,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:s,...a}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ce,a)}onStarting(){[[q],[B],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(B),this._injector.get(q)}_initRenderModule(){[K].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},ne(c.UniverDocsThreadCommentUIPlugin,"pluginName",ie),ne(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(O.UniverThreadCommentUIPlugin),G(1,o.Inject(o.Injector)),G(2,U.IRenderManagerService),G(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=H,c.DeleteDocCommentComment=L,c.ShowCommentPanelOperation=N,c.StartAddCommentOperation=V,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-thread-comment-ui",
3
- "version": "0.8.2-nightly.202506261607",
3
+ "version": "0.8.3-nightly.202506271607",
4
4
  "private": false,
5
5
  "description": "Univer thread comment plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,13 +48,13 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@univerjs/icons": "^0.4.4",
51
- "@univerjs/core": "0.8.2-nightly.202506261607",
52
- "@univerjs/docs": "0.8.2-nightly.202506261607",
53
- "@univerjs/docs-ui": "0.8.2-nightly.202506261607",
54
- "@univerjs/thread-comment": "0.8.2-nightly.202506261607",
55
- "@univerjs/engine-render": "0.8.2-nightly.202506261607",
56
- "@univerjs/thread-comment-ui": "0.8.2-nightly.202506261607",
57
- "@univerjs/ui": "0.8.2-nightly.202506261607"
51
+ "@univerjs/core": "0.8.3-nightly.202506271607",
52
+ "@univerjs/docs": "0.8.3-nightly.202506271607",
53
+ "@univerjs/docs-ui": "0.8.3-nightly.202506271607",
54
+ "@univerjs/engine-render": "0.8.3-nightly.202506271607",
55
+ "@univerjs/thread-comment": "0.8.3-nightly.202506271607",
56
+ "@univerjs/thread-comment-ui": "0.8.3-nightly.202506271607",
57
+ "@univerjs/ui": "0.8.3-nightly.202506271607"
58
58
  },
59
59
  "devDependencies": {
60
60
  "postcss": "^8.5.6",
@@ -64,7 +64,7 @@
64
64
  "typescript": "^5.8.3",
65
65
  "vite": "^6.3.5",
66
66
  "vitest": "^3.2.4",
67
- "@univerjs-infra/shared": "0.8.2"
67
+ "@univerjs-infra/shared": "0.8.3"
68
68
  },
69
69
  "scripts": {
70
70
  "test": "vitest run",