diff --git a/uui-editor/src/plugins/linkPlugin/AddLinkModal.tsx b/uui-editor/src/plugins/linkPlugin/AddLinkModal.tsx index d043ffeaeb..8f9bc37550 100644 --- a/uui-editor/src/plugins/linkPlugin/AddLinkModal.tsx +++ b/uui-editor/src/plugins/linkPlugin/AddLinkModal.tsx @@ -1,6 +1,6 @@ -import React, { useEffect, useState } from 'react'; -import { ELEMENT_LINK, insertLink, unwrapLink } from '@udecode/plate-link'; -import { PlateEditor, getPluginType, getAboveNode, getSelectionText } from '@udecode/plate-common'; +import React, { useState } from 'react'; +import { ELEMENT_LINK, TLinkElement, unwrapLink, upsertLink } from '@udecode/plate-link'; +import { PlateEditor, getPluginType, getSelectionText, findNode, getEditorString } from '@udecode/plate-common'; import { IModal } from '@epam/uui-core'; import { FlexRow, FlexSpacer, ModalWindow, ModalBlocker, ModalFooter, ModalHeader, Button, LabeledInput, TextInput } from '@epam/uui'; @@ -10,33 +10,23 @@ interface AddLinkModalProps extends IModal { editor: PlateEditor; } -export function AddLinkModal(props: AddLinkModalProps) { +export function AddLinkModal({ editor, ...modalProps }: AddLinkModalProps) { + const { success, abort } = modalProps; const [link, setLink] = useState(''); - const isLinkInvalid = false; - - const linkValidationProps = { - isInvalid: isLinkInvalid, - validationMessage: 'Link is invalid', - }; - - useEffect(() => { - const type = getPluginType(props.editor, ELEMENT_LINK); - - const linkNode = getAboveNode(props.editor, { - match: { type }, - }); - if (linkNode) { - setLink(linkNode[0].url as string); - } - }, [props]); return ( - + - + - - setLink(newVal) } autoFocus /> + + { + setLink(newVal!); + } } + autoFocus + /> @@ -46,16 +36,26 @@ export function AddLinkModal(props: AddLinkModalProps) { caption="Delete" onClick={ () => { setLink(''); - unwrapLink(props.editor); - props.abort(); + unwrapLink(editor); + abort(); } } />