UNPKG

@atlaskit/editor-plugin-alignment

Version:

Alignment plugin for @atlaskit/editor-core

77 lines 2.37 kB
import React from 'react'; import { ALIGNMENT_GROUP, ALIGNMENT_GROUP_RANK, ALIGNMENT_MENU, ALIGNMENT_MENU_SECTION, TEXT_SECTION, TEXT_SECTION_RANK, ALIGNMENT_MENU_RANK, TEXT_COLLAPSED_MENU_RANK, TEXT_COLLAPSED_MENU, TEXT_SECTION_PRIMARY_TOOLBAR, TEXT_SECTION_PRIMARY_TOOLBAR_RANK } from '@atlaskit/editor-common/toolbar'; import { AlignmentMenu } from './Toolbar/AlignmentMenu'; import { AlignmentMenuItem } from './Toolbar/AlignmentMenuItem'; import { MenuSection } from './Toolbar/MenuSection'; import { alignmentOptions } from './Toolbar/options'; const getAlignmentMenuItems = api => { return Object.entries(alignmentOptions()).map(([alignment, item]) => { const { key, type, rank } = item; return { type, key, parents: [{ type: ALIGNMENT_MENU_SECTION.type, key: ALIGNMENT_MENU_SECTION.key, rank }], component: ({ parents }) => { return /*#__PURE__*/React.createElement(AlignmentMenuItem, { api: api, option: item, alignment: alignment, parents: parents }); } }; }); }; export const getToolbarComponents = api => { return [{ type: ALIGNMENT_GROUP.type, key: ALIGNMENT_GROUP.key, parents: [{ type: TEXT_SECTION.type, key: TEXT_SECTION.key, rank: TEXT_SECTION_RANK[ALIGNMENT_GROUP.key] }, { type: TEXT_SECTION_PRIMARY_TOOLBAR.type, key: TEXT_SECTION_PRIMARY_TOOLBAR.key, rank: TEXT_SECTION_PRIMARY_TOOLBAR_RANK[ALIGNMENT_GROUP.key] }] }, { type: ALIGNMENT_MENU.type, key: ALIGNMENT_MENU.key, parents: [{ type: ALIGNMENT_GROUP.type, key: ALIGNMENT_GROUP.key, rank: ALIGNMENT_GROUP_RANK[ALIGNMENT_MENU.key] }], component: ({ children }) => { return /*#__PURE__*/React.createElement(AlignmentMenu, { api: api }, children); } }, { type: ALIGNMENT_MENU_SECTION.type, key: ALIGNMENT_MENU_SECTION.key, parents: [{ type: ALIGNMENT_MENU.type, key: ALIGNMENT_MENU.key, rank: ALIGNMENT_MENU_RANK[ALIGNMENT_MENU_SECTION.key] }, { type: TEXT_COLLAPSED_MENU.type, key: TEXT_COLLAPSED_MENU.key, rank: TEXT_COLLAPSED_MENU_RANK[ALIGNMENT_MENU_SECTION.key] }], component: MenuSection }, ...getAlignmentMenuItems(api)]; };