@univerjs/sheets-thread-comment 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +443 -708
- package/lib/types/controllers/render-controllers/render.controller.d.ts +1 -1
- package/lib/types/controllers/sheets-thread-comment-copy-paste.controller.d.ts +1 -1
- package/lib/types/controllers/sheets-thread-comment-hover.controller.d.ts +1 -1
- package/lib/types/controllers/sheets-thread-comment.controller.d.ts +1 -1
- package/lib/types/index.d.ts +1 -2
- package/lib/umd/index.js +1 -1
- package/package.json +25 -22
- package/lib/types/controllers/sheets-thread-comment-ref-range.controller.d.ts +0 -16
- package/lib/types/models/sheets-thread-comment.model.d.ts +0 -31
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 re=Object.defineProperty;var oe=(o,n,e)=>n in o?re(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e;var $=(o,n,e)=>(oe(o,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("@wendellhu/redi"),a=require("@univerjs/core"),T=require("@univerjs/thread-comment-ui"),C=require("@univerjs/ui"),S=require("@univerjs/sheets"),N=require("@univerjs/engine-formula"),w=require("@univerjs/thread-comment"),E=require("@univerjs/sheets-ui"),j=require("@univerjs/sheets-thread-comment-base"),P=require("@wendellhu/redi/react-bindings"),I=require("react"),q=require("rxjs"),ie=require("@univerjs/engine-render");var g=function(){return g=Object.assign||function(o){for(var n,e=1,t=arguments.length;e<t;e++){n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(o[r]=n[r])}return o},g.apply(this,arguments)},se=function(o,n){var e={};for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&n.indexOf(t)<0&&(e[t]=o[t]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(o);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(o,t[r])&&(e[t[r]]=o[t[r]]);return e},Y=I.forwardRef(function(o,n){var e=o.icon,t=o.id,r=o.className,i=o.extend,s=se(o,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),m=I.useRef("_".concat(de()));return X(e,"".concat(t),{defIds:e.defIds,idSuffix:m.current},g({ref:n,className:c},s),i)});function X(o,n,e,t,r){return I.createElement(o.tag,g(g({key:n},ae(o,e,r)),t),(ce(o,e).children||[]).map(function(i,s){return X(i,"".concat(n,"-").concat(o.tag,"-").concat(s),e,void 0,r)}))}function ae(o,n,e){var t=g({},o.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var r=n.defIds;return!r||r.length===0||(o.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(i){var s=i[0],c=i[1];typeof c=="string"&&(t[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function ce(o,n){var e,t=n.defIds;return!t||t.length===0?o:o.tag==="defs"&&(!((e=o.children)===null||e===void 0)&&e.length)?g(g({},o),{children:o.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?g(g({},r),{attrs:g(g({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):o}function de(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var me={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"}}]},J=I.forwardRef(function(o,n){return I.createElement(Y,Object.assign({},o,{id:"comment-single",ref:n,icon:me}))});J.displayName="CommentSingle";const Q="univer.sheet.thread-comment-modal",W="comment-single",Z="univer.sheet.thread-comment";var ue=Object.defineProperty,he=Object.getOwnPropertyDescriptor,le=(o,n,e,t)=>{for(var r=t>1?void 0:t?he(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&ue(n,e,r),r},z=(o,n)=>(e,t)=>n(e,t,o);exports.SheetsThreadCommentPopupService=class extends a.Disposable{constructor(e,t){super();$(this,"_lastPopup",null);$(this,"_activePopup");$(this,"_activePopup$",new q.BehaviorSubject(null));$(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:r,col:i,unitId:s,subUnitId:c}=e;if(this._activePopup&&r===this._activePopup.row&&i===this._activePopup.col&&s===this._activePopup.unitId&&c===((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(r,i,{componentKey:Q,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 a.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=le([z(0,v.Inject(E.SheetCanvasPopManagerService)),z(1,C.IZenZoneService)],exports.SheetsThreadCommentPopupService);const pe=()=>{const o=P.useDependency(a.IUniverInstanceService),n=P.useDependency(exports.SheetsThreadCommentPopupService),e=C.useObservable(n.activePopup$),t=P.useDependency(j.SheetsThreadCommentModel);if(C.useObservable(t.commentUpdate$),!e)return null;const{row:r,col:i,unitId:s,subUnitId:c,trigger:m}=e,d=t.getByLocation(s,c,r,i),h=`${a.Tools.chatAtABC(i)}${r+1}`,u=()=>{n.hidePopup()},b=R=>{var y,M,D;return(D=(M=(y=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:y.getSheetBySheetId(R))==null?void 0:M.getName())!=null?D:""};return I.createElement(T.ThreadCommentTree,{onClick:()=>{n.persistPopup()},prefix:"cell",id:d,unitId:s,subUnitId:c,type:a.UniverInstanceType.UNIVER_SHEET,refStr:h,onClose:u,getSubUnitName:b,autoFocus:m==="context-menu"})},V={type:a.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(o){var M;const n=o.get(S.SelectionManagerService),e=o.get(a.IUniverInstanceService),t=o.get(exports.SheetsThreadCommentPopupService),r=o.get(T.ThreadCommentPanelService),i=(M=n.getFirst())==null?void 0:M.primary,s=n.getCurrent(),c=o.get(j.SheetsThreadCommentModel);if(!s||!i)return!1;const{unitId:m,sheetId:d}=s,h=S.getSheetCommandTarget(e,{unitId:m,subUnitId:d});if(!h)return!1;const{workbook:u,worksheet:b}=h,R={workbook:u,worksheet:b,unitId:m,subUnitId:d,row:i.startRow,col:i.startColumn};t.showPopup(R);const y=c.getByLocation(m,d,i.startRow,i.startColumn);return y&&r.setActiveComment({unitId:m,subUnitId:d,commentId:y,trigger:"context-menu"}),!0}},ve=()=>{const o=P.useDependency(E.IMarkSelectionService),n=P.useDependency(a.IUniverInstanceService),e=P.useDependency(w.ThreadCommentModel),t=P.useDependency(exports.SheetsThreadCommentPopupService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return null;const i=r.getUnitId(),s=P.useDependency(a.ICommandService),c=I.useMemo(()=>r.activeSheet$.pipe(q.map(l=>l==null?void 0:l.getSheetId())),[r.activeSheet$]),m=P.useObservable(c,r.getActiveSheet().getSheetId()),d=I.useRef(),h=P.useDependency(T.ThreadCommentPanelService),u=P.useObservable(h.activeCommentId$),b=I.useCallback(l=>{const p=r.getSheets(),_={};return p.forEach((f,O)=>{_[f.getSheetId()]=O}),l.map(f=>{var k;const O=N.singleReferenceToGrid(f.ref),ne=[(k=_[f.subUnitId])!=null?k:0,O.row,O.column];return{...f,p:ne}}).sort((f,O)=>f.p[0]===O.p[0]?f.p[1]===O.p[1]?f.p[2]-O.p[2]:f.p[1]-O.p[1]:f.p[0]-O.p[0])},[r]),R=I.useCallback(l=>{if(l.unitId===i&&l.subUnitId===m&&!l.resolved){const{row:p,column:_}=N.singleReferenceToGrid(l.ref);if(!Number.isNaN(p)&&!Number.isNaN(_))return o.addShape({range:{startColumn:_,endColumn:_,startRow:p,endRow:p},style:{hasAutoFill:!1,fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[o,m,i]),y=l=>{var p,_;return(_=(p=r.getSheetBySheetId(l))==null?void 0:p.getName())!=null?_:""},M=()=>{s.executeCommand(V.id)},D=()=>{t.hidePopup()},A=l=>{u&&u.unitId===l.unitId&&u.subUnitId===l.subUnitId&&u.commentId===l.id||(d.current&&(o.removeShape(d.current),d.current=null),d.current=R(l))},x=()=>{d.current&&(o.removeShape(d.current),d.current=null)};return I.useEffect(()=>{if(!u)return;const l=e.getComment(u.unitId,u.subUnitId,u.commentId);if(!l)return;const p=R(l);return()=>{p&&o.removeShape(p)}},[R,u,e,o]),I.createElement(T.ThreadCommentPanel,{unitId:i,subUnitId$:c,type:a.UniverInstanceType.UNIVER_SHEET,onAdd:M,getSubUnitName:y,onResolve:D,sortComments:b,onItemEnter:A,onItemLeave:x})},Ce=o=>({id:V.id,type:C.MenuItemType.BUTTON,positions:[C.MenuPosition.CONTEXT_MENU],icon:W,title:"sheetThreadComment.menu.addComment",hidden$:C.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(o,{workbookTypes:[S.WorkbookCommentPermission],worksheetTypes:[S.WorksheetViewPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Se=o=>({id:T.ToggleSheetCommentPanelOperation.id,type:C.MenuItemType.BUTTON,icon:W,tooltip:"sheetThreadComment.menu.commentManagement",positions:C.MenuPosition.TOOLBAR_START,group:C.MenuGroup.TOOLBAR_OTHERS,disabled$:E.getCurrentRangeDisable$(o,{workbookTypes:[S.WorkbookCommentPermission],worksheetTypes:[S.WorksheetViewPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]}),hidden$:C.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_SHEET)}),fe={id:V.id,binding:C.KeyCode.M|C.MetaKeys.CTRL_COMMAND|C.MetaKeys.ALT,preconditions:E.whenSheetEditorFocused};var _e=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,ge=(o,n,e,t)=>{for(var r=t>1?void 0:t?Ie(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&_e(n,e,r),r},U=(o,n)=>(e,t)=>n(e,t,o);const Te={};exports.SheetsThreadCommentController=class extends a.Disposable{constructor(n,e,t,r,i,s,c,m,d,h,u){super(),this._config=n,this._menuService=e,this._injector=t,this._componentManager=r,this._localeService=i,this._commandService=s,this._sheetsThreadCommentPopupService=c,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(fe)}_initCommandListener(){this._commandService.onCommandExecuted(n=>{if(n.id===S.SetSelectionsOperation.id){const e=n.params,{unitId:t,subUnitId:r,selections:i,type:s}=e;if((s===S.SelectionMoveType.MOVE_END||s===void 0)&&i[0].primary){const c=i[0].primary.actualRow,m=i[0].primary.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(t,r,c,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(T.SetActiveCommentOperation.id);return}const d=this._sheetsThreadCommentModel.getByLocation(t,r,c,m);d&&this._commandService.executeCommand(T.SetActiveCommentOperation.id,{unitId:t,subUnitId:r,commentId:d})}}if(n.id===w.DeleteCommentMutation.id){const e=n.params,t=this._sheetsThreadCommentPopupService.activePopup;if(!t)return;const{unitId:r,subUnitId:i,commentId:s}=t;e.unitId===r&&e.subUnitId===i&&e.commentId===s&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initMenu(){const{menu:n={}}=this._config;[Ce,Se].forEach(e=>{this._menuService.addMenuItem(e(this._injector),n)})}_initComponent(){[[Q,pe],[T.THREAD_COMMENT_PANEL,ve],[W,J]].forEach(([n,e])=>{this._componentManager.register(n,e)})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async n=>{if(n){const{unitId:e,subUnitId:t,commentId:r,trigger:i}=n,s=this._sheetsThreadCommentModel.getComment(e,t,r);if(!s||s.resolved)return;const c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!c||c.getUnitId()!==e)return;c.getActiveSheet().getSheetId()!==t&&await this._commandService.executeCommand(S.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const h=N.singleReferenceToGrid(s.ref),u=5;await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:{startRow:Math.max(h.row-u,0),endRow:h.row+u,startColumn:Math.max(h.column-u,0),endColumn:h.column+u}}),this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:t,row:h.row,col:h.column,commentId:s.id,trigger:i})}else this._sheetsThreadCommentPopupService.hidePopup()}))}};exports.SheetsThreadCommentController=ge([a.OnLifecycle(a.LifecycleStages.Starting,exports.SheetsThreadCommentController),U(1,C.IMenuService),U(2,v.Inject(v.Injector)),U(3,v.Inject(C.ComponentManager)),U(4,v.Inject(a.LocaleService)),U(5,a.ICommandService),U(6,v.Inject(exports.SheetsThreadCommentPopupService)),U(7,v.Inject(j.SheetsThreadCommentModel)),U(8,v.Inject(T.ThreadCommentPanelService)),U(9,C.IShortcutService),U(10,a.IUniverInstanceService)],exports.SheetsThreadCommentController);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,ye=(o,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Pe(n,e,r),r},L=(o,n)=>(e,t)=>n(e,t,o);let H=class extends a.Disposable{constructor(o,n,e,t){super(),this._sheetInterceptorService=o,this._sheetsThreadCommentModel=n,this._univerInstanceService=e,this._renderManagerService=t,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(o,n,e)=>{const{row:t,col:r,unitId:i,subUnitId:s}=n;return this._sheetsThreadCommentModel.showCommentMarker(i,s,t,r)?e({...o,markers:{...o==null?void 0:o.markers,tr:{color:"#FFBD37",size:6}}}):e(o)},priority:100}))}_initSkeletonChange(){const o=()=>{const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return;const e=n.getUnitId(),t=n.getActiveSheet().getSheetId(),r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(E.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:t});i==null||i.makeDirty(!0),i==null||i.calculate(),r&&r.mainComponent.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(()=>{o()}))}};H=ye([a.OnLifecycle(a.LifecycleStages.Ready,H),L(0,v.Inject(S.SheetInterceptorService)),L(1,v.Inject(j.SheetsThreadCommentModel)),L(2,a.IUniverInstanceService),L(3,ie.IRenderManagerService)],H);var Me=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,Ue=(o,n,e,t)=>{for(var r=t>1?void 0:t?Oe(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Me(n,e,r),r},G=(o,n)=>(e,t)=>n(e,t,o);const we=(o,n,e)=>{const t=N.singleReferenceToGrid(o),r=e.row-n.row,i=e.column-n.column,s={startColumn:t.column+i,startRow:t.row+r,endColumn:t.column+i,endRow:t.row+r};return N.serializeRange(s)};exports.SheetsThreadCommentCopyPasteController=class extends a.Disposable{constructor(e,t){super();$(this,"_copyInfo");this._sheetClipboardService=e,this._sheetsThreadCommentModel=t,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Z,onBeforeCopy:(e,t,r)=>{this._copyInfo={unitId:e,subUnitId:t,range:r}},onPasteCells:(e,t,r,i)=>{const{unitId:s,subUnitId:c,range:m}=t,d={row:m.rows[0],column:m.cols[0]};if(i.copyType===E.COPY_TYPE.CUT&&this._copyInfo){const{range:h,unitId:u,subUnitId:b}=this._copyInfo,R={row:h.startRow,column:h.startColumn};if(!(s===u&&c===b)){const y=[];a.Range.foreach(h,(p,_)=>{const f=this._sheetsThreadCommentModel.getCommentWithChildren(u,b,p,_);f&&y.push(f)});const M=[],D=[],A=[],x=[],l=p=>{M.unshift({id:w.DeleteCommentMutation.id,params:{unitId:u,subUnitId:b,commentId:p.id}}),A.push({id:w.AddCommentMutation.id,params:{unitId:s,subUnitId:c,comment:{...p,ref:we(p.ref,R,d),unitId:s,subUnitId:c}}}),D.push({id:w.AddCommentMutation.id,params:{unitId:u,subUnitId:b,comment:p}}),x.unshift({id:w.DeleteCommentMutation.id,params:{unitId:s,subUnitId:c,commentId:p.id}})};return y.forEach(p=>{l(p.root),p.children.forEach(_=>{l(_)})}),{redos:[...M,...A],undos:[...x,...D]}}}return{redos:[],undos:[]}}}))}};exports.SheetsThreadCommentCopyPasteController=Ue([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentCopyPasteController),G(0,v.Inject(E.ISheetClipboardService)),G(1,v.Inject(j.SheetsThreadCommentModel))],exports.SheetsThreadCommentCopyPasteController);var Ee=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,je=(o,n,e,t)=>{for(var r=t>1?void 0:t?Re(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Ee(n,e,r),r},B=(o,n)=>(e,t)=>n(e,t,o);exports.SheetsThreadCommentHoverController=class extends a.Disposable{constructor(n,e,t){super(),this._hoverManagerService=n,this._sheetsThreadCommentPopupService=e,this._sheetsThreadCommentModel=t,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(n=>{const e=this._sheetsThreadCommentPopupService.activePopup;if(n&&(e&&e.temp||!e)){const{location:t}=n,{unitId:r,subUnitId:i,row:s,col:c}=t,m=this._sheetsThreadCommentModel.getByLocation(r,i,s,c);if(m){const d=this._sheetsThreadCommentModel.getComment(r,i,m);d&&!d.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:r,subUnitId:i,row:s,col:c,commentId:m,temp:!0})}else e&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};exports.SheetsThreadCommentHoverController=je([a.OnLifecycle(a.LifecycleStages.Rendered,exports.SheetsThreadCommentHoverController),B(0,v.Inject(E.HoverManagerService)),B(1,v.Inject(exports.SheetsThreadCommentPopupService)),B(2,v.Inject(j.SheetsThreadCommentModel))],exports.SheetsThreadCommentHoverController);var De=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,Ne=(o,n,e,t)=>{for(var r=t>1?void 0:t?$e(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&De(n,e,r),r},F=(o,n)=>(e,t)=>n(e,t,o);exports.ThreadCommentRemoveSheetsController=class extends a.Disposable{constructor(n,e,t){super(),this._sheetInterceptorService=n,this._univerInstanceService=e,this._threadCommentModel=t,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===S.RemoveSheetCommand.id){const e=n.params,t=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return{redos:[],undos:[]};const r=t.getUnitId(),i=e.subUnitId||t.getActiveSheet().getSheetId(),{commentMap:s}=this._threadCommentModel.ensureMap(r,i),c=Array.from(Object.keys(s)),m=Array.from(Object.values(s)),d=c.map(u=>({id:w.DeleteCommentMutation.id,params:{unitId:r,subUnitId:i,commentId:u}})),h=m.map(u=>({id:w.AddCommentMutation.id,params:{unitId:r,subUnitId:i,comment:u}}));return{redos:d,undos:h}}return{redos:[],undos:[]}}}))}};exports.ThreadCommentRemoveSheetsController=Ne([a.OnLifecycle(a.LifecycleStages.Ready,exports.ThreadCommentRemoveSheetsController),F(0,v.Inject(S.SheetInterceptorService)),F(1,a.IUniverInstanceService),F(2,v.Inject(w.ThreadCommentModel))],exports.ThreadCommentRemoveSheetsController);var ee=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(o,n,e)=>n in o?ee(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e,Le=(o,n,e,t)=>{for(var r=t>1?void 0:t?Ae(n,e):n,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&ee(n,e,r),r},K=(o,n)=>(e,t)=>n(e,t,o),te=(o,n,e)=>(xe(o,typeof n!="symbol"?n+"":n,e),e);exports.UniverSheetsThreadCommentPlugin=class extends a.Plugin{constructor(e={},t,r){super();$(this,"_pluginConfig");this._injector=t,this._commandService=r,this._pluginConfig=a.Tools.deepMerge({},Te,e)}onStarting(e){[[exports.SheetsThreadCommentController,{useFactory:()=>this._injector.createInstance(exports.SheetsThreadCommentController,this._pluginConfig)}],[H],[exports.SheetsThreadCommentCopyPasteController],[exports.SheetsThreadCommentHoverController],[exports.ThreadCommentRemoveSheetsController],[exports.SheetsThreadCommentPopupService]].forEach(t=>{e.add(t)}),[V].forEach(t=>{this._commandService.registerCommand(t)})}};te(exports.UniverSheetsThreadCommentPlugin,"pluginName",Z);te(exports.UniverSheetsThreadCommentPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsThreadCommentPlugin=Le([a.DependentOn(T.UniverThreadCommentUIPlugin,j.UniverSheetsThreadCommentBasePlugin),K(1,v.Inject(v.Injector)),K(2,v.Inject(a.ICommandService))],exports.UniverSheetsThreadCommentPlugin);Object.defineProperty(exports,"Inject",{enumerable:!0,get:()=>v.Inject});Object.defineProperty(exports,"Injector",{enumerable:!0,get:()=>v.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:()=>T.IThreadCommentMentionDataService});Object.defineProperty(exports,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>T.UniverThreadCommentUIPlugin});Object.defineProperty(exports,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>w.IThreadCommentDataSourceService});Object.defineProperty(exports,"SheetsThreadCommentModel",{enumerable:!0,get:()=>j.SheetsThreadCommentModel});exports.SHEETS_THREAD_COMMENT=Z;
|