Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 2 additions & 8 deletions src/components/inline-tools/inline-tool-bold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import type { MenuConfig } from '../../../types/tools';
*
* Inline Toolbar Tool
*
* Makes selected text bolder
* Makes selected text bold
*/
export default class BoldInlineTool implements InlineTool {
/**
* Specifies Tool as Inline Toolbar Tool
*
* @returns {boolean}
*/
public static isInline = true;

Expand All @@ -25,13 +23,11 @@ export default class BoldInlineTool implements InlineTool {
/**
* Sanitizer Rule
* Leave <b> tags
*
* @returns {object}
*/
public static get sanitize(): SanitizerConfig {
return {
b: {},
} as SanitizerConfig;
};
}

/**
Expand All @@ -55,8 +51,6 @@ export default class BoldInlineTool implements InlineTool {

/**
* Set a shortcut
*
* @returns {boolean}
*/
public get shortcut(): string {
return 'CMD+B';
Expand Down
56 changes: 10 additions & 46 deletions src/components/inline-tools/inline-tool-italic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { InlineTool, SanitizerConfig } from '../../../types';
import { IconItalic } from '@codexteam/icons';
import type { MenuConfig } from '../../../types/tools';

/**
* Italic Tool
Expand All @@ -11,8 +12,6 @@ import { IconItalic } from '@codexteam/icons';
export default class ItalicInlineTool implements InlineTool {
/**
* Specifies Tool as Inline Toolbar Tool
*
* @returns {boolean}
*/
public static isInline = true;

Expand All @@ -24,64 +23,29 @@ export default class ItalicInlineTool implements InlineTool {
/**
* Sanitizer Rule
* Leave <i> tags
*
* @returns {object}
*/
public static get sanitize(): SanitizerConfig {
return {
i: {},
} as SanitizerConfig;
};
}

/**
* Native Document's command that uses for Italic
*/
private readonly commandName: string = 'italic';

/**
* Styles
*/
private readonly CSS = {
button: 'ce-inline-tool',
buttonActive: 'ce-inline-tool--active',
buttonModifier: 'ce-inline-tool--italic',
};

/**
* Elements
*/
private nodes: {button: HTMLButtonElement} = {
button: null,
};

/**
* Create button for Inline Toolbar
*/
public render(): HTMLElement {
this.nodes.button = document.createElement('button') as HTMLButtonElement;
this.nodes.button.type = 'button';
this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier);
this.nodes.button.innerHTML = IconItalic;

return this.nodes.button;
}

/**
* Wrap range with <i> tag
*/
public surround(): void {
document.execCommand(this.commandName);
}

/**
* Check selection and set activated state to button if there are <i> tag
*/
public checkState(): boolean {
const isActive = document.queryCommandState(this.commandName);

this.nodes.button.classList.toggle(this.CSS.buttonActive, isActive);

return isActive;
public render(): MenuConfig {
return {
icon: IconItalic,
name: 'italic',
toggle: true,
onActivate: () => document.execCommand(this.commandName),
isActive: () => document.queryCommandState(this.commandName),
};
}

/**
Expand Down