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 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
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

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
8 changes: 6 additions & 2 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +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 ?? 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
2 changes: 1 addition & 1 deletion types/tools/tool-settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export interface ToolSettings {
/**
* Tool's Toolbox settings
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
*/
toolbox?: ToolboxConfig;
toolbox?: ToolboxConfig | false;
}