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/hide conversion toolbar #991

Merged
merged 7 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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 dist/editor.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- `Fix` — Set initial hidden Inline Toolbar position [#979](https://github.com/codex-team/editor.js/issues/979)
- `Fix` — Fix issue with CodeX.Toolips TypeScript definitions [#978](https://github.com/codex-team/editor.js/issues/978)
- `Fix` — Fix some issues with Inline and Tunes toolbars.
- `Fix` - Fix `minHeight` option with zero-value issue [#724](https://github.com/codex-team/editor.js/issues/724)
- `Fix` - Fix `minHeight` option with zero-value issue [#724](https://github.com/codex-team/editor.js/issues/724)
- `Improvements` — Unable Conversion Toolbar if there are no Conversion Tools

### 2.16

Expand Down
9 changes: 9 additions & 0 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ export default class ConversionToolbar extends Module {
}
}

/**
* Returns true if it has any more than one conversion tool
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Returns true if it has any more than one conversion tool
* Returns true if it has more than one tool available for convert in

*/
public hasConversionTools(): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

better to name hasTools because we have no such entity as «conversion tool»

const tools = Object.keys(this.tools); // available tools in array representation

return !(tools.length === 1 && tools.shift() === this.config.initialBlock);
}

/**
* Replaces one Block with another
* For that Tools must provide import/export methods
Expand Down
16 changes: 14 additions & 2 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export default class InlineToolbar extends Module {
*/
this.addTools();

/**
* Prepare conversion toolbar.
* If it has any conversion tool then it will be enabled in the Inline Toolbar
*/
this.prepareConversionToolbar();

/**
Expand Down Expand Up @@ -273,6 +277,10 @@ export default class InlineToolbar extends Module {
this.buttonsList = this.nodes.buttons.querySelectorAll(`.${this.CSS.inlineToolButton}`);
this.opened = true;

if (!this.Editor.ConversionToolbar.hasConversionTools()) {
this.nodes.conversionToggler.hidden = true;
}

/**
* Change Conversion Dropdown content for current tool
*/
Expand Down Expand Up @@ -447,8 +455,12 @@ export default class InlineToolbar extends Module {
const conversionConfig = Tools.available[toolName][Tools.INTERNAL_SETTINGS.CONVERSION_CONFIG] || {};
const exportRuleDefined = conversionConfig && conversionConfig.export;

this.nodes.conversionToggler.hidden = !exportRuleDefined;
this.nodes.conversionToggler.classList.toggle(this.CSS.conversionTogglerHidden, !exportRuleDefined);
if (this.Editor.ConversionToolbar.hasConversionTools()) {
this.nodes.conversionToggler.hidden = !exportRuleDefined;
this.nodes.conversionToggler.classList.toggle(this.CSS.conversionTogglerHidden, !exportRuleDefined);
} else {
this.nodes.conversionToggler.hidden = true;
}

/**
* Get icon or title for dropdown
Expand Down