@atlaskit/editor-plugin-insert-block
Version:
Insert block plugin for @atlaskit/editor-core
72 lines • 3.31 kB
JavaScript
import React, { useCallback } from 'react';
import Popup from '@atlaskit/editor-common/Popup';
import { useMenuPopupSizing } from '@atlaskit/editor-common/quick-insert/use-menu-popup-sizing';
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
import InsertMenu, { DEFAULT_HEIGHT } from '../ElementBrowser/InsertMenu';
import { RegisteredInsertMenuContent } from '../registered-insert-menu/RegisteredInsertMenuContent';
import { DropDownButton } from './dropdown-button';
// This determines how the popup should fit. We prefer the insert menu
// opening on the bottom as we have a search bar and should only open on
// top if there is more than sufficient room.
var FIT_HEIGHT_BUFFER = 100;
export var BlockInsertElementBrowser = function BlockInsertElementBrowser(props) {
var togglePlusMenuVisibility = props.togglePlusMenuVisibility,
plusButtonRef = props.plusButtonRef;
var isRegisteredMenu = isExperimentEnabled('platform_editor_slash_command');
var menuHeight = useMenuPopupSizing({
target: plusButtonRef,
boundariesElement: props.popupsBoundariesElement,
scrollableElement: props.popupsScrollableElement,
maxHeight: 520,
offset: 3,
isOpen: props.open && isRegisteredMenu
});
var closeRegisteredMenu = useCallback(function () {
return togglePlusMenuVisibility();
}, [togglePlusMenuVisibility]);
var closeRegisteredMenuAndRestoreFocus = useCallback(function () {
togglePlusMenuVisibility();
plusButtonRef === null || plusButtonRef === void 0 || plusButtonRef.focus();
}, [togglePlusMenuVisibility, plusButtonRef]);
return /*#__PURE__*/React.createElement(React.Fragment, null, props.open && /*#__PURE__*/React.createElement(Popup, {
target: props.plusButtonRef,
fitHeight: isRegisteredMenu ? menuHeight : DEFAULT_HEIGHT + FIT_HEIGHT_BUFFER,
fitWidth: 350
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
offset: [0, 3],
mountTo: props.popupsMountPoint,
boundariesElement: props.popupsBoundariesElement,
scrollableElement: props.popupsScrollableElement,
preventOverflow: true,
alignX: "right"
}, isRegisteredMenu ? /*#__PURE__*/React.createElement(RegisteredInsertMenuContent, {
api: props.pluginInjectionApi,
maxHeight: menuHeight,
editorView: props.editorView,
isOffline: Boolean(props.isEditorOffline),
onClose: closeRegisteredMenuAndRestoreFocus,
onDismiss: closeRegisteredMenu,
onSelect: closeRegisteredMenu,
target: props.plusButtonRef
}) : /*#__PURE__*/React.createElement(InsertMenu, {
editorView: props.editorView,
dropdownItems: props.items,
onInsert: props.onInsert,
toggleVisiblity: props.togglePlusMenuVisibility,
showElementBrowserLink: props.showElementBrowserLink,
pluginInjectionApi: props.pluginInjectionApi,
isFullPageAppearance: props.isFullPageAppearance
})), /*#__PURE__*/React.createElement(DropDownButton, {
"aria-expanded": props.open,
"aria-haspopup": true,
handleRef: props.onRef,
selected: props.open,
disabled: props.disabled,
onClick: props.onClick,
onKeyDown: props.onKeyDown,
spacing: props.spacing,
label: props.label,
"aria-keyshortcuts": "/"
}));
};