@univerjs/docs-thread-comment-ui 0.8.0-nightly.202505261607 → 0.8.0-nightly.202505281606
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 +2 -2
- package/lib/es/index.js +143 -143
- package/lib/index.js +143 -143
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
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"),
|
|
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(w.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.indexOf(i.attrs.id)>-1?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:{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.13521 5.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.13521 8.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.13521 11.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-single",ref:t,icon:ge}))});ee.displayName="CommentSingle";const pe={[u.RibbonInsertGroup.MEDIA]:{[z.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(){[G,Z,N,j,z].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(pe)}_initComponents(){[[y.componentKey,y],["CommentSingle",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 K=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])}}}))}};K=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(w.ThreadCommentModel)),R(6,c.ICommandService)],K);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=k,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:o,...a}=c.merge({},k,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(){[K].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=G;exports.DeleteDocCommentComment=Z;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"),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;
|