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