import InlineTool from '../interfaces/tools/inline-tool'; import SelectionUtils from '../selection'; declare var $: any; /** * Bold Tool * * Inline Toolbar Tool * * Makes selected text bolder */ export default class BoldInlineTool implements InlineTool { /** * Native Document's command that uses for Bold */ private readonly commandName: string = 'bold'; /** * Styles */ private readonly CSS = { button: 'ce-inline-tool', buttonActive: 'ce-inline-tool--active', buttonModifier: 'ce-inline-tool--bold', }; /** * Elements */ private nodes = { button: undefined, }; /** * @param {{api: IAPI}} - CodeX Editor API */ constructor({api}) { } /** * Create button for Inline Toolbar */ public render(): HTMLElement { this.nodes.button = document.createElement('button'); this.nodes.button.type = 'button'; this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier); this.nodes.button.appendChild($.svg('bold', 13, 15)); return this.nodes.button; } /** * Wrap range with tag * @param {Range} range */ public surround(range: Range): void { document.execCommand(this.commandName); } /** * Check selection and set activated state to button if there are tag * @param {Selection} selection */ public checkState(selection: Selection): boolean { const isActive = document.queryCommandState(this.commandName); this.nodes.button.classList.toggle(this.CSS.buttonActive, isActive); return isActive; } /** * Set a shortcut */ public get shortcut(): string { return 'CMD+B'; } }