@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
65 lines • 1.93 kB
JavaScript
import { fg } from '@atlaskit/platform-feature-flags';
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 => {
var _pluginState$decorati;
if (!editorState) {
return {
isDisplayingChanges: false,
activeIndex: undefined
};
}
const pluginState = showDiffPluginKey.getState(editorState);
const decorationCount = fg('platform_editor_show_diff_scroll_navigation') ? getScrollableDecorations(pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations, editorState.doc) : (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$decorati = pluginState.decorations) === null || _pluginState$decorati === void 0 ? void 0 : _pluginState$decorati.find()) || [];
return {
isDisplayingChanges: decorationCount.length > 0,
activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
numberOfChanges: decorationCount.length
};
}
});