UNPKG

@atlaskit/editor-plugin-feature-flags

Version:

Feature flags plugin for @atlaskit/editor-core

33 lines (32 loc) 867 B
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; const pluginKey = new PluginKey('featureFlags'); /** * Feature flag plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor` * from `@atlaskit/editor-core`. */ export const featureFlagsPlugin = ({ config: featureFlags = {} }) => ({ name: 'featureFlags', getSharedState(editorState) { if (!editorState) { return featureFlags || {}; } return pluginKey.getState(editorState) || featureFlags || {}; }, pmPlugins() { return [{ name: 'featureFlags', plugin: () => new SafePlugin({ key: pluginKey, state: { init: () => ({ ...featureFlags }), apply: (_, pluginState) => pluginState } }) }]; } });