@univerjs/docs-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 (41) hide show
  1. package/lib/cjs/index.js +860 -1
  2. package/lib/cjs/locale/ca-ES.js +24 -1
  3. package/lib/cjs/locale/en-US.js +39 -1
  4. package/lib/cjs/locale/es-ES.js +24 -1
  5. package/lib/cjs/locale/fa-IR.js +24 -1
  6. package/lib/cjs/locale/fr-FR.js +24 -1
  7. package/lib/cjs/locale/ja-JP.js +24 -1
  8. package/lib/cjs/locale/ko-KR.js +24 -1
  9. package/lib/cjs/locale/ru-RU.js +24 -1
  10. package/lib/cjs/locale/sk-SK.js +24 -1
  11. package/lib/cjs/locale/vi-VN.js +24 -1
  12. package/lib/cjs/locale/zh-CN.js +24 -1
  13. package/lib/cjs/locale/zh-TW.js +24 -1
  14. package/lib/es/index.js +854 -1
  15. package/lib/es/locale/ca-ES.js +23 -1
  16. package/lib/es/locale/en-US.js +38 -1
  17. package/lib/es/locale/es-ES.js +23 -1
  18. package/lib/es/locale/fa-IR.js +23 -1
  19. package/lib/es/locale/fr-FR.js +23 -1
  20. package/lib/es/locale/ja-JP.js +23 -1
  21. package/lib/es/locale/ko-KR.js +23 -1
  22. package/lib/es/locale/ru-RU.js +23 -1
  23. package/lib/es/locale/sk-SK.js +23 -1
  24. package/lib/es/locale/vi-VN.js +23 -1
  25. package/lib/es/locale/zh-CN.js +23 -1
  26. package/lib/es/locale/zh-TW.js +23 -1
  27. package/lib/index.js +854 -1
  28. package/lib/locale/ca-ES.js +23 -1
  29. package/lib/locale/en-US.js +38 -1
  30. package/lib/locale/es-ES.js +23 -1
  31. package/lib/locale/fa-IR.js +23 -1
  32. package/lib/locale/fr-FR.js +23 -1
  33. package/lib/locale/ja-JP.js +23 -1
  34. package/lib/locale/ko-KR.js +23 -1
  35. package/lib/locale/ru-RU.js +23 -1
  36. package/lib/locale/sk-SK.js +23 -1
  37. package/lib/locale/vi-VN.js +23 -1
  38. package/lib/locale/zh-CN.js +23 -1
  39. package/lib/locale/zh-TW.js +23 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +11 -11
package/lib/index.js CHANGED
@@ -1 +1,854 @@
1
- import{BuildTextUtils as e,CommandType as t,CustomRangeType as n,DOCS_NORMAL_EDITOR_UNIT_ID_KEY as r,DOCS_ZEN_EDITOR_UNIT_ID_KEY as i,DependentOn as a,Disposable as o,ICommandService as s,IConfigService as c,IUniverInstanceService as l,Inject as u,Injector as d,LocaleService as f,Plugin as p,Tools as m,UniverInstanceType as h,generateRandomId as g,getBodySlice as _,merge as v}from"@univerjs/core";import{UniverDocsHyperLinkPlugin as y}from"@univerjs/docs-hyper-link";import{IRenderManagerService as b}from"@univerjs/engine-render";import{DOC_INTERCEPTOR_POINT as x,DocInterceptorService as S,DocSelectionManagerService as C,DocSkeletonManagerService as ee,SetTextSelectionsOperation as te,addCustomRangeBySelectionFactory as ne,deleteCustomRangeFactory as re,replaceSelectionFactory as ie}from"@univerjs/docs";import{DocCanvasPopManagerService as ae,DocEventManagerService as oe,DocRenderController as se,whenDocAndEditorFocused as ce}from"@univerjs/docs-ui";import{BehaviorSubject as le,Observable as ue,debounceTime as de,distinctUntilChanged as fe,pairwise as pe}from"rxjs";import{Button as w,FormLayout as T,Input as E,MessageType as me,Tooltip as D,borderClassName as O,clsx as he}from"@univerjs/design";import{ComponentManager as ge,ContextMenuGroup as _e,ContextMenuPosition as ve,IMenuManagerService as ye,IMessageService as be,IShortcutService as xe,KeyCode as k,MenuItemType as Se,MetaKeys as Ce,RibbonInsertGroup as we,getMenuHiddenObservable as Te,useDependency as A,useObservable as j}from"@univerjs/ui";import{useEffect as Ee,useState as M}from"react";import{jsx as N,jsxs as P}from"react/jsx-runtime";import{CopyIcon as De,LinkIcon as F,UnlinkIcon as Oe,WriteIcon as ke}from"@univerjs/icons";var Ae=`@univerjs/docs-hyper-link-ui`,je=`0.20.1`;const I=`docs-hyper-link-ui.config`;Symbol(I);const L={},Me={type:t.COMMAND,id:`docs.command.add-hyper-link`,async handler(e,t){if(!t)return!1;let{payload:r,unitId:i,selections:a}=t,o=e.get(s),c=ne(e,{rangeId:g(),rangeType:n.HYPERLINK,properties:{url:r},unitId:i,selections:a});return c?o.syncExecuteCommand(c.id,c.params):!1}},R={id:`docs.command.update-hyper-link`,type:t.COMMAND,handler(e,t){var r;if(!t)return!1;let{unitId:i,payload:a,segmentId:o,linkId:c}=t,u=e.get(s),d=e.get(l),f=e.get(C).getActiveTextRange(),p=d.getUnit(i,h.UNIVER_DOC);if(!f||!p)return!1;let m=(r=_(p.getSelfOrHeaderFooterModel(o).getBody(),f.startOffset,f.endOffset).textRuns)==null?void 0:r[0];m&&(m.ed=t.label.length+1);let g=ie(e,{unitId:i,body:{dataStream:`${t.label}`,customRanges:[{rangeId:c,rangeType:n.HYPERLINK,startIndex:0,endIndex:t.label.length+1,properties:{url:a}}],textRuns:m?[m]:void 0},selection:{startOffset:f.startOffset,endOffset:f.endOffset,collapsed:!1,segmentId:o}});return g?u.syncExecuteCommand(g.id,g.params):!1}};function z(e){return e.trim().length===0}function Ne(e){return/^[a-zA-Z]+:\/\//.test(e)}function Pe(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Fe(e){return Ne(e)?e:Pe(e)?`mailto://${e}`:`https://${e}`}const B=()=>{let t=A(J),n=A(f),r=j(t.editingLink$),i=A(s),a=A(l),o=A(C),[c,u]=M(``),[d,p]=M(``),[g,v]=M(!1),y=m.isLegalUrl(c),b=r?a.getUnit(r.unitId,h.UNIVER_DOC):a.getCurrentUnitForType(h.UNIVER_DOC);Ee(()=>{var t,n,i;let a=o.getActiveTextRange();if(!a)return;if(r){var s,c;let t=b==null||(s=b.getSelfOrHeaderFooterModel(r.segmentId))==null?void 0:s.getBody(),n=t==null||(c=t.customRanges)==null?void 0:c.find(e=>(r==null?void 0:r.linkId)===e.rangeId&&e.startIndex===r.startIndex&&e.endIndex===r.endIndex);if(b&&n){var l,d;u((l=(d=n.properties)==null?void 0:d.url)==null?``:l),p(e.transform.getPlainText(_(t,n.startIndex,n.endIndex+1).dataStream))}return}let f=b==null||(t=b.getSelfOrHeaderFooterModel(a.segmentId))==null?void 0:t.getBody(),m=f?a:null,h=m&&((n=e.customRange.getCustomRangesInterestsWithSelection(m,(i=f==null?void 0:f.customRanges)==null?[]:i))==null?void 0:n[0]);if(b&&h){var g,v;u((g=h==null||(v=h.properties)==null?void 0:v.url)==null?``:g)}},[b,r,o,a]);let x=()=>{t.hideEditPopup()},S=()=>{if(v(!0),!y||!b)return;let e=Fe(c);if(!r)i.executeCommand(Me.id,{unitId:b.getUnitId(),payload:e});else{if(z(d))return;i.executeCommand(R.id,{unitId:b.getUnitId(),payload:e,linkId:r.linkId,label:d,segmentId:r.segmentId})}t.hideEditPopup()};if(b)return P(`div`,{className:he(`univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900`,O),children:[P(`div`,{children:[r?N(T,{label:n.t(`docLink.edit.label`),error:g&&z(d)?n.t(`docLink.edit.labelError`):``,children:N(E,{value:d,onChange:p,autoFocus:!0,onKeyDown:e=>{e.keyCode===k.ENTER&&S()}})}):null,N(T,{label:n.t(`docLink.edit.address`),error:g&&!y?n.t(`docLink.edit.addressError`):``,children:N(E,{value:c,onChange:u,autoFocus:!0,onKeyDown:e=>{e.keyCode===k.ENTER&&S()}})})]}),P(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[N(w,{onClick:x,children:n.t(`docLink.edit.cancel`)}),N(w,{variant:`primary`,disabled:z(c),onClick:S,children:n.t(`docLink.edit.confirm`)})]})]})};B.componentKey=`docs-hyper-link-edit`;const Ie={type:t.COMMAND,id:`docs.command.delete-hyper-link`,async handler(e,t){if(!t)return!1;let{unitId:n,linkId:r,segmentId:i}=t,a=e.get(s),o=re(e,{unitId:n,rangeId:r,segmentId:i});return o?await a.syncExecuteCommand(o.id,o.params):!1}},Le=e=>{let t=e.get(C),n=e.get(l),r=t.getTextRanges();if(!(r!=null&&r.length))return!0;let i=r[0];return!!(!n.getCurrentUnitForType(h.UNIVER_DOC)||!i||i.collapsed)},V={type:t.OPERATION,id:`doc.operation.show-hyper-link-edit-popup`,handler(e,t){var n;let r=t==null?void 0:t.link,i=e.get(l);if(Le(e)&&!r)return!1;let a=e.get(J),o=(r==null?void 0:r.unitId)||((n=i.getCurrentUnitForType(h.UNIVER_DOC))==null?void 0:n.getUnitId());return o?(a.showEditPopup(o,r),!0):!1}},H={type:t.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(J);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},Re={type:t.OPERATION,id:`doc.operation.click-hyper-link`,handler(e,t){var r;if(!t)return!1;let{unitId:i,linkId:a,segmentId:o}=t,s=e.get(l).getUnit(i,h.UNIVER_DOC),c=s==null?void 0:s.getSelfOrHeaderFooterModel(o).getBody(),u=c==null||(r=c.customRanges)==null||(r=r.find(e=>e.rangeId===a&&e.rangeType===n.HYPERLINK))==null||(r=r.properties)==null?void 0:r.url;return u&&window.open(u,`_blank`,`noopener noreferrer`),!0}},U=()=>{var e,t;let r=A(J),i=A(s),a=A(be),o=A(f),c=j(r.showingLink$),u=A(l);if(!c)return null;let{unitId:d,linkId:p,segmentId:m,startIndex:g,endIndex:_}=c,v=u.getUnit(d,h.UNIVER_DOC),y=v==null?void 0:v.getSelfOrHeaderFooterModel(m).getBody(),b=y==null||(e=y.customRanges)==null?void 0:e.find(e=>e.rangeId===p&&e.rangeType===n.HYPERLINK&&e.startIndex===g&&e.endIndex===_);if(!b)return null;let x=(t=b.properties)==null?void 0:t.url;return P(`div`,{className:he(`univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900`,O),onClick:()=>{r.hideInfoPopup()},children:[P(`div`,{className:`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500`,onClick:()=>window.open(x,void 0,`noopener noreferrer`),children:[N(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white`,children:N(F,{})}),N(D,{showIfEllipsis:!0,title:x,children:N(`span`,{className:`univer-flex-1 univer-truncate`,children:x})})]}),P(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[N(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{navigator.clipboard.writeText(x),a.show({content:o.t(`docLink.info.coped`),type:me.Info})},children:N(D,{placement:`bottom`,title:o.t(`docLink.info.copy`),children:N(De,{})})}),N(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{i.executeCommand(V.id,{link:c})},children:N(D,{placement:`bottom`,title:o.t(`docLink.info.edit`),children:N(ke,{})})}),N(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{i.executeCommand(Ie.id,{unitId:d,linkId:b.rangeId,segmentId:m})},children:N(D,{placement:`bottom`,title:o.t(`docLink.info.cancel`),children:N(Oe,{})})})]})]})};U.componentKey=`univer.doc.link-info-popup`;function W(e){"@babel/helpers - typeof";return W=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},W(e)}function ze(e,t){if(W(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(W(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Be(e){var t=ze(e,`string`);return W(t)==`symbol`?t:t+``}function G(e,t,n){return(t=Be(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function K(e,t){return function(n,r){t(n,r,e)}}function q(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let J=class extends o{constructor(e,t,n){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,G(this,`_editingLink$`,new le(null)),G(this,`_showingLink$`,new le(null)),G(this,`editingLink$`,this._editingLink$.asObservable()),G(this,`showingLink$`,this._showingLink$.asObservable()),G(this,`_editPopup`,null),G(this,`_infoPopup`,null),this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);let n=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e}),r=n==null?void 0:n[n.length-1];if(t){let{segmentId:e,segmentPage:n,startIndex:i,endIndex:a}=t;r={collapsed:!1,startOffset:i,endOffset:a+1,segmentId:e,segmentPage:n},this._textSelectionManagerService.replaceDocRanges([{startOffset:i,endOffset:a+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:B.componentKey,direction:`bottom`},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var t,n,r,i,a,o;let{linkId:s,unitId:c,segmentId:l,segmentPage:u,startIndex:d,endIndex:f}=e;if(!(((t=this.showing)==null?void 0:t.linkId)===s&&((n=this.showing)==null?void 0:n.unitId)===c&&((r=this.showing)==null?void 0:r.segmentId)===l&&((i=this.showing)==null?void 0:i.segmentPage)===u&&((a=this.showing)==null?void 0:a.startIndex)===d&&((o=this.showing)==null?void 0:o.endIndex)===f)&&(this._infoPopup&&this._infoPopup.dispose(),this._univerInstanceService.getUnit(c,h.UNIVER_DOC)))return this._showingLink$.next({unitId:c,linkId:s,segmentId:l,segmentPage:u,startIndex:d,endIndex:f}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:d,endOffset:f+1,segmentId:l,segmentPage:u},{componentKey:U.componentKey,direction:`top-center`,multipleDirection:`top`,onClickOutside:()=>{this.hideInfoPopup()}},c),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};J=q([K(0,u(ae)),K(1,u(C)),K(2,l)],J);let Y=class extends o{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._docHyperLinkService=n,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===te.id){let{unitId:r,ranges:i,segmentId:a}=e.params,o=this._univerInstanceService.getUnit(r,h.UNIVER_DOC),s=i[0];if(s&&o){var t;let{startOffset:e,endOffset:i,collapsed:c,segmentPage:l}=s,u=(t=o.getSelfOrHeaderFooterModel(a))==null||(t=t.getBody())==null?void 0:t.customRanges;if(c){var n;let t=(n=u==null?void 0:u.findIndex(t=>t.startIndex<e&&t.endIndex>i-1))==null?-1:n;if(t>-1){let e=u[t];this._docHyperLinkService.showInfoPopup({unitId:r,linkId:e.rangeId,segmentId:a,segmentPage:l,startIndex:e.startIndex,endIndex:e.endIndex});return}}else if(u!=null&&u.find(t=>t.startIndex<=e&&t.endIndex>=i-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};Y=q([K(0,s),K(1,l),K(2,u(J))],Y);let X=class extends o{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,t,n,a,o,s){super(),this._context=e,this._docEventManagerService=t,this._commandService=n,this._hyperLinkPopupService=a,this._docSkeletonManagerService=o,this._docSelectionManagerService=s,!(this._context.unitId===i||this._context.unitId===r)&&(this._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(H.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(e=>{var t;let r=e.find(e=>e.range.rangeType===n.HYPERLINK),i=this._docSelectionManagerService.getTextRanges(),a=i==null?void 0:i[0].segmentId;if(((t=r==null?void 0:r.segmentId)==null?``:t)!==a){this._hideInfoPopup();return}r?this._commandService.executeCommand(H.id,{unitId:this._context.unitId,linkId:r.range.rangeId,segmentId:r.segmentId,segmentPage:r.segmentPageIndex,rangeId:r.range.rangeId,startIndex:r.range.startIndex,endIndex:r.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;t&&this._commandService.executeCommand(Re.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}))}};X=q([K(1,u(oe)),K(2,s),K(3,u(J)),K(4,u(ee)),K(5,u(C))],X);let Z=class extends o{constructor(e,t,n,r){super(),this._context=e,this._docInterceptorService=t,this._hyperLinkService=n,this._docRenderController=r,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(x.CUSTOM_RANGE,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i}=t,a=this._hyperLinkService.showing;if(!a)return n({...e,active:!1});let{linkId:o,unitId:s,startIndex:c,endIndex:l}=a,u=s===r&&e.rangeId===o&&i>=c&&i<=l;return n({...e,active:u})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(fe((e,t)=>(e==null?void 0:e.linkId)===(t==null?void 0:t.linkId)&&(e==null?void 0:e.unitId)===(t==null?void 0:t.unitId)&&(e==null?void 0:e.startIndex)===(t==null?void 0:t.startIndex)),pe()).subscribe(([e,t])=>{t?t.unitId===this._context.unitId&&this._docRenderController.reRender(t.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};Z=q([K(1,u(S)),K(2,u(J)),K(3,u(se))],Z);const Ve=`doc-hyper-link-icon`;function He(e){return{id:V.id,type:Se.BUTTON,icon:Ve,title:`docLink.menu.tooltip`,tooltip:`docLink.menu.tooltip`,hidden$:Te(e,h.UNIVER_DOC),disabled$:new ue(function(t){let n=e.get(C).textSelection$.pipe(de(16)).subscribe(()=>{t.next(Le(e))});return()=>{n.unsubscribe()}})}}const Ue={id:V.id,binding:Ce.CTRL_COMMAND|k.K,description:`docLink.menu.tooltip`,preconditions:ce},We={[we.MEDIA]:{[V.id]:{order:1,menuItemFactory:He}},[ve.MAIN_AREA]:{[_e.DATA]:{[V.id]:{order:0,menuItemFactory:He}}}};let Q=class extends o{constructor(e,t,n,r){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._shortcutService=r,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[B.componentKey,B],[U.componentKey,U],[Ve,F]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initCommands(){[Me,R,Ie,V,H,Re].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[Ue].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.mergeMenu(We)}};Q=q([K(0,u(ge)),K(1,s),K(2,ye),K(3,xe)],Q);let $=class extends p{constructor(e=L,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=r;let{menu:i,...a}=v({},L,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(I,a)}onStarting(){[[J],[Q],[Y]].forEach(e=>{this._injector.add(e)}),this._injector.get(Q)}onReady(){this._injector.get(Y)}onRendered(){this._initRenderModule()}_initRenderModule(){[[Z],[X]].forEach(e=>{this._renderManagerSrv.registerRenderModule(h.UNIVER_DOC,e)})}};G($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),G($,`packageName`,Ae),G($,`version`,je),G($,`type`,h.UNIVER_DOC),$=q([a(y),K(1,u(d)),K(2,b),K(3,c)],$);export{$ as UniverDocsHyperLinkUIPlugin};
1
+ import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, generateRandomId, getBodySlice, merge } from "@univerjs/core";
2
+ import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
3
+ import { IRenderManagerService } from "@univerjs/engine-render";
4
+ import { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, SetTextSelectionsOperation, addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
5
+ import { DocCanvasPopManagerService, DocEventManagerService, DocRenderController, whenDocAndEditorFocused } from "@univerjs/docs-ui";
6
+ import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
7
+ import { Button, FormLayout, Input, MessageType, Tooltip, borderClassName, clsx } from "@univerjs/design";
8
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IShortcutService, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
9
+ import { useEffect, useState } from "react";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
12
+
13
+ //#region package.json
14
+ var name = "@univerjs/docs-hyper-link-ui";
15
+ var version = "0.21.0";
16
+
17
+ //#endregion
18
+ //#region src/config/config.ts
19
+ const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
20
+ const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
21
+ const defaultPluginConfig = {};
22
+
23
+ //#endregion
24
+ //#region src/commands/commands/add-link.command.ts
25
+ const AddDocHyperLinkCommand = {
26
+ type: CommandType.COMMAND,
27
+ id: "docs.command.add-hyper-link",
28
+ async handler(accessor, params) {
29
+ if (!params) return false;
30
+ const { payload, unitId, selections } = params;
31
+ const commandService = accessor.get(ICommandService);
32
+ const doMutation = addCustomRangeBySelectionFactory(accessor, {
33
+ rangeId: generateRandomId(),
34
+ rangeType: CustomRangeType.HYPERLINK,
35
+ properties: { url: payload },
36
+ unitId,
37
+ selections
38
+ });
39
+ if (doMutation) return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
40
+ return false;
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ //#region src/commands/commands/update-link.command.ts
46
+ const UpdateDocHyperLinkCommand = {
47
+ id: "docs.command.update-hyper-link",
48
+ type: CommandType.COMMAND,
49
+ handler(accessor, params) {
50
+ var _oldBody$textRuns;
51
+ if (!params) return false;
52
+ const { unitId, payload, segmentId, linkId } = params;
53
+ const commandService = accessor.get(ICommandService);
54
+ const univerInstanceService = accessor.get(IUniverInstanceService);
55
+ const currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange();
56
+ const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
57
+ if (!currentSelection || !doc) return false;
58
+ const textRun = (_oldBody$textRuns = getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(), currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _oldBody$textRuns === void 0 ? void 0 : _oldBody$textRuns[0];
59
+ if (textRun) textRun.ed = params.label.length + 1;
60
+ const replaceSelection = replaceSelectionFactory(accessor, {
61
+ unitId,
62
+ body: {
63
+ dataStream: `${params.label}`,
64
+ customRanges: [{
65
+ rangeId: linkId,
66
+ rangeType: CustomRangeType.HYPERLINK,
67
+ startIndex: 0,
68
+ endIndex: params.label.length + 1,
69
+ properties: { url: payload }
70
+ }],
71
+ textRuns: textRun ? [textRun] : void 0
72
+ },
73
+ selection: {
74
+ startOffset: currentSelection.startOffset,
75
+ endOffset: currentSelection.endOffset,
76
+ collapsed: false,
77
+ segmentId
78
+ }
79
+ });
80
+ if (!replaceSelection) return false;
81
+ return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
82
+ }
83
+ };
84
+
85
+ //#endregion
86
+ //#region src/views/hyper-link-edit/utils.ts
87
+ /**
88
+ * Copyright 2023-present DreamNum Co., Ltd.
89
+ *
90
+ * Licensed under the Apache License, Version 2.0 (the "License");
91
+ * you may not use this file except in compliance with the License.
92
+ * You may obtain a copy of the License at
93
+ *
94
+ * http://www.apache.org/licenses/LICENSE-2.0
95
+ *
96
+ * Unless required by applicable law or agreed to in writing, software
97
+ * distributed under the License is distributed on an "AS IS" BASIS,
98
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99
+ * See the License for the specific language governing permissions and
100
+ * limitations under the License.
101
+ */
102
+ function isBlankInput(value) {
103
+ return value.trim().length === 0;
104
+ }
105
+
106
+ //#endregion
107
+ //#region src/views/hyper-link-edit/index.tsx
108
+ function hasProtocol(urlString) {
109
+ return /^[a-zA-Z]+:\/\//.test(urlString);
110
+ }
111
+ function isEmail(url) {
112
+ return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
113
+ }
114
+ function transformUrl(urlStr) {
115
+ return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
116
+ }
117
+ const DocHyperLinkEdit = () => {
118
+ const hyperLinkService = useDependency(DocHyperLinkPopupService);
119
+ const localeService = useDependency(LocaleService);
120
+ const editing = useObservable(hyperLinkService.editingLink$);
121
+ const commandService = useDependency(ICommandService);
122
+ const univerInstanceService = useDependency(IUniverInstanceService);
123
+ const docSelectionManagerService = useDependency(DocSelectionManagerService);
124
+ const [link, setLink] = useState("");
125
+ const [label, setLabel] = useState("");
126
+ const [showError, setShowError] = useState(false);
127
+ const isLegal = Tools.isLegalUrl(link);
128
+ const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
129
+ useEffect(() => {
130
+ var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
131
+ const activeRange = docSelectionManagerService.getActiveTextRange();
132
+ if (!activeRange) return;
133
+ if (editing) {
134
+ var _doc$getSelfOrHeaderF, _body$customRanges;
135
+ const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
136
+ const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
137
+ if (doc && matchedRange) {
138
+ var _matchedRange$propert, _matchedRange$propert2;
139
+ setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
140
+ setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
141
+ }
142
+ return;
143
+ }
144
+ const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
145
+ const selection = body ? activeRange : null;
146
+ const matchedRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges2 = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges2 !== void 0 ? _body$customRanges2 : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
147
+ if (doc && matchedRange) {
148
+ var _matchedRange$propert3, _matchedRange$propert4;
149
+ setLink((_matchedRange$propert3 = matchedRange === null || matchedRange === void 0 || (_matchedRange$propert4 = matchedRange.properties) === null || _matchedRange$propert4 === void 0 ? void 0 : _matchedRange$propert4.url) !== null && _matchedRange$propert3 !== void 0 ? _matchedRange$propert3 : "");
150
+ }
151
+ }, [
152
+ doc,
153
+ editing,
154
+ docSelectionManagerService,
155
+ univerInstanceService
156
+ ]);
157
+ const handleCancel = () => {
158
+ hyperLinkService.hideEditPopup();
159
+ };
160
+ const handleConfirm = () => {
161
+ setShowError(true);
162
+ if (!isLegal || !doc) return;
163
+ const linkFinal = transformUrl(link);
164
+ if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
165
+ unitId: doc.getUnitId(),
166
+ payload: linkFinal
167
+ });
168
+ else {
169
+ if (isBlankInput(label)) return;
170
+ commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
171
+ unitId: doc.getUnitId(),
172
+ payload: linkFinal,
173
+ linkId: editing.linkId,
174
+ label,
175
+ segmentId: editing.segmentId
176
+ });
177
+ }
178
+ hyperLinkService.hideEditPopup();
179
+ };
180
+ if (!doc) return;
181
+ return /* @__PURE__ */ jsxs("div", {
182
+ className: clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", borderClassName),
183
+ children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
184
+ label: localeService.t("docLink.edit.label"),
185
+ error: showError && isBlankInput(label) ? localeService.t("docLink.edit.labelError") : "",
186
+ children: /* @__PURE__ */ jsx(Input, {
187
+ value: label,
188
+ onChange: setLabel,
189
+ autoFocus: true,
190
+ onKeyDown: (evt) => {
191
+ if (evt.keyCode === KeyCode.ENTER) handleConfirm();
192
+ }
193
+ })
194
+ }) : null, /* @__PURE__ */ jsx(FormLayout, {
195
+ label: localeService.t("docLink.edit.address"),
196
+ error: showError && !isLegal ? localeService.t("docLink.edit.addressError") : "",
197
+ children: /* @__PURE__ */ jsx(Input, {
198
+ value: link,
199
+ onChange: setLink,
200
+ autoFocus: true,
201
+ onKeyDown: (evt) => {
202
+ if (evt.keyCode === KeyCode.ENTER) handleConfirm();
203
+ }
204
+ })
205
+ })] }), /* @__PURE__ */ jsxs("div", {
206
+ className: "univer-flex univer-justify-end univer-gap-3",
207
+ children: [/* @__PURE__ */ jsx(Button, {
208
+ onClick: handleCancel,
209
+ children: localeService.t("docLink.edit.cancel")
210
+ }), /* @__PURE__ */ jsx(Button, {
211
+ variant: "primary",
212
+ disabled: isBlankInput(link),
213
+ onClick: handleConfirm,
214
+ children: localeService.t("docLink.edit.confirm")
215
+ })]
216
+ })]
217
+ });
218
+ };
219
+ DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
220
+
221
+ //#endregion
222
+ //#region src/commands/commands/delete-link.command.ts
223
+ const DeleteDocHyperLinkCommand = {
224
+ type: CommandType.COMMAND,
225
+ id: "docs.command.delete-hyper-link",
226
+ async handler(accessor, params) {
227
+ if (!params) return false;
228
+ const { unitId, linkId, segmentId } = params;
229
+ const commandService = accessor.get(ICommandService);
230
+ const doMutation = deleteCustomRangeFactory(accessor, {
231
+ unitId,
232
+ rangeId: linkId,
233
+ segmentId
234
+ });
235
+ if (!doMutation) return false;
236
+ return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
237
+ }
238
+ };
239
+
240
+ //#endregion
241
+ //#region src/commands/operations/popup.operation.ts
242
+ const shouldDisableAddLink = (accessor) => {
243
+ const textSelectionService = accessor.get(DocSelectionManagerService);
244
+ const univerInstanceService = accessor.get(IUniverInstanceService);
245
+ const textRanges = textSelectionService.getTextRanges();
246
+ if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
247
+ const activeRange = textRanges[0];
248
+ if (!univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed) return true;
249
+ return false;
250
+ };
251
+ const ShowDocHyperLinkEditPopupOperation = {
252
+ type: CommandType.OPERATION,
253
+ id: "doc.operation.show-hyper-link-edit-popup",
254
+ handler(accessor, params) {
255
+ var _univerInstanceServic;
256
+ const linkInfo = params === null || params === void 0 ? void 0 : params.link;
257
+ const univerInstanceService = accessor.get(IUniverInstanceService);
258
+ if (shouldDisableAddLink(accessor) && !linkInfo) return false;
259
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService);
260
+ const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
261
+ if (!unitId) return false;
262
+ hyperLinkService.showEditPopup(unitId, linkInfo);
263
+ return true;
264
+ }
265
+ };
266
+ const ToggleDocHyperLinkInfoPopupOperation = {
267
+ type: CommandType.OPERATION,
268
+ id: "doc.operation.toggle-hyper-link-info-popup",
269
+ handler(accessor, params) {
270
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService);
271
+ if (!params) {
272
+ hyperLinkService.hideInfoPopup();
273
+ return true;
274
+ }
275
+ hyperLinkService.showInfoPopup(params);
276
+ return true;
277
+ }
278
+ };
279
+ const ClickDocHyperLinkOperation = {
280
+ type: CommandType.OPERATION,
281
+ id: "doc.operation.click-hyper-link",
282
+ handler(accessor, params) {
283
+ var _body$customRanges;
284
+ if (!params) return false;
285
+ const { unitId, linkId, segmentId } = params;
286
+ const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
287
+ const body = doc === null || doc === void 0 ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody();
288
+ const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
289
+ if (link) window.open(link, "_blank", "noopener noreferrer");
290
+ return true;
291
+ }
292
+ };
293
+
294
+ //#endregion
295
+ //#region src/views/hyper-link-popup/index.tsx
296
+ const DocLinkPopup = () => {
297
+ var _body$customRanges, _link$properties;
298
+ const hyperLinkService = useDependency(DocHyperLinkPopupService);
299
+ const commandService = useDependency(ICommandService);
300
+ const messageService = useDependency(IMessageService);
301
+ const localeService = useDependency(LocaleService);
302
+ const currentPopup = useObservable(hyperLinkService.showingLink$);
303
+ const univerInstanceService = useDependency(IUniverInstanceService);
304
+ if (!currentPopup) return null;
305
+ const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
306
+ const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
307
+ const body = doc === null || doc === void 0 ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody();
308
+ const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
309
+ if (!link) return null;
310
+ const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
311
+ return /* @__PURE__ */ jsxs("div", {
312
+ className: clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900", borderClassName),
313
+ onClick: () => {
314
+ hyperLinkService.hideInfoPopup();
315
+ },
316
+ children: [/* @__PURE__ */ jsxs("div", {
317
+ className: "univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",
318
+ onClick: () => window.open(url, void 0, "noopener noreferrer"),
319
+ children: [/* @__PURE__ */ jsx("div", {
320
+ className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",
321
+ children: /* @__PURE__ */ jsx(LinkIcon, {})
322
+ }), /* @__PURE__ */ jsx(Tooltip, {
323
+ showIfEllipsis: true,
324
+ title: url,
325
+ children: /* @__PURE__ */ jsx("span", {
326
+ className: "univer-flex-1 univer-truncate",
327
+ children: url
328
+ })
329
+ })]
330
+ }), /* @__PURE__ */ jsxs("div", {
331
+ className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",
332
+ children: [
333
+ /* @__PURE__ */ jsx("div", {
334
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
335
+ onClick: () => {
336
+ navigator.clipboard.writeText(url);
337
+ messageService.show({
338
+ content: localeService.t("docLink.info.coped"),
339
+ type: MessageType.Info
340
+ });
341
+ },
342
+ children: /* @__PURE__ */ jsx(Tooltip, {
343
+ placement: "bottom",
344
+ title: localeService.t("docLink.info.copy"),
345
+ children: /* @__PURE__ */ jsx(CopyIcon, {})
346
+ })
347
+ }),
348
+ /* @__PURE__ */ jsx("div", {
349
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
350
+ onClick: () => {
351
+ commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
352
+ },
353
+ children: /* @__PURE__ */ jsx(Tooltip, {
354
+ placement: "bottom",
355
+ title: localeService.t("docLink.info.edit"),
356
+ children: /* @__PURE__ */ jsx(WriteIcon, {})
357
+ })
358
+ }),
359
+ /* @__PURE__ */ jsx("div", {
360
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
361
+ onClick: () => {
362
+ commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
363
+ unitId,
364
+ linkId: link.rangeId,
365
+ segmentId
366
+ });
367
+ },
368
+ children: /* @__PURE__ */ jsx(Tooltip, {
369
+ placement: "bottom",
370
+ title: localeService.t("docLink.info.cancel"),
371
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
372
+ })
373
+ })
374
+ ]
375
+ })]
376
+ });
377
+ };
378
+ DocLinkPopup.componentKey = "univer.doc.link-info-popup";
379
+
380
+ //#endregion
381
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
382
+ function _typeof(o) {
383
+ "@babel/helpers - typeof";
384
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
385
+ return typeof o;
386
+ } : function(o) {
387
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
388
+ }, _typeof(o);
389
+ }
390
+
391
+ //#endregion
392
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
393
+ function toPrimitive(t, r) {
394
+ if ("object" != _typeof(t) || !t) return t;
395
+ var e = t[Symbol.toPrimitive];
396
+ if (void 0 !== e) {
397
+ var i = e.call(t, r || "default");
398
+ if ("object" != _typeof(i)) return i;
399
+ throw new TypeError("@@toPrimitive must return a primitive value.");
400
+ }
401
+ return ("string" === r ? String : Number)(t);
402
+ }
403
+
404
+ //#endregion
405
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
406
+ function toPropertyKey(t) {
407
+ var i = toPrimitive(t, "string");
408
+ return "symbol" == _typeof(i) ? i : i + "";
409
+ }
410
+
411
+ //#endregion
412
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
413
+ function _defineProperty(e, r, t) {
414
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
415
+ value: t,
416
+ enumerable: !0,
417
+ configurable: !0,
418
+ writable: !0
419
+ }) : e[r] = t, e;
420
+ }
421
+
422
+ //#endregion
423
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
424
+ function __decorateParam(paramIndex, decorator) {
425
+ return function(target, key) {
426
+ decorator(target, key, paramIndex);
427
+ };
428
+ }
429
+
430
+ //#endregion
431
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
432
+ function __decorate(decorators, target, key, desc) {
433
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
434
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
435
+ 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;
436
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
437
+ }
438
+
439
+ //#endregion
440
+ //#region src/services/hyper-link-popup.service.ts
441
+ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable {
442
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
443
+ super();
444
+ this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
445
+ this._textSelectionManagerService = _textSelectionManagerService;
446
+ this._univerInstanceService = _univerInstanceService;
447
+ _defineProperty(this, "_editingLink$", new BehaviorSubject(null));
448
+ _defineProperty(this, "_showingLink$", new BehaviorSubject(null));
449
+ _defineProperty(this, "editingLink$", this._editingLink$.asObservable());
450
+ _defineProperty(this, "showingLink$", this._showingLink$.asObservable());
451
+ _defineProperty(this, "_editPopup", null);
452
+ _defineProperty(this, "_infoPopup", null);
453
+ this.disposeWithMe(() => {
454
+ this._editingLink$.complete();
455
+ this._showingLink$.complete();
456
+ });
457
+ }
458
+ get editing() {
459
+ return this._editingLink$.value;
460
+ }
461
+ get showing() {
462
+ return this._showingLink$.value;
463
+ }
464
+ showEditPopup(unitId, linkInfo) {
465
+ if (this._editPopup) this._editPopup.dispose();
466
+ this._editingLink$.next(linkInfo);
467
+ const textRanges = this._textSelectionManagerService.getTextRanges({
468
+ unitId,
469
+ subUnitId: unitId
470
+ });
471
+ let activeRange = textRanges === null || textRanges === void 0 ? void 0 : textRanges[textRanges.length - 1];
472
+ if (linkInfo) {
473
+ const { segmentId, segmentPage, startIndex, endIndex } = linkInfo;
474
+ activeRange = {
475
+ collapsed: false,
476
+ startOffset: startIndex,
477
+ endOffset: endIndex + 1,
478
+ segmentId,
479
+ segmentPage
480
+ };
481
+ this._textSelectionManagerService.replaceDocRanges([{
482
+ startOffset: startIndex,
483
+ endOffset: endIndex + 1
484
+ }]);
485
+ }
486
+ if (activeRange) {
487
+ this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
488
+ componentKey: DocHyperLinkEdit.componentKey,
489
+ direction: "bottom"
490
+ }, unitId);
491
+ return this._editPopup;
492
+ }
493
+ return null;
494
+ }
495
+ hideEditPopup() {
496
+ var _this$_editPopup;
497
+ this._editingLink$.next(null);
498
+ (_this$_editPopup = this._editPopup) === null || _this$_editPopup === void 0 || _this$_editPopup.dispose();
499
+ }
500
+ showInfoPopup(info) {
501
+ var _this$showing, _this$showing2, _this$showing3, _this$showing4, _this$showing5, _this$showing6;
502
+ const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
503
+ if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.linkId) === linkId && ((_this$showing2 = this.showing) === null || _this$showing2 === void 0 ? void 0 : _this$showing2.unitId) === unitId && ((_this$showing3 = this.showing) === null || _this$showing3 === void 0 ? void 0 : _this$showing3.segmentId) === segmentId && ((_this$showing4 = this.showing) === null || _this$showing4 === void 0 ? void 0 : _this$showing4.segmentPage) === segmentPage && ((_this$showing5 = this.showing) === null || _this$showing5 === void 0 ? void 0 : _this$showing5.startIndex) === startIndex && ((_this$showing6 = this.showing) === null || _this$showing6 === void 0 ? void 0 : _this$showing6.endIndex) === endIndex) return;
504
+ if (this._infoPopup) this._infoPopup.dispose();
505
+ if (!this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC)) return;
506
+ this._showingLink$.next({
507
+ unitId,
508
+ linkId,
509
+ segmentId,
510
+ segmentPage,
511
+ startIndex,
512
+ endIndex
513
+ });
514
+ this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange({
515
+ collapsed: false,
516
+ startOffset: startIndex,
517
+ endOffset: endIndex + 1,
518
+ segmentId,
519
+ segmentPage
520
+ }, {
521
+ componentKey: DocLinkPopup.componentKey,
522
+ direction: "top-center",
523
+ multipleDirection: "top",
524
+ onClickOutside: () => {
525
+ this.hideInfoPopup();
526
+ }
527
+ }, unitId);
528
+ return this._infoPopup;
529
+ }
530
+ hideInfoPopup() {
531
+ var _this$_infoPopup;
532
+ this._showingLink$.next(null);
533
+ (_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
534
+ }
535
+ };
536
+ DocHyperLinkPopupService = __decorate([
537
+ __decorateParam(0, Inject(DocCanvasPopManagerService)),
538
+ __decorateParam(1, Inject(DocSelectionManagerService)),
539
+ __decorateParam(2, IUniverInstanceService)
540
+ ], DocHyperLinkPopupService);
541
+
542
+ //#endregion
543
+ //#region src/controllers/doc-hyper-link-selection.controller.ts
544
+ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends Disposable {
545
+ constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
546
+ super();
547
+ this._commandService = _commandService;
548
+ this._univerInstanceService = _univerInstanceService;
549
+ this._docHyperLinkService = _docHyperLinkService;
550
+ this._initSelectionChange();
551
+ }
552
+ _initSelectionChange() {
553
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
554
+ if (commandInfo.id === SetTextSelectionsOperation.id) {
555
+ const { unitId, ranges, segmentId } = commandInfo.params;
556
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
557
+ const primary = ranges[0];
558
+ if (primary && doc) {
559
+ var _doc$getSelfOrHeaderF;
560
+ const { startOffset, endOffset, collapsed, segmentPage } = primary;
561
+ const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.customRanges;
562
+ if (collapsed) {
563
+ var _customRanges$findInd;
564
+ const index = (_customRanges$findInd = customRanges === null || customRanges === void 0 ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) !== null && _customRanges$findInd !== void 0 ? _customRanges$findInd : -1;
565
+ if (index > -1) {
566
+ const customRange = customRanges[index];
567
+ this._docHyperLinkService.showInfoPopup({
568
+ unitId,
569
+ linkId: customRange.rangeId,
570
+ segmentId,
571
+ segmentPage,
572
+ startIndex: customRange.startIndex,
573
+ endIndex: customRange.endIndex
574
+ });
575
+ return;
576
+ }
577
+ } else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
578
+ }
579
+ this._docHyperLinkService.hideInfoPopup();
580
+ this._docHyperLinkService.hideEditPopup();
581
+ }
582
+ }));
583
+ }
584
+ };
585
+ DocHyperLinkSelectionController = __decorate([
586
+ __decorateParam(0, ICommandService),
587
+ __decorateParam(1, IUniverInstanceService),
588
+ __decorateParam(2, Inject(DocHyperLinkPopupService))
589
+ ], DocHyperLinkSelectionController);
590
+
591
+ //#endregion
592
+ //#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
593
+ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController extends Disposable {
594
+ get _skeleton() {
595
+ return this._docSkeletonManagerService.getSkeleton();
596
+ }
597
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
598
+ super();
599
+ this._context = _context;
600
+ this._docEventManagerService = _docEventManagerService;
601
+ this._commandService = _commandService;
602
+ this._hyperLinkPopupService = _hyperLinkPopupService;
603
+ this._docSkeletonManagerService = _docSkeletonManagerService;
604
+ this._docSelectionManagerService = _docSelectionManagerService;
605
+ if (this._context.unitId === DOCS_ZEN_EDITOR_UNIT_ID_KEY || this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
606
+ this._initHover();
607
+ this._initClick();
608
+ }
609
+ _hideInfoPopup() {
610
+ if (this._hyperLinkPopupService.showing) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id);
611
+ }
612
+ _initHover() {
613
+ this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
614
+ var _link$segmentId;
615
+ const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
616
+ const activeRanges = this._docSelectionManagerService.getTextRanges();
617
+ const currentSegmentId = activeRanges === null || activeRanges === void 0 ? void 0 : activeRanges[0].segmentId;
618
+ if (((_link$segmentId = link === null || link === void 0 ? void 0 : link.segmentId) !== null && _link$segmentId !== void 0 ? _link$segmentId : "") !== currentSegmentId) {
619
+ this._hideInfoPopup();
620
+ return;
621
+ }
622
+ if (link) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id, {
623
+ unitId: this._context.unitId,
624
+ linkId: link.range.rangeId,
625
+ segmentId: link.segmentId,
626
+ segmentPage: link.segmentPageIndex,
627
+ rangeId: link.range.rangeId,
628
+ startIndex: link.range.startIndex,
629
+ endIndex: link.range.endIndex
630
+ });
631
+ else this._hideInfoPopup();
632
+ }));
633
+ }
634
+ _initClick() {
635
+ this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
636
+ const link = range.range;
637
+ if (link) this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
638
+ unitId: this._context.unitId,
639
+ linkId: link.rangeId,
640
+ segmentId: range.segmentId
641
+ });
642
+ }));
643
+ }
644
+ };
645
+ DocHyperLinkEventRenderController = __decorate([
646
+ __decorateParam(1, Inject(DocEventManagerService)),
647
+ __decorateParam(2, ICommandService),
648
+ __decorateParam(3, Inject(DocHyperLinkPopupService)),
649
+ __decorateParam(4, Inject(DocSkeletonManagerService)),
650
+ __decorateParam(5, Inject(DocSelectionManagerService))
651
+ ], DocHyperLinkEventRenderController);
652
+
653
+ //#endregion
654
+ //#region src/controllers/render-controllers/render.controller.ts
655
+ let DocHyperLinkRenderController = class DocHyperLinkRenderController extends Disposable {
656
+ constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
657
+ super();
658
+ this._context = _context;
659
+ this._docInterceptorService = _docInterceptorService;
660
+ this._hyperLinkService = _hyperLinkService;
661
+ this._docRenderController = _docRenderController;
662
+ this._init();
663
+ this._initReRender();
664
+ }
665
+ _init() {
666
+ this._docInterceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, { handler: (data, pos, next) => {
667
+ if (!data) return next(data);
668
+ const { unitId, index } = pos;
669
+ const activeLink = this._hyperLinkService.showing;
670
+ if (!activeLink) return next({
671
+ ...data,
672
+ active: false
673
+ });
674
+ const { linkId, unitId: linkUnitId, startIndex, endIndex } = activeLink;
675
+ const isActive = linkUnitId === unitId && data.rangeId === linkId && index >= startIndex && index <= endIndex;
676
+ return next({
677
+ ...data,
678
+ active: isActive
679
+ });
680
+ } });
681
+ }
682
+ _initReRender() {
683
+ this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(distinctUntilChanged((prev, aft) => (prev === null || prev === void 0 ? void 0 : prev.linkId) === (aft === null || aft === void 0 ? void 0 : aft.linkId) && (prev === null || prev === void 0 ? void 0 : prev.unitId) === (aft === null || aft === void 0 ? void 0 : aft.unitId) && (prev === null || prev === void 0 ? void 0 : prev.startIndex) === (aft === null || aft === void 0 ? void 0 : aft.startIndex)), pairwise()).subscribe(([preLink, link]) => {
684
+ if (link) {
685
+ if (link.unitId === this._context.unitId) this._docRenderController.reRender(link.unitId);
686
+ } else if (preLink && preLink.unitId === this._context.unitId) this._docRenderController.reRender(preLink.unitId);
687
+ }));
688
+ }
689
+ };
690
+ DocHyperLinkRenderController = __decorate([
691
+ __decorateParam(1, Inject(DocInterceptorService)),
692
+ __decorateParam(2, Inject(DocHyperLinkPopupService)),
693
+ __decorateParam(3, Inject(DocRenderController))
694
+ ], DocHyperLinkRenderController);
695
+
696
+ //#endregion
697
+ //#region src/menu/menu.ts
698
+ const DOC_LINK_ICON = "doc-hyper-link-icon";
699
+ function AddHyperLinkMenuItemFactory(accessor) {
700
+ return {
701
+ id: ShowDocHyperLinkEditPopupOperation.id,
702
+ type: MenuItemType.BUTTON,
703
+ icon: DOC_LINK_ICON,
704
+ title: "docLink.menu.tooltip",
705
+ tooltip: "docLink.menu.tooltip",
706
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
707
+ disabled$: new Observable(function(subscribe) {
708
+ const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
709
+ subscribe.next(shouldDisableAddLink(accessor));
710
+ });
711
+ return () => {
712
+ observer.unsubscribe();
713
+ };
714
+ })
715
+ };
716
+ }
717
+ const addLinkShortcut = {
718
+ id: ShowDocHyperLinkEditPopupOperation.id,
719
+ binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
720
+ description: "docLink.menu.tooltip",
721
+ preconditions: whenDocAndEditorFocused
722
+ };
723
+
724
+ //#endregion
725
+ //#region src/menu/schema.ts
726
+ const menuSchema = {
727
+ [RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
728
+ order: 1,
729
+ menuItemFactory: AddHyperLinkMenuItemFactory
730
+ } },
731
+ [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
732
+ order: 0,
733
+ menuItemFactory: AddHyperLinkMenuItemFactory
734
+ } } }
735
+ };
736
+
737
+ //#endregion
738
+ //#region src/controllers/ui.controller.ts
739
+ let DocHyperLinkUIController = class DocHyperLinkUIController extends Disposable {
740
+ constructor(_componentManager, _commandService, _menuManagerService, _shortcutService) {
741
+ super();
742
+ this._componentManager = _componentManager;
743
+ this._commandService = _commandService;
744
+ this._menuManagerService = _menuManagerService;
745
+ this._shortcutService = _shortcutService;
746
+ this._initComponents();
747
+ this._initCommands();
748
+ this._initMenus();
749
+ this._initShortcut();
750
+ }
751
+ _initComponents() {
752
+ [
753
+ [DocHyperLinkEdit.componentKey, DocHyperLinkEdit],
754
+ [DocLinkPopup.componentKey, DocLinkPopup],
755
+ [DOC_LINK_ICON, LinkIcon]
756
+ ].forEach(([key, comp]) => {
757
+ this.disposeWithMe(this._componentManager.register(key, comp));
758
+ });
759
+ }
760
+ _initCommands() {
761
+ [
762
+ AddDocHyperLinkCommand,
763
+ UpdateDocHyperLinkCommand,
764
+ DeleteDocHyperLinkCommand,
765
+ ShowDocHyperLinkEditPopupOperation,
766
+ ToggleDocHyperLinkInfoPopupOperation,
767
+ ClickDocHyperLinkOperation
768
+ ].forEach((command) => {
769
+ this._commandService.registerCommand(command);
770
+ });
771
+ }
772
+ _initShortcut() {
773
+ [addLinkShortcut].forEach((shortcut) => {
774
+ this._shortcutService.registerShortcut(shortcut);
775
+ });
776
+ }
777
+ _initMenus() {
778
+ this._menuManagerService.mergeMenu(menuSchema);
779
+ }
780
+ };
781
+ DocHyperLinkUIController = __decorate([
782
+ __decorateParam(0, Inject(ComponentManager)),
783
+ __decorateParam(1, ICommandService),
784
+ __decorateParam(2, IMenuManagerService),
785
+ __decorateParam(3, IShortcutService)
786
+ ], DocHyperLinkUIController);
787
+
788
+ //#endregion
789
+ //#region src/types/const/index.ts
790
+ /**
791
+ * Copyright 2023-present DreamNum Co., Ltd.
792
+ *
793
+ * Licensed under the Apache License, Version 2.0 (the "License");
794
+ * you may not use this file except in compliance with the License.
795
+ * You may obtain a copy of the License at
796
+ *
797
+ * http://www.apache.org/licenses/LICENSE-2.0
798
+ *
799
+ * Unless required by applicable law or agreed to in writing, software
800
+ * distributed under the License is distributed on an "AS IS" BASIS,
801
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
802
+ * See the License for the specific language governing permissions and
803
+ * limitations under the License.
804
+ */
805
+ const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
806
+
807
+ //#endregion
808
+ //#region src/plugin.ts
809
+ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plugin {
810
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
811
+ super();
812
+ this._config = _config;
813
+ this._injector = _injector;
814
+ this._renderManagerSrv = _renderManagerSrv;
815
+ this._configService = _configService;
816
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
817
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
818
+ this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
819
+ }
820
+ onStarting() {
821
+ [
822
+ [DocHyperLinkPopupService],
823
+ [DocHyperLinkUIController],
824
+ [DocHyperLinkSelectionController]
825
+ ].forEach((dep) => {
826
+ this._injector.add(dep);
827
+ });
828
+ this._injector.get(DocHyperLinkUIController);
829
+ }
830
+ onReady() {
831
+ this._injector.get(DocHyperLinkSelectionController);
832
+ }
833
+ onRendered() {
834
+ this._initRenderModule();
835
+ }
836
+ _initRenderModule() {
837
+ [[DocHyperLinkRenderController], [DocHyperLinkEventRenderController]].forEach((dep) => {
838
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
839
+ });
840
+ }
841
+ };
842
+ _defineProperty(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
843
+ _defineProperty(UniverDocsHyperLinkUIPlugin, "packageName", name);
844
+ _defineProperty(UniverDocsHyperLinkUIPlugin, "version", version);
845
+ _defineProperty(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
846
+ UniverDocsHyperLinkUIPlugin = __decorate([
847
+ DependentOn(UniverDocsHyperLinkPlugin),
848
+ __decorateParam(1, Inject(Injector)),
849
+ __decorateParam(2, IRenderManagerService),
850
+ __decorateParam(3, IConfigService)
851
+ ], UniverDocsHyperLinkUIPlugin);
852
+
853
+ //#endregion
854
+ export { UniverDocsHyperLinkUIPlugin };