Skip to content

fix the readonly issue with empty blocks #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/tools/embed
7 changes: 6 additions & 1 deletion src/components/modules/api/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ export default class BlocksAPI extends Module {
* @param {OutputData} data — Saved Editor data
*/
public render(data: OutputData): Promise<void> {
this.Editor.BlockManager.clear();
const needToAddDefaultBlock = !data.blocks.length;
this.Editor.BlockManager.clear(needToAddDefaultBlock);

if (needToAddDefaultBlock){
return Promise.resolve();
}

return this.Editor.Renderer.render(data.blocks);
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/modules/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default class Renderer extends Module {
* @param {OutputBlockData[]} blocks - blocks to render
*/
public async render(blocks: OutputBlockData[]): Promise<void> {

if (blocks.length === 0) {
blocks = [{
"data": {"text": ""},
"id": "WhateverXX",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider leaving a comment about why this initialization is required, and the significance of the initial values if any (eg. "Placeholder values will not appear on screen" or "text field of data must be given this value for this reason").

"type": "paragraph",
}]
}

const chainData = blocks.map((block) => ({ function: (): Promise<void> => this.insertBlock(block) }));

/**
Expand Down