MCPcopy Index your code
hub / github.com/codex-team/editor.js / documentClicked

Method documentClicked

src/components/modules/ui.ts:659–707  ·  view source on GitHub ↗

* All clicks on document * * @param {MouseEvent} event - Click event

(event: MouseEvent)

Source from the content-addressed store, hash-verified

657 * @param {MouseEvent} event - Click event
658 */
659 private documentClicked(event: MouseEvent): void {
660 /**
661 * Sometimes we emulate click on some UI elements, for example by Enter on Block Settings button
662 * We don't need to handle such events, because they handled in other place.
663 */
664 if (!event.isTrusted) {
665 return;
666 }
667 /**
668 * Close Inline Toolbar when nothing selected
669 * Do not fire check on clicks at the Inline Toolbar buttons
670 */
671 const target = event.target as HTMLElement;
672 const clickedInsideOfEditor = this.nodes.holder.contains(target) || Selection.isAtEditor;
673
674 if (!clickedInsideOfEditor) {
675 /**
676 * Clear pointer on BlockManager
677 *
678 * Current page might contain several instances
679 * Click between instances MUST clear focus, pointers and close toolbars
680 */
681 this.Editor.BlockManager.unsetCurrentBlock();
682 this.Editor.Toolbar.close();
683 }
684
685 /**
686 * If Block Settings opened, close them by click on document.
687 *
688 * But allow clicking inside Block Settings.
689 * Also, do not process clicks on the Block Settings Toggler, because it has own click listener
690 */
691 const isClickedInsideBlockSettings = this.Editor.BlockSettings.nodes.wrapper?.contains(target);
692 const isClickedInsideBlockSettingsToggler = this.Editor.Toolbar.nodes.settingsToggler?.contains(target);
693 const doNotProcess = isClickedInsideBlockSettings || isClickedInsideBlockSettingsToggler;
694
695 if (this.Editor.BlockSettings.opened && !doNotProcess) {
696 this.Editor.BlockSettings.close();
697
698 const clickedBlock = this.Editor.BlockManager.getBlockByChildNode(target);
699
700 this.Editor.Toolbar.moveAndOpen(clickedBlock);
701 }
702
703 /**
704 * Clear Selection if user clicked somewhere
705 */
706 this.Editor.BlockSelection.clearSelection(event);
707 }
708
709 /**
710 * First touch on editor

Callers 1

Calls 5

unsetCurrentBlockMethod · 0.80
getBlockByChildNodeMethod · 0.80
moveAndOpenMethod · 0.80
closeMethod · 0.65
clearSelectionMethod · 0.45

Tested by

no test coverage detected