@atlaskit/editor-plugin-quick-insert
Version:
Quick insert plugin for @atlaskit/editor-core
103 lines • 3.31 kB
JavaScript
import React from 'react';
import { useIntl } from 'react-intl';
import { BLOCK_TEMPLATES_SECTION, DATA_AND_CHARTS_SECTION, EMBED_SECTION, MEDIA_SECTION, MENU, OTHER_SECTION, RECOMMENDED_SECTION, ROVO_SECTION, STRUCTURE_SECTION, TEXT_FORMATTING_SECTION, VIEW_ALL_ELEMENTS_MENU_ITEM } from '@atlaskit/editor-common/quick-insert/keys';
import { QuickInsertMenuRoot } from '@atlaskit/editor-common/quick-insert/menu-root';
import { QuickInsertMenuSection } from '@atlaskit/editor-common/quick-insert/menu-section';
import { messages } from '@atlaskit/editor-common/quick-insert/messages';
import { CATEGORY_VIEW_MORE_RANK, QUICK_INSERT_MENU_RANK } from '@atlaskit/editor-common/quick-insert/rank';
import { getMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-get-menu-footer-section-key';
import { getSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-get-section-overflow-item-key';
import { QuickInsertMenuFooterItem } from './QuickInsertMenuFooterItem';
import { QuickInsertSectionOverflowMenuItem } from './QuickInsertSectionOverflowMenuItem';
const categories = [{
message: messages.categoryRecommended,
section: RECOMMENDED_SECTION
}, {
message: messages.categoryStructure,
section: STRUCTURE_SECTION
}, {
message: messages.categoryMedia,
section: MEDIA_SECTION
}, {
message: messages.categoryEmbed,
section: EMBED_SECTION
}, {
message: messages.categoryTextFormatting,
section: TEXT_FORMATTING_SECTION
}, {
message: messages.categoryRovo,
section: ROVO_SECTION
}, {
message: messages.categoryDataAndCharts,
section: DATA_AND_CHARTS_SECTION
}, {
message: messages.categoryBlockTemplates,
section: BLOCK_TEMPLATES_SECTION
}, {
message: messages.categoryOther,
section: OTHER_SECTION
}];
const createSectionComponent = message => {
const SectionComponent = ({
children
}) => {
const {
formatMessage
} = useIntl();
return /*#__PURE__*/React.createElement(QuickInsertMenuSection, {
title: formatMessage(message)
}, children);
};
return SectionComponent;
};
export const getQuickInsertComponents = ({
api,
includeElementBrowserItems
}) => [{
key: MENU.key,
type: MENU.type,
component: QuickInsertMenuRoot
}, ...categories.flatMap(({
message,
section
}) => [{
key: section.key,
type: section.type,
parents: [{
key: MENU.key,
type: MENU.type,
rank: QUICK_INSERT_MENU_RANK[section.key]
}],
component: createSectionComponent(message)
}, ...(includeElementBrowserItems ? [{
key: getSectionOverflowItemKey(section.key),
type: 'menu-item',
parents: [{
key: section.key,
type: section.type,
rank: CATEGORY_VIEW_MORE_RANK
}],
component: () => /*#__PURE__*/React.createElement(QuickInsertSectionOverflowMenuItem, {
api,
category: section.key
})
}] : [])]), ...(includeElementBrowserItems ? [{
key: getMenuFooterSectionKey(MENU.key),
type: 'menu-section',
parents: [{
key: MENU.key,
type: MENU.type,
rank: Number.MAX_SAFE_INTEGER
}]
}, {
key: VIEW_ALL_ELEMENTS_MENU_ITEM.key,
type: VIEW_ALL_ELEMENTS_MENU_ITEM.type,
parents: [{
key: getMenuFooterSectionKey(MENU.key),
type: 'menu-section',
rank: 100
}],
component: () => /*#__PURE__*/React.createElement(QuickInsertMenuFooterItem, {
api
})
}] : [])];