UNPKG

@atlaskit/editor-plugin-code-bidi-warning

Version:

Code bidi warning plugin for @atlaskit/editor-core.

57 lines 2.59 kB
import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages'; import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { DecorationSet } from '@atlaskit/editor-prosemirror/view'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import { codeBidiWarningPluginKey } from './plugin-key'; import { createBidiWarningsDecorationSetFromDoc as reactCreateBidiWarningsDecorationSetFromDoc, pluginFactoryCreator as reactPluginFactoryCreator } from './react-plugin-factory'; export var createPlugin = function createPlugin(api, _ref, _ref2) { var dispatch = _ref.dispatch, getIntl = _ref.getIntl, nodeViewPortalProviderAPI = _ref.nodeViewPortalProviderAPI; var appearance = _ref2.appearance; var intl = getIntl(); var codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label); var _reactPluginFactoryCr = reactPluginFactoryCreator(nodeViewPortalProviderAPI), createPluginState = _reactPluginFactoryCr.createPluginState, getPluginState = _reactPluginFactoryCr.getPluginState; return new SafePlugin({ key: codeBidiWarningPluginKey, state: createPluginState(dispatch, function (state) { var _api$limitedMode; if (expValEquals('platform_editor_remove_bidi_char_warning', 'isEnabled', true)) { return { decorationSet: DecorationSet.empty, codeBidiWarningLabel: '', tooltipEnabled: false }; } if (api !== null && api !== void 0 && (_api$limitedMode = api.limitedMode) !== null && _api$limitedMode !== void 0 && (_api$limitedMode = _api$limitedMode.sharedState.currentState()) !== null && _api$limitedMode !== void 0 && _api$limitedMode.enabled) { return { decorationSet: DecorationSet.empty, codeBidiWarningLabel: '', tooltipEnabled: false }; } return { decorationSet: reactCreateBidiWarningsDecorationSetFromDoc({ doc: state.doc, codeBidiWarningLabel: codeBidiWarningLabel, tooltipEnabled: true, nodeViewPortalProviderAPI: nodeViewPortalProviderAPI }), codeBidiWarningLabel: codeBidiWarningLabel, tooltipEnabled: true }; }), props: { decorations: function decorations(state) { if (expValEquals('platform_editor_remove_bidi_char_warning', 'isEnabled', true)) { return DecorationSet.empty; } var _getPluginState = getPluginState(state), decorationSet = _getPluginState.decorationSet; return decorationSet; } } }); };