mirror of
https://github.com/codex-team/editor.js
synced 2024-05-18 14:26:48 +02:00
chore(blocks.render): mutex for onchange added to the blocks.render() (#2449)
This commit is contained in:
parent
be0d33ce0f
commit
42612a0fd9
|
@ -18,6 +18,7 @@
|
||||||
- `Improvement` - The stub-block style simplified.
|
- `Improvement` - The stub-block style simplified.
|
||||||
- `Improvement` - If some Block's tool will throw an error during construction, we will show Stub block instead of skipping it during render
|
- `Improvement` - If some Block's tool will throw an error during construction, we will show Stub block instead of skipping it during render
|
||||||
- `Improvement` - Call of `blocks.clear()` now will trigger onChange with "block-removed" event for all removed blocks.
|
- `Improvement` - Call of `blocks.clear()` now will trigger onChange with "block-removed" event for all removed blocks.
|
||||||
|
- `Improvement` - The `blocks.clear()` now can be awaited.
|
||||||
- `Improvement` - `BlockMutationType` and `BlockMutationEvent` types exported
|
- `Improvement` - `BlockMutationType` and `BlockMutationEvent` types exported
|
||||||
- `Improvement` - `blocks.update(id, data)` now can accept partial data object — it will update only passed properties, others will remain the same.
|
- `Improvement` - `blocks.update(id, data)` now can accept partial data object — it will update only passed properties, others will remain the same.
|
||||||
- `Improvement` - `blocks.update(id, data)` now will trigger onChange with only `block-change` event.
|
- `Improvement` - `blocks.update(id, data)` now will trigger onChange with only `block-change` event.
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default class BlocksAPI extends Module {
|
||||||
*/
|
*/
|
||||||
public get methods(): Blocks {
|
public get methods(): Blocks {
|
||||||
return {
|
return {
|
||||||
clear: (): void => this.clear(),
|
clear: (): Promise<void> => this.clear(),
|
||||||
render: (data: OutputData): Promise<void> => this.render(data),
|
render: (data: OutputData): Promise<void> => this.render(data),
|
||||||
renderFromHTML: (data: string): Promise<void> => this.renderFromHTML(data),
|
renderFromHTML: (data: string): Promise<void> => this.renderFromHTML(data),
|
||||||
delete: (index?: number): void => this.delete(index),
|
delete: (index?: number): void => this.delete(index),
|
||||||
|
@ -172,8 +172,8 @@ export default class BlocksAPI extends Module {
|
||||||
/**
|
/**
|
||||||
* Clear Editor's area
|
* Clear Editor's area
|
||||||
*/
|
*/
|
||||||
public clear(): void {
|
public async clear(): Promise<void> {
|
||||||
this.Editor.BlockManager.clear(true);
|
await this.Editor.BlockManager.clear(true);
|
||||||
this.Editor.InlineToolbar.close();
|
this.Editor.InlineToolbar.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,9 +187,16 @@ export default class BlocksAPI extends Module {
|
||||||
throw new Error('Incorrect data passed to the render() method');
|
throw new Error('Incorrect data passed to the render() method');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.Editor.BlockManager.clear();
|
/**
|
||||||
|
* Semantic meaning of the "render" method: "Display the new document over the existing one that stays unchanged"
|
||||||
|
* So we need to disable modifications observer temporarily
|
||||||
|
*/
|
||||||
|
this.Editor.ModificationsObserver.disable();
|
||||||
|
|
||||||
return this.Editor.Renderer.render(data.blocks);
|
await this.Editor.BlockManager.clear();
|
||||||
|
await this.Editor.Renderer.render(data.blocks);
|
||||||
|
|
||||||
|
this.Editor.ModificationsObserver.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -578,7 +578,7 @@ describe('onChange callback', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called on blocks.render() on non-empty editor with removed blocks', () => {
|
it('should not be called on blocks.render() on non-empty editor', () => {
|
||||||
createEditor([
|
createEditor([
|
||||||
{
|
{
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
|
@ -608,14 +608,7 @@ describe('onChange callback', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
cy.get('@onChange').should('be.calledWithBatchedEvents', [
|
cy.get('@onChange').should('have.callCount', 0);
|
||||||
{
|
|
||||||
type: BlockRemovedMutationType,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: BlockRemovedMutationType,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called on blocks.update() with "block-changed" event', () => {
|
it('should be called on blocks.update() with "block-changed" event', () => {
|
||||||
|
|
2
types/api/blocks.d.ts
vendored
2
types/api/blocks.d.ts
vendored
|
@ -9,7 +9,7 @@ export interface Blocks {
|
||||||
/**
|
/**
|
||||||
* Remove all blocks from Editor zone
|
* Remove all blocks from Editor zone
|
||||||
*/
|
*/
|
||||||
clear(): void;
|
clear(): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render passed data
|
* Render passed data
|
||||||
|
|
Loading…
Reference in a new issue