UNPKG

@atlaskit/editor-plugin-toolbar

Version:

Toolbar plugin for @atlaskit/editor-core

287 lines (286 loc) 10.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getToolbarComponents = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _react = _interopRequireDefault(require("react")); var _analytics = require("@atlaskit/editor-common/analytics"); var _toolbar = require("@atlaskit/editor-common/toolbar"); var _editorToolbar = require("@atlaskit/editor-toolbar"); var _consts = require("./consts"); var _OverflowMenu = require("./OverflowMenu"); var _OverflowMenuSection = require("./OverflowMenuSection"); var _OverflowSection = require("./OverflowSection"); var _PrimaryToolbar = require("./PrimaryToolbar"); var _Section = require("./Section"); var _TextCollapsedMenu = require("./TextCollapsedMenu"); var getInlineTextToolbarComponents = function getInlineTextToolbarComponents() { return [{ type: 'toolbar', key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR, component: function component(_ref) { var children = _ref.children; return /*#__PURE__*/_react.default.createElement(_editorToolbar.Toolbar, { label: _consts.SELECTION_TOOLBAR_LABEL, actionSubjectId: _analytics.ACTION_SUBJECT_ID.SELECTION_TOOLBAR, testId: 'editor-floating-toolbar' }, children); } }]; }; var getPrimaryToolbarComponents = function getPrimaryToolbarComponents(breakpointPreset) { return [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, component: function component(_ref2) { var children = _ref2.children; return /*#__PURE__*/_react.default.createElement(_PrimaryToolbar.PrimaryToolbar, { breakpointPreset: breakpointPreset }, children); } }]; }; var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(contextualFormattingEnabled, api, breakpointPreset) { var components = [{ type: _toolbar.TEXT_SECTION.type, key: _toolbar.TEXT_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION.key] }], component: function component(_ref3) { var children = _ref3.children, parents = _ref3.parents; return /*#__PURE__*/_react.default.createElement(_editorToolbar.Show, { above: "md" }, /*#__PURE__*/_react.default.createElement(_Section.Section, { parents: parents, api: api, testId: "text-section" }, children)); } }, { type: _toolbar.TEXT_SECTION_PRIMARY_TOOLBAR.type, key: _toolbar.TEXT_SECTION_PRIMARY_TOOLBAR.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION.key] }], component: function component(_ref4) { var children = _ref4.children, parents = _ref4.parents; return /*#__PURE__*/_react.default.createElement(_editorToolbar.Show, { above: "md" }, /*#__PURE__*/_react.default.createElement(_Section.Section, { parents: parents, api: api, testId: "text-section" }, children)); } }, { type: _toolbar.TEXT_SECTION_COLLAPSED.type, key: _toolbar.TEXT_SECTION_COLLAPSED.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION_COLLAPSED.key] }, { type: 'toolbar', key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION_COLLAPSED.key] }], component: function component(_ref5) { var children = _ref5.children, parents = _ref5.parents; return /*#__PURE__*/_react.default.createElement(_editorToolbar.Show, { below: "md" }, /*#__PURE__*/_react.default.createElement(_Section.Section, { parents: parents, api: api, testId: "text-section" }, children)); } }, { type: _toolbar.TEXT_COLLAPSED_GROUP.type, key: _toolbar.TEXT_COLLAPSED_GROUP.key, parents: [{ type: _toolbar.TEXT_SECTION_COLLAPSED.type, key: _toolbar.TEXT_SECTION_COLLAPSED.key, rank: 100 }] }, { type: _toolbar.TEXT_COLLAPSED_MENU.type, key: _toolbar.TEXT_COLLAPSED_MENU.key, parents: [{ type: _toolbar.TEXT_COLLAPSED_GROUP.type, key: _toolbar.TEXT_COLLAPSED_GROUP.key, rank: 100 }], component: _TextCollapsedMenu.TextCollapsedMenu }, { type: _toolbar.INSERT_BLOCK_SECTION.type, key: _toolbar.INSERT_BLOCK_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.INSERT_BLOCK_SECTION.key] }], component: function component(_ref6) { var children = _ref6.children, parents = _ref6.parents; return /*#__PURE__*/_react.default.createElement(_Section.Section, { testId: "insert-block-section", parents: parents, api: api, showSeparatorInFullPagePrimaryToolbar: true, isSharedSection: false }, children); } }, { type: _toolbar.LINKING_SECTION.type, key: _toolbar.LINKING_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.LINKING_SECTION.key] }, { type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.LINKING_SECTION.key] }], component: function component(_ref7) { var children = _ref7.children, parents = _ref7.parents; return /*#__PURE__*/_react.default.createElement(_Section.Section, { testId: "link-section", parents: parents, api: api, showSeparatorInFullPagePrimaryToolbar: true }, children); } }, { type: _toolbar.OVERFLOW_SECTION.type, key: _toolbar.OVERFLOW_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.OVERFLOW_SECTION.key] }] }, { type: _toolbar.OVERFLOW_GROUP.type, key: _toolbar.OVERFLOW_GROUP.key, parents: [{ type: _toolbar.OVERFLOW_SECTION.type, key: _toolbar.OVERFLOW_SECTION.key, rank: _toolbar.OVERFLOW_SECTION_RANK[_toolbar.OVERFLOW_GROUP.key] }] }, { type: _toolbar.OVERFLOW_MENU.type, key: _toolbar.OVERFLOW_MENU.key, parents: [{ type: _toolbar.OVERFLOW_GROUP.type, key: _toolbar.OVERFLOW_GROUP.key, rank: _toolbar.OVERFLOW_GROUP_RANK[_toolbar.OVERFLOW_MENU.key] }], component: function component(_ref8) { var children = _ref8.children; return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children); } }, { type: _toolbar.OVERFLOW_EXTENSIONS_MENU_SECTION.type, key: _toolbar.OVERFLOW_EXTENSIONS_MENU_SECTION.key, parents: [{ type: _toolbar.OVERFLOW_MENU.type, key: _toolbar.OVERFLOW_MENU.key, rank: _toolbar.OVERFLOW_MENU_RANK[_toolbar.OVERFLOW_EXTENSIONS_MENU_SECTION.key] }], component: _OverflowMenuSection.OverflowMenuSection }, { type: _toolbar.PIN_SECTION.type, key: _toolbar.PIN_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.PIN_SECTION.key] }], component: function component(_ref9) { var children = _ref9.children, parents = _ref9.parents; return /*#__PURE__*/_react.default.createElement(_Section.Section, { testId: "pin-section", parents: parents, api: api, showSeparatorInFullPagePrimaryToolbar: true }, children); } }]; components.push({ type: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.type, key: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key] }], component: function component(_ref0) { var children = _ref0.children; return /*#__PURE__*/_react.default.createElement(_OverflowSection.OverflowSection, null, children); } }, { type: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.type, key: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key, parents: [{ type: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.type, key: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key, rank: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key] }] }, { type: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.type, key: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key, parents: [{ type: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.type, key: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key, rank: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key] }], component: function component(_ref1) { var children = _ref1.children; return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children); } }); switch (contextualFormattingEnabled) { case 'always-inline': components.unshift.apply(components, (0, _toConsumableArray2.default)(getInlineTextToolbarComponents())); break; case 'always-pinned': components.unshift.apply(components, (0, _toConsumableArray2.default)(getPrimaryToolbarComponents(breakpointPreset))); break; case 'controlled': components.unshift.apply(components, (0, _toConsumableArray2.default)(getInlineTextToolbarComponents())); components.unshift.apply(components, (0, _toConsumableArray2.default)(getPrimaryToolbarComponents(breakpointPreset))); break; } components.push({ type: _toolbar.TRACK_CHANGES_SECTION.type, key: _toolbar.TRACK_CHANGES_SECTION.key, parents: [{ type: 'toolbar', key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR, rank: _toolbar.TOOLBAR_RANK[_toolbar.TRACK_CHANGES_SECTION.key] }], component: function component(_ref10) { var children = _ref10.children, parents = _ref10.parents; return /*#__PURE__*/_react.default.createElement(_Section.Section, { testId: "track-changes-section", parents: parents, api: api, showSeparatorInFullPagePrimaryToolbar: true }, children); } }); return components; };