-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Refactoring] Tools #1595
Conversation
src/components/tools/base.ts
Outdated
PasteConfig = 'pasteConfig' | ||
} | ||
|
||
export type ToolConfig = Omit<ToolSettings, 'class'> |
There was a problem hiding this comment.
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.
src/components/tools/base.ts
Outdated
public name: string; | ||
|
||
/** | ||
* Flag show is current Tool internal or not |
There was a problem hiding this comment.
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
src/components/tools/base.ts
Outdated
/** | ||
* Editor default tool | ||
*/ | ||
protected defaultTool: string; |
There was a problem hiding this comment.
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
?
src/components/tools/base.ts
Outdated
/** | ||
* Returns true if current Tool is default | ||
*/ | ||
public get isDefault(): boolean { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/components/modules/tools.ts
Outdated
|
||
/** | ||
* Tools` classes available to use | ||
*/ | ||
private readonly toolsAvailable: { [name: string]: ToolConstructable } = {}; | ||
private readonly toolsAvailable: Map<string, InlineTool | BlockTool | BlockTune> = new Map(); |
There was a problem hiding this comment.
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;
src/components/modules/paste.ts
Outdated
@@ -20,7 +20,7 @@ interface TagSubstitute { | |||
* | |||
* @type {string} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @type {string} |
src/components/modules/paste.ts
Outdated
@@ -46,7 +46,7 @@ interface PatternSubstitute { | |||
* | |||
* @type {string} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @type {string} |
src/components/modules/readonly.ts
Outdated
} | ||
}); | ||
Array | ||
.from(block.entries()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/modules/tools.ts
Outdated
* | ||
* @param {object} data - append tool to unavailable list | ||
*/ | ||
private fallback(data: { toolName: string }): void { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const settingsElement = this.Editor.BlockManager.currentBlock.renderSettings(); | |
const settingsElement = this.Editor.BlockManager.currentBlock?.renderSettings(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
I've added inner wrappers for tools so we can work with them as with abstract objects