@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
51 lines (50 loc) • 2.79 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EditorToolbarUIProvider = void 0;
var _react = _interopRequireWildcard(require("react"));
var _editorToolbar = require("@atlaskit/editor-toolbar");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var EditorToolbarUIProvider = exports.EditorToolbarUIProvider = function EditorToolbarUIProvider(_ref) {
var children = _ref.children,
api = _ref.api,
isDisabled = _ref.isDisabled,
popupsMountPoint = _ref.popupsMountPoint,
popupsBoundariesElement = _ref.popupsBoundariesElement,
popupsScrollableElement = _ref.popupsScrollableElement,
fireAnalyticsEvent = _ref.fireAnalyticsEvent,
keyboardNavigation = _ref.keyboardNavigation;
var onDropdownOpenChanged = (0, _react.useCallback)(function (_ref2) {
var isOpen = _ref2.isOpen,
event = _ref2.event;
if (!isOpen) {
// Only refocus the editor when the dropdown closes via mouse or programmatic close.
// When closed via keyboard Escape, keep focus on the trigger for better keyboard UX.
var isKeyboardEscape = event instanceof KeyboardEvent && event.key === 'Escape';
var shouldFocusEditor = !isKeyboardEscape;
if (shouldFocusEditor) {
// On Dropdown closed, focus is returned to trigger button by default in requestAnimationFrame
// Hence, `.focus()` should also be called in requestAnimationFrame
setTimeout(function () {
return requestAnimationFrame(function () {
api === null || api === void 0 || api.core.actions.focus({
scrollIntoView: false
});
});
}, 1);
}
}
}, [api]);
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarUIProvider, {
onDropdownOpenChanged: onDropdownOpenChanged,
preventDefaultOnMouseDown: true,
isDisabled: isDisabled,
popupsMountPoint: popupsMountPoint,
popupsBoundariesElement: popupsBoundariesElement,
popupsScrollableElement: popupsScrollableElement,
fireAnalyticsEvent: fireAnalyticsEvent,
keyboardNavigation: keyboardNavigation
}, children);
};