@atlaskit/editor-plugin-highlight
Version:
Highlight plugin for @atlaskit/editor-core
38 lines • 1.62 kB
JavaScript
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { bindKeymapWithCommand, keymap, toggleHighlightPalette, applyYellowHighlight } from '@atlaskit/editor-common/keymaps';
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
import { highlightColorPalette } from '@atlaskit/editor-common/ui-color';
import { changeColor } from '../editor-commands/change-color';
import { togglePalette } from '../editor-commands/palette';
export function keymapPlugin({
api
}) {
var _api$analytics;
const list = {};
const isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
if (!isToolbarAIFCEnabled) {
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
toggleHighlightPalette.common,
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
togglePalette(api)({
inputMethod: INPUT_METHOD.SHORTCUT
}), list);
}
const analyticsApi = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
const color = highlightColorPalette.find(({
label
}) => label === 'Yellow');
if (color) {
bindKeymapWithCommand(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
applyYellowHighlight.common, editorCommandToPMCommand(changeColor(analyticsApi)({
color: color.value,
inputMethod: INPUT_METHOD.SHORTCUT
})), list);
}
return keymap(list);
}