UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

63 lines 1.59 kB
import { getScrollableDecorations } from './pm-plugins/getScrollableDecorations'; import { createPlugin, showDiffPluginKey } from './pm-plugins/main'; export const showDiffPlugin = ({ api, config }) => ({ name: 'showDiff', commands: { showDiff: params => ({ tr }) => { return tr.setMeta(showDiffPluginKey, { ...params, action: 'SHOW_DIFF' }); }, hideDiff: ({ tr }) => { return tr.setMeta(showDiffPluginKey, { steps: [], action: 'HIDE_DIFF' }); }, scrollToNext: ({ tr }) => { return tr.setMeta(showDiffPluginKey, { action: 'SCROLL_TO_NEXT' }); }, scrollToPrevious: ({ tr }) => { return tr.setMeta(showDiffPluginKey, { action: 'SCROLL_TO_PREVIOUS' }); } }, pmPlugins() { return [{ name: 'showDiffPlugin', plugin: ({ getIntl }) => createPlugin(config, getIntl, api) }]; }, getSharedState: editorState => { if (!editorState) { return { isDisplayingChanges: false, activeIndex: undefined }; } const pluginState = showDiffPluginKey.getState(editorState); const decorationCount = getScrollableDecorations(pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations, editorState.doc); return { isDisplayingChanges: decorationCount.length > 0, activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex, numberOfChanges: decorationCount.length }; } });