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

Save Tools' order in the Toolbox #1113

Merged
merged 5 commits into from
Apr 25, 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.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `Improvements` - TSLint (deprecated) replaced with ESLint, old config changed to [CodeX ESLint Config](https://github.com/codex-team/eslint-config).
- `Improvements` - Fix many code-style issues, add missed annotations.
- `Improvements` - Adjusted GitHub action for ESLint.
- `Fix` - Toolbox: Tool's order in Toolbox is now saved in accordance with `tools` object keys order [#1073](https://github.com/codex-team/editor.js/issues/1073)

### 2.17

Expand Down
17 changes: 14 additions & 3 deletions src/components/modules/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default class Tools extends Module {
* @param {object} data - append tool to available list
*/
public success(data: {toolName: string}): void {
console.log(data);
Copy link
Member

Choose a reason for hiding this comment

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

log

this.toolsAvailable[data.toolName] = this.toolsClasses[data.toolName];
}

Expand Down Expand Up @@ -429,20 +430,30 @@ export default class Tools extends Module {
for (const toolName in this.toolsClasses) {
if (Object.prototype.hasOwnProperty.call(this.toolsClasses, toolName)) {
const toolClass = this.toolsClasses[toolName];
const toolConfig = this.toolsSettings[toolName][this.USER_SETTINGS.CONFIG];

if (typeof toolClass.prepare === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

so this condition is no longer needed because both cases are similar.

toolPreparationList.push({
function: toolClass.prepare,
data: {
toolName,
config: this.toolsSettings[toolName][this.USER_SETTINGS.CONFIG],
config: toolConfig,
},
});
} else {
/**
* If Tool hasn't a prepare method, mark it as available
* If Tool hasn't a prepare method,
* still push it to tool preparation list to save tools order in Toolbox.
* As Tool's prepare method might be async, _.sequence util helps to save the order.
*/
this.toolsAvailable[toolName] = toolClass;
toolPreparationList.push({
// eslint-disable-next-line @typescript-eslint/no-empty-function
function: () => {},
data: {
toolName,
config: toolConfig,
},
});
}
}
}
Expand Down