@univerjs/sheets-thread-comment-ui 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1 +1,1043 @@
1
- import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,Plugin as d,RANGE_TYPE as f,Range as p,Rectangle as m,Tools as h,UniverInstanceType as g,merge as ee}from"@univerjs/core";import{INTERCEPTOR_POINT as te,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as ne,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as re}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as ie}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ThreadCommentTreeLocation as se,UniverThreadCommentUIPlugin as ce,UniverThreadCommentUIPlugin as le}from"@univerjs/thread-comment-ui";import{ComponentManager as ue,ContextMenuGroup as de,ContextMenuPosition as fe,IMenuManagerService as pe,IShortcutService as me,ISidebarService as he,IZenZoneService as ge,KeyCode as _e,MenuItemType as E,MetaKeys as D,RibbonInsertGroup as ve,getMenuHiddenObservable as O,useDependency as k,useObservable as A}from"@univerjs/ui";import{COPY_TYPE as ye,CellPopupManagerService as be,HoverManagerService as xe,IEditorBridgeService as Se,IMarkSelectionService as j,ISheetClipboardService as Ce,ScrollToRangeOperation as we,SheetCanvasPopManagerService as Te,SheetSkeletonManagerService as Ee,getCurrentRangeDisable$ as M,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{BehaviorSubject as Oe,debounceTime as N,map as ke}from"rxjs";import{IRenderManagerService as P}from"@univerjs/engine-render";import{serializeRange as Ae,singleReferenceToGrid as F}from"@univerjs/engine-formula";import{AddCommentCommand as je,AddCommentCommand as Me,AddCommentMutation as I,DeleteCommentCommand as Ne,DeleteCommentCommand as Pe,DeleteCommentMutation as L,DeleteCommentTreeCommand as Fe,DeleteCommentTreeCommand as Ie,IThreadCommentDataSourceService as Le,IThreadCommentDataSourceService as Re,ResolveCommentCommand as ze,ResolveCommentCommand as Be,UpdateCommentCommand as Ve,UpdateCommentCommand as He}from"@univerjs/thread-comment";import{CommentIcon as Ue}from"@univerjs/icons";import{jsx as R}from"react/jsx-runtime";import{useCallback as z,useEffect as We,useMemo as Ge,useRef as Ke}from"react";const qe=`univer.sheet.thread-comment-modal`,Je=`univer.sheet.thread-comment-panel`,Ye=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function B(e){"@babel/helpers - typeof";return B=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},B(e)}function Xe(e,t){if(B(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ze(e){var t=Xe(e,`string`);return B(t)==`symbol`?t:t+``}function V(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,V(this,`_lastPopup`,null),V(this,`_activePopup`,void 0),V(this,`_activePopup$`,new Oe(null)),V(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:qe,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=U([H(0,s(Te)),H(1,ge),H(2,s(be))],W);const G={type:e.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var t;let n=e.get(ne),r=e.get(o),i=e.get(W),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=re(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}},K={id:`sheet.operation.toggle-comment-panel`,type:e.OPERATION,handler(e){let t=e.get(he),n=e.get(T);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):(t.open({header:{title:`threadCommentUI.panel.title`},children:{label:Je},width:360}),n.setPanelVisible(!0)),!0}};var Qe=`@univerjs/sheets-thread-comment-ui`,$e=`0.20.1`;const et=`sheets-thread-comment.config`;Symbol(et);const tt={};let q=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(te.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(N(16)).subscribe(()=>{e()}))}};q=U([H(0,s(y)),H(1,s(C)),H(2,o),H(3,P)],q);const nt=(e,t,n)=>{let r=F(e),i=n.row-t.row,a=n.column-t.column;return Ae({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let J=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,V(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Ye,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===ye.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];p.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],f=e=>{c.unshift({id:L.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:I.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:nt(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:I.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:L.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{f(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};J=U([H(0,s(Ce)),H(1,s(C)),H(2,Re)],J);let Y=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Y=U([H(0,s(xe)),H(1,s(W)),H(2,s(C)),H(3,s(b))],Y);let X=class extends n{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===G.id||t===K.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[x],worksheetTypes:[S]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===Me.id){let{unitId:t,subUnitId:n,comment:r}=e.params,{row:i,column:a}=F(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:i,startColumn:a,endRow:i,endColumn:a}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===He.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);if(a){let{row:e,column:r}=F(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===Be.id||t===Pe.id||t===Ie.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);if(i){let{row:e,column:r}=F(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};X=U([H(0,s(u)),H(1,i),H(2,s(b)),H(3,s(C))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,V(this,`_isSwitchToCommenting`,!1),V(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(Ee).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?f.NORMAL:a)!==f.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,d=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,d)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let p=this._sheetsThreadCommentModel.getByLocation(t,n,u,d);p&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:p})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=F(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(we.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(N(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=F(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=U([H(0,i),H(1,s(W)),H(2,s(C)),H(3,s(T)),H(4,o),H(5,s(b)),H(6,j),H(7,s(ne)),H(8,Se),H(9,P)],Z);const rt=e=>({id:G.id,type:E.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:O(e,g.UNIVER_SHEET),disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),it=e=>({id:K.id,type:E.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:O(e,g.UNIVER_SHEET)}),at={id:G.id,binding:_e.M|D.CTRL_COMMAND|D.ALT,preconditions:De},ot={[ve.MEDIA]:{[K.id]:{order:2,menuItemFactory:it}},[fe.MAIN_AREA]:{[de.OTHERS]:{[G.id]:{order:0,menuItemFactory:rt}}}},st=()=>{let e=k(o),t=k(W),n=A(t.activePopup$),r=k(C);if(A(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${h.chatAtABC(a)}${i+1}`;return R(oe,{onClick:()=>{t.persistPopup()},location:se.CELL,id:u,unitId:s,subUnitId:c,type:g.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(g.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},ct=()=>{var e;let t=k(j),n=k(o),r=k(W),a=n.getCurrentUnitForType(g.UNIVER_SHEET),s=a.getUnitId(),c=k(i),l=Ge(()=>a.activeSheet$.pipe(ke(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=A(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=Ke(null),f=k(T),p=A(f.activeCommentId$),m=A(f.panelVisible$,f.panelVisible),h=z(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=F(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=z(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=F(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),te=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},_=()=>{c.executeCommand(G.id)},v=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},y=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return We(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),R(ae,{unitId:s,subUnitId$:l,type:g.UNIVER_SHEET,onAdd:_,getSubUnitName:te,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:h,onItemEnter:v,onItemLeave:y,onDeleteComment:()=>(y(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(at)}_initMenu(){this._menuManagerService.mergeMenu(ot)}_initComponent(){[[qe,st],[Je,ct],[`CommentIcon`,Ue]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=U([H(0,pe),H(1,s(ue)),H(2,me)],Q);let $=class extends d{constructor(e=tt,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=ee({},tt,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(et,a)}onStarting(){[[Q],[q],[J],[Y],[Z],[W],[X]].forEach(e=>{this._injector.add(e)}),[G,K].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(q)}onRendered(){this._injector.get(J),this._injector.get(Y),this._injector.get(Z),this._injector.get(X)}};V($,`pluginName`,Ye),V($,`packageName`,Qe),V($,`version`,$e),V($,`type`,g.UNIVER_SHEET),$=U([t(le,ie),H(1,s(c)),H(2,s(i)),H(3,a)],$);export{je as AddCommentCommand,Ne as DeleteCommentCommand,Fe as DeleteCommentTreeCommand,Le as IThreadCommentDataSourceService,ze as ResolveCommentCommand,W as SheetsThreadCommentPopupService,G as ShowAddSheetCommentModalOperation,K as ToggleSheetCommentPanelOperation,$ as UniverSheetsThreadCommentUIPlugin,ce as UniverThreadCommentUIPlugin,Ve as UpdateCommentCommand};
1
+ import { CommandType, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RANGE_TYPE, Range, Rectangle, Tools, UniverInstanceType, merge } from "@univerjs/core";
2
+ import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, WorkbookCommentPermission, WorksheetViewPermission, getSheetCommandTarget } from "@univerjs/sheets";
3
+ import { SheetsThreadCommentModel, UniverSheetsThreadCommentPlugin } from "@univerjs/sheets-thread-comment";
4
+ import { SetActiveCommentOperation, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentUIPlugin, UniverThreadCommentUIPlugin as UniverThreadCommentUIPlugin$1 } from "@univerjs/thread-comment-ui";
5
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IShortcutService, ISidebarService, IZenZoneService, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
6
+ import { COPY_TYPE, CellPopupManagerService, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, ScrollToRangeOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, getCurrentRangeDisable$, whenSheetEditorFocused } from "@univerjs/sheets-ui";
7
+ import { BehaviorSubject, debounceTime, map } from "rxjs";
8
+ import { IRenderManagerService } from "@univerjs/engine-render";
9
+ import { serializeRange, singleReferenceToGrid } from "@univerjs/engine-formula";
10
+ import { AddCommentCommand, AddCommentCommand as AddCommentCommand$1, AddCommentMutation, DeleteCommentCommand, DeleteCommentCommand as DeleteCommentCommand$1, DeleteCommentMutation, DeleteCommentTreeCommand, DeleteCommentTreeCommand as DeleteCommentTreeCommand$1, IThreadCommentDataSourceService, IThreadCommentDataSourceService as IThreadCommentDataSourceService$1, ResolveCommentCommand, ResolveCommentCommand as ResolveCommentCommand$1, UpdateCommentCommand, UpdateCommentCommand as UpdateCommentCommand$1 } from "@univerjs/thread-comment";
11
+ import { CommentIcon } from "@univerjs/icons";
12
+ import { jsx } from "react/jsx-runtime";
13
+ import { useCallback, useEffect, useMemo, useRef } from "react";
14
+
15
+ //#region src/types/const.ts
16
+ /**
17
+ * Copyright 2023-present DreamNum Co., Ltd.
18
+ *
19
+ * Licensed under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License.
21
+ * You may obtain a copy of the License at
22
+ *
23
+ * http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const SHEETS_THREAD_COMMENT_MODAL = "univer.sheet.thread-comment-modal";
32
+ const SHEETS_THREAD_COMMENT_PANEL = "univer.sheet.thread-comment-panel";
33
+ const PLUGIN_NAME = "SHEET_THREAD_COMMENT_UI_PLUGIN";
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
37
+ function _typeof(o) {
38
+ "@babel/helpers - typeof";
39
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
40
+ return typeof o;
41
+ } : function(o) {
42
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
43
+ }, _typeof(o);
44
+ }
45
+
46
+ //#endregion
47
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
48
+ function toPrimitive(t, r) {
49
+ if ("object" != _typeof(t) || !t) return t;
50
+ var e = t[Symbol.toPrimitive];
51
+ if (void 0 !== e) {
52
+ var i = e.call(t, r || "default");
53
+ if ("object" != _typeof(i)) return i;
54
+ throw new TypeError("@@toPrimitive must return a primitive value.");
55
+ }
56
+ return ("string" === r ? String : Number)(t);
57
+ }
58
+
59
+ //#endregion
60
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
61
+ function toPropertyKey(t) {
62
+ var i = toPrimitive(t, "string");
63
+ return "symbol" == _typeof(i) ? i : i + "";
64
+ }
65
+
66
+ //#endregion
67
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
68
+ function _defineProperty(e, r, t) {
69
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
70
+ value: t,
71
+ enumerable: !0,
72
+ configurable: !0,
73
+ writable: !0
74
+ }) : e[r] = t, e;
75
+ }
76
+
77
+ //#endregion
78
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
79
+ function __decorateParam(paramIndex, decorator) {
80
+ return function(target, key) {
81
+ decorator(target, key, paramIndex);
82
+ };
83
+ }
84
+
85
+ //#endregion
86
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
87
+ function __decorate(decorators, target, key, desc) {
88
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
90
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
92
+ }
93
+
94
+ //#endregion
95
+ //#region src/services/sheets-thread-comment-popup.service.ts
96
+ let SheetsThreadCommentPopupService = class SheetsThreadCommentPopupService extends Disposable {
97
+ get activePopup() {
98
+ return this._activePopup;
99
+ }
100
+ constructor(_canvasPopupManagerService, _zenZoneService, _cellPopupManagerService) {
101
+ super();
102
+ this._canvasPopupManagerService = _canvasPopupManagerService;
103
+ this._zenZoneService = _zenZoneService;
104
+ this._cellPopupManagerService = _cellPopupManagerService;
105
+ _defineProperty(this, "_lastPopup", null);
106
+ _defineProperty(this, "_activePopup", void 0);
107
+ _defineProperty(this, "_activePopup$", new BehaviorSubject(null));
108
+ _defineProperty(this, "activePopup$", this._activePopup$.asObservable());
109
+ this._initZenVisible();
110
+ this.disposeWithMe(() => {
111
+ this._activePopup$.complete();
112
+ });
113
+ }
114
+ _initZenVisible() {
115
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
116
+ if (visible) this.hidePopup();
117
+ }));
118
+ }
119
+ dispose() {
120
+ super.dispose();
121
+ this.hidePopup();
122
+ }
123
+ showPopup(location, onHide) {
124
+ var _this$activePopup;
125
+ const { row, col, unitId, subUnitId } = location;
126
+ if (this._activePopup && row === this._activePopup.row && col === this._activePopup.col && unitId === this._activePopup.unitId && subUnitId === ((_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.subUnitId)) {
127
+ this._activePopup = location;
128
+ this._activePopup$.next(location);
129
+ return;
130
+ }
131
+ if (this._lastPopup) this._lastPopup.dispose();
132
+ if (this._zenZoneService.visible) return;
133
+ this._activePopup = location;
134
+ this._activePopup$.next(location);
135
+ const popupDisposable = this._cellPopupManagerService.showPopup({
136
+ row,
137
+ col,
138
+ unitId,
139
+ subUnitId
140
+ }, {
141
+ componentKey: SHEETS_THREAD_COMMENT_MODAL,
142
+ onClickOutside: () => {
143
+ this.hidePopup();
144
+ },
145
+ direction: "horizontal",
146
+ excludeOutside: [...Array.from(document.querySelectorAll(".univer-thread-comment")), document.getElementById("thread-comment-add")].filter(Boolean),
147
+ priority: 2
148
+ });
149
+ if (!popupDisposable) throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");
150
+ const disposableCollection = new DisposableCollection();
151
+ disposableCollection.add(popupDisposable);
152
+ disposableCollection.add({ dispose: () => {
153
+ onHide === null || onHide === void 0 || onHide();
154
+ } });
155
+ this._lastPopup = disposableCollection;
156
+ }
157
+ hidePopup() {
158
+ if (!this._activePopup) return;
159
+ if (this._lastPopup) this._lastPopup.dispose();
160
+ this._lastPopup = null;
161
+ this._activePopup = null;
162
+ this._activePopup$.next(null);
163
+ }
164
+ persistPopup() {
165
+ if (!this._activePopup || !this._activePopup.temp) return;
166
+ this._activePopup = {
167
+ ...this._activePopup,
168
+ temp: false
169
+ };
170
+ this._activePopup$.next(this._activePopup);
171
+ }
172
+ };
173
+ SheetsThreadCommentPopupService = __decorate([
174
+ __decorateParam(0, Inject(SheetCanvasPopManagerService)),
175
+ __decorateParam(1, IZenZoneService),
176
+ __decorateParam(2, Inject(CellPopupManagerService))
177
+ ], SheetsThreadCommentPopupService);
178
+
179
+ //#endregion
180
+ //#region src/commands/operations/comment.operation.ts
181
+ const ShowAddSheetCommentModalOperation = {
182
+ type: CommandType.OPERATION,
183
+ id: "sheet.operation.show-comment-modal",
184
+ handler(accessor) {
185
+ var _selectionManagerServ;
186
+ const selectionManagerService = accessor.get(SheetsSelectionsService);
187
+ const univerInstanceService = accessor.get(IUniverInstanceService);
188
+ const sheetsThreadCommentPopupService = accessor.get(SheetsThreadCommentPopupService);
189
+ const threadCommentPanelService = accessor.get(ThreadCommentPanelService);
190
+ const activeCell = (_selectionManagerServ = selectionManagerService.getCurrentLastSelection()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.primary;
191
+ const model = accessor.get(SheetsThreadCommentModel);
192
+ if (!activeCell) return false;
193
+ const result = getSheetCommandTarget(univerInstanceService);
194
+ if (!result) return false;
195
+ const { workbook, worksheet, unitId, subUnitId } = result;
196
+ const location = {
197
+ workbook,
198
+ worksheet,
199
+ unitId,
200
+ subUnitId,
201
+ row: activeCell.startRow,
202
+ col: activeCell.startColumn
203
+ };
204
+ sheetsThreadCommentPopupService.showPopup(location);
205
+ const rootId = model.getByLocation(unitId, subUnitId, activeCell.startRow, activeCell.startColumn);
206
+ if (rootId) threadCommentPanelService.setActiveComment({
207
+ unitId,
208
+ subUnitId,
209
+ commentId: rootId,
210
+ trigger: "context-menu"
211
+ });
212
+ return true;
213
+ }
214
+ };
215
+ const ToggleSheetCommentPanelOperation = {
216
+ id: "sheet.operation.toggle-comment-panel",
217
+ type: CommandType.OPERATION,
218
+ handler(accessor) {
219
+ const sidebarService = accessor.get(ISidebarService);
220
+ const panelService = accessor.get(ThreadCommentPanelService);
221
+ if (panelService.panelVisible) {
222
+ sidebarService.close();
223
+ panelService.setPanelVisible(false);
224
+ } else {
225
+ sidebarService.open({
226
+ header: { title: "threadCommentUI.panel.title" },
227
+ children: { label: SHEETS_THREAD_COMMENT_PANEL },
228
+ width: 360
229
+ });
230
+ panelService.setPanelVisible(true);
231
+ }
232
+ return true;
233
+ }
234
+ };
235
+
236
+ //#endregion
237
+ //#region package.json
238
+ var name = "@univerjs/sheets-thread-comment-ui";
239
+ var version = "0.21.0";
240
+
241
+ //#endregion
242
+ //#region src/config/config.ts
243
+ const SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "sheets-thread-comment.config";
244
+ const configSymbol = Symbol(SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
245
+ const defaultPluginConfig = {};
246
+
247
+ //#endregion
248
+ //#region src/controllers/render-controllers/render.controller.ts
249
+ let SheetsThreadCommentRenderController = class SheetsThreadCommentRenderController extends Disposable {
250
+ constructor(_sheetInterceptorService, _sheetsThreadCommentModel, _univerInstanceService, _renderManagerService) {
251
+ super();
252
+ this._sheetInterceptorService = _sheetInterceptorService;
253
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
254
+ this._univerInstanceService = _univerInstanceService;
255
+ this._renderManagerService = _renderManagerService;
256
+ this._initViewModelIntercept();
257
+ this._initSkeletonChange();
258
+ }
259
+ _initViewModelIntercept() {
260
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
261
+ effect: InterceptorEffectEnum.Style,
262
+ handler: (cell, pos, next) => {
263
+ const { row, col, unitId, subUnitId } = pos;
264
+ if (this._sheetsThreadCommentModel.showCommentMarker(unitId, subUnitId, row, col)) {
265
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
266
+ cell.markers = {
267
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
268
+ tr: {
269
+ color: "#FFBD37",
270
+ size: 6
271
+ }
272
+ };
273
+ return next(cell);
274
+ }
275
+ return next(cell);
276
+ },
277
+ priority: 100
278
+ }));
279
+ }
280
+ _initSkeletonChange() {
281
+ const markSkeletonDirty = () => {
282
+ var _currentRender$mainCo;
283
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
284
+ if (!workbook) return;
285
+ const unitId = workbook.getUnitId();
286
+ const currentRender = this._renderManagerService.getRenderById(unitId);
287
+ currentRender === null || currentRender === void 0 || (_currentRender$mainCo = currentRender.mainComponent) === null || _currentRender$mainCo === void 0 || _currentRender$mainCo.makeForceDirty();
288
+ };
289
+ this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(debounceTime(16)).subscribe(() => {
290
+ markSkeletonDirty();
291
+ }));
292
+ }
293
+ };
294
+ SheetsThreadCommentRenderController = __decorate([
295
+ __decorateParam(0, Inject(SheetInterceptorService)),
296
+ __decorateParam(1, Inject(SheetsThreadCommentModel)),
297
+ __decorateParam(2, IUniverInstanceService),
298
+ __decorateParam(3, IRenderManagerService)
299
+ ], SheetsThreadCommentRenderController);
300
+
301
+ //#endregion
302
+ //#region src/controllers/sheets-thread-comment-copy-paste.controller.ts
303
+ const transformRef = (ref, source, target) => {
304
+ const refObj = singleReferenceToGrid(ref);
305
+ const offsetRow = target.row - source.row;
306
+ const offsetCol = target.column - source.column;
307
+ return serializeRange({
308
+ startColumn: refObj.column + offsetCol,
309
+ startRow: refObj.row + offsetRow,
310
+ endColumn: refObj.column + offsetCol,
311
+ endRow: refObj.row + offsetRow
312
+ });
313
+ };
314
+ let SheetsThreadCommentCopyPasteController = class SheetsThreadCommentCopyPasteController extends Disposable {
315
+ constructor(_sheetClipboardService, _sheetsThreadCommentModel, _threadCommentDataSourceService) {
316
+ super();
317
+ this._sheetClipboardService = _sheetClipboardService;
318
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
319
+ this._threadCommentDataSourceService = _threadCommentDataSourceService;
320
+ _defineProperty(this, "_copyInfo", void 0);
321
+ this._initClipboardHook();
322
+ }
323
+ _initClipboardHook() {
324
+ this.disposeWithMe(this._sheetClipboardService.addClipboardHook({
325
+ id: PLUGIN_NAME,
326
+ onBeforeCopy: (unitId, subUnitId, range) => {
327
+ this._copyInfo = {
328
+ unitId,
329
+ subUnitId,
330
+ range
331
+ };
332
+ },
333
+ onPasteCells: (_pasteFrom, pasteTo, _data, payload) => {
334
+ const { unitId: targetUnitId, subUnitId: targetSubUnitId, range } = pasteTo;
335
+ const targetPos = {
336
+ row: range.rows[0],
337
+ column: range.cols[0]
338
+ };
339
+ if (payload.copyType === COPY_TYPE.CUT && this._copyInfo) {
340
+ const { range, unitId: sourceUnitId, subUnitId: sourceSubUnitId } = this._copyInfo;
341
+ const sourcePos = {
342
+ row: range.startRow,
343
+ column: range.startColumn
344
+ };
345
+ if (!(targetUnitId === sourceUnitId && targetSubUnitId === sourceSubUnitId)) {
346
+ const roots = [];
347
+ Range.foreach(range, (row, col) => {
348
+ const comments = this._sheetsThreadCommentModel.getAllByLocation(sourceUnitId, sourceSubUnitId, row, col);
349
+ if (this._threadCommentDataSourceService.syncUpdateMutationToColla) comments.forEach((comment) => {
350
+ roots.push(comment);
351
+ });
352
+ else comments.forEach(({ children, ...comment }) => {
353
+ if (!comment.parentId) roots.push(comment);
354
+ });
355
+ });
356
+ const sourceRedos = [];
357
+ const sourceUndos = [];
358
+ const targetRedos = [];
359
+ const targetUndos = [];
360
+ const handleCommentItem = (item) => {
361
+ sourceRedos.unshift({
362
+ id: DeleteCommentMutation.id,
363
+ params: {
364
+ unitId: sourceUnitId,
365
+ subUnitId: sourceSubUnitId,
366
+ commentId: item.id
367
+ }
368
+ });
369
+ targetRedos.push({
370
+ id: AddCommentMutation.id,
371
+ params: {
372
+ unitId: targetUnitId,
373
+ subUnitId: targetSubUnitId,
374
+ comment: {
375
+ ...item,
376
+ ref: transformRef(item.ref, sourcePos, targetPos),
377
+ unitId: targetUnitId,
378
+ subUnitId: targetSubUnitId
379
+ },
380
+ sync: true
381
+ }
382
+ });
383
+ sourceUndos.push({
384
+ id: AddCommentMutation.id,
385
+ params: {
386
+ unitId: sourceUnitId,
387
+ subUnitId: sourceSubUnitId,
388
+ comment: item,
389
+ sync: true
390
+ }
391
+ });
392
+ targetUndos.unshift({
393
+ id: DeleteCommentMutation.id,
394
+ params: {
395
+ unitId: targetUnitId,
396
+ subUnitId: targetSubUnitId,
397
+ commentId: item.id
398
+ }
399
+ });
400
+ };
401
+ roots.forEach((root) => {
402
+ handleCommentItem(root);
403
+ });
404
+ return {
405
+ redos: [...sourceRedos, ...targetRedos],
406
+ undos: [...targetUndos, ...sourceUndos]
407
+ };
408
+ }
409
+ }
410
+ return {
411
+ redos: [],
412
+ undos: []
413
+ };
414
+ }
415
+ }));
416
+ }
417
+ };
418
+ SheetsThreadCommentCopyPasteController = __decorate([
419
+ __decorateParam(0, Inject(ISheetClipboardService)),
420
+ __decorateParam(1, Inject(SheetsThreadCommentModel)),
421
+ __decorateParam(2, IThreadCommentDataSourceService$1)
422
+ ], SheetsThreadCommentCopyPasteController);
423
+
424
+ //#endregion
425
+ //#region src/controllers/sheets-thread-comment-hover.controller.ts
426
+ /**
427
+ * Copyright 2023-present DreamNum Co., Ltd.
428
+ *
429
+ * Licensed under the Apache License, Version 2.0 (the "License");
430
+ * you may not use this file except in compliance with the License.
431
+ * You may obtain a copy of the License at
432
+ *
433
+ * http://www.apache.org/licenses/LICENSE-2.0
434
+ *
435
+ * Unless required by applicable law or agreed to in writing, software
436
+ * distributed under the License is distributed on an "AS IS" BASIS,
437
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
438
+ * See the License for the specific language governing permissions and
439
+ * limitations under the License.
440
+ */
441
+ let SheetsThreadCommentHoverController = class SheetsThreadCommentHoverController extends Disposable {
442
+ constructor(_hoverManagerService, _sheetsThreadCommentPopupService, _sheetsThreadCommentModel, _sheetPermissionCheckController) {
443
+ super();
444
+ this._hoverManagerService = _hoverManagerService;
445
+ this._sheetsThreadCommentPopupService = _sheetsThreadCommentPopupService;
446
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
447
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
448
+ this._initHoverEvent();
449
+ }
450
+ _initHoverEvent() {
451
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((cell) => {
452
+ const currentPopup = this._sheetsThreadCommentPopupService.activePopup;
453
+ if (cell && (currentPopup && currentPopup.temp || !currentPopup)) {
454
+ const { location } = cell;
455
+ const { unitId, subUnitId, row, col } = location;
456
+ const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
457
+ if (commentId) {
458
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
459
+ workbookTypes: [WorkbookCommentPermission],
460
+ worksheetTypes: [WorksheetViewPermission],
461
+ rangeTypes: [RangeProtectionPermissionViewPoint]
462
+ }, [{
463
+ startRow: row,
464
+ startColumn: col,
465
+ endRow: row,
466
+ endColumn: col
467
+ }], unitId, subUnitId)) return;
468
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
469
+ if (comment && !comment.resolved) this._sheetsThreadCommentPopupService.showPopup({
470
+ unitId,
471
+ subUnitId,
472
+ row,
473
+ col,
474
+ commentId,
475
+ temp: true
476
+ });
477
+ } else if (currentPopup) this._sheetsThreadCommentPopupService.hidePopup();
478
+ }
479
+ }));
480
+ }
481
+ };
482
+ SheetsThreadCommentHoverController = __decorate([
483
+ __decorateParam(0, Inject(HoverManagerService)),
484
+ __decorateParam(1, Inject(SheetsThreadCommentPopupService)),
485
+ __decorateParam(2, Inject(SheetsThreadCommentModel)),
486
+ __decorateParam(3, Inject(SheetPermissionCheckController))
487
+ ], SheetsThreadCommentHoverController);
488
+
489
+ //#endregion
490
+ //#region src/controllers/sheets-thread-comment-permission.controller.ts
491
+ let SheetsThreadCommentPermissionController = class SheetsThreadCommentPermissionController extends Disposable {
492
+ constructor(_localeService, _commandService, _sheetPermissionCheckController, _sheetsThreadCommentModel) {
493
+ super();
494
+ this._localeService = _localeService;
495
+ this._commandService = _commandService;
496
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
497
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
498
+ this._commandExecutedListener();
499
+ }
500
+ _commandExecutedListener() {
501
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
502
+ const { id } = command;
503
+ if (id === ShowAddSheetCommentModalOperation.id || id === ToggleSheetCommentPanelOperation.id) {
504
+ if (!this._sheetPermissionCheckController.permissionCheckWithoutRange({
505
+ workbookTypes: [WorkbookCommentPermission],
506
+ worksheetTypes: [WorksheetViewPermission]
507
+ })) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.commentErr"));
508
+ } else if (id === AddCommentCommand$1.id) {
509
+ const { unitId, subUnitId, comment } = command.params;
510
+ const { row, column } = singleReferenceToGrid(comment.ref);
511
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
512
+ workbookTypes: [WorkbookCommentPermission],
513
+ worksheetTypes: [WorksheetViewPermission],
514
+ rangeTypes: [RangeProtectionPermissionViewPoint]
515
+ }, [{
516
+ startRow: row,
517
+ startColumn: column,
518
+ endRow: row,
519
+ endColumn: column
520
+ }], unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.commentErr"));
521
+ } else if (id === UpdateCommentCommand$1.id) {
522
+ const { unitId, subUnitId, payload } = command.params;
523
+ const { commentId } = payload;
524
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
525
+ if (comment) {
526
+ const { row, column } = singleReferenceToGrid(comment.ref);
527
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
528
+ workbookTypes: [WorkbookCommentPermission],
529
+ worksheetTypes: [WorksheetViewPermission],
530
+ rangeTypes: [RangeProtectionPermissionViewPoint]
531
+ }, [{
532
+ startRow: row,
533
+ startColumn: column,
534
+ endRow: row,
535
+ endColumn: column
536
+ }], unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.commentErr"));
537
+ }
538
+ } else if (id === ResolveCommentCommand$1.id || id === DeleteCommentCommand$1.id || id === DeleteCommentTreeCommand$1.id) {
539
+ const { unitId, subUnitId, commentId } = command.params;
540
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
541
+ if (comment) {
542
+ const { row, column } = singleReferenceToGrid(comment.ref);
543
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
544
+ workbookTypes: [WorkbookCommentPermission],
545
+ worksheetTypes: [WorksheetViewPermission],
546
+ rangeTypes: [RangeProtectionPermissionViewPoint]
547
+ }, [{
548
+ startRow: row,
549
+ startColumn: column,
550
+ endRow: row,
551
+ endColumn: column
552
+ }], unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.commentErr"));
553
+ }
554
+ }
555
+ }));
556
+ }
557
+ };
558
+ SheetsThreadCommentPermissionController = __decorate([
559
+ __decorateParam(0, Inject(LocaleService)),
560
+ __decorateParam(1, ICommandService),
561
+ __decorateParam(2, Inject(SheetPermissionCheckController)),
562
+ __decorateParam(3, Inject(SheetsThreadCommentModel))
563
+ ], SheetsThreadCommentPermissionController);
564
+
565
+ //#endregion
566
+ //#region src/controllers/sheets-thread-comment-popup.controller.ts
567
+ let SheetsThreadCommentPopupController = class SheetsThreadCommentPopupController extends Disposable {
568
+ constructor(_commandService, _sheetsThreadCommentPopupService, _sheetsThreadCommentModel, _threadCommentPanelService, _univerInstanceService, _sheetPermissionCheckController, _markSelectionService, _sheetSelectionService, _editorBridgeService, _renderManagerService) {
569
+ super();
570
+ this._commandService = _commandService;
571
+ this._sheetsThreadCommentPopupService = _sheetsThreadCommentPopupService;
572
+ this._sheetsThreadCommentModel = _sheetsThreadCommentModel;
573
+ this._threadCommentPanelService = _threadCommentPanelService;
574
+ this._univerInstanceService = _univerInstanceService;
575
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
576
+ this._markSelectionService = _markSelectionService;
577
+ this._sheetSelectionService = _sheetSelectionService;
578
+ this._editorBridgeService = _editorBridgeService;
579
+ this._renderManagerService = _renderManagerService;
580
+ _defineProperty(this, "_isSwitchToCommenting", false);
581
+ _defineProperty(this, "_selectionShapeInfo", null);
582
+ this._initCommandListener();
583
+ this._initPanelListener();
584
+ this._initMarkSelection();
585
+ this._initSelectionUpdateListener();
586
+ this._initEditorBridge();
587
+ }
588
+ _handleSelectionChange(selections, unitId, subUnitId) {
589
+ var _selections$, _render$with$getSkele, _range$rangeType;
590
+ const range = (_selections$ = selections[0]) === null || _selections$ === void 0 ? void 0 : _selections$.range;
591
+ const render = this._renderManagerService.getRenderById(unitId);
592
+ const skeleton = render === null || render === void 0 || (_render$with$getSkele = render.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele === void 0 ? void 0 : _render$with$getSkele.skeleton;
593
+ if (!skeleton) return;
594
+ if (!range) return;
595
+ const actualCell = skeleton.getCellWithCoordByIndex(range.startRow, range.startColumn);
596
+ if ((((_range$rangeType = range.rangeType) !== null && _range$rangeType !== void 0 ? _range$rangeType : RANGE_TYPE.NORMAL) !== RANGE_TYPE.NORMAL || range.endColumn - range.startColumn > 0 || range.endRow - range.startRow > 0) && !((actualCell.isMerged || actualCell.isMergedMainCell) && Rectangle.equals(actualCell.mergeInfo, range))) {
597
+ if (this._threadCommentPanelService.activeCommentId) this._commandService.executeCommand(SetActiveCommentOperation.id);
598
+ return;
599
+ }
600
+ const row = actualCell.actualRow;
601
+ const col = actualCell.actualColumn;
602
+ if (!this._sheetsThreadCommentModel.showCommentMarker(unitId, subUnitId, row, col)) {
603
+ if (this._threadCommentPanelService.activeCommentId) this._commandService.executeCommand(SetActiveCommentOperation.id);
604
+ return;
605
+ }
606
+ const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
607
+ if (commentId) this._commandService.executeCommand(SetActiveCommentOperation.id, {
608
+ unitId,
609
+ subUnitId,
610
+ commentId
611
+ });
612
+ }
613
+ _initSelectionUpdateListener() {
614
+ this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe((selections) => {
615
+ if (this._isSwitchToCommenting) return;
616
+ const current = this._sheetSelectionService.currentSelectionParam;
617
+ if (!current) return;
618
+ this._handleSelectionChange(selections, current.unitId, current.sheetId);
619
+ }));
620
+ }
621
+ _initEditorBridge() {
622
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
623
+ if (visible.visible) this._sheetsThreadCommentPopupService.hidePopup();
624
+ }));
625
+ }
626
+ _initCommandListener() {
627
+ this._commandService.onCommandExecuted((commandInfo) => {
628
+ if (commandInfo.id === DeleteCommentMutation.id) {
629
+ const params = commandInfo.params;
630
+ const active = this._sheetsThreadCommentPopupService.activePopup;
631
+ if (!active) return;
632
+ const { unitId, subUnitId, commentId } = active;
633
+ if (params.unitId === unitId && params.subUnitId === subUnitId && params.commentId === commentId) this._sheetsThreadCommentPopupService.hidePopup();
634
+ }
635
+ });
636
+ }
637
+ _initPanelListener() {
638
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async (commentInfo) => {
639
+ if (commentInfo) {
640
+ var _currentUnit$getActiv;
641
+ const { unitId, subUnitId, commentId, trigger } = commentInfo;
642
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
643
+ if (!comment || comment.resolved) return;
644
+ const currentUnit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
645
+ if (!currentUnit) return;
646
+ if (currentUnit.getUnitId() !== unitId) return;
647
+ this._isSwitchToCommenting = true;
648
+ if (((_currentUnit$getActiv = currentUnit.getActiveSheet()) === null || _currentUnit$getActiv === void 0 ? void 0 : _currentUnit$getActiv.getSheetId()) !== subUnitId) await this._commandService.executeCommand(SetWorksheetActiveOperation.id, {
649
+ unitId,
650
+ subUnitId
651
+ });
652
+ this._isSwitchToCommenting = false;
653
+ const location = singleReferenceToGrid(comment.ref);
654
+ const { row, column: col } = location;
655
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
656
+ workbookTypes: [WorkbookCommentPermission],
657
+ worksheetTypes: [WorksheetViewPermission],
658
+ rangeTypes: [RangeProtectionPermissionViewPoint]
659
+ }, [{
660
+ startRow: row,
661
+ startColumn: col,
662
+ endRow: row,
663
+ endColumn: col
664
+ }], unitId, subUnitId)) return;
665
+ const GAP = 1;
666
+ await this._commandService.executeCommand(ScrollToRangeOperation.id, { range: {
667
+ startRow: Math.max(location.row - GAP, 0),
668
+ endRow: location.row + GAP,
669
+ startColumn: Math.max(location.column - GAP, 0),
670
+ endColumn: location.column + GAP
671
+ } });
672
+ if (this._editorBridgeService.isVisible().visible) return;
673
+ this._sheetsThreadCommentPopupService.showPopup({
674
+ unitId,
675
+ subUnitId,
676
+ row: location.row,
677
+ col: location.column,
678
+ commentId: comment.id,
679
+ trigger
680
+ });
681
+ } else this._sheetsThreadCommentPopupService.hidePopup();
682
+ }));
683
+ }
684
+ _initMarkSelection() {
685
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(debounceTime(100)).subscribe((activeComment) => {
686
+ var _this$_univerInstance, _worksheet$getMergedC;
687
+ if (!activeComment) {
688
+ if (this._selectionShapeInfo) {
689
+ this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId);
690
+ this._selectionShapeInfo = null;
691
+ }
692
+ return;
693
+ }
694
+ const { unitId, subUnitId, commentId } = activeComment;
695
+ if (this._selectionShapeInfo) {
696
+ this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId);
697
+ this._selectionShapeInfo = null;
698
+ }
699
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);
700
+ if (!comment) return;
701
+ const { row, column } = singleReferenceToGrid(comment.ref);
702
+ if (Number.isNaN(row) || Number.isNaN(column)) return null;
703
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
704
+ const mergeInfo = (_worksheet$getMergedC = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getMergedCell(row, column)) !== null && _worksheet$getMergedC !== void 0 ? _worksheet$getMergedC : {
705
+ startColumn: column,
706
+ endColumn: column,
707
+ startRow: row,
708
+ endRow: row
709
+ };
710
+ const shapeId = this._markSelectionService.addShape({
711
+ range: mergeInfo,
712
+ style: {
713
+ fill: "rgba(255, 189, 55, 0.35)",
714
+ strokeWidth: 1,
715
+ stroke: "#FFBD37",
716
+ widgets: {}
717
+ },
718
+ primary: null
719
+ }, [], -1);
720
+ if (!shapeId) return;
721
+ this._selectionShapeInfo = {
722
+ ...activeComment,
723
+ shapeId
724
+ };
725
+ }));
726
+ }
727
+ };
728
+ SheetsThreadCommentPopupController = __decorate([
729
+ __decorateParam(0, ICommandService),
730
+ __decorateParam(1, Inject(SheetsThreadCommentPopupService)),
731
+ __decorateParam(2, Inject(SheetsThreadCommentModel)),
732
+ __decorateParam(3, Inject(ThreadCommentPanelService)),
733
+ __decorateParam(4, IUniverInstanceService),
734
+ __decorateParam(5, Inject(SheetPermissionCheckController)),
735
+ __decorateParam(6, IMarkSelectionService),
736
+ __decorateParam(7, Inject(SheetsSelectionsService)),
737
+ __decorateParam(8, IEditorBridgeService),
738
+ __decorateParam(9, IRenderManagerService)
739
+ ], SheetsThreadCommentPopupController);
740
+
741
+ //#endregion
742
+ //#region src/menu/menu.ts
743
+ const threadCommentMenuFactory = (accessor) => {
744
+ return {
745
+ id: ShowAddSheetCommentModalOperation.id,
746
+ type: MenuItemType.BUTTON,
747
+ icon: "CommentIcon",
748
+ title: "sheetThreadComment.menu.addComment",
749
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
750
+ disabled$: getCurrentRangeDisable$(accessor, {
751
+ workbookTypes: [WorkbookCommentPermission],
752
+ worksheetTypes: [WorksheetViewPermission],
753
+ rangeTypes: [RangeProtectionPermissionViewPoint]
754
+ })
755
+ };
756
+ };
757
+ const threadPanelMenuFactory = (accessor) => {
758
+ return {
759
+ id: ToggleSheetCommentPanelOperation.id,
760
+ type: MenuItemType.BUTTON,
761
+ icon: "CommentIcon",
762
+ tooltip: "sheetThreadComment.menu.commentManagement",
763
+ disabled$: getCurrentRangeDisable$(accessor, {
764
+ workbookTypes: [WorkbookCommentPermission],
765
+ worksheetTypes: [WorksheetViewPermission],
766
+ rangeTypes: [RangeProtectionPermissionViewPoint]
767
+ }),
768
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
769
+ };
770
+ };
771
+ const AddCommentShortcut = {
772
+ id: ShowAddSheetCommentModalOperation.id,
773
+ binding: KeyCode.M | MetaKeys.CTRL_COMMAND | MetaKeys.ALT,
774
+ preconditions: whenSheetEditorFocused
775
+ };
776
+
777
+ //#endregion
778
+ //#region src/menu/schema.ts
779
+ const menuSchema = {
780
+ [RibbonInsertGroup.MEDIA]: { [ToggleSheetCommentPanelOperation.id]: {
781
+ order: 2,
782
+ menuItemFactory: threadPanelMenuFactory
783
+ } },
784
+ [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: { [ShowAddSheetCommentModalOperation.id]: {
785
+ order: 0,
786
+ menuItemFactory: threadCommentMenuFactory
787
+ } } }
788
+ };
789
+
790
+ //#endregion
791
+ //#region src/views/sheets-thread-comment-cell/index.tsx
792
+ const SheetsThreadCommentCell = () => {
793
+ const univerInstanceService = useDependency(IUniverInstanceService);
794
+ const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
795
+ const activePopup = useObservable(sheetsThreadCommentPopupService.activePopup$);
796
+ const sheetThreadCommentModel = useDependency(SheetsThreadCommentModel);
797
+ useObservable(sheetThreadCommentModel.commentUpdate$);
798
+ if (!activePopup) return null;
799
+ const { row, col, unitId, subUnitId, trigger } = activePopup;
800
+ const rootId = sheetThreadCommentModel.getByLocation(unitId, subUnitId, row, col);
801
+ const ref = `${Tools.chatAtABC(col)}${row + 1}`;
802
+ const onClose = () => {
803
+ sheetsThreadCommentPopupService.hidePopup();
804
+ };
805
+ const getSubUnitName = (id) => {
806
+ var _univerInstanceServic, _univerInstanceServic2;
807
+ return (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetId(id)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getName()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : "";
808
+ };
809
+ return /* @__PURE__ */ jsx(ThreadCommentTree, {
810
+ onClick: () => {
811
+ sheetsThreadCommentPopupService.persistPopup();
812
+ },
813
+ location: ThreadCommentTreeLocation.CELL,
814
+ id: rootId,
815
+ unitId,
816
+ subUnitId,
817
+ type: UniverInstanceType.UNIVER_SHEET,
818
+ refStr: ref,
819
+ onClose,
820
+ getSubUnitName,
821
+ autoFocus: trigger === "context-menu"
822
+ });
823
+ };
824
+
825
+ //#endregion
826
+ //#region src/views/sheets-thread-comment-panel/index.tsx
827
+ const SheetsThreadCommentPanel = () => {
828
+ var _workbook$getActiveSh;
829
+ const markSelectionService = useDependency(IMarkSelectionService);
830
+ const univerInstanceService = useDependency(IUniverInstanceService);
831
+ const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
832
+ const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
833
+ const unitId = workbook.getUnitId();
834
+ const commandService = useDependency(ICommandService);
835
+ const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i === null || i === void 0 ? void 0 : i.getSheetId())), [workbook.activeSheet$]);
836
+ const subUnitId = useObservable(subUnitId$, (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
837
+ const hoverShapeId = useRef(null);
838
+ const panelService = useDependency(ThreadCommentPanelService);
839
+ const activeCommentId = useObservable(panelService.activeCommentId$);
840
+ const panelVisible = useObservable(panelService.panelVisible$, panelService.panelVisible);
841
+ const sortComments = useCallback((comments) => {
842
+ const worksheets = workbook.getSheets();
843
+ const sheetIndex = {};
844
+ worksheets.forEach((sheet, i) => {
845
+ sheetIndex[sheet.getSheetId()] = i;
846
+ });
847
+ const sort = (comments) => {
848
+ return comments.map((comment) => {
849
+ var _sheetIndex$comment$s;
850
+ const ref = singleReferenceToGrid(comment.ref);
851
+ const p = [
852
+ (_sheetIndex$comment$s = sheetIndex[comment.subUnitId]) !== null && _sheetIndex$comment$s !== void 0 ? _sheetIndex$comment$s : 0,
853
+ ref.row,
854
+ ref.column
855
+ ];
856
+ return {
857
+ ...comment,
858
+ p
859
+ };
860
+ }).sort((pre, aft) => {
861
+ if (pre.p[0] === aft.p[0]) {
862
+ if (pre.p[1] === aft.p[1]) return pre.p[2] - aft.p[2];
863
+ return pre.p[1] - aft.p[1];
864
+ }
865
+ return pre.p[0] - aft.p[0];
866
+ });
867
+ };
868
+ return [...sort(comments.filter((comment) => !comment.resolved)), ...sort(comments.filter((comment) => comment.resolved))];
869
+ }, [workbook]);
870
+ const showShape = useCallback((comment) => {
871
+ if (comment.unitId === unitId && comment.subUnitId === subUnitId && !comment.resolved) {
872
+ var _worksheet$getMergedC;
873
+ const { row, column } = singleReferenceToGrid(comment.ref);
874
+ const worksheet = workbook.getSheetBySheetId(comment.subUnitId);
875
+ const mergeInfo = (_worksheet$getMergedC = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getMergedCell(row, column)) !== null && _worksheet$getMergedC !== void 0 ? _worksheet$getMergedC : {
876
+ startColumn: column,
877
+ endColumn: column,
878
+ startRow: row,
879
+ endRow: row
880
+ };
881
+ if (!Number.isNaN(row) && !Number.isNaN(column)) return markSelectionService.addShape({
882
+ range: mergeInfo,
883
+ style: {
884
+ fill: "rgb(255, 189, 55, 0.35)",
885
+ strokeWidth: 1,
886
+ stroke: "#FFBD37",
887
+ widgets: {}
888
+ },
889
+ primary: null
890
+ });
891
+ }
892
+ return null;
893
+ }, [
894
+ markSelectionService,
895
+ subUnitId,
896
+ unitId
897
+ ]);
898
+ const getSubUnitName = (id) => {
899
+ var _workbook$getSheetByS, _workbook$getSheetByS2;
900
+ return (_workbook$getSheetByS = (_workbook$getSheetByS2 = workbook.getSheetBySheetId(id)) === null || _workbook$getSheetByS2 === void 0 ? void 0 : _workbook$getSheetByS2.getName()) !== null && _workbook$getSheetByS !== void 0 ? _workbook$getSheetByS : "";
901
+ };
902
+ const handleAdd = () => {
903
+ commandService.executeCommand(ShowAddSheetCommentModalOperation.id);
904
+ };
905
+ const handleHover = (comment) => {
906
+ if (activeCommentId && activeCommentId.unitId === comment.unitId && activeCommentId.subUnitId === comment.subUnitId && activeCommentId.commentId === comment.id) return;
907
+ if (hoverShapeId.current) {
908
+ markSelectionService.removeShape(hoverShapeId.current);
909
+ hoverShapeId.current = null;
910
+ }
911
+ hoverShapeId.current = showShape(comment);
912
+ };
913
+ const handleLeave = () => {
914
+ if (hoverShapeId.current) {
915
+ markSelectionService.removeShape(hoverShapeId.current);
916
+ hoverShapeId.current = null;
917
+ }
918
+ };
919
+ const handleResolve = (id, resolved) => {
920
+ if (resolved) sheetsThreadCommentPopupService.hidePopup();
921
+ };
922
+ useEffect(() => {
923
+ if (!panelVisible && hoverShapeId.current) markSelectionService.removeShape(hoverShapeId.current);
924
+ }, [markSelectionService, panelVisible]);
925
+ return /* @__PURE__ */ jsx(ThreadCommentPanel, {
926
+ unitId,
927
+ subUnitId$,
928
+ type: UniverInstanceType.UNIVER_SHEET,
929
+ onAdd: handleAdd,
930
+ getSubUnitName,
931
+ onResolve: handleResolve,
932
+ sortComments,
933
+ onItemEnter: handleHover,
934
+ onItemLeave: handleLeave,
935
+ onDeleteComment: () => {
936
+ handleLeave();
937
+ return true;
938
+ }
939
+ });
940
+ };
941
+
942
+ //#endregion
943
+ //#region src/controllers/sheets-thread-comment.controller.ts
944
+ /**
945
+ * Copyright 2023-present DreamNum Co., Ltd.
946
+ *
947
+ * Licensed under the Apache License, Version 2.0 (the "License");
948
+ * you may not use this file except in compliance with the License.
949
+ * You may obtain a copy of the License at
950
+ *
951
+ * http://www.apache.org/licenses/LICENSE-2.0
952
+ *
953
+ * Unless required by applicable law or agreed to in writing, software
954
+ * distributed under the License is distributed on an "AS IS" BASIS,
955
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
956
+ * See the License for the specific language governing permissions and
957
+ * limitations under the License.
958
+ */
959
+ let SheetsThreadCommentController = class SheetsThreadCommentController extends Disposable {
960
+ constructor(_menuManagerService, _componentManager, _shortcutService) {
961
+ super();
962
+ this._menuManagerService = _menuManagerService;
963
+ this._componentManager = _componentManager;
964
+ this._shortcutService = _shortcutService;
965
+ this._initMenu();
966
+ this._initShortcut();
967
+ this._initComponent();
968
+ }
969
+ _initShortcut() {
970
+ this._shortcutService.registerShortcut(AddCommentShortcut);
971
+ }
972
+ _initMenu() {
973
+ this._menuManagerService.mergeMenu(menuSchema);
974
+ }
975
+ _initComponent() {
976
+ [
977
+ [SHEETS_THREAD_COMMENT_MODAL, SheetsThreadCommentCell],
978
+ [SHEETS_THREAD_COMMENT_PANEL, SheetsThreadCommentPanel],
979
+ ["CommentIcon", CommentIcon]
980
+ ].forEach(([key, comp]) => {
981
+ this.disposeWithMe(this._componentManager.register(key, comp));
982
+ });
983
+ }
984
+ };
985
+ SheetsThreadCommentController = __decorate([
986
+ __decorateParam(0, IMenuManagerService),
987
+ __decorateParam(1, Inject(ComponentManager)),
988
+ __decorateParam(2, IShortcutService)
989
+ ], SheetsThreadCommentController);
990
+
991
+ //#endregion
992
+ //#region src/plugin.ts
993
+ let UniverSheetsThreadCommentUIPlugin = class UniverSheetsThreadCommentUIPlugin extends Plugin {
994
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
995
+ super();
996
+ this._config = _config;
997
+ this._injector = _injector;
998
+ this._commandService = _commandService;
999
+ this._configService = _configService;
1000
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
1001
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
1002
+ this._configService.setConfig(SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
1003
+ }
1004
+ onStarting() {
1005
+ [
1006
+ [SheetsThreadCommentController],
1007
+ [SheetsThreadCommentRenderController],
1008
+ [SheetsThreadCommentCopyPasteController],
1009
+ [SheetsThreadCommentHoverController],
1010
+ [SheetsThreadCommentPopupController],
1011
+ [SheetsThreadCommentPopupService],
1012
+ [SheetsThreadCommentPermissionController]
1013
+ ].forEach((dep) => {
1014
+ this._injector.add(dep);
1015
+ });
1016
+ [ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation].forEach((command) => {
1017
+ this._commandService.registerCommand(command);
1018
+ });
1019
+ this._injector.get(SheetsThreadCommentController);
1020
+ }
1021
+ onReady() {
1022
+ this._injector.get(SheetsThreadCommentRenderController);
1023
+ }
1024
+ onRendered() {
1025
+ this._injector.get(SheetsThreadCommentCopyPasteController);
1026
+ this._injector.get(SheetsThreadCommentHoverController);
1027
+ this._injector.get(SheetsThreadCommentPopupController);
1028
+ this._injector.get(SheetsThreadCommentPermissionController);
1029
+ }
1030
+ };
1031
+ _defineProperty(UniverSheetsThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
1032
+ _defineProperty(UniverSheetsThreadCommentUIPlugin, "packageName", name);
1033
+ _defineProperty(UniverSheetsThreadCommentUIPlugin, "version", version);
1034
+ _defineProperty(UniverSheetsThreadCommentUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1035
+ UniverSheetsThreadCommentUIPlugin = __decorate([
1036
+ DependentOn(UniverThreadCommentUIPlugin$1, UniverSheetsThreadCommentPlugin),
1037
+ __decorateParam(1, Inject(Injector)),
1038
+ __decorateParam(2, Inject(ICommandService)),
1039
+ __decorateParam(3, IConfigService)
1040
+ ], UniverSheetsThreadCommentUIPlugin);
1041
+
1042
+ //#endregion
1043
+ export { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, IThreadCommentDataSourceService, ResolveCommentCommand, SheetsThreadCommentPopupService, ShowAddSheetCommentModalOperation, ToggleSheetCommentPanelOperation, UniverSheetsThreadCommentUIPlugin, UniverThreadCommentUIPlugin, UpdateCommentCommand };