@univerjs/docs-thread-comment-ui 0.5.5-nightly.202501211606 → 0.5.5-nightly.202501220324
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 -10
- package/lib/es/index.js +3 -33
- package/lib/types/views/doc-thread-comment-panel/index.d.ts +16 -2
- package/lib/umd/index.js +2 -10
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
"use strict";var de=Object.defineProperty;var ae=(e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var L=(e,t,r)=>ae(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),x=require("@univerjs/engine-render"),O=require("@univerjs/thread-comment-ui"),S=require("@univerjs/docs"),$=require("@univerjs/docs-ui"),N=require("@univerjs/thread-comment"),I=require("@univerjs/ui"),R=require("rxjs"),g=require("react"),me="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",le="docs-thread-comment-ui.config",Q={};var ue=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,Ce=(e,t,r,n)=>{for(var i=n>1?void 0:n?fe(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(n?c(t,r,i):c(i))||i);return n&&i&&ue(t,r,i),i},X=(e,t)=>(r,n)=>t(r,n,e);let P=class extends o.Disposable{constructor(t,r){super();L(this,"_addingComment$",new R.BehaviorSubject(void 0));L(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=Ce([X(0,I.ISidebarService),X(1,o.Inject(O.ThreadCommentPanelService))],P);var W={exports:{}},A={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var k;function he(){if(k)return A;k=1;var e=g,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function c(d,m,f){var a,C={},v=null,p=null;f!==void 0&&(v=""+f),m.key!==void 0&&(v=""+m.key),m.ref!==void 0&&(p=m.ref);for(a in m)n.call(m,a)&&!s.hasOwnProperty(a)&&(C[a]=m[a]);if(d&&d.defaultProps)for(a in m=d.defaultProps,m)C[a]===void 0&&(C[a]=m[a]);return{$$typeof:t,type:d,key:v,ref:p,props:C,_owner:i.current}}return A.Fragment=r,A.jsx=c,A.jsxs=c,A}var ee;function ve(){return ee||(ee=1,W.exports=he()),W.exports}var pe=ve();const Z={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(N.IThreadCommentDataSourceService).addComment(r),c=e.get(o.ICommandService),d=$.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(d){const m={id:N.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},f={id:O.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([m,d,f],c)).result}return!1}},z={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}},te=e=>{const t=e.get(x.IRenderManagerService),r=e.get(S.DocSelectionManagerService),n=t.getCurrent(),i=n==null?void 0:n.with(S.DocSkeletonManagerService).getSkeleton(),s=i==null?void 0:i.getViewModel().getEditArea();if(s===x.DocumentEditArea.FOOTER||s===x.DocumentEditArea.HEADER)return!0;const c=r.getActiveTextRange();return!!(c==null||c.collapsed)};function Ie(e){return{id:V.id,type:I.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:I.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,void 0,o.SHEET_EDITOR_UNITS),disabled$:new R.Observable(function(t){const n=e.get(S.DocSelectionManagerService).textSelection$.pipe(R.debounceTime(16)).subscribe(()=>{t.next(te(e))});return()=>{n.unsubscribe()}})}}function _e(e){return{id:Y.id,type:I.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:I.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC)}}const E=()=>{const e=o.useDependency(o.IUniverInstanceService),t=o.useDependency(o.Injector),r=g.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(R.filter(l=>!!l&&!o.isInternalEditorID(l.getUnitId()))),[e]),n=o.useObservable(r),i=g.useMemo(()=>new R.Observable(l=>l.next(M)),[]),s=o.useDependency(S.DocSelectionManagerService),c=g.useMemo(()=>s.textSelection$.pipe(R.debounceTime(16)),[s.textSelection$]);o.useObservable(c);const d=o.useDependency(o.ICommandService),m=o.useDependency(P),f=o.useObservable(m.addingComment$),[a,C]=g.useState([]);if(g.useEffect(()=>{var D;const l=new Set,u=n==null?void 0:n.getCustomDecorations();C((D=u==null?void 0:u.map(h=>h.id).filter(h=>{const T=l.has(h);return l.add(h),!T}))!=null?D:[]);const b=d.onCommandExecuted(h=>{var T;if(h.id===S.RichTextEditingMutation.id){const w=new Set,H=n==null?void 0:n.getCustomDecorations();C((T=H==null?void 0:H.map(B=>B.id).filter(B=>{const ce=w.has(B);return w.add(B),!ce}))!=null?T:[])}});return()=>{b.dispose()}},[d,n]),!n)return null;const v=te(t),p=n.getUnitId();return pe.jsx(O.ThreadCommentPanel,{unitId:p,subUnitId$:i,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{d.executeCommand(V.id)},getSubUnitName:()=>"",disableAdd:v,tempComment:f,onAddComment:l=>{if(!l.parentId){const u={unitId:p,range:f,comment:l};return d.executeCommand(Z.id,u),m.endAdd(),!1}return!0},onDeleteComment:l=>{if(!l.parentId){const u={unitId:p,commentId:l.id};return d.executeCommand(z.id,u),!1}return!0},showComments:a})};E.componentKey="univer.doc.thread-comment-panel";const j={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var i;const r=e.get(O.ThreadCommentPanelService),n=e.get(I.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==E.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:E.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.setActiveComment(t==null?void 0:t.activeComment),!0}},Y={id:"docs.operation.toggle-comment-panel",type:o.CommandType.OPERATION,handler(e){var n;const t=e.get(O.ThreadCommentPanelService),r=e.get(I.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==E.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:E.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 h,T,w;const t=e.get(O.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),i=e.get(S.DocSelectionManagerService),s=e.get(x.IRenderManagerService),c=e.get(o.UserManagerService),d=e.get(P),m=e.get(o.ICommandService),f=e.get(I.ISidebarService),a=i.getActiveTextRange();if(!n||!a)return!1;const C=(h=s.getRenderById(n.getUnitId()))==null?void 0:h.with($.DocSelectionRenderService);if(C==null||C.setReserveRangesStatus(!0),a.collapsed)return t.panelVisible?(t.setPanelVisible(!1),f.close()):m.executeCommand(j.id),!0;m.executeCommand(j.id);const v=n.getUnitId(),p=((w=(T=n.getBody())==null?void 0:T.dataStream)!=null?w:"").slice(a.startOffset,a.endOffset),l=o.BuildTextUtils.transform.getPlainText(p),u=M,b="",D={unitId:v,subUnitId:u,id:b,ref:l,dT:N.getDT(),personId:c.getCurrentUser().userID,text:{dataStream:`\r
|
|
10
|
-
`},startOffset:a.startOffset,endOffset:a.endOffset,collapsed:!0,threadId:b};return C==null||C.blur(),d.startAdd(D),t.setActiveComment({unitId:v,subUnitId:u,commentId:b}),!0}};var ge=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,Oe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(n?c(t,r,i):c(i))||i);return n&&i&&ge(t,r,i),i},y=(e,t)=>(r,n)=>t(r,n,e);let q=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===S.SetTextSelectionsOperation.id){const c=t.params,{unitId:d,ranges:m}=c;if(o.isInternalEditorID(d))return;const f=this._univerInstanceService.getUnit(d,o.UniverInstanceType.UNIVER_DOC),a=m[0];if((e==null?void 0:e.startOffset)===(a==null?void 0:a.startOffset)&&(e==null?void 0:e.endOffset)===(a==null?void 0:a.endOffset))return;if(e=a,a&&f){const{startOffset:C,endOffset:v,collapsed:p}=a;let l;if(p?l=(n=(r=f.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(u=>u.startIndex<=C&&u.endIndex>=v-1):l=(s=(i=f.getBody())==null?void 0:i.customDecorations)==null?void 0:s.find(u=>u.startIndex<=C&&u.endIndex>=v-1),l){const u=this._threadCommentModel.getComment(d,M,l.id);u&&!u.resolved&&this._commandService.executeCommand(j.id,{activeComment:{unitId:d,subUnitId:M,commentId:l.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 c=(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(m=>m.id===e.commentId);d&&c&&c.scrollToRange({startOffset:d.startIndex,endOffset:d.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};q=Oe([y(0,o.Inject(O.ThreadCommentPanelService)),y(1,o.IUniverInstanceService),y(2,o.ICommandService),y(3,o.Inject(P)),y(4,x.IRenderManagerService),y(5,o.Inject(N.ThreadCommentModel))],q);var _=function(){return _=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},_.apply(this,arguments)},be=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},ne=g.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,c=be(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),m=g.useRef("_".concat(De()));return re(r,"".concat(n),{defIds:r.defIds,idSuffix:m.current},_({ref:t,className:d},c),s)});function re(e,t,r,n,i){return g.createElement(e.tag,_(_({key:t},Me(e,r,i)),n),(Te(e,r).children||[]).map(function(s,c){return re(s,"".concat(t,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function Me(e,t,r){var n=_({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);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 c=s[0],d=s[1];typeof d=="string"&&(n[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Te(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)?_(_({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?_(_({},i),{attrs:_(_({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function De(){return Math.random().toString(36).substring(2,8)}ne.displayName="UniverIcon";var ye={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"}}]},ie=g.forwardRef(function(e,t){return g.createElement(ne,Object.assign({},e,{id:"comment-single",ref:t,icon:ye}))});ie.displayName="CommentSingle";const Ue={[I.RibbonStartGroup.OTHERS]:{[Y.id]:{order:1,menuItemFactory:_e}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.DATA]:{[V.id]:{order:1,menuItemFactory:Ie}}}};var xe=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Re(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(n?c(t,r,i):c(i))||i);return n&&i&&xe(t,r,i),i},J=(e,t)=>(r,n)=>t(r,n,e);let F=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(){[Z,z,j,V,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(Ue)}_initComponents(){[E].forEach(e=>{this.disposeWithMe(this._componentManager.register(e.componentKey,e))}),this.disposeWithMe(this._componentManager.register("CommentSingle",ie))}};F=Pe([J(0,o.ICommandService),J(1,I.IMenuManagerService),J(2,o.Inject(I.ComponentManager))],F);var Ee=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?we(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(n?c(t,r,i):c(i))||i);return n&&i&&Ee(t,r,i),i},U=(e,t)=>(r,n)=>t(r,n,e);let G=class extends o.Disposable{constructor(e,t,r,n,i,s,c){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=s,this._commandService=c,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(S.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:s}=t,c=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:m}=c||{},f=s.find(p=>p.id===d),a=this._threadCommentModel.getComment(n,M,e.id);if(!a)return r({...e,show:!1});const C=f&&i>=f.startIndex&&i<=f.endIndex,v=m===n&&e.id===d;return r({...e,active:v||C,show:!a.resolved})}})}_initSyncComments(){var i,s,c;const e=this._context.unit.getUnitId(),t=M,r=(c=(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?c:[];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 m,f,a;if(d.id===S.RichTextEditingMutation.id){if(d.params.unitId!==this._context.unit.getUnitId())return;const v=(a=(f=(m=this._context.unit.getBody())==null?void 0:m.customDecorations)==null?void 0:f.filter(l=>l.type===o.CustomDecorationType.COMMENT).map(l=>l.id))!=null?a:[],p=v.sort();if(JSON.stringify(n)!==JSON.stringify(p)){const l=new Set(n),u=new Set(p),b=new Set,D=new Set;v.forEach(h=>{l.has(h)||b.add(h)}),n.forEach(h=>{u.has(h)||D.add(h)}),n=p,b.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,[...b])}}}))}};G=Ae([U(1,o.Inject(S.DocInterceptorService)),U(2,o.Inject(O.ThreadCommentPanelService)),U(3,o.Inject($.DocRenderController)),U(4,o.IUniverInstanceService),U(5,o.Inject(N.ThreadCommentModel)),U(6,o.ICommandService)],G);var oe=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,je=(e,t,r)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ne(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(n?c(t,r,i):c(i))||i);return n&&i&&oe(t,r,i),i},K=(e,t)=>(r,n)=>t(r,n,e),se=(e,t,r)=>je(e,typeof t!="symbol"?t+"":t,r);exports.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,...c}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(le,c)}onStarting(){[[F],[q],[P]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(q),this._injector.get(F)}_initRenderModule(){[G].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}};se(exports.UniverDocsThreadCommentUIPlugin,"pluginName",me);se(exports.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=$e([o.DependentOn(O.UniverThreadCommentUIPlugin),K(1,o.Inject(o.Injector)),K(2,x.IRenderManagerService),K(3,o.IConfigService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=Z;exports.DeleteDocCommentComment=z;exports.ShowCommentPanelOperation=j;exports.StartAddCommentOperation=V;
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),engineRender=require("@univerjs/engine-render"),threadCommentUi=require("@univerjs/thread-comment-ui"),docs=require("@univerjs/docs"),docsUi=require("@univerjs/docs-ui"),threadComment=require("@univerjs/thread-comment"),ui=require("@univerjs/ui"),rxjs=require("rxjs"),jsxRuntime=require("react/jsx-runtime"),react=require("react"),PLUGIN_NAME="DOC_THREAD_COMMENT_UI_PLUGIN",DEFAULT_DOC_SUBUNIT_ID="default_doc",DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY="docs-thread-comment-ui.config",defaultPluginConfig={};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a;let DocThreadCommentService=(_a=class extends core.Disposable{constructor(_sidebarService,_threadCommentPanelService){super();__publicField(this,"_addingComment$",new rxjs.BehaviorSubject(void 0));__publicField(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=_sidebarService,this._threadCommentPanelService=_threadCommentPanelService,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(comment){this._addingComment$.next(comment)}endAdd(){this._addingComment$.next(void 0)}},__name(_a,"DocThreadCommentService"),_a);DocThreadCommentService=__decorateClass$4([__decorateParam$4(0,ui.ISidebarService),__decorateParam$4(1,core.Inject(threadCommentUi.ThreadCommentPanelService))],DocThreadCommentService);const AddDocCommentComment={id:"docs.command.add-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{comment:originComment,unitId}=params,comment=await accessor.get(threadComment.IThreadCommentDataSourceService).addComment(originComment),commandService=accessor.get(core.ICommandService),doMutation=docsUi.addCustomDecorationBySelectionFactory(accessor,{id:comment.threadId,type:core.CustomDecorationType.COMMENT,unitId});if(doMutation){const addComment={id:threadComment.AddCommentMutation.id,params:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,comment}},activeOperation={id:threadCommentUi.SetActiveCommentOperation.id,params:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,commentId:comment.id}};return(await core.sequenceExecute([addComment,doMutation,activeOperation],commandService)).result}return!1}},DeleteDocCommentComment={id:"docs.command.delete-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{commentId,unitId}=params,commandService=accessor.get(core.ICommandService),doMutation=docsUi.deleteCustomDecorationFactory(accessor,{id:commentId,unitId});return doMutation?(await core.sequenceExecute([doMutation],commandService)).result:!1}},shouldDisableAddComment=__name(accessor=>{const renderManagerService=accessor.get(engineRender.IRenderManagerService),docSelectionManagerService=accessor.get(docs.DocSelectionManagerService),render2=renderManagerService.getCurrent(),skeleton=render2==null?void 0:render2.with(docs.DocSkeletonManagerService).getSkeleton(),editArea=skeleton==null?void 0:skeleton.getViewModel().getEditArea();if(editArea===engineRender.DocumentEditArea.FOOTER||editArea===engineRender.DocumentEditArea.HEADER)return!0;const range=docSelectionManagerService.getActiveTextRange();return!!(range==null||range.collapsed)},"shouldDisableAddComment");function AddDocCommentMenuItemFactory(accessor){return{id:StartAddCommentOperation.id,type:ui.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC,void 0,core.SHEET_EDITOR_UNITS),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.DocSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddComment(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddDocCommentMenuItemFactory,"AddDocCommentMenuItemFactory");function ToolbarDocCommentMenuItemFactory(accessor){return{id:ToggleCommentPanelOperation.id,type:ui.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC)}}__name(ToolbarDocCommentMenuItemFactory,"ToolbarDocCommentMenuItemFactory");const DocThreadCommentPanel=__name(()=>{const univerInstanceService=core.useDependency(core.IUniverInstanceService),injector=core.useDependency(core.Injector),doc$=react.useMemo(()=>univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.filter(doc2=>!!doc2&&!core.isInternalEditorID(doc2.getUnitId()))),[univerInstanceService]),doc=core.useObservable(doc$),subUnitId$=react.useMemo(()=>new rxjs.Observable(sub=>sub.next(DEFAULT_DOC_SUBUNIT_ID)),[]),docSelectionManagerService=core.useDependency(docs.DocSelectionManagerService),selectionChange$=react.useMemo(()=>docSelectionManagerService.textSelection$.pipe(rxjs.debounceTime(16)),[docSelectionManagerService.textSelection$]);core.useObservable(selectionChange$);const commandService=core.useDependency(core.ICommandService),docCommentService=core.useDependency(DocThreadCommentService),tempComment=core.useObservable(docCommentService.addingComment$),[commentIds,setCommentIds]=react.useState([]);if(react.useEffect(()=>{var _a6;const set=new Set,customRanges=doc==null?void 0:doc.getCustomDecorations();setCommentIds((_a6=customRanges==null?void 0:customRanges.map(r=>r.id).filter(i=>{const hasRepeat=set.has(i);return set.add(i),!hasRepeat}))!=null?_a6:[]);const dispose=commandService.onCommandExecuted(command=>{var _a7;if(command.id===docs.RichTextEditingMutation.id){const set2=new Set,customRanges2=doc==null?void 0:doc.getCustomDecorations();setCommentIds((_a7=customRanges2==null?void 0:customRanges2.map(r=>r.id).filter(i=>{const hasRepeat=set2.has(i);return set2.add(i),!hasRepeat}))!=null?_a7:[])}});return()=>{dispose.dispose()}},[commandService,doc]),!doc)return null;const isInValidSelection=shouldDisableAddComment(injector),unitId=doc.getUnitId();return jsxRuntime.jsx(threadCommentUi.ThreadCommentPanel,{unitId,subUnitId$,type:core.UniverInstanceType.UNIVER_DOC,onAdd:__name(()=>{commandService.executeCommand(StartAddCommentOperation.id)},"onAdd"),getSubUnitName:__name(()=>"","getSubUnitName"),disableAdd:isInValidSelection,tempComment,onAddComment:__name(comment=>{if(!comment.parentId){const params={unitId,range:tempComment,comment};return commandService.executeCommand(AddDocCommentComment.id,params),docCommentService.endAdd(),!1}return!0},"onAddComment"),onDeleteComment:__name(comment=>{if(!comment.parentId){const params={unitId,commentId:comment.id};return commandService.executeCommand(DeleteDocCommentComment.id,params),!1}return!0},"onDeleteComment"),showComments:commentIds})},"DocThreadCommentPanel");DocThreadCommentPanel.componentKey="univer.doc.thread-comment-panel";const ShowCommentPanelOperation={id:"docs.operation.show-comment-panel",type:core.CommandType.OPERATION,handler(accessor,params){var _a6;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),sidebarService=accessor.get(ui.ISidebarService);return(!panelService.panelVisible||((_a6=sidebarService.options.children)==null?void 0:_a6.label)!==DocThreadCommentPanel.componentKey)&&(sidebarService.open({header:{title:"threadCommentUI.panel.title"},children:{label:DocThreadCommentPanel.componentKey},width:320,onClose:__name(()=>panelService.setPanelVisible(!1),"onClose")}),panelService.setPanelVisible(!0)),params&&panelService.setActiveComment(params==null?void 0:params.activeComment),!0}},ToggleCommentPanelOperation={id:"docs.operation.toggle-comment-panel",type:core.CommandType.OPERATION,handler(accessor){var _a6;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),sidebarService=accessor.get(ui.ISidebarService);return!panelService.panelVisible||((_a6=sidebarService.options.children)==null?void 0:_a6.label)!==DocThreadCommentPanel.componentKey?(sidebarService.open({header:{title:"threadCommentUI.panel.title"},children:{label:DocThreadCommentPanel.componentKey},width:320,onClose:__name(()=>panelService.setPanelVisible(!1),"onClose")}),panelService.setPanelVisible(!0)):(sidebarService.close(),panelService.setPanelVisible(!1),panelService.setActiveComment(null)),!0}},StartAddCommentOperation={id:"docs.operation.start-add-comment",type:core.CommandType.OPERATION,handler(accessor){var _a6,_b,_c;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),doc=accessor.get(core.IUniverInstanceService).getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC),docSelectionManagerService=accessor.get(docs.DocSelectionManagerService),renderManagerService=accessor.get(engineRender.IRenderManagerService),userManagerService=accessor.get(core.UserManagerService),docCommentService=accessor.get(DocThreadCommentService),commandService=accessor.get(core.ICommandService),sidebarService=accessor.get(ui.ISidebarService),textRange=docSelectionManagerService.getActiveTextRange();if(!doc||!textRange)return!1;const docSelectionRenderManager=(_a6=renderManagerService.getRenderById(doc.getUnitId()))==null?void 0:_a6.with(docsUi.DocSelectionRenderService);if(docSelectionRenderManager==null||docSelectionRenderManager.setReserveRangesStatus(!0),textRange.collapsed)return panelService.panelVisible?(panelService.setPanelVisible(!1),sidebarService.close()):commandService.executeCommand(ShowCommentPanelOperation.id),!0;commandService.executeCommand(ShowCommentPanelOperation.id);const unitId=doc.getUnitId(),dataStream=((_c=(_b=doc.getBody())==null?void 0:_b.dataStream)!=null?_c:"").slice(textRange.startOffset,textRange.endOffset),text=core.BuildTextUtils.transform.getPlainText(dataStream),subUnitId=DEFAULT_DOC_SUBUNIT_ID,commentId="",comment={unitId,subUnitId,id:commentId,ref:text,dT:threadComment.getDT(),personId:userManagerService.getCurrentUser().userID,text:{dataStream:`\r
|
|
2
|
+
`},startOffset:textRange.startOffset,endOffset:textRange.endOffset,collapsed:!0,threadId:commentId};return docSelectionRenderManager==null||docSelectionRenderManager.blur(),docCommentService.startAdd(comment),panelService.setActiveComment({unitId,subUnitId,commentId}),!0}};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a2;let DocThreadCommentSelectionController=(_a2=class extends core.Disposable{constructor(_threadCommentPanelService,_univerInstanceService,_commandService,_docThreadCommentService,_renderManagerService,_threadCommentModel){super(),this._threadCommentPanelService=_threadCommentPanelService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._docThreadCommentService=_docThreadCommentService,this._renderManagerService=_renderManagerService,this._threadCommentModel=_threadCommentModel,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let lastSelection;this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a6,_b,_c,_d;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges}=params;if(core.isInternalEditorID(unitId))return;const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if((lastSelection==null?void 0:lastSelection.startOffset)===(primary==null?void 0:primary.startOffset)&&(lastSelection==null?void 0:lastSelection.endOffset)===(primary==null?void 0:primary.endOffset))return;if(lastSelection=primary,primary&&doc){const{startOffset,endOffset,collapsed}=primary;let customRange;if(collapsed?customRange=(_b=(_a6=doc.getBody())==null?void 0:_a6.customDecorations)==null?void 0:_b.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1):customRange=(_d=(_c=doc.getBody())==null?void 0:_c.customDecorations)==null?void 0:_d.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1),customRange){const comment=this._threadCommentModel.getComment(unitId,DEFAULT_DOC_SUBUNIT_ID,customRange.id);comment&&!comment.resolved&&this._commandService.executeCommand(ShowCommentPanelOperation.id,{activeComment:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,commentId:customRange.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(threadCommentUi.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(activeComment=>{var _a6,_b,_c,_d;if(activeComment){const doc=this._univerInstanceService.getUnit(activeComment.unitId);if(doc){const backScrollController=(_a6=this._renderManagerService.getRenderById(activeComment.unitId))==null?void 0:_a6.with(docsUi.DocBackScrollRenderController),customRange=(_c=(_b=doc.getBody())==null?void 0:_b.customDecorations)==null?void 0:_c.find(range=>range.id===activeComment.commentId);customRange&&backScrollController&&backScrollController.scrollToRange({startOffset:customRange.startIndex,endOffset:customRange.endIndex,collapsed:!1})}}(!activeComment||activeComment.commentId!==((_d=this._docThreadCommentService.addingComment)==null?void 0:_d.id))&&this._docThreadCommentService.endAdd()}))}},__name(_a2,"DocThreadCommentSelectionController"),_a2);DocThreadCommentSelectionController=__decorateClass$3([__decorateParam$3(0,core.Inject(threadCommentUi.ThreadCommentPanelService)),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocThreadCommentService)),__decorateParam$3(4,engineRender.IRenderManagerService),__decorateParam$3(5,core.Inject(threadComment.ThreadCommentModel))],DocThreadCommentSelectionController);var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=react.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=react.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return react.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a6){var key=_a6[0],value=_a6[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a6,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a6=node.children)===null||_a6===void 0)&&_a6.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid");IconBase.displayName="UniverIcon";var element={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"}}]},CommentSingle=react.forwardRef(function(props,ref){return react.createElement(IconBase,Object.assign({},props,{id:"comment-single",ref,icon:element}))});CommentSingle.displayName="CommentSingle";const menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ToggleCommentPanelOperation.id]:{order:1,menuItemFactory:ToolbarDocCommentMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[StartAddCommentOperation.id]:{order:1,menuItemFactory:AddDocCommentMenuItemFactory}}}};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a3;let DocThreadCommentUIController=(_a3=class extends core.Disposable{constructor(_commandService,_menuManagerService,_componentManager){super(),this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._componentManager=_componentManager,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[AddDocCommentComment,DeleteDocCommentComment,ShowCommentPanelOperation,StartAddCommentOperation,ToggleCommentPanelOperation].forEach(command=>{this.disposeWithMe(this._commandService.registerCommand(command))})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}_initComponents(){[DocThreadCommentPanel].forEach(comp=>{this.disposeWithMe(this._componentManager.register(comp.componentKey,comp))}),this.disposeWithMe(this._componentManager.register("CommentSingle",CommentSingle))}},__name(_a3,"DocThreadCommentUIController"),_a3);DocThreadCommentUIController=__decorateClass$2([__decorateParam$2(0,core.ICommandService),__decorateParam$2(1,ui.IMenuManagerService),__decorateParam$2(2,core.Inject(ui.ComponentManager))],DocThreadCommentUIController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a4;let DocThreadCommentRenderController=(_a4=class extends core.Disposable{constructor(_context,_docInterceptorService,_threadCommentPanelService,_docRenderController,_univerInstanceService,_threadCommentModel,_commandService){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._threadCommentPanelService=_threadCommentPanelService,this._docRenderController=_docRenderController,this._univerInstanceService=_univerInstanceService,this._threadCommentModel=_threadCommentModel,this._commandService=_commandService,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(activeComment=>{var _a6;if(activeComment){this._docRenderController.reRender(activeComment.unitId);return}const unitId=(_a6=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a6.getUnitId();unitId&&this._docRenderController.reRender(unitId)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(update=>{update.type==="resolve"&&this._docRenderController.reRender(update.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId,index,customDecorations}=pos,activeComment=this._threadCommentPanelService.activeCommentId,{commentId,unitId:commentUnitID}=activeComment||{},activeCustomDecoration=customDecorations.find(i=>i.id===commentId),comment=this._threadCommentModel.getComment(unitId,DEFAULT_DOC_SUBUNIT_ID,data.id);if(!comment)return next({...data,show:!1});const isActiveIndex=activeCustomDecoration&&index>=activeCustomDecoration.startIndex&&index<=activeCustomDecoration.endIndex,isActive=commentUnitID===unitId&&data.id===commentId;return next({...data,active:isActive||isActiveIndex,show:!comment.resolved})},"handler")})}_initSyncComments(){var _a6,_b,_c;const unitId=this._context.unit.getUnitId(),subUnitId=DEFAULT_DOC_SUBUNIT_ID,threadIds=(_c=(_b=(_a6=this._context.unit.getBody())==null?void 0:_a6.customDecorations)==null?void 0:_b.filter(i=>i.type===core.CustomDecorationType.COMMENT).map(i=>i.id))!=null?_c:[];threadIds.forEach(id=>{this._threadCommentModel.getComment(unitId,subUnitId,id)||this._threadCommentModel.addComment(unitId,subUnitId,{id,threadId:id,ref:"",dT:"",personId:"",text:{dataStream:""},unitId,subUnitId})}),threadIds.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),DEFAULT_DOC_SUBUNIT_ID,threadIds);let prevThreadIds=threadIds.sort();this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a7,_b2,_c2;if(commandInfo.id===docs.RichTextEditingMutation.id){if(commandInfo.params.unitId!==this._context.unit.getUnitId())return;const currentThreadIds=(_c2=(_b2=(_a7=this._context.unit.getBody())==null?void 0:_a7.customDecorations)==null?void 0:_b2.filter(i=>i.type===core.CustomDecorationType.COMMENT).map(i=>i.id))!=null?_c2:[],currentThreadIdsSorted=currentThreadIds.sort();if(JSON.stringify(prevThreadIds)!==JSON.stringify(currentThreadIdsSorted)){const preIds=new Set(prevThreadIds),currentIds=new Set(currentThreadIdsSorted),addIds=new Set,deleteIds=new Set;currentThreadIds.forEach(id=>{preIds.has(id)||addIds.add(id)}),prevThreadIds.forEach(id=>{currentIds.has(id)||deleteIds.add(id)}),prevThreadIds=currentThreadIdsSorted,addIds.forEach(id=>{this._threadCommentModel.getComment(unitId,subUnitId,id)||this._threadCommentModel.addComment(unitId,subUnitId,{id,threadId:id,ref:"",dT:"",personId:"",text:{dataStream:""},unitId,subUnitId})}),this._threadCommentModel.syncThreadComments(unitId,subUnitId,[...addIds])}}}))}},__name(_a4,"DocThreadCommentRenderController"),_a4);DocThreadCommentRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docs.DocInterceptorService)),__decorateParam$1(2,core.Inject(threadCommentUi.ThreadCommentPanelService)),__decorateParam$1(3,core.Inject(docsUi.DocRenderController)),__decorateParam$1(4,core.IUniverInstanceService),__decorateParam$1(5,core.Inject(threadComment.ThreadCommentModel)),__decorateParam$1(6,core.ICommandService)],DocThreadCommentRenderController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a5;exports.UniverDocsThreadCommentUIPlugin=(_a5=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=core.merge({},defaultPluginConfig,this._config);menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocThreadCommentUIController],[DocThreadCommentSelectionController],[DocThreadCommentService]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule(),this._injector.get(DocThreadCommentSelectionController),this._injector.get(DocThreadCommentUIController)}_initRenderModule(){[DocThreadCommentRenderController].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_a5,"UniverDocsThreadCommentUIPlugin"),_a5);__publicField2(exports.UniverDocsThreadCommentUIPlugin,"pluginName",PLUGIN_NAME);__publicField2(exports.UniverDocsThreadCommentUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=__decorateClass([core.DependentOn(threadCommentUi.UniverThreadCommentUIPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=AddDocCommentComment;exports.DeleteDocCommentComment=DeleteDocCommentComment;exports.ShowCommentPanelOperation=ShowCommentPanelOperation;exports.StartAddCommentOperation=StartAddCommentOperation;
|
package/lib/es/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { addCustomDecorationBySelectionFactory, deleteCustomDecorationFactory, D
|
|
|
10
10
|
import { IThreadCommentDataSourceService, AddCommentMutation, getDT, ThreadCommentModel } from "@univerjs/thread-comment";
|
|
11
11
|
import { ISidebarService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService } from "@univerjs/ui";
|
|
12
12
|
import { BehaviorSubject, Observable, debounceTime, filter } from "rxjs";
|
|
13
|
-
import
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useMemo, useState, useEffect, forwardRef, useRef, createElement } from "react";
|
|
14
15
|
const PLUGIN_NAME = "DOC_THREAD_COMMENT_UI_PLUGIN", DEFAULT_DOC_SUBUNIT_ID = "default_doc", DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "docs-thread-comment-ui.config", defaultPluginConfig = {};
|
|
15
16
|
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
16
17
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -40,37 +41,6 @@ DocThreadCommentService = __decorateClass$4([
|
|
|
40
41
|
__decorateParam$4(0, ISidebarService),
|
|
41
42
|
__decorateParam$4(1, Inject(ThreadCommentPanelService))
|
|
42
43
|
], DocThreadCommentService);
|
|
43
|
-
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
44
|
-
/**
|
|
45
|
-
* @license React
|
|
46
|
-
* react-jsx-runtime.production.min.js
|
|
47
|
-
*
|
|
48
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
49
|
-
*
|
|
50
|
-
* This source code is licensed under the MIT license found in the
|
|
51
|
-
* LICENSE file in the root directory of this source tree.
|
|
52
|
-
*/
|
|
53
|
-
var hasRequiredReactJsxRuntime_production_min;
|
|
54
|
-
function requireReactJsxRuntime_production_min() {
|
|
55
|
-
if (hasRequiredReactJsxRuntime_production_min) return reactJsxRuntime_production_min;
|
|
56
|
-
hasRequiredReactJsxRuntime_production_min = 1;
|
|
57
|
-
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
58
|
-
function q(c, a, g) {
|
|
59
|
-
var b, d = {}, e = null, h = null;
|
|
60
|
-
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
61
|
-
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
62
|
-
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
63
|
-
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
64
|
-
}
|
|
65
|
-
return __name(q, "q"), reactJsxRuntime_production_min.Fragment = l, reactJsxRuntime_production_min.jsx = q, reactJsxRuntime_production_min.jsxs = q, reactJsxRuntime_production_min;
|
|
66
|
-
}
|
|
67
|
-
__name(requireReactJsxRuntime_production_min, "requireReactJsxRuntime_production_min");
|
|
68
|
-
var hasRequiredJsxRuntime;
|
|
69
|
-
function requireJsxRuntime() {
|
|
70
|
-
return hasRequiredJsxRuntime || (hasRequiredJsxRuntime = 1, jsxRuntime.exports = requireReactJsxRuntime_production_min()), jsxRuntime.exports;
|
|
71
|
-
}
|
|
72
|
-
__name(requireJsxRuntime, "requireJsxRuntime");
|
|
73
|
-
var jsxRuntimeExports = requireJsxRuntime();
|
|
74
44
|
const AddDocCommentComment = {
|
|
75
45
|
id: "docs.command.add-comment",
|
|
76
46
|
type: CommandType.COMMAND,
|
|
@@ -184,7 +154,7 @@ const DocThreadCommentPanel = /* @__PURE__ */ __name(() => {
|
|
|
184
154
|
}, [commandService, doc]), !doc)
|
|
185
155
|
return null;
|
|
186
156
|
const isInValidSelection = shouldDisableAddComment(injector), unitId = doc.getUnitId();
|
|
187
|
-
return /* @__PURE__ */
|
|
157
|
+
return /* @__PURE__ */ jsx(
|
|
188
158
|
ThreadCommentPanel,
|
|
189
159
|
{
|
|
190
160
|
unitId,
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
2
16
|
export declare const DocThreadCommentPanel: {
|
|
3
|
-
():
|
|
17
|
+
(): import("react/jsx-runtime").JSX.Element | null;
|
|
4
18
|
componentKey: string;
|
|
5
19
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
(function(u,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")):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"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.UniverDocsThreadCommentUi={},u.UniverCore,u.UniverEngineRender,u.UniverThreadCommentUi,u.UniverDocs,u.UniverDocsUi,u.UniverThreadComment,u.UniverUi,u.rxjs,u.React))})(this,function(u,o,g,T,D,w,A,_,U,O){"use strict";var Ve=Object.defineProperty;var $e=(u,o,g)=>o in u?Ve(u,o,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[o]=g;var Q=(u,o,g)=>$e(u,typeof o!="symbol"?o+"":o,g);const ae="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",ce="docs-thread-comment-ui.config",X={};var me=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,le=(e,t,r,n)=>{for(var i=n>1?void 0:n?ue(t,r):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(i=(n?d(t,r,i):d(i))||i);return n&&i&&me(t,r,i),i},k=(e,t)=>(r,n)=>t(r,n,e);let R=class extends o.Disposable{constructor(t,r){super();Q(this,"_addingComment$",new U.BehaviorSubject(void 0));Q(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=le([k(0,_.ISidebarService),k(1,o.Inject(T.ThreadCommentPanelService))],R);var W={exports:{}},N={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ee;function fe(){if(ee)return N;ee=1;var e=O,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function d(a,m,v){var c,h={},p=null,I=null;v!==void 0&&(p=""+v),m.key!==void 0&&(p=""+m.key),m.ref!==void 0&&(I=m.ref);for(c in m)n.call(m,c)&&!s.hasOwnProperty(c)&&(h[c]=m[c]);if(a&&a.defaultProps)for(c in m=a.defaultProps,m)h[c]===void 0&&(h[c]=m[c]);return{$$typeof:t,type:a,key:p,ref:I,props:h,_owner:i.current}}return N.Fragment=r,N.jsx=d,N.jsxs=d,N}var te;function ve(){return te||(te=1,W.exports=fe()),W.exports}var he=ve();const J={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),d=e.get(o.ICommandService),a=w.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(a){const m={id:A.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},v={id:T.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([m,a,v],d)).result}return!1}},K={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}},ne=e=>{const t=e.get(g.IRenderManagerService),r=e.get(D.DocSelectionManagerService),n=t.getCurrent(),i=n==null?void 0:n.with(D.DocSkeletonManagerService).getSkeleton(),s=i==null?void 0:i.getViewModel().getEditArea();if(s===g.DocumentEditArea.FOOTER||s===g.DocumentEditArea.HEADER)return!0;const d=r.getActiveTextRange();return!!(d==null||d.collapsed)};function Ce(e){return{id:$.id,type:_.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,void 0,o.SHEET_EDITOR_UNITS),disabled$:new U.Observable(function(t){const n=e.get(D.DocSelectionManagerService).textSelection$.pipe(U.debounceTime(16)).subscribe(()=>{t.next(ne(e))});return()=>{n.unsubscribe()}})}}function pe(e){return{id:q.id,type:_.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC)}}const P=()=>{const e=o.useDependency(o.IUniverInstanceService),t=o.useDependency(o.Injector),r=O.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(U.filter(l=>!!l&&!o.isInternalEditorID(l.getUnitId()))),[e]),n=o.useObservable(r),i=O.useMemo(()=>new U.Observable(l=>l.next(M)),[]),s=o.useDependency(D.DocSelectionManagerService),d=O.useMemo(()=>s.textSelection$.pipe(U.debounceTime(16)),[s.textSelection$]);o.useObservable(d);const a=o.useDependency(o.ICommandService),m=o.useDependency(R),v=o.useObservable(m.addingComment$),[c,h]=O.useState([]);if(O.useEffect(()=>{var j;const l=new Set,f=n==null?void 0:n.getCustomDecorations();h((j=f==null?void 0:f.map(C=>C.id).filter(C=>{const b=l.has(C);return l.add(C),!b}))!=null?j:[]);const y=a.onCommandExecuted(C=>{var b;if(C.id===D.RichTextEditingMutation.id){const B=new Set,Y=n==null?void 0:n.getCustomDecorations();h((b=Y==null?void 0:Y.map(L=>L.id).filter(L=>{const Ne=B.has(L);return B.add(L),!Ne}))!=null?b:[])}});return()=>{y.dispose()}},[a,n]),!n)return null;const p=ne(t),I=n.getUnitId();return he.jsx(T.ThreadCommentPanel,{unitId:I,subUnitId$:i,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{a.executeCommand($.id)},getSubUnitName:()=>"",disableAdd:p,tempComment:v,onAddComment:l=>{if(!l.parentId){const f={unitId:I,range:v,comment:l};return a.executeCommand(J.id,f),m.endAdd(),!1}return!0},onDeleteComment:l=>{if(!l.parentId){const f={unitId:I,commentId:l.id};return a.executeCommand(K.id,f),!1}return!0},showComments:c})};P.componentKey="univer.doc.thread-comment-panel";const V={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var i;const r=e.get(T.ThreadCommentPanelService),n=e.get(_.ISidebarService);return(!r.panelVisible||((i=n.options.children)==null?void 0:i.label)!==P.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:P.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.setActiveComment(t==null?void 0:t.activeComment),!0}},q={id:"docs.operation.toggle-comment-panel",type:o.CommandType.OPERATION,handler(e){var n;const t=e.get(T.ThreadCommentPanelService),r=e.get(_.ISidebarService);return!t.panelVisible||((n=r.options.children)==null?void 0:n.label)!==P.componentKey?(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:P.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(r.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},$={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var C,b,B;const t=e.get(T.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),i=e.get(D.DocSelectionManagerService),s=e.get(g.IRenderManagerService),d=e.get(o.UserManagerService),a=e.get(R),m=e.get(o.ICommandService),v=e.get(_.ISidebarService),c=i.getActiveTextRange();if(!n||!c)return!1;const h=(C=s.getRenderById(n.getUnitId()))==null?void 0:C.with(w.DocSelectionRenderService);if(h==null||h.setReserveRangesStatus(!0),c.collapsed)return t.panelVisible?(t.setPanelVisible(!1),v.close()):m.executeCommand(V.id),!0;m.executeCommand(V.id);const p=n.getUnitId(),I=((B=(b=n.getBody())==null?void 0:b.dataStream)!=null?B:"").slice(c.startOffset,c.endOffset),l=o.BuildTextUtils.transform.getPlainText(I),f=M,y="",j={unitId:p,subUnitId:f,id:y,ref:l,dT:A.getDT(),personId:d.getCurrentUser().userID,text:{dataStream:`\r
|
|
10
|
-
`},startOffset:c.startOffset,endOffset:c.endOffset,collapsed:!0,threadId:y};return h==null||h.blur(),a.startAdd(j),t.setActiveComment({unitId:p,subUnitId:f,commentId:y}),!0}};var Ie=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,Se=(e,t,r,n)=>{for(var i=n>1?void 0:n?_e(t,r):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(i=(n?d(t,r,i):d(i))||i);return n&&i&&Ie(t,r,i),i},x=(e,t)=>(r,n)=>t(r,n,e);let F=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===D.SetTextSelectionsOperation.id){const d=t.params,{unitId:a,ranges:m}=d;if(o.isInternalEditorID(a))return;const v=this._univerInstanceService.getUnit(a,o.UniverInstanceType.UNIVER_DOC),c=m[0];if((e==null?void 0:e.startOffset)===(c==null?void 0:c.startOffset)&&(e==null?void 0:e.endOffset)===(c==null?void 0:c.endOffset))return;if(e=c,c&&v){const{startOffset:h,endOffset:p,collapsed:I}=c;let l;if(I?l=(n=(r=v.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(f=>f.startIndex<=h&&f.endIndex>=p-1):l=(s=(i=v.getBody())==null?void 0:i.customDecorations)==null?void 0:s.find(f=>f.startIndex<=h&&f.endIndex>=p-1),l){const f=this._threadCommentModel.getComment(a,M,l.id);f&&!f.resolved&&this._commandService.executeCommand(V.id,{activeComment:{unitId:a,subUnitId:M,commentId:l.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(T.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 d=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(w.DocBackScrollRenderController),a=(n=(r=s.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(m=>m.id===e.commentId);a&&d&&d.scrollToRange({startOffset:a.startIndex,endOffset:a.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};F=Se([x(0,o.Inject(T.ThreadCommentPanelService)),x(1,o.IUniverInstanceService),x(2,o.ICommandService),x(3,o.Inject(R)),x(4,g.IRenderManagerService),x(5,o.Inject(A.ThreadCommentModel))],F);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)},ge=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},re=O.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,d=ge(e,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),m=O.useRef("_".concat(De()));return ie(r,"".concat(n),{defIds:r.defIds,idSuffix:m.current},S({ref:t,className:a},d),s)});function ie(e,t,r,n,i){return O.createElement(e.tag,S(S({key:t},Oe(e,r,i)),n),(Te(e,r).children||[]).map(function(s,d){return ie(s,"".concat(t,"-").concat(e.tag,"-").concat(d),r,void 0,i)}))}function Oe(e,t,r){var n=S({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);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 d=s[0],a=s[1];typeof a=="string"&&(n[d]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Te(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.indexOf(i.attrs.id)>-1?S(S({},i),{attrs:S(S({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function De(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";var Me={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"}}]},oe=O.forwardRef(function(e,t){return O.createElement(re,Object.assign({},e,{id:"comment-single",ref:t,icon:Me}))});oe.displayName="CommentSingle";const ye={[_.RibbonStartGroup.OTHERS]:{[q.id]:{order:1,menuItemFactory:pe}},[_.ContextMenuPosition.MAIN_AREA]:{[_.ContextMenuGroup.DATA]:{[$.id]:{order:1,menuItemFactory:Ce}}}};var be=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,Re=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ue(t,r):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(i=(n?d(t,r,i):d(i))||i);return n&&i&&be(t,r,i),i},G=(e,t)=>(r,n)=>t(r,n,e);let H=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(){[J,K,V,$,q].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(ye)}_initComponents(){[P].forEach(e=>{this.disposeWithMe(this._componentManager.register(e.componentKey,e))}),this.disposeWithMe(this._componentManager.register("CommentSingle",oe))}};H=Re([G(0,o.ICommandService),G(1,_.IMenuManagerService),G(2,o.Inject(_.ComponentManager))],H);var Pe=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Ee=(e,t,r,n)=>{for(var i=n>1?void 0:n?xe(t,r):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(i=(n?d(t,r,i):d(i))||i);return n&&i&&Pe(t,r,i),i},E=(e,t)=>(r,n)=>t(r,n,e);let Z=class extends o.Disposable{constructor(e,t,r,n,i,s,d){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=s,this._commandService=d,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(D.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:s}=t,d=this._threadCommentPanelService.activeCommentId,{commentId:a,unitId:m}=d||{},v=s.find(I=>I.id===a),c=this._threadCommentModel.getComment(n,M,e.id);if(!c)return r({...e,show:!1});const h=v&&i>=v.startIndex&&i<=v.endIndex,p=m===n&&e.id===a;return r({...e,active:p||h,show:!c.resolved})}})}_initSyncComments(){var i,s,d;const e=this._context.unit.getUnitId(),t=M,r=(d=(s=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:s.filter(a=>a.type===o.CustomDecorationType.COMMENT).map(a=>a.id))!=null?d:[];r.forEach(a=>{this._threadCommentModel.getComment(e,t,a)||this._threadCommentModel.addComment(e,t,{id:a,threadId:a,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(a=>{var m,v,c;if(a.id===D.RichTextEditingMutation.id){if(a.params.unitId!==this._context.unit.getUnitId())return;const p=(c=(v=(m=this._context.unit.getBody())==null?void 0:m.customDecorations)==null?void 0:v.filter(l=>l.type===o.CustomDecorationType.COMMENT).map(l=>l.id))!=null?c:[],I=p.sort();if(JSON.stringify(n)!==JSON.stringify(I)){const l=new Set(n),f=new Set(I),y=new Set,j=new Set;p.forEach(C=>{l.has(C)||y.add(C)}),n.forEach(C=>{f.has(C)||j.add(C)}),n=I,y.forEach(C=>{this._threadCommentModel.getComment(e,t,C)||this._threadCommentModel.addComment(e,t,{id:C,threadId:C,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...y])}}}))}};Z=Ee([E(1,o.Inject(D.DocInterceptorService)),E(2,o.Inject(T.ThreadCommentPanelService)),E(3,o.Inject(w.DocRenderController)),E(4,o.IUniverInstanceService),E(5,o.Inject(A.ThreadCommentModel)),E(6,o.ICommandService)],Z);var se=Object.defineProperty,je=Object.getOwnPropertyDescriptor,we=(e,t,r)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?je(t,r):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(i=(n?d(t,r,i):d(i))||i);return n&&i&&se(t,r,i),i},z=(e,t)=>(r,n)=>t(r,n,e),de=(e,t,r)=>we(e,typeof t!="symbol"?t+"":t,r);u.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=X,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:s,...d}=o.merge({},X,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ce,d)}onStarting(){[[H],[F],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(F),this._injector.get(H)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},de(u.UniverDocsThreadCommentUIPlugin,"pluginName",ae),de(u.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),u.UniverDocsThreadCommentUIPlugin=Ae([o.DependentOn(T.UniverThreadCommentUIPlugin),z(1,o.Inject(o.Injector)),z(2,g.IRenderManagerService),z(3,o.IConfigService)],u.UniverDocsThreadCommentUIPlugin),u.AddDocCommentComment=J,u.DeleteDocCommentComment=K,u.ShowCommentPanelOperation=V,u.StartAddCommentOperation=$,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(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"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocsThreadCommentUi={},global.UniverCore,global.UniverEngineRender,global.UniverThreadCommentUi,global.UniverDocs,global.UniverDocsUi,global.UniverThreadComment,global.UniverUi,global.rxjs,global.React,global.React))})(this,function(exports2,core,engineRender,threadCommentUi,docs,docsUi,threadComment,ui,rxjs,jsxRuntime,react){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e;const PLUGIN_NAME="DOC_THREAD_COMMENT_UI_PLUGIN",DEFAULT_DOC_SUBUNIT_ID="default_doc",DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY="docs-thread-comment-ui.config",defaultPluginConfig={};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");let DocThreadCommentService=(_a=class extends core.Disposable{constructor(_sidebarService,_threadCommentPanelService){super();__publicField(this,"_addingComment$",new rxjs.BehaviorSubject(void 0));__publicField(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=_sidebarService,this._threadCommentPanelService=_threadCommentPanelService,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(comment){this._addingComment$.next(comment)}endAdd(){this._addingComment$.next(void 0)}},__name(_a,"DocThreadCommentService"),_a);DocThreadCommentService=__decorateClass$4([__decorateParam$4(0,ui.ISidebarService),__decorateParam$4(1,core.Inject(threadCommentUi.ThreadCommentPanelService))],DocThreadCommentService);const AddDocCommentComment={id:"docs.command.add-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{comment:originComment,unitId}=params,comment=await accessor.get(threadComment.IThreadCommentDataSourceService).addComment(originComment),commandService=accessor.get(core.ICommandService),doMutation=docsUi.addCustomDecorationBySelectionFactory(accessor,{id:comment.threadId,type:core.CustomDecorationType.COMMENT,unitId});if(doMutation){const addComment={id:threadComment.AddCommentMutation.id,params:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,comment}},activeOperation={id:threadCommentUi.SetActiveCommentOperation.id,params:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,commentId:comment.id}};return(await core.sequenceExecute([addComment,doMutation,activeOperation],commandService)).result}return!1}},DeleteDocCommentComment={id:"docs.command.delete-comment",type:core.CommandType.COMMAND,async handler(accessor,params){if(!params)return!1;const{commentId,unitId}=params,commandService=accessor.get(core.ICommandService),doMutation=docsUi.deleteCustomDecorationFactory(accessor,{id:commentId,unitId});return doMutation?(await core.sequenceExecute([doMutation],commandService)).result:!1}},shouldDisableAddComment=__name(accessor=>{const renderManagerService=accessor.get(engineRender.IRenderManagerService),docSelectionManagerService=accessor.get(docs.DocSelectionManagerService),render2=renderManagerService.getCurrent(),skeleton=render2==null?void 0:render2.with(docs.DocSkeletonManagerService).getSkeleton(),editArea=skeleton==null?void 0:skeleton.getViewModel().getEditArea();if(editArea===engineRender.DocumentEditArea.FOOTER||editArea===engineRender.DocumentEditArea.HEADER)return!0;const range=docSelectionManagerService.getActiveTextRange();return!!(range==null||range.collapsed)},"shouldDisableAddComment");function AddDocCommentMenuItemFactory(accessor){return{id:StartAddCommentOperation.id,type:ui.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC,void 0,core.SHEET_EDITOR_UNITS),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.DocSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddComment(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddDocCommentMenuItemFactory,"AddDocCommentMenuItemFactory");function ToolbarDocCommentMenuItemFactory(accessor){return{id:ToggleCommentPanelOperation.id,type:ui.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC)}}__name(ToolbarDocCommentMenuItemFactory,"ToolbarDocCommentMenuItemFactory");const DocThreadCommentPanel=__name(()=>{const univerInstanceService=core.useDependency(core.IUniverInstanceService),injector=core.useDependency(core.Injector),doc$=react.useMemo(()=>univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.filter(doc2=>!!doc2&&!core.isInternalEditorID(doc2.getUnitId()))),[univerInstanceService]),doc=core.useObservable(doc$),subUnitId$=react.useMemo(()=>new rxjs.Observable(sub=>sub.next(DEFAULT_DOC_SUBUNIT_ID)),[]),docSelectionManagerService=core.useDependency(docs.DocSelectionManagerService),selectionChange$=react.useMemo(()=>docSelectionManagerService.textSelection$.pipe(rxjs.debounceTime(16)),[docSelectionManagerService.textSelection$]);core.useObservable(selectionChange$);const commandService=core.useDependency(core.ICommandService),docCommentService=core.useDependency(DocThreadCommentService),tempComment=core.useObservable(docCommentService.addingComment$),[commentIds,setCommentIds]=react.useState([]);if(react.useEffect(()=>{var _a2;const set=new Set,customRanges=doc==null?void 0:doc.getCustomDecorations();setCommentIds((_a2=customRanges==null?void 0:customRanges.map(r=>r.id).filter(i=>{const hasRepeat=set.has(i);return set.add(i),!hasRepeat}))!=null?_a2:[]);const dispose=commandService.onCommandExecuted(command=>{var _a3;if(command.id===docs.RichTextEditingMutation.id){const set2=new Set,customRanges2=doc==null?void 0:doc.getCustomDecorations();setCommentIds((_a3=customRanges2==null?void 0:customRanges2.map(r=>r.id).filter(i=>{const hasRepeat=set2.has(i);return set2.add(i),!hasRepeat}))!=null?_a3:[])}});return()=>{dispose.dispose()}},[commandService,doc]),!doc)return null;const isInValidSelection=shouldDisableAddComment(injector),unitId=doc.getUnitId();return jsxRuntime.jsx(threadCommentUi.ThreadCommentPanel,{unitId,subUnitId$,type:core.UniverInstanceType.UNIVER_DOC,onAdd:__name(()=>{commandService.executeCommand(StartAddCommentOperation.id)},"onAdd"),getSubUnitName:__name(()=>"","getSubUnitName"),disableAdd:isInValidSelection,tempComment,onAddComment:__name(comment=>{if(!comment.parentId){const params={unitId,range:tempComment,comment};return commandService.executeCommand(AddDocCommentComment.id,params),docCommentService.endAdd(),!1}return!0},"onAddComment"),onDeleteComment:__name(comment=>{if(!comment.parentId){const params={unitId,commentId:comment.id};return commandService.executeCommand(DeleteDocCommentComment.id,params),!1}return!0},"onDeleteComment"),showComments:commentIds})},"DocThreadCommentPanel");DocThreadCommentPanel.componentKey="univer.doc.thread-comment-panel";const ShowCommentPanelOperation={id:"docs.operation.show-comment-panel",type:core.CommandType.OPERATION,handler(accessor,params){var _a2;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),sidebarService=accessor.get(ui.ISidebarService);return(!panelService.panelVisible||((_a2=sidebarService.options.children)==null?void 0:_a2.label)!==DocThreadCommentPanel.componentKey)&&(sidebarService.open({header:{title:"threadCommentUI.panel.title"},children:{label:DocThreadCommentPanel.componentKey},width:320,onClose:__name(()=>panelService.setPanelVisible(!1),"onClose")}),panelService.setPanelVisible(!0)),params&&panelService.setActiveComment(params==null?void 0:params.activeComment),!0}},ToggleCommentPanelOperation={id:"docs.operation.toggle-comment-panel",type:core.CommandType.OPERATION,handler(accessor){var _a2;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),sidebarService=accessor.get(ui.ISidebarService);return!panelService.panelVisible||((_a2=sidebarService.options.children)==null?void 0:_a2.label)!==DocThreadCommentPanel.componentKey?(sidebarService.open({header:{title:"threadCommentUI.panel.title"},children:{label:DocThreadCommentPanel.componentKey},width:320,onClose:__name(()=>panelService.setPanelVisible(!1),"onClose")}),panelService.setPanelVisible(!0)):(sidebarService.close(),panelService.setPanelVisible(!1),panelService.setActiveComment(null)),!0}},StartAddCommentOperation={id:"docs.operation.start-add-comment",type:core.CommandType.OPERATION,handler(accessor){var _a2,_b2,_c2;const panelService=accessor.get(threadCommentUi.ThreadCommentPanelService),doc=accessor.get(core.IUniverInstanceService).getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC),docSelectionManagerService=accessor.get(docs.DocSelectionManagerService),renderManagerService=accessor.get(engineRender.IRenderManagerService),userManagerService=accessor.get(core.UserManagerService),docCommentService=accessor.get(DocThreadCommentService),commandService=accessor.get(core.ICommandService),sidebarService=accessor.get(ui.ISidebarService),textRange=docSelectionManagerService.getActiveTextRange();if(!doc||!textRange)return!1;const docSelectionRenderManager=(_a2=renderManagerService.getRenderById(doc.getUnitId()))==null?void 0:_a2.with(docsUi.DocSelectionRenderService);if(docSelectionRenderManager==null||docSelectionRenderManager.setReserveRangesStatus(!0),textRange.collapsed)return panelService.panelVisible?(panelService.setPanelVisible(!1),sidebarService.close()):commandService.executeCommand(ShowCommentPanelOperation.id),!0;commandService.executeCommand(ShowCommentPanelOperation.id);const unitId=doc.getUnitId(),dataStream=((_c2=(_b2=doc.getBody())==null?void 0:_b2.dataStream)!=null?_c2:"").slice(textRange.startOffset,textRange.endOffset),text=core.BuildTextUtils.transform.getPlainText(dataStream),subUnitId=DEFAULT_DOC_SUBUNIT_ID,commentId="",comment={unitId,subUnitId,id:commentId,ref:text,dT:threadComment.getDT(),personId:userManagerService.getCurrentUser().userID,text:{dataStream:`\r
|
|
2
|
+
`},startOffset:textRange.startOffset,endOffset:textRange.endOffset,collapsed:!0,threadId:commentId};return docSelectionRenderManager==null||docSelectionRenderManager.blur(),docCommentService.startAdd(comment),panelService.setActiveComment({unitId,subUnitId,commentId}),!0}};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let DocThreadCommentSelectionController=(_b=class extends core.Disposable{constructor(_threadCommentPanelService,_univerInstanceService,_commandService,_docThreadCommentService,_renderManagerService,_threadCommentModel){super(),this._threadCommentPanelService=_threadCommentPanelService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._docThreadCommentService=_docThreadCommentService,this._renderManagerService=_renderManagerService,this._threadCommentModel=_threadCommentModel,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let lastSelection;this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a2,_b2,_c2,_d2;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges}=params;if(core.isInternalEditorID(unitId))return;const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if((lastSelection==null?void 0:lastSelection.startOffset)===(primary==null?void 0:primary.startOffset)&&(lastSelection==null?void 0:lastSelection.endOffset)===(primary==null?void 0:primary.endOffset))return;if(lastSelection=primary,primary&&doc){const{startOffset,endOffset,collapsed}=primary;let customRange;if(collapsed?customRange=(_b2=(_a2=doc.getBody())==null?void 0:_a2.customDecorations)==null?void 0:_b2.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1):customRange=(_d2=(_c2=doc.getBody())==null?void 0:_c2.customDecorations)==null?void 0:_d2.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1),customRange){const comment=this._threadCommentModel.getComment(unitId,DEFAULT_DOC_SUBUNIT_ID,customRange.id);comment&&!comment.resolved&&this._commandService.executeCommand(ShowCommentPanelOperation.id,{activeComment:{unitId,subUnitId:DEFAULT_DOC_SUBUNIT_ID,commentId:customRange.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(threadCommentUi.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(activeComment=>{var _a2,_b2,_c2,_d2;if(activeComment){const doc=this._univerInstanceService.getUnit(activeComment.unitId);if(doc){const backScrollController=(_a2=this._renderManagerService.getRenderById(activeComment.unitId))==null?void 0:_a2.with(docsUi.DocBackScrollRenderController),customRange=(_c2=(_b2=doc.getBody())==null?void 0:_b2.customDecorations)==null?void 0:_c2.find(range=>range.id===activeComment.commentId);customRange&&backScrollController&&backScrollController.scrollToRange({startOffset:customRange.startIndex,endOffset:customRange.endIndex,collapsed:!1})}}(!activeComment||activeComment.commentId!==((_d2=this._docThreadCommentService.addingComment)==null?void 0:_d2.id))&&this._docThreadCommentService.endAdd()}))}},__name(_b,"DocThreadCommentSelectionController"),_b);DocThreadCommentSelectionController=__decorateClass$3([__decorateParam$3(0,core.Inject(threadCommentUi.ThreadCommentPanelService)),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocThreadCommentService)),__decorateParam$3(4,engineRender.IRenderManagerService),__decorateParam$3(5,core.Inject(threadComment.ThreadCommentModel))],DocThreadCommentSelectionController);var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=react.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=react.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return react.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={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"}}]},CommentSingle=react.forwardRef(function(props,ref){return react.createElement(IconBase,Object.assign({},props,{id:"comment-single",ref,icon:element}))});CommentSingle.displayName="CommentSingle";const menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ToggleCommentPanelOperation.id]:{order:1,menuItemFactory:ToolbarDocCommentMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[StartAddCommentOperation.id]:{order:1,menuItemFactory:AddDocCommentMenuItemFactory}}}};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let DocThreadCommentUIController=(_c=class extends core.Disposable{constructor(_commandService,_menuManagerService,_componentManager){super(),this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._componentManager=_componentManager,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[AddDocCommentComment,DeleteDocCommentComment,ShowCommentPanelOperation,StartAddCommentOperation,ToggleCommentPanelOperation].forEach(command=>{this.disposeWithMe(this._commandService.registerCommand(command))})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}_initComponents(){[DocThreadCommentPanel].forEach(comp=>{this.disposeWithMe(this._componentManager.register(comp.componentKey,comp))}),this.disposeWithMe(this._componentManager.register("CommentSingle",CommentSingle))}},__name(_c,"DocThreadCommentUIController"),_c);DocThreadCommentUIController=__decorateClass$2([__decorateParam$2(0,core.ICommandService),__decorateParam$2(1,ui.IMenuManagerService),__decorateParam$2(2,core.Inject(ui.ComponentManager))],DocThreadCommentUIController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let DocThreadCommentRenderController=(_d=class extends core.Disposable{constructor(_context,_docInterceptorService,_threadCommentPanelService,_docRenderController,_univerInstanceService,_threadCommentModel,_commandService){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._threadCommentPanelService=_threadCommentPanelService,this._docRenderController=_docRenderController,this._univerInstanceService=_univerInstanceService,this._threadCommentModel=_threadCommentModel,this._commandService=_commandService,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(activeComment=>{var _a2;if(activeComment){this._docRenderController.reRender(activeComment.unitId);return}const unitId=(_a2=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a2.getUnitId();unitId&&this._docRenderController.reRender(unitId)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(update=>{update.type==="resolve"&&this._docRenderController.reRender(update.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId,index,customDecorations}=pos,activeComment=this._threadCommentPanelService.activeCommentId,{commentId,unitId:commentUnitID}=activeComment||{},activeCustomDecoration=customDecorations.find(i=>i.id===commentId),comment=this._threadCommentModel.getComment(unitId,DEFAULT_DOC_SUBUNIT_ID,data.id);if(!comment)return next({...data,show:!1});const isActiveIndex=activeCustomDecoration&&index>=activeCustomDecoration.startIndex&&index<=activeCustomDecoration.endIndex,isActive=commentUnitID===unitId&&data.id===commentId;return next({...data,active:isActive||isActiveIndex,show:!comment.resolved})},"handler")})}_initSyncComments(){var _a2,_b2,_c2;const unitId=this._context.unit.getUnitId(),subUnitId=DEFAULT_DOC_SUBUNIT_ID,threadIds=(_c2=(_b2=(_a2=this._context.unit.getBody())==null?void 0:_a2.customDecorations)==null?void 0:_b2.filter(i=>i.type===core.CustomDecorationType.COMMENT).map(i=>i.id))!=null?_c2:[];threadIds.forEach(id=>{this._threadCommentModel.getComment(unitId,subUnitId,id)||this._threadCommentModel.addComment(unitId,subUnitId,{id,threadId:id,ref:"",dT:"",personId:"",text:{dataStream:""},unitId,subUnitId})}),threadIds.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),DEFAULT_DOC_SUBUNIT_ID,threadIds);let prevThreadIds=threadIds.sort();this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a3,_b3,_c3;if(commandInfo.id===docs.RichTextEditingMutation.id){if(commandInfo.params.unitId!==this._context.unit.getUnitId())return;const currentThreadIds=(_c3=(_b3=(_a3=this._context.unit.getBody())==null?void 0:_a3.customDecorations)==null?void 0:_b3.filter(i=>i.type===core.CustomDecorationType.COMMENT).map(i=>i.id))!=null?_c3:[],currentThreadIdsSorted=currentThreadIds.sort();if(JSON.stringify(prevThreadIds)!==JSON.stringify(currentThreadIdsSorted)){const preIds=new Set(prevThreadIds),currentIds=new Set(currentThreadIdsSorted),addIds=new Set,deleteIds=new Set;currentThreadIds.forEach(id=>{preIds.has(id)||addIds.add(id)}),prevThreadIds.forEach(id=>{currentIds.has(id)||deleteIds.add(id)}),prevThreadIds=currentThreadIdsSorted,addIds.forEach(id=>{this._threadCommentModel.getComment(unitId,subUnitId,id)||this._threadCommentModel.addComment(unitId,subUnitId,{id,threadId:id,ref:"",dT:"",personId:"",text:{dataStream:""},unitId,subUnitId})}),this._threadCommentModel.syncThreadComments(unitId,subUnitId,[...addIds])}}}))}},__name(_d,"DocThreadCommentRenderController"),_d);DocThreadCommentRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docs.DocInterceptorService)),__decorateParam$1(2,core.Inject(threadCommentUi.ThreadCommentPanelService)),__decorateParam$1(3,core.Inject(docsUi.DocRenderController)),__decorateParam$1(4,core.IUniverInstanceService),__decorateParam$1(5,core.Inject(threadComment.ThreadCommentModel)),__decorateParam$1(6,core.ICommandService)],DocThreadCommentRenderController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverDocsThreadCommentUIPlugin=(_e=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=core.merge({},defaultPluginConfig,this._config);menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocThreadCommentUIController],[DocThreadCommentSelectionController],[DocThreadCommentService]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule(),this._injector.get(DocThreadCommentSelectionController),this._injector.get(DocThreadCommentUIController)}_initRenderModule(){[DocThreadCommentRenderController].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_e,"UniverDocsThreadCommentUIPlugin"),_e),__publicField2(exports2.UniverDocsThreadCommentUIPlugin,"pluginName",PLUGIN_NAME),__publicField2(exports2.UniverDocsThreadCommentUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC),exports2.UniverDocsThreadCommentUIPlugin=__decorateClass([core.DependentOn(threadCommentUi.UniverThreadCommentUIPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports2.UniverDocsThreadCommentUIPlugin),exports2.AddDocCommentComment=AddDocCommentComment,exports2.DeleteDocCommentComment=DeleteDocCommentComment,exports2.ShowCommentPanelOperation=ShowCommentPanelOperation,exports2.StartAddCommentOperation=StartAddCommentOperation,Object.defineProperty(exports2,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.5.5-nightly.
|
|
3
|
+
"version": "0.5.5-nightly.202501220324",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -43,19 +43,19 @@
|
|
|
43
43
|
"lib"
|
|
44
44
|
],
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"react": "
|
|
46
|
+
"react": ">=16.9.0 || >=17 || >=18 || >=19",
|
|
47
47
|
"rxjs": ">=7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@univerjs/icons": "^0.2.12",
|
|
51
51
|
"clsx": "^2.1.1",
|
|
52
|
-
"@univerjs/core": "0.5.5-nightly.
|
|
53
|
-
"@univerjs/docs
|
|
54
|
-
"@univerjs/
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/thread-comment": "0.5.5-nightly.
|
|
57
|
-
"@univerjs/thread-comment-ui": "0.5.5-nightly.
|
|
58
|
-
"@univerjs/ui": "0.5.5-nightly.
|
|
52
|
+
"@univerjs/core": "0.5.5-nightly.202501220324",
|
|
53
|
+
"@univerjs/docs": "0.5.5-nightly.202501220324",
|
|
54
|
+
"@univerjs/docs-ui": "0.5.5-nightly.202501220324",
|
|
55
|
+
"@univerjs/engine-render": "0.5.5-nightly.202501220324",
|
|
56
|
+
"@univerjs/thread-comment": "0.5.5-nightly.202501220324",
|
|
57
|
+
"@univerjs/thread-comment-ui": "0.5.5-nightly.202501220324",
|
|
58
|
+
"@univerjs/ui": "0.5.5-nightly.202501220324"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"postcss": "^8.4.49",
|