) => {
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return
+ setIsExpanded(draftRef.current.trim().length > 0)
+ },
+ [],
+ )
+
const canSave = draft.trim().length > 0 && !isSaving
+ const editorHeight =
+ isExpanded || draft.trim() ? "min-h-[188px]" : "min-h-[120px]"
return (
setIsExpanded(true)}
+ onBlurCapture={handleBlurCapture}
style={{
boxShadow: "inset 1.421px 1.421px 4.263px 0 rgba(11, 15, 21, 0.4)",
}}
@@ -77,18 +85,23 @@ export function QuickNoteCard({
-
+ aria-disabled={isSaving}
+ >
+
+
void
onSubmit: () => void
debounceMs?: number
+ editable?: boolean
}) {
const containerRef = useRef(null)
const editorRef = useRef(null)
@@ -44,6 +46,7 @@ export function TextEditor({
extensions,
content: initialContent,
contentType: "markdown",
+ editable,
immediatelyRender: true,
onCreate: ({ editor }) => {
editorRef.current = editor
@@ -86,12 +89,21 @@ export function TextEditor({
})
useEffect(() => {
- if (editor && initialContent) {
+ if (editor && initialContent !== undefined) {
+ const json = editor.getJSON()
+ const currentContent =
+ editor.storage.markdown?.manager?.serialize(json) ?? ""
+ if (currentContent === initialContent) return
+
hasUserEditedRef.current = false
editor.commands.setContent(initialContent, { contentType: "markdown" })
}
}, [editor, initialContent])
+ useEffect(() => {
+ editor?.setEditable(editable)
+ }, [editor, editable])
+
const handleClick = useCallback((e: React.MouseEvent) => {
const target = e.target as HTMLElement
if (target.closest(".ProseMirror")) {