@atlaskit/editor-plugin-find-replace
Version:
find replace plugin for @atlaskit/editor-core
67 lines (66 loc) • 3.44 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _actions = require("./actions");
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) { (0, _defineProperty2.default)(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; }
var reducer = function reducer(getInitialState) {
return function (state, action) {
switch (action.type) {
case _actions.FindReplaceActionTypes.ACTIVATE:
case _actions.FindReplaceActionTypes.FIND:
return _objectSpread(_objectSpread({}, state), {}, {
isActive: true,
shouldFocus: action.type === _actions.FindReplaceActionTypes.ACTIVATE,
findText: action.findText !== undefined ? action.findText : state.findText,
matches: action.matches || state.matches,
index: action.index !== undefined ? action.index : state.index
});
case _actions.FindReplaceActionTypes.UPDATE_DECORATIONS:
return _objectSpread(_objectSpread({}, state), {}, {
decorationSet: action.decorationSet
});
case _actions.FindReplaceActionTypes.FIND_NEXT:
return _objectSpread(_objectSpread({}, state), {}, {
index: action.index,
decorationSet: action.decorationSet
});
case _actions.FindReplaceActionTypes.FIND_PREVIOUS:
return _objectSpread(_objectSpread({}, state), {}, {
index: action.index,
decorationSet: action.decorationSet
});
case _actions.FindReplaceActionTypes.REPLACE:
case _actions.FindReplaceActionTypes.REPLACE_ALL:
return _objectSpread(_objectSpread({}, state), {}, {
replaceText: action.replaceText,
decorationSet: action.decorationSet,
matches: action.matches,
index: action.index
});
case _actions.FindReplaceActionTypes.CANCEL:
var getIntl = state.getIntl,
api = state.api;
return (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? _objectSpread(_objectSpread({}, getInitialState()), {}, {
getIntl: getIntl,
api: api
}) : getInitialState();
case _actions.FindReplaceActionTypes.BLUR:
return _objectSpread(_objectSpread({}, state), {}, {
shouldFocus: false
});
case _actions.FindReplaceActionTypes.TOGGLE_MATCH_CASE:
return _objectSpread(_objectSpread({}, state), {}, {
shouldMatchCase: !state.shouldMatchCase
});
default:
return state;
}
};
};
var _default = exports.default = reducer;