mirror of
https://github.com/codex-team/editor.js
synced 2024-06-01 21:42:26 +02:00
add data-mutation-free=deep
This commit is contained in:
parent
494d6e4b9b
commit
029907c0fb
|
@ -911,7 +911,7 @@ export default class Block extends EventsDispatcher<BlockEvents> {
|
|||
return false;
|
||||
}
|
||||
|
||||
return (node as HTMLElement).dataset.mutationFree === 'true';
|
||||
return (node as HTMLElement).dataset.mutationFree === 'true' || !!node.closest('[data-mutation-free="deep"]');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -544,6 +544,73 @@ describe('onChange callback', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not be fired when child element of "data-mutation-free=deep" mark changes some attribute', () => {
|
||||
/**
|
||||
* Mock for tool wrapper which we will mutate in a test
|
||||
*/
|
||||
const toolWrapper = document.createElement('div');
|
||||
const toolChild = document.createElement('div');
|
||||
|
||||
toolWrapper.appendChild(toolChild);
|
||||
|
||||
/**
|
||||
* Mark it as mutation-free with deep check
|
||||
*/
|
||||
toolWrapper.dataset.mutationFree = 'deep';
|
||||
|
||||
/**
|
||||
* Mock of tool with data-mutation-free attribute
|
||||
*/
|
||||
class ToolWithMutationFreeAttribute {
|
||||
/**
|
||||
* Simply return mocked element
|
||||
*/
|
||||
public render(): HTMLElement {
|
||||
return toolWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving logic is not necessary for this test
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
public save(): void {}
|
||||
}
|
||||
|
||||
const editorConfig = {
|
||||
tools: {
|
||||
testTool: ToolWithMutationFreeAttribute,
|
||||
},
|
||||
onChange: (api, event): void => {
|
||||
console.log('something changed', event);
|
||||
},
|
||||
data: {
|
||||
blocks: [
|
||||
{
|
||||
type: 'testTool',
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
cy.spy(editorConfig, 'onChange').as('onChange');
|
||||
cy.createEditor(editorConfig).as('editorInstance');
|
||||
|
||||
/**
|
||||
* Emulate tool's internal attribute mutation
|
||||
*/
|
||||
cy.wait(100).then(() => {
|
||||
toolChild.setAttribute('some-changed-attr', 'some-new-value');
|
||||
});
|
||||
|
||||
/**
|
||||
* Check that onChange callback was not called
|
||||
*/
|
||||
cy.wait(500).then(() => {
|
||||
cy.get('@onChange').should('have.callCount', 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be called on blocks.clear() with removed and added blocks', () => {
|
||||
createEditor([
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue