@atlaskit/editor-plugin-toolbar
Version:
Toolbar plugin for @atlaskit/editor-core
70 lines (69 loc) • 3.53 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Section = void 0;
var _react = _interopRequireDefault(require("react"));
var _toolbar = require("@atlaskit/editor-common/toolbar");
var _editorToolbar = require("@atlaskit/editor-toolbar");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking, contextualFormattingEnabled) {
if (editMode === 'view') {
return false;
}
if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_placement_overridden')) {
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR) {
return toolbarDocking !== 'top' || contextualFormattingEnabled === 'always-inline';
}
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.PRIMARY_TOOLBAR) {
return toolbarDocking !== 'none' || contextualFormattingEnabled === 'always-pinned';
}
} else {
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
return true;
}
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.PRIMARY_TOOLBAR && toolbarDocking !== 'none') {
return true;
}
}
return false;
};
var usePluginState = function usePluginState(_api) {
var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
editorViewMode = _useEditorToolbar.editorViewMode,
editorToolbarDockingPreference = _useEditorToolbar.editorToolbarDockingPreference,
editorAppearance = _useEditorToolbar.editorAppearance;
return {
editorViewMode: editorViewMode,
editorToolbarDockingPreference: editorToolbarDockingPreference,
editorAppearance: editorAppearance
};
};
var Section = exports.Section = function Section(_ref) {
var _api$toolbar$actions$, _api$toolbar;
var children = _ref.children,
parents = _ref.parents,
api = _ref.api,
testId = _ref.testId,
showSeparatorInFullPagePrimaryToolbar = _ref.showSeparatorInFullPagePrimaryToolbar,
_ref$isSharedSection = _ref.isSharedSection,
isSharedSection = _ref$isSharedSection === void 0 ? true : _ref$isSharedSection;
var _usePluginState = usePluginState(api),
editorViewMode = _usePluginState.editorViewMode,
editorToolbarDockingPreference = _usePluginState.editorToolbarDockingPreference,
editorAppearance = _usePluginState.editorAppearance;
var toolbar = parents.find(function (parent) {
return parent.type === 'toolbar';
});
var contextualFormattingEnabled = (_api$toolbar$actions$ = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.contextualFormattingMode()) !== null && _api$toolbar$actions$ !== void 0 ? _api$toolbar$actions$ : 'always-pinned';
if (isSharedSection && !shouldShowSection(editorViewMode, toolbar, editorToolbarDockingPreference, contextualFormattingEnabled)) {
return null;
}
var isFullPage = editorAppearance === 'full-page';
var hasSeparator = showSeparatorInFullPagePrimaryToolbar && isFullPage;
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarSection, {
testId: testId,
hasSeparator: hasSeparator ? _editorToolbar.SeparatorPosition.START : hasSeparator
}, children);
};