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

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