UNPKG

@atlaskit/editor-plugin-find-replace

Version:

find replace plugin for @atlaskit/editor-core

39 lines 1.9 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } 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 var initialState = { isActive: false, shouldFocus: false, findText: '', replaceText: '', index: 0, matches: [], decorationSet: DecorationSet.empty, shouldMatchCase: false }; export var createPlugin = function createPlugin(dispatch, getIntl, api) { return new SafePlugin({ key: findReplacePluginKey, state: createPluginState(dispatch, function () { return _objectSpread(_objectSpread({}, initialState), {}, { getIntl: getIntl, api: api }); }), props: { decorations: function decorations(state) { var _getPluginState = getPluginState(state), isActive = _getPluginState.isActive, findText = _getPluginState.findText, decorationSet = _getPluginState.decorationSet; if (isActive && findText) { return decorationSet; } } } }); };