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