UNPKG

@atlaskit/editor-plugin-custom-autoformat

Version:

Custom autoformat plugin for @atlaskit/editor-core

43 lines (40 loc) 2.18 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; 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; } // queues a match at a given position in the document export var matched = function matched(state, action) { return _objectSpread(_objectSpread({}, state), {}, { resolving: [].concat(_toConsumableArray(state.resolving), [{ start: action.start, end: action.end, match: action.match }]) }); }; // store the replacement for a match export var resolved = function resolved(state, action) { return _objectSpread(_objectSpread({}, state), {}, { matches: [].concat(_toConsumableArray(state.matches), [{ replacement: action.replacement, matchString: action.matchString }]) }); }; // indicates a replacement in the document has been completed, and removes the match from both resolving and matches export var finish = function finish(state, action) { return _objectSpread(_objectSpread({}, state), {}, { resolving: state.resolving.filter(function (resolving) { return resolving.match[0] !== action.matchString; }), matches: state.matches.filter(function (matching) { return matching.matchString !== action.matchString; }) }); }; // sets the autoformatting provider in the shared plugin state export var setProvider = function setProvider(state, action) { return _objectSpread(_objectSpread({}, state), {}, { autoformattingProvider: action.provider }); };