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(modules): Tooltip module is util now #1601

Merged
merged 9 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

### 2.20.1

- `Refactoring` - Tooltip module is util now.

### 2.20.0

- `New` — [Block Tunes API](block-tunes.md) added


### 2.19.3

- `Fix` — Ignore error raised by Shortcut module
Expand Down
6 changes: 3 additions & 3 deletions src/components/__module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export default class Module<T extends ModuleNodes = {}> {

/**
* @class
*
* @param {EditorConfig} config - Editor's config
* @param {EventsDispatcher} eventsDispatcher - Editor's event dispatcher
* @param {object} moduleConfiguration - Module Configuration
* @param {EditorConfig} moduleConfiguration.config - Editor's config
* @param {EventsDispatcher} moduleConfiguration.eventsDispatcher - Editor's event dispatcher
*/
constructor({ config, eventsDispatcher }: ModuleConfig) {
if (new.target === Module) {
Expand Down
34 changes: 28 additions & 6 deletions src/components/modules/api/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import { Tooltip } from '../../../../types/api';
import { Tooltip as ITooltip } from '../../../../types/api';
import { TooltipContent, TooltipOptions } from 'codex-tooltip';
import Module from '../../__module';

import { ModuleConfig } from '../../../types-internal/module-config';
import Tooltip from '../../utils/tooltip';
import EventsDispatcher from '../../utils/events';
import { EditorConfig } from '../../../../types';
/**
* @class TooltipAPI
* @classdesc Tooltip API
*/
export default class TooltipAPI extends Module {
/**
* Tooltip utility Instance
*/
private tooltip: Tooltip;
/**
* @class
* @param {object} moduleConfiguration - Module Configuration
* @param {EditorConfig} moduleConfiguration.config - Editor's config
* @param {EventsDispatcher} moduleConfiguration.eventsDispatcher - Editor's event dispatcher
*/
constructor({ config, eventsDispatcher }: ModuleConfig) {
super({
config,
eventsDispatcher,
});

this.tooltip = new Tooltip();
}

/**
* Available methods
*/
public get methods(): Tooltip {
public get methods(): ITooltip {
return {
show: (element: HTMLElement,
content: TooltipContent,
Expand All @@ -32,14 +54,14 @@ export default class TooltipAPI extends Module {
* @param {TooltipOptions} options - tooltip options
*/
public show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
this.Editor.Tooltip.show(element, content, options);
this.tooltip.show(element, content, options);
}

/**
* Method hides tooltip on HTML page
*/
public hide(): void {
this.Editor.Tooltip.hide();
this.tooltip.hide();
}

/**
Expand All @@ -50,6 +72,6 @@ export default class TooltipAPI extends Module {
* @param {TooltipOptions} options - tooltip options
*/
public onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
this.Editor.Tooltip.onHover(element, content, options);
this.tooltip.onHover(element, content, options);
}
}
26 changes: 24 additions & 2 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import $ from '../../dom';
import * as _ from '../../utils';
import I18n from '../../i18n';
import { I18nInternalNS } from '../../i18n/namespace-internal';
import Tooltip from '../../utils/tooltip';
import { ModuleConfig } from '../../../types-internal/module-config';
import EventsDispatcher from '../../utils/events';
import { EditorConfig } from '../../../../types';

/**
* HTML Elements used for Toolbar UI
Expand Down Expand Up @@ -72,6 +76,24 @@ interface ToolbarNodes {
* @property {Element} nodes.defaultSettings - Default Settings section of Settings Panel
*/
export default class Toolbar extends Module<ToolbarNodes> {
/**
* Tooltip utility Instance
*/
private tooltip: Tooltip;
/**
* @class
* @param {object} moduleConfiguration - Module Configuration
* @param {EditorConfig} moduleConfiguration.config - Editor's config
* @param {EventsDispatcher} moduleConfiguration.eventsDispatcher - Editor's event dispatcher
*/
constructor({ config, eventsDispatcher }: ModuleConfig) {
super({
config,
eventsDispatcher,
});
this.tooltip = new Tooltip();
}

/**
* CSS styles
*
Expand Down Expand Up @@ -277,7 +299,7 @@ export default class Toolbar extends Module<ToolbarNodes> {
textContent: '⇥ Tab',
}));

this.Editor.Tooltip.onHover(this.nodes.plusButton, tooltipContent);
this.tooltip.onHover(this.nodes.plusButton, tooltipContent);

/**
* Fill Actions Zone:
Expand All @@ -293,7 +315,7 @@ export default class Toolbar extends Module<ToolbarNodes> {
$.append(this.nodes.blockActionsButtons, this.nodes.settingsToggler);
$.append(this.nodes.actions, this.nodes.blockActionsButtons);

this.Editor.Tooltip.onHover(
this.tooltip.onHover(
this.nodes.settingsToggler,
I18n.ui(I18nInternalNS.ui.blockTunes.toggler, 'Click to tune'),
{
Expand Down
30 changes: 26 additions & 4 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import Module from '../../__module';
import $ from '../../dom';
import SelectionUtils from '../../selection';
import * as _ from '../../utils';
import { InlineTool as IInlineTool } from '../../../../types';
import { InlineTool as IInlineTool, InlineToolConstructable, ToolConstructable, ToolSettings, EditorConfig } from '../../../../types';
import Flipper from '../../flipper';
import I18n from '../../i18n';
import { I18nInternalNS } from '../../i18n/namespace-internal';
import Shortcuts from '../../utils/shortcuts';
import { EditorModules } from '../../../types-internal/editor-modules';
import Tooltip from '../../utils/tooltip';
import { ModuleConfig } from '../../../types-internal/module-config';
import EventsDispatcher from '../../utils/events';
import InlineTool from '../../tools/inline';
import { CommonInternalSettings } from '../../tools/base';
import BlockTool from '../../tools/block';
Expand Down Expand Up @@ -93,6 +97,24 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
*/
private flipper: Flipper = null;

/**
* Tooltip utility Instance
*/
private tooltip: Tooltip;
/**
* @class
* @param {object} moduleConfiguration - Module Configuration
* @param {EditorConfig} moduleConfiguration.config - Editor's config
* @param {EventsDispatcher} moduleConfiguration.eventsDispatcher - Editor's event dispatcher
*/
constructor({ config, eventsDispatcher }: ModuleConfig) {
super({
config,
eventsDispatcher,
});
this.tooltip = new Tooltip();
}

/**
* Toggles read-only mode
*
Expand Down Expand Up @@ -500,7 +522,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
});
});

this.Editor.Tooltip.onHover(this.nodes.conversionToggler, I18n.ui(I18nInternalNS.ui.inlineToolbar.converter, 'Convert to'), {
this.tooltip.onHover(this.nodes.conversionToggler, I18n.ui(I18nInternalNS.ui.inlineToolbar.converter, 'Convert to'), {
placement: 'top',
hidingDelay: 100,
});
Expand Down Expand Up @@ -590,7 +612,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
*/
private addTool(tool: InlineTool): void {
const {
Tooltip,
Tools,
robonetphy marked this conversation as resolved.
Show resolved Hide resolved
} = this.Editor;

const instance = tool.create();
Expand Down Expand Up @@ -642,7 +664,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
}));
}

Tooltip.onHover(button, tooltipContent, {
this.tooltip.onHover(button, tooltipContent, {
placement: 'top',
hidingDelay: 100,
});
Expand Down
27 changes: 24 additions & 3 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Module from '../../__module';
import $ from '../../dom';
import * as _ from '../../utils';
import { BlockToolConstructable } from '../../../../types';
import { BlockToolConstructable, ToolConstructable, EditorConfig } from '../../../../types';
import Flipper from '../../flipper';
import { BlockToolAPI } from '../../block';
import I18n from '../../i18n';
import { I18nInternalNS } from '../../i18n/namespace-internal';
import Shortcuts from '../../utils/shortcuts';
import Tooltip from '../../utils/tooltip';
import { ModuleConfig } from '../../../types-internal/module-config';
import EventsDispatcher from '../../utils/events';
import BlockTool from '../../tools/block';

/**
Expand Down Expand Up @@ -41,7 +44,7 @@ export default class Toolbox extends Module<ToolboxNodes> {
*
* @returns {object.<string, string>}
*/
public get CSS(): {[name: string]: string} {
public get CSS(): { [name: string]: string } {
return {
toolbox: 'ce-toolbox',
toolboxButton: 'ce-toolbox__button',
Expand Down Expand Up @@ -84,6 +87,24 @@ export default class Toolbox extends Module<ToolboxNodes> {
*/
private flipper: Flipper = null;

/**
* Tooltip utility Instance
*/
private tooltip: Tooltip;
/**
* @class
* @param {object} moduleConfiguration - Module Configuration
* @param {EditorConfig} moduleConfiguration.config - Editor's config
* @param {EventsDispatcher} moduleConfiguration.eventsDispatcher - Editor's event dispatcher
*/
constructor({ config, eventsDispatcher }: ModuleConfig) {
super({
config,
eventsDispatcher,
});
this.tooltip = new Tooltip();
}

/**
* Makes the Toolbox
*/
Expand Down Expand Up @@ -219,7 +240,7 @@ export default class Toolbox extends Module<ToolboxNodes> {
*/
const tooltipContent = this.drawTooltip(tool);

this.Editor.Tooltip.onHover(button, tooltipContent, {
this.tooltip.onHover(button, tooltipContent, {
placement: 'bottom',
hidingDelay: 200,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable jsdoc/no-undefined-types */
import Module from '../__module';

/**
* Use external module CodeX Tooltip
*/
Expand All @@ -11,7 +9,7 @@ import CodeXTooltips, { TooltipContent, TooltipOptions } from 'codex-tooltip';
*
* Decorates any tooltip module like adapter
*/
export default class Tooltip extends Module {
export default class Tooltip {
/**
* Tooltips lib: CodeX Tooltips
*
Expand Down
2 changes: 0 additions & 2 deletions src/types-internal/editor-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Toolbox from '../components/modules/toolbar/toolbox';
import BlockSettings from '../components/modules/toolbar/blockSettings';
import Paste from '../components/modules/paste';
import Notifier from '../components/modules/notifier';
import Tooltip from '../components/modules/tooltip';
import DragNDrop from '../components/modules/dragNDrop';
import ModificationsObserver from '../components/modules/modificationsObserver';
import Renderer from '../components/modules/renderer';
Expand Down Expand Up @@ -56,7 +55,6 @@ export interface EditorModules {
Caret: Caret;
Saver: Saver;
Notifier: Notifier;
Tooltip: Tooltip;
BlockManager: BlockManager;
BlocksAPI: BlocksAPI;
CaretAPI: CaretAPI;
Expand Down