|
5 | 5 | * @type {UI} |
6 | 6 | */ |
7 | 7 | import Module from '../__module'; |
8 | | -import $ from '../dom'; |
| 8 | +import $, { toggleEmptyMark } from '../dom'; |
9 | 9 | import * as _ from '../utils'; |
10 | 10 |
|
11 | 11 | import Selection from '../selection'; |
@@ -380,6 +380,12 @@ export default class UI extends Module<UINodes> { |
380 | 380 | * Start watching 'block-hovered' events that is used by Toolbar for moving |
381 | 381 | */ |
382 | 382 | this.watchBlockHoveredEvents(); |
| 383 | + |
| 384 | + /** |
| 385 | + * We have custom logic for providing placeholders for contenteditable elements. |
| 386 | + * To make it work, we need to have data-empty mark on empty inputs. |
| 387 | + */ |
| 388 | + this.enableInputsEmptyMark(); |
383 | 389 | } |
384 | 390 |
|
385 | 391 |
|
@@ -498,7 +504,7 @@ export default class UI extends Module<UINodes> { |
498 | 504 | /** |
499 | 505 | * Remove all highlights and remove caret |
500 | 506 | */ |
501 | | - this.Editor.BlockManager.dropPointer(); |
| 507 | + this.Editor.BlockManager.unsetCurrentBlock(); |
502 | 508 |
|
503 | 509 | /** |
504 | 510 | * Close Toolbar |
@@ -645,12 +651,12 @@ export default class UI extends Module<UINodes> { |
645 | 651 |
|
646 | 652 | if (!clickedInsideOfEditor) { |
647 | 653 | /** |
648 | | - * Clear highlights and pointer on BlockManager |
| 654 | + * Clear pointer on BlockManager |
649 | 655 | * |
650 | 656 | * Current page might contain several instances |
651 | 657 | * Click between instances MUST clear focus, pointers and close toolbars |
652 | 658 | */ |
653 | | - this.Editor.BlockManager.dropPointer(); |
| 659 | + this.Editor.BlockManager.unsetCurrentBlock(); |
654 | 660 | this.Editor.Toolbar.close(); |
655 | 661 | } |
656 | 662 |
|
@@ -874,4 +880,28 @@ export default class UI extends Module<UINodes> { |
874 | 880 |
|
875 | 881 | this.Editor.InlineToolbar.tryToShow(true); |
876 | 882 | } |
| 883 | + |
| 884 | + /** |
| 885 | + * Editor.js provides and ability to show placeholders for empty contenteditable elements |
| 886 | + * |
| 887 | + * This method watches for input and focus events and toggles 'data-empty' attribute |
| 888 | + * to workaroud the case, when inputs contains only <br>s and has no visible content |
| 889 | + * Then, CSS could rely on this attribute to show placeholders |
| 890 | + */ |
| 891 | + private enableInputsEmptyMark(): void { |
| 892 | + /** |
| 893 | + * Toggle data-empty attribute on input depending on its emptiness |
| 894 | + * |
| 895 | + * @param event - input or focus event |
| 896 | + */ |
| 897 | + function handleInputOrFocusChange(event: Event): void { |
| 898 | + const input = event.target as HTMLElement; |
| 899 | + |
| 900 | + toggleEmptyMark(input); |
| 901 | + } |
| 902 | + |
| 903 | + this.readOnlyMutableListeners.on(this.nodes.wrapper, 'input', handleInputOrFocusChange); |
| 904 | + this.readOnlyMutableListeners.on(this.nodes.wrapper, 'focusin', handleInputOrFocusChange); |
| 905 | + this.readOnlyMutableListeners.on(this.nodes.wrapper, 'focusout', handleInputOrFocusChange); |
| 906 | + } |
877 | 907 | } |
0 commit comments