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

Add hidden option to toolbox #1220

Merged
merged 6 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all 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.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `New` - Tool's `reset` static method added to the API to clean up any data added by Tool on initialization
- `Improvements` - Unuseful log about missed i18n section has been removed [#1269](https://github.com/codex-team/editor.js/issues/1269)
- `Fix` - Fixed issue with enter key in inputs and textareas [#920](https://github.com/codex-team/editor.js/issues/920)
- `Improvements` - Allowed to set `false` as `toolbox` config in order to hide Toolbox button [#1221](https://github.com/codex-team/editor.js/issues/1221)

### 2.18

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class Renderer extends Module {
const toolToolboxSettings = (Tools.unavailable[tool] as BlockToolConstructable).toolbox;
const userToolboxSettings = Tools.getToolSettings(tool).toolbox;

stubData.title = toolToolboxSettings.title || userToolboxSettings.title || stubData.title;
stubData.title = toolToolboxSettings.title || (userToolboxSettings && userToolboxSettings.title) || stubData.title;
}

const stub = BlockManager.insert({
Expand Down
9 changes: 7 additions & 2 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ export default class ConversionToolbar extends Module {
const toolToolboxSettings = toolClass[internalSettings.TOOLBOX];
const conversionConfig = toolClass[internalSettings.CONVERSION_CONFIG];

const userSettings = this.Editor.Tools.USER_SETTINGS;
const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX];

const toolboxSettings = userToolboxSettings ?? toolToolboxSettings;

/**
* Skip tools that don't pass 'toolbox' property
*/
if (_.isEmpty(toolToolboxSettings) || !toolToolboxSettings.icon) {
if (_.isEmpty(toolboxSettings) || !toolboxSettings.icon) {
continue;
}

Expand All @@ -278,7 +283,7 @@ export default class ConversionToolbar extends Module {
continue;
}

this.addTool(toolName, toolToolboxSettings.icon, toolToolboxSettings.title);
this.addTool(toolName, toolboxSettings.icon, toolboxSettings.title);
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ export default class Toolbox extends Module {
// return;
// }

const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX] || {};
const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX];

/**
* Hide Toolbox button if Toolbox settings is false
*/
if ((userToolboxSettings ?? toolToolboxSettings) === false) {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const button = $.make('li', [ this.CSS.toolboxButton ]);

button.dataset.tool = toolName;
button.innerHTML = userToolboxSettings.icon || toolToolboxSettings.icon;
button.innerHTML = (userToolboxSettings && userToolboxSettings.icon) || toolToolboxSettings.icon;
gohabereg marked this conversation as resolved.
Show resolved Hide resolved

$.append(this.nodes.toolbox, button);

Expand Down
3 changes: 2 additions & 1 deletion types/tools/tool-settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface ToolSettings {

/**
* Tool's Toolbox settings
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
* It will be hidden from Toolbox when false is specified.
*/
toolbox?: ToolboxConfig;
toolbox?: ToolboxConfig | false;
}