Skip to content
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

Fix #1640 #1649

Merged
merged 4 commits into from
Apr 14, 2021
Merged
Changes from 3 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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 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)

### 2.20.1

- `Fix` - Create a new block when clicked at the bottom [#1588](https://github.com/codex-team/editor.js/issues/1588).
10 changes: 7 additions & 3 deletions src/components/modules/tools.ts
Original file line number Diff line number Diff line change
@@ -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;
}

19 changes: 18 additions & 1 deletion test/cypress/tests/modules/Tools.spec.ts
Original file line number Diff line number Diff line change
@@ -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');