/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/@univerjs/sheets-thread-comment-ui@0.25.1/lib/es/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{CommandType,DependentOn,Disposable,DisposableCollection,ICommandService,IConfigService,IUniverInstanceService,Inject,Injector,InterceptorEffectEnum,LocaleService,Plugin,RANGE_TYPE,Range,Rectangle,Tools,UniverInstanceType,merge}from"@univerjs/core";import{INTERCEPTOR_POINT,RangeProtectionPermissionViewPoint,SetWorksheetActiveOperation,SheetInterceptorService,SheetPermissionCheckController,SheetsSelectionsService,WorkbookCommentPermission,WorksheetViewPermission,getSheetCommandTarget}from"@univerjs/sheets";import{SheetsThreadCommentModel,UniverSheetsThreadCommentPlugin}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation,ThreadCommentPanel,ThreadCommentPanelService,ThreadCommentTree,ThreadCommentTreeLocation,UniverThreadCommentUIPlugin,UniverThreadCommentUIPlugin as UniverThreadCommentUIPlugin$1}from"@univerjs/thread-comment-ui";import{ComponentManager,ContextMenuGroup,ContextMenuPosition,IMenuManagerService,IShortcutService,ISidebarService,IZenZoneService,KeyCode,MenuItemType,MetaKeys,RibbonInsertGroup,getMenuHiddenObservable,useDependency,useObservable}from"@univerjs/ui";import{COPY_TYPE,CellPopupManagerService,HoverManagerService,IEditorBridgeService,IMarkSelectionService,ISheetClipboardService,ScrollToRangeOperation,SheetCanvasPopManagerService,SheetSkeletonManagerService,getCurrentRangeDisable$,whenSheetEditorFocused}from"@univerjs/sheets-ui";import{BehaviorSubject,debounceTime,map}from"rxjs";import{IRenderManagerService}from"@univerjs/engine-render";import{serializeRange,singleReferenceToGrid}from"@univerjs/engine-formula";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";import{CommentIcon}from"@univerjs/icons";import{jsx}from"react/jsx-runtime";import{useCallback,useEffect,useMemo,useRef}from"react";const SHEETS_THREAD_COMMENT_MODAL="univer.sheet.thread-comment-modal",SHEETS_THREAD_COMMENT_PANEL="univer.sheet.thread-comment-panel",PLUGIN_NAME="SHEET_THREAD_COMMENT_UI_PLUGIN";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var n=o.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function toPropertyKey(e){var t=toPrimitive(e,"string");return"symbol"==_typeof(t)?t:t+""}function _defineProperty(e,t,o){return(t=toPropertyKey(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function __decorateParam(e,t){return function(o,n){t(o,n,e)}}function __decorate(e,t,o,n){var r,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,n);else for(var m=e.length-1;m>=0;m--)(r=e[m])&&(s=(i<3?r(s):i>3?r(t,o,s):r(t,o))||s);return i>3&&s&&Object.defineProperty(t,o,s),s}let SheetsThreadCommentPopupService=class extends Disposable{get activePopup(){return this._activePopup}constructor(e,t,o){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=o,_defineProperty(this,"_lastPopup",null),_defineProperty(this,"_activePopup",void 0),_defineProperty(this,"_activePopup$",new BehaviorSubject(null)),_defineProperty(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 o;const{row:n,col:r,unitId:i,subUnitId:s}=e;if(this._activePopup&&n===this._activePopup.row&&r===this._activePopup.col&&i===this._activePopup.unitId&&s===(null===(o=this.activePopup)||void 0===o?void 0:o.subUnitId))return this._activePopup=e,void this._activePopup$.next(e);if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);const m=this._cellPopupManagerService.showPopup({row:n,col:r,unitId:i,subUnitId:s},{componentKey:SHEETS_THREAD_COMMENT_MODAL,onClickOutside:()=>{this.hidePopup()},direction:"horizontal",excludeOutside:[...Array.from(document.querySelectorAll(".univer-thread-comment")),document.getElementById("thread-comment-add")].filter(Boolean),priority:2});if(!m)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const a=new DisposableCollection;a.add(m),a.add({dispose:()=>{null==t||t()}}),this._lastPopup=a}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))}};SheetsThreadCommentPopupService=__decorate([__decorateParam(0,Inject(SheetCanvasPopManagerService)),__decorateParam(1,IZenZoneService),__decorateParam(2,Inject(CellPopupManagerService))],SheetsThreadCommentPopupService);const ShowAddSheetCommentModalOperation={type:CommandType.OPERATION,id:"sheet.operation.show-comment-modal",handler(e){var t;const o=e.get(SheetsSelectionsService),n=e.get(IUniverInstanceService),r=e.get(SheetsThreadCommentPopupService),i=e.get(ThreadCommentPanelService),s=null===(t=o.getCurrentLastSelection())||void 0===t?void 0:t.primary,m=e.get(SheetsThreadCommentModel);if(!s)return!1;const a=getSheetCommandTarget(n);if(!a)return!1;const{workbook:d,worksheet:c,unitId:h,subUnitId:l}=a,u={workbook:d,worksheet:c,unitId:h,subUnitId:l,row:s.startRow,col:s.startColumn};r.showPopup(u);const p=m.getByLocation(h,l,s.startRow,s.startColumn);return p&&i.setActiveComment({unitId:h,subUnitId:l,commentId:p,trigger:"context-menu"}),!0}},ToggleSheetCommentPanelOperation={id:"sheet.operation.toggle-comment-panel",type:CommandType.OPERATION,handler(e){const t=e.get(ISidebarService),o=e.get(ThreadCommentPanelService);return o.panelVisible?(t.close(),o.setPanelVisible(!1)):(t.open({header:{title:"sheets-thread-comment-ui.panel.title"},children:{label:SHEETS_THREAD_COMMENT_PANEL},width:360}),o.setPanelVisible(!0)),!0}};var name="@univerjs/sheets-thread-comment-ui",version="0.25.1";const SHEETS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY="sheets-thread-comment.config",configSymbol=Symbol("sheets-thread-comment.config"),defaultPluginConfig={};let SheetsThreadCommentRenderController=class extends Disposable{constructor(e,t,o,n){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=o,this._renderManagerService=n,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT,{effect:InterceptorEffectEnum.Style,handler:(e,t,o)=>{const{row:n,col:r,unitId:i,subUnitId:s}=t;return this._sheetsThreadCommentModel.showCommentMarker(i,s,n,r)?(e&&e!==t.rawData||(e={...t.rawData}),e.markers={...null==e?void 0:e.markers,tr:{color:"#FFBD37",size:6}},o(e)):o(e)},priority:100}))}_initSkeletonChange(){const e=()=>{var e;const t=this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);if(!t)return;const o=t.getUnitId(),n=this._renderManagerService.getRenderById(o);null==n||null===(e=n.mainComponent)||void 0===e||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(debounceTime(16)).subscribe(()=>{e()}))}};SheetsThreadCommentRenderController=__decorate([__decorateParam(0,Inject(SheetInterceptorService)),__decorateParam(1,Inject(SheetsThreadCommentModel)),__decorateParam(2,IUniverInstanceService),__decorateParam(3,IRenderManagerService)],SheetsThreadCommentRenderController);const transformRef=(e,t,o)=>{const n=singleReferenceToGrid(e),r=o.row-t.row,i=o.column-t.column;return serializeRange({startColumn:n.column+i,startRow:n.row+r,endColumn:n.column+i,endRow:n.row+r})};let SheetsThreadCommentCopyPasteController=class extends Disposable{constructor(e,t,o){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=o,_defineProperty(this,"_copyInfo",void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:PLUGIN_NAME,onBeforeCopy:(e,t,o)=>{this._copyInfo={unitId:e,subUnitId:t,range:o}},onPasteCells:(e,t,o,n)=>{const{unitId:r,subUnitId:i,range:s}=t,m={row:s.rows[0],column:s.cols[0]};if(n.copyType===COPY_TYPE.CUT&&this._copyInfo){const{range:e,unitId:t,subUnitId:o}=this._copyInfo,n={row:e.startRow,column:e.startColumn};if(r!==t||i!==o){const s=[];Range.foreach(e,(e,n)=>{const r=this._sheetsThreadCommentModel.getAllByLocation(t,o,e,n);this._threadCommentDataSourceService.syncUpdateMutationToColla?r.forEach(e=>{s.push(e)}):r.forEach(({children:e,...t})=>{t.parentId||s.push(t)})});const a=[],d=[],c=[],h=[],l=e=>{a.unshift({id:DeleteCommentMutation.id,params:{unitId:t,subUnitId:o,commentId:e.id}}),c.push({id:AddCommentMutation.id,params:{unitId:r,subUnitId:i,comment:{...e,ref:transformRef(e.ref,n,m),unitId:r,subUnitId:i},sync:!0}}),d.push({id:AddCommentMutation.id,params:{unitId:t,subUnitId:o,comment:e,sync:!0}}),h.unshift({id:DeleteCommentMutation.id,params:{unitId:r,subUnitId:i,commentId:e.id}})};return s.forEach(e=>{l(e)}),{redos:[...a,...c],undos:[...h,...d]}}}return{redos:[],undos:[]}}}))}};SheetsThreadCommentCopyPasteController=__decorate([__decorateParam(0,Inject(ISheetClipboardService)),__decorateParam(1,Inject(SheetsThreadCommentModel)),__decorateParam(2,IThreadCommentDataSourceService$1)],SheetsThreadCommentCopyPasteController);let SheetsThreadCommentHoverController=class extends Disposable{constructor(e,t,o,n){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=o,this._sheetPermissionCheckController=n,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe(e=>{const t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){const{location:o}=e,{unitId:n,subUnitId:r,row:i,col:s}=o,m=this._sheetsThreadCommentModel.getByLocation(n,r,i,s);if(m){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]},[{startRow:i,startColumn:s,endRow:i,endColumn:s}],n,r))return;const e=this._sheetsThreadCommentModel.getComment(n,r,m);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:i,col:s,commentId:m,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};SheetsThreadCommentHoverController=__decorate([__decorateParam(0,Inject(HoverManagerService)),__decorateParam(1,Inject(SheetsThreadCommentPopupService)),__decorateParam(2,Inject(SheetsThreadCommentModel)),__decorateParam(3,Inject(SheetPermissionCheckController))],SheetsThreadCommentHoverController);let SheetsThreadCommentPermissionController=class extends Disposable{constructor(e,t,o,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=o,this._sheetsThreadCommentModel=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{const{id:t}=e;if(t===ShowAddSheetCommentModalOperation.id||t===ToggleSheetCommentPanelOperation.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"));else if(t===AddCommentCommand$1.id){const{unitId:t,subUnitId:o,comment:n}=e.params,{row:r,column:i}=singleReferenceToGrid(n.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],t,o)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"))}else if(t===UpdateCommentCommand$1.id){const{unitId:t,subUnitId:o,payload:n}=e.params,{commentId:r}=n,i=this._sheetsThreadCommentModel.getComment(t,o,r);if(i){const{row:e,column:n}=singleReferenceToGrid(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:n,endRow:e,endColumn:n}],t,o)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"))}}else if(t===ResolveCommentCommand$1.id||t===DeleteCommentCommand$1.id||t===DeleteCommentTreeCommand$1.id){const{unitId:t,subUnitId:o,commentId:n}=e.params,r=this._sheetsThreadCommentModel.getComment(t,o,n);if(r){const{row:e,column:n}=singleReferenceToGrid(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:n,endRow:e,endColumn:n}],t,o)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-thread-comment-ui.permission.commentErr"))}}}))}};SheetsThreadCommentPermissionController=__decorate([__decorateParam(0,Inject(LocaleService)),__decorateParam(1,ICommandService),__decorateParam(2,Inject(SheetPermissionCheckController)),__decorateParam(3,Inject(SheetsThreadCommentModel))],SheetsThreadCommentPermissionController);let SheetsThreadCommentPopupController=class extends Disposable{constructor(e,t,o,n,r,i,s,m,a,d){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=o,this._threadCommentPanelService=n,this._univerInstanceService=r,this._sheetPermissionCheckController=i,this._markSelectionService=s,this._sheetSelectionService=m,this._editorBridgeService=a,this._renderManagerService=d,_defineProperty(this,"_isSwitchToCommenting",!1),_defineProperty(this,"_selectionShapeInfo",null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,o){var n,r,i;const s=null===(n=e[0])||void 0===n?void 0:n.range,m=this._renderManagerService.getRenderById(t),a=null==m||null===(r=m.with(SheetSkeletonManagerService).getSkeletonParam(o))||void 0===r?void 0:r.skeleton;if(!a)return;if(!s)return;const d=a.getCellWithCoordByIndex(s.startRow,s.startColumn);if(((null!==(i=s.rangeType)&&void 0!==i?i:RANGE_TYPE.NORMAL)!==RANGE_TYPE.NORMAL||s.endColumn-s.startColumn>0||s.endRow-s.startRow>0)&&(!d.isMerged&&!d.isMergedMainCell||!Rectangle.equals(d.mergeInfo,s)))return void(this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(SetActiveCommentOperation.id));const c=d.actualRow,h=d.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,o,c,h))return void(this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(SetActiveCommentOperation.id));const l=this._sheetsThreadCommentModel.getByLocation(t,o,c,h);l&&this._commandService.executeCommand(SetActiveCommentOperation.id,{unitId:t,subUnitId:o,commentId:l})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;const 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===DeleteCommentMutation.id){const t=e.params,o=this._sheetsThreadCommentPopupService.activePopup;if(!o)return;const{unitId:n,subUnitId:r,commentId:i}=o;t.unitId===n&&t.subUnitId===r&&t.commentId===i&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;const{unitId:o,subUnitId:n,commentId:r,trigger:i}=e,s=this._sheetsThreadCommentModel.getComment(o,n,r);if(!s||s.resolved)return;const m=this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);if(!m)return;if(m.getUnitId()!==o)return;this._isSwitchToCommenting=!0,(null===(t=m.getActiveSheet())||void 0===t?void 0:t.getSheetId())!==n&&await this._commandService.executeCommand(SetWorksheetActiveOperation.id,{unitId:o,subUnitId:n}),this._isSwitchToCommenting=!1;const a=singleReferenceToGrid(s.ref),{row:d,column:c}=a;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]},[{startRow:d,startColumn:c,endRow:d,endColumn:c}],o,n))return;const h=1;if(await this._commandService.executeCommand(ScrollToRangeOperation.id,{range:{startRow:Math.max(a.row-h,0),endRow:a.row+h,startColumn:Math.max(a.column-h,0),endColumn:a.column+h}}),this._editorBridgeService.isVisible().visible)return;this._sheetsThreadCommentPopupService.showPopup({unitId:o,subUnitId:n,row:a.row,col:a.column,commentId:s.id,trigger:i})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(debounceTime(100)).subscribe(e=>{var t,o;if(!e)return void(this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null));const{unitId:n,subUnitId:r,commentId:i}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);const s=this._sheetsThreadCommentModel.getComment(n,r,i);if(!s)return;const{row:m,column:a}=singleReferenceToGrid(s.ref);if(Number.isNaN(m)||Number.isNaN(a))return null;const d=null===(t=this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET))||void 0===t?void 0:t.getSheetBySheetId(r),c=null!==(o=null==d?void 0:d.getMergedCell(m,a))&&void 0!==o?o:{startColumn:a,endColumn:a,startRow:m,endRow:m},h=this._markSelectionService.addShape({range:c,style:{fill:"rgba(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1);h&&(this._selectionShapeInfo={...e,shapeId:h})}))}};SheetsThreadCommentPopupController=__decorate([__decorateParam(0,ICommandService),__decorateParam(1,Inject(SheetsThreadCommentPopupService)),__decorateParam(2,Inject(SheetsThreadCommentModel)),__decorateParam(3,Inject(ThreadCommentPanelService)),__decorateParam(4,IUniverInstanceService),__decorateParam(5,Inject(SheetPermissionCheckController)),__decorateParam(6,IMarkSelectionService),__decorateParam(7,Inject(SheetsSelectionsService)),__decorateParam(8,IEditorBridgeService),__decorateParam(9,IRenderManagerService)],SheetsThreadCommentPopupController);const threadCommentMenuFactory=e=>({id:ShowAddSheetCommentModalOperation.id,type:MenuItemType.BUTTON,icon:"CommentIcon",title:"sheets-thread-comment-ui.menu.addComment",hidden$:getMenuHiddenObservable(e,UniverInstanceType.UNIVER_SHEET),disabled$:getCurrentRangeDisable$(e,{workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]})}),threadPanelMenuFactory=e=>({id:ToggleSheetCommentPanelOperation.id,type:MenuItemType.BUTTON,icon:"CommentIcon",tooltip:"sheets-thread-comment-ui.menu.commentManagement",disabled$:getCurrentRangeDisable$(e,{workbookTypes:[WorkbookCommentPermission],worksheetTypes:[WorksheetViewPermission],rangeTypes:[RangeProtectionPermissionViewPoint]}),hidden$:getMenuHiddenObservable(e,UniverInstanceType.UNIVER_SHEET)}),AddCommentShortcut={id:ShowAddSheetCommentModalOperation.id,binding:KeyCode.M|MetaKeys.CTRL_COMMAND|MetaKeys.ALT,preconditions:whenSheetEditorFocused},menuSchema={[RibbonInsertGroup.MEDIA]:{[ToggleSheetCommentPanelOperation.id]:{order:2,menuItemFactory:threadPanelMenuFactory}},[ContextMenuPosition.MAIN_AREA]:{[ContextMenuGroup.OTHERS]:{[ShowAddSheetCommentModalOperation.id]:{order:0,menuItemFactory:threadCommentMenuFactory}}}},SheetsThreadCommentCell=()=>{const e=useDependency(IUniverInstanceService),t=useDependency(SheetsThreadCommentPopupService),o=useObservable(t.activePopup$),n=useDependency(SheetsThreadCommentModel);if(useObservable(n.commentUpdate$),!o)return null;const{row:r,col:i,unitId:s,subUnitId:m,trigger:a}=o,d=n.getByLocation(s,m,r,i),c=`${Tools.chatAtABC(i)}${r+1}`;return jsx(ThreadCommentTree,{onClick:()=>{t.persistPopup()},location:ThreadCommentTreeLocation.CELL,id:d,unitId:s,subUnitId:m,type:UniverInstanceType.UNIVER_SHEET,refStr:c,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var o,n;return null!==(o=null===(n=e.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET))||void 0===n||null===(n=n.getSheetBySheetId(t))||void 0===n?void 0:n.getName())&&void 0!==o?o:""},autoFocus:"context-menu"===a})},SheetsThreadCommentPanel=()=>{var e;const t=useDependency(IMarkSelectionService),o=useDependency(IUniverInstanceService),n=useDependency(SheetsThreadCommentPopupService),r=o.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET),i=r.getUnitId(),s=useDependency(ICommandService),m=useMemo(()=>r.activeSheet$.pipe(map(e=>null==e?void 0:e.getSheetId())),[r.activeSheet$]),a=useObservable(m,null===(e=r.getActiveSheet())||void 0===e?void 0:e.getSheetId()),d=useRef(null),c=useDependency(ThreadCommentPanelService),h=useObservable(c.activeCommentId$),l=useObservable(c.panelVisible$,c.panelVisible),u=useCallback(e=>{const t=r.getSheets(),o={};t.forEach((e,t)=>{o[e.getSheetId()]=t});const n=e=>e.map(e=>{var t;const n=singleReferenceToGrid(e.ref),r=[null!==(t=o[e.subUnitId])&&void 0!==t?t:0,n.row,n.column];return{...e,p:r}}).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[...n(e.filter(e=>!e.resolved)),...n(e.filter(e=>e.resolved))]},[r]),p=useCallback(e=>{if(e.unitId===i&&e.subUnitId===a&&!e.resolved){var o;const{row:n,column:i}=singleReferenceToGrid(e.ref),s=r.getSheetBySheetId(e.subUnitId),m=null!==(o=null==s?void 0:s.getMergedCell(n,i))&&void 0!==o?o:{startColumn:i,endColumn:i,startRow:n,endRow:n};if(!Number.isNaN(n)&&!Number.isNaN(i))return t.addShape({range:m,style:{fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}return null},[t,a,i]),C=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return useEffect(()=>{!l&&d.current&&t.removeShape(d.current)},[t,l]),jsx(ThreadCommentPanel,{unitId:i,subUnitId$:m,type:UniverInstanceType.UNIVER_SHEET,onAdd:()=>{s.executeCommand(ShowAddSheetCommentModalOperation.id)},getSubUnitName:e=>{var t,o;return null!==(t=null===(o=r.getSheetBySheetId(e))||void 0===o?void 0:o.getName())&&void 0!==t?t:""},onResolve:(e,t)=>{t&&n.hidePopup()},sortComments:u,onItemEnter:e=>{h&&h.unitId===e.unitId&&h.subUnitId===e.subUnitId&&h.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=p(e))},onItemLeave:C,onDeleteComment:()=>(C(),!0)})};let SheetsThreadCommentController=class extends Disposable{constructor(e,t,o){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=o,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(AddCommentShortcut)}_initMenu(){this._menuManagerService.mergeMenu(menuSchema)}_initComponent(){[[SHEETS_THREAD_COMMENT_MODAL,SheetsThreadCommentCell],[SHEETS_THREAD_COMMENT_PANEL,SheetsThreadCommentPanel],["CommentIcon",CommentIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};SheetsThreadCommentController=__decorate([__decorateParam(0,IMenuManagerService),__decorateParam(1,Inject(ComponentManager)),__decorateParam(2,IShortcutService)],SheetsThreadCommentController);let UniverSheetsThreadCommentUIPlugin=class extends Plugin{constructor(e=defaultPluginConfig,t,o,n){super(),this._config=e,this._injector=t,this._commandService=o,this._configService=n;const{menu:r,...i}=merge({},defaultPluginConfig,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig("sheets-thread-comment.config",i)}onStarting(){[[SheetsThreadCommentController],[SheetsThreadCommentRenderController],[SheetsThreadCommentCopyPasteController],[SheetsThreadCommentHoverController],[SheetsThreadCommentPopupController],[SheetsThreadCommentPopupService],[SheetsThreadCommentPermissionController]].forEach(e=>{this._injector.add(e)}),[ShowAddSheetCommentModalOperation,ToggleSheetCommentPanelOperation].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(SheetsThreadCommentController)}onReady(){this._injector.get(SheetsThreadCommentRenderController)}onRendered(){this._injector.get(SheetsThreadCommentCopyPasteController),this._injector.get(SheetsThreadCommentHoverController),this._injector.get(SheetsThreadCommentPopupController),this._injector.get(SheetsThreadCommentPermissionController)}};_defineProperty(UniverSheetsThreadCommentUIPlugin,"pluginName",PLUGIN_NAME),_defineProperty(UniverSheetsThreadCommentUIPlugin,"packageName",name),_defineProperty(UniverSheetsThreadCommentUIPlugin,"version",version),_defineProperty(UniverSheetsThreadCommentUIPlugin,"type",UniverInstanceType.UNIVER_SHEET),UniverSheetsThreadCommentUIPlugin=__decorate([DependentOn(UniverThreadCommentUIPlugin$1,UniverSheetsThreadCommentPlugin),__decorateParam(1,Inject(Injector)),__decorateParam(2,Inject(ICommandService)),__decorateParam(3,IConfigService)],UniverSheetsThreadCommentUIPlugin);export{AddCommentCommand,DeleteCommentCommand,DeleteCommentTreeCommand,IThreadCommentDataSourceService,ResolveCommentCommand,SheetsThreadCommentPopupService,ShowAddSheetCommentModalOperation,ToggleSheetCommentPanelOperation,UniverSheetsThreadCommentUIPlugin,UniverThreadCommentUIPlugin,UpdateCommentCommand};
//# sourceMappingURL=/sm/43a35018282df3c3108285715e0389bfdbd6d9f3e135bb5ae465c6232659ee06.map