chore: fix link button
This commit is contained in:
@@ -57,13 +57,6 @@ const FloatingLinkEditor = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const linkEditorElement = linkEditorRef.current
|
|
||||||
|
|
||||||
if (!linkEditorElement) {
|
|
||||||
setTimeout(updateLinkEditorPosition)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const nativeSelection = window.getSelection()
|
const nativeSelection = window.getSelection()
|
||||||
const rootElement = editor.getRootElement()
|
const rootElement = editor.getRootElement()
|
||||||
|
|
||||||
@@ -71,24 +64,36 @@ const FloatingLinkEditor = ({
|
|||||||
if (rootElement.contains(nativeSelection.anchorNode)) {
|
if (rootElement.contains(nativeSelection.anchorNode)) {
|
||||||
rangeRect.current = getDOMRangeRect(nativeSelection, rootElement)
|
rangeRect.current = getDOMRangeRect(nativeSelection, rootElement)
|
||||||
}
|
}
|
||||||
const linkEditorRect = linkEditorElement.getBoundingClientRect()
|
}
|
||||||
const rootElementRect = rootElement.getBoundingClientRect()
|
|
||||||
|
|
||||||
const calculatedStyles = getPositionedPopoverStyles({
|
const linkEditorElement = linkEditorRef.current
|
||||||
align: 'center',
|
|
||||||
side: 'top',
|
if (!linkEditorElement) {
|
||||||
anchorRect: rangeRect.current,
|
setTimeout(updateLinkEditorPosition)
|
||||||
popoverRect: linkEditorRect,
|
return
|
||||||
documentRect: rootElementRect,
|
}
|
||||||
offset: 12,
|
|
||||||
maxHeightFunction: () => 'none',
|
if (!rootElement) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const linkEditorRect = linkEditorElement.getBoundingClientRect()
|
||||||
|
const rootElementRect = rootElement.getBoundingClientRect()
|
||||||
|
|
||||||
|
const calculatedStyles = getPositionedPopoverStyles({
|
||||||
|
align: 'center',
|
||||||
|
side: 'top',
|
||||||
|
anchorRect: rangeRect.current,
|
||||||
|
popoverRect: linkEditorRect,
|
||||||
|
documentRect: rootElementRect,
|
||||||
|
offset: 12,
|
||||||
|
maxHeightFunction: () => 'none',
|
||||||
|
})
|
||||||
|
if (calculatedStyles) {
|
||||||
|
Object.entries(calculatedStyles).forEach(([key, value]) => {
|
||||||
|
linkEditorElement.style.setProperty(key, value)
|
||||||
})
|
})
|
||||||
if (calculatedStyles) {
|
linkEditorElement.style.opacity = '1'
|
||||||
Object.entries(calculatedStyles).forEach(([key, value]) => {
|
|
||||||
linkEditorElement.style.setProperty(key, value)
|
|
||||||
})
|
|
||||||
linkEditorElement.style.opacity = '1'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [editor, isMobile])
|
}, [editor, isMobile])
|
||||||
|
|
||||||
|
|||||||
@@ -267,6 +267,7 @@ const ToolbarPlugin = () => {
|
|||||||
return activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, null)
|
return activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, null)
|
||||||
} else if (typeof payload === 'string') {
|
} else if (typeof payload === 'string') {
|
||||||
const dispatched = activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, payload)
|
const dispatched = activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, payload)
|
||||||
|
setIsLink(true)
|
||||||
setLinkUrl(payload)
|
setLinkUrl(payload)
|
||||||
setIsLinkEditMode(true)
|
setIsLinkEditMode(true)
|
||||||
return dispatched
|
return dispatched
|
||||||
|
|||||||
Reference in New Issue
Block a user