@univerjs/sheets-hyper-link-ui 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/cjs/facade.js +31 -1
  2. package/lib/cjs/index.js +2286 -1
  3. package/lib/cjs/locale/ca-ES.js +36 -1
  4. package/lib/cjs/locale/en-US.js +51 -1
  5. package/lib/cjs/locale/es-ES.js +36 -1
  6. package/lib/cjs/locale/fa-IR.js +36 -1
  7. package/lib/cjs/locale/fr-FR.js +36 -1
  8. package/lib/cjs/locale/ja-JP.js +36 -1
  9. package/lib/cjs/locale/ko-KR.js +36 -1
  10. package/lib/cjs/locale/ru-RU.js +36 -1
  11. package/lib/cjs/locale/sk-SK.js +36 -1
  12. package/lib/cjs/locale/vi-VN.js +36 -1
  13. package/lib/cjs/locale/zh-CN.js +36 -1
  14. package/lib/cjs/locale/zh-TW.js +36 -1
  15. package/lib/es/facade.js +32 -1
  16. package/lib/es/index.js +2257 -1
  17. package/lib/es/locale/ca-ES.js +35 -1
  18. package/lib/es/locale/en-US.js +50 -1
  19. package/lib/es/locale/es-ES.js +35 -1
  20. package/lib/es/locale/fa-IR.js +35 -1
  21. package/lib/es/locale/fr-FR.js +35 -1
  22. package/lib/es/locale/ja-JP.js +35 -1
  23. package/lib/es/locale/ko-KR.js +35 -1
  24. package/lib/es/locale/ru-RU.js +35 -1
  25. package/lib/es/locale/sk-SK.js +35 -1
  26. package/lib/es/locale/vi-VN.js +35 -1
  27. package/lib/es/locale/zh-CN.js +35 -1
  28. package/lib/es/locale/zh-TW.js +35 -1
  29. package/lib/facade.js +32 -1
  30. package/lib/index.js +2257 -1
  31. package/lib/locale/ca-ES.js +35 -1
  32. package/lib/locale/en-US.js +50 -1
  33. package/lib/locale/es-ES.js +35 -1
  34. package/lib/locale/fa-IR.js +35 -1
  35. package/lib/locale/fr-FR.js +35 -1
  36. package/lib/locale/ja-JP.js +35 -1
  37. package/lib/locale/ko-KR.js +35 -1
  38. package/lib/locale/ru-RU.js +35 -1
  39. package/lib/locale/sk-SK.js +35 -1
  40. package/lib/locale/vi-VN.js +35 -1
  41. package/lib/locale/zh-CN.js +35 -1
  42. package/lib/locale/zh-TW.js +35 -1
  43. package/lib/umd/index.js +1 -1
  44. package/package.json +16 -16
package/lib/index.js CHANGED
@@ -1 +1,2257 @@
1
- import{BuildTextUtils as e,ColorKit as t,CommandType as n,CustomRangeType as r,DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as i,DOCS_NORMAL_EDITOR_UNIT_ID_KEY as a,DOCS_ZEN_EDITOR_UNIT_ID_KEY as o,DataStreamTreeTokenType as s,DataValidationType as c,DependentOn as l,Disposable as u,DisposableCollection as d,FOCUSING_SHEET as f,ICommandService as p,IConfigService as m,IContextService as h,IPermissionService as g,IUniverInstanceService as _,Inject as v,Injector as y,LocaleService as b,ObjectMatrix as x,Plugin as S,RANGE_TYPE as C,Range as w,Rectangle as T,ThemeService as ee,Tools as te,UniverInstanceType as E,generateRandomId as D,isValidRange as O,merge as k}from"@univerjs/core";import{AUTO_FILL_APPLY_TYPE as A,AutoFillTools as j,ClearSelectionAllCommand as ne,ClearSelectionContentCommand as re,ClearSelectionFormatCommand as M,IAutoFillService as N,RangeProtectionPermissionEditPoint as ie,RangeProtectionPermissionViewPoint as ae,SetSelectionsOperation as oe,SetWorksheetActiveOperation as se,SheetPermissionCheckController as ce,SheetsSelectionsService as le,WorkbookCopyPermission as ue,WorkbookEditablePermission as de,WorkbookViewPermission as fe,WorksheetCopyPermission as pe,WorksheetEditPermission as me,WorksheetInsertHyperlinkPermission as he,WorksheetSetCellValuePermission as ge,WorksheetViewPermission as _e,getSheetCommandTarget as ve,rangeToDiscreteRange as ye}from"@univerjs/sheets";import{COPY_TYPE as P,HoverManagerService as be,HoverRenderController as xe,IEditorBridgeService as F,IMarkSelectionService as Se,ISheetClipboardService as Ce,PREDEFINED_HOOK_NAME_PASTE as I,ScrollToRangeOperation as we,SheetCanvasPopManagerService as L,SheetSkeletonManagerService as Te,getCurrentRangeDisable$ as R,getCustomRangePosition as Ee,getEditingCustomRangePosition as De,getRepeatRange as Oe,virtualizeDiscreteRanges as ke,whenSheetEditorFocused as Ae}from"@univerjs/sheets-ui";import{DocSelectionManagerService as je}from"@univerjs/docs";import{DocBackScrollRenderController as Me,DocCanvasPopManagerService as Ne,DocEventManagerService as Pe,DocSelectionRenderService as Fe,UniverDocsUIPlugin as Ie,calcDocRangePositions as Le}from"@univerjs/docs-ui";import{IRenderManagerService as Re}from"@univerjs/engine-render";import{ComponentManager as ze,ContextMenuGroup as Be,ContextMenuPosition as Ve,IMenuManagerService as He,IMessageService as Ue,IShortcutService as We,IZenZoneService as Ge,KeyCode as Ke,MenuItemType as qe,MetaKeys as Je,RibbonInsertGroup as Ye,getMenuHiddenObservable as Xe,useDependency as z,useEvent as Ze,useObservable as Qe}from"@univerjs/ui";import{BehaviorSubject as $e,Observable as et,Subject as tt,combineLatest as nt,debounceTime as rt,map as it,of as B,switchMap as at}from"rxjs";import{Button as ot,FormLayout as st,Input as ct,MessageType as lt,Select as ut,Tooltip as dt,borderClassName as ft,clsx as pt}from"@univerjs/design";import{IDefinedNamesService as mt,deserializeRangeWithSheet as ht,serializeRange as gt,serializeRangeToRefString as _t,serializeRangeWithSheet as vt}from"@univerjs/engine-formula";import{RangeSelector as yt}from"@univerjs/sheets-formula-ui";import{AddHyperLinkCommand as bt,AddHyperLinkMutation as xt,AddRichHyperLinkCommand as St,CancelHyperLinkCommand as Ct,CancelRichHyperLinkCommand as wt,ERROR_RANGE as Tt,HyperLinkModel as Et,RemoveHyperLinkMutation as Dt,SheetHyperLinkType as V,SheetsHyperLinkParserService as Ot,UniverSheetsHyperLinkPlugin as kt,UpdateHyperLinkCommand as At,UpdateRichHyperLinkCommand as jt}from"@univerjs/sheets-hyper-link";import{useCallback as Mt,useEffect as H,useMemo as Nt,useRef as Pt,useState as U}from"react";import{Fragment as Ft,jsx as W,jsxs as It}from"react/jsx-runtime";import{AllBorderIcon as Lt,CopyIcon as Rt,LinkIcon as zt,UnlinkIcon as Bt,WriteIcon as Vt,XlsxMultiIcon as Ht}from"@univerjs/icons";import{SheetDataValidationModel as Ut}from"@univerjs/sheets-data-validation";let G=function(e){return e.EDITING=`editing`,e.VIEWING=`viewing`,e.ZEN_EDITOR=`zen_mode`,e}({});function Wt(e){return te.isLegalUrl(e)}function Gt(e){return/^[a-zA-Z]+:\/\//.test(e)}function Kt(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function qt(e){if(Wt(e)){let t=Gt(e)?e:Kt(e)?`mailto://${e}`:`http://${e}`,n;try{n=new URL(t)}catch{return e}return n.hostname===location.hostname&&n.port===location.port&&n.protocol===location.protocol&&n.pathname===location.pathname&&n.hash&&!n.search?n.hash:t}return e}const Jt=`sheets-hyper-link-ui.config`;Symbol(Jt);const Yt={};function K(e,t){return function(n,r){t(n,r,e)}}function q(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function Xt(e,t){let n=t.getMergeData(),r=t.getMaxColumns()-1,i=t.getMaxRows()-1;if(r<e.endColumn&&(e.endColumn=r),i<e.endRow&&(e.endRow=i),e.rangeType===C.COLUMN||C.ROW)return e;let a=[];return n.forEach(t=>{T.intersects(e,t)&&a.push(t)}),T.realUnion(e,...a)}let J=class{constructor(e,t,n,r,i,a){this._univerInstanceService=e,this._commandService=t,this._definedNamesService=n,this._messageService=r,this._localeService=i,this._configService=a}navigate(e){switch(e.type){case V.URL:this.navigateToOtherWebsite(e.url);break;default:this._navigateToUniver(e.searchObj)}}_navigateToUniver(e){let{gid:t,range:n,rangeid:r}=e,i=this._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET);if(!i)return;let a=i.getUnitId();if(r){let e=this._definedNamesService.getValueById(a,r);if(!e)return;let{formulaOrRefString:t}=e,n=this._definedNamesService.getWorksheetByRef(a,t);if(!n){this._messageService.show({content:this._localeService.t(`hyperLink.message.refError`),type:lt.Error});return}if(n.isSheetHidden()){this._messageService.show({content:this._localeService.t(`hyperLink.message.hiddenSheet`),type:lt.Error});return}this.navigateToDefineName(a,r)}if(t){if(n){let e=ht(n);O(e.range)&&n!==Tt&&this.navigateToRange(a,t,e.range);return}this.navigateToSheetById(a,t)}}async navigateToRange(e,t,n,r){let i=await this.navigateToSheetById(e,t);if(i){let a=Xt(n,i);await this._commandService.executeCommand(oe.id,{unitId:e,subUnitId:t,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(we.id,{range:a,forceTop:r})}}async navigateToSheetById(e,t){let n=this._univerInstanceService.getUnit(e,E.UNIVER_SHEET);if(!n)return!1;let r=n.getActiveSheet();if(!r)return!1;if(r.getSheetId()===t)return r;let i=n.getSheetBySheetId(t);return i?n.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t(`hyperLink.message.hiddenSheet`),type:lt.Error}),!1):await this._commandService.executeCommand(se.id,{unitId:e,subUnitId:t})?i:!1:(this._messageService.show({content:this._localeService.t(`hyperLink.message.noSheet`),type:lt.Error}),!1)}async navigateToDefineName(e,t){return this._definedNamesService.focusRange(e,t),!0}async navigateToOtherWebsite(e){var t;let n=this._configService.getConfig(Jt);if(!(n==null||(t=n.urlHandler)==null)&&t.navigateToOtherWebsite)return n.urlHandler.navigateToOtherWebsite(e);window.open(e,`_blank`,`noopener noreferrer`)}};J=q([K(0,_),K(1,p),K(2,mt),K(3,Ue),K(4,v(b)),K(5,m)],J);function Zt(e){"@babel/helpers - typeof";return Zt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Zt(e)}function Qt(e,t){if(Zt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Zt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function $t(e){var t=Qt(e,`string`);return Zt(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=$t(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var en=class extends u{constructor(...e){super(...e),Y(this,`_customHyperLinks`,new Map)}isBuiltInLinkType(e){return e!==V.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:e})=>e)}findCustomHyperLink(e){return Array.from(this._customHyperLinks.values()).find(t=>t.match(e))}registerCustomHyperLink(e){this._customHyperLinks.set(e.type,e)}getCustomHyperLink(e){return this._customHyperLinks.get(e)}removeCustomHyperLink(e){let{_customHyperLinks:t}=this;t.delete(e)}dispose(){super.dispose(),this._customHyperLinks.clear()}};function tn(e){return e.trim().length===0}function nn(e,t){let[n]=e.split(`,`).map(ht);return!n||!O(n.range)?``:(n.sheetName||(n.sheetName=t),_t(n))}const rn=()=>{var n;let[i,a]=U(``),[c,l]=U(!1),[u,m]=U(``),[g,v]=U(!0),[y,x]=U(V.URL),[S,C]=U(``),w=z(b),T=z(mt),O=z(F),k=z(_),A=z(X),j=Qe(A.currentEditing$),ne=z(Ot),re=z(J),M=z(p),N=z(en),ie=Nt(()=>N.getOptions(),[N]),ae=z(Ge),ce=z(Re),ue=z(Se),de=z(je),fe=z(h),pe=z(ee),me=z(je),[he,ge]=U(!1),_e=z(le),ve=Nt(()=>_e.getCurrentSelections(),[]),ye=Nt(()=>{if(!N.isBuiltInLinkType(y))return N.getCustomHyperLink(y)},[N,y]),[P,be]=U(!1),[xe,Ce]=U(!1),I=Pt(!1),L=k.getCurrentUnitOfType(E.UNIVER_SHEET),Te=(L==null?void 0:L.getActiveSheet().getSheetId())||``,R=Mt(e=>{m(e.replaceAll(s.CUSTOM_RANGE_START,``).replaceAll(s.CUSTOM_RANGE_END,``))},[m]);H(()=>{if((j==null?void 0:j.row)!==void 0&&j.col!==void 0){let{customRange:y,row:b,col:S}=j,{label:w}=j;typeof w==`number`&&(w=`${w}`);let T;if(y){var t,n,i,o;T={id:(t=y==null?void 0:y.rangeId)==null?``:t,display:(n=w)==null?``:n,payload:(i=y==null||(o=y.properties)==null?void 0:o.url)==null?``:i,row:b,column:S}}else if(j.type===G.VIEWING){var s,c,l,u;let t=k.getUnit(j.unitId),n=t==null?void 0:t.getSheetBySheetId(j.subUnitId),i=n==null?void 0:n.getCellRaw(j.row,j.col),a=i==null||(s=i.p)==null||(s=s.body)==null||(s=s.customRanges)==null?void 0:s.find(e=>{var t;return e.rangeType===r.HYPERLINK&&((t=e.properties)==null?void 0:t.url)}),o=i==null?void 0:i.v;i&&(!e.transform.isEmptyDocument((c=i.p)==null||(c=c.body)==null?void 0:c.dataStream)||te.isDefine(o))&&v(!1),T={id:``,display:``,payload:(l=a==null||(u=a.properties)==null?void 0:u.url)==null?``:l,row:b,column:S}}else{var d,f,p,m,h;let t=k.getCurrentUnitForType(E.UNIVER_DOC),n=de.getActiveTextRange(),r=t==null?void 0:t.getBody(),i=n&&r?n:null,a=i&&((d=e.customRange.getCustomRangesInterestsWithSelection(i,(f=r==null?void 0:r.customRanges)==null?[]:f))==null?void 0:d[0]);v(!1),T={id:``,display:(p=w)==null?``:p,payload:(m=a==null||(h=a.properties)==null?void 0:h.url)==null?``:m,row:b,column:S}}a(T.id);let ee=N.findCustomHyperLink(T);if(ee){let e=ee.convert(T);x(e.type),C(e.payload),R(e.display);return}R(T.display);let D=ne.parseHyperLink(T.payload);switch(x(D.type===V.INVALID?V.RANGE:D.type),D.type){case V.URL:C(D.url),D.url===T.display&&(I.current=!0);break;case V.RANGE:{var g,_;let e=D.searchObj,t=vt(e.gid?(g=(_=k.getUnit(j.unitId))==null||(_=_.getSheetBySheetId(e.gid))==null?void 0:_.getName())==null?``:g:``,ht(e.range).range);C(t),t===T.display&&(I.current=!0);break}case V.SHEET:{let e=D.searchObj;C(e.gid);break}case V.DEFINE_NAME:{let e=D.searchObj;C(e.rangeid);break}default:C(``);break}}},[j,re,N,de,k]),H(()=>{let e=null;if(j&&!j.customRangeId&&j.type===G.VIEWING&&te.isDefine(j.row)&&te.isDefine(j.col)){let n=k.getUnit(j.unitId,E.UNIVER_SHEET),r=n==null?void 0:n.getSheetBySheetId(j.subUnitId),i=r==null?void 0:r.getMergedCell(j.row,j.col),a=new t(pe.getColorFromTheme(`primary.600`)).toRgb();e=ue.addShape({range:i==null?{startColumn:j.col,endColumn:j.col,startRow:j.row,endRow:j.row}:i,style:{fill:`rgb(${a.r}, ${a.g}, ${a.b}, 0.12)`,strokeWidth:1,stroke:`#FFBD37`,widgets:{}},primary:null},[],-1)}return()=>{e&&ue.removeShape(e)}},[j,ue,pe,k]),H(()=>{Ce(y===V.RANGE)},[y]),H(()=>{let e=(j==null?void 0:j.type)===G.ZEN_EDITOR?ce.getRenderById(o):ce.getRenderById(O.getCurrentEditorId()),t=new d;if(e){let n=e.with(Fe);n.setReserveRangesStatus(!0),t.add(()=>{n.setReserveRangesStatus(!1)})}return()=>{O.disableForceKeepVisible(),t.dispose()}},[j==null?void 0:j.type,O,ce]),H(()=>(xe&&A.setIsKeepVisible(xe),A.setIsKeepVisible(he),()=>{A.setIsKeepVisible(!1)}),[xe,he,A]),H(()=>()=>{ae.temporaryHidden&&(ae.show(),fe.setContextValue(f,!1))},[fe,ae]),H(()=>{if(xe)return O.enableForceKeepVisible(),()=>{O.disableForceKeepVisible()}},[xe,O]);let Ee=[{label:w.t(`hyperLink.form.link`),value:V.URL},{label:w.t(`hyperLink.form.range`),value:V.RANGE},{label:w.t(`hyperLink.form.worksheet`),value:V.SHEET},{label:w.t(`hyperLink.form.definedName`),value:V.DEFINE_NAME},...ie];if(!L)return;let De=L.getHiddenWorksheets(),Oe=L.getSheets().map(e=>({label:e.getName(),value:e.getSheetId()})).filter(e=>De.indexOf(e.value)===-1),ke=Object.values((n=T.getDefinedNameMap(L.getUnitId()))==null?{}:n).map(e=>({label:e.name,value:e.id})),Ae=(e,t)=>{if(e===V.URL)return qt(t);if(e===V.RANGE){let e=ht(t),n=L.getSheetBySheetName(e.sheetName);if(n)return`#gid=${n.getSheetId()}&range=${gt(e.range)}`}return`#${e}=${t}`},Ne=Ze(e=>{var t;let n=nn(e,((t=L.getActiveSheet())==null?void 0:t.getName())||``);if(!n){C(``);return}C(n),n&&(I.current||!u)&&(R(n),I.current=!0)}),Pe=async()=>{if(g&&tn(u)||!S||y===V.URL&&!Wt(S)){be(!0);return}if(j)if(i){let e=j.type===G.ZEN_EDITOR||j.type===G.EDITING?jt.id:At.id;await M.executeCommand(e,{id:i,unitId:j.unitId,subUnitId:j.subUnitId,payload:{display:g?u:``,payload:Ae(y,S)},row:j.row,column:j.col,documentId:j.type===G.ZEN_EDITOR?o:O.getCurrentEditorId()})}else{let e=j.type===G.ZEN_EDITOR||j.type===G.EDITING?St.id:bt.id;await M.executeCommand(e,{unitId:j.unitId,subUnitId:j.subUnitId,link:{id:D(),row:j.row,column:j.col,payload:Ae(y,S),display:g?u:``},documentId:j.type===G.ZEN_EDITOR?o:O.getCurrentEditorId()})}(j==null?void 0:j.type)===G.VIEWING&&(await M.executeCommand(se.id,{unitId:j.unitId,subUnitId:j.subUnitId}),await M.executeCommand(we.id,{range:{startRow:Math.max(j.row-1,0),endRow:j.row+1,startColumn:Math.max(j.col-1,0),endColumn:j.col+1}})),M.executeCommand(mn.id)};return j?It(`div`,{className:pt(`univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900`,ft),children:[g?W(st,{label:w.t(`hyperLink.form.label`),error:P&&tn(u)?w.t(`hyperLink.form.inputError`):``,children:W(ct,{value:u,onChange:e=>{R(e),I.current=!1},placeholder:w.t(`hyperLink.form.labelPlaceholder`),autoFocus:!0,onKeyDown:e=>{e.keyCode===Ke.ENTER&&Pe()}})}):null,W(st,{label:w.t(`hyperLink.form.type`),children:W(ut,{className:`univer-w-full`,options:Ee,value:y,onChange:e=>{x(e),C(``)}})}),y===V.URL&&W(st,{error:P?S?Wt(S)?``:w.t(`hyperLink.form.linkError`):w.t(`hyperLink.form.inputError`):``,children:W(ct,{value:S,onChange:e=>{C(e),e&&(I.current||!u||u===e)&&(R(e),I.current=!0)},placeholder:w.t(`hyperLink.form.linkPlaceholder`),autoFocus:!0,onKeyDown:e=>{e.keyCode===Ke.ENTER&&Pe()}})}),y===V.RANGE&&W(st,{error:P&&!S?w.t(`hyperLink.form.inputError`):``,children:W(yt,{unitId:L.getUnitId(),subUnitId:Te,maxRangeCount:1,supportAcrossSheet:!0,initialValue:S,resetRange:ve,onChange:(e,t)=>Ne(t),onRangeSelectorDialogVisibleChange:async e=>{if(ge(e),e)j.type===G.ZEN_EDITOR&&(ae.hide(),fe.setContextValue(f,!0)),j.type!==G.VIEWING&&O.enableForceKeepVisible(),l(!0);else{if(await re.navigateToRange(j.unitId,j.subUnitId,{startRow:j.row,endRow:j.row,startColumn:j.col,endColumn:j.col},!0),j.type===G.ZEN_EDITOR){var t,n;await M.executeCommand(oe.id,{unitId:j.unitId,subUnitId:j.subUnitId,selections:[{range:{startRow:j.row,endRow:j.row,startColumn:j.col,endColumn:j.col}}]}),ae.show(),fe.setContextValue(f,!1);let e=(t=ce.getRenderById(o))==null?void 0:t.with(Me),r=(n=me.getTextRanges({unitId:o,subUnitId:o}))==null?void 0:n[0];e&&r&&(e.scrollToRange(r),me.refreshSelection({unitId:o,subUnitId:o}))}O.disableForceKeepVisible(),l(!1)}},onFocusChange:e=>Ce(e)})}),y===V.SHEET&&W(st,{error:P&&!S?w.t(`hyperLink.form.selectError`):``,children:W(ut,{className:`univer-w-full`,options:Oe,value:S,onChange:e=>{var t,n;C(e);let r=(t=Oe.find(t=>t.value===e))==null?void 0:t.label,i=(n=Oe.find(e=>e.value===S))==null?void 0:n.label;r&&(I.current||!u||u===i)&&(R(r),I.current=!0)}})}),y===V.DEFINE_NAME&&W(st,{error:P&&!S?w.t(`hyperLink.form.selectError`):``,children:W(ut,{className:`univer-w-full`,options:ke,value:S,onChange:e=>{var t,n;C(e);let r=(t=ke.find(t=>t.value===e))==null?void 0:t.label,i=(n=ke.find(e=>e.value===S))==null?void 0:n.label;r&&(I.current||!u||u===i)&&(R(r),I.current=!0)}})}),(ye==null?void 0:ye.Form)&&W(ye.Form,{linkId:i,payload:S,display:u,showError:P,setByPayload:I,setDisplay:e=>{R(e),I.current=!0},setPayload:C}),It(`div`,{className:`univer-flex univer-flex-row univer-justify-end univer-gap-2`,children:[W(ot,{onClick:()=>{j&&re.navigateToRange(j.unitId,j.subUnitId,{startRow:j.row,endRow:j.row,startColumn:j.col,endColumn:j.col},!0),M.executeCommand(mn.id)},children:w.t(`hyperLink.form.cancel`)}),W(ot,{variant:`primary`,onClick:async()=>{Pe()},children:w.t(`hyperLink.form.ok`)})]})]}):null};rn.componentKey=`univer.sheet.cell-link-edit`;const an={[V.URL]:W(zt,{}),[V.SHEET]:W(Ht,{className:`univer-text-green-500`}),[V.RANGE]:W(Lt,{}),[V.DEFINE_NAME]:W(Lt,{}),[V.INVALID]:W(Lt,{})},on=e=>{var t,n;let r=z(X),i=z(p),a=z(Ue),s=z(b),c=z(J),l=z(F),u=z(Ot),d=z(Ge),{customRange:f,row:m,col:h,unitId:g,subUnitId:_,editPermission:v,copyPermission:y,type:x}=e;if(!(!(f==null||(t=f.properties)==null)&&t.url))return null;let S=u.parseHyperLink((n=f.properties.url)==null?``:n),C=S.type===V.INVALID;return It(`div`,{className:pt(`univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900`,ft),onClick:()=>r.hideCurrentPopup(),children:[It(`div`,{className:pt(`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600`,{"univer-text-red-500":C}),onClick:()=>{d.visible||C||c.navigate(S)},children:[W(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white`,children:an[S.type]}),W(dt,{showIfEllipsis:!0,title:S.name,asChild:!0,children:W(`span`,{className:`univer-flex-1 univer-truncate`,children:S.name})})]}),It(`div`,{className:`univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center`,children:[y&&W(`div`,{className:pt(`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,{"univer-text-red-500":C}),onClick:()=>{if(!C){if(S.type!==V.URL){let e=new URL(window.location.href);e.hash=S.url.slice(1),navigator.clipboard.writeText(e.href)}else navigator.clipboard.writeText(S.url);a.show({content:s.t(`hyperLink.message.coped`),type:lt.Info})}},children:W(dt,{placement:`bottom`,title:s.t(`hyperLink.popup.copy`),children:W(Rt,{className:`dark:!univer-text-white`})})}),v&&It(Ft,{children:[W(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,onClick:()=>{i.executeCommand(pn.id,{unitId:g,subUnitId:_,row:m,col:h,customRangeId:f.rangeId,type:x})},children:W(dt,{placement:`bottom`,title:s.t(`hyperLink.popup.edit`),children:W(Vt,{className:`dark:!univer-text-white`})})}),W(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,onClick:()=>{let e=x===G.EDITING||x===G.ZEN_EDITOR?wt.id:Ct.id;i.syncExecuteCommand(e,{unitId:g,subUnitId:_,id:f.rangeId,row:m,column:h,documentId:x===G.ZEN_EDITOR?o:l.getCurrentEditorId()})&&r.hideCurrentPopup(void 0,!0)},children:W(dt,{placement:`bottom`,title:s.t(`hyperLink.popup.cancel`),children:W(Bt,{className:`dark:!univer-text-white`})})})]})]})]})},sn=()=>{let e=z(X),[t,n]=U(null),r=z(_);if(H(()=>{n(e.currentPopup);let t=e.currentPopup$.subscribe(e=>{n(e)});return()=>{t.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!t)return null;if(t.showAll){var i;let e=r.getUnit(t.unitId,E.UNIVER_SHEET),n=e==null?void 0:e.getSheetBySheetId(t.subUnitId),a=n==null?void 0:n.getCell(t.row,t.col),o=a==null||(i=a.p)==null||(i=i.body)==null?void 0:i.customRanges;return o!=null&&o.length?W(`div`,{children:o.map(e=>W(on,{...t,customRange:e},e.rangeId))}):null}return W(on,{...t})};sn.componentKey=`univer.sheet.cell-link-popup`;const cn=(e,t)=>{var n,r;return e.unitId===t.unitId&&e.subUnitId===t.subUnitId&&e.row===t.row&&e.col===t.col&&((n=e.customRange)==null?void 0:n.rangeId)===((r=t.customRange)==null?void 0:r.rangeId)&&e.type===t.type};let X=class extends u{get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}constructor(e,t,n,r,i,a,o){super(),this._sheetCanvasPopManagerService=e,this._injector=t,this._univerInstanceService=n,this._editorBridgeService=r,this._textSelectionManagerService=i,this._docCanvasPopManagerService=a,this._zenZoneService=o,Y(this,`_currentPopup`,null),Y(this,`_currentPopup$`,new tt),Y(this,`currentPopup$`,this._currentPopup$.asObservable()),Y(this,`_currentEditingPopup`,null),Y(this,`_currentEditing$`,new $e(null)),Y(this,`currentEditing$`,this._currentEditing$.asObservable()),Y(this,`_isKeepVisible`,!1),this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}setIsKeepVisible(e){this._isKeepVisible=e}getIsKeepVisible(){return this._isKeepVisible}showPopup(e){if(this._currentPopup&&cn(e,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),e.type!==G.ZEN_EDITOR&&this._zenZoneService.visible))return;let t=this._currentEditing$.getValue();if(t&&cn(e,t))return;let{unitId:n,subUnitId:r,row:i,col:a,customRangeRect:s,customRange:c}=e,l,u={componentKey:sn.componentKey,direction:`bottom`,onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(e.type,!0)}};if(e.type===G.EDITING){if(!c)return;l=s&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(s,u)}else if(e.type===G.ZEN_EDITOR){if(!c)return;l=this._docCanvasPopManagerService.attachPopupToRange({startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},u,o)}else if(e.showAll)l=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,u,n,r);else{if(!c)return;l=s&&this._sheetCanvasPopManagerService.attachPopupByPosition(s,u,e)}if(l){if(this._currentPopup){var d;(d=this._currentPopup.disposable)==null||d.dispose()}this._currentPopup={unitId:n,subUnitId:r,disposable:l,row:i,col:a,editPermission:!!e.editPermission,copyPermission:!!e.copyPermission,customRange:c,type:e.type,showAll:e.showAll},this._currentPopup$.next(this._currentPopup)}}hideCurrentPopup(e,t){if(this._currentPopup&&((!e||e===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||t)){var n;(n=this._currentPopup)==null||(n=n.disposable)==null||n.dispose(),this._currentPopup=null,this._currentPopup$.next(null)}}dispose(){super.dispose(),this.hideCurrentPopup(),this.endEditing(),this._currentPopup$.complete(),this._currentEditing$.complete()}_getEditingRange(){let t=this._editorBridgeService.isVisible().visible,n=this._editorBridgeService.getEditCellState();if(t&&n){var i,a,o;let t=this._textSelectionManagerService.getActiveTextRange(),s=(i=n.documentLayoutObject.documentModel)==null?void 0:i.getBody();if(!s)return null;if(!t||t.collapsed)return{startOffset:0,endOffset:s.dataStream.length-2,collapsed:s.dataStream.length-2==0,label:e.transform.getPlainText(s.dataStream)};let c=e.customRange.getCustomRangesInterestsWithSelection(t,(a=(o=s.customRanges)==null?void 0:o.filter(e=>e.rangeType===r.HYPERLINK))==null?[]:a),l=t.startOffset,u=t.endOffset;return c.forEach(e=>{l=Math.min(l,e.startIndex),u=Math.max(u,e.endIndex+1)}),{startOffset:l,endOffset:u,collapsed:l===u,label:e.transform.getPlainText(s.dataStream.slice(l,u))}}return null}get _editPopup(){return{componentKey:rn.componentKey,direction:`vertical`,onClickOutside:()=>{this.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:`hide`}}startAddEditing(t){let{unitId:n,subUnitId:r,type:i}=t;if(i===G.ZEN_EDITOR){var s;let e=this._univerInstanceService.getUnit(o,E.UNIVER_DOC);if(!e)return;let n=this._textSelectionManagerService.getActiveTextRange();if(!n)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(n,this._editPopup,o);let r=(s=e.getBody())==null?void 0:s.dataStream.slice(n.startOffset,n.endOffset);this._currentEditing$.next({...t,label:r})}else if(i===G.EDITING){var c;let e=this._getEditingRange();if(!e)return;this._textSelectionManagerService.replaceDocRanges([{...e}],{unitId:a,subUnitId:a});let i=this._injector.get(Re).getRenderById(a);if(!i)return;let o=Le(e,i);if(!(o!=null&&o.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(o.pop(),this._editPopup,n,r),this._currentEditing$.next({...t,label:(c=e==null?void 0:e.label)==null?``:c})}else{var l,u,d;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,n,r);let i=this._univerInstanceService.getUnit(n,E.UNIVER_SHEET),a=i==null?void 0:i.getSheetBySheetId(r),o=a==null?void 0:a.getCellRaw(t.row,t.col);this._currentEditing$.next({...t,label:o!=null&&o.p?e.transform.getPlainText((l=(u=o.p.body)==null?void 0:u.dataStream)==null?``:l):((d=o==null?void 0:o.v)==null?``:d).toString()})}}startEditing(e){var t;(t=this._currentEditingPopup)==null||t.dispose(),this.hideCurrentPopup(void 0,!0);let{unitId:n,subUnitId:r}=e,i,a;if(e.type===G.ZEN_EDITOR){var s,c;let t=this._univerInstanceService.getUnit(o,E.UNIVER_DOC);if(i=t==null||(s=t.getBody())==null||(s=s.customRanges)==null?void 0:s.find(t=>t.rangeId===e.customRangeId),a=i?t==null||(c=t.getBody())==null?void 0:c.dataStream.slice(i.startIndex,i.endIndex+1):``,!i||!a)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:i.startIndex,endOffset:i.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:i.startIndex,endOffset:i.endIndex,collapsed:!1},this._editPopup,o)}else if(e.type===G.EDITING){var l;let t=De(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!t||!((l=t.rects)!=null&&l.length))return;i=t.customRange,a=t.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:i.startIndex,endOffset:i.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(t.rects.pop(),this._editPopup,n,r)}else{var u;let t=this._univerInstanceService.getUnit(n,E.UNIVER_SHEET),o=t==null?void 0:t.getSheetBySheetId(r),s=o==null?void 0:o.getCellRaw(e.row,e.col),c=t==null?void 0:t.getStyles().getStyleByCell(s),l=c==null?void 0:c.tr,d=Ee(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!d||!((u=d.rects)!=null&&u.length))return;i=d.customRange,a=d.label,l?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,n,r):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(d.rects.pop(),this._editPopup,{unitId:n,subUnitId:r,row:e.row,col:e.col})}this._currentEditing$.next({...e,customRange:i,label:a})}endEditing(e){if(this.getIsKeepVisible())return;let t=this._currentEditing$.getValue();if(t&&(!e||e===t.type)){var n;(n=this._currentEditingPopup)==null||n.dispose(),this._currentEditing$.next(null)}}};X=q([K(0,v(L)),K(1,v(y)),K(2,_),K(3,F),K(4,v(je)),K(5,v(Ne)),K(6,Ge)],X);let Z=function(e){return e[e.ALLOWED=0]=`ALLOWED`,e[e.DISABLED_BY_CELL=1]=`DISABLED_BY_CELL`,e[e.ALLOW_ON_EDITING=2]=`ALLOW_ON_EDITING`,e}({});const ln=new Set([c.CHECKBOX,c.LIST,c.LIST_MULTIPLE]),un=(e,t,n,r)=>{var i,a;let o=t.getCell(n,r);if(o!=null&&o.f||o!=null&&o.si||!(o==null||(i=o.p)==null||(i=i.body)==null||(i=i.customBlocks)==null)&&i.length)return Z.DISABLED_BY_CELL;let s=e.has(Ut)?e.get(Ut):null,c=s==null?void 0:s.getRuleByLocation(t.getUnitId(),t.getSheetId(),n,r);return c&&ln.has(c.type)?!0:!(o==null||(a=o.p)==null||(a=a.drawingsOrder)==null)&&a.length?Z.ALLOW_ON_EDITING:Z.ALLOWED},dn=e=>{let t=e.get(_).getCurrentUnitForType(E.UNIVER_SHEET);if(!t)return!0;let n=t.getActiveSheet(),r=e.get(le).getCurrentSelections();if(!r.length)return!0;let i=r[0].range.startRow,a=r[0].range.startColumn;return un(e,n,i,a)===Z.DISABLED_BY_CELL},fn=e=>{let t=e.get(je),n=e.get(_),r=t.getTextRanges();if(!(r!=null&&r.length))return!0;let i=n.getCurrentUnitForType(E.UNIVER_DOC);return!!(!i||r.every(e=>e.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},pn={type:n.OPERATION,id:`sheet.operation.open-hyper-link-edit-panel`,handler(e,t){if(!t)return!1;let n=e.get(X);return t.customRangeId?n.startEditing(t):n.startAddEditing(t),!0}},mn={type:n.OPERATION,id:`sheet.operation.close-hyper-link-popup`,handler(e){return e.get(X).endEditing(),!0}},hn={type:n.OPERATION,id:`sheet.operation.insert-hyper-link`,handler(e){var t;let n=e.get(_),r=ve(n),i=e.get(F);if(!r)return!1;let a=e.get(p),s=e.get(le).getCurrentLastSelection();if(!s)return!1;let c=s.range.startRow,l=s.range.startColumn,u=i.isVisible(),d=((t=n.getFocusedUnit())==null?void 0:t.getUnitId())===o;return a.executeCommand(pn.id,{unitId:r.unitId,subUnitId:r.subUnitId,row:c,col:l,type:d?G.ZEN_EDITOR:u.visible?G.EDITING:G.VIEWING})}},Q={type:n.OPERATION,id:`sheet.operation.insert-hyper-link-toolbar`,handler(e){if(dn(e))return!1;let t=e.get(p);return e.get(X).currentEditing?t.executeCommand(mn.id):t.executeCommand(hn.id)}},gn=`SHEET_HYPER_LINK_UI_PLUGIN`;let _n=class extends u{registerPlainTextFilter(e){this._plainTextFilter.add(e)}removePlainTextFilter(e){this._plainTextFilter.delete(e)}_filterPlainText(e){return Array.from(this._plainTextFilter).every(t=>t(e))}constructor(e,t,n,r){super(),this._sheetClipboardService=e,this._hyperLinkModel=t,this._injector=n,this._resolverService=r,Y(this,`_plainTextFilter`,new Set),Y(this,`_copyInfo`,void 0),this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:gn,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=P.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})},onPastePlainText:(e,t)=>{let n=this._filterPlainText(t);if(Wt(t)&&n){let{range:t,unitId:n,subUnitId:r}=e,{ranges:[i],mapFunc:a}=ke([t]),o=[],s=[];return w.foreach(i,(e,t)=>{let{row:i,col:c}=a(e,t),l=this._hyperLinkModel.getHyperLinkByLocation(n,r,i,c);l&&o.push({id:Dt.id,params:{unitId:n,subUnitId:r,id:l.id}}),l&&s.push({id:xt.id,params:{unitId:n,subUnitId:r,link:l}})}),{redos:o,undos:s}}return{undos:[],redos:[]}},priority:99})}_collect(e,t,n){let r=new x;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>ye(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{var s;let c=this._hyperLinkModel.getHyperLinkByLocation(e,t,n,a);r.setValue(i,o,(s=c==null?void 0:c.id)==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo||!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[I.SPECIAL_PASTE_COL_WIDTH,I.SPECIAL_PASTE_VALUE,I.SPECIAL_PASTE_FORMAT,I.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo,i=[],a=[],{ranges:[o,s],mapFunc:c}=ke([t.copyRange,e]);return Oe(o,s,!0).forEach(({startRange:e})=>{var o;(o=this._copyInfo)==null||o.matrix.forValue((o,s,l)=>{let u=T.getPositionRange({startRow:o,endRow:o,startColumn:s,endColumn:s},e),d=this._hyperLinkModel.getHyperLink(n,r,l),{row:f,col:p}=c(u.startRow,u.startColumn),m=this._hyperLinkModel.getHyperLinkByLocation(t.unitId,t.subUnitId,f,p),h=D();m&&i.push({id:Dt.id,params:{unitId:t.unitId,subUnitId:t.subUnitId,id:m.id}}),d&&(i.push({id:xt.id,params:{unitId:t.unitId,subUnitId:t.subUnitId,link:{...d,id:h,row:f,column:p}}}),a.push({id:Dt.id,params:{unitId:t.unitId,subUnitId:t.subUnitId,id:h}})),m&&a.push({id:xt.id,params:{unitId:t.unitId,subUnitId:t.subUnitId,link:m}})})}),{redos:i,undos:a}}};_n=q([K(0,Ce),K(1,v(Et)),K(2,v(y)),K(3,v(J))],_n);const vn=(e,t=o)=>{var n;let r=e.get(_),i=(n=e.get(Re).getRenderById(t))==null?void 0:n.with(Fe);return i?i.textSelectionInner$.pipe(it(()=>{let t=e.get(F).getEditCellState();if(!t)return!0;let n=ve(r,{unitId:t.unitId,subUnitId:t.sheetId});return!(n!=null&&n.worksheet)||un(e,n.worksheet,t.row,t.column)===1?!0:fn(e)})):B(!0)},yn=e=>{var t;let n=e.get(_),r=e.has(F)?e.get(F):null;return((t=r==null?void 0:r.currentEditCellState$.pipe(it(t=>{if(!t)return Z.DISABLED_BY_CELL;let r=ve(n,{unitId:t.unitId,subUnitId:t.sheetId});return r?un(e,r.worksheet,t.row,t.column):Z.DISABLED_BY_CELL}),at(t=>t===Z.DISABLED_BY_CELL?B(!0):nt([r?r.visible$:B(null),n.getCurrentTypeOfUnit$(E.UNIVER_DOC)]).pipe(at(([n,r])=>n!=null&&n.visible?(r==null?void 0:r.getUnitId())===i?B(!0):vn(e,a):B(t!==Z.ALLOWED))))))==null?B(!0):t).pipe(at(t=>t?B(!0):R(e,{workbookTypes:[de],worksheetTypes:[me,ge,he],rangeTypes:[ie]},!0)))},bn={commandId:hn.id,type:qe.BUTTON,title:`hyperLink.menu.add`,icon:`LinkIcon`},xn=e=>`${e}-zen-editor`,Sn=e=>({...bn,id:bn.commandId,hidden$:Xe(e,E.UNIVER_SHEET),disabled$:yn(e)}),Cn=e=>({...bn,id:xn(bn.commandId),hidden$:Xe(e,E.UNIVER_DOC,o),disabled$:vn(e)}),wn={tooltip:`hyperLink.form.addTitle`,commandId:Q.id,type:qe.BUTTON,icon:`LinkIcon`},Tn=e=>({...wn,id:wn.commandId,hidden$:Xe(e,E.UNIVER_SHEET),disabled$:yn(e)}),En=e=>({...wn,id:xn(wn.commandId),hidden$:Xe(e,E.UNIVER_DOC,o),disabled$:vn(e)}),Dn={id:Q.id,binding:Ke.K|Je.CTRL_COMMAND,preconditions:Ae};var On=`@univerjs/sheets-hyper-link-ui`,kn=`0.20.1`;let An=class extends u{constructor(e,t){super(),this._autoFillService=e,this._hyperLinkModel=t,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=ke([n,r]),[s,c]=o.ranges,{mapFunc:l}=o,u={row:s.startRow,col:s.startColumn},d=j.getAutoFillRepeatRange(s,c),f=[],p=[];return d.forEach(e=>{let n=e.repeatStartCell,r=e.relativeRange,o={startRow:u.row,startColumn:u.col,endColumn:u.col,endRow:u.row},s={startRow:n.row,startColumn:n.col,endColumn:n.col,endRow:n.row};w.foreach(r,(e,n)=>{let r=T.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},o),{row:c,col:u}=l(r.startRow,r.startColumn),d=this._hyperLinkModel.getHyperLinkByLocation(i,a,c,u),m=T.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},s),{row:h,col:g}=l(m.startRow,m.startColumn),_=D(),v=this._hyperLinkModel.getHyperLinkByLocation(i,a,h,g);v&&f.push({id:Dt.id,params:{unitId:i,subUnitId:a,id:v.id}}),(A.COPY===t||A.SERIES===t)&&d&&(f.push({id:xt.id,params:{unitId:i,subUnitId:a,link:{...d,id:_,row:h,column:g}}}),p.push({id:Dt.id,params:{unitId:i,subUnitId:a,id:_}})),v&&p.push({id:xt.id,params:{unitId:i,subUnitId:a,link:v}})})}),{undos:p,redos:f}},n={id:gn,onFillData:(n,r,i)=>i===A.COPY||i===A.ONLY_FORMAT||i===A.SERIES?t(n,i):e()};this.disposeWithMe(this._autoFillService.addHook(n))}};An=q([K(0,N),K(1,v(Et))],An);let jn=class extends u{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===Dn.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[de],rangeTypes:[ie],worksheetTypes:[me,ge,he]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.hyperLinkErr`)))}))}};jn=q([K(0,v(b)),K(1,p),K(2,v(ce))],jn);let Mn=class extends u{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=t,this._renderManagerService=n,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=a,this._editorBridgeService=o,this._textSelectionManagerService=s,this._univerInstanceService=c,this._zenZoneService=l,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(e){let{unitId:t,subUnitId:n,row:r,col:i}=e,a=this._univerInstanceService.getUnit(t,E.UNIVER_SHEET),o=a==null?void 0:a.getSheetBySheetId(n);if(!o)return{viewPermission:!1,editPermission:!1,copyPermission:!1};let s=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[fe],worksheetTypes:[_e],rangeTypes:[ae]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],t,n),c=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[de],worksheetTypes:[me,he],rangeTypes:[ie]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],t,n),l=o.getCellRaw(r,i);l!=null&&l.f&&l.f.startsWith(`=HYPERLINK(`)&&(c=!1);let u=this._permissionService.composePermission([new ue(t).id,new pe(t,n).id]).every(e=>e.value);return{viewPermission:s,editPermission:c,copyPermission:u}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(rt(200)).subscribe(e=>{var t,n,i;if(!e||((t=e.customRange)==null?void 0:t.rangeType)!==r.HYPERLINK){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}let{unitId:a,subUnitId:o,row:s,col:c}=e,l=this._renderManagerService.getRenderById(a);if(!l)return;let u=this._univerInstanceService.getUnit(a,E.UNIVER_SHEET),d=u==null?void 0:u.getSheetBySheetId(o);if(!d)return;if(!l.with(xe).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(G.VIEWING);return}let f=l==null||(n=l.with(Te).getSkeletonParam(o))==null?void 0:n.skeleton,p=c,m=s,h=m,g=p;f&&f.overflowCache.forValue((e,t,n)=>{T.contains(n,{startColumn:p,endColumn:p,startRow:m,endRow:m})&&(h=e,g=t)});let{viewPermission:_,editPermission:v,copyPermission:y}=this._getLinkPermission(e);if(!_){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}let b=d.getCellStyleOnly(h,g),x=u.getStyles().getStyleByCell(b),S=x==null||(i=x.tr)==null?void 0:i.a;if(!S&&!e.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:h,col:g,editPermission:v,copyPermission:y,customRange:e.customRange,customRangeRect:e.rect,type:G.VIEWING,unitId:a,subUnitId:o,showAll:!!S})}))}_initHoverEditingListener(){let e=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(at(e=>this._editorBridgeService.visible$.pipe(it(t=>({visible:t,state:e}))))).subscribe(({visible:t,state:n})=>{if(!n||n.editorUnitId!==a)return;if(!t.visible){e==null||e.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(G.EDITING),this._sheetsHyperLinkPopupService.endEditing(G.EDITING);return}let{editorUnitId:i,unitId:o,sheetId:s,row:c,column:l}=n,u=this._renderManagerService.getRenderById(i);if(!u)return;let{editPermission:d,viewPermission:f,copyPermission:p}=this._getLinkPermission({unitId:o,subUnitId:s,row:c,col:l}),m=u.with(Pe);f&&(e==null||e.unsubscribe(),e=m.hoverCustomRanges$.pipe(rt(200)).subscribe(e=>{var t;let n=e.find(e=>e.range.rangeType===r.HYPERLINK);if(!n){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}let i=n.rects[n.rects.length-1];if(!(!((t=this._renderManagerService.getRenderById(o))==null||(t=t.with(Te).getSkeletonParam(s))==null)&&t.skeleton)||!i)return;let a=u.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:o,subUnitId:s,row:c,col:l,customRange:n.range,customRangeRect:{left:i.left+a.left,top:i.top+a.top,bottom:i.bottom+a.top,right:i.right+a.left},editPermission:d,copyPermission:p,type:G.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(G.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(G.EDITING),this._sheetsHyperLinkPopupService.endEditing(G.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(G.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(G.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(G.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(at(e=>{let t=e===o?this._renderManagerService.getRenderById(e):null;return t?t.with(Pe).hoverCustomRanges$.pipe(rt(200)):new et(e=>{e.next(null)})})).subscribe(e=>{let t=e==null?void 0:e.find(e=>e.range.rangeType===r.HYPERLINK),n=this._editorBridgeService.getEditCellState();if(t&&n){let{unitId:e,sheetId:r,row:i,column:a}=n,{editPermission:o,viewPermission:s,copyPermission:c}=this._getLinkPermission({unitId:e,subUnitId:r,row:i,col:a});s&&this._sheetsHyperLinkPopupService.showPopup({type:G.ZEN_EDITOR,unitId:e,subUnitId:r,row:i,col:a,customRange:t.range,editPermission:o,copyPermission:c})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(G.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===a&&this._sheetsHyperLinkPopupService.endEditing(G.EDITING)}))}_initCommandListener(){let e=[re.id,ne.id,M.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{e.includes(t.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Mn=q([K(0,v(be)),K(1,v(X)),K(2,v(Re)),K(3,v(g)),K(4,v(ce)),K(5,p),K(6,F),K(7,v(je)),K(8,_),K(9,Ge)],Mn);let Nn=class extends u{constructor(e,t){super(),this._context=e,this._hyperLinkModel=t,this._initSkeletonChange()}_initSkeletonChange(){let e=()=>{var e;(e=this._context.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(rt(16)).subscribe(()=>{e()}))}};Nn=q([K(1,v(Et))],Nn);const Pn={[Ye.MEDIA]:{[Q.id]:{order:1,menuItemFactory:Tn},[xn(Q.id)]:{order:1,menuItemFactory:En}},[Ve.MAIN_AREA]:{[Be.OTHERS]:{order:1,[Q.id]:{order:0,menuItemFactory:Sn},[xn(Q.id)]:{order:0,menuItemFactory:Cn}}}};let Fn=class extends u{constructor(e,t,n,r,i){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._injector=r,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[sn.componentKey,sn],[rn.componentKey,rn],[`LinkIcon`,zt]].forEach(([e,t])=>{this._componentManager.register(e,t)})}_initCommands(){[pn,mn,hn,Q].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(Pn)}_initShortCut(){this._shortcutService.registerShortcut(Dn)}};Fn=q([K(0,v(ze)),K(1,p),K(2,He),K(3,v(y)),K(4,v(We))],Fn);let In=class extends u{constructor(e,t){super(),this._parserService=e,this._resolverService=t,this._handleInitUrl()}_handleInitUrl(){let e=location.hash;if(e){let t=this._parserService.parseHyperLink(e);this._resolverService.navigate(t)}}};In=q([K(0,v(Ot)),K(1,v(J))],In);let $=class extends S{constructor(e=Yt,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=k({},Yt,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(Jt,i)}onStarting(){[[J],[X],[en],[Mn],[Fn],[An],[_n],[jn],[In]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(Re).registerRenderModule(E.UNIVER_SHEET,[Nn]),this._injector.get(An),this._injector.get(_n),this._injector.get(Fn)}onRendered(){this._injector.get(jn),this._injector.get(In),this._injector.get(Mn)}};Y($,`pluginName`,gn),Y($,`packageName`,On),Y($,`version`,kn),Y($,`type`,E.UNIVER_SHEET),$=q([l(kt,Ie),K(1,v(y)),K(2,m)],$);export{mn as CloseHyperLinkPopupOperation,hn as InsertHyperLinkOperation,Dn as InsertLinkShortcut,pn as OpenHyperLinkEditPanelOperation,_n as SheetsHyperLinkCopyPasteController,X as SheetsHyperLinkPopupService,J as SheetsHyperLinkResolverService,en as SheetsHyperLinkSidePanelService,$ as UniverSheetsHyperLinkUIPlugin};
1
+ import { BuildTextUtils, ColorKit, CommandType, CustomRangeType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DataStreamTreeTokenType, DataValidationType, DependentOn, Disposable, DisposableCollection, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IPermissionService, IUniverInstanceService, Inject, Injector, LocaleService, ObjectMatrix, Plugin, RANGE_TYPE, Range, Rectangle, ThemeService, Tools, UniverInstanceType, generateRandomId, isValidRange, merge } from "@univerjs/core";
2
+ import { AUTO_FILL_APPLY_TYPE, AutoFillTools, ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, IAutoFillService, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, SetSelectionsOperation, SetWorksheetActiveOperation, SheetPermissionCheckController, SheetsSelectionsService, WorkbookCopyPermission, WorkbookEditablePermission, WorkbookViewPermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission, WorksheetViewPermission, getSheetCommandTarget, rangeToDiscreteRange } from "@univerjs/sheets";
3
+ import { COPY_TYPE, HoverManagerService, HoverRenderController, IEditorBridgeService, IMarkSelectionService, ISheetClipboardService, PREDEFINED_HOOK_NAME_PASTE, ScrollToRangeOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, getCurrentRangeDisable$, getCustomRangePosition, getEditingCustomRangePosition, getRepeatRange, virtualizeDiscreteRanges, whenSheetEditorFocused } from "@univerjs/sheets-ui";
4
+ import { DocSelectionManagerService } from "@univerjs/docs";
5
+ import { DocBackScrollRenderController, DocCanvasPopManagerService, DocEventManagerService, DocSelectionRenderService, UniverDocsUIPlugin, calcDocRangePositions } from "@univerjs/docs-ui";
6
+ import { IRenderManagerService } from "@univerjs/engine-render";
7
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IShortcutService, IZenZoneService, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useEvent, useObservable } from "@univerjs/ui";
8
+ import { BehaviorSubject, Observable, Subject, combineLatest, debounceTime, map, of, switchMap } from "rxjs";
9
+ import { Button, FormLayout, Input, MessageType, Select, Tooltip, borderClassName, clsx } from "@univerjs/design";
10
+ import { IDefinedNamesService, deserializeRangeWithSheet, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from "@univerjs/engine-formula";
11
+ import { RangeSelector } from "@univerjs/sheets-formula-ui";
12
+ import { AddHyperLinkCommand, AddHyperLinkMutation, AddRichHyperLinkCommand, CancelHyperLinkCommand, CancelRichHyperLinkCommand, ERROR_RANGE, HyperLinkModel, RemoveHyperLinkMutation, SheetHyperLinkType, SheetsHyperLinkParserService, UniverSheetsHyperLinkPlugin, UpdateHyperLinkCommand, UpdateRichHyperLinkCommand } from "@univerjs/sheets-hyper-link";
13
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
14
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
+ import { AllBorderIcon, CopyIcon, LinkIcon, UnlinkIcon, WriteIcon, XlsxMultiIcon } from "@univerjs/icons";
16
+ import { SheetDataValidationModel } from "@univerjs/sheets-data-validation";
17
+
18
+ //#region src/types/enums/edit-source.ts
19
+ /**
20
+ * Copyright 2023-present DreamNum Co., Ltd.
21
+ *
22
+ * Licensed under the Apache License, Version 2.0 (the "License");
23
+ * you may not use this file except in compliance with the License.
24
+ * You may obtain a copy of the License at
25
+ *
26
+ * http://www.apache.org/licenses/LICENSE-2.0
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ let HyperLinkEditSourceType = /* @__PURE__ */ function(HyperLinkEditSourceType) {
35
+ HyperLinkEditSourceType["EDITING"] = "editing";
36
+ HyperLinkEditSourceType["VIEWING"] = "viewing";
37
+ HyperLinkEditSourceType["ZEN_EDITOR"] = "zen_mode";
38
+ return HyperLinkEditSourceType;
39
+ }({});
40
+
41
+ //#endregion
42
+ //#region src/common/util.ts
43
+ /**
44
+ * Copyright 2023-present DreamNum Co., Ltd.
45
+ *
46
+ * Licensed under the Apache License, Version 2.0 (the "License");
47
+ * you may not use this file except in compliance with the License.
48
+ * You may obtain a copy of the License at
49
+ *
50
+ * http://www.apache.org/licenses/LICENSE-2.0
51
+ *
52
+ * Unless required by applicable law or agreed to in writing, software
53
+ * distributed under the License is distributed on an "AS IS" BASIS,
54
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55
+ * See the License for the specific language governing permissions and
56
+ * limitations under the License.
57
+ */
58
+ function isLegalLink(link) {
59
+ return Tools.isLegalUrl(link);
60
+ }
61
+ function hasProtocol(urlString) {
62
+ return /^[a-zA-Z]+:\/\//.test(urlString);
63
+ }
64
+ function isEmail(url) {
65
+ return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
66
+ }
67
+ function serializeUrl(urlStr) {
68
+ if (isLegalLink(urlStr)) {
69
+ const transformedUrl = hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `http://${urlStr}`;
70
+ let url;
71
+ try {
72
+ url = new URL(transformedUrl);
73
+ } catch {
74
+ return urlStr;
75
+ }
76
+ if (url.hostname === location.hostname && url.port === location.port && url.protocol === location.protocol && url.pathname === location.pathname && url.hash && !url.search) return url.hash;
77
+ return transformedUrl;
78
+ }
79
+ return urlStr;
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/config/config.ts
84
+ const SHEETS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "sheets-hyper-link-ui.config";
85
+ const configSymbol = Symbol(SHEETS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
86
+ const defaultPluginConfig = {};
87
+
88
+ //#endregion
89
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
90
+ function __decorateParam(paramIndex, decorator) {
91
+ return function(target, key) {
92
+ decorator(target, key, paramIndex);
93
+ };
94
+ }
95
+
96
+ //#endregion
97
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
98
+ function __decorate(decorators, target, key, desc) {
99
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
100
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
101
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
102
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
103
+ }
104
+
105
+ //#endregion
106
+ //#region src/services/resolver.service.ts
107
+ function getContainRange(range, worksheet) {
108
+ const mergedCells = worksheet.getMergeData();
109
+ const maxCol = worksheet.getMaxColumns() - 1;
110
+ const maxRow = worksheet.getMaxRows() - 1;
111
+ if (maxCol < range.endColumn) range.endColumn = maxCol;
112
+ if (maxRow < range.endRow) range.endRow = maxRow;
113
+ if (range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW) return range;
114
+ const relativeCells = [];
115
+ mergedCells.forEach((cell) => {
116
+ if (Rectangle.intersects(range, cell)) relativeCells.push(cell);
117
+ });
118
+ return Rectangle.realUnion(range, ...relativeCells);
119
+ }
120
+ let SheetsHyperLinkResolverService = class SheetsHyperLinkResolverService {
121
+ constructor(_univerInstanceService, _commandService, _definedNamesService, _messageService, _localeService, _configService) {
122
+ this._univerInstanceService = _univerInstanceService;
123
+ this._commandService = _commandService;
124
+ this._definedNamesService = _definedNamesService;
125
+ this._messageService = _messageService;
126
+ this._localeService = _localeService;
127
+ this._configService = _configService;
128
+ }
129
+ navigate(info) {
130
+ switch (info.type) {
131
+ case SheetHyperLinkType.URL:
132
+ this.navigateToOtherWebsite(info.url);
133
+ break;
134
+ default: this._navigateToUniver(info.searchObj);
135
+ }
136
+ }
137
+ _navigateToUniver(params) {
138
+ const { gid, range, rangeid } = params;
139
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
140
+ if (!workbook) return;
141
+ const unitId = workbook.getUnitId();
142
+ if (rangeid) {
143
+ const item = this._definedNamesService.getValueById(unitId, rangeid);
144
+ if (!item) return;
145
+ const { formulaOrRefString } = item;
146
+ const worksheet = this._definedNamesService.getWorksheetByRef(unitId, formulaOrRefString);
147
+ if (!worksheet) {
148
+ this._messageService.show({
149
+ content: this._localeService.t("hyperLink.message.refError"),
150
+ type: MessageType.Error
151
+ });
152
+ return;
153
+ }
154
+ if (worksheet.isSheetHidden()) {
155
+ this._messageService.show({
156
+ content: this._localeService.t("hyperLink.message.hiddenSheet"),
157
+ type: MessageType.Error
158
+ });
159
+ return;
160
+ }
161
+ this.navigateToDefineName(unitId, rangeid);
162
+ }
163
+ if (!gid) return;
164
+ if (range) {
165
+ const rangeInfo = deserializeRangeWithSheet(range);
166
+ if (isValidRange(rangeInfo.range) && range !== ERROR_RANGE) this.navigateToRange(unitId, gid, rangeInfo.range);
167
+ return;
168
+ }
169
+ this.navigateToSheetById(unitId, gid);
170
+ }
171
+ async navigateToRange(unitId, subUnitId, range, forceTop) {
172
+ const worksheet = await this.navigateToSheetById(unitId, subUnitId);
173
+ if (worksheet) {
174
+ const realRange = getContainRange(range, worksheet);
175
+ await this._commandService.executeCommand(SetSelectionsOperation.id, {
176
+ unitId,
177
+ subUnitId,
178
+ selections: [{
179
+ range: realRange,
180
+ primary: null
181
+ }]
182
+ });
183
+ await this._commandService.executeCommand(ScrollToRangeOperation.id, {
184
+ range: realRange,
185
+ forceTop
186
+ });
187
+ }
188
+ }
189
+ async navigateToSheetById(unitId, subUnitId) {
190
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
191
+ if (!workbook) return false;
192
+ const worksheet = workbook.getActiveSheet();
193
+ if (!worksheet) return false;
194
+ if (worksheet.getSheetId() === subUnitId) return worksheet;
195
+ const targetSheet = workbook.getSheetBySheetId(subUnitId);
196
+ if (!targetSheet) {
197
+ this._messageService.show({
198
+ content: this._localeService.t("hyperLink.message.noSheet"),
199
+ type: MessageType.Error
200
+ });
201
+ return false;
202
+ }
203
+ if (workbook.getHiddenWorksheets().indexOf(subUnitId) > -1) {
204
+ this._messageService.show({
205
+ content: this._localeService.t("hyperLink.message.hiddenSheet"),
206
+ type: MessageType.Error
207
+ });
208
+ return false;
209
+ }
210
+ if (await this._commandService.executeCommand(SetWorksheetActiveOperation.id, {
211
+ unitId,
212
+ subUnitId
213
+ })) return targetSheet;
214
+ return false;
215
+ }
216
+ async navigateToDefineName(unitId, rangeId) {
217
+ this._definedNamesService.focusRange(unitId, rangeId);
218
+ return true;
219
+ }
220
+ async navigateToOtherWebsite(url) {
221
+ var _config$urlHandler;
222
+ const config = this._configService.getConfig(SHEETS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
223
+ if (config === null || config === void 0 || (_config$urlHandler = config.urlHandler) === null || _config$urlHandler === void 0 ? void 0 : _config$urlHandler.navigateToOtherWebsite) return config.urlHandler.navigateToOtherWebsite(url);
224
+ window.open(url, "_blank", "noopener noreferrer");
225
+ }
226
+ };
227
+ SheetsHyperLinkResolverService = __decorate([
228
+ __decorateParam(0, IUniverInstanceService),
229
+ __decorateParam(1, ICommandService),
230
+ __decorateParam(2, IDefinedNamesService),
231
+ __decorateParam(3, IMessageService),
232
+ __decorateParam(4, Inject(LocaleService)),
233
+ __decorateParam(5, IConfigService)
234
+ ], SheetsHyperLinkResolverService);
235
+
236
+ //#endregion
237
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
238
+ function _typeof(o) {
239
+ "@babel/helpers - typeof";
240
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
241
+ return typeof o;
242
+ } : function(o) {
243
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
244
+ }, _typeof(o);
245
+ }
246
+
247
+ //#endregion
248
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
249
+ function toPrimitive(t, r) {
250
+ if ("object" != _typeof(t) || !t) return t;
251
+ var e = t[Symbol.toPrimitive];
252
+ if (void 0 !== e) {
253
+ var i = e.call(t, r || "default");
254
+ if ("object" != _typeof(i)) return i;
255
+ throw new TypeError("@@toPrimitive must return a primitive value.");
256
+ }
257
+ return ("string" === r ? String : Number)(t);
258
+ }
259
+
260
+ //#endregion
261
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
262
+ function toPropertyKey(t) {
263
+ var i = toPrimitive(t, "string");
264
+ return "symbol" == _typeof(i) ? i : i + "";
265
+ }
266
+
267
+ //#endregion
268
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
269
+ function _defineProperty(e, r, t) {
270
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
271
+ value: t,
272
+ enumerable: !0,
273
+ configurable: !0,
274
+ writable: !0
275
+ }) : e[r] = t, e;
276
+ }
277
+
278
+ //#endregion
279
+ //#region src/services/side-panel.service.ts
280
+ var SheetsHyperLinkSidePanelService = class extends Disposable {
281
+ constructor(..._args) {
282
+ super(..._args);
283
+ _defineProperty(this, "_customHyperLinks", /* @__PURE__ */ new Map());
284
+ }
285
+ isBuiltInLinkType(type) {
286
+ return type !== SheetHyperLinkType.URL;
287
+ }
288
+ getOptions() {
289
+ return Array.from(this._customHyperLinks.values()).map(({ option }) => option);
290
+ }
291
+ findCustomHyperLink(link) {
292
+ return Array.from(this._customHyperLinks.values()).find((item) => item.match(link));
293
+ }
294
+ registerCustomHyperLink(customHyperLink) {
295
+ this._customHyperLinks.set(customHyperLink.type, customHyperLink);
296
+ }
297
+ getCustomHyperLink(type) {
298
+ return this._customHyperLinks.get(type);
299
+ }
300
+ removeCustomHyperLink(type) {
301
+ const { _customHyperLinks } = this;
302
+ _customHyperLinks.delete(type);
303
+ }
304
+ dispose() {
305
+ super.dispose();
306
+ this._customHyperLinks.clear();
307
+ }
308
+ };
309
+
310
+ //#endregion
311
+ //#region src/views/CellLinkEdit/utils.ts
312
+ /**
313
+ * Copyright 2023-present DreamNum Co., Ltd.
314
+ *
315
+ * Licensed under the Apache License, Version 2.0 (the "License");
316
+ * you may not use this file except in compliance with the License.
317
+ * You may obtain a copy of the License at
318
+ *
319
+ * http://www.apache.org/licenses/LICENSE-2.0
320
+ *
321
+ * Unless required by applicable law or agreed to in writing, software
322
+ * distributed under the License is distributed on an "AS IS" BASIS,
323
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
324
+ * See the License for the specific language governing permissions and
325
+ * limitations under the License.
326
+ */
327
+ function isBlankInput(value) {
328
+ return value.trim().length === 0;
329
+ }
330
+ function resolveRangePayload(rangeText, defaultSheetName) {
331
+ const [range] = rangeText.split(",").map(deserializeRangeWithSheet);
332
+ if (!range || !isValidRange(range.range)) return "";
333
+ if (!range.sheetName) range.sheetName = defaultSheetName;
334
+ return serializeRangeToRefString(range);
335
+ }
336
+
337
+ //#endregion
338
+ //#region src/views/CellLinkEdit/index.tsx
339
+ const CellLinkEdit = () => {
340
+ var _definedNameService$g;
341
+ const [id, setId] = useState("");
342
+ const [hide, setHide] = useState(false);
343
+ const [display, _setDisplay] = useState("");
344
+ const [showLabel, setShowLabel] = useState(true);
345
+ const [type, setType] = useState(SheetHyperLinkType.URL);
346
+ const [payload, setPayload] = useState("");
347
+ const localeService = useDependency(LocaleService);
348
+ const definedNameService = useDependency(IDefinedNamesService);
349
+ const editorBridgeService = useDependency(IEditorBridgeService);
350
+ const univerInstanceService = useDependency(IUniverInstanceService);
351
+ const popupService = useDependency(SheetsHyperLinkPopupService);
352
+ const editing = useObservable(popupService.currentEditing$);
353
+ const parserService = useDependency(SheetsHyperLinkParserService);
354
+ const resolverService = useDependency(SheetsHyperLinkResolverService);
355
+ const commandService = useDependency(ICommandService);
356
+ const sidePanelService = useDependency(SheetsHyperLinkSidePanelService);
357
+ const sidePanelOptions = useMemo(() => sidePanelService.getOptions(), [sidePanelService]);
358
+ const zenZoneService = useDependency(IZenZoneService);
359
+ const renderManagerService = useDependency(IRenderManagerService);
360
+ const markSelectionService = useDependency(IMarkSelectionService);
361
+ const textSelectionService = useDependency(DocSelectionManagerService);
362
+ const contextService = useDependency(IContextService);
363
+ const themeService = useDependency(ThemeService);
364
+ const docSelectionManagerService = useDependency(DocSelectionManagerService);
365
+ const [selectorDialogVisible, setSelectorDialogVisible] = useState(false);
366
+ const sheetsSelectionService = useDependency(SheetsSelectionsService);
367
+ const selections = useMemo(() => sheetsSelectionService.getCurrentSelections(), []);
368
+ const customHyperLinkSidePanel = useMemo(() => {
369
+ if (sidePanelService.isBuiltInLinkType(type)) return;
370
+ return sidePanelService.getCustomHyperLink(type);
371
+ }, [sidePanelService, type]);
372
+ const [showError, setShowError] = useState(false);
373
+ const [isFocusRangeSelector, setIsFocusRangeSelector] = useState(false);
374
+ const setByPayload = useRef(false);
375
+ const workbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
376
+ const subUnitId = (workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet().getSheetId()) || "";
377
+ const setDisplay = useCallback((value) => {
378
+ _setDisplay(value.replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, ""));
379
+ }, [_setDisplay]);
380
+ useEffect(() => {
381
+ if ((editing === null || editing === void 0 ? void 0 : editing.row) !== void 0 && editing.col !== void 0) {
382
+ const { customRange, row, col } = editing;
383
+ let { label } = editing;
384
+ if (typeof label === "number") label = `${label}`;
385
+ let link;
386
+ if (customRange) {
387
+ var _customRange$rangeId, _label, _customRange$properti, _customRange$properti2;
388
+ link = {
389
+ id: (_customRange$rangeId = customRange === null || customRange === void 0 ? void 0 : customRange.rangeId) !== null && _customRange$rangeId !== void 0 ? _customRange$rangeId : "",
390
+ display: (_label = label) !== null && _label !== void 0 ? _label : "",
391
+ payload: (_customRange$properti = customRange === null || customRange === void 0 || (_customRange$properti2 = customRange.properties) === null || _customRange$properti2 === void 0 ? void 0 : _customRange$properti2.url) !== null && _customRange$properti !== void 0 ? _customRange$properti : "",
392
+ row,
393
+ column: col
394
+ };
395
+ } else if (editing.type === HyperLinkEditSourceType.VIEWING) {
396
+ var _cell$p, _cell$p2, _range$properties$url, _range$properties2;
397
+ const workbook = univerInstanceService.getUnit(editing.unitId);
398
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(editing.subUnitId);
399
+ const cell = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellRaw(editing.row, editing.col);
400
+ const range = cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 || (_cell$p = _cell$p.customRanges) === null || _cell$p === void 0 ? void 0 : _cell$p.find((range) => {
401
+ var _range$properties;
402
+ return range.rangeType === CustomRangeType.HYPERLINK && ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.url);
403
+ });
404
+ const cellValue = cell === null || cell === void 0 ? void 0 : cell.v;
405
+ if (cell && (!BuildTextUtils.transform.isEmptyDocument((_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.body) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.dataStream) || Tools.isDefine(cellValue))) setShowLabel(false);
406
+ link = {
407
+ id: "",
408
+ display: "",
409
+ payload: (_range$properties$url = range === null || range === void 0 || (_range$properties2 = range.properties) === null || _range$properties2 === void 0 ? void 0 : _range$properties2.url) !== null && _range$properties$url !== void 0 ? _range$properties$url : "",
410
+ row,
411
+ column: col
412
+ };
413
+ } else {
414
+ var _BuildTextUtils$custo, _body$customRanges, _label2, _customRange$properti3, _customRange$properti4;
415
+ const doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
416
+ const currentSelection = textSelectionService.getActiveTextRange();
417
+ const body = doc === null || doc === void 0 ? void 0 : doc.getBody();
418
+ const selection = currentSelection && body ? currentSelection : null;
419
+ const customRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
420
+ setShowLabel(false);
421
+ link = {
422
+ id: "",
423
+ display: (_label2 = label) !== null && _label2 !== void 0 ? _label2 : "",
424
+ payload: (_customRange$properti3 = customRange === null || customRange === void 0 || (_customRange$properti4 = customRange.properties) === null || _customRange$properti4 === void 0 ? void 0 : _customRange$properti4.url) !== null && _customRange$properti3 !== void 0 ? _customRange$properti3 : "",
425
+ row,
426
+ column: col
427
+ };
428
+ }
429
+ setId(link.id);
430
+ const customLink = sidePanelService.findCustomHyperLink(link);
431
+ if (customLink) {
432
+ const customLinkInfo = customLink.convert(link);
433
+ setType(customLinkInfo.type);
434
+ setPayload(customLinkInfo.payload);
435
+ setDisplay(customLinkInfo.display);
436
+ return;
437
+ }
438
+ setDisplay(link.display);
439
+ const linkInfo = parserService.parseHyperLink(link.payload);
440
+ setType(linkInfo.type === SheetHyperLinkType.INVALID ? SheetHyperLinkType.RANGE : linkInfo.type);
441
+ switch (linkInfo.type) {
442
+ case SheetHyperLinkType.URL:
443
+ setPayload(linkInfo.url);
444
+ if (linkInfo.url === link.display) setByPayload.current = true;
445
+ break;
446
+ case SheetHyperLinkType.RANGE: {
447
+ var _univerInstanceServic, _univerInstanceServic2;
448
+ const params = linkInfo.searchObj;
449
+ const payload = serializeRangeWithSheet(params.gid ? (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getUnit(editing.unitId)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetId(params.gid)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getName()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : "" : "", deserializeRangeWithSheet(params.range).range);
450
+ setPayload(payload);
451
+ if (payload === link.display) setByPayload.current = true;
452
+ break;
453
+ }
454
+ case SheetHyperLinkType.SHEET: {
455
+ const params = linkInfo.searchObj;
456
+ setPayload(params.gid);
457
+ break;
458
+ }
459
+ case SheetHyperLinkType.DEFINE_NAME: {
460
+ const params = linkInfo.searchObj;
461
+ setPayload(params.rangeid);
462
+ break;
463
+ }
464
+ default:
465
+ setPayload("");
466
+ break;
467
+ }
468
+ }
469
+ }, [
470
+ editing,
471
+ resolverService,
472
+ sidePanelService,
473
+ textSelectionService,
474
+ univerInstanceService
475
+ ]);
476
+ useEffect(() => {
477
+ let id = null;
478
+ if (editing && !editing.customRangeId && editing.type === HyperLinkEditSourceType.VIEWING && Tools.isDefine(editing.row) && Tools.isDefine(editing.col)) {
479
+ const workbook = univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_SHEET);
480
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(editing.subUnitId);
481
+ const mergeInfo = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getMergedCell(editing.row, editing.col);
482
+ const color = new ColorKit(themeService.getColorFromTheme("primary.600")).toRgb();
483
+ id = markSelectionService.addShape({
484
+ range: mergeInfo !== null && mergeInfo !== void 0 ? mergeInfo : {
485
+ startColumn: editing.col,
486
+ endColumn: editing.col,
487
+ startRow: editing.row,
488
+ endRow: editing.row
489
+ },
490
+ style: {
491
+ fill: `rgb(${color.r}, ${color.g}, ${color.b}, 0.12)`,
492
+ strokeWidth: 1,
493
+ stroke: "#FFBD37",
494
+ widgets: {}
495
+ },
496
+ primary: null
497
+ }, [], -1);
498
+ }
499
+ return () => {
500
+ if (id) markSelectionService.removeShape(id);
501
+ };
502
+ }, [
503
+ editing,
504
+ markSelectionService,
505
+ themeService,
506
+ univerInstanceService
507
+ ]);
508
+ useEffect(() => {
509
+ setIsFocusRangeSelector(type === SheetHyperLinkType.RANGE);
510
+ }, [type]);
511
+ useEffect(() => {
512
+ const render = (editing === null || editing === void 0 ? void 0 : editing.type) === HyperLinkEditSourceType.ZEN_EDITOR ? renderManagerService.getRenderById(DOCS_ZEN_EDITOR_UNIT_ID_KEY) : renderManagerService.getRenderById(editorBridgeService.getCurrentEditorId());
513
+ const disposeCollection = new DisposableCollection();
514
+ if (render) {
515
+ const selectionRenderService = render.with(DocSelectionRenderService);
516
+ selectionRenderService.setReserveRangesStatus(true);
517
+ disposeCollection.add(() => {
518
+ selectionRenderService.setReserveRangesStatus(false);
519
+ });
520
+ }
521
+ return () => {
522
+ editorBridgeService.disableForceKeepVisible();
523
+ disposeCollection.dispose();
524
+ };
525
+ }, [
526
+ editing === null || editing === void 0 ? void 0 : editing.type,
527
+ editorBridgeService,
528
+ renderManagerService
529
+ ]);
530
+ useEffect(() => {
531
+ if (isFocusRangeSelector) popupService.setIsKeepVisible(isFocusRangeSelector);
532
+ popupService.setIsKeepVisible(selectorDialogVisible);
533
+ return () => {
534
+ popupService.setIsKeepVisible(false);
535
+ };
536
+ }, [
537
+ isFocusRangeSelector,
538
+ selectorDialogVisible,
539
+ popupService
540
+ ]);
541
+ useEffect(() => {
542
+ return () => {
543
+ if (zenZoneService.temporaryHidden) {
544
+ zenZoneService.show();
545
+ contextService.setContextValue(FOCUSING_SHEET, false);
546
+ }
547
+ };
548
+ }, [contextService, zenZoneService]);
549
+ useEffect(() => {
550
+ if (isFocusRangeSelector) {
551
+ editorBridgeService.enableForceKeepVisible();
552
+ return () => {
553
+ editorBridgeService.disableForceKeepVisible();
554
+ };
555
+ }
556
+ }, [isFocusRangeSelector, editorBridgeService]);
557
+ const linkTypeOptions = [
558
+ {
559
+ label: localeService.t("hyperLink.form.link"),
560
+ value: SheetHyperLinkType.URL
561
+ },
562
+ {
563
+ label: localeService.t("hyperLink.form.range"),
564
+ value: SheetHyperLinkType.RANGE
565
+ },
566
+ {
567
+ label: localeService.t("hyperLink.form.worksheet"),
568
+ value: SheetHyperLinkType.SHEET
569
+ },
570
+ {
571
+ label: localeService.t("hyperLink.form.definedName"),
572
+ value: SheetHyperLinkType.DEFINE_NAME
573
+ },
574
+ ...sidePanelOptions
575
+ ];
576
+ if (!workbook) return;
577
+ const hiddens = workbook.getHiddenWorksheets();
578
+ const sheetsOption = workbook.getSheets().map((sheet) => ({
579
+ label: sheet.getName(),
580
+ value: sheet.getSheetId()
581
+ })).filter((opt) => hiddens.indexOf(opt.value) === -1);
582
+ const definedNames = Object.values((_definedNameService$g = definedNameService.getDefinedNameMap(workbook.getUnitId())) !== null && _definedNameService$g !== void 0 ? _definedNameService$g : {}).map((value) => ({
583
+ label: value.name,
584
+ value: value.id
585
+ }));
586
+ const formatUrl = (type, payload) => {
587
+ if (type === SheetHyperLinkType.URL) return serializeUrl(payload);
588
+ if (type === SheetHyperLinkType.RANGE) {
589
+ const info = deserializeRangeWithSheet(payload);
590
+ const worksheet = workbook.getSheetBySheetName(info.sheetName);
591
+ if (worksheet) return `#gid=${worksheet.getSheetId()}&range=${serializeRange(info.range)}`;
592
+ }
593
+ return `#${type}=${payload}`;
594
+ };
595
+ const handleRangeChange = useEvent((rangeText) => {
596
+ var _workbook$getActiveSh;
597
+ const newPayload = resolveRangePayload(rangeText, ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getName()) || "");
598
+ if (!newPayload) {
599
+ setPayload("");
600
+ return;
601
+ }
602
+ setPayload(newPayload);
603
+ if (newPayload && (setByPayload.current || !display)) {
604
+ setDisplay(newPayload);
605
+ setByPayload.current = true;
606
+ }
607
+ });
608
+ const handleSubmit = async () => {
609
+ if (showLabel && isBlankInput(display) || !payload || type === SheetHyperLinkType.URL && !isLegalLink(payload)) {
610
+ setShowError(true);
611
+ return;
612
+ }
613
+ if (editing) if (id) {
614
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? UpdateRichHyperLinkCommand.id : UpdateHyperLinkCommand.id;
615
+ await commandService.executeCommand(commandId, {
616
+ id,
617
+ unitId: editing.unitId,
618
+ subUnitId: editing.subUnitId,
619
+ payload: {
620
+ display: showLabel ? display : "",
621
+ payload: formatUrl(type, payload)
622
+ },
623
+ row: editing.row,
624
+ column: editing.col,
625
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
626
+ });
627
+ } else {
628
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? AddRichHyperLinkCommand.id : AddHyperLinkCommand.id;
629
+ await commandService.executeCommand(commandId, {
630
+ unitId: editing.unitId,
631
+ subUnitId: editing.subUnitId,
632
+ link: {
633
+ id: generateRandomId(),
634
+ row: editing.row,
635
+ column: editing.col,
636
+ payload: formatUrl(type, payload),
637
+ display: showLabel ? display : ""
638
+ },
639
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
640
+ });
641
+ }
642
+ if ((editing === null || editing === void 0 ? void 0 : editing.type) === HyperLinkEditSourceType.VIEWING) {
643
+ await commandService.executeCommand(SetWorksheetActiveOperation.id, {
644
+ unitId: editing.unitId,
645
+ subUnitId: editing.subUnitId
646
+ });
647
+ const GAP = 1;
648
+ await commandService.executeCommand(ScrollToRangeOperation.id, { range: {
649
+ startRow: Math.max(editing.row - GAP, 0),
650
+ endRow: editing.row + GAP,
651
+ startColumn: Math.max(editing.col - GAP, 0),
652
+ endColumn: editing.col + GAP
653
+ } });
654
+ }
655
+ commandService.executeCommand(CloseHyperLinkPopupOperation.id);
656
+ };
657
+ if (!editing) return null;
658
+ return /* @__PURE__ */ jsxs("div", {
659
+ className: clsx("univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900", borderClassName),
660
+ children: [
661
+ showLabel ? /* @__PURE__ */ jsx(FormLayout, {
662
+ label: localeService.t("hyperLink.form.label"),
663
+ error: showError && isBlankInput(display) ? localeService.t("hyperLink.form.inputError") : "",
664
+ children: /* @__PURE__ */ jsx(Input, {
665
+ value: display,
666
+ onChange: (v) => {
667
+ setDisplay(v);
668
+ setByPayload.current = false;
669
+ },
670
+ placeholder: localeService.t("hyperLink.form.labelPlaceholder"),
671
+ autoFocus: true,
672
+ onKeyDown: (e) => {
673
+ if (e.keyCode === KeyCode.ENTER) handleSubmit();
674
+ }
675
+ })
676
+ }) : null,
677
+ /* @__PURE__ */ jsx(FormLayout, {
678
+ label: localeService.t("hyperLink.form.type"),
679
+ children: /* @__PURE__ */ jsx(Select, {
680
+ className: "univer-w-full",
681
+ options: linkTypeOptions,
682
+ value: type,
683
+ onChange: (newType) => {
684
+ setType(newType);
685
+ setPayload("");
686
+ }
687
+ })
688
+ }),
689
+ type === SheetHyperLinkType.URL && /* @__PURE__ */ jsx(FormLayout, {
690
+ error: showError ? !payload ? localeService.t("hyperLink.form.inputError") : !isLegalLink(payload) ? localeService.t("hyperLink.form.linkError") : "" : "",
691
+ children: /* @__PURE__ */ jsx(Input, {
692
+ value: payload,
693
+ onChange: (newLink) => {
694
+ setPayload(newLink);
695
+ if (newLink && (setByPayload.current || !display || display === newLink)) {
696
+ setDisplay(newLink);
697
+ setByPayload.current = true;
698
+ }
699
+ },
700
+ placeholder: localeService.t("hyperLink.form.linkPlaceholder"),
701
+ autoFocus: true,
702
+ onKeyDown: (e) => {
703
+ if (e.keyCode === KeyCode.ENTER) handleSubmit();
704
+ }
705
+ })
706
+ }),
707
+ type === SheetHyperLinkType.RANGE && /* @__PURE__ */ jsx(FormLayout, {
708
+ error: showError && !payload ? localeService.t("hyperLink.form.inputError") : "",
709
+ children: /* @__PURE__ */ jsx(RangeSelector, {
710
+ unitId: workbook.getUnitId(),
711
+ subUnitId,
712
+ maxRangeCount: 1,
713
+ supportAcrossSheet: true,
714
+ initialValue: payload,
715
+ resetRange: selections,
716
+ onChange: (_, text) => handleRangeChange(text),
717
+ onRangeSelectorDialogVisibleChange: async (visible) => {
718
+ setSelectorDialogVisible(visible);
719
+ if (visible) {
720
+ if (editing.type === HyperLinkEditSourceType.ZEN_EDITOR) {
721
+ zenZoneService.hide();
722
+ contextService.setContextValue(FOCUSING_SHEET, true);
723
+ }
724
+ if (editing.type !== HyperLinkEditSourceType.VIEWING) editorBridgeService.enableForceKeepVisible();
725
+ setHide(true);
726
+ } else {
727
+ await resolverService.navigateToRange(editing.unitId, editing.subUnitId, {
728
+ startRow: editing.row,
729
+ endRow: editing.row,
730
+ startColumn: editing.col,
731
+ endColumn: editing.col
732
+ }, true);
733
+ if (editing.type === HyperLinkEditSourceType.ZEN_EDITOR) {
734
+ var _renderManagerService, _docSelectionManagerS;
735
+ await commandService.executeCommand(SetSelectionsOperation.id, {
736
+ unitId: editing.unitId,
737
+ subUnitId: editing.subUnitId,
738
+ selections: [{ range: {
739
+ startRow: editing.row,
740
+ endRow: editing.row,
741
+ startColumn: editing.col,
742
+ endColumn: editing.col
743
+ } }]
744
+ });
745
+ zenZoneService.show();
746
+ contextService.setContextValue(FOCUSING_SHEET, false);
747
+ const docBackScrollRenderController = (_renderManagerService = renderManagerService.getRenderById(DOCS_ZEN_EDITOR_UNIT_ID_KEY)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocBackScrollRenderController);
748
+ const range = (_docSelectionManagerS = docSelectionManagerService.getTextRanges({
749
+ unitId: DOCS_ZEN_EDITOR_UNIT_ID_KEY,
750
+ subUnitId: DOCS_ZEN_EDITOR_UNIT_ID_KEY
751
+ })) === null || _docSelectionManagerS === void 0 ? void 0 : _docSelectionManagerS[0];
752
+ if (docBackScrollRenderController && range) {
753
+ docBackScrollRenderController.scrollToRange(range);
754
+ docSelectionManagerService.refreshSelection({
755
+ unitId: DOCS_ZEN_EDITOR_UNIT_ID_KEY,
756
+ subUnitId: DOCS_ZEN_EDITOR_UNIT_ID_KEY
757
+ });
758
+ }
759
+ }
760
+ editorBridgeService.disableForceKeepVisible();
761
+ setHide(false);
762
+ }
763
+ },
764
+ onFocusChange: (focus) => setIsFocusRangeSelector(focus)
765
+ })
766
+ }),
767
+ type === SheetHyperLinkType.SHEET && /* @__PURE__ */ jsx(FormLayout, {
768
+ error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "",
769
+ children: /* @__PURE__ */ jsx(Select, {
770
+ className: "univer-w-full",
771
+ options: sheetsOption,
772
+ value: payload,
773
+ onChange: (newPayload) => {
774
+ var _sheetsOption$find, _sheetsOption$find2;
775
+ setPayload(newPayload);
776
+ const label = (_sheetsOption$find = sheetsOption.find((i) => i.value === newPayload)) === null || _sheetsOption$find === void 0 ? void 0 : _sheetsOption$find.label;
777
+ const oldLabel = (_sheetsOption$find2 = sheetsOption.find((i) => i.value === payload)) === null || _sheetsOption$find2 === void 0 ? void 0 : _sheetsOption$find2.label;
778
+ if (label && (setByPayload.current || !display || display === oldLabel)) {
779
+ setDisplay(label);
780
+ setByPayload.current = true;
781
+ }
782
+ }
783
+ })
784
+ }),
785
+ type === SheetHyperLinkType.DEFINE_NAME && /* @__PURE__ */ jsx(FormLayout, {
786
+ error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "",
787
+ children: /* @__PURE__ */ jsx(Select, {
788
+ className: "univer-w-full",
789
+ options: definedNames,
790
+ value: payload,
791
+ onChange: (newValue) => {
792
+ var _definedNames$find, _definedNames$find2;
793
+ setPayload(newValue);
794
+ const label = (_definedNames$find = definedNames.find((i) => i.value === newValue)) === null || _definedNames$find === void 0 ? void 0 : _definedNames$find.label;
795
+ const oldLabel = (_definedNames$find2 = definedNames.find((i) => i.value === payload)) === null || _definedNames$find2 === void 0 ? void 0 : _definedNames$find2.label;
796
+ if (label && (setByPayload.current || !display || display === oldLabel)) {
797
+ setDisplay(label);
798
+ setByPayload.current = true;
799
+ }
800
+ }
801
+ })
802
+ }),
803
+ (customHyperLinkSidePanel === null || customHyperLinkSidePanel === void 0 ? void 0 : customHyperLinkSidePanel.Form) && /* @__PURE__ */ jsx(customHyperLinkSidePanel.Form, {
804
+ linkId: id,
805
+ payload,
806
+ display,
807
+ showError,
808
+ setByPayload,
809
+ setDisplay: (newLink) => {
810
+ setDisplay(newLink);
811
+ setByPayload.current = true;
812
+ },
813
+ setPayload
814
+ }),
815
+ /* @__PURE__ */ jsxs("div", {
816
+ className: "univer-flex univer-flex-row univer-justify-end univer-gap-2",
817
+ children: [/* @__PURE__ */ jsx(Button, {
818
+ onClick: () => {
819
+ if (editing) resolverService.navigateToRange(editing.unitId, editing.subUnitId, {
820
+ startRow: editing.row,
821
+ endRow: editing.row,
822
+ startColumn: editing.col,
823
+ endColumn: editing.col
824
+ }, true);
825
+ commandService.executeCommand(CloseHyperLinkPopupOperation.id);
826
+ },
827
+ children: localeService.t("hyperLink.form.cancel")
828
+ }), /* @__PURE__ */ jsx(Button, {
829
+ variant: "primary",
830
+ onClick: async () => {
831
+ handleSubmit();
832
+ },
833
+ children: localeService.t("hyperLink.form.ok")
834
+ })]
835
+ })
836
+ ]
837
+ });
838
+ };
839
+ CellLinkEdit.componentKey = "univer.sheet.cell-link-edit";
840
+
841
+ //#endregion
842
+ //#region src/views/CellLinkPopup/index.tsx
843
+ const iconsMap = {
844
+ [SheetHyperLinkType.URL]: /* @__PURE__ */ jsx(LinkIcon, {}),
845
+ [SheetHyperLinkType.SHEET]: /* @__PURE__ */ jsx(XlsxMultiIcon, { className: "univer-text-green-500" }),
846
+ [SheetHyperLinkType.RANGE]: /* @__PURE__ */ jsx(AllBorderIcon, {}),
847
+ [SheetHyperLinkType.DEFINE_NAME]: /* @__PURE__ */ jsx(AllBorderIcon, {}),
848
+ [SheetHyperLinkType.INVALID]: /* @__PURE__ */ jsx(AllBorderIcon, {})
849
+ };
850
+ const CellLinkPopupPure = (props) => {
851
+ var _customRange$properti, _customRange$properti2;
852
+ const popupService = useDependency(SheetsHyperLinkPopupService);
853
+ const commandService = useDependency(ICommandService);
854
+ const messageService = useDependency(IMessageService);
855
+ const localeService = useDependency(LocaleService);
856
+ const resolverService = useDependency(SheetsHyperLinkResolverService);
857
+ const editorBridgeService = useDependency(IEditorBridgeService);
858
+ const parserHyperLinkService = useDependency(SheetsHyperLinkParserService);
859
+ const zenZoneService = useDependency(IZenZoneService);
860
+ const { customRange, row, col, unitId, subUnitId, editPermission, copyPermission, type } = props;
861
+ if (!(customRange === null || customRange === void 0 || (_customRange$properti = customRange.properties) === null || _customRange$properti === void 0 ? void 0 : _customRange$properti.url)) return null;
862
+ const linkObj = parserHyperLinkService.parseHyperLink((_customRange$properti2 = customRange.properties.url) !== null && _customRange$properti2 !== void 0 ? _customRange$properti2 : "");
863
+ const isError = linkObj.type === SheetHyperLinkType.INVALID;
864
+ return /* @__PURE__ */ jsxs("div", {
865
+ className: clsx("univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900", borderClassName),
866
+ onClick: () => popupService.hideCurrentPopup(),
867
+ children: [/* @__PURE__ */ jsxs("div", {
868
+ className: clsx("univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600", { "univer-text-red-500": isError }),
869
+ onClick: () => {
870
+ if (zenZoneService.visible) return;
871
+ if (isError) return;
872
+ resolverService.navigate(linkObj);
873
+ },
874
+ children: [/* @__PURE__ */ jsx("div", {
875
+ className: "univer-mr-2 univer-flex univer-size-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",
876
+ children: iconsMap[linkObj.type]
877
+ }), /* @__PURE__ */ jsx(Tooltip, {
878
+ showIfEllipsis: true,
879
+ title: linkObj.name,
880
+ asChild: true,
881
+ children: /* @__PURE__ */ jsx("span", {
882
+ className: "univer-flex-1 univer-truncate",
883
+ children: linkObj.name
884
+ })
885
+ })]
886
+ }), /* @__PURE__ */ jsxs("div", {
887
+ className: "univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center",
888
+ children: [copyPermission && /* @__PURE__ */ jsx("div", {
889
+ className: clsx("univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700", { "univer-text-red-500": isError }),
890
+ onClick: () => {
891
+ if (isError) return;
892
+ if (linkObj.type !== SheetHyperLinkType.URL) {
893
+ const url = new URL(window.location.href);
894
+ url.hash = linkObj.url.slice(1);
895
+ navigator.clipboard.writeText(url.href);
896
+ } else navigator.clipboard.writeText(linkObj.url);
897
+ messageService.show({
898
+ content: localeService.t("hyperLink.message.coped"),
899
+ type: MessageType.Info
900
+ });
901
+ },
902
+ children: /* @__PURE__ */ jsx(Tooltip, {
903
+ placement: "bottom",
904
+ title: localeService.t("hyperLink.popup.copy"),
905
+ children: /* @__PURE__ */ jsx(CopyIcon, { className: "dark:!univer-text-white" })
906
+ })
907
+ }), editPermission && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
908
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
909
+ onClick: () => {
910
+ commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
911
+ unitId,
912
+ subUnitId,
913
+ row,
914
+ col,
915
+ customRangeId: customRange.rangeId,
916
+ type
917
+ });
918
+ },
919
+ children: /* @__PURE__ */ jsx(Tooltip, {
920
+ placement: "bottom",
921
+ title: localeService.t("hyperLink.popup.edit"),
922
+ children: /* @__PURE__ */ jsx(WriteIcon, { className: "dark:!univer-text-white" })
923
+ })
924
+ }), /* @__PURE__ */ jsx("div", {
925
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
926
+ onClick: () => {
927
+ const commandId = type === HyperLinkEditSourceType.EDITING || type === HyperLinkEditSourceType.ZEN_EDITOR ? CancelRichHyperLinkCommand.id : CancelHyperLinkCommand.id;
928
+ if (commandService.syncExecuteCommand(commandId, {
929
+ unitId,
930
+ subUnitId,
931
+ id: customRange.rangeId,
932
+ row,
933
+ column: col,
934
+ documentId: type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
935
+ })) popupService.hideCurrentPopup(void 0, true);
936
+ },
937
+ children: /* @__PURE__ */ jsx(Tooltip, {
938
+ placement: "bottom",
939
+ title: localeService.t("hyperLink.popup.cancel"),
940
+ children: /* @__PURE__ */ jsx(UnlinkIcon, { className: "dark:!univer-text-white" })
941
+ })
942
+ })] })]
943
+ })]
944
+ });
945
+ };
946
+ const CellLinkPopup = () => {
947
+ const popupService = useDependency(SheetsHyperLinkPopupService);
948
+ const [currentPopup, setCurrentPopup] = useState(null);
949
+ const univerInstanceService = useDependency(IUniverInstanceService);
950
+ useEffect(() => {
951
+ setCurrentPopup(popupService.currentPopup);
952
+ const ob = popupService.currentPopup$.subscribe((popup) => {
953
+ setCurrentPopup(popup);
954
+ });
955
+ return () => {
956
+ ob.unsubscribe();
957
+ };
958
+ }, [popupService.currentPopup, popupService.currentPopup$]);
959
+ if (!currentPopup) return null;
960
+ if (currentPopup.showAll) {
961
+ var _cell$p;
962
+ const workbook = univerInstanceService.getUnit(currentPopup.unitId, UniverInstanceType.UNIVER_SHEET);
963
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(currentPopup.subUnitId);
964
+ const cell = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCell(currentPopup.row, currentPopup.col);
965
+ const customRanges = cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.customRanges;
966
+ return (customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) ? /* @__PURE__ */ jsx("div", { children: customRanges.map((customRange) => {
967
+ return /* @__PURE__ */ jsx(CellLinkPopupPure, {
968
+ ...currentPopup,
969
+ customRange
970
+ }, customRange.rangeId);
971
+ }) }) : null;
972
+ }
973
+ return /* @__PURE__ */ jsx(CellLinkPopupPure, { ...currentPopup });
974
+ };
975
+ CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
976
+
977
+ //#endregion
978
+ //#region src/services/popup.service.ts
979
+ const isEqualLink = (a, b) => {
980
+ var _a$customRange, _b$customRange;
981
+ return a.unitId === b.unitId && a.subUnitId === b.subUnitId && a.row === b.row && a.col === b.col && ((_a$customRange = a.customRange) === null || _a$customRange === void 0 ? void 0 : _a$customRange.rangeId) === ((_b$customRange = b.customRange) === null || _b$customRange === void 0 ? void 0 : _b$customRange.rangeId) && a.type === b.type;
982
+ };
983
+ let SheetsHyperLinkPopupService = class SheetsHyperLinkPopupService extends Disposable {
984
+ get currentPopup() {
985
+ return this._currentPopup;
986
+ }
987
+ get currentEditing() {
988
+ return this._currentEditing$.getValue();
989
+ }
990
+ constructor(_sheetCanvasPopManagerService, _injector, _univerInstanceService, _editorBridgeService, _textSelectionManagerService, _docCanvasPopManagerService, _zenZoneService) {
991
+ super();
992
+ this._sheetCanvasPopManagerService = _sheetCanvasPopManagerService;
993
+ this._injector = _injector;
994
+ this._univerInstanceService = _univerInstanceService;
995
+ this._editorBridgeService = _editorBridgeService;
996
+ this._textSelectionManagerService = _textSelectionManagerService;
997
+ this._docCanvasPopManagerService = _docCanvasPopManagerService;
998
+ this._zenZoneService = _zenZoneService;
999
+ _defineProperty(this, "_currentPopup", null);
1000
+ _defineProperty(this, "_currentPopup$", new Subject());
1001
+ _defineProperty(this, "currentPopup$", this._currentPopup$.asObservable());
1002
+ _defineProperty(this, "_currentEditingPopup", null);
1003
+ _defineProperty(this, "_currentEditing$", new BehaviorSubject(null));
1004
+ _defineProperty(this, "currentEditing$", this._currentEditing$.asObservable());
1005
+ _defineProperty(this, "_isKeepVisible", false);
1006
+ this.disposeWithMe(() => {
1007
+ this.hideCurrentPopup();
1008
+ this.endEditing();
1009
+ this._currentEditing$.complete();
1010
+ this._currentPopup$.complete();
1011
+ });
1012
+ }
1013
+ setIsKeepVisible(v) {
1014
+ this._isKeepVisible = v;
1015
+ }
1016
+ getIsKeepVisible() {
1017
+ return this._isKeepVisible;
1018
+ }
1019
+ showPopup(location) {
1020
+ if (this._currentPopup && isEqualLink(location, this._currentPopup)) return;
1021
+ this.hideCurrentPopup(void 0, true);
1022
+ if (location.type !== HyperLinkEditSourceType.ZEN_EDITOR && this._zenZoneService.visible) return;
1023
+ const currentEditing = this._currentEditing$.getValue();
1024
+ if (currentEditing && isEqualLink(location, currentEditing)) return;
1025
+ const { unitId, subUnitId, row, col, customRangeRect, customRange } = location;
1026
+ let disposable;
1027
+ const popup = {
1028
+ componentKey: CellLinkPopup.componentKey,
1029
+ direction: "bottom",
1030
+ onClickOutside: () => {
1031
+ this.hideCurrentPopup();
1032
+ },
1033
+ onClick: () => {
1034
+ this.hideCurrentPopup(location.type, true);
1035
+ }
1036
+ };
1037
+ if (location.type === HyperLinkEditSourceType.EDITING) {
1038
+ if (!customRange) return;
1039
+ disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(customRangeRect, popup);
1040
+ } else if (location.type === HyperLinkEditSourceType.ZEN_EDITOR) {
1041
+ if (!customRange) return;
1042
+ disposable = this._docCanvasPopManagerService.attachPopupToRange({
1043
+ startOffset: customRange.startIndex,
1044
+ endOffset: customRange.endIndex + 1,
1045
+ collapsed: false
1046
+ }, popup, DOCS_ZEN_EDITOR_UNIT_ID_KEY);
1047
+ } else if (location.showAll) disposable = this._sheetCanvasPopManagerService.attachPopupToCell(location.row, location.col, popup, unitId, subUnitId);
1048
+ else {
1049
+ if (!customRange) return;
1050
+ disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupByPosition(customRangeRect, popup, location);
1051
+ }
1052
+ if (disposable) {
1053
+ if (this._currentPopup) {
1054
+ var _this$_currentPopup$d;
1055
+ (_this$_currentPopup$d = this._currentPopup.disposable) === null || _this$_currentPopup$d === void 0 || _this$_currentPopup$d.dispose();
1056
+ }
1057
+ this._currentPopup = {
1058
+ unitId,
1059
+ subUnitId,
1060
+ disposable,
1061
+ row,
1062
+ col,
1063
+ editPermission: !!location.editPermission,
1064
+ copyPermission: !!location.copyPermission,
1065
+ customRange,
1066
+ type: location.type,
1067
+ showAll: location.showAll
1068
+ };
1069
+ this._currentPopup$.next(this._currentPopup);
1070
+ }
1071
+ }
1072
+ hideCurrentPopup(type, force) {
1073
+ if (!this._currentPopup) return;
1074
+ if ((!type || type === this._currentPopup.type) && this._currentPopup.disposable.canDispose() || force) {
1075
+ var _this$_currentPopup;
1076
+ (_this$_currentPopup = this._currentPopup) === null || _this$_currentPopup === void 0 || (_this$_currentPopup = _this$_currentPopup.disposable) === null || _this$_currentPopup === void 0 || _this$_currentPopup.dispose();
1077
+ this._currentPopup = null;
1078
+ this._currentPopup$.next(null);
1079
+ }
1080
+ }
1081
+ dispose() {
1082
+ super.dispose();
1083
+ this.hideCurrentPopup();
1084
+ this.endEditing();
1085
+ this._currentPopup$.complete();
1086
+ this._currentEditing$.complete();
1087
+ }
1088
+ _getEditingRange() {
1089
+ const visible = this._editorBridgeService.isVisible().visible;
1090
+ const state = this._editorBridgeService.getEditCellState();
1091
+ if (visible && state) {
1092
+ var _state$documentLayout, _body$customRanges$fi, _body$customRanges;
1093
+ const textRange = this._textSelectionManagerService.getActiveTextRange();
1094
+ const body = (_state$documentLayout = state.documentLayoutObject.documentModel) === null || _state$documentLayout === void 0 ? void 0 : _state$documentLayout.getBody();
1095
+ if (!body) return null;
1096
+ if (!textRange || textRange.collapsed) return {
1097
+ startOffset: 0,
1098
+ endOffset: body.dataStream.length - 2,
1099
+ collapsed: body.dataStream.length - 2 === 0,
1100
+ label: BuildTextUtils.transform.getPlainText(body.dataStream)
1101
+ };
1102
+ const links = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(textRange, (_body$customRanges$fi = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.filter((i) => i.rangeType === CustomRangeType.HYPERLINK)) !== null && _body$customRanges$fi !== void 0 ? _body$customRanges$fi : []);
1103
+ let start = textRange.startOffset;
1104
+ let end = textRange.endOffset;
1105
+ links.forEach((link) => {
1106
+ start = Math.min(start, link.startIndex);
1107
+ end = Math.max(end, link.endIndex + 1);
1108
+ });
1109
+ return {
1110
+ startOffset: start,
1111
+ endOffset: end,
1112
+ collapsed: start === end,
1113
+ label: BuildTextUtils.transform.getPlainText(body.dataStream.slice(start, end))
1114
+ };
1115
+ }
1116
+ return null;
1117
+ }
1118
+ get _editPopup() {
1119
+ return {
1120
+ componentKey: CellLinkEdit.componentKey,
1121
+ direction: "vertical",
1122
+ onClickOutside: () => {
1123
+ this.endEditing();
1124
+ },
1125
+ onContextMenu: () => {
1126
+ this.endEditing();
1127
+ },
1128
+ hiddenType: "hide"
1129
+ };
1130
+ }
1131
+ startAddEditing(link) {
1132
+ const { unitId, subUnitId, type } = link;
1133
+ if (type === HyperLinkEditSourceType.ZEN_EDITOR) {
1134
+ var _document$getBody;
1135
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1136
+ if (!document) return;
1137
+ const range = this._textSelectionManagerService.getActiveTextRange();
1138
+ if (!range) return;
1139
+ this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange(range, this._editPopup, DOCS_ZEN_EDITOR_UNIT_ID_KEY);
1140
+ const label = (_document$getBody = document.getBody()) === null || _document$getBody === void 0 ? void 0 : _document$getBody.dataStream.slice(range.startOffset, range.endOffset);
1141
+ this._currentEditing$.next({
1142
+ ...link,
1143
+ label
1144
+ });
1145
+ } else if (type === HyperLinkEditSourceType.EDITING) {
1146
+ var _range$label;
1147
+ const range = this._getEditingRange();
1148
+ if (!range) return;
1149
+ this._textSelectionManagerService.replaceDocRanges([{ ...range }], {
1150
+ unitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
1151
+ subUnitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY
1152
+ });
1153
+ const currentRender = this._injector.get(IRenderManagerService).getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
1154
+ if (!currentRender) return;
1155
+ const rects = calcDocRangePositions(range, currentRender);
1156
+ if (!(rects === null || rects === void 0 ? void 0 : rects.length)) return;
1157
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(rects.pop(), this._editPopup, unitId, subUnitId);
1158
+ this._currentEditing$.next({
1159
+ ...link,
1160
+ label: (_range$label = range === null || range === void 0 ? void 0 : range.label) !== null && _range$label !== void 0 ? _range$label : ""
1161
+ });
1162
+ } else {
1163
+ var _cell$p$body$dataStre, _cell$p$body, _cell$v;
1164
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(link.row, link.col, this._editPopup, unitId, subUnitId);
1165
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1166
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1167
+ const cell = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellRaw(link.row, link.col);
1168
+ this._currentEditing$.next({
1169
+ ...link,
1170
+ label: (cell === null || cell === void 0 ? void 0 : cell.p) ? BuildTextUtils.transform.getPlainText((_cell$p$body$dataStre = (_cell$p$body = cell.p.body) === null || _cell$p$body === void 0 ? void 0 : _cell$p$body.dataStream) !== null && _cell$p$body$dataStre !== void 0 ? _cell$p$body$dataStre : "") : ((_cell$v = cell === null || cell === void 0 ? void 0 : cell.v) !== null && _cell$v !== void 0 ? _cell$v : "").toString()
1171
+ });
1172
+ }
1173
+ }
1174
+ startEditing(link) {
1175
+ var _this$_currentEditing;
1176
+ (_this$_currentEditing = this._currentEditingPopup) === null || _this$_currentEditing === void 0 || _this$_currentEditing.dispose();
1177
+ this.hideCurrentPopup(void 0, true);
1178
+ const { unitId, subUnitId } = link;
1179
+ let customRange;
1180
+ let label;
1181
+ if (link.type === HyperLinkEditSourceType.ZEN_EDITOR) {
1182
+ var _document$getBody2, _document$getBody3;
1183
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1184
+ customRange = document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 || (_document$getBody2 = _document$getBody2.customRanges) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.find((range) => range.rangeId === link.customRangeId);
1185
+ label = customRange ? document === null || document === void 0 || (_document$getBody3 = document.getBody()) === null || _document$getBody3 === void 0 ? void 0 : _document$getBody3.dataStream.slice(customRange.startIndex, customRange.endIndex + 1) : "";
1186
+ if (!customRange || !label) return;
1187
+ this._textSelectionManagerService.replaceTextRanges([{
1188
+ startOffset: customRange.startIndex,
1189
+ endOffset: customRange.endIndex + 1
1190
+ }]);
1191
+ this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange({
1192
+ startOffset: customRange.startIndex,
1193
+ endOffset: customRange.endIndex,
1194
+ collapsed: false
1195
+ }, this._editPopup, DOCS_ZEN_EDITOR_UNIT_ID_KEY);
1196
+ } else if (link.type === HyperLinkEditSourceType.EDITING) {
1197
+ var _customRangeInfo$rect;
1198
+ const customRangeInfo = getEditingCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1199
+ if (!customRangeInfo || !((_customRangeInfo$rect = customRangeInfo.rects) === null || _customRangeInfo$rect === void 0 ? void 0 : _customRangeInfo$rect.length)) return;
1200
+ customRange = customRangeInfo.customRange;
1201
+ label = customRangeInfo.label;
1202
+ this._textSelectionManagerService.replaceTextRanges([{
1203
+ startOffset: customRange.startIndex,
1204
+ endOffset: customRange.endIndex + 1
1205
+ }]);
1206
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(customRangeInfo.rects.pop(), this._editPopup, unitId, subUnitId);
1207
+ } else {
1208
+ var _customRangeInfo$rect2;
1209
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1210
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1211
+ const cell = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellRaw(link.row, link.col);
1212
+ const style = workbook === null || workbook === void 0 ? void 0 : workbook.getStyles().getStyleByCell(cell);
1213
+ const tr = style === null || style === void 0 ? void 0 : style.tr;
1214
+ const customRangeInfo = getCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1215
+ if (!customRangeInfo || !((_customRangeInfo$rect2 = customRangeInfo.rects) === null || _customRangeInfo$rect2 === void 0 ? void 0 : _customRangeInfo$rect2.length)) return;
1216
+ customRange = customRangeInfo.customRange;
1217
+ label = customRangeInfo.label;
1218
+ if (tr) this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(link.row, link.col, this._editPopup, unitId, subUnitId);
1219
+ else this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupByPosition(customRangeInfo.rects.pop(), this._editPopup, {
1220
+ unitId,
1221
+ subUnitId,
1222
+ row: link.row,
1223
+ col: link.col
1224
+ });
1225
+ }
1226
+ this._currentEditing$.next({
1227
+ ...link,
1228
+ customRange,
1229
+ label
1230
+ });
1231
+ }
1232
+ endEditing(type) {
1233
+ if (this.getIsKeepVisible()) return;
1234
+ const current = this._currentEditing$.getValue();
1235
+ if (current && (!type || type === current.type)) {
1236
+ var _this$_currentEditing2;
1237
+ (_this$_currentEditing2 = this._currentEditingPopup) === null || _this$_currentEditing2 === void 0 || _this$_currentEditing2.dispose();
1238
+ this._currentEditing$.next(null);
1239
+ }
1240
+ }
1241
+ };
1242
+ SheetsHyperLinkPopupService = __decorate([
1243
+ __decorateParam(0, Inject(SheetCanvasPopManagerService)),
1244
+ __decorateParam(1, Inject(Injector)),
1245
+ __decorateParam(2, IUniverInstanceService),
1246
+ __decorateParam(3, IEditorBridgeService),
1247
+ __decorateParam(4, Inject(DocSelectionManagerService)),
1248
+ __decorateParam(5, Inject(DocCanvasPopManagerService)),
1249
+ __decorateParam(6, IZenZoneService)
1250
+ ], SheetsHyperLinkPopupService);
1251
+
1252
+ //#endregion
1253
+ //#region src/utils/index.ts
1254
+ let DisableLinkType = /* @__PURE__ */ function(DisableLinkType) {
1255
+ DisableLinkType[DisableLinkType["ALLOWED"] = 0] = "ALLOWED";
1256
+ DisableLinkType[DisableLinkType["DISABLED_BY_CELL"] = 1] = "DISABLED_BY_CELL";
1257
+ DisableLinkType[DisableLinkType["ALLOW_ON_EDITING"] = 2] = "ALLOW_ON_EDITING";
1258
+ return DisableLinkType;
1259
+ }({});
1260
+ const disables = new Set([
1261
+ DataValidationType.CHECKBOX,
1262
+ DataValidationType.LIST,
1263
+ DataValidationType.LIST_MULTIPLE
1264
+ ]);
1265
+ const getShouldDisableCellLink = (accessor, worksheet, row, col) => {
1266
+ var _cell$p, _cell$p2;
1267
+ const cell = worksheet.getCell(row, col);
1268
+ if ((cell === null || cell === void 0 ? void 0 : cell.f) || (cell === null || cell === void 0 ? void 0 : cell.si)) return DisableLinkType.DISABLED_BY_CELL;
1269
+ if (cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 || (_cell$p = _cell$p.customBlocks) === null || _cell$p === void 0 ? void 0 : _cell$p.length) return DisableLinkType.DISABLED_BY_CELL;
1270
+ const dataValidationModel = accessor.has(SheetDataValidationModel) ? accessor.get(SheetDataValidationModel) : null;
1271
+ const rule = dataValidationModel === null || dataValidationModel === void 0 ? void 0 : dataValidationModel.getRuleByLocation(worksheet.getUnitId(), worksheet.getSheetId(), row, col);
1272
+ if (rule && disables.has(rule.type)) return true;
1273
+ if (cell === null || cell === void 0 || (_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.drawingsOrder) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.length) return DisableLinkType.ALLOW_ON_EDITING;
1274
+ return DisableLinkType.ALLOWED;
1275
+ };
1276
+ const getShouldDisableCurrentCellLink = (accessor) => {
1277
+ const unit = accessor.get(IUniverInstanceService).getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1278
+ if (!unit) return true;
1279
+ const worksheet = unit.getActiveSheet();
1280
+ const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
1281
+ if (!selections.length) return true;
1282
+ const row = selections[0].range.startRow;
1283
+ const col = selections[0].range.startColumn;
1284
+ return getShouldDisableCellLink(accessor, worksheet, row, col) === DisableLinkType.DISABLED_BY_CELL;
1285
+ };
1286
+ const shouldDisableAddLink = (accessor) => {
1287
+ const textSelectionService = accessor.get(DocSelectionManagerService);
1288
+ const univerInstanceService = accessor.get(IUniverInstanceService);
1289
+ const textRanges = textSelectionService.getTextRanges();
1290
+ if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
1291
+ const doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1292
+ if (!doc || textRanges.every((range) => range.collapsed)) return true;
1293
+ if (!doc.getSelfOrHeaderFooterModel(textRanges[0].segmentId).getBody()) return true;
1294
+ return false;
1295
+ };
1296
+
1297
+ //#endregion
1298
+ //#region src/commands/operations/popup.operations.ts
1299
+ const OpenHyperLinkEditPanelOperation = {
1300
+ type: CommandType.OPERATION,
1301
+ id: "sheet.operation.open-hyper-link-edit-panel",
1302
+ handler(accessor, params) {
1303
+ if (!params) return false;
1304
+ const popupService = accessor.get(SheetsHyperLinkPopupService);
1305
+ if (!params.customRangeId) popupService.startAddEditing(params);
1306
+ else popupService.startEditing(params);
1307
+ return true;
1308
+ }
1309
+ };
1310
+ const CloseHyperLinkPopupOperation = {
1311
+ type: CommandType.OPERATION,
1312
+ id: "sheet.operation.close-hyper-link-popup",
1313
+ handler(accessor) {
1314
+ accessor.get(SheetsHyperLinkPopupService).endEditing();
1315
+ return true;
1316
+ }
1317
+ };
1318
+ const InsertHyperLinkOperation = {
1319
+ type: CommandType.OPERATION,
1320
+ id: "sheet.operation.insert-hyper-link",
1321
+ handler(accessor) {
1322
+ var _univerInstanceServic;
1323
+ const univerInstanceService = accessor.get(IUniverInstanceService);
1324
+ const target = getSheetCommandTarget(univerInstanceService);
1325
+ const editorBridgeService = accessor.get(IEditorBridgeService);
1326
+ if (!target) return false;
1327
+ const commandService = accessor.get(ICommandService);
1328
+ const selection = accessor.get(SheetsSelectionsService).getCurrentLastSelection();
1329
+ if (!selection) return false;
1330
+ const row = selection.range.startRow;
1331
+ const col = selection.range.startColumn;
1332
+ const visible = editorBridgeService.isVisible();
1333
+ const isZenEditor = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) === DOCS_ZEN_EDITOR_UNIT_ID_KEY;
1334
+ return commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
1335
+ unitId: target.unitId,
1336
+ subUnitId: target.subUnitId,
1337
+ row,
1338
+ col,
1339
+ type: isZenEditor ? HyperLinkEditSourceType.ZEN_EDITOR : visible.visible ? HyperLinkEditSourceType.EDITING : HyperLinkEditSourceType.VIEWING
1340
+ });
1341
+ }
1342
+ };
1343
+ const InsertHyperLinkToolbarOperation = {
1344
+ type: CommandType.OPERATION,
1345
+ id: "sheet.operation.insert-hyper-link-toolbar",
1346
+ handler(accessor) {
1347
+ if (getShouldDisableCurrentCellLink(accessor)) return false;
1348
+ const commandService = accessor.get(ICommandService);
1349
+ if (accessor.get(SheetsHyperLinkPopupService).currentEditing) return commandService.executeCommand(CloseHyperLinkPopupOperation.id);
1350
+ else return commandService.executeCommand(InsertHyperLinkOperation.id);
1351
+ }
1352
+ };
1353
+
1354
+ //#endregion
1355
+ //#region src/types/const.ts
1356
+ /**
1357
+ * Copyright 2023-present DreamNum Co., Ltd.
1358
+ *
1359
+ * Licensed under the Apache License, Version 2.0 (the "License");
1360
+ * you may not use this file except in compliance with the License.
1361
+ * You may obtain a copy of the License at
1362
+ *
1363
+ * http://www.apache.org/licenses/LICENSE-2.0
1364
+ *
1365
+ * Unless required by applicable law or agreed to in writing, software
1366
+ * distributed under the License is distributed on an "AS IS" BASIS,
1367
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1368
+ * See the License for the specific language governing permissions and
1369
+ * limitations under the License.
1370
+ */
1371
+ const SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
1372
+
1373
+ //#endregion
1374
+ //#region src/controllers/copy-paste.controller.ts
1375
+ let SheetsHyperLinkCopyPasteController = class SheetsHyperLinkCopyPasteController extends Disposable {
1376
+ registerPlainTextFilter(filter) {
1377
+ this._plainTextFilter.add(filter);
1378
+ }
1379
+ removePlainTextFilter(filter) {
1380
+ this._plainTextFilter.delete(filter);
1381
+ }
1382
+ _filterPlainText(text) {
1383
+ return Array.from(this._plainTextFilter).every((filter) => filter(text));
1384
+ }
1385
+ constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
1386
+ super();
1387
+ this._sheetClipboardService = _sheetClipboardService;
1388
+ this._hyperLinkModel = _hyperLinkModel;
1389
+ this._injector = _injector;
1390
+ this._resolverService = _resolverService;
1391
+ _defineProperty(this, "_plainTextFilter", /* @__PURE__ */ new Set());
1392
+ _defineProperty(this, "_copyInfo", void 0);
1393
+ this._initCopyPaste();
1394
+ this.disposeWithMe(() => {
1395
+ this._plainTextFilter.clear();
1396
+ });
1397
+ }
1398
+ _initCopyPaste() {
1399
+ this._sheetClipboardService.addClipboardHook({
1400
+ id: SHEET_HYPER_LINK_UI_PLUGIN,
1401
+ onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
1402
+ onPasteCells: (pasteFrom, pasteTo, data, payload) => {
1403
+ const { copyType = COPY_TYPE.COPY, pasteType } = payload;
1404
+ const { range: copyRange } = pasteFrom || {};
1405
+ const { range: pastedRange, unitId, subUnitId } = pasteTo;
1406
+ return this._generateMutations(pastedRange, {
1407
+ copyType,
1408
+ pasteType,
1409
+ copyRange,
1410
+ unitId,
1411
+ subUnitId
1412
+ });
1413
+ },
1414
+ onPastePlainText: (pasteTo, clipText) => {
1415
+ const filterResult = this._filterPlainText(clipText);
1416
+ if (isLegalLink(clipText) && filterResult) {
1417
+ const { range, unitId, subUnitId } = pasteTo;
1418
+ const { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]);
1419
+ const redos = [];
1420
+ const undos = [];
1421
+ Range.foreach(pasteToRange, (originRow, originCol) => {
1422
+ const { row, col: column } = mapFunc(originRow, originCol);
1423
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
1424
+ if (link) redos.push({
1425
+ id: RemoveHyperLinkMutation.id,
1426
+ params: {
1427
+ unitId,
1428
+ subUnitId,
1429
+ id: link.id
1430
+ }
1431
+ });
1432
+ if (link) undos.push({
1433
+ id: AddHyperLinkMutation.id,
1434
+ params: {
1435
+ unitId,
1436
+ subUnitId,
1437
+ link
1438
+ }
1439
+ });
1440
+ });
1441
+ return {
1442
+ redos,
1443
+ undos
1444
+ };
1445
+ }
1446
+ return {
1447
+ undos: [],
1448
+ redos: []
1449
+ };
1450
+ },
1451
+ priority: 99
1452
+ });
1453
+ }
1454
+ _collect(unitId, subUnitId, range) {
1455
+ const matrix = new ObjectMatrix();
1456
+ this._copyInfo = {
1457
+ unitId,
1458
+ subUnitId,
1459
+ matrix
1460
+ };
1461
+ const discreteRange = this._injector.invoke((accessor) => {
1462
+ return rangeToDiscreteRange(range, accessor, unitId, subUnitId);
1463
+ });
1464
+ if (!discreteRange) return;
1465
+ const { rows, cols } = discreteRange;
1466
+ rows.forEach((row, rowIndex) => {
1467
+ cols.forEach((col, colIndex) => {
1468
+ var _link$id;
1469
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1470
+ matrix.setValue(rowIndex, colIndex, (_link$id = link === null || link === void 0 ? void 0 : link.id) !== null && _link$id !== void 0 ? _link$id : "");
1471
+ });
1472
+ });
1473
+ }
1474
+ _generateMutations(pastedRange, copyInfo) {
1475
+ if (!this._copyInfo) return {
1476
+ redos: [],
1477
+ undos: []
1478
+ };
1479
+ if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange) return {
1480
+ redos: [],
1481
+ undos: []
1482
+ };
1483
+ if ([
1484
+ PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,
1485
+ PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,
1486
+ PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,
1487
+ PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
1488
+ ].includes(copyInfo.pasteType)) return {
1489
+ redos: [],
1490
+ undos: []
1491
+ };
1492
+ const { unitId, subUnitId } = this._copyInfo;
1493
+ const redos = [];
1494
+ const undos = [];
1495
+ const { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
1496
+ getRepeatRange(vCopyRange, vPastedRange, true).forEach(({ startRange }) => {
1497
+ var _this$_copyInfo;
1498
+ (_this$_copyInfo = this._copyInfo) === null || _this$_copyInfo === void 0 || _this$_copyInfo.matrix.forValue((row, col, ruleId) => {
1499
+ const range = Rectangle.getPositionRange({
1500
+ startRow: row,
1501
+ endRow: row,
1502
+ startColumn: col,
1503
+ endColumn: col
1504
+ }, startRange);
1505
+ const oldLink = this._hyperLinkModel.getHyperLink(unitId, subUnitId, ruleId);
1506
+ const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1507
+ const currentLink = this._hyperLinkModel.getHyperLinkByLocation(copyInfo.unitId, copyInfo.subUnitId, startRow, startColumn);
1508
+ const id = generateRandomId();
1509
+ if (currentLink) redos.push({
1510
+ id: RemoveHyperLinkMutation.id,
1511
+ params: {
1512
+ unitId: copyInfo.unitId,
1513
+ subUnitId: copyInfo.subUnitId,
1514
+ id: currentLink.id
1515
+ }
1516
+ });
1517
+ if (oldLink) {
1518
+ redos.push({
1519
+ id: AddHyperLinkMutation.id,
1520
+ params: {
1521
+ unitId: copyInfo.unitId,
1522
+ subUnitId: copyInfo.subUnitId,
1523
+ link: {
1524
+ ...oldLink,
1525
+ id,
1526
+ row: startRow,
1527
+ column: startColumn
1528
+ }
1529
+ }
1530
+ });
1531
+ undos.push({
1532
+ id: RemoveHyperLinkMutation.id,
1533
+ params: {
1534
+ unitId: copyInfo.unitId,
1535
+ subUnitId: copyInfo.subUnitId,
1536
+ id
1537
+ }
1538
+ });
1539
+ }
1540
+ if (currentLink) undos.push({
1541
+ id: AddHyperLinkMutation.id,
1542
+ params: {
1543
+ unitId: copyInfo.unitId,
1544
+ subUnitId: copyInfo.subUnitId,
1545
+ link: currentLink
1546
+ }
1547
+ });
1548
+ });
1549
+ });
1550
+ return {
1551
+ redos,
1552
+ undos
1553
+ };
1554
+ }
1555
+ };
1556
+ SheetsHyperLinkCopyPasteController = __decorate([
1557
+ __decorateParam(0, ISheetClipboardService),
1558
+ __decorateParam(1, Inject(HyperLinkModel)),
1559
+ __decorateParam(2, Inject(Injector)),
1560
+ __decorateParam(3, Inject(SheetsHyperLinkResolverService))
1561
+ ], SheetsHyperLinkCopyPasteController);
1562
+
1563
+ //#endregion
1564
+ //#region src/menu/menu.ts
1565
+ const getEditingLinkDisable$ = (accessor, unitId = DOCS_ZEN_EDITOR_UNIT_ID_KEY) => {
1566
+ var _accessor$get$getRend;
1567
+ const univerInstanceService = accessor.get(IUniverInstanceService);
1568
+ const docSelctionService = (_accessor$get$getRend = accessor.get(IRenderManagerService).getRenderById(unitId)) === null || _accessor$get$getRend === void 0 ? void 0 : _accessor$get$getRend.with(DocSelectionRenderService);
1569
+ if (!docSelctionService) return of(true);
1570
+ return docSelctionService.textSelectionInner$.pipe(map(() => {
1571
+ const state = accessor.get(IEditorBridgeService).getEditCellState();
1572
+ if (!state) return true;
1573
+ const target = getSheetCommandTarget(univerInstanceService, {
1574
+ unitId: state.unitId,
1575
+ subUnitId: state.sheetId
1576
+ });
1577
+ if (!(target === null || target === void 0 ? void 0 : target.worksheet)) return true;
1578
+ if (getShouldDisableCellLink(accessor, target.worksheet, state.row, state.column) === 1) return true;
1579
+ return shouldDisableAddLink(accessor);
1580
+ }));
1581
+ };
1582
+ const getLinkDisable$ = (accessor) => {
1583
+ var _editorBridgeService$;
1584
+ const univerInstanceService = accessor.get(IUniverInstanceService);
1585
+ const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
1586
+ return ((_editorBridgeService$ = editorBridgeService === null || editorBridgeService === void 0 ? void 0 : editorBridgeService.currentEditCellState$.pipe(map((state) => {
1587
+ if (!state) return DisableLinkType.DISABLED_BY_CELL;
1588
+ const target = getSheetCommandTarget(univerInstanceService, {
1589
+ unitId: state.unitId,
1590
+ subUnitId: state.sheetId
1591
+ });
1592
+ if (!target) return DisableLinkType.DISABLED_BY_CELL;
1593
+ return getShouldDisableCellLink(accessor, target.worksheet, state.row, state.column);
1594
+ }), switchMap((disableCell) => {
1595
+ if (disableCell === DisableLinkType.DISABLED_BY_CELL) return of(true);
1596
+ return combineLatest([editorBridgeService ? editorBridgeService.visible$ : of(null), univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC)]).pipe(switchMap(([editing, focusingDoc]) => {
1597
+ return (editing === null || editing === void 0 ? void 0 : editing.visible) ? (focusingDoc === null || focusingDoc === void 0 ? void 0 : focusingDoc.getUnitId()) === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY ? of(true) : getEditingLinkDisable$(accessor, DOCS_NORMAL_EDITOR_UNIT_ID_KEY) : of(disableCell !== DisableLinkType.ALLOWED);
1598
+ }));
1599
+ }))) !== null && _editorBridgeService$ !== void 0 ? _editorBridgeService$ : of(true)).pipe(switchMap((disableCell) => {
1600
+ if (disableCell) return of(true);
1601
+ else return getCurrentRangeDisable$(accessor, {
1602
+ workbookTypes: [WorkbookEditablePermission],
1603
+ worksheetTypes: [
1604
+ WorksheetEditPermission,
1605
+ WorksheetSetCellValuePermission,
1606
+ WorksheetInsertHyperlinkPermission
1607
+ ],
1608
+ rangeTypes: [RangeProtectionPermissionEditPoint]
1609
+ }, true);
1610
+ }));
1611
+ };
1612
+ const linkMenu = {
1613
+ commandId: InsertHyperLinkOperation.id,
1614
+ type: MenuItemType.BUTTON,
1615
+ title: "hyperLink.menu.add",
1616
+ icon: "LinkIcon"
1617
+ };
1618
+ const genZenEditorMenuId = (id) => `${id}-zen-editor`;
1619
+ const insertLinkMenuFactory = (accessor) => {
1620
+ return {
1621
+ ...linkMenu,
1622
+ id: linkMenu.commandId,
1623
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1624
+ disabled$: getLinkDisable$(accessor)
1625
+ };
1626
+ };
1627
+ const zenEditorInsertLinkMenuFactory = (accessor) => {
1628
+ return {
1629
+ ...linkMenu,
1630
+ id: genZenEditorMenuId(linkMenu.commandId),
1631
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1632
+ disabled$: getEditingLinkDisable$(accessor)
1633
+ };
1634
+ };
1635
+ const linkToolbarMenu = {
1636
+ tooltip: "hyperLink.form.addTitle",
1637
+ commandId: InsertHyperLinkToolbarOperation.id,
1638
+ type: MenuItemType.BUTTON,
1639
+ icon: "LinkIcon"
1640
+ };
1641
+ const insertLinkMenuToolbarFactory = (accessor) => {
1642
+ return {
1643
+ ...linkToolbarMenu,
1644
+ id: linkToolbarMenu.commandId,
1645
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1646
+ disabled$: getLinkDisable$(accessor)
1647
+ };
1648
+ };
1649
+ const zenEditorInsertLinkMenuToolbarFactory = (accessor) => {
1650
+ return {
1651
+ ...linkToolbarMenu,
1652
+ id: genZenEditorMenuId(linkToolbarMenu.commandId),
1653
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1654
+ disabled$: getEditingLinkDisable$(accessor)
1655
+ };
1656
+ };
1657
+ const InsertLinkShortcut = {
1658
+ id: InsertHyperLinkToolbarOperation.id,
1659
+ binding: KeyCode.K | MetaKeys.CTRL_COMMAND,
1660
+ preconditions: whenSheetEditorFocused
1661
+ };
1662
+
1663
+ //#endregion
1664
+ //#region package.json
1665
+ var name = "@univerjs/sheets-hyper-link-ui";
1666
+ var version = "0.21.0";
1667
+
1668
+ //#endregion
1669
+ //#region src/controllers/auto-fill.controller.ts
1670
+ let SheetsHyperLinkAutoFillController = class SheetsHyperLinkAutoFillController extends Disposable {
1671
+ constructor(_autoFillService, _hyperLinkModel) {
1672
+ super();
1673
+ this._autoFillService = _autoFillService;
1674
+ this._hyperLinkModel = _hyperLinkModel;
1675
+ this._initAutoFill();
1676
+ }
1677
+ _initAutoFill() {
1678
+ const noopReturnFunc = () => ({
1679
+ redos: [],
1680
+ undos: []
1681
+ });
1682
+ const generalApplyFunc = (location, applyType) => {
1683
+ const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
1684
+ const virtualRange = virtualizeDiscreteRanges([sourceRange, targetRange]);
1685
+ const [vSourceRange, vTargetRange] = virtualRange.ranges;
1686
+ const { mapFunc } = virtualRange;
1687
+ const sourceStartCell = {
1688
+ row: vSourceRange.startRow,
1689
+ col: vSourceRange.startColumn
1690
+ };
1691
+ const repeats = AutoFillTools.getAutoFillRepeatRange(vSourceRange, vTargetRange);
1692
+ const redos = [];
1693
+ const undos = [];
1694
+ repeats.forEach((repeat) => {
1695
+ const targetStartCell = repeat.repeatStartCell;
1696
+ const relativeRange = repeat.relativeRange;
1697
+ const sourceRange = {
1698
+ startRow: sourceStartCell.row,
1699
+ startColumn: sourceStartCell.col,
1700
+ endColumn: sourceStartCell.col,
1701
+ endRow: sourceStartCell.row
1702
+ };
1703
+ const targetRange = {
1704
+ startRow: targetStartCell.row,
1705
+ startColumn: targetStartCell.col,
1706
+ endColumn: targetStartCell.col,
1707
+ endRow: targetStartCell.row
1708
+ };
1709
+ Range.foreach(relativeRange, (row, col) => {
1710
+ const sourcePositionRange = Rectangle.getPositionRange({
1711
+ startRow: row,
1712
+ startColumn: col,
1713
+ endColumn: col,
1714
+ endRow: row
1715
+ }, sourceRange);
1716
+ const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn);
1717
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, sourceRow, sourceCol);
1718
+ const targetPositionRange = Rectangle.getPositionRange({
1719
+ startRow: row,
1720
+ startColumn: col,
1721
+ endColumn: col,
1722
+ endRow: row
1723
+ }, targetRange);
1724
+ const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
1725
+ const id = generateRandomId();
1726
+ const currentLink = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, targetRow, targetCol);
1727
+ if (currentLink) redos.push({
1728
+ id: RemoveHyperLinkMutation.id,
1729
+ params: {
1730
+ unitId,
1731
+ subUnitId,
1732
+ id: currentLink.id
1733
+ }
1734
+ });
1735
+ if ((AUTO_FILL_APPLY_TYPE.COPY === applyType || AUTO_FILL_APPLY_TYPE.SERIES === applyType) && link) {
1736
+ redos.push({
1737
+ id: AddHyperLinkMutation.id,
1738
+ params: {
1739
+ unitId,
1740
+ subUnitId,
1741
+ link: {
1742
+ ...link,
1743
+ id,
1744
+ row: targetRow,
1745
+ column: targetCol
1746
+ }
1747
+ }
1748
+ });
1749
+ undos.push({
1750
+ id: RemoveHyperLinkMutation.id,
1751
+ params: {
1752
+ unitId,
1753
+ subUnitId,
1754
+ id
1755
+ }
1756
+ });
1757
+ }
1758
+ if (currentLink) undos.push({
1759
+ id: AddHyperLinkMutation.id,
1760
+ params: {
1761
+ unitId,
1762
+ subUnitId,
1763
+ link: currentLink
1764
+ }
1765
+ });
1766
+ });
1767
+ });
1768
+ return {
1769
+ undos,
1770
+ redos
1771
+ };
1772
+ };
1773
+ const hook = {
1774
+ id: SHEET_HYPER_LINK_UI_PLUGIN,
1775
+ onFillData: (location, direction, applyType) => {
1776
+ if (applyType === AUTO_FILL_APPLY_TYPE.COPY || applyType === AUTO_FILL_APPLY_TYPE.ONLY_FORMAT || applyType === AUTO_FILL_APPLY_TYPE.SERIES) return generalApplyFunc(location, applyType);
1777
+ return noopReturnFunc();
1778
+ }
1779
+ };
1780
+ this.disposeWithMe(this._autoFillService.addHook(hook));
1781
+ }
1782
+ };
1783
+ SheetsHyperLinkAutoFillController = __decorate([__decorateParam(0, IAutoFillService), __decorateParam(1, Inject(HyperLinkModel))], SheetsHyperLinkAutoFillController);
1784
+
1785
+ //#endregion
1786
+ //#region src/controllers/hyper-link-permission.controller.ts
1787
+ let SheetsHyperLinkPermissionController = class SheetsHyperLinkPermissionController extends Disposable {
1788
+ constructor(_localeService, _commandService, _sheetPermissionCheckController) {
1789
+ super();
1790
+ this._localeService = _localeService;
1791
+ this._commandService = _commandService;
1792
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
1793
+ this._commandExecutedListener();
1794
+ }
1795
+ _commandExecutedListener() {
1796
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1797
+ if (command.id === InsertLinkShortcut.id) {
1798
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1799
+ workbookTypes: [WorkbookEditablePermission],
1800
+ rangeTypes: [RangeProtectionPermissionEditPoint],
1801
+ worksheetTypes: [
1802
+ WorksheetEditPermission,
1803
+ WorksheetSetCellValuePermission,
1804
+ WorksheetInsertHyperlinkPermission
1805
+ ]
1806
+ })) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr"));
1807
+ }
1808
+ }));
1809
+ }
1810
+ };
1811
+ SheetsHyperLinkPermissionController = __decorate([
1812
+ __decorateParam(0, Inject(LocaleService)),
1813
+ __decorateParam(1, ICommandService),
1814
+ __decorateParam(2, Inject(SheetPermissionCheckController))
1815
+ ], SheetsHyperLinkPermissionController);
1816
+
1817
+ //#endregion
1818
+ //#region src/controllers/popup.controller.ts
1819
+ let SheetsHyperLinkPopupController = class SheetsHyperLinkPopupController extends Disposable {
1820
+ constructor(_hoverManagerService, _sheetsHyperLinkPopupService, _renderManagerService, _permissionService, _sheetPermissionCheckController, _commandService, _editorBridgeService, _textSelectionManagerService, _univerInstanceService, _zenZoneService) {
1821
+ super();
1822
+ this._hoverManagerService = _hoverManagerService;
1823
+ this._sheetsHyperLinkPopupService = _sheetsHyperLinkPopupService;
1824
+ this._renderManagerService = _renderManagerService;
1825
+ this._permissionService = _permissionService;
1826
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
1827
+ this._commandService = _commandService;
1828
+ this._editorBridgeService = _editorBridgeService;
1829
+ this._textSelectionManagerService = _textSelectionManagerService;
1830
+ this._univerInstanceService = _univerInstanceService;
1831
+ this._zenZoneService = _zenZoneService;
1832
+ this._initHoverListener();
1833
+ this._initCommandListener();
1834
+ this._initHoverEditingListener();
1835
+ this._initTextSelectionListener();
1836
+ this._initZenEditor();
1837
+ }
1838
+ _getLinkPermission(location) {
1839
+ const { unitId, subUnitId, row: currentRow, col: currentCol } = location;
1840
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1841
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1842
+ if (!worksheet) return {
1843
+ viewPermission: false,
1844
+ editPermission: false,
1845
+ copyPermission: false
1846
+ };
1847
+ const viewPermission = this._sheetPermissionCheckController.permissionCheckWithRanges({
1848
+ workbookTypes: [WorkbookViewPermission],
1849
+ worksheetTypes: [WorksheetViewPermission],
1850
+ rangeTypes: [RangeProtectionPermissionViewPoint]
1851
+ }, [{
1852
+ startRow: currentRow,
1853
+ startColumn: currentCol,
1854
+ endRow: currentRow,
1855
+ endColumn: currentCol
1856
+ }], unitId, subUnitId);
1857
+ let editPermission = this._sheetPermissionCheckController.permissionCheckWithRanges({
1858
+ workbookTypes: [WorkbookEditablePermission],
1859
+ worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],
1860
+ rangeTypes: [RangeProtectionPermissionEditPoint]
1861
+ }, [{
1862
+ startRow: currentRow,
1863
+ startColumn: currentCol,
1864
+ endRow: currentRow,
1865
+ endColumn: currentCol
1866
+ }], unitId, subUnitId);
1867
+ const cell = worksheet.getCellRaw(currentRow, currentCol);
1868
+ if ((cell === null || cell === void 0 ? void 0 : cell.f) && cell.f.startsWith("=HYPERLINK(")) editPermission = false;
1869
+ const copyPermission = this._permissionService.composePermission([new WorkbookCopyPermission(unitId).id, new WorksheetCopyPermission(unitId, subUnitId).id]).every((permission) => permission.value);
1870
+ return {
1871
+ viewPermission,
1872
+ editPermission,
1873
+ copyPermission
1874
+ };
1875
+ }
1876
+ _initHoverListener() {
1877
+ this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(debounceTime(200)).subscribe((currentCell) => {
1878
+ var _currentCell$customRa, _renderer$with$getSke, _style$tr;
1879
+ if (!currentCell || ((_currentCell$customRa = currentCell.customRange) === null || _currentCell$customRa === void 0 ? void 0 : _currentCell$customRa.rangeType) !== CustomRangeType.HYPERLINK) {
1880
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
1881
+ return;
1882
+ }
1883
+ const { unitId, subUnitId, row, col } = currentCell;
1884
+ const renderer = this._renderManagerService.getRenderById(unitId);
1885
+ if (!renderer) return;
1886
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1887
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1888
+ if (!worksheet) return;
1889
+ if (!renderer.with(HoverRenderController).active) {
1890
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING);
1891
+ return;
1892
+ }
1893
+ const skeleton = renderer === null || renderer === void 0 || (_renderer$with$getSke = renderer.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _renderer$with$getSke === void 0 ? void 0 : _renderer$with$getSke.skeleton;
1894
+ const currentCol = col;
1895
+ const currentRow = row;
1896
+ let targetRow = currentRow;
1897
+ let targetCol = currentCol;
1898
+ if (skeleton) skeleton.overflowCache.forValue((row, col, value) => {
1899
+ if (Rectangle.contains(value, {
1900
+ startColumn: currentCol,
1901
+ endColumn: currentCol,
1902
+ startRow: currentRow,
1903
+ endRow: currentRow
1904
+ })) {
1905
+ targetRow = row;
1906
+ targetCol = col;
1907
+ }
1908
+ });
1909
+ const { viewPermission, editPermission, copyPermission } = this._getLinkPermission(currentCell);
1910
+ if (!viewPermission) {
1911
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
1912
+ return;
1913
+ }
1914
+ const cell = worksheet.getCellStyleOnly(targetRow, targetCol);
1915
+ const style = workbook.getStyles().getStyleByCell(cell);
1916
+ const tr = style === null || style === void 0 || (_style$tr = style.tr) === null || _style$tr === void 0 ? void 0 : _style$tr.a;
1917
+ if (!tr && !currentCell.customRange) {
1918
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
1919
+ return;
1920
+ }
1921
+ this._sheetsHyperLinkPopupService.showPopup({
1922
+ row: targetRow,
1923
+ col: targetCol,
1924
+ editPermission,
1925
+ copyPermission,
1926
+ customRange: currentCell.customRange,
1927
+ customRangeRect: currentCell.rect,
1928
+ type: HyperLinkEditSourceType.VIEWING,
1929
+ unitId,
1930
+ subUnitId,
1931
+ showAll: Boolean(tr)
1932
+ });
1933
+ }));
1934
+ }
1935
+ _initHoverEditingListener() {
1936
+ let subscribe = null;
1937
+ this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(switchMap((state) => this._editorBridgeService.visible$.pipe(map((visible) => ({
1938
+ visible,
1939
+ state
1940
+ }))))).subscribe(({ visible, state }) => {
1941
+ if (!state) return;
1942
+ if (state.editorUnitId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
1943
+ if (!visible.visible) {
1944
+ subscribe === null || subscribe === void 0 || subscribe.unsubscribe();
1945
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING);
1946
+ this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
1947
+ return;
1948
+ }
1949
+ const { editorUnitId, unitId, sheetId, row, column } = state;
1950
+ const renderer = this._renderManagerService.getRenderById(editorUnitId);
1951
+ if (!renderer) return;
1952
+ const { editPermission, viewPermission, copyPermission } = this._getLinkPermission({
1953
+ unitId,
1954
+ subUnitId: sheetId,
1955
+ row,
1956
+ col: column
1957
+ });
1958
+ const docEventService = renderer.with(DocEventManagerService);
1959
+ if (!viewPermission) return;
1960
+ subscribe === null || subscribe === void 0 || subscribe.unsubscribe();
1961
+ subscribe = docEventService.hoverCustomRanges$.pipe(debounceTime(200)).subscribe((customRanges) => {
1962
+ var _this$_renderManagerS;
1963
+ const customRange = customRanges.find((customRange) => customRange.range.rangeType === CustomRangeType.HYPERLINK);
1964
+ if (!customRange) {
1965
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
1966
+ return;
1967
+ }
1968
+ const rect = customRange.rects[customRange.rects.length - 1];
1969
+ if (!((_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.with(SheetSkeletonManagerService).getSkeletonParam(sheetId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.skeleton) || !rect) return;
1970
+ const canvasClientRect = renderer.engine.getCanvasElement().getBoundingClientRect();
1971
+ this._sheetsHyperLinkPopupService.showPopup({
1972
+ unitId,
1973
+ subUnitId: sheetId,
1974
+ row,
1975
+ col: column,
1976
+ customRange: customRange.range,
1977
+ customRangeRect: {
1978
+ left: rect.left + canvasClientRect.left,
1979
+ top: rect.top + canvasClientRect.top,
1980
+ bottom: rect.bottom + canvasClientRect.top,
1981
+ right: rect.right + canvasClientRect.left
1982
+ },
1983
+ editPermission,
1984
+ copyPermission,
1985
+ type: HyperLinkEditSourceType.EDITING
1986
+ });
1987
+ });
1988
+ }));
1989
+ this.disposeWithMe(() => {
1990
+ subscribe === null || subscribe === void 0 || subscribe.unsubscribe();
1991
+ });
1992
+ }
1993
+ _initZenEditor() {
1994
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
1995
+ if (visible) {
1996
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING);
1997
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING);
1998
+ this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
1999
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING);
2000
+ } else {
2001
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.ZEN_EDITOR);
2002
+ this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.ZEN_EDITOR);
2003
+ }
2004
+ }));
2005
+ this.disposeWithMe(this._univerInstanceService.focused$.pipe(switchMap((id) => {
2006
+ const render = id === DOCS_ZEN_EDITOR_UNIT_ID_KEY ? this._renderManagerService.getRenderById(id) : null;
2007
+ if (render) return render.with(DocEventManagerService).hoverCustomRanges$.pipe(debounceTime(200));
2008
+ return new Observable((sub) => {
2009
+ sub.next(null);
2010
+ });
2011
+ })).subscribe((value) => {
2012
+ const range = value === null || value === void 0 ? void 0 : value.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
2013
+ const state = this._editorBridgeService.getEditCellState();
2014
+ if (range && state) {
2015
+ const { unitId, sheetId, row, column } = state;
2016
+ const { editPermission, viewPermission, copyPermission } = this._getLinkPermission({
2017
+ unitId,
2018
+ subUnitId: sheetId,
2019
+ row,
2020
+ col: column
2021
+ });
2022
+ if (viewPermission) this._sheetsHyperLinkPopupService.showPopup({
2023
+ type: HyperLinkEditSourceType.ZEN_EDITOR,
2024
+ unitId,
2025
+ subUnitId: sheetId,
2026
+ row,
2027
+ col: column,
2028
+ customRange: range.range,
2029
+ editPermission,
2030
+ copyPermission
2031
+ });
2032
+ } else this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.ZEN_EDITOR);
2033
+ }));
2034
+ }
2035
+ _initTextSelectionListener() {
2036
+ this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe((selection) => {
2037
+ if (selection && selection.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
2038
+ }));
2039
+ }
2040
+ _initCommandListener() {
2041
+ const HIDE_COMMAND_LIST = [
2042
+ ClearSelectionContentCommand.id,
2043
+ ClearSelectionAllCommand.id,
2044
+ ClearSelectionFormatCommand.id
2045
+ ];
2046
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2047
+ if (HIDE_COMMAND_LIST.includes(command.id)) this._sheetsHyperLinkPopupService.hideCurrentPopup();
2048
+ }));
2049
+ }
2050
+ };
2051
+ SheetsHyperLinkPopupController = __decorate([
2052
+ __decorateParam(0, Inject(HoverManagerService)),
2053
+ __decorateParam(1, Inject(SheetsHyperLinkPopupService)),
2054
+ __decorateParam(2, Inject(IRenderManagerService)),
2055
+ __decorateParam(3, Inject(IPermissionService)),
2056
+ __decorateParam(4, Inject(SheetPermissionCheckController)),
2057
+ __decorateParam(5, ICommandService),
2058
+ __decorateParam(6, IEditorBridgeService),
2059
+ __decorateParam(7, Inject(DocSelectionManagerService)),
2060
+ __decorateParam(8, IUniverInstanceService),
2061
+ __decorateParam(9, IZenZoneService)
2062
+ ], SheetsHyperLinkPopupController);
2063
+
2064
+ //#endregion
2065
+ //#region src/controllers/render-controllers/render.controller.ts
2066
+ let SheetsHyperLinkRenderController = class SheetsHyperLinkRenderController extends Disposable {
2067
+ constructor(_context, _hyperLinkModel) {
2068
+ super();
2069
+ this._context = _context;
2070
+ this._hyperLinkModel = _hyperLinkModel;
2071
+ this._initSkeletonChange();
2072
+ }
2073
+ _initSkeletonChange() {
2074
+ const markSkeletonDirty = () => {
2075
+ var _this$_context$mainCo;
2076
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeForceDirty();
2077
+ };
2078
+ this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(debounceTime(16)).subscribe(() => {
2079
+ markSkeletonDirty();
2080
+ }));
2081
+ }
2082
+ };
2083
+ SheetsHyperLinkRenderController = __decorate([__decorateParam(1, Inject(HyperLinkModel))], SheetsHyperLinkRenderController);
2084
+
2085
+ //#endregion
2086
+ //#region src/menu/schema.ts
2087
+ const menuSchema = {
2088
+ [RibbonInsertGroup.MEDIA]: {
2089
+ [InsertHyperLinkToolbarOperation.id]: {
2090
+ order: 1,
2091
+ menuItemFactory: insertLinkMenuToolbarFactory
2092
+ },
2093
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2094
+ order: 1,
2095
+ menuItemFactory: zenEditorInsertLinkMenuToolbarFactory
2096
+ }
2097
+ },
2098
+ [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: {
2099
+ order: 1,
2100
+ [InsertHyperLinkToolbarOperation.id]: {
2101
+ order: 0,
2102
+ menuItemFactory: insertLinkMenuFactory
2103
+ },
2104
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2105
+ order: 0,
2106
+ menuItemFactory: zenEditorInsertLinkMenuFactory
2107
+ }
2108
+ } }
2109
+ };
2110
+
2111
+ //#endregion
2112
+ //#region src/controllers/ui.controller.ts
2113
+ /**
2114
+ * Copyright 2023-present DreamNum Co., Ltd.
2115
+ *
2116
+ * Licensed under the Apache License, Version 2.0 (the "License");
2117
+ * you may not use this file except in compliance with the License.
2118
+ * You may obtain a copy of the License at
2119
+ *
2120
+ * http://www.apache.org/licenses/LICENSE-2.0
2121
+ *
2122
+ * Unless required by applicable law or agreed to in writing, software
2123
+ * distributed under the License is distributed on an "AS IS" BASIS,
2124
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2125
+ * See the License for the specific language governing permissions and
2126
+ * limitations under the License.
2127
+ */
2128
+ let SheetsHyperLinkUIController = class SheetsHyperLinkUIController extends Disposable {
2129
+ constructor(_componentManager, _commandService, _menuManagerService, _injector, _shortcutService) {
2130
+ super();
2131
+ this._componentManager = _componentManager;
2132
+ this._commandService = _commandService;
2133
+ this._menuManagerService = _menuManagerService;
2134
+ this._injector = _injector;
2135
+ this._shortcutService = _shortcutService;
2136
+ this._initComponents();
2137
+ this._initCommands();
2138
+ this._initMenus();
2139
+ this._initShortCut();
2140
+ }
2141
+ _initComponents() {
2142
+ [
2143
+ [CellLinkPopup.componentKey, CellLinkPopup],
2144
+ [CellLinkEdit.componentKey, CellLinkEdit],
2145
+ ["LinkIcon", LinkIcon]
2146
+ ].forEach(([key, comp]) => {
2147
+ this._componentManager.register(key, comp);
2148
+ });
2149
+ }
2150
+ _initCommands() {
2151
+ [
2152
+ OpenHyperLinkEditPanelOperation,
2153
+ CloseHyperLinkPopupOperation,
2154
+ InsertHyperLinkOperation,
2155
+ InsertHyperLinkToolbarOperation
2156
+ ].forEach((command) => {
2157
+ this._commandService.registerCommand(command);
2158
+ });
2159
+ }
2160
+ _initMenus() {
2161
+ this._menuManagerService.mergeMenu(menuSchema);
2162
+ }
2163
+ _initShortCut() {
2164
+ this._shortcutService.registerShortcut(InsertLinkShortcut);
2165
+ }
2166
+ };
2167
+ SheetsHyperLinkUIController = __decorate([
2168
+ __decorateParam(0, Inject(ComponentManager)),
2169
+ __decorateParam(1, ICommandService),
2170
+ __decorateParam(2, IMenuManagerService),
2171
+ __decorateParam(3, Inject(Injector)),
2172
+ __decorateParam(4, Inject(IShortcutService))
2173
+ ], SheetsHyperLinkUIController);
2174
+
2175
+ //#endregion
2176
+ //#region src/controllers/url.controller.ts
2177
+ /**
2178
+ * Copyright 2023-present DreamNum Co., Ltd.
2179
+ *
2180
+ * Licensed under the Apache License, Version 2.0 (the "License");
2181
+ * you may not use this file except in compliance with the License.
2182
+ * You may obtain a copy of the License at
2183
+ *
2184
+ * http://www.apache.org/licenses/LICENSE-2.0
2185
+ *
2186
+ * Unless required by applicable law or agreed to in writing, software
2187
+ * distributed under the License is distributed on an "AS IS" BASIS,
2188
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2189
+ * See the License for the specific language governing permissions and
2190
+ * limitations under the License.
2191
+ */
2192
+ let SheetHyperLinkUrlController = class SheetHyperLinkUrlController extends Disposable {
2193
+ constructor(_parserService, _resolverService) {
2194
+ super();
2195
+ this._parserService = _parserService;
2196
+ this._resolverService = _resolverService;
2197
+ this._handleInitUrl();
2198
+ }
2199
+ _handleInitUrl() {
2200
+ const hash = location.hash;
2201
+ if (hash) {
2202
+ const linkInfo = this._parserService.parseHyperLink(hash);
2203
+ this._resolverService.navigate(linkInfo);
2204
+ }
2205
+ }
2206
+ };
2207
+ SheetHyperLinkUrlController = __decorate([__decorateParam(0, Inject(SheetsHyperLinkParserService)), __decorateParam(1, Inject(SheetsHyperLinkResolverService))], SheetHyperLinkUrlController);
2208
+
2209
+ //#endregion
2210
+ //#region src/plugin.ts
2211
+ let UniverSheetsHyperLinkUIPlugin = class UniverSheetsHyperLinkUIPlugin extends Plugin {
2212
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
2213
+ super();
2214
+ this._config = _config;
2215
+ this._injector = _injector;
2216
+ this._configService = _configService;
2217
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
2218
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
2219
+ this._configService.setConfig(SHEETS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
2220
+ }
2221
+ onStarting() {
2222
+ [
2223
+ [SheetsHyperLinkResolverService],
2224
+ [SheetsHyperLinkPopupService],
2225
+ [SheetsHyperLinkSidePanelService],
2226
+ [SheetsHyperLinkPopupController],
2227
+ [SheetsHyperLinkUIController],
2228
+ [SheetsHyperLinkAutoFillController],
2229
+ [SheetsHyperLinkCopyPasteController],
2230
+ [SheetsHyperLinkPermissionController],
2231
+ [SheetHyperLinkUrlController]
2232
+ ].forEach((dep) => this._injector.add(dep));
2233
+ }
2234
+ onReady() {
2235
+ this._injector.get(IRenderManagerService).registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetsHyperLinkRenderController]);
2236
+ this._injector.get(SheetsHyperLinkAutoFillController);
2237
+ this._injector.get(SheetsHyperLinkCopyPasteController);
2238
+ this._injector.get(SheetsHyperLinkUIController);
2239
+ }
2240
+ onRendered() {
2241
+ this._injector.get(SheetsHyperLinkPermissionController);
2242
+ this._injector.get(SheetHyperLinkUrlController);
2243
+ this._injector.get(SheetsHyperLinkPopupController);
2244
+ }
2245
+ };
2246
+ _defineProperty(UniverSheetsHyperLinkUIPlugin, "pluginName", SHEET_HYPER_LINK_UI_PLUGIN);
2247
+ _defineProperty(UniverSheetsHyperLinkUIPlugin, "packageName", name);
2248
+ _defineProperty(UniverSheetsHyperLinkUIPlugin, "version", version);
2249
+ _defineProperty(UniverSheetsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
2250
+ UniverSheetsHyperLinkUIPlugin = __decorate([
2251
+ DependentOn(UniverSheetsHyperLinkPlugin, UniverDocsUIPlugin),
2252
+ __decorateParam(1, Inject(Injector)),
2253
+ __decorateParam(2, IConfigService)
2254
+ ], UniverSheetsHyperLinkUIPlugin);
2255
+
2256
+ //#endregion
2257
+ export { CloseHyperLinkPopupOperation, InsertHyperLinkOperation, InsertLinkShortcut, OpenHyperLinkEditPanelOperation, SheetsHyperLinkCopyPasteController, SheetsHyperLinkPopupService, SheetsHyperLinkResolverService, SheetsHyperLinkSidePanelService, UniverSheetsHyperLinkUIPlugin };