UNPKG

@atlaskit/editor-plugin-primary-toolbar

Version:

Primary toolbar plugin for @atlaskit/editor-core

36 lines (35 loc) 1.39 kB
import { registerComponent } from './editor-actions/actions'; import { createPlugin, primaryToolbarPluginKey } from './pm-plugins/pm-plugin'; import Separator from './ui/separator'; export var primaryToolbarPlugin = function primaryToolbarPlugin(_ref) { var config = _ref.config; // We use a plugin variable to store the component registry to avoid having to use // effects in each plugin, and to enable rendering the toolbar in SSR // TODO: ED-26962 - Replace this with something in plugin state once we have a way to initialise across plugins on plugin initialisation var componentRegistry = new Map(); // Pre-fill registry with the separator component componentRegistry.set('separator', Separator); return { name: 'primaryToolbar', actions: { registerComponent: registerComponent(componentRegistry) }, pmPlugins: function pmPlugins() { return [{ name: 'primaryToolbar', plugin: function plugin() { return createPlugin({ componentRegistry: componentRegistry, contextualFormattingEnabled: config === null || config === void 0 ? void 0 : config.contextualFormattingEnabled }); } }]; }, getSharedState: function getSharedState(editorState) { if (!editorState) { return; } return primaryToolbarPluginKey.getState(editorState); } }; };