UNPKG

@atlaskit/editor-plugin-text-formatting

Version:

Text-formatting plugin for @atlaskit/editor-core

110 lines 4.3 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import React from 'react'; import { CLEAR_FORMARTTING_MENU_SECTION, CLEAR_FORMATTING_MENU_ITEM, TEXT_FORMATTING_MENU, TEXT_FORMATTING_MENU_SECTION, TEXT_FORMATTING_GROUP, TEXT_FORMATTING_GROUP_COLLAPSED, TEXT_FORMATTING_GROUP_INLINE, TEXT_FORMATTING_HERO_BUTTON, TEXT_FORMAT_GROUP_RANK, TEXT_FORMAT_MENU_RANK, CLEAR_FORMARTTING_MENU_SECTION_RANK, TEXT_COLLAPSED_MENU_RANK, TEXT_COLLAPSED_MENU } from '@atlaskit/editor-common/toolbar'; import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar'; import { ClearFormatMenuItem, MoreFormattingMenu, MenuSection, FormatMenuItem } from './Component'; import { formatOptions } from './utils'; export var getFormatMenuItems = function getFormatMenuItems(api) { return Object.entries(formatOptions()).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), optionType = _ref2[0], _ref2$ = _ref2[1], icon = _ref2$.icon, shortcut = _ref2$.shortcut, title = _ref2$.title, command = _ref2$.command, rank = _ref2$.rank, key = _ref2$.key; return { type: 'menu-item', key: key, parents: [{ type: TEXT_FORMATTING_MENU_SECTION.type, key: TEXT_FORMATTING_MENU_SECTION.key, rank: rank }], component: function component(_ref3) { var parents = _ref3.parents; return /*#__PURE__*/React.createElement(FormatMenuItem, { api: api, parents: parents, icon: icon, shortcut: shortcut, title: title, optionType: optionType, toggleMarkWithAnalyticsCallback: command }); } }; }); }; export var textFormattingMenuGroup = function textFormattingMenuGroup(api) { return [{ type: TEXT_FORMATTING_MENU.type, key: TEXT_FORMATTING_MENU.key, parents: [{ type: TEXT_FORMATTING_GROUP.type, key: TEXT_FORMATTING_GROUP.key, rank: TEXT_FORMAT_GROUP_RANK[TEXT_FORMATTING_MENU.key] }, { type: TEXT_FORMATTING_GROUP_COLLAPSED.type, key: TEXT_FORMATTING_GROUP_COLLAPSED.key, rank: TEXT_FORMAT_GROUP_RANK[TEXT_FORMATTING_MENU.key] }, { type: TEXT_FORMATTING_GROUP_INLINE.type, key: TEXT_FORMATTING_GROUP_INLINE.key, rank: TEXT_FORMAT_GROUP_RANK[TEXT_FORMATTING_HERO_BUTTON.key] }], component: function component(_ref4) { var children = _ref4.children; return /*#__PURE__*/React.createElement(MoreFormattingMenu, null, children); } }, { type: TEXT_FORMATTING_MENU_SECTION.type, key: TEXT_FORMATTING_MENU_SECTION.key, parents: [{ type: TEXT_FORMATTING_MENU.type, key: TEXT_FORMATTING_MENU.key, rank: TEXT_FORMAT_MENU_RANK[TEXT_FORMATTING_MENU_SECTION.key] }, { type: TEXT_COLLAPSED_MENU.type, key: TEXT_COLLAPSED_MENU.key, rank: TEXT_COLLAPSED_MENU_RANK[TEXT_FORMATTING_MENU_SECTION.key] }], component: MenuSection }].concat(_toConsumableArray(getFormatMenuItems(api)), [{ type: CLEAR_FORMARTTING_MENU_SECTION.type, key: CLEAR_FORMARTTING_MENU_SECTION.key, parents: [{ type: TEXT_FORMATTING_MENU.type, key: TEXT_FORMATTING_MENU.key, rank: TEXT_FORMAT_MENU_RANK[CLEAR_FORMARTTING_MENU_SECTION.key] }, { type: TEXT_COLLAPSED_MENU.type, key: TEXT_COLLAPSED_MENU.key, rank: TEXT_COLLAPSED_MENU_RANK[CLEAR_FORMARTTING_MENU_SECTION.key] }], component: function component(_ref5) { var children = _ref5.children; return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, { hasSeparator: true }, children); } }, { type: CLEAR_FORMATTING_MENU_ITEM.type, key: CLEAR_FORMATTING_MENU_ITEM.key, parents: [{ type: CLEAR_FORMARTTING_MENU_SECTION.type, key: CLEAR_FORMARTTING_MENU_SECTION.key, rank: CLEAR_FORMARTTING_MENU_SECTION_RANK[CLEAR_FORMATTING_MENU_ITEM.key] }], component: function component(_ref6) { var parents = _ref6.parents; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ClearFormatMenuItem, { parents: parents, api: api })); } }]); };