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

[Draft] Feature/tooltip enhancements #907

Merged
merged 27 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@
[submodule "example/tools/warning"]
path = example/tools/warning
url = https://github.com/editor-js/warning
[submodule "src/components/external/codex.tooltips"]
path = src/components/external/codex.tooltips
url = https://github.com/codex-team/codex.tooltips
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

END OF TERMS AND CONDITIONS

Copyright © 2015-2018 CodeX
Copyright © 2015-present CodeX

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
22 changes: 16 additions & 6 deletions dist/editor.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions dist/editor.licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


codex-tooltip
MIT
Copyright 2019 CodeX https://codex.so

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


core-js
MIT
Copyright (c) 2014-2018 Denis Pushkarev
Expand Down
25 changes: 25 additions & 0 deletions docs/tools-inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,28 @@ static get sanitize() {
```

Read more about Sanitizer configuration at the [Tools#sanitize](tools.md#sanitize)

### Specifying a title

You can pass your Tool's title via `title` static getter. It can be used, for example, in the Tooltip with
icon description that appears by hover.

![](https://capella.pics/00e7094a-fdb9-429b-8015-9c56f19b4ef5.jpg)

```ts
export default class BoldInlineTool implements InlineTool {
/**
* Specifies Tool as Inline Toolbar Tool
*
* @return {boolean}
*/
public static isInline = true;

/**
* Title for hover-tooltip
*/
public static title: string = 'Bold';

// ... other methods
}
```
2 changes: 1 addition & 1 deletion example/tools/header
2 changes: 1 addition & 1 deletion example/tools/inline-code
2 changes: 1 addition & 1 deletion example/tools/marker
8 changes: 7 additions & 1 deletion src/components/block-tunes/block-tune-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export default class DeleteTune implements BlockTune {
this.nodes.button = $.make('div', [this.CSS.button, this.CSS.buttonDelete], {});
this.nodes.button.appendChild($.svg('cross', 12, 12));
this.api.listeners.on(this.nodes.button, 'click', (event: MouseEvent) => this.handleClick(event), false);

/**
* Enable tooltip module
*/
this.api.tooltip.onHover(this.nodes.button, 'Delete');

return this.nodes.button;
}

Expand Down Expand Up @@ -95,8 +101,8 @@ export default class DeleteTune implements BlockTune {
this.api.events.off('block-settings-closed', this.resetConfirmation);

this.api.blocks.delete();

this.api.toolbar.close();
this.api.tooltip.hide();

/**
* Prevent firing ui~documentClicked that can drop currentBlock pointer
Expand Down
8 changes: 8 additions & 0 deletions src/components/block-tunes/block-tune-move-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export default class MoveDownTune implements BlockTune {
(event) => this.handleClick(event as MouseEvent, moveDownButton),
false,
);

/**
* Enable tooltip module on button
*/
this.api.tooltip.onHover(moveDownButton, 'Move down');

return moveDownButton;
}

Expand Down Expand Up @@ -88,5 +94,7 @@ export default class MoveDownTune implements BlockTune {
/** Change blocks positions */
this.api.blocks.swap(currentBlockIndex, currentBlockIndex + 1);

/** Hide the Tooltip */
this.api.tooltip.hide();
}
}
9 changes: 9 additions & 0 deletions src/components/block-tunes/block-tune-move-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export default class MoveUpTune implements BlockTune {
(event) => this.handleClick(event as MouseEvent, moveUpButton),
false,
);

/**
* Enable tooltip module on button
*/
this.api.tooltip.onHover(moveUpButton, 'Move up');

return moveUpButton;
}

Expand Down Expand Up @@ -94,5 +100,8 @@ export default class MoveUpTune implements BlockTune {

/** Change blocks positions */
this.api.blocks.swap(currentBlockIndex, currentBlockIndex - 1);

/** Hide the Tooltip */
this.api.tooltip.hide();
}
}
1 change: 1 addition & 0 deletions src/components/external/codex.tooltips
Submodule codex.tooltips added at 8aeef1
5 changes: 5 additions & 0 deletions src/components/inline-tools/inline-tool-bold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export default class BoldInlineTool implements InlineTool {
*/
public static isInline = true;

/**
* Title for hover-tooltip
*/
public static title: string = 'Bold';

/**
* Sanitizer Rule
* Leave <b> tags
Expand Down
5 changes: 5 additions & 0 deletions src/components/inline-tools/inline-tool-italic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export default class ItalicInlineTool implements InlineTool {
*/
public static isInline = true;

/**
* Title for hover-tooltip
*/
public static title: string = 'Italic';

/**
* Sanitizer Rule
* Leave <i> tags
Expand Down
5 changes: 5 additions & 0 deletions src/components/inline-tools/inline-tool-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export default class LinkInlineTool implements InlineTool {
*/
public static isInline = true;

/**
* Title for hover-tooltip
*/
public static title: string = 'Link';

/**
* Sanitizer Rule
* Leave <a> tags
Expand Down
1 change: 1 addition & 0 deletions src/components/modules/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class API extends Module {
styles: this.Editor.StylesAPI.classes,
toolbar: this.Editor.ToolbarAPI.methods,
inlineToolbar: this.Editor.InlineToolbarAPI.methods,
tooltip: this.Editor.TooltipAPI.methods,
} as APIInterfaces;
}
}
55 changes: 55 additions & 0 deletions src/components/modules/api/tooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Module from '../../__module';
import { Tooltip } from '../../../../types/api';
import {TooltipContent, TooltipOptions} from '../../external/codex.tooltips';

/**
* @class TooltipAPI
* @classdesc Tooltip API
*/
export default class TooltipAPI extends Module {
/**
* Available methods
*/
get methods(): Tooltip {
return {
show: (element: HTMLElement,
content: TooltipContent,
options?: TooltipOptions,
) => this.show(element, content, options),
hide: () => this.hide(),
onHover: (element: HTMLElement,
content: TooltipContent,
options?: TooltipOptions,
) => this.onHover(element, content, options),
};
}

/**
* Method show tooltip on element with passed HTML content
*
* @param {HTMLElement} element
* @param {TooltipContent} content
* @param {TooltipOptions} options
*/
public show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions) {
this.Editor.Tooltip.show(element, content, options);
}

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

/**
* Decorator for showing Tooltip by mouseenter/mouseleave
*
* @param {HTMLElement} element
* @param {TooltipContent} content
* @param {TooltipOptions} options
*/
public onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions) {
this.Editor.Tooltip.onHover(element, content, options);
}
}
36 changes: 15 additions & 21 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default class Toolbar extends Module {

// Content Zone
plusButton: 'ce-toolbar__plus',
plusButtonShortcut: 'ce-toolbar__plus-shortcut',
plusButtonHidden: 'ce-toolbar__plus--hidden',

// Actions Zone
Expand Down Expand Up @@ -113,33 +114,22 @@ export default class Toolbar extends Module {
* - Toolbox
*/
this.nodes.plusButton = $.make('div', this.CSS.plusButton);
$.append(this.nodes.plusButton, $.svg('plus', 14, 14));
$.append(this.nodes.content, this.nodes.plusButton);

this.Editor.Listeners.on(this.nodes.plusButton, 'click', () => this.plusButtonClicked(), false);

/**
* Add events to show/hide tooltip for plus button
*/
this.Editor.Listeners.on(this.nodes.plusButton, 'mouseenter', () => {
const tooltip = this.Editor.Toolbox.nodes.tooltip;
const fragment = document.createDocumentFragment();

fragment.appendChild(document.createTextNode('Add'));
fragment.appendChild($.make('div', this.Editor.Toolbox.CSS.tooltipShortcut, {
textContent: '⇥ Tab',
}));

tooltip.style.left = '-17px';

tooltip.innerHTML = '';
tooltip.appendChild(fragment);
tooltip.classList.add(this.Editor.Toolbox.CSS.tooltipShown);
});
const tooltipContent = $.make('div');

this.Editor.Listeners.on(this.nodes.plusButton, 'mouseleave', () => {
this.Editor.Toolbox.hideTooltip();
});
tooltipContent.appendChild(document.createTextNode('Add'));
tooltipContent.appendChild($.make('div', this.CSS.plusButtonShortcut, {
textContent: '⇥ Tab',
}));

$.append(this.nodes.plusButton, $.svg('plus', 14, 14));
$.append(this.nodes.content, this.nodes.plusButton);
this.Editor.Listeners.on(this.nodes.plusButton, 'click', () => this.plusButtonClicked(), false);
this.Editor.Tooltip.onHover(this.nodes.plusButton, tooltipContent);

/**
* Make a Toolbox
Expand All @@ -160,6 +150,10 @@ export default class Toolbar extends Module {
$.append(this.nodes.blockActionsButtons, this.nodes.settingsToggler);
$.append(this.nodes.actions, this.nodes.blockActionsButtons);

this.Editor.Tooltip.onHover(this.nodes.settingsToggler, 'Click to tune', {
placement: 'top',
});

/**
* Make and append Settings Panel
*/
Expand Down
27 changes: 27 additions & 0 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class InlineToolbar extends Module {
inlineToolbarShowed: 'ce-inline-toolbar--showed',
inlineToolbarLeftOriented: 'ce-inline-toolbar--left-oriented',
inlineToolbarRightOriented: 'ce-inline-toolbar--right-oriented',
inlineToolbarShortcut: 'ce-inline-toolbar__shortcut',
buttonsWrapper: 'ce-inline-toolbar__buttons',
actionsWrapper: 'ce-inline-toolbar__actions',
inlineToolButton: 'ce-inline-tool',
Expand Down Expand Up @@ -420,6 +421,11 @@ export default class InlineToolbar extends Module {
}
});
});

this.Editor.Tooltip.onHover(this.nodes.conversionToggler, 'Convert to', {
placement: 'top',
hidingDelay: 100,
});
}

/**
Expand Down Expand Up @@ -483,6 +489,7 @@ export default class InlineToolbar extends Module {
const {
Listeners,
Tools,
Tooltip,
} = this.Editor;

const button = tool.render();
Expand Down Expand Up @@ -540,6 +547,26 @@ export default class InlineToolbar extends Module {
if (shortcut) {
this.enableShortcuts(tool, shortcut);
}

/**
* Enable tooltip module on button
*/
const tooltipContent = $.make('div');
const toolTitle = Tools.toolsClasses[toolName][Tools.INTERNAL_SETTINGS.TITLE] || _.capitalize(toolName);

tooltipContent.appendChild($.text(toolTitle));

if (shortcut) {
tooltipContent.appendChild($.make('div', this.CSS.inlineToolbarShortcut, {
textContent: _.beautifyShortcut(shortcut),
}));
}

Tooltip.onHover(button, tooltipContent, {
placement: 'top',
hidingDelay: 100,
});

}

/**
Expand Down
Loading