UNPKG

@atlaskit/editor-plugin-toolbar

Version:

Toolbar plugin for @atlaskit/editor-core

70 lines (68 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getKeyboardNavigationConfig = void 0; var _browserApis = require("@atlaskit/browser-apis"); var _messages = require("@atlaskit/editor-common/messages"); var _monitoring = require("@atlaskit/editor-common/monitoring"); var _ui = require("@atlaskit/editor-common/ui"); var _toolbar = require("../utils/toolbar"); var getKeyboardNavigationConfig = exports.getKeyboardNavigationConfig = function getKeyboardNavigationConfig(editorView, intl, api) { if (!(editorView.dom instanceof HTMLElement)) { return; } var toolbarSelector = "[data-testid='editor-floating-toolbar']"; return { childComponentSelector: toolbarSelector, dom: editorView.dom, isShortcutToFocusToolbar: _toolbar.isShortcutToFocusToolbar, handleFocus: function handleFocus(event) { try { var _getDocument, _filteredFocusableEle, _filteredFocusableEle2, _filteredFocusableEle3; var toolbar = (_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.querySelector(toolbarSelector); if (!(toolbar instanceof HTMLElement)) { return; } var filteredFocusableElements = (0, _toolbar.getFocusableElements)(toolbar); (_filteredFocusableEle = filteredFocusableElements[0]) === null || _filteredFocusableEle === void 0 || _filteredFocusableEle.focus(); // the button element removes the focus ring so this class adds it back if (((_filteredFocusableEle2 = filteredFocusableElements[0]) === null || _filteredFocusableEle2 === void 0 ? void 0 : _filteredFocusableEle2.tagName) === 'BUTTON') { filteredFocusableElements[0].classList.add('first-floating-toolbar-button'); } (_filteredFocusableEle3 = filteredFocusableElements[0]) === null || _filteredFocusableEle3 === void 0 || _filteredFocusableEle3.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); event.preventDefault(); event.stopPropagation(); } catch (error) { if (error instanceof Error) { (0, _monitoring.logException)(error, { location: 'editor-plugin-toolbar/selectionToolbar' }); } } }, handleEscape: function handleEscape(event) { try { var isDropdownOpen = !!document.querySelector('[data-toolbar-component="menu-section"]'); if (isDropdownOpen) { return; } api === null || api === void 0 || api.core.actions.focus(); event.preventDefault(); event.stopPropagation(); } catch (error) { if (error instanceof Error) { (0, _monitoring.logException)(error, { location: 'editor-plugin-toolbar/selectionToolbar' }); } } }, ariaControls: _ui.EDIT_AREA_ID, ariaLabel: intl.formatMessage(_messages.fullPageMessages.toolbarLabel) }; };