@univerjs/sheets-thread-comment 0.2.3 → 0.2.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
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 p=require("@wendellhu/redi"),a=require("@univerjs/core"),M=require("@univerjs/thread-comment-ui"),S=require("@univerjs/ui"),v=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(),u=T.useRef("_".concat(he()));return ee(n,"".concat(e),{defIds:n.defIds,idSuffix:u.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 l;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===((l=this.activePopup)==null?void 0:l.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 u=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(!u)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const h=new a.DisposableCollection;h.add(u),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,p.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:u}=n,h=e.getByLocation(s,c,t,i),l=`${a.Tools.chatAtABC(i)}${t+1}`,m=()=>{r.hidePopup()},f=C=>{var I,P,$;return($=(P=(I=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:I.getSheetBySheetId(C))==null?void 0:P.getName())!=null?$:""};return T.createElement(M.ThreadCommentTree,{onClick:()=>{r.persistPopup()},prefix:"cell",id:h,unitId:s,subUnitId:c,type:a.UniverInstanceType.UNIVER_SHEET,refStr:l,onClose:m,getSubUnitName:f,autoFocus:u==="context-menu"})},H={type:a.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(o){var I;const r=o.get(v.SheetsSelectionsService),n=o.get(a.IUniverInstanceService),e=o.get(exports.SheetsThreadCommentPopupService),t=o.get(M.ThreadCommentPanelService),i=(I=r.getCurrentLastSelection())==null?void 0:I.primary,s=o.get(D.SheetsThreadCommentModel);if(!i)return!1;const c=v.getSheetCommandTarget(n);if(!c)return!1;const{workbook:u,worksheet:h,unitId:l,subUnitId:m}=c,f={workbook:u,worksheet:h,unitId:l,subUnitId:m,row:i.startRow,col:i.startColumn};e.showPopup(f);const C=s.getByLocation(l,m,i.startRow,i.startColumn);return C&&t.setActiveComment({unitId:l,subUnitId:m,commentId:C,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$]),u=S.useObservable(c,(B=t.getActiveSheet())==null?void 0:B.getSheetId()),h=T.useRef(),l=R.useDependency(M.ThreadCommentPanelService),m=S.useObservable(l.activeCommentId$),f=T.useCallback(d=>{const _=t.getSheets(),g={};_.forEach((U,O)=>{g[U.getSheetId()]=O});const V=U=>U.map(O=>{var Y;const j=x.singleReferenceToGrid(O.ref),ie=[(Y=g[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]),C=T.useCallback(d=>{if(d.unitId===i&&d.subUnitId===u&&!d.resolved){const{row:_,column:g}=x.singleReferenceToGrid(d.ref);if(!Number.isNaN(_)&&!Number.isNaN(g))return o.addShape({range:{startColumn:g,endColumn:g,startRow:_,endRow:_},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[o,u,i]),I=d=>{var _,g;return(g=(_=t.getSheetBySheetId(d))==null?void 0:_.getName())!=null?g:""},P=()=>{s.executeCommand(H.id)},$=d=>{m&&m.unitId===d.unitId&&m.subUnitId===d.subUnitId&&m.commentId===d.id||(h.current&&(o.removeShape(h.current),h.current=null),h.current=C(d))},A=()=>{h.current&&(o.removeShape(h.current),h.current=null)},L=(d,_)=>{_&&e.hidePopup()};return T.useEffect(()=>{if(!m)return;const d=n.getComment(m.unitId,m.subUnitId,m.commentId);if(!d)return;const _=C(d);return()=>{_&&o.removeShape(_)}},[C,m,n,o]),T.createElement(M.ThreadCommentPanel,{unitId:i,subUnitId$:c,type:a.UniverInstanceType.UNIVER_SHEET,onAdd:P,getSubUnitName:I,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:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.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:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]}),hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET)}),Pe={id:H.id,binding:S.KeyCode.M|S.MetaKeys.CTRL_COMMAND|S.MetaKeys.ALT,preconditions:w.whenSheetEditorFocused};var ge=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&&ge(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,u,h,l,m){super(),this._config=r,this._menuService=n,this._injector=e,this._componentManager=t,this._commandService=i,this._sheetsThreadCommentPopupService=s,this._sheetsThreadCommentModel=c,this._threadCommentPanelService=u,this._shortcutService=h,this._univerInstanceService=l,this._sheetPermissionInterceptorBaseController=m,this._initMenu(),this._initShortcut(),this._initComponent(),this._initCommandListener(),this._initPanelListener()}_initShortcut(){this._shortcutService.registerShortcut(Pe)}_initCommandListener(){this._commandService.onCommandExecuted(r=>{if(r.id===v.SetSelectionsOperation.id){const n=r.params,{unitId:e,subUnitId:t,selections:i,type:s}=n;if((s===v.SelectionMoveType.MOVE_END||s===void 0)&&i[0].primary){const c=i[0].primary.actualRow,u=i[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(e,t,c,u)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(M.SetActiveCommentOperation.id);return}const h=this._sheetsThreadCommentModel.getByLocation(e,t,c,u);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 u=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!u||u.getUnitId()!==e)return;((n=u.getActiveSheet())==null?void 0:n.getSheetId())!==t&&await this._commandService.executeCommand(v.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const m=x.singleReferenceToGrid(c.ref),{row:f,column:C}=m;if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]},[{startRow:f,startColumn:C,endRow:f,endColumn:C}]))return;const P=1;await this._commandService.executeCommand(w.ScrollToRangeOperation.id,{range:{startRow:Math.max(m.row-P,0),endRow:m.row+P,startColumn:Math.max(m.column-P,0),endColumn:m.column+P}}),this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:t,row:m.row,col:m.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,p.Inject(p.Injector)),E(3,p.Inject(S.ComponentManager)),E(4,a.ICommandService),E(5,p.Inject(exports.SheetsThreadCommentPopupService)),E(6,p.Inject(D.SheetsThreadCommentModel)),E(7,p.Inject(M.ThreadCommentPanelService)),E(8,S.IShortcutService),E(9,a.IUniverInstanceService),E(10,p.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(v.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,p.Inject(v.SheetInterceptorService)),k(1,p.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:u}=e,h={row:u.rows[0],column:u.cols[0]};if(i.copyType===w.COPY_TYPE.CUT&&this._copyInfo){const{range:l,unitId:m,subUnitId:f}=this._copyInfo,C={row:l.startRow,column:l.startColumn};if(!(s===m&&c===f)){const I=[];a.Range.foreach(l,(d,_)=>{const g=this._sheetsThreadCommentModel.getAllByLocation(m,f,d,_);this._threadCommentDataSourceService.syncUpdateMutationToColla?g.forEach(V=>{I.push(V)}):g.forEach(({children:V,...U})=>{U.parentId||I.push(U)})});const P=[],$=[],A=[],L=[],B=d=>{P.unshift({id:y.DeleteCommentMutation.id,params:{unitId:m,subUnitId:f,commentId:d.id}}),A.push({id:y.AddCommentMutation.id,params:{unitId:s,subUnitId:c,comment:{...d,ref:je(d.ref,C,h),unitId:s,subUnitId:c},sync:!0}}),$.push({id:y.AddCommentMutation.id,params:{unitId:m,subUnitId:f,comment:d,sync:!0}}),L.unshift({id:y.DeleteCommentMutation.id,params:{unitId:s,subUnitId:c,commentId:d.id}})};return I.forEach(d=>{B(d)}),{redos:[...P,...A],undos:[...L,...$]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=Re([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),Z(0,p.Inject(w.ISheetClipboardService)),Z(1,p.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,u=this._sheetsThreadCommentModel.getByLocation(t,i,s,c);if(u){if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]},[{startRow:s,startColumn:c,endRow:s,endColumn:c}]))return;const l=this._sheetsThreadCommentModel.getComment(t,i,u);l&&!l.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:t,subUnitId:i,row:s,col:c,commentId:u,temp:!0})}else n&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=Ne([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),F(0,p.Inject(w.HoverManagerService)),F(1,p.Inject(exports.SheetsThreadCommentPopupService)),F(2,p.Inject(D.SheetsThreadCommentModel)),F(3,p.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===v.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),u=Array.from(Object.values(c)).filter(C=>!C.parentId),h=u.map(C=>C.id),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,m=h.map(C=>({id:y.DeleteCommentMutation.id,params:{unitId:i,subUnitId:s,commentId:C}})),f=u.map(({children:C,...I})=>({id:y.AddCommentMutation.id,params:{unitId:i,subUnitId:s,comment:{...I,children:l?C:void 0},sync:!l}}));return{redos:m,undos:f}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=xe([a.OnLifecycle(a.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),W(0,p.Inject(v.SheetInterceptorService)),W(1,a.IUniverInstanceService),W(2,p.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,p.Inject(p.Injector)),J(2,p.Inject(a.ICommandService))],exports.UniverSheetsThreadCommentPlugin);Object.defineProperty(exports,"Inject",{enumerable:!0,get:()=>p.Inject});Object.defineProperty(exports,"Injector",{enumerable:!0,get:()=>p.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;
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 R=(o,r,t)=>ie(o,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),y=require("@univerjs/thread-comment-ui"),S=require("@univerjs/ui"),C=require("@univerjs/sheets"),N=require("@univerjs/engine-formula"),O=require("@univerjs/thread-comment"),_=require("@univerjs/sheets-ui"),D=require("@univerjs/sheets-thread-comment-base"),T=require("react"),q=require("rxjs"),se=require("@univerjs/engine-render");var b=function(){return b=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},b.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=T.forwardRef(function(o,r){var t=o.icon,e=o.id,n=o.className,i=o.extend,s=ae(o,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),c=T.useRef("_".concat(he()));return J(t,"".concat(e),{defIds:t.defIds,idSuffix:c.current},b({ref:r,className:m},s),i)});function J(o,r,t,e,n){return T.createElement(o.tag,b(b({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=b({},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],m=i[1];typeof m=="string"&&(e[s]=m.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)?b(b({},o),{children:o.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?b(b({},n),{attrs:b(b({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):o}function he(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var de={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=T.forwardRef(function(o,r){return T.createElement(X,Object.assign({},o,{id:"comment-single",ref:r,icon:de}))});Q.displayName="CommentSingle";const ee="univer.sheet.thread-comment-modal",Z="comment-single",z="SHEET_THREAD_COMMENT";var ue=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&&ue(r,t,n),n},K=(o,r)=>(t,e)=>r(t,e,o);exports.SheetsThreadCommentPopupService=class extends a.Disposable{constructor(t,e){super();R(this,"_lastPopup",null);R(this,"_activePopup");R(this,"_activePopup$",new q.BehaviorSubject(null));R(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=t,this._zenZoneService=e,this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t&&this.hidePopup()}))}showPopup(t,e){var h;const{row:n,col:i,unitId:s,subUnitId:m}=t;if(this._activePopup&&n===this._activePopup.row&&i===this._activePopup.col&&s===this._activePopup.unitId&&m===((h=this.activePopup)==null?void 0:h.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 c=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(!c)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const d=new a.DisposableCollection;d.add(c),d.add({dispose:()=>{e==null||e()}}),this._lastPopup=d}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([K(0,a.Inject(_.SheetCanvasPopManagerService)),K(1,S.IZenZoneService)],exports.SheetsThreadCommentPopupService);const ve=()=>{const o=a.useDependency(a.IUniverInstanceService),r=a.useDependency(exports.SheetsThreadCommentPopupService),t=S.useObservable(r.activePopup$),e=a.useDependency(D.SheetsThreadCommentModel);if(S.useObservable(e.commentUpdate$),!t)return null;const{row:n,col:i,unitId:s,subUnitId:m,trigger:c}=t,d=e.getByLocation(s,m,n,i),h=`${a.Tools.chatAtABC(i)}${n+1}`,p=()=>{r.hidePopup()},l=v=>{var f,E,I;return(I=(E=(f=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:f.getSheetBySheetId(v))==null?void 0:E.getName())!=null?I:""};return T.createElement(y.ThreadCommentTree,{onClick:()=>{r.persistPopup()},prefix:"cell",id:d,unitId:s,subUnitId:m,type:a.UniverInstanceType.UNIVER_SHEET,refStr:h,onClose:p,getSubUnitName:l,autoFocus:c==="context-menu"})},A={type:a.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(o){var f;const r=o.get(C.SheetsSelectionsService),t=o.get(a.IUniverInstanceService),e=o.get(exports.SheetsThreadCommentPopupService),n=o.get(y.ThreadCommentPanelService),i=(f=r.getCurrentLastSelection())==null?void 0:f.primary,s=o.get(D.SheetsThreadCommentModel);if(!i)return!1;const m=C.getSheetCommandTarget(t);if(!m)return!1;const{workbook:c,worksheet:d,unitId:h,subUnitId:p}=m,l={workbook:c,worksheet:d,unitId:h,subUnitId:p,row:i.startRow,col:i.startColumn};e.showPopup(l);const v=s.getByLocation(h,p,i.startRow,i.startColumn);return v&&n.setActiveComment({unitId:h,subUnitId:p,commentId:v,trigger:"context-menu"}),!0}},Ce=()=>{var H;const o=a.useDependency(_.IMarkSelectionService),r=a.useDependency(a.IUniverInstanceService),t=a.useDependency(exports.SheetsThreadCommentPopupService),e=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),n=e.getUnitId(),i=a.useDependency(a.ICommandService),s=T.useMemo(()=>e.activeSheet$.pipe(q.map(u=>u==null?void 0:u.getSheetId())),[e.activeSheet$]),m=S.useObservable(s,(H=e.getActiveSheet())==null?void 0:H.getSheetId()),c=T.useRef(),d=a.useDependency(y.ThreadCommentPanelService),h=S.useObservable(d.activeCommentId$),p=S.useObservable(d.panelVisible$,d.panelVisible),l=T.useCallback(u=>{const g=e.getSheets(),P={};g.forEach((U,M)=>{P[U.getSheetId()]=M});const V=U=>U.map(M=>{var G;const j=N.singleReferenceToGrid(M.ref),re=[(G=P[M.subUnitId])!=null?G:0,j.row,j.column];return{...M,p:re}}).sort((M,j)=>M.p[0]===j.p[0]?M.p[1]===j.p[1]?M.p[2]-j.p[2]:M.p[1]-j.p[1]:M.p[0]-j.p[0]);return[...V(u.filter(U=>!U.resolved)),...V(u.filter(U=>U.resolved))]},[e]),v=T.useCallback(u=>{if(u.unitId===n&&u.subUnitId===m&&!u.resolved){const{row:g,column:P}=N.singleReferenceToGrid(u.ref);if(!Number.isNaN(g)&&!Number.isNaN(P))return o.addShape({range:{startColumn:P,endColumn:P,startRow:g,endRow:g},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[o,m,n]),f=u=>{var g,P;return(P=(g=e.getSheetBySheetId(u))==null?void 0:g.getName())!=null?P:""},E=()=>{i.executeCommand(A.id)},I=u=>{h&&h.unitId===u.unitId&&h.subUnitId===u.subUnitId&&h.commentId===u.id||(c.current&&(o.removeShape(c.current),c.current=null),c.current=v(u))},$=()=>{c.current&&(o.removeShape(c.current),c.current=null)},x=(u,g)=>{g&&t.hidePopup()};return T.useEffect(()=>{!p&&c.current&&o.removeShape(c.current)},[o,p]),T.createElement(y.ThreadCommentPanel,{unitId:n,subUnitId$:s,type:a.UniverInstanceType.UNIVER_SHEET,onAdd:E,getSubUnitName:f,onResolve:x,sortComments:l,onItemEnter:I,onItemLeave:$,onDeleteComment:()=>($(),!0)})},Se=o=>({id:A.id,type:S.MenuItemType.BUTTON,positions:[S.MenuPosition.CONTEXT_MENU],icon:Z,title:"sheetThreadComment.menu.addComment",hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET),disabled$:_.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]})}),fe=o=>({id:y.ToggleSheetCommentPanelOperation.id,type:S.MenuItemType.BUTTON,icon:Z,tooltip:"sheetThreadComment.menu.commentManagement",positions:S.MenuPosition.TOOLBAR_START,group:S.MenuGroup.TOOLBAR_OTHERS,disabled$:_.getCurrentRangeDisable$(o,{workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]}),hidden$:S.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET)}),_e={id:A.id,binding:S.KeyCode.M|S.MetaKeys.CTRL_COMMAND|S.MetaKeys.ALT,preconditions:_.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},w=(o,r)=>(t,e)=>r(t,e,o);const Te={};exports.SheetsThreadCommentController=class extends a.Disposable{constructor(t,e,n,i,s,m,c,d,h,p,l,v){super();R(this,"_isSwitchToCommenting",!1);R(this,"_selectionShapeInfo",null);this._config=t,this._menuService=e,this._injector=n,this._componentManager=i,this._commandService=s,this._sheetsThreadCommentPopupService=m,this._sheetsThreadCommentModel=c,this._threadCommentPanelService=d,this._shortcutService=h,this._univerInstanceService=p,this._sheetPermissionInterceptorBaseController=l,this._markSelectionService=v,this._initMenu(),this._initShortcut(),this._initComponent(),this._initCommandListener(),this._initPanelListener(),this._initMarkSelection()}_initShortcut(){this._shortcutService.registerShortcut(_e)}_initCommandListener(){this._commandService.onCommandExecuted(t=>{if(t.id===C.SetSelectionsOperation.id){if(this._isSwitchToCommenting)return;const e=t.params,{unitId:n,subUnitId:i,selections:s,type:m}=e;if((m===C.SelectionMoveType.MOVE_END||m===void 0)&&s[0].primary){const c=s[0].range;if(c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)return;const d=s[0].primary.actualRow,h=s[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,i,d,h)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(y.SetActiveCommentOperation.id);return}const p=this._sheetsThreadCommentModel.getByLocation(n,i,d,h);p&&this._commandService.executeCommand(y.SetActiveCommentOperation.id,{unitId:n,subUnitId:i,commentId:p})}}if(t.id===O.DeleteCommentMutation.id){const e=t.params,n=this._sheetsThreadCommentPopupService.activePopup;if(!n)return;const{unitId:i,subUnitId:s,commentId:m}=n;e.unitId===i&&e.subUnitId===s&&e.commentId===m&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initMenu(){const{menu:t={}}=this._config;[Se,fe].forEach(e=>{this._menuService.addMenuItem(e(this._injector),t)})}_initComponent(){[[ee,ve],[y.THREAD_COMMENT_PANEL,Ce],[Z,Q]].forEach(([t,e])=>{this._componentManager.register(t,e)})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async t=>{var e;if(t){const{unitId:n,subUnitId:i,commentId:s,trigger:m}=t,c=this._sheetsThreadCommentModel.getComment(n,i,s);if(!c||c.resolved)return;const d=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!d||d.getUnitId()!==n)return;this._isSwitchToCommenting=!0,((e=d.getActiveSheet())==null?void 0:e.getSheetId())!==i&&await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:i}),this._isSwitchToCommenting=!1;const l=N.singleReferenceToGrid(c.ref),{row:v,column:f}=l;if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:v,startColumn:f,endRow:v,endColumn:f}]))return;const I=1;await this._commandService.executeCommand(_.ScrollToRangeOperation.id,{range:{startRow:Math.max(l.row-I,0),endRow:l.row+I,startColumn:Math.max(l.column-I,0),endColumn:l.column+I}}),this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:i,row:l.row,col:l.column,commentId:c.id,trigger:m})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(t=>{if(!t){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}const{unitId:e,subUnitId:n,commentId:i}=t;if(this._selectionShapeInfo){if(this._selectionShapeInfo.unitId===e&&this._selectionShapeInfo.subUnitId===n&&this._selectionShapeInfo.commentId===i)return;this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null}const s=this._sheetsThreadCommentModel.getComment(e,n,i);if(!s)return;const m=N.singleReferenceToGrid(s.ref),{row:c,column:d}=m;if(Number.isNaN(c)||Number.isNaN(d))return;const h=this._markSelectionService.addShape({range:{startColumn:d,endColumn:d,startRow:c,endRow:c},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null});h&&(this._selectionShapeInfo={...t,shapeId:h})}))}};exports.SheetsThreadCommentController=Pe([a.OnLifecycle(a.LifecycleStages.Starting,exports.SheetsThreadCommentController),w(1,S.IMenuService),w(2,a.Inject(a.Injector)),w(3,a.Inject(S.ComponentManager)),w(4,a.ICommandService),w(5,a.Inject(exports.SheetsThreadCommentPopupService)),w(6,a.Inject(D.SheetsThreadCommentModel)),w(7,a.Inject(y.ThreadCommentPanelService)),w(8,S.IShortcutService),w(9,a.IUniverInstanceService),w(10,a.Inject(_.SheetPermissionInterceptorBaseController)),w(11,_.IMarkSelectionService)],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},L=(o,r)=>(t,e)=>r(t,e,o);let F=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(_.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:e});i==null||i.makeDirty(!0),i==null||i.calculate(),n&&n.mainComponent.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(r=>{o()}))}};F=Me([a.OnLifecycle(a.LifecycleStages.Ready,F),L(0,a.Inject(C.SheetInterceptorService)),L(1,a.Inject(D.SheetsThreadCommentModel)),L(2,a.IUniverInstanceService),L(3,se.IRenderManagerService)],F);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},W=(o,r)=>(t,e)=>r(t,e,o);const Re=(o,r,t)=>{const e=N.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 N.serializeRange(s)};exports.SheetsThreadCommentCopyPasteController=class extends a.Disposable{constructor(t,e,n){super();R(this,"_copyInfo");this._sheetClipboardService=t,this._sheetsThreadCommentModel=e,this._threadCommentDataSourceService=n,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:m,range:c}=e,d={row:c.rows[0],column:c.cols[0]};if(i.copyType===_.COPY_TYPE.CUT&&this._copyInfo){const{range:h,unitId:p,subUnitId:l}=this._copyInfo,v={row:h.startRow,column:h.startColumn};if(!(s===p&&m===l)){const f=[];a.Range.foreach(h,(u,g)=>{const P=this._sheetsThreadCommentModel.getAllByLocation(p,l,u,g);this._threadCommentDataSourceService.syncUpdateMutationToColla?P.forEach(V=>{f.push(V)}):P.forEach(({children:V,...U})=>{U.parentId||f.push(U)})});const E=[],I=[],$=[],x=[],H=u=>{E.unshift({id:O.DeleteCommentMutation.id,params:{unitId:p,subUnitId:l,commentId:u.id}}),$.push({id:O.AddCommentMutation.id,params:{unitId:s,subUnitId:m,comment:{...u,ref:Re(u.ref,v,d),unitId:s,subUnitId:m},sync:!0}}),I.push({id:O.AddCommentMutation.id,params:{unitId:p,subUnitId:l,comment:u,sync:!0}}),x.unshift({id:O.DeleteCommentMutation.id,params:{unitId:s,subUnitId:m,commentId:u.id}})};return f.forEach(u=>{H(u)}),{redos:[...E,...$],undos:[...x,...I]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=Ue([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),W(0,a.Inject(_.ISheetClipboardService)),W(1,a.Inject(D.SheetsThreadCommentModel)),W(2,O.IThreadCommentDataSourceService)],exports.SheetsThreadCommentCopyPasteController);var Ee=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&&Ee(r,t,n),n},k=(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(q.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:m}=e,c=this._sheetsThreadCommentModel.getByLocation(n,i,s,m);if(c){if(!this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({workbookTypes:[C.WorkbookCommentPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:s,startColumn:m,endRow:s,endColumn:m}]))return;const h=this._sheetsThreadCommentModel.getComment(n,i,c);h&&!h.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:i,row:s,col:m,commentId:c,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=De([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),k(0,a.Inject(_.HoverManagerService)),k(1,a.Inject(exports.SheetsThreadCommentPopupService)),k(2,a.Inject(D.SheetsThreadCommentModel)),k(3,a.Inject(_.SheetPermissionInterceptorBaseController))],exports.SheetsThreadCommentHoverController);var Ne=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,Ve=(o,r,t,e)=>{for(var n=e>1?void 0:e?$e(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&&Ne(r,t,n),n},B=(o,r)=>(t,e)=>r(t,e,o);exports.ThreadCommentRemoveSheetsController=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._threadCommentModel=e,this._threadCommentDataSourceService=n,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:m}=this._threadCommentModel.ensureMap(i,s),c=Array.from(Object.values(m)).filter(v=>!v.parentId),d=c.map(v=>v.id),h=this._threadCommentDataSourceService.syncUpdateMutationToColla,p=d.map(v=>({id:O.DeleteCommentMutation.id,params:{unitId:i,subUnitId:s,commentId:v}})),l=c.map(({children:v,...f})=>({id:O.AddCommentMutation.id,params:{unitId:i,subUnitId:s,comment:{...f,children:h?v:void 0},sync:!h}}));return{redos:p,undos:l}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=Ve([a.OnLifecycle(a.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),B(0,a.Inject(C.SheetInterceptorService)),B(1,a.IUniverInstanceService),B(2,a.Inject(O.ThreadCommentModel)),B(3,O.IThreadCommentDataSourceService)],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();R(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)}],[F],[exports.SheetsThreadCommentCopyPasteController],[exports.SheetsThreadCommentHoverController],[exports.ThreadCommentRemoveSheetsController],[exports.SheetsThreadCommentPopupService]].forEach(e=>{t.add(e)}),[A].forEach(e=>{this._commandService.registerCommand(e)})}};ne(exports.UniverSheetsThreadCommentPlugin,"pluginName",z);ne(exports.UniverSheetsThreadCommentPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=He([a.DependentOn(y.UniverThreadCommentUIPlugin,D.UniverSheetsThreadCommentBasePlugin),Y(1,a.Inject(a.Injector)),Y(2,a.Inject(a.ICommandService))],exports.UniverSheetsThreadCommentPlugin);Object.defineProperty(exports,"ICommandService",{enumerable:!0,get:()=>a.ICommandService});Object.defineProperty(exports,"Inject",{enumerable:!0,get:()=>a.Inject});Object.defineProperty(exports,"Injector",{enumerable:!0,get:()=>a.Injector});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:()=>y.IThreadCommentMentionDataService});Object.defineProperty(exports,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>y.UniverThreadCommentUIPlugin});Object.defineProperty(exports,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>O.IThreadCommentDataSourceService});Object.defineProperty(exports,"SheetsThreadCommentModel",{enumerable:!0,get:()=>D.SheetsThreadCommentModel});exports.SHEETS_THREAD_COMMENT=z;exports.ShowAddSheetCommentModalOperation=A;