index.js 60 KB

123456789
  1. "use strict";var Kt=Object.defineProperty;var Yt=(e,n,t)=>n in e?Kt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Z=(e,n,t)=>Yt(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),v=require("@univerjs/sheets-hyper-link"),y=require("@univerjs/sheets-ui"),w=require("@univerjs/design"),X=require("@univerjs/engine-formula"),E=require("@univerjs/sheets"),b=require("@univerjs/ui"),ne=require("@univerjs/docs-ui"),Ce=require("@univerjs/engine-render"),R=require("rxjs"),Ie=require("@univerjs/docs"),I=require("react"),Gt=require("@univerjs/sheets-formula-ui"),mt=require("@univerjs/sheets-data-validation");function Pe(e){return s.Tools.isLegalUrl(e)}function zt(e){return/^[a-zA-Z]+:\/\//.test(e)}function qt(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Jt(e){if(Pe(e)){const n=zt(e)?e:qt(e)?`mailto://${e}`:`http://${e}`;let t;try{t=new URL(n)}catch{return e}return t.hostname===location.hostname&&t.port===location.port&&t.protocol===location.protocol&&t.pathname===location.pathname&&t.hash&&!t.search?t.hash:n}return e}const Ot="sheets-hyper-link-ui.config",ft={};var Xt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(e,n,t,r)=>{for(var i=r>1?void 0:r?Qt(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&Xt(n,t,i),i},ue=(e,n)=>(t,r)=>n(t,r,e);function tn(e,n){const t=n.getMergeData(),r=n.getMaxColumns()-1,i=n.getMaxRows()-1;if(r<e.endColumn&&(e.endColumn=r),i<e.endRow&&(e.endRow=i),e.rangeType===s.RANGE_TYPE.COLUMN||s.RANGE_TYPE.ROW)return e;const c=[];return t.forEach(o=>{s.Rectangle.intersects(e,o)&&c.push(o)}),s.Rectangle.realUnion(e,...c)}exports.SheetsHyperLinkResolverService=class{constructor(n,t,r,i,c,o){this._univerInstanceService=n,this._commandService=t,this._definedNamesService=r,this._messageService=i,this._localeService=c,this._configService=o}navigate(n){switch(n.type){case v.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:t,range:r,rangeid:i}=n,c=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!c)return;const o=c.getUnitId();if(i){const l=this._definedNamesService.getValueById(o,i);if(!l)return;const{formulaOrRefString:u}=l,p=this._definedNamesService.getWorksheetByRef(o,u);if(!p){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:w.MessageType.Error});return}if(p.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error});return}this.navigateToDefineName(o,i)}if(t){if(r){const l=X.deserializeRangeWithSheet(r);s.isValidRange(l.range)&&r!==v.ERROR_RANGE&&this.navigateToRange(o,t,l.range);return}this.navigateToSheetById(o,t)}}async navigateToRange(n,t,r,i){const c=await this.navigateToSheetById(n,t);if(c){const o=tn(r,c);await this._commandService.executeCommand(E.SetSelectionsOperation.id,{unitId:n,subUnitId:t,selections:[{range:o,primary:null}]}),await this._commandService.executeCommand(y.ScrollToRangeOperation.id,{range:o,forceTop:i})}}async navigateToSheetById(n,t){const r=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const i=r.getActiveSheet();if(!i)return!1;if(i.getSheetId()===t)return i;const c=r.getSheetBySheetId(t);return c?r.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error}),!1):await this._commandService.executeCommand(E.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:t})?c:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:w.MessageType.Error}),!1)}async navigateToDefineName(n,t){return this._definedNamesService.focusRange(n,t),!0}async navigateToOtherWebsite(n){var r;const t=this._configService.getConfig(Ot);if((r=t==null?void 0:t.urlHandler)!=null&&r.navigateToOtherWebsite)return t.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}};exports.SheetsHyperLinkResolverService=en([ue(0,s.IUniverInstanceService),ue(1,s.ICommandService),ue(2,X.IDefinedNamesService),ue(3,b.IMessageService),ue(4,s.Inject(s.LocaleService)),ue(5,s.IConfigService)],exports.SheetsHyperLinkResolverService);const qe="SHEET_HYPER_LINK_UI_PLUGIN";var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,sn=(e,n,t,r)=>{for(var i=r>1?void 0:r?rn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&nn(n,t,i),i},Re=(e,n)=>(t,r)=>n(t,r,e);exports.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(t,r,i,c){super();Z(this,"_plainTextFilter",new Set);Z(this,"_copyInfo");this._sheetClipboardService=t,this._hyperLinkModel=r,this._injector=i,this._resolverService=c,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(t){this._plainTextFilter.add(t)}removePlainTextFilter(t){this._plainTextFilter.delete(t)}_filterPlainText(t){return Array.from(this._plainTextFilter).every(r=>r(t))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:qe,onBeforeCopy:(t,r,i)=>this._collect(t,r,i),onPasteCells:(t,r,i,c)=>{const{copyType:o=y.COPY_TYPE.COPY,pasteType:l}=c,{range:u}=t||{},{range:p,unitId:d,subUnitId:h}=r;return this._generateMutations(p,{copyType:o,pasteType:l,copyRange:u,unitId:d,subUnitId:h})},onPastePlainText:(t,r)=>{const i=this._filterPlainText(r);if(Pe(r)&&i){const{range:c,unitId:o,subUnitId:l}=t,{ranges:[u],mapFunc:p}=y.virtualizeDiscreteRanges([c]),d=[],h=[];return s.Range.foreach(u,(S,g)=>{const{row:C,col:L}=p(S,g),P=this._hyperLinkModel.getHyperLinkByLocation(o,l,C,L);P&&d.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:o,subUnitId:l,id:P.id}}),P&&h.push({id:v.AddHyperLinkMutation.id,params:{unitId:o,subUnitId:l,link:P}})}),{redos:d,undos:h}}return{undos:[],redos:[]}},priority:99})}_collect(t,r,i){const c=new s.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:r,matrix:c};const o=this._injector.invoke(p=>y.rangeToDiscreteRange(i,p,t,r));if(!o)return;const{rows:l,cols:u}=o;l.forEach((p,d)=>{u.forEach((h,S)=>{var C;const g=this._hyperLinkModel.getHyperLinkByLocation(t,r,p,h);c.setValue(d,S,(C=g==null?void 0:g.id)!=null?C:"")})})}_generateMutations(t,r){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:c,subUnitId:o}=this._copyInfo,l=[],u=[],{ranges:[p,d],mapFunc:h}=y.virtualizeDiscreteRanges([r.copyRange,t]);return y.getRepeatRange(p,d,!0).forEach(({startRange:g})=>{var C;(C=this._copyInfo)==null||C.matrix.forValue((L,P,a)=>{const k=s.Rectangle.getPositionRange({startRow:L,endRow:L,startColumn:P,endColumn:P},g),x=this._hyperLinkModel.getHyperLink(c,o,a),{row:H,col:N}=h(k.startRow,k.startColumn),B=this._hyperLinkModel.getHyperLinkByLocation(r.unitId,r.subUnitId,H,N),A=s.Tools.generateRandomId();B&&l.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:B.id}}),x&&(l.push({id:v.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:{...x,id:A,row:H,column:N}}}),u.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:A}})),B&&u.push({id:v.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:B}})})}),{redos:l,undos:u}}};exports.SheetsHyperLinkCopyPasteController=sn([Re(0,y.ISheetClipboardService),Re(1,s.Inject(v.HyperLinkModel)),Re(2,s.Inject(s.Injector)),Re(3,s.Inject(exports.SheetsHyperLinkResolverService))],exports.SheetsHyperLinkCopyPasteController);var f=(e=>(e.EDITING="editing",e.VIEWING="viewing",e.ZEN_EDITOR="zen_mode",e))(f||{}),Ke={exports:{}},ve={};/**
  2. * @license React
  3. * react-jsx-runtime.production.min.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */var It;function on(){if(It)return ve;It=1;var e=I,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function o(l,u,p){var d,h={},S=null,g=null;p!==void 0&&(S=""+p),u.key!==void 0&&(S=""+u.key),u.ref!==void 0&&(g=u.ref);for(d in u)r.call(u,d)&&!c.hasOwnProperty(d)&&(h[d]=u[d]);if(l&&l.defaultProps)for(d in u=l.defaultProps,u)h[d]===void 0&&(h[d]=u[d]);return{$$typeof:n,type:l,key:S,ref:g,props:h,_owner:i.current}}return ve.Fragment=t,ve.jsx=o,ve.jsxs=o,ve}var yt;function cn(){return yt||(yt=1,Ke.exports=on()),Ke.exports}var m=cn();class Je extends s.Disposable{constructor(){super(...arguments);Z(this,"_customHyperLinks",new Map)}isBuiltInLinkType(t){return t!==v.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:t})=>t)}findCustomHyperLink(t){return Array.from(this._customHyperLinks.values()).find(i=>i.match(t))}registerCustomHyperLink(t){this._customHyperLinks.set(t.type,t)}getCustomHyperLink(t){return this._customHyperLinks.get(t)}removeCustomHyperLink(t){const{_customHyperLinks:r}=this;r.delete(t)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const an="univer-cell-link-edit",ln="univer-cell-link-edit-buttons",Ct={cellLinkEdit:an,cellLinkEditButtons:ln},Te=()=>{var rt;const[e,n]=I.useState(""),[t,r]=I.useState(!1),[i,c]=I.useState(""),[o,l]=I.useState(!0),[u,p]=I.useState(v.SheetHyperLinkType.URL),[d,h]=I.useState(""),S=s.useDependency(s.LocaleService),g=s.useDependency(X.IDefinedNamesService),C=s.useDependency(y.IEditorBridgeService),L=s.useDependency(s.IUniverInstanceService),P=s.useDependency(exports.SheetsHyperLinkPopupService),a=b.useObservable(P.currentEditing$),k=s.useDependency(v.SheetsHyperLinkParserService),x=s.useDependency(exports.SheetsHyperLinkResolverService),H=s.useDependency(s.ICommandService),N=s.useDependency(Je),B=I.useMemo(()=>N.getOptions(),[N]),A=s.useDependency(b.IZenZoneService),q=s.useDependency(Ce.IRenderManagerService),de=s.useDependency(y.IMarkSelectionService),Ee=s.useDependency(Ie.DocSelectionManagerService),re=s.useDependency(s.IContextService),pe=s.useDependency(s.ThemeService),he=s.useDependency(Ie.DocSelectionManagerService),ge=I.useRef({}),ie=I.useMemo(()=>{if(!N.isBuiltInLinkType(u))return N.getCustomHyperLink(u)},[N,u]),[F,Bt]=I.useState(!1),[_e,Be]=I.useState(!1),$=I.useRef(!1),W=L.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),$t=(W==null?void 0:W.getActiveSheet().getSheetId())||"",Q=I.useCallback(_=>{c(_.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[c]);I.useEffect(()=>{var _,O,T,D,M,K,it,st,ot,ct,at,lt,ut,dt,pt,ht,gt;if((a==null?void 0:a.row)!==void 0&&a.col!==void 0){const{customRange:se,row:Ze,col:We}=a;let{label:J}=a;typeof J=="number"&&(J=`${J}`);let Y;if(se)Y={id:(_=se==null?void 0:se.rangeId)!=null?_:"",display:J!=null?J:"",payload:(T=(O=se==null?void 0:se.properties)==null?void 0:O.url)!=null?T:"",row:Ze,column:We};else if(a.type===f.VIEWING){const U=L.getUnit(a.unitId),te=U==null?void 0:U.getSheetBySheetId(a.subUnitId),j=te==null?void 0:te.getCellRaw(a.row,a.col),le=(K=(M=(D=j==null?void 0:j.p)==null?void 0:D.body)==null?void 0:M.customRanges)==null?void 0:K.find(St=>{var vt;return St.rangeType===s.CustomRangeType.HYPERLINK&&((vt=St.properties)==null?void 0:vt.url)}),Se=j==null?void 0:j.v;j&&(!s.BuildTextUtils.transform.isEmptyDocument((st=(it=j.p)==null?void 0:it.body)==null?void 0:st.dataStream)||s.Tools.isDefine(Se))&&l(!1),Y={id:"",display:"",payload:(ct=(ot=le==null?void 0:le.properties)==null?void 0:ot.url)!=null?ct:"",row:Ze,column:We}}else{const U=L.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),te=Ee.getActiveTextRange(),j=U==null?void 0:U.getBody(),le=te&&j?te:null,Se=le&&((lt=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(at=j==null?void 0:j.customRanges)!=null?at:[]))==null?void 0:lt[0]);l(!1),Y={id:"",display:J!=null?J:"",payload:(dt=(ut=Se==null?void 0:Se.properties)==null?void 0:ut.url)!=null?dt:"",row:Ze,column:We}}n(Y.id);const _t=N.findCustomHyperLink(Y);if(_t){const U=_t.convert(Y);p(U.type),h(U.payload),Q(U.display);return}Q(Y.display);const ee=k.parseHyperLink(Y.payload);switch(p(ee.type===v.SheetHyperLinkType.INVALID?v.SheetHyperLinkType.RANGE:ee.type),ee.type){case v.SheetHyperLinkType.URL:{h(ee.url),ee.url===Y.display&&($.current=!0);break}case v.SheetHyperLinkType.RANGE:{const U=ee.searchObj,te=U.gid&&(gt=(ht=(pt=L.getUnit(a.unitId))==null?void 0:pt.getSheetBySheetId(U.gid))==null?void 0:ht.getName())!=null?gt:"",j=X.serializeRangeWithSheet(te,X.deserializeRangeWithSheet(U.range).range);h(j),j===Y.display&&($.current=!0);break}case v.SheetHyperLinkType.SHEET:{const U=ee.searchObj;h(U.gid);break}case v.SheetHyperLinkType.DEFINE_NAME:{const U=ee.searchObj;h(U.rangeid);break}default:h("");break}}},[a,x,N,Ee,L]),I.useEffect(()=>{let _=null;if(a&&!a.customRangeId&&a.type===f.VIEWING&&s.Tools.isDefine(a.row)&&s.Tools.isDefine(a.col)){const O=L.getUnit(a.unitId,s.UniverInstanceType.UNIVER_SHEET),T=O==null?void 0:O.getSheetBySheetId(a.subUnitId),D=T==null?void 0:T.getMergedCell(a.row,a.col),M=new s.ColorKit(pe.getCurrentTheme().hyacinth500).toRgb();_=de.addShape({range:D!=null?D:{startColumn:a.col,endColumn:a.col,startRow:a.row,endRow:a.row},style:{fill:`rgb(${M.r}, ${M.g}, ${M.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{_&&de.removeShape(_)}},[a,de,pe,L]),I.useEffect(()=>{Be(u===v.SheetHyperLinkType.RANGE)},[u]),I.useEffect(()=>{const _=(a==null?void 0:a.type)===f.ZEN_EDITOR?q.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):q.getRenderById(C.getCurrentEditorId()),O=new s.DisposableCollection;if(_){const T=_.with(ne.DocSelectionRenderService);T.setReserveRangesStatus(!0),O.add(()=>{T.setReserveRangesStatus(!1)})}return()=>{C.disableForceKeepVisible(),O.dispose()}},[a==null?void 0:a.type,C,q]),I.useEffect(()=>(P.setIsKeepVisible(_e),()=>{P.setIsKeepVisible(!1)}),[_e,P]),I.useEffect(()=>()=>{A.temporaryHidden&&(A.show(),re.setContextValue(s.FOCUSING_SHEET,!1))},[re,A]),I.useEffect(()=>{if(_e)return C.enableForceKeepVisible(),()=>{C.disableForceKeepVisible()}},[_e,C]);const Vt=[{label:S.t("hyperLink.form.link"),value:v.SheetHyperLinkType.URL},{label:S.t("hyperLink.form.range"),value:v.SheetHyperLinkType.RANGE},{label:S.t("hyperLink.form.worksheet"),value:v.SheetHyperLinkType.SHEET},{label:S.t("hyperLink.form.definedName"),value:v.SheetHyperLinkType.DEFINE_NAME},...B];if(!W)return;const Ft=W.getHiddenWorksheets(),$e=W.getSheets().map(_=>({label:_.getName(),value:_.getSheetId()})).filter(_=>Ft.indexOf(_.value)===-1),Ve=Object.values((rt=g.getDefinedNameMap(W.getUnitId()))!=null?rt:{}).map(_=>({label:_.name,value:_.id})),nt=(_,O)=>{if(_===v.SheetHyperLinkType.URL)return Jt(O);if(_===v.SheetHyperLinkType.RANGE){const T=X.deserializeRangeWithSheet(O),D=W.getSheetBySheetName(T.sheetName);if(D)return`#gid=${D.getSheetId()}&range=${X.serializeRange(T.range)}`}return`#${_}=${O}`},Zt=b.useEvent(_=>{var M;const T=_.split(",").map(X.deserializeRangeWithSheet)[0];if(!T||!s.isValidRange(T.range))return;T.sheetName||(T.sheetName=((M=W.getActiveSheet())==null?void 0:M.getName())||"");const D=X.serializeRangeToRefString(T);h(D),D&&($.current||!i)&&(Q(D),$.current=!0)}),Fe=async()=>{if(o&&!i||!d||u===v.SheetHyperLinkType.URL&&!Pe(d)){Bt(!0);return}if(a)if(e){const _=a.type===f.ZEN_EDITOR||a.type===f.EDITING?v.UpdateRichHyperLinkCommand.id:v.UpdateHyperLinkCommand.id;await H.executeCommand(_,{id:e,unitId:a.unitId,subUnitId:a.subUnitId,payload:{display:o?i:"",payload:nt(u,d)},row:a.row,column:a.col,documentId:a.type===f.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:C.getCurrentEditorId()})}else{const _=a.type===f.ZEN_EDITOR||a.type===f.EDITING?v.AddRichHyperLinkCommand.id:v.AddHyperLinkCommand.id;await H.executeCommand(_,{unitId:a.unitId,subUnitId:a.subUnitId,link:{id:s.generateRandomId(),row:a.row,column:a.col,payload:nt(u,d),display:o?i:""},documentId:a.type===f.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:C.getCurrentEditorId()})}if((a==null?void 0:a.type)===f.VIEWING){await H.executeCommand(E.SetWorksheetActiveOperation.id,{unitId:a.unitId,subUnitId:a.subUnitId});const _=1;await H.executeCommand(y.ScrollToRangeOperation.id,{range:{startRow:Math.max(a.row-_,0),endRow:a.row+_,startColumn:Math.max(a.col-_,0),endColumn:a.col+_}})}H.executeCommand(ye.id)},Wt=_=>{var T;if(u!==v.SheetHyperLinkType.RANGE)return;const O=(T=ge.current)==null?void 0:T.handleOutClick;O&&O(_,()=>Be(!1))};return a?m.jsxs("div",{className:Ct.cellLinkEdit,style:{display:t?"none":"block"},onClick:Wt,children:[o?m.jsx(w.FormLayout,{label:S.t("hyperLink.form.label"),error:F&&!i?S.t("hyperLink.form.inputError"):"",children:m.jsx(w.Input,{value:i,onChange:_=>{Q(_),$.current=!1},placeholder:S.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===b.KeyCode.ENTER&&Fe()}})}):null,m.jsx(w.FormLayout,{label:S.t("hyperLink.form.type"),children:m.jsx(w.Select,{options:Vt,value:u,onChange:_=>{p(_),h("")}})}),u===v.SheetHyperLinkType.URL&&m.jsx(w.FormLayout,{error:F?d?Pe(d)?"":S.t("hyperLink.form.linkError"):S.t("hyperLink.form.inputError"):"",children:m.jsx(w.Input,{value:d,onChange:_=>{h(_),_&&($.current||!i||i===d)&&(Q(_),$.current=!0)},placeholder:S.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===b.KeyCode.ENTER&&Fe()}})}),u===v.SheetHyperLinkType.RANGE&&m.jsx(w.FormLayout,{error:F&&!d?S.t("hyperLink.form.inputError"):"",children:m.jsx(Gt.RangeSelector,{unitId:W.getUnitId(),subUnitId:$t,isOnlyOneRange:!0,isSupportAcrossSheet:!0,initValue:d,onChange:Zt,isFocus:_e,onFocus:()=>Be(!0),actions:ge.current,onRangeSelectorDialogVisibleChange:async _=>{var O,T;if(_)a.type===f.ZEN_EDITOR&&(A.hide(),re.setContextValue(s.FOCUSING_SHEET,!0)),a.type!==f.VIEWING&&C.enableForceKeepVisible(),r(!0);else{if(await x.navigateToRange(a.unitId,a.subUnitId,{startRow:a.row,endRow:a.row,startColumn:a.col,endColumn:a.col},!0),a.type===f.ZEN_EDITOR){await H.executeCommand(E.SetSelectionsOperation.id,{unitId:a.unitId,subUnitId:a.subUnitId,selections:[{range:{startRow:a.row,endRow:a.row,startColumn:a.col,endColumn:a.col}}]}),A.show(),re.setContextValue(s.FOCUSING_SHEET,!1);const D=(O=q.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:O.with(ne.DocBackScrollRenderController),M=(T=he.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:T[0];D&&M&&(D.scrollToRange(M),he.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}C.disableForceKeepVisible(),r(!1)}}})}),u===v.SheetHyperLinkType.SHEET&&m.jsx(w.FormLayout,{error:F&&!d?S.t("hyperLink.form.selectError"):"",children:m.jsx(w.Select,{options:$e,value:d,onChange:_=>{var D,M;h(_);const O=(D=$e.find(K=>K.value===_))==null?void 0:D.label,T=(M=$e.find(K=>K.value===d))==null?void 0:M.label;O&&($.current||!i||i===T)&&(Q(O),$.current=!0)}})}),u===v.SheetHyperLinkType.DEFINE_NAME&&m.jsx(w.FormLayout,{error:F&&!d?S.t("hyperLink.form.selectError"):"",children:m.jsx(w.Select,{options:Ve,value:d,onChange:_=>{var D,M;h(_);const O=(D=Ve.find(K=>K.value===_))==null?void 0:D.label,T=(M=Ve.find(K=>K.value===d))==null?void 0:M.label;O&&($.current||!i||i===T)&&(Q(O),$.current=!0)}})}),(ie==null?void 0:ie.Form)&&m.jsx(ie.Form,{linkId:e,payload:d,display:i,showError:F,setByPayload:$,setDisplay:_=>{Q(_),$.current=!0},setPayload:h}),m.jsxs("div",{className:Ct.cellLinkEditButtons,children:[m.jsx(w.Button,{onClick:()=>{a&&x.navigateToRange(a.unitId,a.subUnitId,{startRow:a.row,endRow:a.row,startColumn:a.col,endColumn:a.col},!0),H.executeCommand(ye.id)},children:S.t("hyperLink.form.cancel")}),m.jsx(w.Button,{type:"primary",style:{marginLeft:8},onClick:async()=>{Fe()},children:S.t("hyperLink.form.ok")})]})]}):null};Te.componentKey="univer.sheet.cell-link-edit";var V=function(){return V=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++){n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},V.apply(this,arguments)},un=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(t[r[i]]=e[r[i]]);return t},ae=I.forwardRef(function(e,n){var t=e.icon,r=e.id,i=e.className,c=e.extend,o=un(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),u=I.useRef("_".concat(hn()));return bt(t,"".concat(r),{defIds:t.defIds,idSuffix:u.current},V({ref:n,className:l},o),c)});function bt(e,n,t,r,i){return I.createElement(e.tag,V(V({key:n},dn(e,t,i)),r),(pn(e,t).children||[]).map(function(c,o){return bt(c,"".concat(n,"-").concat(e.tag,"-").concat(o),t,void 0,i)}))}function dn(e,n,t){var r=V({},e.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);var i=n.defIds;return!i||i.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+n.idSuffix),Object.entries(r).forEach(function(c){var o=c[0],l=c[1];typeof l=="string"&&(r[o]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),r}function pn(e,n){var t,r=n.defIds;return!r||r.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?V(V({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?V(V({},i),{attrs:V(V({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function hn(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var gn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.9999 1.12915C8.03875 1.12915 8.07673 1.13284 8.11352 1.13989H12.2599C13.6958 1.13989 14.8599 2.30395 14.8599 3.73989V7.88619C14.867 7.92301 14.8707 7.96102 14.8707 7.9999C14.8707 8.03878 14.867 8.0768 14.8599 8.11362V12.2599C14.8599 13.6958 13.6958 14.8599 12.2599 14.8599H8.11362C8.0768 14.867 8.03878 14.8707 7.9999 14.8707C7.96102 14.8707 7.92301 14.867 7.88619 14.8599H3.73989C2.30396 14.8599 1.13989 13.6958 1.13989 12.2599V8.11352C1.13284 8.07673 1.12915 8.03875 1.12915 7.9999C1.12915 7.96106 1.13284 7.92308 1.13989 7.88629V3.73989C1.13989 2.30396 2.30395 1.13989 3.73989 1.13989H7.88629C7.92308 1.13284 7.96106 1.12915 7.9999 1.12915ZM2.33989 8.5999V12.2599C2.33989 13.0331 2.9667 13.6599 3.73989 13.6599H7.3999V8.5999H2.33989ZM7.3999 7.3999H2.33989V3.73989C2.33989 2.9667 2.96669 2.33989 3.73989 2.33989H7.3999V7.3999ZM8.5999 8.5999V13.6599H12.2599C13.0331 13.6599 13.6599 13.0331 13.6599 12.2599V8.5999H8.5999ZM13.6599 7.3999H8.5999V2.33989H12.2599C13.0331 2.33989 13.6599 2.96669 13.6599 3.73989V7.3999Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Le=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"all-border-single",ref:n,icon:gn}))});Le.displayName="AllBorderSingle";var _n={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Dt=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"copy-single",ref:n,icon:_n}))});Dt.displayName="CopySingle";var Sn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z"}}]},Xe=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"link-single",ref:n,icon:Sn}))});Xe.displayName="LinkSingle";var vn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z"}}]},wt=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"unlink-single",ref:n,icon:vn}))});wt.displayName="UnlinkSingle";var mn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},Ht=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"write-single",ref:n,icon:mn}))});Ht.displayName="WriteSingle";var fn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"#fff",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Nt=I.forwardRef(function(e,n){return I.createElement(ae,Object.assign({},e,{id:"xlsx",ref:n,icon:fn}))});Nt.displayName="Xlsx";function Ut(e){var n,t,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(n=0;n<i;n++)e[n]&&(t=Ut(e[n]))&&(r&&(r+=" "),r+=t)}else for(t in e)e[t]&&(r&&(r+=" "),r+=t);return r}function Et(){for(var e,n,t=0,r="",i=arguments.length;t<i;t++)(e=arguments[t])&&(n=Ut(e))&&(r&&(r+=" "),r+=n);return r}const In="univer-cell-link",yn="univer-cell-link-type",Cn="univer-cell-link-content",En="univer-cell-link-content-error",Rn="univer-cell-link-url",Ln="univer-cell-link-operations",Pn="univer-cell-link-operation",Tn="univer-cell-link-operation-error",G={cellLink:In,cellLinkType:yn,cellLinkContent:Cn,cellLinkContentError:En,cellLinkUrl:Rn,cellLinkOperations:Ln,cellLinkOperation:Pn,cellLinkOperationError:Tn},kn={[v.SheetHyperLinkType.URL]:m.jsx(Xe,{}),[v.SheetHyperLinkType.SHEET]:m.jsx(Nt,{}),[v.SheetHyperLinkType.RANGE]:m.jsx(Le,{}),[v.SheetHyperLinkType.DEFINE_NAME]:m.jsx(Le,{}),[v.SheetHyperLinkType.INVALID]:m.jsx(Le,{})},Rt=e=>{var x,H;const n=s.useDependency(exports.SheetsHyperLinkPopupService),t=s.useDependency(s.ICommandService),r=s.useDependency(b.IMessageService),i=s.useDependency(s.LocaleService),c=s.useDependency(exports.SheetsHyperLinkResolverService),o=s.useDependency(y.IEditorBridgeService),l=s.useDependency(v.SheetsHyperLinkParserService),u=s.useDependency(b.IZenZoneService),{customRange:p,row:d,col:h,unitId:S,subUnitId:g,editPermission:C,copyPermission:L,type:P}=e;if(!((x=p==null?void 0:p.properties)!=null&&x.url))return null;const a=l.parseHyperLink((H=p.properties.url)!=null?H:""),k=a.type===v.SheetHyperLinkType.INVALID;return m.jsxs("div",{className:G.cellLink,onClick:()=>n.hideCurrentPopup(),children:[m.jsxs("div",{className:Et(G.cellLinkContent,{[G.cellLinkContentError]:k}),onClick:()=>{u.visible||k||c.navigate(a)},children:[m.jsx("div",{className:G.cellLinkType,children:kn[a.type]}),m.jsx(w.Tooltip,{showIfEllipsis:!0,title:a.name,asChild:!0,children:m.jsx("span",{className:G.cellLinkUrl,children:a.name})})]}),m.jsxs("div",{className:G.cellLinkOperations,children:[L&&m.jsx("div",{className:Et(G.cellLinkOperation,{[G.cellLinkOperationError]:k}),onClick:()=>{if(!k){if(a.type!==v.SheetHyperLinkType.URL){const N=new URL(window.location.href);N.hash=a.url.slice(1),navigator.clipboard.writeText(N.href)}else navigator.clipboard.writeText(a.url);r.show({content:i.t("hyperLink.message.coped"),type:w.MessageType.Info})}},children:m.jsx(w.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.copy"),children:m.jsx(Dt,{})})}),C&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:G.cellLinkOperation,onClick:()=>{t.executeCommand(je.id,{unitId:S,subUnitId:g,row:d,col:h,customRangeId:p.rangeId,type:P})},children:m.jsx(w.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.edit"),children:m.jsx(Ht,{})})}),m.jsx("div",{className:G.cellLinkOperation,onClick:()=>{const N=P===f.EDITING||P===f.ZEN_EDITOR?v.CancelRichHyperLinkCommand.id:v.CancelHyperLinkCommand.id;t.syncExecuteCommand(N,{unitId:S,subUnitId:g,id:p.rangeId,row:d,column:h,documentId:P===f.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:o.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:m.jsx(w.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.cancel"),children:m.jsx(wt,{})})})]})]})]})},ke=()=>{var i,c;const e=s.useDependency(exports.SheetsHyperLinkPopupService),[n,t]=I.useState(null),r=s.useDependency(s.IUniverInstanceService);if(I.useEffect(()=>{t(e.currentPopup);const o=e.currentPopup$.subscribe(l=>{t(l)});return()=>{o.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!n)return null;if(n.showAll){const o=r.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),l=o==null?void 0:o.getSheetBySheetId(n.subUnitId),u=l==null?void 0:l.getCell(n.row,n.col),p=(c=(i=u==null?void 0:u.p)==null?void 0:i.body)==null?void 0:c.customRanges;return p!=null&&p.length?m.jsx("div",{children:p.map(d=>m.jsx(Rt,{...n,customRange:d},d.rangeId))}):null}return m.jsx(Rt,{...n})};ke.componentKey="univer.sheet.cell-link-popup";var On=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Dn=(e,n,t,r)=>{for(var i=r>1?void 0:r?bn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&On(n,t,i),i},oe=(e,n)=>(t,r)=>n(t,r,e);const Lt=(e,n)=>{var t,r;return e.unitId===n.unitId&&e.subUnitId===n.subUnitId&&e.row===n.row&&e.col===n.col&&((t=e.customRange)==null?void 0:t.rangeId)===((r=n.customRange)==null?void 0:r.rangeId)&&e.type===n.type};exports.SheetsHyperLinkPopupService=class extends s.Disposable{constructor(t,r,i,c,o,l,u){super();Z(this,"_currentPopup",null);Z(this,"_currentPopup$",new R.Subject);Z(this,"currentPopup$",this._currentPopup$.asObservable());Z(this,"_currentEditingPopup",null);Z(this,"_currentEditing$",new R.BehaviorSubject(null));Z(this,"currentEditing$",this._currentEditing$.asObservable());Z(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=t,this._injector=r,this._univerInstanceService=i,this._editorBridgeService=c,this._textSelectionManagerService=o,this._docCanvasPopManagerService=l,this._zenZoneService=u,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(t){this._isKeepVisible=t}getIsKeepVisible(){return this._isKeepVisible}showPopup(t){if(this._currentPopup&&Lt(t,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),t.type!==f.ZEN_EDITOR&&this._zenZoneService.visible))return;const r=this._currentEditing$.getValue();if(r&&Lt(t,r))return;const{unitId:i,subUnitId:c,row:o,col:l,customRangeRect:u,customRange:p}=t;let d;const h={componentKey:ke.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(t.type,!0)}};if(t.type===f.EDITING){if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(u,h)}else if(t.type===f.ZEN_EDITOR){if(!p)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:p.startIndex,endOffset:p.endIndex+1,collapsed:!1},h,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,h,i,c);else{if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupByPosition(u,h,t)}d&&(this._currentPopup={unitId:i,subUnitId:c,disposable:d,row:o,col:l,editPermission:!!t.editPermission,copyPermission:!!t.copyPermission,customRange:p,type:t.type,showAll:t.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(t,r){var i,c;this._currentPopup&&((!t||t===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||r)&&((c=(i=this._currentPopup)==null?void 0:i.disposable)==null||c.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}_getEditingRange(){var i,c,o;const t=this._editorBridgeService.isVisible().visible,r=this._editorBridgeService.getEditCellState();if(t&&r){const l=this._textSelectionManagerService.getActiveTextRange(),u=(i=r.documentLayoutObject.documentModel)==null?void 0:i.getBody();if(!u)return null;if(!l||l.collapsed)return{startOffset:0,endOffset:u.dataStream.length-2,collapsed:u.dataStream.length-2===0,label:s.BuildTextUtils.transform.getPlainText(u.dataStream)};const p=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(l,(o=(c=u.customRanges)==null?void 0:c.filter(S=>S.rangeType===s.CustomRangeType.HYPERLINK))!=null?o:[]);let d=l.startOffset,h=l.endOffset;return p.forEach(S=>{d=Math.min(d,S.startIndex),h=Math.max(h,S.endIndex+1)}),{startOffset:d,endOffset:h,collapsed:d===h,label:s.BuildTextUtils.transform.getPlainText(u.dataStream.slice(d,h))}}return null}get _editPopup(){return{componentKey:Te.componentKey,direction:"vertical",onClickOutside:()=>{this.getIsKeepVisible()||this.endEditing()},onContextMenu:()=>{this.getIsKeepVisible()||this.endEditing()},hiddenType:"hide"}}startAddEditing(t){var o,l,u,p,d;const{unitId:r,subUnitId:i,type:c}=t;if(c===f.ZEN_EDITOR){const h=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!h)return;const S=this._textSelectionManagerService.getActiveTextRange();if(!S)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(S,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const g=(o=h.getBody())==null?void 0:o.dataStream.slice(S.startOffset,S.endOffset);this._currentEditing$.next({...t,label:g})}else if(c===f.EDITING){const h=this._getEditingRange();if(!h)return;this._textSelectionManagerService.replaceDocRanges([{...h}],{unitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const S=this._injector.get(Ce.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!S)return;const g=ne.calcDocRangePositions(h,S);if(!(g!=null&&g.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(g.pop(),this._editPopup,r,i),this._currentEditing$.next({...t,label:(l=h==null?void 0:h.label)!=null?l:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,r,i);const h=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),S=h==null?void 0:h.getSheetBySheetId(i),g=S==null?void 0:S.getCellRaw(t.row,t.col);this._currentEditing$.next({...t,label:g!=null&&g.p?s.BuildTextUtils.transform.getPlainText((p=(u=g.p.body)==null?void 0:u.dataStream)!=null?p:""):((d=g==null?void 0:g.v)!=null?d:"").toString()})}}startEditing(t){var l,u,p,d,h,S;(l=this._currentEditingPopup)==null||l.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:r,subUnitId:i}=t;let c,o;if(t.type===f.ZEN_EDITOR){const g=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(c=(p=(u=g==null?void 0:g.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(C=>C.rangeId===t.customRangeId),o=c?(d=g==null?void 0:g.getBody())==null?void 0:d.dataStream.slice(c.startIndex,c.endIndex+1):"",!c||!o)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:c.startIndex,endOffset:c.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:c.startIndex,endOffset:c.endIndex,collapsed:!1},this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.type===f.EDITING){const g=y.getEditingCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!g||!((h=g.rects)!=null&&h.length))return;c=g.customRange,o=g.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:c.startIndex,endOffset:c.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(g.rects.pop(),this._editPopup,r,i)}else{const g=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),C=g==null?void 0:g.getSheetBySheetId(i),L=C==null?void 0:C.getCellRaw(t.row,t.col),P=g==null?void 0:g.getStyles().getStyleByCell(L),a=P==null?void 0:P.tr,k=y.getCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!k||!((S=k.rects)!=null&&S.length))return;c=k.customRange,o=k.label,a?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,r,i):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(k.rects.pop(),this._editPopup,{unitId:r,subUnitId:i,row:t.row,col:t.col})}this._currentEditing$.next({...t,customRange:c,label:o})}endEditing(t){var i;const r=this._currentEditing$.getValue();r&&(!t||t===r.type)&&((i=this._currentEditingPopup)==null||i.dispose(),this._currentEditing$.next(null))}};exports.SheetsHyperLinkPopupService=Dn([oe(0,s.Inject(y.SheetCanvasPopManagerService)),oe(1,s.Inject(s.Injector)),oe(2,s.IUniverInstanceService),oe(3,y.IEditorBridgeService),oe(4,s.Inject(Ie.DocSelectionManagerService)),oe(5,s.Inject(ne.DocCanvasPopManagerService)),oe(6,b.IZenZoneService)],exports.SheetsHyperLinkPopupService);var fe=(e=>(e[e.ALLOWED=0]="ALLOWED",e[e.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",e[e.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",e))(fe||{});const wn=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),Qe=(e,n,t,r)=>{var l,u;const i=n.getCell(t,r);if(i!=null&&i.f||i!=null&&i.si)return 1;const c=e.has(mt.SheetDataValidationModel)?e.get(mt.SheetDataValidationModel):null,o=c==null?void 0:c.getRuleByLocation(n.getUnitId(),n.getSheetId(),t,r);return o&&wn.has(o.type)?!0:(u=(l=i==null?void 0:i.p)==null?void 0:l.drawingsOrder)!=null&&u.length?2:0},Hn=e=>{const n=e.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const t=n.getActiveSheet(),r=e.get(E.SheetsSelectionsService).getCurrentSelections();if(!r.length)return!0;const i=r[0].range.startRow,c=r[0].range.startColumn;return Qe(e,t,i,c)===1},Nn=e=>{const n=e.get(Ie.DocSelectionManagerService),t=e.get(s.IUniverInstanceService),r=n.getTextRanges();if(!(r!=null&&r.length))return!0;const i=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return!!(!i||r.every(o=>o.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},je={type:s.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(e,n){if(!n)return!1;const t=e.get(exports.SheetsHyperLinkPopupService);return n.customRangeId?t.startEditing(n):t.startAddEditing(n),!0}},ye={type:s.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(e){return e.get(exports.SheetsHyperLinkPopupService).endEditing(),!0}},Ae={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(e){var h;const n=e.get(s.IUniverInstanceService),t=E.getSheetCommandTarget(n),r=e.get(y.IEditorBridgeService);if(!t)return!1;const i=e.get(s.ICommandService),o=e.get(E.SheetsSelectionsService).getCurrentLastSelection();if(!o)return!1;const l=o.range.startRow,u=o.range.startColumn,p=r.isVisible(),d=((h=n.getFocusedUnit())==null?void 0:h.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return i.executeCommand(je.id,{unitId:t.unitId,subUnitId:t.subUnitId,row:l,col:u,type:d?f.ZEN_EDITOR:p.visible?f.EDITING:f.VIEWING})}},ce={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(e){if(Hn(e))return!1;const n=e.get(s.ICommandService);return e.get(exports.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ye.id):n.executeCommand(Ae.id)}},et=(e,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var i;const t=e.get(s.IUniverInstanceService),r=(i=e.get(Ce.IRenderManagerService).getRenderById(n))==null?void 0:i.with(ne.DocSelectionRenderService);return r?r.textSelectionInner$.pipe(R.map(()=>{const o=e.get(y.IEditorBridgeService).getEditCellState();if(!o)return!0;const l=E.getSheetCommandTarget(t,{unitId:o.unitId,subUnitId:o.sheetId});return!(l!=null&&l.worksheet)||Qe(e,l.worksheet,o.row,o.column)===1?!0:Nn(e)})):R.of(!0)},Mt=e=>{const n=y.getCurrentRangeDisable$(e,{workbookTypes:[E.WorkbookEditablePermission],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetSetCellValuePermission,E.WorksheetInsertHyperlinkPermission],rangeTypes:[E.RangeProtectionPermissionEditPoint]},!0),t=e.get(s.IUniverInstanceService),r=e.get(E.SheetsSelectionsService),i=e.has(y.IEditorBridgeService)?e.get(y.IEditorBridgeService):null,c=t.focused$.pipe(R.filter(o=>!!o),R.map(o=>t.getUnit(o,s.UniverInstanceType.UNIVER_SHEET)),R.filter(o=>!!o),R.switchMap(o=>o.activeSheet$),R.switchMap(o=>r.selectionMoveEnd$.pipe(R.map(l=>o&&{selections:l,sheet:o}))),R.map(o=>{if(!o)return fe.DISABLED_BY_CELL;const{selections:l,sheet:u}=o;if(!l.length)return fe.DISABLED_BY_CELL;const p=l[0].range.startRow,d=l[0].range.startColumn;return Qe(e,u,p,d)}),R.switchMap(o=>{if(o===fe.DISABLED_BY_CELL)return R.of(!0);const l=(i?i.visible$:R.of(null)).pipe(R.map(p=>p!=null&&p.visible?s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:void 0)),u=e.get(s.IContextService).subscribeContextValue$(s.FOCUSING_FX_BAR_EDITOR);return R.combineLatest([l,u]).pipe(R.switchMap(([p,d])=>p?d?R.of(!0):et(e,p):R.of(o===fe.ALLOW_ON_EDITING)))}));return n.pipe(R.distinctUntilChanged(),R.switchMap(o=>c.pipe(R.map(l=>o||l))))},Oe={commandId:Ae.id,type:b.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkSingle"},be=e=>`${e}-zen-editor`,Un=e=>({...Oe,id:Oe.commandId,hidden$:b.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Mt(e)}),Mn=e=>({...Oe,id:be(Oe.commandId),hidden$:b.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:et(e)}),De={tooltip:"hyperLink.form.addTitle",commandId:ce.id,type:b.MenuItemType.BUTTON,icon:"LinkSingle"},xn=e=>({...De,id:De.commandId,hidden$:b.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Mt(e)}),jn=e=>({...De,id:be(De.commandId),hidden$:b.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:et(e)}),tt={id:ce.id,binding:b.KeyCode.K|b.MetaKeys.CTRL_COMMAND,preconditions:y.whenSheetEditorFocused};var An=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,$n=(e,n,t,r)=>{for(var i=r>1?void 0:r?Bn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&An(n,t,i),i},Pt=(e,n)=>(t,r)=>n(t,r,e);let we=class extends s.Disposable{constructor(e,n){super(),this._autoFillService=e,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),n=(r,i)=>{const{source:c,target:o,unitId:l,subUnitId:u}=r,p=y.virtualizeDiscreteRanges([c,o]),[d,h]=p.ranges,{mapFunc:S}=p,g={row:d.startRow,col:d.startColumn},C=y.getAutoFillRepeatRange(d,h),L=[],P=[];return C.forEach(a=>{const k=a.repeatStartCell,x=a.relativeRange,H={startRow:g.row,startColumn:g.col,endColumn:g.col,endRow:g.row},N={startRow:k.row,startColumn:k.col,endColumn:k.col,endRow:k.row};s.Range.foreach(x,(B,A)=>{const q=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},H),{row:de,col:Ee}=S(q.startRow,q.startColumn),re=this._hyperLinkModel.getHyperLinkByLocation(l,u,de,Ee),pe=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},N),{row:he,col:ge}=S(pe.startRow,pe.startColumn),ie=s.Tools.generateRandomId(),F=this._hyperLinkModel.getHyperLinkByLocation(l,u,he,ge);F&&L.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:F.id}}),(y.APPLY_TYPE.COPY===i||y.APPLY_TYPE.SERIES===i)&&re&&(L.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:{...re,id:ie,row:he,column:ge}}}),P.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:ie}})),F&&P.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:F}})})}),{undos:P,redos:L}},t={id:qe,onFillData:(r,i,c)=>c===y.APPLY_TYPE.COPY||c===y.APPLY_TYPE.ONLY_FORMAT||c===y.APPLY_TYPE.SERIES?n(r,c):e()};this.disposeWithMe(this._autoFillService.addHook(t))}};we=$n([Pt(0,y.IAutoFillService),Pt(1,s.Inject(v.HyperLinkModel))],we);var Vn=Object.defineProperty,Fn=Object.getOwnPropertyDescriptor,Zn=(e,n,t,r)=>{for(var i=r>1?void 0:r?Fn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&Vn(n,t,i),i},Ye=(e,n)=>(t,r)=>n(t,r,e);let He=class extends s.Disposable{constructor(e,n,t){super(),this._localeService=e,this._commandService=n,this._sheetPermissionCheckController=t,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===tt.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookEditablePermission],rangeTypes:[E.RangeProtectionPermissionEditPoint],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetSetCellValuePermission,E.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};He=Zn([Ye(0,s.Inject(s.LocaleService)),Ye(1,s.ICommandService),Ye(2,s.Inject(E.SheetPermissionCheckController))],He);var Wn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,Yn=(e,n,t,r)=>{for(var i=r>1?void 0:r?Kn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&Wn(n,t,i),i},z=(e,n)=>(t,r)=>n(t,r,e);let Ne=class extends s.Disposable{constructor(e,n,t,r,i,c,o,l,u,p){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=n,this._renderManagerService=t,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=c,this._editorBridgeService=o,this._textSelectionManagerService=l,this._univerInstanceService=u,this._zenZoneService=p,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(e){const{unitId:n,subUnitId:t,row:r,col:i}=e,c=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!(c==null?void 0:c.getSheetBySheetId(t)))return{viewPermission:!1,editPermission:!1,copyPermission:!1};const l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookViewPermission],worksheetTypes:[E.WorksheetViewPermission],rangeTypes:[E.RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookEditablePermission],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetInsertHyperlinkPermission],rangeTypes:[E.RangeProtectionPermissionEditPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),p=this._permissionService.composePermission([new E.WorkbookCopyPermission(n).id,new E.WorksheetCopyPermission(n,t).id]).every(d=>d.value);return{viewPermission:l,editPermission:u,copyPermission:p}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(R.debounceTime(200)).subscribe(e=>{var H,N;if(!e){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:t,row:r,col:i}=e,c=this._renderManagerService.getRenderById(n);if(!c)return;const o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),l=o==null?void 0:o.getSheetBySheetId(t);if(!l)return;if(!c.with(y.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(f.VIEWING);return}const p=(H=c==null?void 0:c.with(y.SheetSkeletonManagerService).getWorksheetSkeleton(t))==null?void 0:H.skeleton,d=i,h=r;let S=h,g=d;p&&p.overflowCache.forValue((B,A,q)=>{s.Rectangle.contains(q,{startColumn:d,endColumn:d,startRow:h,endRow:h})&&(S=B,g=A)});const{viewPermission:C,editPermission:L,copyPermission:P}=this._getLinkPermission(e);if(!C){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const a=l.getCellStyleOnly(S,g),k=o.getStyles().getStyleByCell(a),x=(N=k==null?void 0:k.tr)==null?void 0:N.a;if(!x&&!e.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:S,col:g,editPermission:L,copyPermission:P,customRange:e.customRange,customRangeRect:e.rect,type:f.VIEWING,unitId:n,subUnitId:t,showAll:!!x})}))}_initHoverEditingListener(){let e=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(R.switchMap(n=>this._editorBridgeService.visible$.pipe(R.map(t=>({visible:t,state:n}))))).subscribe(({visible:n,state:t})=>{if(!t||t.editorUnitId!==s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){e==null||e.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(f.EDITING),this._sheetsHyperLinkPopupService.endEditing(f.EDITING);return}const{editorUnitId:r,unitId:i,sheetId:c,row:o,column:l}=t,u=this._renderManagerService.getRenderById(r);if(!u)return;const{editPermission:p,viewPermission:d,copyPermission:h}=this._getLinkPermission({unitId:i,subUnitId:c,row:o,col:l}),S=u.with(ne.DocEventManagerService);d&&(e==null||e.unsubscribe(),e=S.hoverCustomRanges$.pipe(R.debounceTime(200)).subscribe(g=>{var k,x;const C=g.find(H=>H.range.rangeType===s.CustomRangeType.HYPERLINK);if(!C){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const L=C.rects[C.rects.length-1];if(!((x=(k=this._renderManagerService.getRenderById(i))==null?void 0:k.with(y.SheetSkeletonManagerService).getWorksheetSkeleton(c))==null?void 0:x.skeleton)||!L)return;const a=u.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:i,subUnitId:c,row:o,col:l,customRange:C.range,customRangeRect:{left:L.left+a.left,top:L.top+a.top,bottom:L.bottom+a.top,right:L.right+a.left},editPermission:p,copyPermission:h,type:f.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(f.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(f.EDITING),this._sheetsHyperLinkPopupService.endEditing(f.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(f.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(f.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(f.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(R.switchMap(e=>{const n=e===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(e):null;return n?n.with(ne.DocEventManagerService).hoverCustomRanges$.pipe(R.debounceTime(200)):new R.Observable(t=>{t.next(null)})})).subscribe(e=>{const n=e==null?void 0:e.find(r=>r.range.rangeType===s.CustomRangeType.HYPERLINK),t=this._editorBridgeService.getEditCellState();if(n&&t){const{unitId:r,sheetId:i,row:c,column:o}=t,{editPermission:l,viewPermission:u,copyPermission:p}=this._getLinkPermission({unitId:r,subUnitId:i,row:c,col:o});u&&this._sheetsHyperLinkPopupService.showPopup({type:f.ZEN_EDITOR,unitId:r,subUnitId:i,row:c,col:o,customRange:n.range,editPermission:l,copyPermission:p})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(f.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(f.EDITING)}))}_initCommandListener(){const e=[E.ClearSelectionContentCommand.id,E.ClearSelectionAllCommand.id,E.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{e.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ne=Yn([z(0,s.Inject(y.HoverManagerService)),z(1,s.Inject(exports.SheetsHyperLinkPopupService)),z(2,s.Inject(Ce.IRenderManagerService)),z(3,s.Inject(s.IPermissionService)),z(4,s.Inject(E.SheetPermissionCheckController)),z(5,s.ICommandService),z(6,y.IEditorBridgeService),z(7,s.Inject(Ie.DocSelectionManagerService)),z(8,s.IUniverInstanceService),z(9,b.IZenZoneService)],Ne);var Gn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,xt=(e,n,t,r)=>{for(var i=r>1?void 0:r?zn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&Gn(n,t,i),i},Ge=(e,n)=>(t,r)=>n(t,r,e);let ze=class extends s.Disposable{constructor(e,n){super(),this._context=e,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const e=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(R.debounceTime(16)).subscribe(()=>{e()}))}};ze=xt([Ge(1,s.Inject(v.HyperLinkModel))],ze);let Ue=class extends s.Disposable{constructor(e,n){super(),this._sheetInterceptorService=e,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(E.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(e,n,t)=>{const{row:r,col:i,unitId:c,subUnitId:o}=n,l=this._hyperLinkModel.getHyperLinkByLocation(c,o,r,i);return t(l?{...e,linkUrl:l.payload,linkId:l.id}:e)}}))}};Ue=xt([Ge(0,s.Inject(E.SheetInterceptorService)),Ge(1,s.Inject(v.HyperLinkModel))],Ue);const qn={[b.RibbonStartGroup.OTHERS]:{[ce.id]:{order:2,menuItemFactory:xn},[be(ce.id)]:{order:2,menuItemFactory:jn}},[b.ContextMenuPosition.MAIN_AREA]:{[b.ContextMenuGroup.OTHERS]:{order:1,[ce.id]:{order:0,menuItemFactory:Un},[be(ce.id)]:{order:0,menuItemFactory:Mn}}}};var Jn=Object.defineProperty,Xn=Object.getOwnPropertyDescriptor,Qn=(e,n,t,r)=>{for(var i=r>1?void 0:r?Xn(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&Jn(n,t,i),i},me=(e,n)=>(t,r)=>n(t,r,e);let Me=class extends s.Disposable{constructor(e,n,t,r,i){super(),this._componentManager=e,this._commandService=n,this._menuManagerService=t,this._injector=r,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[ke,ke.componentKey],[Te,Te.componentKey],[Xe,"LinkSingle"]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[je,ye,Ae,ce].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(qn)}_initShortCut(){this._shortcutService.registerShortcut(tt)}};Me=Qn([me(0,s.Inject(b.ComponentManager)),me(1,s.ICommandService),me(2,b.IMenuManagerService),me(3,s.Inject(s.Injector)),me(4,s.Inject(b.IShortcutService))],Me);var er=Object.defineProperty,tr=Object.getOwnPropertyDescriptor,nr=(e,n,t,r)=>{for(var i=r>1?void 0:r?tr(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&er(n,t,i),i},Tt=(e,n)=>(t,r)=>n(t,r,e);let xe=class extends s.Disposable{constructor(e,n){super(),this._parserService=e,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const e=location.hash;if(e){const n=this._parserService.parseHyperLink(e);this._resolverService.navigate(n)}}};xe=nr([Tt(0,s.Inject(v.SheetsHyperLinkParserService)),Tt(1,s.Inject(exports.SheetsHyperLinkResolverService))],xe);var jt=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ir=(e,n,t)=>n in e?jt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,sr=(e,n,t,r)=>{for(var i=r>1?void 0:r?rr(n,t):n,c=e.length-1,o;c>=0;c--)(o=e[c])&&(i=(r?o(n,t,i):o(i))||i);return r&&i&&jt(n,t,i),i},kt=(e,n)=>(t,r)=>n(t,r,e),At=(e,n,t)=>ir(e,typeof n!="symbol"?n+"":n,t);exports.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=ft,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{menu:i,...c}=s.merge({},ft,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Ot,c)}onStarting(){[[exports.SheetsHyperLinkResolverService],[exports.SheetsHyperLinkPopupService],[Je],[Ue],[Ne],[Me],[we],[exports.SheetsHyperLinkCopyPasteController],[He],[xe]].forEach(t=>this._injector.add(t)),this._injector.get(Ue)}onReady(){this._injector.get(Ce.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[ze]),this._injector.get(we),this._injector.get(exports.SheetsHyperLinkCopyPasteController),this._injector.get(Me)}onRendered(){this._injector.get(He),this._injector.get(xe),this._injector.get(Ne)}};At(exports.UniverSheetsHyperLinkUIPlugin,"pluginName",qe);At(exports.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkUIPlugin=sr([s.DependentOn(v.UniverSheetsHyperLinkPlugin,ne.UniverDocsUIPlugin),kt(1,s.Inject(s.Injector)),kt(2,s.IConfigService)],exports.UniverSheetsHyperLinkUIPlugin);exports.CloseHyperLinkPopupOperation=ye;exports.InsertHyperLinkOperation=Ae;exports.InsertLinkShortcut=tt;exports.OpenHyperLinkEditPanelOperation=je;exports.SheetsHyperLinkSidePanelService=Je;