@atlaskit/editor-plugin-highlight
Version:
Highlight plugin for @atlaskit/editor-core
51 lines • 2.79 kB
JavaScript
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 { PluginKey } from '@atlaskit/editor-prosemirror/state';
import { getActiveColor } from '../editor-commands/color';
import { getDisabledState } from '../editor-commands/disabled';
export var highlightPluginKey = new PluginKey('highlight');
export var HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
HighlightPluginAction[HighlightPluginAction["SET_PALETTE"] = 1] = "SET_PALETTE";
return HighlightPluginAction;
}({});
export var createPlugin = function createPlugin() {
return new SafePlugin({
key: highlightPluginKey,
state: {
init: function init(_, editorState) {
return {
activeColor: null,
disabled: getDisabledState(editorState),
isPaletteOpen: false
};
},
apply: function apply(tr, pluginState, _oldState, newState) {
var _tr$getMeta;
var action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
switch (action) {
case HighlightPluginAction.CHANGE_COLOR:
var _tr$getMeta2 = tr.getMeta(highlightPluginKey),
color = _tr$getMeta2.color;
return _objectSpread(_objectSpread({}, pluginState), {}, {
activeColor: color
});
case HighlightPluginAction.SET_PALETTE:
var _tr$getMeta3 = tr.getMeta(highlightPluginKey),
isPaletteOpen = _tr$getMeta3.isPaletteOpen;
return _objectSpread(_objectSpread({}, pluginState), {}, {
isPaletteOpen: isPaletteOpen
});
default:
var activeColor = getActiveColor(tr);
return _objectSpread(_objectSpread({}, pluginState), {}, {
activeColor: activeColor,
disabled: getDisabledState(newState)
});
}
}
}
});
};