Open y-as-a opened 2 years ago
// Define the IEditorCore interface
interface IEditorCore extends EditorJS {
destroy(): Promise<void>;
clear(): Promise<void>;
save(): Promise<OutputData>;
render(data: OutputData): Promise<void>;
}
// Initialize Editor.js instance
const editorCore = useRef<EditorJS>();
// Handle initialization
const handleInitialize = useCallback((instance: IEditorCore) => {
editorCore.current = instance;
}, []);
// Save method with correct handling for headers
const saveEditorData = async () => {
try {
const savedData = await editorCore.current.save();
// Ensure table headers are correctly included
savedData.blocks.forEach(block => {
if (block.type === 'table') {
const tableData = block.data;
// Check if headers are included
if (tableData.withHeadings) {
const [header, ...body] = tableData.content;
// Ensure headers are properly attached to the content
tableData.content = [header, ...body];
}
}
});
console.log('Saved data:', savedData);
// Further processing of savedData if needed
} catch (error) {
console.error('Error saving editor data:', error);
}
};
Editor version: 2.25.0 Editor Table version: 2.0.2
When I create a table without a header and save it, all the json data is fine. But in the case of a header, the first two lines are sliced.
Save method
interface IEditorCore extends EditorJS { destroy(): Promise<void>, clear(): Promise<void>, save(): Promise<OutputData>, render(data: OutputData): Promise<void> }
const editorCore = useRef<EditorJS>()
const handleInitialize = useCallback((instance: IEditorCore) => { editorCore.current = instance }, [])
await editorCore.current.save()
Without heading
With heading