Skip to content

Commit

Permalink
Use false in order to hide toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
hata6502 authored and t.hata committed Jul 31, 2020
1 parent 36ccfef commit 419ca2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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
6 changes: 3 additions & 3 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ 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];

if (userToolboxSettings.hidden === undefined ? toolToolboxSettings.hidden : userToolboxSettings.hidden === true) {
if ((userToolboxSettings ?? toolToolboxSettings) === false) {
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;

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

Expand Down
7 changes: 1 addition & 6 deletions types/tools/tool-settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export interface ToolboxConfig {
* HTML string with an icon for Toolbox
*/
icon?: string;

/**
* Hide from tool box, but load the tool
*/
hidden?: boolean;
}

/**
Expand Down Expand Up @@ -50,5 +45,5 @@ export interface ToolSettings {
/**
* Tool's Toolbox settings
*/
toolbox?: ToolboxConfig;
toolbox?: ToolboxConfig | false;
}

0 comments on commit 419ca2f

Please sign in to comment.