chore: show super note placeholder, only on empty notes
This commit is contained in:
@@ -78,23 +78,29 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!isMobile && <ToolbarPlugin />}
|
{!isMobile && <ToolbarPlugin />}
|
||||||
<RichTextPlugin
|
<div className="relative min-h-0 flex-grow">
|
||||||
contentEditable={
|
<RichTextPlugin
|
||||||
<div id="blocks-editor" className="editor-scroller h-full min-h-0">
|
contentEditable={
|
||||||
<div className="editor z-0 overflow-hidden" ref={onRef}>
|
<div id="blocks-editor" className="editor-scroller h-full min-h-0">
|
||||||
<ContentEditable
|
<div className="editor z-0 overflow-hidden" ref={onRef}>
|
||||||
id={SuperEditorContentId}
|
<ContentEditable
|
||||||
className={classNames('ContentEditable__root overflow-y-auto', className)}
|
id={SuperEditorContentId}
|
||||||
spellCheck={spellcheck}
|
className={classNames('ContentEditable__root overflow-y-auto', className)}
|
||||||
onScroll={onScroll}
|
spellCheck={spellcheck}
|
||||||
/>
|
onScroll={onScroll}
|
||||||
<div className="search-highlight-container pointer-events-none absolute left-0 top-0 h-full w-full" />
|
/>
|
||||||
|
<div className="search-highlight-container pointer-events-none absolute left-0 top-0 h-full w-full" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
placeholder={
|
||||||
placeholder={null}
|
<div className="pointer-events-none absolute left-4 top-4 text-passive-1">
|
||||||
ErrorBoundary={LexicalErrorBoundary}
|
Type <span className="rounded bg-passive-4-opacity-variant p-0.5">/</span> for commands...
|
||||||
/>
|
</div>
|
||||||
|
}
|
||||||
|
ErrorBoundary={LexicalErrorBoundary}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{isMobile && <ToolbarPlugin />}
|
{isMobile && <ToolbarPlugin />}
|
||||||
<ListPlugin />
|
<ListPlugin />
|
||||||
<MarkdownShortcutPlugin transformers={MarkdownTransformers} />
|
<MarkdownShortcutPlugin transformers={MarkdownTransformers} />
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
||||||
import {
|
|
||||||
$getSelection,
|
|
||||||
$isRangeSelection,
|
|
||||||
$isParagraphNode,
|
|
||||||
$isTextNode,
|
|
||||||
SELECTION_CHANGE_COMMAND,
|
|
||||||
COMMAND_PRIORITY_LOW,
|
|
||||||
} from 'lexical'
|
|
||||||
import { useCallback, useEffect, useRef } from 'react'
|
|
||||||
import { getSelectedNode } from '../Lexical/Utils/getSelectedNode'
|
|
||||||
import { mergeRegister } from '@lexical/utils'
|
|
||||||
|
|
||||||
export const EmptyLinePlaceholderPlugin = () => {
|
|
||||||
const [editor] = useLexicalComposerContext()
|
|
||||||
|
|
||||||
const placeholderElementRef = useRef<HTMLDivElement>(null)
|
|
||||||
|
|
||||||
const cursorUpdate = useCallback((): boolean => {
|
|
||||||
const selection = $getSelection()
|
|
||||||
if (selection && $isRangeSelection(selection)) {
|
|
||||||
if (!placeholderElementRef.current) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const node = getSelectedNode(selection)
|
|
||||||
if (!node) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const isParagraph = $isParagraphNode(node) || $isTextNode(node)
|
|
||||||
const text = node.getTextContent()
|
|
||||||
if (!isParagraph) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const rootElement = editor.getRootElement()
|
|
||||||
const nodeElement = editor.getElementByKey(node.getKey())
|
|
||||||
const placeholder = placeholderElementRef.current
|
|
||||||
if (!nodeElement || !placeholder.parentElement || !rootElement) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const rect = nodeElement.getBoundingClientRect()
|
|
||||||
const parentRect = placeholder.parentElement.getBoundingClientRect()
|
|
||||||
const rootRect = rootElement.getBoundingClientRect()
|
|
||||||
if (!text && editor.isEditable()) {
|
|
||||||
placeholder.style.top = `${rect.y}px`
|
|
||||||
placeholder.style.left = `${rect.x - parentRect.x + rootRect.x}px`
|
|
||||||
placeholder.style.opacity = '0.65'
|
|
||||||
} else {
|
|
||||||
placeholder.style.opacity = '0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}, [editor])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return mergeRegister(
|
|
||||||
editor.registerCommand(SELECTION_CHANGE_COMMAND, cursorUpdate, COMMAND_PRIORITY_LOW),
|
|
||||||
editor.registerEditableListener(cursorUpdate),
|
|
||||||
)
|
|
||||||
}, [cursorUpdate, editor])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const scrollerElem = editor.getRootElement()
|
|
||||||
|
|
||||||
const update = () => {
|
|
||||||
editor.getEditorState().read(() => {
|
|
||||||
cursorUpdate()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('resize', update)
|
|
||||||
if (scrollerElem) {
|
|
||||||
scrollerElem.addEventListener('scroll', update)
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('resize', update)
|
|
||||||
if (scrollerElem) {
|
|
||||||
scrollerElem.removeEventListener('scroll', update)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [cursorUpdate, editor])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="super-empty-line-placeholder pointer-events-none fixed text-passive-1 opacity-0"
|
|
||||||
ref={placeholderElementRef}
|
|
||||||
>
|
|
||||||
Type <span className="rounded bg-passive-4-opacity-variant p-0.5">/</span> for commands...
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user