@univerjs/sheets-thread-comment 0.1.14 → 0.1.16

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=(i,r,e)=>r in i?oe(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var I=(i,r,e)=>(ie(i,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@wendellhu/redi"),c=require("@univerjs/core"),b=require("@univerjs/thread-comment-ui"),_=require("@univerjs/ui"),v=require("@univerjs/sheets"),M=require("@univerjs/engine-formula"),j=require("@univerjs/sheets-ui"),f=require("@univerjs/thread-comment"),U=require("@wendellhu/redi/react-bindings"),T=require("react"),A=require("rxjs"),se=require("@univerjs/engine-render");var P=function(){return P=Object.assign||function(i){for(var r,e=1,t=arguments.length;e<t;e++){r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},P.apply(this,arguments)},ae=function(i,r){var e={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&r.indexOf(t)<0&&(e[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(i);n<t.length;n++)r.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(i,t[n])&&(e[t[n]]=i[t[n]]);return e},X=T.forwardRef(function(i,r){var e=i.icon,t=i.id,n=i.className,o=i.extend,s=ae(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(t," ").concat(n||"").trim(),m=T.useRef("_".concat(de()));return J(e,"".concat(t),{defIds:e.defIds,idSuffix:m.current},P({ref:r,className:a},s),o)});function J(i,r,e,t,n){return T.createElement(i.tag,P(P({key:r},ce(i,e,n)),t),(me(i,e).children||[]).map(function(o,s){return J(o,"".concat(r,"-").concat(i.tag,"-").concat(s),e,void 0,n)}))}function ce(i,r,e){var t=P({},i.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(t[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),t}function me(i,r){var e,t=r.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?P(P({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&t&&t.indexOf(n.attrs.id)>-1?P(P({},n),{attrs:P(P({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function de(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var he={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(i,r){return T.createElement(X,Object.assign({},i,{id:"comment-single",ref:r,icon:he}))});Q.displayName="CommentSingle";var ue=Object.defineProperty,le=Object.getOwnPropertyDescriptor,pe=(i,r,e,t)=>{for(var n=t>1?void 0:t?le(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&ue(r,e,n),n},G=(i,r)=>(e,t)=>r(e,t,i);exports.SheetsThreadCommentModel=class extends c.Disposable{constructor(e,t){super();I(this,"_matrixMap",new Map);I(this,"_locationMap",new Map);I(this,"_commentUpdate$",new A.Subject);I(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=t,this._init()}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let o=n.get(t);return o||(o=new c.ObjectMatrix,n.set(t,o)),o}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_ensure(e,t){const n=this._ensureCommentMatrix(e,t),o=this._ensureCommentLocationMap(e,t);return{matrix:n,locationMap:o}}_initData(){const e=this._threadCommentModel.getAll();for(const t in e){const n=e[t];for(const o in n){const s=n[o];for(const a in s){const m=s[a];this._addComment(t,o,m)}}}}_addComment(e,t,n){const o=M.singleReferenceToGrid(n.ref),s=n.parentId,{row:a,column:m}=o,d=n.id,{matrix:h,locationMap:u}=this._ensure(e,t);!s&&a>=0&&m>=0&&(h.setValue(a,m,d),u.set(d,{row:a,column:m})),this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:"add",...o})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:o,locationMap:s}=this._ensure(t,n);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:m}=e.payload,d=M.singleReferenceToGrid(m.ref);if(a){const{row:h,column:u}=d;h>=0&&u>=0&&o.realDeleteValue(h,u)}this._commentUpdate$.next({...e,...d});break}case"update":{const{commentId:a}=e.payload,m=this._threadCommentModel.getComment(t,n,a);if(!m)return;const d=M.singleReferenceToGrid(m.ref);this._commentUpdate$.next({...e,...d});break}case"updateRef":{const a=M.singleReferenceToGrid(e.payload.ref),{commentId:m}=e.payload,d=s.get(m);if(!d)return;const{row:h,column:u}=d;o.getValue(h,u)===m&&(o.realDeleteValue(h,u),s.delete(m)),a.row>=0&&a.column>=0&&(o.setValue(a.row,a.column,m),s.set(m,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}}}))}getByLocation(e,t,n,o){return this._ensureCommentMatrix(e,t).getValue(n,o)}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,o){const a=this._ensureCommentMatrix(e,t).getValue(n,o);if(a)return this._threadCommentModel.getCommentWithChildren(e,t,a)}showCommentMarker(e,t,n,o){const s=this.getByLocation(e,t,n,o);if(!s)return!1;const a=this.getComment(e,t,s);return!!(a&&!a.resolved)}};exports.SheetsThreadCommentModel=pe([G(0,l.Inject(f.ThreadCommentModel)),G(1,c.IUniverInstanceService)],exports.SheetsThreadCommentModel);const ee="univer.sheet.thread-comment-modal",q="comment-single",Z="univer.sheet.thread-comment";var Ce=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,_e=(i,r,e,t)=>{for(var n=t>1?void 0:t?ve(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Ce(r,e,n),n},k=(i,r)=>(e,t)=>r(e,t,i);exports.SheetsThreadCommentPopupService=class extends c.Disposable{constructor(e,t){super();I(this,"_lastPopup",null);I(this,"_activePopup");I(this,"_activePopup$",new A.BehaviorSubject(null));I(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=e,this._zenZoneService=t,this._initZenVisible()}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}showPopup(e,t){var h;const{row:n,col:o,unitId:s,subUnitId:a}=e;if(this._activePopup&&n===this._activePopup.row&&o===this._activePopup.col&&s===this._activePopup.unitId&&a===((h=this.activePopup)==null?void 0:h.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);const m=this._canvasPopupManagerService.attachPopupToCell(n,o,{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 d=new c.DisposableCollection;d.add(m),d.add({dispose:()=>{t==null||t()}}),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=_e([k(0,l.Inject(j.SheetCanvasPopManagerService)),k(1,_.IZenZoneService)],exports.SheetsThreadCommentPopupService);const fe=()=>{const i=U.useDependency(c.IUniverInstanceService),r=U.useDependency(exports.SheetsThreadCommentPopupService),e=_.useObservable(r.activePopup$),t=U.useDependency(exports.SheetsThreadCommentModel);if(_.useObservable(t.commentUpdate$),!e)return null;const{row:n,col:o,unitId:s,subUnitId:a,trigger:m}=e,d=t.getByLocation(s,a,n,o),h=`${c.Tools.chatAtABC(o)}${n+1}`,u=()=>{r.hidePopup()},y=D=>{var w,R,$;return($=(R=(w=i.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET))==null?void 0:w.getSheetBySheetId(D))==null?void 0:R.getName())!=null?$:""};return T.createElement(b.ThreadCommentTree,{onClick:()=>{r.persistPopup()},prefix:"cell",id:d,unitId:s,subUnitId:a,type:c.UniverInstanceType.UNIVER_SHEET,refStr:h,onClose:u,getSubUnitName:y,autoFocus:m==="context-menu"})},H={type:c.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(i){var R;const r=i.get(v.SelectionManagerService),e=i.get(c.IUniverInstanceService),t=i.get(exports.SheetsThreadCommentPopupService),n=i.get(b.ThreadCommentPanelService),o=(R=r.getFirst())==null?void 0:R.primary,s=r.getCurrent(),a=i.get(exports.SheetsThreadCommentModel);if(!s||!o)return!1;const{unitId:m,sheetId:d}=s,h=v.getSheetCommandTarget(e,{unitId:m,subUnitId:d});if(!h)return!1;const{workbook:u,worksheet:y}=h,D={workbook:u,worksheet:y,unitId:m,subUnitId:d,row:o.actualRow,col:o.startColumn};t.showPopup(D);const w=a.getByLocation(m,d,o.actualRow,o.startColumn);return w&&n.setActiveComment({unitId:m,subUnitId:d,commentId:w,trigger:"context-menu"}),!0}},Se=()=>{const i=U.useDependency(j.IMarkSelectionService),r=U.useDependency(c.IUniverInstanceService),e=U.useDependency(f.ThreadCommentModel),t=U.useDependency(exports.SheetsThreadCommentPopupService),n=r.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!n)return null;const o=n.getUnitId(),s=U.useDependency(c.ICommandService),a=T.useMemo(()=>n.activeSheet$.pipe(A.map(p=>p==null?void 0:p.getSheetId())),[n.activeSheet$]),m=U.useObservable(a,n.getActiveSheet().getSheetId()),d=T.useRef(),h=U.useDependency(b.ThreadCommentPanelService),u=U.useObservable(h.activeCommentId$),y=T.useCallback(p=>{const C=n.getSheets(),g={};return C.forEach((S,O)=>{g[S.getSheetId()]=O}),p.map(S=>{var z;const O=M.singleReferenceToGrid(S.ref),re=[(z=g[S.subUnitId])!=null?z:0,O.row,O.column];return{...S,p:re}}).sort((S,O)=>S.p[0]===O.p[0]?S.p[1]===O.p[1]?S.p[2]-O.p[2]:S.p[1]-O.p[1]:S.p[0]-O.p[0])},[n]),D=T.useCallback(p=>{if(p.unitId===o&&p.subUnitId===m&&!p.resolved){const{row:C,column:g}=M.singleReferenceToGrid(p.ref);if(!Number.isNaN(C)&&!Number.isNaN(g))return i.addShape({range:{startColumn:g,endColumn:g,startRow:C,endRow:C},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[i,m,o]),w=p=>{var C,g;return(g=(C=n.getSheetBySheetId(p))==null?void 0:C.getName())!=null?g:""},R=()=>{s.executeCommand(H.id)},$=()=>{t.hidePopup()},x=p=>{u&&u.unitId===p.unitId&&u.subUnitId===p.subUnitId&&u.commentId===p.id||(d.current&&(i.removeShape(d.current),d.current=null),d.current=D(p))},N=()=>{d.current&&(i.removeShape(d.current),d.current=null)};return T.useEffect(()=>{if(!u)return;const p=e.getComment(u.unitId,u.subUnitId,u.commentId);if(!p)return;const C=D(p);return()=>{C&&i.removeShape(C)}},[D,u,e,i]),T.createElement(b.ThreadCommentPanel,{unitId:o,subUnitId$:a,type:c.UniverInstanceType.UNIVER_SHEET,onAdd:R,getSubUnitName:w,onResolve:$,sortComments:y,onItemEnter:x,onItemLeave:N})},ge=i=>({id:H.id,type:_.MenuItemType.BUTTON,positions:[_.MenuPosition.CONTEXT_MENU],icon:q,title:"sheetThreadComment.menu.addComment",hidden$:_.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}),Ie=i=>({id:b.ToggleSheetCommentPanelOperation.id,type:_.MenuItemType.BUTTON,icon:q,tooltip:"sheetThreadComment.menu.commentManagement",positions:_.MenuPosition.TOOLBAR_START,group:_.MenuGroup.TOOLBAR_OTHERS,disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}),Te={id:H.id,binding:_.KeyCode.M|_.MetaKeys.CTRL_COMMAND|_.MetaKeys.ALT,preconditions:j.whenSheetEditorFocused};var Pe=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,be=(i,r,e,t)=>{for(var n=t>1?void 0:t?Me(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Pe(r,e,n),n},E=(i,r)=>(e,t)=>r(e,t,i);const ye={};exports.SheetsThreadCommentController=class extends c.Disposable{constructor(r,e,t,n,o,s,a,m,d,h,u){super(),this._config=r,this._menuService=e,this._injector=t,this._componentManager=n,this._localeService=o,this._commandService=s,this._sheetsThreadCommentPopupService=a,this._sheetsThreadCommentModel=m,this._threadCommentPanelService=d,this._shortcutService=h,this._univerInstanceService=u,this._initMenu(),this._initShortcut(),this._initComponent(),this._initCommandListener(),this._initPanelListener()}_initShortcut(){this._shortcutService.registerShortcut(Te)}_initCommandListener(){this._commandService.onCommandExecuted(r=>{if(r.id===v.SetSelectionsOperation.id){const e=r.params,{unitId:t,subUnitId:n,selections:o,type:s}=e;if((s===v.SelectionMoveType.MOVE_END||s===void 0)&&o[0].primary){const a=o[0].primary.actualRow,m=o[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,n,a,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(b.SetActiveCommentOperation.id);return}const d=this._sheetsThreadCommentModel.getByLocation(t,n,a,m);d&&this._commandService.executeCommand(b.SetActiveCommentOperation.id,{unitId:t,subUnitId:n,commentId:d})}}if(r.id===f.DeleteCommentMutation.id){const e=r.params,t=this._sheetsThreadCommentPopupService.activePopup;if(!t)return;const{unitId:n,subUnitId:o,commentId:s}=t;e.unitId===n&&e.subUnitId===o&&e.commentId===s&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initMenu(){const{menu:r={}}=this._config;[ge,Ie].forEach(e=>{this._menuService.addMenuItem(e(this._injector),r)})}_initComponent(){[[ee,fe],[b.THREAD_COMMENT_PANEL,Se],[q,Q]].forEach(([r,e])=>{this._componentManager.register(r,e)})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async r=>{if(r){const{unitId:e,subUnitId:t,commentId:n,trigger:o}=r,s=this._sheetsThreadCommentModel.getComment(e,t,n);if(!s||s.resolved)return;const a=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!a||a.getUnitId()!==e)return;a.getActiveSheet().getSheetId()!==t&&await this._commandService.executeCommand(v.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const h=M.singleReferenceToGrid(s.ref);await this._commandService.executeCommand(j.ScrollToCellCommand.id,{range:{startColumn:h.column,endColumn:h.column,startRow:h.row,endRow:h.row}}),this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:t,row:h.row,col:h.column,commentId:s.id,trigger:o})}else this._sheetsThreadCommentPopupService.hidePopup()}))}};exports.SheetsThreadCommentController=be([c.OnLifecycle(c.LifecycleStages.Starting,exports.SheetsThreadCommentController),E(1,_.IMenuService),E(2,l.Inject(l.Injector)),E(3,l.Inject(_.ComponentManager)),E(4,l.Inject(c.LocaleService)),E(5,c.ICommandService),E(6,l.Inject(exports.SheetsThreadCommentPopupService)),E(7,l.Inject(exports.SheetsThreadCommentModel)),E(8,l.Inject(b.ThreadCommentPanelService)),E(9,_.IShortcutService),E(10,c.IUniverInstanceService)],exports.SheetsThreadCommentController);var Ue=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Re=(i,r,e,t)=>{for(var n=t>1?void 0:t?we(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Ue(r,e,n),n},W=(i,r)=>(e,t)=>r(e,t,i);exports.SheetsThreadCommentRefRangeController=class extends c.Disposable{constructor(e,t,n){super();I(this,"_disposableMap",new Map);this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){const o=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=m=>{const d=v.handleDefaultRangeChangeWithEffectRefCommands(s,m);return d&&d.startColumn===s.startColumn&&d.startRow===s.startRow?{undos:[],redos:[]}:d?{redos:[{id:f.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:M.serializeRange(d),commentId:o}}}],undos:[{id:f.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:M.serializeRange(s),commentId:o}}}]}:{redos:[{id:f.DeleteCommentMutation.id,params:{unitId:e,subUnitId:t,commentId:o}}],undos:[{id:f.AddCommentMutation.id,params:{unitId:e,subUnitId:t,comment:n}}]}};this._disposableMap.set(this._getIdWithUnitId(e,t,o),this._refRangeService.registerRefRange(s,a,e,t))}_initData(){const e=this._threadCommentModel.getAll();for(const t in e){const n=e[t];for(const o in n){const s=n[o];for(const a in s){const m=s[a],d=m.ref,h=M.singleReferenceToGrid(d);this._register(t,o,{...m,...h})}}}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n}=e;switch(e.type){case"add":{const o=e.payload;this._register(e.unitId,e.subUnitId,{...o,row:e.row,column:e.column});break}case"delete":{const o=this._disposableMap.get(this._getIdWithUnitId(t,n,e.payload.commentId));o==null||o.dispose();break}case"updateRef":{const o=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!o)return;const s=this._disposableMap.get(this._getIdWithUnitId(t,n,o.id));s==null||s.dispose(),this._register(e.unitId,e.subUnitId,{...o,row:e.row,column:e.column});break}}})),this.disposeWithMe(c.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};exports.SheetsThreadCommentRefRangeController=Re([c.OnLifecycle(c.LifecycleStages.Starting,exports.SheetsThreadCommentRefRangeController),W(0,l.Inject(v.RefRangeService)),W(1,l.Inject(exports.SheetsThreadCommentModel)),W(2,l.Inject(f.ThreadCommentModel))],exports.SheetsThreadCommentRefRangeController);var Oe=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,je=(i,r,e,t)=>{for(var n=t>1?void 0:t?Ee(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Oe(r,e,n),n},L=(i,r)=>(e,t)=>r(e,t,i);let V=class extends c.Disposable{constructor(i,r,e,t){super(),this._sheetInterceptorService=i,this._sheetsThreadCommentModel=r,this._univerInstanceService=e,this._renderManagerService=t,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(i,r,e)=>{const{row:t,col:n,unitId:o,subUnitId:s}=r;return this._sheetsThreadCommentModel.showCommentMarker(o,s,t,n)?e({...i,markers:{...i==null?void 0:i.markers,tr:{color:"#FFBD37",size:6}}}):e(i)},priority:100}))}_initSkeletonChange(){const i=()=>{const r=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!r)return;const e=r.getUnitId(),t=r.getActiveSheet().getSheetId(),n=this._renderManagerService.getRenderById(e),o=n==null?void 0:n.with(j.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:t});o==null||o.makeDirty(!0),o==null||o.calculate(),n&&n.mainComponent.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(()=>{i()}))}};V=je([c.OnLifecycle(c.LifecycleStages.Ready,V),L(0,l.Inject(v.SheetInterceptorService)),L(1,l.Inject(exports.SheetsThreadCommentModel)),L(2,c.IUniverInstanceService),L(3,se.IRenderManagerService)],V);var De=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,xe=(i,r,e,t)=>{for(var n=t>1?void 0:t?$e(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&De(r,e,n),n},K=(i,r)=>(e,t)=>r(e,t,i);const Ne=(i,r,e)=>{const t=M.singleReferenceToGrid(i),n=e.row-r.row,o=e.column-r.column,s={startColumn:t.column+o,startRow:t.row+n,endColumn:t.column+o,endRow:t.row+n};return M.serializeRange(s)};exports.SheetsThreadCommentCopyPasteController=class extends c.Disposable{constructor(e,t){super();I(this,"_copyInfo");this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Z,onBeforeCopy:(e,t,n)=>{this._copyInfo={unitId:e,subUnitId:t,range:n}},onPasteCells:(e,t,n,o)=>{const{unitId:s,subUnitId:a,range:m}=t,d={row:m.rows[0],column:m.cols[0]};if(o.copyType===j.COPY_TYPE.CUT&&this._copyInfo){const{range:h,unitId:u,subUnitId:y}=this._copyInfo,D={row:h.startRow,column:h.startColumn};if(!(s===u&&a===y)){const w=[];c.Range.foreach(h,(C,g)=>{const S=this._sheetsThreadCommentModel.getCommentWithChildren(u,y,C,g);S&&w.push(S)});const R=[],$=[],x=[],N=[],p=C=>{R.unshift({id:f.DeleteCommentMutation.id,params:{unitId:u,subUnitId:y,commentId:C.id}}),x.push({id:f.AddCommentMutation.id,params:{unitId:s,subUnitId:a,comment:{...C,ref:Ne(C.ref,D,d),unitId:s,subUnitId:a}}}),$.push({id:f.AddCommentMutation.id,params:{unitId:u,subUnitId:y,comment:C}}),N.unshift({id:f.DeleteCommentMutation.id,params:{unitId:s,subUnitId:a,commentId:C.id}})};return w.forEach(C=>{p(C.root),C.children.forEach(g=>{p(g)})}),{redos:[...R,...x],undos:[...N,...$]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=xe([c.OnLifecycle(c.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),K(0,l.Inject(j.ISheetClipboardService)),K(1,l.Inject(exports.SheetsThreadCommentModel))],exports.SheetsThreadCommentCopyPasteController);var Le=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,Ae=(i,r,e,t)=>{for(var n=t>1?void 0:t?Ve(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Le(r,e,n),n},B=(i,r)=>(e,t)=>r(e,t,i);exports.SheetsThreadCommentHoverController=class extends c.Disposable{constructor(r,e,t){super(),this._hoverManagerService=r,this._sheetsThreadCommentPopupService=e,this._sheetsThreadCommentModel=t,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(A.debounceTime(100)).subscribe(r=>{const e=this._sheetsThreadCommentPopupService.activePopup;if(r&&(e&&e.temp||!e)){const{location:t}=r,{unitId:n,subUnitId:o,row:s,col:a}=t,m=this._sheetsThreadCommentModel.getByLocation(n,o,s,a);if(m){const d=this._sheetsThreadCommentModel.getComment(n,o,m);d&&!d.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:n,subUnitId:o,row:s,col:a,commentId:m,temp:!0})}else e&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=Ae([c.OnLifecycle(c.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),B(0,l.Inject(j.HoverManagerService)),B(1,l.Inject(exports.SheetsThreadCommentPopupService)),B(2,l.Inject(exports.SheetsThreadCommentModel))],exports.SheetsThreadCommentHoverController);var He=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,r,e,t)=>{for(var n=t>1?void 0:t?We(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&He(r,e,n),n},F=(i,r)=>(e,t)=>r(e,t,i);exports.ThreadCommentRemoveSheetsController=class extends c.Disposable{constructor(r,e,t){super(),this._sheetInterceptorService=r,this._univerInstanceService=e,this._threadCommentModel=t,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===v.RemoveSheetCommand.id){const e=r.params,t=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return{redos:[],undos:[]};const n=t.getUnitId(),o=e.subUnitId||t.getActiveSheet().getSheetId(),{commentMap:s}=this._threadCommentModel.ensureMap(n,o),a=Array.from(Object.keys(s)),m=Array.from(Object.values(s)),d=a.map(u=>({id:f.DeleteCommentMutation.id,params:{unitId:n,subUnitId:o,commentId:u}})),h=m.map(u=>({id:f.AddCommentMutation.id,params:{unitId:n,subUnitId:o,comment:u}}));return{redos:d,undos:h}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=Be([c.OnLifecycle(c.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),F(0,l.Inject(v.SheetInterceptorService)),F(1,c.IUniverInstanceService),F(2,l.Inject(f.ThreadCommentModel))],exports.ThreadCommentRemoveSheetsController);var te=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,qe=(i,r,e)=>r in i?te(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,Ze=(i,r,e,t)=>{for(var n=t>1?void 0:t?Fe(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&te(r,e,n),n},Y=(i,r)=>(e,t)=>r(e,t,i),ne=(i,r,e)=>(qe(i,typeof r!="symbol"?r+"":r,e),e);exports.UniverSheetsThreadCommentPlugin=class extends c.Plugin{constructor(e={},t,n){super();I(this,"_pluginConfig");this._injector=t,this._commandService=n,this._pluginConfig=c.Tools.deepMerge({},ye,e)}onStarting(e){[[exports.SheetsThreadCommentModel],[exports.SheetsThreadCommentController,{useFactory:()=>this._injector.createInstance(exports.SheetsThreadCommentController,this._pluginConfig)}],[exports.SheetsThreadCommentRefRangeController],[V],[exports.SheetsThreadCommentCopyPasteController],[exports.SheetsThreadCommentHoverController],[exports.ThreadCommentRemoveSheetsController],[exports.SheetsThreadCommentPopupService]].forEach(t=>{e.add(t)}),[H].forEach(t=>{this._commandService.registerCommand(t)})}};ne(exports.UniverSheetsThreadCommentPlugin,"pluginName",Z);ne(exports.UniverSheetsThreadCommentPlugin,"type",c.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=Ze([c.DependentOn(b.UniverThreadCommentUIPlugin),Y(1,l.Inject(l.Injector)),Y(2,l.Inject(c.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:()=>c.ICommandService});Object.defineProperty(exports,"Plugin",{enumerable:!0,get:()=>c.Plugin});Object.defineProperty(exports,"UniverInstanceType",{enumerable:!0,get:()=>c.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:()=>f.IThreadCommentDataSourceService});exports.SHEETS_THREAD_COMMENT=Z;
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;