@atlaskit/editor-plugin-code-bidi-warning
Version:
Code bidi warning plugin for @atlaskit/editor-core.
61 lines • 2.29 kB
JavaScript
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 const createPlugin = (api, {
dispatch,
getIntl,
nodeViewPortalProviderAPI
}, {
appearance
}) => {
const intl = getIntl();
const codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label);
const {
createPluginState,
getPluginState
} = reactPluginFactoryCreator(nodeViewPortalProviderAPI);
return new SafePlugin({
key: codeBidiWarningPluginKey,
state: createPluginState(dispatch, state => {
var _api$limitedMode, _api$limitedMode$shar;
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$shar = _api$limitedMode.sharedState.currentState()) !== null && _api$limitedMode$shar !== void 0 && _api$limitedMode$shar.enabled) {
return {
decorationSet: DecorationSet.empty,
codeBidiWarningLabel: '',
tooltipEnabled: false
};
}
return {
decorationSet: reactCreateBidiWarningsDecorationSetFromDoc({
doc: state.doc,
codeBidiWarningLabel,
tooltipEnabled: true,
nodeViewPortalProviderAPI
}),
codeBidiWarningLabel,
tooltipEnabled: true
};
}),
props: {
decorations: state => {
if (expValEquals('platform_editor_remove_bidi_char_warning', 'isEnabled', true)) {
return DecorationSet.empty;
}
const {
decorationSet
} = getPluginState(state);
return decorationSet;
}
}
});
};