* Fix #1640

* Update changelog

* Fix typo
This commit is contained in:
George Berezhnoy 2021-04-14 22:07:16 +03:00 committed by GitHub
parent 04749ed098
commit 2996affb0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View file

@ -2,6 +2,7 @@
### 2.20.2
- `Fix` — Append default Tunes if user tunes are provided for Block Tool [#1640](https://github.com/codex-team/editor.js/issues/1640)
- `Fix` - Prevent the leak of codex-tooltip when Editor.js is destroyed [#1475](https://github.com/codex-team/editor.js/issues/1475).
### 2.20.1

View file

@ -354,23 +354,27 @@ export default class Tools extends Module {
* @param tool Block Tool
*/
private assignBlockTunesToBlockTool(tool: BlockTool): void {
if (tool.enabledInlineTools === false) {
if (tool.enabledBlockTunes === false) {
return;
}
if (Array.isArray(tool.enabledBlockTunes)) {
tool.tunes = new ToolsCollection<BlockTune>(
const userTunes = new ToolsCollection<BlockTune>(
tool.enabledBlockTunes.map(name => [name, this.blockTunes.get(name)])
);
tool.tunes = new ToolsCollection<BlockTune>([...userTunes, ...this.blockTunes.internalTools]);
return;
}
if (Array.isArray(this.config.tunes)) {
tool.tunes = new ToolsCollection<BlockTune>(
const userTunes = new ToolsCollection<BlockTune>(
this.config.tunes.map(name => [name, this.blockTunes.get(name)])
);
tool.tunes = new ToolsCollection<BlockTune>([...userTunes, ...this.blockTunes.internalTools]);
return;
}

View file

@ -103,6 +103,7 @@ describe('Tools module', () => {
class: class {} as any,
inlineToolbar: true,
},
blockToolWithoutSettings: class {} as any,
inlineTool: class {
public static isInline = true
@ -204,12 +205,28 @@ describe('Tools module', () => {
expect(Array.from(module.blockTools.values()).every(tool => tool.isBlock())).to.be.true;
});
it('Block Tools should contain default tunes if no settings is specified', () => {
const tool = module.blockTools.get('blockToolWithoutSettings');
expect(tool.tunes.has('deleteTune')).to.be.true;
expect(tool.tunes.has('moveUpTune')).to.be.true;
expect(tool.tunes.has('moveDownTune')).to.be.true;
});
it('Block Tools should contain default tunes', () => {
const tool = module.blockTools.get('blockTool');
expect(tool.tunes.has('deleteTune')).to.be.true;
expect(tool.tunes.has('moveUpTune')).to.be.true;
expect(tool.tunes.has('moveDownTune')).to.be.true;
});
it('Block Tools should contain tunes in correct order', () => {
let tool = module.blockTools.get('blockTool');
expect(tool.tunes.has('blockTune')).to.be.true;
expect(tool.tunes.has('blockTune2')).to.be.true;
expect(Array.from(tool.tunes.keys())).to.be.deep.eq(['blockTune2', 'blockTune']);
expect(Array.from(tool.tunes.keys())).to.be.deep.eq(['blockTune2', 'blockTune', 'moveUpTune', 'deleteTune', 'moveDownTune']);
tool = module.blockTools.get('withSuccessfulPrepare');