@univerjs/sheets-thread-comment 0.1.17 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var oe=Object.defineProperty;var ie=(o,r,t)=>r in o?oe(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t;var $=(o,r,t)=>ie(o,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@wendellhu/redi"),a=require("@univerjs/core"),b=require("@univerjs/thread-comment-ui"),S=require("@univerjs/ui"),C=require("@univerjs/sheets"),V=require("@univerjs/engine-formula"),E=require("@univerjs/thread-comment"),y=require("@univerjs/sheets-ui"),j=require("@univerjs/sheets-thread-comment-base"),R=require("@wendellhu/redi/react-bindings"),P=require("react"),W=require("rxjs"),se=require("@univerjs/engine-render");var T=function(){return T=Object.assign||function(o){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(o[n]=r[n])}return o},T.apply(this,arguments)},ae=function(o,r){var t={};for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&r.indexOf(e)<0&&(t[e]=o[e]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(o);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(o,e[n])&&(t[e[n]]=o[e[n]]);return t},X=P.forwardRef(function(o,r){var t=o.icon,e=o.id,n=o.className,i=o.extend,s=ae(o,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),m=P.useRef("_".concat(de()));return J(t,"".concat(e),{defIds:t.defIds,idSuffix:m.current},T({ref:r,className:c},s),i)});function J(o,r,t,e,n){return P.createElement(o.tag,T(T({key:r},ce(o,t,n)),e),(me(o,t).children||[]).map(function(i,s){return J(i,"".concat(r,"-").concat(o.tag,"-").concat(s),t,void 0,n)}))}function ce(o,r,t){var e=T({},o.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);var n=r.defIds;return!n||n.length===0||(o.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(i){var s=i[0],c=i[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function me(o,r){var t,e=r.defIds;return!e||e.length===0?o:o.tag==="defs"&&(!((t=o.children)===null||t===void 0)&&t.length)?T(T({},o),{children:o.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?T(T({},n),{attrs:T(T({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):o}function de(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var ue={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Q=P.forwardRef(function(o,r){return P.createElement(X,Object.assign({},o,{id:"comment-single",ref:r,icon:ue}))});Q.displayName="CommentSingle";const ee="univer.sheet.thread-comment-modal",q="comment-single",Z="SHEET_THREAD_COMMENT";var he=Object.defineProperty,le=Object.getOwnPropertyDescriptor,pe=(o,r,t,e)=>{for(var n=e>1?void 0:e?le(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&he(r,t,n),n},G=(o,r)=>(t,e)=>r(t,e,o);exports.SheetsThreadCommentPopupService=class extends a.Disposable{constructor(t,e){super();$(this,"_lastPopup",null);$(this,"_activePopup");$(this,"_activePopup$",new W.BehaviorSubject(null));$(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=t,this._zenZoneService=e,this._initZenVisible()}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t&&this.hidePopup()}))}showPopup(t,e){var p;const{row:n,col:i,unitId:s,subUnitId:c}=t;if(this._activePopup&&n===this._activePopup.row&&i===this._activePopup.col&&s===this._activePopup.unitId&&c===((p=this.activePopup)==null?void 0:p.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);const m=this._canvasPopupManagerService.attachPopupToCell(n,i,{componentKey:ee,onClickOutside:()=>{this.hidePopup()},direction:"horizontal",excludeOutside:[...Array.from(document.querySelectorAll(".univer-thread-comment")),document.getElementById("thread-comment-add")].filter(Boolean)});if(!m)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const h=new a.DisposableCollection;h.add(m),h.add({dispose:()=>{e==null||e()}}),this._lastPopup=h}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))}};exports.SheetsThreadCommentPopupService=pe([G(0,l.Inject(y.SheetCanvasPopManagerService)),G(1,S.IZenZoneService)],exports.SheetsThreadCommentPopupService);const Ce=()=>{const o=R.useDependency(a.IUniverInstanceService),r=R.useDependency(exports.SheetsThreadCommentPopupService),t=S.useObservable(r.activePopup$),e=R.useDependency(j.SheetsThreadCommentModel);if(S.useObservable(e.commentUpdate$),!t)return null;const{row:n,col:i,unitId:s,subUnitId:c,trigger:m}=t,h=e.getByLocation(s,c,n,i),p=`${a.Tools.chatAtABC(i)}${n+1}`,u=()=>{r.hidePopup()},v=I=>{var M,_,D;return(D=(_=(M=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:M.getSheetBySheetId(I))==null?void 0:_.getName())!=null?D:""};return P.createElement(b.ThreadCommentTree,{onClick:()=>{r.persistPopup()},prefix:"cell",id:h,unitId:s,subUnitId:c,type:a.UniverInstanceType.UNIVER_SHEET,refStr:p,onClose:u,getSubUnitName:v,autoFocus:m==="context-menu"})},k={type:a.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(o){var _;const r=o.get(C.SelectionManagerService),t=o.get(a.IUniverInstanceService),e=o.get(exports.SheetsThreadCommentPopupService),n=o.get(b.ThreadCommentPanelService),i=(_=r.getFirst())==null?void 0:_.primary,s=r.getCurrent(),c=o.get(j.SheetsThreadCommentModel);if(!s||!i)return!1;const{unitId:m,sheetId:h}=s,p=C.getSheetCommandTarget(t,{unitId:m,subUnitId:h});if(!p)return!1;const{workbook:u,worksheet:v}=p,I={workbook:u,worksheet:v,unitId:m,subUnitId:h,row:i.startRow,col:i.startColumn};e.showPopup(I);const M=c.getByLocation(m,h,i.startRow,i.startColumn);return M&&n.setActiveComment({unitId:m,subUnitId:h,commentId:M,trigger:"context-menu"}),!0}},ve=()=>{var N;const o=R.useDependency(y.IMarkSelectionService),r=R.useDependency(a.IUniverInstanceService),t=R.useDependency(E.ThreadCommentModel),e=R.useDependency(exports.SheetsThreadCommentPopupService),n=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;const i=n.getUnitId(),s=R.useDependency(a.ICommandService),c=P.useMemo(()=>n.activeSheet$.pipe(W.map(d=>d==null?void 0:d.getSheetId())),[n.activeSheet$]),m=S.useObservable(c,(N=n.getActiveSheet())==null?void 0:N.getSheetId()),h=P.useRef(),p=R.useDependency(b.ThreadCommentPanelService),u=S.useObservable(p.activeCommentId$),v=P.useCallback(d=>{const f=n.getSheets(),g={};return f.forEach((w,U)=>{g[w.getSheetId()]=U}),d.map(w=>{var z;const U=V.singleReferenceToGrid(w.ref),re=[(z=g[w.subUnitId])!=null?z:0,U.row,U.column];return{...w,p:re}}).sort((w,U)=>w.p[0]===U.p[0]?w.p[1]===U.p[1]?w.p[2]-U.p[2]:w.p[1]-U.p[1]:w.p[0]-U.p[0])},[n]),I=P.useCallback(d=>{if(d.unitId===i&&d.subUnitId===m&&!d.resolved){const{row:f,column:g}=V.singleReferenceToGrid(d.ref);if(!Number.isNaN(f)&&!Number.isNaN(g))return o.addShape({range:{startColumn:g,endColumn:g,startRow:f,endRow:f},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[o,m,i]),M=d=>{var f,g;return(g=(f=n.getSheetBySheetId(d))==null?void 0:f.getName())!=null?g:""},_=()=>{s.executeCommand(k.id)},D=()=>{e.hidePopup()},A=d=>{u&&u.unitId===d.unitId&&u.subUnitId===d.subUnitId&&u.commentId===d.id||(h.current&&(o.removeShape(h.current),h.current=null),h.current=I(d))},x=()=>{h.current&&(o.removeShape(h.current),h.current=null)};return P.useEffect(()=>{if(!u)return;const d=t.getComment(u.unitId,u.subUnitId,u.commentId);if(!d)return;const f=I(d);return()=>{f&&o.removeShape(f)}},[I,u,t,o]),P.createElement(b.ThreadCommentPanel,{unitId:i,subUnitId$:c,type:a.UniverInstanceType.UNIVER_SHEET,onAdd:_,getSubUnitName:M,onResolve:D,sortComments:v,onItemEnter:A,onItemLeave:x})},Se=o=>({id:k.id,type:S.MenuItemType.BUTTON,positions:[S.MenuPosition.CONTEXT_MENU],icon:q,title:"sheetThreadComment.menu.addComment",hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET),disabled$:y.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]})}),_e=o=>({id:b.ToggleSheetCommentPanelOperation.id,type:S.MenuItemType.BUTTON,icon:q,tooltip:"sheetThreadComment.menu.commentManagement",positions:S.MenuPosition.TOOLBAR_START,group:S.MenuGroup.TOOLBAR_OTHERS,disabled$:y.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]}),hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET)}),fe={id:k.id,binding:S.KeyCode.M|S.MetaKeys.CTRL_COMMAND|S.MetaKeys.ALT,preconditions:y.whenSheetEditorFocused};var Ie=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,Pe=(o,r,t,e)=>{for(var n=e>1?void 0:e?ge(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Ie(r,t,n),n},O=(o,r)=>(t,e)=>r(t,e,o);const Te={};exports.SheetsThreadCommentController=class extends a.Disposable{constructor(r,t,e,n,i,s,c,m,h,p,u,v){super(),this._config=r,this._menuService=t,this._injector=e,this._componentManager=n,this._localeService=i,this._commandService=s,this._sheetsThreadCommentPopupService=c,this._sheetsThreadCommentModel=m,this._threadCommentPanelService=h,this._shortcutService=p,this._univerInstanceService=u,this._sheetPermissionInterceptorBaseController=v,this._initMenu(),this._initShortcut(),this._initComponent(),this._initCommandListener(),this._initPanelListener()}_initShortcut(){this._shortcutService.registerShortcut(fe)}_initCommandListener(){this._commandService.onCommandExecuted(r=>{if(r.id===C.SetSelectionsOperation.id){const t=r.params,{unitId:e,subUnitId:n,selections:i,type:s}=t;if((s===C.SelectionMoveType.MOVE_END||s===void 0)&&i[0].primary){const c=i[0].primary.actualRow,m=i[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(e,n,c,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(b.SetActiveCommentOperation.id);return}const h=this._sheetsThreadCommentModel.getByLocation(e,n,c,m);h&&this._commandService.executeCommand(b.SetActiveCommentOperation.id,{unitId:e,subUnitId:n,commentId:h})}}if(r.id===E.DeleteCommentMutation.id){const t=r.params,e=this._sheetsThreadCommentPopupService.activePopup;if(!e)return;const{unitId:n,subUnitId:i,commentId:s}=e;t.unitId===n&&t.subUnitId===i&&t.commentId===s&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initMenu(){const{menu:r={}}=this._config;[Se,_e].forEach(t=>{this._menuService.addMenuItem(t(this._injector),r)})}_initComponent(){[[ee,Ce],[b.THREAD_COMMENT_PANEL,ve],[q,Q]].forEach(([r,t])=>{this._componentManager.register(r,t)})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async r=>{var t;if(r){const{unitId:e,subUnitId:n,commentId:i,trigger:s}=r,c=this._sheetsThreadCommentModel.getComment(e,n,i);if(!c||c.resolved)return;const m=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!m||m.getUnitId()!==e)return;((t=m.getActiveSheet())==null?void 0:t.getSheetId())!==n&&await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:n});const u=V.singleReferenceToGrid(c.ref),{row:v,column:I}=u;if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:v,startColumn:I,endRow:v,endColumn:I}]))return;const _=5;await this._commandService.executeCommand(y.ScrollToRangeOperation.id,{range:{startRow:Math.max(u.row-_,0),endRow:u.row+_,startColumn:Math.max(u.column-_,0),endColumn:u.column+_}}),this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:n,row:u.row,col:u.column,commentId:c.id,trigger:s})}else this._sheetsThreadCommentPopupService.hidePopup()}))}};exports.SheetsThreadCommentController=Pe([a.OnLifecycle(a.LifecycleStages.Starting,exports.SheetsThreadCommentController),O(1,S.IMenuService),O(2,l.Inject(l.Injector)),O(3,l.Inject(S.ComponentManager)),O(4,l.Inject(a.LocaleService)),O(5,a.ICommandService),O(6,l.Inject(exports.SheetsThreadCommentPopupService)),O(7,l.Inject(j.SheetsThreadCommentModel)),O(8,l.Inject(b.ThreadCommentPanelService)),O(9,S.IShortcutService),O(10,a.IUniverInstanceService),O(11,l.Inject(y.SheetPermissionInterceptorBaseController))],exports.SheetsThreadCommentController);var be=Object.defineProperty,ye=Object.getOwnPropertyDescriptor,Me=(o,r,t,e)=>{for(var n=e>1?void 0:e?ye(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&be(r,t,n),n},H=(o,r)=>(t,e)=>r(t,e,o);let B=class extends a.Disposable{constructor(o,r,t,e){super(),this._sheetInterceptorService=o,this._sheetsThreadCommentModel=r,this._univerInstanceService=t,this._renderManagerService=e,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(o,r,t)=>{const{row:e,col:n,unitId:i,subUnitId:s}=r;return this._sheetsThreadCommentModel.showCommentMarker(i,s,e,n)?t({...o,markers:{...o==null?void 0:o.markers,tr:{color:"#FFBD37",size:6}}}):t(o)},priority:100}))}_initSkeletonChange(){const o=()=>{var s;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return;const t=r.getUnitId(),e=(s=r.getActiveSheet())==null?void 0:s.getSheetId();if(!e){console.warn("No active sheet found");return}const n=this._renderManagerService.getRenderById(t),i=n==null?void 0:n.with(y.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:e});i==null||i.makeDirty(!0),i==null||i.calculate(),n&&n.mainComponent.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(()=>{o()}))}};B=Me([a.OnLifecycle(a.LifecycleStages.Ready,B),H(0,l.Inject(C.SheetInterceptorService)),H(1,l.Inject(j.SheetsThreadCommentModel)),H(2,a.IUniverInstanceService),H(3,se.IRenderManagerService)],B);var we=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,Ue=(o,r,t,e)=>{for(var n=e>1?void 0:e?Oe(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&we(r,t,n),n},K=(o,r)=>(t,e)=>r(t,e,o);const Ee=(o,r,t)=>{const e=V.singleReferenceToGrid(o),n=t.row-r.row,i=t.column-r.column,s={startColumn:e.column+i,startRow:e.row+n,endColumn:e.column+i,endRow:e.row+n};return V.serializeRange(s)};exports.SheetsThreadCommentCopyPasteController=class extends a.Disposable{constructor(t,e){super();$(this,"_copyInfo");this._sheetClipboardService=t,this._sheetsThreadCommentModel=e,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Z,onBeforeCopy:(t,e,n)=>{this._copyInfo={unitId:t,subUnitId:e,range:n}},onPasteCells:(t,e,n,i)=>{const{unitId:s,subUnitId:c,range:m}=e,h={row:m.rows[0],column:m.cols[0]};if(i.copyType===y.COPY_TYPE.CUT&&this._copyInfo){const{range:p,unitId:u,subUnitId:v}=this._copyInfo,I={row:p.startRow,column:p.startColumn};if(!(s===u&&c===v)){const M=[];a.Range.foreach(p,(d,f)=>{const g=this._sheetsThreadCommentModel.getCommentWithChildren(u,v,d,f);g&&M.push(g)});const _=[],D=[],A=[],x=[],N=d=>{_.unshift({id:E.DeleteCommentMutation.id,params:{unitId:u,subUnitId:v,commentId:d.id}}),A.push({id:E.AddCommentMutation.id,params:{unitId:s,subUnitId:c,comment:{...d,ref:Ee(d.ref,I,h),unitId:s,subUnitId:c}}}),D.push({id:E.AddCommentMutation.id,params:{unitId:u,subUnitId:v,comment:d}}),x.unshift({id:E.DeleteCommentMutation.id,params:{unitId:s,subUnitId:c,commentId:d.id}})};return M.forEach(d=>{N(d.root),d.children.forEach(f=>{N(f)})}),{redos:[..._,...A],undos:[...x,...D]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=Ue([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),K(0,l.Inject(y.ISheetClipboardService)),K(1,l.Inject(j.SheetsThreadCommentModel))],exports.SheetsThreadCommentCopyPasteController);var Re=Object.defineProperty,je=Object.getOwnPropertyDescriptor,De=(o,r,t,e)=>{for(var n=e>1?void 0:e?je(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Re(r,t,n),n},L=(o,r)=>(t,e)=>r(t,e,o);exports.SheetsThreadCommentHoverController=class extends a.Disposable{constructor(r,t,e,n){super(),this._hoverManagerService=r,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=e,this._sheetPermissionInterceptorBaseController=n,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(W.debounceTime(100)).subscribe(r=>{const t=this._sheetsThreadCommentPopupService.activePopup;if(r&&(t&&t.temp||!t)){const{location:e}=r,{unitId:n,subUnitId:i,row:s,col:c}=e,m=this._sheetsThreadCommentModel.getByLocation(n,i,s,c);if(m){if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:s,startColumn:c,endRow:s,endColumn:c}]))return;const p=this._sheetsThreadCommentModel.getComment(n,i,m);p&&!p.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:i,row:s,col:c,commentId:m,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=De([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),L(0,l.Inject(y.HoverManagerService)),L(1,l.Inject(exports.SheetsThreadCommentPopupService)),L(2,l.Inject(j.SheetsThreadCommentModel)),L(3,l.Inject(y.SheetPermissionInterceptorBaseController))],exports.SheetsThreadCommentHoverController);var $e=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Ve=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ne(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&$e(r,t,n),n},F=(o,r)=>(t,e)=>r(t,e,o);exports.ThreadCommentRemoveSheetsController=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._threadCommentModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===C.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const{commentMap:c}=this._threadCommentModel.ensureMap(i,s),m=Array.from(Object.keys(c)),h=Array.from(Object.values(c)),p=m.map(v=>({id:E.DeleteCommentMutation.id,params:{unitId:i,subUnitId:s,commentId:v}})),u=h.map(v=>({id:E.AddCommentMutation.id,params:{unitId:i,subUnitId:s,comment:v}}));return{redos:p,undos:u}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=Ve([a.OnLifecycle(a.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),F(0,l.Inject(C.SheetInterceptorService)),F(1,a.IUniverInstanceService),F(2,l.Inject(E.ThreadCommentModel))],exports.ThreadCommentRemoveSheetsController);var te=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(o,r,t)=>r in o?te(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,He=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ae(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&te(r,t,n),n},Y=(o,r)=>(t,e)=>r(t,e,o),ne=(o,r,t)=>xe(o,typeof r!="symbol"?r+"":r,t);exports.UniverSheetsThreadCommentPlugin=class extends a.Plugin{constructor(t={},e,n){super();$(this,"_pluginConfig");this._injector=e,this._commandService=n,this._pluginConfig=a.Tools.deepMerge({},Te,t)}onStarting(t){[[exports.SheetsThreadCommentController,{useFactory:()=>this._injector.createInstance(exports.SheetsThreadCommentController,this._pluginConfig)}],[B],[exports.SheetsThreadCommentCopyPasteController],[exports.SheetsThreadCommentHoverController],[exports.ThreadCommentRemoveSheetsController],[exports.SheetsThreadCommentPopupService]].forEach(e=>{t.add(e)}),[k].forEach(e=>{this._commandService.registerCommand(e)})}};ne(exports.UniverSheetsThreadCommentPlugin,"pluginName",Z);ne(exports.UniverSheetsThreadCommentPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=He([a.DependentOn(b.UniverThreadCommentUIPlugin,j.UniverSheetsThreadCommentBasePlugin),Y(1,l.Inject(l.Injector)),Y(2,l.Inject(a.ICommandService))],exports.UniverSheetsThreadCommentPlugin);Object.defineProperty(exports,"Inject",{enumerable:!0,get:()=>l.Inject});Object.defineProperty(exports,"Injector",{enumerable:!0,get:()=>l.Injector});Object.defineProperty(exports,"ICommandService",{enumerable:!0,get:()=>a.ICommandService});Object.defineProperty(exports,"Plugin",{enumerable:!0,get:()=>a.Plugin});Object.defineProperty(exports,"UniverInstanceType",{enumerable:!0,get:()=>a.UniverInstanceType});Object.defineProperty(exports,"IThreadCommentMentionDataService",{enumerable:!0,get:()=>b.IThreadCommentMentionDataService});Object.defineProperty(exports,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>b.UniverThreadCommentUIPlugin});Object.defineProperty(exports,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>E.IThreadCommentDataSourceService});Object.defineProperty(exports,"SheetsThreadCommentModel",{enumerable:!0,get:()=>j.SheetsThreadCommentModel});exports.SHEETS_THREAD_COMMENT=Z;
1
+ "use strict";var se=Object.defineProperty;var ae=(o,r,n)=>r in o?se(o,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[r]=n;var N=(o,r,n)=>ae(o,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@wendellhu/redi"),a=require("@univerjs/core"),M=require("@univerjs/thread-comment-ui"),S=require("@univerjs/ui"),C=require("@univerjs/sheets"),x=require("@univerjs/engine-formula"),y=require("@univerjs/thread-comment"),w=require("@univerjs/sheets-ui"),D=require("@univerjs/sheets-thread-comment-base"),R=require("@wendellhu/redi/react-bindings"),T=require("react"),z=require("rxjs"),ce=require("@univerjs/engine-render");var b=function(){return b=Object.assign||function(o){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(o[t]=r[t])}return o},b.apply(this,arguments)},me=function(o,r){var n={};for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&r.indexOf(e)<0&&(n[e]=o[e]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(o);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(o,e[t])&&(n[e[t]]=o[e[t]]);return n},Q=T.forwardRef(function(o,r){var n=o.icon,e=o.id,t=o.className,i=o.extend,s=me(o,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),m=T.useRef("_".concat(he()));return ee(n,"".concat(e),{defIds:n.defIds,idSuffix:m.current},b({ref:r,className:c},s),i)});function ee(o,r,n,e,t){return T.createElement(o.tag,b(b({key:r},de(o,n,t)),e),(ue(o,n).children||[]).map(function(i,s){return ee(i,"".concat(r,"-").concat(o.tag,"-").concat(s),n,void 0,t)}))}function de(o,r,n){var e=b({},o.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(o.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(i){var s=i[0],c=i[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function ue(o,r){var n,e=r.defIds;return!e||e.length===0?o:o.tag==="defs"&&(!((n=o.children)===null||n===void 0)&&n.length)?b(b({},o),{children:o.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?b(b({},t),{attrs:b(b({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):o}function he(){return Math.random().toString(36).substring(2,8)}Q.displayName="UniverIcon";var le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},te=T.forwardRef(function(o,r){return T.createElement(Q,Object.assign({},o,{id:"comment-single",ref:r,icon:le}))});te.displayName="CommentSingle";const ne="univer.sheet.thread-comment-modal",G="comment-single",K="SHEET_THREAD_COMMENT";var pe=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,ve=(o,r,n,e)=>{for(var t=e>1?void 0:e?Ce(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&pe(r,n,t),t},X=(o,r)=>(n,e)=>r(n,e,o);exports.SheetsThreadCommentPopupService=class extends a.Disposable{constructor(n,e){super();N(this,"_lastPopup",null);N(this,"_activePopup");N(this,"_activePopup$",new z.BehaviorSubject(null));N(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=n,this._zenZoneService=e,this._initZenVisible()}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(n=>{n&&this.hidePopup()}))}showPopup(n,e){var p;const{row:t,col:i,unitId:s,subUnitId:c}=n;if(this._activePopup&&t===this._activePopup.row&&i===this._activePopup.col&&s===this._activePopup.unitId&&c===((p=this.activePopup)==null?void 0:p.subUnitId)){this._activePopup=n,this._activePopup$.next(n);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=n,this._activePopup$.next(n);const m=this._canvasPopupManagerService.attachPopupToCell(t,i,{componentKey:ne,onClickOutside:()=>{this.hidePopup()},direction:"horizontal",excludeOutside:[...Array.from(document.querySelectorAll(".univer-thread-comment")),document.getElementById("thread-comment-add")].filter(Boolean)});if(!m)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const h=new a.DisposableCollection;h.add(m),h.add({dispose:()=>{e==null||e()}}),this._lastPopup=h}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))}};exports.SheetsThreadCommentPopupService=ve([X(0,l.Inject(w.SheetCanvasPopManagerService)),X(1,S.IZenZoneService)],exports.SheetsThreadCommentPopupService);const Se=()=>{const o=R.useDependency(a.IUniverInstanceService),r=R.useDependency(exports.SheetsThreadCommentPopupService),n=S.useObservable(r.activePopup$),e=R.useDependency(D.SheetsThreadCommentModel);if(S.useObservable(e.commentUpdate$),!n)return null;const{row:t,col:i,unitId:s,subUnitId:c,trigger:m}=n,h=e.getByLocation(s,c,t,i),p=`${a.Tools.chatAtABC(i)}${t+1}`,u=()=>{r.hidePopup()},f=v=>{var g,_,$;return($=(_=(g=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getSheetBySheetId(v))==null?void 0:_.getName())!=null?$:""};return T.createElement(M.ThreadCommentTree,{onClick:()=>{r.persistPopup()},prefix:"cell",id:h,unitId:s,subUnitId:c,type:a.UniverInstanceType.UNIVER_SHEET,refStr:p,onClose:u,getSubUnitName:f,autoFocus:m==="context-menu"})},H={type:a.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(o){var _;const r=o.get(C.SelectionManagerService),n=o.get(a.IUniverInstanceService),e=o.get(exports.SheetsThreadCommentPopupService),t=o.get(M.ThreadCommentPanelService),i=(_=r.getFirst())==null?void 0:_.primary,s=r.getCurrent(),c=o.get(D.SheetsThreadCommentModel);if(!s||!i)return!1;const{unitId:m,sheetId:h}=s,p=C.getSheetCommandTarget(n,{unitId:m,subUnitId:h});if(!p)return!1;const{workbook:u,worksheet:f}=p,v={workbook:u,worksheet:f,unitId:m,subUnitId:h,row:i.startRow,col:i.startColumn};e.showPopup(v);const g=c.getByLocation(m,h,i.startRow,i.startColumn);return g&&t.setActiveComment({unitId:m,subUnitId:h,commentId:g,trigger:"context-menu"}),!0}},fe=()=>{var B;const o=R.useDependency(w.IMarkSelectionService),r=R.useDependency(a.IUniverInstanceService),n=R.useDependency(y.ThreadCommentModel),e=R.useDependency(exports.SheetsThreadCommentPopupService),t=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const i=t.getUnitId(),s=R.useDependency(a.ICommandService),c=T.useMemo(()=>t.activeSheet$.pipe(z.map(d=>d==null?void 0:d.getSheetId())),[t.activeSheet$]),m=S.useObservable(c,(B=t.getActiveSheet())==null?void 0:B.getSheetId()),h=T.useRef(),p=R.useDependency(M.ThreadCommentPanelService),u=S.useObservable(p.activeCommentId$),f=T.useCallback(d=>{const I=t.getSheets(),P={};I.forEach((U,O)=>{P[U.getSheetId()]=O});const V=U=>U.map(O=>{var Y;const j=x.singleReferenceToGrid(O.ref),ie=[(Y=P[O.subUnitId])!=null?Y:0,j.row,j.column];return{...O,p:ie}}).sort((O,j)=>O.p[0]===j.p[0]?O.p[1]===j.p[1]?O.p[2]-j.p[2]:O.p[1]-j.p[1]:O.p[0]-j.p[0]);return[...V(d.filter(U=>!U.resolved)),...V(d.filter(U=>U.resolved))]},[t]),v=T.useCallback(d=>{if(d.unitId===i&&d.subUnitId===m&&!d.resolved){const{row:I,column:P}=x.singleReferenceToGrid(d.ref);if(!Number.isNaN(I)&&!Number.isNaN(P))return o.addShape({range:{startColumn:P,endColumn:P,startRow:I,endRow:I},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[o,m,i]),g=d=>{var I,P;return(P=(I=t.getSheetBySheetId(d))==null?void 0:I.getName())!=null?P:""},_=()=>{s.executeCommand(H.id)},$=d=>{u&&u.unitId===d.unitId&&u.subUnitId===d.subUnitId&&u.commentId===d.id||(h.current&&(o.removeShape(h.current),h.current=null),h.current=v(d))},A=()=>{h.current&&(o.removeShape(h.current),h.current=null)},L=(d,I)=>{I&&e.hidePopup()};return T.useEffect(()=>{if(!u)return;const d=n.getComment(u.unitId,u.subUnitId,u.commentId);if(!d)return;const I=v(d);return()=>{I&&o.removeShape(I)}},[v,u,n,o]),T.createElement(M.ThreadCommentPanel,{unitId:i,subUnitId$:c,type:a.UniverInstanceType.UNIVER_SHEET,onAdd:_,getSubUnitName:g,onResolve:L,sortComments:f,onItemEnter:$,onItemLeave:A,onDeleteComment:()=>(A(),!0)})},_e=o=>({id:H.id,type:S.MenuItemType.BUTTON,positions:[S.MenuPosition.CONTEXT_MENU],icon:G,title:"sheetThreadComment.menu.addComment",hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]})}),Ie=o=>({id:M.ToggleSheetCommentPanelOperation.id,type:S.MenuItemType.BUTTON,icon:G,tooltip:"sheetThreadComment.menu.commentManagement",positions:S.MenuPosition.TOOLBAR_START,group:S.MenuGroup.TOOLBAR_OTHERS,disabled$:w.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]}),hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET)}),ge={id:H.id,binding:S.KeyCode.M|S.MetaKeys.CTRL_COMMAND|S.MetaKeys.ALT,preconditions:w.whenSheetEditorFocused};var Pe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,be=(o,r,n,e)=>{for(var t=e>1?void 0:e?Te(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Pe(r,n,t),t},E=(o,r)=>(n,e)=>r(n,e,o);const ye={};exports.SheetsThreadCommentController=class extends a.Disposable{constructor(r,n,e,t,i,s,c,m,h,p,u){super(),this._config=r,this._menuService=n,this._injector=e,this._componentManager=t,this._commandService=i,this._sheetsThreadCommentPopupService=s,this._sheetsThreadCommentModel=c,this._threadCommentPanelService=m,this._shortcutService=h,this._univerInstanceService=p,this._sheetPermissionInterceptorBaseController=u,this._initMenu(),this._initShortcut(),this._initComponent(),this._initCommandListener(),this._initPanelListener()}_initShortcut(){this._shortcutService.registerShortcut(ge)}_initCommandListener(){this._commandService.onCommandExecuted(r=>{if(r.id===C.SetSelectionsOperation.id){const n=r.params,{unitId:e,subUnitId:t,selections:i,type:s}=n;if((s===C.SelectionMoveType.MOVE_END||s===void 0)&&i[0].primary){const c=i[0].primary.actualRow,m=i[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(e,t,c,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(M.SetActiveCommentOperation.id);return}const h=this._sheetsThreadCommentModel.getByLocation(e,t,c,m);h&&this._commandService.executeCommand(M.SetActiveCommentOperation.id,{unitId:e,subUnitId:t,commentId:h})}}if(r.id===y.DeleteCommentMutation.id){const n=r.params,e=this._sheetsThreadCommentPopupService.activePopup;if(!e)return;const{unitId:t,subUnitId:i,commentId:s}=e;n.unitId===t&&n.subUnitId===i&&n.commentId===s&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initMenu(){const{menu:r={}}=this._config;[_e,Ie].forEach(n=>{this._menuService.addMenuItem(n(this._injector),r)})}_initComponent(){[[ne,Se],[M.THREAD_COMMENT_PANEL,fe],[G,te]].forEach(([r,n])=>{this._componentManager.register(r,n)})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async r=>{var n;if(r){const{unitId:e,subUnitId:t,commentId:i,trigger:s}=r,c=this._sheetsThreadCommentModel.getComment(e,t,i);if(!c||c.resolved)return;const m=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!m||m.getUnitId()!==e)return;((n=m.getActiveSheet())==null?void 0:n.getSheetId())!==t&&await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const u=x.singleReferenceToGrid(c.ref),{row:f,column:v}=u;if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:f,startColumn:v,endRow:f,endColumn:v}]))return;const _=1;await this._commandService.executeCommand(w.ScrollToRangeOperation.id,{range:{startRow:Math.max(u.row-_,0),endRow:u.row+_,startColumn:Math.max(u.column-_,0),endColumn:u.column+_}}),this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:t,row:u.row,col:u.column,commentId:c.id,trigger:s})}else this._sheetsThreadCommentPopupService.hidePopup()}))}};exports.SheetsThreadCommentController=be([a.OnLifecycle(a.LifecycleStages.Starting,exports.SheetsThreadCommentController),E(1,S.IMenuService),E(2,l.Inject(l.Injector)),E(3,l.Inject(S.ComponentManager)),E(4,a.ICommandService),E(5,l.Inject(exports.SheetsThreadCommentPopupService)),E(6,l.Inject(D.SheetsThreadCommentModel)),E(7,l.Inject(M.ThreadCommentPanelService)),E(8,S.IShortcutService),E(9,a.IUniverInstanceService),E(10,l.Inject(w.SheetPermissionInterceptorBaseController))],exports.SheetsThreadCommentController);var Me=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Oe=(o,r,n,e)=>{for(var t=e>1?void 0:e?we(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Me(r,n,t),t},k=(o,r)=>(n,e)=>r(n,e,o);let q=class extends a.Disposable{constructor(o,r,n,e){super(),this._sheetInterceptorService=o,this._sheetsThreadCommentModel=r,this._univerInstanceService=n,this._renderManagerService=e,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(o,r,n)=>{const{row:e,col:t,unitId:i,subUnitId:s}=r;return this._sheetsThreadCommentModel.showCommentMarker(i,s,e,t)?n({...o,markers:{...o==null?void 0:o.markers,tr:{color:"#FFBD37",size:6}}}):n(o)},priority:100}))}_initSkeletonChange(){const o=()=>{var s;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return;const n=r.getUnitId(),e=(s=r.getActiveSheet())==null?void 0:s.getSheetId();if(!e){console.warn("No active sheet found");return}const t=this._renderManagerService.getRenderById(n),i=t==null?void 0:t.with(w.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:e});i==null||i.makeDirty(!0),i==null||i.calculate(),t&&t.mainComponent.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(r=>{o()}))}};q=Oe([a.OnLifecycle(a.LifecycleStages.Ready,q),k(0,l.Inject(C.SheetInterceptorService)),k(1,l.Inject(D.SheetsThreadCommentModel)),k(2,a.IUniverInstanceService),k(3,ce.IRenderManagerService)],q);var Ue=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Re=(o,r,n,e)=>{for(var t=e>1?void 0:e?Ee(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Ue(r,n,t),t},Z=(o,r)=>(n,e)=>r(n,e,o);const je=(o,r,n)=>{const e=x.singleReferenceToGrid(o),t=n.row-r.row,i=n.column-r.column,s={startColumn:e.column+i,startRow:e.row+t,endColumn:e.column+i,endRow:e.row+t};return x.serializeRange(s)};exports.SheetsThreadCommentCopyPasteController=class extends a.Disposable{constructor(n,e,t){super();N(this,"_copyInfo");this._sheetClipboardService=n,this._sheetsThreadCommentModel=e,this._threadCommentDataSourceService=t,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:K,onBeforeCopy:(n,e,t)=>{this._copyInfo={unitId:n,subUnitId:e,range:t}},onPasteCells:(n,e,t,i)=>{const{unitId:s,subUnitId:c,range:m}=e,h={row:m.rows[0],column:m.cols[0]};if(i.copyType===w.COPY_TYPE.CUT&&this._copyInfo){const{range:p,unitId:u,subUnitId:f}=this._copyInfo,v={row:p.startRow,column:p.startColumn};if(!(s===u&&c===f)){const g=[];a.Range.foreach(p,(d,I)=>{const P=this._sheetsThreadCommentModel.getAllByLocation(u,f,d,I);this._threadCommentDataSourceService.syncUpdateMutationToColla?P.forEach(V=>{g.push(V)}):P.forEach(({children:V,...U})=>{U.parentId||g.push(U)})});const _=[],$=[],A=[],L=[],B=d=>{_.unshift({id:y.DeleteCommentMutation.id,params:{unitId:u,subUnitId:f,commentId:d.id}}),A.push({id:y.AddCommentMutation.id,params:{unitId:s,subUnitId:c,comment:{...d,ref:je(d.ref,v,h),unitId:s,subUnitId:c},sync:!0}}),$.push({id:y.AddCommentMutation.id,params:{unitId:u,subUnitId:f,comment:d,sync:!0}}),L.unshift({id:y.DeleteCommentMutation.id,params:{unitId:s,subUnitId:c,commentId:d.id}})};return g.forEach(d=>{B(d)}),{redos:[..._,...A],undos:[...L,...$]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=Re([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),Z(0,l.Inject(w.ISheetClipboardService)),Z(1,l.Inject(D.SheetsThreadCommentModel)),Z(2,y.IThreadCommentDataSourceService)],exports.SheetsThreadCommentCopyPasteController);var De=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,Ne=(o,r,n,e)=>{for(var t=e>1?void 0:e?$e(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&De(r,n,t),t},F=(o,r)=>(n,e)=>r(n,e,o);exports.SheetsThreadCommentHoverController=class extends a.Disposable{constructor(r,n,e,t){super(),this._hoverManagerService=r,this._sheetsThreadCommentPopupService=n,this._sheetsThreadCommentModel=e,this._sheetPermissionInterceptorBaseController=t,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(z.debounceTime(100)).subscribe(r=>{const n=this._sheetsThreadCommentPopupService.activePopup;if(r&&(n&&n.temp||!n)){const{location:e}=r,{unitId:t,subUnitId:i,row:s,col:c}=e,m=this._sheetsThreadCommentModel.getByLocation(t,i,s,c);if(m){if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:s,startColumn:c,endRow:s,endColumn:c}]))return;const p=this._sheetsThreadCommentModel.getComment(t,i,m);p&&!p.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:t,subUnitId:i,row:s,col:c,commentId:m,temp:!0})}else n&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=Ne([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),F(0,l.Inject(w.HoverManagerService)),F(1,l.Inject(exports.SheetsThreadCommentPopupService)),F(2,l.Inject(D.SheetsThreadCommentModel)),F(3,l.Inject(w.SheetPermissionInterceptorBaseController))],exports.SheetsThreadCommentHoverController);var Ae=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,xe=(o,r,n,e)=>{for(var t=e>1?void 0:e?Ve(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Ae(r,n,t),t},W=(o,r)=>(n,e)=>r(n,e,o);exports.ThreadCommentRemoveSheetsController=class extends a.Disposable{constructor(r,n,e,t){super(),this._sheetInterceptorService=r,this._univerInstanceService=n,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var n;if(r.id===C.RemoveSheetCommand.id){const e=r.params,t=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return{redos:[],undos:[]};const i=t.getUnitId(),s=e.subUnitId||((n=t.getActiveSheet())==null?void 0:n.getSheetId());if(!s)return{redos:[],undos:[]};const{commentMap:c}=this._threadCommentModel.ensureMap(i,s),m=Array.from(Object.values(c)).filter(v=>!v.parentId),h=m.map(v=>v.id),p=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=h.map(v=>({id:y.DeleteCommentMutation.id,params:{unitId:i,subUnitId:s,commentId:v}})),f=m.map(({children:v,...g})=>({id:y.AddCommentMutation.id,params:{unitId:i,subUnitId:s,comment:{...g,children:p?v:void 0},sync:!p}}));return{redos:u,undos:f}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=xe([a.OnLifecycle(a.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),W(0,l.Inject(C.SheetInterceptorService)),W(1,a.IUniverInstanceService),W(2,l.Inject(y.ThreadCommentModel)),W(3,y.IThreadCommentDataSourceService)],exports.ThreadCommentRemoveSheetsController);var re=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Le=(o,r,n)=>r in o?re(o,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[r]=n,Be=(o,r,n,e)=>{for(var t=e>1?void 0:e?He(r,n):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&re(r,n,t),t},J=(o,r)=>(n,e)=>r(n,e,o),oe=(o,r,n)=>Le(o,typeof r!="symbol"?r+"":r,n);exports.UniverSheetsThreadCommentPlugin=class extends a.Plugin{constructor(n={},e,t){super();N(this,"_pluginConfig");this._injector=e,this._commandService=t,this._pluginConfig=a.Tools.deepMerge({},ye,n)}onStarting(n){[[exports.SheetsThreadCommentController,{useFactory:()=>this._injector.createInstance(exports.SheetsThreadCommentController,this._pluginConfig)}],[q],[exports.SheetsThreadCommentCopyPasteController],[exports.SheetsThreadCommentHoverController],[exports.ThreadCommentRemoveSheetsController],[exports.SheetsThreadCommentPopupService]].forEach(e=>{n.add(e)}),[H].forEach(e=>{this._commandService.registerCommand(e)})}};oe(exports.UniverSheetsThreadCommentPlugin,"pluginName",K);oe(exports.UniverSheetsThreadCommentPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=Be([a.DependentOn(M.UniverThreadCommentUIPlugin,D.UniverSheetsThreadCommentBasePlugin),J(1,l.Inject(l.Injector)),J(2,l.Inject(a.ICommandService))],exports.UniverSheetsThreadCommentPlugin);Object.defineProperty(exports,"Inject",{enumerable:!0,get:()=>l.Inject});Object.defineProperty(exports,"Injector",{enumerable:!0,get:()=>l.Injector});Object.defineProperty(exports,"ICommandService",{enumerable:!0,get:()=>a.ICommandService});Object.defineProperty(exports,"Plugin",{enumerable:!0,get:()=>a.Plugin});Object.defineProperty(exports,"UniverInstanceType",{enumerable:!0,get:()=>a.UniverInstanceType});Object.defineProperty(exports,"IThreadCommentMentionDataService",{enumerable:!0,get:()=>M.IThreadCommentMentionDataService});Object.defineProperty(exports,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>M.UniverThreadCommentUIPlugin});Object.defineProperty(exports,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>y.IThreadCommentDataSourceService});Object.defineProperty(exports,"SheetsThreadCommentModel",{enumerable:!0,get:()=>D.SheetsThreadCommentModel});exports.SHEETS_THREAD_COMMENT=K;exports.ShowAddSheetCommentModalOperation=H;