UNPKG

@atlaskit/editor-plugin-selection-extension

Version:

editor-plugin-selection-extension plugin for @atlaskit/editor-core

91 lines (90 loc) 4.09 kB
import React from 'react'; import { BLOCK_ACTIONS_MENU_SECTION, BLOCK_ACTIONS_MENU_SECTION_RANK, TRANSFORM_MENU_SECTION, BLOCK_ACTIONS_FEATURED_EXTENSION_SLOT_MENU_ITEM, TRANSFORM_MENU_SECTION_RANK, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_CREATE_MENU_SECTION_RANK, TRANSFORM_DEFAULT_EXTENSION_SLOT_MENU_ITEM } from '@atlaskit/editor-common/block-menu'; import { fg } from '@atlaskit/platform-feature-flags'; import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems'; import { SelectionExtensionComponentContextProvider } from '../SelectionExtensionComponentContext'; export function registerBlockMenuItems(_ref) { var extensionList = _ref.extensionList, api = _ref.api, editorViewRef = _ref.editorViewRef; extensionList.forEach(function (_ref2) { var source = _ref2.source, key = _ref2.key, blockMenu = _ref2.blockMenu; if (source !== 'first-party' || !blockMenu) { return; } if (!(api !== null && api !== void 0 && api.blockMenu)) { return; } var componentsToRegister = []; // Use placement from BlockMenuExtensionConfiguration // Featured placement: register under TRANSFORM_MENU_SECTION // Default placement: register under TRANSFORM_CREATE_MENU_SECTION if (blockMenu.placement === 'featured') { componentsToRegister.push({ type: 'block-menu-item', key: "selection-extension-".concat(key), parent: { type: 'block-menu-section', key: fg('platform_editor_block_menu_divider_patch') ? TRANSFORM_MENU_SECTION.key : BLOCK_ACTIONS_MENU_SECTION.key, rank: fg('platform_editor_block_menu_divider_patch') ? TRANSFORM_MENU_SECTION_RANK[BLOCK_ACTIONS_FEATURED_EXTENSION_SLOT_MENU_ITEM.key] : BLOCK_ACTIONS_MENU_SECTION_RANK[BLOCK_ACTIONS_FEATURED_EXTENSION_SLOT_MENU_ITEM.key] }, component: function component() { var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current; if (!editorView) { return null; } return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , { value: { api: api, editorView: editorView, extensionKey: key, extensionSource: source, extensionLocation: 'block-menu' } }, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, { getMenuItems: blockMenu.getMenuItems })); } }); } else { componentsToRegister.push({ type: 'block-menu-item', key: "selection-extension-".concat(key), isHidden: function isHidden() { return blockMenu.getMenuItems().length === 0; }, parent: { type: 'block-menu-section', key: TRANSFORM_CREATE_MENU_SECTION.key, rank: TRANSFORM_CREATE_MENU_SECTION_RANK[TRANSFORM_DEFAULT_EXTENSION_SLOT_MENU_ITEM.key] }, component: function component() { var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current; if (!editorView) { return null; } return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , { value: { api: api, editorView: editorView, extensionKey: key, extensionSource: source, extensionLocation: 'block-menu' } }, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, { getMenuItems: blockMenu.getMenuItems })); } }); } if (componentsToRegister.length > 0) { api.blockMenu.actions.registerBlockMenuComponents(componentsToRegister); } }); }