@atlaskit/editor-plugin-panel
Version:
Panel plugin for @atlaskit/editor-core.
66 lines • 2.22 kB
JavaScript
import React from 'react';
import { PanelType } from '@atlaskit/adf-schema/panel';
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
import { IconCustomPanel, IconPanel, IconPanelError, IconPanelNote, IconPanelSuccess, IconPanelWarning } from '@atlaskit/editor-common/quick-insert';
import { CUSTOM_PANEL_MENU_ITEM, ERROR_PANEL_MENU_ITEM, INFO_PANEL_MENU_ITEM, NOTE_PANEL_MENU_ITEM, STRUCTURE_SECTION, SUCCESS_PANEL_MENU_ITEM, WARNING_PANEL_MENU_ITEM } from '@atlaskit/editor-common/quick-insert/keys';
import { STRUCTURE_SECTION_RANK } from '@atlaskit/editor-common/quick-insert/rank';
import { PanelQuickInsertMenuItem } from './PanelQuickInsertMenuItem';
const standardPanelItems = [{
icon: IconPanel,
menuItem: INFO_PANEL_MENU_ITEM,
panelType: PanelType.INFO,
title: blockTypeMessages.infoPanel
}, {
icon: IconPanelNote,
menuItem: NOTE_PANEL_MENU_ITEM,
panelType: PanelType.NOTE,
title: blockTypeMessages.notePanel
}, {
icon: IconPanelSuccess,
menuItem: SUCCESS_PANEL_MENU_ITEM,
panelType: PanelType.SUCCESS,
title: blockTypeMessages.successPanel
}, {
icon: IconPanelWarning,
menuItem: WARNING_PANEL_MENU_ITEM,
panelType: PanelType.WARNING,
title: blockTypeMessages.warningPanel
}, {
icon: IconPanelError,
menuItem: ERROR_PANEL_MENU_ITEM,
panelType: PanelType.ERROR,
title: blockTypeMessages.errorPanel
}];
const customPanelItem = {
icon: IconCustomPanel,
menuItem: CUSTOM_PANEL_MENU_ITEM,
panelType: PanelType.CUSTOM,
title: blockTypeMessages.customPanel
};
export const getPanelQuickInsertComponents = ({
api,
allowCustomPanel,
allowCustomPanelEdit
}) => {
const allPanelItems = [...standardPanelItems, ...(allowCustomPanel && allowCustomPanelEdit ? [customPanelItem] : [])];
return allPanelItems.map(({
icon,
menuItem,
panelType,
title
}) => ({
key: menuItem.key,
type: menuItem.type,
parents: [{
key: STRUCTURE_SECTION.key,
type: STRUCTURE_SECTION.type,
rank: STRUCTURE_SECTION_RANK[menuItem.key]
}],
component: () => /*#__PURE__*/React.createElement(PanelQuickInsertMenuItem, {
api: api,
icon: icon,
panelType: panelType,
title: title
})
}));
};