@atlaskit/editor-plugin-find-replace
Version:
find replace plugin for @atlaskit/editor-core
36 lines • 930 B
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
import { createPluginState, getPluginState } from './plugin-factory';
import { findReplacePluginKey } from './plugin-key';
export const initialState = {
isActive: false,
shouldFocus: false,
findText: '',
replaceText: '',
index: 0,
matches: [],
decorationSet: DecorationSet.empty,
shouldMatchCase: false
};
export const createPlugin = (dispatch, getIntl, api) => {
return new SafePlugin({
key: findReplacePluginKey,
state: createPluginState(dispatch, () => ({
...initialState,
getIntl,
api
})),
props: {
decorations(state) {
const {
isActive,
findText,
decorationSet
} = getPluginState(state);
if (isActive && findText) {
return decorationSet;
}
}
}
});
};