UNPKG

@atlaskit/editor-plugin-feature-flags

Version:

Feature flags plugin for @atlaskit/editor-core

42 lines (41 loc) 1.96 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; var pluginKey = new PluginKey('featureFlags'); /** * Feature flag plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor` * from `@atlaskit/editor-core`. */ export var featureFlagsPlugin = function featureFlagsPlugin(_ref) { var _ref$config = _ref.config, featureFlags = _ref$config === void 0 ? {} : _ref$config; return { name: 'featureFlags', getSharedState: function getSharedState(editorState) { if (!editorState) { return featureFlags || {}; } return pluginKey.getState(editorState) || featureFlags || {}; }, pmPlugins: function pmPlugins() { return [{ name: 'featureFlags', plugin: function plugin() { return new SafePlugin({ key: pluginKey, state: { init: function init() { return _objectSpread({}, featureFlags); }, apply: function apply(_, pluginState) { return pluginState; } } }); } }]; } }; };