UNPKG

@atlaskit/editor-plugin-selection-extension

Version:

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

57 lines (56 loc) 2.24 kB
/** * From the full list of extensions, extract only those that have a toolbar item configuration * for the specified type (either 'primaryToolbar' or 'inlineToolbar'). * * @param extensionList - List of all extensions * @param toolbarType - Type of toolbar ('primaryToolbar' or 'inlineToolbar') * @returns Array of ToolbarItemExtension objects * @example */ export var getToolbarItemExtensions = function getToolbarItemExtensions(extensionList, toolbarType) { return extensionList.reduce(function (acc, extension) { var toolbarConfig = extension[toolbarType]; if (toolbarConfig !== null && toolbarConfig !== void 0 && toolbarConfig.getToolbarItem) { acc.push({ getToolbarItem: toolbarConfig.getToolbarItem, getMenuItems: toolbarConfig.getMenuItems }); } return acc; }, []); }; /** * From the full list of extensions, extract only those that have a menu item configuration * for the specified source (either 'first-party' or 'external'). * * Map each to the legacy format for SelectionExtension. * * @param extensionList - List of all extensions * @param targetSource - Source of the extensions ('first-party' or 'external') * @returns Array of SelectionExtension objects * @example */ export var getMenuItemExtensions = function getMenuItemExtensions(extensionList, targetSource) { return extensionList.reduce(function (acc, extension) { var source = extension.source, inlineToolbar = extension.inlineToolbar; if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) { var menuItems = inlineToolbar.getMenuItems(); menuItems.forEach(function (menuItem) { // Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration if ('label' in menuItem && 'icon' in menuItem) { acc.push({ name: menuItem.label, icon: menuItem.icon, onClick: menuItem.onClick, isDisabled: function isDisabled() { return !!menuItem.isDisabled; }, component: menuItem.contentComponent }); } }); } return acc; }, []); };