UNPKG

@atlaskit/editor-plugin-unsupported-content

Version:

Unsupported Content plugin for @atlaskit/editor-core

98 lines (97 loc) • 4.46 kB
import { confluenceUnsupportedBlock } from '@atlaskit/adf-schema/confluence-unsupported-block'; import { confluenceUnsupportedInline } from '@atlaskit/adf-schema/confluence-unsupported-inline'; import { unsupportedBlock } from '@atlaskit/adf-schema/unsupported-block'; import { unsupportedInline } from '@atlaskit/adf-schema/unsupported-inline'; import { unsupportedMark } from '@atlaskit/adf-schema/unsupported-mark'; import { unsupportedNodeAttribute } from '@atlaskit/adf-schema/unsupported-node-attributes'; import { getInlineNodeViewProducer } from '@atlaskit/editor-common/getInlineNodeViewProducer'; import ReactNodeView from '@atlaskit/editor-common/react-node-view'; import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import UnsupportedBlock from '@atlaskit/editor-common/UnsupportedBlock'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled'; import { UnsupportedBlockNodeView } from './nodeviews/unsupported-block-node-view'; import { UnsupportedInlineNodeView } from './nodeviews/unsupported-inline-node-view'; import { UnsupportedInlineNodeViewVanilla } from './nodeviews/unsupported-inline-node-view-vanilla'; var pluginKey = new PluginKey('unsupportedContentPlugin'); var createPlugin = function createPlugin(pmPluginFactoryParams) { var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI, eventDispatcher = pmPluginFactoryParams.eventDispatcher, dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent, getIntl = pmPluginFactoryParams.getIntl; var intl = getIntl(); return new SafePlugin({ key: pluginKey, props: { nodeViews: { confluenceUnsupportedBlock: isExperimentEnabled('platform_editor_vanilla_node_views_phase1') ? function (node) { return new UnsupportedBlockNodeView(node, intl, dispatchAnalyticsEvent); } : ReactNodeView.fromComponent(UnsupportedBlock, portalProviderAPI, eventDispatcher, { dispatchAnalyticsEvent: dispatchAnalyticsEvent }, undefined), confluenceUnsupportedInline: isExperimentEnabled('platform_editor_vanilla_node_views_phase1') ? function (node) { return new UnsupportedInlineNodeViewVanilla(node, intl, dispatchAnalyticsEvent); } : getInlineNodeViewProducer({ pmPluginFactoryParams: pmPluginFactoryParams, Component: UnsupportedInlineNodeView, extraComponentProps: { dispatchAnalyticsEvent: dispatchAnalyticsEvent } }), unsupportedBlock: isExperimentEnabled('platform_editor_vanilla_node_views_phase1') ? function (node) { return new UnsupportedBlockNodeView(node, intl, dispatchAnalyticsEvent); } : ReactNodeView.fromComponent(UnsupportedBlock, portalProviderAPI, eventDispatcher, { dispatchAnalyticsEvent: dispatchAnalyticsEvent }, undefined), unsupportedInline: isExperimentEnabled('platform_editor_vanilla_node_views_phase1') ? function (node) { return new UnsupportedInlineNodeViewVanilla(node, intl, dispatchAnalyticsEvent); } : getInlineNodeViewProducer({ pmPluginFactoryParams: pmPluginFactoryParams, Component: UnsupportedInlineNodeView, extraComponentProps: { dispatchAnalyticsEvent: dispatchAnalyticsEvent } }) } } }); }; /** * Unsupported content plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor` * from `@atlaskit/editor-core`. */ export var unsupportedContentPlugin = function unsupportedContentPlugin() { return { name: 'unsupportedContent', marks: function marks() { return [{ name: 'unsupportedMark', mark: unsupportedMark }, { name: 'unsupportedNodeAttribute', mark: unsupportedNodeAttribute }]; }, nodes: function nodes() { return [{ name: 'confluenceUnsupportedBlock', node: confluenceUnsupportedBlock }, { name: 'confluenceUnsupportedInline', node: confluenceUnsupportedInline }, { name: 'unsupportedBlock', node: unsupportedBlock }, { name: 'unsupportedInline', node: unsupportedInline }]; }, pmPlugins: function pmPlugins() { return [{ name: 'unsupportedContent', plugin: createPlugin }]; } }; };