@univerjs/sheets-hyper-link-ui 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +940 -966
- package/lib/types/services/popup.service.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +16 -17
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Vt=Object.defineProperty;var $t=(e,n,t)=>n in e?Vt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Z=(e,n,t)=>$t(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),S=require("@univerjs/sheets-hyper-link"),f=require("@univerjs/sheets-ui"),H=require("@univerjs/design"),J=require("@univerjs/engine-formula"),L=require("@univerjs/sheets"),I=require("@univerjs/ui"),ne=require("@univerjs/docs-ui"),fe=require("@univerjs/engine-render"),R=require("rxjs"),me=require("@univerjs/docs"),m=require("react/jsx-runtime"),Ft=require("@univerjs/sheets-formula-ui"),C=require("react"),St=require("@univerjs/sheets-data-validation");function Re(e){return s.Tools.isLegalUrl(e)}function Zt(e){return/^[a-zA-Z]+:\/\//.test(e)}function Kt(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Wt(e){if(Re(e)){const n=Zt(e)?e:Kt(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 Rt="sheets-hyper-link-ui.config",_t={};var Yt=Object.getOwnPropertyDescriptor,Gt=(e,n,t,r)=>{for(var i=r>1?void 0:r?Yt(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},ue=(e,n)=>(t,r)=>n(t,r,e);function zt(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 o=[];return t.forEach(c=>{s.Rectangle.intersects(e,c)&&o.push(c)}),s.Rectangle.realUnion(e,...o)}exports.SheetsHyperLinkResolverService=class{constructor(n,t,r,i,o,c){this._univerInstanceService=n,this._commandService=t,this._definedNamesService=r,this._messageService=i,this._localeService=o,this._configService=c}navigate(n){switch(n.type){case S.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:t,range:r,rangeid:i}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const c=o.getUnitId();if(i){const l=this._definedNamesService.getValueById(c,i);if(!l)return;const{formulaOrRefString:u}=l,p=this._definedNamesService.getWorksheetByRef(c,u);if(!p){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:H.MessageType.Error});return}if(p.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:H.MessageType.Error});return}this.navigateToDefineName(c,i)}if(t){if(r){const l=J.deserializeRangeWithSheet(r);s.isValidRange(l.range)&&r!==S.ERROR_RANGE&&this.navigateToRange(c,t,l.range);return}this.navigateToSheetById(c,t)}}async navigateToRange(n,t,r,i){const o=await this.navigateToSheetById(n,t);if(o){const c=zt(r,o);await this._commandService.executeCommand(L.SetSelectionsOperation.id,{unitId:n,subUnitId:t,selections:[{range:c,primary:null}]}),await this._commandService.executeCommand(f.ScrollToRangeOperation.id,{range:c,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 o=r.getSheetBySheetId(t);return o?r.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:H.MessageType.Error}),!1):await this._commandService.executeCommand(L.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:t})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:H.MessageType.Error}),!1)}async navigateToDefineName(n,t){return this._definedNamesService.focusRange(n,t),!0}async navigateToOtherWebsite(n){var r;const t=this._configService.getConfig(Rt);if((r=t==null?void 0:t.urlHandler)!=null&&r.navigateToOtherWebsite)return t.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}};exports.SheetsHyperLinkResolverService=Gt([ue(0,s.IUniverInstanceService),ue(1,s.ICommandService),ue(2,J.IDefinedNamesService),ue(3,I.IMessageService),ue(4,s.Inject(s.LocaleService)),ue(5,s.IConfigService)],exports.SheetsHyperLinkResolverService);const Ge="SHEET_HYPER_LINK_UI_PLUGIN";var qt=Object.getOwnPropertyDescriptor,Xt=(e,n,t,r)=>{for(var i=r>1?void 0:r?qt(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},Ee=(e,n)=>(t,r)=>n(t,r,e);exports.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(t,r,i,o){super();Z(this,"_plainTextFilter",new Set);Z(this,"_copyInfo");this._sheetClipboardService=t,this._hyperLinkModel=r,this._injector=i,this._resolverService=o,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:Ge,onBeforeCopy:(t,r,i)=>this._collect(t,r,i),onPasteCells:(t,r,i,o)=>{const{copyType:c=f.COPY_TYPE.COPY,pasteType:l}=o,{range:u}=t||{},{range:p,unitId:d,subUnitId:h}=r;return this._generateMutations(p,{copyType:c,pasteType:l,copyRange:u,unitId:d,subUnitId:h})},onPastePlainText:(t,r)=>{const i=this._filterPlainText(r);if(Re(r)&&i){const{range:o,unitId:c,subUnitId:l}=t,{ranges:[u],mapFunc:p}=f.virtualizeDiscreteRanges([o]),d=[],h=[];return s.Range.foreach(u,(_,g)=>{const{row:E,col:k}=p(_,g),P=this._hyperLinkModel.getHyperLinkByLocation(c,l,E,k);P&&d.push({id:S.RemoveHyperLinkMutation.id,params:{unitId:c,subUnitId:l,id:P.id}}),P&&h.push({id:S.AddHyperLinkMutation.id,params:{unitId:c,subUnitId:l,link:P}})}),{redos:d,undos:h}}return{undos:[],redos:[]}},priority:99})}_collect(t,r,i){const o=new s.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:r,matrix:o};const c=this._injector.invoke(p=>f.rangeToDiscreteRange(i,p,t,r));if(!c)return;const{rows:l,cols:u}=c;l.forEach((p,d)=>{u.forEach((h,_)=>{var E;const g=this._hyperLinkModel.getHyperLinkByLocation(t,r,p,h);o.setValue(d,_,(E=g==null?void 0:g.id)!=null?E:"")})})}_generateMutations(t,r){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([f.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,f.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,f.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,f.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:o,subUnitId:c}=this._copyInfo,l=[],u=[],{ranges:[p,d],mapFunc:h}=f.virtualizeDiscreteRanges([r.copyRange,t]);return f.getRepeatRange(p,d,!0).forEach(({startRange:g})=>{var E;(E=this._copyInfo)==null||E.matrix.forValue((k,P,a)=>{const O=s.Rectangle.getPositionRange({startRow:k,endRow:k,startColumn:P,endColumn:P},g),x=this._hyperLinkModel.getHyperLink(o,c,a),{row:w,col:N}=h(O.startRow,O.startColumn),B=this._hyperLinkModel.getHyperLinkByLocation(r.unitId,r.subUnitId,w,N),A=s.Tools.generateRandomId();B&&l.push({id:S.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:B.id}}),x&&(l.push({id:S.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:{...x,id:A,row:w,column:N}}}),u.push({id:S.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:A}})),B&&u.push({id:S.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:B}})})}),{redos:l,undos:u}}};exports.SheetsHyperLinkCopyPasteController=Xt([Ee(0,f.ISheetClipboardService),Ee(1,s.Inject(S.HyperLinkModel)),Ee(2,s.Inject(s.Injector)),Ee(3,s.Inject(exports.SheetsHyperLinkResolverService))],exports.SheetsHyperLinkCopyPasteController);var y=(e=>(e.EDITING="editing",e.VIEWING="viewing",e.ZEN_EDITOR="zen_mode",e))(y||{});class ze extends s.Disposable{constructor(){super(...arguments);Z(this,"_customHyperLinks",new Map)}isBuiltInLinkType(t){return t!==S.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 Jt="univer-cell-link-edit",Qt="univer-cell-link-edit-buttons",It={cellLinkEdit:Jt,cellLinkEditButtons:Qt},ke=()=>{var tt;const[e,n]=C.useState(""),[t,r]=C.useState(!1),[i,o]=C.useState(""),[c,l]=C.useState(!0),[u,p]=C.useState(S.SheetHyperLinkType.URL),[d,h]=C.useState(""),_=I.useDependency(s.LocaleService),g=I.useDependency(J.IDefinedNamesService),E=I.useDependency(f.IEditorBridgeService),k=I.useDependency(s.IUniverInstanceService),P=I.useDependency(exports.SheetsHyperLinkPopupService),a=I.useObservable(P.currentEditing$),O=I.useDependency(S.SheetsHyperLinkParserService),x=I.useDependency(exports.SheetsHyperLinkResolverService),w=I.useDependency(s.ICommandService),N=I.useDependency(ze),B=C.useMemo(()=>N.getOptions(),[N]),A=I.useDependency(I.IZenZoneService),q=I.useDependency(fe.IRenderManagerService),de=I.useDependency(f.IMarkSelectionService),Ce=I.useDependency(me.DocSelectionManagerService),re=I.useDependency(s.IContextService),pe=I.useDependency(s.ThemeService),he=I.useDependency(me.DocSelectionManagerService),ge=C.useRef({}),ie=C.useMemo(()=>{if(!N.isBuiltInLinkType(u))return N.getCustomHyperLink(u)},[N,u]),[F,Ut]=C.useState(!1),[ve,Ae]=C.useState(!1),V=C.useRef(!1),K=k.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),Mt=(K==null?void 0:K.getActiveSheet().getSheetId())||"",Q=C.useCallback(v=>{o(v.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);C.useEffect(()=>{var v,D,T,b,M,W,nt,rt,it,st,ot,ct,at,lt,ut,dt,pt;if((a==null?void 0:a.row)!==void 0&&a.col!==void 0){const{customRange:se,row:Fe,col:Ze}=a;let{label:X}=a;typeof X=="number"&&(X=`${X}`);let Y;if(se)Y={id:(v=se==null?void 0:se.rangeId)!=null?v:"",display:X!=null?X:"",payload:(T=(D=se==null?void 0:se.properties)==null?void 0:D.url)!=null?T:"",row:Fe,column:Ze};else if(a.type===y.VIEWING){const U=k.getUnit(a.unitId),te=U==null?void 0:U.getSheetBySheetId(a.subUnitId),j=te==null?void 0:te.getCellRaw(a.row,a.col),le=(W=(M=(b=j==null?void 0:j.p)==null?void 0:b.body)==null?void 0:M.customRanges)==null?void 0:W.find(gt=>{var vt;return gt.rangeType===s.CustomRangeType.HYPERLINK&&((vt=gt.properties)==null?void 0:vt.url)}),Se=j==null?void 0:j.v;j&&(!s.BuildTextUtils.transform.isEmptyDocument((rt=(nt=j.p)==null?void 0:nt.body)==null?void 0:rt.dataStream)||s.Tools.isDefine(Se))&&l(!1),Y={id:"",display:"",payload:(st=(it=le==null?void 0:le.properties)==null?void 0:it.url)!=null?st:"",row:Fe,column:Ze}}else{const U=k.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),te=Ce.getActiveTextRange(),j=U==null?void 0:U.getBody(),le=te&&j?te:null,Se=le&&((ct=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(ot=j==null?void 0:j.customRanges)!=null?ot:[]))==null?void 0:ct[0]);l(!1),Y={id:"",display:X!=null?X:"",payload:(lt=(at=Se==null?void 0:Se.properties)==null?void 0:at.url)!=null?lt:"",row:Fe,column:Ze}}n(Y.id);const ht=N.findCustomHyperLink(Y);if(ht){const U=ht.convert(Y);p(U.type),h(U.payload),Q(U.display);return}Q(Y.display);const ee=O.parseHyperLink(Y.payload);switch(p(ee.type===S.SheetHyperLinkType.INVALID?S.SheetHyperLinkType.RANGE:ee.type),ee.type){case S.SheetHyperLinkType.URL:{h(ee.url),ee.url===Y.display&&(V.current=!0);break}case S.SheetHyperLinkType.RANGE:{const U=ee.searchObj,te=U.gid&&(pt=(dt=(ut=k.getUnit(a.unitId))==null?void 0:ut.getSheetBySheetId(U.gid))==null?void 0:dt.getName())!=null?pt:"",j=J.serializeRangeWithSheet(te,J.deserializeRangeWithSheet(U.range).range);h(j),j===Y.display&&(V.current=!0);break}case S.SheetHyperLinkType.SHEET:{const U=ee.searchObj;h(U.gid);break}case S.SheetHyperLinkType.DEFINE_NAME:{const U=ee.searchObj;h(U.rangeid);break}default:h("");break}}},[a,x,N,Ce,k]),C.useEffect(()=>{let v=null;if(a&&!a.customRangeId&&a.type===y.VIEWING&&s.Tools.isDefine(a.row)&&s.Tools.isDefine(a.col)){const D=k.getUnit(a.unitId,s.UniverInstanceType.UNIVER_SHEET),T=D==null?void 0:D.getSheetBySheetId(a.subUnitId),b=T==null?void 0:T.getMergedCell(a.row,a.col),M=new s.ColorKit(pe.getCurrentTheme().hyacinth500).toRgb();v=de.addShape({range:b!=null?b:{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()=>{v&&de.removeShape(v)}},[a,de,pe,k]),C.useEffect(()=>{Ae(u===S.SheetHyperLinkType.RANGE)},[u]),C.useEffect(()=>{const v=(a==null?void 0:a.type)===y.ZEN_EDITOR?q.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):q.getRenderById(E.getCurrentEditorId()),D=new s.DisposableCollection;if(v){const T=v.with(ne.DocSelectionRenderService);T.setReserveRangesStatus(!0),D.add(()=>{T.setReserveRangesStatus(!1)})}return()=>{E.disableForceKeepVisible(),D.dispose()}},[a==null?void 0:a.type,E,q]),C.useEffect(()=>(P.setIsKeepVisible(ve),()=>{P.setIsKeepVisible(!1)}),[ve,P]),C.useEffect(()=>()=>{A.temporaryHidden&&(A.show(),re.setContextValue(s.FOCUSING_SHEET,!1))},[re,A]),C.useEffect(()=>{if(ve)return E.enableForceKeepVisible(),()=>{E.disableForceKeepVisible()}},[ve,E]);const xt=[{label:_.t("hyperLink.form.link"),value:S.SheetHyperLinkType.URL},{label:_.t("hyperLink.form.range"),value:S.SheetHyperLinkType.RANGE},{label:_.t("hyperLink.form.worksheet"),value:S.SheetHyperLinkType.SHEET},{label:_.t("hyperLink.form.definedName"),value:S.SheetHyperLinkType.DEFINE_NAME},...B];if(!K)return;const jt=K.getHiddenWorksheets(),Be=K.getSheets().map(v=>({label:v.getName(),value:v.getSheetId()})).filter(v=>jt.indexOf(v.value)===-1),Ve=Object.values((tt=g.getDefinedNameMap(K.getUnitId()))!=null?tt:{}).map(v=>({label:v.name,value:v.id})),et=(v,D)=>{if(v===S.SheetHyperLinkType.URL)return Wt(D);if(v===S.SheetHyperLinkType.RANGE){const T=J.deserializeRangeWithSheet(D),b=K.getSheetBySheetName(T.sheetName);if(b)return`#gid=${b.getSheetId()}&range=${J.serializeRange(T.range)}`}return`#${v}=${D}`},At=I.useEvent(v=>{var M;const T=v.split(",").map(J.deserializeRangeWithSheet)[0];if(!T||!s.isValidRange(T.range))return;T.sheetName||(T.sheetName=((M=K.getActiveSheet())==null?void 0:M.getName())||"");const b=J.serializeRangeToRefString(T);h(b),b&&(V.current||!i)&&(Q(b),V.current=!0)}),$e=async()=>{if(c&&!i||!d||u===S.SheetHyperLinkType.URL&&!Re(d)){Ut(!0);return}if(a)if(e){const v=a.type===y.ZEN_EDITOR||a.type===y.EDITING?S.UpdateRichHyperLinkCommand.id:S.UpdateHyperLinkCommand.id;await w.executeCommand(v,{id:e,unitId:a.unitId,subUnitId:a.subUnitId,payload:{display:c?i:"",payload:et(u,d)},row:a.row,column:a.col,documentId:a.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:E.getCurrentEditorId()})}else{const v=a.type===y.ZEN_EDITOR||a.type===y.EDITING?S.AddRichHyperLinkCommand.id:S.AddHyperLinkCommand.id;await w.executeCommand(v,{unitId:a.unitId,subUnitId:a.subUnitId,link:{id:s.generateRandomId(),row:a.row,column:a.col,payload:et(u,d),display:c?i:""},documentId:a.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:E.getCurrentEditorId()})}if((a==null?void 0:a.type)===y.VIEWING){await w.executeCommand(L.SetWorksheetActiveOperation.id,{unitId:a.unitId,subUnitId:a.subUnitId});const v=1;await w.executeCommand(f.ScrollToRangeOperation.id,{range:{startRow:Math.max(a.row-v,0),endRow:a.row+v,startColumn:Math.max(a.col-v,0),endColumn:a.col+v}})}w.executeCommand(ye.id)},Bt=v=>{var T;if(u!==S.SheetHyperLinkType.RANGE)return;const D=(T=ge.current)==null?void 0:T.handleOutClick;D&&D(v,()=>Ae(!1))};return a?m.jsxs("div",{className:It.cellLinkEdit,style:{display:t?"none":"block"},onClick:Bt,children:[c?m.jsx(H.FormLayout,{label:_.t("hyperLink.form.label"),error:F&&!i?_.t("hyperLink.form.inputError"):"",children:m.jsx(H.Input,{value:i,onChange:v=>{Q(v),V.current=!1},placeholder:_.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===I.KeyCode.ENTER&&$e()}})}):null,m.jsx(H.FormLayout,{label:_.t("hyperLink.form.type"),children:m.jsx(H.Select,{options:xt,value:u,onChange:v=>{p(v),h("")}})}),u===S.SheetHyperLinkType.URL&&m.jsx(H.FormLayout,{error:F?d?Re(d)?"":_.t("hyperLink.form.linkError"):_.t("hyperLink.form.inputError"):"",children:m.jsx(H.Input,{value:d,onChange:v=>{h(v),v&&(V.current||!i||i===d)&&(Q(v),V.current=!0)},placeholder:_.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===I.KeyCode.ENTER&&$e()}})}),u===S.SheetHyperLinkType.RANGE&&m.jsx(H.FormLayout,{error:F&&!d?_.t("hyperLink.form.inputError"):"",children:m.jsx(Ft.RangeSelector,{unitId:K.getUnitId(),subUnitId:Mt,isOnlyOneRange:!0,isSupportAcrossSheet:!0,initValue:d,onChange:At,isFocus:ve,onFocus:()=>Ae(!0),actions:ge.current,onRangeSelectorDialogVisibleChange:async v=>{var D,T;if(v)a.type===y.ZEN_EDITOR&&(A.hide(),re.setContextValue(s.FOCUSING_SHEET,!0)),a.type!==y.VIEWING&&E.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===y.ZEN_EDITOR){await w.executeCommand(L.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 b=(D=q.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:D.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];b&&M&&(b.scrollToRange(M),he.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}E.disableForceKeepVisible(),r(!1)}}})}),u===S.SheetHyperLinkType.SHEET&&m.jsx(H.FormLayout,{error:F&&!d?_.t("hyperLink.form.selectError"):"",children:m.jsx(H.Select,{options:Be,value:d,onChange:v=>{var b,M;h(v);const D=(b=Be.find(W=>W.value===v))==null?void 0:b.label,T=(M=Be.find(W=>W.value===d))==null?void 0:M.label;D&&(V.current||!i||i===T)&&(Q(D),V.current=!0)}})}),u===S.SheetHyperLinkType.DEFINE_NAME&&m.jsx(H.FormLayout,{error:F&&!d?_.t("hyperLink.form.selectError"):"",children:m.jsx(H.Select,{options:Ve,value:d,onChange:v=>{var b,M;h(v);const D=(b=Ve.find(W=>W.value===v))==null?void 0:b.label,T=(M=Ve.find(W=>W.value===d))==null?void 0:M.label;D&&(V.current||!i||i===T)&&(Q(D),V.current=!0)}})}),(ie==null?void 0:ie.Form)&&m.jsx(ie.Form,{linkId:e,payload:d,display:i,showError:F,setByPayload:V,setDisplay:v=>{Q(v),V.current=!0},setPayload:h}),m.jsxs("div",{className:It.cellLinkEditButtons,children:[m.jsx(H.Button,{onClick:()=>{a&&x.navigateToRange(a.unitId,a.subUnitId,{startRow:a.row,endRow:a.row,startColumn:a.col,endColumn:a.col},!0),w.executeCommand(ye.id)},children:_.t("hyperLink.form.cancel")}),m.jsx(H.Button,{type:"primary",style:{marginLeft:8},onClick:async()=>{$e()},children:_.t("hyperLink.form.ok")})]})]}):null};ke.componentKey="univer.sheet.cell-link-edit";var $=function(){return $=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},$.apply(this,arguments)},en=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=C.forwardRef(function(e,n){var t=e.icon,r=e.id,i=e.className,o=e.extend,c=en(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),u=C.useRef("_".concat(rn()));return kt(t,"".concat(r),{defIds:t.defIds,idSuffix:u.current},$({ref:n,className:l},c),o)});function kt(e,n,t,r,i){return C.createElement(e.tag,$($({key:n},tn(e,t,i)),r),(nn(e,t).children||[]).map(function(o,c){return kt(o,"".concat(n,"-").concat(e.tag,"-").concat(c),t,void 0,i)}))}function tn(e,n,t){var r=$({},e.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),e.tag==="mask"&&r.id&&(r.id=r.id+n.idSuffix),Object.entries(r).forEach(function(o){var c=o[0],l=o[1];c==="mask"&&typeof l=="string"&&(r[c]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});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(o){var c=o[0],l=o[1];typeof l=="string"&&(r[c]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),r}function nn(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)?$($({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?$($({},i),{attrs:$($({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function rn(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var sn={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=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"all-border-single",ref:n,icon:sn}))});Le.displayName="AllBorderSingle";var on={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"}}]},Pt=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"copy-single",ref:n,icon:on}))});Pt.displayName="CopySingle";var cn={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"}}]},qe=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"link-single",ref:n,icon:cn}))});qe.displayName="LinkSingle";var an={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"}}]},Tt=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"unlink-single",ref:n,icon:an}))});Tt.displayName="UnlinkSingle";var ln={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"}}]},Ot=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"write-single",ref:n,icon:ln}))});Ot.displayName="WriteSingle";var un={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.4538 1.12549C2.70051 1.12549 2.08984 1.73615 2.08984 2.48945V13.5104C2.08984 14.2637 2.70051 14.8744 3.4538 14.8744H12.5468C13.3001 14.8744 13.9108 14.2637 13.9108 13.5104V5.0992L10.0094 1.12549H3.4538Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.0078 1.12549L13.9107 5.09842H10.6745C10.3063 5.09842 10.0078 4.79994 10.0078 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"#fff",d:"M7.80941 10.2949L6.37701 12.403C6.2632 12.5705 6.03516 12.614 5.86766 12.5002C5.70017 12.3864 5.65664 12.1584 5.77045 11.9909L7.36611 9.64252L5.94103 7.54519C5.82722 7.37769 5.87074 7.14964 6.03824 7.03583C6.20573 6.92202 6.43378 6.96555 6.54759 7.13304L7.80941 8.9901L9.07123 7.13304C9.18504 6.96555 9.41309 6.92202 9.58059 7.03583C9.74808 7.14964 9.7916 7.37769 9.67779 7.54519L8.25271 9.64252L9.84837 11.9909C9.96218 12.1584 9.91866 12.3864 9.75116 12.5002C9.58366 12.614 9.35562 12.5705 9.24181 12.403L7.80941 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Dt=C.forwardRef(function(e,n){return C.createElement(ae,Object.assign({},e,{id:"xlsx",ref:n,icon:un}))});Dt.displayName="Xlsx";function bt(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=bt(e[n]))&&(r&&(r+=" "),r+=t)}else for(t in e)e[t]&&(r&&(r+=" "),r+=t);return r}function mt(){for(var e,n,t=0,r="",i=arguments.length;t<i;t++)(e=arguments[t])&&(n=bt(e))&&(r&&(r+=" "),r+=n);return r}const dn="univer-cell-link",pn="univer-cell-link-type",hn="univer-cell-link-content",gn="univer-cell-link-content-error",vn="univer-cell-link-url",Sn="univer-cell-link-operations",_n="univer-cell-link-operation",In="univer-cell-link-operation-error",G={cellLink:dn,cellLinkType:pn,cellLinkContent:hn,cellLinkContentError:gn,cellLinkUrl:vn,cellLinkOperations:Sn,cellLinkOperation:_n,cellLinkOperationError:In},mn={[S.SheetHyperLinkType.URL]:m.jsx(qe,{}),[S.SheetHyperLinkType.SHEET]:m.jsx(Dt,{}),[S.SheetHyperLinkType.RANGE]:m.jsx(Le,{}),[S.SheetHyperLinkType.DEFINE_NAME]:m.jsx(Le,{}),[S.SheetHyperLinkType.INVALID]:m.jsx(Le,{})},yt=e=>{var x,w;const n=I.useDependency(exports.SheetsHyperLinkPopupService),t=I.useDependency(s.ICommandService),r=I.useDependency(I.IMessageService),i=I.useDependency(s.LocaleService),o=I.useDependency(exports.SheetsHyperLinkResolverService),c=I.useDependency(f.IEditorBridgeService),l=I.useDependency(S.SheetsHyperLinkParserService),u=I.useDependency(I.IZenZoneService),{customRange:p,row:d,col:h,unitId:_,subUnitId:g,editPermission:E,copyPermission:k,type:P}=e;if(!((x=p==null?void 0:p.properties)!=null&&x.url))return null;const a=l.parseHyperLink((w=p.properties.url)!=null?w:""),O=a.type===S.SheetHyperLinkType.INVALID;return m.jsxs("div",{className:G.cellLink,onClick:()=>n.hideCurrentPopup(),children:[m.jsxs("div",{className:mt(G.cellLinkContent,{[G.cellLinkContentError]:O}),onClick:()=>{u.visible||O||o.navigate(a)},children:[m.jsx("div",{className:G.cellLinkType,children:mn[a.type]}),m.jsx(H.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:[k&&m.jsx("div",{className:mt(G.cellLinkOperation,{[G.cellLinkOperationError]:O}),onClick:()=>{if(!O){if(a.type!==S.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:H.MessageType.Info})}},children:m.jsx(H.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.copy"),children:m.jsx(Pt,{})})}),E&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:G.cellLinkOperation,onClick:()=>{t.executeCommand(xe.id,{unitId:_,subUnitId:g,row:d,col:h,customRangeId:p.rangeId,type:P})},children:m.jsx(H.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.edit"),children:m.jsx(Ot,{})})}),m.jsx("div",{className:G.cellLinkOperation,onClick:()=>{const N=P===y.EDITING||P===y.ZEN_EDITOR?S.CancelRichHyperLinkCommand.id:S.CancelHyperLinkCommand.id;t.syncExecuteCommand(N,{unitId:_,subUnitId:g,id:p.rangeId,row:d,column:h,documentId:P===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:c.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:m.jsx(H.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.cancel"),children:m.jsx(Tt,{})})})]})]})]})},Pe=()=>{var i,o;const e=I.useDependency(exports.SheetsHyperLinkPopupService),[n,t]=C.useState(null),r=I.useDependency(s.IUniverInstanceService);if(C.useEffect(()=>{t(e.currentPopup);const c=e.currentPopup$.subscribe(l=>{t(l)});return()=>{c.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!n)return null;if(n.showAll){const c=r.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getSheetBySheetId(n.subUnitId),u=l==null?void 0:l.getCell(n.row,n.col),p=(o=(i=u==null?void 0:u.p)==null?void 0:i.body)==null?void 0:o.customRanges;return p!=null&&p.length?m.jsx("div",{children:p.map(d=>m.jsx(yt,{...n,customRange:d},d.rangeId))}):null}return m.jsx(yt,{...n})};Pe.componentKey="univer.sheet.cell-link-popup";var yn=Object.getOwnPropertyDescriptor,fn=(e,n,t,r)=>{for(var i=r>1?void 0:r?yn(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},oe=(e,n)=>(t,r)=>n(t,r,e);const ft=(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,o,c,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=o,this._textSelectionManagerService=c,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&&ft(t,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),t.type!==y.ZEN_EDITOR&&this._zenZoneService.visible))return;const r=this._currentEditing$.getValue();if(r&&ft(t,r))return;const{unitId:i,subUnitId:o,row:c,col:l,customRangeRect:u,customRange:p}=t;let d;const h={componentKey:Pe.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(t.type,!0)}};if(t.type===y.EDITING){if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(u,h)}else if(t.type===y.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,o);else{if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupByPosition(u,h,t)}d&&(this._currentPopup={unitId:i,subUnitId:o,disposable:d,row:c,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,o;this._currentPopup&&((!t||t===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||r)&&((o=(i=this._currentPopup)==null?void 0:i.disposable)==null||o.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}_getEditingRange(){var i,o,c;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,(c=(o=u.customRanges)==null?void 0:o.filter(_=>_.rangeType===s.CustomRangeType.HYPERLINK))!=null?c:[]);let d=l.startOffset,h=l.endOffset;return p.forEach(_=>{d=Math.min(d,_.startIndex),h=Math.max(h,_.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:ke.componentKey,direction:"vertical",onClickOutside:()=>{this.getIsKeepVisible()||this.endEditing()},onContextMenu:()=>{this.getIsKeepVisible()||this.endEditing()},hiddenType:"hide"}}startAddEditing(t){var c,l,u,p,d;const{unitId:r,subUnitId:i,type:o}=t;if(o===y.ZEN_EDITOR){const h=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!h)return;const _=this._textSelectionManagerService.getActiveTextRange();if(!_)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(_,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const g=(c=h.getBody())==null?void 0:c.dataStream.slice(_.startOffset,_.endOffset);this._currentEditing$.next({...t,label:g})}else if(o===y.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 _=this._injector.get(fe.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!_)return;const g=ne.calcDocRangePositions(h,_);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),_=h==null?void 0:h.getSheetBySheetId(i),g=_==null?void 0:_.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,_;(l=this._currentEditingPopup)==null||l.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:r,subUnitId:i}=t;let o,c;if(t.type===y.ZEN_EDITOR){const g=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(p=(u=g==null?void 0:g.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(E=>E.rangeId===t.customRangeId),c=o?(d=g==null?void 0:g.getBody())==null?void 0:d.dataStream.slice(o.startIndex,o.endIndex+1):"",!o||!c)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:o.startIndex,endOffset:o.endIndex,collapsed:!1},this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.type===y.EDITING){const g=f.getEditingCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!g||!((h=g.rects)!=null&&h.length))return;o=g.customRange,c=g.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.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),E=g==null?void 0:g.getSheetBySheetId(i),k=E==null?void 0:E.getCellRaw(t.row,t.col),P=g==null?void 0:g.getStyles().getStyleByCell(k),a=P==null?void 0:P.tr,O=f.getCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!O||!((_=O.rects)!=null&&_.length))return;o=O.customRange,c=O.label,a?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,r,i):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(O.rects.pop(),this._editPopup,{unitId:r,subUnitId:i,row:t.row,col:t.col})}this._currentEditing$.next({...t,customRange:o,label:c})}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=fn([oe(0,s.Inject(f.SheetCanvasPopManagerService)),oe(1,s.Inject(s.Injector)),oe(2,s.IUniverInstanceService),oe(3,f.IEditorBridgeService),oe(4,s.Inject(me.DocSelectionManagerService)),oe(5,s.Inject(ne.DocCanvasPopManagerService)),oe(6,I.IZenZoneService)],exports.SheetsHyperLinkPopupService);var Ie=(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))(Ie||{});const Cn=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),Xe=(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 o=e.has(St.SheetDataValidationModel)?e.get(St.SheetDataValidationModel):null,c=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),t,r);return c&&Cn.has(c.type)?!0:(u=(l=i==null?void 0:i.p)==null?void 0:l.drawingsOrder)!=null&&u.length?2:0},En=e=>{const n=e.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const t=n.getActiveSheet(),r=e.get(L.SheetsSelectionsService).getCurrentSelections();if(!r.length)return!0;const i=r[0].range.startRow,o=r[0].range.startColumn;return Xe(e,t,i,o)===1},Ln=e=>{const n=e.get(me.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(c=>c.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},xe={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}},je={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(e){var h;const n=e.get(s.IUniverInstanceService),t=L.getSheetCommandTarget(n),r=e.get(f.IEditorBridgeService);if(!t)return!1;const i=e.get(s.ICommandService),c=e.get(L.SheetsSelectionsService).getCurrentLastSelection();if(!c)return!1;const l=c.range.startRow,u=c.range.startColumn,p=r.isVisible(),d=((h=n.getFocusedUnit())==null?void 0:h.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return i.executeCommand(xe.id,{unitId:t.unitId,subUnitId:t.subUnitId,row:l,col:u,type:d?y.ZEN_EDITOR:p.visible?y.EDITING:y.VIEWING})}},ce={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(e){if(En(e))return!1;const n=e.get(s.ICommandService);return e.get(exports.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ye.id):n.executeCommand(je.id)}},Je=(e,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var i;const t=e.get(s.IUniverInstanceService),r=(i=e.get(fe.IRenderManagerService).getRenderById(n))==null?void 0:i.with(ne.DocSelectionRenderService);return r?r.textSelectionInner$.pipe(R.map(()=>{const c=e.get(f.IEditorBridgeService).getEditCellState();if(!c)return!0;const l=L.getSheetCommandTarget(t,{unitId:c.unitId,subUnitId:c.sheetId});return!(l!=null&&l.worksheet)||Xe(e,l.worksheet,c.row,c.column)===1?!0:Ln(e)})):R.of(!0)},Ht=e=>{const n=f.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission,L.WorksheetInsertHyperlinkPermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]},!0),t=e.get(s.IUniverInstanceService),r=e.get(L.SheetsSelectionsService),i=e.has(f.IEditorBridgeService)?e.get(f.IEditorBridgeService):null,o=t.focused$.pipe(R.filter(c=>!!c),R.map(c=>t.getUnit(c,s.UniverInstanceType.UNIVER_SHEET)),R.filter(c=>!!c),R.switchMap(c=>c.activeSheet$),R.switchMap(c=>r.selectionMoveEnd$.pipe(R.map(l=>c&&{selections:l,sheet:c}))),R.map(c=>{if(!c)return Ie.DISABLED_BY_CELL;const{selections:l,sheet:u}=c;if(!l.length)return Ie.DISABLED_BY_CELL;const p=l[0].range.startRow,d=l[0].range.startColumn;return Xe(e,u,p,d)}),R.switchMap(c=>{if(c===Ie.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):Je(e,p):R.of(c===Ie.ALLOW_ON_EDITING)))}));return n.pipe(R.distinctUntilChanged(),R.switchMap(c=>o.pipe(R.map(l=>c||l))))},Te={commandId:je.id,type:I.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkSingle"},Oe=e=>`${e}-zen-editor`,Rn=e=>({...Te,id:Te.commandId,hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Ht(e)}),kn=e=>({...Te,id:Oe(Te.commandId),hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Je(e)}),De={tooltip:"hyperLink.form.addTitle",commandId:ce.id,type:I.MenuItemType.BUTTON,icon:"LinkSingle"},Pn=e=>({...De,id:De.commandId,hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Ht(e)}),Tn=e=>({...De,id:Oe(De.commandId),hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Je(e)}),Qe={id:ce.id,binding:I.KeyCode.K|I.MetaKeys.CTRL_COMMAND,preconditions:f.whenSheetEditorFocused};var On=Object.getOwnPropertyDescriptor,Dn=(e,n,t,r)=>{for(var i=r>1?void 0:r?On(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},Ct=(e,n)=>(t,r)=>n(t,r,e);let be=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:o,target:c,unitId:l,subUnitId:u}=r,p=f.virtualizeDiscreteRanges([o,c]),[d,h]=p.ranges,{mapFunc:_}=p,g={row:d.startRow,col:d.startColumn},E=f.getAutoFillRepeatRange(d,h),k=[],P=[];return E.forEach(a=>{const O=a.repeatStartCell,x=a.relativeRange,w={startRow:g.row,startColumn:g.col,endColumn:g.col,endRow:g.row},N={startRow:O.row,startColumn:O.col,endColumn:O.col,endRow:O.row};s.Range.foreach(x,(B,A)=>{const q=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},w),{row:de,col:Ce}=_(q.startRow,q.startColumn),re=this._hyperLinkModel.getHyperLinkByLocation(l,u,de,Ce),pe=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},N),{row:he,col:ge}=_(pe.startRow,pe.startColumn),ie=s.Tools.generateRandomId(),F=this._hyperLinkModel.getHyperLinkByLocation(l,u,he,ge);F&&k.push({id:S.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:F.id}}),(f.APPLY_TYPE.COPY===i||f.APPLY_TYPE.SERIES===i)&&re&&(k.push({id:S.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:{...re,id:ie,row:he,column:ge}}}),P.push({id:S.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:ie}})),F&&P.push({id:S.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:F}})})}),{undos:P,redos:k}},t={id:Ge,onFillData:(r,i,o)=>o===f.APPLY_TYPE.COPY||o===f.APPLY_TYPE.ONLY_FORMAT||o===f.APPLY_TYPE.SERIES?n(r,o):e()};this.disposeWithMe(this._autoFillService.addHook(t))}};be=Dn([Ct(0,f.IAutoFillService),Ct(1,s.Inject(S.HyperLinkModel))],be);var bn=Object.getOwnPropertyDescriptor,Hn=(e,n,t,r)=>{for(var i=r>1?void 0:r?bn(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},Ke=(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===Qe.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookEditablePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission,L.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};He=Hn([Ke(0,s.Inject(s.LocaleService)),Ke(1,s.ICommandService),Ke(2,s.Inject(L.SheetPermissionCheckController))],He);var wn=Object.getOwnPropertyDescriptor,Nn=(e,n,t,r)=>{for(var i=r>1?void 0:r?wn(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},z=(e,n)=>(t,r)=>n(t,r,e);let we=class extends s.Disposable{constructor(e,n,t,r,i,o,c,l,u,p){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=n,this._renderManagerService=t,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=o,this._editorBridgeService=c,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,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!(o==null?void 0:o.getSheetBySheetId(t)))return{viewPermission:!1,editPermission:!1,copyPermission:!1};const l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookViewPermission],worksheetTypes:[L.WorksheetViewPermission],rangeTypes:[L.RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetInsertHyperlinkPermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),p=this._permissionService.composePermission([new L.WorkbookCopyPermission(n).id,new L.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 w,N;if(!e){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:t,row:r,col:i}=e,o=this._renderManagerService.getRenderById(n);if(!o)return;const c=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getSheetBySheetId(t);if(!l)return;if(!o.with(f.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING);return}const p=(w=o==null?void 0:o.with(f.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:w.skeleton,d=i,h=r;let _=h,g=d;p&&p.overflowCache.forValue((B,A,q)=>{s.Rectangle.contains(q,{startColumn:d,endColumn:d,startRow:h,endRow:h})&&(_=B,g=A)});const{viewPermission:E,editPermission:k,copyPermission:P}=this._getLinkPermission(e);if(!E){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const a=l.getCellStyleOnly(_,g),O=c.getStyles().getStyleByCell(a),x=(N=O==null?void 0:O.tr)==null?void 0:N.a;if(!x&&!e.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:_,col:g,editPermission:k,copyPermission:P,customRange:e.customRange,customRangeRect:e.rect,type:y.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(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING);return}const{editorUnitId:r,unitId:i,sheetId:o,row:c,column:l}=t,u=this._renderManagerService.getRenderById(r);if(!u)return;const{editPermission:p,viewPermission:d,copyPermission:h}=this._getLinkPermission({unitId:i,subUnitId:o,row:c,col:l}),_=u.with(ne.DocEventManagerService);d&&(e==null||e.unsubscribe(),e=_.hoverCustomRanges$.pipe(R.debounceTime(200)).subscribe(g=>{var O,x;const E=g.find(w=>w.range.rangeType===s.CustomRangeType.HYPERLINK);if(!E){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const k=E.rects[E.rects.length-1];if(!((x=(O=this._renderManagerService.getRenderById(i))==null?void 0:O.with(f.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:x.skeleton)||!k)return;const a=u.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:i,subUnitId:o,row:c,col:l,customRange:E.range,customRangeRect:{left:k.left+a.left,top:k.top+a.top,bottom:k.bottom+a.top,right:k.right+a.left},editPermission:p,copyPermission:h,type:y.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(y.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:o,column:c}=t,{editPermission:l,viewPermission:u,copyPermission:p}=this._getLinkPermission({unitId:r,subUnitId:i,row:o,col:c});u&&this._sheetsHyperLinkPopupService.showPopup({type:y.ZEN_EDITOR,unitId:r,subUnitId:i,row:o,col:c,customRange:n.range,editPermission:l,copyPermission:p})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(y.EDITING)}))}_initCommandListener(){const e=[L.ClearSelectionContentCommand.id,L.ClearSelectionAllCommand.id,L.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{e.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};we=Nn([z(0,s.Inject(f.HoverManagerService)),z(1,s.Inject(exports.SheetsHyperLinkPopupService)),z(2,s.Inject(fe.IRenderManagerService)),z(3,s.Inject(s.IPermissionService)),z(4,s.Inject(L.SheetPermissionCheckController)),z(5,s.ICommandService),z(6,f.IEditorBridgeService),z(7,s.Inject(me.DocSelectionManagerService)),z(8,s.IUniverInstanceService),z(9,I.IZenZoneService)],we);var Un=Object.getOwnPropertyDescriptor,wt=(e,n,t,r)=>{for(var i=r>1?void 0:r?Un(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},We=(e,n)=>(t,r)=>n(t,r,e);let Ye=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()}))}};Ye=wt([We(1,s.Inject(S.HyperLinkModel))],Ye);let Ne=class extends s.Disposable{constructor(e,n){super(),this._sheetInterceptorService=e,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(L.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(e,n,t)=>{const{row:r,col:i,unitId:o,subUnitId:c}=n,l=this._hyperLinkModel.getHyperLinkByLocation(o,c,r,i);return t(l?{...e,linkUrl:l.payload,linkId:l.id}:e)}}))}};Ne=wt([We(0,s.Inject(L.SheetInterceptorService)),We(1,s.Inject(S.HyperLinkModel))],Ne);const Mn={[I.RibbonStartGroup.OTHERS]:{[ce.id]:{order:2,menuItemFactory:Pn},[Oe(ce.id)]:{order:2,menuItemFactory:Tn}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.OTHERS]:{order:1,[ce.id]:{order:0,menuItemFactory:Rn},[Oe(ce.id)]:{order:0,menuItemFactory:kn}}}};var xn=Object.getOwnPropertyDescriptor,jn=(e,n,t,r)=>{for(var i=r>1?void 0:r?xn(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},_e=(e,n)=>(t,r)=>n(t,r,e);let Ue=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(){[[Pe,Pe.componentKey],[ke,ke.componentKey],[qe,"LinkSingle"]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[xe,ye,je,ce].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(Mn)}_initShortCut(){this._shortcutService.registerShortcut(Qe)}};Ue=jn([_e(0,s.Inject(I.ComponentManager)),_e(1,s.ICommandService),_e(2,I.IMenuManagerService),_e(3,s.Inject(s.Injector)),_e(4,s.Inject(I.IShortcutService))],Ue);var An=Object.getOwnPropertyDescriptor,Bn=(e,n,t,r)=>{for(var i=r>1?void 0:r?An(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},Et=(e,n)=>(t,r)=>n(t,r,e);let Me=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)}}};Me=Bn([Et(0,s.Inject(S.SheetsHyperLinkParserService)),Et(1,s.Inject(exports.SheetsHyperLinkResolverService))],Me);var Vn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Fn=(e,n,t)=>n in e?Vn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Zn=(e,n,t,r)=>{for(var i=r>1?void 0:r?$n(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},Lt=(e,n)=>(t,r)=>n(t,r,e),Nt=(e,n,t)=>Fn(e,typeof n!="symbol"?n+"":n,t);exports.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=_t,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{menu:i,...o}=s.merge({},_t,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Rt,o)}onStarting(){[[exports.SheetsHyperLinkResolverService],[exports.SheetsHyperLinkPopupService],[ze],[Ne],[we],[Ue],[be],[exports.SheetsHyperLinkCopyPasteController],[He],[Me]].forEach(t=>this._injector.add(t)),this._injector.get(Ne)}onReady(){this._injector.get(fe.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[Ye]),this._injector.get(be),this._injector.get(exports.SheetsHyperLinkCopyPasteController),this._injector.get(Ue)}onRendered(){this._injector.get(He),this._injector.get(Me),this._injector.get(we)}};Nt(exports.UniverSheetsHyperLinkUIPlugin,"pluginName",Ge);Nt(exports.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkUIPlugin=Zn([s.DependentOn(S.UniverSheetsHyperLinkPlugin,ne.UniverDocsUIPlugin),Lt(1,s.Inject(s.Injector)),Lt(2,s.IConfigService)],exports.UniverSheetsHyperLinkUIPlugin);exports.CloseHyperLinkPopupOperation=ye;exports.InsertHyperLinkOperation=je;exports.InsertLinkShortcut=Qe;exports.OpenHyperLinkEditPanelOperation=xe;exports.SheetsHyperLinkSidePanelService=ze;
|
|
1
|
+
"use strict";var Vt=Object.defineProperty;var $t=(e,n,t)=>n in e?Vt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var F=(e,n,t)=>$t(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),C=require("@univerjs/sheets"),_=require("@univerjs/sheets-hyper-link"),E=require("@univerjs/sheets-ui"),D=require("@univerjs/design"),X=require("@univerjs/engine-formula"),I=require("@univerjs/ui"),te=require("@univerjs/docs-ui"),fe=require("@univerjs/engine-render"),b=require("rxjs"),me=require("@univerjs/docs"),m=require("react/jsx-runtime"),Ft=require("@univerjs/sheets-formula-ui"),f=require("react"),It=require("@univerjs/sheets-data-validation");function ke(e){return s.Tools.isLegalUrl(e)}function Zt(e){return/^[a-zA-Z]+:\/\//.test(e)}function Kt(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Wt(e){if(ke(e)){const n=Zt(e)?e:Kt(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 Pt="sheets-hyper-link-ui.config",mt={};var Yt=Object.getOwnPropertyDescriptor,Gt=(e,n,t,r)=>{for(var i=r>1?void 0:r?Yt(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},ue=(e,n)=>(t,r)=>n(t,r,e);function zt(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 o=[];return t.forEach(a=>{s.Rectangle.intersects(e,a)&&o.push(a)}),s.Rectangle.realUnion(e,...o)}exports.SheetsHyperLinkResolverService=class{constructor(n,t,r,i,o,a){this._univerInstanceService=n,this._commandService=t,this._definedNamesService=r,this._messageService=i,this._localeService=o,this._configService=a}navigate(n){switch(n.type){case _.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:t,range:r,rangeid:i}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const a=o.getUnitId();if(i){const l=this._definedNamesService.getValueById(a,i);if(!l)return;const{formulaOrRefString:u}=l,p=this._definedNamesService.getWorksheetByRef(a,u);if(!p){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:D.MessageType.Error});return}if(p.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:D.MessageType.Error});return}this.navigateToDefineName(a,i)}if(t){if(r){const l=X.deserializeRangeWithSheet(r);s.isValidRange(l.range)&&r!==_.ERROR_RANGE&&this.navigateToRange(a,t,l.range);return}this.navigateToSheetById(a,t)}}async navigateToRange(n,t,r,i){const o=await this.navigateToSheetById(n,t);if(o){const a=zt(r,o);await this._commandService.executeCommand(C.SetSelectionsOperation.id,{unitId:n,subUnitId:t,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:a,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 o=r.getSheetBySheetId(t);return o?r.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:D.MessageType.Error}),!1):await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:t})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:D.MessageType.Error}),!1)}async navigateToDefineName(n,t){return this._definedNamesService.focusRange(n,t),!0}async navigateToOtherWebsite(n){var r;const t=this._configService.getConfig(Pt);if((r=t==null?void 0:t.urlHandler)!=null&&r.navigateToOtherWebsite)return t.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}};exports.SheetsHyperLinkResolverService=Gt([ue(0,s.IUniverInstanceService),ue(1,s.ICommandService),ue(2,X.IDefinedNamesService),ue(3,I.IMessageService),ue(4,s.Inject(s.LocaleService)),ue(5,s.IConfigService)],exports.SheetsHyperLinkResolverService);const ze="SHEET_HYPER_LINK_UI_PLUGIN";var qt=Object.getOwnPropertyDescriptor,Xt=(e,n,t,r)=>{for(var i=r>1?void 0:r?qt(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Re=(e,n)=>(t,r)=>n(t,r,e);exports.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(t,r,i,o){super();F(this,"_plainTextFilter",new Set);F(this,"_copyInfo");this._sheetClipboardService=t,this._hyperLinkModel=r,this._injector=i,this._resolverService=o,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:ze,onBeforeCopy:(t,r,i)=>this._collect(t,r,i),onPasteCells:(t,r,i,o)=>{const{copyType:a=E.COPY_TYPE.COPY,pasteType:l}=o,{range:u}=t||{},{range:p,unitId:d,subUnitId:h}=r;return this._generateMutations(p,{copyType:a,pasteType:l,copyRange:u,unitId:d,subUnitId:h})},onPastePlainText:(t,r)=>{const i=this._filterPlainText(r);if(ke(r)&&i){const{range:o,unitId:a,subUnitId:l}=t,{ranges:[u],mapFunc:p}=E.virtualizeDiscreteRanges([o]),d=[],h=[];return s.Range.foreach(u,(v,S)=>{const{row:L,col:P}=p(v,S),R=this._hyperLinkModel.getHyperLinkByLocation(a,l,L,P);R&&d.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:l,id:R.id}}),R&&h.push({id:_.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:l,link:R}})}),{redos:d,undos:h}}return{undos:[],redos:[]}},priority:99})}_collect(t,r,i){const o=new s.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:r,matrix:o};const a=this._injector.invoke(p=>C.rangeToDiscreteRange(i,p,t,r));if(!a)return;const{rows:l,cols:u}=a;l.forEach((p,d)=>{u.forEach((h,v)=>{var L;const S=this._hyperLinkModel.getHyperLinkByLocation(t,r,p,h);o.setValue(d,v,(L=S==null?void 0:S.id)!=null?L:"")})})}_generateMutations(t,r){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:o,subUnitId:a}=this._copyInfo,l=[],u=[],{ranges:[p,d],mapFunc:h}=E.virtualizeDiscreteRanges([r.copyRange,t]);return E.getRepeatRange(p,d,!0).forEach(({startRange:S})=>{var L;(L=this._copyInfo)==null||L.matrix.forValue((P,R,c)=>{const k=s.Rectangle.getPositionRange({startRow:P,endRow:P,startColumn:R,endColumn:R},S),x=this._hyperLinkModel.getHyperLink(o,a,c),{row:w,col:N}=h(k.startRow,k.startColumn),B=this._hyperLinkModel.getHyperLinkByLocation(r.unitId,r.subUnitId,w,N),A=s.Tools.generateRandomId();B&&l.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:B.id}}),x&&(l.push({id:_.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:{...x,id:A,row:w,column:N}}}),u.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:A}})),B&&u.push({id:_.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:B}})})}),{redos:l,undos:u}}};exports.SheetsHyperLinkCopyPasteController=Xt([Re(0,E.ISheetClipboardService),Re(1,s.Inject(_.HyperLinkModel)),Re(2,s.Inject(s.Injector)),Re(3,s.Inject(exports.SheetsHyperLinkResolverService))],exports.SheetsHyperLinkCopyPasteController);var y=(e=>(e.EDITING="editing",e.VIEWING="viewing",e.ZEN_EDITOR="zen_mode",e))(y||{});class qe extends s.Disposable{constructor(){super(...arguments);F(this,"_customHyperLinks",new Map)}isBuiltInLinkType(t){return t!==_.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 Jt="univer-cell-link-edit",Qt="univer-cell-link-edit-buttons",yt={cellLinkEdit:Jt,cellLinkEditButtons:Qt},Te=()=>{var rt;const[e,n]=f.useState(""),[t,r]=f.useState(!1),[i,o]=f.useState(""),[a,l]=f.useState(!0),[u,p]=f.useState(_.SheetHyperLinkType.URL),[d,h]=f.useState(""),v=I.useDependency(s.LocaleService),S=I.useDependency(X.IDefinedNamesService),L=I.useDependency(E.IEditorBridgeService),P=I.useDependency(s.IUniverInstanceService),R=I.useDependency(exports.SheetsHyperLinkPopupService),c=I.useObservable(R.currentEditing$),k=I.useDependency(_.SheetsHyperLinkParserService),x=I.useDependency(exports.SheetsHyperLinkResolverService),w=I.useDependency(s.ICommandService),N=I.useDependency(qe),B=f.useMemo(()=>N.getOptions(),[N]),A=I.useDependency(I.IZenZoneService),z=I.useDependency(fe.IRenderManagerService),de=I.useDependency(E.IMarkSelectionService),Ce=I.useDependency(me.DocSelectionManagerService),ne=I.useDependency(s.IContextService),pe=I.useDependency(s.ThemeService),he=I.useDependency(me.DocSelectionManagerService),[ge,Ee]=f.useState(!1),ae=I.useDependency(C.SheetsSelectionsService),Ut=f.useMemo(()=>ae.getCurrentSelections(),[]),Le=f.useMemo(()=>{if(!N.isBuiltInLinkType(u))return N.getCustomHyperLink(u)},[N,u]),[ce,Mt]=f.useState(!1),[Se,tt]=f.useState(!1),V=f.useRef(!1),Z=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),xt=(Z==null?void 0:Z.getActiveSheet().getSheetId())||"",J=f.useCallback(g=>{o(g.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);f.useEffect(()=>{var g,T,O,H,M,K,it,st,ot,at,ct,lt,ut,dt,pt,ht,gt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:re,row:Ze,col:Ke}=c;let{label:q}=c;typeof q=="number"&&(q=`${q}`);let W;if(re)W={id:(g=re==null?void 0:re.rangeId)!=null?g:"",display:q!=null?q:"",payload:(O=(T=re==null?void 0:re.properties)==null?void 0:T.url)!=null?O:"",row:Ze,column:Ke};else if(c.type===y.VIEWING){const U=P.getUnit(c.unitId),ee=U==null?void 0:U.getSheetBySheetId(c.subUnitId),j=ee==null?void 0:ee.getCellRaw(c.row,c.col),le=(K=(M=(H=j==null?void 0:j.p)==null?void 0:H.body)==null?void 0:M.customRanges)==null?void 0:K.find(vt=>{var _t;return vt.rangeType===s.CustomRangeType.HYPERLINK&&((_t=vt.properties)==null?void 0:_t.url)}),ve=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(ve))&&l(!1),W={id:"",display:"",payload:(at=(ot=le==null?void 0:le.properties)==null?void 0:ot.url)!=null?at:"",row:Ze,column:Ke}}else{const U=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),ee=Ce.getActiveTextRange(),j=U==null?void 0:U.getBody(),le=ee&&j?ee:null,ve=le&&((lt=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(ct=j==null?void 0:j.customRanges)!=null?ct:[]))==null?void 0:lt[0]);l(!1),W={id:"",display:q!=null?q:"",payload:(dt=(ut=ve==null?void 0:ve.properties)==null?void 0:ut.url)!=null?dt:"",row:Ze,column:Ke}}n(W.id);const St=N.findCustomHyperLink(W);if(St){const U=St.convert(W);p(U.type),h(U.payload),J(U.display);return}J(W.display);const Q=k.parseHyperLink(W.payload);switch(p(Q.type===_.SheetHyperLinkType.INVALID?_.SheetHyperLinkType.RANGE:Q.type),Q.type){case _.SheetHyperLinkType.URL:{h(Q.url),Q.url===W.display&&(V.current=!0);break}case _.SheetHyperLinkType.RANGE:{const U=Q.searchObj,ee=U.gid&&(gt=(ht=(pt=P.getUnit(c.unitId))==null?void 0:pt.getSheetBySheetId(U.gid))==null?void 0:ht.getName())!=null?gt:"",j=X.serializeRangeWithSheet(ee,X.deserializeRangeWithSheet(U.range).range);h(j),j===W.display&&(V.current=!0);break}case _.SheetHyperLinkType.SHEET:{const U=Q.searchObj;h(U.gid);break}case _.SheetHyperLinkType.DEFINE_NAME:{const U=Q.searchObj;h(U.rangeid);break}default:h("");break}}},[c,x,N,Ce,P]),f.useEffect(()=>{let g=null;if(c&&!c.customRangeId&&c.type===y.VIEWING&&s.Tools.isDefine(c.row)&&s.Tools.isDefine(c.col)){const T=P.getUnit(c.unitId,s.UniverInstanceType.UNIVER_SHEET),O=T==null?void 0:T.getSheetBySheetId(c.subUnitId),H=O==null?void 0:O.getMergedCell(c.row,c.col),M=new s.ColorKit(pe.getCurrentTheme().hyacinth500).toRgb();g=de.addShape({range:H!=null?H:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${M.r}, ${M.g}, ${M.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{g&&de.removeShape(g)}},[c,de,pe,P]),f.useEffect(()=>{tt(u===_.SheetHyperLinkType.RANGE)},[u]),f.useEffect(()=>{const g=(c==null?void 0:c.type)===y.ZEN_EDITOR?z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):z.getRenderById(L.getCurrentEditorId()),T=new s.DisposableCollection;if(g){const O=g.with(te.DocSelectionRenderService);O.setReserveRangesStatus(!0),T.add(()=>{O.setReserveRangesStatus(!1)})}return()=>{L.disableForceKeepVisible(),T.dispose()}},[c==null?void 0:c.type,L,z]),f.useEffect(()=>(Se&&R.setIsKeepVisible(Se),R.setIsKeepVisible(ge),()=>{R.setIsKeepVisible(!1)}),[Se,ge,R]),f.useEffect(()=>()=>{A.temporaryHidden&&(A.show(),ne.setContextValue(s.FOCUSING_SHEET,!1))},[ne,A]),f.useEffect(()=>{if(Se)return L.enableForceKeepVisible(),()=>{L.disableForceKeepVisible()}},[Se,L]);const jt=[{label:v.t("hyperLink.form.link"),value:_.SheetHyperLinkType.URL},{label:v.t("hyperLink.form.range"),value:_.SheetHyperLinkType.RANGE},{label:v.t("hyperLink.form.worksheet"),value:_.SheetHyperLinkType.SHEET},{label:v.t("hyperLink.form.definedName"),value:_.SheetHyperLinkType.DEFINE_NAME},...B];if(!Z)return;const At=Z.getHiddenWorksheets(),Ve=Z.getSheets().map(g=>({label:g.getName(),value:g.getSheetId()})).filter(g=>At.indexOf(g.value)===-1),$e=Object.values((rt=S.getDefinedNameMap(Z.getUnitId()))!=null?rt:{}).map(g=>({label:g.name,value:g.id})),nt=(g,T)=>{if(g===_.SheetHyperLinkType.URL)return Wt(T);if(g===_.SheetHyperLinkType.RANGE){const O=X.deserializeRangeWithSheet(T),H=Z.getSheetBySheetName(O.sheetName);if(H)return`#gid=${H.getSheetId()}&range=${X.serializeRange(O.range)}`}return`#${g}=${T}`},Bt=I.useEvent(g=>{var M;const O=g.split(",").map(X.deserializeRangeWithSheet)[0];if(!O||!s.isValidRange(O.range))return;O.sheetName||(O.sheetName=((M=Z.getActiveSheet())==null?void 0:M.getName())||"");const H=X.serializeRangeToRefString(O);h(H),H&&(V.current||!i)&&(J(H),V.current=!0)}),Fe=async()=>{if(a&&!i||!d||u===_.SheetHyperLinkType.URL&&!ke(d)){Mt(!0);return}if(c)if(e){const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?_.UpdateRichHyperLinkCommand.id:_.UpdateHyperLinkCommand.id;await w.executeCommand(g,{id:e,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?i:"",payload:nt(u,d)},row:c.row,column:c.col,documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:L.getCurrentEditorId()})}else{const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?_.AddRichHyperLinkCommand.id:_.AddHyperLinkCommand.id;await w.executeCommand(g,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:s.generateRandomId(),row:c.row,column:c.col,payload:nt(u,d),display:a?i:""},documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:L.getCurrentEditorId()})}if((c==null?void 0:c.type)===y.VIEWING){await w.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const g=1;await w.executeCommand(E.ScrollToRangeOperation.id,{range:{startRow:Math.max(c.row-g,0),endRow:c.row+g,startColumn:Math.max(c.col-g,0),endColumn:c.col+g}})}w.executeCommand(ye.id)};return c?m.jsxs("div",{className:yt.cellLinkEdit,style:{display:t?"none":"block"},children:[a?m.jsx(D.FormLayout,{label:v.t("hyperLink.form.label"),error:ce&&!i?v.t("hyperLink.form.inputError"):"",children:m.jsx(D.Input,{value:i,onChange:g=>{J(g),V.current=!1},placeholder:v.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===I.KeyCode.ENTER&&Fe()}})}):null,m.jsx(D.FormLayout,{label:v.t("hyperLink.form.type"),children:m.jsx(D.Select,{options:jt,value:u,onChange:g=>{p(g),h("")}})}),u===_.SheetHyperLinkType.URL&&m.jsx(D.FormLayout,{error:ce?d?ke(d)?"":v.t("hyperLink.form.linkError"):v.t("hyperLink.form.inputError"):"",children:m.jsx(D.Input,{value:d,onChange:g=>{h(g),g&&(V.current||!i||i===d)&&(J(g),V.current=!0)},placeholder:v.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===I.KeyCode.ENTER&&Fe()}})}),u===_.SheetHyperLinkType.RANGE&&m.jsx(D.FormLayout,{error:ce&&!d?v.t("hyperLink.form.inputError"):"",children:m.jsx(Ft.RangeSelector,{unitId:Z.getUnitId(),subUnitId:xt,maxRangeCount:1,supportAcrossSheet:!0,initialValue:d,resetRange:Ut,onChange:(g,T)=>Bt(T),onRangeSelectorDialogVisibleChange:async g=>{var T,O;if(Ee(g),g)c.type===y.ZEN_EDITOR&&(A.hide(),ne.setContextValue(s.FOCUSING_SHEET,!0)),c.type!==y.VIEWING&&L.enableForceKeepVisible(),r(!0);else{if(await x.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===y.ZEN_EDITOR){await w.executeCommand(C.SetSelectionsOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId,selections:[{range:{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col}}]}),A.show(),ne.setContextValue(s.FOCUSING_SHEET,!1);const H=(T=z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:T.with(te.DocBackScrollRenderController),M=(O=he.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:O[0];H&&M&&(H.scrollToRange(M),he.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}L.disableForceKeepVisible(),r(!1)}},onFocusChange:g=>tt(g)})}),u===_.SheetHyperLinkType.SHEET&&m.jsx(D.FormLayout,{error:ce&&!d?v.t("hyperLink.form.selectError"):"",children:m.jsx(D.Select,{options:Ve,value:d,onChange:g=>{var H,M;h(g);const T=(H=Ve.find(K=>K.value===g))==null?void 0:H.label,O=(M=Ve.find(K=>K.value===d))==null?void 0:M.label;T&&(V.current||!i||i===O)&&(J(T),V.current=!0)}})}),u===_.SheetHyperLinkType.DEFINE_NAME&&m.jsx(D.FormLayout,{error:ce&&!d?v.t("hyperLink.form.selectError"):"",children:m.jsx(D.Select,{options:$e,value:d,onChange:g=>{var H,M;h(g);const T=(H=$e.find(K=>K.value===g))==null?void 0:H.label,O=(M=$e.find(K=>K.value===d))==null?void 0:M.label;T&&(V.current||!i||i===O)&&(J(T),V.current=!0)}})}),(Le==null?void 0:Le.Form)&&m.jsx(Le.Form,{linkId:e,payload:d,display:i,showError:ce,setByPayload:V,setDisplay:g=>{J(g),V.current=!0},setPayload:h}),m.jsxs("div",{className:yt.cellLinkEditButtons,children:[m.jsx(D.Button,{onClick:()=>{c&&x.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),w.executeCommand(ye.id)},children:v.t("hyperLink.form.cancel")}),m.jsx(D.Button,{type:"primary",style:{marginLeft:8},onClick:async()=>{Fe()},children:v.t("hyperLink.form.ok")})]})]}):null};Te.componentKey="univer.sheet.cell-link-edit";var $=function(){return $=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},$.apply(this,arguments)},en=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},oe=f.forwardRef(function(e,n){var t=e.icon,r=e.id,i=e.className,o=e.extend,a=en(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),u=f.useRef("_".concat(rn()));return kt(t,"".concat(r),{defIds:t.defIds,idSuffix:u.current},$({ref:n,className:l},a),o)});function kt(e,n,t,r,i){return f.createElement(e.tag,$($({key:n},tn(e,t,i)),r),(nn(e,t).children||[]).map(function(o,a){return kt(o,"".concat(n,"-").concat(e.tag,"-").concat(a),t,void 0,i)}))}function tn(e,n,t){var r=$({},e.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),e.tag==="mask"&&r.id&&(r.id=r.id+n.idSuffix),Object.entries(r).forEach(function(o){var a=o[0],l=o[1];a==="mask"&&typeof l=="string"&&(r[a]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});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(o){var a=o[0],l=o[1];typeof l=="string"&&(r[a]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),r}function nn(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)?$($({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?$($({},i),{attrs:$($({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function rn(){return Math.random().toString(36).substring(2,8)}oe.displayName="UniverIcon";var sn={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"}}]},Pe=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"all-border-single",ref:n,icon:sn}))});Pe.displayName="AllBorderSingle";var on={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"}}]},Tt=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"copy-single",ref:n,icon:on}))});Tt.displayName="CopySingle";var an={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=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"link-single",ref:n,icon:an}))});Xe.displayName="LinkSingle";var cn={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"}}]},Ot=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"unlink-single",ref:n,icon:cn}))});Ot.displayName="UnlinkSingle";var ln={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"}}]},Dt=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"write-single",ref:n,icon:ln}))});Dt.displayName="WriteSingle";var un={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.4538 1.12549C2.70051 1.12549 2.08984 1.73615 2.08984 2.48945V13.5104C2.08984 14.2637 2.70051 14.8744 3.4538 14.8744H12.5468C13.3001 14.8744 13.9108 14.2637 13.9108 13.5104V5.0992L10.0094 1.12549H3.4538Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.0078 1.12549L13.9107 5.09842H10.6745C10.3063 5.09842 10.0078 4.79994 10.0078 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"#fff",d:"M7.80941 10.2949L6.37701 12.403C6.2632 12.5705 6.03516 12.614 5.86766 12.5002C5.70017 12.3864 5.65664 12.1584 5.77045 11.9909L7.36611 9.64252L5.94103 7.54519C5.82722 7.37769 5.87074 7.14964 6.03824 7.03583C6.20573 6.92202 6.43378 6.96555 6.54759 7.13304L7.80941 8.9901L9.07123 7.13304C9.18504 6.96555 9.41309 6.92202 9.58059 7.03583C9.74808 7.14964 9.7916 7.37769 9.67779 7.54519L8.25271 9.64252L9.84837 11.9909C9.96218 12.1584 9.91866 12.3864 9.75116 12.5002C9.58366 12.614 9.35562 12.5705 9.24181 12.403L7.80941 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},bt=f.forwardRef(function(e,n){return f.createElement(oe,Object.assign({},e,{id:"xlsx",ref:n,icon:un}))});bt.displayName="Xlsx";const dn="univer-cell-link",pn="univer-cell-link-type",hn="univer-cell-link-content",gn="univer-cell-link-content-error",Sn="univer-cell-link-url",vn="univer-cell-link-operations",_n="univer-cell-link-operation",In="univer-cell-link-operation-error",Y={cellLink:dn,cellLinkType:pn,cellLinkContent:hn,cellLinkContentError:gn,cellLinkUrl:Sn,cellLinkOperations:vn,cellLinkOperation:_n,cellLinkOperationError:In},mn={[_.SheetHyperLinkType.URL]:m.jsx(Xe,{}),[_.SheetHyperLinkType.SHEET]:m.jsx(bt,{}),[_.SheetHyperLinkType.RANGE]:m.jsx(Pe,{}),[_.SheetHyperLinkType.DEFINE_NAME]:m.jsx(Pe,{}),[_.SheetHyperLinkType.INVALID]:m.jsx(Pe,{})},ft=e=>{var x,w;const n=I.useDependency(exports.SheetsHyperLinkPopupService),t=I.useDependency(s.ICommandService),r=I.useDependency(I.IMessageService),i=I.useDependency(s.LocaleService),o=I.useDependency(exports.SheetsHyperLinkResolverService),a=I.useDependency(E.IEditorBridgeService),l=I.useDependency(_.SheetsHyperLinkParserService),u=I.useDependency(I.IZenZoneService),{customRange:p,row:d,col:h,unitId:v,subUnitId:S,editPermission:L,copyPermission:P,type:R}=e;if(!((x=p==null?void 0:p.properties)!=null&&x.url))return null;const c=l.parseHyperLink((w=p.properties.url)!=null?w:""),k=c.type===_.SheetHyperLinkType.INVALID;return m.jsxs("div",{className:Y.cellLink,onClick:()=>n.hideCurrentPopup(),children:[m.jsxs("div",{className:D.clsx(Y.cellLinkContent,{[Y.cellLinkContentError]:k}),onClick:()=>{u.visible||k||o.navigate(c)},children:[m.jsx("div",{className:Y.cellLinkType,children:mn[c.type]}),m.jsx(D.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:m.jsx("span",{className:Y.cellLinkUrl,children:c.name})})]}),m.jsxs("div",{className:Y.cellLinkOperations,children:[P&&m.jsx("div",{className:D.clsx(Y.cellLinkOperation,{[Y.cellLinkOperationError]:k}),onClick:()=>{if(!k){if(c.type!==_.SheetHyperLinkType.URL){const N=new URL(window.location.href);N.hash=c.url.slice(1),navigator.clipboard.writeText(N.href)}else navigator.clipboard.writeText(c.url);r.show({content:i.t("hyperLink.message.coped"),type:D.MessageType.Info})}},children:m.jsx(D.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.copy"),children:m.jsx(Tt,{})})}),L&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:Y.cellLinkOperation,onClick:()=>{t.executeCommand(Ae.id,{unitId:v,subUnitId:S,row:d,col:h,customRangeId:p.rangeId,type:R})},children:m.jsx(D.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.edit"),children:m.jsx(Dt,{})})}),m.jsx("div",{className:Y.cellLinkOperation,onClick:()=>{const N=R===y.EDITING||R===y.ZEN_EDITOR?_.CancelRichHyperLinkCommand.id:_.CancelHyperLinkCommand.id;t.syncExecuteCommand(N,{unitId:v,subUnitId:S,id:p.rangeId,row:d,column:h,documentId:R===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:m.jsx(D.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.cancel"),children:m.jsx(Ot,{})})})]})]})]})},Oe=()=>{var i,o;const e=I.useDependency(exports.SheetsHyperLinkPopupService),[n,t]=f.useState(null),r=I.useDependency(s.IUniverInstanceService);if(f.useEffect(()=>{t(e.currentPopup);const a=e.currentPopup$.subscribe(l=>{t(l)});return()=>{a.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!n)return null;if(n.showAll){const a=r.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),l=a==null?void 0:a.getSheetBySheetId(n.subUnitId),u=l==null?void 0:l.getCell(n.row,n.col),p=(o=(i=u==null?void 0:u.p)==null?void 0:i.body)==null?void 0:o.customRanges;return p!=null&&p.length?m.jsx("div",{children:p.map(d=>m.jsx(ft,{...n,customRange:d},d.rangeId))}):null}return m.jsx(ft,{...n})};Oe.componentKey="univer.sheet.cell-link-popup";var yn=Object.getOwnPropertyDescriptor,fn=(e,n,t,r)=>{for(var i=r>1?void 0:r?yn(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},ie=(e,n)=>(t,r)=>n(t,r,e);const Ct=(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,o,a,l,u){super();F(this,"_currentPopup",null);F(this,"_currentPopup$",new b.Subject);F(this,"currentPopup$",this._currentPopup$.asObservable());F(this,"_currentEditingPopup",null);F(this,"_currentEditing$",new b.BehaviorSubject(null));F(this,"currentEditing$",this._currentEditing$.asObservable());F(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=t,this._injector=r,this._univerInstanceService=i,this._editorBridgeService=o,this._textSelectionManagerService=a,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&&Ct(t,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),t.type!==y.ZEN_EDITOR&&this._zenZoneService.visible))return;const r=this._currentEditing$.getValue();if(r&&Ct(t,r))return;const{unitId:i,subUnitId:o,row:a,col:l,customRangeRect:u,customRange:p}=t;let d;const h={componentKey:Oe.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(t.type,!0)}};if(t.type===y.EDITING){if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(u,h)}else if(t.type===y.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,o);else{if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupByPosition(u,h,t)}d&&(this._currentPopup={unitId:i,subUnitId:o,disposable:d,row:a,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,o;this._currentPopup&&((!t||t===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||r)&&((o=(i=this._currentPopup)==null?void 0:i.disposable)==null||o.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}_getEditingRange(){var i,o,a;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,(a=(o=u.customRanges)==null?void 0:o.filter(v=>v.rangeType===s.CustomRangeType.HYPERLINK))!=null?a:[]);let d=l.startOffset,h=l.endOffset;return p.forEach(v=>{d=Math.min(d,v.startIndex),h=Math.max(h,v.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.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:"hide"}}startAddEditing(t){var a,l,u,p,d;const{unitId:r,subUnitId:i,type:o}=t;if(o===y.ZEN_EDITOR){const h=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!h)return;const v=this._textSelectionManagerService.getActiveTextRange();if(!v)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(v,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const S=(a=h.getBody())==null?void 0:a.dataStream.slice(v.startOffset,v.endOffset);this._currentEditing$.next({...t,label:S})}else if(o===y.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 v=this._injector.get(fe.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!v)return;const S=te.calcDocRangePositions(h,v);if(!(S!=null&&S.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.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),v=h==null?void 0:h.getSheetBySheetId(i),S=v==null?void 0:v.getCellRaw(t.row,t.col);this._currentEditing$.next({...t,label:S!=null&&S.p?s.BuildTextUtils.transform.getPlainText((p=(u=S.p.body)==null?void 0:u.dataStream)!=null?p:""):((d=S==null?void 0:S.v)!=null?d:"").toString()})}}startEditing(t){var l,u,p,d,h,v;(l=this._currentEditingPopup)==null||l.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:r,subUnitId:i}=t;let o,a;if(t.type===y.ZEN_EDITOR){const S=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(p=(u=S==null?void 0:S.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(L=>L.rangeId===t.customRangeId),a=o?(d=S==null?void 0:S.getBody())==null?void 0:d.dataStream.slice(o.startIndex,o.endIndex+1):"",!o||!a)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:o.startIndex,endOffset:o.endIndex,collapsed:!1},this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.type===y.EDITING){const S=E.getEditingCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!S||!((h=S.rects)!=null&&h.length))return;o=S.customRange,a=S.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.rects.pop(),this._editPopup,r,i)}else{const S=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),L=S==null?void 0:S.getSheetBySheetId(i),P=L==null?void 0:L.getCellRaw(t.row,t.col),R=S==null?void 0:S.getStyles().getStyleByCell(P),c=R==null?void 0:R.tr,k=E.getCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!k||!((v=k.rects)!=null&&v.length))return;o=k.customRange,a=k.label,c?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:o,label:a})}endEditing(t){var i;if(this.getIsKeepVisible())return;const r=this._currentEditing$.getValue();r&&(!t||t===r.type)&&((i=this._currentEditingPopup)==null||i.dispose(),this._currentEditing$.next(null))}};exports.SheetsHyperLinkPopupService=fn([ie(0,s.Inject(E.SheetCanvasPopManagerService)),ie(1,s.Inject(s.Injector)),ie(2,s.IUniverInstanceService),ie(3,E.IEditorBridgeService),ie(4,s.Inject(me.DocSelectionManagerService)),ie(5,s.Inject(te.DocCanvasPopManagerService)),ie(6,I.IZenZoneService)],exports.SheetsHyperLinkPopupService);var Ie=(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))(Ie||{});const Cn=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),Je=(e,n,t,r)=>{var l,u,p,d,h;const i=n.getCell(t,r);if(i!=null&&i.f||i!=null&&i.si||(p=(u=(l=i==null?void 0:i.p)==null?void 0:l.body)==null?void 0:u.customBlocks)!=null&&p.length)return 1;const o=e.has(It.SheetDataValidationModel)?e.get(It.SheetDataValidationModel):null,a=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),t,r);return a&&Cn.has(a.type)?!0:(h=(d=i==null?void 0:i.p)==null?void 0:d.drawingsOrder)!=null&&h.length?2:0},En=e=>{const n=e.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const t=n.getActiveSheet(),r=e.get(C.SheetsSelectionsService).getCurrentSelections();if(!r.length)return!0;const i=r[0].range.startRow,o=r[0].range.startColumn;return Je(e,t,i,o)===1},Ln=e=>{const n=e.get(me.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(a=>a.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},Ae={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}},Be={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(e){var h;const n=e.get(s.IUniverInstanceService),t=C.getSheetCommandTarget(n),r=e.get(E.IEditorBridgeService);if(!t)return!1;const i=e.get(s.ICommandService),a=e.get(C.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const l=a.range.startRow,u=a.range.startColumn,p=r.isVisible(),d=((h=n.getFocusedUnit())==null?void 0:h.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return i.executeCommand(Ae.id,{unitId:t.unitId,subUnitId:t.subUnitId,row:l,col:u,type:d?y.ZEN_EDITOR:p.visible?y.EDITING:y.VIEWING})}},se={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(e){if(En(e))return!1;const n=e.get(s.ICommandService);return e.get(exports.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ye.id):n.executeCommand(Be.id)}},Qe=(e,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var i;const t=e.get(s.IUniverInstanceService),r=(i=e.get(fe.IRenderManagerService).getRenderById(n))==null?void 0:i.with(te.DocSelectionRenderService);return r?r.textSelectionInner$.pipe(b.map(()=>{const a=e.get(E.IEditorBridgeService).getEditCellState();if(!a)return!0;const l=C.getSheetCommandTarget(t,{unitId:a.unitId,subUnitId:a.sheetId});return!(l!=null&&l.worksheet)||Je(e,l.worksheet,a.row,a.column)===1?!0:Ln(e)})):b.of(!0)},Ht=e=>{var o;const n=E.getCurrentRangeDisable$(e,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetSetCellValuePermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},!0),t=e.get(s.IUniverInstanceService),r=e.has(E.IEditorBridgeService)?e.get(E.IEditorBridgeService):null;return((o=r==null?void 0:r.currentEditCellState$.pipe(b.map(a=>{if(!a)return Ie.DISABLED_BY_CELL;const l=C.getSheetCommandTarget(t,{unitId:a.unitId,subUnitId:a.sheetId});return l?Je(e,l.worksheet,a.row,a.column):Ie.DISABLED_BY_CELL}),b.switchMap(a=>{if(a===Ie.DISABLED_BY_CELL)return b.of(!0);const l=r?r.visible$:b.of(null);return b.combineLatest([l,t.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC)]).pipe(b.switchMap(([u,p])=>u!=null&&u.visible?(p==null?void 0:p.getUnitId())===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?b.of(!0):Qe(e,s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY):b.of(a!==Ie.ALLOWED)))})))!=null?o:b.of(!0)).pipe(b.switchMap(a=>a?b.of(!0):n))},De={commandId:Be.id,type:I.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkSingle"},be=e=>`${e}-zen-editor`,Rn=e=>({...De,id:De.commandId,hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Ht(e)}),Pn=e=>({...De,id:be(De.commandId),hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Qe(e)}),He={tooltip:"hyperLink.form.addTitle",commandId:se.id,type:I.MenuItemType.BUTTON,icon:"LinkSingle"},kn=e=>({...He,id:He.commandId,hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:Ht(e)}),Tn=e=>({...He,id:be(He.commandId),hidden$:I.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Qe(e)}),et={id:se.id,binding:I.KeyCode.K|I.MetaKeys.CTRL_COMMAND,preconditions:E.whenSheetEditorFocused};var On=Object.getOwnPropertyDescriptor,Dn=(e,n,t,r)=>{for(var i=r>1?void 0:r?On(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Et=(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:o,target:a,unitId:l,subUnitId:u}=r,p=E.virtualizeDiscreteRanges([o,a]),[d,h]=p.ranges,{mapFunc:v}=p,S={row:d.startRow,col:d.startColumn},L=E.getAutoFillRepeatRange(d,h),P=[],R=[];return L.forEach(c=>{const k=c.repeatStartCell,x=c.relativeRange,w={startRow:S.row,startColumn:S.col,endColumn:S.col,endRow:S.row},N={startRow:k.row,startColumn:k.col,endColumn:k.col,endRow:k.row};s.Range.foreach(x,(B,A)=>{const z=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},w),{row:de,col:Ce}=v(z.startRow,z.startColumn),ne=this._hyperLinkModel.getHyperLinkByLocation(l,u,de,Ce),pe=s.Rectangle.getPositionRange({startRow:B,startColumn:A,endColumn:A,endRow:B},N),{row:he,col:ge}=v(pe.startRow,pe.startColumn),Ee=s.Tools.generateRandomId(),ae=this._hyperLinkModel.getHyperLinkByLocation(l,u,he,ge);ae&&P.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:ae.id}}),(E.APPLY_TYPE.COPY===i||E.APPLY_TYPE.SERIES===i)&&ne&&(P.push({id:_.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:{...ne,id:Ee,row:he,column:ge}}}),R.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:Ee}})),ae&&R.push({id:_.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:ae}})})}),{undos:R,redos:P}},t={id:ze,onFillData:(r,i,o)=>o===E.APPLY_TYPE.COPY||o===E.APPLY_TYPE.ONLY_FORMAT||o===E.APPLY_TYPE.SERIES?n(r,o):e()};this.disposeWithMe(this._autoFillService.addHook(t))}};we=Dn([Et(0,E.IAutoFillService),Et(1,s.Inject(_.HyperLinkModel))],we);var bn=Object.getOwnPropertyDescriptor,Hn=(e,n,t,r)=>{for(var i=r>1?void 0:r?bn(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},We=(e,n)=>(t,r)=>n(t,r,e);let Ne=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===et.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookEditablePermission],rangeTypes:[C.RangeProtectionPermissionEditPoint],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetSetCellValuePermission,C.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};Ne=Hn([We(0,s.Inject(s.LocaleService)),We(1,s.ICommandService),We(2,s.Inject(C.SheetPermissionCheckController))],Ne);var wn=Object.getOwnPropertyDescriptor,Nn=(e,n,t,r)=>{for(var i=r>1?void 0:r?wn(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},G=(e,n)=>(t,r)=>n(t,r,e);let Ue=class extends s.Disposable{constructor(e,n,t,r,i,o,a,l,u,p){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=n,this._renderManagerService=t,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=o,this._editorBridgeService=a,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,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!(o==null?void 0:o.getSheetBySheetId(t)))return{viewPermission:!1,editPermission:!1,copyPermission:!1};const l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookViewPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}]),p=this._permissionService.composePermission([new C.WorkbookCopyPermission(n).id,new C.WorksheetCopyPermission(n,t).id]).every(d=>d.value);return{viewPermission:l,editPermission:u,copyPermission:p}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(b.debounceTime(200)).subscribe(e=>{var w,N;if(!e){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:t,row:r,col:i}=e,o=this._renderManagerService.getRenderById(n);if(!o)return;const a=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),l=a==null?void 0:a.getSheetBySheetId(t);if(!l)return;if(!o.with(E.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING);return}const p=(w=o==null?void 0:o.with(E.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:w.skeleton,d=i,h=r;let v=h,S=d;p&&p.overflowCache.forValue((B,A,z)=>{s.Rectangle.contains(z,{startColumn:d,endColumn:d,startRow:h,endRow:h})&&(v=B,S=A)});const{viewPermission:L,editPermission:P,copyPermission:R}=this._getLinkPermission(e);if(!L){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=l.getCellStyleOnly(v,S),k=a.getStyles().getStyleByCell(c),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:v,col:S,editPermission:P,copyPermission:R,customRange:e.customRange,customRangeRect:e.rect,type:y.VIEWING,unitId:n,subUnitId:t,showAll:!!x})}))}_initHoverEditingListener(){let e=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(b.switchMap(n=>this._editorBridgeService.visible$.pipe(b.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(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING);return}const{editorUnitId:r,unitId:i,sheetId:o,row:a,column:l}=t,u=this._renderManagerService.getRenderById(r);if(!u)return;const{editPermission:p,viewPermission:d,copyPermission:h}=this._getLinkPermission({unitId:i,subUnitId:o,row:a,col:l}),v=u.with(te.DocEventManagerService);d&&(e==null||e.unsubscribe(),e=v.hoverCustomRanges$.pipe(b.debounceTime(200)).subscribe(S=>{var k,x;const L=S.find(w=>w.range.rangeType===s.CustomRangeType.HYPERLINK);if(!L){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const P=L.rects[L.rects.length-1];if(!((x=(k=this._renderManagerService.getRenderById(i))==null?void 0:k.with(E.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:x.skeleton)||!P)return;const c=u.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:i,subUnitId:o,row:a,col:l,customRange:L.range,customRangeRect:{left:P.left+c.left,top:P.top+c.top,bottom:P.bottom+c.top,right:P.right+c.left},editPermission:p,copyPermission:h,type:y.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(y.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(b.switchMap(e=>{const n=e===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(e):null;return n?n.with(te.DocEventManagerService).hoverCustomRanges$.pipe(b.debounceTime(200)):new b.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:o,column:a}=t,{editPermission:l,viewPermission:u,copyPermission:p}=this._getLinkPermission({unitId:r,subUnitId:i,row:o,col:a});u&&this._sheetsHyperLinkPopupService.showPopup({type:y.ZEN_EDITOR,unitId:r,subUnitId:i,row:o,col:a,customRange:n.range,editPermission:l,copyPermission:p})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(y.EDITING)}))}_initCommandListener(){const e=[C.ClearSelectionContentCommand.id,C.ClearSelectionAllCommand.id,C.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{e.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ue=Nn([G(0,s.Inject(E.HoverManagerService)),G(1,s.Inject(exports.SheetsHyperLinkPopupService)),G(2,s.Inject(fe.IRenderManagerService)),G(3,s.Inject(s.IPermissionService)),G(4,s.Inject(C.SheetPermissionCheckController)),G(5,s.ICommandService),G(6,E.IEditorBridgeService),G(7,s.Inject(me.DocSelectionManagerService)),G(8,s.IUniverInstanceService),G(9,I.IZenZoneService)],Ue);var Un=Object.getOwnPropertyDescriptor,wt=(e,n,t,r)=>{for(var i=r>1?void 0:r?Un(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Ye=(e,n)=>(t,r)=>n(t,r,e);let Ge=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(b.debounceTime(16)).subscribe(()=>{e()}))}};Ge=wt([Ye(1,s.Inject(_.HyperLinkModel))],Ge);let Me=class extends s.Disposable{constructor(e,n){super(),this._sheetInterceptorService=e,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(e,n,t)=>{const{row:r,col:i,unitId:o,subUnitId:a}=n,l=this._hyperLinkModel.getHyperLinkByLocation(o,a,r,i);return t(l?{...e,linkUrl:l.payload,linkId:l.id}:e)}}))}};Me=wt([Ye(0,s.Inject(C.SheetInterceptorService)),Ye(1,s.Inject(_.HyperLinkModel))],Me);const Mn={[I.RibbonStartGroup.OTHERS]:{[se.id]:{order:2,menuItemFactory:kn},[be(se.id)]:{order:2,menuItemFactory:Tn}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.OTHERS]:{order:1,[se.id]:{order:0,menuItemFactory:Rn},[be(se.id)]:{order:0,menuItemFactory:Pn}}}};var xn=Object.getOwnPropertyDescriptor,jn=(e,n,t,r)=>{for(var i=r>1?void 0:r?xn(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},_e=(e,n)=>(t,r)=>n(t,r,e);let xe=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(){[[Oe,Oe.componentKey],[Te,Te.componentKey],[Xe,"LinkSingle"]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[Ae,ye,Be,se].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(Mn)}_initShortCut(){this._shortcutService.registerShortcut(et)}};xe=jn([_e(0,s.Inject(I.ComponentManager)),_e(1,s.ICommandService),_e(2,I.IMenuManagerService),_e(3,s.Inject(s.Injector)),_e(4,s.Inject(I.IShortcutService))],xe);var An=Object.getOwnPropertyDescriptor,Bn=(e,n,t,r)=>{for(var i=r>1?void 0:r?An(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Lt=(e,n)=>(t,r)=>n(t,r,e);let je=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)}}};je=Bn([Lt(0,s.Inject(_.SheetsHyperLinkParserService)),Lt(1,s.Inject(exports.SheetsHyperLinkResolverService))],je);var Vn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Fn=(e,n,t)=>n in e?Vn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Zn=(e,n,t,r)=>{for(var i=r>1?void 0:r?$n(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},Rt=(e,n)=>(t,r)=>n(t,r,e),Nt=(e,n,t)=>Fn(e,typeof n!="symbol"?n+"":n,t);exports.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=mt,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{menu:i,...o}=s.merge({},mt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Pt,o)}onStarting(){[[exports.SheetsHyperLinkResolverService],[exports.SheetsHyperLinkPopupService],[qe],[Me],[Ue],[xe],[we],[exports.SheetsHyperLinkCopyPasteController],[Ne],[je]].forEach(t=>this._injector.add(t)),this._injector.get(Me)}onReady(){this._injector.get(fe.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[Ge]),this._injector.get(we),this._injector.get(exports.SheetsHyperLinkCopyPasteController),this._injector.get(xe)}onRendered(){this._injector.get(Ne),this._injector.get(je),this._injector.get(Ue)}};Nt(exports.UniverSheetsHyperLinkUIPlugin,"pluginName",ze);Nt(exports.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkUIPlugin=Zn([s.DependentOn(_.UniverSheetsHyperLinkPlugin,te.UniverDocsUIPlugin),Rt(1,s.Inject(s.Injector)),Rt(2,s.IConfigService)],exports.UniverSheetsHyperLinkUIPlugin);exports.CloseHyperLinkPopupOperation=ye;exports.InsertHyperLinkOperation=Be;exports.InsertLinkShortcut=et;exports.OpenHyperLinkEditPanelOperation=Ae;exports.SheetsHyperLinkSidePanelService=qe;
|