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

[Refactoring] Tools #1595

Merged
merged 13 commits into from
Mar 31, 2021
Merged

[Refactoring] Tools #1595

merged 13 commits into from
Mar 31, 2021

Conversation

gohabereg
Copy link
Member

I've added inner wrappers for tools so we can work with them as with abstract objects

@gohabereg gohabereg marked this pull request as ready for review March 15, 2021 04:48
@gohabereg gohabereg changed the title [WIP][Reafctoring] Tools [Refactoring] Tools Mar 15, 2021
.gitmodules Outdated Show resolved Hide resolved
src/components/block/index.ts Show resolved Hide resolved
src/components/tools/base.ts Outdated Show resolved Hide resolved
PasteConfig = 'pasteConfig'
}

export type ToolConfig = Omit<ToolSettings, 'class'>
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest naming it ToolOptions or something like that, to avoid conflicts with tools config property.

public name: string;

/**
* Flag show is current Tool internal or not
Copy link
Member

Choose a reason for hiding this comment

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

need to clarify what does internal tool mean

/**
* Editor default tool
*/
protected defaultTool: string;
Copy link
Member

Choose a reason for hiding this comment

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

why not using isDefault: boolean?

/**
* Returns true if current Tool is default
*/
public get isDefault(): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Is it related only to Block Tools? If so, we need to move it from the abstract class to the BlockTool

@@ -5,6 +5,7 @@ import Module from '../__module';
import * as _ from '../utils';
import SelectionUtils from '../selection';
import Flipper from '../flipper';
import BlockTool from '../tools/block';
Copy link
Member

Choose a reason for hiding this comment

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

where this class is used?

ToolConstructable,
ToolSettings
} from '../../../types';
import BoldInlineTool from '../inline-tools/inline-tool-bold';
import ItalicInlineTool from '../inline-tools/inline-tool-italic';
import LinkInlineTool from '../inline-tools/inline-tool-link';
import Stub from '../tools/stub';
import Stub from '../../tools/stub';
Copy link
Member

Choose a reason for hiding this comment

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

The Stub tool is just an implementation of the Block Tool, so it should not be placed at the same level as abstract tools classes. It would better to move it to the tools/block/stub

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a confusion about dir names. We have tools for paragraph and stub, I just moved it one level up


/**
* Tools` classes available to use
*/
private readonly toolsAvailable: { [name: string]: ToolConstructable } = {};
private readonly toolsAvailable: Map<string, InlineTool | BlockTool | BlockTune> = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

type ToolClass = InlineTool | BlockTool | BlockTune;

@@ -20,7 +20,7 @@ interface TagSubstitute {
*
* @type {string}
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
* @type {string}

@@ -46,7 +46,7 @@ interface PatternSubstitute {
*
* @type {string}
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
* @type {string}

}
});
Array
.from(block.entries())
Copy link
Member

Choose a reason for hiding this comment

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

I think, it's better to name Block Tools getter blockTools rather than block — it will be more readable

Copy link
Member

Choose a reason for hiding this comment

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

and inlineTools, blockTunes

src/components/tools/base.ts Show resolved Hide resolved
*
* @param {object} data - append tool to unavailable list
*/
private fallback(data: { toolName: string }): void {
Copy link
Member

Choose a reason for hiding this comment

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

naming is not clear.

@@ -229,8 +229,10 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
* Add Tool's settings
*/
private addToolSettings(): void {
if (_.isFunction(this.Editor.BlockManager.currentBlock.tool.renderSettings)) {
$.append(this.nodes.toolSettings, this.Editor.BlockManager.currentBlock.tool.renderSettings());
const settingsElement = this.Editor.BlockManager.currentBlock.renderSettings();
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
const settingsElement = this.Editor.BlockManager.currentBlock.renderSettings();
const settingsElement = this.Editor.BlockManager.currentBlock?.renderSettings();

Copy link
Member Author

Choose a reason for hiding this comment

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

currentBlock must be defined there. I'd suggest to leave it without ? because we will know something is wrong

Copy link
Member

Choose a reason for hiding this comment

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

but it will throw an exception if currentBlock is null

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant it cannot be null here, but if it is we will got an exception — that means something is not correct in the code

@gohabereg gohabereg merged commit 4cfcb65 into next Mar 31, 2021
@gohabereg gohabereg deleted the reafctoring/tools branch March 31, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants