@atlaskit/editor-plugin-selection-extension
Version:
editor-plugin-selection-extension plugin for @atlaskit/editor-core
98 lines (96 loc) • 4.4 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerBlockMenuItems = registerBlockMenuItems;
var _react = _interopRequireDefault(require("react"));
var _blockMenu = require("@atlaskit/editor-common/block-menu");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _SelectionExtensionMenuItems = require("../menu/SelectionExtensionMenuItems");
var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
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: (0, _platformFeatureFlags.fg)('platform_editor_block_menu_divider_patch') ? _blockMenu.TRANSFORM_MENU_SECTION.key : _blockMenu.BLOCK_ACTIONS_MENU_SECTION.key,
rank: (0, _platformFeatureFlags.fg)('platform_editor_block_menu_divider_patch') ? _blockMenu.TRANSFORM_MENU_SECTION_RANK[_blockMenu.BLOCK_ACTIONS_FEATURED_EXTENSION_SLOT_MENU_ITEM.key] : _blockMenu.BLOCK_ACTIONS_MENU_SECTION_RANK[_blockMenu.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.default.createElement(_SelectionExtensionComponentContext.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.default.createElement(_SelectionExtensionMenuItems.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: _blockMenu.TRANSFORM_CREATE_MENU_SECTION.key,
rank: _blockMenu.TRANSFORM_CREATE_MENU_SECTION_RANK[_blockMenu.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.default.createElement(_SelectionExtensionComponentContext.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.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
getMenuItems: blockMenu.getMenuItems
}));
}
});
}
if (componentsToRegister.length > 0) {
api.blockMenu.actions.registerBlockMenuComponents(componentsToRegister);
}
});
}