debug: add logging to trace editor content loading issue
This commit is contained in:
parent
639a4a2429
commit
7211ccff9f
2 changed files with 32 additions and 7 deletions
|
|
@ -51,6 +51,9 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
function populateFormData(data: Project) {
|
function populateFormData(data: Project) {
|
||||||
|
console.log('ProjectForm - populateFormData called with:', data);
|
||||||
|
console.log('ProjectForm - caseStudyContent:', data.caseStudyContent);
|
||||||
|
|
||||||
formData = {
|
formData = {
|
||||||
title: data.title || '',
|
title: data.title || '',
|
||||||
subtitle: data.subtitle || '',
|
subtitle: data.subtitle || '',
|
||||||
|
|
@ -72,6 +75,8 @@
|
||||||
content: [{ type: 'paragraph' }]
|
content: [{ type: 'paragraph' }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('ProjectForm - formData.caseStudyContent after populate:', formData.caseStudyContent);
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,6 @@
|
||||||
let element = $state<HTMLElement>()
|
let element = $state<HTMLElement>()
|
||||||
let isLoading = $state(true)
|
let isLoading = $state(true)
|
||||||
let initialized = false
|
let initialized = false
|
||||||
let contentLoaded = false
|
|
||||||
const mediaSelectionState = $derived($mediaSelectionStore)
|
const mediaSelectionState = $derived($mediaSelectionStore)
|
||||||
|
|
||||||
// Toolbar component ref
|
// Toolbar component ref
|
||||||
|
|
@ -163,20 +162,39 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch for external data changes and update editor
|
// Watch for external data changes and update editor
|
||||||
|
let lastDataString = '';
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (editor && data && !contentLoaded) {
|
if (editor && data) {
|
||||||
// Only update if the data has actual content (not just empty doc)
|
console.log('ComposerCore effect - data received:', data);
|
||||||
|
|
||||||
|
// Check if the data has actual content (not just empty doc)
|
||||||
const hasContent = data.content && data.content.length > 0 &&
|
const hasContent = data.content && data.content.length > 0 &&
|
||||||
!(data.content.length === 1 && data.content[0].type === 'paragraph' && !data.content[0].content);
|
!(data.content.length === 1 && data.content[0].type === 'paragraph' && !data.content[0].content);
|
||||||
|
|
||||||
|
console.log('ComposerCore effect - hasContent:', hasContent);
|
||||||
|
|
||||||
if (hasContent) {
|
if (hasContent) {
|
||||||
editor.commands.setContent(data);
|
// Compare with last known data to avoid unnecessary updates
|
||||||
contentLoaded = true;
|
const currentDataString = JSON.stringify(data);
|
||||||
|
|
||||||
|
if (currentDataString !== lastDataString) {
|
||||||
|
console.log('ComposerCore effect - updating editor with:', data);
|
||||||
|
// Update the editor with new content
|
||||||
|
try {
|
||||||
|
editor.commands.setContent(data);
|
||||||
|
lastDataString = currentDataString;
|
||||||
|
console.log('ComposerCore effect - editor updated successfully');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('ComposerCore effect - error updating editor:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
console.log('ComposerCore onMount - initial data:', data);
|
||||||
|
|
||||||
// Get extensions with custom options
|
// Get extensions with custom options
|
||||||
const extensions = getEditorExtensions({
|
const extensions = getEditorExtensions({
|
||||||
showSlashCommands,
|
showSlashCommands,
|
||||||
|
|
@ -188,11 +206,13 @@
|
||||||
// Initialize editor
|
// Initialize editor
|
||||||
const newEditor = initiateEditor(
|
const newEditor = initiateEditor(
|
||||||
element,
|
element,
|
||||||
|
data, // content
|
||||||
|
undefined, // limit
|
||||||
|
extensions,
|
||||||
{
|
{
|
||||||
initialContent: data,
|
|
||||||
extensions,
|
|
||||||
onCreate: () => {
|
onCreate: () => {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
|
console.log('ComposerCore - editor created');
|
||||||
},
|
},
|
||||||
onUpdate: handleUpdate,
|
onUpdate: handleUpdate,
|
||||||
editable,
|
editable,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue