Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
const el = ref.current;
const {selection} = editor;
if (!el) {
return
}
if (
!selection ||
!ReactEditor.isFocused(editor) ||
Range.isCollapsed(selection) ||
Editor.string(editor, selection) === ''
) {
el.removeAttribute('style');
return
}
const domSelection = window.getSelection();
const domRange = domSelection.getRangeAt(0);
const rect = domRange.getBoundingClientRect();
el.style.opacity = 1;
el.style.top = `${rect.top + window.pageYOffset - el.offsetHeight}px`;
el.style.left = `${rect.left +
window.pageXOffset -
el.offsetWidth / 2 +
useEffect(() => {
const el = ref.current
const { selection } = editor
if (!el) {
return
}
if (
!selection ||
!ReactEditor.isFocused(editor) ||
Range.isCollapsed(selection) ||
Editor.string(editor, selection) === ''
) {
el.removeAttribute('style')
return
}
const domSelection = window.getSelection()
const domRange = domSelection.getRangeAt(0)
const rect = domRange.getBoundingClientRect()
el.style.opacity = '1'
el.style.top = `${rect.top + window.pageYOffset - el.offsetHeight}px`
el.style.left = `${rect.left +
window.pageXOffset -
el.offsetWidth / 2 +
rect.width / 2}px`
useEffect(() => {
const el = ref.current
const { selection } = editor
if (!el) {
return
}
if (
!selection ||
!ReactEditor.isFocused(editor) ||
Range.isCollapsed(selection) ||
Editor.string(editor, selection) === ''
) {
el.removeAttribute('style')
return
}
const domSelection = window.getSelection()
const domRange = domSelection.getRangeAt(0)
const rect = domRange.getBoundingClientRect()
el.style.opacity = 1
el.style.top = `${rect.top + window.pageYOffset - el.offsetHeight}px`
el.style.left = `${rect.left +
window.pageXOffset -
el.offsetWidth / 2 +
rect.width / 2}px`
React.useEffect(() => {
if (!menu.current || !triangle.current) return
const { selection } = editor
if (
!selection ||
!ReactEditor.isFocused(editor) ||
Range.isCollapsed(selection) ||
SlateEditor.string(editor, selection) === ''
) {
menu.current.style.top = ''
menu.current.style.left = ''
return
}
const domSelection = window.getSelection()
if (!domSelection || domSelection.rangeCount === 0) return
const domRange = domSelection.getRangeAt(0)
const rect = domRange.getBoundingClientRect()
if (!rect || rect.height === 0) return