@univerjs/sheets-thread-comment-ui 0.19.0 → 0.20.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 +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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.19.0`;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`});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.0`;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}});
|
package/lib/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,Plugin as d,RANGE_TYPE as f,Range as p,Rectangle as m,Tools as h,UniverInstanceType as g,merge as ee}from"@univerjs/core";import{INTERCEPTOR_POINT as te,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as ne,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as re}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as ie}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ThreadCommentTreeLocation as se,UniverThreadCommentUIPlugin as ce,UniverThreadCommentUIPlugin as le}from"@univerjs/thread-comment-ui";import{ComponentManager as ue,ContextMenuGroup as de,ContextMenuPosition as fe,IMenuManagerService as pe,IShortcutService as me,ISidebarService as he,IZenZoneService as ge,KeyCode as _e,MenuItemType as E,MetaKeys as D,RibbonInsertGroup as ve,getMenuHiddenObservable as O,useDependency as k,useObservable as A}from"@univerjs/ui";import{COPY_TYPE as ye,CellPopupManagerService as be,HoverManagerService as xe,IEditorBridgeService as Se,IMarkSelectionService as j,ISheetClipboardService as Ce,ScrollToRangeOperation as we,SheetCanvasPopManagerService as Te,SheetSkeletonManagerService as Ee,getCurrentRangeDisable$ as M,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{BehaviorSubject as Oe,debounceTime as N,map as ke}from"rxjs";import{IRenderManagerService as P}from"@univerjs/engine-render";import{serializeRange as Ae,singleReferenceToGrid as F}from"@univerjs/engine-formula";import{AddCommentCommand as je,AddCommentCommand as Me,AddCommentMutation as I,DeleteCommentCommand as Ne,DeleteCommentCommand as Pe,DeleteCommentMutation as L,DeleteCommentTreeCommand as Fe,DeleteCommentTreeCommand as Ie,IThreadCommentDataSourceService as Le,IThreadCommentDataSourceService as Re,ResolveCommentCommand as ze,ResolveCommentCommand as Be,UpdateCommentCommand as Ve,UpdateCommentCommand as He}from"@univerjs/thread-comment";import{CommentIcon as Ue}from"@univerjs/icons";import{jsx as R}from"react/jsx-runtime";import{useCallback as z,useEffect as We,useMemo as Ge,useRef as Ke}from"react";const qe=`univer.sheet.thread-comment-modal`,Je=`univer.sheet.thread-comment-panel`,Ye=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function B(e){"@babel/helpers - typeof";return B=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},B(e)}function Xe(e,t){if(B(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ze(e){var t=Xe(e,`string`);return B(t)==`symbol`?t:t+``}function V(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,V(this,`_lastPopup`,null),V(this,`_activePopup`,void 0),V(this,`_activePopup$`,new Oe(null)),V(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:qe,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=U([H(0,s(Te)),H(1,ge),H(2,s(be))],W);const G={type:e.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var t;let n=e.get(ne),r=e.get(o),i=e.get(W),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=re(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}},K={id:`sheet.operation.toggle-comment-panel`,type:e.OPERATION,handler(e){let t=e.get(he),n=e.get(T);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):(t.open({header:{title:`threadCommentUI.panel.title`},children:{label:Je},width:360}),n.setPanelVisible(!0)),!0}};var Qe=`@univerjs/sheets-thread-comment-ui`,$e=`0.19.0`;const et=`sheets-thread-comment.config`;Symbol(et);const tt={};let q=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(te.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(N(16)).subscribe(()=>{e()}))}};q=U([H(0,s(y)),H(1,s(C)),H(2,o),H(3,P)],q);const nt=(e,t,n)=>{let r=F(e),i=n.row-t.row,a=n.column-t.column;return Ae({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let J=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,V(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Ye,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===ye.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];p.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],f=e=>{c.unshift({id:L.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:I.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:nt(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:I.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:L.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{f(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};J=U([H(0,s(Ce)),H(1,s(C)),H(2,Re)],J);let Y=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Y=U([H(0,s(xe)),H(1,s(W)),H(2,s(C)),H(3,s(b))],Y);let X=class extends n{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===G.id||t===K.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[x],worksheetTypes:[S]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===Me.id){let{unitId:t,subUnitId:n,comment:r}=e.params,{row:i,column:a}=F(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:i,startColumn:a,endRow:i,endColumn:a}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===He.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);if(a){let{row:e,column:r}=F(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===Be.id||t===Pe.id||t===Ie.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);if(i){let{row:e,column:r}=F(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};X=U([H(0,s(u)),H(1,i),H(2,s(b)),H(3,s(C))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,V(this,`_isSwitchToCommenting`,!1),V(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(Ee).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?f.NORMAL:a)!==f.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,d=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,d)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let p=this._sheetsThreadCommentModel.getByLocation(t,n,u,d);p&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:p})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=F(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(we.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(N(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=F(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=U([H(0,i),H(1,s(W)),H(2,s(C)),H(3,s(T)),H(4,o),H(5,s(b)),H(6,j),H(7,s(ne)),H(8,Se),H(9,P)],Z);const rt=e=>({id:G.id,type:E.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:O(e,g.UNIVER_SHEET),disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),it=e=>({id:K.id,type:E.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:O(e,g.UNIVER_SHEET)}),at={id:G.id,binding:_e.M|D.CTRL_COMMAND|D.ALT,preconditions:De},ot={[ve.MEDIA]:{[K.id]:{order:2,menuItemFactory:it}},[fe.MAIN_AREA]:{[de.OTHERS]:{[G.id]:{order:0,menuItemFactory:rt}}}},st=()=>{let e=k(o),t=k(W),n=A(t.activePopup$),r=k(C);if(A(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${h.chatAtABC(a)}${i+1}`;return R(oe,{onClick:()=>{t.persistPopup()},location:se.CELL,id:u,unitId:s,subUnitId:c,type:g.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(g.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},ct=()=>{var e;let t=k(j),n=k(o),r=k(W),a=n.getCurrentUnitForType(g.UNIVER_SHEET),s=a.getUnitId(),c=k(i),l=Ge(()=>a.activeSheet$.pipe(ke(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=A(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=Ke(null),f=k(T),p=A(f.activeCommentId$),m=A(f.panelVisible$,f.panelVisible),h=z(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=F(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=z(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=F(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),te=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},_=()=>{c.executeCommand(G.id)},v=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},y=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return We(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),R(ae,{unitId:s,subUnitId$:l,type:g.UNIVER_SHEET,onAdd:_,getSubUnitName:te,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:h,onItemEnter:v,onItemLeave:y,onDeleteComment:()=>(y(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(at)}_initMenu(){this._menuManagerService.mergeMenu(ot)}_initComponent(){[[qe,st],[Je,ct],[`CommentIcon`,Ue]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=U([H(0,pe),H(1,s(ue)),H(2,me)],Q);let $=class extends d{constructor(e=tt,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=ee({},tt,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(et,a)}onStarting(){[[Q],[q],[J],[Y],[Z],[W],[X]].forEach(e=>{this._injector.add(e)}),[G,K].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(q)}onRendered(){this._injector.get(J),this._injector.get(Y),this._injector.get(Z),this._injector.get(X)}};V($,`pluginName`,Ye),V($,`packageName`,Qe),V($,`version`,$e),V($,`type`,g.UNIVER_SHEET),$=U([t(le,ie),H(1,s(c)),H(2,s(i)),H(3,a)],$);export{je as AddCommentCommand,Ne as DeleteCommentCommand,Fe as DeleteCommentTreeCommand,Le as IThreadCommentDataSourceService,ze as ResolveCommentCommand,W as SheetsThreadCommentPopupService,G as ShowAddSheetCommentModalOperation,K as ToggleSheetCommentPanelOperation,$ as UniverSheetsThreadCommentUIPlugin,ce as UniverThreadCommentUIPlugin,Ve as UpdateCommentCommand};
|
|
1
|
+
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,Plugin as d,RANGE_TYPE as f,Range as p,Rectangle as m,Tools as h,UniverInstanceType as g,merge as ee}from"@univerjs/core";import{INTERCEPTOR_POINT as te,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as ne,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as re}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as ie}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ThreadCommentTreeLocation as se,UniverThreadCommentUIPlugin as ce,UniverThreadCommentUIPlugin as le}from"@univerjs/thread-comment-ui";import{ComponentManager as ue,ContextMenuGroup as de,ContextMenuPosition as fe,IMenuManagerService as pe,IShortcutService as me,ISidebarService as he,IZenZoneService as ge,KeyCode as _e,MenuItemType as E,MetaKeys as D,RibbonInsertGroup as ve,getMenuHiddenObservable as O,useDependency as k,useObservable as A}from"@univerjs/ui";import{COPY_TYPE as ye,CellPopupManagerService as be,HoverManagerService as xe,IEditorBridgeService as Se,IMarkSelectionService as j,ISheetClipboardService as Ce,ScrollToRangeOperation as we,SheetCanvasPopManagerService as Te,SheetSkeletonManagerService as Ee,getCurrentRangeDisable$ as M,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{BehaviorSubject as Oe,debounceTime as N,map as ke}from"rxjs";import{IRenderManagerService as P}from"@univerjs/engine-render";import{serializeRange as Ae,singleReferenceToGrid as F}from"@univerjs/engine-formula";import{AddCommentCommand as je,AddCommentCommand as Me,AddCommentMutation as I,DeleteCommentCommand as Ne,DeleteCommentCommand as Pe,DeleteCommentMutation as L,DeleteCommentTreeCommand as Fe,DeleteCommentTreeCommand as Ie,IThreadCommentDataSourceService as Le,IThreadCommentDataSourceService as Re,ResolveCommentCommand as ze,ResolveCommentCommand as Be,UpdateCommentCommand as Ve,UpdateCommentCommand as He}from"@univerjs/thread-comment";import{CommentIcon as Ue}from"@univerjs/icons";import{jsx as R}from"react/jsx-runtime";import{useCallback as z,useEffect as We,useMemo as Ge,useRef as Ke}from"react";const qe=`univer.sheet.thread-comment-modal`,Je=`univer.sheet.thread-comment-panel`,Ye=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function B(e){"@babel/helpers - typeof";return B=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},B(e)}function Xe(e,t){if(B(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ze(e){var t=Xe(e,`string`);return B(t)==`symbol`?t:t+``}function V(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,V(this,`_lastPopup`,null),V(this,`_activePopup`,void 0),V(this,`_activePopup$`,new Oe(null)),V(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:qe,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=U([H(0,s(Te)),H(1,ge),H(2,s(be))],W);const G={type:e.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var t;let n=e.get(ne),r=e.get(o),i=e.get(W),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=re(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}},K={id:`sheet.operation.toggle-comment-panel`,type:e.OPERATION,handler(e){let t=e.get(he),n=e.get(T);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):(t.open({header:{title:`threadCommentUI.panel.title`},children:{label:Je},width:360}),n.setPanelVisible(!0)),!0}};var Qe=`@univerjs/sheets-thread-comment-ui`,$e=`0.20.0`;const et=`sheets-thread-comment.config`;Symbol(et);const tt={};let q=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(te.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(N(16)).subscribe(()=>{e()}))}};q=U([H(0,s(y)),H(1,s(C)),H(2,o),H(3,P)],q);const nt=(e,t,n)=>{let r=F(e),i=n.row-t.row,a=n.column-t.column;return Ae({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let J=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,V(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Ye,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===ye.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];p.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],f=e=>{c.unshift({id:L.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:I.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:nt(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:I.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:L.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{f(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};J=U([H(0,s(Ce)),H(1,s(C)),H(2,Re)],J);let Y=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Y=U([H(0,s(xe)),H(1,s(W)),H(2,s(C)),H(3,s(b))],Y);let X=class extends n{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===G.id||t===K.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[x],worksheetTypes:[S]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===Me.id){let{unitId:t,subUnitId:n,comment:r}=e.params,{row:i,column:a}=F(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:i,startColumn:a,endRow:i,endColumn:a}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===He.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);if(a){let{row:e,column:r}=F(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===Be.id||t===Pe.id||t===Ie.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);if(i){let{row:e,column:r}=F(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};X=U([H(0,s(u)),H(1,i),H(2,s(b)),H(3,s(C))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,V(this,`_isSwitchToCommenting`,!1),V(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(Ee).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?f.NORMAL:a)!==f.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,d=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,d)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let p=this._sheetsThreadCommentModel.getByLocation(t,n,u,d);p&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:p})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=F(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(we.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(N(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=F(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=U([H(0,i),H(1,s(W)),H(2,s(C)),H(3,s(T)),H(4,o),H(5,s(b)),H(6,j),H(7,s(ne)),H(8,Se),H(9,P)],Z);const rt=e=>({id:G.id,type:E.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:O(e,g.UNIVER_SHEET),disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),it=e=>({id:K.id,type:E.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:O(e,g.UNIVER_SHEET)}),at={id:G.id,binding:_e.M|D.CTRL_COMMAND|D.ALT,preconditions:De},ot={[ve.MEDIA]:{[K.id]:{order:2,menuItemFactory:it}},[fe.MAIN_AREA]:{[de.OTHERS]:{[G.id]:{order:0,menuItemFactory:rt}}}},st=()=>{let e=k(o),t=k(W),n=A(t.activePopup$),r=k(C);if(A(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${h.chatAtABC(a)}${i+1}`;return R(oe,{onClick:()=>{t.persistPopup()},location:se.CELL,id:u,unitId:s,subUnitId:c,type:g.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(g.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},ct=()=>{var e;let t=k(j),n=k(o),r=k(W),a=n.getCurrentUnitForType(g.UNIVER_SHEET),s=a.getUnitId(),c=k(i),l=Ge(()=>a.activeSheet$.pipe(ke(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=A(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=Ke(null),f=k(T),p=A(f.activeCommentId$),m=A(f.panelVisible$,f.panelVisible),h=z(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=F(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=z(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=F(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),te=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},_=()=>{c.executeCommand(G.id)},v=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},y=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return We(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),R(ae,{unitId:s,subUnitId$:l,type:g.UNIVER_SHEET,onAdd:_,getSubUnitName:te,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:h,onItemEnter:v,onItemLeave:y,onDeleteComment:()=>(y(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(at)}_initMenu(){this._menuManagerService.mergeMenu(ot)}_initComponent(){[[qe,st],[Je,ct],[`CommentIcon`,Ue]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=U([H(0,pe),H(1,s(ue)),H(2,me)],Q);let $=class extends d{constructor(e=tt,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=ee({},tt,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(et,a)}onStarting(){[[Q],[q],[J],[Y],[Z],[W],[X]].forEach(e=>{this._injector.add(e)}),[G,K].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(q)}onRendered(){this._injector.get(J),this._injector.get(Y),this._injector.get(Z),this._injector.get(X)}};V($,`pluginName`,Ye),V($,`packageName`,Qe),V($,`version`,$e),V($,`type`,g.UNIVER_SHEET),$=U([t(le,ie),H(1,s(c)),H(2,s(i)),H(3,a)],$);export{je as AddCommentCommand,Ne as DeleteCommentCommand,Fe as DeleteCommentTreeCommand,Le as IThreadCommentDataSourceService,ze as ResolveCommentCommand,W as SheetsThreadCommentPopupService,G as ShowAddSheetCommentModalOperation,K as ToggleSheetCommentPanelOperation,$ as UniverSheetsThreadCommentUIPlugin,ce as UniverThreadCommentUIPlugin,Ve as UpdateCommentCommand};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,Plugin as d,RANGE_TYPE as f,Range as p,Rectangle as m,Tools as h,UniverInstanceType as g,merge as ee}from"@univerjs/core";import{INTERCEPTOR_POINT as te,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as ne,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as re}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as ie}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ThreadCommentTreeLocation as se,UniverThreadCommentUIPlugin as ce,UniverThreadCommentUIPlugin as le}from"@univerjs/thread-comment-ui";import{ComponentManager as ue,ContextMenuGroup as de,ContextMenuPosition as fe,IMenuManagerService as pe,IShortcutService as me,ISidebarService as he,IZenZoneService as ge,KeyCode as _e,MenuItemType as E,MetaKeys as D,RibbonInsertGroup as ve,getMenuHiddenObservable as O,useDependency as k,useObservable as A}from"@univerjs/ui";import{COPY_TYPE as ye,CellPopupManagerService as be,HoverManagerService as xe,IEditorBridgeService as Se,IMarkSelectionService as j,ISheetClipboardService as Ce,ScrollToRangeOperation as we,SheetCanvasPopManagerService as Te,SheetSkeletonManagerService as Ee,getCurrentRangeDisable$ as M,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{BehaviorSubject as Oe,debounceTime as N,map as ke}from"rxjs";import{IRenderManagerService as P}from"@univerjs/engine-render";import{serializeRange as Ae,singleReferenceToGrid as F}from"@univerjs/engine-formula";import{AddCommentCommand as je,AddCommentCommand as Me,AddCommentMutation as I,DeleteCommentCommand as Ne,DeleteCommentCommand as Pe,DeleteCommentMutation as L,DeleteCommentTreeCommand as Fe,DeleteCommentTreeCommand as Ie,IThreadCommentDataSourceService as Le,IThreadCommentDataSourceService as Re,ResolveCommentCommand as ze,ResolveCommentCommand as Be,UpdateCommentCommand as Ve,UpdateCommentCommand as He}from"@univerjs/thread-comment";import{CommentIcon as Ue}from"@univerjs/icons";import{jsx as R}from"react/jsx-runtime";import{useCallback as z,useEffect as We,useMemo as Ge,useRef as Ke}from"react";const qe=`univer.sheet.thread-comment-modal`,Je=`univer.sheet.thread-comment-panel`,Ye=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function B(e){"@babel/helpers - typeof";return B=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},B(e)}function Xe(e,t){if(B(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ze(e){var t=Xe(e,`string`);return B(t)==`symbol`?t:t+``}function V(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,V(this,`_lastPopup`,null),V(this,`_activePopup`,void 0),V(this,`_activePopup$`,new Oe(null)),V(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:qe,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=U([H(0,s(Te)),H(1,ge),H(2,s(be))],W);const G={type:e.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var t;let n=e.get(ne),r=e.get(o),i=e.get(W),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=re(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}},K={id:`sheet.operation.toggle-comment-panel`,type:e.OPERATION,handler(e){let t=e.get(he),n=e.get(T);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):(t.open({header:{title:`threadCommentUI.panel.title`},children:{label:Je},width:360}),n.setPanelVisible(!0)),!0}};var Qe=`@univerjs/sheets-thread-comment-ui`,$e=`0.19.0`;const et=`sheets-thread-comment.config`;Symbol(et);const tt={};let q=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(te.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(N(16)).subscribe(()=>{e()}))}};q=U([H(0,s(y)),H(1,s(C)),H(2,o),H(3,P)],q);const nt=(e,t,n)=>{let r=F(e),i=n.row-t.row,a=n.column-t.column;return Ae({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let J=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,V(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Ye,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===ye.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];p.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],f=e=>{c.unshift({id:L.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:I.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:nt(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:I.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:L.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{f(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};J=U([H(0,s(Ce)),H(1,s(C)),H(2,Re)],J);let Y=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Y=U([H(0,s(xe)),H(1,s(W)),H(2,s(C)),H(3,s(b))],Y);let X=class extends n{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===G.id||t===K.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[x],worksheetTypes:[S]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===Me.id){let{unitId:t,subUnitId:n,comment:r}=e.params,{row:i,column:a}=F(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:i,startColumn:a,endRow:i,endColumn:a}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===He.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);if(a){let{row:e,column:r}=F(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===Be.id||t===Pe.id||t===Ie.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);if(i){let{row:e,column:r}=F(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};X=U([H(0,s(u)),H(1,i),H(2,s(b)),H(3,s(C))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,V(this,`_isSwitchToCommenting`,!1),V(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(Ee).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?f.NORMAL:a)!==f.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,d=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,d)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let p=this._sheetsThreadCommentModel.getByLocation(t,n,u,d);p&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:p})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=F(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(we.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(N(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=F(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=U([H(0,i),H(1,s(W)),H(2,s(C)),H(3,s(T)),H(4,o),H(5,s(b)),H(6,j),H(7,s(ne)),H(8,Se),H(9,P)],Z);const rt=e=>({id:G.id,type:E.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:O(e,g.UNIVER_SHEET),disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),it=e=>({id:K.id,type:E.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:O(e,g.UNIVER_SHEET)}),at={id:G.id,binding:_e.M|D.CTRL_COMMAND|D.ALT,preconditions:De},ot={[ve.MEDIA]:{[K.id]:{order:2,menuItemFactory:it}},[fe.MAIN_AREA]:{[de.OTHERS]:{[G.id]:{order:0,menuItemFactory:rt}}}},st=()=>{let e=k(o),t=k(W),n=A(t.activePopup$),r=k(C);if(A(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${h.chatAtABC(a)}${i+1}`;return R(oe,{onClick:()=>{t.persistPopup()},location:se.CELL,id:u,unitId:s,subUnitId:c,type:g.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(g.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},ct=()=>{var e;let t=k(j),n=k(o),r=k(W),a=n.getCurrentUnitForType(g.UNIVER_SHEET),s=a.getUnitId(),c=k(i),l=Ge(()=>a.activeSheet$.pipe(ke(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=A(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=Ke(null),f=k(T),p=A(f.activeCommentId$),m=A(f.panelVisible$,f.panelVisible),h=z(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=F(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=z(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=F(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),te=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},_=()=>{c.executeCommand(G.id)},v=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},y=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return We(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),R(ae,{unitId:s,subUnitId$:l,type:g.UNIVER_SHEET,onAdd:_,getSubUnitName:te,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:h,onItemEnter:v,onItemLeave:y,onDeleteComment:()=>(y(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(at)}_initMenu(){this._menuManagerService.mergeMenu(ot)}_initComponent(){[[qe,st],[Je,ct],[`CommentIcon`,Ue]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=U([H(0,pe),H(1,s(ue)),H(2,me)],Q);let $=class extends d{constructor(e=tt,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=ee({},tt,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(et,a)}onStarting(){[[Q],[q],[J],[Y],[Z],[W],[X]].forEach(e=>{this._injector.add(e)}),[G,K].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(q)}onRendered(){this._injector.get(J),this._injector.get(Y),this._injector.get(Z),this._injector.get(X)}};V($,`pluginName`,Ye),V($,`packageName`,Qe),V($,`version`,$e),V($,`type`,g.UNIVER_SHEET),$=U([t(le,ie),H(1,s(c)),H(2,s(i)),H(3,a)],$);export{je as AddCommentCommand,Ne as DeleteCommentCommand,Fe as DeleteCommentTreeCommand,Le as IThreadCommentDataSourceService,ze as ResolveCommentCommand,W as SheetsThreadCommentPopupService,G as ShowAddSheetCommentModalOperation,K as ToggleSheetCommentPanelOperation,$ as UniverSheetsThreadCommentUIPlugin,ce as UniverThreadCommentUIPlugin,Ve as UpdateCommentCommand};
|
|
1
|
+
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,Plugin as d,RANGE_TYPE as f,Range as p,Rectangle as m,Tools as h,UniverInstanceType as g,merge as ee}from"@univerjs/core";import{INTERCEPTOR_POINT as te,RangeProtectionPermissionViewPoint as _,SetWorksheetActiveOperation as v,SheetInterceptorService as y,SheetPermissionCheckController as b,SheetsSelectionsService as ne,WorkbookCommentPermission as x,WorksheetViewPermission as S,getSheetCommandTarget as re}from"@univerjs/sheets";import{SheetsThreadCommentModel as C,UniverSheetsThreadCommentPlugin as ie}from"@univerjs/sheets-thread-comment";import{SetActiveCommentOperation as w,ThreadCommentPanel as ae,ThreadCommentPanelService as T,ThreadCommentTree as oe,ThreadCommentTreeLocation as se,UniverThreadCommentUIPlugin as ce,UniverThreadCommentUIPlugin as le}from"@univerjs/thread-comment-ui";import{ComponentManager as ue,ContextMenuGroup as de,ContextMenuPosition as fe,IMenuManagerService as pe,IShortcutService as me,ISidebarService as he,IZenZoneService as ge,KeyCode as _e,MenuItemType as E,MetaKeys as D,RibbonInsertGroup as ve,getMenuHiddenObservable as O,useDependency as k,useObservable as A}from"@univerjs/ui";import{COPY_TYPE as ye,CellPopupManagerService as be,HoverManagerService as xe,IEditorBridgeService as Se,IMarkSelectionService as j,ISheetClipboardService as Ce,ScrollToRangeOperation as we,SheetCanvasPopManagerService as Te,SheetSkeletonManagerService as Ee,getCurrentRangeDisable$ as M,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{BehaviorSubject as Oe,debounceTime as N,map as ke}from"rxjs";import{IRenderManagerService as P}from"@univerjs/engine-render";import{serializeRange as Ae,singleReferenceToGrid as F}from"@univerjs/engine-formula";import{AddCommentCommand as je,AddCommentCommand as Me,AddCommentMutation as I,DeleteCommentCommand as Ne,DeleteCommentCommand as Pe,DeleteCommentMutation as L,DeleteCommentTreeCommand as Fe,DeleteCommentTreeCommand as Ie,IThreadCommentDataSourceService as Le,IThreadCommentDataSourceService as Re,ResolveCommentCommand as ze,ResolveCommentCommand as Be,UpdateCommentCommand as Ve,UpdateCommentCommand as He}from"@univerjs/thread-comment";import{CommentIcon as Ue}from"@univerjs/icons";import{jsx as R}from"react/jsx-runtime";import{useCallback as z,useEffect as We,useMemo as Ge,useRef as Ke}from"react";const qe=`univer.sheet.thread-comment-modal`,Je=`univer.sheet.thread-comment-panel`,Ye=`SHEET_THREAD_COMMENT_UI_PLUGIN`;function B(e){"@babel/helpers - typeof";return B=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},B(e)}function Xe(e,t){if(B(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ze(e){var t=Xe(e,`string`);return B(t)==`symbol`?t:t+``}function V(e,t,n){return(t=Ze(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t,n){super(),this._canvasPopupManagerService=e,this._zenZoneService=t,this._cellPopupManagerService=n,V(this,`_lastPopup`,null),V(this,`_activePopup`,void 0),V(this,`_activePopup$`,new Oe(null)),V(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey:qe,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,excludeOutside:[...Array.from(document.querySelectorAll(`.univer-thread-comment`)),document.getElementById(`thread-comment-add`)].filter(Boolean),priority:2});if(!c)throw Error(`[SheetsThreadCommentPopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=U([H(0,s(Te)),H(1,ge),H(2,s(be))],W);const G={type:e.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var t;let n=e.get(ne),r=e.get(o),i=e.get(W),a=e.get(T),s=(t=n.getCurrentLastSelection())==null?void 0:t.primary,c=e.get(C);if(!s)return!1;let l=re(r);if(!l)return!1;let{workbook:u,worksheet:d,unitId:f,subUnitId:p}=l,m={workbook:u,worksheet:d,unitId:f,subUnitId:p,row:s.startRow,col:s.startColumn};i.showPopup(m);let h=c.getByLocation(f,p,s.startRow,s.startColumn);return h&&a.setActiveComment({unitId:f,subUnitId:p,commentId:h,trigger:`context-menu`}),!0}},K={id:`sheet.operation.toggle-comment-panel`,type:e.OPERATION,handler(e){let t=e.get(he),n=e.get(T);return n.panelVisible?(t.close(),n.setPanelVisible(!1)):(t.open({header:{title:`threadCommentUI.panel.title`},children:{label:Je},width:360}),n.setPanelVisible(!0)),!0}};var Qe=`@univerjs/sheets-thread-comment-ui`,$e=`0.20.0`;const et=`sheets-thread-comment.config`;Symbol(et);const tt={};let q=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(te.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsThreadCommentModel.showCommentMarker(a,o,r,i)?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(N(16)).subscribe(()=>{e()}))}};q=U([H(0,s(y)),H(1,s(C)),H(2,o),H(3,P)],q);const nt=(e,t,n)=>{let r=F(e),i=n.row-t.row,a=n.column-t.column;return Ae({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})};let J=class extends n{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._threadCommentDataSourceService=n,V(this,`_copyInfo`,void 0),this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Ye,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,r)=>{let{unitId:i,subUnitId:a,range:o}=t,s={row:o.rows[0],column:o.cols[0]};if(r.copyType===ye.CUT&&this._copyInfo){let{range:e,unitId:t,subUnitId:n}=this._copyInfo,r={row:e.startRow,column:e.startColumn};if(!(i===t&&a===n)){let o=[];p.foreach(e,(e,r)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(t,n,e,r);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],l=[],u=[],d=[],f=e=>{c.unshift({id:L.id,params:{unitId:t,subUnitId:n,commentId:e.id}}),u.push({id:I.id,params:{unitId:i,subUnitId:a,comment:{...e,ref:nt(e.ref,r,s),unitId:i,subUnitId:a},sync:!0}}),l.push({id:I.id,params:{unitId:t,subUnitId:n,comment:e,sync:!0}}),d.unshift({id:L.id,params:{unitId:i,subUnitId:a,commentId:e.id}})};return o.forEach(e=>{f(e)}),{redos:[...c,...u],undos:[...d,...l]}}}return{redos:[],undos:[]}}}))}};J=U([H(0,s(Ce)),H(1,s(C)),H(2,Re)],J);let Y=class extends n{constructor(e,t,n,r){super(),this._hoverManagerService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=r,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){let{location:n}=e,{unitId:r,subUnitId:i,row:a,col:o}=n,s=this._sheetsThreadCommentModel.getByLocation(r,i,a,o);if(s){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],r,i))return;let e=this._sheetsThreadCommentModel.getComment(r,i,s);e&&!e.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:a,col:o,commentId:s,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Y=U([H(0,s(xe)),H(1,s(W)),H(2,s(C)),H(3,s(b))],Y);let X=class extends n{constructor(e,t,n,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._sheetsThreadCommentModel=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(t===G.id||t===K.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[x],worksheetTypes:[S]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===Me.id){let{unitId:t,subUnitId:n,comment:r}=e.params,{row:i,column:a}=F(r.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:i,startColumn:a,endRow:i,endColumn:a}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===He.id){let{unitId:t,subUnitId:n,payload:r}=e.params,{commentId:i}=r,a=this._sheetsThreadCommentModel.getComment(t,n,i);if(a){let{row:e,column:r}=F(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===Be.id||t===Pe.id||t===Ie.id){let{unitId:t,subUnitId:n,commentId:r}=e.params,i=this._sheetsThreadCommentModel.getComment(t,n,r);if(i){let{row:e,column:r}=F(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:e,startColumn:r,endRow:e,endColumn:r}],t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};X=U([H(0,s(u)),H(1,i),H(2,s(b)),H(3,s(C))],X);let Z=class extends n{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._threadCommentPanelService=r,this._univerInstanceService=i,this._sheetPermissionCheckController=a,this._markSelectionService=o,this._sheetSelectionService=s,this._editorBridgeService=c,this._renderManagerService=l,V(this,`_isSwitchToCommenting`,!1),V(this,`_selectionShapeInfo`,null),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(Ee).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?f.NORMAL:a)!==f.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let u=l.actualRow,d=l.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,u,d)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(w.id);return}let p=this._sheetsThreadCommentModel.getByLocation(t,n,u,d);p&&this._commandService.executeCommand(w.id,{unitId:t,subUnitId:n,commentId:p})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchToCommenting)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let t=e.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;let{unitId:r,subUnitId:i,commentId:a}=n;t.unitId===r&&t.subUnitId===i&&t.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async e=>{if(e){var t;let{unitId:n,subUnitId:r,commentId:i,trigger:a}=e,o=this._sheetsThreadCommentModel.getComment(n,r,i);if(!o||o.resolved)return;let s=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET);if(!s||s.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((t=s.getActiveSheet())==null?void 0:t.getSheetId())!==r&&await this._commandService.executeCommand(v.id,{unitId:n,subUnitId:r}),this._isSwitchToCommenting=!1;let c=F(o.ref),{row:l,column:u}=c;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]},[{startRow:l,startColumn:u,endRow:l,endColumn:u}],n,r)||(await this._commandService.executeCommand(we.id,{range:{startRow:Math.max(c.row-1,0),endRow:c.row+1,startColumn:Math.max(c.column-1,0),endColumn:c.column+1}}),this._editorBridgeService.isVisible().visible))return;this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:r,row:c.row,col:c.column,commentId:o.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(N(100)).subscribe(e=>{var t,n;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:r,subUnitId:i,commentId:a}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let o=this._sheetsThreadCommentModel.getComment(r,i,a);if(!o)return;let{row:s,column:c}=F(o.ref);if(Number.isNaN(s)||Number.isNaN(c))return null;let l=(t=this._univerInstanceService.getCurrentUnitForType(g.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(i),u=(n=l==null?void 0:l.getMergedCell(s,c))==null?{startColumn:c,endColumn:c,startRow:s,endRow:s}:n,d=this._markSelectionService.addShape({range:u,style:{fill:`rgba(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1);d&&(this._selectionShapeInfo={...e,shapeId:d})}))}};Z=U([H(0,i),H(1,s(W)),H(2,s(C)),H(3,s(T)),H(4,o),H(5,s(b)),H(6,j),H(7,s(ne)),H(8,Se),H(9,P)],Z);const rt=e=>({id:G.id,type:E.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:O(e,g.UNIVER_SHEET),disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]})}),it=e=>({id:K.id,type:E.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:M(e,{workbookTypes:[x],worksheetTypes:[S],rangeTypes:[_]}),hidden$:O(e,g.UNIVER_SHEET)}),at={id:G.id,binding:_e.M|D.CTRL_COMMAND|D.ALT,preconditions:De},ot={[ve.MEDIA]:{[K.id]:{order:2,menuItemFactory:it}},[fe.MAIN_AREA]:{[de.OTHERS]:{[G.id]:{order:0,menuItemFactory:rt}}}},st=()=>{let e=k(o),t=k(W),n=A(t.activePopup$),r=k(C);if(A(r.commentUpdate$),!n)return null;let{row:i,col:a,unitId:s,subUnitId:c,trigger:l}=n,u=r.getByLocation(s,c,i,a),d=`${h.chatAtABC(a)}${i+1}`;return R(oe,{onClick:()=>{t.persistPopup()},location:se.CELL,id:u,unitId:s,subUnitId:c,type:g.UNIVER_SHEET,refStr:d,onClose:()=>{t.hidePopup()},getSubUnitName:t=>{var n,r;return(n=(r=e.getCurrentUnitForType(g.UNIVER_SHEET))==null||(r=r.getSheetBySheetId(t))==null?void 0:r.getName())==null?``:n},autoFocus:l===`context-menu`})},ct=()=>{var e;let t=k(j),n=k(o),r=k(W),a=n.getCurrentUnitForType(g.UNIVER_SHEET),s=a.getUnitId(),c=k(i),l=Ge(()=>a.activeSheet$.pipe(ke(e=>e==null?void 0:e.getSheetId())),[a.activeSheet$]),u=A(l,(e=a.getActiveSheet())==null?void 0:e.getSheetId()),d=Ke(null),f=k(T),p=A(f.activeCommentId$),m=A(f.panelVisible$,f.panelVisible),h=z(e=>{let t=a.getSheets(),n={};t.forEach((e,t)=>{n[e.getSheetId()]=t});let r=e=>e.map(e=>{var t;let r=F(e.ref),i=[(t=n[e.subUnitId])==null?0:t,r.row,r.column];return{...e,p:i}}).sort((e,t)=>e.p[0]===t.p[0]?e.p[1]===t.p[1]?e.p[2]-t.p[2]:e.p[1]-t.p[1]:e.p[0]-t.p[0]);return[...r(e.filter(e=>!e.resolved)),...r(e.filter(e=>e.resolved))]},[a]),ee=z(e=>{if(e.unitId===s&&e.subUnitId===u&&!e.resolved){var n;let{row:r,column:i}=F(e.ref),o=a.getSheetBySheetId(e.subUnitId),s=(n=o==null?void 0:o.getMergedCell(r,i))==null?{startColumn:i,endColumn:i,startRow:r,endRow:r}:n;if(!Number.isNaN(r)&&!Number.isNaN(i))return t.addShape({range:s,style:{fill:`rgb(255, 189, 55, 0.35)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null})}return null},[t,u,s]),te=e=>{var t,n;return(t=(n=a.getSheetBySheetId(e))==null?void 0:n.getName())==null?``:t},_=()=>{c.executeCommand(G.id)},v=e=>{p&&p.unitId===e.unitId&&p.subUnitId===e.subUnitId&&p.commentId===e.id||(d.current&&(t.removeShape(d.current),d.current=null),d.current=ee(e))},y=()=>{d.current&&(t.removeShape(d.current),d.current=null)};return We(()=>{!m&&d.current&&t.removeShape(d.current)},[t,m]),R(ae,{unitId:s,subUnitId$:l,type:g.UNIVER_SHEET,onAdd:_,getSubUnitName:te,onResolve:(e,t)=>{t&&r.hidePopup()},sortComments:h,onItemEnter:v,onItemLeave:y,onDeleteComment:()=>(y(),!0)})};let Q=class extends n{constructor(e,t,n){super(),this._menuManagerService=e,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(at)}_initMenu(){this._menuManagerService.mergeMenu(ot)}_initComponent(){[[qe,st],[Je,ct],[`CommentIcon`,Ue]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=U([H(0,pe),H(1,s(ue)),H(2,me)],Q);let $=class extends d{constructor(e=tt,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=ee({},tt,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(et,a)}onStarting(){[[Q],[q],[J],[Y],[Z],[W],[X]].forEach(e=>{this._injector.add(e)}),[G,K].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(Q)}onReady(){this._injector.get(q)}onRendered(){this._injector.get(J),this._injector.get(Y),this._injector.get(Z),this._injector.get(X)}};V($,`pluginName`,Ye),V($,`packageName`,Qe),V($,`version`,$e),V($,`type`,g.UNIVER_SHEET),$=U([t(le,ie),H(1,s(c)),H(2,s(i)),H(3,a)],$);export{je as AddCommentCommand,Ne as DeleteCommentCommand,Fe as DeleteCommentTreeCommand,Le as IThreadCommentDataSourceService,ze as ResolveCommentCommand,W as SheetsThreadCommentPopupService,G as ShowAddSheetCommentModalOperation,K as ToggleSheetCommentPanelOperation,$ as UniverSheetsThreadCommentUIPlugin,ce as UniverThreadCommentUIPlugin,Ve as UpdateCommentCommand};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/sheets-thread-comment`),require(`@univerjs/thread-comment-ui`),require(`@univerjs/ui`),require(`@univerjs/sheets-ui`),require(`rxjs`),require(`@univerjs/engine-render`),require(`@univerjs/engine-formula`),require(`@univerjs/thread-comment`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/sheets-thread-comment`,`@univerjs/thread-comment-ui`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/engine-render`,`@univerjs/engine-formula`,`@univerjs/thread-comment`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentUi={},e.UniverCore,e.UniverSheets,e.UniverSheetsThreadComment,e.UniverThreadCommentUi,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverEngineRender,e.UniverEngineFormula,e.UniverThreadComment,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let 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 t.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 s.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(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey: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 t.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,t.Inject)(o.SheetCanvasPopManagerService)),b(1,a.IZenZoneService),b(2,(0,t.Inject)(o.CellPopupManagerService))],S);let C={type:t.CommandType.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var a;let o=e.get(n.SheetsSelectionsService),s=e.get(t.IUniverInstanceService),c=e.get(S),l=e.get(i.ThreadCommentPanelService),u=(a=o.getCurrentLastSelection())==null?void 0:a.primary,d=e.get(r.SheetsThreadCommentModel);if(!u)return!1;let f=(0,n.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:t.CommandType.OPERATION,handler(e){let t=e.get(a.ISidebarService),n=e.get(i.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.19.0`;let D=`sheets-thread-comment.config`;Symbol(D);let O={},k=class extends t.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(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.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 e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe((0,s.debounceTime)(16)).subscribe(()=>{e()}))}};k=x([b(0,(0,t.Inject)(n.SheetInterceptorService)),b(1,(0,t.Inject)(r.SheetsThreadCommentModel)),b(2,t.IUniverInstanceService),b(3,c.IRenderManagerService)],k);let A=(e,t,n)=>{let r=(0,l.singleReferenceToGrid)(e),i=n.row-t.row,a=n.column-t.column;return(0,l.serializeRange)({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})},j=class extends t.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:(e,n,r,i)=>{let{unitId:a,subUnitId:s,range:c}=n,l={row:c.rows[0],column:c.cols[0]};if(i.copyType===o.COPY_TYPE.CUT&&this._copyInfo){let{range:e,unitId:n,subUnitId:r}=this._copyInfo,i={row:e.startRow,column:e.startColumn};if(!(a===n&&s===r)){let o=[];t.Range.foreach(e,(e,t)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(n,r,e,t);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],d=[],f=[],p=[],m=e=>{c.unshift({id:u.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:e.id}}),f.push({id:u.AddCommentMutation.id,params:{unitId:a,subUnitId:s,comment:{...e,ref:A(e.ref,i,l),unitId:a,subUnitId:s},sync:!0}}),d.push({id:u.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:e,sync:!0}}),p.unshift({id:u.DeleteCommentMutation.id,params:{unitId:a,subUnitId:s,commentId:e.id}})};return o.forEach(e=>{m(e)}),{redos:[...c,...f],undos:[...p,...d]}}}return{redos:[],undos:[]}}}))}};j=x([b(0,(0,t.Inject)(o.ISheetClipboardService)),b(1,(0,t.Inject)(r.SheetsThreadCommentModel)),b(2,u.IThreadCommentDataSourceService)],j);let M=class extends t.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,s.debounceTime)(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){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:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.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 t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};M=x([b(0,(0,t.Inject)(o.HoverManagerService)),b(1,(0,t.Inject)(S)),b(2,(0,t.Inject)(r.SheetsThreadCommentModel)),b(3,(0,t.Inject)(n.SheetPermissionCheckController))],M);let N=class extends t.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:t}=e;if(t===C.id||t===w.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===u.AddCommentCommand.id){let{unitId:t,subUnitId:r,comment:i}=e.params,{row:a,column:o}=(0,l.singleReferenceToGrid)(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===u.UpdateCommentCommand.id){let{unitId:t,subUnitId:r,payload:i}=e.params,{commentId:a}=i,o=this._sheetsThreadCommentModel.getComment(t,r,a);if(o){let{row:e,column:i}=(0,l.singleReferenceToGrid)(o.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:i,endRow:e,endColumn:i}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===u.ResolveCommentCommand.id||t===u.DeleteCommentCommand.id||t===u.DeleteCommentTreeCommand.id){let{unitId:t,subUnitId:r,commentId:i}=e.params,a=this._sheetsThreadCommentModel.getComment(t,r,i);if(a){let{row:e,column:i}=(0,l.singleReferenceToGrid)(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:i,endRow:e,endColumn:i}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};N=x([b(0,(0,t.Inject)(t.LocaleService)),b(1,t.ICommandService),b(2,(0,t.Inject)(n.SheetPermissionCheckController)),b(3,(0,t.Inject)(r.SheetsThreadCommentModel))],N);let P=class extends t.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(e,n,r){var a,s,c;let l=(a=e[0])==null?void 0:a.range,u=this._renderManagerService.getRenderById(n),d=u==null||(s=u.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:s.skeleton;if(!d||!l)return;let f=d.getCellWithCoordByIndex(l.startRow,l.startColumn);if((((c=l.rangeType)==null?t.RANGE_TYPE.NORMAL:c)!==t.RANGE_TYPE.NORMAL||l.endColumn-l.startColumn>0||l.endRow-l.startRow>0)&&!((f.isMerged||f.isMergedMainCell)&&t.Rectangle.equals(f.mergeInfo,l))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(i.SetActiveCommentOperation.id);return}let p=f.actualRow,m=f.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,r,p,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(i.SetActiveCommentOperation.id);return}let h=this._sheetsThreadCommentModel.getByLocation(n,r,p,m);h&&this._commandService.executeCommand(i.SetActiveCommentOperation.id,{unitId:n,subUnitId:r,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===u.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 e=>{if(e){var r;let{unitId:i,subUnitId:a,commentId:s,trigger:c}=e,u=this._sheetsThreadCommentModel.getComment(i,a,s);if(!u||u.resolved)return;let d=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!d||d.getUnitId()!==i)return;this._isSwitchToCommenting=!0,((r=d.getActiveSheet())==null?void 0:r.getSheetId())!==a&&await this._commandService.executeCommand(n.SetWorksheetActiveOperation.id,{unitId:i,subUnitId:a}),this._isSwitchToCommenting=!1;let f=(0,l.singleReferenceToGrid)(u.ref),{row:p,column:m}=f;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:p,startColumn:m,endRow:p,endColumn:m}],i,a)||(await this._commandService.executeCommand(o.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:a,row:f.row,col:f.column,commentId:u.id,trigger:c})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var n,r;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:i,subUnitId:a,commentId:o}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let s=this._sheetsThreadCommentModel.getComment(i,a,o);if(!s)return;let{row:c,column:u}=(0,l.singleReferenceToGrid)(s.ref);if(Number.isNaN(c)||Number.isNaN(u))return null;let d=(n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(a),f=(r=d==null?void 0:d.getMergedCell(c,u))==null?{startColumn:u,endColumn:u,startRow:c,endRow:c}: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={...e,shapeId:p})}))}};P=x([b(0,t.ICommandService),b(1,(0,t.Inject)(S)),b(2,(0,t.Inject)(r.SheetsThreadCommentModel)),b(3,(0,t.Inject)(i.ThreadCommentPanelService)),b(4,t.IUniverInstanceService),b(5,(0,t.Inject)(n.SheetPermissionCheckController)),b(6,o.IMarkSelectionService),b(7,(0,t.Inject)(n.SheetsSelectionsService)),b(8,o.IEditorBridgeService),b(9,c.IRenderManagerService)],P);function F({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,d.useRef)(`_${z()}`);return I(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function I(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...L(e,n,i),...r},(R(e,n).children||[]).map((r,a)=>I(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function L(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function R(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function z(){return Math.random().toString(36).substring(2,8)}F.displayName=`UniverIcon`;let B={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},V=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(F,Object.assign({},e,{id:`comment-icon`,ref:t,icon:B}))});V.displayName=`CommentIcon`;let H=e=>({id:C.id,type:a.MenuItemType.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]})}),U=e=>({id:w.id,type:a.MenuItemType.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]}),hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}),W={id:C.id,binding:a.KeyCode.M|a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT,preconditions:o.whenSheetEditorFocused},G={[a.RibbonInsertGroup.MEDIA]:{[w.id]:{order:2,menuItemFactory:U}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.OTHERS]:{[C.id]:{order:0,menuItemFactory:H}}}},K=()=>{let e=(0,a.useDependency)(t.IUniverInstanceService),n=(0,a.useDependency)(S),o=(0,a.useObservable)(n.activePopup$),s=(0,a.useDependency)(r.SheetsThreadCommentModel);if((0,a.useObservable)(s.commentUpdate$),!o)return null;let{row:c,col:l,unitId:u,subUnitId:d,trigger:p}=o,m=s.getByLocation(u,d,c,l),h=`${t.Tools.chatAtABC(l)}${c+1}`;return(0,f.jsx)(i.ThreadCommentTree,{onClick:()=>{n.persistPopup()},location:i.ThreadCommentTreeLocation.CELL,id:m,unitId:u,subUnitId:d,type:t.UniverInstanceType.UNIVER_SHEET,refStr:h,onClose:()=>{n.hidePopup()},getSubUnitName:n=>{var r,i;return(r=(i=e.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null||(i=i.getSheetBySheetId(n))==null?void 0:i.getName())==null?``:r},autoFocus:p===`context-menu`})},q=()=>{var e;let n=(0,a.useDependency)(o.IMarkSelectionService),r=(0,a.useDependency)(t.IUniverInstanceService),c=(0,a.useDependency)(S),u=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),p=u.getUnitId(),m=(0,a.useDependency)(t.ICommandService),h=(0,d.useMemo)(()=>u.activeSheet$.pipe((0,s.map)(e=>e==null?void 0:e.getSheetId())),[u.activeSheet$]),g=(0,a.useObservable)(h,(e=u.getActiveSheet())==null?void 0:e.getSheetId()),_=(0,d.useRef)(null),v=(0,a.useDependency)(i.ThreadCommentPanelService),y=(0,a.useObservable)(v.activeCommentId$),b=(0,a.useObservable)(v.panelVisible$,v.panelVisible),x=(0,d.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,l.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,d.useCallback)(e=>{if(e.unitId===p&&e.subUnitId===g&&!e.resolved){var t;let{row:r,column:i}=(0,l.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,d.useEffect)(()=>{!b&&_.current&&n.removeShape(_.current)},[n,b]),(0,f.jsx)(i.ThreadCommentPanel,{unitId:p,subUnitId$:h,type:t.UniverInstanceType.UNIVER_SHEET,onAdd:E,getSubUnitName:T,onResolve:(e,t)=>{t&&c.hidePopup()},sortComments:x,onItemEnter:D,onItemLeave:O,onDeleteComment:()=>(O(),!0)})},J=class extends t.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(W)}_initMenu(){this._menuManagerService.mergeMenu(G)}_initComponent(){[[p,K],[m,q],[`CommentIcon`,V]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};J=x([b(0,a.IMenuManagerService),b(1,(0,t.Inject)(a.ComponentManager)),b(2,a.IShortcutService)],J);let Y=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},O,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(D,o)}onStarting(){[[J],[k],[j],[M],[P],[S],[N]].forEach(e=>{this._injector.add(e)}),[C,w].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(J)}onReady(){this._injector.get(k)}onRendered(){this._injector.get(j),this._injector.get(M),this._injector.get(P),this._injector.get(N)}};y(Y,`pluginName`,h),y(Y,`packageName`,T),y(Y,`version`,E),y(Y,`type`,t.UniverInstanceType.UNIVER_SHEET),Y=x([(0,t.DependentOn)(i.UniverThreadCommentUIPlugin,r.UniverSheetsThreadCommentPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,(0,t.Inject)(t.ICommandService)),b(3,t.IConfigService)],Y),Object.defineProperty(e,`AddCommentCommand`,{enumerable:!0,get:function(){return u.AddCommentCommand}}),Object.defineProperty(e,`DeleteCommentCommand`,{enumerable:!0,get:function(){return u.DeleteCommentCommand}}),Object.defineProperty(e,`DeleteCommentTreeCommand`,{enumerable:!0,get:function(){return u.DeleteCommentTreeCommand}}),Object.defineProperty(e,`IThreadCommentDataSourceService`,{enumerable:!0,get:function(){return u.IThreadCommentDataSourceService}}),Object.defineProperty(e,`ResolveCommentCommand`,{enumerable:!0,get:function(){return u.ResolveCommentCommand}}),Object.defineProperty(e,`SheetsThreadCommentPopupService`,{enumerable:!0,get:function(){return S}}),e.ShowAddSheetCommentModalOperation=C,e.ToggleSheetCommentPanelOperation=w,Object.defineProperty(e,`UniverSheetsThreadCommentUIPlugin`,{enumerable:!0,get:function(){return Y}}),Object.defineProperty(e,`UniverThreadCommentUIPlugin`,{enumerable:!0,get:function(){return i.UniverThreadCommentUIPlugin}}),Object.defineProperty(e,`UpdateCommentCommand`,{enumerable:!0,get:function(){return u.UpdateCommentCommand}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/sheets-thread-comment`),require(`@univerjs/thread-comment-ui`),require(`@univerjs/ui`),require(`@univerjs/sheets-ui`),require(`rxjs`),require(`@univerjs/engine-render`),require(`@univerjs/engine-formula`),require(`@univerjs/thread-comment`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/sheets-thread-comment`,`@univerjs/thread-comment-ui`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/engine-render`,`@univerjs/engine-formula`,`@univerjs/thread-comment`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentUi={},e.UniverCore,e.UniverSheets,e.UniverSheetsThreadComment,e.UniverThreadCommentUi,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverEngineRender,e.UniverEngineFormula,e.UniverThreadComment,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let 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 t.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 s.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(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({row:i,col:a,unitId:o,subUnitId:s},{componentKey: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 t.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,t.Inject)(o.SheetCanvasPopManagerService)),b(1,a.IZenZoneService),b(2,(0,t.Inject)(o.CellPopupManagerService))],S);let C={type:t.CommandType.OPERATION,id:`sheet.operation.show-comment-modal`,handler(e){var a;let o=e.get(n.SheetsSelectionsService),s=e.get(t.IUniverInstanceService),c=e.get(S),l=e.get(i.ThreadCommentPanelService),u=(a=o.getCurrentLastSelection())==null?void 0:a.primary,d=e.get(r.SheetsThreadCommentModel);if(!u)return!1;let f=(0,n.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:t.CommandType.OPERATION,handler(e){let t=e.get(a.ISidebarService),n=e.get(i.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.0`;let D=`sheets-thread-comment.config`;Symbol(D);let O={},k=class extends t.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(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.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 e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe((0,s.debounceTime)(16)).subscribe(()=>{e()}))}};k=x([b(0,(0,t.Inject)(n.SheetInterceptorService)),b(1,(0,t.Inject)(r.SheetsThreadCommentModel)),b(2,t.IUniverInstanceService),b(3,c.IRenderManagerService)],k);let A=(e,t,n)=>{let r=(0,l.singleReferenceToGrid)(e),i=n.row-t.row,a=n.column-t.column;return(0,l.serializeRange)({startColumn:r.column+a,startRow:r.row+i,endColumn:r.column+a,endRow:r.row+i})},j=class extends t.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:(e,n,r,i)=>{let{unitId:a,subUnitId:s,range:c}=n,l={row:c.rows[0],column:c.cols[0]};if(i.copyType===o.COPY_TYPE.CUT&&this._copyInfo){let{range:e,unitId:n,subUnitId:r}=this._copyInfo,i={row:e.startRow,column:e.startColumn};if(!(a===n&&s===r)){let o=[];t.Range.foreach(e,(e,t)=>{let i=this._sheetsThreadCommentModel.getAllByLocation(n,r,e,t);this._threadCommentDataSourceService.syncUpdateMutationToColla?i.forEach(e=>{o.push(e)}):i.forEach(({children:e,...t})=>{t.parentId||o.push(t)})});let c=[],d=[],f=[],p=[],m=e=>{c.unshift({id:u.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:e.id}}),f.push({id:u.AddCommentMutation.id,params:{unitId:a,subUnitId:s,comment:{...e,ref:A(e.ref,i,l),unitId:a,subUnitId:s},sync:!0}}),d.push({id:u.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:e,sync:!0}}),p.unshift({id:u.DeleteCommentMutation.id,params:{unitId:a,subUnitId:s,commentId:e.id}})};return o.forEach(e=>{m(e)}),{redos:[...c,...f],undos:[...p,...d]}}}return{redos:[],undos:[]}}}))}};j=x([b(0,(0,t.Inject)(o.ISheetClipboardService)),b(1,(0,t.Inject)(r.SheetsThreadCommentModel)),b(2,u.IThreadCommentDataSourceService)],j);let M=class extends t.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,s.debounceTime)(100)).subscribe(e=>{let t=this._sheetsThreadCommentPopupService.activePopup;if(e&&(t&&t.temp||!t)){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:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.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 t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};M=x([b(0,(0,t.Inject)(o.HoverManagerService)),b(1,(0,t.Inject)(S)),b(2,(0,t.Inject)(r.SheetsThreadCommentModel)),b(3,(0,t.Inject)(n.SheetPermissionCheckController))],M);let N=class extends t.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:t}=e;if(t===C.id||t===w.id)this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`));else if(t===u.AddCommentCommand.id){let{unitId:t,subUnitId:r,comment:i}=e.params,{row:a,column:o}=(0,l.singleReferenceToGrid)(i.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:a,startColumn:o,endRow:a,endColumn:o}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}else if(t===u.UpdateCommentCommand.id){let{unitId:t,subUnitId:r,payload:i}=e.params,{commentId:a}=i,o=this._sheetsThreadCommentModel.getComment(t,r,a);if(o){let{row:e,column:i}=(0,l.singleReferenceToGrid)(o.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:i,endRow:e,endColumn:i}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}else if(t===u.ResolveCommentCommand.id||t===u.DeleteCommentCommand.id||t===u.DeleteCommentTreeCommand.id){let{unitId:t,subUnitId:r,commentId:i}=e.params,a=this._sheetsThreadCommentModel.getComment(t,r,i);if(a){let{row:e,column:i}=(0,l.singleReferenceToGrid)(a.ref);this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:e,startColumn:i,endRow:e,endColumn:i}],t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.commentErr`))}}}))}};N=x([b(0,(0,t.Inject)(t.LocaleService)),b(1,t.ICommandService),b(2,(0,t.Inject)(n.SheetPermissionCheckController)),b(3,(0,t.Inject)(r.SheetsThreadCommentModel))],N);let P=class extends t.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(e,n,r){var a,s,c;let l=(a=e[0])==null?void 0:a.range,u=this._renderManagerService.getRenderById(n),d=u==null||(s=u.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:s.skeleton;if(!d||!l)return;let f=d.getCellWithCoordByIndex(l.startRow,l.startColumn);if((((c=l.rangeType)==null?t.RANGE_TYPE.NORMAL:c)!==t.RANGE_TYPE.NORMAL||l.endColumn-l.startColumn>0||l.endRow-l.startRow>0)&&!((f.isMerged||f.isMergedMainCell)&&t.Rectangle.equals(f.mergeInfo,l))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(i.SetActiveCommentOperation.id);return}let p=f.actualRow,m=f.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,r,p,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(i.SetActiveCommentOperation.id);return}let h=this._sheetsThreadCommentModel.getByLocation(n,r,p,m);h&&this._commandService.executeCommand(i.SetActiveCommentOperation.id,{unitId:n,subUnitId:r,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===u.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 e=>{if(e){var r;let{unitId:i,subUnitId:a,commentId:s,trigger:c}=e,u=this._sheetsThreadCommentModel.getComment(i,a,s);if(!u||u.resolved)return;let d=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!d||d.getUnitId()!==i)return;this._isSwitchToCommenting=!0,((r=d.getActiveSheet())==null?void 0:r.getSheetId())!==a&&await this._commandService.executeCommand(n.SetWorksheetActiveOperation.id,{unitId:i,subUnitId:a}),this._isSwitchToCommenting=!1;let f=(0,l.singleReferenceToGrid)(u.ref),{row:p,column:m}=f;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]},[{startRow:p,startColumn:m,endRow:p,endColumn:m}],i,a)||(await this._commandService.executeCommand(o.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:a,row:f.row,col:f.column,commentId:u.id,trigger:c})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var n,r;if(!e){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}let{unitId:i,subUnitId:a,commentId:o}=e;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);let s=this._sheetsThreadCommentModel.getComment(i,a,o);if(!s)return;let{row:c,column:u}=(0,l.singleReferenceToGrid)(s.ref);if(Number.isNaN(c)||Number.isNaN(u))return null;let d=(n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(a),f=(r=d==null?void 0:d.getMergedCell(c,u))==null?{startColumn:u,endColumn:u,startRow:c,endRow:c}: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={...e,shapeId:p})}))}};P=x([b(0,t.ICommandService),b(1,(0,t.Inject)(S)),b(2,(0,t.Inject)(r.SheetsThreadCommentModel)),b(3,(0,t.Inject)(i.ThreadCommentPanelService)),b(4,t.IUniverInstanceService),b(5,(0,t.Inject)(n.SheetPermissionCheckController)),b(6,o.IMarkSelectionService),b(7,(0,t.Inject)(n.SheetsSelectionsService)),b(8,o.IEditorBridgeService),b(9,c.IRenderManagerService)],P);function F({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,d.useRef)(`_${z()}`);return I(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function I(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...L(e,n,i),...r},(R(e,n).children||[]).map((r,a)=>I(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function L(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function R(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function z(){return Math.random().toString(36).substring(2,8)}F.displayName=`UniverIcon`;let B={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},V=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(F,Object.assign({},e,{id:`comment-icon`,ref:t,icon:B}))});V.displayName=`CommentIcon`;let H=e=>({id:C.id,type:a.MenuItemType.BUTTON,icon:`CommentIcon`,title:`sheetThreadComment.menu.addComment`,hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]})}),U=e=>({id:w.id,type:a.MenuItemType.BUTTON,icon:`CommentIcon`,tooltip:`sheetThreadComment.menu.commentManagement`,disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookCommentPermission],worksheetTypes:[n.WorksheetViewPermission],rangeTypes:[n.RangeProtectionPermissionViewPoint]}),hidden$:(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}),W={id:C.id,binding:a.KeyCode.M|a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT,preconditions:o.whenSheetEditorFocused},G={[a.RibbonInsertGroup.MEDIA]:{[w.id]:{order:2,menuItemFactory:U}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.OTHERS]:{[C.id]:{order:0,menuItemFactory:H}}}},K=()=>{let e=(0,a.useDependency)(t.IUniverInstanceService),n=(0,a.useDependency)(S),o=(0,a.useObservable)(n.activePopup$),s=(0,a.useDependency)(r.SheetsThreadCommentModel);if((0,a.useObservable)(s.commentUpdate$),!o)return null;let{row:c,col:l,unitId:u,subUnitId:d,trigger:p}=o,m=s.getByLocation(u,d,c,l),h=`${t.Tools.chatAtABC(l)}${c+1}`;return(0,f.jsx)(i.ThreadCommentTree,{onClick:()=>{n.persistPopup()},location:i.ThreadCommentTreeLocation.CELL,id:m,unitId:u,subUnitId:d,type:t.UniverInstanceType.UNIVER_SHEET,refStr:h,onClose:()=>{n.hidePopup()},getSubUnitName:n=>{var r,i;return(r=(i=e.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null||(i=i.getSheetBySheetId(n))==null?void 0:i.getName())==null?``:r},autoFocus:p===`context-menu`})},q=()=>{var e;let n=(0,a.useDependency)(o.IMarkSelectionService),r=(0,a.useDependency)(t.IUniverInstanceService),c=(0,a.useDependency)(S),u=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),p=u.getUnitId(),m=(0,a.useDependency)(t.ICommandService),h=(0,d.useMemo)(()=>u.activeSheet$.pipe((0,s.map)(e=>e==null?void 0:e.getSheetId())),[u.activeSheet$]),g=(0,a.useObservable)(h,(e=u.getActiveSheet())==null?void 0:e.getSheetId()),_=(0,d.useRef)(null),v=(0,a.useDependency)(i.ThreadCommentPanelService),y=(0,a.useObservable)(v.activeCommentId$),b=(0,a.useObservable)(v.panelVisible$,v.panelVisible),x=(0,d.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,l.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,d.useCallback)(e=>{if(e.unitId===p&&e.subUnitId===g&&!e.resolved){var t;let{row:r,column:i}=(0,l.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,d.useEffect)(()=>{!b&&_.current&&n.removeShape(_.current)},[n,b]),(0,f.jsx)(i.ThreadCommentPanel,{unitId:p,subUnitId$:h,type:t.UniverInstanceType.UNIVER_SHEET,onAdd:E,getSubUnitName:T,onResolve:(e,t)=>{t&&c.hidePopup()},sortComments:x,onItemEnter:D,onItemLeave:O,onDeleteComment:()=>(O(),!0)})},J=class extends t.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(W)}_initMenu(){this._menuManagerService.mergeMenu(G)}_initComponent(){[[p,K],[m,q],[`CommentIcon`,V]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};J=x([b(0,a.IMenuManagerService),b(1,(0,t.Inject)(a.ComponentManager)),b(2,a.IShortcutService)],J);let Y=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},O,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(D,o)}onStarting(){[[J],[k],[j],[M],[P],[S],[N]].forEach(e=>{this._injector.add(e)}),[C,w].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(J)}onReady(){this._injector.get(k)}onRendered(){this._injector.get(j),this._injector.get(M),this._injector.get(P),this._injector.get(N)}};y(Y,`pluginName`,h),y(Y,`packageName`,T),y(Y,`version`,E),y(Y,`type`,t.UniverInstanceType.UNIVER_SHEET),Y=x([(0,t.DependentOn)(i.UniverThreadCommentUIPlugin,r.UniverSheetsThreadCommentPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,(0,t.Inject)(t.ICommandService)),b(3,t.IConfigService)],Y),Object.defineProperty(e,`AddCommentCommand`,{enumerable:!0,get:function(){return u.AddCommentCommand}}),Object.defineProperty(e,`DeleteCommentCommand`,{enumerable:!0,get:function(){return u.DeleteCommentCommand}}),Object.defineProperty(e,`DeleteCommentTreeCommand`,{enumerable:!0,get:function(){return u.DeleteCommentTreeCommand}}),Object.defineProperty(e,`IThreadCommentDataSourceService`,{enumerable:!0,get:function(){return u.IThreadCommentDataSourceService}}),Object.defineProperty(e,`ResolveCommentCommand`,{enumerable:!0,get:function(){return u.ResolveCommentCommand}}),Object.defineProperty(e,`SheetsThreadCommentPopupService`,{enumerable:!0,get:function(){return S}}),e.ShowAddSheetCommentModalOperation=C,e.ToggleSheetCommentPanelOperation=w,Object.defineProperty(e,`UniverSheetsThreadCommentUIPlugin`,{enumerable:!0,get:function(){return Y}}),Object.defineProperty(e,`UniverThreadCommentUIPlugin`,{enumerable:!0,get:function(){return i.UniverThreadCommentUIPlugin}}),Object.defineProperty(e,`UpdateCommentCommand`,{enumerable:!0,get:function(){return u.UpdateCommentCommand}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-thread-comment-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@univerjs/icons": "^1.1.1",
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/sheets": "0.
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/sheets-ui": "0.
|
|
62
|
-
"@univerjs/thread-comment": "0.
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/ui": "0.
|
|
56
|
+
"@univerjs/engine-formula": "0.20.0",
|
|
57
|
+
"@univerjs/sheets-thread-comment": "0.20.0",
|
|
58
|
+
"@univerjs/core": "0.20.0",
|
|
59
|
+
"@univerjs/sheets": "0.20.0",
|
|
60
|
+
"@univerjs/engine-render": "0.20.0",
|
|
61
|
+
"@univerjs/sheets-ui": "0.20.0",
|
|
62
|
+
"@univerjs/thread-comment": "0.20.0",
|
|
63
|
+
"@univerjs/ui": "0.20.0",
|
|
64
|
+
"@univerjs/thread-comment-ui": "0.20.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"postcss": "^8.5.8",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"tailwindcss": "3.4.18",
|
|
71
71
|
"typescript": "^6.0.2",
|
|
72
72
|
"vitest": "^4.1.1",
|
|
73
|
-
"@univerjs-infra/shared": "0.
|
|
73
|
+
"@univerjs-infra/shared": "0.20.0"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"test": "vitest run",
|