@atlaskit/editor-plugin-track-changes
Version:
ShowDiff plugin for @atlaskit/editor-core
33 lines (32 loc) • 1.89 kB
JavaScript
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
import { bindKeymapWithCommand, isCapsLockOnAndModifyKeyboardEvent, toggleViewChanges } from '@atlaskit/editor-common/keymaps';
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
export function keymapPlugin(api) {
const list = {};
const browser = getBrowserInfo();
// Exclude Firefox browser from keyboard shortcut
if (!browser.gecko) {
bindKeymapWithCommand(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
toggleViewChanges.common, () => {
var _api$trackChanges, _api$trackChanges2;
const trackChangesState = api === null || api === void 0 ? void 0 : (_api$trackChanges = api.trackChanges) === null || _api$trackChanges === void 0 ? void 0 : _api$trackChanges.sharedState.currentState();
// Mirror the toolbar button: no changes to show, or another plugin currently owns
// the diff decorations (e.g. the AI Review moment is visible).
if (!(trackChangesState !== null && trackChangesState !== void 0 && trackChangesState.isShowDiffAvailable) || trackChangesState !== null && trackChangesState !== void 0 && trackChangesState.isToggleChangesDisabled) {
return false;
}
const result = api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$trackChanges2 = api.trackChanges) === null || _api$trackChanges2 === void 0 ? void 0 : _api$trackChanges2.commands.toggleChanges);
return result !== null && result !== void 0 ? result : false;
}, list);
}
return new SafePlugin({
props: {
handleKeyDown(view, event) {
const keyboardEvent = isCapsLockOnAndModifyKeyboardEvent(event);
return keydownHandler(list)(view, keyboardEvent);
}
}
});
}