@univerjs/sheets-hyper-link-ui 0.12.4 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var jt=Object.defineProperty;var At=(t,n,e)=>n in t?jt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var V=(t,n,e)=>At(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),C=require("@univerjs/sheets"),E=require("@univerjs/sheets-ui"),Ie=require("@univerjs/docs"),Q=require("@univerjs/docs-ui"),_e=require("@univerjs/engine-render"),S=require("@univerjs/ui"),D=require("rxjs"),_=require("react/jsx-runtime"),T=require("@univerjs/design"),z=require("@univerjs/engine-formula"),$t=require("@univerjs/sheets-formula-ui"),I=require("@univerjs/sheets-hyper-link"),f=require("react"),mt=require("@univerjs/sheets-data-validation");var y=(t=>(t.EDITING="editing",t.VIEWING="viewing",t.ZEN_EDITOR="zen_mode",t))(y||{});function Le(t){return s.Tools.isLegalUrl(t)}function Bt(t){return/^[a-zA-Z]+:\/\//.test(t)}function Vt(t){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(t)}function Ft(t){if(Le(t)){const n=Bt(t)?t:Vt(t)?`mailto://${t}`:`http://${t}`;let e;try{e=new URL(n)}catch{return t}return e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol&&e.pathname===location.pathname&&e.hash&&!e.search?e.hash:n}return t}const Et="sheets-hyper-link-ui.config",It={};var Zt=Object.getOwnPropertyDescriptor,Kt=(t,n,e,r)=>{for(var i=r>1?void 0:r?Zt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ue=(t,n)=>(e,r)=>n(e,r,t);function Wt(t,n){const e=n.getMergeData(),r=n.getMaxColumns()-1,i=n.getMaxRows()-1;if(r<t.endColumn&&(t.endColumn=r),i<t.endRow&&(t.endRow=i),t.rangeType===s.RANGE_TYPE.COLUMN||s.RANGE_TYPE.ROW)return t;const o=[];return e.forEach(a=>{s.Rectangle.intersects(t,a)&&o.push(a)}),s.Rectangle.realUnion(t,...o)}exports.SheetsHyperLinkResolverService=class{constructor(n,e,r,i,o,a){this._univerInstanceService=n,this._commandService=e,this._definedNamesService=r,this._messageService=i,this._localeService=o,this._configService=a}navigate(n){switch(n.type){case I.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:e,range:r,rangeid:i}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const a=o.getUnitId();if(i){const u=this._definedNamesService.getValueById(a,i);if(!u)return;const{formulaOrRefString:l}=u,h=this._definedNamesService.getWorksheetByRef(a,l);if(!h){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:T.MessageType.Error});return}if(h.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:T.MessageType.Error});return}this.navigateToDefineName(a,i)}if(e){if(r){const u=z.deserializeRangeWithSheet(r);s.isValidRange(u.range)&&r!==I.ERROR_RANGE&&this.navigateToRange(a,e,u.range);return}this.navigateToSheetById(a,e)}}async navigateToRange(n,e,r,i){const o=await this.navigateToSheetById(n,e);if(o){const a=Wt(r,o);await this._commandService.executeCommand(C.SetSelectionsOperation.id,{unitId:n,subUnitId:e,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:a,forceTop:i})}}async navigateToSheetById(n,e){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()===e)return i;const o=r.getSheetBySheetId(e);return o?r.getHiddenWorksheets().indexOf(e)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:T.MessageType.Error}),!1):await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:e})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:T.MessageType.Error}),!1)}async navigateToDefineName(n,e){return this._definedNamesService.focusRange(n,e),!0}async navigateToOtherWebsite(n){var r;const e=this._configService.getConfig(Et);if((r=e==null?void 0:e.urlHandler)!=null&&r.navigateToOtherWebsite)return e.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}};exports.SheetsHyperLinkResolverService=Kt([ue(0,s.IUniverInstanceService),ue(1,s.ICommandService),ue(2,z.IDefinedNamesService),ue(3,S.IMessageService),ue(4,s.Inject(s.LocaleService)),ue(5,s.IConfigService)],exports.SheetsHyperLinkResolverService);class Ye extends s.Disposable{constructor(){super(...arguments);V(this,"_customHyperLinks",new Map)}isBuiltInLinkType(e){return e!==I.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:e})=>e)}findCustomHyperLink(e){return Array.from(this._customHyperLinks.values()).find(i=>i.match(e))}registerCustomHyperLink(e){this._customHyperLinks.set(e.type,e)}getCustomHyperLink(e){return this._customHyperLinks.get(e)}removeCustomHyperLink(e){const{_customHyperLinks:r}=this;r.delete(e)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const Pe=()=>{var tt;const[t,n]=f.useState(""),[e,r]=f.useState(!1),[i,o]=f.useState(""),[a,u]=f.useState(!0),[l,h]=f.useState(I.SheetHyperLinkType.URL),[d,p]=f.useState(""),m=S.useDependency(s.LocaleService),v=S.useDependency(z.IDefinedNamesService),R=S.useDependency(E.IEditorBridgeService),P=S.useDependency(s.IUniverInstanceService),L=S.useDependency(exports.SheetsHyperLinkPopupService),c=S.useObservable(L.currentEditing$),k=S.useDependency(I.SheetsHyperLinkParserService),M=S.useDependency(exports.SheetsHyperLinkResolverService),N=S.useDependency(s.ICommandService),H=S.useDependency(Ye),$=f.useMemo(()=>H.getOptions(),[H]),A=S.useDependency(S.IZenZoneService),Y=S.useDependency(_e.IRenderManagerService),ee=S.useDependency(E.IMarkSelectionService),ye=S.useDependency(Ie.DocSelectionManagerService),te=S.useDependency(s.IContextService),le=S.useDependency(s.ThemeService),de=S.useDependency(Ie.DocSelectionManagerService),[pe,fe]=f.useState(!1),oe=S.useDependency(C.SheetsSelectionsService),Ot=f.useMemo(()=>oe.getCurrentSelections(),[]),Ce=f.useMemo(()=>{if(!H.isBuiltInLinkType(l))return H.getCustomHyperLink(l)},[H,l]),[ae,Nt]=f.useState(!1),[he,Qe]=f.useState(!1),B=f.useRef(!1),F=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),Ht=(F==null?void 0:F.getActiveSheet().getSheetId())||"",q=f.useCallback(g=>{o(g.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);f.useEffect(()=>{var g,w,b,O,U,Z,nt,rt,it,st,ot,at,ct,ut,lt,dt,pt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:ne,row:Ve,col:Fe}=c;let{label:G}=c;typeof G=="number"&&(G=`${G}`);let K;if(ne)K={id:(g=ne==null?void 0:ne.rangeId)!=null?g:"",display:G!=null?G:"",payload:(b=(w=ne==null?void 0:ne.properties)==null?void 0:w.url)!=null?b:"",row:Ve,column:Fe};else if(c.type===y.VIEWING){const x=P.getUnit(c.unitId),J=x==null?void 0:x.getSheetBySheetId(c.subUnitId),j=J==null?void 0:J.getCellRaw(c.row,c.col),ce=(Z=(U=(O=j==null?void 0:j.p)==null?void 0:O.body)==null?void 0:U.customRanges)==null?void 0:Z.find(gt=>{var vt;return gt.rangeType===s.CustomRangeType.HYPERLINK&&((vt=gt.properties)==null?void 0:vt.url)}),ge=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(ge))&&u(!1),K={id:"",display:"",payload:(st=(it=ce==null?void 0:ce.properties)==null?void 0:it.url)!=null?st:"",row:Ve,column:Fe}}else{const x=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),J=ye.getActiveTextRange(),j=x==null?void 0:x.getBody(),ce=J&&j?J:null,ge=ce&&((at=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(ce,(ot=j==null?void 0:j.customRanges)!=null?ot:[]))==null?void 0:at[0]);u(!1),K={id:"",display:G!=null?G:"",payload:(ut=(ct=ge==null?void 0:ge.properties)==null?void 0:ct.url)!=null?ut:"",row:Ve,column:Fe}}n(K.id);const ht=H.findCustomHyperLink(K);if(ht){const x=ht.convert(K);h(x.type),p(x.payload),q(x.display);return}q(K.display);const X=k.parseHyperLink(K.payload);switch(h(X.type===I.SheetHyperLinkType.INVALID?I.SheetHyperLinkType.RANGE:X.type),X.type){case I.SheetHyperLinkType.URL:{p(X.url),X.url===K.display&&(B.current=!0);break}case I.SheetHyperLinkType.RANGE:{const x=X.searchObj,J=x.gid&&(pt=(dt=(lt=P.getUnit(c.unitId))==null?void 0:lt.getSheetBySheetId(x.gid))==null?void 0:dt.getName())!=null?pt:"",j=z.serializeRangeWithSheet(J,z.deserializeRangeWithSheet(x.range).range);p(j),j===K.display&&(B.current=!0);break}case I.SheetHyperLinkType.SHEET:{const x=X.searchObj;p(x.gid);break}case I.SheetHyperLinkType.DEFINE_NAME:{const x=X.searchObj;p(x.rangeid);break}default:p("");break}}},[c,M,H,ye,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 w=P.getUnit(c.unitId,s.UniverInstanceType.UNIVER_SHEET),b=w==null?void 0:w.getSheetBySheetId(c.subUnitId),O=b==null?void 0:b.getMergedCell(c.row,c.col),U=new s.ColorKit(le.getColorFromTheme("primary.600")).toRgb();g=ee.addShape({range:O!=null?O:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${U.r}, ${U.g}, ${U.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{g&&ee.removeShape(g)}},[c,ee,le,P]),f.useEffect(()=>{Qe(l===I.SheetHyperLinkType.RANGE)},[l]),f.useEffect(()=>{const g=(c==null?void 0:c.type)===y.ZEN_EDITOR?Y.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):Y.getRenderById(R.getCurrentEditorId()),w=new s.DisposableCollection;if(g){const b=g.with(Q.DocSelectionRenderService);b.setReserveRangesStatus(!0),w.add(()=>{b.setReserveRangesStatus(!1)})}return()=>{R.disableForceKeepVisible(),w.dispose()}},[c==null?void 0:c.type,R,Y]),f.useEffect(()=>(he&&L.setIsKeepVisible(he),L.setIsKeepVisible(pe),()=>{L.setIsKeepVisible(!1)}),[he,pe,L]),f.useEffect(()=>()=>{A.temporaryHidden&&(A.show(),te.setContextValue(s.FOCUSING_SHEET,!1))},[te,A]),f.useEffect(()=>{if(he)return R.enableForceKeepVisible(),()=>{R.disableForceKeepVisible()}},[he,R]);const xt=[{label:m.t("hyperLink.form.link"),value:I.SheetHyperLinkType.URL},{label:m.t("hyperLink.form.range"),value:I.SheetHyperLinkType.RANGE},{label:m.t("hyperLink.form.worksheet"),value:I.SheetHyperLinkType.SHEET},{label:m.t("hyperLink.form.definedName"),value:I.SheetHyperLinkType.DEFINE_NAME},...$];if(!F)return;const Ut=F.getHiddenWorksheets(),Ae=F.getSheets().map(g=>({label:g.getName(),value:g.getSheetId()})).filter(g=>Ut.indexOf(g.value)===-1),$e=Object.values((tt=v.getDefinedNameMap(F.getUnitId()))!=null?tt:{}).map(g=>({label:g.name,value:g.id})),et=(g,w)=>{if(g===I.SheetHyperLinkType.URL)return Ft(w);if(g===I.SheetHyperLinkType.RANGE){const b=z.deserializeRangeWithSheet(w),O=F.getSheetBySheetName(b.sheetName);if(O)return`#gid=${O.getSheetId()}&range=${z.serializeRange(b.range)}`}return`#${g}=${w}`},Mt=S.useEvent(g=>{var U;const b=g.split(",").map(z.deserializeRangeWithSheet)[0];if(!b||!s.isValidRange(b.range))return;b.sheetName||(b.sheetName=((U=F.getActiveSheet())==null?void 0:U.getName())||"");const O=z.serializeRangeToRefString(b);p(O),O&&(B.current||!i)&&(q(O),B.current=!0)}),Be=async()=>{if(a&&!i||!d||l===I.SheetHyperLinkType.URL&&!Le(d)){Nt(!0);return}if(c)if(t){const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?I.UpdateRichHyperLinkCommand.id:I.UpdateHyperLinkCommand.id;await N.executeCommand(g,{id:t,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?i:"",payload:et(l,d)},row:c.row,column:c.col,documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}else{const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?I.AddRichHyperLinkCommand.id:I.AddHyperLinkCommand.id;await N.executeCommand(g,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:s.generateRandomId(),row:c.row,column:c.col,payload:et(l,d),display:a?i:""},documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}if((c==null?void 0:c.type)===y.VIEWING){await N.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const g=1;await N.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}})}N.executeCommand(Se.id)};return c?_.jsxs("div",{className:T.clsx("univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900",T.borderClassName),children:[a?_.jsx(T.FormLayout,{label:m.t("hyperLink.form.label"),error:ae&&!i?m.t("hyperLink.form.inputError"):"",children:_.jsx(T.Input,{value:i,onChange:g=>{q(g),B.current=!1},placeholder:m.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===S.KeyCode.ENTER&&Be()}})}):null,_.jsx(T.FormLayout,{label:m.t("hyperLink.form.type"),children:_.jsx(T.Select,{className:"univer-w-full",options:xt,value:l,onChange:g=>{h(g),p("")}})}),l===I.SheetHyperLinkType.URL&&_.jsx(T.FormLayout,{error:ae?d?Le(d)?"":m.t("hyperLink.form.linkError"):m.t("hyperLink.form.inputError"):"",children:_.jsx(T.Input,{value:d,onChange:g=>{p(g),g&&(B.current||!i||i===g)&&(q(g),B.current=!0)},placeholder:m.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===S.KeyCode.ENTER&&Be()}})}),l===I.SheetHyperLinkType.RANGE&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.inputError"):"",children:_.jsx($t.RangeSelector,{unitId:F.getUnitId(),subUnitId:Ht,maxRangeCount:1,supportAcrossSheet:!0,initialValue:d,resetRange:Ot,onChange:(g,w)=>Mt(w),onRangeSelectorDialogVisibleChange:async g=>{var w,b;if(fe(g),g)c.type===y.ZEN_EDITOR&&(A.hide(),te.setContextValue(s.FOCUSING_SHEET,!0)),c.type!==y.VIEWING&&R.enableForceKeepVisible(),r(!0);else{if(await M.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===y.ZEN_EDITOR){await N.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(),te.setContextValue(s.FOCUSING_SHEET,!1);const O=(w=Y.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:w.with(Q.DocBackScrollRenderController),U=(b=de.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:b[0];O&&U&&(O.scrollToRange(U),de.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}R.disableForceKeepVisible(),r(!1)}},onFocusChange:g=>Qe(g)})}),l===I.SheetHyperLinkType.SHEET&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.selectError"):"",children:_.jsx(T.Select,{className:"univer-w-full",options:Ae,value:d,onChange:g=>{var O,U;p(g);const w=(O=Ae.find(Z=>Z.value===g))==null?void 0:O.label,b=(U=Ae.find(Z=>Z.value===d))==null?void 0:U.label;w&&(B.current||!i||i===b)&&(q(w),B.current=!0)}})}),l===I.SheetHyperLinkType.DEFINE_NAME&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.selectError"):"",children:_.jsx(T.Select,{className:"univer-w-full",options:$e,value:d,onChange:g=>{var O,U;p(g);const w=(O=$e.find(Z=>Z.value===g))==null?void 0:O.label,b=(U=$e.find(Z=>Z.value===d))==null?void 0:U.label;w&&(B.current||!i||i===b)&&(q(w),B.current=!0)}})}),(Ce==null?void 0:Ce.Form)&&_.jsx(Ce.Form,{linkId:t,payload:d,display:i,showError:ae,setByPayload:B,setDisplay:g=>{q(g),B.current=!0},setPayload:p}),_.jsxs("div",{className:"univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[_.jsx(T.Button,{onClick:()=>{c&&M.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),N.executeCommand(Se.id)},children:m.t("hyperLink.form.cancel")}),_.jsx(T.Button,{variant:"primary",onClick:async()=>{Be()},children:m.t("hyperLink.form.ok")})]})]}):null};Pe.componentKey="univer.sheet.cell-link-edit";function se({ref:t,...n}){const{icon:e,id:r,className:i,extend:o,...a}=n,u=`univerjs-icon univerjs-icon-${r} ${i||""}`.trim(),l=f.useRef(`_${zt()}`);return Rt(e,`${r}`,{defIds:e.defIds,idSuffix:l.current},{ref:t,className:u,...a},o)}function Rt(t,n,e,r,i){return f.createElement(t.tag,{key:n,...Yt(t,e,i),...r},(Gt(t,e).children||[]).map((o,a)=>Rt(o,`${n}-${t.tag}-${a}`,e,void 0,i)))}function Yt(t,n,e){const r={...t.attrs};e!=null&&e.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=e.colorChannel1),t.tag==="mask"&&r.id&&(r.id=r.id+n.idSuffix),Object.entries(r).forEach(([o,a])=>{o==="mask"&&typeof a=="string"&&(r[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))});const{defIds:i}=n;return!i||i.length===0||(t.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+n.idSuffix),Object.entries(r).forEach(([o,a])=>{typeof a=="string"&&(r[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))})),r}function Gt(t,n){var r;const{defIds:e}=n;return!e||e.length===0?t:t.tag==="defs"&&((r=t.children)!=null&&r.length)?{...t,children:t.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+n.idSuffix}}:i)}:t}function zt(){return Math.random().toString(36).substring(2,8)}se.displayName="UniverIcon";const qt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Re=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"all-border-icon",ref:e,icon:qt}))});Re.displayName="AllBorderIcon";const Xt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Lt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"copy-icon",ref:e,icon:Xt}))});Lt.displayName="CopyIcon";const Jt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ge=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"link-icon",ref:e,icon:Jt}))});Ge.displayName="LinkIcon";const Qt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z"}}]},Pt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"unlink-icon",ref:e,icon:Qt}))});Pt.displayName="UnlinkIcon";const en={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Tt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"write-icon",ref:e,icon:en}))});Tt.displayName="WriteIcon";const tn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"white",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},kt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"xlsx-multi-icon",ref:e,icon:tn}))});kt.displayName="XlsxMultiIcon";const nn={[I.SheetHyperLinkType.URL]:_.jsx(Ge,{}),[I.SheetHyperLinkType.SHEET]:_.jsx(kt,{className:"univer-text-green-500"}),[I.SheetHyperLinkType.RANGE]:_.jsx(Re,{}),[I.SheetHyperLinkType.DEFINE_NAME]:_.jsx(Re,{}),[I.SheetHyperLinkType.INVALID]:_.jsx(Re,{})},St=t=>{var M,N;const n=S.useDependency(exports.SheetsHyperLinkPopupService),e=S.useDependency(s.ICommandService),r=S.useDependency(S.IMessageService),i=S.useDependency(s.LocaleService),o=S.useDependency(exports.SheetsHyperLinkResolverService),a=S.useDependency(E.IEditorBridgeService),u=S.useDependency(I.SheetsHyperLinkParserService),l=S.useDependency(S.IZenZoneService),{customRange:h,row:d,col:p,unitId:m,subUnitId:v,editPermission:R,copyPermission:P,type:L}=t;if(!((M=h==null?void 0:h.properties)!=null&&M.url))return null;const c=u.parseHyperLink((N=h.properties.url)!=null?N:""),k=c.type===I.SheetHyperLinkType.INVALID;return _.jsxs("div",{className:T.clsx("univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900",T.borderClassName),onClick:()=>n.hideCurrentPopup(),children:[_.jsxs("div",{className:T.clsx("univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600",{"univer-text-red-500":k}),onClick:()=>{l.visible||k||o.navigate(c)},children:[_.jsx("div",{className:"univer-mr-2 univer-flex univer-h-5 univer-w-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:nn[c.type]}),_.jsx(T.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:_.jsx("span",{className:"univer-flex-1 univer-truncate",children:c.name})})]}),_.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center",children:[P&&_.jsx("div",{className:T.clsx("univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-red-500":k}),onClick:()=>{if(!k){if(c.type!==I.SheetHyperLinkType.URL){const H=new URL(window.location.href);H.hash=c.url.slice(1),navigator.clipboard.writeText(H.href)}else navigator.clipboard.writeText(c.url);r.show({content:i.t("hyperLink.message.coped"),type:T.MessageType.Info})}},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.copy"),children:_.jsx(Lt,{className:"dark:!univer-text-white"})})}),R&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{e.executeCommand(Me.id,{unitId:m,subUnitId:v,row:d,col:p,customRangeId:h.rangeId,type:L})},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.edit"),children:_.jsx(Tt,{className:"dark:!univer-text-white"})})}),_.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{const H=L===y.EDITING||L===y.ZEN_EDITOR?I.CancelRichHyperLinkCommand.id:I.CancelHyperLinkCommand.id;e.syncExecuteCommand(H,{unitId:m,subUnitId:v,id:h.rangeId,row:d,column:p,documentId:L===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.cancel"),children:_.jsx(Pt,{className:"dark:!univer-text-white"})})})]})]})]})},Te=()=>{var i,o;const t=S.useDependency(exports.SheetsHyperLinkPopupService),[n,e]=f.useState(null),r=S.useDependency(s.IUniverInstanceService);if(f.useEffect(()=>{e(t.currentPopup);const a=t.currentPopup$.subscribe(u=>{e(u)});return()=>{a.unsubscribe()}},[t.currentPopup,t.currentPopup$]),!n)return null;if(n.showAll){const a=r.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(n.subUnitId),l=u==null?void 0:u.getCell(n.row,n.col),h=(o=(i=l==null?void 0:l.p)==null?void 0:i.body)==null?void 0:o.customRanges;return h!=null&&h.length?_.jsx("div",{children:h.map(d=>_.jsx(St,{...n,customRange:d},d.rangeId))}):null}return _.jsx(St,{...n})};Te.componentKey="univer.sheet.cell-link-popup";var rn=Object.getOwnPropertyDescriptor,sn=(t,n,e,r)=>{for(var i=r>1?void 0:r?rn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},re=(t,n)=>(e,r)=>n(e,r,t);const _t=(t,n)=>{var e,r;return t.unitId===n.unitId&&t.subUnitId===n.subUnitId&&t.row===n.row&&t.col===n.col&&((e=t.customRange)==null?void 0:e.rangeId)===((r=n.customRange)==null?void 0:r.rangeId)&&t.type===n.type};exports.SheetsHyperLinkPopupService=class extends s.Disposable{constructor(e,r,i,o,a,u,l){super();V(this,"_currentPopup",null);V(this,"_currentPopup$",new D.Subject);V(this,"currentPopup$",this._currentPopup$.asObservable());V(this,"_currentEditingPopup",null);V(this,"_currentEditing$",new D.BehaviorSubject(null));V(this,"currentEditing$",this._currentEditing$.asObservable());V(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=e,this._injector=r,this._univerInstanceService=i,this._editorBridgeService=o,this._textSelectionManagerService=a,this._docCanvasPopManagerService=u,this._zenZoneService=l,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(e){this._isKeepVisible=e}getIsKeepVisible(){return this._isKeepVisible}showPopup(e){var m;if(this._currentPopup&&_t(e,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),e.type!==y.ZEN_EDITOR&&this._zenZoneService.visible))return;const r=this._currentEditing$.getValue();if(r&&_t(e,r))return;const{unitId:i,subUnitId:o,row:a,col:u,customRangeRect:l,customRange:h}=e;let d;const p={componentKey:Te.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(e.type,!0)}};if(e.type===y.EDITING){if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(l,p)}else if(e.type===y.ZEN_EDITOR){if(!h)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:h.startIndex,endOffset:h.endIndex+1,collapsed:!1},p,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(e.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,p,i,o);else{if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupByPosition(l,p,e)}d&&(this._currentPopup&&((m=this._currentPopup.disposable)==null||m.dispose()),this._currentPopup={unitId:i,subUnitId:o,disposable:d,row:a,col:u,editPermission:!!e.editPermission,copyPermission:!!e.copyPermission,customRange:h,type:e.type,showAll:e.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(e,r){var i,o;this._currentPopup&&((!e||e===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))}dispose(){super.dispose(),this.hideCurrentPopup(),this.endEditing(),this._currentPopup$.complete(),this._currentEditing$.complete()}_getEditingRange(){var i,o,a;const e=this._editorBridgeService.isVisible().visible,r=this._editorBridgeService.getEditCellState();if(e&&r){const u=this._textSelectionManagerService.getActiveTextRange(),l=(i=r.documentLayoutObject.documentModel)==null?void 0:i.getBody();if(!l)return null;if(!u||u.collapsed)return{startOffset:0,endOffset:l.dataStream.length-2,collapsed:l.dataStream.length-2===0,label:s.BuildTextUtils.transform.getPlainText(l.dataStream)};const h=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(u,(a=(o=l.customRanges)==null?void 0:o.filter(m=>m.rangeType===s.CustomRangeType.HYPERLINK))!=null?a:[]);let d=u.startOffset,p=u.endOffset;return h.forEach(m=>{d=Math.min(d,m.startIndex),p=Math.max(p,m.endIndex+1)}),{startOffset:d,endOffset:p,collapsed:d===p,label:s.BuildTextUtils.transform.getPlainText(l.dataStream.slice(d,p))}}return null}get _editPopup(){return{componentKey:Pe.componentKey,direction:"vertical",onClickOutside:()=>{this.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:"hide"}}startAddEditing(e){var a,u,l,h,d;const{unitId:r,subUnitId:i,type:o}=e;if(o===y.ZEN_EDITOR){const p=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!p)return;const m=this._textSelectionManagerService.getActiveTextRange();if(!m)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(m,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const v=(a=p.getBody())==null?void 0:a.dataStream.slice(m.startOffset,m.endOffset);this._currentEditing$.next({...e,label:v})}else if(o===y.EDITING){const p=this._getEditingRange();if(!p)return;this._textSelectionManagerService.replaceDocRanges([{...p}],{unitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const m=this._injector.get(_e.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!m)return;const v=Q.calcDocRangePositions(p,m);if(!(v!=null&&v.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(v.pop(),this._editPopup,r,i),this._currentEditing$.next({...e,label:(u=p==null?void 0:p.label)!=null?u:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,r,i);const p=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),m=p==null?void 0:p.getSheetBySheetId(i),v=m==null?void 0:m.getCellRaw(e.row,e.col);this._currentEditing$.next({...e,label:v!=null&&v.p?s.BuildTextUtils.transform.getPlainText((h=(l=v.p.body)==null?void 0:l.dataStream)!=null?h:""):((d=v==null?void 0:v.v)!=null?d:"").toString()})}}startEditing(e){var u,l,h,d,p,m;(u=this._currentEditingPopup)==null||u.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:r,subUnitId:i}=e;let o,a;if(e.type===y.ZEN_EDITOR){const v=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(h=(l=v==null?void 0:v.getBody())==null?void 0:l.customRanges)==null?void 0:h.find(R=>R.rangeId===e.customRangeId),a=o?(d=v==null?void 0:v.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(e.type===y.EDITING){const v=E.getEditingCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!v||!((p=v.rects)!=null&&p.length))return;o=v.customRange,a=v.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(v.rects.pop(),this._editPopup,r,i)}else{const v=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),R=v==null?void 0:v.getSheetBySheetId(i),P=R==null?void 0:R.getCellRaw(e.row,e.col),L=v==null?void 0:v.getStyles().getStyleByCell(P),c=L==null?void 0:L.tr,k=E.getCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!k||!((m=k.rects)!=null&&m.length))return;o=k.customRange,a=k.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,r,i):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(k.rects.pop(),this._editPopup,{unitId:r,subUnitId:i,row:e.row,col:e.col})}this._currentEditing$.next({...e,customRange:o,label:a})}endEditing(e){var i;if(this.getIsKeepVisible())return;const r=this._currentEditing$.getValue();r&&(!e||e===r.type)&&((i=this._currentEditingPopup)==null||i.dispose(),this._currentEditing$.next(null))}};exports.SheetsHyperLinkPopupService=sn([re(0,s.Inject(E.SheetCanvasPopManagerService)),re(1,s.Inject(s.Injector)),re(2,s.IUniverInstanceService),re(3,E.IEditorBridgeService),re(4,s.Inject(Ie.DocSelectionManagerService)),re(5,s.Inject(Q.DocCanvasPopManagerService)),re(6,S.IZenZoneService)],exports.SheetsHyperLinkPopupService);var me=(t=>(t[t.ALLOWED=0]="ALLOWED",t[t.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",t[t.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",t))(me||{});const on=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),ze=(t,n,e,r)=>{var u,l,h,d,p;const i=n.getCell(e,r);if(i!=null&&i.f||i!=null&&i.si||(h=(l=(u=i==null?void 0:i.p)==null?void 0:u.body)==null?void 0:l.customBlocks)!=null&&h.length)return 1;const o=t.has(mt.SheetDataValidationModel)?t.get(mt.SheetDataValidationModel):null,a=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),e,r);return a&&on.has(a.type)?!0:(p=(d=i==null?void 0:i.p)==null?void 0:d.drawingsOrder)!=null&&p.length?2:0},an=t=>{const n=t.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const e=n.getActiveSheet(),r=t.get(C.SheetsSelectionsService).getCurrentSelections();if(!r.length)return!0;const i=r[0].range.startRow,o=r[0].range.startColumn;return ze(t,e,i,o)===1},cn=t=>{const n=t.get(Ie.DocSelectionManagerService),e=t.get(s.IUniverInstanceService),r=n.getTextRanges();if(!(r!=null&&r.length))return!0;const i=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return!!(!i||r.every(a=>a.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},Me={type:s.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(t,n){if(!n)return!1;const e=t.get(exports.SheetsHyperLinkPopupService);return n.customRangeId?e.startEditing(n):e.startAddEditing(n),!0}},Se={type:s.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(t){return t.get(exports.SheetsHyperLinkPopupService).endEditing(),!0}},je={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(t){var p;const n=t.get(s.IUniverInstanceService),e=C.getSheetCommandTarget(n),r=t.get(E.IEditorBridgeService);if(!e)return!1;const i=t.get(s.ICommandService),a=t.get(C.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const u=a.range.startRow,l=a.range.startColumn,h=r.isVisible(),d=((p=n.getFocusedUnit())==null?void 0:p.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return i.executeCommand(Me.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:u,col:l,type:d?y.ZEN_EDITOR:h.visible?y.EDITING:y.VIEWING})}},ie={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(t){if(an(t))return!1;const n=t.get(s.ICommandService);return t.get(exports.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(Se.id):n.executeCommand(je.id)}},qe="SHEET_HYPER_LINK_UI_PLUGIN";var un=Object.getOwnPropertyDescriptor,ln=(t,n,e,r)=>{for(var i=r>1?void 0:r?un(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ee=(t,n)=>(e,r)=>n(e,r,t);exports.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(e,r,i,o){super();V(this,"_plainTextFilter",new Set);V(this,"_copyInfo");this._sheetClipboardService=e,this._hyperLinkModel=r,this._injector=i,this._resolverService=o,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(e){this._plainTextFilter.add(e)}removePlainTextFilter(e){this._plainTextFilter.delete(e)}_filterPlainText(e){return Array.from(this._plainTextFilter).every(r=>r(e))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:qe,onBeforeCopy:(e,r,i)=>this._collect(e,r,i),onPasteCells:(e,r,i,o)=>{const{copyType:a=E.COPY_TYPE.COPY,pasteType:u}=o,{range:l}=e||{},{range:h,unitId:d,subUnitId:p}=r;return this._generateMutations(h,{copyType:a,pasteType:u,copyRange:l,unitId:d,subUnitId:p})},onPastePlainText:(e,r)=>{const i=this._filterPlainText(r);if(Le(r)&&i){const{range:o,unitId:a,subUnitId:u}=e,{ranges:[l],mapFunc:h}=E.virtualizeDiscreteRanges([o]),d=[],p=[];return s.Range.foreach(l,(m,v)=>{const{row:R,col:P}=h(m,v),L=this._hyperLinkModel.getHyperLinkByLocation(a,u,R,P);L&&d.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:u,id:L.id}}),L&&p.push({id:I.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:u,link:L}})}),{redos:d,undos:p}}return{undos:[],redos:[]}},priority:99})}_collect(e,r,i){const o=new s.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:r,matrix:o};const a=this._injector.invoke(h=>C.rangeToDiscreteRange(i,h,e,r));if(!a)return;const{rows:u,cols:l}=a;u.forEach((h,d)=>{l.forEach((p,m)=>{var R;const v=this._hyperLinkModel.getHyperLinkByLocation(e,r,h,p);o.setValue(d,m,(R=v==null?void 0:v.id)!=null?R:"")})})}_generateMutations(e,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,u=[],l=[],{ranges:[h,d],mapFunc:p}=E.virtualizeDiscreteRanges([r.copyRange,e]);return E.getRepeatRange(h,d,!0).forEach(({startRange:v})=>{var R;(R=this._copyInfo)==null||R.matrix.forValue((P,L,c)=>{const k=s.Rectangle.getPositionRange({startRow:P,endRow:P,startColumn:L,endColumn:L},v),M=this._hyperLinkModel.getHyperLink(o,a,c),{row:N,col:H}=p(k.startRow,k.startColumn),$=this._hyperLinkModel.getHyperLinkByLocation(r.unitId,r.subUnitId,N,H),A=s.generateRandomId();$&&u.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:$.id}}),M&&(u.push({id:I.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:{...M,id:A,row:N,column:H}}}),l.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:A}})),$&&l.push({id:I.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:$}})})}),{redos:u,undos:l}}};exports.SheetsHyperLinkCopyPasteController=ln([Ee(0,E.ISheetClipboardService),Ee(1,s.Inject(I.HyperLinkModel)),Ee(2,s.Inject(s.Injector)),Ee(3,s.Inject(exports.SheetsHyperLinkResolverService))],exports.SheetsHyperLinkCopyPasteController);const Xe=(t,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var i;const e=t.get(s.IUniverInstanceService),r=(i=t.get(_e.IRenderManagerService).getRenderById(n))==null?void 0:i.with(Q.DocSelectionRenderService);return r?r.textSelectionInner$.pipe(D.map(()=>{const a=t.get(E.IEditorBridgeService).getEditCellState();if(!a)return!0;const u=C.getSheetCommandTarget(e,{unitId:a.unitId,subUnitId:a.sheetId});return!(u!=null&&u.worksheet)||ze(t,u.worksheet,a.row,a.column)===1?!0:cn(t)})):D.of(!0)},wt=t=>{var i;const n=t.get(s.IUniverInstanceService),e=t.has(E.IEditorBridgeService)?t.get(E.IEditorBridgeService):null;return((i=e==null?void 0:e.currentEditCellState$.pipe(D.map(o=>{if(!o)return me.DISABLED_BY_CELL;const a=C.getSheetCommandTarget(n,{unitId:o.unitId,subUnitId:o.sheetId});return a?ze(t,a.worksheet,o.row,o.column):me.DISABLED_BY_CELL}),D.switchMap(o=>{if(o===me.DISABLED_BY_CELL)return D.of(!0);const a=e?e.visible$:D.of(null);return D.combineLatest([a,n.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC)]).pipe(D.switchMap(([u,l])=>u!=null&&u.visible?(l==null?void 0:l.getUnitId())===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?D.of(!0):Xe(t,s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY):D.of(o!==me.ALLOWED)))})))!=null?i:D.of(!0)).pipe(D.switchMap(o=>o?D.of(!0):E.getCurrentRangeDisable$(t,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetSetCellValuePermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},!0)))},ke={commandId:je.id,type:S.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkIcon"},we=t=>`${t}-zen-editor`,dn=t=>({...ke,id:ke.commandId,hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:wt(t)}),pn=t=>({...ke,id:we(ke.commandId),hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Xe(t)}),be={tooltip:"hyperLink.form.addTitle",commandId:ie.id,type:S.MenuItemType.BUTTON,icon:"LinkIcon"},hn=t=>({...be,id:be.commandId,hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:wt(t)}),gn=t=>({...be,id:we(be.commandId),hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Xe(t)}),Je={id:ie.id,binding:S.KeyCode.K|S.MetaKeys.CTRL_COMMAND,preconditions:E.whenSheetEditorFocused};var vn=Object.getOwnPropertyDescriptor,mn=(t,n,e,r)=>{for(var i=r>1?void 0:r?vn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},yt=(t,n)=>(e,r)=>n(e,r,t);let De=class extends s.Disposable{constructor(t,n){super(),this._autoFillService=t,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const t=()=>({redos:[],undos:[]}),n=(r,i)=>{const{source:o,target:a,unitId:u,subUnitId:l}=r,h=E.virtualizeDiscreteRanges([o,a]),[d,p]=h.ranges,{mapFunc:m}=h,v={row:d.startRow,col:d.startColumn},R=E.getAutoFillRepeatRange(d,p),P=[],L=[];return R.forEach(c=>{const k=c.repeatStartCell,M=c.relativeRange,N={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},H={startRow:k.row,startColumn:k.col,endColumn:k.col,endRow:k.row};s.Range.foreach(M,($,A)=>{const Y=s.Rectangle.getPositionRange({startRow:$,startColumn:A,endColumn:A,endRow:$},N),{row:ee,col:ye}=m(Y.startRow,Y.startColumn),te=this._hyperLinkModel.getHyperLinkByLocation(u,l,ee,ye),le=s.Rectangle.getPositionRange({startRow:$,startColumn:A,endColumn:A,endRow:$},H),{row:de,col:pe}=m(le.startRow,le.startColumn),fe=s.generateRandomId(),oe=this._hyperLinkModel.getHyperLinkByLocation(u,l,de,pe);oe&&P.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:oe.id}}),(E.APPLY_TYPE.COPY===i||E.APPLY_TYPE.SERIES===i)&&te&&(P.push({id:I.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:{...te,id:fe,row:de,column:pe}}}),L.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:fe}})),oe&&L.push({id:I.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:oe}})})}),{undos:L,redos:P}},e={id:qe,onFillData:(r,i,o)=>o===E.APPLY_TYPE.COPY||o===E.APPLY_TYPE.ONLY_FORMAT||o===E.APPLY_TYPE.SERIES?n(r,o):t()};this.disposeWithMe(this._autoFillService.addHook(e))}};De=mn([yt(0,E.IAutoFillService),yt(1,s.Inject(I.HyperLinkModel))],De);var In=Object.getOwnPropertyDescriptor,Sn=(t,n,e,r)=>{for(var i=r>1?void 0:r?In(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ze=(t,n)=>(e,r)=>n(e,r,t);let Oe=class extends s.Disposable{constructor(t,n,e){super(),this._localeService=t,this._commandService=n,this._sheetPermissionCheckController=e,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Je.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")))}))}};Oe=Sn([Ze(0,s.Inject(s.LocaleService)),Ze(1,s.ICommandService),Ze(2,s.Inject(C.SheetPermissionCheckController))],Oe);var _n=Object.getOwnPropertyDescriptor,yn=(t,n,e,r)=>{for(var i=r>1?void 0:r?_n(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},W=(t,n)=>(e,r)=>n(e,r,t);let Ne=class extends s.Disposable{constructor(t,n,e,r,i,o,a,u,l,h){super(),this._hoverManagerService=t,this._sheetsHyperLinkPopupService=n,this._renderManagerService=e,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=o,this._editorBridgeService=a,this._textSelectionManagerService=u,this._univerInstanceService=l,this._zenZoneService=h,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(t){const{unitId:n,subUnitId:e,row:r,col:i}=t,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),a=o==null?void 0:o.getSheetBySheetId(e);if(!a)return{viewPermission:!1,editPermission:!1,copyPermission:!1};const u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookViewPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],n,e);let l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],n,e);const h=a.getCellRaw(r,i);h!=null&&h.f&&h.f.startsWith("=HYPERLINK(")&&(l=!1);const d=this._permissionService.composePermission([new C.WorkbookCopyPermission(n).id,new C.WorksheetCopyPermission(n,e).id]).every(p=>p.value);return{viewPermission:u,editPermission:l,copyPermission:d}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(D.debounceTime(200)).subscribe(t=>{var N,H,$;if(!t||((N=t.customRange)==null?void 0:N.rangeType)!==s.CustomRangeType.HYPERLINK){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:e,row:r,col:i}=t,o=this._renderManagerService.getRenderById(n);if(!o)return;const a=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(e);if(!u)return;if(!o.with(E.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING);return}const h=(H=o==null?void 0:o.with(E.SheetSkeletonManagerService).getSkeletonParam(e))==null?void 0:H.skeleton,d=i,p=r;let m=p,v=d;h&&h.overflowCache.forValue((A,Y,ee)=>{s.Rectangle.contains(ee,{startColumn:d,endColumn:d,startRow:p,endRow:p})&&(m=A,v=Y)});const{viewPermission:R,editPermission:P,copyPermission:L}=this._getLinkPermission(t);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=u.getCellStyleOnly(m,v),k=a.getStyles().getStyleByCell(c),M=($=k==null?void 0:k.tr)==null?void 0:$.a;if(!M&&!t.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:m,col:v,editPermission:P,copyPermission:L,customRange:t.customRange,customRangeRect:t.rect,type:y.VIEWING,unitId:n,subUnitId:e,showAll:!!M})}))}_initHoverEditingListener(){let t=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(D.switchMap(n=>this._editorBridgeService.visible$.pipe(D.map(e=>({visible:e,state:n}))))).subscribe(({visible:n,state:e})=>{if(!e||e.editorUnitId!==s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){t==null||t.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING);return}const{editorUnitId:r,unitId:i,sheetId:o,row:a,column:u}=e,l=this._renderManagerService.getRenderById(r);if(!l)return;const{editPermission:h,viewPermission:d,copyPermission:p}=this._getLinkPermission({unitId:i,subUnitId:o,row:a,col:u}),m=l.with(Q.DocEventManagerService);d&&(t==null||t.unsubscribe(),t=m.hoverCustomRanges$.pipe(D.debounceTime(200)).subscribe(v=>{var k,M;const R=v.find(N=>N.range.rangeType===s.CustomRangeType.HYPERLINK);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const P=R.rects[R.rects.length-1];if(!((M=(k=this._renderManagerService.getRenderById(i))==null?void 0:k.with(E.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:M.skeleton)||!P)return;const c=l.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:i,subUnitId:o,row:a,col:u,customRange:R.range,customRangeRect:{left:P.left+c.left,top:P.top+c.top,bottom:P.bottom+c.top,right:P.right+c.left},editPermission:h,copyPermission:p,type:y.EDITING})}))})),this.disposeWithMe(()=>{t==null||t.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t?(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(D.switchMap(t=>{const n=t===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(t):null;return n?n.with(Q.DocEventManagerService).hoverCustomRanges$.pipe(D.debounceTime(200)):new D.Observable(e=>{e.next(null)})})).subscribe(t=>{const n=t==null?void 0:t.find(r=>r.range.rangeType===s.CustomRangeType.HYPERLINK),e=this._editorBridgeService.getEditCellState();if(n&&e){const{unitId:r,sheetId:i,row:o,column:a}=e,{editPermission:u,viewPermission:l,copyPermission:h}=this._getLinkPermission({unitId:r,subUnitId:i,row:o,col:a});l&&this._sheetsHyperLinkPopupService.showPopup({type:y.ZEN_EDITOR,unitId:r,subUnitId:i,row:o,col:a,customRange:n.range,editPermission:u,copyPermission:h})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(t=>{t&&t.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(y.EDITING)}))}_initCommandListener(){const t=[C.ClearSelectionContentCommand.id,C.ClearSelectionAllCommand.id,C.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{t.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ne=yn([W(0,s.Inject(E.HoverManagerService)),W(1,s.Inject(exports.SheetsHyperLinkPopupService)),W(2,s.Inject(_e.IRenderManagerService)),W(3,s.Inject(s.IPermissionService)),W(4,s.Inject(C.SheetPermissionCheckController)),W(5,s.ICommandService),W(6,E.IEditorBridgeService),W(7,s.Inject(Ie.DocSelectionManagerService)),W(8,s.IUniverInstanceService),W(9,S.IZenZoneService)],Ne);var fn=Object.getOwnPropertyDescriptor,bt=(t,n,e,r)=>{for(var i=r>1?void 0:r?fn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ke=(t,n)=>(e,r)=>n(e,r,t);let We=class extends s.Disposable{constructor(t,n){super(),this._context=t,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const t=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(D.debounceTime(16)).subscribe(()=>{t()}))}};We=bt([Ke(1,s.Inject(I.HyperLinkModel))],We);let He=class extends s.Disposable{constructor(t,n){super(),this._sheetInterceptorService=t,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(t,n,e)=>{const{row:r,col:i,unitId:o,subUnitId:a}=n,u=this._hyperLinkModel.getHyperLinkByLocation(o,a,r,i);return u&&t&&(t===n.rawData&&(t={...n.rawData}),t.linkUrl=u.payload,t.linkId=u.id),e(t)}}))}};He=bt([Ke(0,s.Inject(C.SheetInterceptorService)),Ke(1,s.Inject(I.HyperLinkModel))],He);const Cn={[S.RibbonInsertGroup.MEDIA]:{[ie.id]:{order:1,menuItemFactory:hn},[we(ie.id)]:{order:1,menuItemFactory:gn}},[S.ContextMenuPosition.MAIN_AREA]:{[S.ContextMenuGroup.OTHERS]:{order:1,[ie.id]:{order:0,menuItemFactory:dn},[we(ie.id)]:{order:0,menuItemFactory:pn}}}};var En=Object.getOwnPropertyDescriptor,Rn=(t,n,e,r)=>{for(var i=r>1?void 0:r?En(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ve=(t,n)=>(e,r)=>n(e,r,t);let xe=class extends s.Disposable{constructor(t,n,e,r,i){super(),this._componentManager=t,this._commandService=n,this._menuManagerService=e,this._injector=r,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Te.componentKey,Te],[Pe.componentKey,Pe],["LinkIcon",Ge]].forEach(([t,n])=>{this._componentManager.register(t,n)})}_initCommands(){[Me,Se,je,ie].forEach(t=>{this._commandService.registerCommand(t)})}_initMenus(){this._menuManagerService.mergeMenu(Cn)}_initShortCut(){this._shortcutService.registerShortcut(Je)}};xe=Rn([ve(0,s.Inject(S.ComponentManager)),ve(1,s.ICommandService),ve(2,S.IMenuManagerService),ve(3,s.Inject(s.Injector)),ve(4,s.Inject(S.IShortcutService))],xe);var Ln=Object.getOwnPropertyDescriptor,Pn=(t,n,e,r)=>{for(var i=r>1?void 0:r?Ln(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ft=(t,n)=>(e,r)=>n(e,r,t);let Ue=class extends s.Disposable{constructor(t,n){super(),this._parserService=t,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const t=location.hash;if(t){const n=this._parserService.parseHyperLink(t);this._resolverService.navigate(n)}}};Ue=Pn([ft(0,s.Inject(I.SheetsHyperLinkParserService)),ft(1,s.Inject(exports.SheetsHyperLinkResolverService))],Ue);var Tn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,wn=(t,n,e)=>n in t?Tn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,bn=(t,n,e,r)=>{for(var i=r>1?void 0:r?kn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ct=(t,n)=>(e,r)=>n(e,r,t),Dt=(t,n,e)=>wn(t,typeof n!="symbol"?n+"":n,e);exports.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=It,e,r){super(),this._config=n,this._injector=e,this._configService=r;const{menu:i,...o}=s.merge({},It,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Et,o)}onStarting(){[[exports.SheetsHyperLinkResolverService],[exports.SheetsHyperLinkPopupService],[Ye],[He],[Ne],[xe],[De],[exports.SheetsHyperLinkCopyPasteController],[Oe],[Ue]].forEach(e=>this._injector.add(e)),this._injector.get(He)}onReady(){this._injector.get(_e.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[We]),this._injector.get(De),this._injector.get(exports.SheetsHyperLinkCopyPasteController),this._injector.get(xe)}onRendered(){this._injector.get(Oe),this._injector.get(Ue),this._injector.get(Ne)}};Dt(exports.UniverSheetsHyperLinkUIPlugin,"pluginName",qe);Dt(exports.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkUIPlugin=bn([s.DependentOn(I.UniverSheetsHyperLinkPlugin,Q.UniverDocsUIPlugin),Ct(1,s.Inject(s.Injector)),Ct(2,s.IConfigService)],exports.UniverSheetsHyperLinkUIPlugin);exports.CloseHyperLinkPopupOperation=Se;exports.InsertHyperLinkOperation=je;exports.InsertLinkShortcut=Je;exports.OpenHyperLinkEditPanelOperation=Me;exports.SheetsHyperLinkSidePanelService=Ye;
1
+ "use strict";var jt=Object.defineProperty;var At=(t,n,e)=>n in t?jt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var V=(t,n,e)=>At(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),C=require("@univerjs/sheets"),E=require("@univerjs/sheets-ui"),Ie=require("@univerjs/docs"),Q=require("@univerjs/docs-ui"),_e=require("@univerjs/engine-render"),S=require("@univerjs/ui"),D=require("rxjs"),_=require("react/jsx-runtime"),T=require("@univerjs/design"),z=require("@univerjs/engine-formula"),$t=require("@univerjs/sheets-formula-ui"),I=require("@univerjs/sheets-hyper-link"),f=require("react"),mt=require("@univerjs/sheets-data-validation");var y=(t=>(t.EDITING="editing",t.VIEWING="viewing",t.ZEN_EDITOR="zen_mode",t))(y||{});function Le(t){return s.Tools.isLegalUrl(t)}function Bt(t){return/^[a-zA-Z]+:\/\//.test(t)}function Vt(t){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(t)}function Ft(t){if(Le(t)){const n=Bt(t)?t:Vt(t)?`mailto://${t}`:`http://${t}`;let e;try{e=new URL(n)}catch{return t}return e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol&&e.pathname===location.pathname&&e.hash&&!e.search?e.hash:n}return t}const Et="sheets-hyper-link-ui.config",It={};var Zt=Object.getOwnPropertyDescriptor,Kt=(t,n,e,r)=>{for(var i=r>1?void 0:r?Zt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ue=(t,n)=>(e,r)=>n(e,r,t);function Wt(t,n){const e=n.getMergeData(),r=n.getMaxColumns()-1,i=n.getMaxRows()-1;if(r<t.endColumn&&(t.endColumn=r),i<t.endRow&&(t.endRow=i),t.rangeType===s.RANGE_TYPE.COLUMN||s.RANGE_TYPE.ROW)return t;const o=[];return e.forEach(a=>{s.Rectangle.intersects(t,a)&&o.push(a)}),s.Rectangle.realUnion(t,...o)}exports.SheetsHyperLinkResolverService=class{constructor(n,e,r,i,o,a){this._univerInstanceService=n,this._commandService=e,this._definedNamesService=r,this._messageService=i,this._localeService=o,this._configService=a}navigate(n){switch(n.type){case I.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:e,range:r,rangeid:i}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const a=o.getUnitId();if(i){const u=this._definedNamesService.getValueById(a,i);if(!u)return;const{formulaOrRefString:l}=u,h=this._definedNamesService.getWorksheetByRef(a,l);if(!h){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:T.MessageType.Error});return}if(h.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:T.MessageType.Error});return}this.navigateToDefineName(a,i)}if(e){if(r){const u=z.deserializeRangeWithSheet(r);s.isValidRange(u.range)&&r!==I.ERROR_RANGE&&this.navigateToRange(a,e,u.range);return}this.navigateToSheetById(a,e)}}async navigateToRange(n,e,r,i){const o=await this.navigateToSheetById(n,e);if(o){const a=Wt(r,o);await this._commandService.executeCommand(C.SetSelectionsOperation.id,{unitId:n,subUnitId:e,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:a,forceTop:i})}}async navigateToSheetById(n,e){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()===e)return i;const o=r.getSheetBySheetId(e);return o?r.getHiddenWorksheets().indexOf(e)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:T.MessageType.Error}),!1):await this._commandService.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:e})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:T.MessageType.Error}),!1)}async navigateToDefineName(n,e){return this._definedNamesService.focusRange(n,e),!0}async navigateToOtherWebsite(n){var r;const e=this._configService.getConfig(Et);if((r=e==null?void 0:e.urlHandler)!=null&&r.navigateToOtherWebsite)return e.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}};exports.SheetsHyperLinkResolverService=Kt([ue(0,s.IUniverInstanceService),ue(1,s.ICommandService),ue(2,z.IDefinedNamesService),ue(3,S.IMessageService),ue(4,s.Inject(s.LocaleService)),ue(5,s.IConfigService)],exports.SheetsHyperLinkResolverService);class Ye extends s.Disposable{constructor(){super(...arguments);V(this,"_customHyperLinks",new Map)}isBuiltInLinkType(e){return e!==I.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:e})=>e)}findCustomHyperLink(e){return Array.from(this._customHyperLinks.values()).find(i=>i.match(e))}registerCustomHyperLink(e){this._customHyperLinks.set(e.type,e)}getCustomHyperLink(e){return this._customHyperLinks.get(e)}removeCustomHyperLink(e){const{_customHyperLinks:r}=this;r.delete(e)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const Pe=()=>{var tt;const[t,n]=f.useState(""),[e,r]=f.useState(!1),[i,o]=f.useState(""),[a,u]=f.useState(!0),[l,h]=f.useState(I.SheetHyperLinkType.URL),[d,p]=f.useState(""),m=S.useDependency(s.LocaleService),v=S.useDependency(z.IDefinedNamesService),R=S.useDependency(E.IEditorBridgeService),P=S.useDependency(s.IUniverInstanceService),L=S.useDependency(exports.SheetsHyperLinkPopupService),c=S.useObservable(L.currentEditing$),k=S.useDependency(I.SheetsHyperLinkParserService),M=S.useDependency(exports.SheetsHyperLinkResolverService),N=S.useDependency(s.ICommandService),H=S.useDependency(Ye),$=f.useMemo(()=>H.getOptions(),[H]),A=S.useDependency(S.IZenZoneService),Y=S.useDependency(_e.IRenderManagerService),ee=S.useDependency(E.IMarkSelectionService),ye=S.useDependency(Ie.DocSelectionManagerService),te=S.useDependency(s.IContextService),le=S.useDependency(s.ThemeService),de=S.useDependency(Ie.DocSelectionManagerService),[pe,fe]=f.useState(!1),oe=S.useDependency(C.SheetsSelectionsService),Ot=f.useMemo(()=>oe.getCurrentSelections(),[]),Ce=f.useMemo(()=>{if(!H.isBuiltInLinkType(l))return H.getCustomHyperLink(l)},[H,l]),[ae,Nt]=f.useState(!1),[he,Qe]=f.useState(!1),B=f.useRef(!1),F=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),Ht=(F==null?void 0:F.getActiveSheet().getSheetId())||"",q=f.useCallback(g=>{o(g.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);f.useEffect(()=>{var g,w,b,O,U,Z,nt,rt,it,st,ot,at,ct,ut,lt,dt,pt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:ne,row:Ve,col:Fe}=c;let{label:G}=c;typeof G=="number"&&(G=`${G}`);let K;if(ne)K={id:(g=ne==null?void 0:ne.rangeId)!=null?g:"",display:G!=null?G:"",payload:(b=(w=ne==null?void 0:ne.properties)==null?void 0:w.url)!=null?b:"",row:Ve,column:Fe};else if(c.type===y.VIEWING){const x=P.getUnit(c.unitId),J=x==null?void 0:x.getSheetBySheetId(c.subUnitId),j=J==null?void 0:J.getCellRaw(c.row,c.col),ce=(Z=(U=(O=j==null?void 0:j.p)==null?void 0:O.body)==null?void 0:U.customRanges)==null?void 0:Z.find(gt=>{var vt;return gt.rangeType===s.CustomRangeType.HYPERLINK&&((vt=gt.properties)==null?void 0:vt.url)}),ge=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(ge))&&u(!1),K={id:"",display:"",payload:(st=(it=ce==null?void 0:ce.properties)==null?void 0:it.url)!=null?st:"",row:Ve,column:Fe}}else{const x=P.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),J=ye.getActiveTextRange(),j=x==null?void 0:x.getBody(),ce=J&&j?J:null,ge=ce&&((at=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(ce,(ot=j==null?void 0:j.customRanges)!=null?ot:[]))==null?void 0:at[0]);u(!1),K={id:"",display:G!=null?G:"",payload:(ut=(ct=ge==null?void 0:ge.properties)==null?void 0:ct.url)!=null?ut:"",row:Ve,column:Fe}}n(K.id);const ht=H.findCustomHyperLink(K);if(ht){const x=ht.convert(K);h(x.type),p(x.payload),q(x.display);return}q(K.display);const X=k.parseHyperLink(K.payload);switch(h(X.type===I.SheetHyperLinkType.INVALID?I.SheetHyperLinkType.RANGE:X.type),X.type){case I.SheetHyperLinkType.URL:{p(X.url),X.url===K.display&&(B.current=!0);break}case I.SheetHyperLinkType.RANGE:{const x=X.searchObj,J=x.gid&&(pt=(dt=(lt=P.getUnit(c.unitId))==null?void 0:lt.getSheetBySheetId(x.gid))==null?void 0:dt.getName())!=null?pt:"",j=z.serializeRangeWithSheet(J,z.deserializeRangeWithSheet(x.range).range);p(j),j===K.display&&(B.current=!0);break}case I.SheetHyperLinkType.SHEET:{const x=X.searchObj;p(x.gid);break}case I.SheetHyperLinkType.DEFINE_NAME:{const x=X.searchObj;p(x.rangeid);break}default:p("");break}}},[c,M,H,ye,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 w=P.getUnit(c.unitId,s.UniverInstanceType.UNIVER_SHEET),b=w==null?void 0:w.getSheetBySheetId(c.subUnitId),O=b==null?void 0:b.getMergedCell(c.row,c.col),U=new s.ColorKit(le.getColorFromTheme("primary.600")).toRgb();g=ee.addShape({range:O!=null?O:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${U.r}, ${U.g}, ${U.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{g&&ee.removeShape(g)}},[c,ee,le,P]),f.useEffect(()=>{Qe(l===I.SheetHyperLinkType.RANGE)},[l]),f.useEffect(()=>{const g=(c==null?void 0:c.type)===y.ZEN_EDITOR?Y.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):Y.getRenderById(R.getCurrentEditorId()),w=new s.DisposableCollection;if(g){const b=g.with(Q.DocSelectionRenderService);b.setReserveRangesStatus(!0),w.add(()=>{b.setReserveRangesStatus(!1)})}return()=>{R.disableForceKeepVisible(),w.dispose()}},[c==null?void 0:c.type,R,Y]),f.useEffect(()=>(he&&L.setIsKeepVisible(he),L.setIsKeepVisible(pe),()=>{L.setIsKeepVisible(!1)}),[he,pe,L]),f.useEffect(()=>()=>{A.temporaryHidden&&(A.show(),te.setContextValue(s.FOCUSING_SHEET,!1))},[te,A]),f.useEffect(()=>{if(he)return R.enableForceKeepVisible(),()=>{R.disableForceKeepVisible()}},[he,R]);const xt=[{label:m.t("hyperLink.form.link"),value:I.SheetHyperLinkType.URL},{label:m.t("hyperLink.form.range"),value:I.SheetHyperLinkType.RANGE},{label:m.t("hyperLink.form.worksheet"),value:I.SheetHyperLinkType.SHEET},{label:m.t("hyperLink.form.definedName"),value:I.SheetHyperLinkType.DEFINE_NAME},...$];if(!F)return;const Ut=F.getHiddenWorksheets(),Ae=F.getSheets().map(g=>({label:g.getName(),value:g.getSheetId()})).filter(g=>Ut.indexOf(g.value)===-1),$e=Object.values((tt=v.getDefinedNameMap(F.getUnitId()))!=null?tt:{}).map(g=>({label:g.name,value:g.id})),et=(g,w)=>{if(g===I.SheetHyperLinkType.URL)return Ft(w);if(g===I.SheetHyperLinkType.RANGE){const b=z.deserializeRangeWithSheet(w),O=F.getSheetBySheetName(b.sheetName);if(O)return`#gid=${O.getSheetId()}&range=${z.serializeRange(b.range)}`}return`#${g}=${w}`},Mt=S.useEvent(g=>{var U;const b=g.split(",").map(z.deserializeRangeWithSheet)[0];if(!b||!s.isValidRange(b.range))return;b.sheetName||(b.sheetName=((U=F.getActiveSheet())==null?void 0:U.getName())||"");const O=z.serializeRangeToRefString(b);p(O),O&&(B.current||!i)&&(q(O),B.current=!0)}),Be=async()=>{if(a&&!i||!d||l===I.SheetHyperLinkType.URL&&!Le(d)){Nt(!0);return}if(c)if(t){const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?I.UpdateRichHyperLinkCommand.id:I.UpdateHyperLinkCommand.id;await N.executeCommand(g,{id:t,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?i:"",payload:et(l,d)},row:c.row,column:c.col,documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}else{const g=c.type===y.ZEN_EDITOR||c.type===y.EDITING?I.AddRichHyperLinkCommand.id:I.AddHyperLinkCommand.id;await N.executeCommand(g,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:s.generateRandomId(),row:c.row,column:c.col,payload:et(l,d),display:a?i:""},documentId:c.type===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}if((c==null?void 0:c.type)===y.VIEWING){await N.executeCommand(C.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const g=1;await N.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}})}N.executeCommand(Se.id)};return c?_.jsxs("div",{className:T.clsx("univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900",T.borderClassName),children:[a?_.jsx(T.FormLayout,{label:m.t("hyperLink.form.label"),error:ae&&!i?m.t("hyperLink.form.inputError"):"",children:_.jsx(T.Input,{value:i,onChange:g=>{q(g),B.current=!1},placeholder:m.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===S.KeyCode.ENTER&&Be()}})}):null,_.jsx(T.FormLayout,{label:m.t("hyperLink.form.type"),children:_.jsx(T.Select,{className:"univer-w-full",options:xt,value:l,onChange:g=>{h(g),p("")}})}),l===I.SheetHyperLinkType.URL&&_.jsx(T.FormLayout,{error:ae?d?Le(d)?"":m.t("hyperLink.form.linkError"):m.t("hyperLink.form.inputError"):"",children:_.jsx(T.Input,{value:d,onChange:g=>{p(g),g&&(B.current||!i||i===g)&&(q(g),B.current=!0)},placeholder:m.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:g=>{g.keyCode===S.KeyCode.ENTER&&Be()}})}),l===I.SheetHyperLinkType.RANGE&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.inputError"):"",children:_.jsx($t.RangeSelector,{unitId:F.getUnitId(),subUnitId:Ht,maxRangeCount:1,supportAcrossSheet:!0,initialValue:d,resetRange:Ot,onChange:(g,w)=>Mt(w),onRangeSelectorDialogVisibleChange:async g=>{var w,b;if(fe(g),g)c.type===y.ZEN_EDITOR&&(A.hide(),te.setContextValue(s.FOCUSING_SHEET,!0)),c.type!==y.VIEWING&&R.enableForceKeepVisible(),r(!0);else{if(await M.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===y.ZEN_EDITOR){await N.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(),te.setContextValue(s.FOCUSING_SHEET,!1);const O=(w=Y.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:w.with(Q.DocBackScrollRenderController),U=(b=de.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:b[0];O&&U&&(O.scrollToRange(U),de.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}R.disableForceKeepVisible(),r(!1)}},onFocusChange:g=>Qe(g)})}),l===I.SheetHyperLinkType.SHEET&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.selectError"):"",children:_.jsx(T.Select,{className:"univer-w-full",options:Ae,value:d,onChange:g=>{var O,U;p(g);const w=(O=Ae.find(Z=>Z.value===g))==null?void 0:O.label,b=(U=Ae.find(Z=>Z.value===d))==null?void 0:U.label;w&&(B.current||!i||i===b)&&(q(w),B.current=!0)}})}),l===I.SheetHyperLinkType.DEFINE_NAME&&_.jsx(T.FormLayout,{error:ae&&!d?m.t("hyperLink.form.selectError"):"",children:_.jsx(T.Select,{className:"univer-w-full",options:$e,value:d,onChange:g=>{var O,U;p(g);const w=(O=$e.find(Z=>Z.value===g))==null?void 0:O.label,b=(U=$e.find(Z=>Z.value===d))==null?void 0:U.label;w&&(B.current||!i||i===b)&&(q(w),B.current=!0)}})}),(Ce==null?void 0:Ce.Form)&&_.jsx(Ce.Form,{linkId:t,payload:d,display:i,showError:ae,setByPayload:B,setDisplay:g=>{q(g),B.current=!0},setPayload:p}),_.jsxs("div",{className:"univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[_.jsx(T.Button,{onClick:()=>{c&&M.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),N.executeCommand(Se.id)},children:m.t("hyperLink.form.cancel")}),_.jsx(T.Button,{variant:"primary",onClick:async()=>{Be()},children:m.t("hyperLink.form.ok")})]})]}):null};Pe.componentKey="univer.sheet.cell-link-edit";function se({ref:t,...n}){const{icon:e,id:r,className:i,extend:o,...a}=n,u=`univerjs-icon univerjs-icon-${r} ${i||""}`.trim(),l=f.useRef(`_${zt()}`);return Rt(e,`${r}`,{defIds:e.defIds,idSuffix:l.current},{ref:t,className:u,...a},o)}function Rt(t,n,e,r,i){return f.createElement(t.tag,{key:n,...Yt(t,e,i),...r},(Gt(t,e).children||[]).map((o,a)=>Rt(o,`${n}-${t.tag}-${a}`,e,void 0,i)))}function Yt(t,n,e){const r={...t.attrs};e!=null&&e.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=e.colorChannel1),t.tag==="mask"&&r.id&&(r.id=r.id+n.idSuffix),Object.entries(r).forEach(([o,a])=>{o==="mask"&&typeof a=="string"&&(r[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))});const{defIds:i}=n;return!i||i.length===0||(t.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+n.idSuffix),Object.entries(r).forEach(([o,a])=>{typeof a=="string"&&(r[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))})),r}function Gt(t,n){var r;const{defIds:e}=n;return!e||e.length===0?t:t.tag==="defs"&&((r=t.children)!=null&&r.length)?{...t,children:t.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+n.idSuffix}}:i)}:t}function zt(){return Math.random().toString(36).substring(2,8)}se.displayName="UniverIcon";const qt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Re=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"all-border-icon",ref:e,icon:qt}))});Re.displayName="AllBorderIcon";const Xt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Lt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"copy-icon",ref:e,icon:Xt}))});Lt.displayName="CopyIcon";const Jt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ge=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"link-icon",ref:e,icon:Jt}))});Ge.displayName="LinkIcon";const Qt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z"}}]},Pt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"unlink-icon",ref:e,icon:Qt}))});Pt.displayName="UnlinkIcon";const en={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Tt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"write-icon",ref:e,icon:en}))});Tt.displayName="WriteIcon";const tn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"white",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},kt=f.forwardRef(function(n,e){return f.createElement(se,Object.assign({},n,{id:"xlsx-multi-icon",ref:e,icon:tn}))});kt.displayName="XlsxMultiIcon";const nn={[I.SheetHyperLinkType.URL]:_.jsx(Ge,{}),[I.SheetHyperLinkType.SHEET]:_.jsx(kt,{className:"univer-text-green-500"}),[I.SheetHyperLinkType.RANGE]:_.jsx(Re,{}),[I.SheetHyperLinkType.DEFINE_NAME]:_.jsx(Re,{}),[I.SheetHyperLinkType.INVALID]:_.jsx(Re,{})},St=t=>{var M,N;const n=S.useDependency(exports.SheetsHyperLinkPopupService),e=S.useDependency(s.ICommandService),r=S.useDependency(S.IMessageService),i=S.useDependency(s.LocaleService),o=S.useDependency(exports.SheetsHyperLinkResolverService),a=S.useDependency(E.IEditorBridgeService),u=S.useDependency(I.SheetsHyperLinkParserService),l=S.useDependency(S.IZenZoneService),{customRange:h,row:d,col:p,unitId:m,subUnitId:v,editPermission:R,copyPermission:P,type:L}=t;if(!((M=h==null?void 0:h.properties)!=null&&M.url))return null;const c=u.parseHyperLink((N=h.properties.url)!=null?N:""),k=c.type===I.SheetHyperLinkType.INVALID;return _.jsxs("div",{className:T.clsx("univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900",T.borderClassName),onClick:()=>n.hideCurrentPopup(),children:[_.jsxs("div",{className:T.clsx("univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600",{"univer-text-red-500":k}),onClick:()=>{l.visible||k||o.navigate(c)},children:[_.jsx("div",{className:"univer-mr-2 univer-flex univer-h-5 univer-w-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:nn[c.type]}),_.jsx(T.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:_.jsx("span",{className:"univer-flex-1 univer-truncate",children:c.name})})]}),_.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center",children:[P&&_.jsx("div",{className:T.clsx("univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-red-500":k}),onClick:()=>{if(!k){if(c.type!==I.SheetHyperLinkType.URL){const H=new URL(window.location.href);H.hash=c.url.slice(1),navigator.clipboard.writeText(H.href)}else navigator.clipboard.writeText(c.url);r.show({content:i.t("hyperLink.message.coped"),type:T.MessageType.Info})}},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.copy"),children:_.jsx(Lt,{className:"dark:!univer-text-white"})})}),R&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{e.executeCommand(Me.id,{unitId:m,subUnitId:v,row:d,col:p,customRangeId:h.rangeId,type:L})},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.edit"),children:_.jsx(Tt,{className:"dark:!univer-text-white"})})}),_.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{const H=L===y.EDITING||L===y.ZEN_EDITOR?I.CancelRichHyperLinkCommand.id:I.CancelHyperLinkCommand.id;e.syncExecuteCommand(H,{unitId:m,subUnitId:v,id:h.rangeId,row:d,column:p,documentId:L===y.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:_.jsx(T.Tooltip,{placement:"bottom",title:i.t("hyperLink.popup.cancel"),children:_.jsx(Pt,{className:"dark:!univer-text-white"})})})]})]})]})},Te=()=>{var i,o;const t=S.useDependency(exports.SheetsHyperLinkPopupService),[n,e]=f.useState(null),r=S.useDependency(s.IUniverInstanceService);if(f.useEffect(()=>{e(t.currentPopup);const a=t.currentPopup$.subscribe(u=>{e(u)});return()=>{a.unsubscribe()}},[t.currentPopup,t.currentPopup$]),!n)return null;if(n.showAll){const a=r.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(n.subUnitId),l=u==null?void 0:u.getCell(n.row,n.col),h=(o=(i=l==null?void 0:l.p)==null?void 0:i.body)==null?void 0:o.customRanges;return h!=null&&h.length?_.jsx("div",{children:h.map(d=>_.jsx(St,{...n,customRange:d},d.rangeId))}):null}return _.jsx(St,{...n})};Te.componentKey="univer.sheet.cell-link-popup";var rn=Object.getOwnPropertyDescriptor,sn=(t,n,e,r)=>{for(var i=r>1?void 0:r?rn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},re=(t,n)=>(e,r)=>n(e,r,t);const _t=(t,n)=>{var e,r;return t.unitId===n.unitId&&t.subUnitId===n.subUnitId&&t.row===n.row&&t.col===n.col&&((e=t.customRange)==null?void 0:e.rangeId)===((r=n.customRange)==null?void 0:r.rangeId)&&t.type===n.type};exports.SheetsHyperLinkPopupService=class extends s.Disposable{constructor(e,r,i,o,a,u,l){super();V(this,"_currentPopup",null);V(this,"_currentPopup$",new D.Subject);V(this,"currentPopup$",this._currentPopup$.asObservable());V(this,"_currentEditingPopup",null);V(this,"_currentEditing$",new D.BehaviorSubject(null));V(this,"currentEditing$",this._currentEditing$.asObservable());V(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=e,this._injector=r,this._univerInstanceService=i,this._editorBridgeService=o,this._textSelectionManagerService=a,this._docCanvasPopManagerService=u,this._zenZoneService=l,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(e){this._isKeepVisible=e}getIsKeepVisible(){return this._isKeepVisible}showPopup(e){var m;if(this._currentPopup&&_t(e,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),e.type!==y.ZEN_EDITOR&&this._zenZoneService.visible))return;const r=this._currentEditing$.getValue();if(r&&_t(e,r))return;const{unitId:i,subUnitId:o,row:a,col:u,customRangeRect:l,customRange:h}=e;let d;const p={componentKey:Te.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(e.type,!0)}};if(e.type===y.EDITING){if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(l,p)}else if(e.type===y.ZEN_EDITOR){if(!h)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:h.startIndex,endOffset:h.endIndex+1,collapsed:!1},p,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(e.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,p,i,o);else{if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupByPosition(l,p,e)}d&&(this._currentPopup&&((m=this._currentPopup.disposable)==null||m.dispose()),this._currentPopup={unitId:i,subUnitId:o,disposable:d,row:a,col:u,editPermission:!!e.editPermission,copyPermission:!!e.copyPermission,customRange:h,type:e.type,showAll:e.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(e,r){var i,o;this._currentPopup&&((!e||e===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))}dispose(){super.dispose(),this.hideCurrentPopup(),this.endEditing(),this._currentPopup$.complete(),this._currentEditing$.complete()}_getEditingRange(){var i,o,a;const e=this._editorBridgeService.isVisible().visible,r=this._editorBridgeService.getEditCellState();if(e&&r){const u=this._textSelectionManagerService.getActiveTextRange(),l=(i=r.documentLayoutObject.documentModel)==null?void 0:i.getBody();if(!l)return null;if(!u||u.collapsed)return{startOffset:0,endOffset:l.dataStream.length-2,collapsed:l.dataStream.length-2===0,label:s.BuildTextUtils.transform.getPlainText(l.dataStream)};const h=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(u,(a=(o=l.customRanges)==null?void 0:o.filter(m=>m.rangeType===s.CustomRangeType.HYPERLINK))!=null?a:[]);let d=u.startOffset,p=u.endOffset;return h.forEach(m=>{d=Math.min(d,m.startIndex),p=Math.max(p,m.endIndex+1)}),{startOffset:d,endOffset:p,collapsed:d===p,label:s.BuildTextUtils.transform.getPlainText(l.dataStream.slice(d,p))}}return null}get _editPopup(){return{componentKey:Pe.componentKey,direction:"vertical",onClickOutside:()=>{this.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:"hide"}}startAddEditing(e){var a,u,l,h,d;const{unitId:r,subUnitId:i,type:o}=e;if(o===y.ZEN_EDITOR){const p=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!p)return;const m=this._textSelectionManagerService.getActiveTextRange();if(!m)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(m,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const v=(a=p.getBody())==null?void 0:a.dataStream.slice(m.startOffset,m.endOffset);this._currentEditing$.next({...e,label:v})}else if(o===y.EDITING){const p=this._getEditingRange();if(!p)return;this._textSelectionManagerService.replaceDocRanges([{...p}],{unitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const m=this._injector.get(_e.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!m)return;const v=Q.calcDocRangePositions(p,m);if(!(v!=null&&v.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(v.pop(),this._editPopup,r,i),this._currentEditing$.next({...e,label:(u=p==null?void 0:p.label)!=null?u:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,r,i);const p=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),m=p==null?void 0:p.getSheetBySheetId(i),v=m==null?void 0:m.getCellRaw(e.row,e.col);this._currentEditing$.next({...e,label:v!=null&&v.p?s.BuildTextUtils.transform.getPlainText((h=(l=v.p.body)==null?void 0:l.dataStream)!=null?h:""):((d=v==null?void 0:v.v)!=null?d:"").toString()})}}startEditing(e){var u,l,h,d,p,m;(u=this._currentEditingPopup)==null||u.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:r,subUnitId:i}=e;let o,a;if(e.type===y.ZEN_EDITOR){const v=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(h=(l=v==null?void 0:v.getBody())==null?void 0:l.customRanges)==null?void 0:h.find(R=>R.rangeId===e.customRangeId),a=o?(d=v==null?void 0:v.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(e.type===y.EDITING){const v=E.getEditingCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!v||!((p=v.rects)!=null&&p.length))return;o=v.customRange,a=v.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(v.rects.pop(),this._editPopup,r,i)}else{const v=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET),R=v==null?void 0:v.getSheetBySheetId(i),P=R==null?void 0:R.getCellRaw(e.row,e.col),L=v==null?void 0:v.getStyles().getStyleByCell(P),c=L==null?void 0:L.tr,k=E.getCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!k||!((m=k.rects)!=null&&m.length))return;o=k.customRange,a=k.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,r,i):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(k.rects.pop(),this._editPopup,{unitId:r,subUnitId:i,row:e.row,col:e.col})}this._currentEditing$.next({...e,customRange:o,label:a})}endEditing(e){var i;if(this.getIsKeepVisible())return;const r=this._currentEditing$.getValue();r&&(!e||e===r.type)&&((i=this._currentEditingPopup)==null||i.dispose(),this._currentEditing$.next(null))}};exports.SheetsHyperLinkPopupService=sn([re(0,s.Inject(E.SheetCanvasPopManagerService)),re(1,s.Inject(s.Injector)),re(2,s.IUniverInstanceService),re(3,E.IEditorBridgeService),re(4,s.Inject(Ie.DocSelectionManagerService)),re(5,s.Inject(Q.DocCanvasPopManagerService)),re(6,S.IZenZoneService)],exports.SheetsHyperLinkPopupService);var me=(t=>(t[t.ALLOWED=0]="ALLOWED",t[t.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",t[t.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",t))(me||{});const on=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),ze=(t,n,e,r)=>{var u,l,h,d,p;const i=n.getCell(e,r);if(i!=null&&i.f||i!=null&&i.si||(h=(l=(u=i==null?void 0:i.p)==null?void 0:u.body)==null?void 0:l.customBlocks)!=null&&h.length)return 1;const o=t.has(mt.SheetDataValidationModel)?t.get(mt.SheetDataValidationModel):null,a=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),e,r);return a&&on.has(a.type)?!0:(p=(d=i==null?void 0:i.p)==null?void 0:d.drawingsOrder)!=null&&p.length?2:0},an=t=>{const n=t.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const e=n.getActiveSheet(),r=t.get(C.SheetsSelectionsService).getCurrentSelections();if(!r.length)return!0;const i=r[0].range.startRow,o=r[0].range.startColumn;return ze(t,e,i,o)===1},cn=t=>{const n=t.get(Ie.DocSelectionManagerService),e=t.get(s.IUniverInstanceService),r=n.getTextRanges();if(!(r!=null&&r.length))return!0;const i=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return!!(!i||r.every(a=>a.collapsed)||!i.getSelfOrHeaderFooterModel(r[0].segmentId).getBody())},Me={type:s.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(t,n){if(!n)return!1;const e=t.get(exports.SheetsHyperLinkPopupService);return n.customRangeId?e.startEditing(n):e.startAddEditing(n),!0}},Se={type:s.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(t){return t.get(exports.SheetsHyperLinkPopupService).endEditing(),!0}},je={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(t){var p;const n=t.get(s.IUniverInstanceService),e=C.getSheetCommandTarget(n),r=t.get(E.IEditorBridgeService);if(!e)return!1;const i=t.get(s.ICommandService),a=t.get(C.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const u=a.range.startRow,l=a.range.startColumn,h=r.isVisible(),d=((p=n.getFocusedUnit())==null?void 0:p.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return i.executeCommand(Me.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:u,col:l,type:d?y.ZEN_EDITOR:h.visible?y.EDITING:y.VIEWING})}},ie={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(t){if(an(t))return!1;const n=t.get(s.ICommandService);return t.get(exports.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(Se.id):n.executeCommand(je.id)}},qe="SHEET_HYPER_LINK_UI_PLUGIN";var un=Object.getOwnPropertyDescriptor,ln=(t,n,e,r)=>{for(var i=r>1?void 0:r?un(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ee=(t,n)=>(e,r)=>n(e,r,t);exports.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(e,r,i,o){super();V(this,"_plainTextFilter",new Set);V(this,"_copyInfo");this._sheetClipboardService=e,this._hyperLinkModel=r,this._injector=i,this._resolverService=o,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(e){this._plainTextFilter.add(e)}removePlainTextFilter(e){this._plainTextFilter.delete(e)}_filterPlainText(e){return Array.from(this._plainTextFilter).every(r=>r(e))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:qe,onBeforeCopy:(e,r,i)=>this._collect(e,r,i),onPasteCells:(e,r,i,o)=>{const{copyType:a=E.COPY_TYPE.COPY,pasteType:u}=o,{range:l}=e||{},{range:h,unitId:d,subUnitId:p}=r;return this._generateMutations(h,{copyType:a,pasteType:u,copyRange:l,unitId:d,subUnitId:p})},onPastePlainText:(e,r)=>{const i=this._filterPlainText(r);if(Le(r)&&i){const{range:o,unitId:a,subUnitId:u}=e,{ranges:[l],mapFunc:h}=E.virtualizeDiscreteRanges([o]),d=[],p=[];return s.Range.foreach(l,(m,v)=>{const{row:R,col:P}=h(m,v),L=this._hyperLinkModel.getHyperLinkByLocation(a,u,R,P);L&&d.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:u,id:L.id}}),L&&p.push({id:I.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:u,link:L}})}),{redos:d,undos:p}}return{undos:[],redos:[]}},priority:99})}_collect(e,r,i){const o=new s.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:r,matrix:o};const a=this._injector.invoke(h=>C.rangeToDiscreteRange(i,h,e,r));if(!a)return;const{rows:u,cols:l}=a;u.forEach((h,d)=>{l.forEach((p,m)=>{var R;const v=this._hyperLinkModel.getHyperLinkByLocation(e,r,h,p);o.setValue(d,m,(R=v==null?void 0:v.id)!=null?R:"")})})}_generateMutations(e,r){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:o,subUnitId:a}=this._copyInfo,u=[],l=[],{ranges:[h,d],mapFunc:p}=E.virtualizeDiscreteRanges([r.copyRange,e]);return E.getRepeatRange(h,d,!0).forEach(({startRange:v})=>{var R;(R=this._copyInfo)==null||R.matrix.forValue((P,L,c)=>{const k=s.Rectangle.getPositionRange({startRow:P,endRow:P,startColumn:L,endColumn:L},v),M=this._hyperLinkModel.getHyperLink(o,a,c),{row:N,col:H}=p(k.startRow,k.startColumn),$=this._hyperLinkModel.getHyperLinkByLocation(r.unitId,r.subUnitId,N,H),A=s.generateRandomId();$&&u.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:$.id}}),M&&(u.push({id:I.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:{...M,id:A,row:N,column:H}}}),l.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,id:A}})),$&&l.push({id:I.AddHyperLinkMutation.id,params:{unitId:r.unitId,subUnitId:r.subUnitId,link:$}})})}),{redos:u,undos:l}}};exports.SheetsHyperLinkCopyPasteController=ln([Ee(0,E.ISheetClipboardService),Ee(1,s.Inject(I.HyperLinkModel)),Ee(2,s.Inject(s.Injector)),Ee(3,s.Inject(exports.SheetsHyperLinkResolverService))],exports.SheetsHyperLinkCopyPasteController);const Xe=(t,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var i;const e=t.get(s.IUniverInstanceService),r=(i=t.get(_e.IRenderManagerService).getRenderById(n))==null?void 0:i.with(Q.DocSelectionRenderService);return r?r.textSelectionInner$.pipe(D.map(()=>{const a=t.get(E.IEditorBridgeService).getEditCellState();if(!a)return!0;const u=C.getSheetCommandTarget(e,{unitId:a.unitId,subUnitId:a.sheetId});return!(u!=null&&u.worksheet)||ze(t,u.worksheet,a.row,a.column)===1?!0:cn(t)})):D.of(!0)},wt=t=>{var i;const n=t.get(s.IUniverInstanceService),e=t.has(E.IEditorBridgeService)?t.get(E.IEditorBridgeService):null;return((i=e==null?void 0:e.currentEditCellState$.pipe(D.map(o=>{if(!o)return me.DISABLED_BY_CELL;const a=C.getSheetCommandTarget(n,{unitId:o.unitId,subUnitId:o.sheetId});return a?ze(t,a.worksheet,o.row,o.column):me.DISABLED_BY_CELL}),D.switchMap(o=>{if(o===me.DISABLED_BY_CELL)return D.of(!0);const a=e?e.visible$:D.of(null);return D.combineLatest([a,n.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC)]).pipe(D.switchMap(([u,l])=>u!=null&&u.visible?(l==null?void 0:l.getUnitId())===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?D.of(!0):Xe(t,s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY):D.of(o!==me.ALLOWED)))})))!=null?i:D.of(!0)).pipe(D.switchMap(o=>o?D.of(!0):E.getCurrentRangeDisable$(t,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetSetCellValuePermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},!0)))},ke={commandId:je.id,type:S.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkIcon"},we=t=>`${t}-zen-editor`,dn=t=>({...ke,id:ke.commandId,hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:wt(t)}),pn=t=>({...ke,id:we(ke.commandId),hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Xe(t)}),be={tooltip:"hyperLink.form.addTitle",commandId:ie.id,type:S.MenuItemType.BUTTON,icon:"LinkIcon"},hn=t=>({...be,id:be.commandId,hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:wt(t)}),gn=t=>({...be,id:we(be.commandId),hidden$:S.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Xe(t)}),Je={id:ie.id,binding:S.KeyCode.K|S.MetaKeys.CTRL_COMMAND,preconditions:E.whenSheetEditorFocused};var vn=Object.getOwnPropertyDescriptor,mn=(t,n,e,r)=>{for(var i=r>1?void 0:r?vn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},yt=(t,n)=>(e,r)=>n(e,r,t);let De=class extends s.Disposable{constructor(t,n){super(),this._autoFillService=t,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const t=()=>({redos:[],undos:[]}),n=(r,i)=>{const{source:o,target:a,unitId:u,subUnitId:l}=r,h=E.virtualizeDiscreteRanges([o,a]),[d,p]=h.ranges,{mapFunc:m}=h,v={row:d.startRow,col:d.startColumn},R=E.getAutoFillRepeatRange(d,p),P=[],L=[];return R.forEach(c=>{const k=c.repeatStartCell,M=c.relativeRange,N={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},H={startRow:k.row,startColumn:k.col,endColumn:k.col,endRow:k.row};s.Range.foreach(M,($,A)=>{const Y=s.Rectangle.getPositionRange({startRow:$,startColumn:A,endColumn:A,endRow:$},N),{row:ee,col:ye}=m(Y.startRow,Y.startColumn),te=this._hyperLinkModel.getHyperLinkByLocation(u,l,ee,ye),le=s.Rectangle.getPositionRange({startRow:$,startColumn:A,endColumn:A,endRow:$},H),{row:de,col:pe}=m(le.startRow,le.startColumn),fe=s.generateRandomId(),oe=this._hyperLinkModel.getHyperLinkByLocation(u,l,de,pe);oe&&P.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:oe.id}}),(E.APPLY_TYPE.COPY===i||E.APPLY_TYPE.SERIES===i)&&te&&(P.push({id:I.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:{...te,id:fe,row:de,column:pe}}}),L.push({id:I.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:fe}})),oe&&L.push({id:I.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:oe}})})}),{undos:L,redos:P}},e={id:qe,onFillData:(r,i,o)=>o===E.APPLY_TYPE.COPY||o===E.APPLY_TYPE.ONLY_FORMAT||o===E.APPLY_TYPE.SERIES?n(r,o):t()};this.disposeWithMe(this._autoFillService.addHook(e))}};De=mn([yt(0,E.IAutoFillService),yt(1,s.Inject(I.HyperLinkModel))],De);var In=Object.getOwnPropertyDescriptor,Sn=(t,n,e,r)=>{for(var i=r>1?void 0:r?In(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ze=(t,n)=>(e,r)=>n(e,r,t);let Oe=class extends s.Disposable{constructor(t,n,e){super(),this._localeService=t,this._commandService=n,this._sheetPermissionCheckController=e,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Je.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")))}))}};Oe=Sn([Ze(0,s.Inject(s.LocaleService)),Ze(1,s.ICommandService),Ze(2,s.Inject(C.SheetPermissionCheckController))],Oe);var _n=Object.getOwnPropertyDescriptor,yn=(t,n,e,r)=>{for(var i=r>1?void 0:r?_n(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},W=(t,n)=>(e,r)=>n(e,r,t);let Ne=class extends s.Disposable{constructor(t,n,e,r,i,o,a,u,l,h){super(),this._hoverManagerService=t,this._sheetsHyperLinkPopupService=n,this._renderManagerService=e,this._permissionService=r,this._sheetPermissionCheckController=i,this._commandService=o,this._editorBridgeService=a,this._textSelectionManagerService=u,this._univerInstanceService=l,this._zenZoneService=h,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(t){const{unitId:n,subUnitId:e,row:r,col:i}=t,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),a=o==null?void 0:o.getSheetBySheetId(e);if(!a)return{viewPermission:!1,editPermission:!1,copyPermission:!1};const u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookViewPermission],worksheetTypes:[C.WorksheetViewPermission],rangeTypes:[C.RangeProtectionPermissionViewPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],n,e);let l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission,C.WorksheetInsertHyperlinkPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]},[{startRow:r,startColumn:i,endRow:r,endColumn:i}],n,e);const h=a.getCellRaw(r,i);h!=null&&h.f&&h.f.startsWith("=HYPERLINK(")&&(l=!1);const d=this._permissionService.composePermission([new C.WorkbookCopyPermission(n).id,new C.WorksheetCopyPermission(n,e).id]).every(p=>p.value);return{viewPermission:u,editPermission:l,copyPermission:d}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(D.debounceTime(200)).subscribe(t=>{var N,H,$;if(!t||((N=t.customRange)==null?void 0:N.rangeType)!==s.CustomRangeType.HYPERLINK){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:e,row:r,col:i}=t,o=this._renderManagerService.getRenderById(n);if(!o)return;const a=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(e);if(!u)return;if(!o.with(E.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING);return}const h=(H=o==null?void 0:o.with(E.SheetSkeletonManagerService).getSkeletonParam(e))==null?void 0:H.skeleton,d=i,p=r;let m=p,v=d;h&&h.overflowCache.forValue((A,Y,ee)=>{s.Rectangle.contains(ee,{startColumn:d,endColumn:d,startRow:p,endRow:p})&&(m=A,v=Y)});const{viewPermission:R,editPermission:P,copyPermission:L}=this._getLinkPermission(t);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=u.getCellStyleOnly(m,v),k=a.getStyles().getStyleByCell(c),M=($=k==null?void 0:k.tr)==null?void 0:$.a;if(!M&&!t.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:m,col:v,editPermission:P,copyPermission:L,customRange:t.customRange,customRangeRect:t.rect,type:y.VIEWING,unitId:n,subUnitId:e,showAll:!!M})}))}_initHoverEditingListener(){let t=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(D.switchMap(n=>this._editorBridgeService.visible$.pipe(D.map(e=>({visible:e,state:n}))))).subscribe(({visible:n,state:e})=>{if(!e||e.editorUnitId!==s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){t==null||t.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING);return}const{editorUnitId:r,unitId:i,sheetId:o,row:a,column:u}=e,l=this._renderManagerService.getRenderById(r);if(!l)return;const{editPermission:h,viewPermission:d,copyPermission:p}=this._getLinkPermission({unitId:i,subUnitId:o,row:a,col:u}),m=l.with(Q.DocEventManagerService);d&&(t==null||t.unsubscribe(),t=m.hoverCustomRanges$.pipe(D.debounceTime(200)).subscribe(v=>{var k,M;const R=v.find(N=>N.range.rangeType===s.CustomRangeType.HYPERLINK);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const P=R.rects[R.rects.length-1];if(!((M=(k=this._renderManagerService.getRenderById(i))==null?void 0:k.with(E.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:M.skeleton)||!P)return;const c=l.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:i,subUnitId:o,row:a,col:u,customRange:R.range,customRangeRect:{left:P.left+c.left,top:P.top+c.top,bottom:P.bottom+c.top,right:P.right+c.left},editPermission:h,copyPermission:p,type:y.EDITING})}))})),this.disposeWithMe(()=>{t==null||t.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t?(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(D.switchMap(t=>{const n=t===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(t):null;return n?n.with(Q.DocEventManagerService).hoverCustomRanges$.pipe(D.debounceTime(200)):new D.Observable(e=>{e.next(null)})})).subscribe(t=>{const n=t==null?void 0:t.find(r=>r.range.rangeType===s.CustomRangeType.HYPERLINK),e=this._editorBridgeService.getEditCellState();if(n&&e){const{unitId:r,sheetId:i,row:o,column:a}=e,{editPermission:u,viewPermission:l,copyPermission:h}=this._getLinkPermission({unitId:r,subUnitId:i,row:o,col:a});l&&this._sheetsHyperLinkPopupService.showPopup({type:y.ZEN_EDITOR,unitId:r,subUnitId:i,row:o,col:a,customRange:n.range,editPermission:u,copyPermission:h})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(t=>{t&&t.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(y.EDITING)}))}_initCommandListener(){const t=[C.ClearSelectionContentCommand.id,C.ClearSelectionAllCommand.id,C.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{t.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ne=yn([W(0,s.Inject(E.HoverManagerService)),W(1,s.Inject(exports.SheetsHyperLinkPopupService)),W(2,s.Inject(_e.IRenderManagerService)),W(3,s.Inject(s.IPermissionService)),W(4,s.Inject(C.SheetPermissionCheckController)),W(5,s.ICommandService),W(6,E.IEditorBridgeService),W(7,s.Inject(Ie.DocSelectionManagerService)),W(8,s.IUniverInstanceService),W(9,S.IZenZoneService)],Ne);var fn=Object.getOwnPropertyDescriptor,bt=(t,n,e,r)=>{for(var i=r>1?void 0:r?fn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ke=(t,n)=>(e,r)=>n(e,r,t);let We=class extends s.Disposable{constructor(t,n){super(),this._context=t,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const t=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(D.debounceTime(16)).subscribe(()=>{t()}))}};We=bt([Ke(1,s.Inject(I.HyperLinkModel))],We);let He=class extends s.Disposable{constructor(t,n){super(),this._sheetInterceptorService=t,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(t,n,e)=>{const{row:r,col:i,unitId:o,subUnitId:a}=n,u=this._hyperLinkModel.getHyperLinkByLocation(o,a,r,i);return u&&t&&(t===n.rawData&&(t={...n.rawData}),t.linkUrl=u.payload,t.linkId=u.id),e(t)}}))}};He=bt([Ke(0,s.Inject(C.SheetInterceptorService)),Ke(1,s.Inject(I.HyperLinkModel))],He);const Cn={[S.RibbonInsertGroup.MEDIA]:{[ie.id]:{order:1,menuItemFactory:hn},[we(ie.id)]:{order:1,menuItemFactory:gn}},[S.ContextMenuPosition.MAIN_AREA]:{[S.ContextMenuGroup.OTHERS]:{order:1,[ie.id]:{order:0,menuItemFactory:dn},[we(ie.id)]:{order:0,menuItemFactory:pn}}}};var En=Object.getOwnPropertyDescriptor,Rn=(t,n,e,r)=>{for(var i=r>1?void 0:r?En(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ve=(t,n)=>(e,r)=>n(e,r,t);let xe=class extends s.Disposable{constructor(t,n,e,r,i){super(),this._componentManager=t,this._commandService=n,this._menuManagerService=e,this._injector=r,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Te.componentKey,Te],[Pe.componentKey,Pe],["LinkIcon",Ge]].forEach(([t,n])=>{this._componentManager.register(t,n)})}_initCommands(){[Me,Se,je,ie].forEach(t=>{this._commandService.registerCommand(t)})}_initMenus(){this._menuManagerService.mergeMenu(Cn)}_initShortCut(){this._shortcutService.registerShortcut(Je)}};xe=Rn([ve(0,s.Inject(S.ComponentManager)),ve(1,s.ICommandService),ve(2,S.IMenuManagerService),ve(3,s.Inject(s.Injector)),ve(4,s.Inject(S.IShortcutService))],xe);var Ln=Object.getOwnPropertyDescriptor,Pn=(t,n,e,r)=>{for(var i=r>1?void 0:r?Ln(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},ft=(t,n)=>(e,r)=>n(e,r,t);let Ue=class extends s.Disposable{constructor(t,n){super(),this._parserService=t,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const t=location.hash;if(t){const n=this._parserService.parseHyperLink(t);this._resolverService.navigate(n)}}};Ue=Pn([ft(0,s.Inject(I.SheetsHyperLinkParserService)),ft(1,s.Inject(exports.SheetsHyperLinkResolverService))],Ue);var Tn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,wn=(t,n,e)=>n in t?Tn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,bn=(t,n,e,r)=>{for(var i=r>1?void 0:r?kn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(i=a(i)||i);return i},Ct=(t,n)=>(e,r)=>n(e,r,t),Dt=(t,n,e)=>wn(t,typeof n!="symbol"?n+"":n,e);exports.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=It,e,r){super(),this._config=n,this._injector=e,this._configService=r;const{menu:i,...o}=s.merge({},It,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Et,o)}onStarting(){[[exports.SheetsHyperLinkResolverService],[exports.SheetsHyperLinkPopupService],[Ye],[He],[Ne],[xe],[De],[exports.SheetsHyperLinkCopyPasteController],[Oe],[Ue]].forEach(e=>this._injector.add(e)),this._injector.get(He)}onReady(){this._injector.get(_e.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[We]),this._injector.get(De),this._injector.get(exports.SheetsHyperLinkCopyPasteController),this._injector.get(xe)}onRendered(){this._injector.get(Oe),this._injector.get(Ue),this._injector.get(Ne)}};Dt(exports.UniverSheetsHyperLinkUIPlugin,"pluginName",qe);Dt(exports.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkUIPlugin=bn([s.DependentOn(I.UniverSheetsHyperLinkPlugin,Q.UniverDocsUIPlugin),Ct(1,s.Inject(s.Injector)),Ct(2,s.IConfigService)],exports.UniverSheetsHyperLinkUIPlugin);exports.CloseHyperLinkPopupOperation=Se;exports.InsertHyperLinkOperation=je;exports.InsertLinkShortcut=Je;exports.OpenHyperLinkEditPanelOperation=Me;exports.SheetsHyperLinkSidePanelService=Ye;
package/lib/es/index.js CHANGED
@@ -3,7 +3,7 @@ var Jn = (t, e, n) => e in t ? qn(t, e, { enumerable: !0, configurable: !0, writ
3
3
  var A = (t, e, n) => Jn(t, typeof e != "symbol" ? e + "" : e, n);
4
4
  import { Tools as Fe, IUniverInstanceService as G, ICommandService as te, Inject as y, LocaleService as ct, IConfigService as Cn, UniverInstanceType as k, isValidRange as Sn, RANGE_TYPE as an, Rectangle as Ie, Disposable as K, IContextService as Qn, ThemeService as er, DataStreamTreeTokenType as cn, CustomRangeType as Te, BuildTextUtils as ve, ColorKit as tr, DOCS_ZEN_EDITOR_UNIT_ID_KEY as x, DisposableCollection as nr, FOCUSING_SHEET as It, generateRandomId as bt, Injector as ut, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as _e, DataValidationType as Ct, CommandType as lt, Range as yn, ObjectMatrix as rr, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ir, IPermissionService as sr, InterceptorEffectEnum as or, DependentOn as ar, Plugin as cr, merge as ur } from "@univerjs/core";
5
5
  import { SetSelectionsOperation as En, SetWorksheetActiveOperation as Rn, SheetsSelectionsService as kt, getSheetCommandTarget as Tt, rangeToDiscreteRange as lr, RangeProtectionPermissionEditPoint as Nt, WorksheetEditPermission as xt, WorksheetSetCellValuePermission as Pn, WorksheetInsertHyperlinkPermission as Ot, WorkbookEditablePermission as Mt, SheetPermissionCheckController as Ln, RangeProtectionPermissionViewPoint as dr, WorksheetViewPermission as pr, WorkbookViewPermission as hr, WorkbookCopyPermission as gr, WorksheetCopyPermission as mr, ClearSelectionContentCommand as vr, ClearSelectionAllCommand as fr, ClearSelectionFormatCommand as _r, SheetInterceptorService as Ir, INTERCEPTOR_POINT as Cr } from "@univerjs/sheets";
6
- import { ScrollToRangeOperation as wn, IEditorBridgeService as ee, IMarkSelectionService as Sr, SheetCanvasPopManagerService as yr, getEditingCustomRangePosition as Er, getCustomRangePosition as Rr, ISheetClipboardService as Pr, virtualizeDiscreteRanges as Rt, COPY_TYPE as Lr, PREDEFINED_HOOK_NAME as Ae, getRepeatRange as wr, whenSheetEditorFocused as br, getCurrentRangeDisable$ as kr, IAutoFillService as Tr, APPLY_TYPE as Le, getAutoFillRepeatRange as Nr, HoverManagerService as xr, HoverRenderController as Or, SheetSkeletonManagerService as un } from "@univerjs/sheets-ui";
6
+ import { ScrollToRangeOperation as wn, IEditorBridgeService as ee, IMarkSelectionService as Sr, SheetCanvasPopManagerService as yr, getEditingCustomRangePosition as Er, getCustomRangePosition as Rr, ISheetClipboardService as Pr, virtualizeDiscreteRanges as Rt, COPY_TYPE as Lr, PREDEFINED_HOOK_NAME_PASTE as Ae, getRepeatRange as wr, whenSheetEditorFocused as br, getCurrentRangeDisable$ as kr, IAutoFillService as Tr, APPLY_TYPE as Le, getAutoFillRepeatRange as Nr, HoverManagerService as xr, HoverRenderController as Or, SheetSkeletonManagerService as un } from "@univerjs/sheets-ui";
7
7
  import { DocSelectionManagerService as Me } from "@univerjs/docs";
8
8
  import { DocSelectionRenderService as bn, DocBackScrollRenderController as Mr, DocCanvasPopManagerService as Ur, calcDocRangePositions as Hr, DocEventManagerService as ln, UniverDocsUIPlugin as Dr } from "@univerjs/docs-ui";
9
9
  import { IRenderManagerService as Ue } from "@univerjs/engine-render";
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var Jn = (t, e, n) => e in t ? qn(t, e, { enumerable: !0, configurable: !0, writ
3
3
  var A = (t, e, n) => Jn(t, typeof e != "symbol" ? e + "" : e, n);
4
4
  import { Tools as Fe, IUniverInstanceService as G, ICommandService as te, Inject as y, LocaleService as ct, IConfigService as Cn, UniverInstanceType as k, isValidRange as Sn, RANGE_TYPE as an, Rectangle as Ie, Disposable as K, IContextService as Qn, ThemeService as er, DataStreamTreeTokenType as cn, CustomRangeType as Te, BuildTextUtils as ve, ColorKit as tr, DOCS_ZEN_EDITOR_UNIT_ID_KEY as x, DisposableCollection as nr, FOCUSING_SHEET as It, generateRandomId as bt, Injector as ut, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as _e, DataValidationType as Ct, CommandType as lt, Range as yn, ObjectMatrix as rr, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ir, IPermissionService as sr, InterceptorEffectEnum as or, DependentOn as ar, Plugin as cr, merge as ur } from "@univerjs/core";
5
5
  import { SetSelectionsOperation as En, SetWorksheetActiveOperation as Rn, SheetsSelectionsService as kt, getSheetCommandTarget as Tt, rangeToDiscreteRange as lr, RangeProtectionPermissionEditPoint as Nt, WorksheetEditPermission as xt, WorksheetSetCellValuePermission as Pn, WorksheetInsertHyperlinkPermission as Ot, WorkbookEditablePermission as Mt, SheetPermissionCheckController as Ln, RangeProtectionPermissionViewPoint as dr, WorksheetViewPermission as pr, WorkbookViewPermission as hr, WorkbookCopyPermission as gr, WorksheetCopyPermission as mr, ClearSelectionContentCommand as vr, ClearSelectionAllCommand as fr, ClearSelectionFormatCommand as _r, SheetInterceptorService as Ir, INTERCEPTOR_POINT as Cr } from "@univerjs/sheets";
6
- import { ScrollToRangeOperation as wn, IEditorBridgeService as ee, IMarkSelectionService as Sr, SheetCanvasPopManagerService as yr, getEditingCustomRangePosition as Er, getCustomRangePosition as Rr, ISheetClipboardService as Pr, virtualizeDiscreteRanges as Rt, COPY_TYPE as Lr, PREDEFINED_HOOK_NAME as Ae, getRepeatRange as wr, whenSheetEditorFocused as br, getCurrentRangeDisable$ as kr, IAutoFillService as Tr, APPLY_TYPE as Le, getAutoFillRepeatRange as Nr, HoverManagerService as xr, HoverRenderController as Or, SheetSkeletonManagerService as un } from "@univerjs/sheets-ui";
6
+ import { ScrollToRangeOperation as wn, IEditorBridgeService as ee, IMarkSelectionService as Sr, SheetCanvasPopManagerService as yr, getEditingCustomRangePosition as Er, getCustomRangePosition as Rr, ISheetClipboardService as Pr, virtualizeDiscreteRanges as Rt, COPY_TYPE as Lr, PREDEFINED_HOOK_NAME_PASTE as Ae, getRepeatRange as wr, whenSheetEditorFocused as br, getCurrentRangeDisable$ as kr, IAutoFillService as Tr, APPLY_TYPE as Le, getAutoFillRepeatRange as Nr, HoverManagerService as xr, HoverRenderController as Or, SheetSkeletonManagerService as un } from "@univerjs/sheets-ui";
7
7
  import { DocSelectionManagerService as Me } from "@univerjs/docs";
8
8
  import { DocSelectionRenderService as bn, DocBackScrollRenderController as Mr, DocCanvasPopManagerService as Ur, calcDocRangePositions as Hr, DocEventManagerService as ln, UniverDocsUIPlugin as Dr } from "@univerjs/docs-ui";
9
9
  import { IRenderManagerService as Ue } from "@univerjs/engine-render";
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(g,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui"),require("@univerjs/sheets-hyper-link"),require("react"),require("@univerjs/sheets-data-validation")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-ui","@univerjs/docs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","@univerjs/design","@univerjs/engine-formula","@univerjs/sheets-formula-ui","@univerjs/sheets-hyper-link","react","@univerjs/sheets-data-validation"],s):(g=typeof globalThis<"u"?globalThis:g||self,s(g.UniverSheetsHyperLinkUi={},g.UniverCore,g.UniverSheets,g.UniverSheetsUi,g.UniverDocs,g.UniverDocsUi,g.UniverEngineRender,g.UniverUi,g.rxjs,g.React,g.UniverDesign,g.UniverEngineFormula,g.UniverSheetsFormulaUi,g.UniverSheetsHyperLink,g.React,g.UniverSheetsDataValidation))})(this,(function(g,s,f,E,de,X,pe,m,O,y,L,G,Nt,_,R,et){"use strict";var bn=Object.defineProperty;var kn=(g,s,f)=>s in g?bn(g,s,{enumerable:!0,configurable:!0,writable:!0,value:f}):g[s]=f;var Z=(g,s,f)=>kn(g,typeof s!="symbol"?s+"":s,f);var C=(t=>(t.EDITING="editing",t.VIEWING="viewing",t.ZEN_EDITOR="zen_mode",t))(C||{});function ye(t){return s.Tools.isLegalUrl(t)}function Mt(t){return/^[a-zA-Z]+:\/\//.test(t)}function Ut(t){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(t)}function Ht(t){if(ye(t)){const n=Mt(t)?t:Ut(t)?`mailto://${t}`:`http://${t}`;let e;try{e=new URL(n)}catch{return t}return e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol&&e.pathname===location.pathname&&e.hash&&!e.search?e.hash:n}return t}const tt="sheets-hyper-link-ui.config",nt={};var xt=Object.getOwnPropertyDescriptor,At=(t,n,e,i)=>{for(var r=i>1?void 0:i?xt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ae=(t,n)=>(e,i)=>n(e,i,t);function $t(t,n){const e=n.getMergeData(),i=n.getMaxColumns()-1,r=n.getMaxRows()-1;if(i<t.endColumn&&(t.endColumn=i),r<t.endRow&&(t.endRow=r),t.rangeType===s.RANGE_TYPE.COLUMN||s.RANGE_TYPE.ROW)return t;const o=[];return e.forEach(a=>{s.Rectangle.intersects(t,a)&&o.push(a)}),s.Rectangle.realUnion(t,...o)}g.SheetsHyperLinkResolverService=class{constructor(n,e,i,r,o,a){this._univerInstanceService=n,this._commandService=e,this._definedNamesService=i,this._messageService=r,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:e,range:i,rangeid:r}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const a=o.getUnitId();if(r){const u=this._definedNamesService.getValueById(a,r);if(!u)return;const{formulaOrRefString:l}=u,h=this._definedNamesService.getWorksheetByRef(a,l);if(!h){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:L.MessageType.Error});return}if(h.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:L.MessageType.Error});return}this.navigateToDefineName(a,r)}if(e){if(i){const u=G.deserializeRangeWithSheet(i);s.isValidRange(u.range)&&i!==_.ERROR_RANGE&&this.navigateToRange(a,e,u.range);return}this.navigateToSheetById(a,e)}}async navigateToRange(n,e,i,r){const o=await this.navigateToSheetById(n,e);if(o){const a=$t(i,o);await this._commandService.executeCommand(f.SetSelectionsOperation.id,{unitId:n,subUnitId:e,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:a,forceTop:r})}}async navigateToSheetById(n,e){const i=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!i)return!1;const r=i.getActiveSheet();if(!r)return!1;if(r.getSheetId()===e)return r;const o=i.getSheetBySheetId(e);return o?i.getHiddenWorksheets().indexOf(e)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:L.MessageType.Error}),!1):await this._commandService.executeCommand(f.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:e})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:L.MessageType.Error}),!1)}async navigateToDefineName(n,e){return this._definedNamesService.focusRange(n,e),!0}async navigateToOtherWebsite(n){var i;const e=this._configService.getConfig(tt);if((i=e==null?void 0:e.urlHandler)!=null&&i.navigateToOtherWebsite)return e.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}},g.SheetsHyperLinkResolverService=At([ae(0,s.IUniverInstanceService),ae(1,s.ICommandService),ae(2,G.IDefinedNamesService),ae(3,m.IMessageService),ae(4,s.Inject(s.LocaleService)),ae(5,s.IConfigService)],g.SheetsHyperLinkResolverService);class Be extends s.Disposable{constructor(){super(...arguments);Z(this,"_customHyperLinks",new Map)}isBuiltInLinkType(e){return e!==_.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:e})=>e)}findCustomHyperLink(e){return Array.from(this._customHyperLinks.values()).find(r=>r.match(e))}registerCustomHyperLink(e){this._customHyperLinks.set(e.type,e)}getCustomHyperLink(e){return this._customHyperLinks.get(e)}removeCustomHyperLink(e){const{_customHyperLinks:i}=this;i.delete(e)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const Ce=()=>{var _t;const[t,n]=R.useState(""),[e,i]=R.useState(!1),[r,o]=R.useState(""),[a,u]=R.useState(!0),[l,h]=R.useState(_.SheetHyperLinkType.URL),[d,p]=R.useState(""),S=m.useDependency(s.LocaleService),I=m.useDependency(G.IDefinedNamesService),P=m.useDependency(E.IEditorBridgeService),w=m.useDependency(s.IUniverInstanceService),T=m.useDependency(g.SheetsHyperLinkPopupService),c=m.useObservable(T.currentEditing$),D=m.useDependency(_.SheetsHyperLinkParserService),A=m.useDependency(g.SheetsHyperLinkResolverService),M=m.useDependency(s.ICommandService),U=m.useDependency(Be),V=R.useMemo(()=>U.getOptions(),[U]),B=m.useDependency(m.IZenZoneService),z=m.useDependency(pe.IRenderManagerService),re=m.useDependency(E.IMarkSelectionService),xe=m.useDependency(de.DocSelectionManagerService),se=m.useDependency(s.IContextService),Ie=m.useDependency(s.ThemeService),Se=m.useDependency(de.DocSelectionManagerService),[_e,Ae]=R.useState(!1),ce=m.useDependency(f.SheetsSelectionsService),Rn=R.useMemo(()=>ce.getCurrentSelections(),[]),$e=R.useMemo(()=>{if(!U.isBuiltInLinkType(l))return U.getCustomHyperLink(l)},[U,l]),[ue,Pn]=R.useState(!1),[me,It]=R.useState(!1),j=R.useRef(!1),K=w.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),Tn=(K==null?void 0:K.getActiveSheet().getSheetId())||"",J=R.useCallback(v=>{o(v.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);R.useEffect(()=>{var v,b,k,N,x,W,mt,ft,yt,Ct,Et,Rt,Pt,Tt,Lt,wt,Dt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:oe,row:Je,col:Qe}=c;let{label:q}=c;typeof q=="number"&&(q=`${q}`);let Y;if(oe)Y={id:(v=oe==null?void 0:oe.rangeId)!=null?v:"",display:q!=null?q:"",payload:(k=(b=oe==null?void 0:oe.properties)==null?void 0:b.url)!=null?k:"",row:Je,column:Qe};else if(c.type===C.VIEWING){const H=w.getUnit(c.unitId),ee=H==null?void 0:H.getSheetBySheetId(c.subUnitId),$=ee==null?void 0:ee.getCellRaw(c.row,c.col),le=(W=(x=(N=$==null?void 0:$.p)==null?void 0:N.body)==null?void 0:x.customRanges)==null?void 0:W.find(kt=>{var Ot;return kt.rangeType===s.CustomRangeType.HYPERLINK&&((Ot=kt.properties)==null?void 0:Ot.url)}),fe=$==null?void 0:$.v;$&&(!s.BuildTextUtils.transform.isEmptyDocument((ft=(mt=$.p)==null?void 0:mt.body)==null?void 0:ft.dataStream)||s.Tools.isDefine(fe))&&u(!1),Y={id:"",display:"",payload:(Ct=(yt=le==null?void 0:le.properties)==null?void 0:yt.url)!=null?Ct:"",row:Je,column:Qe}}else{const H=w.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),ee=xe.getActiveTextRange(),$=H==null?void 0:H.getBody(),le=ee&&$?ee:null,fe=le&&((Rt=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(Et=$==null?void 0:$.customRanges)!=null?Et:[]))==null?void 0:Rt[0]);u(!1),Y={id:"",display:q!=null?q:"",payload:(Tt=(Pt=fe==null?void 0:fe.properties)==null?void 0:Pt.url)!=null?Tt:"",row:Je,column:Qe}}n(Y.id);const bt=U.findCustomHyperLink(Y);if(bt){const H=bt.convert(Y);h(H.type),p(H.payload),J(H.display);return}J(Y.display);const Q=D.parseHyperLink(Y.payload);switch(h(Q.type===_.SheetHyperLinkType.INVALID?_.SheetHyperLinkType.RANGE:Q.type),Q.type){case _.SheetHyperLinkType.URL:{p(Q.url),Q.url===Y.display&&(j.current=!0);break}case _.SheetHyperLinkType.RANGE:{const H=Q.searchObj,ee=H.gid&&(Dt=(wt=(Lt=w.getUnit(c.unitId))==null?void 0:Lt.getSheetBySheetId(H.gid))==null?void 0:wt.getName())!=null?Dt:"",$=G.serializeRangeWithSheet(ee,G.deserializeRangeWithSheet(H.range).range);p($),$===Y.display&&(j.current=!0);break}case _.SheetHyperLinkType.SHEET:{const H=Q.searchObj;p(H.gid);break}case _.SheetHyperLinkType.DEFINE_NAME:{const H=Q.searchObj;p(H.rangeid);break}default:p("");break}}},[c,A,U,xe,w]),R.useEffect(()=>{let v=null;if(c&&!c.customRangeId&&c.type===C.VIEWING&&s.Tools.isDefine(c.row)&&s.Tools.isDefine(c.col)){const b=w.getUnit(c.unitId,s.UniverInstanceType.UNIVER_SHEET),k=b==null?void 0:b.getSheetBySheetId(c.subUnitId),N=k==null?void 0:k.getMergedCell(c.row,c.col),x=new s.ColorKit(Ie.getColorFromTheme("primary.600")).toRgb();v=re.addShape({range:N!=null?N:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${x.r}, ${x.g}, ${x.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{v&&re.removeShape(v)}},[c,re,Ie,w]),R.useEffect(()=>{It(l===_.SheetHyperLinkType.RANGE)},[l]),R.useEffect(()=>{const v=(c==null?void 0:c.type)===C.ZEN_EDITOR?z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):z.getRenderById(P.getCurrentEditorId()),b=new s.DisposableCollection;if(v){const k=v.with(X.DocSelectionRenderService);k.setReserveRangesStatus(!0),b.add(()=>{k.setReserveRangesStatus(!1)})}return()=>{P.disableForceKeepVisible(),b.dispose()}},[c==null?void 0:c.type,P,z]),R.useEffect(()=>(me&&T.setIsKeepVisible(me),T.setIsKeepVisible(_e),()=>{T.setIsKeepVisible(!1)}),[me,_e,T]),R.useEffect(()=>()=>{B.temporaryHidden&&(B.show(),se.setContextValue(s.FOCUSING_SHEET,!1))},[se,B]),R.useEffect(()=>{if(me)return P.enableForceKeepVisible(),()=>{P.disableForceKeepVisible()}},[me,P]);const Ln=[{label:S.t("hyperLink.form.link"),value:_.SheetHyperLinkType.URL},{label:S.t("hyperLink.form.range"),value:_.SheetHyperLinkType.RANGE},{label:S.t("hyperLink.form.worksheet"),value:_.SheetHyperLinkType.SHEET},{label:S.t("hyperLink.form.definedName"),value:_.SheetHyperLinkType.DEFINE_NAME},...V];if(!K)return;const wn=K.getHiddenWorksheets(),ze=K.getSheets().map(v=>({label:v.getName(),value:v.getSheetId()})).filter(v=>wn.indexOf(v.value)===-1),qe=Object.values((_t=I.getDefinedNameMap(K.getUnitId()))!=null?_t:{}).map(v=>({label:v.name,value:v.id})),St=(v,b)=>{if(v===_.SheetHyperLinkType.URL)return Ht(b);if(v===_.SheetHyperLinkType.RANGE){const k=G.deserializeRangeWithSheet(b),N=K.getSheetBySheetName(k.sheetName);if(N)return`#gid=${N.getSheetId()}&range=${G.serializeRange(k.range)}`}return`#${v}=${b}`},Dn=m.useEvent(v=>{var x;const k=v.split(",").map(G.deserializeRangeWithSheet)[0];if(!k||!s.isValidRange(k.range))return;k.sheetName||(k.sheetName=((x=K.getActiveSheet())==null?void 0:x.getName())||"");const N=G.serializeRangeToRefString(k);p(N),N&&(j.current||!r)&&(J(N),j.current=!0)}),Xe=async()=>{if(a&&!r||!d||l===_.SheetHyperLinkType.URL&&!ye(d)){Pn(!0);return}if(c)if(t){const v=c.type===C.ZEN_EDITOR||c.type===C.EDITING?_.UpdateRichHyperLinkCommand.id:_.UpdateHyperLinkCommand.id;await M.executeCommand(v,{id:t,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?r:"",payload:St(l,d)},row:c.row,column:c.col,documentId:c.type===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:P.getCurrentEditorId()})}else{const v=c.type===C.ZEN_EDITOR||c.type===C.EDITING?_.AddRichHyperLinkCommand.id:_.AddHyperLinkCommand.id;await M.executeCommand(v,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:s.generateRandomId(),row:c.row,column:c.col,payload:St(l,d),display:a?r:""},documentId:c.type===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:P.getCurrentEditorId()})}if((c==null?void 0:c.type)===C.VIEWING){await M.executeCommand(f.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const v=1;await M.executeCommand(E.ScrollToRangeOperation.id,{range:{startRow:Math.max(c.row-v,0),endRow:c.row+v,startColumn:Math.max(c.col-v,0),endColumn:c.col+v}})}M.executeCommand(ve.id)};return c?y.jsxs("div",{className:L.clsx("univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900",L.borderClassName),children:[a?y.jsx(L.FormLayout,{label:S.t("hyperLink.form.label"),error:ue&&!r?S.t("hyperLink.form.inputError"):"",children:y.jsx(L.Input,{value:r,onChange:v=>{J(v),j.current=!1},placeholder:S.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===m.KeyCode.ENTER&&Xe()}})}):null,y.jsx(L.FormLayout,{label:S.t("hyperLink.form.type"),children:y.jsx(L.Select,{className:"univer-w-full",options:Ln,value:l,onChange:v=>{h(v),p("")}})}),l===_.SheetHyperLinkType.URL&&y.jsx(L.FormLayout,{error:ue?d?ye(d)?"":S.t("hyperLink.form.linkError"):S.t("hyperLink.form.inputError"):"",children:y.jsx(L.Input,{value:d,onChange:v=>{p(v),v&&(j.current||!r||r===v)&&(J(v),j.current=!0)},placeholder:S.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===m.KeyCode.ENTER&&Xe()}})}),l===_.SheetHyperLinkType.RANGE&&y.jsx(L.FormLayout,{error:ue&&!d?S.t("hyperLink.form.inputError"):"",children:y.jsx(Nt.RangeSelector,{unitId:K.getUnitId(),subUnitId:Tn,maxRangeCount:1,supportAcrossSheet:!0,initialValue:d,resetRange:Rn,onChange:(v,b)=>Dn(b),onRangeSelectorDialogVisibleChange:async v=>{var b,k;if(Ae(v),v)c.type===C.ZEN_EDITOR&&(B.hide(),se.setContextValue(s.FOCUSING_SHEET,!0)),c.type!==C.VIEWING&&P.enableForceKeepVisible(),i(!0);else{if(await A.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===C.ZEN_EDITOR){await M.executeCommand(f.SetSelectionsOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId,selections:[{range:{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col}}]}),B.show(),se.setContextValue(s.FOCUSING_SHEET,!1);const N=(b=z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(X.DocBackScrollRenderController),x=(k=Se.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:k[0];N&&x&&(N.scrollToRange(x),Se.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}P.disableForceKeepVisible(),i(!1)}},onFocusChange:v=>It(v)})}),l===_.SheetHyperLinkType.SHEET&&y.jsx(L.FormLayout,{error:ue&&!d?S.t("hyperLink.form.selectError"):"",children:y.jsx(L.Select,{className:"univer-w-full",options:ze,value:d,onChange:v=>{var N,x;p(v);const b=(N=ze.find(W=>W.value===v))==null?void 0:N.label,k=(x=ze.find(W=>W.value===d))==null?void 0:x.label;b&&(j.current||!r||r===k)&&(J(b),j.current=!0)}})}),l===_.SheetHyperLinkType.DEFINE_NAME&&y.jsx(L.FormLayout,{error:ue&&!d?S.t("hyperLink.form.selectError"):"",children:y.jsx(L.Select,{className:"univer-w-full",options:qe,value:d,onChange:v=>{var N,x;p(v);const b=(N=qe.find(W=>W.value===v))==null?void 0:N.label,k=(x=qe.find(W=>W.value===d))==null?void 0:x.label;b&&(j.current||!r||r===k)&&(J(b),j.current=!0)}})}),($e==null?void 0:$e.Form)&&y.jsx($e.Form,{linkId:t,payload:d,display:r,showError:ue,setByPayload:j,setDisplay:v=>{J(v),j.current=!0},setPayload:p}),y.jsxs("div",{className:"univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[y.jsx(L.Button,{onClick:()=>{c&&A.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),M.executeCommand(ve.id)},children:S.t("hyperLink.form.cancel")}),y.jsx(L.Button,{variant:"primary",onClick:async()=>{Xe()},children:S.t("hyperLink.form.ok")})]})]}):null};Ce.componentKey="univer.sheet.cell-link-edit";function te({ref:t,...n}){const{icon:e,id:i,className:r,extend:o,...a}=n,u=`univerjs-icon univerjs-icon-${i} ${r||""}`.trim(),l=R.useRef(`_${jt()}`);return it(e,`${i}`,{defIds:e.defIds,idSuffix:l.current},{ref:t,className:u,...a},o)}function it(t,n,e,i,r){return R.createElement(t.tag,{key:n,...Bt(t,e,r),...i},(Vt(t,e).children||[]).map((o,a)=>it(o,`${n}-${t.tag}-${a}`,e,void 0,r)))}function Bt(t,n,e){const i={...t.attrs};e!=null&&e.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=e.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+n.idSuffix),Object.entries(i).forEach(([o,a])=>{o==="mask"&&typeof a=="string"&&(i[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))});const{defIds:r}=n;return!r||r.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(([o,a])=>{typeof a=="string"&&(i[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))})),i}function Vt(t,n){var i;const{defIds:e}=n;return!e||e.length===0?t:t.tag==="defs"&&((i=t.children)!=null&&i.length)?{...t,children:t.children.map(r=>typeof r.attrs.id=="string"&&e&&e.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+n.idSuffix}}:r)}:t}function jt(){return Math.random().toString(36).substring(2,8)}te.displayName="UniverIcon";const Zt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ee=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"all-border-icon",ref:e,icon:Zt}))});Ee.displayName="AllBorderIcon";const Ft={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},rt=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"copy-icon",ref:e,icon:Ft}))});rt.displayName="CopyIcon";const Kt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ve=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"link-icon",ref:e,icon:Kt}))});Ve.displayName="LinkIcon";const Wt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z"}}]},st=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"unlink-icon",ref:e,icon:Wt}))});st.displayName="UnlinkIcon";const Yt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"write-icon",ref:e,icon:Yt}))});ot.displayName="WriteIcon";const Gt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"white",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},at=R.forwardRef(function(n,e){return R.createElement(te,Object.assign({},n,{id:"xlsx-multi-icon",ref:e,icon:Gt}))});at.displayName="XlsxMultiIcon";const zt={[_.SheetHyperLinkType.URL]:y.jsx(Ve,{}),[_.SheetHyperLinkType.SHEET]:y.jsx(at,{className:"univer-text-green-500"}),[_.SheetHyperLinkType.RANGE]:y.jsx(Ee,{}),[_.SheetHyperLinkType.DEFINE_NAME]:y.jsx(Ee,{}),[_.SheetHyperLinkType.INVALID]:y.jsx(Ee,{})},ct=t=>{var A,M;const n=m.useDependency(g.SheetsHyperLinkPopupService),e=m.useDependency(s.ICommandService),i=m.useDependency(m.IMessageService),r=m.useDependency(s.LocaleService),o=m.useDependency(g.SheetsHyperLinkResolverService),a=m.useDependency(E.IEditorBridgeService),u=m.useDependency(_.SheetsHyperLinkParserService),l=m.useDependency(m.IZenZoneService),{customRange:h,row:d,col:p,unitId:S,subUnitId:I,editPermission:P,copyPermission:w,type:T}=t;if(!((A=h==null?void 0:h.properties)!=null&&A.url))return null;const c=u.parseHyperLink((M=h.properties.url)!=null?M:""),D=c.type===_.SheetHyperLinkType.INVALID;return y.jsxs("div",{className:L.clsx("univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900",L.borderClassName),onClick:()=>n.hideCurrentPopup(),children:[y.jsxs("div",{className:L.clsx("univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600",{"univer-text-red-500":D}),onClick:()=>{l.visible||D||o.navigate(c)},children:[y.jsx("div",{className:"univer-mr-2 univer-flex univer-h-5 univer-w-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:zt[c.type]}),y.jsx(L.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:y.jsx("span",{className:"univer-flex-1 univer-truncate",children:c.name})})]}),y.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center",children:[w&&y.jsx("div",{className:L.clsx("univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-red-500":D}),onClick:()=>{if(!D){if(c.type!==_.SheetHyperLinkType.URL){const U=new URL(window.location.href);U.hash=c.url.slice(1),navigator.clipboard.writeText(U.href)}else navigator.clipboard.writeText(c.url);i.show({content:r.t("hyperLink.message.coped"),type:L.MessageType.Info})}},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.copy"),children:y.jsx(rt,{className:"dark:!univer-text-white"})})}),P&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{e.executeCommand(Pe.id,{unitId:S,subUnitId:I,row:d,col:p,customRangeId:h.rangeId,type:T})},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.edit"),children:y.jsx(ot,{className:"dark:!univer-text-white"})})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{const U=T===C.EDITING||T===C.ZEN_EDITOR?_.CancelRichHyperLinkCommand.id:_.CancelHyperLinkCommand.id;e.syncExecuteCommand(U,{unitId:S,subUnitId:I,id:h.rangeId,row:d,column:p,documentId:T===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.cancel"),children:y.jsx(st,{className:"dark:!univer-text-white"})})})]})]})]})},Re=()=>{var r,o;const t=m.useDependency(g.SheetsHyperLinkPopupService),[n,e]=R.useState(null),i=m.useDependency(s.IUniverInstanceService);if(R.useEffect(()=>{e(t.currentPopup);const a=t.currentPopup$.subscribe(u=>{e(u)});return()=>{a.unsubscribe()}},[t.currentPopup,t.currentPopup$]),!n)return null;if(n.showAll){const a=i.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(n.subUnitId),l=u==null?void 0:u.getCell(n.row,n.col),h=(o=(r=l==null?void 0:l.p)==null?void 0:r.body)==null?void 0:o.customRanges;return h!=null&&h.length?y.jsx("div",{children:h.map(d=>y.jsx(ct,{...n,customRange:d},d.rangeId))}):null}return y.jsx(ct,{...n})};Re.componentKey="univer.sheet.cell-link-popup";var qt=Object.getOwnPropertyDescriptor,Xt=(t,n,e,i)=>{for(var r=i>1?void 0:i?qt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ne=(t,n)=>(e,i)=>n(e,i,t);const ut=(t,n)=>{var e,i;return t.unitId===n.unitId&&t.subUnitId===n.subUnitId&&t.row===n.row&&t.col===n.col&&((e=t.customRange)==null?void 0:e.rangeId)===((i=n.customRange)==null?void 0:i.rangeId)&&t.type===n.type};g.SheetsHyperLinkPopupService=class extends s.Disposable{constructor(e,i,r,o,a,u,l){super();Z(this,"_currentPopup",null);Z(this,"_currentPopup$",new O.Subject);Z(this,"currentPopup$",this._currentPopup$.asObservable());Z(this,"_currentEditingPopup",null);Z(this,"_currentEditing$",new O.BehaviorSubject(null));Z(this,"currentEditing$",this._currentEditing$.asObservable());Z(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=e,this._injector=i,this._univerInstanceService=r,this._editorBridgeService=o,this._textSelectionManagerService=a,this._docCanvasPopManagerService=u,this._zenZoneService=l,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(e){this._isKeepVisible=e}getIsKeepVisible(){return this._isKeepVisible}showPopup(e){var S;if(this._currentPopup&&ut(e,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),e.type!==C.ZEN_EDITOR&&this._zenZoneService.visible))return;const i=this._currentEditing$.getValue();if(i&&ut(e,i))return;const{unitId:r,subUnitId:o,row:a,col:u,customRangeRect:l,customRange:h}=e;let d;const p={componentKey:Re.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(e.type,!0)}};if(e.type===C.EDITING){if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(l,p)}else if(e.type===C.ZEN_EDITOR){if(!h)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:h.startIndex,endOffset:h.endIndex+1,collapsed:!1},p,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(e.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,p,r,o);else{if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupByPosition(l,p,e)}d&&(this._currentPopup&&((S=this._currentPopup.disposable)==null||S.dispose()),this._currentPopup={unitId:r,subUnitId:o,disposable:d,row:a,col:u,editPermission:!!e.editPermission,copyPermission:!!e.copyPermission,customRange:h,type:e.type,showAll:e.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(e,i){var r,o;this._currentPopup&&((!e||e===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||i)&&((o=(r=this._currentPopup)==null?void 0:r.disposable)==null||o.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}dispose(){super.dispose(),this.hideCurrentPopup(),this.endEditing(),this._currentPopup$.complete(),this._currentEditing$.complete()}_getEditingRange(){var r,o,a;const e=this._editorBridgeService.isVisible().visible,i=this._editorBridgeService.getEditCellState();if(e&&i){const u=this._textSelectionManagerService.getActiveTextRange(),l=(r=i.documentLayoutObject.documentModel)==null?void 0:r.getBody();if(!l)return null;if(!u||u.collapsed)return{startOffset:0,endOffset:l.dataStream.length-2,collapsed:l.dataStream.length-2===0,label:s.BuildTextUtils.transform.getPlainText(l.dataStream)};const h=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(u,(a=(o=l.customRanges)==null?void 0:o.filter(S=>S.rangeType===s.CustomRangeType.HYPERLINK))!=null?a:[]);let d=u.startOffset,p=u.endOffset;return h.forEach(S=>{d=Math.min(d,S.startIndex),p=Math.max(p,S.endIndex+1)}),{startOffset:d,endOffset:p,collapsed:d===p,label:s.BuildTextUtils.transform.getPlainText(l.dataStream.slice(d,p))}}return null}get _editPopup(){return{componentKey:Ce.componentKey,direction:"vertical",onClickOutside:()=>{this.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:"hide"}}startAddEditing(e){var a,u,l,h,d;const{unitId:i,subUnitId:r,type:o}=e;if(o===C.ZEN_EDITOR){const p=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!p)return;const S=this._textSelectionManagerService.getActiveTextRange();if(!S)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(S,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const I=(a=p.getBody())==null?void 0:a.dataStream.slice(S.startOffset,S.endOffset);this._currentEditing$.next({...e,label:I})}else if(o===C.EDITING){const p=this._getEditingRange();if(!p)return;this._textSelectionManagerService.replaceDocRanges([{...p}],{unitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const S=this._injector.get(pe.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!S)return;const I=X.calcDocRangePositions(p,S);if(!(I!=null&&I.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(I.pop(),this._editPopup,i,r),this._currentEditing$.next({...e,label:(u=p==null?void 0:p.label)!=null?u:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,i,r);const p=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET),S=p==null?void 0:p.getSheetBySheetId(r),I=S==null?void 0:S.getCellRaw(e.row,e.col);this._currentEditing$.next({...e,label:I!=null&&I.p?s.BuildTextUtils.transform.getPlainText((h=(l=I.p.body)==null?void 0:l.dataStream)!=null?h:""):((d=I==null?void 0:I.v)!=null?d:"").toString()})}}startEditing(e){var u,l,h,d,p,S;(u=this._currentEditingPopup)==null||u.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:i,subUnitId:r}=e;let o,a;if(e.type===C.ZEN_EDITOR){const I=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(h=(l=I==null?void 0:I.getBody())==null?void 0:l.customRanges)==null?void 0:h.find(P=>P.rangeId===e.customRangeId),a=o?(d=I==null?void 0:I.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(e.type===C.EDITING){const I=E.getEditingCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!I||!((p=I.rects)!=null&&p.length))return;o=I.customRange,a=I.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:o.startIndex,endOffset:o.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(I.rects.pop(),this._editPopup,i,r)}else{const I=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET),P=I==null?void 0:I.getSheetBySheetId(r),w=P==null?void 0:P.getCellRaw(e.row,e.col),T=I==null?void 0:I.getStyles().getStyleByCell(w),c=T==null?void 0:T.tr,D=E.getCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!D||!((S=D.rects)!=null&&S.length))return;o=D.customRange,a=D.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,i,r):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(D.rects.pop(),this._editPopup,{unitId:i,subUnitId:r,row:e.row,col:e.col})}this._currentEditing$.next({...e,customRange:o,label:a})}endEditing(e){var r;if(this.getIsKeepVisible())return;const i=this._currentEditing$.getValue();i&&(!e||e===i.type)&&((r=this._currentEditingPopup)==null||r.dispose(),this._currentEditing$.next(null))}},g.SheetsHyperLinkPopupService=Xt([ne(0,s.Inject(E.SheetCanvasPopManagerService)),ne(1,s.Inject(s.Injector)),ne(2,s.IUniverInstanceService),ne(3,E.IEditorBridgeService),ne(4,s.Inject(de.DocSelectionManagerService)),ne(5,s.Inject(X.DocCanvasPopManagerService)),ne(6,m.IZenZoneService)],g.SheetsHyperLinkPopupService);var he=(t=>(t[t.ALLOWED=0]="ALLOWED",t[t.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",t[t.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",t))(he||{});const Jt=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),je=(t,n,e,i)=>{var u,l,h,d,p;const r=n.getCell(e,i);if(r!=null&&r.f||r!=null&&r.si||(h=(l=(u=r==null?void 0:r.p)==null?void 0:u.body)==null?void 0:l.customBlocks)!=null&&h.length)return 1;const o=t.has(et.SheetDataValidationModel)?t.get(et.SheetDataValidationModel):null,a=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),e,i);return a&&Jt.has(a.type)?!0:(p=(d=r==null?void 0:r.p)==null?void 0:d.drawingsOrder)!=null&&p.length?2:0},Qt=t=>{const n=t.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const e=n.getActiveSheet(),i=t.get(f.SheetsSelectionsService).getCurrentSelections();if(!i.length)return!0;const r=i[0].range.startRow,o=i[0].range.startColumn;return je(t,e,r,o)===1},en=t=>{const n=t.get(de.DocSelectionManagerService),e=t.get(s.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;const r=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return!!(!r||i.every(a=>a.collapsed)||!r.getSelfOrHeaderFooterModel(i[0].segmentId).getBody())},Pe={type:s.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(t,n){if(!n)return!1;const e=t.get(g.SheetsHyperLinkPopupService);return n.customRangeId?e.startEditing(n):e.startAddEditing(n),!0}},ve={type:s.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(t){return t.get(g.SheetsHyperLinkPopupService).endEditing(),!0}},Te={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(t){var p;const n=t.get(s.IUniverInstanceService),e=f.getSheetCommandTarget(n),i=t.get(E.IEditorBridgeService);if(!e)return!1;const r=t.get(s.ICommandService),a=t.get(f.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const u=a.range.startRow,l=a.range.startColumn,h=i.isVisible(),d=((p=n.getFocusedUnit())==null?void 0:p.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return r.executeCommand(Pe.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:u,col:l,type:d?C.ZEN_EDITOR:h.visible?C.EDITING:C.VIEWING})}},ie={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(t){if(Qt(t))return!1;const n=t.get(s.ICommandService);return t.get(g.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ve.id):n.executeCommand(Te.id)}},Ze="SHEET_HYPER_LINK_UI_PLUGIN";var tn=Object.getOwnPropertyDescriptor,nn=(t,n,e,i)=>{for(var r=i>1?void 0:i?tn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},Le=(t,n)=>(e,i)=>n(e,i,t);g.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(e,i,r,o){super();Z(this,"_plainTextFilter",new Set);Z(this,"_copyInfo");this._sheetClipboardService=e,this._hyperLinkModel=i,this._injector=r,this._resolverService=o,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(e){this._plainTextFilter.add(e)}removePlainTextFilter(e){this._plainTextFilter.delete(e)}_filterPlainText(e){return Array.from(this._plainTextFilter).every(i=>i(e))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:Ze,onBeforeCopy:(e,i,r)=>this._collect(e,i,r),onPasteCells:(e,i,r,o)=>{const{copyType:a=E.COPY_TYPE.COPY,pasteType:u}=o,{range:l}=e||{},{range:h,unitId:d,subUnitId:p}=i;return this._generateMutations(h,{copyType:a,pasteType:u,copyRange:l,unitId:d,subUnitId:p})},onPastePlainText:(e,i)=>{const r=this._filterPlainText(i);if(ye(i)&&r){const{range:o,unitId:a,subUnitId:u}=e,{ranges:[l],mapFunc:h}=E.virtualizeDiscreteRanges([o]),d=[],p=[];return s.Range.foreach(l,(S,I)=>{const{row:P,col:w}=h(S,I),T=this._hyperLinkModel.getHyperLinkByLocation(a,u,P,w);T&&d.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:u,id:T.id}}),T&&p.push({id:_.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:u,link:T}})}),{redos:d,undos:p}}return{undos:[],redos:[]}},priority:99})}_collect(e,i,r){const o=new s.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:i,matrix:o};const a=this._injector.invoke(h=>f.rangeToDiscreteRange(r,h,e,i));if(!a)return;const{rows:u,cols:l}=a;u.forEach((h,d)=>{l.forEach((p,S)=>{var P;const I=this._hyperLinkModel.getHyperLinkByLocation(e,i,h,p);o.setValue(d,S,(P=I==null?void 0:I.id)!=null?P:"")})})}_generateMutations(e,i){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!i.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(i.pasteType))return{redos:[],undos:[]};const{unitId:o,subUnitId:a}=this._copyInfo,u=[],l=[],{ranges:[h,d],mapFunc:p}=E.virtualizeDiscreteRanges([i.copyRange,e]);return E.getRepeatRange(h,d,!0).forEach(({startRange:I})=>{var P;(P=this._copyInfo)==null||P.matrix.forValue((w,T,c)=>{const D=s.Rectangle.getPositionRange({startRow:w,endRow:w,startColumn:T,endColumn:T},I),A=this._hyperLinkModel.getHyperLink(o,a,c),{row:M,col:U}=p(D.startRow,D.startColumn),V=this._hyperLinkModel.getHyperLinkByLocation(i.unitId,i.subUnitId,M,U),B=s.generateRandomId();V&&u.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:V.id}}),A&&(u.push({id:_.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:{...A,id:B,row:M,column:U}}}),l.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:B}})),V&&l.push({id:_.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:V}})})}),{redos:u,undos:l}}},g.SheetsHyperLinkCopyPasteController=nn([Le(0,E.ISheetClipboardService),Le(1,s.Inject(_.HyperLinkModel)),Le(2,s.Inject(s.Injector)),Le(3,s.Inject(g.SheetsHyperLinkResolverService))],g.SheetsHyperLinkCopyPasteController);const Fe=(t,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var r;const e=t.get(s.IUniverInstanceService),i=(r=t.get(pe.IRenderManagerService).getRenderById(n))==null?void 0:r.with(X.DocSelectionRenderService);return i?i.textSelectionInner$.pipe(O.map(()=>{const a=t.get(E.IEditorBridgeService).getEditCellState();if(!a)return!0;const u=f.getSheetCommandTarget(e,{unitId:a.unitId,subUnitId:a.sheetId});return!(u!=null&&u.worksheet)||je(t,u.worksheet,a.row,a.column)===1?!0:en(t)})):O.of(!0)},lt=t=>{var r;const n=t.get(s.IUniverInstanceService),e=t.has(E.IEditorBridgeService)?t.get(E.IEditorBridgeService):null;return((r=e==null?void 0:e.currentEditCellState$.pipe(O.map(o=>{if(!o)return he.DISABLED_BY_CELL;const a=f.getSheetCommandTarget(n,{unitId:o.unitId,subUnitId:o.sheetId});return a?je(t,a.worksheet,o.row,o.column):he.DISABLED_BY_CELL}),O.switchMap(o=>{if(o===he.DISABLED_BY_CELL)return O.of(!0);const a=e?e.visible$:O.of(null);return O.combineLatest([a,n.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC)]).pipe(O.switchMap(([u,l])=>u!=null&&u.visible?(l==null?void 0:l.getUnitId())===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?O.of(!0):Fe(t,s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY):O.of(o!==he.ALLOWED)))})))!=null?r:O.of(!0)).pipe(O.switchMap(o=>o?O.of(!0):E.getCurrentRangeDisable$(t,{workbookTypes:[f.WorkbookEditablePermission],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetSetCellValuePermission,f.WorksheetInsertHyperlinkPermission],rangeTypes:[f.RangeProtectionPermissionEditPoint]},!0)))},we={commandId:Te.id,type:m.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkIcon"},De=t=>`${t}-zen-editor`,rn=t=>({...we,id:we.commandId,hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:lt(t)}),sn=t=>({...we,id:De(we.commandId),hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Fe(t)}),be={tooltip:"hyperLink.form.addTitle",commandId:ie.id,type:m.MenuItemType.BUTTON,icon:"LinkIcon"},on=t=>({...be,id:be.commandId,hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:lt(t)}),an=t=>({...be,id:De(be.commandId),hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Fe(t)}),Ke={id:ie.id,binding:m.KeyCode.K|m.MetaKeys.CTRL_COMMAND,preconditions:E.whenSheetEditorFocused};var cn=Object.getOwnPropertyDescriptor,un=(t,n,e,i)=>{for(var r=i>1?void 0:i?cn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},dt=(t,n)=>(e,i)=>n(e,i,t);let ke=class extends s.Disposable{constructor(t,n){super(),this._autoFillService=t,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const t=()=>({redos:[],undos:[]}),n=(i,r)=>{const{source:o,target:a,unitId:u,subUnitId:l}=i,h=E.virtualizeDiscreteRanges([o,a]),[d,p]=h.ranges,{mapFunc:S}=h,I={row:d.startRow,col:d.startColumn},P=E.getAutoFillRepeatRange(d,p),w=[],T=[];return P.forEach(c=>{const D=c.repeatStartCell,A=c.relativeRange,M={startRow:I.row,startColumn:I.col,endColumn:I.col,endRow:I.row},U={startRow:D.row,startColumn:D.col,endColumn:D.col,endRow:D.row};s.Range.foreach(A,(V,B)=>{const z=s.Rectangle.getPositionRange({startRow:V,startColumn:B,endColumn:B,endRow:V},M),{row:re,col:xe}=S(z.startRow,z.startColumn),se=this._hyperLinkModel.getHyperLinkByLocation(u,l,re,xe),Ie=s.Rectangle.getPositionRange({startRow:V,startColumn:B,endColumn:B,endRow:V},U),{row:Se,col:_e}=S(Ie.startRow,Ie.startColumn),Ae=s.generateRandomId(),ce=this._hyperLinkModel.getHyperLinkByLocation(u,l,Se,_e);ce&&w.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:ce.id}}),(E.APPLY_TYPE.COPY===r||E.APPLY_TYPE.SERIES===r)&&se&&(w.push({id:_.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:{...se,id:Ae,row:Se,column:_e}}}),T.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:Ae}})),ce&&T.push({id:_.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:ce}})})}),{undos:T,redos:w}},e={id:Ze,onFillData:(i,r,o)=>o===E.APPLY_TYPE.COPY||o===E.APPLY_TYPE.ONLY_FORMAT||o===E.APPLY_TYPE.SERIES?n(i,o):t()};this.disposeWithMe(this._autoFillService.addHook(e))}};ke=un([dt(0,E.IAutoFillService),dt(1,s.Inject(_.HyperLinkModel))],ke);var ln=Object.getOwnPropertyDescriptor,dn=(t,n,e,i)=>{for(var r=i>1?void 0:i?ln(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},We=(t,n)=>(e,i)=>n(e,i,t);let Oe=class extends s.Disposable{constructor(t,n,e){super(),this._localeService=t,this._commandService=n,this._sheetPermissionCheckController=e,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Ke.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookEditablePermission],rangeTypes:[f.RangeProtectionPermissionEditPoint],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetSetCellValuePermission,f.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};Oe=dn([We(0,s.Inject(s.LocaleService)),We(1,s.ICommandService),We(2,s.Inject(f.SheetPermissionCheckController))],Oe);var pn=Object.getOwnPropertyDescriptor,hn=(t,n,e,i)=>{for(var r=i>1?void 0:i?pn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},F=(t,n)=>(e,i)=>n(e,i,t);let Ne=class extends s.Disposable{constructor(t,n,e,i,r,o,a,u,l,h){super(),this._hoverManagerService=t,this._sheetsHyperLinkPopupService=n,this._renderManagerService=e,this._permissionService=i,this._sheetPermissionCheckController=r,this._commandService=o,this._editorBridgeService=a,this._textSelectionManagerService=u,this._univerInstanceService=l,this._zenZoneService=h,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(t){const{unitId:n,subUnitId:e,row:i,col:r}=t,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),a=o==null?void 0:o.getSheetBySheetId(e);if(!a)return{viewPermission:!1,editPermission:!1,copyPermission:!1};const u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookViewPermission],worksheetTypes:[f.WorksheetViewPermission],rangeTypes:[f.RangeProtectionPermissionViewPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}],n,e);let l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookEditablePermission],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetInsertHyperlinkPermission],rangeTypes:[f.RangeProtectionPermissionEditPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}],n,e);const h=a.getCellRaw(i,r);h!=null&&h.f&&h.f.startsWith("=HYPERLINK(")&&(l=!1);const d=this._permissionService.composePermission([new f.WorkbookCopyPermission(n).id,new f.WorksheetCopyPermission(n,e).id]).every(p=>p.value);return{viewPermission:u,editPermission:l,copyPermission:d}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(O.debounceTime(200)).subscribe(t=>{var M,U,V;if(!t||((M=t.customRange)==null?void 0:M.rangeType)!==s.CustomRangeType.HYPERLINK){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:e,row:i,col:r}=t,o=this._renderManagerService.getRenderById(n);if(!o)return;const a=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(e);if(!u)return;if(!o.with(E.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING);return}const h=(U=o==null?void 0:o.with(E.SheetSkeletonManagerService).getSkeletonParam(e))==null?void 0:U.skeleton,d=r,p=i;let S=p,I=d;h&&h.overflowCache.forValue((B,z,re)=>{s.Rectangle.contains(re,{startColumn:d,endColumn:d,startRow:p,endRow:p})&&(S=B,I=z)});const{viewPermission:P,editPermission:w,copyPermission:T}=this._getLinkPermission(t);if(!P){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=u.getCellStyleOnly(S,I),D=a.getStyles().getStyleByCell(c),A=(V=D==null?void 0:D.tr)==null?void 0:V.a;if(!A&&!t.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:S,col:I,editPermission:w,copyPermission:T,customRange:t.customRange,customRangeRect:t.rect,type:C.VIEWING,unitId:n,subUnitId:e,showAll:!!A})}))}_initHoverEditingListener(){let t=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(O.switchMap(n=>this._editorBridgeService.visible$.pipe(O.map(e=>({visible:e,state:n}))))).subscribe(({visible:n,state:e})=>{if(!e||e.editorUnitId!==s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){t==null||t.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.EDITING),this._sheetsHyperLinkPopupService.endEditing(C.EDITING);return}const{editorUnitId:i,unitId:r,sheetId:o,row:a,column:u}=e,l=this._renderManagerService.getRenderById(i);if(!l)return;const{editPermission:h,viewPermission:d,copyPermission:p}=this._getLinkPermission({unitId:r,subUnitId:o,row:a,col:u}),S=l.with(X.DocEventManagerService);d&&(t==null||t.unsubscribe(),t=S.hoverCustomRanges$.pipe(O.debounceTime(200)).subscribe(I=>{var D,A;const P=I.find(M=>M.range.rangeType===s.CustomRangeType.HYPERLINK);if(!P){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const w=P.rects[P.rects.length-1];if(!((A=(D=this._renderManagerService.getRenderById(r))==null?void 0:D.with(E.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:A.skeleton)||!w)return;const c=l.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:r,subUnitId:o,row:a,col:u,customRange:P.range,customRangeRect:{left:w.left+c.left,top:w.top+c.top,bottom:w.bottom+c.top,right:w.right+c.left},editPermission:h,copyPermission:p,type:C.EDITING})}))})),this.disposeWithMe(()=>{t==null||t.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t?(this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.EDITING),this._sheetsHyperLinkPopupService.endEditing(C.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(C.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(C.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(O.switchMap(t=>{const n=t===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(t):null;return n?n.with(X.DocEventManagerService).hoverCustomRanges$.pipe(O.debounceTime(200)):new O.Observable(e=>{e.next(null)})})).subscribe(t=>{const n=t==null?void 0:t.find(i=>i.range.rangeType===s.CustomRangeType.HYPERLINK),e=this._editorBridgeService.getEditCellState();if(n&&e){const{unitId:i,sheetId:r,row:o,column:a}=e,{editPermission:u,viewPermission:l,copyPermission:h}=this._getLinkPermission({unitId:i,subUnitId:r,row:o,col:a});l&&this._sheetsHyperLinkPopupService.showPopup({type:C.ZEN_EDITOR,unitId:i,subUnitId:r,row:o,col:a,customRange:n.range,editPermission:u,copyPermission:h})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(C.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(t=>{t&&t.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(C.EDITING)}))}_initCommandListener(){const t=[f.ClearSelectionContentCommand.id,f.ClearSelectionAllCommand.id,f.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{t.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ne=hn([F(0,s.Inject(E.HoverManagerService)),F(1,s.Inject(g.SheetsHyperLinkPopupService)),F(2,s.Inject(pe.IRenderManagerService)),F(3,s.Inject(s.IPermissionService)),F(4,s.Inject(f.SheetPermissionCheckController)),F(5,s.ICommandService),F(6,E.IEditorBridgeService),F(7,s.Inject(de.DocSelectionManagerService)),F(8,s.IUniverInstanceService),F(9,m.IZenZoneService)],Ne);var vn=Object.getOwnPropertyDescriptor,pt=(t,n,e,i)=>{for(var r=i>1?void 0:i?vn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},Ye=(t,n)=>(e,i)=>n(e,i,t);let Ge=class extends s.Disposable{constructor(t,n){super(),this._context=t,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const t=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(O.debounceTime(16)).subscribe(()=>{t()}))}};Ge=pt([Ye(1,s.Inject(_.HyperLinkModel))],Ge);let Me=class extends s.Disposable{constructor(t,n){super(),this._sheetInterceptorService=t,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(t,n,e)=>{const{row:i,col:r,unitId:o,subUnitId:a}=n,u=this._hyperLinkModel.getHyperLinkByLocation(o,a,i,r);return u&&t&&(t===n.rawData&&(t={...n.rawData}),t.linkUrl=u.payload,t.linkId=u.id),e(t)}}))}};Me=pt([Ye(0,s.Inject(f.SheetInterceptorService)),Ye(1,s.Inject(_.HyperLinkModel))],Me);const gn={[m.RibbonInsertGroup.MEDIA]:{[ie.id]:{order:1,menuItemFactory:on},[De(ie.id)]:{order:1,menuItemFactory:an}},[m.ContextMenuPosition.MAIN_AREA]:{[m.ContextMenuGroup.OTHERS]:{order:1,[ie.id]:{order:0,menuItemFactory:rn},[De(ie.id)]:{order:0,menuItemFactory:sn}}}};var In=Object.getOwnPropertyDescriptor,Sn=(t,n,e,i)=>{for(var r=i>1?void 0:i?In(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ge=(t,n)=>(e,i)=>n(e,i,t);let Ue=class extends s.Disposable{constructor(t,n,e,i,r){super(),this._componentManager=t,this._commandService=n,this._menuManagerService=e,this._injector=i,this._shortcutService=r,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Re.componentKey,Re],[Ce.componentKey,Ce],["LinkIcon",Ve]].forEach(([t,n])=>{this._componentManager.register(t,n)})}_initCommands(){[Pe,ve,Te,ie].forEach(t=>{this._commandService.registerCommand(t)})}_initMenus(){this._menuManagerService.mergeMenu(gn)}_initShortCut(){this._shortcutService.registerShortcut(Ke)}};Ue=Sn([ge(0,s.Inject(m.ComponentManager)),ge(1,s.ICommandService),ge(2,m.IMenuManagerService),ge(3,s.Inject(s.Injector)),ge(4,s.Inject(m.IShortcutService))],Ue);var _n=Object.getOwnPropertyDescriptor,mn=(t,n,e,i)=>{for(var r=i>1?void 0:i?_n(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ht=(t,n)=>(e,i)=>n(e,i,t);let He=class extends s.Disposable{constructor(t,n){super(),this._parserService=t,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const t=location.hash;if(t){const n=this._parserService.parseHyperLink(t);this._resolverService.navigate(n)}}};He=mn([ht(0,s.Inject(_.SheetsHyperLinkParserService)),ht(1,s.Inject(g.SheetsHyperLinkResolverService))],He);var fn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Cn=(t,n,e)=>n in t?fn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,En=(t,n,e,i)=>{for(var r=i>1?void 0:i?yn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},vt=(t,n)=>(e,i)=>n(e,i,t),gt=(t,n,e)=>Cn(t,typeof n!="symbol"?n+"":n,e);g.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=nt,e,i){super(),this._config=n,this._injector=e,this._configService=i;const{menu:r,...o}=s.merge({},nt,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(tt,o)}onStarting(){[[g.SheetsHyperLinkResolverService],[g.SheetsHyperLinkPopupService],[Be],[Me],[Ne],[Ue],[ke],[g.SheetsHyperLinkCopyPasteController],[Oe],[He]].forEach(e=>this._injector.add(e)),this._injector.get(Me)}onReady(){this._injector.get(pe.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[Ge]),this._injector.get(ke),this._injector.get(g.SheetsHyperLinkCopyPasteController),this._injector.get(Ue)}onRendered(){this._injector.get(Oe),this._injector.get(He),this._injector.get(Ne)}},gt(g.UniverSheetsHyperLinkUIPlugin,"pluginName",Ze),gt(g.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkUIPlugin=En([s.DependentOn(_.UniverSheetsHyperLinkPlugin,X.UniverDocsUIPlugin),vt(1,s.Inject(s.Injector)),vt(2,s.IConfigService)],g.UniverSheetsHyperLinkUIPlugin),g.CloseHyperLinkPopupOperation=ve,g.InsertHyperLinkOperation=Te,g.InsertLinkShortcut=Ke,g.OpenHyperLinkEditPanelOperation=Pe,g.SheetsHyperLinkSidePanelService=Be,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui"),require("@univerjs/sheets-hyper-link"),require("react"),require("@univerjs/sheets-data-validation")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-ui","@univerjs/docs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","@univerjs/design","@univerjs/engine-formula","@univerjs/sheets-formula-ui","@univerjs/sheets-hyper-link","react","@univerjs/sheets-data-validation"],s):(g=typeof globalThis<"u"?globalThis:g||self,s(g.UniverSheetsHyperLinkUi={},g.UniverCore,g.UniverSheets,g.UniverSheetsUi,g.UniverDocs,g.UniverDocsUi,g.UniverEngineRender,g.UniverUi,g.rxjs,g.React,g.UniverDesign,g.UniverEngineFormula,g.UniverSheetsFormulaUi,g.UniverSheetsHyperLink,g.React,g.UniverSheetsDataValidation))})(this,(function(g,s,f,E,de,X,pe,m,O,y,L,G,Nt,_,P,et){"use strict";var bn=Object.defineProperty;var kn=(g,s,f)=>s in g?bn(g,s,{enumerable:!0,configurable:!0,writable:!0,value:f}):g[s]=f;var Z=(g,s,f)=>kn(g,typeof s!="symbol"?s+"":s,f);var C=(t=>(t.EDITING="editing",t.VIEWING="viewing",t.ZEN_EDITOR="zen_mode",t))(C||{});function ye(t){return s.Tools.isLegalUrl(t)}function Mt(t){return/^[a-zA-Z]+:\/\//.test(t)}function Ut(t){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(t)}function Ht(t){if(ye(t)){const n=Mt(t)?t:Ut(t)?`mailto://${t}`:`http://${t}`;let e;try{e=new URL(n)}catch{return t}return e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol&&e.pathname===location.pathname&&e.hash&&!e.search?e.hash:n}return t}const tt="sheets-hyper-link-ui.config",nt={};var xt=Object.getOwnPropertyDescriptor,At=(t,n,e,i)=>{for(var r=i>1?void 0:i?xt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ae=(t,n)=>(e,i)=>n(e,i,t);function $t(t,n){const e=n.getMergeData(),i=n.getMaxColumns()-1,r=n.getMaxRows()-1;if(i<t.endColumn&&(t.endColumn=i),r<t.endRow&&(t.endRow=r),t.rangeType===s.RANGE_TYPE.COLUMN||s.RANGE_TYPE.ROW)return t;const o=[];return e.forEach(a=>{s.Rectangle.intersects(t,a)&&o.push(a)}),s.Rectangle.realUnion(t,...o)}g.SheetsHyperLinkResolverService=class{constructor(n,e,i,r,o,a){this._univerInstanceService=n,this._commandService=e,this._definedNamesService=i,this._messageService=r,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:e,range:i,rangeid:r}=n,o=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!o)return;const a=o.getUnitId();if(r){const u=this._definedNamesService.getValueById(a,r);if(!u)return;const{formulaOrRefString:l}=u,h=this._definedNamesService.getWorksheetByRef(a,l);if(!h){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:L.MessageType.Error});return}if(h.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:L.MessageType.Error});return}this.navigateToDefineName(a,r)}if(e){if(i){const u=G.deserializeRangeWithSheet(i);s.isValidRange(u.range)&&i!==_.ERROR_RANGE&&this.navigateToRange(a,e,u.range);return}this.navigateToSheetById(a,e)}}async navigateToRange(n,e,i,r){const o=await this.navigateToSheetById(n,e);if(o){const a=$t(i,o);await this._commandService.executeCommand(f.SetSelectionsOperation.id,{unitId:n,subUnitId:e,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(E.ScrollToRangeOperation.id,{range:a,forceTop:r})}}async navigateToSheetById(n,e){const i=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET);if(!i)return!1;const r=i.getActiveSheet();if(!r)return!1;if(r.getSheetId()===e)return r;const o=i.getSheetBySheetId(e);return o?i.getHiddenWorksheets().indexOf(e)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:L.MessageType.Error}),!1):await this._commandService.executeCommand(f.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:e})?o:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:L.MessageType.Error}),!1)}async navigateToDefineName(n,e){return this._definedNamesService.focusRange(n,e),!0}async navigateToOtherWebsite(n){var i;const e=this._configService.getConfig(tt);if((i=e==null?void 0:e.urlHandler)!=null&&i.navigateToOtherWebsite)return e.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}},g.SheetsHyperLinkResolverService=At([ae(0,s.IUniverInstanceService),ae(1,s.ICommandService),ae(2,G.IDefinedNamesService),ae(3,m.IMessageService),ae(4,s.Inject(s.LocaleService)),ae(5,s.IConfigService)],g.SheetsHyperLinkResolverService);class Be extends s.Disposable{constructor(){super(...arguments);Z(this,"_customHyperLinks",new Map)}isBuiltInLinkType(e){return e!==_.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:e})=>e)}findCustomHyperLink(e){return Array.from(this._customHyperLinks.values()).find(r=>r.match(e))}registerCustomHyperLink(e){this._customHyperLinks.set(e.type,e)}getCustomHyperLink(e){return this._customHyperLinks.get(e)}removeCustomHyperLink(e){const{_customHyperLinks:i}=this;i.delete(e)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const Ce=()=>{var _t;const[t,n]=P.useState(""),[e,i]=P.useState(!1),[r,o]=P.useState(""),[a,u]=P.useState(!0),[l,h]=P.useState(_.SheetHyperLinkType.URL),[d,p]=P.useState(""),I=m.useDependency(s.LocaleService),S=m.useDependency(G.IDefinedNamesService),R=m.useDependency(E.IEditorBridgeService),w=m.useDependency(s.IUniverInstanceService),T=m.useDependency(g.SheetsHyperLinkPopupService),c=m.useObservable(T.currentEditing$),D=m.useDependency(_.SheetsHyperLinkParserService),A=m.useDependency(g.SheetsHyperLinkResolverService),M=m.useDependency(s.ICommandService),U=m.useDependency(Be),V=P.useMemo(()=>U.getOptions(),[U]),B=m.useDependency(m.IZenZoneService),z=m.useDependency(pe.IRenderManagerService),re=m.useDependency(E.IMarkSelectionService),xe=m.useDependency(de.DocSelectionManagerService),se=m.useDependency(s.IContextService),Se=m.useDependency(s.ThemeService),Ie=m.useDependency(de.DocSelectionManagerService),[_e,Ae]=P.useState(!1),ce=m.useDependency(f.SheetsSelectionsService),Pn=P.useMemo(()=>ce.getCurrentSelections(),[]),$e=P.useMemo(()=>{if(!U.isBuiltInLinkType(l))return U.getCustomHyperLink(l)},[U,l]),[ue,Rn]=P.useState(!1),[me,St]=P.useState(!1),j=P.useRef(!1),K=w.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),Tn=(K==null?void 0:K.getActiveSheet().getSheetId())||"",J=P.useCallback(v=>{o(v.replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(s.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[o]);P.useEffect(()=>{var v,b,k,N,x,W,mt,ft,yt,Ct,Et,Pt,Rt,Tt,Lt,wt,Dt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:oe,row:Je,col:Qe}=c;let{label:q}=c;typeof q=="number"&&(q=`${q}`);let Y;if(oe)Y={id:(v=oe==null?void 0:oe.rangeId)!=null?v:"",display:q!=null?q:"",payload:(k=(b=oe==null?void 0:oe.properties)==null?void 0:b.url)!=null?k:"",row:Je,column:Qe};else if(c.type===C.VIEWING){const H=w.getUnit(c.unitId),ee=H==null?void 0:H.getSheetBySheetId(c.subUnitId),$=ee==null?void 0:ee.getCellRaw(c.row,c.col),le=(W=(x=(N=$==null?void 0:$.p)==null?void 0:N.body)==null?void 0:x.customRanges)==null?void 0:W.find(kt=>{var Ot;return kt.rangeType===s.CustomRangeType.HYPERLINK&&((Ot=kt.properties)==null?void 0:Ot.url)}),fe=$==null?void 0:$.v;$&&(!s.BuildTextUtils.transform.isEmptyDocument((ft=(mt=$.p)==null?void 0:mt.body)==null?void 0:ft.dataStream)||s.Tools.isDefine(fe))&&u(!1),Y={id:"",display:"",payload:(Ct=(yt=le==null?void 0:le.properties)==null?void 0:yt.url)!=null?Ct:"",row:Je,column:Qe}}else{const H=w.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),ee=xe.getActiveTextRange(),$=H==null?void 0:H.getBody(),le=ee&&$?ee:null,fe=le&&((Pt=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(Et=$==null?void 0:$.customRanges)!=null?Et:[]))==null?void 0:Pt[0]);u(!1),Y={id:"",display:q!=null?q:"",payload:(Tt=(Rt=fe==null?void 0:fe.properties)==null?void 0:Rt.url)!=null?Tt:"",row:Je,column:Qe}}n(Y.id);const bt=U.findCustomHyperLink(Y);if(bt){const H=bt.convert(Y);h(H.type),p(H.payload),J(H.display);return}J(Y.display);const Q=D.parseHyperLink(Y.payload);switch(h(Q.type===_.SheetHyperLinkType.INVALID?_.SheetHyperLinkType.RANGE:Q.type),Q.type){case _.SheetHyperLinkType.URL:{p(Q.url),Q.url===Y.display&&(j.current=!0);break}case _.SheetHyperLinkType.RANGE:{const H=Q.searchObj,ee=H.gid&&(Dt=(wt=(Lt=w.getUnit(c.unitId))==null?void 0:Lt.getSheetBySheetId(H.gid))==null?void 0:wt.getName())!=null?Dt:"",$=G.serializeRangeWithSheet(ee,G.deserializeRangeWithSheet(H.range).range);p($),$===Y.display&&(j.current=!0);break}case _.SheetHyperLinkType.SHEET:{const H=Q.searchObj;p(H.gid);break}case _.SheetHyperLinkType.DEFINE_NAME:{const H=Q.searchObj;p(H.rangeid);break}default:p("");break}}},[c,A,U,xe,w]),P.useEffect(()=>{let v=null;if(c&&!c.customRangeId&&c.type===C.VIEWING&&s.Tools.isDefine(c.row)&&s.Tools.isDefine(c.col)){const b=w.getUnit(c.unitId,s.UniverInstanceType.UNIVER_SHEET),k=b==null?void 0:b.getSheetBySheetId(c.subUnitId),N=k==null?void 0:k.getMergedCell(c.row,c.col),x=new s.ColorKit(Se.getColorFromTheme("primary.600")).toRgb();v=re.addShape({range:N!=null?N:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${x.r}, ${x.g}, ${x.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{v&&re.removeShape(v)}},[c,re,Se,w]),P.useEffect(()=>{St(l===_.SheetHyperLinkType.RANGE)},[l]),P.useEffect(()=>{const v=(c==null?void 0:c.type)===C.ZEN_EDITOR?z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY):z.getRenderById(R.getCurrentEditorId()),b=new s.DisposableCollection;if(v){const k=v.with(X.DocSelectionRenderService);k.setReserveRangesStatus(!0),b.add(()=>{k.setReserveRangesStatus(!1)})}return()=>{R.disableForceKeepVisible(),b.dispose()}},[c==null?void 0:c.type,R,z]),P.useEffect(()=>(me&&T.setIsKeepVisible(me),T.setIsKeepVisible(_e),()=>{T.setIsKeepVisible(!1)}),[me,_e,T]),P.useEffect(()=>()=>{B.temporaryHidden&&(B.show(),se.setContextValue(s.FOCUSING_SHEET,!1))},[se,B]),P.useEffect(()=>{if(me)return R.enableForceKeepVisible(),()=>{R.disableForceKeepVisible()}},[me,R]);const Ln=[{label:I.t("hyperLink.form.link"),value:_.SheetHyperLinkType.URL},{label:I.t("hyperLink.form.range"),value:_.SheetHyperLinkType.RANGE},{label:I.t("hyperLink.form.worksheet"),value:_.SheetHyperLinkType.SHEET},{label:I.t("hyperLink.form.definedName"),value:_.SheetHyperLinkType.DEFINE_NAME},...V];if(!K)return;const wn=K.getHiddenWorksheets(),ze=K.getSheets().map(v=>({label:v.getName(),value:v.getSheetId()})).filter(v=>wn.indexOf(v.value)===-1),qe=Object.values((_t=S.getDefinedNameMap(K.getUnitId()))!=null?_t:{}).map(v=>({label:v.name,value:v.id})),It=(v,b)=>{if(v===_.SheetHyperLinkType.URL)return Ht(b);if(v===_.SheetHyperLinkType.RANGE){const k=G.deserializeRangeWithSheet(b),N=K.getSheetBySheetName(k.sheetName);if(N)return`#gid=${N.getSheetId()}&range=${G.serializeRange(k.range)}`}return`#${v}=${b}`},Dn=m.useEvent(v=>{var x;const k=v.split(",").map(G.deserializeRangeWithSheet)[0];if(!k||!s.isValidRange(k.range))return;k.sheetName||(k.sheetName=((x=K.getActiveSheet())==null?void 0:x.getName())||"");const N=G.serializeRangeToRefString(k);p(N),N&&(j.current||!r)&&(J(N),j.current=!0)}),Xe=async()=>{if(a&&!r||!d||l===_.SheetHyperLinkType.URL&&!ye(d)){Rn(!0);return}if(c)if(t){const v=c.type===C.ZEN_EDITOR||c.type===C.EDITING?_.UpdateRichHyperLinkCommand.id:_.UpdateHyperLinkCommand.id;await M.executeCommand(v,{id:t,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?r:"",payload:It(l,d)},row:c.row,column:c.col,documentId:c.type===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}else{const v=c.type===C.ZEN_EDITOR||c.type===C.EDITING?_.AddRichHyperLinkCommand.id:_.AddHyperLinkCommand.id;await M.executeCommand(v,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:s.generateRandomId(),row:c.row,column:c.col,payload:It(l,d),display:a?r:""},documentId:c.type===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}if((c==null?void 0:c.type)===C.VIEWING){await M.executeCommand(f.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const v=1;await M.executeCommand(E.ScrollToRangeOperation.id,{range:{startRow:Math.max(c.row-v,0),endRow:c.row+v,startColumn:Math.max(c.col-v,0),endColumn:c.col+v}})}M.executeCommand(ve.id)};return c?y.jsxs("div",{className:L.clsx("univer-box-border univer-w-[296px] univer-rounded-xl univer-bg-white univer-p-4 univer-shadow-md dark:!univer-bg-gray-900",L.borderClassName),children:[a?y.jsx(L.FormLayout,{label:I.t("hyperLink.form.label"),error:ue&&!r?I.t("hyperLink.form.inputError"):"",children:y.jsx(L.Input,{value:r,onChange:v=>{J(v),j.current=!1},placeholder:I.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===m.KeyCode.ENTER&&Xe()}})}):null,y.jsx(L.FormLayout,{label:I.t("hyperLink.form.type"),children:y.jsx(L.Select,{className:"univer-w-full",options:Ln,value:l,onChange:v=>{h(v),p("")}})}),l===_.SheetHyperLinkType.URL&&y.jsx(L.FormLayout,{error:ue?d?ye(d)?"":I.t("hyperLink.form.linkError"):I.t("hyperLink.form.inputError"):"",children:y.jsx(L.Input,{value:d,onChange:v=>{p(v),v&&(j.current||!r||r===v)&&(J(v),j.current=!0)},placeholder:I.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:v=>{v.keyCode===m.KeyCode.ENTER&&Xe()}})}),l===_.SheetHyperLinkType.RANGE&&y.jsx(L.FormLayout,{error:ue&&!d?I.t("hyperLink.form.inputError"):"",children:y.jsx(Nt.RangeSelector,{unitId:K.getUnitId(),subUnitId:Tn,maxRangeCount:1,supportAcrossSheet:!0,initialValue:d,resetRange:Pn,onChange:(v,b)=>Dn(b),onRangeSelectorDialogVisibleChange:async v=>{var b,k;if(Ae(v),v)c.type===C.ZEN_EDITOR&&(B.hide(),se.setContextValue(s.FOCUSING_SHEET,!0)),c.type!==C.VIEWING&&R.enableForceKeepVisible(),i(!0);else{if(await A.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===C.ZEN_EDITOR){await M.executeCommand(f.SetSelectionsOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId,selections:[{range:{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col}}]}),B.show(),se.setContextValue(s.FOCUSING_SHEET,!1);const N=(b=z.getRenderById(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(X.DocBackScrollRenderController),x=(k=Ie.getTextRanges({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:k[0];N&&x&&(N.scrollToRange(x),Ie.refreshSelection({unitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}R.disableForceKeepVisible(),i(!1)}},onFocusChange:v=>St(v)})}),l===_.SheetHyperLinkType.SHEET&&y.jsx(L.FormLayout,{error:ue&&!d?I.t("hyperLink.form.selectError"):"",children:y.jsx(L.Select,{className:"univer-w-full",options:ze,value:d,onChange:v=>{var N,x;p(v);const b=(N=ze.find(W=>W.value===v))==null?void 0:N.label,k=(x=ze.find(W=>W.value===d))==null?void 0:x.label;b&&(j.current||!r||r===k)&&(J(b),j.current=!0)}})}),l===_.SheetHyperLinkType.DEFINE_NAME&&y.jsx(L.FormLayout,{error:ue&&!d?I.t("hyperLink.form.selectError"):"",children:y.jsx(L.Select,{className:"univer-w-full",options:qe,value:d,onChange:v=>{var N,x;p(v);const b=(N=qe.find(W=>W.value===v))==null?void 0:N.label,k=(x=qe.find(W=>W.value===d))==null?void 0:x.label;b&&(j.current||!r||r===k)&&(J(b),j.current=!0)}})}),($e==null?void 0:$e.Form)&&y.jsx($e.Form,{linkId:t,payload:d,display:r,showError:ue,setByPayload:j,setDisplay:v=>{J(v),j.current=!0},setPayload:p}),y.jsxs("div",{className:"univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[y.jsx(L.Button,{onClick:()=>{c&&A.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),M.executeCommand(ve.id)},children:I.t("hyperLink.form.cancel")}),y.jsx(L.Button,{variant:"primary",onClick:async()=>{Xe()},children:I.t("hyperLink.form.ok")})]})]}):null};Ce.componentKey="univer.sheet.cell-link-edit";function te({ref:t,...n}){const{icon:e,id:i,className:r,extend:o,...a}=n,u=`univerjs-icon univerjs-icon-${i} ${r||""}`.trim(),l=P.useRef(`_${jt()}`);return it(e,`${i}`,{defIds:e.defIds,idSuffix:l.current},{ref:t,className:u,...a},o)}function it(t,n,e,i,r){return P.createElement(t.tag,{key:n,...Bt(t,e,r),...i},(Vt(t,e).children||[]).map((o,a)=>it(o,`${n}-${t.tag}-${a}`,e,void 0,r)))}function Bt(t,n,e){const i={...t.attrs};e!=null&&e.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=e.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+n.idSuffix),Object.entries(i).forEach(([o,a])=>{o==="mask"&&typeof a=="string"&&(i[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))});const{defIds:r}=n;return!r||r.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(([o,a])=>{typeof a=="string"&&(i[o]=a.replace(/url\(#(.*)\)/,`url(#$1${n.idSuffix})`))})),i}function Vt(t,n){var i;const{defIds:e}=n;return!e||e.length===0?t:t.tag==="defs"&&((i=t.children)!=null&&i.length)?{...t,children:t.children.map(r=>typeof r.attrs.id=="string"&&e&&e.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+n.idSuffix}}:r)}:t}function jt(){return Math.random().toString(36).substring(2,8)}te.displayName="UniverIcon";const Zt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ee=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"all-border-icon",ref:e,icon:Zt}))});Ee.displayName="AllBorderIcon";const Ft={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},rt=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"copy-icon",ref:e,icon:Ft}))});rt.displayName="CopyIcon";const Kt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Ve=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"link-icon",ref:e,icon:Kt}))});Ve.displayName="LinkIcon";const Wt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z"}}]},st=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"unlink-icon",ref:e,icon:Wt}))});st.displayName="UnlinkIcon";const Yt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"write-icon",ref:e,icon:Yt}))});ot.displayName="WriteIcon";const Gt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"white",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},at=P.forwardRef(function(n,e){return P.createElement(te,Object.assign({},n,{id:"xlsx-multi-icon",ref:e,icon:Gt}))});at.displayName="XlsxMultiIcon";const zt={[_.SheetHyperLinkType.URL]:y.jsx(Ve,{}),[_.SheetHyperLinkType.SHEET]:y.jsx(at,{className:"univer-text-green-500"}),[_.SheetHyperLinkType.RANGE]:y.jsx(Ee,{}),[_.SheetHyperLinkType.DEFINE_NAME]:y.jsx(Ee,{}),[_.SheetHyperLinkType.INVALID]:y.jsx(Ee,{})},ct=t=>{var A,M;const n=m.useDependency(g.SheetsHyperLinkPopupService),e=m.useDependency(s.ICommandService),i=m.useDependency(m.IMessageService),r=m.useDependency(s.LocaleService),o=m.useDependency(g.SheetsHyperLinkResolverService),a=m.useDependency(E.IEditorBridgeService),u=m.useDependency(_.SheetsHyperLinkParserService),l=m.useDependency(m.IZenZoneService),{customRange:h,row:d,col:p,unitId:I,subUnitId:S,editPermission:R,copyPermission:w,type:T}=t;if(!((A=h==null?void 0:h.properties)!=null&&A.url))return null;const c=u.parseHyperLink((M=h.properties.url)!=null?M:""),D=c.type===_.SheetHyperLinkType.INVALID;return y.jsxs("div",{className:L.clsx("univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md dark:!univer-bg-gray-900",L.borderClassName),onClick:()=>n.hideCurrentPopup(),children:[y.jsxs("div",{className:L.clsx("univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600",{"univer-text-red-500":D}),onClick:()=>{l.visible||D||o.navigate(c)},children:[y.jsx("div",{className:"univer-mr-2 univer-flex univer-h-5 univer-w-5 univer-flex-none univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:zt[c.type]}),y.jsx(L.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:y.jsx("span",{className:"univer-flex-1 univer-truncate",children:c.name})})]}),y.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center",children:[w&&y.jsx("div",{className:L.clsx("univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-red-500":D}),onClick:()=>{if(!D){if(c.type!==_.SheetHyperLinkType.URL){const U=new URL(window.location.href);U.hash=c.url.slice(1),navigator.clipboard.writeText(U.href)}else navigator.clipboard.writeText(c.url);i.show({content:r.t("hyperLink.message.coped"),type:L.MessageType.Info})}},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.copy"),children:y.jsx(rt,{className:"dark:!univer-text-white"})})}),R&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{e.executeCommand(Re.id,{unitId:I,subUnitId:S,row:d,col:p,customRangeId:h.rangeId,type:T})},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.edit"),children:y.jsx(ot,{className:"dark:!univer-text-white"})})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center univer-justify-center univer-rounded univer-text-base hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{const U=T===C.EDITING||T===C.ZEN_EDITOR?_.CancelRichHyperLinkCommand.id:_.CancelHyperLinkCommand.id;e.syncExecuteCommand(U,{unitId:I,subUnitId:S,id:h.rangeId,row:d,column:p,documentId:T===C.ZEN_EDITOR?s.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:y.jsx(L.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.cancel"),children:y.jsx(st,{className:"dark:!univer-text-white"})})})]})]})]})},Pe=()=>{var r,o;const t=m.useDependency(g.SheetsHyperLinkPopupService),[n,e]=P.useState(null),i=m.useDependency(s.IUniverInstanceService);if(P.useEffect(()=>{e(t.currentPopup);const a=t.currentPopup$.subscribe(u=>{e(u)});return()=>{a.unsubscribe()}},[t.currentPopup,t.currentPopup$]),!n)return null;if(n.showAll){const a=i.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(n.subUnitId),l=u==null?void 0:u.getCell(n.row,n.col),h=(o=(r=l==null?void 0:l.p)==null?void 0:r.body)==null?void 0:o.customRanges;return h!=null&&h.length?y.jsx("div",{children:h.map(d=>y.jsx(ct,{...n,customRange:d},d.rangeId))}):null}return y.jsx(ct,{...n})};Pe.componentKey="univer.sheet.cell-link-popup";var qt=Object.getOwnPropertyDescriptor,Xt=(t,n,e,i)=>{for(var r=i>1?void 0:i?qt(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ne=(t,n)=>(e,i)=>n(e,i,t);const ut=(t,n)=>{var e,i;return t.unitId===n.unitId&&t.subUnitId===n.subUnitId&&t.row===n.row&&t.col===n.col&&((e=t.customRange)==null?void 0:e.rangeId)===((i=n.customRange)==null?void 0:i.rangeId)&&t.type===n.type};g.SheetsHyperLinkPopupService=class extends s.Disposable{constructor(e,i,r,o,a,u,l){super();Z(this,"_currentPopup",null);Z(this,"_currentPopup$",new O.Subject);Z(this,"currentPopup$",this._currentPopup$.asObservable());Z(this,"_currentEditingPopup",null);Z(this,"_currentEditing$",new O.BehaviorSubject(null));Z(this,"currentEditing$",this._currentEditing$.asObservable());Z(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=e,this._injector=i,this._univerInstanceService=r,this._editorBridgeService=o,this._textSelectionManagerService=a,this._docCanvasPopManagerService=u,this._zenZoneService=l,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(e){this._isKeepVisible=e}getIsKeepVisible(){return this._isKeepVisible}showPopup(e){var I;if(this._currentPopup&&ut(e,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),e.type!==C.ZEN_EDITOR&&this._zenZoneService.visible))return;const i=this._currentEditing$.getValue();if(i&&ut(e,i))return;const{unitId:r,subUnitId:o,row:a,col:u,customRangeRect:l,customRange:h}=e;let d;const p={componentKey:Pe.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(e.type,!0)}};if(e.type===C.EDITING){if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(l,p)}else if(e.type===C.ZEN_EDITOR){if(!h)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:h.startIndex,endOffset:h.endIndex+1,collapsed:!1},p,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(e.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,p,r,o);else{if(!h)return;d=l&&this._sheetCanvasPopManagerService.attachPopupByPosition(l,p,e)}d&&(this._currentPopup&&((I=this._currentPopup.disposable)==null||I.dispose()),this._currentPopup={unitId:r,subUnitId:o,disposable:d,row:a,col:u,editPermission:!!e.editPermission,copyPermission:!!e.copyPermission,customRange:h,type:e.type,showAll:e.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(e,i){var r,o;this._currentPopup&&((!e||e===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||i)&&((o=(r=this._currentPopup)==null?void 0:r.disposable)==null||o.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}dispose(){super.dispose(),this.hideCurrentPopup(),this.endEditing(),this._currentPopup$.complete(),this._currentEditing$.complete()}_getEditingRange(){var r,o,a;const e=this._editorBridgeService.isVisible().visible,i=this._editorBridgeService.getEditCellState();if(e&&i){const u=this._textSelectionManagerService.getActiveTextRange(),l=(r=i.documentLayoutObject.documentModel)==null?void 0:r.getBody();if(!l)return null;if(!u||u.collapsed)return{startOffset:0,endOffset:l.dataStream.length-2,collapsed:l.dataStream.length-2===0,label:s.BuildTextUtils.transform.getPlainText(l.dataStream)};const h=s.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(u,(a=(o=l.customRanges)==null?void 0:o.filter(I=>I.rangeType===s.CustomRangeType.HYPERLINK))!=null?a:[]);let d=u.startOffset,p=u.endOffset;return h.forEach(I=>{d=Math.min(d,I.startIndex),p=Math.max(p,I.endIndex+1)}),{startOffset:d,endOffset:p,collapsed:d===p,label:s.BuildTextUtils.transform.getPlainText(l.dataStream.slice(d,p))}}return null}get _editPopup(){return{componentKey:Ce.componentKey,direction:"vertical",onClickOutside:()=>{this.endEditing()},onContextMenu:()=>{this.endEditing()},hiddenType:"hide"}}startAddEditing(e){var a,u,l,h,d;const{unitId:i,subUnitId:r,type:o}=e;if(o===C.ZEN_EDITOR){const p=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(!p)return;const I=this._textSelectionManagerService.getActiveTextRange();if(!I)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(I,this._editPopup,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const S=(a=p.getBody())==null?void 0:a.dataStream.slice(I.startOffset,I.endOffset);this._currentEditing$.next({...e,label:S})}else if(o===C.EDITING){const p=this._getEditingRange();if(!p)return;this._textSelectionManagerService.replaceDocRanges([{...p}],{unitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const I=this._injector.get(pe.IRenderManagerService).getRenderById(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!I)return;const S=X.calcDocRangePositions(p,I);if(!(S!=null&&S.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.pop(),this._editPopup,i,r),this._currentEditing$.next({...e,label:(u=p==null?void 0:p.label)!=null?u:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,i,r);const p=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET),I=p==null?void 0:p.getSheetBySheetId(r),S=I==null?void 0:I.getCellRaw(e.row,e.col);this._currentEditing$.next({...e,label:S!=null&&S.p?s.BuildTextUtils.transform.getPlainText((h=(l=S.p.body)==null?void 0:l.dataStream)!=null?h:""):((d=S==null?void 0:S.v)!=null?d:"").toString()})}}startEditing(e){var u,l,h,d,p,I;(u=this._currentEditingPopup)==null||u.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:i,subUnitId:r}=e;let o,a;if(e.type===C.ZEN_EDITOR){const S=this._univerInstanceService.getUnit(s.DOCS_ZEN_EDITOR_UNIT_ID_KEY,s.UniverInstanceType.UNIVER_DOC);if(o=(h=(l=S==null?void 0:S.getBody())==null?void 0:l.customRanges)==null?void 0:h.find(R=>R.rangeId===e.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(e.type===C.EDITING){const S=E.getEditingCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!S||!((p=S.rects)!=null&&p.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,i,r)}else{const S=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET),R=S==null?void 0:S.getSheetBySheetId(r),w=R==null?void 0:R.getCellRaw(e.row,e.col),T=S==null?void 0:S.getStyles().getStyleByCell(w),c=T==null?void 0:T.tr,D=E.getCustomRangePosition(this._injector,e.unitId,e.subUnitId,e.row,e.col,e.customRangeId);if(!D||!((I=D.rects)!=null&&I.length))return;o=D.customRange,a=D.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(e.row,e.col,this._editPopup,i,r):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(D.rects.pop(),this._editPopup,{unitId:i,subUnitId:r,row:e.row,col:e.col})}this._currentEditing$.next({...e,customRange:o,label:a})}endEditing(e){var r;if(this.getIsKeepVisible())return;const i=this._currentEditing$.getValue();i&&(!e||e===i.type)&&((r=this._currentEditingPopup)==null||r.dispose(),this._currentEditing$.next(null))}},g.SheetsHyperLinkPopupService=Xt([ne(0,s.Inject(E.SheetCanvasPopManagerService)),ne(1,s.Inject(s.Injector)),ne(2,s.IUniverInstanceService),ne(3,E.IEditorBridgeService),ne(4,s.Inject(de.DocSelectionManagerService)),ne(5,s.Inject(X.DocCanvasPopManagerService)),ne(6,m.IZenZoneService)],g.SheetsHyperLinkPopupService);var he=(t=>(t[t.ALLOWED=0]="ALLOWED",t[t.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",t[t.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",t))(he||{});const Jt=new Set([s.DataValidationType.CHECKBOX,s.DataValidationType.LIST,s.DataValidationType.LIST_MULTIPLE]),je=(t,n,e,i)=>{var u,l,h,d,p;const r=n.getCell(e,i);if(r!=null&&r.f||r!=null&&r.si||(h=(l=(u=r==null?void 0:r.p)==null?void 0:u.body)==null?void 0:l.customBlocks)!=null&&h.length)return 1;const o=t.has(et.SheetDataValidationModel)?t.get(et.SheetDataValidationModel):null,a=o==null?void 0:o.getRuleByLocation(n.getUnitId(),n.getSheetId(),e,i);return a&&Jt.has(a.type)?!0:(p=(d=r==null?void 0:r.p)==null?void 0:d.drawingsOrder)!=null&&p.length?2:0},Qt=t=>{const n=t.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const e=n.getActiveSheet(),i=t.get(f.SheetsSelectionsService).getCurrentSelections();if(!i.length)return!0;const r=i[0].range.startRow,o=i[0].range.startColumn;return je(t,e,r,o)===1},en=t=>{const n=t.get(de.DocSelectionManagerService),e=t.get(s.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;const r=e.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);return!!(!r||i.every(a=>a.collapsed)||!r.getSelfOrHeaderFooterModel(i[0].segmentId).getBody())},Re={type:s.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(t,n){if(!n)return!1;const e=t.get(g.SheetsHyperLinkPopupService);return n.customRangeId?e.startEditing(n):e.startAddEditing(n),!0}},ve={type:s.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(t){return t.get(g.SheetsHyperLinkPopupService).endEditing(),!0}},Te={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(t){var p;const n=t.get(s.IUniverInstanceService),e=f.getSheetCommandTarget(n),i=t.get(E.IEditorBridgeService);if(!e)return!1;const r=t.get(s.ICommandService),a=t.get(f.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const u=a.range.startRow,l=a.range.startColumn,h=i.isVisible(),d=((p=n.getFocusedUnit())==null?void 0:p.getUnitId())===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return r.executeCommand(Re.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:u,col:l,type:d?C.ZEN_EDITOR:h.visible?C.EDITING:C.VIEWING})}},ie={type:s.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(t){if(Qt(t))return!1;const n=t.get(s.ICommandService);return t.get(g.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ve.id):n.executeCommand(Te.id)}},Ze="SHEET_HYPER_LINK_UI_PLUGIN";var tn=Object.getOwnPropertyDescriptor,nn=(t,n,e,i)=>{for(var r=i>1?void 0:i?tn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},Le=(t,n)=>(e,i)=>n(e,i,t);g.SheetsHyperLinkCopyPasteController=class extends s.Disposable{constructor(e,i,r,o){super();Z(this,"_plainTextFilter",new Set);Z(this,"_copyInfo");this._sheetClipboardService=e,this._hyperLinkModel=i,this._injector=r,this._resolverService=o,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(e){this._plainTextFilter.add(e)}removePlainTextFilter(e){this._plainTextFilter.delete(e)}_filterPlainText(e){return Array.from(this._plainTextFilter).every(i=>i(e))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:Ze,onBeforeCopy:(e,i,r)=>this._collect(e,i,r),onPasteCells:(e,i,r,o)=>{const{copyType:a=E.COPY_TYPE.COPY,pasteType:u}=o,{range:l}=e||{},{range:h,unitId:d,subUnitId:p}=i;return this._generateMutations(h,{copyType:a,pasteType:u,copyRange:l,unitId:d,subUnitId:p})},onPastePlainText:(e,i)=>{const r=this._filterPlainText(i);if(ye(i)&&r){const{range:o,unitId:a,subUnitId:u}=e,{ranges:[l],mapFunc:h}=E.virtualizeDiscreteRanges([o]),d=[],p=[];return s.Range.foreach(l,(I,S)=>{const{row:R,col:w}=h(I,S),T=this._hyperLinkModel.getHyperLinkByLocation(a,u,R,w);T&&d.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:u,id:T.id}}),T&&p.push({id:_.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:u,link:T}})}),{redos:d,undos:p}}return{undos:[],redos:[]}},priority:99})}_collect(e,i,r){const o=new s.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:i,matrix:o};const a=this._injector.invoke(h=>f.rangeToDiscreteRange(r,h,e,i));if(!a)return;const{rows:u,cols:l}=a;u.forEach((h,d)=>{l.forEach((p,I)=>{var R;const S=this._hyperLinkModel.getHyperLinkByLocation(e,i,h,p);o.setValue(d,I,(R=S==null?void 0:S.id)!=null?R:"")})})}_generateMutations(e,i){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!i.copyRange)return{redos:[],undos:[]};if([E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(i.pasteType))return{redos:[],undos:[]};const{unitId:o,subUnitId:a}=this._copyInfo,u=[],l=[],{ranges:[h,d],mapFunc:p}=E.virtualizeDiscreteRanges([i.copyRange,e]);return E.getRepeatRange(h,d,!0).forEach(({startRange:S})=>{var R;(R=this._copyInfo)==null||R.matrix.forValue((w,T,c)=>{const D=s.Rectangle.getPositionRange({startRow:w,endRow:w,startColumn:T,endColumn:T},S),A=this._hyperLinkModel.getHyperLink(o,a,c),{row:M,col:U}=p(D.startRow,D.startColumn),V=this._hyperLinkModel.getHyperLinkByLocation(i.unitId,i.subUnitId,M,U),B=s.generateRandomId();V&&u.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:V.id}}),A&&(u.push({id:_.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:{...A,id:B,row:M,column:U}}}),l.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:B}})),V&&l.push({id:_.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:V}})})}),{redos:u,undos:l}}},g.SheetsHyperLinkCopyPasteController=nn([Le(0,E.ISheetClipboardService),Le(1,s.Inject(_.HyperLinkModel)),Le(2,s.Inject(s.Injector)),Le(3,s.Inject(g.SheetsHyperLinkResolverService))],g.SheetsHyperLinkCopyPasteController);const Fe=(t,n=s.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var r;const e=t.get(s.IUniverInstanceService),i=(r=t.get(pe.IRenderManagerService).getRenderById(n))==null?void 0:r.with(X.DocSelectionRenderService);return i?i.textSelectionInner$.pipe(O.map(()=>{const a=t.get(E.IEditorBridgeService).getEditCellState();if(!a)return!0;const u=f.getSheetCommandTarget(e,{unitId:a.unitId,subUnitId:a.sheetId});return!(u!=null&&u.worksheet)||je(t,u.worksheet,a.row,a.column)===1?!0:en(t)})):O.of(!0)},lt=t=>{var r;const n=t.get(s.IUniverInstanceService),e=t.has(E.IEditorBridgeService)?t.get(E.IEditorBridgeService):null;return((r=e==null?void 0:e.currentEditCellState$.pipe(O.map(o=>{if(!o)return he.DISABLED_BY_CELL;const a=f.getSheetCommandTarget(n,{unitId:o.unitId,subUnitId:o.sheetId});return a?je(t,a.worksheet,o.row,o.column):he.DISABLED_BY_CELL}),O.switchMap(o=>{if(o===he.DISABLED_BY_CELL)return O.of(!0);const a=e?e.visible$:O.of(null);return O.combineLatest([a,n.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC)]).pipe(O.switchMap(([u,l])=>u!=null&&u.visible?(l==null?void 0:l.getUnitId())===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?O.of(!0):Fe(t,s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY):O.of(o!==he.ALLOWED)))})))!=null?r:O.of(!0)).pipe(O.switchMap(o=>o?O.of(!0):E.getCurrentRangeDisable$(t,{workbookTypes:[f.WorkbookEditablePermission],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetSetCellValuePermission,f.WorksheetInsertHyperlinkPermission],rangeTypes:[f.RangeProtectionPermissionEditPoint]},!0)))},we={commandId:Te.id,type:m.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkIcon"},De=t=>`${t}-zen-editor`,rn=t=>({...we,id:we.commandId,hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:lt(t)}),sn=t=>({...we,id:De(we.commandId),hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Fe(t)}),be={tooltip:"hyperLink.form.addTitle",commandId:ie.id,type:m.MenuItemType.BUTTON,icon:"LinkIcon"},on=t=>({...be,id:be.commandId,hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:lt(t)}),an=t=>({...be,id:De(be.commandId),hidden$:m.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_DOC,s.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Fe(t)}),Ke={id:ie.id,binding:m.KeyCode.K|m.MetaKeys.CTRL_COMMAND,preconditions:E.whenSheetEditorFocused};var cn=Object.getOwnPropertyDescriptor,un=(t,n,e,i)=>{for(var r=i>1?void 0:i?cn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},dt=(t,n)=>(e,i)=>n(e,i,t);let ke=class extends s.Disposable{constructor(t,n){super(),this._autoFillService=t,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const t=()=>({redos:[],undos:[]}),n=(i,r)=>{const{source:o,target:a,unitId:u,subUnitId:l}=i,h=E.virtualizeDiscreteRanges([o,a]),[d,p]=h.ranges,{mapFunc:I}=h,S={row:d.startRow,col:d.startColumn},R=E.getAutoFillRepeatRange(d,p),w=[],T=[];return R.forEach(c=>{const D=c.repeatStartCell,A=c.relativeRange,M={startRow:S.row,startColumn:S.col,endColumn:S.col,endRow:S.row},U={startRow:D.row,startColumn:D.col,endColumn:D.col,endRow:D.row};s.Range.foreach(A,(V,B)=>{const z=s.Rectangle.getPositionRange({startRow:V,startColumn:B,endColumn:B,endRow:V},M),{row:re,col:xe}=I(z.startRow,z.startColumn),se=this._hyperLinkModel.getHyperLinkByLocation(u,l,re,xe),Se=s.Rectangle.getPositionRange({startRow:V,startColumn:B,endColumn:B,endRow:V},U),{row:Ie,col:_e}=I(Se.startRow,Se.startColumn),Ae=s.generateRandomId(),ce=this._hyperLinkModel.getHyperLinkByLocation(u,l,Ie,_e);ce&&w.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:ce.id}}),(E.APPLY_TYPE.COPY===r||E.APPLY_TYPE.SERIES===r)&&se&&(w.push({id:_.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:{...se,id:Ae,row:Ie,column:_e}}}),T.push({id:_.RemoveHyperLinkMutation.id,params:{unitId:u,subUnitId:l,id:Ae}})),ce&&T.push({id:_.AddHyperLinkMutation.id,params:{unitId:u,subUnitId:l,link:ce}})})}),{undos:T,redos:w}},e={id:Ze,onFillData:(i,r,o)=>o===E.APPLY_TYPE.COPY||o===E.APPLY_TYPE.ONLY_FORMAT||o===E.APPLY_TYPE.SERIES?n(i,o):t()};this.disposeWithMe(this._autoFillService.addHook(e))}};ke=un([dt(0,E.IAutoFillService),dt(1,s.Inject(_.HyperLinkModel))],ke);var ln=Object.getOwnPropertyDescriptor,dn=(t,n,e,i)=>{for(var r=i>1?void 0:i?ln(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},We=(t,n)=>(e,i)=>n(e,i,t);let Oe=class extends s.Disposable{constructor(t,n,e){super(),this._localeService=t,this._commandService=n,this._sheetPermissionCheckController=e,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Ke.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookEditablePermission],rangeTypes:[f.RangeProtectionPermissionEditPoint],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetSetCellValuePermission,f.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};Oe=dn([We(0,s.Inject(s.LocaleService)),We(1,s.ICommandService),We(2,s.Inject(f.SheetPermissionCheckController))],Oe);var pn=Object.getOwnPropertyDescriptor,hn=(t,n,e,i)=>{for(var r=i>1?void 0:i?pn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},F=(t,n)=>(e,i)=>n(e,i,t);let Ne=class extends s.Disposable{constructor(t,n,e,i,r,o,a,u,l,h){super(),this._hoverManagerService=t,this._sheetsHyperLinkPopupService=n,this._renderManagerService=e,this._permissionService=i,this._sheetPermissionCheckController=r,this._commandService=o,this._editorBridgeService=a,this._textSelectionManagerService=u,this._univerInstanceService=l,this._zenZoneService=h,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(t){const{unitId:n,subUnitId:e,row:i,col:r}=t,o=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),a=o==null?void 0:o.getSheetBySheetId(e);if(!a)return{viewPermission:!1,editPermission:!1,copyPermission:!1};const u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookViewPermission],worksheetTypes:[f.WorksheetViewPermission],rangeTypes:[f.RangeProtectionPermissionViewPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}],n,e);let l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[f.WorkbookEditablePermission],worksheetTypes:[f.WorksheetEditPermission,f.WorksheetInsertHyperlinkPermission],rangeTypes:[f.RangeProtectionPermissionEditPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}],n,e);const h=a.getCellRaw(i,r);h!=null&&h.f&&h.f.startsWith("=HYPERLINK(")&&(l=!1);const d=this._permissionService.composePermission([new f.WorkbookCopyPermission(n).id,new f.WorksheetCopyPermission(n,e).id]).every(p=>p.value);return{viewPermission:u,editPermission:l,copyPermission:d}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(O.debounceTime(200)).subscribe(t=>{var M,U,V;if(!t||((M=t.customRange)==null?void 0:M.rangeType)!==s.CustomRangeType.HYPERLINK){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:e,row:i,col:r}=t,o=this._renderManagerService.getRenderById(n);if(!o)return;const a=this._univerInstanceService.getUnit(n,s.UniverInstanceType.UNIVER_SHEET),u=a==null?void 0:a.getSheetBySheetId(e);if(!u)return;if(!o.with(E.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING);return}const h=(U=o==null?void 0:o.with(E.SheetSkeletonManagerService).getSkeletonParam(e))==null?void 0:U.skeleton,d=r,p=i;let I=p,S=d;h&&h.overflowCache.forValue((B,z,re)=>{s.Rectangle.contains(re,{startColumn:d,endColumn:d,startRow:p,endRow:p})&&(I=B,S=z)});const{viewPermission:R,editPermission:w,copyPermission:T}=this._getLinkPermission(t);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=u.getCellStyleOnly(I,S),D=a.getStyles().getStyleByCell(c),A=(V=D==null?void 0:D.tr)==null?void 0:V.a;if(!A&&!t.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:I,col:S,editPermission:w,copyPermission:T,customRange:t.customRange,customRangeRect:t.rect,type:C.VIEWING,unitId:n,subUnitId:e,showAll:!!A})}))}_initHoverEditingListener(){let t=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(O.switchMap(n=>this._editorBridgeService.visible$.pipe(O.map(e=>({visible:e,state:n}))))).subscribe(({visible:n,state:e})=>{if(!e||e.editorUnitId!==s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){t==null||t.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.EDITING),this._sheetsHyperLinkPopupService.endEditing(C.EDITING);return}const{editorUnitId:i,unitId:r,sheetId:o,row:a,column:u}=e,l=this._renderManagerService.getRenderById(i);if(!l)return;const{editPermission:h,viewPermission:d,copyPermission:p}=this._getLinkPermission({unitId:r,subUnitId:o,row:a,col:u}),I=l.with(X.DocEventManagerService);d&&(t==null||t.unsubscribe(),t=I.hoverCustomRanges$.pipe(O.debounceTime(200)).subscribe(S=>{var D,A;const R=S.find(M=>M.range.rangeType===s.CustomRangeType.HYPERLINK);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const w=R.rects[R.rects.length-1];if(!((A=(D=this._renderManagerService.getRenderById(r))==null?void 0:D.with(E.SheetSkeletonManagerService).getSkeletonParam(o))==null?void 0:A.skeleton)||!w)return;const c=l.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:r,subUnitId:o,row:a,col:u,customRange:R.range,customRangeRect:{left:w.left+c.left,top:w.top+c.top,bottom:w.bottom+c.top,right:w.right+c.left},editPermission:h,copyPermission:p,type:C.EDITING})}))})),this.disposeWithMe(()=>{t==null||t.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t?(this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.EDITING),this._sheetsHyperLinkPopupService.endEditing(C.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(C.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(C.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(C.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(O.switchMap(t=>{const n=t===s.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(t):null;return n?n.with(X.DocEventManagerService).hoverCustomRanges$.pipe(O.debounceTime(200)):new O.Observable(e=>{e.next(null)})})).subscribe(t=>{const n=t==null?void 0:t.find(i=>i.range.rangeType===s.CustomRangeType.HYPERLINK),e=this._editorBridgeService.getEditCellState();if(n&&e){const{unitId:i,sheetId:r,row:o,column:a}=e,{editPermission:u,viewPermission:l,copyPermission:h}=this._getLinkPermission({unitId:i,subUnitId:r,row:o,col:a});l&&this._sheetsHyperLinkPopupService.showPopup({type:C.ZEN_EDITOR,unitId:i,subUnitId:r,row:o,col:a,customRange:n.range,editPermission:u,copyPermission:h})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(C.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(t=>{t&&t.unitId===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(C.EDITING)}))}_initCommandListener(){const t=[f.ClearSelectionContentCommand.id,f.ClearSelectionAllCommand.id,f.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{t.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ne=hn([F(0,s.Inject(E.HoverManagerService)),F(1,s.Inject(g.SheetsHyperLinkPopupService)),F(2,s.Inject(pe.IRenderManagerService)),F(3,s.Inject(s.IPermissionService)),F(4,s.Inject(f.SheetPermissionCheckController)),F(5,s.ICommandService),F(6,E.IEditorBridgeService),F(7,s.Inject(de.DocSelectionManagerService)),F(8,s.IUniverInstanceService),F(9,m.IZenZoneService)],Ne);var vn=Object.getOwnPropertyDescriptor,pt=(t,n,e,i)=>{for(var r=i>1?void 0:i?vn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},Ye=(t,n)=>(e,i)=>n(e,i,t);let Ge=class extends s.Disposable{constructor(t,n){super(),this._context=t,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const t=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(O.debounceTime(16)).subscribe(()=>{t()}))}};Ge=pt([Ye(1,s.Inject(_.HyperLinkModel))],Ge);let Me=class extends s.Disposable{constructor(t,n){super(),this._sheetInterceptorService=t,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value,priority:100,handler:(t,n,e)=>{const{row:i,col:r,unitId:o,subUnitId:a}=n,u=this._hyperLinkModel.getHyperLinkByLocation(o,a,i,r);return u&&t&&(t===n.rawData&&(t={...n.rawData}),t.linkUrl=u.payload,t.linkId=u.id),e(t)}}))}};Me=pt([Ye(0,s.Inject(f.SheetInterceptorService)),Ye(1,s.Inject(_.HyperLinkModel))],Me);const gn={[m.RibbonInsertGroup.MEDIA]:{[ie.id]:{order:1,menuItemFactory:on},[De(ie.id)]:{order:1,menuItemFactory:an}},[m.ContextMenuPosition.MAIN_AREA]:{[m.ContextMenuGroup.OTHERS]:{order:1,[ie.id]:{order:0,menuItemFactory:rn},[De(ie.id)]:{order:0,menuItemFactory:sn}}}};var Sn=Object.getOwnPropertyDescriptor,In=(t,n,e,i)=>{for(var r=i>1?void 0:i?Sn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ge=(t,n)=>(e,i)=>n(e,i,t);let Ue=class extends s.Disposable{constructor(t,n,e,i,r){super(),this._componentManager=t,this._commandService=n,this._menuManagerService=e,this._injector=i,this._shortcutService=r,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Pe.componentKey,Pe],[Ce.componentKey,Ce],["LinkIcon",Ve]].forEach(([t,n])=>{this._componentManager.register(t,n)})}_initCommands(){[Re,ve,Te,ie].forEach(t=>{this._commandService.registerCommand(t)})}_initMenus(){this._menuManagerService.mergeMenu(gn)}_initShortCut(){this._shortcutService.registerShortcut(Ke)}};Ue=In([ge(0,s.Inject(m.ComponentManager)),ge(1,s.ICommandService),ge(2,m.IMenuManagerService),ge(3,s.Inject(s.Injector)),ge(4,s.Inject(m.IShortcutService))],Ue);var _n=Object.getOwnPropertyDescriptor,mn=(t,n,e,i)=>{for(var r=i>1?void 0:i?_n(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},ht=(t,n)=>(e,i)=>n(e,i,t);let He=class extends s.Disposable{constructor(t,n){super(),this._parserService=t,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const t=location.hash;if(t){const n=this._parserService.parseHyperLink(t);this._resolverService.navigate(n)}}};He=mn([ht(0,s.Inject(_.SheetsHyperLinkParserService)),ht(1,s.Inject(g.SheetsHyperLinkResolverService))],He);var fn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Cn=(t,n,e)=>n in t?fn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,En=(t,n,e,i)=>{for(var r=i>1?void 0:i?yn(n,e):n,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=a(r)||r);return r},vt=(t,n)=>(e,i)=>n(e,i,t),gt=(t,n,e)=>Cn(t,typeof n!="symbol"?n+"":n,e);g.UniverSheetsHyperLinkUIPlugin=class extends s.Plugin{constructor(n=nt,e,i){super(),this._config=n,this._injector=e,this._configService=i;const{menu:r,...o}=s.merge({},nt,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(tt,o)}onStarting(){[[g.SheetsHyperLinkResolverService],[g.SheetsHyperLinkPopupService],[Be],[Me],[Ne],[Ue],[ke],[g.SheetsHyperLinkCopyPasteController],[Oe],[He]].forEach(e=>this._injector.add(e)),this._injector.get(Me)}onReady(){this._injector.get(pe.IRenderManagerService).registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[Ge]),this._injector.get(ke),this._injector.get(g.SheetsHyperLinkCopyPasteController),this._injector.get(Ue)}onRendered(){this._injector.get(Oe),this._injector.get(He),this._injector.get(Ne)}},gt(g.UniverSheetsHyperLinkUIPlugin,"pluginName",Ze),gt(g.UniverSheetsHyperLinkUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkUIPlugin=En([s.DependentOn(_.UniverSheetsHyperLinkPlugin,X.UniverDocsUIPlugin),vt(1,s.Inject(s.Injector)),vt(2,s.IConfigService)],g.UniverSheetsHyperLinkUIPlugin),g.CloseHyperLinkPopupOperation=ve,g.InsertHyperLinkOperation=Te,g.InsertLinkShortcut=Ke,g.OpenHyperLinkEditPanelOperation=Re,g.SheetsHyperLinkSidePanelService=Be,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link-ui",
3
- "version": "0.12.4",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -65,18 +65,18 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@univerjs/icons": "^1.0.2",
68
- "@univerjs/core": "0.12.4",
69
- "@univerjs/design": "0.12.4",
70
- "@univerjs/docs": "0.12.4",
71
- "@univerjs/docs-ui": "0.12.4",
72
- "@univerjs/engine-render": "0.12.4",
73
- "@univerjs/sheets": "0.12.4",
74
- "@univerjs/sheets-formula-ui": "0.12.4",
75
- "@univerjs/sheets-data-validation": "0.12.4",
76
- "@univerjs/engine-formula": "0.12.4",
77
- "@univerjs/sheets-hyper-link": "0.12.4",
78
- "@univerjs/sheets-ui": "0.12.4",
79
- "@univerjs/ui": "0.12.4"
68
+ "@univerjs/core": "0.13.0",
69
+ "@univerjs/design": "0.13.0",
70
+ "@univerjs/docs-ui": "0.13.0",
71
+ "@univerjs/engine-render": "0.13.0",
72
+ "@univerjs/engine-formula": "0.13.0",
73
+ "@univerjs/sheets": "0.13.0",
74
+ "@univerjs/docs": "0.13.0",
75
+ "@univerjs/sheets-data-validation": "0.13.0",
76
+ "@univerjs/sheets-ui": "0.13.0",
77
+ "@univerjs/sheets-hyper-link": "0.13.0",
78
+ "@univerjs/ui": "0.13.0",
79
+ "@univerjs/sheets-formula-ui": "0.13.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "postcss": "^8.5.6",
@@ -84,9 +84,9 @@
84
84
  "rxjs": "^7.8.2",
85
85
  "tailwindcss": "3.4.18",
86
86
  "typescript": "^5.9.3",
87
- "vite": "^7.2.6",
87
+ "vite": "^7.2.7",
88
88
  "vitest": "^4.0.15",
89
- "@univerjs-infra/shared": "0.12.4"
89
+ "@univerjs-infra/shared": "0.13.0"
90
90
  },
91
91
  "scripts": {
92
92
  "test": "vitest run",