This commit is contained in:
Timothy Jaeryang Baek committed 2026-01-05 17:44:44 +04:00
1 parent 3f577c0c3f
commit e27fb3e291
2 files changed
+12 -1

No files matched your search

@@ -131,11 +131,19 @@ export class SocketIOCollaborationProvider {
const isEmptyEditor = !this.editor?.getText().trim(); const isEmptyEditor = !this.editor?.getText().trim();
if (isEmptyEditor && this.editor) { if (isEmptyEditor && this.editor) {
if (this.initialContent && (data?.sessions ?? ['']).length === 1) { if (this.initialContent && (data?.sessions ?? ['']).length === 1) {
// Check if initialContent is HTML (string) or JSON (object)
if (typeof this.initialContent === 'string') {
// HTML content - let the editor parse it, then sync to Yjs
this.editor.commands.setContent(this.initialContent);
// The Yjs plugin will automatically sync the content
} else {
// JSON content - use the existing approach
const editorYdoc = prosemirrorJSONToYDoc(this.editor.schema, this.initialContent); const editorYdoc = prosemirrorJSONToYDoc(this.editor.schema, this.initialContent);
if (editorYdoc) { if (editorYdoc) {
Y.applyUpdate(this.doc, Y.encodeStateAsUpdate(editorYdoc)); Y.applyUpdate(this.doc, Y.encodeStateAsUpdate(editorYdoc));
} }
} }
}
} else { } else {
// If the editor already has content, we don't need to send an empty state // If the editor already has content, we don't need to send an empty state
if (this.doc.getXmlFragment('prosemirror').length > 0) { if (this.doc.getXmlFragment('prosemirror').length > 0) {
+4 -1
View File
@@ -145,6 +145,9 @@
let inputElement = null; let inputElement = null;
// Computed HTML for editor: fall back to markdown if HTML is missing
$: editorHtml = note?.data?.content?.html || (note?.data?.content?.md ? marked.parse(note.data.content.md) : '');
const init = async () => { const init = async () => {
loading = true; loading = true;
const res = await getNoteById(localStorage.token, id).catch((error) => { const res = await getNoteById(localStorage.token, id).catch((error) => {
@@ -1154,7 +1157,7 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
className="input-prose-sm px-0.5 h-[calc(100%-2rem)]" className="input-prose-sm px-0.5 h-[calc(100%-2rem)]"
json={true} json={true}
bind:value={note.data.content.json} bind:value={note.data.content.json}
html={note.data?.content?.html} html={editorHtml}
documentId={`note:${note.id}`} documentId={`note:${note.id}`}
collaboration={true} collaboration={true}
socket={$socket} socket={$socket}